dsh-progress-union 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  本项目的所有值得记录的变更都写在这里。版本号遵循语义化版本。
4
4
 
5
+ ## 0.8.1 (2026-12-04)
6
+
7
+ **feat(ops):降级链从「只能手写 cordis.patch.yml」改成设置面直接编。**
8
+
9
+ 0.8.0 把介入范围收紧成白名单是对的方向,但设置面只给了两个文本框(主路由 provider/model)+ 一个开关,`ops.fallbacks` 整条降级链仍然只能去 profile 的 yml 里手写 —— 用户看得到设置面却改不动链,实际等于「配置由代理/开发者代手写」。本次把整条链搬进面板,形态照 dsh-prime-memory 的「全局默认链」。
10
+
11
+ - **链编辑器(设置页「LLM 操作与队列提醒」卡内)**:统一列表,第 1 行是主路由(挂「主」标签),其后为有序回退链;每行两个下拉(供应商 / 模型)加上移、下移、删除,底部「+ 添加回退路由」与「清空链」,再挂一行「实际链」只读预览(带 本地 / 云端 标注,与动板时的裁决同一口径)。链长上限 6 行(含主路由),到顶禁用添加。
12
+ - **整链一次提交**:`routeProvider` + `routeModel` + `fallbacks` 三个键同批写入,不留「主路由已改、降级链还是旧的」的半截状态;不成对的行(只选供应商没选模型)不入库。无 `mutate` 写面时直接告知去 yml 改,不开「整组铺回」的分支(那条路 0.7.5 实测被 `settings/rejected` 拒)。
13
+ - **新路由 `GET /ops/catalog`**:供应商目录走宿主 `llm.listProviders()`(同步/Promise 两态都吃),模型清单走逐家 `llm.listModels(provider)`,带 4s 限时与 60s TTL 缓存;**报错或超时不进缓存**(下次开卡重试,不把一次故障长挂一分钟)。目录缺失时该行降级为手输框(回执 `modelsAvailable:false`);当前值不在目录里时补一个「不在册」选项回显,不静默消失。
14
+ - **`ops.fallbacks` 改为 `.volatile()`**:宿主成文规则(`vendor/schemastery/src/index.ts:481-496`)允许数组作 volatile 值,只要在固定对象路径上且外面没有包着别的 volatile;本键位于 `ops.fallbacks` 且 `ops` 节本身未标,因此合法。本仓写面闸 `test/settings.test.mjs` 原本只扫 `switchInput/textInput/...` 的调用点,扫不到直接拼 `path: [...]` 字面量的新写点 —— 本次一并补上采集器,并把「fallbacks 必须 volatile、ops 节不得被标 volatile、不得整组铺回」钉成回归闸。
15
+ - 配置键与默认值不变,手写 yml 这条路照常有效(上一版已钉定的 profile 无需迁移);`GET /ops/providers` 响应形状不变,新增路由只给设置面用。
16
+
5
17
  ## 0.8.0 (2026-12-04)
6
18
 
7
19
  **feat(ops):介入范围改为配置白名单(主路由 + 有序降级链);未钉定一律 403,不再静默沿用宿主主模型烧高价 token。**
package/README.md CHANGED
@@ -309,12 +309,12 @@ npm test # node --test test/*.test.mjs(246 用例,纯 mock ctx,无需宿
309
309
  - **按指令改板**:一句自然语言翻成 add/edit/remove/`order` 排序。
310
310
  - **问询**:只回文本,模型硬塞 `changes` 也不写板。
311
311
 
312
- **介入范围 = 配置白名单(v0.8.0)**。哪些模型能动这块板,只由三个键决定:
312
+ **介入范围 = 配置白名单(v0.8.0)**。哪些模型能动这块板,只由四个键决定(**v0.8.1 起四个都能在设置面编**,不再需要手写 yml):
313
313
 
314
314
  | 键 | 作用 | 默认 |
315
315
  |---|---|---|
316
- | `ops.routeProvider` / `ops.routeModel` | 主路由,两者都填才算钉定;走宿主已注册渠道(registered) | `''` = 未钉定 |
317
- | `ops.fallbacks[]` | 有序降级链,元素 `{provider, model}`;缺 provider/model 的条目剔除,与主路由同串的剔除 | `[]` |
316
+ | `ops.routeProvider` / `ops.routeModel` | 主路由(链编辑器第 1 行),两者都填才算钉定;走宿主已注册渠道(registered) | `''` = 未钉定 |
317
+ | `ops.fallbacks[]` | 有序降级链(编辑器第 2 行起),元素 `{provider, model}`;缺 provider/model 的条目剔除,与主路由同串的剔除 | `[]` |
318
318
  | `ops.preferLocal` | 链上同时有本地与云端候选时,把**按名字判定**的本地路由排到链首(只重排、不删、不裁决) | `true` |
319
319
 
320
320
  - **未钉定即 403**:链为空时 refine/mutate/ask 一律 403,**不会退回宿主主模型**(旧行为是静默沿用 `assistant.*` 与宿主当前选择,那往往就是最贵的云端旗舰)。`GET /ops/providers` 同时报 `unconfigured:true`,面板把三个按钮与输入一起禁用,并在块内给一行「该去哪配」的引导,而不是给一堆禁用下拉。
@@ -333,7 +333,13 @@ npm test # node --test test/*.test.mjs(246 用例,纯 mock ctx,无需宿
333
333
 
334
334
  **整块开关 `ops.enabled`(v0.7.2,默认开)**:关掉后 `GET /ops/providers` 直接报 `disabled:true`,客户端据此把「LLM 操作」块整块收起(不是一堆禁用按钮,也不是报错);`POST /ops` 的 refine / mutate / ask 一律 **403**,唯独 `op:"validate"` 这条路由照常 200 —— 它是零 token 的本地板面体检,与花不花钱无关(v0.7.9 后面板上已无此按钮,路由只为外部消费者与单测保留)。该键与 `download.*` / `toolGloss.*` / `notifyMajorChanges` 同级:逐叶子 `.volatile()`、`DEFAULT_CONFIG.ops`、`flatSection('ops', …)` 三处齐全。表单入口从 **v0.7.5** 起真的存在(见下一节);开关关掉时服务端的 403 / `disabled` 判定是即时的,客户端块的隐去靠一次轮询重探(最多 15s),无需重加载页面。
335
335
 
336
- 模型选择面从 **v0.8.0** 起归本插件自己:`ops.routeProvider` / `ops.routeModel` / `ops.preferLocal` 三个叶子都是 volatile,设置页「LLM 操作与队列提醒」卡里有对应输入行与开关(上一段旧说法「不提供 defaultProvider/defaultModel 覆盖、由宿主选择器承担」已被本次改判推翻 —— 当时担心的是第二套模型配置面,而真机证明「沿用宿主选择」的实际后果是默认拉到付费旗舰)。`ops.fallbacks` 是数组,仍只走 `cordis.patch.yml`:
336
+ 模型选择面从 **v0.8.0** 起归本插件自己(上一段旧说法「不提供 defaultProvider/defaultModel 覆盖、由宿主选择器承担」已被本次改判推翻 —— 当时担心的是第二套模型配置面,而真机证明「沿用宿主选择」的实际后果是默认拉到付费旗舰)。
337
+
338
+ **v0.8.1:整条链改在设置面里编。**形态照 dsh-prime-memory 的「全局默认链」:设置页「LLM 操作与队列提醒」卡内是一张统一列表 —— 第 1 行主路由、其后为有序回退链,每行两个下拉(供应商 / 模型)加上移、下移、删除,底部「+ 添加回退路由」与「清空链」,再挂一行「实际链」只读预览(带 本地 / 云端 标注,与动板时的裁决同一口径)。一次改动提交 `routeProvider` + `routeModel` + `fallbacks` 三个键,不留「主路由已改、降级链还是旧的」的半截状态;不成对的行(只选了供应商没选模型)不入库。链长上限 6 行(含主路由),到顶后添加按钮禁用。
339
+
340
+ 候选数据源是新增的 `GET /ops/catalog`:供应商目录走宿主 `llm.listProviders()`,模型清单走逐家 `llm.listModels(provider)`(内置适配器读本地快照不触网,仍加 4s 限时与 60s TTL 缓存)。**该家不供清单、报错或超时时,那一行降级为手输框**(回执里带 `modelsAvailable:false`)—— 只给下拉会让不供列表的第三方适配器把整个编辑器填不了。当前值不在目录里(手写配置、或该渠道刚被删)时也会补一个标着「不在册」的选项回显,不让它静默消失。
341
+
342
+ `ops.fallbacks` 也标了 `.volatile()`(宿主成文规则:数组可以作为 volatile 值,只要在固定对象路径上且外面没包着别的 volatile;`ops` 节本身未标,所以 `ops.fallbacks` 合法)。写入必须走 `scope.mutate` 的叶路径,嵌套组整组铺回仍会被 `settings/rejected` 拒。手写 yml 这条路照常有效(数组本来就只能这么维护),例:
337
343
 
338
344
  ```yaml
339
345
  - id: dsh-progress-union
@@ -351,7 +357,7 @@ npm test # node --test test/*.test.mjs(246 用例,纯 mock ctx,无需宿
351
357
  设置页里的「进度板」分节(宿主把本插件的 composition entry 直接当成一个独立设置节,导航文案 = `setTitle`)现在共 6 组:除原有的辅助 LLM / 观察者 / 官方 todo 同步外,新增两张:
352
358
 
353
359
  - **下载感知与工序**:`download.enabled`(关掉即观察块不出 `⬇` 行、快照 `download.active` 恒为 false)、`download.showSubBar`(不再下发 download 字段)、`download.markBackground`(后台徽标)、`download.ttlMs`(一次下载算「还在跑」的窗口),以及 `toolGloss.enabled` / `toolGloss.softNarrate` / `toolGloss.maxLen`(关掉后「最近动作」逐字退回 0.6.x 的 `name×count`)。
354
- - **LLM 操作与队列提醒**:`ops.enabled`(整块开关)与 `notifyMajorChanges`(结构性变更是否落输入队列)。
360
+ - **LLM 操作与队列提醒**:`ops.enabled`(整块开关)、**模型路由链编辑器**(v0.8.1:主路由 + 有序降级链,行级下拉/增删/排序)与 `notifyMajorChanges`(结构性变更是否落输入队列)。
355
361
 
356
362
  开关类拨完即落盘,数字类进草稿、点「保存」提交。**v0.7.6 前这里全是坏的**:宿主 `ConfigForm.set(field, value)` 只支持**顶层标量**(它把 path 拼成单段 `[field]`),而 `isVolatilePath` 对 `path:["ops"]` 要的是组对象自己带 volatile——本插件按表单生成规则只在**叶子**上标,所以嵌套组的整对象写回一律 `settings/rejected: Config field "ops" is not volatile`(UI 表现为「保存失败」+「有未保存的改动」)。现在嵌套组走 `scope.mutate([{ op:'set', path:[group, key], value }])` 的**叶路径**(老宿主无 `mutate` 时才退回整组 `set`);`test/settings.test.mjs` 把「设置卡实写的每条路径 ∈ volatile 叶子」钉成回归闸。**v0.7.7** 再把脏位改成「草稿值 ≠ 存值」——开关拨完即落盘,快照追平后不该再算未保存(否则「已保存」与「有未保存的改动」会并存,「保存」永远可点、还会重写同值)。
357
363
 
package/client.js CHANGED
@@ -24,7 +24,7 @@ window.__ModuleLoader__.load({
24
24
  var REPO_URL = "https://github.com/drscrewdriver/dsh-progress-union";
25
25
  var STAR_NS = "progress-union";
26
26
  var STAR_GEN = "v4"; /* ladder:gen */
27
- var STAR_VERSION = "0.8.0"; /* ladder:ver */
27
+ var STAR_VERSION = "0.8.1"; /* ladder:ver */
28
28
  var LANGS = ["zh", "en", "ja", "ko", "fr", "de", "it", "ru", "es", "pt"];
29
29
 
30
30
  // 三代共享:GitHub 单色 mark(octicon 轮廓,fill 随 currentColor)。
@@ -442,7 +442,7 @@ window.__ModuleLoader__.load({
442
442
  opsLocalTag: '本地',
443
443
  opsCloudTag: '云端',
444
444
  opsRouteDowngraded: '已降级到链上第 N 条路由',
445
- opsUnconfigured: '未钉定模型路由:三个动作都不会调用模型。请在「设置 → 进度板 → LLM 操作」填主路由的 provider/model(降级链 ops.fallbacks 在 cordis.patch.yml 里配)。',
445
+ opsUnconfigured: '未钉定模型路由:三个动作都不会调用模型。请在「设置 → 进度板 → LLM 操作」的路由链里添加主路由与回退行。',
446
446
  setTitle: '进度板',
447
447
  setLlmGroup: '辅助 LLM(监控/审查)',
448
448
  setLlmHint: '选「已注册」复用 Settings→模型 里的 provider/model(走宿主 llm.stream,免密钥);「直连」打自建 OpenAI 兼容端点。仅在进度板滞后时触发,每回合至多一次。',
@@ -495,14 +495,26 @@ window.__ModuleLoader__.load({
495
495
  setGlossMaxLen: '工序句上限(字)',
496
496
  setOpsGroup: 'LLM 操作与队列提醒',
497
497
  setOpsBadge: '操作',
498
- setOpsHint: '关掉即侧边栏「LLM 操作」整块收起:细化/改板/问询返回 403。v0.8.0 起介入范围由白名单决定:只有下面钉定的主路由(加 cordis.patch.yml 里的 ops.fallbacks)能动板;未钉定时三个动作一律 403,不会退回宿主主模型去烧高价 token。板面体检随每次回答自动跑,输出不合格直接打回重问。',
498
+ setOpsHint: '关掉即侧边栏「LLM 操作」整块收起:细化/改板/问询返回 403。介入范围由白名单决定:只有下面路由链里显式写出的模型能动板;链为空时三个动作一律 403,不会退回宿主主模型去烧高价 token。板面体检随每次回答自动跑,输出不合格直接打回重问。',
499
499
  setOpsEnabled: '开放 LLM 任务操作',
500
- setOpsRouteProvider: '主路由 provider',
501
- setOpsRouteProviderHint: '宿主已注册渠道名(白名单,不填则 ops 一律 403)',
502
- setOpsRouteModel: '主路由 model',
500
+ setOpsChain: '模型路由链',
501
+ setOpsChainHint: '第 1 行是主路由,其后为有序降级链(每条各享全额超时,前一条不通才走下一条)。改完即时落盘,无需重启。',
502
+ setOpsChainPrimary: '主',
503
+ setOpsChainProvider: '选择供应商',
504
+ setOpsChainProviderManual: '供应商名(手输)',
505
+ setOpsChainModel: '选择模型',
506
+ setOpsChainModelManual: '模型 id(手输)',
507
+ setOpsChainAdd: '+ 添加回退路由',
508
+ setOpsChainClear: '清空链',
509
+ setOpsChainMax: '链最长 N 行(含主路由)',
510
+ setOpsChainEffective: '实际链(保存后更新)',
511
+ setOpsChainUnlisted: '不在册',
512
+ setOpsChainEmpty: '链为空:三个动作都不会调用模型(403)。',
513
+ setOpsChainUp: '上移',
514
+ setOpsChainDown: '下移',
515
+ setOpsChainRemove: '删除该行',
503
516
  setOpsPreferLocal: '本地候选优先',
504
- setOpsPreferLocalHint: '只把按名字判定的本地路由排到链首,不参与裁决;关掉则严格按配置顺序。',
505
- setOpsFallbackNote: '降级链 ops.fallbacks 是数组,不在本表单编辑:请在 profile 的 cordis.patch.yml 里配 ops.fallbacks: [{provider, model}]。',
517
+ setOpsPreferLocalHint: '只把按名字判定的本地路由排到链首,不参与裁决;关掉则严格按链上顺序。',
506
518
  setNotifyMajor: '结构性变更落输入队列(黄档)',
507
519
  setNotifyMajorHint: '增删/重排任务时往队列插一条提醒,让模型先对齐板面;纯状态刷新不触发。',
508
520
  setSaved: '已保存',
@@ -670,7 +682,7 @@ window.__ModuleLoader__.load({
670
682
  opsLocalTag: 'local',
671
683
  opsCloudTag: 'cloud',
672
684
  opsRouteDowngraded: 'Fell back to chain route N',
673
- opsUnconfigured: 'No model route pinned: none of the three actions will call a model. Set the primary provider/model under Settings → Progress board → LLM actions (the ops.fallbacks chain lives in cordis.patch.yml).',
685
+ opsUnconfigured: 'No model route pinned: none of the three actions will call a model. Add a primary route and fallback rows under Settings → Progress board → LLM actions.',
674
686
  setTitle: 'Progress board',
675
687
  setLlmGroup: 'Assistant LLM (monitor/audit)',
676
688
  setLlmHint: 'Pick "Registered" to reuse a provider/model from Settings → Models (via host llm.stream, no API key), or "Direct" for a self-hosted OpenAI-compatible endpoint. Runs only while the board is overdue, at most once per turn.',
@@ -723,14 +735,26 @@ window.__ModuleLoader__.load({
723
735
  setGlossMaxLen: 'Max gloss length (chars)',
724
736
  setOpsGroup: 'LLM actions & queue notices',
725
737
  setOpsBadge: 'Actions',
726
- setOpsHint: 'Off collapses the sidebar “LLM actions” block: refine/mutate/ask return 403. Since v0.8.0 the scope is an allowlist — only the primary route pinned below (plus ops.fallbacks in cordis.patch.yml) may touch the board; with nothing pinned all three actions return 403 instead of silently using the main model of the host. The board check runs on every reply, and non-conforming output is rejected and asked again.',
738
+ setOpsHint: 'Off collapses the sidebar “LLM actions” block: refine/mutate/ask return 403. The scope is an allowlist — only routes explicitly listed in the chain below may touch the board; with an empty chain all three actions return 403 instead of silently using the main model of the host. The board check runs on every reply, and non-conforming output is rejected and asked again.',
727
739
  setOpsEnabled: 'Allow LLM board actions',
728
- setOpsRouteProvider: 'Primary provider',
729
- setOpsRouteProviderHint: 'A host-registered provider name (allowlist; empty means ops returns 403)',
730
- setOpsRouteModel: 'Primary model',
740
+ setOpsChain: 'Model route chain',
741
+ setOpsChainHint: 'Row 1 is the primary route; the rest is the ordered fallback chain (each entry gets the full timeout and is only tried after the previous one fails). Saved live, no restart needed.',
742
+ setOpsChainPrimary: 'Main',
743
+ setOpsChainProvider: 'Select provider',
744
+ setOpsChainProviderManual: 'Provider name (manual)',
745
+ setOpsChainModel: 'Select model',
746
+ setOpsChainModelManual: 'Model id (manual)',
747
+ setOpsChainAdd: '+ Add fallback route',
748
+ setOpsChainClear: 'Clear chain',
749
+ setOpsChainMax: 'Chain capped at N rows (primary included)',
750
+ setOpsChainEffective: 'Effective chain (updates after save)',
751
+ setOpsChainUnlisted: 'not registered',
752
+ setOpsChainEmpty: 'Empty chain: none of the three actions will call a model (403).',
753
+ setOpsChainUp: 'Move up',
754
+ setOpsChainDown: 'Move down',
755
+ setOpsChainRemove: 'Remove this row',
731
756
  setOpsPreferLocal: 'Prefer local candidates',
732
757
  setOpsPreferLocalHint: 'Only reorders name-detected local routes to the head of the chain; it never vetoes a route. Off keeps the configured order.',
733
- setOpsFallbackNote: 'The ops.fallbacks chain is an array and is not editable in this form: set ops.fallbacks: [{provider, model}] in the profile cordis.patch.yml.',
734
758
  setNotifyMajor: 'Route structural changes into the input queue (yellow tier)',
735
759
  setNotifyMajorHint: 'Inserts one queue message on add/remove/reorder so the model re-aligns the board; pure status refreshes never trigger it.',
736
760
  setSaved: 'Saved',
@@ -2464,6 +2488,15 @@ window.__ModuleLoader__.load({
2464
2488
  .dsu-input, .dsu-select { flex: 1; min-width: 0; padding: 7px 10px; font: inherit; font-size: 12px; color: inherit; background: var(--dsw-alias-bg-base, rgba(255,255,255,.04)); border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.3)); border-radius: 8px; outline: none; transition: border-color .15s, box-shadow .15s; }
2465
2489
  .dsu-input:focus, .dsu-select:focus { border-color: #2f6fed; box-shadow: 0 0 0 3px rgba(47,111,237,.14); }
2466
2490
  .dsu-input[disabled] { opacity: .6; }
2491
+ .dsu-chain { display: grid; gap: 8px; min-width: 0; }
2492
+ .dsu-chain-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 6px; align-items: center; }
2493
+ .dsu-chain-idx { font-size: 11px; opacity: .7; text-align: center; white-space: nowrap; }
2494
+ .dsu-chain-tools { display: flex; gap: 4px; }
2495
+ .dsu-chain-btn { font: inherit; font-size: 11px; padding: 4px 8px; border-radius: 7px; border: 1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.3)); background: transparent; color: inherit; cursor: pointer; white-space: nowrap; }
2496
+ .dsu-chain-btn:hover:not([disabled]) { background: rgba(128,128,128,.1); }
2497
+ .dsu-chain-btn[disabled] { opacity: .45; cursor: default; }
2498
+ .dsu-chain-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
2499
+ .dsu-chain-eff { font-size: 11px; line-height: 1.6; opacity: .72; word-break: break-all; }
2467
2500
  .dsu-unit { flex: none; font-size: 11px; opacity: .6; min-width: 18px; }
2468
2501
  .dsu-switch { position: relative; display: inline-flex; width: 38px; height: 21px; flex: none; }
2469
2502
  .dsu-switch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
@@ -2595,6 +2628,170 @@ window.__ModuleLoader__.load({
2595
2628
  )
2596
2629
  }
2597
2630
 
2631
+ /** 配置里的链拆成编辑行:第 1 行恒是主路由,其后是降级链。 */
2632
+ function chainRowsOf(ops) {
2633
+ const o = ops && typeof ops === 'object' ? ops : {}
2634
+ const out = []
2635
+ const primary = { provider: String(o.routeProvider || ''), model: String(o.routeModel || '') }
2636
+ if (primary.provider !== '' || primary.model !== '') out.push(primary)
2637
+ for (const e of Array.isArray(o.fallbacks) ? o.fallbacks : []) {
2638
+ if (!e || typeof e !== 'object') continue
2639
+ const provider = String(e.provider || '')
2640
+ const model = String(e.model || '')
2641
+ if (provider === '' && model === '') continue
2642
+ out.push({ provider, model })
2643
+ }
2644
+ return out
2645
+ }
2646
+
2647
+ /**
2648
+ * v0.8.1 模型路由链编辑器:形态照 dsh-prime-memory 的「全局默认链」——统一列表,
2649
+ * 第 1 行主路由、其后为回退链,每行两个下拉 + 上移/下移/删除,底部添加与清空。
2650
+ * 数据源 GET /ops/catalog:provider 目录走宿主 listProviders(),模型清单走逐
2651
+ * provider listModels()。目录拿不到(宿主无该方法、超时、或该家不供列表)时
2652
+ * 该行降级为手输——只给下拉会让不供列表的适配器把整个编辑器填不了。
2653
+ * 写入一次提交整链三个键,不留「主路由已改、降级链还是旧的」这种半截状态。
2654
+ */
2655
+ function SettingsChainEditor(props) {
2656
+ const t = props.t
2657
+ const stored = chainRowsOf(props.ops)
2658
+ const storedSig = JSON.stringify(stored)
2659
+ const [draft, setDraft] = useState(null)
2660
+ const [catalog, setCatalog] = useState(null)
2661
+ const [tick, setTick] = useState(0)
2662
+ const rows = draft || stored
2663
+ const maxChain = Number(catalog && catalog.maxChain) > 0 ? Number(catalog.maxChain) : 6
2664
+ const providers = catalog && Array.isArray(catalog.providers) ? catalog.providers : []
2665
+ const routes = catalog && Array.isArray(catalog.routes) ? catalog.routes : []
2666
+ const disabled = props.writable !== true || props.busy === true
2667
+
2668
+ useEffect(() => {
2669
+ setDraft(null)
2670
+ }, [storedSig])
2671
+
2672
+ useEffect(() => {
2673
+ let alive = true
2674
+ fetch(`${API}/ops/catalog`, { method: 'GET', credentials: 'same-origin' })
2675
+ .then((response) => response.json().catch(() => null))
2676
+ .then((body) => {
2677
+ if (alive && body && typeof body === 'object') setCatalog(body)
2678
+ })
2679
+ .catch(() => {
2680
+ // 目录读失败不抛白屏:两个下拉退成手输框
2681
+ })
2682
+ return () => {
2683
+ alive = false
2684
+ }
2685
+ }, [tick])
2686
+
2687
+ const apply = (next) => {
2688
+ setDraft(next)
2689
+ setTick((v) => v + 1)
2690
+ props.onSubmit(next)
2691
+ }
2692
+ const patchRow = (index, key, value) => {
2693
+ apply(rows.map((row, i) => (i === index ? { ...row, [key]: value } : row)))
2694
+ }
2695
+ const move = (index, delta) => {
2696
+ const to = index + delta
2697
+ if (to < 0 || to >= rows.length) return
2698
+ const next = rows.slice()
2699
+ const held = next[index]
2700
+ next[index] = next[to]
2701
+ next[to] = held
2702
+ apply(next)
2703
+ }
2704
+ const remove = (index) => apply(rows.filter((_row, i) => i !== index))
2705
+ const add = () => {
2706
+ if (rows.length >= maxChain) return
2707
+ apply(rows.concat([{ provider: '', model: '' }]))
2708
+ }
2709
+
2710
+ // 当前值不在目录里也要能回显(手写配置、或该渠道刚被删):补一个带标注的选项。
2711
+ const optionSet = (list, current, unlistedLabel) => {
2712
+ const out = list.map((item) => h('option', { key: item.id, value: item.id }, item.label || item.id))
2713
+ if (current && !list.some((item) => item.id === current)) {
2714
+ out.unshift(h('option', { key: `__unlisted-${current}`, value: current }, `${current} · ${unlistedLabel}`))
2715
+ }
2716
+ return out
2717
+ }
2718
+
2719
+ const rowEls = rows.map((row, index) => {
2720
+ const bucket = providers.find((p) => p.id === row.provider) || null
2721
+ const models = bucket && bucket.modelsAvailable === true && Array.isArray(bucket.models) ? bucket.models : []
2722
+ const manualModel = !models.length
2723
+ return h(
2724
+ 'div',
2725
+ { key: `row-${index}`, className: 'dsu-chain-row', 'data-row': String(index) },
2726
+ h('span', { className: 'dsu-chain-idx' }, index === 0 ? t('setOpsChainPrimary') : String(index + 1)),
2727
+ providers.length
2728
+ ? h(
2729
+ 'select',
2730
+ {
2731
+ className: 'dsu-select',
2732
+ value: row.provider,
2733
+ disabled,
2734
+ onChange: (e) => patchRow(index, 'provider', e.target.value),
2735
+ },
2736
+ h('option', { key: '__none', value: '' }, t('setOpsChainProvider')), ...optionSet(providers, row.provider, t('setOpsChainUnlisted')),
2737
+ )
2738
+ : h('input', {
2739
+ className: 'dsu-input',
2740
+ type: 'text',
2741
+ value: row.provider,
2742
+ disabled,
2743
+ placeholder: t('setOpsChainProviderManual'),
2744
+ onBlur: (e) => patchRow(index, 'provider', e.target.value.trim()),
2745
+ }),
2746
+ manualModel
2747
+ ? h('input', {
2748
+ className: 'dsu-input',
2749
+ type: 'text',
2750
+ value: row.model,
2751
+ disabled: disabled || !row.provider,
2752
+ placeholder: t('setOpsChainModelManual'),
2753
+ onBlur: (e) => patchRow(index, 'model', e.target.value.trim()),
2754
+ })
2755
+ : h(
2756
+ 'select',
2757
+ {
2758
+ className: 'dsu-select',
2759
+ value: row.model,
2760
+ disabled: disabled || !row.provider,
2761
+ onChange: (e) => patchRow(index, 'model', e.target.value),
2762
+ },
2763
+ h('option', { key: '__none', value: '' }, t('setOpsChainModel')), ...optionSet(models, row.model, t('setOpsChainUnlisted')),
2764
+ ),
2765
+ h(
2766
+ 'span',
2767
+ { className: 'dsu-chain-tools' },
2768
+ h('button', { type: 'button', className: 'dsu-chain-btn', title: t('setOpsChainUp'), disabled: disabled || index === 0, onClick: () => move(index, -1) }, '↑'),
2769
+ h('button', { type: 'button', className: 'dsu-chain-btn', title: t('setOpsChainDown'), disabled: disabled || index === rows.length - 1, onClick: () => move(index, 1) }, '↓'),
2770
+ h('button', { type: 'button', className: 'dsu-chain-btn', title: t('setOpsChainRemove'), disabled, onClick: () => remove(index) }, '×'),
2771
+ ),
2772
+ )
2773
+ })
2774
+
2775
+ const effective = routes.map((r) => `${r.provider}/${r.model} · ${t(r.local === true ? 'opsLocalTag' : 'opsCloudTag')}`).join(' → ')
2776
+ return h(
2777
+ 'div',
2778
+ { className: 'dsu-chain' },
2779
+ rowEls.length ? rowEls : h('div', { className: 'dsu-hint' }, t('setOpsChainEmpty')),
2780
+ h(
2781
+ 'div',
2782
+ { className: 'dsu-chain-foot' },
2783
+ h('button', { type: 'button', className: 'dsu-chain-btn', disabled: disabled || rows.length >= maxChain, onClick: add }, t('setOpsChainAdd')),
2784
+ rows.length
2785
+ ? h('button', { type: 'button', className: 'dsu-chain-btn', disabled, onClick: () => apply([]) }, t('setOpsChainClear'))
2786
+ : null,
2787
+ rows.length >= maxChain ? h('span', { className: 'dsu-hint' }, t('setOpsChainMax').replace('N', String(maxChain))) : null,
2788
+ ),
2789
+ effective
2790
+ ? h('div', { className: 'dsu-chain-eff' }, `${t('setOpsChainEffective')}:${effective}`)
2791
+ : null,
2792
+ )
2793
+ }
2794
+
2598
2795
  function ProgressUnionSettings(props) {
2599
2796
  const t = makeT(props)
2600
2797
  const scope = useUnionScope()
@@ -2721,6 +2918,28 @@ window.__ModuleLoader__.load({
2721
2918
  if (canMutate()) return void writeOps([{ op: 'set', path: [group, key], value: next }])
2722
2919
  return void commit(group, { ...(base || {}), [key]: next })
2723
2920
  }
2921
+ // 路由链整块提交(v0.8.1):三个键一起写,不留「主路由已改、降级链还是旧的」。
2922
+ // 不成对的行(只选了 provider 没选 model)不入库:链构建本来也会剔除它,
2923
+ // 写进去只会让下次打开看到一个填不动的幽灵行。
2924
+ // 只能走 mutate 的多段 path:嵌套组不能整组铺回(宿主只认 volatile 叶子,
2925
+ // `Config field "ops" is not volatile` 是 0.7.5 的真机实测),本仓的写面闸
2926
+ // settings.test 就是拿这条拦它的,所以这里不留 commit('ops', …) 分支。
2927
+ const commitChain = (rows) => {
2928
+ if (!canMutate()) {
2929
+ setStatus(t('setNoScope'))
2930
+ return
2931
+ }
2932
+ const list = Array.isArray(rows) ? rows : []
2933
+ const primary = list[0] || { provider: '', model: '' }
2934
+ const fallbacks = list.slice(1)
2935
+ .filter((row) => row && row.provider && row.model)
2936
+ .map((row) => ({ provider: String(row.provider), model: String(row.model) }))
2937
+ void writeOps([
2938
+ { op: 'set', path: ['ops', 'routeProvider'], value: String(primary.provider || '') },
2939
+ { op: 'set', path: ['ops', 'routeModel'], value: String(primary.model || '') },
2940
+ { op: 'set', path: ['ops', 'fallbacks'], value: fallbacks },
2941
+ ])
2942
+ }
2724
2943
  const flush = async () => {
2725
2944
  for (const group of ['assistant', 'observer', 'todo', 'download', 'toolGloss', 'ops']) {
2726
2945
  const keys = dirtyKeys(group)
@@ -2840,12 +3059,15 @@ window.__ModuleLoader__.load({
2840
3059
  SettingsCard,
2841
3060
  { title: t('setOpsGroup'), badge: t('setOpsBadge'), hint: t('setOpsHint'), defaultOpen: false },
2842
3061
  h(SettingsRow, { label: t('setOpsEnabled') }, switchInput('ops', ops, 'enabled', true)),
2843
- h(SettingsRow, { label: t('setOpsRouteProvider'), hint: t('setOpsRouteProviderHint') },
2844
- textInput('ops', 'routeProvider', '', 'local-35')),
2845
- h(SettingsRow, { label: t('setOpsRouteModel') },
2846
- textInput('ops', 'routeModel', '', 'Qwen3.6-35B-A3B')),
3062
+ h(SettingsRow, { label: t('setOpsChain'), hint: t('setOpsChainHint') },
3063
+ h(SettingsChainEditor, {
3064
+ t,
3065
+ ops,
3066
+ writable,
3067
+ busy,
3068
+ onSubmit: commitChain,
3069
+ })),
2847
3070
  h(SettingsRow, { label: t('setOpsPreferLocal'), hint: t('setOpsPreferLocalHint') }, switchInput('ops', ops, 'preferLocal', true)),
2848
- h('div', { className: 'dsu-hint' }, t('setOpsFallbackNote')),
2849
3071
  h(SettingsRow, { label: t('setNotifyMajor'), hint: t('setNotifyMajorHint') },
2850
3072
  h(SettingsSwitch, {
2851
3073
  checked: Object.prototype.hasOwnProperty.call(draft, 'notifyMajorChanges') ? draft.notifyMajorChanges : value.notifyMajorChanges !== false,
package/dsh.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "dsh-external/dsh-progress-union",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "main": "./index.js",
5
5
  "description": "进度结合原型:board 槽位真相源(用户可编辑、diff+ack 增量同步、staleness nudge)× 鲸程时间引擎(step 计数、ETA 三档 board>todo>local>prior、悬浮迷你条),向压缩插件暴露只读三层进度锚点 progressAnchor(board 语义锚 + time 时间锚 + userEdits 未确认改动,service 与 HTTP 双平面),并在 0.6.0 起每回合落一版会话归档(handoff 规则摘要 + 重启注入一次)。",
6
6
  "engines": {
package/index.js CHANGED
@@ -104,11 +104,14 @@ export const Config = z.object({
104
104
  // 本地优先:只把按名字判定的本地候选排到链首,不参与裁决、不删条目。
105
105
  preferLocal: z.boolean().default(true).volatile(),
106
106
  // 有序降级链(每条各享全额 timeoutMs;与主路由同 provider+model 的条目剔除)。
107
- // 数组不进设置表单(宿主表单不渲染数组),真值走 cordis.patch.yml。
107
+ // v0.8.1:改叶级 volatile,让设置面的路由链编辑器能直接增删排序并即时落盘。
108
+ // 宿主成文规则(vendor/schemastery/src/index.ts:481-496):数组可以作为 volatile
109
+ // 值(递归冻结的纯数据快照),前提是它在固定对象路径上且外面没有包着别的
110
+ // volatile——本键位于 ops.fallbacks,ops 节本身未标 volatile,因此合法。
108
111
  fallbacks: z.array(z.object({
109
112
  provider: z.string().default(''),
110
113
  model: z.string().default(''),
111
- })).default([]),
114
+ })).default([]).volatile(),
112
115
  }).default({}),
113
116
  })
114
117
 
@@ -675,6 +678,9 @@ const OPS_MAX_ITEMS = 60
675
678
  const OPS_MAX_TITLE = 180
676
679
  const OPS_MAX_CHANGES = 8
677
680
  const OPS_MAX_ATTEMPTS = 3
681
+ // v0.8.1:设置面路由链编辑器的链长上限(含主路由那一行)。客户端截断、
682
+ // 服务端只读回显,不拿它拒写(配置手写超上限时降级链照旧逐条试)。
683
+ const OPS_MAX_CHAIN = 6
678
684
  const OPS_KINDS = new Set(['refine', 'mutate', 'ask', 'validate'])
679
685
  const OPS_CHANGE_KINDS = new Set(['add', 'edit', 'remove'])
680
686
  // edit 至少要动这一个字段,否则这条改动落下去什么都没变(模型爱犯的空转)。
@@ -3497,6 +3503,93 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
3497
3503
  }
3498
3504
  }
3499
3505
 
3506
+ // v0.8.1:设置面路由链编辑器的数据源。与 opsProviders() 分工不同——那个回的是
3507
+ // 「链上真值」(裁决与面板候选用),这个回的是「可选目录」(宿主全量注册渠道 +
3508
+ // 逐 provider 模型清单)。模型清单走 llm.listModels(provider)(prime-memory 同径:
3509
+ // 内置适配器读本地快照不触网,但仍加限时兜底);宿主无该方法、报错或超时即回
3510
+ // 空表,客户端据此把该行降级为手输模型 id(不能只给下拉,否则第三方适配器
3511
+ // 不供列表时整个编辑器就填不了)。
3512
+ const CATALOG_TTL_MS = 60000
3513
+ const CATALOG_QUERY_MS = 4000
3514
+ const catalogCache = new Map() // providerId -> { at, models, available }
3515
+
3516
+ async function catalogModels(providerId) {
3517
+ const hit = catalogCache.get(providerId)
3518
+ if (hit && Date.now() - hit.at < CATALOG_TTL_MS) return hit
3519
+ if (!llm || typeof llm.listModels !== 'function') return { at: 0, models: [], available: false }
3520
+ let timer = null
3521
+ try {
3522
+ const listed = await Promise.race([
3523
+ Promise.resolve(llm.listModels(providerId)),
3524
+ new Promise((_resolve, reject) => {
3525
+ timer = setTimeout(() => reject(new Error('model-list-timeout')), CATALOG_QUERY_MS)
3526
+ }),
3527
+ ])
3528
+ const models = (Array.isArray(listed) ? listed : []).slice(0, 64)
3529
+ .map((m) => ({
3530
+ id: text(String(m && m.id ? m.id : ''), 160),
3531
+ label: text(String((m && (m.name || m.id)) || ''), 160),
3532
+ }))
3533
+ .filter((m) => m.id !== '')
3534
+ const entry = { at: Date.now(), models, available: true }
3535
+ catalogCache.set(providerId, entry)
3536
+ return entry
3537
+ } catch (_error) {
3538
+ // 失败不进缓存:下次开卡重试,不把一次超时长挂一分钟
3539
+ catalogCache.delete(providerId)
3540
+ return { at: 0, models: [], available: false }
3541
+ } finally {
3542
+ if (timer) clearTimeout(timer)
3543
+ }
3544
+ }
3545
+
3546
+ async function catalogProviders() {
3547
+ if (!llm || typeof llm.listProviders !== 'function') return []
3548
+ try {
3549
+ // 宿主侧 listProviders() 是同步的(prime-memory 不 await),但单测桩与某些
3550
+ // 第三方适配器可能回 Promise——两态都吃,不然这里静默退成空目录。
3551
+ const listed = await Promise.resolve(llm.listProviders())
3552
+ return (Array.isArray(listed) ? listed : []).slice(0, 64)
3553
+ .map((p) => ({
3554
+ id: text(String(p && p.id ? p.id : ''), 160),
3555
+ label: text(String((p && (p.name || p.id)) || ''), 160),
3556
+ }))
3557
+ .filter((p) => p.id !== '')
3558
+ } catch (_error) {
3559
+ return []
3560
+ }
3561
+ }
3562
+
3563
+ async function opsCatalog() {
3564
+ const a0 = liveAssistant()
3565
+ const providers = await catalogProviders()
3566
+ const listed = await Promise.all(providers.map(async (p) => {
3567
+ const entry = await catalogModels(p.id)
3568
+ return { id: p.id, label: p.label || p.id, models: entry.models, modelsAvailable: entry.available }
3569
+ }))
3570
+ // 回显已存配置原串(不是 buildOpsChain 之后的链):编辑器要能看见并修好那些
3571
+ // 被链构建剔除的半成品行,否则用户只会看到「写了但行里没多一条」。
3572
+ const saved = (Array.isArray(cfg.ops.fallbacks) ? cfg.ops.fallbacks : []).map((e) => ({
3573
+ provider: text(String(e && e.provider ? e.provider : ''), 160),
3574
+ model: text(String(e && e.model ? e.model : ''), 160),
3575
+ }))
3576
+ return {
3577
+ ok: true,
3578
+ enabled: cfg.ops.enabled === true,
3579
+ maxChain: OPS_MAX_CHAIN,
3580
+ providers: listed,
3581
+ chain: {
3582
+ routeProvider: text(String(cfg.ops.routeProvider || ''), 160),
3583
+ routeModel: text(String(cfg.ops.routeModel || ''), 160),
3584
+ fallbacks: saved,
3585
+ preferLocal: cfg.ops.preferLocal !== false,
3586
+ },
3587
+ // 生效链(带 local 标注):只读预览行拿它说话,与动板时的裁决同一口径。
3588
+ routes: opsChainOf(),
3589
+ host: { provider: text(String(a0.provider || ''), 160), model: text(String(a0.model || ''), 160) },
3590
+ }
3591
+ }
3592
+
3500
3593
  // 选定这次动作用哪条路由(v0.8.0):面板给了 provider/model 就必须命中链上条目
3501
3594
  // (链外一律 403);没给就取链首。恒走宿主 registered —— ops 不再沿用 assistant
3502
3595
  // 的 mode,也不再用 direct 端点:白名单里的 provider 必须是宿主已注册渠道。
@@ -3628,7 +3721,7 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
3628
3721
 
3629
3722
  const choice = opsRouteChoice(body)
3630
3723
  if (choice.error === 'unconfigured') {
3631
- forbidden('ops 未钉定模型路由:请在「设置 → 进度板 → LLM 操作与队列提醒」填主路由的 provider/model,或在 cordis.patch.yml 配 ops.routeProvider / ops.routeModel 与 ops.fallbacks')
3724
+ forbidden('ops 未钉定模型路由:请在「设置 → 进度板 → LLM 操作与队列提醒」的模型路由链里添加主路由与回退行(或在 cordis.patch.yml 配 ops.routeProvider / ops.routeModel 与 ops.fallbacks)')
3632
3725
  }
3633
3726
  if (choice.error === 'off-chain') {
3634
3727
  forbidden(`所选模型不在 ops 允许范围内:${String(body && body.provider ? body.provider : '')}/${String(body && body.model ? body.model : '')}(链上只有 ${choice.chain.map((r) => `${r.provider}/${r.model}`).join('、')})`)
@@ -5404,6 +5497,25 @@ ${reason}。本回合开始前先用 progress_update 处理进度板:用户这
5404
5497
  },
5405
5498
  }),
5406
5499
  )
5500
+ routeDisposers.push(
5501
+ webServer.register({
5502
+ kind: 'exact',
5503
+ path: `${ROUTE_BASE}/ops/catalog`,
5504
+ handler: async (req, res) => {
5505
+ if (req.method !== 'GET') {
5506
+ res.writeHead(405, { allow: 'GET' })
5507
+ res.end()
5508
+ return
5509
+ }
5510
+ try {
5511
+ sendJson(res, 200, await opsCatalog())
5512
+ } catch (error) {
5513
+ // 目录读失败不能把设置卡抛成白屏:回空目录 + error,客户端退化为手输。
5514
+ sendJson(res, 200, { ok: false, providers: [], maxChain: OPS_MAX_CHAIN, chain: { routeProvider: '', routeModel: '', fallbacks: [], preferLocal: true }, routes: [], error: error instanceof Error ? error.message : String(error) })
5515
+ }
5516
+ },
5517
+ }),
5518
+ )
5407
5519
  routeDisposers.push(
5408
5520
  webServer.register({
5409
5521
  kind: 'exact',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-progress-union",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "description": "进度结合原型:dsh-progress-board 槽位真相源 × 鲸程 widget 时间/ETA 引擎;向压缩插件暴露只读三层进度锚点(service + HTTP 双平面);0.6.0 起每回合落一版会话归档(handoff + 重启注入一次)。基于 l3j3y3/dsh-progress-board (MIT) 与 uuhihj/task-progress-bar dsh-progress-widget (MIT)。",
6
6
  "license": "MIT",
@@ -429,6 +429,20 @@ test('rc.3:操作块文案 zh/en 成对(本仓 client 只有内联 zh/en 两
429
429
  }
430
430
  })
431
431
 
432
+ // v0.8.1:路由链编辑器的文案。这批键全部是面板上看得见的字,漏一语就是
433
+ // 渲染时直接露键名(而不是退成中文)。
434
+ test('v0.8.1:链编辑器文案 zh/en 成对', () => {
435
+ const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
436
+ const keys = ['setOpsChain', 'setOpsChainHint', 'setOpsChainPrimary', 'setOpsChainProvider', 'setOpsChainProviderManual', 'setOpsChainModel', 'setOpsChainModelManual', 'setOpsChainAdd', 'setOpsChainClear', 'setOpsChainMax', 'setOpsChainEffective', 'setOpsChainUnlisted', 'setOpsChainEmpty', 'setOpsChainUp', 'setOpsChainDown', 'setOpsChainRemove']
437
+ for (const k of keys) {
438
+ const hits = src.match(new RegExp(`\\n\\s+${k}: '[^']+',`, 'g')) || []
439
+ assert.equal(hits.length, 2, `${k} 必须在 zh/en 各出现一次(实得 ${hits.length})`)
440
+ }
441
+ // 带占位符的键两边都得含 N,否则 replace('N', …) 会静默不填数
442
+ assert.match(src, /setOpsChainMax: '\u94fe\u6700\u957f N \u884c/, 'zh 链长上限文案要带 N 占位')
443
+ assert.match(src, /setOpsChainMax: 'Chain capped at N rows/, 'en 链长上限文案要带 N 占位')
444
+ })
445
+
432
446
  test('0.7.0:新增任务 wake 与 R4 落队列互斥,同一次改板队列里只留一条', () => {
433
447
  const src = fs.readFileSync(clientFile, 'utf8').replace(/\r\n/g, '\n')
434
448
  // 真机偏差:面板加两项后 input-traffic 出现两条同文排队条目——客户端 wake 与
package/test/ops.test.mjs CHANGED
@@ -30,8 +30,12 @@ function llmMock(reply, calls) {
30
30
  }
31
31
  }
32
32
 
33
- async function booted({ config = {}, reply = '{}', calls = [], providers = undefined } = {}) {
34
- const llm = { ...llmMock(reply, calls), ...(providers ? { listProviders: async () => providers } : {}) }
33
+ async function booted({ config = {}, reply = '{}', calls = [], providers = undefined, models = undefined } = {}) {
34
+ const llm = {
35
+ ...llmMock(reply, calls),
36
+ ...(providers ? { listProviders: async () => providers } : {}),
37
+ ...(models ? { listModels: typeof models === 'function' ? models : async () => models } : {}),
38
+ }
35
39
  const harness = createHarness({
36
40
  config: {
37
41
  assistant: { mode: 'registered', provider: 'local', model: 'qwen', minIntervalMs: 0 },
@@ -202,6 +206,76 @@ test('providers:候选只来自配置白名单,不再枚举宿主 listProvid
202
206
  assert.equal(wrong.status, 405)
203
207
  })
204
208
 
209
+ test('catalog:链编辑器数据源 = 宿主 provider 目录 + 逐家模型清单 + 已存链原串', async () => {
210
+ let listed = 0
211
+ const harness = await booted({
212
+ providers: [{ id: 'local-35', name: 'local-35' }, { id: 'deepseek-own', name: 'DeepSeek' }],
213
+ models: async (provider) => {
214
+ listed += 1
215
+ return provider === 'local-35'
216
+ ? [{ id: 'Qwen3.6-35B-A3B', name: 'Qwen 3.6 35B' }, { id: 'Qwen3.8-27B' }]
217
+ : [{ id: 'deepseek-flash', name: 'Flash' }]
218
+ },
219
+ config: { ops: { enabled: true, routeProvider: 'local-35', routeModel: 'Qwen3.6-35B-A3B', preferLocal: true, fallbacks: [{ provider: 'deepseek-own', model: 'deepseek-flash' }, { provider: '', model: 'ghost' }] } },
220
+ })
221
+ const get = async () => (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
222
+ const json = await get()
223
+ assert.equal(json.ok, true)
224
+ assert.equal(json.enabled, true)
225
+ assert.equal(json.maxChain, 6, '链长上限要随目录给出,客户端才能拿宿主口径截断')
226
+ assert.deepEqual(json.providers.map((p) => p.id), ['local-35', 'deepseek-own'])
227
+ assert.deepEqual(json.providers[0].models.map((m) => m.id), ['Qwen3.6-35B-A3B', 'Qwen3.8-27B'])
228
+ assert.equal(json.providers[0].models[0].label, 'Qwen 3.6 35B', '无 name 时回退到 id,有 name 用 name')
229
+ assert.equal(json.providers[0].modelsAvailable, true)
230
+ // 回显的是已存配置原串,不是链构建结果:半成品行也要看得见、能修好
231
+ assert.equal(json.chain.fallbacks.length, 2)
232
+ assert.deepEqual(json.chain.fallbacks[1], { provider: '', model: 'ghost' })
233
+ assert.deepEqual(json.routes.map((r) => `${r.provider}/${r.model}`), ['local-35/Qwen3.6-35B-A3B', 'deepseek-own/deepseek-flash'], '生效链那侧仍剔除缺 provider 的行')
234
+ assert.deepEqual(json.host, { provider: 'local', model: 'qwen' }, '宿主当前选择只作展示,不进候选')
235
+
236
+ await get()
237
+ assert.equal(listed, 2, '两家 provider 各查一次,第二次开卡命中 TTL 缓存不重打宿主')
238
+ const wrong = await callRoute(harness, `${OPS}/catalog`, { method: 'POST', url: `${OPS}/catalog`, headers: {} })
239
+ assert.equal(wrong.status, 405)
240
+ })
241
+
242
+ test('catalog:宿主不供模型清单或查询报错时回空表并标 modelsAvailable=false', async () => {
243
+ const bare = await booted({ providers: [{ id: 'local-35', name: 'local-35' }] })
244
+ const j1 = (await callRoute(bare, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
245
+ assert.equal(j1.providers.length, 1, 'provider 目录照常给')
246
+ assert.equal(j1.providers[0].modelsAvailable, false, '没 listModels 就得告知客户端降级手输')
247
+ assert.deepEqual(j1.providers[0].models, [])
248
+
249
+ let calls = 0
250
+ const boom = await booted({
251
+ providers: [{ id: 'x', name: 'x' }],
252
+ models: async () => { calls += 1; throw new Error('adapter-down') },
253
+ })
254
+ const getBoom = async () => (await callRoute(boom, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
255
+ const j2 = await getBoom()
256
+ assert.equal(j2.providers[0].modelsAvailable, false)
257
+ assert.equal(j2.providers[0].models.length, 0)
258
+ await getBoom()
259
+ assert.equal(calls, 2, '失败不进缓存:下次开卡重试,不把一次报错长挂一分钟')
260
+
261
+ const none = await booted({ config: { ops: { enabled: true, routeProvider: '', routeModel: '' } } })
262
+ const j3 = (await callRoute(none, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
263
+ assert.deepEqual(j3.providers, [], '宿主没给 llm 目录面时回空集,客户端全行手输')
264
+ assert.deepEqual(j3.routes, [])
265
+ })
266
+
267
+ test('catalog:ops.enabled=false 时目录与已存链照常回(关闭态也要能编链)', async () => {
268
+ const harness = await booted({
269
+ providers: [{ id: 'local', name: 'local' }],
270
+ models: async () => [{ id: 'qwen', name: 'qwen' }],
271
+ config: { ops: { enabled: false, routeProvider: 'local', routeModel: 'qwen', preferLocal: true, fallbacks: [] } },
272
+ })
273
+ const json = (await callRoute(harness, `${OPS}/catalog`, { method: 'GET', url: `${OPS}/catalog`, headers: {} })).json()
274
+ assert.equal(json.enabled, false, '开关态单独告知,不影响目录')
275
+ assert.equal(json.providers.length, 1)
276
+ assert.equal(json.chain.routeProvider, 'local', '关闭态下已存链仍可回显可编辑')
277
+ })
278
+
205
279
  test('ops.enabled=false:providers 报 disabled 且不枚举宿主、refine/mutate/ask 一律 403,validate 照常可用', async () => {
206
280
  let listed = 0
207
281
  const harness = await booted({
@@ -150,14 +150,40 @@ test('设置卡:每条写路径必须是 Config 里的 volatile 叶子', () =>
150
150
  const paths = new Set()
151
151
  for (const m of src.matchAll(/(?:switchInput|segmentInput)\('(\w+)',\s*\w+,\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
152
152
  for (const m of src.matchAll(/(?:numberInput|textInput|secretInput)\('(\w+)',\s*'(\w+)'/g)) paths.add(`${m[1]}.${m[2]}`)
153
+ // v0.8.1:路由链编辑器直接拼 mutate 的 path 字面量,这类写点以前扫不到——
154
+ // 不补上就等于开了个绕过本闸的后门(新写点必须同样落在 volatile 叶子上)。
155
+ for (const m of src.matchAll(/path:\s*\['(\w+)',\s*'(\w+)'\]/g)) paths.add(`${m[1]}.${m[2]}`)
153
156
  for (const m of src.matchAll(/void commit\('(\w+)'/g)) paths.add(m[1])
154
- assert.ok(paths.size >= 24, `扫到的写路径只有 ${paths.size} 条,正则可能失效`)
157
+ assert.ok(paths.size >= 27, `扫到的写路径只有 ${paths.size} 条,正则可能失效`)
155
158
  for (const p of [...paths].sort()) {
156
159
  assert.ok(p in leaves, `设置卡要写 ${p},但 Config 里没这个键`)
157
160
  assert.equal(leaves[p], true, `设置卡要写 ${p},但它不是 volatile 叶子 → 宿主 settings/rejected`)
158
161
  }
159
162
  })
160
163
 
164
+ /**
165
+ * v0.8.1:降级链从「只能手写 yml」改成面板可编。本闸钉住四件事:
166
+ * fallbacks 必须是 volatile 叶子(否则编辑器拨了不落盘);整链一次提交
167
+ * 三个键;不得再开整组铺回的分支;目录拉不到时要能降级手输。
168
+ */
169
+ test('v0.8.1:路由链编辑器的写面与降级形态', () => {
170
+ const leaves = volatileLeaves(Config)
171
+ assert.equal(leaves['ops.fallbacks'], true, 'ops.fallbacks 必须是 volatile 叶子,否则面板编不了链')
172
+ assert.equal(leaves['ops'], undefined, 'ops 节本身不得被标 volatile(嵌套 volatile 宿主直接拒)')
173
+
174
+ const src = fs.readFileSync(fileURLToPath(new URL('../client.js', import.meta.url)), 'utf8').replace(/\r\n/g, '\n')
175
+ for (const key of ['routeProvider', 'routeModel', 'fallbacks']) {
176
+ assert.ok(src.includes(`path: ['ops', '${key}']`), `整链提交必须含 ${key} 这一键,不留半截状态`)
177
+ }
178
+ assert.ok(!/void commit\('ops'/.test(src), '嵌套组不得整组铺回(0.7.5 实测会被 settings/rejected 拒)')
179
+ assert.match(src, /fetch\(`\$\{API\}\/ops\/catalog`/, '编辑器必须从宿主目录拉 provider/模型')
180
+ assert.match(src, /bucket\.modelsAvailable === true/, '该家不供模型清单时要降级为手输,不能给一个填不了的空下拉')
181
+ assert.match(src, /rows\.length >= maxChain/, '添加按钮到链长上限要禁用')
182
+ assert.match(src, /const move = \(index, delta\) =>/, '行序必须能在面板调(降级链语义就是顺序)')
183
+ assert.match(src, /chainRowsOf\(props\.ops\)/, '行初值必须从已存配置回显,不能从空表开始')
184
+ assert.ok(!src.includes('setOpsFallbackNote'), '「fallbacks 只能改 yml」的旧说法必须从文案里消失')
185
+ })
186
+
161
187
  /**
162
188
  * v0.7.7 真机回灌:0.7.6 修好写面后,页脚出现「已保存」与「有未保存的改动」并存
163
189
  * —— 开关拨完即落盘,但乐观草稿仍按「键存在」计脏。脏位必须按值比对。