mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-08-12 07:49:00 +00:00
* fix: use backend thread token usage for header total * Refactor thread token usage fetch
25 lines
685 B
TypeScript
25 lines
685 B
TypeScript
import { fetch as fetchWithAuth } from "@/core/api/fetcher";
|
|
import { getBackendBaseURL } from "@/core/config";
|
|
|
|
import type { ThreadTokenUsageResponse } from "./types";
|
|
|
|
export async function fetchThreadTokenUsage(
|
|
threadId: string,
|
|
): Promise<ThreadTokenUsageResponse | null> {
|
|
const response = await fetchWithAuth(
|
|
`${getBackendBaseURL()}/api/threads/${encodeURIComponent(threadId)}/token-usage`,
|
|
{
|
|
method: "GET",
|
|
},
|
|
);
|
|
|
|
if (!response.ok) {
|
|
if (response.status === 403 || response.status === 404) {
|
|
return null;
|
|
}
|
|
throw new Error("Failed to load thread token usage.");
|
|
}
|
|
|
|
return (await response.json()) as ThreadTokenUsageResponse;
|
|
}
|