feat: add support for Router provider and enhance command handling

This commit is contained in:
asepharyana
2026-07-12 01:43:57 +07:00
parent a8fee71e06
commit 9f272d5973
5 changed files with 48 additions and 7 deletions
+16 -3
View File
@@ -577,7 +577,7 @@ fn run_agent_turn(
};
let mut stream_started = false;
let (response, usage) = tc.client.chat_with_tools_streaming(
let (response, usage) = match tc.client.chat_with_tools_streaming(
&wire_msgs,
Some(tc.tdefs.clone()),
Some(tc.temperature),
@@ -602,8 +602,21 @@ fn run_agent_turn(
}
_ => {}
},
)?;
let _ = usage; // already emitted as TurnEvent::Usage inside the on_event callback, if present
) {
Ok(result) => result,
Err(_stream_err) => {
// Provider doesn't support streaming — fall back to non-streaming
let (msg, usage_fb) = tc.client.chat_with_tools_non_streaming(
&wire_msgs, Some(tc.tdefs.clone()),
)?;
if let Some((tok_in, tok_out)) = usage_fb {
if let Ok(mut q) = events_q.lock() {
q.push_back(TurnEvent::Usage { tokens_in: tok_in, tokens_out: tok_out });
}
}
(msg, usage_fb)
}
};
let has_tool_calls = response.tool_calls.is_some()
&& response.tool_calls.as_ref().is_some_and(|tc| !tc.is_empty());