diff --git a/CHANGELOG.md b/CHANGELOG.md index 860deda7f..37906d139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f ### Fixed +- **Switch an existing chat back to Auto reasoning.** The composer shows the selected mode separately from this turn's effort, follows changes made in another tab, and restores the mode when you reopen the chat. Viewing an earlier branch shows the mode recorded in the displayed history without changing the live session. Sending from an earlier branch or navigating back to the live tip keeps the reasoning controls disabled while confirming the live mode; if it cannot be confirmed, the composer does not present the historical mode as current. Branch history displays without waiting for tip verification, and a failed or timed-out navigation keeps the last confirmed branch visible and reports the error. Older sessions without a recorded mode no longer appear to have selected a fixed level. - **Horizontal scrollbars no longer clip file-panel tabs.** The tab row keeps its full height in narrow panels, including on mobile. - **Refreshing Usage applies changed prices, and says when it fails.** Prices edited in `models.yml` now apply to existing sessions on refresh; they used to keep the old prices until the web server restarted. A refresh that fails now shows the error above the last report instead of leaving it up without a word. - **Show the generation-speed pill in the top bar again.** Since the header opener was split from the file-panel close control, the pill's box sized to zero width and its narrow-header rule hid it on every screen; it now keeps its width. Phone-width screens still hide it. diff --git a/app/api/sessions/[id]/route.ts b/app/api/sessions/[id]/route.ts index eebaba262..ff9ba16d1 100644 --- a/app/api/sessions/[id]/route.ts +++ b/app/api/sessions/[id]/route.ts @@ -68,6 +68,8 @@ function navigationShape(value: SessionReadValue): SessionReadValue { ...value.info, model: value.context.model, thinkingLevel: value.context.thinkingLevel, + observedThinkingLevel: value.context.observedThinkingLevel, + configuredThinkingLevel: value.context.configuredThinkingLevel, }, context: null, }; diff --git a/app/globals.css b/app/globals.css index 4d9954a33..1e4fc27c9 100644 --- a/app/globals.css +++ b/app/globals.css @@ -2258,7 +2258,6 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image .composer-thinking-control { flex: 0 1 auto; min-width: 24px !important; - max-width: 100px; } .composer-thinking-glyph { display: inline-flex; @@ -2351,7 +2350,7 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image } @container (max-width: 400px) { .composer-thinking-control > button > svg, - .composer-thinking-glyph[data-level] + .composer-thinking-label, + .composer-thinking-glyph + .composer-thinking-label, .composer-fast-control > span, .composer-slow-control > span { display: none; @@ -2402,7 +2401,7 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image max-width: 28px; } .composer-thinking-control > button > svg, - .composer-thinking-glyph[data-level] + .composer-thinking-label { + .composer-thinking-glyph + .composer-thinking-label { display: none; } .composer-thinking-control > button > .composer-thinking-glyph { diff --git a/components/ChatInput.fullscreen.test.mjs b/components/ChatInput.fullscreen.test.mjs index d065c0c3e..d6ab98287 100644 --- a/components/ChatInput.fullscreen.test.mjs +++ b/components/ChatInput.fullscreen.test.mjs @@ -24,7 +24,7 @@ async function renderComposer(t, props = {}) { const view = render(React.createElement(ChatInput, { async onSend(message) { sent.push(message); return { status: "accepted" }; }, onThinkingLevelChange() {}, - thinkingLevel: "auto", + configuredThinkingLevel: "auto", isStreaming: false, ...props, })); diff --git a/components/ChatInput.reasoning.test.mjs b/components/ChatInput.reasoning.test.mjs new file mode 100644 index 000000000..c1d11f901 --- /dev/null +++ b/components/ChatInput.reasoning.test.mjs @@ -0,0 +1,63 @@ +import assert from "node:assert/strict"; +import "../tests/setup-dom.mjs"; +import test from "node:test"; +import React from "react"; +import { cleanup, fireEvent, render } from "@testing-library/react/pure.js"; +import { ChatInput } from "./ChatInput.tsx"; + +window.matchMedia = globalThis.matchMedia; + +for (const [configuredThinkingLevel, observedThinkingLevel, label] of [ + ["auto", "low", "Auto (this turn: low)"], + ["auto", undefined, "Auto"], + ["low", "low", "Fixed: low"], + [undefined, "low", "Level: low"], + [undefined, undefined, "Thinking level"], +]) { + test(`reasoning picker: ${label}`, (t) => { + t.after(cleanup); + const changes = []; + const view = render(React.createElement(ChatInput, { + onSend() {}, isStreaming: false, configuredThinkingLevel, observedThinkingLevel, + onThinkingLevelChange: level => changes.push(level), + })); + const trigger = view.container.querySelector(".composer-thinking-control > button"); + if (!configuredThinkingLevel && !observedThinkingLevel) { + assert.ok(trigger.querySelector('.composer-thinking-glyph[aria-hidden="true"] svg'), "compact picker needs a neutral glyph"); + } + assert.equal(trigger.textContent, label); + assert.ok(trigger.getAttribute("aria-label").endsWith(label)); + fireEvent.click(trigger); + assert.deepEqual(view.queryAllByRole("menuitemradio", { checked: true }).map(row => row.textContent), + configuredThinkingLevel ? [configuredThinkingLevel === "auto" ? "Auto" : configuredThinkingLevel] : []); + fireEvent.click(view.getByRole("menuitemradio", { name: "low" })); + assert.deepEqual(changes, configuredThinkingLevel === "low" ? [] : ["low"]); + }); +} + +for (const locked of ["thinkingLevelDisabled", "isStreaming"]) { + test(`reasoning picker cannot submit while ${locked}`, (t) => { + t.after(cleanup); + const view = render(React.createElement(ChatInput, { onSend() {}, onThinkingLevelChange() {}, [locked]: true })); + assert.equal(view.container.querySelector(".composer-thinking-control > button").disabled, true); + }); +} + +for (const [mode, observed, useDraftThinkingDefault, label, selected] of [ + ["medium", "low", false, "Fixed: medium", "medium → low"], + ["auto", "low", false, "Auto (this turn: low)", "Auto"], + [undefined, "low", false, "Level: low", undefined], + ["auto", undefined, true, "Use omp default", "Use omp default"], +]) { + test(`model mapping and draft semantics: ${label}`, (t) => { + t.after(cleanup); + const view = render(React.createElement(ChatInput, { + onSend() {}, onThinkingLevelChange() {}, configuredThinkingLevel: mode, observedThinkingLevel: observed, + useDraftThinkingDefault, thinkingLevelMap: { medium: "low", low: "minimal" }, + })); + const trigger = view.container.querySelector(".composer-thinking-control > button"); + assert.equal(trigger.textContent, label); + fireEvent.click(trigger); + assert.deepEqual(view.queryAllByRole("menuitemradio", { checked: true }).map(row => row.textContent), selected ? [selected] : []); + }); +} diff --git a/components/ChatInput.test.mjs b/components/ChatInput.test.mjs index f5847700c..d18b84fa0 100644 --- a/components/ChatInput.test.mjs +++ b/components/ChatInput.test.mjs @@ -12,13 +12,13 @@ test("provider-defined reasoning levels appear once in the trigger", () => { const html = renderToStaticMarkup(React.createElement(ChatInput, { async onSend() { return { status: "accepted" }; }, onThinkingLevelChange() {}, - thinkingLevel, + configuredThinkingLevel: thinkingLevel, isStreaming: false, })); const dom = new JSDOM(html); try { const trigger = dom.window.document.querySelector(".composer-thinking-control > button"); - assert.equal(trigger.textContent, thinkingLevel); + assert.equal(trigger.textContent, `Fixed: ${thinkingLevel}`); assert.ok(trigger.getAttribute("aria-label").endsWith(`: ${thinkingLevel}`)); } finally { dom.window.close(); diff --git a/components/ChatInput.tsx b/components/ChatInput.tsx index 719af6332..53c7ebfb4 100644 --- a/components/ChatInput.tsx +++ b/components/ChatInput.tsx @@ -2,7 +2,7 @@ import React, { useRef, useState, useCallback, useEffect, useLayoutEffect, useImperativeHandle, forwardRef, memo, KeyboardEvent } from "react"; import { createPortal } from "react-dom"; -import { ChevronDown, ClipboardPaste, CornerDownRight, ListChecks, Loader2, Maximize2, Mic, Paperclip, Plus, RotateCw, Shrink, Snail, Sparkles, Terminal, Wrench, X, Zap } from "lucide-react"; +import { Brain, ChevronDown, ClipboardPaste, CornerDownRight, ListChecks, Loader2, Maximize2, Mic, Paperclip, Plus, RotateCw, Shrink, Snail, Sparkles, Terminal, Wrench, X, Zap } from "lucide-react"; import { getSubmitDuringRunBehavior, isWordCompletionEnabled } from "@/lib/composer-prefs"; import type { BuiltinSlashCommandResult, CompactResultInfo, PromptSendOptions, PromptSubmissionResult, QueuedMessages, SlashCommandInfo } from "@/hooks/useAgentSession"; import type { ActiveGoal, ActivePlan } from "@/lib/web-mode-state"; @@ -215,7 +215,10 @@ interface Props { onAbortCompaction?: () => void; isCompacting?: boolean; compactResult?: CompactResultInfo | null; - thinkingLevel?: string; + configuredThinkingLevel?: string; + observedThinkingLevel?: string; + thinkingLevelDisabled?: boolean; + useDraftThinkingDefault?: boolean; onThinkingLevelChange?: (level: string) => void; availableThinkingLevels?: string[] | null; thinkingLevelMap?: Record | null; @@ -373,7 +376,7 @@ function menuDropStyle(placement: MenuPlacement, maxHeight: number | null): Reac export const ChatInput = memo(forwardRef(function ChatInput({ onSend, onPredictWord, onPredictWordFeedback, onAbort, onSteer, onFollowUp, isStreaming, model, isAutoModelSelection, modelNames, modelList, modelError, modelsLoading, onModelChange, fastModeEnabled, fastModeActive, usageLimit, fastModeSupported, onFastModeChange, slowModeSupported, slowModeEnabled, slowModeScope, onSlowModeChange, onAbortCompaction, isCompacting, compactResult, - thinkingLevel, onThinkingLevelChange, availableThinkingLevels, thinkingLevelMap, modelNameOverride, + configuredThinkingLevel, observedThinkingLevel, thinkingLevelDisabled, useDraftThinkingDefault, onThinkingLevelChange, availableThinkingLevels, thinkingLevelMap, modelNameOverride, toolPreset, onToolPresetChange, sessionToolPreset, isNewSession, retryInfo, queuedMessages, inputHistory = [], onAbortRetry, slashCommands, slashCommandsLoading, onLoadSlashCommands, @@ -2301,21 +2304,26 @@ export const ChatInput = memo(forwardRef(function ChatIn const activeToolCount = getToolPresetToolCount(activeToolPreset); const toolsetBadgeLabel = `tools: ${activeToolPreset}${activeToolCount === null ? "" : ` (${activeToolCount})`}`; const restrictedToolPreset = toolPresetKnown && activeToolPreset !== "full" ? activeToolPreset : null; + const thinkingDisabled = isStreaming || !!thinkingLevelDisabled; + const autoOptionLabel = useDraftThinkingDefault ? t("chatInput.thinkingAuto") : t("chatInput.reasoningAuto"); const thinkingDisplayLabel = (() => { - const lvl = thinkingLevel ?? "auto"; - if (lvl === "auto" || !thinkingLevelMap) return lvl; - return thinkingLevelMap[lvl] ?? lvl; + if (configuredThinkingLevel === "auto") { + return observedThinkingLevel && observedThinkingLevel !== "auto" + ? t("chatInput.reasoningAutoTurn", { level: observedThinkingLevel }) + : autoOptionLabel; + } + if (configuredThinkingLevel) return t("chatInput.reasoningFixed", { level: configuredThinkingLevel }); + if (observedThinkingLevel) return t("chatInput.reasoningLevel", { level: observedThinkingLevel }); + return t("chatInput.reasoningUnknown"); })(); const thinkingLevelOptions = React.useMemo( () => selectableThinkingLevels(availableThinkingLevels), [availableThinkingLevels], ); - // A run starting mid-interaction must not leave the reasoning menu - // open: the level only applies to the next prompt, and the trigger is - // disabled while streaming. + // A run or a pending change can lock an already open picker. useEffect(() => { - if (isStreaming) setThinkingDropdownOpen(false); - }, [isStreaming]); + if (thinkingDisabled) setThinkingDropdownOpen(false); + }, [thinkingDisabled]); useEffect(() => { if (!modelDropdownOpen) { @@ -3681,7 +3689,7 @@ export const ChatInput = memo(forwardRef(function ChatIn
@@ -3734,9 +3744,9 @@ export const ChatInput = memo(forwardRef(function ChatIn
{thinkingLevelOptions.map((lvl) => { - const isActive = (thinkingLevel ?? "auto") === lvl; - const mappedVal = (lvl !== "auto" && thinkingLevelMap) ? thinkingLevelMap[lvl] : undefined; - const displayLabel = (mappedVal != null && mappedVal !== lvl) ? mappedVal : lvl; + const isActive = configuredThinkingLevel === lvl; + const mapped = thinkingLevelMap && Object.hasOwn(thinkingLevelMap, lvl) ? thinkingLevelMap[lvl] : undefined; + const displayLabel = lvl === "auto" ? autoOptionLabel : mapped && mapped !== lvl ? `${lvl} → ${mapped}` : lvl; return (