perf: speed up chat loading and resume

This commit is contained in:
Federico Jaramillo Martinez
2026-07-12 09:22:19 +02:00
parent 02f34c495c
commit 338faf4b81
25 changed files with 1565 additions and 83 deletions
@@ -22,6 +22,22 @@ describe("SessionEventHub", () => {
expect(otherSocket.send).not.toHaveBeenCalled();
});
it("omits thinking signatures from final-message payloads without mutating source events", () => {
const hub = new SessionEventHub();
const socket = new FakeSocket();
hub.add("s1", socket);
const thinkingBlock = { type: "thinking", thinking: "private chain", thinkingSignature: "opaque-provider-payload", redacted: true };
const message = { role: "assistant", content: [thinkingBlock, { type: "text", text: "visible answer" }] };
hub.publish("s1", { type: "message.end", message });
expect(socket.send).toHaveBeenCalledWith(JSON.stringify({
type: "message.end",
message: { role: "assistant", content: [{ type: "thinking", thinking: "private chain", redacted: true }, { type: "text", text: "visible answer" }] },
}));
expect(thinkingBlock.thinkingSignature).toBe("opaque-provider-payload");
});
it("removes session sockets on close and skips non-open sockets", () => {
const hub = new SessionEventHub();
const closed = new FakeSocket();
+2 -1
View File
@@ -1,4 +1,5 @@
import type { GlobalSessionEvent, RealtimeEvent, SessionUiEvent } from "../../shared/apiTypes.js";
import { projectBrowserSessionEvent } from "../browserMessageProjection.js";
export interface RealtimeSocket {
readonly OPEN: number;
@@ -29,7 +30,7 @@ export class SessionEventHub {
}
publish(sessionId: string, event: SessionUiEvent): void {
const payload = JSON.stringify(event);
const payload = JSON.stringify(projectBrowserSessionEvent(event));
for (const socket of this.socketsBySession.get(sessionId) ?? []) {
if (socket.readyState === socket.OPEN) socket.send(payload);
}