Bouncy lead chat

This commit is contained in:
Ian Gulliver
2026-10-15 20:41:42 -07:00
parent f84b1788ae
commit cb2188e3cf
4 changed files with 30 additions and 9 deletions
+14 -3
View File
@@ -74,6 +74,7 @@ type Ctx = {
root: () => string;
taskId: string | undefined;
held: HTMLElement | undefined;
open: boolean;
drawn: HTMLElement[] | undefined;
quiet: boolean;
handoff: { summary: HTMLElement; body: HTMLElement } | undefined;
@@ -217,6 +218,7 @@ export function mountChat(root: HTMLElement, src: ChatSource, makeHead: (rerende
reviewButtons: new Map(),
run: undefined,
held: undefined,
open: false,
drawn: undefined,
quiet: false,
handoff: undefined,
@@ -245,13 +247,14 @@ export function mountChat(root: HTMLElement, src: ChatSource, makeHead: (rerende
transcript.append(el);
}
};
const syncRunning = () => setRunning(src.session()?.state === "running" && !ctx.held);
const syncRunning = () => setRunning(src.session()?.state === "running" && ctx.open);
const release = () => {
const el = ctx.held;
if (!el) {
return;
}
ctx.held = undefined;
ctx.open = true;
ctx.drawn?.push(el);
putBefore(el, stream?.el ?? pending[0]?.el);
syncRunning();
@@ -273,6 +276,7 @@ export function mountChat(root: HTMLElement, src: ChatSource, makeHead: (rerende
}
ctx.drawn = undefined;
ctx.held = undefined;
ctx.open = false;
ctx.quiet = false;
syncRunning();
};
@@ -380,7 +384,7 @@ export function mountChat(root: HTMLElement, src: ChatSource, makeHead: (rerende
return;
}
if (!stream) {
stream = { el: h("div", { class: "msg agent" }), text: "", timer: 0 };
stream = { el: h("div", { class: "msg agent", hidden: true }), text: "", timer: 0 };
ctx.run = undefined;
put(stream.el, true);
}
@@ -480,6 +484,9 @@ export function mountChat(root: HTMLElement, src: ChatSource, makeHead: (rerende
continue;
}
ctx.run = undefined;
if (ev.kind === "turn.ended") {
ctx.open = false;
}
if (ev.kind === "turn.ended" && p["handoff"] === true && ctx.handoff) {
closeHandoff(el);
continue;
@@ -499,12 +506,16 @@ export function mountChat(root: HTMLElement, src: ChatSource, makeHead: (rerende
}
if (ev.kind === "user.message" && ev.actor === "byre" && ev.owner && p["mid_turn"] !== true && p["handoff"] !== true) {
ctx.held = el;
ctx.open = false;
ctx.drawn = [];
syncRunning();
continue;
}
if (ev.kind === "user.message" && p["mid_turn"] !== true) {
ctx.open = true;
}
put(el);
}
syncRunning();
if (contextChanged) {
renderHead();
const sess = src.session();