fix(task): update UI with final usage after stream completion (#7552)

Ensure the UI displays accurate token usage and costs by updating the API request message when the stream completes. This commit adds a call to updateApiReqMsg followed by saving messages and posting state to the webview, which occurs before finalizing tool calls. This ensures users see the final usage statistics (input/output tokens, cache tokens, and total cost) reflected in the interface immediately after stream processing.
This commit is contained in:
Bee authored and GitHub committed 2025-11-19 02:54:31 -08:00
1 parent 7abeae5019
commit 499ee22b3b
1 file changed
+14
+14
View File
@@ -2960,6 +2960,20 @@ export class Task {
}
}
// Update UI with final usage after stream is complete
await updateApiReqMsg({
messageStateHandler: this.messageStateHandler,
lastApiReqIndex,
inputTokens,
outputTokens,
cacheWriteTokens,
cacheReadTokens,
api: this.api,
totalCost,
})
await this.messageStateHandler.saveClineMessagesAndUpdateHistory()
await this.postStateToWebview()
// Finalize any remaining tool calls at the end of the stream
if (this.useNativeToolCalls) {
// For native tool calls, mark all pending tool uses as complete