A local-first multi-agent app development platform, built on PenguinHarness
fix(models): a refused write keeps its reason in the confirmation (7.19)
lmliheng449c27fb76f0
diff --git a/changelog/unreleased/2026-10-21-models-refusal-in-card.md b/changelog/unreleased/2026-10-21-models-refusal-in-card.mdnew file mode 100644index 00000000..242bd099--- /dev/null+++ b/changelog/unreleased/2026-10-21-models-refusal-in-card.md@@ -0,0 +1,37 @@+# A refused write keeps its reason in the confirmation that asked for it++- **Date:** 2026-10-21+- **Type:** fix+- **Scope:** `web`, `ui`+- **Breaking:** no++[中文版](2026-10-21-models-refusal-in-card.zh.md)++Every confirmation in the model library that writes the Project's config — save a model's config, make it+the default, make it the vision proxy, delete the model, delete the group, sync the presets — now draws the+server's reason for a refused write inside the card, under its sentence, right above the button that retries+it.++That sentence used to appear in a toast only: the same words, but gone after six seconds and floating over+the card rather than in it. So the one moment it was needed — after reading it, deciding whether to retry —+it had usually already left. This is the last loose end of the previous round's rule that a confirmation+closes on its write's outcome rather than on the click.++## Details++- `ConfirmModal` gained a `refusal` slot: when it has words, a danger-toned strip is drawn under the+ sentence; when it does not, the slot is not drawn at all. Every confirmation in the app is this one card,+ so another page adopts it by passing a string.+- The model library's writes (`persist`) no longer raise the toast themselves: they hand the server's own+ words back to the card that asked for the write (`WriteOutcome` / `refusalOf` in+ `features/models/write-outcome.ts`). The strip leads with the app's own "操作被拒绝:" ("Refused:") and+ then carries that sentence verbatim.+- Two writes keep the toast because they have no card to keep it in: a group's API key (its dialog closes on+ submit) and the toolbar's "sync presets" (which never had a confirmation). The six that do have a card+ show the reason in it.+- One attempt, one strip: opening a confirmation again, or pressing its confirm again, drops the previous+ reason first — that sentence was about the previous write.++## Compatibility++- No API, wire-format or dependency change: this is only where the refusal's words are drawn.diff --git a/changelog/unreleased/2026-10-21-models-refusal-in-card.zh.md b/changelog/unreleased/2026-10-21-models-refusal-in-card.zh.mdnew file mode 100644index 00000000..1fb3aa54--- /dev/null+++ b/changelog/unreleased/2026-10-21-models-refusal-in-card.zh.md@@ -0,0 +1,31 @@+# 写入被拒时,原因留在那张确认框里++- **Date:** 2026-10-21+- **Type:** fix+- **Scope:** `web`、`ui`+- **Breaking:** no++[English](2026-10-21-models-refusal-in-card.md)++模型库里每一个写着项目配置的确认框 —— 保存模型的配置、设为默认模型、设为视觉代理模型、删除模型、+删除分组、同步预置 —— 现在把写入被拒的原因画在框里、句子下面,就贴在重试的那个按钮上方。++此前那句话只出现在一条 toast 里:同一条提示,但它在六秒后自己消失,而且浮在框的上方而不是框里。于是+最需要它的时候(看完原因、决定要不要重试)它往往已经走了;上一轮修好的「确认框等到写入有结果才收起」+留下的最后一个尾巴就是这个。++## 细节++- `ConfirmModal` 多一个 `refusal` 槽:有内容时在句子下画一条 danger 色的提示条,没内容时槽根本不画。+ 十几个页面的确认框共用这张卡片,因此别的页面接上它只需传一句话。+- 模型库的写入(`persist`)不再自己弹 toast,而是把服务端的原话交回给发起写入的那张卡片+ (`features/models/write-outcome.ts` 的 `WriteOutcome` / `refusalOf`)。提示条的落款是「操作被拒绝:」,+ 英文是「Refused:」,后面原样接服务端那句话。+- 仍在用 toast 的两处是**没有框可以留**的写入:分组密钥(对话框一提交就关)、工具栏上的「同步预置」+ (本来就没有确认框)。有框的那六处都改成框内显示。+- 换一次尝试就换一次提示条:重新打开确认框、或者重新按下它的确认,上一次的原因先撤掉 —— 那句话说+ 的是上一次写入。++## 兼容性++- 没有接口、传输格式或依赖变化;只改了拒绝提示画在哪。diff --git a/docs/FORK-PROGRESS.md b/docs/FORK-PROGRESS.mdindex 6df18f08..ff9899bb 100644--- a/docs/FORK-PROGRESS.md+++ b/docs/FORK-PROGRESS.md@@ -1248,6 +1248,16 @@ mock 路由导入序、`chat-page.tsx` 的旧探针体),自带 4 份用例等 `document.getAnimations()` 里正在跑的 `CSSTransition` 各自 `finished`(只认 CSS 过渡,不碰无限循环的脉冲/转圈),两处缩放各换成它。细节、两态读数与反证见该节。+- [x] **7.19 写入被拒的原因留在那张确认框里**(**2026-10-21 第九十七轮**落地,提交见该节;+ `packages/ui` 的 `ConfirmModal` 多一个 `refusal` 槽 + `packages/web` 的模型库六处写入接上,+ changelog 一对):第九十四轮逐处摸过「点击即关、失败只弹 toast」那一族之后留下的那件 —— 框+ 留住了(7.9、7.11–7.15),可**原因**还只在一条六秒后自己消失、且浮在框上方的 toast 里。+ **现在**:确认框被拒时把服务端的原话画在句子下面、重试按钮正上方;`persist` 不再自己弹 toast,+ 而是把原话交回发起写入的那张卡片(`features/models/write-outcome.ts` 的 `WriteOutcome` /+ `refusalOf`)。**还差什么**:这一族还有十几个页面没收 —— 模型库这六处先做(它们本来就有+ 「写成功才收起」的用例可延长),余下的页面同一条规则、只差逐页接 `refusal` 与各自的用例。+ 细节、反证与截图见该节。+## 发布 v0.2.0(2026-10-05)用户要求「先发布最新版本到 GitHub,说明是基于 penguin harness 做的」。这一版是**源码版**:@@ -1864,6 +1874,7 @@ v0.2.2」——它只加台账里 v0.2.2 那一节与两行表格,**跟本轮| 2026-10-20 | 7.16 | **竖栏折叠后的取样等它落定:`tooltip-beside` 曾把折到一半的竖栏边缘当成停稳的那道边**(不是移植:1 个新文件 `packages/web/e2e/rail.mjs`(`collapseRail`,等 `aside.right <= 48.5` 并显式给 15 s)+ 两份 spec 改用它(`tooltip-beside` −11 +1、`company-rail-hints` −12 +1,后者第八十七轮那份本地同款收进共用),**无新依赖、不碰产品代码、不写 changelog**):第九十三轮整套 e2e 首跑的那条红(`placed.rect.left 48 < railRight - 1 50.97`)的真因在**等待**本身 —— 第八十五轮写的是 `expect.poll(...).toBeLessThan(80)`,也就是「比展开的侧栏窄就放行」,而折叠动画要 ~150 ms 才落到 48。**逐帧量到的**(真服务 + 真浏览器,`mktemp` 数据根、`localhost:8964`、1280×900):`aside.right` 231.25 → 178.28 → 132.84 → 101.83 → **81** → 66.98 → 57.72 → **51.97** → 48.91 → 48,所以等待可能停在 81.00 / 66.98 / 51.97(那一跑量到的正是 51.97),而提示面板按已停稳的 48 摆放 —— 断言只错在竖栏那一条,静悄悄地错一两个像素。**现在**:`e2e/rail.mjs` 的 `collapseRail` 等停稳的 48 px 列,两份 spec 共用它;`tooltip-beside` 的竖栏前提与全部落位断言原样保留。**为什么是它**:待办里能一轮做完的条目仍然没有(2.2c 桌面壳 / 部署单元、3.5 拍板、3.6 模型 key、4.1–4.3 明令不动、5.6 / 5.10 拍板 / 新依赖),而第九十三轮点名的那一族「点击即关、失败只弹 toast」的确认框本轮逐处摸过(插件市场 / 智能体设置 / 定时任务 / 公司日历、组织、频道 / MCP / 用户仓库),**没有一处留下假状态**,故不再顺着它找 | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`(193 接口 / 589 类型)** —— 本笔不碰源码)· `npx oxlint` 全仓 **0 警告 0 错误**(2236 文件)· `npx prettier --check .`「All matched files use Prettier code style!」(`rail.mjs` 首跑一条,`--write` 后复检)· `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **67 文件 / 1399 通过 / 6 跳过** · ui **129 / 1043** · cli **38 / 561** · web **261 文件 / 3212 通过 / 2 跳过** · server **202 文件 / 2955 通过 / 4 跳过** · 改动涉及的两份用例同服务连跑 **4 passed(12.8s)**(`tooltip-beside` 2 + `company-rail-hints` 2;改前同一服务单跑 `tooltip-beside` 2 passed 作基线)· **真服务 + 真浏览器整套 e2e**(`SKIP_BUILD=1 pnpm -C packages/web test:e2e`,脚本自己的 `mktemp` 数据根、mock 8931 / 服务端 8930):**105 passed(7.6m)、0 failed**,第九十三轮那条偶发红这次没有出现 · **反证**(同一浏览器、同一页,把折叠放慢成 1.2 s 让「中途」这段窗口宽到能看清差别):**旧等待** 706 ms 后以 `railRight=78.28` 放行、面板 `left=48.00`,`48.00 >= 77.28` → **FAIL**;**新等待** 1127 ms 后以 `railRight=48.39` 放行、面板 `left=48.00` → **PASS**;探针 `r94/probe-fold.mjs`(逐帧轨迹)与 `r94/probe-old-vs-new.mjs`(两套等待)在 scratchpad · **真看一眼**:`r94/{old-wait-midfold,new-wait-settled}.png`,竖栏 48 px、提示「插件市场」贴着竖栏右边缘弹出;console 只有按设计的 `GET …/machines` **403**,无其它 error / ≥400 · 端口只用 8964 / 8965 与 8930 / 8931(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在一次性 `/tmp/r94data.*` 与 e2e 自己的 `mktemp` 根,一个字节没往 `~/.penguin` / `~/.adelie` 里写(`packages/*/dist`、`test-results/` 都是产物,未 `git add`)· 没有切版本号、没发 npm、没发安装包、没发发布汇总 | `ab04ae9c` || 2026-10-20 | 7.17 | **停靠栏的取样等它落定:`dock.spec` 的 24 px 松口子与三处猜时长的 `waitForTimeout(200)`**(不是移植:1 个新文件 `packages/web/e2e/settle.mjs`(`settledBox()` —— 逐帧读 `getBoundingClientRect()`,连续两帧在 0.5 px 内一致才返回;元素离场、或 10 s 还没停稳,直接报错而不是返回一个还在动的数)+ `dock.spec.mjs` 三处(恢复那条 `|h − after| < 24` → 等停稳后 `≤ 2`;拖拽前的 `before` 由一次性读改成停稳后读;全屏那段手写的「两帧宽度相等」轮询 → `settledBox(composer)`)+ `layout.spec.mjs` 三处(`waitForTimeout(200)` 的弹入等待 → `settledBox(panel|picker|finder)`),无新依赖、不碰产品代码):逐帧量到的实情 —— 右停靠栏宽度 1 → 8.88 → 43.78 → … → 510 → 512(~293 ms,旁边的会话列跟着缩:composer 746 → 428)、底栏高度 1 → 6.03 → 29.75 → 82.33 → 159.27 → … → 333.92 → 346.66 → 348(~289 ms)、刷新后的恢复 29.61 → 82.3 → … → 348、全屏的 `data-fullscreen` 要到 ~278 ms 才从 `entering` 转 `full`(而 header 一上来就是 992 宽、只抖 ±1 px,所以量到它的那几条本来就对,不必再改)、抽屉 `.anim-drawer-left` 240 ms 但**没有任何用例打开它**、菜单弹入 `.anim-pop` 170 ms(三处 200 ms 的余量只剩 30 ms)。老等待的松口子在放慢 7× 的过渡下停在 324.88(停稳 346.22,差 21.34 px) | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`(193 接口 / 589 类型)**,本笔不碰源码)· 逐包 test **`EXIT=0`、0 失败**:core **1399 通过 / 6 跳过**(68 文件)· ui **1043**(129 文件)· cli **561**(38 文件)· server **202 文件 / 2955 通过 / 4 跳过** · web **261 文件 / 3212 通过 / 2 跳过** · 改到的两份 spec 加 `mobile-dock` 同服务连跑 **17 passed(1.1m)** · **整套 e2e**(`pnpm -C packages/web test:e2e`:重建 core/server/web、脚本自己的 `mktemp` 数据根、mock 8931 / 服务端 8930)**105 passed(7.6m)、0 failed** · **反证(真浏览器、同一份恢复动画,老等待与新等待并排量)**:老等待真速下停在 346.66(离 348 差 1.34 px),放慢到 1.4 s 后停在 324.88(差 21.34 px,即 `|h − after| < 24` 会放行一个离停稳位置还差五分之一的盒子);`settledBox` 真速读到 348.00、放慢 1.4 s 读到 346.22(离目标 1.78 px,这就是断言留 2 px 而非严格相等的原因)· 真看一眼:`r95/shots/docks-1280.png`(右侧记忆 + 底部轨迹两个停靠栏)与 `r95/shots/drawer-390.png`(390 宽手机抽屉),console 只有按设计的 `GET …/machines` 403,无其它 error / ≥400 · 端口只用 8940(一次性探针服务,已停)与 e2e 自己的 8930 / 8931(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在一次性 `/tmp/r95data.*` 与 e2e 自己的 `mktemp` 根,一个字节没往 `~/.penguin` / `~/.adelie` 里写 | `40620042` || 2026-10-21 | 7.18 | **缩放视口后的取样等过渡落定:`chat.spec` 那两处 `waitForTimeout(200)` 恰好等于侧栏宽度过渡的 200 ms**(不是移植:`packages/web/e2e/settle.mjs` 加一个 `settledTransitions()`(先让一帧落地,再等 `document.getAnimations()` 里每个正在跑的 `CSSTransition` 各自 `finished`,循环到列表为空;超时带着「还剩哪几个过渡、落在谁身上」报错)+ `chat.spec.mjs` 两处 `waitForTimeout(200)` 改成它,**无新依赖、不碰产品代码、不写 changelog**):第九十五轮末尾点的「唯一没核过的一处」—— 那两条用例先 `setViewportSize`(1280×900 → 877×438)再量工具栏里两个 span 是否重叠。**逐帧量到的实情**:`aside` 是 `hidden md:block w-64 lg:w-72` 且带 `transition … width 0.2s`,877 正好跨过 `lg` 档,于是侧栏 288 → 256 滑了**整整 200 ms**(280.39 → 273.34 → … → 256.11 → 256),把工具栏左半边一起拖着走(标题 x 304 → 272、「运行中」chip 487.73 → 455.73),而右对齐的 Token chip 同一帧就跳到 785.39 —— 旧等待与过渡时长一字不差,实测停稳要 **210 / 219 ms**(两次缩放),余量为零。**为什么不用 `settledBox`**:过渡开头 50 ms 只挪 7.6 px,「连续两帧一致」会把缩放前的 288 认成停稳。至此「等动画落定再量」这一族收口(停靠栏 / 全屏 / 抽屉 / 竖栏 / 弹入 / 缩放) | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`(193 接口 / 589 类型)** —— 本笔不碰源码)· 两份改动文件 `prettier --check` 干净、`npx oxlint` **0 警告 0 错误**、`git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **67 文件 / 1399 通过 / 6 跳过** · ui **129 / 1043** · cli **38 / 561** · web **261 文件 / 3212 通过 / 2 跳过** · server **202 文件 / 2955 通过 / 4 跳过** · **整套 e2e**(一次性 `mktemp` 数据根、mock 8931 / 服务端 8930):**105 passed(7.6m)、0 failed**;改到的 `chat.spec` 先单跑 **1 passed(11.4s)** · **反证(同页同一条缩放,老等待与新等待并排量,侧栏过渡放慢到 1.4 s 让差别看得见)**:去 877 时老等待读到侧栏 **284.77** / chip x **484.5**(停稳 256 / 455.73,差 28.77 px),新等待 1413 ms 后读到 256 / 455.73;回 1280 时老等待读到 **257.88** / **457.61**(停稳 288 / 487.73),新等待读到 288 / 487.73;真速下两套读数一致(`settledTransitions` 花 210 / 219 ms)· **这条用例的断言(两 chip 不重叠)今天两态都过** —— 修的是「量的是停稳的布局」这个前提,台账不写成抓到了假绿 · **两处 `layout.spec` 的 390 缩放**本轮量过、不是同一类:390 下 `aside` 是 `display: none`(宽度过渡不参与),200 ms 后只剩一枚 `rotate@svg`,页宽 200 ms 与停稳后逐字相同(390 / 390),故未改 · **真看一眼**:`r96/shots/{look-877,look-toolbar-877,look-1280}.png`,877 下顶栏「运行中」与 Token `0` / 耗时 `0s` 并列不重叠,console 只有按设计的 `GET …/machines` **403**,无其它 error / ≥400;1280 下 `scrollWidth = clientWidth = 1280` · 探针 `r96/probe-{viewport,who-moves,settle-transitions,old-vs-new,resize-390}.mjs` 在 scratchpad · 端口只用 8940 / 8930 / 8931(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在一次性 `/tmp/r96data.*` 与 e2e 的 `mktemp` 根,一个字节没往 `~/.penguin` / `~/.adelie` 里写 · 没有切版本号、没发 npm、没发安装包、没发发布汇总 · **汇报邮件仍发不出去**(993 / 465 的 TCP 都建不起来,同时 github 200,与第九十五轮同一类) | `d3bde807` |+| 2026-10-21 | 7.19 | **写入被拒的原因留在那张确认框里**(不是移植:`packages/ui` 的 `ConfirmModal` 多一个 `refusal` 槽(有内容时在句子下画一条 `NoticeStrip tone="danger" role="alert"`,没有时槽不画),`packages/web` 新增 `features/models/write-outcome.ts`(`WriteOutcome` / `refusalOf`)把 `persist` 的返回从 `boolean` 换成「写成了 / 被拒了 + 服务端原话」,模型库六处写入选各自把这句话画在哪:配置框四个动作画进它的确认框、删除分组与同步预置画进各自的框、分组密钥与工具栏同步预置与导入分组没有框可留故保留 toast;`common.refused()` 两句文案 + 四份 spec 收紧断言(`cardText()` 助手、`通知` 区必须没有 toast)、changelog 一对):第九十四轮逐处摸过「点击即关、失败只弹 toast」那一族之后留下的那件 —— 框留住了(7.9、7.11–7.15),**原因**却只在一条 6 秒后自己消失、还浮在框上方的 toast 里(`ui` 的时长表 error = 6000 ms)| 六包 `typecheck` **`EXIT=0`**(`gen:ifaces` = `src/ifaces.json unchanged`,193 接口 / 589 类型)· 11 份改动文件 `prettier --check` 干净、`npx oxlint` **0 警告 0 错误**、`git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **67 文件 / 1399 通过 / 6 跳过** · ui **129 / 1044** · cli **38 / 561** · web **262 文件 / 3215 通过 / 2 跳过** · server **202 文件 / 2955 通过 / 4 跳过**(中间红过一次:`todo-notice.test.ts` 的守卫读 `onAction` 里第一个 setter,改成先开框再清原因后转绿,没动守卫)· **整套 e2e 105 passed(7.4m)、0 failed**,改到的四份 spec 先单跑 **9 passed(18.4s)** · **反证**:把 `models-page.tsx` 暂存回去重建产物后同一批 spec **5 failed**(红的就是新的两类断言),`stash pop` 重建后 9 passed · **真看一眼**:`r97/look-refusal-card.png` 里句子下面就是 danger 色的「操作被拒绝:models store is closed」,`look-refusal-after-6s.png` 证明 6.5 秒后仍在框里,`通知` 区按钮数 **0**,1280 下 `scrollWidth = clientWidth`,console 只有按设计的 `/machines` 403 与注入的 500 · 端口只用 8941 / 8931(跑完已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰,数据只落 `/tmp/r97data.*` · 没有切版本号、没发 npm、没发安装包 | 见本行提交 |> **2026-10-11 与另一条线的交汇(第三十七轮)**:定时任务触发时(07:00)`git status --short` **不干净**> —— 另一条线(会话 `session-2026-10-05-20-32-50-2ee69aba`)正在做**用户点单**的「回复能复制成纯文本」@@ -12461,3 +12472,100 @@ Token 两枚 chip);探针在页面里用一个 rAF 采样器逐帧读盒子- 「点击即关、失败只弹 toast」那一族第九十四轮逐处摸过,**没有一处留下假状态**;要动就是统一「失败原因随框留着」,那是一次横跨十几个页面、且要先定文案的改动,仍得单独一轮。- 若用户点单桌宠的后续三问(第九十一轮记的三条)或别的功能,按点单优先。++## 第九十七轮:写入被拒的原因留在那张确认框里(2026-10-21,条目 7.19)++### 开工自检与选活理由++- 同步:`git status --short` 干净,`main` 停在 `cf0d4234`(第九十六轮的台账补记);+ `git fetch origin && git merge --ff-only origin/main` = Already up to date(没切分支、没碰+ `legacy/main`、没推 upstream)。+- 上游:按台账的办法按 URL 现拉+ (`git fetch --no-tags https://github.com/Prism-Shadow/penguin-harness main:refs/adelie-tmp/upstream-main-r97`),+ 尖端仍是 **`8aa76123`** —— `git rev-list --count 8aa76123..refs/adelie-tmp/upstream-main-r97` = **0**,+ 没有可移植的新提交。+- 选活:待办里最靠前的未勾选条目仍是 **2.2c**(剩下的全在桌面壳写侧、`adelie-app.service` 单元、+ 桌面壳自己的开关那一侧);3.5 / 3.6 / 4.1–4.3 要拍板或要 key;5.6 / 5.10 也要拍板或有前置。+ 于是接过第九十六轮末尾(也是第九十四轮)唯一点名的那件:**统一「失败原因随框留着」**。+ 这一族横跨十几个页面,本轮先做**模型库那六处**——它们已经有一整套「写成功才收起」的用例+ (`models-save-refusal` / `models-delete-model` / `models-delete-group` / `models-sync-order`),+ 正好把「原因在不在框里」一起钉住;余下的页面在条目里写成「还差什么」。++### 先量清楚(不是推测)++- 读代码就够确定的一半:`persist` 的 catch 里唯一一句话是 `toastError(apiErrorText(e))`,而+ `packages/ui` 的 toast 时长表写着 error = **6000 ms**、并按 `LEAVE_MS = 160` 退场;toast 是一个+ 浮在 `z-[100]`、portal 到 `document.body` 的按钮(`Toaster` 的「通知」区),所以它**不在框里**,+ 也不随框留着。+- 两态实测(真服务 + 真浏览器,一次性数据根 `/tmp/r97data.Q0KwE0`、服务端 `localhost:8941`、+ mock `127.0.0.1:8931`、1280×900、PUT 被 `page.route` 拒成 500 `models store is closed`):+ - **改前**:框里没有那句话(断言 `dialog.getByText("models store is closed")` 找不到元素),+ 原话只在 toast 里。反证见下。+ - **改后**:框里那条 danger 色提示条读到 `操作被拒绝:models store is closed`(`role="alert"`,+ 盒子 302×34,落在句子下面、按钮上方);`通知` 区的按钮数 **0**;**6.5 秒之后**那句话仍在框里+ (toast 的 6 秒早已过去);页宽 `scrollWidth = clientWidth = 1280`,无横向溢出。++### 改了什么(12 个文件 + 台账:ui 两处、web 源码三处(含一个新文件)、四份 spec、zh/en 两份文案、changelog 一对)++- `packages/ui/src/components/overlays/confirm-modal/confirm-modal.tsx`:`ConfirmModalProps` 多一个+ `refusal?: string`,有内容时在句子下画一条 `NoticeStrip tone="danger" role="alert"`(`data-slot="body"`+ 里放原话),没有时槽根本不画。**为什么放在这张卡片里**:全应用的确认框都是这一张,别的页面接上+ 只需传一句话;把提示条画在这里也就等于「原因长在提问那一段上」,而不是第二条浮动的卡片。+- `packages/web/src/features/models/write-outcome.ts`(新)+ `test/models-write-outcome.test.ts`:+ `WriteOutcome = { ok: true } | { ok: false; reason }` 与 `refusalOf()`。`persist` 的返回类型从+ `boolean` 改成它 —— 被拒时把服务端的原话交回调用方,**不再自己弹 toast**。+- `packages/web/src/features/models/models-page.tsx`:`persist` 换成返回 `WriteOutcome`;+ 六处写入各自决定这话放哪 ——+ - 配置框里三个动作(保存 / 设为默认 / 设为视觉代理)与「删除模型」:由 `ModelDialog` 自己的+ `refusal` 状态接住,画在它的确认框里;`confirm(action)` 与 `submit()` 开头各自把上一次的原因撤掉+ (一次尝试一条原因)。+ - 删除分组、同步预置:页面级 `deleteGroupRefusal` / `syncRefusal`,画在各自的确认框里;打开框时清空。+ - 分组密钥、工具栏的「同步预置」、导入分组:**没有框可留**(前两个的对话框一提交就关、后者根本没有+ 确认框),保留 toast —— `refusalOf` 的注释把这层分工写明。+- `packages/web/src/lib/strings.ts` / `strings-en.ts`:`common.refused(reason)` =+ 「操作被拒绝:{原因}」/「Refused: {reason}」。提示条要有自己的落款:服务端那句话可能只是一个短语。+- 四份 spec(`models-save-refusal` / `models-delete-model` / `models-delete-group` / `models-sync-order`,+ 没有新增文件):断言从「页面上能看到那句话」收紧成**「框里能看到」**(`dialog.getByText(...)`)+ 并多两条 —— `通知` 区**没有** toast、整卡文字(去掉拒绝那一行后)与写入前**逐字相同**(新的+ `cardText()` 助手)。这一族从此钉住的是「原因留在框里」,不是「某处弹过一句」。+- changelog 一对(`changelog/unreleased/2026-10-21-models-refusal-in-card{.zh,}.md`):这是用户可见的行为变化。++### 验证++- 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`(193 接口 /+ 589 类型)** —— 本笔不碰契约)。+- 改动的 12 份文件与台账 `prettier --check` 干净;`npx oxlint` **0 警告 0 错误**;`git diff --check` 干净。+- 逐包 test **`EXIT=0`、0 失败**:core **67 文件 / 1399 通过 / 6 跳过** · ui **129 / 1044** ·+ cli **38 / 561** · web **262 文件 / 3215 通过 / 2 跳过** · server **202 文件 / 2955 通过 / 4 跳过**+ (web 比上轮 +3,就是新那份 `models-write-outcome.test.ts`;ui +1 是 `ConfirmModal` 的新用例)。+ **中间红过一次**:`test/todo-notice.test.ts` 的守卫读 `onAction` 里**第一个** setter,而我把+ `setSyncRefusal(null)` 写在了 `setSyncConfirmOpen(true)` 前面 —— 守卫于是要求 `syncRefusal` 去守+ `ConfirmModal`。改法是**让「打开」先落**(两处都改成先开框、再清原因),没动守卫。+- **整套浏览器 e2e**(一次性数据根、服务端 8941 / mock 8931):**105 passed(7.4m)、0 failed**;+ 四份改到的 spec 先单跑 **9 passed(18.4s)**。+- **反证(真的把页面改回去再跑)**:`git stash push -- packages/web/src/features/models/models-page.tsx`+ + 重建 web 产物,同一批 spec **5 failed**,红的正是新加的两类断言+ (`dialog.getByText("models store is closed")` → element(s) not found;`通知` 区那条在同样的位置);+ `git stash pop` + 重建后 9 passed。也就是说这几条断言**真的**能区分「原因在框里」与「原因只在 toast 里」。+- **真看一眼**:`r97/look-refusal-1280.png`(整页)、`look-refusal-card.png`(确认框特写:铅笔标记 ++ 「确定保存对「Probe Look Renamed」的配置修改?」+ danger 色「操作被拒绝:models store is closed」++ 取消 / 确认)、`look-refusal-after-6s.png`(6.5 秒后同一张卡片,那句话还在);console 只有按设计的+ `GET …/machines` **403**(顶栏读机器列表,成员不是管理员)与我们自己注入的 500,无其它 error。+ 探针 `r97/look-refusal.mjs` 在 scratchpad。+- 端口:探针只用 8941 与 mock 8931,e2e 也是这两个(跑完都已停);3003 / 3004 / 4000 / 7364 / 7369+ 一个没碰;数据只落在一次性 `/tmp/r97data.*`,一个字节没往 `~/.penguin` / `~/.adelie` 里写。+- 没有切版本号、没发 npm、没发安装包、没发发布汇总。++### 没做 / 还差什么++- **这一族剩下的十几个页面**(`schedules` / `machines` / `company`(组织、频道、员工、工单)/+ `plugins` / `settings` / `benchmarks` 等):同一条规则,只差逐页接 `refusal` 与各自的用例;+ `ConfirmModal` 的槽与 `S.common.refused` 已经就位,一页大概是一行 prop 加一条断言。+- 「点击即关」那半边第九十四轮已判**没有一处留下假状态**,本轮没回头再核。++### 下一轮从这里接++- 待办清单的卡点原地:**2.2c**(剩下的全在桌面壳 / 部署单元那一侧)、**3.5**、**3.6**、**4.1–4.3**、+ **5.6** / **5.10**;7.1–7.19 已勾掉。+- 上游尖端 **`8aa76123`**(本轮重拉过,0 个新提交)。+- 7.19 的**下一半**:把「原因随框留着」铺到余下十几个页面(按页面一个个来,每页一条用例)。diff --git a/packages/ui/src/components/overlays/confirm-modal/confirm-modal.tsx b/packages/ui/src/components/overlays/confirm-modal/confirm-modal.tsxindex 677e3fa2..5bdbb997 100644--- a/packages/ui/src/components/overlays/confirm-modal/confirm-modal.tsx+++ b/packages/ui/src/components/overlays/confirm-modal/confirm-modal.tsx@@ -15,9 +15,15 @@* switch anyway / cancel). It stays the same card: a neutral button in the same row, never a* second primary. `confirmDisabled` covers the case where that recommended action is temporarily* unavailable — the body then says why, and the other choices stay live.+ *+ * A confirmation whose action is a write can also report the refusal of that write (`refusal`):+ * the server's words render inside the card, under its sentence, so the reason sits next to the+ * button that retries it. A toast says the same thing, but it dismisses itself out of the card+ * the user is still looking at.*/import type { ReactNode } from "react";import { Button } from "../../actions/button/button";+import { NoticeStrip } from "../../feedback/notice/notice-strip";import { ICONS } from "../../icons/icons";import { Modal } from "../modal/modal";@@ -75,6 +81,11 @@ export interface ConfirmModalProps {*/glyph?: string;busy?: boolean;+ /**+ * The words for a write this confirmation asked for and the server refused, rendered under the+ * card's sentence. Absent (not empty) when nothing was refused, so the slot is simply not drawn.+ */+ refusal?: string;children: ReactNode;}@@ -91,13 +102,27 @@ export function ConfirmModal({tone = "danger",glyph,busy = false,+ refusal,children,}: ConfirmModalProps) {return (<Modal open={open} title={title} onClose={onClose} headerless widthClass="sm:max-w-sm"><div className="flex items-start gap-3"><ToneMark tone={tone} {...(glyph !== undefined ? { glyph } : {})} />- <div className="min-w-0 flex-1 pt-1.5">{children}</div>+ <div className="min-w-0 flex-1 pt-1.5">+ {children}+ {refusal !== undefined && (+ // The card's own words, in the card's own width: a small strip under the sentence so+ // the reason reads as part of the question that was refused, not as page-level news.+ <NoticeStrip+ tone="danger"+ role="alert"+ className="mt-3 rounded-md border px-2.5 py-2 text-xs"+ >+ <span data-slot="body">{refusal}</span>+ </NoticeStrip>+ )}+ </div></div>{/* Wraps rather than overflows: three choices with long labels don't fit one row insidethe bottom-sheet width on a phone (a two-button card never reaches the wrap point). */}diff --git a/packages/ui/test/confirm-modal.test.ts b/packages/ui/test/confirm-modal.test.tsindex 3c6955a4..0d5fa547 100644--- a/packages/ui/test/confirm-modal.test.ts+++ b/packages/ui/test/confirm-modal.test.ts@@ -2,7 +2,8 @@* ConfirmModal (src/components/overlays/confirm-modal/confirm-modal.tsx): the headerless confirm* card. Both labels are the caller's copy, the optional third choice needs both halves to appear,* `confirmDisabled` holds back the confirm button alone, and the tone rides on the mark's ink over- * a neutral disc — never an icon in a tint of its own tone.+ * a neutral disc — never an icon in a tint of its own tone. A refused write reports its words in+ * `refusal`, drawn inside the card so the reason sits beside the retry button.*/import { createElement } from "react";import type { ReactNode } from "react";@@ -77,4 +78,27 @@ describe("ConfirmModal", () => {expect(primary).toEqual(expect.arrayContaining(["bg-line-muted", "text-tone-neutral-fg"]));expect(primary).not.toContain("text-tone-danger-fg");});++ /**+ * A refused write's words are the card's own: a danger notice under the sentence, in the body+ * column beside the mark (not a second floating card), and nothing at all when none was given.+ */+ it("draws a refusal inside the card, and no slot at all when there is none", () => {+ expect(confirm()).not.toContain("ui-notice");+ expect(confirm({ refusal: "" })).toContain("ui-notice");++ const html = confirm({ refusal: "models store is closed" });+ const strip = /<div role="alert"[^>]*>/.exec(html)?.[0] ?? "";+ expect(classTokens(strip)).toEqual(+ expect.arrayContaining(["ui-notice", "bg-tone-danger-bg", "text-tone-danger-fg", "mt-3"]),+ );+ expect(html).toContain("models store is closed");+ // Under the caller's sentence: the body column reads sentence, then the refusal.+ expect(html.indexOf("The transcript goes with it.")).toBeLessThan(+ html.indexOf("models store is closed"),+ );+ // The slot the notice hook lets a theme restyle the words through, and no mark of its own.+ expect(strip).toContain('data-tone="danger"');+ expect(html).toContain('data-slot="body"');+ });});diff --git a/packages/web/e2e/models-delete-group.spec.mjs b/packages/web/e2e/models-delete-group.spec.mjsindex b138911c..53adef90 100644--- a/packages/web/e2e/models-delete-group.spec.mjs+++ b/packages/web/e2e/models-delete-group.spec.mjs@@ -113,6 +113,15 @@ async function openDeleteDialog(page) {return dialog;}+/**+ * The card's own text with the refusal slot dropped: a refused write adds one line under the+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal is allowed to change —+ * the sentence, the list it names and the buttons must read exactly as they did before the write.+ */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}+test("a refused group delete keeps its dialog, its sentence and the group the server has", async ({page,}) => {@@ -129,11 +138,15 @@ test("a refused group delete keeps its dialog, its sentence and the group the seawait refuseWrites(page, puts);await dialog.getByRole("button", { name: "确认" }).click();- // The write was refused and the dialog stays exactly as it was — same group, same count.- await expect(page.getByText("models store is closed")).toBeVisible();+ // The write was refused and the dialog stays exactly as it was — same group, same count —+ // with the server's own words added under its sentence. That is the only thing this refusal+ // puts on screen: the reason used to be a toast, which dismissed itself after six seconds and+ // sat over the card rather than in it, so the one thing the retry needs left first.+ await expect(dialog.getByText("models store is closed")).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);expect(puts).toHaveLength(1);await expect(dialog).toBeVisible();- expect(await dialog.innerText()).toBe(sentence);+ expect(await cardText(dialog)).toBe(sentence);// The group is back on the page, and its header still offers the way to this action: before// the fix the refused delete took both away while the server kept the rows.@@ -178,7 +191,7 @@ test("the retry after a refused group delete writes it, and only a written one cconst dialog = await openDeleteDialog(page);await dialog.getByRole("button", { name: "确认" }).click();- await expect(page.getByText("models store is closed")).toBeVisible();+ await expect(dialog.getByText("models store is closed")).toBeVisible();await expect(dialog).toBeVisible();expect(puts).toHaveLength(1);diff --git a/packages/web/e2e/models-delete-model.spec.mjs b/packages/web/e2e/models-delete-model.spec.mjsindex a6819f16..9638d9ce 100644--- a/packages/web/e2e/models-delete-model.spec.mjs+++ b/packages/web/e2e/models-delete-model.spec.mjs@@ -115,6 +115,15 @@ function confirmation(page) {return page.getByRole("dialog").filter({ hasText: "确定删除" });}+/**+ * The card's own text with the refusal slot dropped: a refused write adds one line under the+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal is allowed to change —+ * the sentence, the list it names and the buttons must read exactly as they did before the write.+ */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}+test("a refused model delete keeps its dialog, its sentence and the card the server still backs", async ({page,}) => {@@ -133,11 +142,13 @@ test("a refused model delete keeps its dialog, its sentence and the card the serawait confirm.getByRole("button", { name: "确认" }).click();// The write was refused: the server's words show, and both dialogs are still exactly as they- // were — the same model, the same sentence.- await expect(page.getByText("models store is closed")).toBeVisible();+ // were — the same model, the same sentence, with the refusal drawn under it (a toast used to+ // be the only place they showed, and it dismissed itself out of the card still on screen).+ await expect(confirm.getByText("models store is closed")).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);expect(puts).toHaveLength(1);await expect(confirm).toBeVisible();- expect(await confirm.innerText()).toBe(sentence);+ expect(await cardText(confirm)).toBe(sentence);await expect(page.getByRole("button", { name: "删除模型" })).toBeVisible();// The card is back on the page behind the dialog (the dialog's own title also carries the@@ -180,7 +191,7 @@ test("the retry after a refused model delete writes it, and only a written one cawait page.getByRole("button", { name: "删除模型" }).click();const confirm = confirmation(page);await confirm.getByRole("button", { name: "确认" }).click();- await expect(page.getByText("models store is closed")).toBeVisible();+ await expect(confirm.getByText("models store is closed")).toBeVisible();await expect(confirm).toBeVisible();expect(puts).toHaveLength(1);diff --git a/packages/web/e2e/models-save-refusal.spec.mjs b/packages/web/e2e/models-save-refusal.spec.mjsindex 3191b15a..e60ddc88 100644--- a/packages/web/e2e/models-save-refusal.spec.mjs+++ b/packages/web/e2e/models-save-refusal.spec.mjs@@ -136,6 +136,15 @@ function cardFor(page, name) {return page.getByText(name, { exact: true }).first().locator("xpath=ancestor::button[1]");}+/**+ * The card's own text with the refusal slot dropped: a refused write adds one line under the+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal is allowed to change —+ * the sentence, the list it names and the buttons must read exactly as they did before the write.+ */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}+test("a refused save keeps both dialogs and the name the server still holds", async ({ page }) => {const { read } = await projectWithModel(page, "r93save");@@ -155,12 +164,15 @@ test("a refused save keeps both dialogs and the name the server still holds", asawait refuseWrites(page, puts);await confirm.getByRole("button", { name: "确认" }).click();- // The write was refused: the server's words show, and both dialogs are still exactly as they- // were — the same sentence, the draft still in the field.- await expect(page.getByText("models store is closed")).toBeVisible();+ // The write was refused: the server's words show inside the confirmation — not in a toast,+ // which used to be their only home and dismissed itself out of the card still on screen —+ // and both dialogs are still exactly as they were: the same sentence, the draft still in the+ // field.+ await expect(confirm.getByText("models store is closed")).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);expect(puts).toHaveLength(1);await expect(confirm).toBeVisible();- expect(await confirm.innerText()).toBe(sentence);+ expect(await cardText(confirm)).toBe(sentence);await expect(nameInput).toHaveValue(RENAMED);await expect(page.getByRole("button", { name: "删除模型" })).toBeVisible();@@ -208,7 +220,7 @@ test("the retry of a refused save is the same confirmation, and only a written oawait dialog.getByRole("button", { name: "确认" }).click();const confirm = confirmation(page, "确定保存对");await confirm.getByRole("button", { name: "确认" }).click();- await expect(page.getByText("models store is closed")).toBeVisible();+ await expect(confirm.getByText("models store is closed")).toBeVisible();await expect(confirm).toBeVisible();expect(puts).toHaveLength(1);@@ -244,7 +256,7 @@ test("a refused set-as-default keeps both dialogs and the pointer the server stiawait refuseWrites(page, puts);await confirm.getByRole("button", { name: "确认" }).click();- await expect(page.getByText("models store is closed")).toBeVisible();+ await expect(confirm.getByText("models store is closed")).toBeVisible();expect(puts).toHaveLength(1);// Both dialogs stay up: the confirmation over the config dialog it was started from.await expect(page.getByRole("dialog")).toHaveCount(2);diff --git a/packages/web/e2e/models-sync-order.spec.mjs b/packages/web/e2e/models-sync-order.spec.mjsindex 794d8072..ace0a337 100644--- a/packages/web/e2e/models-sync-order.spec.mjs+++ b/packages/web/e2e/models-sync-order.spec.mjs@@ -89,6 +89,15 @@ async function refuseWrites(page, seen) {});}+/**+ * The card's own text with the refusal slot dropped: a refused write adds one line under the+ * sentence ("操作被拒绝:…"), and that line is the only thing the refusal is allowed to change —+ * the sentence, the list it names and the buttons must read exactly as they did before the write.+ */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}+test("a refused preset sync keeps its dialog, its sentence and the table the server has", async ({page,}) => {@@ -108,11 +117,14 @@ test("a refused preset sync keeps its dialog, its sentence and the table the serawait refuseWrites(page, puts);await dialog.getByRole("button", { name: "同步预置" }).click();- // The write was refused, and the dialog stays exactly as it was — same sentence, same list.- await expect(page.getByText("models store is closed")).toBeVisible();+ // The write was refused, and the dialog stays exactly as it was — same sentence, same list —+ // with the server's words added under it. They are in the card rather than in a toast that+ // dismissed itself six seconds later over the card the user is still looking at.+ await expect(dialog.getByText("models store is closed")).toBeVisible();+ await expect(page.getByRole("region", { name: "通知" }).getByRole("button")).toHaveCount(0);expect(puts).toHaveLength(1);await expect(dialog).toBeVisible();- expect(await dialog.innerText()).toBe(sentence);+ expect(await cardText(dialog)).toBe(sentence);// The server still holds the old table, and the page's own table agrees with it: the entry// the merge would have added is not there to be found, although the notice still names it.@@ -159,7 +171,7 @@ test("the retry after a refused sync writes the merge, and only a written one clawait page.getByRole("button", { name: "现在升级" }).click();const dialog = page.getByRole("dialog");await dialog.getByRole("button", { name: "同步预置" }).click();- await expect(page.getByText("models store is closed")).toBeVisible();+ await expect(dialog.getByText("models store is closed")).toBeVisible();await expect(dialog).toBeVisible();expect(puts).toHaveLength(1);diff --git a/packages/web/src/features/models/models-page.tsx b/packages/web/src/features/models/models-page.tsxindex 28a2c80f..00924fe8 100644--- a/packages/web/src/features/models/models-page.tsx+++ b/packages/web/src/features/models/models-page.tsx@@ -164,6 +164,8 @@ import {import type { GroupHeaderAction } from "./group-header";import { GroupBalance } from "./group-balance";import { isPinned, usePinnedBalance } from "./balance";+import { refusalOf } from "./write-outcome";+import type { WriteOutcome } from "./write-outcome";/*** The authorization flows a group's Connect dialog can run, keyed by the flow named in that@@ -849,6 +851,13 @@ export function ModelsPage() {const keyLanded = useRef(false);/** User-defined group (provider id) whose delete confirmation is open (built-in groups never offer this). */const [deleteGroupFor, setDeleteGroupFor] = useState<string | null>(null);+ /**+ * The words of the last refused group delete / preset sync, drawn inside that confirmation+ * (`refusal` on the card) so the reason is still there when the user presses retry. Cleared+ * when the confirmation opens again: a fresh attempt has not been refused yet.+ */+ const [deleteGroupRefusal, setDeleteGroupRefusal] = useState<string | null>(null);+ const [syncRefusal, setSyncRefusal] = useState<string | null>(null);/** "Add group" popup (user-defined group): create-only hands off to that group's add-model dialog, import mode fills the group from its endpoint (see AddGroupDialog). */const [addGroupOpen, setAddGroupOpen] = useState(false);/** "Add models with AI" dialog: the prompt goes to the Project's default agent. */@@ -905,12 +914,17 @@ export function ModelsPage() {* avoids the trap of "still have to click save after confirming". On failure, the error* is echoed back with the table the caller names (see `refusedRows`), so a retry starts* from something the server still holds rather than from a change it declined.+ *+ * The answer is a {@link WriteOutcome}, not a boolean: a refusal carries the server's words so+ * the caller can put them in the card that asked for the write (see `refusalOf`). They are not+ * raised as a toast here — the two call sites with no card still on screen add the toast+ * themselves, and every other one shows the reason where the retry button is.*/const persist = async (nextRows: RowState[],nextDefault: ModelRefDto | undefined,nextVision: ModelRefDto | undefined,- /** Success toast text (defaults to "saved"); on failure this function shows an error toast instead. */+ /** Success toast text (defaults to "saved"). */successText?: string,/*** The table to leave on the page when the write is refused. Default: the attempted rows,@@ -921,8 +935,10 @@ export function ModelsPage() {* still being in the table, and claims a change that did not happen.*/refusedRows?: RowState[],- ): Promise<boolean> => {- if (!projectId) return false;+ ): Promise<WriteOutcome> => {+ // Unreachable through the page (it renders nothing without a Project, and every caller is+ // behind that gate). The generic sentence is what a write that never left would report.+ if (!projectId) return { ok: false, reason: S.common.unknownError };setBusy(true);// The vision model pointer must point to a row that still exists and isn't marked "doesn't support images" (invalidated on delete/re-annotation).const effectiveVision =@@ -943,13 +959,12 @@ export function ModelsPage() {clearDraftModelRef(userId, projectId);}toastSuccess(successText ?? S.common.saved);- return true;+ return { ok: true };} catch (e) {setRows(refusedRows ?? nextRows);if (nextDefault !== undefined) setDefaultModel(nextDefault);if (effectiveVision !== undefined) setVisionModel(effectiveVision);- toastError(apiErrorText(e));- return false;+ return { ok: false, reason: apiErrorText(e) };} finally {setBusy(false);}@@ -976,11 +991,13 @@ export function ModelsPage() {* install has them, and local additions are untouched — see catalog-sync.ts). No-op with a* toast when everything is already up to date.*- * Returns whether the table in hand now matches what the catalog holds — `true` for the no-op- * too. The notice's confirmation keeps itself open until then.+ * Returns what the write answered — `ok` for the no-op too, since the table in hand then+ * matches the catalog. The notice's confirmation keeps itself open until then and draws the+ * refusal inside itself; the toolbar button that runs the same merge has no card to draw it+ * in, so that caller raises the toast (`refusalOf`).*/- const syncPresets = async (): Promise<boolean> => {- if (!rows) return false;+ const syncPresets = async (): Promise<WriteOutcome> => {+ if (!rows) return { ok: false, reason: S.common.unknownError };const merged = syncRowsWithCatalog(rows);if (merged.added === 0 && merged.updated === 0) {toastInfo(S.models.syncUpToDate);@@ -989,7 +1006,7 @@ export function ModelsPage() {// of. Without it the notice keeps offering a button that can only answer "already// up to date" — a loop the user gets out of only by dismissing or reloading.refreshProjectTodos(projectId);- return true;+ return { ok: true };}// A refused write takes the merge back off the screen. `persist` keeps the attempted rows// for a field edit the user is still holding, but a preset sync is a batch the catalog@@ -998,18 +1015,18 @@ export function ModelsPage() {// anything while the notice still names every missing entry (measured on a refused write:// the retry produced no PUT at all and the server kept its old table).const before = rows;- const saved = await persist(+ const outcome = await persist(merged.rows,defaultModel,visionModel,S.models.syncDone(merged.added, merged.updated),);- if (!saved) setRows(before);+ if (!outcome.ok) setRows(before);// The Models nav badge is gated on the SAVED table, which this page holds only as row// state: re-probe it so the dot goes down on the server's answer rather than on the// assumption that the write covered everything the catalog offered.refreshProjectTodos(projectId);- return saved;+ return outcome;};const syncPlatformModels = async () => {@@ -1087,6 +1104,9 @@ export function ModelsPage() {* attempted rows on screen (right for a field edit the user is still holding), which* here would show the whole group as if it existed and make the dialog's own name check* report the name as taken on the retry.+ *+ * The refusal is raised as a toast: the add-group dialog closes the moment the import lands+ * and keeps its own fields, so there is no card here to carry the server's words.*/const importGroup = async (nextRows: RowState[],@@ -1096,13 +1116,14 @@ export function ModelsPage() {): Promise<boolean> => {if (!projectId) return false;const before = rows;- const ok = await persist(+ const outcome = await persist(nextRows,defaultModel,visionModel,S.models.groupImported(added, skipped),);- if (!ok) {+ if (!outcome.ok) {+ toastError(outcome.reason);setRows(before);return false;}@@ -1357,7 +1378,11 @@ export function ModelsPage() {disabled={busy}aria-label={`${S.models.deleteGroup} ${provider.label}`}title={S.models.deleteGroup}- onClick={() => setDeleteGroupFor(group.provider.id)}+ onClick={() => {+ setDeleteGroupFor(group.provider.id);+ // A new attempt, not the one that was refused: the card opens with no reason in it.+ setDeleteGroupRefusal(null);+ }}><GlyphIcon d={ICONS.trash} size={ICON_SIZE.groupHeaderAction} /><span className={HEADER_LABEL}>{S.models.deleteGroup}</span>@@ -1435,7 +1460,11 @@ export function ModelsPage() {}actionLabel={S.todo.updateNow}busy={syncing}- onAction={() => setSyncConfirmOpen(true)}+ onAction={() => {+ setSyncConfirmOpen(true);+ // A new attempt, not the one that was refused: the card opens with no reason in it.+ setSyncRefusal(null);+ }}dismissLabel={S.todo.dismiss}onDismiss={() => dismissTodo(projectId, "models", todo.signature)}/>@@ -1631,15 +1660,18 @@ export function ModelsPage() {const nextRows = rows.map((r) =>r.provider === target ? { ...r, apiKeyInput: key, clearApiKey: false } : r,);- // Success toast is shown inside persist (with "configured N" text); on failure- // only an error toast is shown, no false success report (persist swallows the- // error and doesn't reject, so a .then can't unconditionally report success).+ // Success toast is shown inside persist (with "configured N" text); a refusal is+ // raised here because this dialog closes on submit and has nothing left to draw it+ // in (no false success report either — persist swallows the error, so a .then can't+ // unconditionally report success).void persist(nextRows,defaultModel,visionModel,S.models.groupKeyApplied(affected.length),- );+ ).then((outcome) => {+ if (!outcome.ok) toastError(outcome.reason);+ });}}/>)}@@ -1719,19 +1751,26 @@ export function ModelsPage() {// the only way back to this action, goes with it, so the retry needs a reload// (measured on a refused write: dialog gone, no `probegroup` anywhere on the page,// 2 rows still on the server). Keeping the confirmation means the retry is the same- // click, against the sentence whose count the restored rows still match.+ // click, against the sentence whose count the restored rows still match — and the+ // server's own words for the refusal sit inside it (`refusal`), not in a toast that+ // would have dismissed itself long before the retry.void persist(before.filter((r) => r.provider !== target),defaultModel?.provider === target ? undefined : defaultModel,visionModel?.provider === target ? undefined : visionModel,S.models.groupDeleted(removed.length),- ).then((saved) => {- if (saved) setDeleteGroupFor(null);- else setRows(before);+ ).then((outcome) => {+ if (outcome.ok) {+ setDeleteGroupFor(null);+ return;+ }+ setDeleteGroupRefusal(refusalOf(outcome));+ setRows(before);});}}confirmLabel={S.common.confirm}cancelLabel={S.common.cancel}+ refusal={deleteGroupRefusal === null ? undefined : S.common.refused(deleteGroupRefusal)}><p className="text-sm text-gray-700 dark:text-gray-300">{/* Offered on user-defined groups only, whose display info is always synthesized. */}@@ -1762,13 +1801,15 @@ export function ModelsPage() {// Only a written merge dismisses the dialog. A refused one keeps the sentence and// the list of refs it names, so the retry is this same confirmation — the table// behind it has been put back, and finding the notice again to start over is work- // the failure does not justify.+ // the failure does not justify. The refusal's words stay in the card (`refusal`).void syncPresets()- .then((saved) => {- if (saved) setSyncConfirmOpen(false);+ .then((outcome) => {+ if (outcome.ok) setSyncConfirmOpen(false);+ else setSyncRefusal(refusalOf(outcome));}).finally(() => setSyncing(false));}}+ refusal={syncRefusal === null ? undefined : S.common.refused(syncRefusal)}><div className="space-y-3"><p className="text-sm text-gray-600 dark:text-gray-300">{S.models.syncCatalogHint}</p>@@ -1883,9 +1924,9 @@ export function ModelsPage() {sameModelRef(removed, visionModel) ? undefined : visionModel,undefined,before,- ).then((saved) => {- if (saved) closeModelDialog();- return saved;+ ).then((outcome) => {+ if (outcome.ok) closeModelDialog();+ return outcome;});}const nextRows = isNew@@ -1911,14 +1952,14 @@ export function ModelsPage() {const beforeDefault = defaultModel;const beforeVision = visionModel;return persist(nextRows, ptr.defaultModel, ptr.visionModel, undefined, before).then(- (saved) => {- if (saved) {+ (outcome) => {+ if (outcome.ok) {closeModelDialog();- return true;+ return outcome;}setDefaultModel(beforeDefault);setVisionModel(beforeVision);- return false;+ return outcome;},);}}@@ -2513,14 +2554,15 @@ function ModelDialog({/** Closes the dialog and runs the header's "sync presets" merge; absent for a member, who cannot write the config. */onSyncPresets?: () => void;/**- * Commit one action and report whether its write landed. Every action answers now: this+ * Commit one action and report what its write answered. Every action answers now: this* dialog and its confirmation stay up until the answer arrives, so a refused save, a* refused "set as default / as vision proxy" and a refused delete all keep their sentence* and their retry where the user left them. Only a written change closes them (the page- * does that for the actions it owns). `void` stays in the type for a caller with nothing- * to wait for.+ * does that for the actions it owns); a refusal also carries the server's words, which the+ * confirmation draws in its `refusal` slot. `void` stays in the type for a caller with+ * nothing to wait for.*/- onSubmit: (row: RowState, action: DialogAction) => Promise<boolean> | void;+ onSubmit: (row: RowState, action: DialogAction) => Promise<WriteOutcome> | void;}) {// Pricing input is displayed/entered in the current currency; converted back to USD storage on submit (RowState always stores USD).const [form, setForm] = useState<RowState>(() => {@@ -2589,6 +2631,21 @@ function ModelDialog({* (Adding a new custom model isn't confirmed: opening the dialog is itself a clear intent.)*/const [confirming, setConfirming] = useState<DialogAction | null>(null);+ /**+ * The server's words for the last refused write, drawn in the confirmation's `refusal` slot.+ * It lives with the confirmation rather than with the page because that card is what the user+ * is looking at while they retry: the reason has to survive the toast that would otherwise be+ * the only trace of it (a toast dismisses itself after six seconds, over the card, not in it).+ */+ const [refusal, setRefusal] = useState<string | null>(null);+ /**+ * Open the confirmation for one action, without the previous refusal: that sentence belonged+ * to the write that was refused, and a confirmation opened now has not been tried yet.+ */+ const confirm = (action: DialogAction) => {+ setRefusal(null);+ setConfirming(action);+ };/*** The confirmed write is on the wire: its confirmation waits for the answer instead of* closing on the click, and its buttons are locked so a second click cannot fire a rival@@ -3044,10 +3101,14 @@ function ModelDialog({// "set as default" used to take this dialog and its confirmation down with the request,// so the sentence that named the change was gone and the only way to retry was to find// the card again (and the page behind it showed the change the server had refused).- // Keeping both until the answer arrives makes the retry the same click.+ // Keeping both until the answer arrives makes the retry the same click, and the answer+ // brings the server's words with it, which the confirmation then shows beside that click.+ setRefusal(null);setWriting(true);try {- if (await written) setConfirming(null);+ const outcome = await written;+ if (outcome.ok) setConfirming(null);+ else setRefusal(refusalOf(outcome));} finally {setWriting(false);}@@ -3272,7 +3333,7 @@ function ModelDialog({toastInfo(S.common.noChangesToSave);return;}- setConfirming("save");+ confirm("save");}}>{detecting ? S.models.detecting : S.common.confirm}@@ -3375,7 +3436,7 @@ function ModelDialog({{testing ? S.models.testing : S.models.testConnection}</Button>{!isNew && !isDefault && (- <Button size="sm" onClick={() => setConfirming("setDefault")}>+ <Button size="sm" onClick={() => confirm("setDefault")}>{S.models.setDefault}</Button>)}@@ -3385,7 +3446,7 @@ function ModelDialog({title={S.models.visionModelHint}// The hint says what setting this model as the vision one does, which its label cannot.data-tooltip-extra- onClick={() => setConfirming("setVisionModel")}+ onClick={() => confirm("setVisionModel")}>{S.models.setVisionModel}</Button>@@ -3393,7 +3454,7 @@ function ModelDialog({{!isNew && (<><span className="min-w-0 flex-1" />- <Button size="sm" variant="danger" onClick={() => setConfirming("remove")}>+ <Button size="sm" variant="danger" onClick={() => confirm("remove")}>{S.models.remove}</Button></>@@ -3846,6 +3907,9 @@ function ModelDialog({}}confirmLabel={S.common.confirm}cancelLabel={S.common.cancel}+ // A refused write's words, inside the card that asked for it: the toast they used to+ // ride on dismissed itself, and the retry is the button right below this line.+ refusal={refusal === null ? undefined : S.common.refused(refusal)}><p className="text-sm text-gray-700 dark:text-gray-300">{CONFIRM_BODY[confirming](modelLabel)}diff --git a/packages/web/src/features/models/write-outcome.ts b/packages/web/src/features/models/write-outcome.tsnew file mode 100644index 00000000..b1ad38d7--- /dev/null+++ b/packages/web/src/features/models/write-outcome.ts@@ -0,0 +1,19 @@+/**+ * What a confirmed write in the model library answered (`persist` in models-page.tsx).+ *+ * Only a written change (`ok`) dismisses the confirmation that asked for it; a refusal carries the+ * server's own words back to that confirmation, which draws them beside its retry button. The+ * reason used to be raised as a toast alone — the same sentence, in a box that dismisses itself+ * after six seconds and sits over the dialog rather than in it, so the one thing the user needs+ * while retrying was also the first thing to leave.+ *+ * The words are the caller's to place: a call site with a card still on screen hands them to that+ * card, and the two that have none (a group key written from a dialog that closes on submit, the+ * presets sync started from the toolbar) keep the toast.+ */+export type WriteOutcome = { ok: true } | { ok: false; reason: string };++/** The refusal's words, or `null` for a written change: the single branch every call site reads. */+export function refusalOf(outcome: WriteOutcome): string | null {+ return outcome.ok ? null : outcome.reason;+}diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 29bca9aa..89d8801d 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -1122,6 +1122,11 @@ export const en: Strings = {none: "(none)",retry: "Retry",unknownError: "Request failed, please try again later",+ /**+ * Lead-in for a write the server refused, in the card that asked for it: the reason is the+ * server's own sentence, so the card has to say what that sentence is about.+ */+ refused: (reason: string) => `Refused: ${reason}`,requiredField: "This field is required",/** A menu row that copies what it acts on (the conversation's selection menu); the confirmation is `copied`. */copy: "Copy",diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 4e2ea820..de8562b0 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -1170,6 +1170,12 @@ export const zh = {none: "(无)",retry: "重试",unknownError: "请求失败,请稍后重试",+ /**+ * Lead-in for a write the server refused, in the card that asked for it: the reason is the+ * server's own sentence, so the card needs to say what that sentence is about. «被拒绝» is the+ * library's own word for a refused write (the dialogs keep themselves open on one).+ */+ refused: (reason: string) => `操作被拒绝:${reason}`,requiredField: "此项必填",/** A menu row that copies what it acts on (the conversation's selection menu); the confirmation is `copied`. */copy: "复制",diff --git a/packages/web/test/models-write-outcome.test.ts b/packages/web/test/models-write-outcome.test.tsnew file mode 100644index 00000000..8fcbb213--- /dev/null+++ b/packages/web/test/models-write-outcome.test.ts@@ -0,0 +1,26 @@+/**+ * The model library's write verdict (features/models/write-outcome.ts): a refusal carries the+ * server's words to the card that asked for the write, a written change carries nothing.+ */+import { describe, expect, it } from "vitest";+import { refusalOf } from "../src/features/models/write-outcome";+import type { WriteOutcome } from "../src/features/models/write-outcome";++describe("write outcome", () => {+ it("hands a refusal's words to the card, and only the refusal", () => {+ expect(refusalOf({ ok: false, reason: "models store is closed" })).toBe(+ "models store is closed",+ );+ });++ it("says nothing to place for a written change", () => {+ expect(refusalOf({ ok: true })).toBeNull();+ });++ it("keeps the words as the server gave them", () => {+ // The reason is shown, not re-worded: every call site renders exactly this string.+ const reason = "分组 probegroup 仍然有 2 个模型,不能删除";+ const outcome: WriteOutcome = { ok: false, reason };+ expect(refusalOf(outcome)).toBe(reason);+ });+});