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:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user