web: one chat activity line, clearer groups and paste attachments

Replace the reasoning, tool and bottom thinking rows with one stable activity
line and refresh Stop on the step frame. Make directory and Closed bands share
an elevated square surface, centred text and a collapse toggle. Read pasted
files into the composer attachment path and show sent files in user bubbles.
This commit is contained in:
2026-10-20 14:30:57 +01:00
parent f5ccec8e1f
commit 3799d37d7c
11 changed files with 583 additions and 306 deletions
+263 -173
View File
@@ -81,7 +81,6 @@ import {
approvalCard,
attachmentDisplayName,
attachmentError,
attachmentFiles,
backgroundTasksRunningLabel,
chatBottomDistancePx,
chatCommandEffect,
@@ -126,6 +125,7 @@ import {
queuedAfterFrame,
readChatSeen,
reasoningLabel,
relativeSessionTime,
renameChatOverride,
restoreChatOverride,
resumedThread,
@@ -144,10 +144,8 @@ import {
shellOutputState,
shellsLoaded,
takeChatNoticeOffer as takeChatNoticeOfferModel,
formatToolDuration,
threadElapsedMillis,
threadPhase,
threadRunningTools,
threadToolElapsedMillis,
TURN_PHASE_WAITING,
toolCallCount,
@@ -764,8 +762,17 @@ function onChatEvent(frame) {
// read the newest history once so the user message (and anything else the page
// missed) appears without a manual refresh.
const knownTurn = messageId !== "" && (thread.messages ?? []).some((m) => m?.id === messageId);
state.chatThreads.set(sessionId, applyChatEvent(thread, frame, Date.now()));
const wasRunning = thread.running === true;
const wasQueued = thread.queued === true;
const next = applyChatEvent(thread, frame, Date.now());
state.chatThreads.set(sessionId, next);
if (state.view === "chat" && sessionId === state.chatActiveId) {
// The composer's Stop lives outside the transcript. A step frame changes
// running here, so update the mounted primary control now; the transcript-only
// repaint below leaves the composer in place.
if (next.running !== wasRunning || next.queued !== wasQueued) {
refreshChatComposerState(sessionId);
}
scheduleChatRender("transcript");
}
if (!knownTurn) scheduleHistorySync(sessionId, messageId);
@@ -1598,14 +1605,21 @@ async function sendChatPrompt(sessionId, session) {
// Show the operator's own turn at once, with the id OpenCode will persist.
// Waiting for the first assistant frame made the running placeholder appear
// before the message the operator just sent.
const fileParts = attachments
.filter((attachment) => attachment?.error == null)
.map((attachment) => ({
type: "file",
name: String(attachment.name ?? ""),
uri: String(attachment.uri ?? attachment.name ?? ""),
mime: String(attachment.mime ?? ""),
}));
const optimistic = {
id: messageId || `local-${operationId}`,
session_id: sessionId,
role: "user",
operation_id: operationId,
parts: [{ type: "text", text }],
parts: [{ type: "text", text }, ...fileParts],
};
releaseAttachments(attachments);
setThread(sessionId, {
draft: "",
attachments: [],
@@ -1632,7 +1646,11 @@ async function postChatPrompt(sessionId, text, attachments, { operationId, optim
setThread(sessionId, { running: true });
renderContent();
try {
const queued = await repo.chatPrompt(sessionId, body, attachmentFiles(attachments), operationId);
const payloads = await chatAttachmentPayloads(attachments);
// The optimistic message and the wire copy are built; the File objects and
// their preview URLs are no longer needed.
releaseAttachments(attachments);
const queued = await repo.chatPrompt(sessionId, body, [], operationId, payloads);
const thread = state.chatThreads.get(sessionId);
if (!thread) return;
// Prompting a closed session reopens it on the server; clear the local mark
@@ -1671,21 +1689,84 @@ function sendChatCommandOffer(sessionId, noticeId) {
postChatPrompt(sessionId, offer, []);
}
// The websocket frame that carries a prompt is bounded at 2 MiB, and base64
// expands bytes by a third. This keeps ordinary screenshots and text files
// usable without risking a frame the server refuses. The server enforces the
// same budget again.
const MAX_CHAT_ATTACHMENT_BYTES = 1 << 20;
/** Encode an ArrayBuffer as standard base64 without a huge spread call. */
function base64FromBuffer(buffer) {
const bytes = new Uint8Array(buffer);
let binary = "";
const chunk = 0x8000;
for (let offset = 0; offset < bytes.length; offset += chunk) {
binary += String.fromCharCode(...bytes.subarray(offset, offset + chunk));
}
return btoa(binary);
}
/** Read the pending files into the wire attachment shape, or explain why not. */
async function chatAttachmentPayloads(attachments) {
const valid = (attachments ?? []).filter((attachment) => attachment?.error == null);
if (valid.length === 0) return [];
let total = 0;
const payloads = [];
for (const attachment of valid) {
if (!attachment?.file || typeof attachment.file.arrayBuffer !== "function") {
throw new Error(`"${attachmentDisplayName(attachment?.name, attachment?.uri)}" could not be read.`);
}
const buffer = await attachment.file.arrayBuffer();
total += buffer.byteLength;
if (total > MAX_CHAT_ATTACHMENT_BYTES) {
throw new Error("Attachments are too large for web chat (1 MiB total).");
}
payloads.push({
name: String(attachment.name ?? "").trim() || "attachment",
mime: String(attachment.mime ?? "").trim() || "application/octet-stream",
data: base64FromBuffer(buffer),
});
}
return payloads;
}
/**
* Resolve the files the operator picked into composer attachments. Only the
* metadata is read here (nothing is transmitted until the message is sent): the
* browser has no `content://` reference, so the file's own name is carried as the
* best-effort reference string. A file over the limit is returned with its error
* set rather than dropped.
* Resolve the files the operator picked or pasted into composer attachments.
* Only the metadata is read here (nothing is transmitted until the message is
* sent); a file over the limit is returned with its error set rather than
* dropped.
*/
function pastedAttachmentName(mime, sequence) {
const subtype = String(mime ?? "").split("/").pop()?.toLowerCase() ?? "";
const extension = subtype === "jpeg" ? "jpg" : subtype.replace(/[^a-z0-9]/g, "") || "bin";
return `pasted-${sequence}.${extension}`;
}
/** Attach files pasted into the composer (an image or copied file). */
function onComposerPaste(event, sessionId, session) {
const data = event.clipboardData;
if (!data) return;
const files = [];
for (const item of data.items ?? []) {
if (item?.kind !== "file") continue;
const file = item.getAsFile?.();
if (file) files.push(file);
}
if (files.length === 0) return;
// A pasted image has no editable text; keep the composer's own text untouched
// and attach the clipboard file as the next message's attachment.
event.preventDefault();
onChatFilesPicked(sessionId, session, files);
}
function onChatFilesPicked(sessionId, session, fileList) {
const thread = state.chatThreads.get(sessionId);
if (!thread) return;
const picked = [];
for (const file of fileList ?? []) {
chatAttachmentSeq += 1;
const name = String(file?.name ?? "");
const mime = String(file?.type ?? "");
const name = String(file?.name ?? "").trim() || pastedAttachmentName(mime, chatAttachmentSeq);
const size = Number(file?.size) || 0;
picked.push({
id: `att-${chatAttachmentSeq}`,
@@ -1724,6 +1805,22 @@ function removeChatAttachment(sessionId, attachmentId) {
renderContent();
}
/** The one New chat control: a real primary action, not a quiet text link. */
function chatNewButton() {
return h(
"button",
{
class: "chat-new",
type: "button",
title: CHAT_NEW_ACTION,
"aria-label": CHAT_NEW_ACTION,
onclick: startNewChat,
},
h("span", { class: "chat-new-glyph", "aria-hidden": "true", text: "+" }),
h("span", { class: "chat-new-label", text: CHAT_NEW_ACTION }),
);
}
function renderChatList() {
// The open menu must not be clipped by the list's rounded-corner overflow; the
// class is present only while a menu is open, so the normal list stays clipped.
@@ -1746,12 +1843,7 @@ function renderChatList() {
}),
// C2: the create path stays one tap away while the list is narrowed, the same
// trailing action the app keeps beside its search control.
h("button", {
class: "ghost chat-new",
type: "button",
text: CHAT_NEW_ACTION,
onclick: startNewChat,
}),
chatNewButton(),
);
list.append(toolbar);
const rows = h("div", { id: "chatRows", class: "chat-rows list-scroll" });
@@ -1795,14 +1887,7 @@ function fillChatRows(rows) {
}
if (filtered.length === 0) {
const empty = chatEmpty(CHAT_EMPTY);
empty.append(
h("button", {
class: "ghost chat-new",
type: "button",
text: CHAT_NEW_ACTION,
onclick: startNewChat,
}),
);
empty.append(chatNewButton());
rows.append(empty);
return;
}
@@ -1818,14 +1903,40 @@ function fillChatRows(rows) {
// per-row actions name can include the session id only when it is needed.
const duplicateTitles = duplicateChatTitles(filtered);
if (starred.length > 0) {
rows.append(h("div", { class: "chat-group-header", text: "Starred" }));
rows.append(
h(
"div",
{ class: "chat-group-header chat-group-starred" },
h("span", { class: "chat-group-title", text: "Starred" }),
),
);
for (const session of starred) rows.append(renderChatRow(session, duplicateTitles));
}
const groups = groupSessionsByDirectory(active);
if (groups.length > 1) {
for (const group of groups) {
rows.append(h("div", { class: "chat-group-header", text: directoryLabel(group.directory) }));
for (const session of group.sessions) rows.append(renderChatRow(session, duplicateTitles));
const label = directoryLabel(group.directory);
const key = String(group.directory ?? "");
const collapsed = state.chatCollapsedDirs?.has?.(key) === true;
const toggle = h("button", {
class: "chat-group-header chat-group-toggle chat-group-directory",
type: "button",
title: label,
"aria-expanded": collapsed ? "false" : "true",
"aria-label": `${collapsed ? "Expand" : "Collapse"} ${label}`,
onclick: () => {
if (!state.chatCollapsedDirs) state.chatCollapsedDirs = new Set();
if (collapsed) state.chatCollapsedDirs.delete(key);
else state.chatCollapsedDirs.add(key);
renderContent();
},
});
toggle.append(h("span", { class: "chat-group-title", text: label }));
toggle.append(h("span", { class: "chevron", text: collapsed ? "\u25b8" : "\u25be" }));
rows.append(toggle);
if (!collapsed) {
for (const session of group.sessions) rows.append(renderChatRow(session, duplicateTitles));
}
}
} else {
for (const session of active) rows.append(renderChatRow(session, duplicateTitles));
@@ -1909,7 +2020,10 @@ function renderChatRow(session, duplicateTitles = new Set()) {
opened: state.chatThreads.has(session.id),
});
const activity = sessionActivity(thread?.running === true, unseen);
const badge = sessionActivityBadge(activity, open);
// `Idle` and `Open` said nothing about a chat; the row's recency does. Keep a
// badge only when the session is genuinely doing something or has news.
const badge = activity === "idle" ? "" : sessionActivityBadge(activity, open);
const updated = relativeSessionTime(session.updated_at);
// The row is a plain container (M6): the session title/meta area is the native
// button and the Chat actions control is its sibling, not a child.
const row = h("div", {
@@ -1946,9 +2060,9 @@ function renderChatRow(session, duplicateTitles = new Set()) {
head.append(h("span", { class: `chat-activity ${statusClass}`, text: statusWord }));
}
sessionButton.append(head);
const directory = String(session.directory ?? "").trim();
if (directory !== "") {
sessionButton.append(h("span", { class: "row-meta chat-row-meta", text: directory }));
const meta = [updated, String(session.directory ?? "").trim()].filter(Boolean).join(" \u00b7 ");
if (meta !== "") {
sessionButton.append(h("span", { class: "row-meta chat-row-meta", text: meta }));
}
const model = String(session.model ?? "").trim();
if (model !== "") {
@@ -2549,11 +2663,13 @@ function renderChatTranscript(
transcript.append(renderChatAgentTurn(row.turn, streaming, elapsed, thread));
}
});
// 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 && threadRunningTools(thread.messages).length === 0) {
transcript.append(renderChatRunningIndicator(thread, now));
// The live turn's one activity row lives inside the last agent turn. If the
// turn has not produced an assistant row yet (the operator just sent the
// prompt), show the same row after their message instead of a second indicator.
const lastRow = rows[rows.length - 1] ?? null;
if (running && lastRow?.kind !== "agent") {
const placeholder = { key: `pending:${sessionId}`, parts: [], reasoning: "", reasoningSteps: [], tools: [] };
transcript.append(renderChatActivity(placeholder, true, () => 0, thread));
}
// The conversation's local command lines sit after the turns, full width and
// deliberately unlike a message bubble (see ChatCommandNoticeItem).
@@ -2804,71 +2920,33 @@ function approvalControl(label, decision, sessionId, requestId, extraClass = "")
});
}
/**
* 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" });
const spinner = h("span", { class: "spinner chat-running-spinner", "aria-hidden": "true" });
// Every streamed delta re-renders the transcript, so a fresh spinner would
// restart its CSS rotation at 0deg many times a second and look frozen. Start
// it at the wall-clock phase instead, so re-renders continue the same turn.
spinner.style.animationDelay = `-${(performance.now() % 800) / 1000}s`;
head.append(spinner);
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);
return wrap;
}
function runningToolText(part) {
const name = toolLabel(part);
const detail = toolDetail(part);
return detail == null ? name : `${name} ${detail}`;
}
function renderChatRunningTool(thread, part, now) {
const line = h("div", { class: "chat-running-tool", "data-part-id": String(part?.id ?? "") });
line.append(h("span", { class: "chat-running-tool-text", text: runningToolText(part) }));
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" });
const bubble = h("div", { class: "chat-bubble user-bubble" });
const client = String(message?.client ?? "").trim();
if (client !== "") bubble.append(h("div", { class: "chat-client", text: message.client }));
const text = (message?.parts ?? [])
const parts = message?.parts ?? [];
const text = parts
.filter((part) => part?.type === "text" || !part?.type)
.map((part) => String(part?.text ?? ""))
.join("\n")
.trim();
if (text !== "") bubble.append(h("div", { class: "chat-user-text", text }));
const files = parts.filter(
(part) => part?.type === "file" && (String(part?.name ?? "").trim() !== "" || String(part?.uri ?? "").trim() !== ""),
);
if (files.length > 0) {
const strip = h("div", { class: "chat-user-files" });
for (const part of files) {
const name = attachmentDisplayName(part?.name, part?.uri);
const file = h("span", { class: "chat-user-file", title: name });
file.append(h("span", { class: "chat-user-file-glyph", "aria-hidden": "true", text: "\u{1F4CE}" }));
file.append(h("span", { class: "chat-user-file-name", text: name }));
strip.append(file);
}
bubble.append(strip);
}
turn.append(bubble);
return turn;
}
@@ -2877,34 +2955,77 @@ function renderChatUserMessage(message) {
function renderChatAgentTurn(turn, streaming = false, elapsedMillis = () => 0, thread = null) {
const wrap = h("div", { class: "chat-turn chat-turn-agent" });
const bubble = h("div", { class: "chat-bubble agent-bubble" });
const steps = turn.reasoningSteps;
// Thinking is evidence about the turn, not part of the answer bubble. Keep it
// outside and above the message, the way the tool summary sits outside and
// below it.
if (steps.length > 0) wrap.append(renderChatReasoning(turn, streaming, thread));
// One activity line carries the whole live turn: the spinner, the reasoning
// toggle, the tool-call summary and the elapsed time. The old separate
// reasoning, tool and bottom "thinking" rows made the transcript jump as each
// phase came and went.
const activity = renderChatActivity(turn, streaming, elapsedMillis, thread);
if (activity) wrap.append(activity);
if (turn.answer.trim() !== "") bubble.append(renderMarkdown(turn.answer));
if (bubble.childElementCount > 0) wrap.append(bubble);
// The tool summary is a quiet line beside the message, not a highlighted chip
// inside it; its panel still opens right there.
if (turn.tools.length > 0) {
const tools = renderChatToolCalls(turn, { streaming, elapsedMillis });
if (tools) wrap.append(tools);
}
return wrap;
}
/**
* The turn's one collapsible reasoning block. The open/closed state lives on the
* conversation keyed by the turn, so it survives a re-render; toggling it never
* rebuilds the transcript (and so never moves the operator's scroll). The label is
* the app's own (see `reasoningLabel`) with the turn's server-reported duration
* appended when it has one; a settled history turn reads `Reasoning` (or
* `Reasoning · N steps`), a live one `Thinking…`/`Thinking · N steps`. Live
* elapsed time is C5's; this renders the parts' own timing.
* One stable activity row for a turn: spinner, reasoning toggle, tool-call
* summary and the elapsed time. The reasoning body (when expanded) and the tool
* panel hang off this row, so the three old live lines never appear and vanish
* independently while a turn moves from thinking to tools and back.
*/
function renderChatReasoning(turn, streaming = false, thread = null) {
function renderChatActivity(turn, streaming = false, elapsedMillis = () => 0, thread = null) {
const steps = turn.reasoningSteps ?? [];
const parts = turn.tools ?? [];
if (!streaming && steps.length === 0 && parts.length === 0) return null;
const wrap = h("div", {
class: `chat-reasoning chat-activity${streaming ? " chat-reasoning-live" : ""}`,
});
const head = h("div", { class: "chat-activity-head" });
if (streaming) {
const spinner = h("span", {
class: "spinner chat-activity-spinner",
"aria-hidden": "true",
});
// Keep the rotation continuous across transcript repaints.
spinner.style.animationDelay = `-${(performance.now() % 800) / 1000}s`;
head.append(spinner);
}
if (steps.length > 0) {
head.append(renderChatReasoningToggle(turn, streaming, steps));
} else if (streaming) {
head.append(
h("span", {
class: "chat-activity-phase",
text: turnPhaseLabel(threadPhase(thread, Date.now()) ?? TURN_PHASE_WAITING),
}),
);
}
if (parts.length > 0) {
if (head.childElementCount > 0) head.append(h("span", { class: "chat-activity-sep", text: "\u00b7" }));
head.append(renderChatToolChip(turn, { streaming, elapsedMillis }));
}
const elapsed = streaming
? threadElapsedMillis(thread, Date.now())
: turnElapsedMillis(turn.parts);
if (elapsed != null) {
head.append(
h("span", {
class: "chat-activity-elapsed",
text: `\u00b7 ${formatDuration(Math.trunc(elapsed / 1000))}`,
}),
);
}
wrap.append(head);
if (steps.length > 0) {
const body = h("div", { class: "chat-reasoning-body", text: turn.reasoning });
body.hidden = !state.chatReasoning.has(turn.key);
wrap.append(body);
}
return wrap;
}
/** The reasoning half of the activity row: a quiet, expandable label. */
function renderChatReasoningToggle(turn, streaming, steps) {
const expanded = state.chatReasoning.has(turn.key);
const block = h("div", { class: `chat-reasoning${streaming ? " chat-reasoning-live" : ""}` });
const toggle = h("button", {
class: "chat-reasoning-toggle",
type: "button",
@@ -2918,23 +3039,17 @@ function renderChatReasoning(turn, streaming = false, thread = null) {
text: expanded ? "\u25be" : "\u25b8",
}),
);
const label = reasoningLabel(turn.reasoningSteps.length, streaming);
// A live turn has no completed timing envelope yet, so measure from the
// thread's running clock; the one-second clock refreshes this label in place.
const elapsedMillis = streaming
? threadElapsedMillis(thread, Date.now())
: turnElapsedMillis(turn.parts);
const duration = elapsedMillis == null ? null : formatDuration(Math.trunc(elapsedMillis / 1000));
toggle.append(
h("span", {
class: "chat-reasoning-label",
"data-live-steps": streaming ? String(turn.reasoningSteps.length) : null,
text: duration == null ? label : `${label} · ${duration}`,
"data-live-steps": streaming ? String(steps.length) : null,
text: reasoningLabel(steps.length, streaming),
}),
);
const body = h("div", { class: "chat-reasoning-body", text: turn.reasoning });
body.hidden = !expanded;
toggle.addEventListener("click", () => {
const block = toggle.closest(".chat-activity");
const body = block?.querySelector(".chat-reasoning-body");
if (!body) return;
const next = body.hidden;
body.hidden = !next;
toggle.setAttribute("aria-expanded", String(next));
@@ -2944,35 +3059,21 @@ function renderChatReasoning(turn, streaming = false, thread = null) {
if (next) state.chatReasoning.add(turn.key);
else state.chatReasoning.delete(turn.key);
});
block.append(toggle, body);
return block;
return toggle;
}
/**
* One turn's tool calls behind a single summary chip (C6), the browser's port of
* `ui/chat/ChatToolCalls.kt`: `N tools called`, a spinner while any call is in
* flight, a `· long` mark (error tint) once a running call has passed
* [TOOL_LONG_RUNNING_MILLIS], error styling once a call failed, and a chevron
* naming the panel it opens. The panel is a fixed overlay anchored below the chip
* (flipped above when there is no room), with a header count, a close control, an
* internally scrolling list, and per-row expand state; because it never joins the
* transcript's flow, opening or closing it cannot re-flow the conversation nor
* move its scroll position (C14).
*
* [streaming] is whether the turn is still live, and [elapsedMillis] the live age
* of a running call (the conversation supplies it from its own clock, so the
* `long` mark is derived from real time, never guessed). A settled history turn
* passes neither, so a stored `running` status cannot spin or wear the mark.
* One turn's tool calls behind a single summary chip: `N tools called`, the
* current call while one is in flight, a `· long` mark and the panel chevron.
* The line's single spinner lives in the activity row, not here.
*/
function renderChatToolCalls(turn, { streaming = false, elapsedMillis = () => 0 } = {}) {
function renderChatToolChip(turn, { streaming = false, elapsedMillis = () => 0 } = {}) {
const parts = turn.tools;
if (parts.length === 0) return null;
const count = toolCallCount(turn.parts);
const running = streaming && toolsRunning(turn.parts);
const failed = parts.some((part) => toolFailed(part.state));
const long = running && parts.some((part) => toolRunning(part) && toolLongRunning(elapsedMillis(part)));
const wrap = h("div", { class: "chat-tools" });
const chip = h("button", {
class: `chip chat-tool-chip${failed ? " chat-tool-chip-failed" : ""}`,
type: "button",
@@ -2981,21 +3082,14 @@ function renderChatToolCalls(turn, { streaming = false, elapsedMillis = () => 0
"aria-haspopup": "dialog",
});
const currentTool = running ? parts.filter((part) => toolRunning(part)).at(-1) ?? null : null;
if (running) {
chip.append(h("span", { class: "spinner chat-tool-spinner", "aria-hidden": "true" }));
} else {
chip.append(
h("span", {
class: `chat-tool-icon${failed ? " chat-tool-icon-failed" : ""}`,
"aria-hidden": "true",
text: failed ? "\u26a0" : "\u29c9",
}),
);
}
chip.append(
h("span", {
class: `chat-tool-icon${failed ? " chat-tool-icon-failed" : ""}`,
"aria-hidden": "true",
text: failed ? "\u26a0" : "\u29c9",
}),
);
chip.append(h("span", { class: "chat-tool-label", text: toolCallsLabel(count) }));
// The live call lives on the same line as the count instead of in a second
// status line below the transcript. The chip therefore updates in place while
// the count and the rest of the row remain stable.
if (currentTool) {
const detail = toolDetail(currentTool);
const name = toolLabel(currentTool);
@@ -3019,8 +3113,7 @@ function renderChatToolCalls(turn, { streaming = false, elapsedMillis = () => 0
event.stopPropagation();
openChatToolCalls(turn, parts, count);
});
wrap.append(chip);
return wrap;
return chip;
}
/** The tool list body, shared by the modal: one expandable row per call. */
@@ -3405,6 +3498,7 @@ function renderChatComposer(thread, session, sessionId) {
input.value = thread.draft ?? "";
input.addEventListener("input", (event) => onComposerInput(event, sessionId, session, controls));
input.addEventListener("keydown", (event) => onComposerKeydown(event, sessionId, session, controls));
input.addEventListener("paste", (event) => onComposerPaste(event, sessionId, session));
row.append(input);
const primary = h("span", { class: "chat-composer-primary" });
@@ -3759,24 +3853,20 @@ function stopChatClock() {
}
}
/** Refresh the running indicator in place from the thread's own state at [now]. */
/** Refresh the activity row in place from the thread's own state at [now]. */
function updateChatIndicator(now) {
const thread = state.chatActiveId ? state.chatThreads.get(state.chatActiveId) : null;
if (!thread?.running) return;
// The live reasoning label is a second continuous clock: "Thinking · N steps ·
// 1m 2s" must keep counting even when no frame arrives.
const liveReasoning = document.querySelector("#chatTranscript .chat-reasoning-live .chat-reasoning-label");
if (liveReasoning) {
const steps = Number(liveReasoning.dataset.liveSteps) || 0;
const duration = formatDuration(Math.trunc(threadElapsedMillis(thread, now) / 1000));
liveReasoning.textContent = `${reasoningLabel(steps, true)} · ${duration}`;
// The live turn is the last activity row, not the first one in a long
// transcript.
const elapsed = [...document.querySelectorAll("#chatTranscript .chat-activity-elapsed")].at(-1);
if (elapsed) {
elapsed.textContent = `\u00b7 ${formatDuration(Math.trunc(threadElapsedMillis(thread, now) / 1000))}`;
}
const phase = [...document.querySelectorAll("#chatTranscript .chat-activity-phase")].at(-1);
if (phase) {
phase.textContent = turnPhaseLabel(threadPhase(thread, now) ?? TURN_PHASE_WAITING);
}
const el = document.getElementById("chatRunning");
if (!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))}`;
}
return {
+2
View File
@@ -29,6 +29,7 @@ export function createRunsView(rt) {
const { state } = rt;
const renderContent = (...args) => rt.renderContent(...args);
const selectRun = (...args) => rt.selectRun(...args);
const renderAttentionBell = () => rt.renderAttentionBell();
function renderRunList(now = Date.now()) {
@@ -193,6 +194,7 @@ function renderRunToolbar() {
state.openMenu === "sort" ? renderSortMenu() : null,
),
h("span", { class: "spacer" }),
renderAttentionBell(),
);
return toolbar;
}