feat: Enhance token usage tracking and improve chat UI with emojis
This commit is contained in:
@@ -449,12 +449,22 @@ pub fn run_subagent(ctx: &SubagentContext, tx: &mpsc::Sender<SubagentEvent>) ->
|
||||
// drain thread can accumulate it and update the Usage panel.
|
||||
// Without this, the Usage panel always shows zeros because the
|
||||
// subagent never tells the parent about the tokens consumed.
|
||||
if let Some((tokens_in, tokens_out)) = returned_usage {
|
||||
let _ = tx.blocking_send(SubagentEvent::Usage {
|
||||
tokens_in,
|
||||
tokens_out,
|
||||
});
|
||||
let (mut tok_in, mut tok_out) = returned_usage.unwrap_or((0, 0));
|
||||
if tok_in == 0 {
|
||||
let prompt_chars: usize = messages.iter()
|
||||
.filter_map(|m| m.content.as_deref())
|
||||
.map(str::len)
|
||||
.sum();
|
||||
tok_in = (prompt_chars / 4).max(1) as u64;
|
||||
}
|
||||
if tok_out == 0 {
|
||||
let response_chars = response.content.as_deref().map_or(0, str::len);
|
||||
tok_out = (response_chars / 4).max(1) as u64;
|
||||
}
|
||||
let _ = tx.blocking_send(SubagentEvent::Usage {
|
||||
tokens_in: tok_in,
|
||||
tokens_out: tok_out,
|
||||
});
|
||||
|
||||
let has_tool_calls = response.tool_calls.is_some()
|
||||
&& response.tool_calls.as_ref().is_some_and(|tc| !tc.is_empty());
|
||||
|
||||
Reference in New Issue
Block a user