dsh-token-dash 1.0.5 → 1.0.7

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/AGENTS.md CHANGED
@@ -1,84 +1,84 @@
1
- # dsh-token-dash 项目规则
1
+ # AGENTS.md
2
2
 
3
- > 面向 AI agent 与维护者。本仓库是 DSH 插件代码仓;当前插件的计划在 `docs/plan/`、checklist 在 `docs/checklist/` 维护,`Context-Engineer` 不再维护本插件文档。规则以本文件为准。
3
+ ## 文档定位
4
4
 
5
- ## 构建与测试
5
+ - 本文件只保留仓库协作与执行规则,不承担开发总览、目录索引或版本现状。
6
+ - 开发/架构入口:`docs/design.md`;先读架构、Provider/VM/UI 边界、模块职责,再看代码。
7
+ - 验证命令以 `package.json` 的 scripts 为准;不要在本文件复制测试规模、构建命令或版本号。
6
8
 
7
- - Node `>=20`;纯 ESM;首版零构建,源码直接发布。
8
- - 宿主入口 `index.js`,客户端 `client.js`(手写 `window.__ModuleLoader__` bundle,id 必须等于包名)。
9
- - 不提交 `lib/`;`prepublishOnly` 跑 `npm test`。
9
+ ### 重点文档读取位置
10
10
 
11
- ```bash
12
- npm test # L1:node --test
13
- npm run e2e # L2 + L3:临时 DSH_HOME + Playwright
14
- npm pack --dry-run
15
- ```
11
+ | 场景 | 先读 | 再看 |
12
+ |---|---|---|
13
+ | 改代码 / 架构 | `docs/design.md` | `src/`、`client.js`、`test/unit/`、对应 active plan |
14
+ | 需求 / 规划 | `docs/plan/AGENTS.md` | `docs/plan/active/`(先看文件头状态)、`docs/plan/archived/`(历史) |
15
+ | 施工 / 走查 | `docs/checklist/AGENTS.md` | `docs/checklist/active/dsh/`、`docs/checklist/archived/dsh/` |
16
+ | 发布 / 版本 | `docs/release.md` | `.agents/skills/dsh-token-dash-release/SKILL.md`、版本记录 `.agents/skills/dsh-token-dash-release/references/official-release-version.md` |
17
+ | 用户说明 / 变更历史 | `README.md` / `README.en.md` | `CHANGELOG.md`、`docs/pic/` |
18
+ | Skill 维护 | `.agents/skills/`(项目 skill) | `D:\Projects\Context-Engineer\skills\`(全局 skill 真源) |
16
19
 
17
- ## 文档位置
20
+ - 当前 active plan / checklist 不在此复制;进入目录后按文件头状态判断,避免本文件与文档状态漂移。
18
21
 
19
- - 稳定文档:`docs/design.md`、`docs/release.md`。
20
- - 计划:`docs/plan/active/feature_token_dash.md`(遵循全局 `plan-workflow` 的 `docs/plan/` 约定;单项目仓不再分项目域)。
21
- - checklist:`docs/checklist/active/dsh/`、`docs/checklist/archived/dsh/`。
22
- - 本插件文档只在本仓维护;`Context-Engineer` 不保留同名副本。
22
+ ## 修改原则
23
23
 
24
- ## 规划
24
+ - 纯 ESM、零构建;宿主编排入口 `index.js`,客户端 `client.js`;client bundle id 必须等于包名。
25
+ - 源码即产物,不提交 `lib/`;npm 包内容由 `package.json#files` 控制。
26
+ - 保持现有五家 provider 边界:adapter 只输出 `ProviderSnapshot`,VM 只输出 `SummaryVM`,UI 只消费 VM;不引入 provider 插件系统或 per-provider 文件拆分。
27
+ - 不做无关重构;改动范围以 plan / checklist 声明为准,越界先更新文档并确认。
28
+ - 日志用 `[TD:<module>]` 语义前缀;错误不吞,关键链路带 `errorKind` / `httpStatus`。
29
+ - 临时产物、一次性脚本和 MCP 输出统一放 `.tmp/`;不在仓库根或 `src/` 下新建临时文件。
25
30
 
26
- - 计划目录遵循全局 `plan-workflow`:`docs/plan/active/<feature>.md`、`docs/plan/tracking/<topic>/`、`docs/plan/archived/`。
27
- - 当前主计划:`docs/plan/active/feature_token_dash.md`。
31
+ ## Skill 归属
28
32
 
29
- ## 临时目录
33
+ - 项目 skill 只放在仓库 `.agents/skills/`,Codex 与 DSH 原生识别,不复制到用户层。
34
+ - 全局 skill 真源只放在 `D:\Projects\Context-Engineer\skills\`;`~/.agents/skills/<name>` 用 junction 指向 CE,不保留副本。
35
+ - 新增或修改全局 skill 在 CE 内完成,再建 junction;项目 skill 与全局 skill 不混放。
30
36
 
31
- - 统一使用仓库根 `.tmp/`,禁止在仓库根或 `src/` 下创建临时文件。
32
- - 子目录固定:`.tmp/dsh-home`(隔离 DSH_HOME)、`.tmp/pack`(tgz)、`.tmp/e2e`(截图 / 日志 / summary)。
33
- - 可用环境变量 `TOKEN_DASH_TMP` 覆盖;E2E 默认 teardown 清理,`--keep` 保留现场。
34
- - 测试工具脚本放 `scripts/`,本地与 CI 复用,不写进 `tests/`。
37
+ ## 提交前规则
35
38
 
36
- ## Git 管理边界
39
+ 1. 更新相关文档:plan / checklist / design / README,以改动范围为准。
40
+ 2. 执行受影响验证:L1 `npm test`,涉及 UI/宿主链路时加 `npm run e2e`。
41
+ 3. 涉及发布时再执行 `npm run pack`,确认 tarball 内容。
42
+ 4. 确认无 `.tmp/`、`build/`、真实会话或凭证进入提交。
43
+ 5. 再 `commit` + `push`;用户说“提交”默认包含推送,除非明确“只本地提交”。
37
44
 
38
- ### 进入版本管理
45
+ - 纯文档更新且不涉及代码、测试脚本、发布资产时,可跳过测试和打包,但提交说明必须写明“仅文档更新,未启动测试/打包”。
46
+ - 文档互引使用以仓库根为基准的相对路径。
47
+ - 完成本地打包后,立即回写当前 active plan 的进度;本地打包本身必须先有用户显式指令。
39
48
 
40
- | 类别 | 文件 |
41
- |---|---|
42
- | 包与配置 | `package.json`、`pnpm-lock.yaml`、`tsconfig.json`、`tsdown.config.ts`、`playwright.config.ts`、`cordis.patch.yml`、`.gitignore` |
43
- | 源码 | `src/**` |
44
- | 文案资源 | `locale/**`、`icon.svg` |
45
- | 测试脚本 | `tests/unit/**`、`tests/e2e/**/*.spec.ts`、`tests/e2e/fixtures/**`(仅合成数据) |
46
- | 工具脚本 | `scripts/**` |
47
- | 工程与发布 | `.github/workflows/**`、`README.md`、`LICENSE`、`AGENTS.md`、`CHANGELOG.md` |
48
- | 文档 | `docs/**` |
49
+ ## 版本与发布
49
50
 
50
- ### 不进入版本管理
51
+ - 版本号遵循 `MAJOR.MINOR.PATCH`;当前正式版本以 `.agents/skills/dsh-token-dash-release/references/official-release-version.md` 为准,不在此复制。
52
+ - 发版流程唯一来源:`docs/release.md` + `.agents/skills/dsh-token-dash-release/SKILL.md`;GitHub Release、npm Trusted Publishing 均由 tag 触发。
53
+ - **本地打包必须由用户显式指令触发**(`本地打包` / `本地版本` / `候选包`)。完成 issue、修复、测试或提交后,不得自动改版本号、写 CHANGELOG local 块、`npm run pack` 或安装本地包。
54
+ - 本地构建记录写 `CHANGELOG.md` 顶部 `## [X.Y.Z-local.N]`,标题下加 `> 本地构建,未发布`;不 tag、不发布。正式发布时合并进正式块并删除,最终历史不保留 local 块。
55
+ - 正式发布:确认版本 → CHANGELOG 正式块 → L1 + E2E → pack → commit/push → tag → 双 workflow → 核验 npm latest 与 Release body;随后更新 `official-release-version.md`。
56
+ - Release body 按 tag 版本从 CHANGELOG 提取,不按“文件第一块”提取;local 块不得进入 Release body。
57
+ - 未获用户明确授权,不执行 `npm publish`、不推 tag、不声称已上线。
51
58
 
52
- | 类别 | 文件 |
53
- |---|---|
54
- | 依赖与产物 | `node_modules/`、`lib/`、`dist/`、`build/` |
55
- | 临时目录 | `.tmp/`、`artifacts/`、`coverage/`、`playwright-report/`、`test-results/` |
56
- | 打包产物 | `*.tgz`、`*.tar.gz` |
57
- | 日志与缓存 | `*.log`、`.cache/` |
58
- | 敏感信息 | `.env`、`.env.*`、`*.pem`、`*.key`、`.credentials*` |
59
- | 系统与编辑器 | `.DS_Store`、`Thumbs.db`、`.vscode/` |
59
+ ## 规划工作流
60
60
 
61
- 规则:
61
+ - 复杂功能、跨模块修改、架构调整先用 `plan-workflow` skill 维护 `docs/plan/active/`;已归档内容只读,重开走受控流程。
62
+ - 同一时间只推进一个主 feature;优先恢复已有 plan,不新建重复计划。
63
+ - 施工与走查用 `checklist` skill 维护 `docs/checklist/active/dsh/`;回写完成 + 用户明确指令后才归档。
64
+ - 每次实现完成、测试通过或发布后,回写 plan 的 §3.0/§5 与 checklist 的阶段/测试/执行日志,避免状态只在对话里。
62
65
 
63
- 1. E2E **测试脚本与合成 fixture 必须入库**;截图、日志、报告、trace 一律忽略。
64
- 2. 真实 `$DSH_HOME/sessions`、真实会话 JSONL、任何凭证**永不入库**。
65
- 3. `pnpm-lock.yaml` 必须提交,保证可复现构建。
66
- 4. 提交前至少跑 `pnpm test` 与 `pnpm pack:check`。
66
+ ## Git 管理与临时文件
67
67
 
68
- ## 发布
69
-
70
- - AI 只准备到“可发布”,不执行 `npm publish`、不推 tag;发布由用户明确授权。
71
- - npm 包只含 `lib` / `cordis.patch.yml` / `locale` / `README.md` / `LICENSE`。
72
- - 发布流程见 `docs/release.md`;历史发布 checklist 见 `docs/checklist/archived/dsh/token-dash-release-checklist.md`。
68
+ - 入库:`src/`、`client.js`、`index.js`、`test/`、`scripts/`、`docs/`、`locale/`、`.agents/`、`.github/`、`README*`、`CHANGELOG.md`、`AGENTS.md`、`package.json`、`pnpm-lock.yaml`、`cordis.patch.yml`。
69
+ - 不入库:`node_modules/`、`build/`、`.tmp/`、`artifacts/`、`coverage/`、`playwright-report/`、`test-results/`、`*.tgz`、`*.log`、真实会话 JSONL、凭证与密钥。
70
+ - E2E 测试脚本与合成 fixture 必须入库;截图、日志、报告、trace 一律忽略。
71
+ - `pnpm-lock.yaml` 必须提交,保证可复现安装。
73
72
 
74
73
  ## 安全
75
74
 
76
75
  - 不读取 `~/.dsh/.credentials.yaml`;凭据只经宿主 `ctx.credentials.resolve(...)`。
77
- - 余额查询仅限 DeepSeek / Kimi / GLM 官方接口;第三方显示“第三方不支持”且不请求。
76
+ - 余额查询仅限 DeepSeek / Kimi / GLM / OpenRouter / Qwen 官方接口;第三方显示“第三方不支持”且不请求。
78
77
  - 密钥、cookie、token 不得出现在源码、日志、fixture 或提交信息中。
79
78
 
80
- ## 变更纪律
79
+ ## 完成后的汇报
80
+
81
+ - 汇报“本次改了什么 / 测试改了什么”前,先读取对应 commit:`git show --stat <commit>`、`git show --name-status <commit>`,并核对受影响测试与文档 diff。
82
+ - 已提交内容、未提交工作区、运行态结果分开说明;不能用记忆或推测代替 commit 事实。
83
+ - 本轮尚未形成 commit 时,明确标注“未提交”,不得说成“已完成修改”。
81
84
 
82
- - 先更新 plan / checklist,再改代码;改动范围以施工稿声明为准。
83
- - 不顺手改边界外文件;需要越界时先更新文档并重新确认。
84
- - 新增依赖前说明理由;运行时依赖保持最少(当前仅 `zod`)。
package/README.en.md CHANGED
@@ -5,7 +5,8 @@
5
5
  </p>
6
6
 
7
7
  <p align="center">
8
- Track daily/monthly model spend and budget headroom right next to the DSH input box: paste an API Key and the plan is auto-detected (subscription or pay-as-you-go), set a monthly budget, and consumption is estimated locally in real time.
8
+ Track daily/monthly model spend and budget headroom right next to the DSH input box:<br />
9
+ paste an API Key and the plan is auto-detected (subscription or pay-as-you-go), set a monthly budget, and consumption is estimated locally in real time.
9
10
  </p>
10
11
 
11
12
  <p align="center">
@@ -16,6 +17,7 @@
16
17
 
17
18
  <p align="center">
18
19
  <img src="https://img.shields.io/github/v/tag/spartawhy117/dsh-token-dash?label=version&sort=semver" alt="version" />
20
+ <img src="https://img.shields.io/npm/dt/dsh-token-dash?logo=npm&label=npm%20downloads" alt="npm downloads" />
19
21
  <img src="https://img.shields.io/github/downloads/spartawhy117/dsh-token-dash/total?label=downloads" alt="downloads" />
20
22
  <img src="https://img.shields.io/github/license/spartawhy117/dsh-token-dash" alt="license" />
21
23
  <img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node" />
@@ -41,7 +43,7 @@ dsh plugin --profile desktop add dsh-token-dash
41
43
  dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
42
44
 
43
45
  # Option 3: download dsh-token-dash-x.y.z.tgz from Releases and install locally (offline)
44
- dsh plugin --profile desktop add /path/to/dsh-token-dash-1.0.5.tgz
46
+ dsh plugin --profile desktop add /path/to/dsh-token-dash-1.0.6.tgz
45
47
  ```
46
48
 
47
49
  Update: run `update` with the same name, or use the in-app updater (settings → check for updates). Remove: run `remove` with the same name; data stays in `$DSH_HOME/dsh-token-dash/`.
@@ -64,13 +66,17 @@ P2 · Floating dashboard (opens right above the pill; cards appear as API keys a
64
66
  │ Token Dashboard Refresh Settings × │
65
67
  │ Pay-as-you-go (3 detected) just now │
66
68
  │ ┌──────────────────────────────────────────────────────┐ │
67
- │ │ DeepSeek Budget ¥79.13/¥95.80 · 91.9% Today Bal. │ │
69
+ │ │ DeepSeek Budget ¥91.90/¥100.00 · 91.9% Today Bal. │ │
68
70
  │ │ [=========================================-------] │ │
69
71
  │ └──────────────────────────────────────────────────────┘ │
70
72
  │ ┌──────────────────────────────────────────────────────┐ │
71
- │ │ OpenRouter Budget $23.52/$62.00 · 38.0% Today Bal. │ │
73
+ │ │ OpenRouter Budget $22.80/$60.00 · 38.0% Today Bal. │ │
72
74
  │ │ [==================--------------------------------] │ │
73
75
  │ └──────────────────────────────────────────────────────┘ │
76
+ │ ┌──────────────────────────────────────────────────────┐ │
77
+ │ │ Qwen Budget ¥0.40/¥5.00 · 8.0% Today Bal. │ │
78
+ │ │ [====----------------------------------------------] │ │
79
+ │ └──────────────────────────────────────────────────────┘ │
74
80
  │ Subscriptions (2 detected) │
75
81
  │ ┌────────────────────────────┐ ┌────────────────────────┐ │
76
82
  │ │ GLM Coding │ │ Kimi Coding │ │
@@ -84,9 +90,10 @@ P2 · Floating dashboard (opens right above the pill; cards appear as API keys a
84
90
  P3 · Settings
85
91
  ┌──────────────────────────────────────────────────────────┐
86
92
  │ ← Back Token Dashboard [Close] │
87
- │ API billing (2 detected) │
88
- │ DeepSeek Monthly budget [ 500.00 ] CNY │
89
- │ OpenRouter Monthly budget [ 50.00 ] USD │
93
+ │ API billing (3 detected) │
94
+ │ DeepSeek Monthly budget [ 100.00 ] CNY │
95
+ │ OpenRouter Monthly budget [ 60.00 ] USD │
96
+ │ Qwen Monthly budget [ 5.00 ] CNY │
90
97
  │ Subscriptions (2 detected) [Rescan] │
91
98
  │ GLM Coding 5h 42% / Week 18% │
92
99
  │ Kimi Coding 5h 30% / Week 12% │
@@ -96,7 +103,8 @@ P3 · Settings
96
103
  │ Logs │
97
104
  │ View logs [Open log folder] [Export logs] │
98
105
  │ Pricing & version │
99
- │ Version 1.0.5 [Check update]│
106
+ │ View pricing DeepSeek GLM Kimi OpenRouter Qwen │
107
+ │ Version 1.0.6 [Check update]│
100
108
  └──────────────────────────────────────────────────────────┘
101
109
 
102
110
  UI transitions
@@ -138,7 +146,7 @@ UI transitions
138
146
 
139
147
  ## Logs & privacy
140
148
 
141
- When filing a bug, attach `~/.dsh/logs/dsh-token-dash/` (already redacted). Error log entries carry `errorKind` (http/timeout/network/parse) and `httpStatus`, which usually pinpoints the cause:
149
+ When filing a bug, attach `$DSH_HOME/logs/dsh-token-dash/` (already redacted). Error log entries carry `errorKind` (http/timeout/network/parse) and `httpStatus`, which usually pinpoints the cause:
142
150
 
143
151
  ```bash
144
152
  npm run logs -- --tail 50 # tail recent logs
@@ -155,7 +163,7 @@ npm run e2e # end-to-end (temp DSH_HOME + web profile + Playwright)
155
163
  npm run pack # build the release tarball into build/
156
164
  ```
157
165
 
158
- Releases: pushing a `v*` tag triggers the GitHub Release (tarball) and an npm staged publish automatically (goes live after a maintainer approves it on npmjs.com with 2FA); see [docs/release.md](./docs/release.md) for the full checklist.
166
+ Releases: pushing a `v*` tag triggers the GitHub Release (tarball) and a direct npm publish automatically (Trusted Publishing via OIDC, with provenance — no manual approval step); see [docs/release.md](./docs/release.md) for the full checklist.
159
167
 
160
168
  ## Acknowledgements
161
169
 
package/README.md CHANGED
@@ -5,7 +5,8 @@
5
5
  </p>
6
6
 
7
7
  <p align="center">
8
- 在 DSH 输入框旁看清每日/每月模型消耗与预算余量:API Key 一填即自动识别订阅还是按量计费,月度预算可设、消耗实时估算。
8
+ 在 DSH 输入框旁看清每日/每月模型消耗与预算余量:<br />
9
+ API Key 一填即自动识别订阅还是按量计费,月度预算可设、消耗实时估算。
9
10
  </p>
10
11
 
11
12
  <p align="center">
@@ -16,6 +17,7 @@
16
17
 
17
18
  <p align="center">
18
19
  <img src="https://img.shields.io/github/v/tag/spartawhy117/dsh-token-dash?label=version&sort=semver" alt="version" />
20
+ <img src="https://img.shields.io/npm/dt/dsh-token-dash?logo=npm&label=npm%20downloads" alt="npm downloads" />
19
21
  <img src="https://img.shields.io/github/downloads/spartawhy117/dsh-token-dash/total?label=downloads" alt="downloads" />
20
22
  <img src="https://img.shields.io/github/license/spartawhy117/dsh-token-dash" alt="license" />
21
23
  <img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node" />
@@ -31,7 +33,7 @@
31
33
 
32
34
  ## 安装
33
35
 
34
- Requires DSH `0.2.1` or newer,三种方式任选:
36
+ 需要 DSH `0.2.1` 或更新版本,三种方式任选:
35
37
 
36
38
  ```bash
37
39
  # 方式一:npm 安装(推荐)
@@ -41,7 +43,7 @@ dsh plugin --profile desktop add dsh-token-dash
41
43
  dsh plugin --profile desktop add github:spartawhy117/dsh-token-dash
42
44
 
43
45
  # 方式三:从 Releases 下载 dsh-token-dash-x.y.z.tgz 后本地安装(离线场景)
44
- dsh plugin --profile desktop add /path/to/dsh-token-dash-1.0.5.tgz
46
+ dsh plugin --profile desktop add /path/to/dsh-token-dash-1.0.6.tgz
45
47
  ```
46
48
 
47
49
  更新:`update` 同名命令(npm / github: 各自同名),或在插件设置页(P3 → 检查更新)内完成。卸载:`remove` 同名命令,数据保留在 `$DSH_HOME/dsh-token-dash/`。
@@ -64,15 +66,15 @@ P2 · 浮层看板(pill 正上方弹出;卡片与行随 API Key 侦测动态
64
66
  │ Token 看板 刷新 设置 关闭│
65
67
  │ API 按量(已检测 3) 刚刚 │
66
68
  │ ┌──────────────────────────────────────────────────────┐ │
67
- │ │ DeepSeek 官方 预算 ¥79.13/¥95.80 · 91.9% 今日 余额 │ │
69
+ │ │ DeepSeek 预算 ¥91.90/¥100.00 · 91.9% 今日 余额 │ │
68
70
  │ │ [=========================================-------] │ │
69
71
  │ └──────────────────────────────────────────────────────┘ │
70
72
  │ ┌──────────────────────────────────────────────────────┐ │
71
- │ │ OpenRouter 预算 $23.52/$62.00 · 38.0% 今日 余额 │ │
73
+ │ │ OpenRouter 预算 $22.80/$60.00 · 38.0% 今日 余额 │ │
72
74
  │ │ [==================--------------------------------] │ │
73
75
  │ └──────────────────────────────────────────────────────┘ │
74
76
  │ ┌──────────────────────────────────────────────────────┐ │
75
- │ │ Qwen(百炼) 预算 ¥0.02/¥0.25 · 8.0% 今日 余额 │ │
77
+ │ │ 通义千问 预算 ¥0.40/¥5.00 · 8.0% 今日 余额 │ │
76
78
  │ │ [====----------------------------------------------] │ │
77
79
  │ └──────────────────────────────────────────────────────┘ │
78
80
  │ 订阅套餐(已检测 2) │
@@ -82,26 +84,27 @@ P2 · 浮层看板(pill 正上方弹出;卡片与行随 API Key 侦测动态
82
84
  │ │ 重置 14:05 │ │ 重置 15:20 │ │
83
85
  │ └────────────────────────────┘ └────────────────────────┘ │
84
86
  │ API 费用明细 / 本月 DSH 本机估算 │
85
- │ CNY 合计 ¥4.96 │
86
- │ DeepSeek 官方 / DeepSeek-V4.1-Flash 99.6% ¥4.94 │
87
- │ Qwen / Qwen3.8-Max 0.4% ¥0.02 │
88
- │ USD 合计 $0.12 │
89
- │ OpenRouter / DeepSeek-V4.1-Flash 100.0% $0.12 │
87
+ │ CNY 合计 ¥92.30 │
88
+ │ DeepSeek / DeepSeek-V4.1-Flash 99.6% ¥91.90 │
89
+ │ 通义千问 / Qwen3.8-Max 0.4% ¥0.40 │
90
+ │ USD 合计 $22.80 │
91
+ │ OpenRouter / DeepSeek-V4.1-Flash 100.0% $22.80 │
90
92
  │ 模型用量明细 / 本月 合计 1.31M│
91
93
  │ 模型 请求 输入 命中 输出 │
92
- │ DeepSeek 官方 / V4.1-Flash 48 0.11M 0.20M 0.02M│
94
+ │ DeepSeek / V4.1-Flash 48 0.11M 0.20M 0.02M│
93
95
  │ OpenRouter / V4.1-Flash 12 0.02M 0.01M 0.01M│
94
- │ Qwen / Qwen3.8-Max 24 0.05M 0.02M 0.01M│
95
- │ GLM Coding / GLM-5.3 64 0.30M 0.60M 0.04M│
96
+ │ 通义千问 / Qwen3.8-Max 24 0.05M 0.02M 0.01M│
97
+ │ GLM Coding / GLM-5.3 64 0.30M 0.52M 0.04M│
96
98
  └──────────────────────────────────────────────────────────┘
97
99
 
98
100
  P3 · 设置
99
101
  ┌──────────────────────────────────────────────────────────┐
100
102
  │ ← 返回 Token 看板 [关闭] │
101
- │ API 计费(已检测 2) │
103
+ │ API 计费(已检测 3) │
102
104
  │ ┌──────────────────────────────────────────────────────┐ │
103
- │ │ DeepSeek 官方 月度预算 [ 500.00 ] CNY │ │
104
- │ │ OpenRouter 月度预算 [ 50.00 ] USD │ │
105
+ │ │ DeepSeek 月度预算 [ 100.00 ] CNY │ │
106
+ │ │ OpenRouter 月度预算 [ 60.00 ] USD │ │
107
+ │ │ 通义千问 月度预算 [ 5.00 ] CNY │ │
105
108
  │ └──────────────────────────────────────────────────────┘ │
106
109
  │ 订阅计费(已检测 2) [重新检测] │
107
110
  │ ┌──────────────────────────────────────────────────────┐ │
@@ -119,7 +122,8 @@ P3 · 设置
119
122
  │ └──────────────────────────────────────────────────────┘ │
120
123
  │ 价格与版本 │
121
124
  │ ┌──────────────────────────────────────────────────────┐ │
122
- │ │ 版本 1.0.5 [检查更新] │ │
125
+ │ │ 查看价格明细 DeepSeek GLM Kimi OpenRouter Qwen │ │
126
+ │ │ 版本 1.0.6 [检查更新] │ │
123
127
  │ └──────────────────────────────────────────────────────┘ │
124
128
  └──────────────────────────────────────────────────────────┘
125
129
 
@@ -162,7 +166,7 @@ UI 交互转移
162
166
 
163
167
  ## 日志与隐私
164
168
 
165
- 报障时附上 `~/.dsh/logs/dsh-token-dash/`(已脱敏),错误日志带 `errorKind`(http/timeout/network/parse)与 `httpStatus`,可直接定位原因:
169
+ 报障时附上 `$DSH_HOME/logs/dsh-token-dash/`(已脱敏),错误日志带 `errorKind`(http/timeout/network/parse)与 `httpStatus`,可直接定位原因:
166
170
 
167
171
  ```bash
168
172
  npm run logs -- --tail 50 # 查看最近日志
@@ -179,7 +183,7 @@ npm run e2e # 端到端(临时 DSH_HOME + web profile + Playwright)
179
183
  npm run pack # 发布 tarball 生成到 build/
180
184
  ```
181
185
 
182
- 发版:推 `v*` tag 自动触发 GitHub Release(tarball)与 npm 暂存(staged publishing,网页 2FA 审批后上线);完整流程见 [docs/release.md](./docs/release.md)。
186
+ 发版:推 `v*` tag 自动触发 GitHub Release(tarball)与 npm 直发(Trusted Publishing / OIDC,含 provenance 溯源,无需人工审批);完整流程见 [docs/release.md](./docs/release.md)。
183
187
 
184
188
  ## 致谢
185
189
 
package/client.js CHANGED
@@ -11,15 +11,7 @@ window.__ModuleLoader__.load({
11
11
 
12
12
  const API = '/token-dash/api'
13
13
  const PKG = 'dsh-token-dash'
14
- const LINKS = [
15
- ['DeepSeek', 'https://api-docs.deepseek.com/quick_start/pricing'],
16
- ['GLM', 'https://docs.bigmodel.cn/cn/guide/start/pricing'],
17
- ['Kimi', 'https://platform.moonshot.cn/docs/pricing/chat'],
18
- ['OpenRouter', 'https://openrouter.ai/models'],
19
- ['Qwen', 'https://help.aliyun.com/zh/model-studio/billing-for-alibaba-cloud-model-studio'],
20
- ]
21
-
22
- const COLORS = { primary: '#6ea8ff', warn: '#f0a020', over: '#e05a5a' }
14
+ const COLORS = { primary: 'var(--dsw-alias-state-business-primary, #6ea8ff)', warn: '#f0a020', over: '#e05a5a' }
23
15
  const budgetColor = (state) => (state === 'over' ? COLORS.over : state === 'warn' ? COLORS.warn : COLORS.primary)
24
16
  const percentColor = (value) => (value >= 100 ? COLORS.over : value >= 80 ? COLORS.warn : COLORS.primary)
25
17
 
@@ -112,7 +104,7 @@ window.__ModuleLoader__.load({
112
104
  titleBar: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, minHeight: 36 },
113
105
  buttonGroup: { display: 'flex', gap: 12 },
114
106
  bar: { height: 6, borderRadius: 3, background: 'rgba(128,128,128,.25)', overflow: 'hidden', margin: '8px 0' },
115
- barFill: { height: '100%', background: '#6ea8ff' },
107
+ barFill: { height: '100%', background: COLORS.primary },
116
108
  barNeutral: { height: '100%', background: 'rgba(128,128,128,.45)' },
117
109
  cols: { display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 0, marginTop: 8 },
118
110
  subGrid: { display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(240px, 1fr))', gap: 8 },
@@ -175,11 +167,11 @@ window.__ModuleLoader__.load({
175
167
  }
176
168
 
177
169
  function subscriptionText(provider) {
178
- const plans = Array.isArray(provider.plans) ? provider.plans : []
179
- if (plans.length === 0) return '套餐查询失败'
180
- const text = plans.slice(0, 2).map((plan) => `${windowLabel[plan.key] ?? plan.key} ${fmtUsed(plan.usedPercent)}`).join(' · ')
181
- if (plans.length === 1) {
182
- const reset = fmtReset(plans[0].resetAt)
170
+ const windows = Array.isArray(provider.windows) ? provider.windows : []
171
+ if (windows.length === 0) return '套餐查询失败'
172
+ const text = windows.slice(0, 2).map((plan) => `${windowLabel[plan.key] ?? plan.key} ${fmtUsed(plan.usedPercent)}`).join(' · ')
173
+ if (windows.length === 1) {
174
+ const reset = fmtReset(windows[0].resetAt)
183
175
  if (reset !== null) return `${text} · 重置 ${reset}`
184
176
  }
185
177
  return text
@@ -187,14 +179,14 @@ window.__ModuleLoader__.load({
187
179
 
188
180
  /** 订阅窗口节点:百分比按官方原值着色;withReset 时单窗口附重置时间(P1)。 */
189
181
  function subscriptionNodes(provider, withReset = false) {
190
- const plans = Array.isArray(provider.plans) ? provider.plans : []
191
- if (plans.length === 0) return [h('span', { key: 'fail' }, '套餐查询失败')]
192
- const nodes = plans.slice(0, 2).map((plan, index) => h(React.Fragment, { key: plan.key },
182
+ const windows = Array.isArray(provider.windows) ? provider.windows : []
183
+ if (windows.length === 0) return [h('span', { key: 'fail' }, '套餐查询失败')]
184
+ const nodes = windows.slice(0, 2).map((plan, index) => h(React.Fragment, { key: plan.key },
193
185
  index > 0 ? ' · ' : null,
194
186
  `${windowLabel[plan.key] ?? plan.key} `,
195
187
  h('b', { style: { ...styles.num, color: percentColor(plan.usedPercent ?? 0) } }, fmtUsed(plan.usedPercent))))
196
- if (withReset && plans.length === 1) {
197
- const reset = fmtReset(plans[0].resetAt)
188
+ if (withReset && windows.length === 1) {
189
+ const reset = fmtReset(windows[0].resetAt)
198
190
  if (reset !== null) nodes.push(h('span', { key: 'reset' }, ` · 重置 ${reset}`))
199
191
  }
200
192
  return nodes
@@ -283,7 +275,7 @@ window.__ModuleLoader__.load({
283
275
  if (current?.kind === 'subscription') {
284
276
  prefix = '[订阅]'
285
277
  bodyNodes = [
286
- h('span', { key: 'plans' }, ...subscriptionNodes(current, true)),
278
+ h('span', { key: 'windows' }, ...subscriptionNodes(current, true)),
287
279
  ]
288
280
  ariaText = `${current.name},订阅,账户套餐,${subscriptionText(current)}`
289
281
  } else if (current !== undefined) {
@@ -344,24 +336,26 @@ window.__ModuleLoader__.load({
344
336
  h('span', null, `余额 ${balanceText(provider, true) ?? '--'}`))),
345
337
  h('div', { style: { ...styles.bar, marginTop: 6, marginBottom: 0 } },
346
338
  h('div', {
339
+ 'data-testid': `token-dash-budget-bar-${provider.id}`,
347
340
  style: {
348
- ...(hasBudget ? { background: color } : styles.barNeutral),
341
+ ...styles.barFill,
342
+ background: hasBudget ? color : styles.barNeutral.background,
349
343
  width: hasBudget ? `${Math.min(100, (budget.percent ?? 0) * 100)}%` : '100%',
350
344
  },
351
345
  })))
352
346
  }
353
347
 
354
348
  function SubscriptionCard({ provider }) {
355
- const plans = Array.isArray(provider.plans) ? provider.plans : []
356
- const resets = plans.map((plan) => plan.resetAt).filter((ts) => Number.isFinite(ts) && ts > 0)
349
+ const windows = Array.isArray(provider.windows) ? provider.windows : []
350
+ const resets = windows.map((plan) => plan.resetAt).filter((ts) => Number.isFinite(ts) && ts > 0)
357
351
  const nextReset = resets.length > 0 ? Math.min(...resets) : null
358
352
  return h('div', { 'data-testid': `token-dash-sub-card-${provider.id}`, style: { ...styles.card, marginTop: 0 } },
359
353
  h('div', { style: styles.row }, h('b', { style: styles.nameEllipsis, title: provider.name }, provider.name), h('span', { style: styles.muted }, '订阅')),
360
- plans.length === 0
354
+ windows.length === 0
361
355
  ? h('div', { style: { ...styles.muted, marginTop: 6 } }, '套餐查询失败')
362
356
  : h(React.Fragment, null,
363
357
  h('div', { style: { ...styles.row, marginTop: 6, flexWrap: 'wrap', justifyContent: 'flex-start' } }, subscriptionNodes(provider)),
364
- plans.map((plan) => h('div', { key: plan.key, style: styles.bar },
358
+ windows.map((plan) => h('div', { key: plan.key, style: styles.bar },
365
359
  h('div', { style: { ...styles.barFill, width: `${Math.min(100, plan.usedPercent ?? 0)}%` } }))),
366
360
  nextReset !== null ? h('div', { style: { ...styles.muted, marginTop: 2 } }, `重置 ${fmtReset(nextReset)}`) : null))
367
361
  }
@@ -619,7 +613,7 @@ window.__ModuleLoader__.load({
619
613
  const res = await fetch(`${API}/update/install`, { method: 'POST', headers: { accept: 'application/json' } })
620
614
  const body = await res.json().catch(() => ({}))
621
615
  const data = body?.data
622
- if (body?.ok === true) setUpdate({ phase: 'done', text: '已更新,重启 DSH 后生效' })
616
+ if (body?.ok === true) setUpdate({ phase: 'done', text: data?.to ? `已更新到 ${data.to},重启 DSH 后生效` : '已更新,重启 DSH 后生效' })
623
617
  else setUpdate({ phase: 'error', text: `更新失败(${data?.reason ?? 'unknown'})`, command: data?.command })
624
618
  } catch (error) {
625
619
  setUpdate({ phase: 'error', text: `更新失败(${error.message})` })
@@ -713,7 +707,7 @@ window.__ModuleLoader__.load({
713
707
  h('div', { style: styles.row },
714
708
  h('span', null, '查看价格明细'),
715
709
  h('span', { style: { display: 'flex', flexWrap: 'wrap', justifyContent: 'flex-end', gap: 8 } },
716
- LINKS.map(([label, url]) => h('a', { key: label, href: url, target: '_blank', rel: 'noopener', style: { ...styles.link, marginLeft: 0 } }, label)))),
710
+ (summary?.pricingLinks ?? []).map((link) => h('a', { key: link.id ?? link.label, href: link.url, target: '_blank', rel: 'noopener', style: { ...styles.link, marginLeft: 0 } }, link.label)))),
717
711
  h('div', { style: styles.row },
718
712
  h('span', { style: styles.muted }, `版本 ${version}`),
719
713
  updateControl))),
Binary file
Binary file
package/index.js CHANGED
@@ -7,10 +7,11 @@ import { spawn } from 'node:child_process'
7
7
  import { dirname, join } from 'node:path'
8
8
  import { buildSummary, emptyState, num, repriceState } from './src/core.js'
9
9
  import { ingest, backfill } from './src/collect.js'
10
- import { createFlusher, dataDir, loadPrefs, loadState, logsDir, recoverState, saveJson, saveMonths } from './src/store.js'
10
+ import { createFlusher, dataDir, loadPrefs, loadState, logsDir, recoverState, resolveHome, saveJson, saveMonths } from './src/store.js'
11
11
  import { logAdapterEvents, readProviders, readSubscriptions } from './src/adapters.js'
12
12
  import { catalogInfo, loadCommunityPricing, loadRouterPricing } from './src/pricing.js'
13
13
  import { clearLog, createLogger, exportLog } from './src/diagnostics.js'
14
+ import { isNewer } from './src/version.js'
14
15
 
15
16
  export const name = 'dsh-token-dash'
16
17
 
@@ -19,20 +20,6 @@ const CURRENT_VERSION = JSON.parse(readFileSync(new URL('./package.json', import
19
20
  const PROVIDER_TTL = 30000
20
21
  let updateCache = { at: 0, data: null }
21
22
 
22
- function versionParts(value) {
23
- return String(value).split('.').map((part) => Number.parseInt(part, 10) || 0)
24
- }
25
-
26
- function isNewer(latest, current) {
27
- const left = versionParts(latest)
28
- const right = versionParts(current)
29
- for (let index = 0; index < Math.max(left.length, right.length); index += 1) {
30
- const diff = (left[index] ?? 0) - (right[index] ?? 0)
31
- if (diff !== 0) return diff > 0
32
- }
33
- return false
34
- }
35
-
36
23
  /** Locate the bundled dsh CLI (same layout scripts/e2e.mjs relies on). */
37
24
  function findDshCli() {
38
25
  const fromEnv = process.env.DSH_CLI
@@ -46,16 +33,40 @@ function findDshCli() {
46
33
  return null
47
34
  }
48
35
 
49
- /** Run `dsh plugin --profile <p> update dsh-token-dash`; resolves with { ok, reason?, command, output }. */
50
- function runPluginUpdate(profile) {
36
+ /** Installed version of this plugin inside a DSH profile; null when the manifest is unreadable. */
37
+ function installedVersion(home, profile) {
38
+ try {
39
+ const file = join(home, 'profiles', profile, 'node_modules', 'dsh-token-dash', 'package.json')
40
+ return JSON.parse(readFileSync(file, 'utf8')).version ?? null
41
+ } catch {
42
+ return null
43
+ }
44
+ }
45
+
46
+ /** Ask the npm registry for the published latest; 404 means the package is not published yet. */
47
+ async function fetchLatest() {
48
+ const response = await fetch('https://registry.npmjs.org/dsh-token-dash/latest', {
49
+ headers: { accept: 'application/json' },
50
+ signal: AbortSignal.timeout(5000),
51
+ })
52
+ if (response.status === 404) return { current: CURRENT_VERSION, latest: null, hasUpdate: false, published: false }
53
+ if (!response.ok) throw new Error(`registry-${response.status}`)
54
+ const meta = await response.json()
55
+ if (typeof meta?.version !== 'string') throw new Error('invalid-registry-response')
56
+ return { current: CURRENT_VERSION, latest: meta.version, hasUpdate: isNewer(meta.version, CURRENT_VERSION), published: true }
57
+ }
58
+
59
+ /** Run `dsh plugin --profile <p> add dsh-token-dash@<version> --save-exact`; resolves with { ok, reason?, command, output }. */
60
+ function runPluginUpdate(profile, version) {
51
61
  return new Promise((resolve) => {
52
- const command = `dsh plugin --profile ${profile} update dsh-token-dash`
62
+ const spec = `dsh-token-dash@${version}`
63
+ const command = `dsh plugin --profile ${profile} add ${spec} --save-exact`
53
64
  const cli = findDshCli()
54
65
  if (cli === null) {
55
66
  resolve({ ok: false, reason: 'cli-not-found', command, output: '' })
56
67
  return
57
68
  }
58
- const child = spawn(process.execPath, ['--expose-internals', cli, 'plugin', '--profile', profile, 'update', 'dsh-token-dash'], {
69
+ const child = spawn(process.execPath, ['--expose-internals', cli, 'plugin', '--profile', profile, 'add', spec, '--save-exact'], {
59
70
  env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' },
60
71
  windowsHide: true,
61
72
  })
@@ -287,13 +298,33 @@ export function apply(ctx) {
287
298
  }
288
299
  if (url.pathname === `${ROUTE_PREFIX}/update/install` && req.method === 'POST') {
289
300
  const profile = typeof process.env.DSH_PROFILE === 'string' && process.env.DSH_PROFILE !== '' ? process.env.DSH_PROFILE : 'desktop'
290
- const result = await runPluginUpdate(profile)
291
- logger.info('update', result.ok ? 'install.ok' : 'install.fail', {
301
+ const latest = (await fetchLatest()).latest
302
+ if (latest === null) {
303
+ logger.info('update', 'install.fail', { profile, reason: 'unpublished' })
304
+ json(res, 200, { ok: false, reason: 'unpublished', data: { reason: 'unpublished', command: '' } })
305
+ return
306
+ }
307
+ if (/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(latest) === false) throw new Error('invalid-latest-version')
308
+ const home = resolveHome(scoped)
309
+ const from = installedVersion(home, profile) ?? CURRENT_VERSION
310
+ const result = await runPluginUpdate(profile, latest)
311
+ const to = installedVersion(home, profile)
312
+ const changed = to === latest
313
+ const ok = result.ok === true && changed
314
+ const failReason = result.ok === true ? 'version-unchanged' : result.reason ?? 'install-failed'
315
+ logger.info('update', ok ? 'install.ok' : 'install.fail', {
292
316
  profile,
293
- reason: result.reason ?? null,
294
- ...(result.ok ? {} : { output: String(result.output ?? '').slice(-500) }),
317
+ from,
318
+ to,
319
+ reason: ok ? null : failReason,
320
+ ...(ok ? {} : { output: String(result.output ?? '').slice(-500) }),
321
+ })
322
+ updateCache = { at: 0, data: null }
323
+ json(res, 200, {
324
+ ok,
325
+ data: { ...result, from, to, latest, ...(ok ? {} : { reason: failReason }) },
326
+ ...(ok ? {} : { reason: failReason }),
295
327
  })
296
- json(res, 200, { ok: result.ok, data: result, ...(result.ok ? {} : { reason: 'install-failed' }) })
297
328
  return
298
329
  }
299
330
  if (url.pathname === `${ROUTE_PREFIX}/update` && req.method === 'GET') {
@@ -301,20 +332,7 @@ export function apply(ctx) {
301
332
  json(res, 200, { ok: true, data: updateCache.data })
302
333
  return
303
334
  }
304
- const response = await fetch('https://registry.npmjs.org/dsh-token-dash/latest', {
305
- headers: { accept: 'application/json' },
306
- signal: AbortSignal.timeout(5000),
307
- })
308
- if (response.status === 404) {
309
- const data = { current: CURRENT_VERSION, latest: null, hasUpdate: false, published: false }
310
- updateCache = { at: Date.now(), data }
311
- json(res, 200, { ok: true, data })
312
- return
313
- }
314
- if (!response.ok) throw new Error(`registry-${response.status}`)
315
- const meta = await response.json()
316
- if (typeof meta?.version !== 'string') throw new Error('invalid-registry-response')
317
- const data = { current: CURRENT_VERSION, latest: meta.version, hasUpdate: isNewer(meta.version, CURRENT_VERSION), published: true }
335
+ const data = await fetchLatest()
318
336
  updateCache = { at: Date.now(), data }
319
337
  json(res, 200, { ok: true, data })
320
338
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-token-dash",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "DSH Token 看板:API/订阅动态 provider、预算、配额、模型费用/用量与诊断日志。",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/src/adapters.js CHANGED
@@ -225,6 +225,32 @@ function visibleEntry(entry, prefs) {
225
225
  return entry !== null && prefs?.billingModes?.[entry.id] !== 'hide'
226
226
  }
227
227
 
228
+ /** Adapter → VM boundary: normalize ad-hoc adapter rows into ProviderSnapshot. */
229
+ export function toSnapshot(entry) {
230
+ const error = entry.error ?? entry._error ?? null
231
+ const quotaError = entry.quotaError ?? entry._quotaError ?? null
232
+ const balance = entry.balance ?? null
233
+ const status = error !== null
234
+ ? 'error'
235
+ : balance?.status === 'unconfigured'
236
+ ? 'unconfigured'
237
+ : balance?.status === 'error'
238
+ ? 'error'
239
+ : 'ok'
240
+ return {
241
+ id: entry.id,
242
+ name: entry.name,
243
+ kind: entry.kind === 'subscription' ? 'subscription' : 'api',
244
+ currency: entry.currency,
245
+ status,
246
+ balance,
247
+ windows: Array.isArray(entry.windows) ? entry.windows : Array.isArray(entry.plans) ? entry.plans : [],
248
+ error,
249
+ quotaError,
250
+ fetchedAt: entry.fetchedAt ?? Date.now(),
251
+ }
252
+ }
253
+
228
254
  /** Query configured providers; each failure is isolated. Balance/credits are always requested (P2 shows them regardless of the P1-only toggle, #31). */
229
255
  export async function readProviders(ctx, prefs) {
230
256
  const results = await Promise.allSettled([deepseek(ctx), glm(ctx, prefs), kimi(ctx, prefs), openrouter(ctx), qwen(ctx)])
@@ -233,7 +259,7 @@ export async function readProviders(ctx, prefs) {
233
259
  if (result.status === 'fulfilled' && visibleEntry(result.value, prefs)) {
234
260
  const value = result.value
235
261
  value.currency = value.currency ?? providerCurrency(normalizeProvider(value.id))
236
- out.push(value)
262
+ out.push(toSnapshot(value))
237
263
  }
238
264
  }
239
265
  return out
@@ -250,8 +276,8 @@ export async function readSubscriptions(ctx, prefs) {
250
276
  ])
251
277
  const kimiEntry = kimiQuota.state === 'ok' ? kimiQuota.entry : kimiQuota.state === 'fallback' ? { id: 'moonshot', kind: 'api', currency: 'CNY' } : null
252
278
  const out = []
253
- if (visibleEntry(glmEntry, prefs)) out.push(glmEntry)
254
- if (visibleEntry(kimiEntry, prefs)) out.push(kimiEntry)
279
+ if (visibleEntry(glmEntry, prefs)) out.push(toSnapshot(glmEntry))
280
+ if (visibleEntry(kimiEntry, prefs)) out.push(toSnapshot(kimiEntry))
255
281
  return out
256
282
  }
257
283
 
@@ -263,29 +289,29 @@ export function logAdapterEvents(log, providers) {
263
289
  for (const item of providers) {
264
290
  if (item.id === 'deepseek-official') {
265
291
  if (item.balance?.status === 'ok') info('adapter.deepseek', 'balance.ok', { amount: item.balance.amount })
266
- else if (item.balance?.status === 'unconfigured') info('adapter.deepseek', 'balance.auth', errorMeta(item._error))
267
- else if (item.balance !== undefined) info('adapter.deepseek', 'balance.error', { status: item.balance.status, ...errorMeta(item._error ?? item.balance._error) })
292
+ else if (item.balance?.status === 'unconfigured') info('adapter.deepseek', 'balance.auth', errorMeta(item.error))
293
+ else if (item.balance !== undefined) info('adapter.deepseek', 'balance.error', { status: item.balance.status, ...errorMeta(item.error ?? item.balance._error) })
268
294
  continue
269
295
  }
270
296
  if (item.id === 'zhipu' || item.id === 'moonshot') {
271
297
  const module = item.id === 'zhipu' ? 'adapter.glm' : 'adapter.kimi'
272
298
  if (item.kind === 'subscription') {
273
- const windows = (item.plans ?? []).length
299
+ const windows = (item.windows ?? []).length
274
300
  if (windows > 0) info(module, 'quota.ok', { windows })
275
- else if (item._quotaError?.kind === 'parse') info(module, 'quota.parse', {})
276
- else info(module, 'quota.fail', { windows: 0, ...errorMeta(item._quotaError) })
277
- } else if (item._quotaError !== undefined && item._quotaError !== null) {
278
- info(module, 'quota.fail', { ...errorMeta(item._quotaError) })
301
+ else if (item.quotaError?.kind === 'parse') info(module, 'quota.parse', {})
302
+ else info(module, 'quota.fail', { windows: 0, ...errorMeta(item.quotaError) })
303
+ } else if (item.quotaError !== undefined && item.quotaError !== null) {
304
+ info(module, 'quota.fail', { ...errorMeta(item.quotaError) })
279
305
  } else {
280
306
  info(module, 'quota.miss', {})
281
307
  }
282
308
  if (item.id === 'moonshot' && item.balance?.status === 'ok') info('adapter.kimi', 'balance.ok', { amount: item.balance.amount })
283
- if (item.id === 'moonshot' && item.balance?.status === 'error') info('adapter.kimi', 'balance.error', { status: 'error', ...errorMeta(item._error ?? item.balance._error) })
309
+ if (item.id === 'moonshot' && item.balance?.status === 'error') info('adapter.kimi', 'balance.error', { status: 'error', ...errorMeta(item.error ?? item.balance._error) })
284
310
  continue
285
311
  }
286
312
  if (item.id === 'openrouter') {
287
313
  if (item.balance?.status === 'ok') info('adapter.openrouter', 'credits.ok', { amount: item.balance.amount })
288
- else if (item.balance !== undefined) info('adapter.openrouter', 'credits.error', { status: item.balance.status, ...errorMeta(item._error ?? item.balance._error) })
314
+ else if (item.balance !== undefined) info('adapter.openrouter', 'credits.error', { status: item.balance.status, ...errorMeta(item.error ?? item.balance._error) })
289
315
  continue
290
316
  }
291
317
  if (item.id === 'qwen') {
package/src/core.js CHANGED
@@ -5,10 +5,11 @@
5
5
  import { priceFor } from './pricing.js'
6
6
  import {
7
7
  canBeSubscription,
8
- DEFAULT_MODELS,
8
+ defaultModelFor,
9
9
  modelLabel,
10
10
  normalizeModel,
11
11
  normalizeProvider,
12
+ pricingLinks,
12
13
  providerCurrency,
13
14
  providerFromModel,
14
15
  providerLabel,
@@ -190,6 +191,7 @@ function providerEmpty(providerId) {
190
191
  currency: providerCurrency(providerId),
191
192
  usage: { todayTokens: 0, monthTokens: 0, todayCost: 0, monthCost: 0, requests: 0 },
192
193
  models: [],
194
+ windows: [],
193
195
  }
194
196
  }
195
197
 
@@ -212,7 +214,8 @@ export function buildSummary(state, prefs, now, providerInfoInput) {
212
214
  .map(([id]) => normalizeProvider(id)),
213
215
  )
214
216
 
215
- for (const info of providerInfo) {
217
+ for (const item of providerInfo) {
218
+ const { plans: legacyPlans, ...info } = item
216
219
  const id = normalizeProvider(info.id ?? info.provider)
217
220
  if (id === 'unknown' || hidden.has(id)) continue
218
221
  const base = providerMap.get(id) ?? providerEmpty(id)
@@ -221,14 +224,14 @@ export function buildSummary(state, prefs, now, providerInfoInput) {
221
224
  ...info,
222
225
  id,
223
226
  name: info.name ?? providerLabel(id),
224
- kind: info.kind === 'subscription' || (info.kind === undefined && Array.isArray(info.plans) && info.plans.length > 0)
227
+ kind: info.kind === 'subscription' || (info.kind === undefined && (info.windows ?? legacyPlans ?? []).length > 0)
225
228
  ? 'subscription'
226
229
  : 'api',
227
230
  canSubscribe: canBeSubscription(id),
228
231
  currency: info.currency === 'USD' ? 'USD' : (info.currency === 'CNY' ? 'CNY' : providerCurrency(id)),
229
232
  usage: { ...base.usage, ...(info.usage ?? {}) },
230
233
  balance: info.balance ?? base.balance,
231
- plans: info.plans ?? base.plans,
234
+ windows: info.windows ?? legacyPlans ?? base.windows ?? [],
232
235
  })
233
236
  }
234
237
 
@@ -302,7 +305,7 @@ export function buildSummary(state, prefs, now, providerInfoInput) {
302
305
  for (const info of providerInfo) {
303
306
  const id = normalizeProvider(info.id ?? info.provider)
304
307
  if (id === 'unknown' || hidden.has(id)) continue
305
- const fallbackModel = DEFAULT_MODELS[id]
308
+ const fallbackModel = defaultModelFor(id)
306
309
  if (fallbackModel === undefined) continue
307
310
  const key = `${id}:${fallbackModel}`
308
311
  // provider 已有任意真实模型行时不再补默认行(含 '-' 占位语义)
@@ -425,6 +428,7 @@ export function buildSummary(state, prefs, now, providerInfoInput) {
425
428
  apiTotals,
426
429
  currentProviderId: current,
427
430
  breakdown: { models },
431
+ pricingLinks: pricingLinks(),
428
432
  showBalance: prefs?.showBalance !== false,
429
433
  showMonthTokens: prefs?.showMonthTokens !== false,
430
434
  updatedAt: now,
package/src/providers.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Provider identity, billing mode and currency.
3
- * Pure functions only; no I/O.
2
+ * Provider registry: identity, billing mode, currency, default model,
3
+ * model ownership/labels and official pricing links. Pure data + lookups.
4
4
  */
5
5
 
6
6
  const ALIASES = {
@@ -22,22 +22,76 @@ const ALIASES = {
22
22
  openrouter: 'openrouter',
23
23
  }
24
24
 
25
- const NAMES = {
26
- 'deepseek-official': 'DeepSeek 官方',
27
- zhipu: '智谱 AI',
28
- moonshot: 'Kimi',
29
- qwen: '通义千问',
30
- openrouter: 'OpenRouter',
31
- unknown: '未知来源',
32
- }
25
+ /** Display order is also the P3 pricing-link order. */
26
+ export const PROVIDER_ORDER = ['deepseek-official', 'zhipu', 'moonshot', 'openrouter', 'qwen']
33
27
 
34
- const SUBSCRIPTION = new Set(['zhipu', 'moonshot'])
35
- const CURRENCY = {
36
- 'deepseek-official': 'CNY',
37
- zhipu: 'CNY',
38
- moonshot: 'CNY',
39
- qwen: 'CNY',
40
- openrouter: 'USD',
28
+ const PROVIDERS = {
29
+ 'deepseek-official': {
30
+ id: 'deepseek-official',
31
+ label: 'DeepSeek',
32
+ currency: 'CNY',
33
+ subscription: false,
34
+ defaultModel: 'deepseek-v4.1-flash',
35
+ prefixes: [/^deepseek/],
36
+ modelLabels: {
37
+ 'deepseek-flash': 'DeepSeek-V4.1-Flash',
38
+ 'deepseek-v4.1-flash': 'DeepSeek-V4.1-Flash',
39
+ 'deepseek-v4-flash': 'DeepSeek-V4.1-Flash',
40
+ 'deepseek-pro': 'DeepSeek-V4.1-Pro',
41
+ 'deepseek-v4-pro': 'DeepSeek-V4.1-Pro',
42
+ },
43
+ pricingUrl: 'https://api-docs.deepseek.com/quick_start/pricing',
44
+ },
45
+ zhipu: {
46
+ id: 'zhipu',
47
+ label: '智谱 AI',
48
+ currency: 'CNY',
49
+ subscription: true,
50
+ defaultModel: 'glm-5.3',
51
+ prefixes: [/^glm/],
52
+ modelLabels: {
53
+ 'glm-5.3': 'GLM-5.3',
54
+ 'glm-5.3-flash': 'GLM-5.3-Flash',
55
+ },
56
+ pricingUrl: 'https://docs.bigmodel.cn/cn/guide/start/pricing',
57
+ },
58
+ moonshot: {
59
+ id: 'moonshot',
60
+ label: 'Kimi',
61
+ currency: 'CNY',
62
+ subscription: true,
63
+ defaultModel: 'kimi-k3',
64
+ prefixes: [/^kimi/, /^moonshot/],
65
+ modelLabels: {
66
+ 'kimi-k3': 'Kimi K3',
67
+ 'kimi-k3.1-pro': 'Kimi K3.1 Pro',
68
+ 'kimi-k2.7-code': 'Kimi K2.7 Code',
69
+ },
70
+ pricingUrl: 'https://platform.moonshot.cn/docs/pricing/chat',
71
+ },
72
+ openrouter: {
73
+ id: 'openrouter',
74
+ label: 'OpenRouter',
75
+ currency: 'USD',
76
+ subscription: false,
77
+ defaultModel: '-',
78
+ prefixes: [],
79
+ modelLabels: {},
80
+ pricingUrl: 'https://openrouter.ai/models',
81
+ },
82
+ qwen: {
83
+ id: 'qwen',
84
+ label: '通义千问',
85
+ currency: 'CNY',
86
+ subscription: false,
87
+ defaultModel: 'qwen3.8-max',
88
+ prefixes: [/^qwen/],
89
+ modelLabels: {
90
+ 'qwen3.8-max': 'Qwen3.8-Max',
91
+ 'qwen3.8-flash': 'Qwen3.8-Flash',
92
+ },
93
+ pricingUrl: 'https://help.aliyun.com/zh/model-studio/billing-for-alibaba-cloud-model-studio',
94
+ },
41
95
  }
42
96
 
43
97
  export function normalizeProvider(raw) {
@@ -46,21 +100,26 @@ export function normalizeProvider(raw) {
46
100
  return ALIASES[id] ?? id
47
101
  }
48
102
 
103
+ /** Registry lookup; unknown ids return null. */
104
+ export function providerDescriptor(raw) {
105
+ return PROVIDERS[normalizeProvider(raw)] ?? null
106
+ }
107
+
49
108
  export function providerLabel(raw) {
50
109
  const id = normalizeProvider(raw)
51
- return NAMES[id] ?? id
110
+ return PROVIDERS[id]?.label ?? id
52
111
  }
53
112
 
54
113
  export function isSupportedProvider(raw) {
55
- return Object.prototype.hasOwnProperty.call(NAMES, normalizeProvider(raw)) && normalizeProvider(raw) !== 'unknown'
114
+ return providerDescriptor(raw) !== null
56
115
  }
57
116
 
58
117
  export function providerCurrency(raw) {
59
- return CURRENCY[normalizeProvider(raw)] ?? 'CNY'
118
+ return providerDescriptor(raw)?.currency ?? 'CNY'
60
119
  }
61
120
 
62
121
  export function canBeSubscription(raw) {
63
- return SUBSCRIPTION.has(normalizeProvider(raw))
122
+ return providerDescriptor(raw)?.subscription === true
64
123
  }
65
124
 
66
125
  export function providerKind(raw, mode) {
@@ -69,50 +128,40 @@ export function providerKind(raw, mode) {
69
128
  return canBeSubscription(id) ? 'subscription' : 'api'
70
129
  }
71
130
 
72
- /** #41:模型名前缀 → provider 归因(DSH 会话事件无 provider 标注时,unknown 行按此兜底归属)。 */
73
- const MODEL_OWNER_RULES = [
74
- [/^deepseek/, 'deepseek-official'],
75
- [/^glm/, 'zhipu'],
76
- [/^kimi|^moonshot/, 'moonshot'],
77
- [/^qwen/, 'qwen'],
78
- ]
131
+ /** Configured provider default model; '-' means a placeholder row (OpenRouter). */
132
+ export function defaultModelFor(raw) {
133
+ return providerDescriptor(raw)?.defaultModel
134
+ }
135
+
136
+ /** Derived compatibility export for callers that still read the table. */
137
+ export const DEFAULT_MODELS = Object.fromEntries(
138
+ PROVIDER_ORDER.map((id) => [id, PROVIDERS[id].defaultModel]),
139
+ )
79
140
 
141
+ /** Model-name prefixes → provider attribution when DSH events carry no provider. */
80
142
  export function providerFromModel(modelId) {
81
143
  const id = normalizeModel(modelId)
82
144
  if (id === 'unknown') return null
83
- for (const [pattern, owner] of MODEL_OWNER_RULES) {
84
- if (pattern.test(id)) return owner
145
+ for (const providerId of PROVIDER_ORDER) {
146
+ if (PROVIDERS[providerId].prefixes.some((pattern) => pattern.test(id))) return providerId
85
147
  }
86
148
  return null
87
149
  }
88
150
 
89
- /** #44/#45:已配置 provider 的默认模型——明细表在本月无真实消耗行时补一行(数值 0),保证"配置即可见"。
90
- * OpenRouter 为中转无默认模型:值为 '-' 表示占位行(OpenRouter / -),该 provider 出现任何真实模型行后不再补。 */
91
- export const DEFAULT_MODELS = {
92
- 'deepseek-official': 'deepseek-v4.1-flash',
93
- zhipu: 'glm-5.3',
94
- moonshot: 'kimi-k3',
95
- qwen: 'qwen3.8-max',
96
- openrouter: '-',
97
- }
98
-
99
151
  export function modelLabel(raw) {
100
152
  const id = normalizeModel(raw)
101
- const labels = {
102
- 'deepseek-flash': 'DeepSeek-V4.1-Flash',
103
- 'deepseek-v4.1-flash': 'DeepSeek-V4.1-Flash',
104
- 'deepseek-v4-flash': 'DeepSeek-V4.1-Flash',
105
- 'deepseek-pro': 'DeepSeek-V4.1-Pro',
106
- 'deepseek-v4-pro': 'DeepSeek-V4.1-Pro',
107
- 'glm-5.3': 'GLM-5.3',
108
- 'glm-5.3-flash': 'GLM-5.3-Flash',
109
- 'kimi-k3': 'Kimi K3',
110
- 'kimi-k3.1-pro': 'Kimi K3.1 Pro',
111
- 'kimi-k2.7-code': 'Kimi K2.7 Code',
112
- 'qwen3.8-max': 'Qwen3.8-Max',
113
- 'qwen3.8-flash': 'Qwen3.8-Flash',
153
+ for (const providerId of PROVIDER_ORDER) {
154
+ const label = PROVIDERS[providerId].modelLabels[id]
155
+ if (label !== undefined) return label
114
156
  }
115
- return labels[id] ?? id
157
+ return id
158
+ }
159
+
160
+ /** Five official pricing pages, in display order; UI consumes this via the VM. */
161
+ export function pricingLinks() {
162
+ return PROVIDER_ORDER
163
+ .map((id) => ({ id, label: PROVIDERS[id].label, url: PROVIDERS[id].pricingUrl }))
164
+ .filter((link) => typeof link.url === 'string' && link.url !== '')
116
165
  }
117
166
 
118
167
  /** Only folds casing/provider prefix/date suffixes; never merges generations. */
package/src/version.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Version ordering for the update check.
3
+ *
4
+ * Local builds are published as `X.Y.Z-local.N`; that is a prerelease of the same
5
+ * X.Y.Z, so `1.0.7-local.1 < 1.0.7` and local numbers grow numerically.
6
+ */
7
+
8
+ function parseVersion(value) {
9
+ const text = String(value ?? '')
10
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-local\.(\d+))?$/.exec(text)
11
+ if (match === null) {
12
+ const parts = text.split('.').map((part) => Number.parseInt(part, 10) || 0)
13
+ return { base: [parts[0] ?? 0, parts[1] ?? 0, parts[2] ?? 0], local: null }
14
+ }
15
+ return {
16
+ base: [Number(match[1]), Number(match[2]), Number(match[3])],
17
+ local: match[4] === undefined ? null : Number(match[4]),
18
+ }
19
+ }
20
+
21
+ /** -1 / 0 / 1 for left older than / equal to / newer than right. */
22
+ export function compareVersions(left, right) {
23
+ const a = parseVersion(left)
24
+ const b = parseVersion(right)
25
+ for (let index = 0; index < 3; index += 1) {
26
+ if (a.base[index] !== b.base[index]) return a.base[index] > b.base[index] ? 1 : -1
27
+ }
28
+ if (a.local === null && b.local === null) return 0
29
+ if (a.local === null) return 1
30
+ if (b.local === null) return -1
31
+ return a.local === b.local ? 0 : a.local > b.local ? 1 : -1
32
+ }
33
+
34
+ /** True when `latest` is strictly newer than `current`. */
35
+ export function isNewer(latest, current) {
36
+ return compareVersions(latest, current) > 0
37
+ }