mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-10-26 13:16:24 +00:00
* fix(frontend): authenticate remaining gateway reads * fix(frontend): authenticate artifact reads * fix(frontend): include status in model errors
32 lines
862 B
TypeScript
32 lines
862 B
TypeScript
import { throwGatewayApiError } from "@/core/api/errors";
|
|
import { fetch } from "@/core/api/fetcher";
|
|
|
|
import { getBackendBaseURL } from "../config";
|
|
import { isStaticWebsiteOnly } from "../static-mode";
|
|
|
|
import type { ModelsResponse } from "./types";
|
|
|
|
const STATIC_MODELS_RESPONSE: ModelsResponse = {
|
|
models: [],
|
|
token_usage: { enabled: false },
|
|
};
|
|
|
|
export async function loadModels(): Promise<ModelsResponse> {
|
|
if (isStaticWebsiteOnly()) {
|
|
return STATIC_MODELS_RESPONSE;
|
|
}
|
|
|
|
const res = await fetch(`${getBackendBaseURL()}/api/models`);
|
|
if (!res.ok) {
|
|
await throwGatewayApiError(
|
|
res,
|
|
`Failed to load models: ${res.status} ${res.statusText}`.trim(),
|
|
);
|
|
}
|
|
const data = (await res.json()) as Partial<ModelsResponse>;
|
|
return {
|
|
models: data.models ?? [],
|
|
token_usage: data.token_usage ?? { enabled: false },
|
|
};
|
|
}
|