web: chat composer review fixes — real Stop, /close leaves the pane

Address the review of C8/C9: the composer's Stop control now routes to
`chat_interrupt` (`onStop`) instead of the inert submit path, and the smoke
clicks it and asserts the page's own "Stopping the running turn…" notice with
no `Action failed` dialog (captures/63b). Accepting `/close` finishes the
session locally — the running/queued bits clear and the conversation leaves
the pane for the list, mirroring Android's `finishSession` — and the smoke
asserts the select hint returns. A command notice draws the one terminal
glyph (`CHAT_COMMAND_GLYPH`, `>_`) for both states, tinted only; the growing
textarea accounts for its padding and border so six rows are six whole lines;
remove a shadowed duplicate `chatSessionById`. Wording unchanged; every pure
helper and the wire shapes remain unit-tested.

The smoke creates a throwaway session via `/new`, really prompts, really
interrupts and closes it; the operator's session is never prompted.
This commit is contained in:
2026-10-19 07:26:25 +01:00
parent f660078173
commit d9f5ba6f75
6 changed files with 110 additions and 31 deletions
+43 -23
View File
@@ -198,12 +198,18 @@ import {
retryRequestKey,
} from "./actions.js";
import {
CHAT_ATTACH_LABEL,
CHAT_COMMAND_GLYPH,
CHAT_COMPOSER_PLACEHOLDER,
CHAT_EMPTY,
CHAT_FOLLOW_THRESHOLD_PX,
CHAT_LOADING,
CHAT_NEW_ACTION,
CHAT_NO_MATCH_ACTION,
CHAT_QUEUED_NOTICE,
CHAT_SEARCH_LABEL,
CHAT_SEND_LABEL,
CHAT_STOP_LABEL,
CHAT_TAB_TITLE,
CLOSED_CHIP_LABEL,
CLOSED_SECTION_LABEL,
@@ -263,13 +269,6 @@ import {
transcriptRows,
turnElapsedMillis,
} from "./chat.js";
import {
CHAT_ATTACH_LABEL,
CHAT_COMPOSER_PLACEHOLDER,
CHAT_QUEUED_NOTICE,
CHAT_SEND_LABEL,
CHAT_STOP_LABEL,
} from "./chat.js";
import { codeBlockLabel, parseInline, parseMarkdown } from "./markdown.js";
const STORAGE_KEY = "pipelines.web.serverUrl.v2";
@@ -3443,6 +3442,14 @@ 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.
if (state.chatActiveId === session.id) {
setThread(session.id, { running: false, queued: false });
state.chatActiveId = null;
}
} catch (error) {
state.actionError = describeError(error);
}
@@ -3481,11 +3488,6 @@ function applyChatSessionUpdate(id, updated, closed) {
let chatAttachmentSeq = 0;
let chatNoticeSeq = 0;
/** The session row for an id, or null when the server never listed it. */
function chatSessionById(id) {
return state.chatSessions.find((session) => session.id === id) ?? null;
}
/** Revoke an attachment's image object URL, if it created one. */
function releaseAttachment(attachment) {
if (attachment?.thumbUrl) {
@@ -3589,16 +3591,24 @@ function onComposerKeydown(event, sessionId, session, controls) {
}
}
/** Grow the composer's textarea between one and six rows to fit its content. */
/**
* Grow the composer's textarea between one and six rows to fit its content. The
* element is `box-sizing: border-box` with vertical padding, so the cap and the
* measured height both include the padding and the border: a six-row field is
* six full text lines, not five-and-a-bit, and the first row is not clipped.
*/
function growComposerTextarea(el) {
if (!el) return;
const line = parseFloat(getComputedStyle(el).lineHeight) || 20;
const style = getComputedStyle(el);
const line = parseFloat(style.lineHeight) || 20;
const border = el.offsetHeight - el.clientHeight;
const padding = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
const maxRows = 6;
const max = line * maxRows + border;
const max = line * maxRows + padding + border;
el.style.height = "auto";
el.style.height = `${Math.min(el.scrollHeight, max)}px`;
el.style.overflowY = el.scrollHeight > max ? "auto" : "hidden";
const wanted = el.scrollHeight + border;
el.style.height = `${Math.min(wanted, max)}px`;
el.style.overflowY = wanted > max ? "auto" : "hidden";
}
/**
@@ -3615,7 +3625,10 @@ function refreshComposerControls(sessionId, session, controls) {
const command = suggestions[index];
if (command) runChatCommand(sessionId, session, `/${command.name}`);
});
fillComposerPrimary(controls.primary, thread, () => submitChatComposer(sessionId, session, controls));
fillComposerPrimary(controls.primary, thread, {
onSend: () => submitChatComposer(sessionId, session, controls),
onStop: () => stopChatTurn(sessionId),
});
}
/** Run the composer's submit (Enter): a command runs, else the draft sends. */
@@ -4571,7 +4584,9 @@ function renderChatCommandNotice(sessionId, notice) {
h("span", {
class: "chat-command-notice-glyph",
"aria-hidden": "true",
text: failed ? "⌨" : "▸",
// The app draws `Icons.Default.Terminal` for both states and only changes
// the tint, so both notices share the one terminal glyph.
text: CHAT_COMMAND_GLYPH,
}),
);
head.append(
@@ -4682,7 +4697,10 @@ function renderChatComposer(thread, session, sessionId) {
const command = suggestions[index];
if (command) runChatCommand(sessionId, session, `/${command.name}`);
});
fillComposerPrimary(primary, thread, () => submitChatComposer(sessionId, session, controls));
fillComposerPrimary(primary, thread, {
onSend: () => submitChatComposer(sessionId, session, controls),
onStop: () => stopChatTurn(sessionId),
});
if (typeof requestAnimationFrame === "function") {
requestAnimationFrame(() => growComposerTextarea(input));
@@ -4720,8 +4738,10 @@ function fillCommandPalette(palette, suggestions, selected, onPick) {
/**
* The composer's single primary control: Stop while a turn is in flight (error
* tint), else Send, disabled unless the draft is sendable (or a slash draft).
* Stop routes to [onStop] (`chat_interrupt`), never to the submit path — the
* control must interrupt the running turn, as Android's `onStop` does.
*/
function fillComposerPrimary(primary, thread, onActivate) {
function fillComposerPrimary(primary, thread, { onSend, onStop } = {}) {
if (!primary) return;
primary.replaceChildren();
if (composerAction(thread) === COMPOSER_STOP) {
@@ -4734,7 +4754,7 @@ function fillComposerPrimary(primary, thread, onActivate) {
type: "button",
"aria-label": CHAT_STOP_LABEL,
title: CHAT_STOP_LABEL,
onclick: onActivate,
onclick: onStop,
},
"■",
),
@@ -4751,7 +4771,7 @@ function fillComposerPrimary(primary, thread, onActivate) {
"aria-label": CHAT_SEND_LABEL,
title: CHAT_SEND_LABEL,
disabled: !composerSendEnabled(thread),
onclick: onActivate,
onclick: onSend,
},
"➤",
),
+7
View File
@@ -820,6 +820,13 @@ export const CHAT_ATTACH_LABEL = "Attach file";
/** The composer's queued notice, shown while a prompt waits behind a turn. */
export const CHAT_QUEUED_NOTICE = "Queued — it will send when the current turn finishes.";
/**
* The terminal glyph on a command notice. The app draws `Icons.Default.Terminal`
* for both a successful and a failed notice and only changes the tint, so the
* browser uses this one glyph for both.
*/
export const CHAT_COMMAND_GLYPH = ">_";
/** The two values of [composerAction]. */
export const COMPOSER_SEND = "send";
export const COMPOSER_STOP = "stop";