web: unify detail headers, queue follow-ups, move thinking outside bubbles
Every detail screen now owns one 44px chevron Back control beside its title. Sending appends the user's message immediately and keeps Send available beside Stop so a follow-up can be queued. Reasoning renders above the answer bubble rather than inside it.
This commit is contained in:
+57
-29
@@ -3,10 +3,10 @@
|
||||
// slash commands, notices and the local rename/hide/seen store. Pure models live
|
||||
// in chat.js and markdown.js; this module owns the DOM and the chat wire wiring.
|
||||
|
||||
import { h } from "../dom.js";
|
||||
import { backChevronIcon, h } from "../dom.js";
|
||||
import { readChatStars, writeChatStars } from "../chatStars.js";
|
||||
import { describeError } from "../format.js";
|
||||
import { SHELL_OUTPUT_LIMIT, newChatOperationId } from "../repository.js";
|
||||
import { SHELL_OUTPUT_LIMIT, nativeChatMessageId, newChatOperationId } from "../repository.js";
|
||||
import { codeBlockLabel, parseInline, parseMarkdown } from "../markdown.js";
|
||||
import { highlight } from "../highlight.js";
|
||||
import { formatDuration } from "../runs.js";
|
||||
@@ -1566,11 +1566,31 @@ async function sendChatPrompt(sessionId, session) {
|
||||
const text = String(thread.draft).trim();
|
||||
if (text === "") return;
|
||||
const attachments = thread.attachments ?? [];
|
||||
const operationId = newChatOperationId();
|
||||
const messageId = nativeChatMessageId(operationId);
|
||||
// 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 optimistic = {
|
||||
id: messageId || `local-${operationId}`,
|
||||
session_id: sessionId,
|
||||
role: "user",
|
||||
operation_id: operationId,
|
||||
parts: [{ type: "text", text }],
|
||||
};
|
||||
releaseAttachments(attachments);
|
||||
setThread(sessionId, { draft: "", attachments: [] });
|
||||
setThread(sessionId, {
|
||||
draft: "",
|
||||
attachments: [],
|
||||
running: true,
|
||||
messages: [...(thread.messages ?? []), optimistic],
|
||||
});
|
||||
saveChatDraft(sessionId, "");
|
||||
renderContent();
|
||||
await postChatPrompt(sessionId, text, attachments);
|
||||
await postChatPrompt(sessionId, text, attachments, {
|
||||
operationId,
|
||||
optimisticId: optimistic.id,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1579,13 +1599,13 @@ async function sendChatPrompt(sessionId, session) {
|
||||
* server's reason if it is rejected. The live transcript item (C5) owns the
|
||||
* optimistic bubble; this only drives the composer and its request.
|
||||
*/
|
||||
async function postChatPrompt(sessionId, text, attachments) {
|
||||
async function postChatPrompt(sessionId, text, attachments, { operationId, optimisticId } = {}) {
|
||||
const body = String(text).trim();
|
||||
if (body === "") return;
|
||||
setThread(sessionId, { running: true });
|
||||
renderContent();
|
||||
try {
|
||||
const queued = await repo.chatPrompt(sessionId, body, attachmentFiles(attachments));
|
||||
const queued = await repo.chatPrompt(sessionId, body, attachmentFiles(attachments), operationId);
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
if (!thread) return;
|
||||
// Prompting a closed session reopens it on the server; clear the local mark
|
||||
@@ -1599,12 +1619,16 @@ async function postChatPrompt(sessionId, text, attachments) {
|
||||
releaseAttachment(attachment);
|
||||
return { ...attachment, thumbUrl: null, error: message };
|
||||
});
|
||||
const current = state.chatThreads.get(sessionId);
|
||||
setThread(sessionId, {
|
||||
running: false,
|
||||
queued: false,
|
||||
error: message,
|
||||
draft: body,
|
||||
attachments: restored,
|
||||
messages: optimisticId
|
||||
? (current?.messages ?? []).filter((entry) => entry.id !== optimisticId)
|
||||
: current?.messages,
|
||||
});
|
||||
saveChatDraft(sessionId, body);
|
||||
state.actionError = message;
|
||||
@@ -1917,13 +1941,13 @@ function renderChatCreate() {
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "ghost chat-create-back",
|
||||
class: "ghost back-button chat-create-back",
|
||||
type: "button",
|
||||
"aria-label": CHAT_CREATE_BACK_LABEL,
|
||||
title: CHAT_CREATE_BACK_LABEL,
|
||||
onclick: cancelNewChat,
|
||||
},
|
||||
h("span", { class: "chat-create-back-glyph", "aria-hidden": "true", text: "←" }),
|
||||
backChevronIcon(),
|
||||
),
|
||||
// The create pane is a chat detail too: its title is the route's h1.
|
||||
h("h1", {
|
||||
@@ -2142,13 +2166,13 @@ function renderChatConversation() {
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "ghost chat-create-back chat-back",
|
||||
class: "ghost back-button chat-back",
|
||||
type: "button",
|
||||
"aria-label": "Back to chats",
|
||||
title: "Back to chats",
|
||||
onclick: () => closeDetail("chat"),
|
||||
},
|
||||
h("span", { class: "chat-create-back-glyph", "aria-hidden": "true", text: "←" }),
|
||||
backChevronIcon(),
|
||||
),
|
||||
);
|
||||
const titles = h("div", { class: "chat-bar-titles" });
|
||||
@@ -2814,9 +2838,12 @@ 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));
|
||||
// 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));
|
||||
if (turn.answer.trim() !== "") bubble.append(renderMarkdown(turn.answer));
|
||||
wrap.append(bubble);
|
||||
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) {
|
||||
@@ -3375,23 +3402,8 @@ function fillCommandPalette(palette, suggestions, selected, onPick) {
|
||||
function fillComposerPrimary(primary, thread, { onSend, onStop } = {}) {
|
||||
if (!primary) return;
|
||||
primary.replaceChildren();
|
||||
if (composerAction(thread) === COMPOSER_STOP) {
|
||||
primary.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "chat-stop",
|
||||
id: "chatStop",
|
||||
type: "button",
|
||||
"aria-label": CHAT_STOP_LABEL,
|
||||
title: CHAT_STOP_LABEL,
|
||||
onclick: onStop,
|
||||
},
|
||||
"■",
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Send is always available; while a turn runs, Stop sits beside it and a send
|
||||
// is queued behind the current turn instead of making the operator wait.
|
||||
primary.append(
|
||||
h(
|
||||
"button",
|
||||
@@ -3407,6 +3419,22 @@ function fillComposerPrimary(primary, thread, { onSend, onStop } = {}) {
|
||||
"➤",
|
||||
),
|
||||
);
|
||||
if (composerAction(thread) === COMPOSER_STOP) {
|
||||
primary.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "chat-stop",
|
||||
id: "chatStop",
|
||||
type: "button",
|
||||
"aria-label": CHAT_STOP_LABEL,
|
||||
title: CHAT_STOP_LABEL,
|
||||
onclick: onStop,
|
||||
},
|
||||
"■",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** The removable chips for the files attached to the next message. */
|
||||
|
||||
Reference in New Issue
Block a user