perf(webui): reduce repeated work and bound history rendering (#5703)

* perf(webui): reduce repeated work and bound history rendering

* fix(webui): keep continuation reasoning with its answer

* refactor(webui): reuse answer buffers and prepared copy text

* perf(webui): restore conditional replay buffer initialization

* fix(webui): remove code block pagination
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-09 14:02:26 +08:00
1 parent 1c451b5b5f
commit 1469d4811c
32 files changed
+1156 -361

No files matched your search

@@ -18,6 +18,39 @@ function progressMessage(id: string, phase: "start" | "end" | "error"): UIMessag
}
describe("activity message coalescing", () => {
it("keeps reused call IDs isolated by turn and picks the latest compatible legacy row", () => {
const call = (id: string, turnId?: string): UIMessage => ({
...progressMessage(id, "start"), turnId,
toolEvents: [{ call_id: "shared", phase: "start", name: "web_search" }],
});
const complete = (id: string, turnId?: string): UIMessage => ({
...call(id, turnId), toolEvents: [{ call_id: "shared", phase: "end", name: "web_search" }],
});
const result = coalesceActivityMessages([
call("first", "a"), call("second", "b"), complete("finish-a", "a"),
]);
expect(result.map((row) => [row.id, row.toolEvents?.[0].phase])).toEqual([
["first", "end"], ["second", "start"],
]);
expect(coalesceActivityMessages([
call("first", "a"), call("second", "b"), complete("legacy"),
]).map((row) => [row.id, row.toolEvents?.[0].phase])).toEqual([
["first", "start"], ["second", "end"],
]);
});
it("processes independent calls with a linear event-read budget", () => {
let reads = 0;
const messages: UIMessage[] = Array.from({ length: 1000 }, (_, index) => ({
id: `${index}`, role: "tool", kind: "trace", content: `tool${index}()`, createdAt: index,
get toolEvents() {
reads++;
return [{ call_id: `${index}`, phase: "end" as const, name: `tool${index}` }];
},
}));
expect(coalesceActivityMessages(messages)).toEqual(messages);
expect(reads).toBeLessThanOrEqual(messages.length * 4);
});
it("folds persisted start and terminal progress into one activity", () => {
const result = coalesceActivityMessages([
progressMessage("start", "start"),