SSE reconnect, task switcher state/inbox/new task, stream throttle

This commit is contained in:
Ian Gulliver
2026-10-14 22:28:25 -07:00
parent 8e4c40eb5f
commit 33e682a9d5
27 changed files with 418 additions and 182 deletions
+7 -7
View File
@@ -191,36 +191,36 @@ export function mountTranscript(root: HTMLElement): () => void {
replace(run.group.summary, runSummary(run.calls));
};
let stream: { el: HTMLElement; text: string; frame: number } | undefined;
let stream: { el: HTMLElement; text: string; timer: number } | undefined;
const dropStream = () => {
if (!stream) {
return;
}
cancelAnimationFrame(stream.frame);
clearTimeout(stream.timer);
stream.el.remove();
stream = undefined;
};
const appendDelta = (ev: ByreEvent) => {
if (!stream) {
stream = { el: h("div", { class: "msg agent" }), text: "", frame: 0 };
stream = { el: h("div", { class: "msg agent" }), text: "", timer: 0 };
ctx.run = undefined;
put(stream.el);
}
stream.text += String(ev.payload["text"] ?? "");
if (stream.frame) {
if (stream.timer) {
return;
}
stream.frame = requestAnimationFrame(() => {
stream.timer = setTimeout(() => {
if (!stream) {
return;
}
stream.frame = 0;
stream.timer = 0;
const pinned = transcript.scrollHeight - transcript.scrollTop - transcript.clientHeight < 80;
replace(stream.el, markdown(stream.text, "text md"));
if (pinned) {
transcript.scrollTop = transcript.scrollHeight;
}
});
}, 100);
};
const foldTurn = (start: HTMLElement, end: HTMLElement) => {