dsh-cost-meter 1.8.20 → 1.8.22
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/LICENSE +21 -21
- package/README.md +6 -6
- package/README.zh-CN.md +6 -6
- package/docs/context-costs-design.md +8 -6
- package/docs/qwen-cli-quota.md +5 -4
- package/lib/bailian-cli.js +25 -6
- package/lib/client.js +1 -1
- package/lib/client.statistics.js +8 -8
- package/lib/context-costs.js +3 -4
- package/lib/store.js +3 -0
- package/lib/typert.host.js +1 -0
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 dsh-cost-meter contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-cost-meter contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00; weekends and Chinese public holidays are off-peak all day, with separate labels) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 170+ model-ID catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
|
|
10
10
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
12
|
|
|
13
|
-
**v1.8.
|
|
13
|
+
**v1.8.22** fixes duplicate Context tabs and integration cleanup after repeated toggles, and restores monthly Token Plan quotas from Bailian CLI. The native conversation tab stays unchanged, and turning integration off immediately removes its cost regions. Published dsh-context 0.62.0, 0.66.0 and 0.68.1 are covered. If an older client already left duplicate tabs, reload the client or restart the host once after updating. See the [guide](docs/context-costs-design.md#english).
|
|
14
14
|
|
|
15
15
|
Desktop users: follow the [Desktop installation instructions](docs/install-troubleshooting.md#desktop-安装与更新) for the application's own CLI and `desktop` Profile.
|
|
16
16
|
|
|
@@ -323,22 +323,22 @@ On Node.js 20, use `npm install -g pnpm@10` instead. See [pnpm installation and
|
|
|
323
323
|
dsh plugin --profile web add dsh-cost-meter
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
-
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.8.
|
|
326
|
+
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.8.22`** — review the script before running):
|
|
327
327
|
|
|
328
328
|
```powershell
|
|
329
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
329
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.22/install.ps1 | iex
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
333
333
|
|
|
334
334
|
```sh
|
|
335
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
335
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.22
|
|
336
336
|
```
|
|
337
337
|
|
|
338
338
|
Without git, use the GitHub tag archive:
|
|
339
339
|
|
|
340
340
|
```sh
|
|
341
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
341
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.22.tar.gz
|
|
342
342
|
```
|
|
343
343
|
|
|
344
344
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
package/README.zh-CN.md
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段;周末与中国法定假日全天按谷价,分别标注) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / 火山方舟 / 千问 / 小米 MiMo 十一家,含 Volcano Ark AK/SK 签名与 MiMo 控制台 Cookie 查询) · Plan/API 双轨计费(订阅额度与按量金额分离统计,每 1% 额度与满窗的 token/等值金额估算及日/周/月曲线) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
|
|
10
10
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
12
|
|
|
13
|
-
**v1.8.
|
|
13
|
+
**v1.8.22** 修复 dsh-context 重复页签、关闭残留,以及百炼 CLI 月额度卡片空白的问题。会话页保留原生页签,关闭联动立即移除费用区域;覆盖 0.62.0、0.66.0、0.68.1。如旧客户端已累积重复页签,更新后重新加载客户端或重启宿主一次。详见[使用说明](docs/context-costs-design.md)。
|
|
14
14
|
|
|
15
15
|
桌面端用户请按 [Desktop 安装说明](docs/install-troubleshooting.md#desktop-安装与更新),使用应用自带的 CLI 和 `desktop` Profile。
|
|
16
16
|
|
|
@@ -323,22 +323,22 @@ Node.js 20 请改用 `npm install -g pnpm@10`。版本要求见 [pnpm 官方安
|
|
|
323
323
|
dsh plugin --profile web add dsh-cost-meter
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.
|
|
326
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.22`**,建议先下载审阅再运行):
|
|
327
327
|
|
|
328
328
|
```powershell
|
|
329
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
329
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.22/install.ps1 | iex
|
|
330
330
|
```
|
|
331
331
|
|
|
332
332
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
333
333
|
|
|
334
334
|
```sh
|
|
335
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
335
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.22
|
|
336
336
|
```
|
|
337
337
|
|
|
338
338
|
没有 git 时可用 GitHub tag 打包直链:
|
|
339
339
|
|
|
340
340
|
```sh
|
|
341
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
341
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.22.tar.gz
|
|
342
342
|
```
|
|
343
343
|
|
|
344
344
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## 使用方式
|
|
4
4
|
|
|
5
|
-
点击对话输入区的费用明细,只查看当前对话。费用概览集中显示总费用、调用次数、Token
|
|
5
|
+
点击对话输入区的费用明细,只查看当前对话。费用概览集中显示总费用、调用次数、Token、缓存命中率和费用构成;计费轨迹直接显示在概览,逐次调用明细原位展开;“费用明细”默认用一张圆环图汇总全部轨迹步骤费用,每块代表一步。逐步独立圆环和上下文参考默认折叠。设置中的计费统计保留跨对话查询入口。两处的计费口径选择写入插件配置,关闭重开及重启后保留;尚未选择时沿用全局 API/含 Plan 设置。
|
|
6
6
|
|
|
7
7
|
“步骤费用构成”按已有轨迹步骤汇总费用,显示每步金额与全会话占比。超过 20 步时,费用最高的 20 步单列,其余合并为一块,所有步骤均计入分母。“计费轨迹”逐步列出输入、输出、缓存金额及占比,点击步骤可展开 Token、单价和金额。多个工具属于同一步时,整步模型费用只计一次;工具名称用于识别步骤,不把整笔费用重复分摊给各工具。缺少步骤编号的调用单列。
|
|
8
8
|
|
|
@@ -57,11 +57,13 @@ dsh-context 主要展示上下文占用、组成、变化和注入事件。0.66.
|
|
|
57
57
|
|
|
58
58
|
启用后,费用区域位于 dsh-context 的当前上下文卡片内部,覆盖会话页、右侧栏与 `/context` 弹窗。未启用或关闭联动时,本插件的独立费用展示继续可用。
|
|
59
59
|
|
|
60
|
-
-
|
|
60
|
+
- 宿主通过本地 `pluginManager.listBundles()` 确认 dsh-context 已启用,客户端检测所需公开插槽、注册形态和当前卡片挂载位置。联动不依赖精确版本名单,已验证 0.62.0、0.66.0、0.68.1;后续版本沿用这些接口时,无需添加版本号。
|
|
61
61
|
- 开关和“已提示”状态保存在本插件配置中。关闭按钮、Esc、点击遮罩和“暂不启用”均可退出;退出不等待保存请求。浏览器另存提示记录,防止保存失败、重新载入或多个页面造成反复提示。
|
|
62
62
|
- 用户手动重开预览再关闭,不改变已经启用的开关。设置中始终保留开关与预览入口。
|
|
63
63
|
- 自动提示等其他弹窗关闭后再出现。短窗口保持关闭按钮和操作区可见,避开 DSH 桌面标题栏,支持键盘焦点限制与关闭后恢复焦点。
|
|
64
|
-
- 复用 dsh-context 的公开 `contextTimeline.current`
|
|
64
|
+
- 复用 dsh-context 的公开 `contextTimeline.current` 分类;不修改对方文件或注册。会话页保留原始 `conversation.view`,通过独立的会话输入区挂载点向同一会话的当前卡片添加费用区域,避免宿主按原始插槽记录生成重复页签。侧栏与 `/context` 弹窗仍使用公共插槽优先级包装,保留原 props、语言、会话和 hooks。关闭或卸载时撤销自己的注册与观察器。
|
|
65
|
+
- 宿主在插槽注册和撤销时同步发送变更事件。联动在完成一次安装或清理并保存撤销函数后,再处理期间发生的配置通知,避免重入造成重复安装及关闭后残留。
|
|
66
|
+
- 如果旧版本已经累积了重复页签,更新后需重新加载客户端或重启宿主一次,清除旧版本遗留的挂载。修复后的开关切换不需要重启;本插件不会按同名页签批量删除其他插件的注册。
|
|
65
67
|
- 尚未验证的插槽结构不会被覆盖;原面板保留,独立入口继续使用。
|
|
66
68
|
|
|
67
69
|
## 加载与实时性
|
|
@@ -85,7 +87,7 @@ dsh-context 主要展示上下文占用、组成、变化和注入事件。0.66.
|
|
|
85
87
|
|
|
86
88
|
## 验证范围
|
|
87
89
|
|
|
88
|
-
本地合成会话用于核对分类金额总和、长上下文阈值、缓存与输出计价、人民币换算、Plan、零价格和未定价。真实 DSH Session、TokenMeter 和投影服务用于核对取数接口及只读行为。真实发布的 dsh-context
|
|
90
|
+
本地合成会话用于核对分类金额总和、长上下文阈值、缓存与输出计价、人民币换算、Plan、零价格和未定价。真实 DSH Session、TokenMeter 和投影服务用于核对取数接口及只读行为。真实发布的 dsh-context 客户端和宿主页签投影用于验证三个界面入口、先后安装、会话隔离、反复开关、重新载入及原始页签保留。真实 Cordis 与 SlotRegistry 验证同步变更事件重入、关闭、插件卸载及延迟请求完成后的清理。
|
|
89
91
|
|
|
90
92
|
浏览器检查覆盖明暗主题、窄屏和短窗口、预览、关闭方式、焦点恢复及保存失败。预览采用示例数据,所有模型和外部网络请求均被禁用。
|
|
91
93
|
|
|
@@ -95,9 +97,9 @@ Each expanded call pairs a cost donut and a token/rate/cost/share table with Inp
|
|
|
95
97
|
|
|
96
98
|
Open **Cost details** beside the conversation input to see only that conversation: call-log totals, context composition, latest-call charges and turn/call details. Cross-conversation statistics remain available in Settings.
|
|
97
99
|
|
|
98
|
-
Overview and Cost details are the two main views. Overview keeps the input/output/cache composition beside step cost composition and a compact billing trajectory. Cost details opens one aggregate donut: each slice represents a trajectory step’s share of the full session cost. The top 20 steps are separate slices; any remaining steps are combined without dropping their costs. Individual step donuts and token/rate/cost tables are in a collapsed section; context references are also collapsed. Individual call records expand within Overview. Overview includes per-call shares across the full selection, cache token/cost comparisons and conditional model/activity charts. The seven highest-cost calls are individual slices; the rest are combined. Select a call to open its details, even on another page. Donut charts use a brighter palette with compact percentage legends. Hover or focus a slice or legend item to inspect its amount and tokens, including tiny categories. Leaving the chart or moving keyboard focus away clears the highlight. Expanding the individual-step section reveals its billing tables, which can also be collapsed. The close button stays visible while scrolling; Escape also closes the dialog. Dialogs follow DSH popup background tokens, including dsh-dream-skin opacity.
|
|
100
|
+
The selected API, Plan or combined cost basis is saved in plugin configuration and survives reopening and restart. Before the first explicit selection, it follows the existing global API/Plan display preference. Overview and Cost details are the two main views. Overview keeps the input/output/cache composition beside step cost composition and a compact billing trajectory. Cost details opens one aggregate donut: each slice represents a trajectory step’s share of the full session cost. The top 20 steps are separate slices; any remaining steps are combined without dropping their costs. Individual step donuts and token/rate/cost tables are in a collapsed section; context references are also collapsed. Individual call records expand within Overview. Overview includes per-call shares across the full selection, cache token/cost comparisons and conditional model/activity charts. The seven highest-cost calls are individual slices; the rest are combined. Select a call to open its details, even on another page. Donut charts use a brighter palette with compact percentage legends. Hover or focus a slice or legend item to inspect its amount and tokens, including tiny categories. Leaving the chart or moving keyboard focus away clears the highlight. Expanding the individual-step section reveals its billing tables, which can also be collapsed. The close button stays visible while scrolling; Escape also closes the dialog. Dialogs follow DSH popup background tokens, including dsh-dream-skin opacity.
|
|
99
101
|
|
|
100
|
-
Expand **Display and integration settings → dsh-context integration** to enable or disable the optional integration or reopen its before/after preview.
|
|
102
|
+
Expand **Display and integration settings → dsh-context integration** to enable or disable the optional integration or reopen its before/after preview. Compatibility is determined from the enabled peer and its required view registration interfaces, rather than an exact release list. Published clients 0.62.0, 0.66.0 and 0.68.1 are verified. Integration starts off; dismissing the initial prompt prevents repeated automatic prompts. When enabled, costs appear inside the peer's current-context card in the conversation tab, right sidebar and `/context` overlay.
|
|
101
103
|
|
|
102
104
|
Context amounts use uncached input rates as a reference; they are not itemized bills. Latest-call amounts use reported usage and configured rates, with Plan amounts shown as API equivalents. These amounts are separate and must not be added together. Unknown prices are not treated as free. Visible views react to local changes and refresh every 10 seconds; hidden views pause. No model requests or additional model API charges are introduced, and no context or ledger data is changed.
|
|
103
105
|
|
package/docs/qwen-cli-quota.md
CHANGED
|
@@ -50,9 +50,10 @@ bl usage coding-plan --output json
|
|
|
50
50
|
|
|
51
51
|
登录最长等待 5 分钟,之后可重试。凭据仍由官方 CLI 保存;插件丢弃登录输出,错误只显示双语分类提示。并发登录合并为一次;切换来源、关闭显示或卸载插件时取消在途登录,旧结果不覆盖新配置。回归使用合成凭据与真实子进程,未执行真实账号浏览器授权。
|
|
52
52
|
|
|
53
|
-
- 一次查询并行执行 `usage token-plan` 与 `usage coding-plan` 两个只读子命令并合并:Token Plan
|
|
54
|
-
- Token Plan 读取 `per5HourPercentage` / `per1WeekPercentage` 及对应的 `ResetTime`;Coding Plan 读取各窗口的 `percentage`(缺失时按 `usedQuota/totalQuota` 推算)。官方 CLI 返回比例值,乘以 100 后保留一位小数,例如 `0.5` 显示为 `50%`。重置时间以 epoch 毫秒转为 ISO。缺失的 Token Plan 窗口、无正额度上限的 Coding Plan 窗口不生成进度条。
|
|
55
|
-
-
|
|
53
|
+
- 一次查询并行执行 `usage token-plan` 与 `usage coding-plan` 两个只读子命令并合并:Token Plan 优先提供同名的 5 小时 / 周 / 月窗口,Coding Plan 补全其余窗口(`per5Hour` / `perWeek` / `perBillMonth`),另附「source」行标注实际应答的订阅与实例(如 `Coding Plan (pro) (CLI)`)。
|
|
54
|
+
- Token Plan 读取 `per5HourPercentage` / `per1WeekPercentage` / `per1MonthPercentage` 及对应的 `ResetTime`;Coding Plan 读取各窗口的 `percentage`(缺失时按 `usedQuota/totalQuota` 推算)。官方 CLI 返回比例值,乘以 100 后保留一位小数,例如 `0.5` 显示为 `50%`。重置时间以 epoch 毫秒转为 ISO。缺失的 Token Plan 窗口、无正额度上限的 Coding Plan 窗口不生成进度条。
|
|
55
|
+
- CLI 2.1.0 的 `usage token-plan` 输出会丢弃月额度字段。常规两路查询均无有效额度且 Token Plan 命令成功时,通过固定的 `console call --api zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage --data '{}'` 读取原始用量,兼容平铺字段和官方 `data` / `DataV2` 响应。正常已有额度时不追加查询。
|
|
56
|
+
- 单个子命令失败时以另一命令的结果作答;两者都失败时给出登录/失败提示,两者皆无有效额度时为软提示(无可识别数据不直接判定为未订阅)。与官方 CLI 档一致:不生成千问「每 1% / 满窗 Token」估算,账号总用量不写入 DSH 账本。
|
|
56
57
|
- 执行安全与 CLI 桥一致:固定参数、不经 shell、单命令 15 秒超时、stdout/stderr 各 1 MiB、窗口隐藏、错误不含子进程原始输出;Windows 下直接以 Node 运行包内 ESM 入口,不执行 npm 的 `.cmd` / `.ps1` 包装脚本。
|
|
57
58
|
- 查询间隔(1–1440 分钟)与并发合并同官方 CLI 档;回归见 `test/bailian-cli.mjs`(真实子进程、双命令合并、单边失败容错、超时/脱敏、缓存/并发/切源、账本三态与 codec),使用合成输出验证,未使用真实百炼订阅账号(`bl usage token-plan` 对未开通账号返回 `{}`)。
|
|
58
59
|
|
|
@@ -82,7 +83,7 @@ Clicking **Login** runs the fixed `bl auth login --console` command and opens th
|
|
|
82
83
|
|
|
83
84
|
Login waits up to five minutes and can be retried. The official CLI owns credentials; the plugin discards login output and returns only classified bilingual errors. Concurrent logins share one process. Source changes, hidden quota display and plugin unload cancel pending login. Regression uses synthetic credentials and real child processes; live account browser authorization was not performed.
|
|
84
85
|
|
|
85
|
-
One query runs `usage token-plan` and `usage coding-plan` in parallel and merges them: Token Plan wins
|
|
86
|
+
One query runs `usage token-plan` and `usage coding-plan` in parallel and merges them: Token Plan wins shared 5-hour/week/monthly windows and Coding Plan fills missing windows, and a `source` row names the subscriptions that answered (e.g. `Coding Plan (pro) (CLI)`). Token Plan uses the flat `per5HourPercentage` / `per1WeekPercentage` / `per1MonthPercentage` fields and their reset times. Coding Plan uses nested `per5Hour` / `perWeek` / `perBillMonth` windows. CLI ratios are multiplied by 100 (0.5 becomes 50%); missing Coding Plan ratios are derived from used/total. Percentages retain one decimal, and reset times are epoch milliseconds. Missing Token Plan windows and Coding Plan windows without positive limits are skipped. When one subcommand fails the other answers; both failing shows the login/failure hint, and no recognized quota produces an actionable soft notice. If both normal responses have no valid quota and the Token Plan command succeeded, a fixed read-only console usage call recovers monthly fields stripped by CLI 2.1.0. Existing valid quota avoids this extra query; flat and official data/DataV2 envelopes are supported. Like the Official CLI source this mode creates no per-1%/full-window estimates and writes no account totals into the ledger. Execution uses the shared CLI bridge (fixed arguments, no shell, 15s timeout, 1 MiB caps, hidden window, no raw child output; Windows runs the package ESM entry directly via Node). Refresh interval and concurrency coalescing match the Official CLI source. Regression: `test/bailian-cli.mjs` with synthetic output and real child processes; no live Bailian subscription was used (`bl usage token-plan` returns `{}` for accounts without Token Plan).
|
|
86
87
|
|
|
87
88
|
Tests use synthetic output, real child processes and bilingual component callbacks. No live Qianwen subscription account was used.
|
|
88
89
|
|
package/lib/bailian-cli.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Official Bailian CLI bridge (GitHub modelstudioai/cli, npm bailian-cli, `bl` / `bailian`).
|
|
3
3
|
* Credentials remain owned by the CLI (bl auth login --console / --api-key).
|
|
4
|
-
* Reads Token Plan + Coding Plan quota windows
|
|
4
|
+
* Reads Token Plan + Coding Plan quota windows through fixed read-only commands.
|
|
5
5
|
*/
|
|
6
6
|
import { bridgeCode, resolveNpmCli, runCliJson, runCliCommand } from './cli-bridge.js'
|
|
7
7
|
|
|
8
8
|
export const BAILIAN_TOKEN_PLAN_ARGS = Object.freeze(['usage', 'token-plan', '--output', 'json', '--quiet'])
|
|
9
9
|
export const BAILIAN_CODING_PLAN_ARGS = Object.freeze(['usage', 'coding-plan', '--output', 'json', '--quiet'])
|
|
10
|
+
export const BAILIAN_TOKEN_PLAN_RAW_ARGS = Object.freeze(['console', 'call', '--api', 'zeldaHttp.apikeyMgr./tokenplan/personal/api/v2/usage', '--data', '{}', '--output', 'json', '--quiet'])
|
|
10
11
|
export const BAILIAN_AUTH_STATUS_ARGS = Object.freeze(['auth', 'status', '--output', 'json', '--quiet'])
|
|
11
12
|
export const BAILIAN_LOGIN_ARGS = Object.freeze(['auth', 'login', '--console'])
|
|
12
13
|
|
|
@@ -16,7 +17,7 @@ const MESSAGES = {
|
|
|
16
17
|
failed: '百炼 CLI 查询失败,请运行 bl auth status --output json 检查登录后重试。',
|
|
17
18
|
timeout: '百炼 CLI 查询超时,请检查网络后刷新。',
|
|
18
19
|
invalid: '百炼 CLI 返回的额度格式无效,请更新 CLI 后重试。',
|
|
19
|
-
unavailable: '百炼 CLI
|
|
20
|
+
unavailable: '百炼 CLI 未返回可识别的计划额度,请检查订阅或更新 CLI 与插件。',
|
|
20
21
|
auth: '百炼 CLI 未登录,请点击"登录"按钮或运行 bl auth login --console 完成授权。',
|
|
21
22
|
loginFailed: '百炼 CLI 登录失败,请在 DSH 主机运行 bl auth login --console 检查后重试。',
|
|
22
23
|
loginTimeout: '百炼 CLI 登录超时,请重新点击登录并在 DSH 主机的浏览器完成授权。',
|
|
@@ -27,7 +28,7 @@ const MESSAGES = {
|
|
|
27
28
|
failed: 'Bailian CLI query failed. Check bl auth status --output json and retry.',
|
|
28
29
|
timeout: 'Bailian CLI query timed out. Check the network and refresh.',
|
|
29
30
|
invalid: 'Bailian CLI returned invalid quota data. Update the CLI and retry.',
|
|
30
|
-
unavailable: 'Bailian CLI returned no
|
|
31
|
+
unavailable: 'Bailian CLI returned no recognized plan quota. Check the subscription or update the CLI and plugin.',
|
|
31
32
|
auth: 'Bailian CLI not authenticated. Click the "Login" button or run bl auth login --console to authorize.',
|
|
32
33
|
loginFailed: 'Bailian CLI login failed. Run bl auth login --console on the DSH host and retry.',
|
|
33
34
|
loginTimeout: 'Bailian CLI login timed out. Retry and complete authorization in the DSH host browser.',
|
|
@@ -54,13 +55,20 @@ function windowOf(ratio, reset, locale) {
|
|
|
54
55
|
|
|
55
56
|
function tokenWindows(payload, locale) {
|
|
56
57
|
const windows = {}
|
|
57
|
-
for (const [prefix, name] of [['per5Hour', 'fiveHour'], ['per1Week', 'weekly']]) {
|
|
58
|
+
for (const [prefix, name] of [['per5Hour', 'fiveHour'], ['per1Week', 'weekly'], ['per1Month', 'monthly']]) {
|
|
58
59
|
const ratio = payload[`${prefix}Percentage`]
|
|
59
60
|
if (ratio !== undefined) windows[name] = windowOf(ratio, payload[`${prefix}ResetTime`], locale)
|
|
60
61
|
}
|
|
61
62
|
return windows
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
// Official CLI console responses may carry data.DataV2.data.data, data.data,
|
|
66
|
+
// or a flat payload. Keep this adapter limited to that published envelope.
|
|
67
|
+
function rawTokenPayload(response) {
|
|
68
|
+
const data = response?.data, v2 = data?.DataV2
|
|
69
|
+
return v2?.data?.data ?? v2?.data ?? v2 ?? data?.data ?? data ?? response
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
function codingWindows(payload, locale) {
|
|
65
73
|
const windows = {}
|
|
66
74
|
for (const [rawKey, name] of PERIOD_KEYS) {
|
|
@@ -80,8 +88,8 @@ function codingWindows(payload, locale) {
|
|
|
80
88
|
|
|
81
89
|
/**
|
|
82
90
|
* Merge both payloads into the normalized windows contract.
|
|
83
|
-
* Token Plan wins same-name
|
|
84
|
-
*
|
|
91
|
+
* Token Plan wins same-name windows, including the monthly personal plan;
|
|
92
|
+
* Coding Plan fills missing windows. `source` records the subscriptions.
|
|
85
93
|
*/
|
|
86
94
|
export function parseBailianUsage(payloads, locale = 'zh') {
|
|
87
95
|
const token = payloads?.token, coding = payloads?.coding
|
|
@@ -175,6 +183,17 @@ export async function queryBailianCli(locale = 'zh', options = {}) {
|
|
|
175
183
|
coding: settled[1].status === 'fulfilled' ? settled[1].value : null,
|
|
176
184
|
}, locale)
|
|
177
185
|
} catch (error) {
|
|
186
|
+
// CLI 2.1.0 strips per1Month* before emitting usage token-plan JSON. Only
|
|
187
|
+
// recover raw usage when no regular quota exists and Token Plan answered.
|
|
188
|
+
if (error.code === 'unavailable' && settled[0].status === 'fulfilled' && record(settled[0].value)) {
|
|
189
|
+
let raw
|
|
190
|
+
try { raw = await run(BAILIAN_TOKEN_PLAN_RAW_ARGS) }
|
|
191
|
+
catch (failure) { signal?.throwIfAborted(); throw fail(locale, bridgeCode(failure, { authExitCode: 3 })) }
|
|
192
|
+
signal?.throwIfAborted()
|
|
193
|
+
try {
|
|
194
|
+
return parseBailianUsage({ token: rawTokenPayload(raw), coding: settled[1].status === 'fulfilled' ? settled[1].value : null }, locale)
|
|
195
|
+
} catch (failure) { if (failure.code !== 'unavailable') throw failure }
|
|
196
|
+
}
|
|
178
197
|
// With one command broken, a surviving source still answers; only when nothing
|
|
179
198
|
// valid remains does the broken command's real failure become the message.
|
|
180
199
|
if (error.code === 'unavailable') {
|