Merge branch 'main' into web-chat-composer

# Conflicts:
#	web/src/app.js
#	web/src/client.js
#	web/src/protocol.js
#	web/test/chat.test.mjs
#	web/test/repository.test.mjs
#	web/test/ui-smoke.mjs
This commit is contained in:
2026-10-19 07:33:49 +01:00
14 changed files with 1840 additions and 39 deletions
+482 -28
View File
@@ -3,7 +3,7 @@
// that came from the server is set with textContent, never innerHTML.
import { PipelinesClient } from "./client.js";
import { PipelinesRepository } from "./repository.js";
import { PROTOCOL_VERSION } from "./protocol.js";
import { PROTOCOL_VERSION, Protocol, ChatKeys } from "./protocol.js";
import { validateServerUrl, resolveArtifactUrl } from "./serverUrl.js";
import {
ForegroundAction,
@@ -78,6 +78,15 @@ import {
runFiltersActiveCount,
} from "./runs.js";
import {
CREATE_ACTION_LABEL,
CREATE_NAME_LABEL,
CREATE_NOTE,
createConfirmLabel,
createDismissLabel,
createFormTitle,
createFormValid,
createSuccessMessage,
createdPipelineName,
effectiveStageType,
templateCard,
templateDetailName,
@@ -224,6 +233,7 @@ import {
LOAD_OLDER_ACTION,
REOPEN_ACTION,
SELECT_CHAT_HINT,
applyChatEvent,
attachmentDisplayName,
attachmentError,
attachmentFiles,
@@ -237,6 +247,7 @@ import {
chatNoMatchMessage,
chatOpensAtNewest,
chatShowJumpToLatest,
chatStreamState,
closeChatConfirmation,
composerAction,
composerCanSend,
@@ -245,7 +256,9 @@ import {
directoryLabel,
filterSessions,
groupSessionsByDirectory,
historyResync,
mergeHistoryPage,
newChatThread,
parseChatInput,
queuedAfterFrame,
reasoningLabel,
@@ -258,16 +271,26 @@ import {
sessionStatusLabel,
sessionTitle,
sessionWorkLabel,
settledThread,
formatToolDuration,
threadElapsedMillis,
threadPhase,
threadRunningTools,
threadToolElapsedMillis,
TURN_PHASE_WAITING,
toolCallCount,
toolCallRow,
toolCallsAnnouncement,
toolCallsLabel,
toolDetail,
toolFailed,
toolLabel,
toolLongRunning,
toolRunning,
toolsRunning,
transcriptRows,
turnElapsedMillis,
turnPhaseLabel,
} from "./chat.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "./markdown.js";
@@ -350,6 +373,16 @@ const state = {
templateGraphs: new Map(),
selectedTemplateKey: null,
templateTab: "summary",
// The create-from-template dialog (P5): whether it is open, the name being
// typed, whether a validate+submit is in flight, the server's refusal text and
// the created pipeline's name (null until a success, which is also what makes
// Cancel read Close and the field lock). The dialog validates the template's
// source first, then submits it create-only; nothing runs.
templateCreateOpen: false,
templateCreateName: "",
templateCreateSending: false,
templateCreateError: "",
templateCreateCreated: null,
loading: false,
error: "",
runFilters: defaultRunFilters(),
@@ -434,6 +467,12 @@ const state = {
// report for a refused close/reopen.
chatClose: null,
chatBusy: false,
// C5: the session ids this connection currently has subscribed to their shared
// live stream. The server detaches a subscription when the connection closes
// (there is no chat_unsubscribe), so this is cleared on every socket drop and
// re-established for the open chat on reconnect. A refused subscription simply
// never joins the set, so the badge reads "not live" honestly.
chatSubscriptions: new Set(),
};
let runPoll = null;
@@ -451,6 +490,12 @@ let listNow = Date.now();
let detailClock = null;
let detailNow = Date.now();
// The chat running indicator's own live clock (C5): it ticks once a second only
// while the open conversation has a turn in flight, updating just the indicator
// in place (never a full re-render), so the transcript's scroll is not disturbed.
let chatClock = null;
let chatNow = Date.now();
// ---------------------------------------------------------------------------
// DOM helpers
// ---------------------------------------------------------------------------
@@ -912,8 +957,10 @@ function renderContent() {
afterChatRender();
stopListClock();
stopDetailClock();
refreshChatClock();
return;
}
stopChatClock();
if (state.view === "runs") {
refreshListClock();
refreshDetailClock();
@@ -1320,6 +1367,7 @@ function renderTemplateDetail() {
return pane;
}
const graph = templateGraphFor(entry.key);
pane.append(renderTemplateDetailActions());
pane.append(
h(
"div",
@@ -1332,9 +1380,190 @@ function renderTemplateDetail() {
if (state.templateTab === "graph") pane.append(renderTemplateGraphTab(graph));
else if (state.templateTab === "source") pane.append(renderTemplateSourceTab(entry, graph));
else pane.append(renderTemplateSummaryTab(entry, graph));
if (state.templateCreateOpen) pane.append(renderTemplateCreateDialog(entry));
return pane;
}
/**
* The template detail's action row: the one "Create pipeline from this
* template" action (P5), matching the app's top-bar add action. It opens the
* dialog; it never submits on its own.
*/
function renderTemplateDetailActions() {
return h(
"div",
{ class: "detail-actions" },
h("button", {
class: "ghost template-create-open",
type: "button",
text: CREATE_ACTION_LABEL,
onclick: () => openTemplateCreateDialog(),
}),
);
}
/** Open the create dialog with a fresh, empty name; nothing is sent until Create. */
function openTemplateCreateDialog() {
state.templateCreateOpen = true;
state.templateCreateName = "";
state.templateCreateSending = false;
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
document.querySelector(".template-create-name")?.focus();
}
/** Dismiss the create dialog (never while a validate+submit is in flight). */
function closeTemplateCreateDialog() {
if (state.templateCreateSending) return;
state.templateCreateOpen = false;
state.templateCreateName = "";
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
}
/**
* The create dialog (P5): the title, the one required name field, the note, the
* server's refusal text or the success line, and Create/Cancel (Cancel reads
* Close after a success). Create is disabled while the name is blank or while
* sending; the field locks while sending and after a success. Every server
* string is set with textContent.
*/
function renderTemplateCreateDialog(entry) {
const title = createFormTitle(entry);
const overlay = h("div", {
class: "template-create-dialog",
role: "dialog",
"aria-modal": "true",
"aria-label": title,
});
overlay.addEventListener("click", (event) => {
if (event.target === overlay) closeTemplateCreateDialog();
});
const panel = h("div", { class: "template-create-panel" });
panel.append(h("h2", { class: "template-create-title", text: title }));
const field = h("label", { class: "template-create-field" });
field.append(h("span", { class: "template-create-label", text: CREATE_NAME_LABEL }));
field.append(
h("input", {
class: "template-create-name",
type: "text",
value: state.templateCreateName,
spellcheck: "false",
autocomplete: "off",
disabled: state.templateCreateSending || state.templateCreateCreated != null,
oninput: (event) => {
// Update in place (no re-render) so the field keeps focus and its caret;
// only the confirm button's enabled state depends on the name.
state.templateCreateName = event.target.value;
const confirm = overlay.querySelector(".template-create-confirm");
if (confirm) {
confirm.disabled = !createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
});
}
},
}),
);
panel.append(field);
panel.append(h("p", { class: "template-create-note muted", text: CREATE_NOTE }));
if (state.templateCreateError) {
panel.append(h("div", { class: "template-create-error bad", text: state.templateCreateError }));
}
if (state.templateCreateCreated != null) {
panel.append(
h("div", {
class: "template-create-success",
text: createSuccessMessage(state.templateCreateCreated),
}),
);
}
const actions = h("div", { class: "template-create-actions" });
actions.append(
h("button", {
class: "ghost template-create-cancel",
type: "button",
text: createDismissLabel(state.templateCreateCreated),
disabled: state.templateCreateSending,
onclick: closeTemplateCreateDialog,
}),
);
actions.append(
h("button", {
class: "template-create-confirm",
type: "button",
text: createConfirmLabel(state.templateCreateSending),
disabled: !createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
}),
onclick: () => createFromTemplate(entry),
}),
);
panel.append(actions);
overlay.append(panel);
return overlay;
}
/**
* The P5 submit flow, exactly the app's: validate the template's source first
* and, when the server refuses to parse it, show its own error in the dialog and
* send nothing; otherwise submit the source create-only with the chosen name. On
* success remember the created name, refresh the pipeline list so the new row is
* visible and leave the dialog open (Cancel now reads Close); on failure show
* the server's error without closing.
*/
async function createFromTemplate(entry) {
if (
!createFormValid(state.templateCreateName, {
sending: state.templateCreateSending,
created: state.templateCreateCreated,
})
) {
return;
}
const name = state.templateCreateName;
state.templateCreateSending = true;
state.templateCreateError = "";
renderContent();
try {
await repo.validate(entry.source);
} catch (error) {
state.templateCreateSending = false;
state.templateCreateError = describeError(error);
renderContent();
return;
}
try {
const detail = await repo.submit(name, entry.source);
state.templateCreateSending = false;
state.templateCreateCreated = createdPipelineName(detail, name);
await refreshPipelines();
} catch (error) {
state.templateCreateSending = false;
state.templateCreateError = describeError(error);
}
renderContent();
}
/**
* Refresh just the pipeline summaries after a create so the new row appears when
* the operator returns to the Pipelines list. A failed refresh keeps the created
* name and is surfaced through the banner rather than discarded.
*/
async function refreshPipelines() {
try {
state.pipelines = await repo.listPipelines();
state.pipelinesLoaded = true;
} catch (error) {
state.error = describeError(error);
}
}
function templateTabButton(tab, label) {
return h("button", {
class: `minitab${state.templateTab === tab ? " active" : ""}`,
@@ -1586,7 +1815,7 @@ function renderRunToolbar() {
function renderLiveBadge(info) {
return h(
"span",
{ class: `live-badge live-${info.tone}`, title: "Live run stream" },
{ class: `live-badge live-${info.tone}`, title: info.title ?? "Live run stream" },
h("span", { class: "live-dot", "aria-hidden": "true" }),
h("span", { class: "live-word", text: info.label }),
);
@@ -3342,7 +3571,7 @@ async function loadChatSessions(force = false) {
renderContent();
}
/** Open a session: select it and load its newest history page. */
/** Open a session: select it, subscribe its stream and load its newest history page. */
async function openChatSession(id) {
if (state.chatActiveId === id && state.chatThreads.get(id)?.loaded) return;
// Remember where the operator left the conversation being closed.
@@ -3356,21 +3585,22 @@ async function openChatSession(id) {
state.chatToolRows = new Set();
const existing = state.chatThreads.get(id);
state.chatThreads.set(id, {
...newChatThread(id),
...(existing ?? {}),
// The composer's own per-chat state (C8/C9) survives a switch; the draft is
// seeded from localStorage on the first open (the per-device analogue).
// seeded from localStorage on the first open (the per-device analogue). The
// live-stream fields (C5) come from `newChatThread`.
draft: existing ? existing.draft ?? "" : readChatDraft(id),
attachments: existing?.attachments ?? [],
notices: existing?.notices ?? [],
queued: existing?.queued ?? false,
running: existing?.running ?? false,
messages: existing?.messages ?? [],
nextCursor: existing?.nextCursor ?? "",
hasMore: existing?.hasMore ?? false,
loaded: false,
loading: true,
error: "",
});
renderContent();
// Attach the shared live stream once per session per connection; its failure is
// non-fatal — history stays usable and the badge reads "not live".
subscribeChatSession(id);
await loadChatHistory(id);
}
@@ -3381,9 +3611,78 @@ function setThread(sessionId, patch) {
state.chatThreads.set(sessionId, { ...current, ...patch });
}
/**
* Attach one session's shared live stream (C5): `chat_subscribe` with the session
* id as the body. Idempotent per connection — a session already subscribed is not
* asked for again. A refusal (an older server that does not know the command, or
* any other error) leaves history usable and the live badge `not live`.
*/
async function subscribeChatSession(id) {
if (!id || state.connection.kind !== "connected") return;
if (state.chatSubscriptions.has(id)) return;
try {
await repo.subscribeChat(id);
state.chatSubscriptions = new Set(state.chatSubscriptions).add(id);
} catch {
// The subscription is not live; nothing else changes. The badge says so.
}
renderContent();
}
/** Drop the per-connection subscriptions (the server detaches them on close). */
function clearChatSubscriptions() {
if (state.chatSubscriptions.size > 0) state.chatSubscriptions = new Set();
}
/**
* Settle every conversation that was running. A socket drop (or a close) removes
* the frames feeding the turn, so no thread keeps claiming to run until a fresh
* frame proves otherwise.
*/
function settleChatThreads() {
for (const [id, thread] of state.chatThreads) {
if (thread?.running || thread?.queued) state.chatThreads.set(id, settledThread(thread));
}
}
/**
* Fold one pushed `chat_event` frame into its conversation. Only a conversation
* this client has open is folded (a frame for a session nobody opened is
* ignored); the server only pushes frames for sessions this connection subscribed
* to, so this is a no-op in practice until a chat is opened.
*/
function onChatEvent(frame) {
const sessionId = String(frame?.session_id ?? "").trim();
if (!sessionId || !state.chatThreads.has(sessionId)) return;
const thread = state.chatThreads.get(sessionId);
state.chatThreads.set(sessionId, applyChatEvent(thread, frame, Date.now()));
renderContent();
}
/**
* The reconnect repair (C5): re-attach the open chat's stream and replace its
* conversation with the newest history page wholesale. Everything the gap could
* have missed is repaired; a turn that was in flight is settled. Only the open
* conversation is repaired — the others are not on screen.
*/
async function resyncOpenChat() {
const id = state.chatActiveId;
if (!id || state.connection.kind !== "connected") return;
await subscribeChatSession(id);
const previous = state.chatThreads.get(id) ?? newChatThread(id);
state.chatThreads.set(id, settledThread(previous));
try {
const page = await repo.chatHistory(id);
state.chatThreads.set(id, historyResync(previous, page));
} catch {
// The history refresh failed; the settled thread stands and the badge is honest.
}
renderContent();
}
/** Load (or reload) a session's newest history page and merge it in. */
async function loadChatHistory(id) {
const previous = state.chatThreads.get(id) ?? { messages: [] };
const previous = state.chatThreads.get(id) ?? newChatThread(id);
try {
const page = await repo.chatHistory(id);
// The merged page replaces only the history fields; spreading it over the
@@ -3442,12 +3741,20 @@ async function acceptChatClose(session) {
try {
const { session: updated } = await repo.closeChat(session.id);
applyChatSessionUpdate(session.id, updated, true);
// Closing finishes the session for every client: the turn is stopped and the
// conversation leaves the pane, back to the list (mirrors Android's
// `finishSession` calling `chatStore.close`). A rejection above leaves the
// conversation exactly as it was.
// A closed chat's turn was stopped on the server: settle its conversation and
// stop treating it as a live subscription. Nothing is deleted and it can be
// reopened from the list.
const thread = state.chatThreads.get(session.id);
if (thread) state.chatThreads.set(session.id, settledThread(thread));
if (state.chatSubscriptions.has(session.id)) {
state.chatSubscriptions = new Set(state.chatSubscriptions);
state.chatSubscriptions.delete(session.id);
}
// Closing also finishes the session for this client: the conversation leaves
// the pane, back to the list (mirrors Android's `finishSession` calling
// `chatStore.close`). A rejection above leaves the conversation exactly as it
// was; `settledThread` has already cleared the running/queued bits.
if (state.chatActiveId === session.id) {
setThread(session.id, { running: false, queued: false });
state.chatActiveId = null;
}
} catch (error) {
@@ -4089,6 +4396,14 @@ function renderChatConversation() {
text: sessionStatusLabel(thread?.running === true, session?.closed === true),
}),
);
// The live-stream badge (C5): live while this session is subscribed, the same
// words as the run badge (`live` / `reconnecting` / `not live`).
context.append(
renderLiveBadge({
...chatStreamState(state.connection.kind, state.chatSubscriptions.has(state.chatActiveId)),
title: "Live chat stream",
}),
);
const contextMeta = [session?.directory, session?.model]
.map((value) => String(value ?? "").trim())
.filter((value) => value !== "")
@@ -4112,10 +4427,11 @@ function renderChatConversation() {
pane.append(empty);
} else {
const rows = transcriptRows(thread?.messages ?? []);
if (rows.length === 0 && notices.length === 0) {
const running = thread?.running === true;
if (rows.length === 0 && notices.length === 0 && !running) {
pane.append(h("div", { class: "chat-transcript-empty muted", text: CONVERSATION_EMPTY }));
} else {
pane.append(renderChatTranscript(state.chatActiveId, rows, notices));
pane.append(renderChatTranscript(state.chatActiveId, rows, { notices, running, now: Date.now() }));
}
if (thread?.error && thread?.loaded) {
pane.append(h("div", { class: "chat-transcript-error", text: thread.error }));
@@ -4147,17 +4463,30 @@ function appendChatDialogs(pane) {
* in order as the reasoning block, then the tool-call chip, then the answer
* markdown. No timestamps, model or agent are shown inside the transcript.
*/
function renderChatTranscript(sessionId, rows, notices = []) {
function renderChatTranscript(sessionId, rows, { notices = [], running = false, now = Date.now() } = {}) {
const wrap = h("div", { class: "chat-transcript-wrap" });
const transcript = h("div", {
class: "chat-transcript",
id: "chatTranscript",
"data-session": sessionId,
});
for (const row of rows) {
const thread = state.chatThreads.get(sessionId) ?? null;
let lastAgent = -1;
rows.forEach((row, index) => {
if (row.kind === "agent") lastAgent = index;
});
rows.forEach((row, index) => {
if (row.kind === "user") transcript.append(renderChatUserMessage(row.message));
else transcript.append(renderChatAgentTurn(row.turn));
}
else {
const streaming = running && index === lastAgent;
const elapsed = (part) => threadToolElapsedMillis(thread, part, now);
transcript.append(renderChatAgentTurn(row.turn, streaming, elapsed));
}
});
// The running indicator sits under the transcript, after the last agent turn:
// a spinner, the phase headline, the turn's elapsed, then one line per running
// tool (a call over 60 s is tinted and marked `· long`).
if (running && thread) transcript.append(renderChatRunningIndicator(thread, now));
// The conversation's local command lines sit after the turns, full width and
// deliberately unlike a message bubble (see ChatCommandNoticeItem).
for (const notice of notices) transcript.append(renderChatCommandNotice(sessionId, notice));
@@ -4180,6 +4509,53 @@ function renderChatTranscript(sessionId, rows, notices = []) {
return wrap;
}
/**
* The in-flight turn's indicator: a spinner, the phase headline (`Thinking…` /
* `Running a tool…` / `Waiting…`), `· {elapsed}`, then one line per running tool
* with its own elapsed. A call that has passed [TOOL_LONG_RUNNING_MILLIS] is
* tinted and marked `· long` — the same threshold the tool chip uses.
*/
function renderChatRunningIndicator(thread, now) {
const wrap = h("div", { class: "chat-running", id: "chatRunning" });
const head = h("div", { class: "chat-running-head" });
head.append(h("span", { class: "spinner chat-running-spinner", "aria-hidden": "true" }));
head.append(
h("span", {
class: "chat-running-label",
text: turnPhaseLabel(threadPhase(thread, now) ?? TURN_PHASE_WAITING),
}),
);
head.append(
h("span", {
class: "chat-running-elapsed",
text: `\u00b7 ${formatDuration(Math.trunc(threadElapsedMillis(thread, now) / 1000))}`,
}),
);
wrap.append(head);
for (const part of threadRunningTools(thread.messages)) {
wrap.append(renderChatRunningTool(thread, part, now));
}
return wrap;
}
function renderChatRunningTool(thread, part, now) {
const line = h("div", { class: "chat-running-tool", "data-part-id": String(part?.id ?? "") });
const name = toolLabel(part);
const detail = toolDetail(part);
line.append(h("span", { class: "chat-running-tool-text", text: detail == null ? name : `${name} ${detail}` }));
line.append(
h("span", {
class: "chat-running-tool-elapsed muted",
text: formatToolDuration(threadToolElapsedMillis(thread, part, now)),
}),
);
if (toolLongRunning(threadToolElapsedMillis(thread, part, now))) {
line.classList.add("chat-running-tool-long");
line.append(h("span", { class: "chat-tool-long", text: "\u00b7 long" }));
}
return line;
}
/** One operator turn, right-aligned, carrying its sender label when present. */
function renderChatUserMessage(message) {
const turn = h("div", { class: "chat-turn chat-turn-user" });
@@ -4197,13 +4573,13 @@ function renderChatUserMessage(message) {
}
/** One folded agent reply, left-aligned: reasoning, tool-call chip, answer. */
function renderChatAgentTurn(turn, streaming = false) {
function renderChatAgentTurn(turn, streaming = false, elapsedMillis = () => 0) {
const wrap = h("div", { class: "chat-turn chat-turn-agent" });
const bubble = h("div", { class: "chat-bubble agent-bubble" });
const steps = turn.reasoningSteps;
if (steps.length > 0) bubble.append(renderChatReasoning(turn, streaming));
if (turn.tools.length > 0) {
const tools = renderChatToolCalls(turn, { streaming });
const tools = renderChatToolCalls(turn, { streaming, elapsedMillis });
if (tools) bubble.append(tools);
}
if (turn.answer.trim() !== "") bubble.append(renderMarkdown(turn.answer));
@@ -5497,6 +5873,13 @@ async function validateTemplate(entry) {
function selectTemplate(key) {
state.selectedTemplateKey = key;
state.templateTab = "summary";
// A different template reseeds the create dialog, so a name typed for one
// template can never be submitted against another.
state.templateCreateOpen = false;
state.templateCreateName = "";
state.templateCreateSending = false;
state.templateCreateError = "";
state.templateCreateCreated = null;
renderContent();
}
@@ -5617,6 +6000,53 @@ function stopDetailClock() {
}
}
/**
* (Re)start the chat indicator's clock: it ticks once a second only while the
* open conversation has a turn in flight, updating the phase, the elapsed and the
* per-tool `· long` marks in place (never a full re-render).
*/
function refreshChatClock() {
stopChatClock();
chatNow = Date.now();
const thread = state.chatActiveId ? state.chatThreads.get(state.chatActiveId) : null;
if (state.view === "chat" && thread?.running) {
chatClock = setInterval(() => {
chatNow = Date.now();
updateChatIndicator(chatNow);
}, 1000);
}
}
function stopChatClock() {
if (chatClock) {
clearInterval(chatClock);
chatClock = null;
}
}
/** Refresh the running indicator in place from the thread's own state at [now]. */
function updateChatIndicator(now) {
const thread = state.chatActiveId ? state.chatThreads.get(state.chatActiveId) : null;
const el = document.getElementById("chatRunning");
if (!thread?.running || !el) return;
const label = el.querySelector(".chat-running-label");
if (label) label.textContent = turnPhaseLabel(threadPhase(thread, now) ?? TURN_PHASE_WAITING);
const elapsed = el.querySelector(".chat-running-elapsed");
if (elapsed) elapsed.textContent = `\u00b7 ${formatDuration(Math.trunc(threadElapsedMillis(thread, now) / 1000))}`;
for (const part of threadRunningTools(thread.messages)) {
const line = el.querySelector(`.chat-running-tool[data-part-id="${String(part?.id ?? "")}"]`);
if (!line) continue;
const age = threadToolElapsedMillis(thread, part, now);
const toolElapsed = line.querySelector(".chat-running-tool-elapsed");
if (toolElapsed) toolElapsed.textContent = formatToolDuration(age);
const mark = line.querySelector(".chat-tool-long");
if (toolLongRunning(age) && !mark) {
line.classList.add("chat-running-tool-long");
line.append(h("span", { class: "chat-tool-long", text: "\u00b7 long" }));
}
}
}
// ---------------------------------------------------------------------------
// Boot
// ---------------------------------------------------------------------------
@@ -5633,15 +6063,34 @@ client.addEventListener("state", (event) => {
stopRunPoll();
stopListClock();
stopDetailClock();
stopChatClock();
// The socket dropped: the server detaches every chat subscription with it
// (there is no chat_unsubscribe), and the frames feeding any running turn are
// gone, so no thread keeps claiming to run until a fresh frame proves it.
clearChatSubscriptions();
settleChatThreads();
}
// A reconnect (not a first connect): re-attach the open chat's stream and
// refresh its history wholesale, so a gap that swallowed the end of a turn is
// repaired rather than shown stale.
if (next.kind === "connected" && (previousKind === "connecting" || previousKind === "disconnected")) {
resyncOpenChat();
}
render();
});
// Server pushes (a `chat_event` frame, a pushed `run_event`, …) have no matching
// request; the client fans them out as a `frame` event and the chat composer
// folds the ones it needs, so a queued prompt clears and a settled turn releases
// the Stop control.
client.addEventListener("frame", (event) => onChatFrame(event.detail));
// The client surfaces every unsolicited envelope as a DOM-free `frame` event
// (client.js). A `chat_event` frame is folded twice, on purpose: the live
// transcript (C5) folds the frame itself, and the composer's own bookkeeping
// clears the queued notice and releases the Stop control. A frame for any other
// type is ignored.
client.addEventListener("frame", (event) => {
const message = event.detail;
if (!message || message.type !== Protocol.CHAT_EVENT) return;
const frame = message[ChatKeys.EVENT];
if (frame) onChatEvent(frame);
onChatFrame(message);
});
// The stage pane, the decision sheet, the confirm/Action-failed dialogs, the
// omni-search field and the attention sheet are modal: Escape closes the topmost
@@ -5657,6 +6106,11 @@ document.addEventListener("keydown", (event) => {
return;
}
if (document.querySelector(".artifact-viewer") || document.querySelector(".change-viewer")) return;
if (state.templateCreateOpen) {
event.preventDefault();
closeTemplateCreateDialog();
return;
}
if (state.actionError) {
event.preventDefault();
dismissActionError();