SSE reconnect, task switcher state/inbox/new task, stream throttle
This commit is contained in:
+7
-7
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user