新增后台架构前端状态层
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import type { LlmTraceManifest } from "../../lib/llm/trace-types";
|
||||
|
||||
function traceHeaders(apiAccessKey: string): Record<string, string> {
|
||||
return apiAccessKey ? { "x-api-key": apiAccessKey } : {};
|
||||
}
|
||||
|
||||
async function traceFetch<T>(path: string, apiAccessKey: string): Promise<T> {
|
||||
const response = await fetch(path, {
|
||||
credentials: "same-origin",
|
||||
headers: traceHeaders(apiAccessKey),
|
||||
cache: "no-store",
|
||||
});
|
||||
const body = await response.json().catch(() => ({})) as T & {
|
||||
error?: string;
|
||||
};
|
||||
if (!response.ok) throw new Error(body.error ?? "读取后台追踪失败");
|
||||
return body;
|
||||
}
|
||||
|
||||
export function getLatestTrace(apiAccessKey: string) {
|
||||
return traceFetch<LlmTraceManifest | { run: null; calls: [] }>(
|
||||
"/api/llm-traces/latest",
|
||||
apiAccessKey,
|
||||
);
|
||||
}
|
||||
|
||||
export function getJobTrace(jobId: string, apiAccessKey: string) {
|
||||
return traceFetch<LlmTraceManifest>(
|
||||
`/api/jobs/${encodeURIComponent(jobId)}/llm-trace`,
|
||||
apiAccessKey,
|
||||
);
|
||||
}
|
||||
|
||||
export function getTracePayload(
|
||||
jobId: string,
|
||||
callId: string,
|
||||
kind: "request" | "response",
|
||||
apiAccessKey: string,
|
||||
) {
|
||||
return traceFetch<unknown>(
|
||||
`/api/jobs/${encodeURIComponent(jobId)}/llm-trace/${encodeURIComponent(callId)}/${kind}`,
|
||||
apiAccessKey,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user