refactor(webui): unify live and replay event projection (#5819)

* refactor(webui): unify live and replay event projection

* chore(webui): mark legacy projection cleanup

* fix(webui): rewrite streamed replay media URLs
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-20 13:52:43 +08:00
1 parent 3d4200ff0d
commit db675a43b6
14 files changed
+1726 -665

No files matched your search

+25 -4
View File
@@ -81,7 +81,12 @@ describe("webui API helpers", () => {
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ deleted: true, key: "websocket:chat-1", messages: [] }),
json: async () => ({
schemaVersion: 3,
deleted: true,
key: "websocket:chat-1",
messages: [],
}),
}),
);
});
@@ -95,7 +100,7 @@ describe("webui API helpers", () => {
await fetchWebuiThread("tok", "websocket:chat-1");
expect(fetch).toHaveBeenCalledWith(
"/api/sessions/websocket%3Achat-1/webui-thread",
"/api/sessions/websocket%3Achat-1/webui-thread?projection=events",
expect.objectContaining({
headers: { Authorization: "Bearer tok" },
credentials: "same-origin",
@@ -111,7 +116,7 @@ describe("webui API helpers", () => {
});
expect(fetch).toHaveBeenCalledWith(
"/api/sessions/websocket%3Achat-1/webui-thread?limit=120&before=abc%2B%2F%3D",
"/api/sessions/websocket%3Achat-1/webui-thread?limit=120&before=abc%2B%2F%3D&projection=events",
expect.objectContaining({
headers: { Authorization: "Bearer tok" },
credentials: "same-origin",
@@ -136,7 +141,7 @@ describe("webui API helpers", () => {
})).resolves.toBe(cached);
expect(fetch).toHaveBeenCalledWith(
"/api/sessions/websocket%3Achat-1/webui-thread",
"/api/sessions/websocket%3Achat-1/webui-thread?projection=events",
expect.objectContaining({
headers: {
Authorization: "Bearer tok",
@@ -147,6 +152,22 @@ describe("webui API helpers", () => {
);
});
it("rejects malformed canonical thread events at the HTTP boundary", async () => {
vi.mocked(fetch).mockResolvedValueOnce({
ok: true,
status: 200,
json: async () => ({
schemaVersion: 3,
projection: "events",
events: [{ event: "file_edit", chat_id: "chat-1", edits: [{ tool: "edit_file" }] }],
}),
} as Response);
await expect(fetchWebuiThread("tok", "websocket:chat-1")).rejects.toThrow(
"Invalid WebUI thread projection event: file_edit",
);
});
it("fetches deferred trace details with encoded session and ref", async () => {
await fetchWebuiThreadTraceDetail("tok", "websocket:chat-1", "9.tr-deadbeefdeadbeef");