A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 思考等级没切过去时,原因留在输入卡上方,不再只活六秒
lmlihenge5d5882364f4
diff --git a/changelog/unreleased/2026-11-07-thinking-level-refusal.md b/changelog/unreleased/2026-11-07-thinking-level-refusal.mdnew file mode 100644index 00000000..70de0744--- /dev/null+++ b/changelog/unreleased/2026-11-07-thinking-level-refusal.md@@ -0,0 +1,73 @@+# A thinking level that did not take says why above the input card, not in a six-second toast++- **Date:** 2026-11-07+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-11-07-thinking-level-refusal.zh.md)++The thinking level has two pickers: the one on the new-conversation page writes into the Agent's+settings (it also becomes the Agent's new default and the level the first message's Session is+created on), the one inside a conversation pins that Session (it applies from the next LLM request).+Both write on the pick, and both display **the level they read back**, not the one that was clicked —+so a refused write changes nothing on screen: the picker still reads the old level and the button+itself is the retry. The reason went to a notification that dismissed itself after six seconds, and+the screen then read exactly as it had before the press, as though the click had not registered.++That sentence now renders above the input card (the same place, and for the same reason, as the+microphone's notice: it explains a control inside the card), with `role="alert"`, the danger colour,+two lines, and the whole sentence on hover — this one is longer than the other refusals, because a+failed switch also has to say which level did not move, so two lines leave only its beginning and the+rest has to be readable on hover. It stays until the next attempt starts.++## The two pickers are saying two different things++The draft's picker writes through to the Agent's settings, so when it is refused the Agent's default+did not move either — while the click itself read as "this draft's setting" at the moment it was+made. The draft's sentence therefore says so ("the Agent's default is unchanged too"); the Session's+picker only pins this one conversation, so its sentence leaves the Agent out. Both share one entry,+split by a `forAgent` argument.++Which object the sentence belongs to is tracked the same way: the draft page keys it by Agent (a+different Agent no longer draws it), the Session page by Session (switching away and back does not+hang another conversation's failure on this one).++## Details++- `packages/web/src/features/chat/thinking-level-refusal.ts` (new): `thinkingLevelRefused(error,+ forAgent)` — the reason goes through `refusalText` (7.19's rule: an answer the server gave is read+ through its code's own localized sentence, a value this codebase raised itself is shown as it+ wrote it), and `S.chat.thinkingLevelRefused(reason, forAgent)` completes the line.+- `packages/web/src/features/chat/chat-input.tsx`: a new `thinkingRefusal` prop, drawn in the block+ that holds the microphone's notice, above the input card.+- `packages/web/src/features/chat/draft-view.tsx`: the failure branch of `onChangeThinkingLevel` no+ longer goes to a notification but writes `thinkingRefusal` (Agent id + sentence), cleared when the+ next attempt starts; the optimistic write and its rollback are unchanged.+- `packages/web/src/features/chat/chat-page.tsx`: `applyTurnThinkingLevel`'s failure branch is+ collected the same way (Session id + sentence) and handed to the composer only while that Session+ is the one on screen.+- `packages/web/src/lib/strings{,-en}.ts`: one new sentence,+ `chat.thinkingLevelRefused(reason, forAgent)`.++## Tests++- `packages/web/test/thinking-level-refusal.test.ts` (new, 5 cases): a server answer is read through+ its code's own sentence rather than the English wire message; a request that never reached the+ route keeps what it knows; nothing said falls back to the generic text; the draft's sentence names+ the Agent and the Session's does not; both follow the active language.+- `packages/web/e2e/thinking-level-refusal.spec.mjs` (new, real server + real browser, 2 cases): each+ write is stubbed to a 500 (a code the interface has its own copy for, plus an English wire+ message). A refused draft pick puts the sentence above the card, verbatim with "the Agent's default+ is unchanged too", uses the interface's words, leaves the notification region out of it, keeps the+ picker reading the old level and the Agent config on the old level — and **seven seconds later**+ (past the six an error notification lives) it is still there; once the write is allowed, a second+ pick clears it, the picker reads the new level and the config really moved. The second case: a+ refused Session pick draws the same sentence without the Agent, still visible after seven seconds,+ with the picker rolled back; a retry that lands clears it and the Session reads back the pin.++## Compatibility++No interface change, no new dependency, no Project config change. The success path, the mid-chat+"switching costs the cached context" confirmation (#310) and both optimistic writes' rollbacks are+untouched.diff --git a/changelog/unreleased/2026-11-07-thinking-level-refusal.zh.md b/changelog/unreleased/2026-11-07-thinking-level-refusal.zh.mdnew file mode 100644index 00000000..d1d1cd76--- /dev/null+++ b/changelog/unreleased/2026-11-07-thinking-level-refusal.zh.md@@ -0,0 +1,57 @@+# 思考等级没切过去时,原因留在输入卡上方,不再只活六秒++- **日期:** 2026-11-07+- **类型:** fix+- **范围:** `web`+- **破坏性:** 否++[English](2026-11-07-thinking-level-refusal.md)++思考等级有两个选择器:新对话页的那个写进 Agent 设置(它同时成为这个 Agent 的新默认档,也是第一条消息+建出来的会话所用的档),会话里那个钉在这一场会话上(从下一次 LLM 请求起生效)。两个都是选中即写,而且+显示的是**写完之后读回来的那一档**,不是点下去的那一档 —— 所以一次被拒的写入在屏幕上什么也没变:选择器+还读着原来的档,按钮本身就是重试。原因却只落进一条通知,六秒后自己消失,此后屏幕读起来与按下之前一模+一样,像是那一下没被接住。++那句话现在画在输入卡上方(与麦克风的提示同一处、同一个理由:它解释的是卡里的一个控件),`role="alert"`、+危险色、限两行、整句挂悬停 —— 这一句比别的拒绝长,切换失败时还要点明是哪一档没改动,限两行之后只剩开头,+所以整句必须能悬停读到。它一直留到下一次尝试开始。++## 两个选择器说的是两件事++新对话页的那个写穿到 Agent 设置,被拒时 Agent 的默认档也没改 —— 而在此之前,那次点击看上去只是「这一+份草稿的档位」。所以草稿页的句子把这件事说出来(「同时是 Agent 的默认档,没有改动」),会话里的那个只钉+这一场会话,句子就不提 Agent。两句共用一条文案,多一个 `forAgent` 参数区分。++窗口归属也按各自的对象记:草稿页按 Agent(换了 Agent 就不再画那一句),会话页按 Session(切走再切回来+时不会把一个不相干的会话的失败挂在当前这一场上)。++## 明细++- `packages/web/src/features/chat/thinking-level-refusal.ts`(新):`thinkingLevelRefused(error,+ forAgent)` —— 原因走 `refusalText`(7.19 的规则:服务端答复的按它错误码自己的本地化句子念,本仓自己+ 抛的值按原样念),整句由 `S.chat.thinkingLevelRefused(reason, forAgent)` 补成。+- `packages/web/src/features/chat/chat-input.tsx`:新增 `thinkingRefusal` 属性,句子画在麦克风提示所在+ 的那一段(输入卡上方)。+- `packages/web/src/features/chat/draft-view.tsx`:`onChangeThinkingLevel` 的失败分支不再走通知,写到+ `thinkingRefusal`(Agent id + 句子),开始下一次尝试时清掉;乐观写入与回滚不变。+- `packages/web/src/features/chat/chat-page.tsx`:`applyTurnThinkingLevel` 的失败分支同样收进+ `thinkingRefusal`(Session id + 句子),传给输入卡时只给当前那一场。+- `packages/web/src/lib/strings{,-en}.ts`:一条新文案 `chat.thinkingLevelRefused(reason, forAgent)`。++## 测试++- `packages/web/test/thinking-level-refusal.test.ts`(新,5 条):服务端答复按错误码自己的句子念、不念+ 线上英文原文;请求根本没到路由时保留它知道的那句;什么都没答时回落到通用文案;草稿页那句点明 Agent、+ 会话那句不提;跟随当前语言。+- `packages/web/e2e/thinking-level-refusal.spec.mjs`(新,真服务端 + 真浏览器,2 条):两处写入各自桩成+ 500(一个界面自己有文案的错误码 + 一句英文原文)—— 草稿页被拒时句子出现在输入卡上方、逐字带「同时是+ Agent 的默认档,没有改动」、念的是界面自己的话、通知区里没有它、选择器仍读着原来的档、Agent 配置也仍+ 是原档,**七秒后**(超过错误通知活着的 6 秒)仍在;放行后重选一次,句子消失、选择器读到新档、配置真的+ 变了。第二条:会话页被拒时同一句话(不提 Agent),七秒后仍在,选择器回落到原档;重试成功后句子消失、+ 会话读回那个钉住的档。++## 兼容性++不碰接口、不引入新依赖、不改 Project 配置。成功路径、会话中途的「切换会丢缓存」确认框(#310)与两处+乐观写入的回滚都没动。diff --git a/packages/web/e2e/thinking-level-refusal.spec.mjs b/packages/web/e2e/thinking-level-refusal.spec.mjsnew file mode 100644index 00000000..07ed01d1--- /dev/null+++ b/packages/web/e2e/thinking-level-refusal.spec.mjs@@ -0,0 +1,169 @@+/**+ * Regression: a thinking level the write refused keeps the reason above the input card instead of+ * in a notification that dismisses itself after six seconds.+ *+ * Both pickers write the picked level straight through and then display the level they read back,+ * so a refused write changes nothing on screen: the trigger still reads the level it read before+ * and is the retry. That left a press that looked as though it had never registered, with the+ * reason vanishing six seconds later. The sentence is drawn above the card now (`role="alert"`,+ * danger colour, two lines, the whole sentence on hover) and stays until the next attempt starts.+ *+ * The draft's picker writes through to the Agent settings, so its sentence says the Agent's default+ * is unchanged too; the Session's picker only pins this conversation and must not mention the+ * Agent. Both writes are stubbed with a 500 carrying a code the interface has its own copy for plus+ * an English wire message — that is how the test tells the localized sentence from the raw one.+ */+import { test, expect } from "@playwright/test";+import { provisionAndLogin } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;++/** The refusal: a code the interface translates, plus a message that must not reach the page. */+const REFUSAL = { code: "internal", message: "RAW ENGLISH SERVER MESSAGE" };+/** The line the page draws for that code (S.errors.byCode), after what failed. */+const REASON = "服务器内部错误,请稍后重试。";++const notifications = (page) => page.getByRole("region", { name: "通知" });+const thinkingBtn = (page) => page.getByRole("button", { name: "思考等级" });+const refusalLine = (page) => page.getByRole("alert").filter({ hasText: "没能切换思考等级" });++/**+ * Provision a user and give the Project a model (without one the onboarding overlay covers the+ * pages). No model is ever called: both writes measured here are stubbed.+ */+async function provision(page, userId) {+ await provisionAndLogin(page.request, userId, "password123");+ const projects = await (await page.request.get(`${BASE}/api/projects`)).json();+ const projectId = projects.projects[0].projectId;+ const models = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(models.ok(), "put models").toBeTruthy();+ return projectId;+}++/** Pick a level from the picker's menu (the trigger carries the plain name, the row the wire value). */+async function pick(page, row) {+ await thinkingBtn(page).click();+ await page.getByRole("button", { name: row, exact: true }).click();+}++/** What one refusal looks like on the page, at the moment it lands and past the six seconds. */+async function expectRefusalKept(page, text) {+ const line = refusalLine(page);+ await expect(line).toBeVisible();+ await expect(line).toHaveText(text);+ // The interface's own words for that code, never the server's English message — and the reason+ // is the card's, not a notification's.+ await expect(line).not.toContainText("RAW ENGLISH");+ await expect(notifications(page)).not.toContainText("RAW ENGLISH");++ // Past the six seconds an error notification lived: the sentence is still above the card.+ await page.waitForTimeout(7000);+ await expect(line).toBeVisible();+ await expect(line).toHaveText(text);+}++test("a refused draft pick keeps the reason above the card and leaves it reading the old level", async ({+ page,+}) => {+ const projectId = await provision(page, "thinkingrefusal1");+ await page.goto(`${BASE}/chat/new`);+ await expect(thinkingBtn(page)).toContainText("中");++ const writes = [];+ let refuse = true;+ await page.route("**/api/projects/*/agents/*/config", async (route) => {+ if (route.request().method() !== "PUT") return route.fallback();+ writes.push(route.request().postDataJSON());+ if (!refuse) return route.fallback();+ return route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });++ await pick(page, "高 (high)");++ // The draft's picker writes through to the Agent settings, so the sentence says so.+ await expectRefusalKept(page, `没能切换思考等级(同时是 Agent 的默认档,没有改动):${REASON}`);+ // The write changed nothing: the trigger still reads the level it read before, and is the retry.+ await expect(thinkingBtn(page)).toContainText("中");+ const cfg = await (+ await page.request.get(`${BASE}/api/projects/${projectId}/agents/default_agent/config`)+ ).json();+ expect(cfg.config.model?.thinkingLevel ?? null).not.toBe("high");++ // The retry is the same picker: the sentence of the attempt before it goes, and this one lands.+ refuse = false;+ await pick(page, "高 (high)");+ await expect(thinkingBtn(page)).toContainText("高");+ await expect(page.getByRole("alert")).toHaveCount(0);+ await expect+ .poll(async () => {+ const again = await (+ await page.request.get(`${BASE}/api/projects/${projectId}/agents/default_agent/config`)+ ).json();+ return again.config.model?.thinkingLevel;+ })+ .toBe("high");+ expect(writes).toHaveLength(2);+});++test("a refused session pick keeps the reason and does not claim the Agent default changed", async ({+ page,+}) => {+ const projectId = await provision(page, "thinkingrefusal2");+ const created = await page.request.post(+ `${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,+ { data: { provider: "custom", modelId: "claude-4-8", approvalMode: "always-ask" } },+ );+ expect(created.ok(), `create session: ${await created.text()}`).toBeTruthy();+ const sessionId = (await created.json()).session.sessionId;++ await page.goto(`${BASE}/chat/${sessionId}`);+ await expect(thinkingBtn(page)).toContainText("中");++ let refuse = true;+ await page.route(`**/api/sessions/${sessionId}`, async (route) => {+ if (route.request().method() !== "PATCH") return route.fallback();+ if (!refuse) return route.fallback();+ return route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });++ await pick(page, "高 (high)");++ // Pinning a conversation says nothing about the Agent's default — the sentence must not mention it.+ const text = `没能切换思考等级:${REASON}`;+ await expectRefusalKept(page, text);+ await expect(refusalLine(page)).not.toContainText("Agent");+ await expect(thinkingBtn(page)).toContainText("中");++ // The retry from the same picker lands: the sentence goes and the Session carries the pin.+ refuse = false;+ await pick(page, "高 (high)");+ await expect(page.getByRole("alert")).toHaveCount(0);+ await expect+ .poll(async () => {+ const row = await (await page.request.get(`${BASE}/api/sessions/${sessionId}`)).json();+ return row.session.thinkingLevel;+ })+ .toBe("high");+});diff --git a/packages/web/src/features/chat/chat-input.tsx b/packages/web/src/features/chat/chat-input.tsxindex 35cb5641..30c639df 100644--- a/packages/web/src/features/chat/chat-input.tsx+++ b/packages/web/src/features/chat/chat-input.tsx@@ -594,6 +594,7 @@ export function ChatInput({defaultModel,thinkingLevel,onChangeThinkingLevel,+ thinkingRefusal,turnThinkingLevel,onChangeTurnThinkingLevel,contextWindow,@@ -747,6 +748,14 @@ export function ChatInput({* becomes the Agent's new default).*/onChangeThinkingLevel?: (level: string) => void;+ /**+ * A picked level the write refused — the sentence drawn above the card, or null/absent. Both+ * pickers write the level straight through and display what they read back, so a refused write+ * changes nothing else on screen and a notification would be the only trace of it (gone after+ * six seconds, control unchanged). The parent owns the sentence because it owns the write, and+ * hands it over only while it still describes the Agent / Session on screen.+ */+ thinkingRefusal?: string | null;/*** Session state: the Session's thinking level to DISPLAY — the parent resolves it as "the* user's pick for this session, else the Agent config's level" ("" = neither known yet),@@ -2502,6 +2511,21 @@ export function ChatInput({</p>)}+ {/* A thinking-level pick the write refused: drawn above the card, next to the microphone's+ notice and for the same reason — it explains a control inside the card, and the control+ itself still reads the level it read before, so a toast would leave a click that looks+ like it never registered. The whole sentence hangs on hover (the line is clamped). */}+ {thinkingRefusal != null && thinkingRefusal !== "" && (+ <p+ role="alert"+ data-tooltip={thinkingRefusal}+ data-tooltip-content="text"+ className={`anim-fade mb-1 line-clamp-2 break-words text-xs ${toneInk.danger}`}+ >+ {thinkingRefusal}+ </p>+ )}+{/* Unified input card: the multi-line text body occupies the top area, with all controlscollected onto a single bottom row that never shares a line with the text. The cardcollapses its toolbar by its own width (help text and button text hide under itsdiff --git a/packages/web/src/features/chat/chat-page.tsx b/packages/web/src/features/chat/chat-page.tsxindex d4100fe0..82dc8368 100644--- a/packages/web/src/features/chat/chat-page.tsx+++ b/packages/web/src/features/chat/chat-page.tsx@@ -114,6 +114,7 @@ import {thinkingLevelLabel,} from "./thinking-level";import type { StagedThinkingSwitch } from "./thinking-level";+import { thinkingLevelRefused } from "./thinking-level-refusal";import { ChatDropRegion } from "./drop-zone";import { ConversationOutline, OutlineMenuButton, useOutlineRailFit } from "./conversation-outline";import { DraftView } from "./draft-view";@@ -1641,18 +1642,25 @@ export function ChatPage() {// Pins a picked level on the Session so it outlives this tab: PATCH, then swap the// returned row into the session store (the picker reads it back from there); it applies// from the next LLM request (a pick mid-chat reaches here through the confirm dialog, which- // offers to compact first). Modeled on onChangePermission — a failed write surfaces as a- // toast and leaves the level as it was, rather than showing a level the server does not have.+ // offers to compact first). Modeled on onChangePermission: a failed write leaves the level as+ // it was and the composer keeps the sentence saying why (7.95) — the picker itself reads the+ // store, so a toast would be the only trace of a press that changed nothing.+ const [thinkingRefusal, setThinkingRefusal] = useState<{+ sessionId: string;+ text: string;+ } | null>(null);const applyTurnThinkingLevel = useCallback((level: string) => {if (!selected) return;+ const sessionId = selected.sessionId;+ setThinkingRefusal(null); // The new attempt answers for itself; the old sentence goes.void api- .patchSession(selected.sessionId, {+ .patchSession(sessionId, {thinkingLevel: level as SessionPatchRequest["thinkingLevel"],}).then((res) => replace(res.session)).catch((e: unknown) => {- toastError(apiErrorText(e));+ setThinkingRefusal({ sessionId, text: thinkingLevelRefused(e) });});},[selected, replace],@@ -2229,6 +2237,9 @@ export function ChatPage() {turnThinkingLevel={sessionThinkingLevel(turnThinkingLevel, agentThinkingLevel)}// Guarded: a mid-chat change stages behind the prefix-cache confirm dialog (issue #310).onChangeTurnThinkingLevel={onPickTurnThinkingLevel}+ thinkingRefusal={+ thinkingRefusal?.sessionId === selected.sessionId ? thinkingRefusal.text : null+ }{...(contextWindow !== undefined ? { contextWindow } : {})}{...(compactionLimit !== undefined ? { compactionLimit } : {})}onChangeCompactionLimit={onChangeCompactionLimit}diff --git a/packages/web/src/features/chat/draft-view.tsx b/packages/web/src/features/chat/draft-view.tsxindex 316d4535..d9e8685a 100644--- a/packages/web/src/features/chat/draft-view.tsx+++ b/packages/web/src/features/chat/draft-view.tsx@@ -52,14 +52,14 @@ import type {SkillMetadataItem,TaskInputPart,} from "@adelie/server/api";-import { AgentAvatar, Chevron, Dropdown, MenuItem, AppLogo, toastError } from "@adelie/ui";+import { AgentAvatar, Chevron, Dropdown, MenuItem, AppLogo } from "@adelie/ui";import * as api from "../../api/endpoints";import { S } from "../../lib/strings";import { UNCONFINED, draftSandboxAfter } from "../../lib/permission-level";import type { PermissionPick } from "../../lib/permission-level";import { formatMonthDay } from "../../lib/format";-import { apiErrorText } from "../../lib/api-error";import { sendRefusalReason, sendRefused } from "./first-send-refusal";+import { thinkingLevelRefused } from "./thinking-level-refusal";import { rememberSessionMachine } from "../../lib/session-machines";import { cachedMachineAgents, rememberMachineAgents } from "../../lib/machine-cache";import { useAuth } from "../../state/auth";@@ -493,6 +493,14 @@ export function DraftView({agentThinkingLevel === null || chatDefaults === null? null: effectiveThinkingLevel(agentThinkingLevel, chatDefaults.thinkingLevel);+ /**+ * A refused level write and the Agent it was aimed at. The display rolls back to the level it+ * read before, so this sentence is the only thing saying the press did not take; it is handed to+ * the composer only while that Agent is still the one on screen.+ */+ const [thinkingRefusal, setThinkingRefusal] = useState<{ agentId: string; text: string } | null>(+ null,+ );/** Live mirror for the rollback value (a stale closure would roll back to an outdated level). */const thinkingRef = useRef<string | null>(null);thinkingRef.current = agentThinkingLevel;@@ -501,6 +509,7 @@ export function DraftView({// "" (no override) is not persistable through the config API — the picker disables that row.if (!agentId || !level) return;const rollback = thinkingRef.current;+ setThinkingRefusal(null); // The new attempt answers for itself; the old sentence goes.setAgentThinkingLevel(level); // Optimistic: the derived display follows immediately.api.putAgentConfig(projectId, agentId, {@@ -508,7 +517,9 @@ export function DraftView({}).catch((e: unknown) => {setAgentThinkingLevel(rollback);- toastError(apiErrorText(e));+ // This picker writes through to the Agent's settings, so the refusal left more than+ // this draft alone — the sentence says so (forAgent).+ setThinkingRefusal({ agentId, text: thinkingLevelRefused(e, true) });});},[projectId, agentId],@@ -909,6 +920,7 @@ export function DraftView({onChangeModel={setModelRef}thinkingLevel={thinkingLevel}onChangeThinkingLevel={onChangeThinkingLevel}+ thinkingRefusal={thinkingRefusal?.agentId === agentId ? thinkingRefusal.text : null}{...(models?.defaultModel !== undefined ? { defaultModel: models.defaultModel } : {})}{...(contextWindow !== undefined ? { contextWindow } : {})}contextNow={0}diff --git a/packages/web/src/features/chat/thinking-level-refusal.ts b/packages/web/src/features/chat/thinking-level-refusal.tsnew file mode 100644index 00000000..4c884db8--- /dev/null+++ b/packages/web/src/features/chat/thinking-level-refusal.ts@@ -0,0 +1,29 @@+/**+ * The thinking-level picker: the sentence a refused write leaves above the input card, and why it+ * is drawn there instead of arriving as a toast.+ *+ * Both pickers write the picked level straight through — the draft's to the Agent settings (it+ * becomes the Agent's new default and the level the first send's Session is created on), the+ * Session's onto the Session row (applies from the next LLM request) — and both show the level+ * they read back, never the one that was clicked. A refused write therefore changes nothing on+ * screen: the control still reads the old level and is the retry. The reason used to live only in+ * a notification that dismissed itself after six seconds, leaving a control that looked as though+ * it had not registered the click.+ *+ * Which words: `refusalText`, the rule every refusal slot in the app follows (7.19) — an answer+ * the server gave is read through its code's own localized sentence, and a value this codebase+ * raised itself is shown as it wrote it.+ */+import { refusalText } from "../../lib/api-error";+import { S } from "../../lib/strings";++/**+ * The line the composer draws above the card after a refused level change.+ *+ * `forAgent` marks the draft's picker: its write goes through to the Agent's settings, so a refusal+ * there leaves the Agent's default unchanged too — worth saying, because the pick reads as a+ * single draft's setting at the moment it is made.+ */+export function thinkingLevelRefused(error: unknown, forAgent = false): string {+ return S.chat.thinkingLevelRefused(refusalText(error), forAgent);+}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 57180279..81dba308 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -3428,6 +3428,15 @@ export const en: Strings = {draftSubtitle: "The self-evolving agent that excels at AI development tasks",/** The draft's first message did not go out: nothing was written, the text is still in the card. */draftSendRefused: (reason: string) => `Could not send this message: ${reason}`,+ /**+ * A picked thinking level was refused: the control still reads the level it read before, so the+ * sentence says the pick did not take. `forAgent` is set where the write goes through to the+ * Agent's settings (the draft's picker), which is a wider change than this one conversation.+ */+ thinkingLevelRefused: (reason: string, forAgent?: boolean) =>+ forAgent+ ? `Could not change the thinking level (also the Agent's default, unchanged): ${reason}`+ : `Could not change the thinking level: ${reason}`,/** Second tooltip line on a shortcut row: the click fills the composer, it does not send. */shortcutFillHint: "Click to fill the composer — edit it if you like, then send",/** The draft screen's saved-prompt folder: prompts the user wrote and saved, stored per user on the server. */diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 74f1c613..31c99f6b 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -3497,6 +3497,15 @@ export const zh = {draftSubtitle: "最擅长 AI 开发任务的自进化 Agent",/** The draft's first message did not go out: nothing was written, the text is still in the card. */draftSendRefused: (reason: string) => `没能发出这条消息:${reason}`,+ /**+ * A picked thinking level was refused: the control still reads the level it read before, so the+ * sentence says the pick did not take. `agent` is set where the write goes through to the+ * Agent's settings (the draft's picker), which is a wider change than this one conversation.+ */+ thinkingLevelRefused: (reason: string, forAgent?: boolean) =>+ forAgent+ ? `没能切换思考等级(同时是 Agent 的默认档,没有改动):${reason}`+ : `没能切换思考等级:${reason}`,/** Second tooltip line on a shortcut row: the click fills the composer, it does not send. */shortcutFillHint: "点击填入输入框,可修改后自行发送",/** The draft screen's saved-prompt folder: prompts the user wrote and saved, stored per user on the server. */diff --git a/packages/web/test/thinking-level-refusal.test.ts b/packages/web/test/thinking-level-refusal.test.tsnew file mode 100644index 00000000..8f974a28--- /dev/null+++ b/packages/web/test/thinking-level-refusal.test.ts@@ -0,0 +1,58 @@+/**+ * A thinking level the write refused (src/features/chat/thinking-level-refusal.ts): which words the+ * sentence above the input card uses.+ *+ * Both pickers display the level they read back and never the one that was clicked, so a refused+ * write leaves the control reading as before and the button is the retry — the sentence is the only+ * thing saying why the press changed nothing. Three things it must get right: a server answer+ * speaks the interface's own language rather than the wire message, a write that never reached the+ * route keeps what it knows (7.19's rule), and the draft's picker says out loud that it also left+ * the Agent's default alone.+ */+import { afterEach, describe, expect, it } from "vitest";+import { ApiError } from "../src/api/client";+import { en as EN } from "../src/lib/strings-en";+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";+import { thinkingLevelRefused } from "../src/features/chat/thinking-level-refusal";++afterEach(() => {+ setActiveStrings(ZH);+});++describe("thinkingLevelRefused", () => {+ it("reads a refusal through the code's own sentence, not the wire message", () => {+ const line = thinkingLevelRefused(new ApiError(500, "internal", "RAW ENGLISH"));+ expect(line).not.toContain("RAW ENGLISH");+ expect(line).toBe(S.chat.thinkingLevelRefused(S.errors.byCode.internal as string));+ });++ it("keeps what a write that never reached the route has to say", () => {+ expect(thinkingLevelRefused(new Error("Failed to fetch"))).toBe(+ S.chat.thinkingLevelRefused("Failed to fetch"),+ );+ });++ it("falls back to the generic text when the value has nothing to say", () => {+ expect(thinkingLevelRefused(undefined)).toBe(+ S.chat.thinkingLevelRefused(S.common.unknownError),+ );+ });++ it("says the Agent's default is unchanged too, for the draft's picker", () => {+ const line = thinkingLevelRefused(new ApiError(500, "internal", "RAW"), true);+ expect(line).toBe(S.chat.thinkingLevelRefused(S.errors.byCode.internal as string, true));+ expect(line).toContain("Agent");+ // The session's picker only pins this conversation and must not mention the Agent.+ expect(thinkingLevelRefused(new Error("boom"))).not.toContain("Agent");+ });++ it("speaks the active language", () => {+ setActiveStrings(EN);+ expect(thinkingLevelRefused(new Error("boom"))).toBe(+ "Could not change the thinking level: boom",+ );+ expect(thinkingLevelRefused(new Error("boom"), true)).toBe(+ EN.chat.thinkingLevelRefused("boom", true),+ );+ });+});