fix(webui): cache and defer thread history

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-12 17:09:51 +08:00
1 parent 7ba60c2ef0
commit a490cd629b
30 files changed
+1306 -145

No files matched your search

+24 -1
View File
@@ -41,6 +41,7 @@ import type {
WebSearchSettingsUpdate,
WorkspacesPayload,
WebuiThreadPersistedPayload,
WebuiThreadTraceDetailPayload,
WorkspaceScopePayload,
} from "./types";
import { fetchWithTimeout } from "./http";
@@ -226,6 +227,8 @@ export interface FetchWebuiThreadOptions {
direction?: "latest";
before?: string | null;
signal?: AbortSignal;
revision?: string;
cached?: WebuiThreadPersistedPayload;
}
export async function fetchWebuiThread(
@@ -243,17 +246,37 @@ export async function fetchWebuiThread(
const query = params.toString();
const suffix = query ? `?${query}` : "";
const url = `${resolvedBase}/api/sessions/${encodeURIComponent(key)}/webui-thread${suffix}`;
const headers: Record<string, string> = { Authorization: `Bearer ${token}` };
if (options?.revision) headers["If-None-Match"] = `"${options.revision}"`;
const res = await fetchWithTimeout(url, {
headers: { Authorization: `Bearer ${token}` },
headers,
credentials: "same-origin",
cache: "no-store",
signal: options?.signal,
});
if (res.status === 304 && options?.cached) return options.cached;
if (res.status === 404) return null;
if (!res.ok) throw new ApiError(res.status, `HTTP ${res.status}`);
return (await res.json()) as WebuiThreadPersistedPayload;
}
export async function fetchWebuiThreadTraceDetail(
token: string,
key: string,
ref: string,
base: string = "",
): Promise<WebuiThreadTraceDetailPayload> {
const query = new URLSearchParams({ ref });
const url = `${base}/api/sessions/${encodeURIComponent(key)}/webui-thread/trace-detail?${query}`;
const res = await fetchWithTimeout(url, {
headers: { Authorization: `Bearer ${token}` },
credentials: "same-origin",
cache: "no-store",
});
if (!res.ok) throw new ApiError(res.status, `HTTP ${res.status}`);
return (await res.json()) as WebuiThreadTraceDetailPayload;
}
export async function fetchFilePreview(
token: string,
key: string,