dsh-cost-meter 1.8.31 → 1.8.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/README.zh-CN.md +14 -8
- package/docs/model-history-repricing.md +33 -0
- package/docs/provider-pricing-2026-10.md +1 -1
- package/docs/tokenrhythm-balance.md +38 -0
- package/docs/update-notes-1.8.32.md +21 -0
- package/docs/update-notes-1.8.33.md +19 -0
- package/lib/backfill.js +12 -7
- package/lib/billing-history.js +18 -8
- package/lib/client.js +5 -5
- package/lib/client.pricing.js +3 -3
- package/lib/custom-balance.js +3 -0
- package/lib/index.js +33 -8
- package/lib/pricing.js +43 -16
- package/lib/store.js +6 -6
- package/lib/tokenrhythm-balance.js +95 -0
- package/lib/typert.host.js +6 -3
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ Community and feedback: [Join the WeChat group →](#community). The WeChat grou
|
|
|
10
10
|
|
|
11
11
|
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 / Factory Droid) 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)
|
|
12
12
|
|
|
13
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
14
14
|
|
|
15
|
-
**v1.8.
|
|
15
|
+
**v1.8.33** fixes V4 Pro pricing and adds [historical recalculation for one channel/model](docs/model-history-repricing.md#english), preserving other models and original exchange rates.
|
|
16
16
|
|
|
17
17
|
Desktop users: follow the [Desktop installation instructions](docs/install-troubleshooting.md#desktop-安装与更新) for the application's own CLI and `desktop` Profile.
|
|
18
18
|
|
|
19
|
-
Release notes: [
|
|
19
|
+
Release notes: [Pro pricing and model history — v1.8.33](docs/update-notes-1.8.33.md#english). Fully restart DSH after updating.
|
|
20
20
|
|
|
21
21
|
If startup reports **Ledger is busy** and the cost widgets are missing, see [ledger lock recovery](docs/ledger-lock-recovery.md#english).
|
|
22
22
|
|
|
@@ -327,22 +327,22 @@ On Node.js 20, use `npm install -g pnpm@10` instead. See [pnpm installation and
|
|
|
327
327
|
dsh plugin --profile web add dsh-cost-meter
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
**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.
|
|
330
|
+
**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.33`** — review the script before running):
|
|
331
331
|
|
|
332
332
|
```powershell
|
|
333
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
333
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.33/install.ps1 | iex
|
|
334
334
|
```
|
|
335
335
|
|
|
336
336
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
337
337
|
|
|
338
338
|
```sh
|
|
339
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
339
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.33
|
|
340
340
|
```
|
|
341
341
|
|
|
342
342
|
Without git, use the GitHub tag archive:
|
|
343
343
|
|
|
344
344
|
```sh
|
|
345
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
345
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.33.tar.gz
|
|
346
346
|
```
|
|
347
347
|
|
|
348
348
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
|
@@ -528,7 +528,13 @@ A per-version overview and the community-issue resolution log live in [docs/UPDA
|
|
|
528
528
|
|
|
529
529
|
## Star History
|
|
530
530
|
|
|
531
|
-
|
|
531
|
+
<a href="https://www.star-history.com/?repos=han-1413141%2Fdsh-cost-meter&type=timeline&legend=bottom-right">
|
|
532
|
+
<picture>
|
|
533
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=han-1413141/dsh-cost-meter&type=timeline&theme=dark&legend=bottom-right" />
|
|
534
|
+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=han-1413141/dsh-cost-meter&type=timeline&legend=bottom-right" />
|
|
535
|
+
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=han-1413141/dsh-cost-meter&type=timeline&legend=bottom-right" />
|
|
536
|
+
</picture>
|
|
537
|
+
</a>
|
|
532
538
|
|
|
533
539
|
## License
|
|
534
540
|
|
package/README.zh-CN.md
CHANGED
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
|
|
11
11
|
本会话费用 · 当日费用 · 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 用量一条横排显示,可开关)
|
|
12
12
|
|
|
13
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
14
14
|
|
|
15
|
-
**v1.8.
|
|
15
|
+
**v1.8.33** 修正 V4 Pro 单价,并新增[单模型历史重算](docs/model-history-repricing.md#中文),按渠道+模型修正旧费用,保留其他模型与原调用汇率。
|
|
16
16
|
|
|
17
17
|
桌面端用户请按 [Desktop 安装说明](docs/install-troubleshooting.md#desktop-安装与更新),使用应用自带的 CLI 和 `desktop` Profile。
|
|
18
18
|
|
|
19
|
-
更新说明:[v1.8.
|
|
19
|
+
更新说明:[v1.8.33 Pro 价格与单模型历史重算](docs/update-notes-1.8.33.md#中文)。更新后完全重启 DSH。
|
|
20
20
|
|
|
21
21
|
启动报 **Ledger is busy** 且费用卡片消失时,参见[账本锁恢复说明](docs/ledger-lock-recovery.md#简体中文)。
|
|
22
22
|
|
|
@@ -327,22 +327,22 @@ Node.js 20 请改用 `npm install -g pnpm@10`。版本要求见 [pnpm 官方安
|
|
|
327
327
|
dsh plugin --profile web add dsh-cost-meter
|
|
328
328
|
```
|
|
329
329
|
|
|
330
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.
|
|
330
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.33`**,建议先下载审阅再运行):
|
|
331
331
|
|
|
332
332
|
```powershell
|
|
333
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
333
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.33/install.ps1 | iex
|
|
334
334
|
```
|
|
335
335
|
|
|
336
336
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
337
337
|
|
|
338
338
|
```sh
|
|
339
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
339
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.33
|
|
340
340
|
```
|
|
341
341
|
|
|
342
342
|
没有 git 时可用 GitHub tag 打包直链:
|
|
343
343
|
|
|
344
344
|
```sh
|
|
345
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
345
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.33.tar.gz
|
|
346
346
|
```
|
|
347
347
|
|
|
348
348
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
|
@@ -532,7 +532,13 @@ dsh --profile web --port 3099 # 真机启动(观察启
|
|
|
532
532
|
|
|
533
533
|
## Star 增长记录
|
|
534
534
|
|
|
535
|
-
|
|
535
|
+
<a href="https://www.star-history.com/?repos=han-1413141%2Fdsh-cost-meter&type=timeline&legend=bottom-right">
|
|
536
|
+
<picture>
|
|
537
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=han-1413141/dsh-cost-meter&type=timeline&theme=dark&legend=bottom-right" />
|
|
538
|
+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=han-1413141/dsh-cost-meter&type=timeline&legend=bottom-right" />
|
|
539
|
+
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=han-1413141/dsh-cost-meter&type=timeline&legend=bottom-right" />
|
|
540
|
+
</picture>
|
|
541
|
+
</a>
|
|
536
542
|
|
|
537
543
|
## License
|
|
538
544
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# 按模型重算历史费用
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
在 **费用 → 价格 → 同步与规则 → 历史费用** 中设置“重算范围”。选择框支持搜索历史渠道或模型名。
|
|
6
|
+
|
|
7
|
+
1. 先在“模型定价”或“参考价格表”保存正确的单价和倍率。
|
|
8
|
+
2. 回到“同步与规则”,选择具体的 **渠道+模型**,例如 `deepseek-official:deepseek-v4-pro`。
|
|
9
|
+
3. 点击“重算此模型的历史费用”,核对确认框中的范围,再点击“确认重算”。
|
|
10
|
+
|
|
11
|
+
只更新选中渠道模型在保留历史中的费用;同名模型的其他渠道、同一渠道的其他模型和 Token 数不变。单模型重算使用当前单价与倍率,保留每次调用原有的汇率、调用时间对应的峰谷和上下文档位。只扫描涉及该模型的会话,沿用现有日志完整性检查:日志缺失、Token 或调用数对不上的会话日期记录不改。
|
|
12
|
+
|
|
13
|
+
重算前会在账本旁保存 `ledger.json.before-reprice-时间戳.json`。原金额、价格版本与重算记录继续保留;记录中显示具体渠道模型及该范围的重算前后金额。重启后,统计与明细按对应模型的重算版本读取,其他模型沿用原版本。
|
|
14
|
+
|
|
15
|
+
“全部模型”保留原有全量重算功能。修改重算范围本身不保存价格配置,也不会启动重算。升级修正内置价目不会自动重算已有费用。
|
|
16
|
+
|
|
17
|
+
### #292 的修复
|
|
18
|
+
|
|
19
|
+
v1.8.33 删除了错误的“V4 Pro 自 9 月 14 日按 Flash 价计费”规则。当前 [DeepSeek 官方中文价目页](https://api-docs.deepseek.com/zh-cn/quick_start/pricing/)中,每百万 Token 的 Pro 谷价为缓存命中 ¥0.15、未命中 ¥4.5、输出 ¥13.5,峰价分别为 ¥0.30、¥9、¥27;Flash 谷价仍为 ¥0.02、¥1、¥4,峰价为两倍。
|
|
20
|
+
|
|
21
|
+
更新后会修正可识别的旧内置错误模板,保留手动单价、倍率、其他厂商价格、原历史金额与汇率。官方同步按页面实际价格更新,并同时更新 `deepseek-v4-flash`、`deepseek-v4-flash-vision-exp` 旧名称。需要修正旧账时,按上方步骤选择实际使用的渠道+Pro 模型,不要删除账本的迁移标记。
|
|
22
|
+
|
|
23
|
+
感谢 [ztszzz733](https://github.com/ztszzz733) 在 [#292](https://github.com/Han-1413141/dsh-cost-meter/issues/292) 提供问题定位、官方价格对照及用量比较;单模型重算由本项目维护者提出。
|
|
24
|
+
|
|
25
|
+
## English
|
|
26
|
+
|
|
27
|
+
Open **Cost → Pricing → Sync & rules → Historical pricing**. Save the correct rates and multipliers first, then search for and select one **channel/model** under “Recalculation scope”. Click “Recalculate this model” and confirm the displayed scope.
|
|
28
|
+
|
|
29
|
+
Only that channel/model's retained historical costs change. Other channels using the same model, other models, and Token counts remain unchanged. Model-specific recalculation uses current rates and multipliers while retaining each call's original exchange rates and time/context tiers. Only relevant sessions are scanned. Incomplete or mismatching logs remain unchanged.
|
|
30
|
+
|
|
31
|
+
A full ledger backup is created before recalculation. Original amounts and price versions are retained. History records show the chosen scope and its before/after amounts; replay after restart keeps each model's own revision. “All models” retains the existing full recalculation action. Selecting a scope alone has no side effects.
|
|
32
|
+
|
|
33
|
+
v1.8.33 also fixes [#292](https://github.com/Han-1413141/dsh-cost-meter/issues/292): V4 Pro keeps its separate official price, and legacy Flash names are updated during official synchronization. Recognizable incorrect built-in templates are corrected for future calls without automatically rewriting historical amounts. Thanks to [ztszzz733](https://github.com/ztszzz733) for the report, diagnosis and official-price comparison.
|
|
@@ -21,7 +21,7 @@ Haiku 5.5 按 100,000 输入 Token 分档,缓存读取和写入也计入阈值
|
|
|
21
21
|
- 缺失渠道的旧宿主兼容推断只保留旧 Go 模型集合,并且要求该模型仍在 Go 渠道表中。新增目录条目不会仅因同名就把 API 消费变成订阅
|
|
22
22
|
- `openrouter` 使用完整模型 ID 精确匹配。`:free` / `:online` 等变体、其他路由及本地模型不会借用其价格
|
|
23
23
|
|
|
24
|
-
例如 Gemini 3.8 Flash 的直接 Google 促销价是输入 $0.75 / 输出 $3.75,Zen 是 $1.50 / $7.50,每百万 token。Zen 的 DeepSeek Pro 为固定 $1.74 / $3.48;Go 的 Pro
|
|
24
|
+
例如 Gemini 3.8 Flash 的直接 Google 促销价是输入 $0.75 / 输出 $3.75,Zen 是 $1.50 / $7.50,每百万 token。Zen 的 DeepSeek Pro 为固定 $1.74 / $3.48;Go 的 Pro 为自己的峰谷参考价;均不能与直接 DeepSeek 的独立 Pro / Flash 官方价格混用。
|
|
25
25
|
|
|
26
26
|
自动匹配允许唯一的大小写、标点和日期装饰别名,以及与实际厂商一致的已知前缀,如 `openai/gpt-6.1-sol`、`anthropic/claude-opus-5.5`。不同版本、未知变体、多个候选或错误厂商前缀保持未定价。`exact` 模式要求价格表中存储的完整 ID。
|
|
27
27
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Token Rhythm 余额
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
在 **费用 → 额度 → 添加 Token Rhythm 余额** 中展开卡片,保存网站登录 Cookie,再启用卡片。余额可显示在侧栏、设置页或两处,默认每 15 分钟刷新,也可以手动刷新。
|
|
6
|
+
|
|
7
|
+
获取 Cookie:
|
|
8
|
+
|
|
9
|
+
1. 在浏览器登录 [Token Rhythm 账户页](https://tokenrhythm.studio/account)。
|
|
10
|
+
2. 打开开发者工具,在“应用 / 存储 → Cookie”中找到 `tr_session`,复制它的值;也可以在“网络”中查看账户请求,复制请求头中的 `Cookie`。
|
|
11
|
+
3. 填入插件的 **Token Rhythm Cookie** 输入框并保存。支持裸 `tr_session` 值、`tr_session=值` 或完整 Cookie 请求头;查询时只发送 `tr_session`。
|
|
12
|
+
|
|
13
|
+
Cookie 保存在 DSH 凭据库,不写入费用配置或账本,也不会回显。已有环境变量 `TOKENRHYTHM_COOKIE` 时可直接使用。出现登录失效提示后,重新登录官网并替换 Cookie。此处使用网站登录凭据,不使用模型 API Key。
|
|
14
|
+
|
|
15
|
+
显示值与当前官网账户页一致:读取 `GET https://tokenrhythm.studio/api/wallet/summary` 的 `availableBalanceCny`,按人民币显示。冻结金额、累计获赠和历史消费不计入可用余额;接口缺少有效金额时显示错误,真正的零余额正常显示。接口没有预算上限,因此不据此生成使用百分比。
|
|
16
|
+
|
|
17
|
+
沿用现有余额缓存、并行请求合并和取消机制。反复打开设置不会重查未过期的余额;改换或清除凭据后,旧结果立即失效。该功能仅查询余额,不发起模型调用。
|
|
18
|
+
|
|
19
|
+
### 来源与验证
|
|
20
|
+
|
|
21
|
+
- [ykoneee 的 issue #290](https://github.com/Han-1413141/dsh-cost-meter/issues/290) 提出余额显示需求,并提供参考插件。
|
|
22
|
+
- [162568316/dsh-tokenrhythm-bill](https://github.com/162568316/dsh-tokenrhythm-bill/tree/d6ee046d083571810fa8fc12030f67b4132841ec) 提供 `tr_session` 认证方式及字段参考;本插件使用现有余额适配器框架独立实现。
|
|
23
|
+
- 2026-10-16 核对官网账户页前端版本 `037ffef75d824b1638e65b609018b5054e368f71`,确认账户页已使用 `/wallet/summary` 的 `availableBalanceCny`,因此不再沿用参考插件的旧 `/usage-summary` 查询。
|
|
24
|
+
- 官方端点无凭据请求返回 HTTP 401;金额、鉴权、取消、缓存、凭据与设置交互使用模拟响应验证,未查询真实账户。
|
|
25
|
+
|
|
26
|
+
## English
|
|
27
|
+
|
|
28
|
+
Open **Cost → Quotas → Add Token Rhythm balance**, expand the card, save your website session cookie and enable the card. Choose the sidebar, settings or both. The default refresh interval is 15 minutes; manual refresh is available.
|
|
29
|
+
|
|
30
|
+
Sign in at the [official account page](https://tokenrhythm.studio/account). In browser DevTools, copy `tr_session` from Application / Storage → Cookies, or copy the account request's Cookie header from Network. Paste the raw session value, `tr_session=value`, or the full Cookie header into **Token Rhythm Cookie**. Only `tr_session` is sent upstream.
|
|
31
|
+
|
|
32
|
+
Credentials use the DSH credential store and are never returned to the UI or written to the ledger/configuration. `TOKENRHYTHM_COOKIE` is also supported as an environment fallback. Replace an expired cookie after signing in again. A model API key cannot replace the website session cookie.
|
|
33
|
+
|
|
34
|
+
The integration reads `availableBalanceCny` from `GET https://tokenrhythm.studio/api/wallet/summary`, matching the current account page's available CNY balance. Frozen funds, lifetime gifts and historical spend are separate. Missing amounts produce an error; valid zero balances remain zero. No usage percentage is invented without a budget limit.
|
|
35
|
+
|
|
36
|
+
Existing balance caching, request sharing and cancellation are reused. Reopening settings reuses a fresh result. Changing or clearing the credential invalidates the old result. No model calls are made.
|
|
37
|
+
|
|
38
|
+
Thanks to [ykoneee](https://github.com/ykoneee) for [the request and reference](https://github.com/Han-1413141/dsh-cost-meter/issues/290), and [162568316](https://github.com/162568316/dsh-tokenrhythm-bill/tree/d6ee046d083571810fa8fc12030f67b4132841ec) for the authentication/field reference. The current endpoint and available-balance field were checked against the official frontend on 2026-10-16. Automated checks use synthetic responses; no authenticated live account was tested.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# v1.8.32
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
新增 Token Rhythm 人民币可用余额显示。在“费用 → 额度”点击“添加 Token Rhythm 余额”,保存网站登录 Cookie 后启用,便可在侧栏和设置页查看。沿用 DSH 的额度卡片和凭据输入方式,可选择显示位置与刷新间隔。
|
|
6
|
+
|
|
7
|
+
查询使用当前官网账户页的钱包接口,显示 `availableBalanceCny`,避免把冻结金额或历史消费当作可用余额。未过期的结果直接复用;修改、清除凭据后旧余额作废。缺少有效金额或登录失效时给出明确提示。
|
|
8
|
+
|
|
9
|
+
感谢 [ykoneee](https://github.com/ykoneee) 提出 [#290](https://github.com/Han-1413141/dsh-cost-meter/issues/290) 并提供参考,感谢 [162568316 的开源插件](https://github.com/162568316/dsh-tokenrhythm-bill) 提供认证与字段参考。
|
|
10
|
+
|
|
11
|
+
[设置方法与验证范围](tokenrhythm-balance.md#中文)。更新后完全重启 DSH。
|
|
12
|
+
|
|
13
|
+
## English
|
|
14
|
+
|
|
15
|
+
Token Rhythm available CNY balance is now supported. Under Cost → Quotas, add a Token Rhythm balance card, save the website session cookie and enable the card. Display placement and refresh interval reuse the existing DSH quota UI.
|
|
16
|
+
|
|
17
|
+
The integration uses the current official wallet endpoint and `availableBalanceCny`, keeping frozen funds and historical spend separate. Fresh results are cached; changing or clearing credentials invalidates old results. Missing amounts and expired sessions produce clear errors.
|
|
18
|
+
|
|
19
|
+
Thanks to [ykoneee](https://github.com/ykoneee) for [issue #290 and the reference](https://github.com/Han-1413141/dsh-cost-meter/issues/290), and [162568316](https://github.com/162568316/dsh-tokenrhythm-bill) for the authentication and field reference.
|
|
20
|
+
|
|
21
|
+
See [setup and validation details](tokenrhythm-balance.md#english). Fully restart DSH after upgrading.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# v1.8.33
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
修复 [#292](https://github.com/Han-1413141/dsh-cost-meter/issues/292):V4 Pro 错误套用 Flash 单价,导致费用低估。恢复 Pro 的独立人民币和美元峰谷价格,旧版本中可识别的错误内置模板会更新,手动单价、倍率与其他厂商价格保留。
|
|
6
|
+
|
|
7
|
+
官方价格同步直接采用页面解析结果,内置调价规则不再覆盖官方报价;同时更新旧 Flash 名称。中英文官方文档使用带尾斜线的价格页地址,避免英文地址返回 API 入门页面。
|
|
8
|
+
|
|
9
|
+
新增单模型历史重算。在“费用 → 价格 → 同步与规则 → 历史费用”搜索并选择渠道+模型,确认后只修改该模型的历史费用。保留原调用汇率与其他模型的金额,日志覆盖不完整的记录不改。重算前自动备份,重算记录标明范围;重启后的明细继续沿用各模型自己的价格版本。
|
|
10
|
+
|
|
11
|
+
感谢 [ztszzz733](https://github.com/ztszzz733) 提供问题定位和官方价目对照。[设置与历史修正方法](model-history-repricing.md#中文)。升级后完全重启 DSH。
|
|
12
|
+
|
|
13
|
+
## English
|
|
14
|
+
|
|
15
|
+
Fixes V4 Pro being charged at Flash rates in the built-in catalog. Pro now retains its separate official CNY/USD peak and off-peak prices. Recognizable incorrect defaults are upgraded while preserving manual rates, multipliers and third-party catalogs. Official synchronization respects parsed prices and updates legacy Flash names.
|
|
16
|
+
|
|
17
|
+
Adds channel/model-specific historical recalculation under Pricing → Sync & rules. Only the selected model changes, with original exchange rates retained. Other model amounts and incomplete records remain unchanged. Backups, scoped before/after records and restart-safe price revisions are retained.
|
|
18
|
+
|
|
19
|
+
Thanks to [ztszzz733](https://github.com/ztszzz733) for [#292, diagnosis and price comparisons](https://github.com/Han-1413141/dsh-cost-meter/issues/292). See [usage details](model-history-repricing.md#english). Fully restart DSH after upgrading.
|
package/lib/backfill.js
CHANGED
|
@@ -551,7 +551,7 @@ export function replaySessionRecords(records, config, wantDates = null, collectS
|
|
|
551
551
|
// 按事件时刻计费(历史正确):峰谷时代前用 legacyBase,之后按峰谷两档。
|
|
552
552
|
// 计价/归类/归因一律用改挂后的 effectiveProvider(包装层转发对挂语义上游)。
|
|
553
553
|
const pricedAtMs = !isCompaction && !metered ? stepStarts.get(`${turn}:${step}`) ?? atMs : atMs
|
|
554
|
-
const pricing = pricingConfigAt(config, pricedAtMs, sessionId)
|
|
554
|
+
const pricing = pricingConfigAt(config, pricedAtMs, sessionId, `${effectiveProvider}:${sampleModel}`)
|
|
555
555
|
const resolved = providerPriceEntryFor(effectiveProvider, sampleModel, pricing?.prices, {
|
|
556
556
|
mode: pricing?.priceMatch === 'exact' ? 'exact' : 'auto',
|
|
557
557
|
overrides: pricing?.priceOverrides,
|
|
@@ -989,9 +989,10 @@ export async function importLegacyHistory(ledger, sessionsRoot) {
|
|
|
989
989
|
* @param includeBucket - 可选的 (providerModelKey, date) 过滤器,仅修复目标价格路径。
|
|
990
990
|
* @returns {{ scanned, recostedSessions, skippedSessions, recostedDays }}。
|
|
991
991
|
*/
|
|
992
|
-
export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeBucket, onlySessionIds = null, explicit = false) {
|
|
992
|
+
export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeBucket, onlySessionIds = null, explicit = false, model = '') {
|
|
993
993
|
const result = { scanned: 0, recostedSessions: 0, skippedSessions: 0, recostedDays: 0 }
|
|
994
994
|
const pricingConfig = explicit ? currentPricingConfig(ledger.config) : ledger.config
|
|
995
|
+
if (explicit && model) pricingConfig._repriceFxConfig = ledger.config
|
|
995
996
|
const originalPricing = explicit ? JSON.stringify(pricingSnapshot(ledger.config)) : null
|
|
996
997
|
const originalHistory = explicit ? pricingHistoryFingerprint(ledger.config) : null
|
|
997
998
|
const reset = JSON.stringify(ledger.historyReset ?? null)
|
|
@@ -1020,7 +1021,9 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1020
1021
|
|| JSON.stringify(pricingSnapshot(ledger.config)) !== originalPricing || pricingHistoryFingerprint(ledger.config) !== originalHistory)) {
|
|
1021
1022
|
throw new Error('价格或历史记录已在读取期间改变,本次未重算。请重新确认。')
|
|
1022
1023
|
}
|
|
1023
|
-
|
|
1024
|
+
const amount = day => model ? Number(day.byProviderModel?.[model]?.cost) || 0 : day.cost
|
|
1025
|
+
if (explicit) result.before = Object.values(ledger.days).reduce((sum, day) => sum + amount(day), 0)
|
|
1026
|
+
if (explicit && model) for (const [unit, field] of [['Cny', 'costCny'], ['Eur', 'costEur']]) result['before' + unit] = Object.values(ledger.days).reduce((sum, day) => sum + (Number(day.byProviderModel?.[model]?.[field]) || 0), 0)
|
|
1024
1027
|
const tokenFields = ['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning', 'calls']
|
|
1025
1028
|
for (const [sessionId, days] of bySession) {
|
|
1026
1029
|
for (const [date, pm] of Object.entries(days)) {
|
|
@@ -1028,6 +1031,7 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1028
1031
|
const row = day === undefined ? undefined : (Array.isArray(day.sessions) ? day.sessions : []).find(s => s?.id === sessionId)
|
|
1029
1032
|
if (row === undefined) continue // 账本无此会话行:不新增(与实时计费互斥)。
|
|
1030
1033
|
const oldPm = row.byProviderModel !== null && typeof row.byProviderModel === 'object' ? row.byProviderModel : {}
|
|
1034
|
+
if (model && !Object.hasOwn(oldPm, model)) continue
|
|
1031
1035
|
const newKeys = Object.keys(pm)
|
|
1032
1036
|
const dayPm = day.byProviderModel !== null && typeof day.byProviderModel === 'object' ? day.byProviderModel : {}
|
|
1033
1037
|
// 前置校验(全部通过才动账):键集合一致、逐键 token/calls 相等、日期聚合
|
|
@@ -1047,7 +1051,7 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1047
1051
|
result.skippedSessions += 1
|
|
1048
1052
|
continue
|
|
1049
1053
|
}
|
|
1050
|
-
const selected =
|
|
1054
|
+
const selected = newKeys.filter(key => (!model || key === model) && (!includeBucket || includeBucket(key, date)))
|
|
1051
1055
|
if (selected.length === 0) continue
|
|
1052
1056
|
// 只替换已验证的桶并逐差额调整容器;保留未选中模型和无明细残差。
|
|
1053
1057
|
row.byProviderModel = cloneDayMap(oldPm)
|
|
@@ -1071,14 +1075,15 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1071
1075
|
}
|
|
1072
1076
|
result.recostedSessions += 1
|
|
1073
1077
|
touchedDates.add(date)
|
|
1074
|
-
if (explicit && ledger.pricingHistory) recordPricingRevision(ledger.pricingHistory, pricingConfig, sessionId, date, startedAt, previousAmount, { cost: row.cost, apiCost: row.apiCost })
|
|
1078
|
+
if (explicit && ledger.pricingHistory) recordPricingRevision(ledger.pricingHistory, pricingConfig, sessionId, date, startedAt, previousAmount, { cost: row.cost, apiCost: row.apiCost }, model)
|
|
1075
1079
|
}
|
|
1076
1080
|
}
|
|
1077
1081
|
result.recostedDays = touchedDates.size
|
|
1078
1082
|
if (explicit) {
|
|
1079
|
-
result.after = Object.values(ledger.days).reduce((sum, day) => sum + day
|
|
1083
|
+
result.after = Object.values(ledger.days).reduce((sum, day) => sum + amount(day), 0)
|
|
1084
|
+
if (model) for (const [unit, field] of [['Cny', 'costCny'], ['Eur', 'costEur']]) result['after' + unit] = Object.values(ledger.days).reduce((sum, day) => sum + (Number(day.byProviderModel?.[model]?.[field]) || 0), 0)
|
|
1080
1085
|
for (const [date, day] of Object.entries(ledger.days)) for (const row of day.sessions ?? []) {
|
|
1081
|
-
if (!bySession.get(row.id)?.[date]) result.skippedSessions++
|
|
1086
|
+
if ((!model || Object.hasOwn(row.byProviderModel ?? {}, model)) && !bySession.get(row.id)?.[date]) result.skippedSessions++
|
|
1082
1087
|
}
|
|
1083
1088
|
}
|
|
1084
1089
|
return result
|
package/lib/billing-history.js
CHANGED
|
@@ -21,7 +21,7 @@ function indexOf(history) {
|
|
|
21
21
|
if (index) return index
|
|
22
22
|
const revisions = new Map()
|
|
23
23
|
for (const row of Object.values(history.revisions)) {
|
|
24
|
-
const key = JSON.stringify([row.sessionId, row.date]), previous = revisions.get(key)
|
|
24
|
+
const key = JSON.stringify([row.sessionId, row.date, row.model ?? '']), previous = revisions.get(key)
|
|
25
25
|
if (!previous || compare(row, previous) >= 0) revisions.set(key, row)
|
|
26
26
|
}
|
|
27
27
|
index = { changes: Object.values(history.changes).sort(compare), revisions, fingerprint: hash([history.changes, history.revisions, history.fxChanges]), fx: Object.values(history.fxChanges ?? {}).sort((a, b) => a.at - b.at || (a.sequence ?? 0) - (b.sequence ?? 0)) }
|
|
@@ -53,9 +53,10 @@ export function normalizePricingHistory(raw, config) {
|
|
|
53
53
|
const changes = Object.fromEntries(Object.entries(raw.changes).filter(([id, row]) => safe(id) && Number.isFinite(row?.at) && row.at >= 0 && versions[row.version]))
|
|
54
54
|
if (!Object.values(changes).some(row => row.at === 0)) return createPricingHistory(config)
|
|
55
55
|
const revisions = Object.fromEntries(Object.entries(raw.revisions ?? {}).filter(([id, row]) => safe(id) && typeof row?.sessionId === 'string'
|
|
56
|
+
&& (row.model === undefined || (typeof row.model === 'string' && row.model.includes(':') && row.model.length <= 2048))
|
|
56
57
|
&& /^\d{4}-\d{2}-\d{2}$/.test(row.date) && Number.isFinite(row.at) && versions[row.version]))
|
|
57
58
|
const runs = Object.fromEntries(Object.entries(object(raw.runs) ? raw.runs : {}).filter(([id, row]) => safe(id) && runFields.every(key => Number.isFinite(row?.[key]) && row[key] >= 0))
|
|
58
|
-
.map(([id, row]) => [id, Object.fromEntries(runFields.map(key => [key, row[key]]))]))
|
|
59
|
+
.map(([id, row]) => [id, { ...Object.fromEntries([...runFields, ...['beforeCny', 'afterCny', 'beforeEur', 'afterEur'].filter(key => Number.isFinite(row[key]) && row[key] >= 0)].map(key => [key, row[key]])), ...(typeof row.model === 'string' ? { model: row.model } : {}) }]))
|
|
59
60
|
const fxChanges = Object.fromEntries(Object.entries(raw.fxChanges ?? {}).filter(([id, row]) => safe(id) && Number.isFinite(row?.at) && row.at >= 0 && ['CNY', 'EUR'].every(key => Number.isFinite(row.rates?.[key]) && row.rates[key] > 0)))
|
|
60
61
|
if (!Object.keys(fxChanges).length) for (const [id, row] of Object.entries(changes)) fxChanges[id] = { at: row.at, sequence: row.sequence ?? 0, rates: fxRatesOf({ ...versions[row.version], currency: config.currency }) }
|
|
61
62
|
return { versions, changes, revisions, runs, fxChanges }
|
|
@@ -87,7 +88,13 @@ export function bindPricingHistory(config, history) {
|
|
|
87
88
|
export function pricingHistoryOf(config) { return bindings.get(config) }
|
|
88
89
|
|
|
89
90
|
/** Classification stays editable; monetary rates come from the call's price version. */
|
|
90
|
-
export function pricingConfigAt(config, at, sessionId = '') {
|
|
91
|
+
export function pricingConfigAt(config, at, sessionId = '', model = '') {
|
|
92
|
+
// 单模型重算沿用每次调用原有汇率;当前价格表不绑定原历史版本。
|
|
93
|
+
if (config?._repriceFxConfig) {
|
|
94
|
+
const original = pricingConfigAt(config._repriceFxConfig, at, sessionId, model)
|
|
95
|
+
const rates = fxRatesOf(original)
|
|
96
|
+
return { ...config, fxRates: rates, exchangeRate: rates[config.currency] ?? config.exchangeRate }
|
|
97
|
+
}
|
|
91
98
|
const history = bindings.get(config)
|
|
92
99
|
if (!history) return config
|
|
93
100
|
if (!Number.isFinite(at)) return config
|
|
@@ -97,23 +104,26 @@ export function pricingConfigAt(config, at, sessionId = '') {
|
|
|
97
104
|
let low = 0, high = index.changes.length
|
|
98
105
|
while (low < high) { const middle = (low + high) >>> 1; if (index.changes[middle].at <= at) low = middle + 1; else high = middle }
|
|
99
106
|
const chosen = index.changes[low - 1]
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
const applicable = row => row && at <= row.at ? row : null
|
|
108
|
+
const whole = applicable(index.revisions.get(JSON.stringify([sessionId, day, ''])))
|
|
109
|
+
const scoped = model ? applicable(index.revisions.get(JSON.stringify([sessionId, day, model]))) : null
|
|
110
|
+
const revision = whole && scoped ? (compare(whole, scoped) > 0 ? whole : scoped) : whole ?? scoped
|
|
102
111
|
const version = (revision ?? chosen)?.version
|
|
103
112
|
const result = version && history.versions[version] ? { ...config, ...history.versions[version] } : config
|
|
104
113
|
let fxLow = 0, fxHigh = index.fx.length
|
|
105
114
|
while (fxLow < fxHigh) { const middle = (fxLow + fxHigh) >>> 1; if (index.fx[middle].at <= at) fxLow = middle + 1; else fxHigh = middle }
|
|
106
115
|
const fx = index.fx[fxLow - 1]?.rates
|
|
107
116
|
// Before FX tracking was introduced, the original price version is authoritative.
|
|
108
|
-
const rates = revision ?
|
|
117
|
+
const rates = revision?.preserveFx ? whole?.fxRates ?? fx ?? fxRatesOf(history.versions[chosen?.version] ?? config)
|
|
118
|
+
: revision ? revision.fxRates ?? fxRatesOf(result) : fx ?? fxRatesOf(result)
|
|
109
119
|
return { ...result, fxRates: rates, exchangeRate: rates[result.currency] ?? result.exchangeRate }
|
|
110
120
|
}
|
|
111
121
|
|
|
112
122
|
/** Repricing affects only fully replayable session/day records explicitly accepted by the user. */
|
|
113
|
-
export function recordPricingRevision(history, config, sessionId, date, at, before, after) {
|
|
123
|
+
export function recordPricingRevision(history, config, sessionId, date, at, before, after, model = '') {
|
|
114
124
|
const pricing = pricingSnapshot(config), version = hash(pricing)
|
|
115
125
|
history.versions[version] = pricing
|
|
116
|
-
history.revisions[randomUUID()] = { sessionId, date, at, fxRates: fxRatesOf(config), sequence: Object.keys(history.revisions).length + 1, version, before, after }
|
|
126
|
+
history.revisions[randomUUID()] = { sessionId, date, at, ...(model ? { model, preserveFx: true } : { fxRates: fxRatesOf(config) }), sequence: Object.keys(history.revisions).length + 1, version, before, after }
|
|
117
127
|
indexes.delete(history)
|
|
118
128
|
}
|
|
119
129
|
|