dsh-subusage 0.10.0 → 0.10.2

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/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  > **English.** dsh-subusage shows subscription quota and balance for the AI providers you already use, as a pill next to the model selector in DeepSeek Harness. Provider switches and credentials live in one settings page, and other plugins or agents can read the same snapshot through a read-only quota API.
8
8
 
9
- [![npm version](https://img.shields.io/badge/npm-0.10.0-blue)](https://www.npmjs.com/package/dsh-subusage)
9
+ [![npm version](https://img.shields.io/badge/npm-0.10.2-blue)](https://www.npmjs.com/package/dsh-subusage)
10
10
  [![license](https://img.shields.io/badge/license-MIT-green)](#license--security--许可与安全)
11
11
  [![DSH](https://img.shields.io/badge/DSH-%3E%3D0.2.0--rc.1%20%3C0.3.0--0-informational)](#compatibility--兼容性)
12
12
 
@@ -109,7 +109,7 @@ dsh plugin --profile <profile> remove dsh-subusage
109
109
 
110
110
  1. 安装并启用 bundle,按部署方式重载或重启。
111
111
  2. 打开 **设置 → 订阅用量 → 提供商管理**,开启需要的提供商(默认关闭的 19 条需手动开启)。
112
- 3. 为它配置凭据:在卡片里展开「连接与凭据」填 Key / AK-SK,或把 Key 放进凭据服务 / 启动环境;MiMo 用「登录并自动导入」。
112
+ 3. 为它配置凭据:在卡片里展开「连接与凭据」填 Key / AK-SK,或把 Key 放进凭据服务 / 启动环境;MiMo 用「登录并自动导入」。**不知道去哪拿、或填了不生效** → 见[凭据获取指引](docs/credentials.md)。
113
113
  4. 回到会话,选中该提供商的模型:输入区左侧出现余量药丸(绿色成功 / 红色失败),点开看窗口明细。
114
114
  5. 排障顺序:点「立即刷新」→ 看设置页顶部 `X/Y 家数据获取成功`(可点击,跳到第一家没读成功的)。
115
115
 
@@ -126,6 +126,7 @@ $env:DEEPSEEK_API_KEY = "<你的 DeepSeek API Key>" # 启动环境;改完需
126
126
  ## Configuration / 配置
127
127
 
128
128
  - **设置页路径**:设置 → **订阅用量** → 提供商管理。「没有检测到API的默认隐藏」默认开启;首次没有可见条目时管理区自动展开。关闭的提供商仍可配置凭据,只是不会发起用量请求。
129
+ - **凭据从哪来**:每一类凭据的**官网入口、环境变量名与界面填入位置**都写在[凭据获取指引](docs/credentials.md)——包括火山的 IAM AK/SK(子用户还要挂 `ArkReadOnlyAccess` 且不限制到项目)、MiMo 的平台会话 Cookie、以及各家 API Key 的对照表。**注意推理 Key 与额度凭据不通用。**
129
130
  - **默认开关策略**:新安装默认开启 11 条、默认关闭 19 条;开关即时保存,升级保留已保存的开关,不重算默认值。默认隐藏只影响显示,不会自动开启被关闭的提供商。
130
131
  - **凭据来源优先级**(`inherit` 模式):**凭据服务 → 启动环境 → 旧手动配置兜底**;切到自定义(`manual`)模式时只使用保存的手动 Key。界面会区分这三种来源。
131
132
  - **不接受本地 Key 的提供商**:`commandcode`(凭据链属提供方插件)、`xai-oauth`、`openai-codex`(只读各自 CLI 的登录文件),以及 MiMo(Cookie 会话)。
@@ -256,6 +257,8 @@ const view = await service.quota({ providerIds: ["deepseek"], force: false });
256
257
  |---|---|
257
258
  | 药丸不显示 | 依次确认:当前模型的 provider id 是否与上表一致(自定义 id 不会自动映射)→ 该家检测开关是否开启 → 是否被「没有检测到API的默认隐藏」收起(可在设置页临时关掉它)→ 运行中的 Host 与 Client 是否都已重载 |
258
259
  | 设置页没有提供商标签 | 展开提供商管理,确认开关和凭据;无凭据的条目默认隐藏,可临时关闭自动隐藏查看指引 |
260
+ | 提示「无凭据 / 未检测到 Key」 | 先确认填的是**额度凭据**而不是推理 Key(两者不通用,见[凭据获取指引](docs/credentials.md)),再按该家小节核对来源、环境变量与权限 |
261
+ | 提示「已保存」但仍是「无凭据」 | 凭据编辑要点「**保存设置**」才提交(提供商开关才是立即保存);确认后若仍为空,把界面文案反馈上来 |
259
262
  | 某家读取失败,其他家正常 | 单家失败只影响自己的条目。按文案分类处理:认证类(401 / 凭据被拒)换对应产品与区域的凭据;权限 / 未订阅类(403)检查账号权限与套餐;限流类等待退避后重试 |
260
263
  | 显示认证失效 | 检查是否用了对应产品 / 区域的订阅 Key;MiMo 重新登录或导入 Cookie;旧额度不会当作有效数据保留 |
261
264
  | MiMo Cookie 过期 | 会话 Cookie 自签发起 24 小时有效。药丸与设置页会在 2 小时内 / 30 分钟内分别变黄、变橙,到期显示「Cookie 已过期,请重新登录」;重新登录或重新导入即重新计时。倒计时只是提醒,真实失效以官方接口返回为准 |
@@ -305,7 +308,7 @@ node scripts/render-ui-preview.mjs 530 nanogpt light pill
305
308
  node scripts/check-browser-runtime.mjs # 需要工作区可解析 playwright-core 且本机装有 Google Chrome
306
309
  ```
307
310
 
308
- 文档入口:[开发与验证](docs/development.md)(RPC 契约、缓存与凭据约定、离线预览与实机验收范围)、[提供商清单与额度语义](docs/providers.md)、[提供商覆盖与取舍](docs/provider-coverage.md)、[UX 设计](docs/design-ux.md)、[发布与市场收录](docs/publish.md)、[更新记录](docs/changelog.md)、[审查记录](docs/code-review.md)。
311
+ 文档入口:[凭据获取指引](docs/credentials.md)(每类凭据的官网入口、环境变量与填入位置、报错对照)、[开发与验证](docs/development.md)(RPC 契约、缓存与凭据约定、离线预览与实机验收范围)、[提供商清单与额度语义](docs/providers.md)、[提供商覆盖与取舍](docs/provider-coverage.md)、[UX 设计](docs/design-ux.md)、[发布与市场收录](docs/publish.md)、[更新记录](docs/changelog.md)、[审查记录](docs/code-review.md)。
309
312
 
310
313
  > 打包说明:`package.json` 的 `files` 白名单是 `lib` / `locale` / `cordis.patch.yml` / `README.md`,因此 `assets/title.svg`、`assets/screenshots/` 与 `docs/` **不进 npm 包**——顶部 title 图与下面的界面预览只在 GitHub 页面显示。改动白名单属于发布决策,需单独处理。
311
314
 
package/lib/client.js CHANGED
@@ -74,6 +74,15 @@ window.__ModuleLoader__.load({
74
74
  wperiod: "本周期",
75
75
  wsub: "本周期",
76
76
  wrolling: "滚动",
77
+ // 药丸上的窗口短标签(只在有多个窗口时才出现):不要用 W / M / D 这类缩写让人猜,直接给中文单位。
78
+ s5h: "5时",
79
+ s7d: "7天",
80
+ sday: "日",
81
+ sweek: "周",
82
+ smonth: "月",
83
+ speriod: "周期",
84
+ ssub: "订阅",
85
+ srolling: "滚动",
77
86
  wall: "全部",
78
87
  detailUsed: "已用 {used} / 总计 {limit} {unit}",
79
88
  detailReset: "重置于 {time}",
@@ -178,6 +187,15 @@ window.__ModuleLoader__.load({
178
187
  wperiod: "Period",
179
188
  wsub: "Monthly",
180
189
  wrolling: "Rolling",
190
+ // Pill window tags (only shown when there are several windows): spell out the unit rather than D/W/M.
191
+ s5h: "5h",
192
+ s7d: "7d",
193
+ sday: "1d",
194
+ sweek: "1w",
195
+ smonth: "1m",
196
+ speriod: "cycle",
197
+ ssub: "sub",
198
+ srolling: "roll",
181
199
  wall: "All",
182
200
  detailUsed: "Used {used} / total {limit} {unit}",
183
201
  detailReset: "Resets {time}",
@@ -228,7 +246,8 @@ window.__ModuleLoader__.load({
228
246
  };
229
247
  const NS = "settings.subusage";
230
248
  const KIND_LABEL = { "5h": "w5h", "7d": "w7d", day: "wday", week: "wweek", month: "wmonth", period: "wperiod", sub: "wsub", rolling: "wrolling" };
231
- const KIND_SHORT = { "5h": "5h", "7d": "7d", day: "D", week: "W", month: "M", period: "P", sub: "Sub", rolling: "R" };
249
+ // 药丸的窗口短标签存的是 locale key:让人看 "W"/"M"/"D" 去猜是哪个窗口,不如直接给单位。
250
+ const KIND_SHORT = { "5h": "s5h", "7d": "s7d", day: "sday", week: "sweek", month: "smonth", period: "speriod", sub: "ssub", rolling: "srolling" };
232
251
  const PROVIDER_META = {
233
252
  // 余额型:接口给账户余额而不是订阅窗口,药丸用余额兜底文案显示。
234
253
  "deepseek": { label: "DeepSeek", short: "DeepSeek", envName: "DEEPSEEK_API_KEY" },
@@ -282,9 +301,15 @@ window.__ModuleLoader__.load({
282
301
  // 顺序只影响展示:DeepSeek 放在末尾以免打乱既有条目位置;药丸匹配靠 provider id,与顺序无关。
283
302
  const PROVIDER_ORDER = ["zai-coding-cn", "kimi-coding", "xiaomi-token-plan-cn", "opencode-go", "commandcode", "openai-codex", "xai-oauth", "minimax", "minimax-cn", "zai-coding", "synthetic", "nanogpt", "ark-coding-plan-cn", "ark-agent-plan-cn", "ark-coding-plan-byteplus", "siliconflow", "deepseek", "openrouter", "novita", "hyperbolic", "deepinfra", "chutes", "ollama-cloud", "vercel-ai-gateway", "zenmux", "litellm", "arkcli-agent-plan", "arkcli-coding-plan", "arkcli-agent-plan-team", "arkcli-coding-plan-team"];
284
303
  function providerEnabled(settings, id) { return settings?.visibility?.providers?.[id] ?? (PROVIDER_META[id]?.defaultEnabled !== false); }
285
- function providerVisible(settings, id, entry) {
304
+ // provider id 就是路由 id,而路由由提供方插件/CLI 按「你实际订阅了什么」写入:例如 arkcli helper
305
+ // 只会为真正持有的套餐写路由。所以本机没有 Coding Plan 路由时,就不该默认把 Coding Plan 显示出来
306
+ // ——这比「常量里默认开启」更贴近事实。undefined = 拿不到路由表,按「未知」放行,不谎报未安装。
307
+ function providerRoutable(result, id) { return result?.configured?.[id] !== false; }
308
+ function providerVisible(settings, id, entry, result) {
286
309
  if (!providerEnabled(settings, id)) return false;
310
+ // 关掉「没有检测到 API 的默认隐藏」就是要看全部,不再按路由或凭据收起。
287
311
  if (settings?.visibility?.hideWithoutApi === false) return true;
312
+ if (!providerRoutable(result, id)) return false;
288
313
  return entry?.apiDetected !== false && !["no-key", "no-cookie"].includes(entry?.state);
289
314
  }
290
315
  /** token 数紧凑格式:1,234,567,890 → 1.23B */
@@ -341,7 +366,8 @@ window.__ModuleLoader__.load({
341
366
  }
342
367
  /** 药丸文案:永远答「还能用多少」(余),限额/连坐直说。多窗带窗口短名。 */
343
368
  function pillText(w, multi, t) {
344
- const short = multi ? `${KIND_SHORT[w.kind] ?? w.kind} ` : "";
369
+ // 短标签走 locale(中文「周 / 月 / 日」,英文 1w / 1m / 1d),不让人猜 W 是哪个窗口。
370
+ const short = multi ? `${t(KIND_SHORT[w.kind] ?? "srolling")} ` : "";
345
371
  if (w.status === "rate-limited" && !w.cascade) return `${short}${t("pillLimited")}`;
346
372
  if (w.status === "rate-limited") return `${short}${t("pillBlocked")}`;
347
373
  return `${short}${t("pillRemaining").replace("{p}", String(Math.round(Math.max(0, 100 - w.percent) * 10) / 10))}`;
@@ -642,7 +668,7 @@ window.__ModuleLoader__.load({
642
668
  };
643
669
  const refresh = (ids, force = false) => {
644
670
  if (disposed) return Promise.reject(new Error("Client 已卸载"));
645
- const unique = [...new Set(ids)].filter((id) => PROVIDER_ORDER.includes(id) && providerEnabled(snapshot.settings, id));
671
+ const unique = [...new Set(ids)].filter((id) => PROVIDER_ORDER.includes(id) && providerEnabled(snapshot.settings, id) && providerRoutable(snapshot, id));
646
672
  const missing = unique.filter((id) => !inflight.has(id));
647
673
  if (missing.length) {
648
674
  const startedEpoch = epoch, request = markRequest(missing);
@@ -711,7 +737,7 @@ window.__ModuleLoader__.load({
711
737
  },
712
738
  reader: (id) => {
713
739
  if (!readers.has(id)) {
714
- const current = () => { const e = snapshot.entries.find((item) => item.providerId === id); return { ...(e || { providerId: id, state: "loading", windows: [] }), visible: providerVisible(snapshot.settings, id, e) }; };
740
+ const current = () => { const e = snapshot.entries.find((item) => item.providerId === id); return { ...(e || { providerId: id, state: "loading", windows: [] }), visible: providerVisible(snapshot.settings, id, e, snapshot) }; };
715
741
  const fn = async (force = false) => { await refresh([id], force); return current(); };
716
742
  fn.subscribe = (cb) => subscribe(() => cb(current()));
717
743
  fn.activate = () => activate(id);
@@ -886,6 +912,9 @@ window.__ModuleLoader__.load({
886
912
  w.detail && typeof w.detail.used === "number" && typeof w.detail.limit === "number" && w.detail.limit > 0
887
913
  ? t("detailUsed").replace("{used}", fmtTokens(w.detail.used)).replace("{limit}", fmtTokens(w.detail.limit)).replace("{unit}", w.detail.unit || "")
888
914
  : null,
915
+ // 不同额度线之间不可比(例如 AFP 的日限额只覆盖视觉 / 语音模型与 Harness):如实标出适用范围,
916
+ // 否则"日比周还高"会被读成插件算错。
917
+ w.detail && w.detail.note ? w.detail.note : null,
889
918
  w.detail && w.detail.limitSource === "plan-snapshot" ? t("planSnapshotLimit") : null,
890
919
  resetLine(w, t, getLocale),
891
920
  w.cascade ? t("cascadeLimited") + (w.detail && w.detail.blockedBy ? ` [${w.detail.blockedBy.join(", ")}]` : "") : null
@@ -1044,7 +1073,13 @@ window.__ModuleLoader__.load({
1044
1073
  t("ccUsageAccount").replace("{account}", ccState.activeId === "" || ccState.activeId === "default" ? t("ccAccountDefault") : (ccState.accounts.find((a) => a.id === ccState.activeId)?.label ?? ccState.activeId)),
1045
1074
  ccState.activeId === "" ? h("span", { style: { opacity: 0.85 } }, ` · ${t("ccUsageAutoNote")}`) : null)
1046
1075
  : null,
1047
- windows.map((w) => h(UsageWindowRow, { key: w.kind, w, t, getLocale, uncertain: degraded })),
1076
+ // 额度线切换时插一条分组标题:AFP 的日限额只覆盖视觉 / 语音模型与 Harness,与文本模型的
1077
+ // 5 小时 / 周 / 月不是同一条线,混排会让人把两条线的配额当成一组来互相比较。
1078
+ windows.map((w, index) => h(react.Fragment, { key: w.kind },
1079
+ w.groupLabel && w.groupLabel !== windows[index - 1]?.groupLabel
1080
+ ? h("p", { style: { margin: index ? "14px 0 0" : "6px 0 0", fontSize: 11, opacity: 0.6 } }, w.groupLabel)
1081
+ : null,
1082
+ h(UsageWindowRow, { w, t, getLocale, uncertain: degraded }))),
1048
1083
  entry && entry.extras && entry.extras.length > 0
1049
1084
  ? h("div", { style: { marginTop: 10, opacity: 0.85 } },
1050
1085
  entry.extras.map((x) => h("div", { key: x.kind }, `${extraLabel(x, t)}: ${x.value}`)))
@@ -1069,6 +1104,9 @@ window.__ModuleLoader__.load({
1069
1104
  function draftFor(settings, id) {
1070
1105
  return { keyMode: settings && settings.keyModes && settings.keyModes[id] || "inherit", keyAction: "keep", key: "", cookieAction: "keep", cookie: "", zai: { type: 1, organization: "", project: "", ...(settings && settings.zai) }, volc: { accessKey: "", secret: "", clear: false }, litellm: { baseUrl: settings && settings.litellm && settings.litellm.baseUrl || "" } };
1071
1106
  }
1107
+ // 从网页/控制台复制值时常带上换行、制表或零宽字符,而这些字段本身都不含空白——
1108
+ // 剔除它们比「拒绝保存」省事得多:拒绝只会让用户觉得「填了没用」。
1109
+ function stripInvisible(raw) { return String(raw).replace(/[\s\u200b-\u200d\ufeff]/g, ""); }
1072
1110
  function settingsPatch(id, draft, revision) {
1073
1111
  if (typeof revision !== "string" || !revision) throw new Error("请先加载最新设置,再编辑保存 / Load settings before saving");
1074
1112
  const patch = { providerId: id, expectedRevision: revision };
@@ -1081,10 +1119,11 @@ window.__ModuleLoader__.load({
1081
1119
  if (draft.volc.clear) patch.volc = { accessKeyId: { action: "clear" }, secretAccessKey: { action: "clear" } };
1082
1120
  else {
1083
1121
  const volc = {};
1084
- const accessKey = draft.volc.accessKey.trim(), secret = draft.volc.secret.trim();
1122
+ // 从控制台复制 AK/SK 时经常带上换行、制表或零宽字符,而 AK/SK 本身不含任何空白,
1123
+ // 所以这里**剔除**这些不可见字符而不是拒绝保存——拒绝过严会让用户只看到"没反应"。
1124
+ const accessKey = stripInvisible(draft.volc.accessKey), secret = stripInvisible(draft.volc.secret);
1085
1125
  for (const [field, value] of [["accessKeyId", accessKey], ["secretAccessKey", secret]]) {
1086
1126
  if (!value) continue;
1087
- if (/[\x00-\x1f\x7f]/.test(value)) throw new Error("Access Key 不能包含控制字符");
1088
1127
  volc[field] = { action: "replace", value };
1089
1128
  }
1090
1129
  if (Object.keys(volc).length) patch.volc = volc;
@@ -1098,12 +1137,13 @@ window.__ModuleLoader__.load({
1098
1137
  patch.keyMode = draft.keyMode;
1099
1138
  patch.keyUpdate = { action: draft.keyAction };
1100
1139
  if (draft.keyAction === "replace") {
1101
- if (!draft.key.trim() || /[\r\n\x00-\x1f\x7f]/.test(draft.key)) throw new Error("API Key 不能为空或包含控制字符");
1102
- patch.keyUpdate.value = draft.key.trim();
1140
+ const key = stripInvisible(draft.key);
1141
+ if (!key) throw new Error("API Key 不能为空");
1142
+ patch.keyUpdate.value = key;
1103
1143
  }
1104
- if (id === "zai-coding-cn") patch.zai = { ...draft.zai };
1144
+ if (id === "zai-coding-cn") patch.zai = { ...draft.zai, organization: stripInvisible(draft.zai.organization), project: stripInvisible(draft.zai.project) };
1105
1145
  // LiteLLM 的代理地址不是秘密,原样提交;空串表示清空(请求时会按「未配置」提示)。
1106
- if (id === "litellm") patch.litellm = { baseUrl: draft.litellm.baseUrl.trim() };
1146
+ if (id === "litellm") patch.litellm = { baseUrl: stripInvisible(draft.litellm.baseUrl) };
1107
1147
  }
1108
1148
  return patch;
1109
1149
  }
@@ -1224,9 +1264,14 @@ window.__ModuleLoader__.load({
1224
1264
  const patch = settingsPatch(tab, draft, revisionRef.current);
1225
1265
  const saved = await usageStore.save(patch);
1226
1266
  if (!aliveRef.current) return;
1267
+ // 填了 AK/SK 却只得到一句「已保存」是最误导人的失败方式:这里如实回显到底存没存上。
1268
+ const intendedVolc = Boolean(PROVIDER_META[tab].volc && (patch.volc?.accessKeyId || patch.volc?.secretAccessKey));
1269
+ const storedVolc = Boolean(saved.settings?.volc?.hasAccessKeyId || saved.settings?.volc?.hasSecretAccessKey);
1227
1270
  dirtyRef.current = false; setDirty(false);
1228
1271
  setDraft(draftFor(saved.settings, tab)); revisionRef.current = saved.settings && saved.settings.revision;
1229
- setNotice({ ok: true, text: t("saved") });
1272
+ setNotice(intendedVolc && !storedVolc
1273
+ ? { ok: false, text: text("设置已保存,但你填的 AK/SK 没有写入。请重试;或改用环境变量 VOLC_ACCESSKEY / VOLC_SECRETKEY(重启后生效)。", "Settings saved, but the AK/SK you entered was not stored. Retry, or use the VOLC_ACCESSKEY / VOLC_SECRETKEY environment variables (takes effect after restart).") }
1274
+ : { ok: true, text: t("saved") });
1230
1275
  if (!providerEnabled(saved.settings, tab)) return;
1231
1276
  // 保存已成功落盘;独立验证失败不改写成“保存失败”。
1232
1277
  try {
@@ -1245,7 +1290,7 @@ window.__ModuleLoader__.load({
1245
1290
  // 待处理的排前面;组内保持登记顺序,所以顺序不会自己抖动。
1246
1291
  const visibleIds = PROVIDER_ORDER
1247
1292
  .map((id, index) => ({ id, index, rank: usageAttentionRank(entries.find(e => e.providerId === id), t) }))
1248
- .filter(item => providerVisible(result.settings, item.id, entries.find(e => e.providerId === item.id)))
1293
+ .filter(item => providerVisible(result.settings, item.id, entries.find(e => e.providerId === item.id), result))
1249
1294
  .sort((a, b) => b.rank - a.rank || a.index - b.index)
1250
1295
  .map(item => item.id);
1251
1296
  const success = entries.filter((e) => visibleIds.includes(e.providerId) && e.state === "ok" && e.freshness !== "stale").length;
@@ -1285,6 +1330,11 @@ window.__ModuleLoader__.load({
1285
1330
  hasSaved && draft[kind + "Action"] !== "clear" ? h("button", { type: "button", style: btnStyle, disabled: kind === "cookie" && loginActive, onClick: () => { editDraft({ [kind + "Action"]: "clear", [kind]: "" }); setNotice({ ok: false, text: text("待清除:保存设置后将删除已保存的敏感凭据;取消编辑可保留。", "Pending removal: saving will delete the saved secret. Cancel edits to keep it.") }); } }, text(kind === "cookie" ? "清除登录凭据" : "清除", kind === "cookie" ? "Clear login credentials" : "Clear")) : null,
1286
1331
  draft[kind + "Action"] === "clear" ? h("span", { role: "status" }, text("将删除凭据(尚未保存)", "Credential will be deleted (not saved yet)")) : null
1287
1332
  );
1333
+ // 界面里那些「要先去别处才能拿到」的凭据,直接给出官方入口与本仓库指引,
1334
+ // 省得用户猜菜单藏在哪一层——顺带把「推理 Key ≠ 额度凭据」讲清楚。
1335
+ const CREDENTIALS_DOC = "https://github.com/KouzakiUmi/dsh-subusage/blob/main/docs/credentials.md";
1336
+ const credentialsGuide = h("a", { href: CREDENTIALS_DOC, target: "_blank", rel: "noopener noreferrer" }, text("获取与配置指引", "Get & configure guide"));
1337
+ const externalLink = (href, label) => h("a", { href, target: "_blank", rel: "noopener noreferrer" }, label);
1288
1338
  const credentialEditor = h(react.Fragment, null,
1289
1339
  notice ? h("p", { role: "status", style: { color: notice.ok ? "inherit" : "#dc2626" } }, notice.text) : null,
1290
1340
  h("div", { style: { marginTop: 10 } },
@@ -1296,6 +1346,8 @@ window.__ModuleLoader__.load({
1296
1346
  tab === "commandcode" ? h(react.Fragment, null, h("p", null, t("commandcodeManaged"))) : tab === "xai-oauth" ? h(react.Fragment, null, h("p", null, t("grokManaged"))) : tab === "openai-codex" ? h(react.Fragment, null,
1297
1347
  h("p", null, text("只读 Codex CLI 的 ChatGPT 订阅登录($CODEX_HOME/auth.json 或 ~/.codex/auth.json):本页不保存凭据、不刷新 token。请用 codex login 登录;API Key 模式(auth_mode 不是 chatgpt)取不到订阅额度。", "Reads the Codex CLI ChatGPT subscription login ($CODEX_HOME/auth.json or ~/.codex/auth.json) read-only: this page never saves credentials or refreshes tokens. Sign in with codex login; API-key mode (auth_mode not chatgpt) cannot read subscription quota."))) : PROVIDER_META[tab].volc ? h(react.Fragment, null,
1298
1348
  h("p", null, text("额度查询要用火山引擎 IAM 的 Access Key(AK/SK 配对,权限建议只给方舟只读),与推理用的方舟 API Key 不是同一套;Ark 的这几条路由共用这一组凭据。", "Quota lookup needs a Volcengine IAM Access Key pair (Ark read-only is enough). This is NOT the Ark inference API key; every Ark route here shares this pair.")),
1349
+ // 用户通常已经登录着控制台,直接给入口比让他自己翻菜单快得多。
1350
+ h("p", { style: { fontSize: 12 } }, externalLink("https://console.volcengine.com/iam/keymanage", text("打开火山引擎「API 访问密钥」创建 AK/SK", "Open Volcengine “API access keys”")), " · ", credentialsGuide),
1299
1351
  h("div", { role: "group", "aria-label": text("Key 来源模式", "Key source mode"), style: { display: "flex", gap: 8, flexWrap: "wrap" } },
1300
1352
  ["inherit", "manual"].map((mode) => h("button", { key: mode, type: "button", "aria-pressed": draft.keyMode === mode, style: draft.keyMode === mode ? primary : btnStyle, onClick: () => editDraft({ keyMode: mode }) }, `${draft.keyMode === mode ? "✓ " : ""}${mode === "inherit" ? text("继承凭据 / 环境变量", "Inherit credentials / environment") : text("手动 AK/SK", "Manual AK/SK")}`))),
1301
1353
  h("p", { style: { fontSize: 12 } }, text("继承变量:", "Inherited variables: "), h("code", null, "VOLC_ACCESSKEY"), " / ", h("code", null, "VOLC_SECRETKEY")),
@@ -1311,7 +1363,7 @@ window.__ModuleLoader__.load({
1311
1363
  ({ launching: text("正在启动登录浏览器…", "Launching login browser…"), waiting: text("请在浏览器中完成登录…", "Complete sign-in in the browser…"), verifying: text("正在验证并导入…", "Verifying & importing…") })[login.state],
1312
1364
  h("button", { type: "button", style: btnStyle, disabled: !login.jobId, onClick: cancelLogin }, text("取消登录", "Cancel login"))) : null,
1313
1365
  login.state === "error" || login.state === "cancelled" ? h("p", { role: "status" }, login.state === "cancelled" ? text("登录已取消,可重新登录或手动导入。", "Login cancelled. Retry or import manually.") : text("自动登录失败,可重试或手动导入。", "Automatic login failed. Retry or import manually.") + (login.message ? " " + login.message : "")) : null,
1314
- h("p", null, h("a", { href: "https://platform.xiaomimimo.com", target: "_blank", rel: "noopener noreferrer" }, text("仅打开 MiMo 官网(不会自动导入)", "Open MiMo website only (no automatic import)"))),
1366
+ h("p", { style: { fontSize: 12 } }, externalLink("https://platform.xiaomimimo.com/console/plan-manage", text("仅打开 MiMo 控制台套餐页(不会自动导入)", "Open the MiMo console only (no automatic import)")), " · ", credentialsGuide),
1315
1367
  h("p", null, result.settings && result.settings.xiaomi && result.settings.xiaomi.hasCookie ? text("已保存 Cookie(不回填)", "Cookie saved (never filled back)") : t("statusNoCookie")),
1316
1368
  cookieLifetimeLine(result.settings && result.settings.xiaomi, t, getLocale),
1317
1369
  h("p", { style: { fontSize: 12, opacity: .75 } }, t("mimoCookieTtl")),
@@ -1324,14 +1376,17 @@ window.__ModuleLoader__.load({
1324
1376
  h("div", { role: "group", "aria-label": text("Key 来源模式", "Key source mode"), style: { display: "flex", gap: 8, flexWrap: "wrap" } },
1325
1377
  ["inherit", "manual"].map((mode) => h("button", { key: mode, type: "button", "aria-pressed": draft.keyMode === mode, style: draft.keyMode === mode ? primary : btnStyle, onClick: () => editDraft({ keyMode: mode }) }, `${draft.keyMode === mode ? "✓ " : ""}${mode === "inherit" ? text("继承凭据 / 环境变量", "Inherit credentials / environment") : text("手动 Key", "Manual key")}`))),
1326
1378
  h("p", { style: { fontSize: 12 } }, result.settings && result.settings.hasKeys && result.settings.hasKeys[tab] ? text("已保存 Key(不回填)", "Key saved (never filled back)") : text("未保存手动 Key", "No manual key saved")),
1379
+ h("p", { style: { fontSize: 12 } }, credentialsGuide, " ", text("(含各家 API Key 的获取入口与环境变量名)", "(provider API-key sources and env var names)")),
1327
1380
  credentialButtons("key", result.settings && result.settings.hasKeys && result.settings.hasKeys[tab]),
1328
1381
  draft.keyAction === "replace" ? h("label", null, t("keyLabel"), h("input", { type: "password", autoComplete: "new-password", value: draft.key, disabled: busy, onChange: (e) => editDraft({ key: e.target.value }), style: inputStyle })) : null),
1329
1382
  tab === "litellm" ? h(react.Fragment, null,
1330
1383
  h("label", null, text("代理地址", "Proxy base URL"), h("input", { autoComplete: "off", spellCheck: false, value: draft.litellm.baseUrl, disabled: busy, placeholder: "https://litellm.example.com", onChange: (e) => editDraft({ litellm: { ...draft.litellm, baseUrl: e.target.value } }), style: inputStyle })),
1331
- h("p", { style: { fontSize: 12, opacity: .75 } }, text("管理端点在 proxy 根:末尾的 /v1 会被自动去掉。虚拟 Key 与推理用的是同一把。", "Admin endpoints live at the proxy root: a trailing /v1 is stripped. The virtual key is the same one you use for inference."))) : null,
1384
+ h("p", { style: { fontSize: 12, opacity: .75 } }, text("管理端点在 proxy 根:末尾的 /v1 会被自动去掉。虚拟 Key 与推理用的是同一把。", "Admin endpoints live at the proxy root: a trailing /v1 is stripped. The virtual key is the same one you use for inference.")),
1385
+ h("p", { style: { fontSize: 12 } }, credentialsGuide)) : null,
1332
1386
  tab === "zai-coding-cn" ? h(react.Fragment, null,
1333
1387
  h("div", { role: "radiogroup", "aria-label": t("zaiType"), style: { display: "flex", gap: 8, flexWrap: "wrap" } }, [1, 2].map(type => h("button", { key: type, type: "button", role: "radio", "aria-checked": draft.zai.type === type, style: draft.zai.type === type ? primary : btnStyle, disabled: busy, onClick: () => editDraft({ zai: { ...draft.zai, type } }) }, t(type === 1 ? "zaiTypePersonal" : "zaiTypeTeam")))),
1334
- draft.zai.type === 2 ? ["organization", "project"].map((name) => h("label", { key: name }, t(name === "organization" ? "zaiOrg" : "zaiProject"), h("input", { value: draft.zai[name] || "", disabled: busy, style: inputStyle, onChange: (e) => editDraft({ zai: { ...draft.zai, [name]: e.target.value } }) }))) : null) : null,
1388
+ draft.zai.type === 2 ? ["organization", "project"].map((name) => h("label", { key: name }, t(name === "organization" ? "zaiOrg" : "zaiProject"), h("input", { value: draft.zai[name] || "", disabled: busy, style: inputStyle, onChange: (e) => editDraft({ zai: { ...draft.zai, [name]: e.target.value } }) }))) : null,
1389
+ draft.zai.type === 2 ? h("p", { style: { fontSize: 12 } }, credentialsGuide, " ", text("(团队档的组织 / 项目 ID 在哪拿)", "(where to find team org / project IDs)")) : null) : null,
1335
1390
  dirty ? h("div", { style: { display: "flex", gap: 8, marginTop: 10 } }, h("button", { type: "button", disabled: busy || (tab === "xiaomi-token-plan-cn" && loginActive), style: primary, onClick: onSave }, t(busy ? "saving" : "save")), h("button", { type: "button", disabled: busy, style: btnStyle, onClick: cancel }, text("取消编辑", "Cancel edits"))) : null)),
1336
1391
  h("details", { style: { marginTop: 12 } }, h("summary", { style: { cursor: "pointer" } }, text("技术信息与帮助", "Technical information & help")),
1337
1392
  h("code", null, tab), tab !== "xiaomi-token-plan-cn" && meta.envName ? h("p", null, text("继承变量:", "Inherited variable: "), h("code", null, meta.envName)) : null, h("p", null, t("hint")), ["minimax", "minimax-cn"].includes(tab) ? h("p", null, text("需要对应区域的 Token Plan / Coding Plan 订阅 Key,不是按量计费 Key。读取通用/编程池的剩余百分比;零总计、无上限或未报告的窗口不会显示为零用量,周加量不折算为额外百分比。", "Use a Token Plan / Coding Plan subscription key for the selected region, not a pay-as-you-go key. Shows the general/coding pool; zero-total, unlimited or absent windows are not displayed as zero usage. Weekly boosts are not converted into extra percentage.")) : null, tab === "zai-coding-cn" ? h("p", null, t("zaiOrgHint")) : null, tab === "commandcode" ? h("p", null, t("commandcodeHelp")) : null, tab === "xai-oauth" ? h("p", null, t("grokHelp")) : null,
@@ -1344,12 +1399,13 @@ window.__ModuleLoader__.load({
1344
1399
  !editorOpen && notice ? h("p", { role: "status", style: { color: notice.ok ? "inherit" : "#dc2626" } }, notice.text) : null,
1345
1400
  h("button", { type: "button", role: "switch", "aria-checked": hideWithoutApi, disabled: busy || dirty || !result.settings?.revision, "aria-label": text("没有检测到API的默认隐藏", "Hide providers without detected API credentials"), style: hideWithoutApi ? primary : btnStyle, onClick: () => saveVisibility({ hideWithoutApi: !hideWithoutApi }) }, `${hideWithoutApi ? "✓ " : "○ "}${text("没有检测到API的默认隐藏", "Hide providers without detected API credentials")}`),
1346
1401
  h("p", { style: { fontSize: 12, opacity: .75 } }, text("检测依据为可用 Key 或 MiMo Cookie 是否存在;认证失败和网络错误不会当成未配置 API。隐藏的提供商仍可在这里配置。", "Detection checks for a Key or MiMo Cookie, not request success. Auth/network errors are not treated as missing API credentials. Hidden providers remain configurable here.")),
1347
- h("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 240px), 1fr))", gap: 8 } }, PROVIDER_ORDER.map(id => {
1402
+ // 启用的排到最前面,省得每次往下翻;组内保持 PROVIDER_ORDER 的既有顺序(sort 稳定)。
1403
+ h("div", { style: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 240px), 1fr))", gap: 8 } }, [...PROVIDER_ORDER].sort((a, b) => Number(!providerEnabled(result.settings, a)) - Number(!providerEnabled(result.settings, b))).map(id => {
1348
1404
  const enabled = providerEnabled(result.settings, id), e = entries.find(item => item.providerId === id), editing = tab === id && editorOpen;
1349
1405
  return h("div", { key: id, style: { gridColumn: editing ? "1 / -1" : undefined, display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center", border: "1px solid rgba(128,128,128,.25)", borderRadius: 8, padding: 8 } },
1350
1406
  h("span", { style: { flex: 1, minWidth: 80 } }, PROVIDER_META[id].short),
1351
1407
  h("button", { type: "button", role: "switch", "aria-checked": enabled, disabled: busy || dirty || !result.settings?.revision, "aria-label": `${text("启用", "Enable")} ${PROVIDER_META[id].short}`, style: enabled ? primary : btnStyle, onClick: () => saveVisibility({ providers: { [id]: !enabled } }) }, enabled ? text("已开启", "On") : text("已关闭", "Off")),
1352
- h("span", { style: { width: "100%", fontSize: 12, opacity: .75 } }, !enabled ? text("检测已关闭", "Detection disabled") : e?.apiDetected === false || ["no-key", "no-cookie"].includes(e?.state) ? text(hideWithoutApi ? "未检测到 API · 默认隐藏" : "未检测到 API", "No API credentials detected") : e?.apiDetected === true || (e?.keySource && e.keySource !== "none") ? text("已检测到 API / 凭据", "API credentials detected") : text("待检测", "Detection pending")),
1408
+ h("span", { style: { width: "100%", fontSize: 12, opacity: .75 } }, !enabled ? text("检测已关闭", "Detection disabled") : !providerRoutable(result, id) ? text("本机没装这条路由:提供方插件或 CLI 没有注册它,开了也读不到东西", "Route not installed on this machine: no provider plugin or CLI registered it, so enabling it reads nothing") : e?.apiDetected === false || ["no-key", "no-cookie"].includes(e?.state) ? text(hideWithoutApi ? "未检测到 API · 默认隐藏" : "未检测到 API", "No API credentials detected") : e?.apiDetected === true || (e?.keySource && e.keySource !== "none") ? text("已检测到 API / 凭据", "API credentials detected") : text("待检测", "Detection pending")),
1353
1409
  h("details", { id: `subusage-credentials-${id}`, open: editing, style: { width: "100%" } },
1354
1410
  h("summary", { "aria-label": `${text("连接与凭据", "Connection & credentials")} ${PROVIDER_META[id].short}`, style: { cursor: "pointer" }, onClick: event => { event.preventDefault(); if (busy) return; if (editing) setEditorOpen(false); else openEditor(id); } }, text(id === "xiaomi-token-plan-cn" ? "登录与凭据" : PROVIDER_META[id].managedByPlugin ? "凭据来源" : "连接与凭据", id === "xiaomi-token-plan-cn" ? "Login & credentials" : PROVIDER_META[id].managedByPlugin ? "Credential source" : "Connection & credentials")),
1355
1411
  tab === id ? credentialEditor : null));
package/lib/index.js CHANGED
@@ -227,7 +227,9 @@ function parseSettings(value) {
227
227
  }
228
228
  return { expectedRevision: value.expectedRevision, visibility };
229
229
  }
230
- if (!value || typeof value !== "object" || !IDS.includes(value.providerId)) throw invalid("Invalid provider patch");
230
+ // 这里只校验形状:未知 provider(新版 Client + 还没重启的旧 Host)交给 persist 给可读错误,
231
+ // 否则用户只会看到网关的 "boundary validation" 通用报错,无从判断该重启还是该改配置。
232
+ if (!value || typeof value !== "object" || typeof value.providerId !== "string" || !value.providerId) throw invalid("Invalid provider patch");
231
233
  const out = { providerId: value.providerId };
232
234
  if (value.expectedRevision !== undefined) { if (typeof value.expectedRevision !== "string") throw invalid("Invalid revision"); out.expectedRevision = value.expectedRevision; }
233
235
  if (value.keyMode !== undefined) { if (!["inherit", "manual"].includes(value.keyMode)) throw invalid("Invalid key mode"); out.keyMode = value.keyMode; }
@@ -273,12 +275,16 @@ function parseSettings(value) {
273
275
  function parseQuery(value) {
274
276
  // request 在 wire 层可选(read 描述符声明 acceptsUndefined):缺参/undefined/null
275
277
  // = 全量默认账户查询,兼容旧 client bundle 的无参 read。
276
- if (value === undefined || value === null) return { providerIds: [...IDS], force: false, commandCodeAccount: "" };
277
- if (!value || !Array.isArray(value.providerIds) || value.providerIds.some(id => !IDS.includes(id)) || typeof value.force !== "boolean") throw invalid("Invalid refresh request");
278
+ if (value === undefined || value === null) return { providerIds: [...IDS], unknown: [], force: false, commandCodeAccount: "" };
279
+ // 未知 id **过滤而不是整体拒绝**:provider 清单随版本演进,而 Host 需要重启、Client 刷新即生效,
280
+ // 这个版本窗口期里客户端必然带着本 Host 还不认识的 id 过来。整体拒绝会让用户一片空白;
281
+ // 过滤掉未知项并单独回一条可读原因(见 refresh),既保住其它提供商,也说清了为什么。
282
+ if (!value || !Array.isArray(value.providerIds) || typeof value.force !== "boolean") throw invalid("Invalid refresh request");
278
283
  // commandCodeAccount 是可选的显示账户选择:空串/缺省 = 默认账户(顶层 Key);
279
284
  // 额外账户 id 即其凭据引用名(apiKeyEnv),由 identity 按引用解析。
280
285
  if (value.commandCodeAccount !== undefined && typeof value.commandCodeAccount !== "string") throw invalid("Invalid account selection");
281
- return { providerIds: [...new Set(value.providerIds)], force: value.force, commandCodeAccount: typeof value.commandCodeAccount === "string" ? value.commandCodeAccount.trim() : "" };
286
+ const requested = [...new Set(value.providerIds)].filter(id => typeof id === "string");
287
+ return { providerIds: requested.filter(id => IDS.includes(id)), unknown: requested.filter(id => !IDS.includes(id)), force: value.force, commandCodeAccount: typeof value.commandCodeAccount === "string" ? value.commandCodeAccount.trim() : "" };
282
288
  }
283
289
  function failure(code, message, retryable = false, retryAfterMs) {
284
290
  return new RemoteError(code, message, { retryable, retainPrevious: retryable, ...(retryAfterMs !== undefined ? { retryAfterMs } : {}) });
@@ -296,7 +302,7 @@ function volcFailure(action, error) {
296
302
  }
297
303
  async function fetchJson(fetcher, url, headers, lifetimeSignal, init = {}) {
298
304
  let response;
299
- try { response = await fetcher(url, { method: init.method ?? "GET", ...(init.body !== undefined ? { body: init.body } : {}), headers: { accept: "application/json", "user-agent": "dsh-subusage/0.10.0", ...headers }, signal: lifetimeSignal ? AbortSignal.any([AbortSignal.timeout(10000), lifetimeSignal]) : AbortSignal.timeout(10000), redirect: "manual" }); }
305
+ try { response = await fetcher(url, { method: init.method ?? "GET", ...(init.body !== undefined ? { body: init.body } : {}), headers: { accept: "application/json", "user-agent": "dsh-subusage/0.10.2", ...headers }, signal: lifetimeSignal ? AbortSignal.any([AbortSignal.timeout(10000), lifetimeSignal]) : AbortSignal.timeout(10000), redirect: "manual" }); }
300
306
  catch { throw failure("subusage/network", "网络请求失败或超时", true); }
301
307
  if (response.status >= 300 && response.status < 400 || response.status === 401 || response.status === 403) throw failure("subusage/auth", "登录或凭据已失效");
302
308
  if (!response.ok) {
@@ -744,7 +750,7 @@ export function normalizeLitellm(keyBody, budgetBody) {
744
750
  }
745
751
  function detectConfigured(ctx) {
746
752
  try { const ids = new Set(ctx.llm.listProviders().map(p => p.id)); return Object.fromEntries(IDS.map(id => [id, ids.has(id)])); }
747
- catch { return Object.fromEntries(IDS.map(id => [id, false])); }
753
+ catch { return undefined; }
748
754
  }
749
755
  const codec = (type, parse) => ({ mode: "strict", typeSymbol: `dsh-subusage#${type}`, schema: { parse }, create: () => ({ parse }) });
750
756
  const resultCodec = codec("SubUsageResult", value => { if (!value || !Array.isArray(value.entries) || !value.settings || !value.configured || typeof value.updatedAt !== "string") throw invalid("Invalid result"); return value; });
@@ -1078,9 +1084,12 @@ export class SubUsageService extends TypertRemoteService {
1078
1084
  if (this.disposed) throw failure("subusage/disposed", "服务已卸载");
1079
1085
  const query = parseQuery(request); const settings = this.load();
1080
1086
  const entries = await Promise.all(query.providerIds.map(id => this.provider(id, settings, query.force, query.commandCodeAccount).catch(() => ({ ...this.base(id, "none", settings, query.commandCodeAccount), state: "error", errorCode: "subusage/internal", error: "读取用量失败" }))));
1087
+ // 客户端请求了本 Host 不认识的 provider(装了新版但还没重启 DSH):回一条可读原因,
1088
+ // 否则它只会显示成「无数据」,用户无从判断是该重启还是该配凭据。
1089
+ const unknownEntries = (query.unknown ?? []).map(id => ({ providerId: id, label: id, state: "error", errorCode: "subusage/unknown-provider", error: "本机运行中的 Host 版本较旧,不认识该提供商;重启 DSH 后生效", apiDetected: null, coverage: "partial", freshness: "unknown", keySource: "none", retryable: false, retainPrevious: false, windows: [], extras: [] }));
1081
1090
  const latest = this.load();
1082
- if (hash(latest) !== hash(settings)) return this.result(latest, query.providerIds.map(id => ({ ...this.base(id, "none", latest, query.commandCodeAccount), state: "error", errorCode: "subusage/config-changed", error: "读取期间配置已改变,请刷新" })));
1083
- return this.result(latest, entries);
1091
+ if (hash(latest) !== hash(settings)) return this.result(latest, [...query.providerIds.map(id => ({ ...this.base(id, "none", latest, query.commandCodeAccount), state: "error", errorCode: "subusage/config-changed", error: "读取期间配置已改变,请刷新" })), ...unknownEntries]);
1092
+ return this.result(latest, [...entries, ...unknownEntries]);
1084
1093
  }
1085
1094
  startMimoLogin(request) { return this.login.start(parseLoginStart(request)); } getMimoLoginStatus() { return this.login.status(); }
1086
1095
  cancelMimoLogin(request) { return this.login.cancel(parseLoginCancel(request)); }
@@ -1105,6 +1114,9 @@ export class SubUsageService extends TypertRemoteService {
1105
1114
  persist(settings, cookieCap) {
1106
1115
  if (this.disposed) throw failure("subusage/disposed", "服务已卸载");
1107
1116
  const patch = parseSettings(settings); const stored = this.load();
1117
+ // 未知 provider:这是「客户端已更新、Host 还没重启」的版本窗口期,给出可读原因而不是静默写入垃圾配置。
1118
+ // 只改可见性的 patch 不带 providerId,不能因此被拒。
1119
+ if (patch.providerId !== undefined && !IDS.includes(patch.providerId)) throw failure("subusage/unknown-provider", "本机运行中的 Host 版本较旧,不认识该提供商;重启 DSH 后生效");
1108
1120
  if (patch.expectedRevision !== undefined && patch.expectedRevision !== hash(stored)) throw failure("subusage/revision-conflict", "设置已被其他窗口修改,请重新读取");
1109
1121
  const id = patch.providerId;
1110
1122
  // 火山方舟两个 provider 共用一组 AK/SK:改凭据要让所有用它的条目失效,不能只失效当前标签页。
package/lib/mimo-login.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
 
3
3
  export const MIMO_ORIGIN = "https://platform.xiaomimimo.com";
4
+ // 登录要落到控制台的套餐管理页:站点首页不触发登录,用户还得自己点进控制台才有登录入口。
5
+ // 这一页也正是读取 tokenPlan/detail 与 tokenPlan/usage 的地方。
6
+ export const MIMO_LOGIN_URL = `${MIMO_ORIGIN}/console/plan-manage`;
4
7
  export const MIMO_API_URLS = ["balance", "tokenPlan/detail", "tokenPlan/usage"].map(path => `${MIMO_ORIGIN}/api/v1/${path}`);
5
8
  const ACTIVE = new Set(["launching", "waiting", "verifying"]);
6
9
  const REQUIRED = ["api-platform_serviceToken", "userId"];
@@ -84,7 +87,10 @@ export class MimoLogin {
84
87
  page.on?.("close", () => this.finish(job, "cancelled", undefined, "登录窗口已关闭,未保存 Cookie"));
85
88
  if (!this.alive(job)) return;
86
89
  phase = "navigate";
87
- await page.goto(MIMO_ORIGIN, { waitUntil: "domcontentloaded", timeout: 30000 });
90
+ // 先落控制台套餐页以直接触发登录;控制台历史上出现过 502(仅有首页可用),
91
+ // 那时回退到首页,至少让用户能自己在站内导航,而不是停在一个打不开的页面上。
92
+ try { await page.goto(MIMO_LOGIN_URL, { waitUntil: "domcontentloaded", timeout: 30000 }); }
93
+ catch { await page.goto(MIMO_ORIGIN, { waitUntil: "domcontentloaded", timeout: 30000 }); }
88
94
  if (!this.alive(job)) return;
89
95
  job.public.state = "waiting"; job.public.message = "请在官方窗口自行完成登录;账户验证通过后保存,额度状态另行显示";
90
96
  phase = "verify";
package/lib/volcengine.js CHANGED
@@ -128,7 +128,15 @@ export function parseVolcCodingPlan(body) {
128
128
  }
129
129
 
130
130
  // Agent Plan 的 AFP 窗口:Quota / Used 是绝对值,比例由两者算出。
131
- const AFP_WINDOWS = [["AFPFiveHour", "5h"], ["AFPDaily", "day"], ["AFPWeekly", "week"], ["AFPMonthly", "month"]];
131
+ // 顺序即展示顺序,第三列是**额度线分组**:文本 / 向量模型走 5 小时 → 周 → 月(同一条线),
132
+ // 而日限额只在视觉模型、语音模型与 Harness 上生效,是另一条线。两组各自成组展示并标注影响范围,
133
+ // 否则把两条线的配额并排放在一起,谁都会把"日比周还高"读成插件算错了。
134
+ const AFP_WINDOWS = [
135
+ ["AFPFiveHour", "5h", "文本 / 向量模型"],
136
+ ["AFPWeekly", "week", "文本 / 向量模型"],
137
+ ["AFPMonthly", "month", "文本 / 向量模型"],
138
+ ["AFPDaily", "day", "视觉 / 语音模型与 Harness"]
139
+ ];
132
140
 
133
141
  /**
134
142
  * 个人版 Agent Plan:Result 下四个滚动窗口。
@@ -139,14 +147,14 @@ export function parseVolcAgentPlan(body) {
139
147
  if (!result || typeof result !== "object") return { subscribed: false, windows: [], plan: undefined };
140
148
  const windows = [];
141
149
  let reported = false;
142
- for (const [field, kind] of AFP_WINDOWS) {
150
+ for (const [field, kind, groupLabel] of AFP_WINDOWS) {
143
151
  const row = result[field];
144
152
  if (!row || typeof row !== "object") continue;
145
153
  reported = true;
146
154
  const quota = amount(row.Quota), used = amount(row.Used);
147
155
  if (quota === undefined || used === undefined) throw new Error("Volcengine AFP window is invalid");
148
156
  if (quota <= 0) continue;
149
- windows.push({ kind, percent: Math.min(100, used / quota * 100), resetsAt: fromEpoch(row.ResetTime, "milliseconds"), detail: { used, limit: quota, unit: "AFP" } });
157
+ windows.push({ kind, percent: Math.min(100, used / quota * 100), resetsAt: fromEpoch(row.ResetTime, "milliseconds"), groupLabel, detail: { used, limit: quota, unit: "AFP" } });
150
158
  }
151
159
  const plan = typeof result.PlanType === "string" && result.PlanType.trim() ? result.PlanType.trim() : undefined;
152
160
  return { subscribed: windows.length > 0 || reported, windows, plan };
@@ -168,14 +176,16 @@ export function parseVolcSeatAfp(body) {
168
176
  const row = rows[0] && typeof rows[0] === "object" ? rows[0] : {};
169
177
  const windows = [];
170
178
  let reported = false;
171
- for (const [field, kind] of AFP_WINDOWS) {
179
+ // 席位版 Agent Plan 与个人版共用同一组 AFP 窗口(含那条只覆盖视觉 / 语音模型与 Harness 的日限额),
180
+ // 所以分组标注也要一起带上,否则席位卡片里同样会把两条额度线混着显示。
181
+ for (const [field, kind, groupLabel] of AFP_WINDOWS) {
172
182
  const window = row[field];
173
183
  if (!window || typeof window !== "object") continue;
174
184
  reported = true;
175
185
  const quota = amount(window.Quota), used = amount(window.Used);
176
186
  if (quota === undefined || used === undefined) throw new Error("Volcengine seat AFP window is invalid");
177
187
  if (quota <= 0) continue;
178
- windows.push({ kind, percent: Math.min(100, used / quota * 100), resetsAt: fromEpoch(window.ResetTime, "milliseconds"), detail: { used, limit: quota, unit: "AFP" } });
188
+ windows.push({ kind, percent: Math.min(100, used / quota * 100), resetsAt: fromEpoch(window.ResetTime, "milliseconds"), groupLabel, detail: { used, limit: quota, unit: "AFP" } });
179
189
  }
180
190
  const plan = typeof row.PlanType === "string" && row.PlanType.trim() ? row.PlanType.trim() : undefined;
181
191
  const seatId = typeof row.SeatID === "string" && row.SeatID.trim() ? row.SeatID.trim() : undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-subusage",
3
3
  "displayName": "订阅用量显示",
4
- "version": "0.10.0",
4
+ "version": "0.10.2",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/"