web: open reasoning in the tool-style popup
This commit is contained in:
+1
-2
@@ -299,9 +299,8 @@ const state = {
|
||||
chatActiveId: null,
|
||||
chatPlaced: null,
|
||||
chatFollowing: true,
|
||||
chatReasoning: new Set(),
|
||||
// The tool-call panel (C6): the turns whose panel is open and the individual
|
||||
// rows the operator has expanded, both keyed the same way as chatReasoning so
|
||||
// rows the operator has expanded, keyed the same way as the old inline state so
|
||||
// a re-render keeps them.
|
||||
chatToolPanels: new Set(),
|
||||
chatToolRows: new Set(),
|
||||
|
||||
+46
-22
@@ -590,7 +590,6 @@ async function openChatSession(id, { updateRoute = true } = {}) {
|
||||
state.chatMenu = null;
|
||||
state.chatPlaced = null;
|
||||
state.chatFollowing = true;
|
||||
state.chatReasoning = new Set();
|
||||
state.chatToolPanels = new Set();
|
||||
state.chatToolRows = new Set();
|
||||
// Opening reads the conversation: advance the watermark to its current recency
|
||||
@@ -3308,28 +3307,24 @@ function renderChatActivity(turn, streaming = false, elapsedMillis = () => 0, th
|
||||
);
|
||||
}
|
||||
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 toggle = h("button", {
|
||||
class: "chat-reasoning-toggle",
|
||||
type: "button",
|
||||
"aria-expanded": String(expanded),
|
||||
"aria-haspopup": "dialog",
|
||||
"aria-label": "Open reasoning",
|
||||
title: "Open reasoning",
|
||||
});
|
||||
toggle.append(
|
||||
h("span", {
|
||||
class: "chat-reasoning-icon",
|
||||
role: "img",
|
||||
"aria-label": expanded ? "Hide reasoning" : "Show reasoning",
|
||||
text: expanded ? "\u25be" : "\u25b8",
|
||||
"aria-label": "Open reasoning",
|
||||
text: "\u25b8",
|
||||
}),
|
||||
);
|
||||
toggle.append(
|
||||
@@ -3339,22 +3334,51 @@ function renderChatReasoningToggle(turn, streaming, steps) {
|
||||
text: reasoningLabel(steps.length, streaming),
|
||||
}),
|
||||
);
|
||||
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));
|
||||
const icon = toggle.querySelector(".chat-reasoning-icon");
|
||||
icon.textContent = next ? "\u25be" : "\u25b8";
|
||||
icon.setAttribute("aria-label", next ? "Hide reasoning" : "Show reasoning");
|
||||
if (next) state.chatReasoning.add(turn.key);
|
||||
else state.chatReasoning.delete(turn.key);
|
||||
toggle.addEventListener("click", (event) => {
|
||||
event.stopPropagation();
|
||||
openChatReasoning(turn, steps);
|
||||
});
|
||||
return toggle;
|
||||
}
|
||||
|
||||
/** The reasoning overlay, shaped like the tool-call popup. */
|
||||
function openChatReasoning(turn, steps) {
|
||||
const close = () => modal.close("chat-reasoning");
|
||||
const overlay = h("div", {
|
||||
class: "chat-tools-viewer chat-reasoning-viewer",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-label": "Reasoning",
|
||||
});
|
||||
overlay.addEventListener("click", (event) => {
|
||||
if (event.target === overlay) close();
|
||||
});
|
||||
const panel = h("div", { class: "chat-tools-modal-panel chat-reasoning-modal-panel" });
|
||||
panel.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "chat-tool-panel-head" },
|
||||
h("span", { class: "chat-tool-panel-count", text: reasoningLabel(steps.length, false) }),
|
||||
h("button", {
|
||||
class: "ghost chat-tool-close",
|
||||
type: "button",
|
||||
"aria-label": "Close reasoning",
|
||||
title: "Close reasoning",
|
||||
text: "\u00d7",
|
||||
onclick: close,
|
||||
}),
|
||||
),
|
||||
h("div", { class: "chat-reasoning-modal-body", text: turn.reasoning }),
|
||||
);
|
||||
overlay.append(panel);
|
||||
modal.open("chat-reasoning", overlay, {
|
||||
history: false,
|
||||
onClose: close,
|
||||
trigger: document.activeElement,
|
||||
fallbackSelectors: ["#chatTranscript", "#detailTitle", "#pane-main"],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
Reference in New Issue
Block a user