dsh-token-bill 0.0.0-stage → 2.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ # Changelog
2
+
3
+ ## 2.0.1 — 2026-11-07
4
+
5
+ ### Changed
6
+
7
+ - **Renamed to `dsh-token-bill`** (repository `leecisen/dsh-token-bill`, row id `dsh-token-bill`, projection key `dshTokenBill`). The npm name `dsh-token-cost` belongs to a different author's plugin, so installing by that bare name never reached this one. Install with `github:leecisen/dsh-token-bill`.
8
+ - If you installed 2.0.0 (then named `dsh-token-cost`), uninstall it on the Plugins page before installing 2.0.1.
9
+ - Sharper 2x README screenshots in Chinese and English; panel notes keep "9–12" on one line and drop the stray space after Chinese full stops.
10
+
11
+ ## 2.0.0 — 2026-11-07
12
+
13
+ A rewrite of the v1 `@local/token-cost` plugin, published as `dsh-token-cost`.
14
+
15
+ ### Added
16
+
17
+ - **Per-model pricing.** Usage is tracked per provider + model, read from each message's source (or the latest request header for failed attempts), and priced with that model's rates.
18
+ - **Built-in official DeepSeek prices** for `deepseek-flash` and `deepseek-v4-pro` in CNY and USD (checked 2026-11-07); the retired names `deepseek-v4-flash` and `deepseek-v4-flash-vision-exp` bill as Flash.
19
+ - **Peak / off-peak pricing.** Each call is priced by its Beijing time: weekdays 09:00–12:00 and 14:00–18:00 are peak, everything else (weekends and the built-in 2026 public holidays) is half price. `holidays` adds more days; `timeOfDayPricing: false` turns it off.
20
+ - **Breakdown panel** on click: cost per token bucket with a proportion bar, cache hit rate, model calls, thinking tokens, last turn, compaction, off-peak savings, subagents with a grand total, and per-model rows. It follows the built-in context meter's look and closes on Escape or an outside click.
21
+ - **Sidebar costs**: every conversation in the session list shows its cost beside its time (`showInSessionList`).
22
+ - **Compaction calls are billed** (`compaction/summary`), which the built-in token meter does not count.
23
+ - **Forked sessions** no longer re-bill the events they inherited from their parent.
24
+ - `models` overrides keyed by `model` or `provider/model`, optional `offPeak` and `cacheWrite` prices, and a `fallback` price for unknown models; models without a price are shown as unpriced instead of guessed.
25
+ - Chinese and English UI, plugin title / description / detail document for the Plugins page.
26
+ - Unit tests for the fold, the pricing, the Host entry, and a Node smoke test of the browser components.
27
+
28
+ ### Changed
29
+
30
+ - Package renamed to `dsh-token-cost`; row id `dsh-token-cost`, projection key `dshTokenCost`, so v1 and v2 can be installed side by side during an upgrade.
31
+ - The projection stores tokens only and prices them in the view, so price edits apply to every past session.
32
+ - Registration is awaited and checkpoint state is validated on restore, as the session-projection contract asks.
33
+
34
+ ### Compatibility
35
+
36
+ - v1's `inputPrice`, `cacheHitPrice`, and `outputPrice` are still read, as the fallback price for models without their own.
37
+
38
+ ## 1.0.0
39
+
40
+ - First version (`@local/token-cost`): one cost badge next to the context ring, a single price table for the whole session.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 leecisen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,158 @@
1
+ # dsh-token-bill · Conversation cost
2
+
3
+ [中文](README.md)
4
+
5
+ A [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) plugin that estimates **what every conversation costs**.
6
+
7
+ - **Under the composer**: the session's estimated cost sits left of the context ring; click it for a breakdown.
8
+ - **In the sidebar**: every conversation shows its cost next to its time, without opening it.
9
+ - **Per-model pricing**: built-in official DeepSeek prices (`deepseek-flash`, `deepseek-v4-pro`, in CNY and USD); price any other model (for example one routed through pi-ai) in the config.
10
+ - **Peak / off-peak aware**: DeepSeek charges peak rates on Beijing weekdays 09:00–12:00 and 14:00–18:00 and half price at all other times (weekends and Chinese public holidays included). Each call is priced by **when it happened**, and the panel shows how much off-peak hours saved.
11
+ - **More complete**: counts the model calls made by context compaction (the built-in token meter does not), lists subagent costs with a grand total, and never re-bills the history a forked conversation inherited.
12
+ - **Price edits apply at once**: sessions store tokens only and prices are applied when the view is built, so changing a price re-prices every past conversation.
13
+ - Chinese and English UI, follows the light / dark theme; no dependencies, no build step.
14
+
15
+ > Costs are estimated from provider-reported token usage and a price table. Your bill is authoritative.
16
+
17
+ ## Screenshots
18
+
19
+ | Breakdown panel (light) | Breakdown panel (dark) | Sidebar |
20
+ |---|---|---|
21
+ | <img src="docs/panel-light-en.png" width="362" alt="Cost breakdown panel in the light theme"> | <img src="docs/panel-dark-en.png" width="362" alt="Cost breakdown panel in the dark theme"> | <img src="docs/sidebar-en.png" width="300" alt="Each conversation's cost in the sidebar list"> |
22
+
23
+ <sub>2x preview renders of the plugin's code with the DSH theme; the plugin follows DSH's language setting. Sample data: one peak-hour exchange, one night-time (off-peak) exchange, one compaction, one subagent, and one unpriced model (hy4).</sub>
24
+
25
+ What the panel shows:
26
+
27
+ | Row | Meaning |
28
+ |---|---|
29
+ | Input · cache miss / cache hit / Output | Tokens and cost per bucket; the bar shows each bucket's share of the cost. A "Cache write" row appears when there are cache writes. |
30
+ | Cache hit rate | Cached input ÷ all input. |
31
+ | Model calls | Billed model calls (a failed attempt that was retried counts too). |
32
+ | Thinking (in output) | Thinking (reasoning) tokens, already included in Output. |
33
+ | Last turn | Cost of the most recent turn. |
34
+ | Compaction | Cost of the model calls made while compacting the context. |
35
+ | Off-peak savings | What you saved compared with paying peak prices throughout. |
36
+ | Subagents / Total incl. subagents | Cost of the subagents this session started, and the total with them. |
37
+ | By model | Tokens and cost per model; models without a price show "no price". |
38
+
39
+ - A trailing `+` means some model has no price configured and is left out of the total (marked "no price").
40
+ - The subagent lines appear only when the session started subagents and the sidebar has loaded their data.
41
+
42
+ ## Install
43
+
44
+ Requires DeepSeek Harness **0.2.2-rc.1 or newer**.
45
+
46
+ ### From GitHub (recommended)
47
+
48
+ DeepSeek Harness sidebar → **Plugins** → **Add plugin**, then enter:
49
+
50
+ ```text
51
+ github:leecisen/dsh-token-bill
52
+ ```
53
+
54
+ When it finishes, click **Enable now**.
55
+
56
+ > Enter the whole `github:leecisen/dsh-token-bill`. A bare name makes DeepSeek Harness look for an npm package of that name, which may be someone else's plugin.
57
+
58
+ > Can't reach GitHub? Download the ZIP from [Releases](https://github.com/leecisen/dsh-token-bill/releases) or the repository page, extract it somewhere permanent, and enter that folder's **absolute path** in **Add plugin** (for example `D:\dsh-plugins\dsh-token-bill`).
59
+
60
+ ### Upgrading from v1 (`@local/token-cost`)
61
+
62
+ v2 is a separate package (package `dsh-token-bill`, row id `dsh-token-bill`) and does not clash with v1. Install and enable v2, then turn off or remove `@local/token-cost` on the **Plugins** page. v1's `inputPrice` / `cacheHitPrice` / `outputPrice` fields still work as the fallback price for unknown models.
63
+
64
+ Version 2.0.0 was named `dsh-token-cost` (`github:leecisen/dsh-token-cost`). If you installed it, uninstall it on the **Plugins** page first, then install as above.
65
+
66
+ ## Configuration
67
+
68
+ It works without any configuration: CNY, peak / off-peak pricing, costs in the sidebar. To change that, add an entry to your profile's `cordis.patch.yml` (on Windows usually `%USERPROFILE%\.dsh\profiles\desktop\cordis.patch.yml`):
69
+
70
+ ```yaml
71
+ - id: dsh-token-bill
72
+ config:
73
+ currency: CNY # CNY or USD use the built-in DeepSeek prices; other codes use only your `models`
74
+ timeOfDayPricing: true # DeepSeek peak / off-peak tiers; false = everything at peak (an upper bound)
75
+ showInSessionList: true # show each conversation's cost in the sidebar
76
+ holidays: # extra public holidays (Beijing dates), off-peak all day
77
+ - '2027-01-01'
78
+ models: # prices per million tokens, in `currency`
79
+ hy4: # key: a model id, or provider/model id
80
+ input: 0.8 # input, cache miss
81
+ cacheHit: 0.2 # input, cache hit (defaults to input)
82
+ output: 2 # output
83
+ # cacheWrite: 1 # cache write (defaults to input)
84
+ # offPeak: # optional off-peak card; missing fields inherit from above
85
+ # output: 1
86
+ deepseek-account/deepseek-v4-pro: # e.g. override one provider's copy of a model
87
+ input: 9
88
+ cacheHit: 0.3
89
+ output: 27
90
+ fallback: # optional: price for every model without one; omit to show "no price"
91
+ input: 2
92
+ cacheHit: 0.5
93
+ output: 8
94
+ ```
95
+
96
+ Note: this `config` **replaces** the plugin's own config as a whole (DeepSeek Harness does not merge them); fields you leave out take the defaults below.
97
+
98
+ | Field | Default | Meaning |
99
+ |---|---|---|
100
+ | `currency` | `CNY` | Currency code. `CNY` / `USD` have built-in DeepSeek prices. |
101
+ | `symbol` | by currency (`¥`, `$`, …) | Symbol shown before amounts. |
102
+ | `timeOfDayPricing` | `true` | Price DeepSeek peak and off-peak hours separately. |
103
+ | `showInSessionList` | `true` | Show each conversation's cost in the sidebar list. |
104
+ | `holidays` | built-in 2026 days off | Extra holidays as `YYYY-MM-DD` (Beijing time). |
105
+ | `models` | none | Custom or overriding prices. Lookup: `provider/model` → `model` → built-in → `fallback`. |
106
+ | `fallback` | none | Fallback price. v1's `inputPrice` / `cacheHitPrice` / `outputPrice` mean the same. |
107
+
108
+ ### Built-in prices
109
+
110
+ From the [official DeepSeek price page](https://api-docs.deepseek.com/quick_start/pricing), checked **2026-11-07**, per million tokens.
111
+
112
+ | Model | Hours | Input (cache hit) | Input (cache miss) | Output |
113
+ |---|---|---|---|---|
114
+ | `deepseek-flash` | peak | ¥0.04 / $0.006 | ¥2 / $0.30 | ¥8 / $1.20 |
115
+ | `deepseek-flash` | off-peak | ¥0.02 / $0.003 | ¥1 / $0.15 | ¥4 / $0.60 |
116
+ | `deepseek-v4-pro` | peak | ¥0.30 / $0.044 | ¥9 / $1.32 | ¥27 / $3.96 |
117
+ | `deepseek-v4-pro` | off-peak | ¥0.15 / $0.022 | ¥4.5 / $0.66 | ¥13.5 / $1.98 |
118
+
119
+ - The retired names `deepseek-v4-flash` and `deepseek-v4-flash-vision-exp` are billed as `deepseek-flash`, as the official page states.
120
+ - Peak hours: Beijing time Monday to Friday (except Chinese public holidays) 09:00–12:00 and 14:00–18:00 (01:00–04:00 and 06:00–10:00 UTC); all other hours are off-peak. The 2026 holidays are built in; add 2027's with `holidays` once announced, or update the plugin.
121
+ - Through the DeepSeek account provider (`deepseek-account`) the cost is the API-equivalent price. If your account runs on a quota or plan, set `deepseek-account/<model>` under `models` to 0 or to your real rate.
122
+ - Prices can change; the official page wins. Issues and PRs for outdated prices are welcome.
123
+
124
+ ## How it works
125
+
126
+ - The **Host half** registers the session projection `dshTokenBill`, which replays every billed model call in the session log: `assistant/message`, `assistant/attempt` (a failed attempt that was retried is billed too), and `compaction/summary`. Tokens are bucketed per provider + model and per peak / off-peak tier: uncached input, cached input, cache writes, output (and the thinking tokens within it).
127
+ - Within one attempt the final message's usage replaces the streaming sample; after `llm/retry-started` the retry is billed separately — the same rule the built-in token meter follows.
128
+ - The tier comes from each event's timestamp in Beijing time, so the fold is deterministic and replay-stable.
129
+ - Forked sessions: events inherited from the parent (below `inheritedEventCount`) are not billed again.
130
+ - The projection stores tokens only; the **view** applies the current prices, so a price edit applies to every session at once.
131
+ - The **browser half** puts the badge and panel into the `conversation.composer.dock` slot (reading this session's projection) and the per-conversation label into `sidebar.session.row.trailing` (reading the session list's summary rows). Subagent costs come from `subagentCatalog` and the session list.
132
+
133
+ ## Known limitations
134
+
135
+ - It is an estimate from reported usage and a price table. Per-request services such as web search / fetch are not included, nor are auxiliary calls like session-title generation (those calls are not written to the session log).
136
+ - The sidebar shows costs only for sessions with summary data; a conversation from before the plugin was installed may need to be opened once.
137
+ - Subagent costs depend on the child sessions the sidebar has loaded; until then the amount carries a `+`.
138
+ - Holidays are built in through 2026.
139
+
140
+ ## Development
141
+
142
+ ```bash
143
+ git clone https://github.com/leecisen/dsh-token-bill.git
144
+ cd dsh-token-bill
145
+ node --test "test/*.test.js"
146
+ ```
147
+
148
+ - `index.js`: Host entry, registers the projection.
149
+ - `lib/fold.js`: the projection fold (pure).
150
+ - `lib/pricing.js`: price tables, peak / off-peak tiers, and the priced view (pure).
151
+ - `client.js`: the browser half, plain JS without a build step; it requires only DSH's shared `react`, `react-dom`, and `@deepseek-ai/dsh-client-ui-primitives`.
152
+ - `test/`: `node --test` unit tests, including a smoke test that renders the browser components under Node.
153
+
154
+ To try local changes, enter the repository folder's absolute path in DeepSeek Harness's **Add plugin**; restart DSH after editing.
155
+
156
+ ## License
157
+
158
+ [MIT](LICENSE)
package/README.md CHANGED
@@ -1,3 +1,158 @@
1
- # Temporary Holding Version
1
+ # dsh-token-bill · 对话费用
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [English](README.en.md)
4
+
5
+ [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 插件:估算**每个对话花了多少钱**。
6
+
7
+ - **输入框下方**:上下文圆环左边显示本会话的估算费用,点一下展开明细。
8
+ - **侧边栏**:会话列表里,每个对话的时间旁边直接显示它的费用,不用点进去。
9
+ - **按模型计价**:内置 DeepSeek 官方价格(`deepseek-flash`、`deepseek-v4-pro`,人民币 / 美元两套);其他模型(例如通过 pi-ai 接入的模型)在配置里补上价格即可。
10
+ - **区分高峰 / 空闲时段**:DeepSeek 官方在北京时间工作日 9:00–12:00、14:00–18:00 收高峰价,其余时段(含周末、法定节假日全天)半价。插件按**每次调用发生的时间**分别计价,并显示「空闲时段节省」了多少。
11
+ - **算得更全**:上下文压缩(compaction)时的模型调用也计入(内置的 token 计量不含这部分);子代理的费用单独列出并给出合计;从别的会话分叉出来的会话,不会重复计算继承来的部分。
12
+ - **改价立即生效**:会话里只记录 token 数,价格在显示时才套用,改了价格后所有历史会话都按新价格重算。
13
+ - 中英文界面,跟随浅色 / 深色主题;零依赖、无需构建。
14
+
15
+ > 费用由模型返回的 token 用量 × 价格表估算,仅供参考,以实际账单为准。
16
+
17
+ ## 效果
18
+
19
+ | 明细面板(浅色) | 明细面板(深色) | 侧边栏 |
20
+ |---|---|---|
21
+ | <img src="docs/panel-light.png" width="362" alt="浅色主题下的费用明细面板"> | <img src="docs/panel-dark.png" width="362" alt="深色主题下的费用明细面板"> | <img src="docs/sidebar.png" width="300" alt="侧边栏会话列表里每个对话的费用"> |
22
+
23
+ <sub>以上为插件代码在 DSH 主题样式下的 2 倍分辨率预览渲染,示例数据:一次高峰时段对话 + 一次夜间(空闲)对话 + 一次上下文压缩 + 一个子代理 + 一个未定价模型 hy4。</sub>
24
+
25
+ 面板里有什么:
26
+
27
+ | 行 | 含义 |
28
+ |---|---|
29
+ | 输入 · 未命中缓存 / 命中缓存 / 输出 | 各类 token 数与对应费用;彩条是费用占比。有缓存写入时会多一行「缓存写入」。 |
30
+ | 缓存命中率 | 命中缓存的输入 ÷ 全部输入。 |
31
+ | 模型调用 | 计费的模型调用次数(失败后重试的那次也算)。 |
32
+ | 其中思考 | 输出里的思考(推理)tokens,已包含在「输出」中。 |
33
+ | 最近一轮 | 最近一轮对话的费用。 |
34
+ | 上下文压缩 | 压缩上下文时的模型调用费用。 |
35
+ | 空闲时段节省 | 和全部按高峰价相比省下的钱。 |
36
+ | 子代理 / 合计 | 本会话启动的子代理的费用,以及加上它们之后的合计。 |
37
+ | 按模型 | 每个模型的 token 与费用;没有价格的模型显示「未定价」。 |
38
+
39
+ - 金额后面的 `+` 表示有模型没有配置价格,这部分没有计入总额(明细里标为「未定价」)。
40
+ - 「子代理」「合计」只在本会话启动过子代理、并且侧边栏已加载它们的数据时出现。
41
+
42
+ ## 安装
43
+
44
+ 需要 DeepSeek Harness **0.2.2-rc.1 或更新版本**。
45
+
46
+ ### 从 GitHub 安装(推荐)
47
+
48
+ DeepSeek Harness 侧边栏 → **插件** → **添加插件**,填入:
49
+
50
+ ```text
51
+ github:leecisen/dsh-token-bill
52
+ ```
53
+
54
+ 安装完成后点 **立即启用**。
55
+
56
+ > 请填完整的 `github:leecisen/dsh-token-bill`。只填名字的话,DeepSeek Harness 会去 npm 上找同名的包,那可能是别人的插件。
57
+
58
+ > 如果连不上 GitHub:在 [Releases](https://github.com/leecisen/dsh-token-bill/releases) 或仓库首页下载 ZIP,解压到一个固定位置,然后在「添加插件」里填这个文件夹的**绝对路径**(例如 `D:\dsh-plugins\dsh-token-bill`)。
59
+
60
+ ### 从旧版(`@local/token-cost`)升级
61
+
62
+ 新版是一个独立的包(包名 `dsh-token-bill`、行 id `dsh-token-bill`),和旧版互不冲突。安装并启用新版后,在 **插件** 页面关闭或卸载旧的 `@local/token-cost` 即可。旧版的 `inputPrice` / `cacheHitPrice` / `outputPrice` 配置仍然可用,会作为「未知模型的兜底价格」。
63
+
64
+ 2.0.0 版当时叫 `dsh-token-cost`(地址 `github:leecisen/dsh-token-cost`)。如果你装过它,先在 **插件** 页面卸载,再按上面的方法安装新版。
65
+
66
+ ## 配置
67
+
68
+ 不配置也能用:默认人民币、区分时段、在侧边栏显示费用。要修改时,在你的 profile 的 `cordis.patch.yml`(Windows 一般在 `%USERPROFILE%\.dsh\profiles\desktop\cordis.patch.yml`)里加一段:
69
+
70
+ ```yaml
71
+ - id: dsh-token-bill
72
+ config:
73
+ currency: CNY # CNY 或 USD 使用内置 DeepSeek 价格;其他币种只用你在 models 里填的价格
74
+ timeOfDayPricing: true # 区分 DeepSeek 高峰/空闲时段;false = 全部按高峰价(保守上限)
75
+ showInSessionList: true # 在侧边栏会话列表显示费用
76
+ holidays: # 额外的法定节假日(北京时间日期),整天按空闲价
77
+ - '2027-01-01'
78
+ models: # 每百万 tokens 的价格,单位为 currency
79
+ hy4: # 键可以是「模型 id」,也可以是「provider/模型 id」
80
+ input: 0.8 # 输入(未命中缓存)
81
+ cacheHit: 0.2 # 输入(命中缓存),默认等于 input
82
+ output: 2 # 输出
83
+ # cacheWrite: 1 # 缓存写入,默认等于 input
84
+ # offPeak: # 可选:空闲时段价格,缺的字段沿用上面的值
85
+ # output: 1
86
+ deepseek-account/deepseek-v4-pro: # 例:只覆盖某个 provider 下的同名模型
87
+ input: 9
88
+ cacheHit: 0.3
89
+ output: 27
90
+ fallback: # 可选:所有没有价格的模型都按这个算;不填则显示「未定价」
91
+ input: 2
92
+ cacheHit: 0.5
93
+ output: 8
94
+ ```
95
+
96
+ 注意:这里的 `config` 会**整体替换**插件自带的配置(DeepSeek Harness 不做合并),没写的字段使用下表中的默认值。
97
+
98
+ | 字段 | 默认值 | 说明 |
99
+ |---|---|---|
100
+ | `currency` | `CNY` | 币种代码。`CNY` / `USD` 有内置 DeepSeek 价格。 |
101
+ | `symbol` | 随币种(`¥`、`$`…) | 金额前显示的符号。 |
102
+ | `timeOfDayPricing` | `true` | 是否区分 DeepSeek 高峰 / 空闲时段。 |
103
+ | `showInSessionList` | `true` | 是否在侧边栏会话列表显示每个对话的费用。 |
104
+ | `holidays` | 内置 2026 年放假日期 | 追加的节假日,格式 `YYYY-MM-DD`(北京时间)。 |
105
+ | `models` | 无 | 自定义 / 覆盖价格。查找顺序:`provider/模型` → `模型` → 内置价格 → `fallback`。 |
106
+ | `fallback` | 无 | 兜底价格。旧版的 `inputPrice` / `cacheHitPrice` / `outputPrice` 等同于它。 |
107
+
108
+ ### 内置价格
109
+
110
+ 来自 [DeepSeek 官方价格页](https://api-docs.deepseek.com/zh-cn/quick_start/pricing),**2026-11-07** 核对,单位:每百万 tokens。
111
+
112
+ | 模型 | 时段 | 输入(命中缓存) | 输入(未命中缓存) | 输出 |
113
+ |---|---|---|---|---|
114
+ | `deepseek-flash` | 高峰 | ¥0.04 / $0.006 | ¥2 / $0.30 | ¥8 / $1.20 |
115
+ | `deepseek-flash` | 空闲 | ¥0.02 / $0.003 | ¥1 / $0.15 | ¥4 / $0.60 |
116
+ | `deepseek-v4-pro` | 高峰 | ¥0.30 / $0.044 | ¥9 / $1.32 | ¥27 / $3.96 |
117
+ | `deepseek-v4-pro` | 空闲 | ¥0.15 / $0.022 | ¥4.5 / $0.66 | ¥13.5 / $1.98 |
118
+
119
+ - 旧模型名 `deepseek-v4-flash`、`deepseek-v4-flash-vision-exp` 按 `deepseek-flash` 计价(与官方一致)。
120
+ - 高峰时段:北京时间周一至周五(不含法定节假日)9:00–12:00、14:00–18:00;其余时间均为空闲时段。内置了 2026 年的放假日期;2027 年的安排公布后可用 `holidays` 追加,或升级插件。
121
+ - 通过 DeepSeek 账号(`deepseek-account`)使用时,按 API 价格估算,代表「等价 API 费用」;如果你的账号走的是额度/套餐,可以在 `models` 里用 `deepseek-account/<模型>` 把价格改成 0 或你的实际单价。
122
+ - 价格可能调整,以官方页面为准;发现过期欢迎提 issue / PR。
123
+
124
+ ## 计算方式
125
+
126
+ - **Host 端**注册一个会话投影 `dshTokenBill`,重放会话日志里每一次计费的模型调用:`assistant/message`、`assistant/attempt`(失败后重试的那次也计费)和 `compaction/summary`。按「provider + 模型」和「高峰 / 空闲」分桶累计 token:未命中缓存的输入、命中缓存的输入、缓存写入、输出(以及其中的思考 tokens)。
127
+ - 同一次尝试里,流式过程中的用量会被最终消息的用量替换;遇到 `llm/retry-started` 后,重试那次单独计费——与内置 token 计量的规则一致。
128
+ - 高峰 / 空闲按**事件发生时间**(北京时间)判断,结果可重放、确定。
129
+ - 分叉会话:从父会话继承的那部分事件(`inheritedEventCount` 之前)不计费。
130
+ - 投影里只存 token;**视图**才按当前价格计价,所以改价立即对所有会话生效。
131
+ - **浏览器端**:`conversation.composer.dock` 插槽里的徽标和明细面板读取本会话的投影;`sidebar.session.row.trailing` 插槽从会话列表的摘要数据里读取每个会话的费用。子代理的费用来自 `subagentCatalog` 和会话列表。
132
+
133
+ ## 已知限制
134
+
135
+ - 估算值:基于模型返回的用量和价格表,不含联网搜索 / 抓取等按次收费的服务,也不含会话标题生成等辅助调用(这些调用没有写入会话日志)。
136
+ - 侧边栏只显示已经有摘要数据的会话:安装插件前的老会话,可能要打开一次才会显示费用。
137
+ - 子代理费用依赖会话列表里已加载的子会话数据,没加载到时金额后会带 `+`。
138
+ - 节假日只内置到 2026 年。
139
+
140
+ ## 开发
141
+
142
+ ```bash
143
+ git clone https://github.com/leecisen/dsh-token-bill.git
144
+ cd dsh-token-bill
145
+ node --test "test/*.test.js"
146
+ ```
147
+
148
+ - `index.js`:Host 入口,注册投影。
149
+ - `lib/fold.js`:投影的折叠逻辑(纯函数)。
150
+ - `lib/pricing.js`:价格表、高峰 / 空闲判断、计价视图(纯函数)。
151
+ - `client.js`:浏览器端(纯 JS,无需构建),只依赖 DSH 共享的 `react`、`react-dom` 和 `@deepseek-ai/dsh-client-ui-primitives`。
152
+ - `test/`:`node --test` 单元测试,包括在 Node 里渲染浏览器端组件的冒烟测试。
153
+
154
+ 本地调试:在 DeepSeek Harness 的「添加插件」里填仓库文件夹的绝对路径来安装;改完代码后重启 DSH 生效。
155
+
156
+ ## 许可证
157
+
158
+ [MIT](LICENSE)