fix: use backend thread token usage for header total (#2800)

* fix: use backend thread token usage for header total

* Refactor thread token usage fetch
This commit is contained in:
YuJitang
2026-05-09 19:40:32 +08:00
committed by GitHub
parent 881ff71252
commit 417416087b
16 changed files with 540 additions and 35 deletions
+20
View File
@@ -0,0 +1,20 @@
import type { TokenUsage } from "@/core/messages/usage";
import type { ThreadTokenUsageResponse } from "./types";
export function threadTokenUsageQueryKey(threadId?: string | null) {
return ["thread-token-usage", threadId] as const;
}
export function threadTokenUsageToTokenUsage(
usage: ThreadTokenUsageResponse | null | undefined,
): TokenUsage | null {
if (!usage) {
return null;
}
return {
inputTokens: usage.total_input_tokens ?? 0,
outputTokens: usage.total_output_tokens ?? 0,
totalTokens: usage.total_tokens ?? 0,
};
}