dsh-agy-link 0.6.52 → 0.6.54

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
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.54 (2026-11-21)
4
+
5
+ ### English
6
+
7
+ - **Fix(client): the rest of the DOM surfaces now speak the host language (fixes #153, part 2).** Part 1 localized the decision chips; this one covers the image chips and their toasts, the whole image lightbox (tooltips, button labels, loading and keyboard hints), the mermaid view-source toggle and parse warning, the compaction card title, and the question-card insert/recorded labels.
8
+ - **New `src/client/i18n-bridge.ts`**: these modules are plain DOM enhancers, not React components, and several have no `ctx` of their own (the lightbox is opened by the scanner). They now read one translator bound once in `index.ts`, with `translateOr(key, englishFallback)` guaranteeing copy instead of a bare key when no locale service exists. `decisions.ts` was migrated onto it, deleting its private copy of the same fallback logic.
9
+ - **`mermaid` keeps one Chinese literal on purpose**: `代码块` is DSH's own placeholder banner text, matched to DETECT "this banner carries no real language label". Translating it would break the detection.
10
+ - **`compaction` no longer reads `document.documentElement.lang`**: that is DSH's page language, not this plugin's locale, and the two can disagree — the binding is the authority now.
11
+ - **Test(dx): hardened two timing guards in `test/proxy-keychain.test.ts`.** They measured machine load rather than the watchdog: a starved event loop on a busy host made a 5s guard fire before a 400ms timeout could settle, and one escalation test hung to the runner's 60s default. The guards are widened and now reap the child on overrun, while the assertions that bound the actual tick are unchanged.
12
+
13
+ ### 中文
14
+
15
+ - **修复(客户端):其余 DOM 界面也改用宿主语言(修复 #153 第二部分)。** 第一部分本地化了决策芯片;本次覆盖图片 chip 与其 toast、整个图片灯箱(tooltip、按钮文字、加载与键盘提示)、mermaid 的「查看源码」切换与解析失败警告、压缩卡片标题,以及问题卡片的填入/已记录文案。
16
+ - **新增 `src/client/i18n-bridge.ts`**:这些模块是纯 DOM 增强器而非 React 组件,其中几个根本没有自己的 `ctx`(灯箱由 scanner 打开)。它们现在统一读取在 `index.ts` 一次性绑定的 translator,`translateOr(key, 英文兜底)` 保证没有 locale 服务时输出文案而不是裸 key。`decisions.ts` 已迁移过来,删掉了它自己那份重复的兜底逻辑。
17
+ - **`mermaid` 刻意保留一处中文**:`代码块` 是 DSH 自己的占位 banner 文本,用来**识别**「该 banner 没有真实语言标签」。翻译它会破坏这段判断。
18
+ - **`compaction` 不再读 `document.documentElement.lang`**:那是 DSH 的页面语言,不是本插件的 locale,两者可能不一致——现在以 locale 绑定为准。
19
+ - **测试(开发体验):加固 `test/proxy-keychain.test.ts` 的两处时序守卫。** 它们实际在测机器负载而非看门狗:繁忙宿主上被饿死的事件循环会让 5 秒守卫早于 400ms 超时结算,另有一条升级用例会一直挂到 runner 的 60 秒默认超时。守卫已放宽,并在超时时主动回收子进程;约束真实 tick 的断言保持不变。
20
+
21
+ ## 0.6.53 (2026-11-21)
22
+
23
+ ### English
24
+
25
+ - **Feat(settings): the model list becomes a tick-list over the real selectable universe (merges PR #149, closes #131).** The "Model visibility" block was a deny-list of chips fed only by `agy models`, so a host without the CLI offered the 7 static fallback rows while the account pool already knew that account could run 23+ models — the picker looked broken.
26
+ - **Ticking writes an allow-list.** `selectedModels` (`POST /config`, `DSH_AGY_SELECTED_MODELS`) is applied after `hiddenModels`, so a denied model stays denied (and its chip says why). An empty selection still means "no restriction", which keeps the shipped default byte-for-byte and makes unticking the last model unable to blank the picker.
27
+ - **New pure module `src/domain/models/quota-catalog.ts`** folds `accounts[].quotas.<family>.models[]` into catalog entries (same effort-folding rules as the CLI list) and merges them into whatever `agy models` discovered — CLI order and naming stay authoritative, quota rows only contribute models the catalog never mentioned. `/status` scopes this to the active account (or the whole pool under `poolWideCatalog`) and echoes `selectedModels`; model resolution merges the same way so a quota-only model still resolves.
28
+ - **Resolution is deliberately NOT filtered**: a session already running a model the user later untickes keeps resolving it — unticking must not break in-flight work. Only `listModels` (the picker) filters.
29
+ - Merge note: the PR's inline config validation was replaced by the unified `validateConfigValue()` that landed in v0.6.52, extended to cover `selectedModels`, and the maintainer-owned `CHANGELOG.md`/`package.json` were kept.
30
+
31
+ ### 中文
32
+
33
+ - **特性(设置):模型列表改为「真实可选集合」的勾选清单(合并 PR #149,关闭 #131)。** 原「模型可见性」是只由 `agy models` 供数的**拒绝清单**,于是没有 CLI 的宿主只列出 7 条静态兜底、而账号池其实知道该账号能跑 23+ 个模型——选择器看起来像坏了。
34
+ - **勾选写入允许清单。** `selectedModels`(`POST /config`、`DSH_AGY_SELECTED_MODELS`)在 `hiddenModels` **之后**应用,因此被拒绝的模型仍然隐藏(chip 会说明原因);空选择仍表示「无限制」,默认配置逐字节不变,也不会因为取消最后一个勾选而把选择器清空。
35
+ - **新增纯模块 `src/domain/models/quota-catalog.ts`**:把 `accounts[].quotas.<family>.models[]` 折叠成目录条目(与 CLI 列表同一套 effort 折叠规则),再并入 `agy models` 的结果——CLI 的顺序与命名保持权威,配额行只贡献目录里从未出现的模型。`/status` 按活跃账号(或 `poolWideCatalog` 下的整池)限定范围并回显 `selectedModels`;模型解析同样合并,使「只有配额快照才知道」的模型仍可解析。
36
+ - **解析刻意不做过滤**:用户后来取消勾选的模型,已在运行的会话仍能解析——取消勾选不得打断进行中的工作。只有 `listModels`(选择器)过滤。
37
+ - 合并说明:PR 内联的配置校验已替换为 v0.6.52 引入的统一 `validateConfigValue()` 并补充 `selectedModels`;维护者自有的 `CHANGELOG.md`/`package.json` 保持。
38
+
3
39
  ## 0.6.52 (2026-11-21)
4
40
 
5
41
  ### English
@@ -141,6 +141,7 @@ function defaultConfig() {
141
141
  workspaceRoot: "",
142
142
  fallbackModels: DEFAULT_FALLBACK_MODELS,
143
143
  hiddenModels: [],
144
+ selectedModels: [],
144
145
  askTool: false,
145
146
  mediaDir: "",
146
147
  mediaTtlMs: 864e5,
@@ -606,6 +607,7 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
606
607
  workspaceRoot: asString(get("workspaceRoot")) ?? base.workspaceRoot,
607
608
  fallbackModels: Array.isArray(get("fallbackModels")) ? get("fallbackModels").filter((x) => !!x && typeof x === "object" && typeof x.id === "string") : base.fallbackModels,
608
609
  hiddenModels: asStringArray(get("hiddenModels")) ?? base.hiddenModels,
610
+ selectedModels: asStringArray(get("selectedModels")) ?? base.selectedModels,
609
611
  askTool: asBool(get("askTool")) ?? base.askTool,
610
612
  mediaDir: asString(get("mediaDir")) ?? base.mediaDir,
611
613
  mediaTtlMs: asNum(get("mediaTtlMs")) ?? base.mediaTtlMs,
@@ -687,6 +689,10 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
687
689
  const list = asStringArray(env.DSH_AGY_HIDDEN_MODELS.split(","));
688
690
  if (list) cfg.hiddenModels = list;
689
691
  }
692
+ if (env.DSH_AGY_SELECTED_MODELS) {
693
+ const list = asStringArray(env.DSH_AGY_SELECTED_MODELS.split(","));
694
+ if (list && list.length > 0) cfg.selectedModels = list;
695
+ }
690
696
  if (env.DSH_AGY_WORKSPACE_ROOT) cfg.workspaceRoot = env.DSH_AGY_WORKSPACE_ROOT;
691
697
  if (env.DSH_AGY_MEDIA_DIR) cfg.mediaDir = env.DSH_AGY_MEDIA_DIR;
692
698
  if (env.DSH_AGY_MEDIA_TTL_MS) {
@@ -5980,6 +5986,136 @@ var ModelCatalog = class ModelCatalog {
5980
5986
  }
5981
5987
  };
5982
5988
  //#endregion
5989
+ //#region src/domain/models/quota-catalog.ts
5990
+ /** Families whose quota rows describe models the picker may offer. */
5991
+ const QUOTA_FAMILIES = [
5992
+ "google",
5993
+ "argon",
5994
+ "anthropic",
5995
+ "openai"
5996
+ ];
5997
+ /**
5998
+ * Models an account's quota snapshot says are available.
5999
+ *
6000
+ * `displayName` is preferred over the raw slug for the label (agy's quota rows
6001
+ * say "Gemini 4 Neon (Low)", the picker should not show `gemini-4-neon-low`).
6002
+ * Rows without a usable `modelId` are skipped rather than guessed at.
6003
+ */
6004
+ function quotaModelsForAccount(account) {
6005
+ const quotas = account?.quotas;
6006
+ if (!quotas) return [];
6007
+ const out = [];
6008
+ const seen = /* @__PURE__ */ new Set();
6009
+ for (const family of QUOTA_FAMILIES) {
6010
+ const rows = quotas[family]?.models;
6011
+ if (!Array.isArray(rows)) continue;
6012
+ for (const row of rows) {
6013
+ if (!row || typeof row.modelId !== "string") continue;
6014
+ const slug = row.modelId.trim();
6015
+ if (slug === "" || seen.has(slug)) continue;
6016
+ seen.add(slug);
6017
+ const label = typeof row.displayName === "string" && row.displayName.trim() !== "" ? row.displayName.trim() : slug;
6018
+ out.push({
6019
+ slug,
6020
+ label
6021
+ });
6022
+ }
6023
+ }
6024
+ return out;
6025
+ }
6026
+ /** Same as {@link quotaModelsForAccount}, folded into picker entries. */
6027
+ function quotaCatalogForAccount(account) {
6028
+ return foldEfforts(quotaModelsForAccount(account));
6029
+ }
6030
+ /**
6031
+ * Merge the CLI-discovered catalog with quota-derived entries.
6032
+ *
6033
+ * Precedence: a discovered entry wins on IDENTITY and ORDER (agy is
6034
+ * authoritative about what it can run and in which order it lists models), but
6035
+ * a quota row may CONTRIBUTE a model the catalog never mentioned — that is the
6036
+ * whole point of the merge: on a CLI-less host the catalog is a 7-row fallback
6037
+ * and the account knows about 23+ real models.
6038
+ *
6039
+ * Effort sets are unioned so a folded catalog entry (`gemini-4-neon` with
6040
+ * low/medium/high) keeps any extra level only the quota rows knew about.
6041
+ */
6042
+ function mergeCatalogWithQuotaModels(discovered, quota) {
6043
+ if (quota.length === 0) return [...discovered];
6044
+ const merged = [];
6045
+ const byId = /* @__PURE__ */ new Map();
6046
+ const index = /* @__PURE__ */ new Map();
6047
+ const add = (entry, allowOverrideName) => {
6048
+ const existingAt = index.get(entry.id);
6049
+ if (existingAt === void 0) {
6050
+ index.set(entry.id, merged.length);
6051
+ byId.set(entry.id, entry);
6052
+ merged.push(entry);
6053
+ return;
6054
+ }
6055
+ const existing = byId.get(entry.id);
6056
+ if (!existing) return;
6057
+ const efforts = unionEfforts(existing.efforts, entry.efforts);
6058
+ const name = allowOverrideName && existing.name === existing.id && entry.name !== entry.id ? entry.name : existing.name;
6059
+ const next = {
6060
+ id: existing.id,
6061
+ name,
6062
+ efforts
6063
+ };
6064
+ byId.set(entry.id, next);
6065
+ merged[existingAt] = next;
6066
+ };
6067
+ for (const entry of discovered) add(entry, false);
6068
+ for (const entry of quota) add(entry, true);
6069
+ return disambiguateLabels(merged);
6070
+ }
6071
+ /**
6072
+ * Make sure no two rows render under the same label.
6073
+ *
6074
+ * The quota snapshot is not above this. On a current pool `gemini-2.5-flash`,
6075
+ * `gemini-2.5-flash-lite`, `gemini-2.5-flash-thinking` and
6076
+ * `gemini-3.5-flash-lite` ALL report "Gemini 3.5 Flash Lite" (upstream keeps the
6077
+ * legacy slugs pointing at the current model), and effort-folding makes
6078
+ * `gemini-4-hydrogen-tiered` inherit "Gemini 4 Hydrogen" from its `(High)`
6079
+ * siblings. Identical chips are unusable — the user cannot tell which box ticks
6080
+ * what.
6081
+ *
6082
+ * Resolution is not "first wins", it is a stem test: a colliding row keeps its
6083
+ * label only when every other row in the group is an ID-DERIVED VARIANT of it
6084
+ * (`<id>-<something>`). That keeps "Gemini 4 Hydrogen" on the base model and
6085
+ * demotes `-tiered`/`-sonar`, while a group of genuinely different models (the
6086
+ * 2.5/3.5 legacy aliases) has no stem and every row falls back to its id — which
6087
+ * is unique by construction and is what the picker sends back anyway.
6088
+ */
6089
+ function disambiguateLabels(entries) {
6090
+ const groups = /* @__PURE__ */ new Map();
6091
+ for (const entry of entries) {
6092
+ const bucket = groups.get(entry.name);
6093
+ if (bucket) bucket.push(entry);
6094
+ else groups.set(entry.name, [entry]);
6095
+ }
6096
+ const keep = /* @__PURE__ */ new Set();
6097
+ for (const rows of groups.values()) {
6098
+ if (rows.length === 1) continue;
6099
+ const stem = rows.find((candidate) => candidate.name !== candidate.id && rows.every((other) => other === candidate || other.id.startsWith(candidate.id + "-")));
6100
+ if (stem) keep.add(stem.id);
6101
+ }
6102
+ return entries.map((entry) => {
6103
+ if (entry.name === entry.id) return entry;
6104
+ if ((groups.get(entry.name) ?? []).length <= 1) return entry;
6105
+ return keep.has(entry.id) ? entry : {
6106
+ ...entry,
6107
+ name: entry.id
6108
+ };
6109
+ });
6110
+ }
6111
+ function unionEfforts(a, b) {
6112
+ const left = a ?? [];
6113
+ const right = b ?? [];
6114
+ if (right.length === 0) return a;
6115
+ if (left.length === 0) return b;
6116
+ return (/* @__PURE__ */ new Set([...left, ...right])).size === left.length ? a : [...left, ...right.filter((e) => !left.includes(e))];
6117
+ }
6118
+ //#endregion
5983
6119
  //#region src/provider/model-resolution.ts
5984
6120
  function activeAccount(deps) {
5985
6121
  const pool = deps.pool;
@@ -5999,14 +6135,73 @@ function listAvailableModels(deps) {
5999
6135
  } else models = deps.catalog.getUnion(accounts, pool);
6000
6136
  const { entries, dropped } = sanitizeCatalogEntries(models);
6001
6137
  if (dropped.length > 0) deps.warnOnce("catalog-dupes", "model catalog contained duplicate ids [" + dropped.join(", ") + "] — kept first occurrence so DSH does not drop the whole provider group (INVALID_CATALOG)");
6002
- const hidden = new Set(cfg.hiddenModels.map((s) => s.trim()));
6003
- return entries.filter((m) => !hidden.has(m.id)).map((m) => ({
6138
+ return visibleEntries(entries, quotaScopeAccounts(pool, accounts, activeAcc, cfg.poolWideCatalog), cfg).map((m) => ({
6004
6139
  provider: PROVIDER_ID,
6005
6140
  id: m.id,
6006
6141
  name: m.name,
6007
6142
  inputModalities: ["text", "image"]
6008
6143
  }));
6009
6144
  }
6145
+ /**
6146
+ * Accounts whose quota snapshots describe models the picker may offer.
6147
+ *
6148
+ * Narrow mode (default) describes ONE account — the same account whose `agy
6149
+ * models` catalog the picker is showing, so the two sources never contradict
6150
+ * each other. Pool-wide mode describes every enabled account because the
6151
+ * scheduler can route to any of them (issue #107).
6152
+ */
6153
+ function quotaScopeAccounts(pool, accounts, activeAcc, poolWide) {
6154
+ if (!pool) return [];
6155
+ if (poolWide) return accounts;
6156
+ if (activeAcc) return [activeAcc];
6157
+ return accounts.slice(0, 1);
6158
+ }
6159
+ /**
6160
+ * Fold quota-derived models into the catalog and apply BOTH visibility filters.
6161
+ *
6162
+ * Quota rows are merged in because a host without the agy CLI only ever has the
6163
+ * static fallback catalog, while every quota refresh already stored the real
6164
+ * per-account model list — that list is what makes the picker useful at all
6165
+ * (issue #131). Merge, don't replace: `agy models` stays authoritative for the
6166
+ * models it knows about.
6167
+ *
6168
+ * Visibility order is allow-list THEN deny-list: `selectedModels` is the
6169
+ * checkbox state the settings panel writes, `hiddenModels` remains the older
6170
+ * deny-list (env/config escape hatch) and still wins on a conflict so an
6171
+ * operator can hide a model without editing the selection.
6172
+ */
6173
+ function visibleEntries(entries, quotaScope, cfg) {
6174
+ const merged = mergeCatalogWithQuotaModels(entries, quotaCatalogForAccounts(quotaScope));
6175
+ const selected = cfg.selectedModels.map((s) => s.trim()).filter((s) => s !== "");
6176
+ const hidden = new Set(cfg.hiddenModels.map((s) => s.trim()));
6177
+ return merged.filter((m) => (selected.length === 0 || isSelected(m.id, selected)) && !hidden.has(m.id));
6178
+ }
6179
+ /**
6180
+ * Whether a stored selection still covers a catalog row.
6181
+ *
6182
+ * Selections are persisted, and catalog rows are not stable: effort variants
6183
+ * (`gemini-4-hydrogen-tiered`) fold into their base row (`gemini-4-hydrogen`)
6184
+ * once the CLI or a quota snapshot reports the family, and the base row then
6185
+ * carries the effort as a flag instead of an id. Matching by exact id only
6186
+ * would turn every such row into a stale entry that silently hides the base
6187
+ * model - the user ticked it, the panel shows nothing, and nothing on screen
6188
+ * explains why. `modelMatches` degrades an effort-suffixed / aliased id to its
6189
+ * base slug, so a selection made before a fold keeps selecting the same model.
6190
+ */
6191
+ function isSelected(id, selected) {
6192
+ return selected.some((want) => modelMatches(want, id));
6193
+ }
6194
+ /** Union of the quota-derived catalogs of several accounts, first label wins. */
6195
+ function quotaCatalogForAccounts(accounts) {
6196
+ const out = [];
6197
+ const seen = /* @__PURE__ */ new Set();
6198
+ for (const acc of accounts) for (const entry of quotaCatalogForAccount(acc)) {
6199
+ if (seen.has(entry.id)) continue;
6200
+ seen.add(entry.id);
6201
+ out.push(entry);
6202
+ }
6203
+ return out;
6204
+ }
6010
6205
  function resolveModelInfo(deps, model) {
6011
6206
  const pool = deps.pool;
6012
6207
  const activeAcc = activeAccount(deps);
@@ -6016,7 +6211,7 @@ function resolveModelInfo(deps, model) {
6016
6211
  const cleanId = rawModel !== "" ? rawModel : cfg.defaultModel;
6017
6212
  const unionModels = deps.catalog.getUnion(accounts, pool);
6018
6213
  const allModels = deps.catalog.getAllKnownModels(accounts);
6019
- const entry = unionModels.find((m) => m.id === cleanId) ?? allModels.find((m) => m.id === cleanId) ?? findEntry(deps.catalog.get(activeAcc?.id), cleanId) ?? findEntry(deps.catalog.get(), cleanId);
6214
+ const entry = unionModels.find((m) => m.id === cleanId) ?? allModels.find((m) => m.id === cleanId) ?? findEntry(deps.catalog.get(activeAcc?.id), cleanId) ?? findEntry(deps.catalog.get(), cleanId) ?? quotaCatalogForAccounts(quotaScopeAccounts(pool, accounts, activeAcc, cfg.poolWideCatalog)).find((m) => m.id === cleanId);
6020
6215
  const rawName = entry ? entry.name : cleanId;
6021
6216
  const name = typeof rawName === "string" && rawName.trim() !== "" ? rawName.trim() : cleanId;
6022
6217
  const contextWindow = typeof cfg.contextWindowDefault === "number" && cfg.contextWindowDefault > 0 ? cfg.contextWindowDefault : 2e5;