web: add chat model picker, agent badges and a preloaded brief
Show the current model under the chat title with an OpenCode-backed picker, put an agent mark on the right of every chat row, simplify the tool summary to 'N tools', and give the reasoning and tool controls one symmetric hover box. New chats preload an editable behavior brief, and the activity spinner remains the turn's single live progress indicator.
This commit is contained in:
@@ -172,6 +172,9 @@ to it, but the server never lists it and a reload drops it.
|
||||
| B18 | Chat attachments in the message and paste | `chat_prompt.attachments` | done — composer files are read into base64 and sent with the prompt (1 MiB total, under the 2 MiB websocket frame), the server writes them to private temporary files and passes `file://` references to OpenCode's prompt `files`, and both the live user turn and reloaded history render a named file chip inside the message. Pasting an image/file into the textarea attaches it with the same picker path; a pasted image without a filename gets a generated name. The optimistic user bubble shows the file immediately, and OpenCode history maps the top-level user `files` envelope (never its base64 data) into the same part. |
|
||||
| B19 | One live chat activity line and immediate Stop | — | done — every in-flight turn now has one square activity row carrying the spinner, `Thinking`/`Reasoning · N steps`, the tool-call chip with its current call, and the elapsed time; the separate reasoning, tool and bottom "thinking" lines are gone. The row stays in place when the turn settles (spinner off), and the elapsed ticks locally each second. The composer's Stop is refreshed on the step frame itself, so it appears for turns started by another client and stays through tool calls. A subscribe that joins a live turn replays a `step started` marker. Cancel now marks the run and its live step canceled immediately before interrupting the runner, so a context-unaware stage cannot leave a "running" row after Stop. |
|
||||
| B20 | Cancel a running run immediately | `cancel_run` | done — `runner.cancel` persists `canceled` on the run and its live step before calling the runner's cancel function; late stage returns cannot overwrite it (`FinishRun` only updates queued/running, and a failed step persistence is reported as canceled, not a failure). This also covers orphaned running rows with no active goroutine and waiting runs. Verified by store tests and the run that had been stuck at run 13 is now interrupted/canceled rather than running. |
|
||||
| B21 | Change a chat's model | `chat_models`, `chat_model` | done — the open conversation shows its current model under the title. Clicking it lists the OpenCode endpoint's enabled, non-deprecated models with provider/name, scrolls the current selection into view, and switches through `POST /api/session/{id}/model`; the row and header update immediately and the next turn uses it. The list is read-only until a model is chosen, and a failed switch leaves the dialog open with the server's reason. Verified live: 48 models listed and an ephemeral session switched to `opencode-go/beam-free`. |
|
||||
| B22 | Agent badge on chat rows | — | done — every chat row shows the harness mark at its right edge (OpenCode terminal, Codex hex, Claude starburst, Pi), with the harness name as tooltip/aria-label. OpenCode is the default for legacy rows; Codex rows carry their backend from the adapter. The model switcher is hidden for harnesses that do not support it. |
|
||||
| B23 | Preload a new chat's behavior | `chat_create.instructions` | done — the New chat pane now has an editable **How should it act?** brief, prefilled with a project-agnostic care/verification brief. `chat_create` carries it as `instructions`; OpenCode stores it as the durable `pipelines.behavior` session instruction entry before the first turn, so the agent starts with the brief. Other harnesses and older OpenCode builds still create the chat if the instruction surface is unavailable. Verified live with an ephemeral create: the instruction entry was present immediately after creation. |
|
||||
| B13 | Codex chat backend | `chat_backends`, `chat_create.backend` | done — OpenCode stays the default. `chat_backends` lists `codex` when the Codex App Server control socket is present; New chat shows a harness choice, the selected backend is stored on the operator-session row and echoed on every session. The Codex adapter connects to the existing App Server over its Unix WebSocket, maps `thread/start`, `turn/start`, `thread/read`, item/tool events, `item/tool/requestUserInput` to the existing question card, and carries the native user-message id so optimistic and history turns reconcile. Verified live: created a Codex chat from the browser, sent a prompt, saw the streamed answer, read it back through `chat_messages`, and saw the Codex chip and title in the list. Claude is not advertised yet: its OAuth session is expired and the SDK/CLI sidecar is still to be built. |
|
||||
| B12 | One detail header, optimistic sends, thinking above the bubble | — | done — every non-chat detail (pipeline, run, template) now extracts its own `#detailTitle` into a shared `.detail-head` with the same 44px chevron Back control; on phones the button and title are vertically centred, and on wide screens the back control is hidden while the title stays in the header. Chat/create already use the same control. Sending now appends the operator's optimistic user turn immediately (using the native message id OpenCode persists), so the running placeholder cannot appear before their message. While a turn runs, Send stays present beside Stop; a follow-up is queued. The reasoning/thinking block moved outside and above the answer bubble, like the tool summary below it. |
|
||||
| B11 | Enter composes; live shell bars stay in place | — | done — Enter now inserts a newline (a real CDP Enter produced `first\n` and no prompt), while Ctrl/Cmd+Enter sends; a slash draft still runs its command on Enter. The chat star reserves a 26px corner in the row head, so it no longer covers Streaming/New/Idle. Background-shell frames patch the tasks bar in place instead of full-rendering the pane, keeping the composer mounted. The shell cache was bumped to v2 so an installed PWA picks up these client changes. |
|
||||
|
||||
+128
-36
@@ -63,6 +63,22 @@
|
||||
}
|
||||
.chat-create-directories-error { color: var(--bad); }
|
||||
.chat-create-error { color: var(--bad); font-size: 13px; }
|
||||
.chat-create-instructions { display: grid; gap: 6px; }
|
||||
.chat-create-instructions-label { font-size: 13px; font-weight: 600; }
|
||||
.chat-create-instructions-input {
|
||||
width: 100%;
|
||||
min-height: 96px;
|
||||
padding: 10px 12px;
|
||||
resize: vertical;
|
||||
background: var(--color-surface-2);
|
||||
color: var(--color-text);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-control);
|
||||
font: inherit;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.chat-create-instructions-helper { margin: 0; font-size: 12px; line-height: 1.5; max-width: 64ch; }
|
||||
.chat-create-model-note { margin: 0; font-size: 12px; line-height: 1.5; max-width: 64ch; }
|
||||
.chat-create-footer {
|
||||
display: flex;
|
||||
@@ -340,10 +356,78 @@
|
||||
.chat-create { overflow-y: auto; overscroll-behavior: contain; }
|
||||
.chat-bar { flex: 0 0 auto; display: flex; gap: var(--space-s); align-items: center; justify-content: space-between; }
|
||||
.chat-bar-titles { display: grid; gap: 2px; min-width: 0; }
|
||||
.chat-bar-title { margin: 0; font-size: 16px; }
|
||||
.chat-bar-title {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.chat-bar-meta { font-size: 12px; }
|
||||
.chat-context { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
|
||||
.chat-load-older { white-space: nowrap; font-size: 12px; }
|
||||
.chat-model-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
flex: none;
|
||||
max-width: 150px;
|
||||
min-width: 0;
|
||||
padding: 4px 8px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-control);
|
||||
background: var(--surface-2);
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
.chat-model-button:hover { background: var(--color-elevated); color: var(--text); }
|
||||
.chat-model-button-label {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.chat-model-button .chevron { flex: none; font-size: 10px; }
|
||||
/* Model picker: a bounded list of the current harness's models. */
|
||||
.chat-model-panel { width: min(480px, 100%); max-height: calc(100dvh - 48px); }
|
||||
.chat-model-helper { margin: 0; font-size: 12px; }
|
||||
.chat-model-loading { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
|
||||
.chat-model-error { margin: 0; color: var(--bad); font-size: 12px; }
|
||||
.chat-model-empty { margin: 0; font-size: 13px; }
|
||||
.chat-model-list {
|
||||
display: grid;
|
||||
gap: 2px;
|
||||
max-height: min(50vh, 420px);
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-card);
|
||||
padding: 4px;
|
||||
}
|
||||
.chat-model-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
min-height: 38px;
|
||||
padding: 7px 9px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius-control);
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
}
|
||||
.chat-model-option:hover { background: var(--tint-hover); color: var(--text); }
|
||||
.chat-model-option.selected { border-color: var(--accent); background: var(--tint-selected); color: var(--text); }
|
||||
.chat-model-option-name {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.chat-model-option-provider { flex: none; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
|
||||
.chat-model-check { flex: none; color: var(--accent); }
|
||||
.chat-transcript-empty { padding: 24px 12px; }
|
||||
|
||||
.chat-transcript-wrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
|
||||
@@ -400,16 +484,6 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
.chat-turn-agent { flex-direction: column; align-items: flex-start; }
|
||||
/* The tool summary is a quiet line next to the message, not a chip inside it. */
|
||||
.chat-tools { margin: 2px 0 10px; }
|
||||
.chat-tool-chip {
|
||||
padding: 2px 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
.chat-tool-chip:hover { color: var(--color-text); }
|
||||
|
||||
.chat-reasoning { margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px dashed var(--border); }
|
||||
/* Thinking sits outside and above the answer bubble, like the tool summary
|
||||
@@ -437,18 +511,6 @@
|
||||
.chat-activity-elapsed { flex: none; }
|
||||
.chat-activity-sep { color: var(--muted); flex: none; }
|
||||
.chat-activity-head > .chat-tool-chip { min-width: 0; overflow: hidden; }
|
||||
.chat-reasoning-toggle {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
flex: none;
|
||||
padding: 2px 0;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
.chat-reasoning-toggle:hover { color: var(--text); }
|
||||
.chat-reasoning-body {
|
||||
margin: 6px 0 2px;
|
||||
white-space: pre-wrap;
|
||||
@@ -461,24 +523,44 @@
|
||||
|
||||
/* The tool-call chip and its panel (C6). The panel is a fixed overlay, so it
|
||||
never joins the transcript's flow and opening it cannot re-flow or scroll it. */
|
||||
/* Thinking and tools are sibling controls on the same line, so they share one
|
||||
hover/focus box: identical padding, radius, height and background. */
|
||||
.chat-reasoning-toggle,
|
||||
.chat-tool-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 2px 0;
|
||||
border: 0;
|
||||
flex: none;
|
||||
min-height: 24px;
|
||||
max-width: 100%;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
padding: 2px 7px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius-control);
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
line-height: 16px;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
.chat-tool-chip:hover { color: var(--color-text); }
|
||||
.chat-reasoning-toggle:hover,
|
||||
.chat-tool-chip:hover {
|
||||
background: var(--tint-hover);
|
||||
color: var(--color-text);
|
||||
}
|
||||
.chat-reasoning-toggle:focus-visible,
|
||||
.chat-tool-chip:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
.chat-tool-chip-failed { border-color: var(--bad); color: var(--bad); }
|
||||
.chat-tool-icon { font-size: 12px; line-height: 1; }
|
||||
.chat-tool-icon-failed { color: var(--bad); }
|
||||
.chat-tool-long { color: var(--bad); }
|
||||
.chat-tool-chevron { color: var(--muted); }
|
||||
.chat-tool-spinner { width: 11px; height: 11px; border-width: 2px; }
|
||||
|
||||
/* C5: the in-flight turn's indicator, under the transcript after the last agent
|
||||
turn — a spinner, the phase headline, the turn's elapsed and one line per
|
||||
@@ -1027,6 +1109,8 @@
|
||||
.chat-group-directory .chat-group-title { font-size: 12px; }
|
||||
.chat-row { min-height: 96px; }
|
||||
.chat-row .row-head { padding-right: 50px; }
|
||||
.chat-backend-logo { width: 22px; height: 22px; }
|
||||
.chat-backend-logo svg { width: 20px; height: 20px; }
|
||||
.chat-star {
|
||||
top: 2px;
|
||||
right: 2px;
|
||||
@@ -1044,6 +1128,7 @@
|
||||
.chat-row-actions .chat-menu-item { padding: 8px 12px; font-size: 14px; }
|
||||
.back-button .back-chevron { width: 24px; height: 24px; }
|
||||
.chat-bar-title { font-size: 18px; }
|
||||
.chat-model-button { max-width: 118px; min-height: 36px; }
|
||||
.chat-activity { font-size: 12px; }
|
||||
.chat-send,
|
||||
.chat-stop { min-width: 44px; min-height: 44px; font-size: 18px; }
|
||||
@@ -1056,6 +1141,21 @@
|
||||
.chat-create-backends { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.chat-create-backend { padding: 6px 12px; border: 1px solid var(--border); color: var(--muted); }
|
||||
.chat-create-backend.selected { border-color: var(--accent); background: var(--tint-selected); color: var(--text); }
|
||||
.chat-backend-logo {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: none;
|
||||
margin-left: auto;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.chat-backend-logo svg { width: 18px; height: 18px; display: block; }
|
||||
.chat-backend-logo.chat-backend-opencode { color: var(--accent); }
|
||||
.chat-backend-logo.chat-backend-codex { color: #9ecb8f; }
|
||||
.chat-backend-logo.chat-backend-claude { color: #d8b46a; }
|
||||
.chat-backend-logo.chat-backend-pi { color: #c58fb0; }
|
||||
.chat-backend-chip {
|
||||
flex: 0 0 auto;
|
||||
padding: 1px 6px;
|
||||
@@ -1070,14 +1170,6 @@
|
||||
|
||||
/* The current tool call shares the count line. It is the one live element on
|
||||
that row, so tool handoffs do not add or remove a second status line. */
|
||||
.chat-tool-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
max-width: 100%;
|
||||
min-width: 0;
|
||||
text-align: left;
|
||||
}
|
||||
.chat-tool-current {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -188,6 +188,12 @@ const state = {
|
||||
// Whether the CLOSED chats group is expanded (the chevron beside its name).
|
||||
chatClosedOpen: false,
|
||||
chatCollapsedDirs: new Set(),
|
||||
chatModelPicker: null,
|
||||
chatModels: [],
|
||||
chatModelsFor: "",
|
||||
chatModelsLoading: false,
|
||||
chatModelsError: "",
|
||||
chatModelBusy: false,
|
||||
// The last time each destination's data arrived (manual refresh or a socket
|
||||
// push); the list's Refresh button shows it on hover.
|
||||
lastUpdated: {},
|
||||
|
||||
+7
-3
@@ -135,6 +135,9 @@ export const CHAT_CREATE_PROMPT = "Where should this chat live?";
|
||||
export const CHAT_CREATE_MODEL_NOTE =
|
||||
"This server has no request for choosing a chat's model, so a new chat uses the server's default.";
|
||||
export const CHAT_CREATE_CONFIRM = "New chat";
|
||||
/** The behavior brief preloaded into a new web chat's session instructions. */
|
||||
export const DEFAULT_CHAT_INSTRUCTIONS =
|
||||
"Act as a careful coding agent. Read the repository's AGENTS.md and the relevant skills before acting. Inspect the current state, keep changes scoped to the request, run the relevant checks, and report exactly what changed and what was not verified. Ask only about real ambiguity, destructive actions or changes outside the request.";
|
||||
export const CHAT_CREATE_CANCEL = "Cancel";
|
||||
|
||||
/** The create footer's line: `Start in {directory}` with the value that is sent. */
|
||||
@@ -195,11 +198,11 @@ export function toolLabel(part) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A turn's one summary chip: `N tools called`, and `1 tool called` for a single
|
||||
* call — a count of one is never pluralised.
|
||||
* A turn's one summary chip: `N tools`, and `1 tool` for a single call — a
|
||||
* count of one is never pluralised.
|
||||
*/
|
||||
export function toolCallsLabel(count) {
|
||||
return count === 1 ? "1 tool called" : `${count} tools called`;
|
||||
return count === 1 ? "1 tool" : `${count} tools`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -986,6 +989,7 @@ export function newChatCreateState(operationId) {
|
||||
return {
|
||||
directory: HOME_DIRECTORY,
|
||||
backend: "opencode",
|
||||
instructions: DEFAULT_CHAT_INSTRUCTIONS,
|
||||
operationId: str(operationId),
|
||||
creating: false,
|
||||
error: "",
|
||||
|
||||
+246
-7
@@ -24,6 +24,7 @@ import {
|
||||
CHAT_CREATE_CONFIRM,
|
||||
CHAT_CREATE_LOADING,
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
DEFAULT_CHAT_INSTRUCTIONS,
|
||||
CHAT_CREATE_PROMPT,
|
||||
CHAT_CREATE_TITLE,
|
||||
CHAT_EMPTY,
|
||||
@@ -563,6 +564,7 @@ async function createNewChat() {
|
||||
// same path for its one real session and closes it afterwards).
|
||||
const created = await repo.chatCreate("New chat", create.directory, create.operationId, {
|
||||
backend: create.backend,
|
||||
instructions: create.instructions,
|
||||
});
|
||||
state.chatCreate = null;
|
||||
state.chatSessions = chatCreateSucceeded(state.chatSessions, created);
|
||||
@@ -1531,7 +1533,10 @@ async function startChatSession(directory) {
|
||||
// creating one for verification never adds a stray "New chat" to the
|
||||
// operator's list. Set only by test tooling; a normal page leaves it unset.
|
||||
const ephemeral = globalThis.__pipelinesEphemeralChat === true;
|
||||
const created = await repo.chatCreate("New chat", directory, undefined, { ephemeral });
|
||||
const created = await repo.chatCreate("New chat", directory, undefined, {
|
||||
ephemeral,
|
||||
instructions: DEFAULT_CHAT_INSTRUCTIONS,
|
||||
});
|
||||
if (ephemeral) {
|
||||
state.chatEphemeralIds = new Set(state.chatEphemeralIds).add(created.id);
|
||||
writeEphemeralChatIds(state.chatEphemeralIds);
|
||||
@@ -2061,11 +2066,7 @@ function renderChatRow(session, duplicateTitles = new Set(), home = "") {
|
||||
});
|
||||
const head = h("span", { class: "row-head" });
|
||||
head.append(h("span", { class: "row-title chat-row-title", text: sessionTitle(session) }));
|
||||
if (session.backend && session.backend !== "opencode") {
|
||||
head.append(
|
||||
h("span", { class: "chat-backend-chip", text: chatBackendLabel(session.backend) }),
|
||||
);
|
||||
}
|
||||
head.append(chatBackendLogo(session.backend));
|
||||
// Only the status word, coloured, with no dot and no operator chip. A closed
|
||||
// session says so here instead of carrying a second chip.
|
||||
const statusWord = session.closed ? "Closed" : badge;
|
||||
@@ -2094,10 +2095,52 @@ function renderChatRow(session, duplicateTitles = new Set(), home = "") {
|
||||
* order, the model note and the footer naming the value that will be sent. Every
|
||||
* server string is set with textContent.
|
||||
*/
|
||||
/** One agent's mark on the right of its chat row. */
|
||||
function chatBackendLogo(backend) {
|
||||
const value = String(backend ?? "").trim().toLowerCase() || "opencode";
|
||||
const label = chatBackendLabel(value);
|
||||
const wrap = h("span", {
|
||||
class: `chat-backend-logo chat-backend-${value}`,
|
||||
title: label,
|
||||
"aria-label": label,
|
||||
});
|
||||
const NS = "http://www.w3.org/2000/svg";
|
||||
const svg = document.createElementNS(NS, "svg");
|
||||
svg.setAttribute("viewBox", "0 0 24 24");
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
svg.setAttribute("focusable", "false");
|
||||
const add = (tag, attrs) => {
|
||||
const node = document.createElementNS(NS, tag);
|
||||
for (const [key, attr] of Object.entries(attrs)) node.setAttribute(key, attr);
|
||||
svg.append(node);
|
||||
return node;
|
||||
};
|
||||
const stroke = { fill: "none", stroke: "currentColor", "stroke-width": "1.8", "stroke-linecap": "round", "stroke-linejoin": "round" };
|
||||
if (value === "opencode") {
|
||||
add("rect", { x: "3.5", y: "4.5", width: "17", height: "15", rx: "3", ...stroke });
|
||||
add("path", { d: "M7.5 9.5 10.5 12l-3 2.5", ...stroke });
|
||||
add("path", { d: "M13 15h3.5", ...stroke });
|
||||
} else if (value === "codex") {
|
||||
add("path", { d: "M12 3.2 19.5 7.4v9.2L12 20.8l-7.5-4.2V7.4z", ...stroke });
|
||||
add("path", { d: "m8.5 12 2.3 2.3 4.7-4.7", ...stroke });
|
||||
} else if (value === "claude") {
|
||||
add("path", { d: "M12 3v18M4.2 7.5l15.6 9M4.2 16.5l15.6-9", ...stroke });
|
||||
add("circle", { cx: "12", cy: "12", r: "2.2", ...stroke });
|
||||
} else if (value === "pi") {
|
||||
add("path", { d: "M5.5 7.5h13M8.5 7.5v9M15.5 7.5v9", ...stroke });
|
||||
} else {
|
||||
add("circle", { cx: "12", cy: "12", r: "7", ...stroke });
|
||||
add("circle", { cx: "12", cy: "12", r: "2", fill: "currentColor" });
|
||||
}
|
||||
wrap.append(svg);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function chatBackendLabel(backend) {
|
||||
switch (backend) {
|
||||
case "codex": return "Codex";
|
||||
case "claude": return "Claude";
|
||||
case "pi": return "Pi";
|
||||
case "opencode": return "OpenCode";
|
||||
default: return String(backend ?? "");
|
||||
}
|
||||
@@ -2164,6 +2207,37 @@ function renderChatCreate() {
|
||||
pane.append(harness);
|
||||
}
|
||||
|
||||
const instructions = h("div", { class: "chat-create-instructions" });
|
||||
instructions.append(
|
||||
h("label", {
|
||||
class: "chat-create-instructions-label",
|
||||
for: "chatCreateInstructions",
|
||||
text: "How should it act?",
|
||||
}),
|
||||
);
|
||||
const instructionField = h(
|
||||
"textarea",
|
||||
{
|
||||
id: "chatCreateInstructions",
|
||||
class: "chat-create-instructions-input",
|
||||
rows: "4",
|
||||
spellcheck: "false",
|
||||
oninput: (event) => {
|
||||
if (!state.chatCreate) return;
|
||||
state.chatCreate = { ...state.chatCreate, instructions: event.target.value };
|
||||
},
|
||||
},
|
||||
create.instructions ?? DEFAULT_CHAT_INSTRUCTIONS,
|
||||
);
|
||||
instructions.append(instructionField);
|
||||
instructions.append(
|
||||
h("p", {
|
||||
class: "chat-create-instructions-helper muted",
|
||||
text: "Preloaded as this chat's session instructions. The agent still reads the repository's AGENTS.md and skills.",
|
||||
}),
|
||||
);
|
||||
pane.append(instructions);
|
||||
|
||||
const choices = directoryChoices(state.chatDirectories);
|
||||
const selected =
|
||||
choices.find((choice) => choice.createDirectory === create.directory) ??
|
||||
@@ -2385,6 +2459,12 @@ function renderChatConversation() {
|
||||
// so a pending request is reached the same way new content is.
|
||||
if (awaiting) bar.append(approvalJumpButton());
|
||||
pane.append(bar);
|
||||
const modelButton = effective ? renderChatModelButton(effective) : null;
|
||||
if (modelButton) {
|
||||
const context = h("div", { class: "chat-context" });
|
||||
context.append(modelButton);
|
||||
pane.append(context);
|
||||
}
|
||||
|
||||
// The background-tasks bar (C11) sits above the transcript, outside the
|
||||
// scroller so the C14 scroll positions are untouched. It is present only while
|
||||
@@ -2440,6 +2520,7 @@ function renderChatConversation() {
|
||||
function appendChatDialogs(pane) {
|
||||
if (state.chatClose) pane.append(renderChatCloseDialog(state.chatClose));
|
||||
if (state.chatRename) pane.append(renderChatRenameDialog(state.chatRename));
|
||||
if (state.chatModelPicker) pane.append(renderChatModelDialog(state.chatModelPicker));
|
||||
if (state.chatSnackbar) pane.append(renderChatSnackbar());
|
||||
if (state.actionError) pane.append(renderActionFailedDialog());
|
||||
}
|
||||
@@ -2463,6 +2544,164 @@ function renderChatSnackbar() {
|
||||
return bar;
|
||||
}
|
||||
|
||||
/** The chat header's model control: current model, opens the switcher. */
|
||||
function renderChatModelButton(session) {
|
||||
const backend = String(session?.backend ?? "").trim();
|
||||
if (backend !== "" && backend !== "opencode") return null;
|
||||
const label = String(session?.model ?? "").trim() || "Model";
|
||||
return h(
|
||||
"button",
|
||||
{
|
||||
class: "ghost chat-model-button",
|
||||
type: "button",
|
||||
title: `Change model (currently ${label})`,
|
||||
"aria-label": `Change model, currently ${label}`,
|
||||
"aria-haspopup": "dialog",
|
||||
onclick: () => openChatModelPicker(session),
|
||||
},
|
||||
h("span", { class: "chat-model-button-label", text: label }),
|
||||
h("span", { class: "chevron", text: "\u25be" }),
|
||||
);
|
||||
}
|
||||
|
||||
/** Open the model picker and load the harness's list on first use. */
|
||||
function openChatModelPicker(session) {
|
||||
state.chatModelPicker = session;
|
||||
state.chatModelsError = "";
|
||||
state.chatModelsFor = "";
|
||||
state.chatModels = [];
|
||||
state.chatModelsLoading = true;
|
||||
renderContent();
|
||||
loadChatModels(session.id);
|
||||
}
|
||||
|
||||
function closeChatModelPicker() {
|
||||
state.chatModelPicker = null;
|
||||
state.chatModelsError = "";
|
||||
state.chatModelsLoading = false;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
async function loadChatModels(sessionId) {
|
||||
const backend = state.chatSessions.find((row) => row.id === sessionId)?.backend ?? "opencode";
|
||||
if (backend !== "" && backend !== "opencode") {
|
||||
state.chatModelsLoading = false;
|
||||
state.chatModelsError = `${chatBackendLabel(backend)} does not support changing models from this client.`;
|
||||
if (state.chatModelPicker?.id === sessionId) renderContent();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const models = await repo.chatModels(sessionId);
|
||||
if (state.chatModelPicker?.id !== sessionId) return;
|
||||
state.chatModels = Array.isArray(models) ? models : [];
|
||||
state.chatModelsFor = sessionId;
|
||||
state.chatModelsError = "";
|
||||
} catch (error) {
|
||||
if (state.chatModelPicker?.id !== sessionId) return;
|
||||
state.chatModelsError = describeError(error);
|
||||
}
|
||||
state.chatModelsLoading = false;
|
||||
if (state.chatModelPicker?.id === sessionId) renderContent();
|
||||
}
|
||||
|
||||
/** Apply one selected model and close the picker. */
|
||||
async function selectChatModel(session, model) {
|
||||
if (state.chatModelBusy) return;
|
||||
state.chatModelBusy = true;
|
||||
state.chatModelsError = "";
|
||||
renderContent();
|
||||
try {
|
||||
await repo.switchChatModel(session.id, model.provider, model.id);
|
||||
applyChatSessionModel(session.id, model.provider, model.id);
|
||||
state.chatModelPicker = null;
|
||||
} catch (error) {
|
||||
state.chatModelsError = describeError(error);
|
||||
}
|
||||
state.chatModelBusy = false;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** Apply a successful model switch to the list row and the open thread. */
|
||||
function applyChatSessionModel(sessionId, provider, model) {
|
||||
state.chatSessions = (state.chatSessions ?? []).map((row) =>
|
||||
row.id === sessionId ? { ...row, model, model_provider: provider } : row,
|
||||
);
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
if (thread) setThread(sessionId, { model, modelProvider: provider });
|
||||
}
|
||||
|
||||
/** The model dialog: current model highlighted; providers and names grouped. */
|
||||
function renderChatModelDialog(session) {
|
||||
const overlay = h("div", {
|
||||
class: "confirm-dialog confirm-chat-model",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": "Change model",
|
||||
"data-modal-stable": "true",
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) closeChatModelPicker();
|
||||
});
|
||||
const panel = h("div", { class: "confirm-panel chat-model-panel" });
|
||||
panel.append(h("h2", { class: "confirm-title", text: "Change model" }));
|
||||
panel.append(
|
||||
h("p", {
|
||||
class: "chat-model-helper muted",
|
||||
text: "Applies to the next turn in this chat.",
|
||||
}),
|
||||
);
|
||||
if (state.chatModelsLoading) {
|
||||
const loading = h("div", { class: "chat-model-loading muted" });
|
||||
loading.append(h("span", { class: "spinner", "aria-hidden": "true" }), h("span", { text: "Loading models\u2026" }));
|
||||
panel.append(loading);
|
||||
} else if (state.chatModelsError) {
|
||||
panel.append(h("p", { class: "chat-model-error", text: state.chatModelsError }));
|
||||
} else if ((state.chatModels ?? []).length === 0) {
|
||||
panel.append(h("p", { class: "chat-model-empty muted", text: "No models are available for this chat." }));
|
||||
} else {
|
||||
const list = h("div", { class: "chat-model-list", role: "listbox", "aria-label": "Available models" });
|
||||
const currentProvider = String(session.model_provider ?? "");
|
||||
const currentModel = String(session.model ?? "");
|
||||
for (const model of state.chatModels) {
|
||||
const selected =
|
||||
model.id === currentModel && (currentProvider === "" || model.provider === currentProvider);
|
||||
const option = h("button", {
|
||||
class: `ghost chat-model-option${selected ? " selected" : ""}`,
|
||||
type: "button",
|
||||
role: "option",
|
||||
"aria-selected": selected ? "true" : "false",
|
||||
disabled: state.chatModelBusy,
|
||||
onclick: () => selectChatModel(session, model),
|
||||
});
|
||||
option.append(h("span", { class: "chat-model-option-name", text: model.name || model.id }));
|
||||
option.append(h("span", { class: "chat-model-option-provider muted", text: model.provider }));
|
||||
if (selected) option.append(h("span", { class: "chat-model-check", text: "\u2713" }));
|
||||
list.append(option);
|
||||
}
|
||||
panel.append(list);
|
||||
if (typeof requestAnimationFrame === "function") {
|
||||
requestAnimationFrame(() => {
|
||||
const selected = list.querySelector(".chat-model-option.selected");
|
||||
if (!selected) return;
|
||||
const top = selected.offsetTop - list.clientHeight / 2 + selected.offsetHeight / 2;
|
||||
list.scrollTop = Math.max(0, top);
|
||||
});
|
||||
}
|
||||
}
|
||||
const actions = h("div", { class: "confirm-actions" });
|
||||
actions.append(
|
||||
h("button", {
|
||||
class: "ghost confirm-dismiss",
|
||||
type: "button",
|
||||
text: "Cancel",
|
||||
onclick: closeChatModelPicker,
|
||||
}),
|
||||
);
|
||||
panel.append(actions);
|
||||
overlay.append(panel);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Rename chat dialog (C13): a locally-kept name, with the helper that says so
|
||||
* plainly. Save is disabled while the trimmed value is blank; typing toggles that
|
||||
@@ -3079,7 +3318,7 @@ function renderChatReasoningToggle(turn, streaming, steps) {
|
||||
}
|
||||
|
||||
/**
|
||||
* One turn's tool calls behind a single summary chip: `N tools called`, the
|
||||
* One turn's tool calls behind a single summary chip: `N tools`, 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.
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
CHAT_CREATE_BACK_LABEL,
|
||||
CHAT_CREATE_CANCEL,
|
||||
CHAT_CREATE_CONFIRM,
|
||||
DEFAULT_CHAT_INSTRUCTIONS,
|
||||
CHAT_CREATE_LOADING,
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
CHAT_CREATE_PROMPT,
|
||||
@@ -245,8 +246,8 @@ test("partRendering classifies text, reasoning, other text and empty parts", ()
|
||||
});
|
||||
|
||||
test("toolCallsLabel never pluralises a count of one", () => {
|
||||
assert.equal(toolCallsLabel(1), "1 tool called");
|
||||
assert.equal(toolCallsLabel(4), "4 tools called");
|
||||
assert.equal(toolCallsLabel(1), "1 tool");
|
||||
assert.equal(toolCallsLabel(4), "4 tools");
|
||||
});
|
||||
|
||||
test("reasoningLabel is Thinking/Reasoning with the step count and streaming word", () => {
|
||||
@@ -1773,6 +1774,7 @@ test("newChatCreateState starts on home, not sending, with the caller's operatio
|
||||
assert.deepEqual(newChatCreateState("web-chat-op"), {
|
||||
directory: HOME_DIRECTORY,
|
||||
backend: "opencode",
|
||||
instructions: DEFAULT_CHAT_INSTRUCTIONS,
|
||||
operationId: "web-chat-op",
|
||||
creating: false,
|
||||
error: "",
|
||||
@@ -1785,6 +1787,7 @@ test("selectChatDirectory sends the chosen value and clears a previous refusal",
|
||||
assert.deepEqual(selectChatDirectory(state, recent), {
|
||||
directory: "/repo/a",
|
||||
backend: "opencode",
|
||||
instructions: DEFAULT_CHAT_INSTRUCTIONS,
|
||||
operationId: "op",
|
||||
creating: false,
|
||||
error: "",
|
||||
@@ -1798,6 +1801,7 @@ test("chatCreateFailed keeps the pane open with the server's message; success st
|
||||
assert.deepEqual(chatCreateFailed(creating, "the directory is not available"), {
|
||||
directory: "~",
|
||||
backend: "opencode",
|
||||
instructions: DEFAULT_CHAT_INSTRUCTIONS,
|
||||
operationId: "op",
|
||||
creating: false,
|
||||
error: "the directory is not available",
|
||||
|
||||
@@ -5177,7 +5177,7 @@ try {
|
||||
if (!chipInfo) throw new Error("C6: no tool-call chip rendered in the live transcript");
|
||||
const parsedCount = Number(/(\d+)/.exec(chipInfo.text)?.[1] ?? NaN);
|
||||
const toolCount = Number.isFinite(parsedCount) ? parsedCount : chipInfo.rows;
|
||||
const toolLabel = toolCount === 1 ? "1 tool called" : `${toolCount} tools called`;
|
||||
const toolLabel = toolCount === 1 ? "1 tool" : `${toolCount} tools`;
|
||||
const toolAria =
|
||||
toolCount === 1 ? "1 tool call, expand for details" : `${toolCount} tool calls, expand for details`;
|
||||
if (!chipInfo.text.includes(toolLabel)) {
|
||||
|
||||
Reference in New Issue
Block a user