mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix: align web token usage display with TUI
Fixes #3322 Use tokens from the last assistant message instead of summing all messages. This matches TUI behavior and shows the actual context size. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a95aa037a3
commit
111fb5ee16
1 changed files with 10 additions and 3 deletions
|
|
@ -277,9 +277,6 @@ export default function Share(props: { id: string; api: string; info: Session.In
|
|||
|
||||
if (msg.role === "assistant") {
|
||||
result.cost += msg.cost
|
||||
result.tokens.input += msg.tokens.input
|
||||
result.tokens.output += msg.tokens.output
|
||||
result.tokens.reasoning += msg.tokens.reasoning
|
||||
|
||||
result.models[`${msg.providerID} ${msg.modelID}`] = [msg.providerID, msg.modelID]
|
||||
|
||||
|
|
@ -292,6 +289,16 @@ export default function Share(props: { id: string; api: string; info: Session.In
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Use tokens from the last assistant message (like TUI does)
|
||||
// This represents the actual context size, not cumulative tokens
|
||||
const lastAssistant = msgs.findLast((x) => x.role === "assistant" && x.tokens?.output > 0)
|
||||
if (lastAssistant && lastAssistant.role === "assistant") {
|
||||
result.tokens.input = lastAssistant.tokens.input
|
||||
result.tokens.output = lastAssistant.tokens.output
|
||||
result.tokens.reasoning = lastAssistant.tokens.reasoning
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue