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

+42
View File
@@ -28,6 +28,7 @@ import {
fetchSkills,
fetchTrendingMarketplaceSkills,
fetchWebuiThread,
fetchWebuiThreadTraceDetail,
fetchWorkspaces,
importMcpConfig,
installMarketplaceSkill,
@@ -117,6 +118,47 @@ describe("webui API helpers", () => {
);
});
it("revalidates a cached WebUI thread and reuses it on 304", async () => {
const cached = {
schemaVersion: 3,
revision: "rev-1",
messages: [],
};
vi.mocked(fetch).mockResolvedValueOnce({
ok: false,
status: 304,
} as Response);
await expect(fetchWebuiThread("tok", "websocket:chat-1", {
revision: cached.revision,
cached,
})).resolves.toBe(cached);
expect(fetch).toHaveBeenCalledWith(
"/api/sessions/websocket%3Achat-1/webui-thread",
expect.objectContaining({
headers: {
Authorization: "Bearer tok",
"If-None-Match": '"rev-1"',
},
cache: "no-store",
}),
);
});
it("fetches deferred trace details with encoded session and ref", async () => {
await fetchWebuiThreadTraceDetail("tok", "websocket:chat-1", "9.tr-deadbeefdeadbeef");
expect(fetch).toHaveBeenCalledWith(
"/api/sessions/websocket%3Achat-1/webui-thread/trace-detail?ref=9.tr-deadbeefdeadbeef",
expect.objectContaining({
headers: { Authorization: "Bearer tok" },
credentials: "same-origin",
cache: "no-store",
}),
);
});
it("aborts a WebUI thread request when its caller signal is aborted", async () => {
let requestSignal: AbortSignal | null = null;
vi.mocked(fetch).mockImplementation((_input, init) => new Promise((_resolve, reject) => {