417416087b
* fix: use backend thread token usage for header total * Refactor thread token usage fetch
21 lines
558 B
TypeScript
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,
|
|
};
|
|
}
|