dsh-token-dash 1.0.5 → 1.0.6

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
@@ -68,8 +68,9 @@ npm pack --dry-run
68
68
  ## 发布
69
69
 
70
70
  - AI 只准备到“可发布”,不执行 `npm publish`、不推 tag;发布由用户明确授权。
71
+ - **本地打包必须由用户显式指令触发**(`本地打包` / `本地版本` / `候选包`)。完成 issue、修复、测试或提交后,不得自动改版本号、写 CHANGELOG local 块、`npm run pack` 或安装本地包。本地构建记录写 CHANGELOG 顶部 `-local.N` 块(中间产物);正式发布时合并进正式块并删除,最终历史不保留 local 块。
71
72
  - npm 包只含 `lib` / `cordis.patch.yml` / `locale` / `README.md` / `LICENSE`。
72
- - 发布流程见 `docs/release.md`;历史发布 checklist 见 `docs/checklist/archived/dsh/token-dash-release-checklist.md`。
73
+ - 发布流程见 `docs/release.md` 与 `.agents/skills/dsh-token-dash-release/SKILL.md`;历史发布 checklist 见 `docs/checklist/archived/dsh/token-dash-release-checklist.md`。
73
74
 
74
75
  ## 安全
75
76
 
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
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,14 +11,6 @@ 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
14
  const COLORS = { 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)
@@ -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) {
@@ -352,16 +344,16 @@ window.__ModuleLoader__.load({
352
344
  }
353
345
 
354
346
  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)
347
+ const windows = Array.isArray(provider.windows) ? provider.windows : []
348
+ const resets = windows.map((plan) => plan.resetAt).filter((ts) => Number.isFinite(ts) && ts > 0)
357
349
  const nextReset = resets.length > 0 ? Math.min(...resets) : null
358
350
  return h('div', { 'data-testid': `token-dash-sub-card-${provider.id}`, style: { ...styles.card, marginTop: 0 } },
359
351
  h('div', { style: styles.row }, h('b', { style: styles.nameEllipsis, title: provider.name }, provider.name), h('span', { style: styles.muted }, '订阅')),
360
- plans.length === 0
352
+ windows.length === 0
361
353
  ? h('div', { style: { ...styles.muted, marginTop: 6 } }, '套餐查询失败')
362
354
  : h(React.Fragment, null,
363
355
  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 },
356
+ windows.map((plan) => h('div', { key: plan.key, style: styles.bar },
365
357
  h('div', { style: { ...styles.barFill, width: `${Math.min(100, plan.usedPercent ?? 0)}%` } }))),
366
358
  nextReset !== null ? h('div', { style: { ...styles.muted, marginTop: 2 } }, `重置 ${fmtReset(nextReset)}`) : null))
367
359
  }
@@ -713,7 +705,7 @@ window.__ModuleLoader__.load({
713
705
  h('div', { style: styles.row },
714
706
  h('span', null, '查看价格明细'),
715
707
  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)))),
708
+ (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
709
  h('div', { style: styles.row },
718
710
  h('span', { style: styles.muted }, `版本 ${version}`),
719
711
  updateControl))),
Binary file
Binary file
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.6",
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. */