dsh-cost-meter 1.7.35 → 1.7.37
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 +9 -9
- package/README.zh-CN.md +9 -9
- package/lib/backfill.js +3 -2
- package/lib/client.js +5 -5
- package/lib/index.js +30 -0
- package/lib/net.js +17 -1
- package/lib/pricing.js +45 -24
- package/lib/store.js +8 -0
- package/lib/typert.host.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
**Session cost tracking plugin for the DeepSeek Harness web GUI (bilingual UI)**
|
|
8
8
|
|
|
9
|
-
Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00;
|
|
9
|
+
Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00; weekends and Chinese public holidays are off-peak all day, with separate labels) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 90+ model price catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
|
|
10
10
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
12
|
|
|
13
|
-
**v1.7.
|
|
13
|
+
**v1.7.37** bills Chinese public holidays at off-peak DeepSeek rates all day, updates the period display, and recalculates affected history when complete session logs are available. Work-shift weekends remain off-peak under DeepSeek's published rule. See the [release notes](docs/release-notes/v1.7.37.md).
|
|
14
14
|
|
|
15
15
|
[](https://www.npmjs.com/package/dsh-cost-meter)
|
|
16
16
|
[](LICENSE)
|
|
@@ -47,7 +47,7 @@ Per-conversation cost · daily totals · OpenCode Go subscription quota display
|
|
|
47
47
|
| Pre-install history import | Automatic on first launch | After install/upgrade, the first launch automatically replays all host session logs to import conversations from before the plugin was installed (missing dates are rebuilt whole; existing dates only gain previously unknown sessions; idempotent and never double-counts live metering; costs priced at per-event historical rates); a manual re-run entry remains in Settings |
|
|
48
48
|
| Budget settings | Settings page, top | Limit, period (today / month / cumulative / custom date range), used % |
|
|
49
49
|
| Price table | Settings page | Per-model off-peak / peak prices (input/output shorthand supported; cache prices derived automatically); fully editable |
|
|
50
|
-
| Peak/off-peak hours display | Settings / budget / today | Shows UTC peak hours 01:00–04:00 and 06:00–10:00 with the current tier;
|
|
50
|
+
| Peak/off-peak hours display | Settings / budget / today | Shows UTC peak hours 01:00–04:00 and 06:00–10:00 with the current tier; weekends and configured Chinese public holidays (Beijing dates) are off-peak all day, with separate labels; expanded view shows a period strip and countdown, collapsed view shows a vertical bar; independently toggleable |
|
|
51
51
|
| Peak/off-peak switch popup alert | Global overlay | A full-width bracketed popup appears when the next tier switch is within the configured lead time (default 2 minutes, 1–30), with an alert-colored badge distinguishing entering peak vs off-peak; position selectable (**bottom-right / screen center**), alert type selectable (entering peak / entering off-peak / both), one alert per switch point; optionally **sends a browser (system) notification** (so you still get alerted when the page is backgrounded; requires granting notification permission); configured in the peak pricing panel in Settings, with a **one-click popup preview** (rendered by the real component — copy, position and notifications exactly as they will fire) |
|
|
52
52
|
| Official price sync | Settings page | Fetches and parses the official pricing page, applies with one click; the **official price currency** is selectable (USD · English page / CNY · Chinese page) — CNY prices are booked at the display exchange rate and match the official CNY bill when displayed in CNY |
|
|
53
53
|
| UI language | Settings → Display settings | Simplified Chinese / English / Follow browser (auto); switches instantly and auto-saves |
|
|
@@ -316,22 +316,22 @@ On Node.js 20, use `npm install -g pnpm@10` instead. See [pnpm installation and
|
|
|
316
316
|
dsh plugin --profile web add dsh-cost-meter
|
|
317
317
|
```
|
|
318
318
|
|
|
319
|
-
**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.7.
|
|
319
|
+
**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.7.37`** — review the script before running):
|
|
320
320
|
|
|
321
321
|
```powershell
|
|
322
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.7.
|
|
322
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.7.37/install.ps1 | iex
|
|
323
323
|
```
|
|
324
324
|
|
|
325
325
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
326
326
|
|
|
327
327
|
```sh
|
|
328
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.7.
|
|
328
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.7.37
|
|
329
329
|
```
|
|
330
330
|
|
|
331
331
|
Without git, use the GitHub tag archive:
|
|
332
332
|
|
|
333
333
|
```sh
|
|
334
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.7.
|
|
334
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.7.37.tar.gz
|
|
335
335
|
```
|
|
336
336
|
|
|
337
337
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
|
@@ -403,7 +403,7 @@ dsh plugin --profile web add link:./dsh-cost-meter # symlink; edit lib/client.j
|
|
|
403
403
|
- Price units match the official docs: **USD / 1M tokens**;
|
|
404
404
|
- cost = cache-missed input × cache-miss + output × output + (cache read + cache write) × cache-hit (cache writes follow the legacy official rule and are billed at the hit price);
|
|
405
405
|
- **Pure two-tier peak/off-peak pricing** (the official scheme since 2026-08): peak hours (01:00–04:00, 06:00–10:00 UTC) bill at the peak price and all other hours at the off-peak price (off-peak = half of peak). The base tier equals the off-peak tier, and billing falls back to off-peak when peak/off-peak is disabled; the Settings page shows the live tier (peak / off-peak); the budget/today's cost area shows a peak/off-peak period strip (current/next period with countdown), and the collapsed rail shows a vertical peak/off-peak progress bar;
|
|
406
|
-
- **
|
|
406
|
+
- **Weekends and Chinese public holidays**: weekends are off-peak all day from 2026-08-23 00:00 Beijing time, including work-shift weekends. Chinese public holidays are also off-peak all day. `peakHolidays` contains Beijing dates in `YYYY-MM-DD` format and defaults to the published 2026 Mid-Autumn and National Day dates after the peak-pricing change; edit the list in Settings → Cost → Peak pricing for future holidays. The period strip labels holidays separately and counts down to the next actual price change. Historical DeepSeek costs are recalculated once from complete session logs; rows without complete logs keep their recorded amounts;
|
|
407
407
|
- **Historical billing correctness**: calls before 2026-08-16 16:00 UTC (the peak-era boundary) are billed at the base prices of that time, and later calls at the two-tier scheme;
|
|
408
408
|
- The ledger always stores amounts in **USD**; currency and FX rate only affect display (default 1 USD = 7.2 CNY, configurable);
|
|
409
409
|
- The session badge is **billed exactly** at the moment each call is made (host-exported per-call cost), just like daily/monthly/cumulative totals and the budget;
|
package/README.zh-CN.md
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
**DeepSeek Harness 会话费用统计插件(界面中英双语)**
|
|
8
8
|
|
|
9
|
-
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00
|
|
9
|
+
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段;周末与中国法定假日全天按谷价,分别标注) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / 火山方舟 / 千问 / 小米 MiMo 十一家,含 Volcano Ark AK/SK 签名与 MiMo 控制台 Cookie 查询) · Plan/API 双轨计费(订阅额度与按量金额分离统计,每 1% 额度与满窗的 token/等值金额估算及日/周/月曲线) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
|
|
10
10
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
12
|
|
|
13
|
-
**v1.7.
|
|
13
|
+
**v1.7.37**:中国法定假日全天按 DeepSeek 谷价计费,界面同步标注假日;可按完整会话日志修正受影响的历史费用。调休上班的周末仍按官方规则全天谷价。详见[更新说明](docs/release-notes/v1.7.37.md)。
|
|
14
14
|
|
|
15
15
|
[](https://www.npmjs.com/package/dsh-cost-meter)
|
|
16
16
|
[](LICENSE)
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
| 导入安装前历史 | 首次启动自动 | 安装/升级后首次启动自动回放宿主全部会话日志,把未装插件时期的对话导入账本(缺失日期整日重建,已有日期只补未知会话,幂等不与实时计费重复;金额按事件时刻历史价回推);设置页保留手动重跑入口 |
|
|
49
49
|
| 预算设置 | 设置页顶部 | 额度、周期(今日/本月/累计/自定义日期区间)、已用% |
|
|
50
50
|
| 价格表 | 设置页 | 每模型 谷时/峰时 两档价格(支持 input/output 简写,缓存价自动补齐),增删改自由 |
|
|
51
|
-
| 峰谷计价时段显示 | 设置页 / 预算 / 今日费用 | 显示 UTC 峰时段 01:00–04:00、06:00–10:00
|
|
51
|
+
| 峰谷计价时段显示 | 设置页 / 预算 / 今日费用 | 显示 UTC 峰时段 01:00–04:00、06:00–10:00 与当前档位;周末和已配置的中国法定假日(北京日期)全天按谷价计费并分别标注;展开态显示时段条与倒计时,收起态显示竖向条,可单独开关 |
|
|
52
52
|
| 峰/谷切换弹窗提醒 | 全局浮层 | 距进入峰/谷时段不足设定提前量(默认 2 分钟,1-30 可配)时全屏色条徽标弹窗(提醒色区分进入峰/谷);弹窗位置可选**右下角 / 屏幕中心**,提醒类型可选(进入峰 / 进入谷 / 峰和谷),同一切换点只提醒一次;可选**同步发送浏览器(系统)通知**(页面最小化也能收到,需授权通知权限);设置页峰谷计价面板内配置,并可**一键预览弹窗效果**(真实组件渲染,文案/位置/通知与实际触发完全一致) |
|
|
53
53
|
| 官方价格同步 | 设置页 | 抓取解析官方定价页,一键应用;可选**官方价格币种**(美元·英文官方页 / 人民币·中文官方页),人民币价按展示汇率折算入账、展示人民币时与官方账单一致 |
|
|
54
54
|
| 界面语言 | 设置页 → 显示设置 | 简体中文 / English / 跟随浏览器(自动);切换即时生效并自动保存 |
|
|
@@ -316,22 +316,22 @@ Node.js 20 请改用 `npm install -g pnpm@10`。版本要求见 [pnpm 官方安
|
|
|
316
316
|
dsh plugin --profile web add dsh-cost-meter
|
|
317
317
|
```
|
|
318
318
|
|
|
319
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.7.
|
|
319
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.7.37`**,建议先下载审阅再运行):
|
|
320
320
|
|
|
321
321
|
```powershell
|
|
322
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.7.
|
|
322
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.7.37/install.ps1 | iex
|
|
323
323
|
```
|
|
324
324
|
|
|
325
325
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
326
326
|
|
|
327
327
|
```sh
|
|
328
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.7.
|
|
328
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.7.37
|
|
329
329
|
```
|
|
330
330
|
|
|
331
331
|
没有 git 时可用 GitHub tag 打包直链:
|
|
332
332
|
|
|
333
333
|
```sh
|
|
334
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.7.
|
|
334
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.7.37.tar.gz
|
|
335
335
|
```
|
|
336
336
|
|
|
337
337
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
|
@@ -403,7 +403,7 @@ dsh plugin --profile web add link:./dsh-cost-meter # 符号链接,改 lib/clien
|
|
|
403
403
|
- 价格单位与官方文档一致:**美元 / 1M tokens**;
|
|
404
404
|
- 成本 = 未命中输入 × cache-miss + 输出 × output + (缓存读 + 缓存写) × cache-hit(缓存写沿用官方历史规则按命中价计费);
|
|
405
405
|
- **纯峰谷两档计价**(2026-08 起官方方案):峰时段(01:00–04:00、06:00–10:00 UTC)按峰时价,其余按谷时价(谷时价 = 峰时价的一半);基础档与谷时档同价,未启用峰谷时按谷时价计;设置页实时显示当前档位(峰时段/谷时段);预算与今日费用区域显示峰时/平价时段条(当前/下一时段与倒计时),收起态显示竖向峰谷进度条;
|
|
406
|
-
-
|
|
406
|
+
- **周末与法定假日全天谷价**:自 2026-08-23 北京时间 00:00 起,周六、周日全天谷价,调休上班的周末也不例外。中国法定假日同样全天谷价。`peakHolidays` 为 `YYYY-MM-DD` 北京日期数组,默认预置 2026 年峰谷规则生效后的中秋和国庆日期;以后可在 设置 → 费用 → 峰谷计价 中修改。时段条单独标注假日并倒计时至下一次实际价格变化。历史 DeepSeek 金额升级时从完整会话日志一次性重算;日志不完整的记录保留原金额;
|
|
407
407
|
- **历史计费正确性**:2026-08-16 16:00 UTC(峰谷时代分界)之前的调用按当时的基础价计费,之后的调用按峰谷两档;
|
|
408
408
|
- 账本金额恒以**美元**存储,币种/汇率仅影响显示(默认 1 USD = 7.2 CNY,可改);
|
|
409
409
|
- 会话徽章与当日/月度/累计、预算一样,按每次调用的**实际时刻精确计费**(宿主导出的逐次成本);
|
package/lib/backfill.js
CHANGED
|
@@ -485,6 +485,7 @@ export function replaySessionRecords(records, config, wantDates = null) {
|
|
|
485
485
|
enabled: resolved.billingMode === 'deepseek-peak' && config?.peakEnabled === true,
|
|
486
486
|
effectiveAtMs: Date.parse(config?.peakEffectiveAt ?? ''),
|
|
487
487
|
windows: config?.peakWindows,
|
|
488
|
+
holidays: config?.peakHolidays,
|
|
488
489
|
}
|
|
489
490
|
// 官方价格币种为人民币(issue #47)时,DeepSeek 主表计出的成本为人民币,
|
|
490
491
|
// 按展示汇率折算为美元入账——与 store.account() 完全同口径。
|
|
@@ -898,10 +899,10 @@ export async function importLegacyHistory(ledger, sessionsRoot) {
|
|
|
898
899
|
* @param includeBucket - 可选的 (providerModelKey, date) 过滤器,仅修复目标价格路径。
|
|
899
900
|
* @returns {{ scanned, recostedSessions, skippedSessions, recostedDays }}。
|
|
900
901
|
*/
|
|
901
|
-
export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeBucket) {
|
|
902
|
+
export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeBucket, onlySessionIds = null) {
|
|
902
903
|
const result = { scanned: 0, recostedSessions: 0, skippedSessions: 0, recostedDays: 0 }
|
|
903
904
|
const bySession = new Map()
|
|
904
|
-
for await (const records of sessionBillingRecords(ledger, sessionsRoot)) {
|
|
905
|
+
for await (const records of sessionBillingRecords(ledger, sessionsRoot, onlySessionIds)) {
|
|
905
906
|
if ((result.scanned += 1) % 8 === 0) await new Promise(resolve => setImmediate(resolve))
|
|
906
907
|
let replayed
|
|
907
908
|
try {
|