@gamegeek-saikel/dsh-cost-meter 0.1.2 → 0.2.0
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 +4 -3
- package/README.zh-CN.md +4 -3
- package/lib/client.js +1 -2
- package/lib/client.js.map +1 -1
- package/lib/index.js +267 -164
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +4 -3
- package/lib/types/pricebook.d.ts +3 -1
- package/lib/types/pricebook.d.ts.map +1 -1
- package/lib/types/pricebook.js +21 -3
- package/lib/types/pricing.d.ts +11 -8
- package/lib/types/pricing.d.ts.map +1 -1
- package/lib/types/pricing.js +209 -138
- package/lib/types/session-cost-projection.d.ts +106 -2
- package/lib/types/session-cost-projection.d.ts.map +1 -1
- package/lib/types/session-cost-projection.js +46 -33
- package/lib/types/types.d.ts +15 -0
- package/lib/types/types.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/client/index.ts +4 -3
- package/src/pricebook.ts +25 -4
- package/src/pricing.ts +225 -140
- package/src/session-cost-projection.ts +70 -35
- package/src/types.ts +15 -0
package/README.md
CHANGED
|
@@ -29,11 +29,11 @@ Then start the harness:
|
|
|
29
29
|
npx @deepseek-ai/dsh web
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
If you have the DSH CLI installed globally, you can also use `dsh` instead of `npx @deepseek-ai/dsh`. To install into another profile, replace `web` with your profile name. The host half requires Node `^22.19.0 || >=24.0.0` and pnpm `11.7.0` for development.
|
|
32
|
+
If you have the DSH CLI installed globally, you can also use `dsh` instead of `npx @deepseek-ai/dsh`. To install into another profile, replace `web` with your profile name. The plugin declares and is verified against DSH `>=0.1.1-rc.1 <0.2.0` (current local version `0.1.1-rc.1`). The host half requires Node `^22.19.0 || >=24.0.0` and pnpm `11.7.0` for development.
|
|
33
33
|
|
|
34
34
|
## Overview
|
|
35
35
|
|
|
36
|
-
Chat costs in DeepSeek pricing change over time (list prices, USD→CNY exchange, and the
|
|
36
|
+
Chat costs in DeepSeek pricing change over time (list prices, USD→CNY exchange, and the 2026-08-17 peak/off-peak rollout; on 2026-08-21 the official zh/en pages were redesigned into a combined table with three model columns and OFF-PEAK/PEAK cells), and a conversation spans many turns with cache-hit, cache-miss, cache-write, and output token buckets. Naively recomputing costs at *current* prices makes history drift every time the price table changes.
|
|
37
37
|
|
|
38
38
|
**Cost Meter** solves this with an **append-only pricebook**: every price/fx/band-table change starts a new immutable `PricebookSnapshot` (monotonic `version`, `effectiveAt`), and each usage event anchors to the snapshot effective at its own time. The result is an immutable per-step cost ledger that only grows — it never mutates. Live streaming estimates are explicitly labeled 估算/estimate because they use *current* prices; they are replaced by the exact anchored value once the step settles.
|
|
39
39
|
|
|
@@ -43,6 +43,7 @@ Chat costs in DeepSeek pricing change over time (list prices, USD→CNY exchange
|
|
|
43
43
|
|---|---|
|
|
44
44
|
| Cost anchoring | Append-only pricebook snapshots; step cost computed once at the event's own time |
|
|
45
45
|
| Price sources | Manual override > official pricing page > built-in fallback > OpenRouter (fallback only, USD→CNY) > none |
|
|
46
|
+
| Official page | Parses both the 2026-08-21 combined zh/en tables (including the `deepseek-v4-flash-vision-exp` column and the English UTC schedule) and the legacy split tables; the built-in historical list still anchors `single` when the page no longer carries one |
|
|
46
47
|
| Peak pricing | 2026-08-17 00:00 Beijing rollout; peak/off-peak windows parsed from each page's own schedule (the zh and en pages may differ; fallback 09:00–12:00 / 14:00–18:00 Beijing), off-peak half price |
|
|
47
48
|
| Cost formula | Uncached input + cache reads (hit rate) + cache writes (billed at uncached input rate) + output, per 1M tokens, CNY |
|
|
48
49
|
| Account balance | Official `GET /user/balance`, cached 60 s, single in-flight request, trust-fenced route |
|
|
@@ -71,7 +72,7 @@ The pricebook (`src/pricebook.ts`) is the durable price source, persisted on the
|
|
|
71
72
|
|
|
72
73
|
- **Priority chain** — per canonical model key (`provider/model`, bare model, or the `flash`/`pro` pricing key for DeepSeek-family models): manual override > official page > built-in fallback > OpenRouter (fallback only, USD→CNY, cache reads at the configured discount) > none.
|
|
73
74
|
- **Snapshot selection** — `snapshotForTime` picks the newest snapshot with `effectiveAt <= event time` (pre-install sessions anchor to the first snapshot once).
|
|
74
|
-
- **Peak/off-peak** — before the 2026-08-17 rollout all steps price at the single list price; after it, the band is chosen by the EVENT's own time against the schedule of the pricebook's own page (the zh and en pages each parse their own peak windows
|
|
75
|
+
- **Peak/off-peak** — before the 2026-08-17 rollout all steps price at the single list price; after it, the band is chosen by the EVENT's own time against the schedule of the pricebook's own page (the zh and en pages each parse their own peak windows — the redesigned English page states UTC — falling back to Beijing 09:00–12:00 / 14:00–18:00, everything else off-peak). When the combined page has no legacy single-price column, `single` keeps anchoring to the built-in historical list; a page that still carries a separate legacy table wins. Each step's band is anchored once at fold time, so the per-reply cards and chips always show the band that round was billed at — never the band of the moment you are looking.
|
|
75
76
|
- **Immutable ledger** — the `sessionCost` projection (`src/session-cost-projection.ts`) folds `request/header` (model) and usage-carrying events into per-step rows; a second usage sample for the same (turn, step) replaces the first (same-step finalization, not a re-price), with O(1) incremental totals.
|
|
76
77
|
|
|
77
78
|
## Project Structure
|
package/README.zh-CN.md
CHANGED
|
@@ -29,11 +29,11 @@ npx @deepseek-ai/dsh plugin --profile web add @gamegeek-saikel/dsh-cost-meter
|
|
|
29
29
|
npx @deepseek-ai/dsh web
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
如果已全局安装 DSH CLI,也可以使用 `dsh` 代替 `npx @deepseek-ai/dsh`。安装到其他 profile 时,把 `web` 替换成你的 profile
|
|
32
|
+
如果已全局安装 DSH CLI,也可以使用 `dsh` 代替 `npx @deepseek-ai/dsh`。安装到其他 profile 时,把 `web` 替换成你的 profile 名称即可。插件声明并已验证兼容 DSH `>=0.1.1-rc.1 <0.2.0`(当前本地版本 `0.1.1-rc.1`)。开发环境要求 Node `^22.19.0 || >=24.0.0` 与 pnpm `11.7.0`。
|
|
33
33
|
|
|
34
34
|
## 概述
|
|
35
35
|
|
|
36
|
-
DeepSeek 的价格随时间变化(官方价目表、USD→CNY 汇率、以及 2026-08-17
|
|
36
|
+
DeepSeek 的价格随时间变化(官方价目表、USD→CNY 汇率、以及 2026-08-17 上线的峰值/闲时分时计价;2026-08-21 官方又把中英文页面改为一张三模型列、空闲/高峰列的价格表),而一次对话跨越很多轮,且每轮都含缓存命中、缓存未命中、缓存写入与输出等 token 桶。若按"当前价格"重算成本,每次价目变动都会让历史记录漂移。
|
|
37
37
|
|
|
38
38
|
**Cost Meter** 用**只追加的价格簿**解决这一问题:每次价格/汇率/分时表变化都会开启一个新的不可变 `PricebookSnapshot`(单调 `version`、`effectiveAt`),每个用量事件锚定到其自身时刻生效的快照。结果是一个**只增长、永不改写**的不可变逐步成本账本。流式实时估算明确标注为"估算"——因为它使用*当前*价格;一旦该步结算,即被精确的锚定值取代。
|
|
39
39
|
|
|
@@ -43,6 +43,7 @@ DeepSeek 的价格随时间变化(官方价目表、USD→CNY 汇率、以及
|
|
|
43
43
|
|---|---|
|
|
44
44
|
| 成本锚定 | 只追加价格簿快照;步成本在事件自身时刻只计算一次 |
|
|
45
45
|
| 价格来源 | 手动覆盖 > 官方价格页 > 内置回退 > OpenRouter(仅回退,USD→CNY)> 无 |
|
|
46
|
+
| 官方页适配 | 同时解析 2026-08-21 新版中英文页面(含 `deepseek-v4-flash-vision-exp` 第三列与英文 UTC 时段)和旧版分表;无旧单价的页面继续用内置历史单价锚定 |
|
|
46
47
|
| 峰值定价 | 2026-08-17 00:00 北京生效;高峰/闲时窗口按各页面自己的时段表解析(中英文页面可能不同,缺省 09:00–12:00 / 14:00–18:00 北京),闲时为半价 |
|
|
47
48
|
| 成本公式 | 未命中输入 + 缓存命中(命中价)+ 缓存写入(按未命中输入价计)+ 输出,每百万 tokens,CNY |
|
|
48
49
|
| 账户余额 | 官方 `GET /user/balance`,缓存 60 秒,单飞请求,路由带信任围栏 |
|
|
@@ -71,7 +72,7 @@ DeepSeek 的价格随时间变化(官方价目表、USD→CNY 汇率、以及
|
|
|
71
72
|
|
|
72
73
|
- **优先级链**——按规范模型键(`provider/model`、裸模型名,或 DeepSeek 系模型的 `flash`/`pro` 定价键):手动覆盖 > 官方页面 > 内置回退 > OpenRouter(仅回退,USD→CNY,缓存读按配置折扣)> 无。
|
|
73
74
|
- **快照选取**——`snapshotForTime` 取 `effectiveAt <= 事件时间` 的最新快照(安装前的会话一次性锚到首个快照)。
|
|
74
|
-
- **峰值/闲时**——2026-08-17
|
|
75
|
+
- **峰值/闲时**——2026-08-17 上线前所有步按单一价目计费;上线后按事件自身时刻与该价格簿页面的时段表选档(中英文页面各自解析自己的高峰窗口,英文新版为 UTC,抓取失败时回退到北京 09:00–12:00 / 14:00–18:00,其余闲时)。新版合并表没有旧单价列时,`single` 继续锚定内置历史单价;页面若有独立旧表,则优先用它。每步的档位在折叠时锚定一次,逐回复卡片与回复小标签永远显示该轮对话当时被计价的档位,而不是查看时刻的档位。
|
|
75
76
|
- **不可变账本**——`sessionCost` 投影(`src/session-cost-projection.ts`)把 `request/header`(模型)与携带用量的事件折叠为逐步记录;同一 (turn, step) 的第二次用量样本**替换**第一条(同一步终结,而非重新计价),总计以 O(1) 增量维护。
|
|
76
77
|
|
|
77
78
|
## 项目结构
|
package/lib/client.js
CHANGED
|
@@ -1490,8 +1490,7 @@ window.__ModuleLoader__.load({
|
|
|
1490
1490
|
}, SessionCostPill));
|
|
1491
1491
|
ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
|
|
1492
1492
|
name: "settings.plugin.item",
|
|
1493
|
-
|
|
1494
|
-
order: 30,
|
|
1493
|
+
key: SETTINGS_NAMESPACE,
|
|
1495
1494
|
locale: NS,
|
|
1496
1495
|
inject: () => ({ scope })
|
|
1497
1496
|
}, CostPluginCard));
|