Files
deer-flow/frontend/src/core/threads/token-usage.ts
T
YuJitang 417416087b fix: use backend thread token usage for header total (#2800)
* fix: use backend thread token usage for header total

* Refactor thread token usage fetch
2026-05-09 19:40:32 +08:00

21 lines
558 B
TypeScript

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,
};
}