Skip to content

Commit 97e3cbe

Browse files
committed
fixup(mockllm): support tool use
1 parent eb29505 commit 97e3cbe

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

crates/chat-cli/src/api_client/mod.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,13 @@ impl ApiClient {
620620
// Each user message gets the next response group in sequence
621621
let response_index = ctx.count_user_messages().saturating_sub(1); // 0-indexed
622622

623-
tracing::debug!(actor="MockLLM", user_message=ctx.current_user_message(), count=ctx.count_user_messages(), response_index);
623+
tracing::debug!(
624+
actor="MockLLM",
625+
user_message=ctx.current_user_message(),
626+
count=ctx.count_user_messages(),
627+
response_index,
628+
response_groups=?response_groups,
629+
);
624630

625631
// Send the corresponding response group
626632
if response_index < response_groups.len() {
@@ -635,29 +641,8 @@ impl ApiClient {
635641
input,
636642
stop,
637643
} => {
638-
// For tool events, we need to create proper tool use structure
639-
if stop.unwrap_or(false) {
640-
// This is a complete tool use - parse the arguments
641-
let args = input
642-
.as_ref()
643-
.map(|s| {
644-
serde_json::from_str(s).unwrap_or(serde_json::Value::String(s.clone()))
645-
})
646-
.unwrap_or(serde_json::Value::Null);
647-
648-
let _tool_use = crate::cli::chat::AssistantToolUse {
649-
id: tool_use_id.clone(),
650-
name: name.clone(),
651-
orig_name: name.clone(),
652-
args: args.clone(),
653-
orig_args: args,
654-
};
655-
656-
// For now, just send text response about tool use since we don't have direct tool event API
657-
// TODO: Implement proper tool event support in MockLLMContext if needed
658-
ctx.respond(format!("[Tool: {} with args: {}]", name, tool_use_id))
659-
.await?;
660-
}
644+
ctx.respond_tool_use(tool_use_id.clone(), name.clone(), input.clone(), stop.clone())
645+
.await?;
661646
},
662647
_ => {}, // Ignore other event types
663648
}

crates/chat-cli/src/mock_llm.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,42 @@ impl MockLLMContext {
3838
.map_err(|_| eyre::eyre!("Response channel closed"))
3939
}
4040

41+
async fn send_tool_use(
42+
tx: &mut mpsc::Sender<Result<ChatResponseStream, RecvError>>,
43+
tool_use_id: String,
44+
name: String,
45+
input: Option<String>,
46+
stop: Option<bool>,
47+
) -> eyre::Result<()> {
48+
tx
49+
.send(Ok(ChatResponseStream::ToolUseEvent {
50+
tool_use_id,
51+
name,
52+
input,
53+
stop,
54+
}))
55+
.await
56+
.map_err(|_| eyre::eyre!("Response channel closed"))
57+
}
58+
4159
/// Respond with text to the user.
4260
#[allow(dead_code)]
4361
pub async fn respond(&mut self, text: impl ToString) -> eyre::Result<()> {
4462
Self::send_text(&mut self.tx, text).await
4563
}
4664

65+
/// Respond with a tool use
66+
#[allow(dead_code)]
67+
pub async fn respond_tool_use(
68+
&mut self,
69+
tool_use_id: String,
70+
name: String,
71+
input: Option<String>,
72+
stop: Option<bool>,
73+
) -> eyre::Result<()> {
74+
Self::send_tool_use(&mut self.tx, tool_use_id, name, input, stop).await
75+
}
76+
4777
/// Count the number of user messages in the conversation (including the current one).
4878
/// Useful for determining which predefined response to use in sequence.
4979
#[allow(dead_code)]

0 commit comments

Comments
 (0)