dsh-subusage 0.10.1 → 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.1-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" },
@@ -347,7 +366,8 @@ window.__ModuleLoader__.load({
347
366
  }
348
367
  /** 药丸文案:永远答「还能用多少」(余),限额/连坐直说。多窗带窗口短名。 */
349
368
  function pillText(w, multi, t) {
350
- 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")} ` : "";
351
371
  if (w.status === "rate-limited" && !w.cascade) return `${short}${t("pillLimited")}`;
352
372
  if (w.status === "rate-limited") return `${short}${t("pillBlocked")}`;
353
373
  return `${short}${t("pillRemaining").replace("{p}", String(Math.round(Math.max(0, 100 - w.percent) * 10) / 10))}`;
@@ -892,6 +912,9 @@ window.__ModuleLoader__.load({
892
912
  w.detail && typeof w.detail.used === "number" && typeof w.detail.limit === "number" && w.detail.limit > 0
893
913
  ? t("detailUsed").replace("{used}", fmtTokens(w.detail.used)).replace("{limit}", fmtTokens(w.detail.limit)).replace("{unit}", w.detail.unit || "")
894
914
  : null,
915
+ // 不同额度线之间不可比(例如 AFP 的日限额只覆盖视觉 / 语音模型与 Harness):如实标出适用范围,
916
+ // 否则"日比周还高"会被读成插件算错。
917
+ w.detail && w.detail.note ? w.detail.note : null,
895
918
  w.detail && w.detail.limitSource === "plan-snapshot" ? t("planSnapshotLimit") : null,
896
919
  resetLine(w, t, getLocale),
897
920
  w.cascade ? t("cascadeLimited") + (w.detail && w.detail.blockedBy ? ` [${w.detail.blockedBy.join(", ")}]` : "") : null
@@ -1050,7 +1073,13 @@ window.__ModuleLoader__.load({
1050
1073
  t("ccUsageAccount").replace("{account}", ccState.activeId === "" || ccState.activeId === "default" ? t("ccAccountDefault") : (ccState.accounts.find((a) => a.id === ccState.activeId)?.label ?? ccState.activeId)),
1051
1074
  ccState.activeId === "" ? h("span", { style: { opacity: 0.85 } }, ` · ${t("ccUsageAutoNote")}`) : null)
1052
1075
  : null,
1053
- 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 }))),
1054
1083
  entry && entry.extras && entry.extras.length > 0
1055
1084
  ? h("div", { style: { marginTop: 10, opacity: 0.85 } },
1056
1085
  entry.extras.map((x) => h("div", { key: x.kind }, `${extraLabel(x, t)}: ${x.value}`)))
@@ -1075,6 +1104,9 @@ window.__ModuleLoader__.load({
1075
1104
  function draftFor(settings, id) {
1076
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 || "" } };
1077
1106
  }
1107
+ // 从网页/控制台复制值时常带上换行、制表或零宽字符,而这些字段本身都不含空白——
1108
+ // 剔除它们比「拒绝保存」省事得多:拒绝只会让用户觉得「填了没用」。
1109
+ function stripInvisible(raw) { return String(raw).replace(/[\s\u200b-\u200d\ufeff]/g, ""); }
1078
1110
  function settingsPatch(id, draft, revision) {
1079
1111
  if (typeof revision !== "string" || !revision) throw new Error("请先加载最新设置,再编辑保存 / Load settings before saving");
1080
1112
  const patch = { providerId: id, expectedRevision: revision };
@@ -1087,10 +1119,11 @@ window.__ModuleLoader__.load({
1087
1119
  if (draft.volc.clear) patch.volc = { accessKeyId: { action: "clear" }, secretAccessKey: { action: "clear" } };
1088
1120
  else {
1089
1121
  const volc = {};
1090
- 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);
1091
1125
  for (const [field, value] of [["accessKeyId", accessKey], ["secretAccessKey", secret]]) {
1092
1126
  if (!value) continue;
1093
- if (/[\x00-\x1f\x7f]/.test(value)) throw new Error("Access Key 不能包含控制字符");
1094
1127
  volc[field] = { action: "replace", value };
1095
1128
  }
1096
1129
  if (Object.keys(volc).length) patch.volc = volc;
@@ -1104,12 +1137,13 @@ window.__ModuleLoader__.load({
1104
1137
  patch.keyMode = draft.keyMode;
1105
1138
  patch.keyUpdate = { action: draft.keyAction };
1106
1139
  if (draft.keyAction === "replace") {
1107
- if (!draft.key.trim() || /[\r\n\x00-\x1f\x7f]/.test(draft.key)) throw new Error("API Key 不能为空或包含控制字符");
1108
- 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;
1109
1143
  }
1110
- 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) };
1111
1145
  // LiteLLM 的代理地址不是秘密,原样提交;空串表示清空(请求时会按「未配置」提示)。
1112
- if (id === "litellm") patch.litellm = { baseUrl: draft.litellm.baseUrl.trim() };
1146
+ if (id === "litellm") patch.litellm = { baseUrl: stripInvisible(draft.litellm.baseUrl) };
1113
1147
  }
1114
1148
  return patch;
1115
1149
  }
@@ -1230,9 +1264,14 @@ window.__ModuleLoader__.load({
1230
1264
  const patch = settingsPatch(tab, draft, revisionRef.current);
1231
1265
  const saved = await usageStore.save(patch);
1232
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);
1233
1270
  dirtyRef.current = false; setDirty(false);
1234
1271
  setDraft(draftFor(saved.settings, tab)); revisionRef.current = saved.settings && saved.settings.revision;
1235
- 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") });
1236
1275
  if (!providerEnabled(saved.settings, tab)) return;
1237
1276
  // 保存已成功落盘;独立验证失败不改写成“保存失败”。
1238
1277
  try {
@@ -1291,6 +1330,11 @@ window.__ModuleLoader__.load({
1291
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,
1292
1331
  draft[kind + "Action"] === "clear" ? h("span", { role: "status" }, text("将删除凭据(尚未保存)", "Credential will be deleted (not saved yet)")) : null
1293
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);
1294
1338
  const credentialEditor = h(react.Fragment, null,
1295
1339
  notice ? h("p", { role: "status", style: { color: notice.ok ? "inherit" : "#dc2626" } }, notice.text) : null,
1296
1340
  h("div", { style: { marginTop: 10 } },
@@ -1302,6 +1346,8 @@ window.__ModuleLoader__.load({
1302
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,
1303
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,
1304
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),
1305
1351
  h("div", { role: "group", "aria-label": text("Key 来源模式", "Key source mode"), style: { display: "flex", gap: 8, flexWrap: "wrap" } },
1306
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")}`))),
1307
1353
  h("p", { style: { fontSize: 12 } }, text("继承变量:", "Inherited variables: "), h("code", null, "VOLC_ACCESSKEY"), " / ", h("code", null, "VOLC_SECRETKEY")),
@@ -1317,7 +1363,7 @@ window.__ModuleLoader__.load({
1317
1363
  ({ launching: text("正在启动登录浏览器…", "Launching login browser…"), waiting: text("请在浏览器中完成登录…", "Complete sign-in in the browser…"), verifying: text("正在验证并导入…", "Verifying & importing…") })[login.state],
1318
1364
  h("button", { type: "button", style: btnStyle, disabled: !login.jobId, onClick: cancelLogin }, text("取消登录", "Cancel login"))) : null,
1319
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,
1320
- 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),
1321
1367
  h("p", null, result.settings && result.settings.xiaomi && result.settings.xiaomi.hasCookie ? text("已保存 Cookie(不回填)", "Cookie saved (never filled back)") : t("statusNoCookie")),
1322
1368
  cookieLifetimeLine(result.settings && result.settings.xiaomi, t, getLocale),
1323
1369
  h("p", { style: { fontSize: 12, opacity: .75 } }, t("mimoCookieTtl")),
@@ -1330,14 +1376,17 @@ window.__ModuleLoader__.load({
1330
1376
  h("div", { role: "group", "aria-label": text("Key 来源模式", "Key source mode"), style: { display: "flex", gap: 8, flexWrap: "wrap" } },
1331
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")}`))),
1332
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)")),
1333
1380
  credentialButtons("key", result.settings && result.settings.hasKeys && result.settings.hasKeys[tab]),
1334
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),
1335
1382
  tab === "litellm" ? h(react.Fragment, null,
1336
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 })),
1337
- 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,
1338
1386
  tab === "zai-coding-cn" ? h(react.Fragment, null,
1339
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")))),
1340
- 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,
1341
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)),
1342
1391
  h("details", { style: { marginTop: 12 } }, h("summary", { style: { cursor: "pointer" } }, text("技术信息与帮助", "Technical information & help")),
1343
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,
@@ -1356,7 +1405,7 @@ window.__ModuleLoader__.load({
1356
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 } },
1357
1406
  h("span", { style: { flex: 1, minWidth: 80 } }, PROVIDER_META[id].short),
1358
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")),
1359
- 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")),
1360
1409
  h("details", { id: `subusage-credentials-${id}`, open: editing, style: { width: "100%" } },
1361
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")),
1362
1411
  tab === id ? credentialEditor : null));
package/lib/index.js CHANGED
@@ -302,7 +302,7 @@ function volcFailure(action, error) {
302
302
  }
303
303
  async function fetchJson(fetcher, url, headers, lifetimeSignal, init = {}) {
304
304
  let response;
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.1", ...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" }); }
306
306
  catch { throw failure("subusage/network", "网络请求失败或超时", true); }
307
307
  if (response.status >= 300 && response.status < 400 || response.status === 401 || response.status === 403) throw failure("subusage/auth", "登录或凭据已失效");
308
308
  if (!response.ok) {
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.1",
4
+ "version": "0.10.2",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "registry": "https://registry.npmjs.org/"