@pinkbanana/dsh-balance 0.14.0 → 0.16.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 CHANGED
@@ -23,7 +23,7 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额,以及 De
23
23
  - 缓存查询结果并支持手动刷新
24
24
  - 模型列表标注内置参考价(输入 / 输出每百万 tokens),未收录价格的模型明确标记
25
25
  - 统计页「会话」分类中点击任一会话,下钻查看该会话的完整请求明细,可随时返回总览
26
- - 按本会话近期已计费请求的 token 构成估算下轮费用:当前时段、下个峰谷切换后、新开会话(全部未命中缓存),以及本 Harness 已配置且可计价的其他官方模型;同时给出继续本会话相对新开因缓存节省的费用。这是估算而非官方账单,不会自动换模型,也不会把会话内容送出本机
26
+ - 按本会话近期已计费请求的 token 构成估算下轮费用:当前时段、下个峰谷切换后、新开会话(全部未命中缓存)、现在 /compact(摘要请求 + 压缩后首轮;摘要长度按约 4,000 tokens 假设),以及本 Harness 已配置且可计价的其他官方模型;同时给出继续本会话相对新开因缓存节省的费用。这是估算而非官方账单,不会自动换模型,也不会把会话内容送出本机。计算细节见 [估算是怎么算的](./docs/estimates.md)
27
27
  - 一键导出当前视图为 JSON 或 CSV(总览导出所选分类或完整摘要,会话导出请求级记录),数据不离开本机
28
28
  - 统计页可直接填写 USD→CNY 汇率(存于浏览器 localStorage,无需重启);插件配置 `usdToCny` 优先生效
29
29
  - 配置 `pricingOverrides` 可用自定义费率替换内置价格(按 provider + model 匹配,支持生效时间),模型列表与计费估算同步生效
@@ -31,14 +31,14 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额,以及 De
31
31
  - 统计页支持自定义日期范围与 12 个常用时区(默认跟随浏览器),月度按当前节奏预测,限定范围时与上一同期对比
32
32
  - 余额与模型查询对 429 / 5xx 自动重试(尊重 `Retry-After`,指数退避,最多 3 次尝试)
33
33
  - 依据 DeepSeek 峰谷定价,在高峰时段(北京时间周一至周五 9:00–12:00、14:00–18:00,中国法定节假日除外)将聊天框下方的余额指示灯变为橙色
34
- - 原生支持简体中文和英文,并跟随 Harness 系统语言切换
34
+ - 原生支持简体中文、繁體中文(zh-TW,缺失键回退到简体中文)和英文,并跟随 Harness 系统语言切换
35
35
  - 支持 Harness 已保存的 `DEEPSEEK_API_KEY`
36
36
 
37
- ![会话消费页示例](./docs/dsh-session-usage-v0100.jpg)
37
+ ![会话下钻与下轮费用估算](./docs/dsh-session-drilldown.png)
38
38
 
39
39
  ## 兼容性
40
40
 
41
- 插件 `0.14.0` 支持 DSH **`>=0.2.1-rc.3 <1.0.0-0`**,需要 Node.js **24.9+**。DSH 的安装和启动检查将预发布版本纳入匹配,范围内无需添加版本豁免。DSH peer 依赖也显式涵盖 `0.2.2-rc.1` 起的 `0.2.2` 预发布版,以便包管理器使用标准 semver 规则解析这些版本。Cordis peer 范围为 `^4.0.5`。开发依赖固定在 DSH `0.2.2-rc.1` 和 Cordis `~4.1.0`,以保持构建可复现。
41
+ 插件 `0.14.2` 支持 DSH **`>=0.2.1-rc.3 <1.0.0-0`**,需要 Node.js **24.9+**。DSH 的安装和启动检查将预发布版本纳入匹配,范围内无需添加版本豁免。DSH peer 依赖也显式涵盖 `0.2.2-rc.1` 起的 `0.2.2` 预发布版,以及 `0.2.3` 预发布版(`0.2.3-alpha.1` 起),以便包管理器使用标准 semver 规则解析这些版本。Cordis peer 范围为 `^4.0.5`。开发依赖固定在 DSH `0.2.2-rc.1` 和 Cordis `~4.1.0`,以保持构建可复现。
42
42
 
43
43
  已在 DSH `0.2.1-rc.3` 和 `0.2.2-rc.5` 的 Web profile 验证安装和启动。仍使用 DSH `0.2.1-rc.2` 的用户可使用插件 `0.11.0`,DSH `0.2.0-rc.2` 的用户可使用插件 `0.10.2`。
44
44
 
@@ -140,7 +140,7 @@ providers:
140
140
 
141
141
  统计仅覆盖当前 dsh 保存的本地会话,不包含其他客户端或整个组织的调用,也不提供 API Key 维度。请求数、输入、输出、缓存读取与缓存写入按 dsh 标准化的 usage 统计;缓存读取已从标准化输入中拆出,不重复计数。支持提供方、模型、会话、日期和活动时段明细,提供方别名统一归为 Tokener。
142
142
 
143
- 内置 2026-11-03 核验的 [Tokener 模型目录](https://www.tokener.ai/zh/models) 对话/推理模型美元参考价,逐个匹配完整模型 ID。使用 Tokener 目录价格,不套用原厂价格或 DeepSeek 峰谷倍率。参考价快照同样用于已有历史记录的估算,不代表历史实际扣款。未知模型、缺少 usage,以及包含未公开价格的缓存写入请求,保留请求数与 token 并标为“未计费”。账户余额、折扣和实际消费以 [Tokener 控制台](https://console.tokener.ai) 为准。
143
+ 内置 2026-11-28 对照 [公开机器可读目录](https://console.tokener.ai/api/public/v1/models) 与 [Tokener 模型说明](https://www.tokener.ai/docs/guides/models) 核验的美元参考价,逐个匹配完整模型 ID。使用 Tokener 目录价格,不套用原厂价格或 DeepSeek 的 2 倍峰谷倍率。目录中公布了官方低谷价的模型(目前为 `deepseek-flash`、`deepseek-v4-pro`)按 [模型页](https://www.tokener.ai/models/deepseek-flash) 的规则计价:北京时间周一至周五 09:00–12:00、14:00–18:00 为高峰(不含中国法定节假日),其余时间为低谷(含周末补班);低谷价仅适用于 2026-01-01 至 2027-12-31,窗口之外按高峰价。有上下文分档的模型(目前为 `claude-haiku-5-5`)按官方规则,用「含缓存在内的输入 token 数」匹配分档,整次请求套用该档的输入、缓存读取和输出单价。嵌入模型按官方「只计输入」计价;缓存读取单价未公布时,带缓存读取的请求标为未计费。已离开公开目录的模型 ID 仍沿用 2026-11-03 快照,便于历史会话估算;2026-11-28 核验时发现改价的模型(`claude-haiku-5-5`、`grok-4.3`、`grok-4.6`)在该日 00:00 北京时间之前沿用旧快照。参考价不代表历史实际扣款。未知模型、缺少 usage,以及包含未公开价格的缓存写入(或嵌入模型的缓存读取)请求,保留请求数与 token 并标为“未计费”。账户余额、折扣和实际消费以 [Tokener 控制台](https://console.tokener.ai) 为准。
144
144
 
145
145
  ## 统计口径
146
146
 
@@ -155,11 +155,22 @@ providers:
155
155
 
156
156
  ## 下轮费用估算
157
157
 
158
- 会话「消费」页会展示下轮费用估算卡片;聊天框下方的余额摘要可按需展开同一估算,默认收起以免占用空间。估算使用本会话最近若干次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过现有计价引擎计算,不另建第二套价格路径。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。
158
+ 会话「消费」页会展示下轮费用估算卡片;在用量统计里点击会话名下钻时也会看到同一卡片。聊天框下方的余额摘要可按需展开该估算,默认收起以免占用空间。
159
159
 
160
- 返回结果包括当前时段、下一次峰谷切换时间、样本数量、token 构成,以及当前模型此刻、切换后、新开会话的估算,还有其他已配置且可计价官方模型的对照。无法定价的模型会被省略,不会显示为 $0。美元与原生人民币分别展示;只有配置了 `usdToCny` 才会给出人民币合计。接口为 `GET /dsh-balance/api/advice?session=…`,仅本机可访问,响应不含 prompt 或会话正文。
160
+ 卡片对照四种下一步的费用:当前时段继续、等待下个峰谷切换、现在 `/compact`(摘要请求 + 压缩后首轮;摘要约 4,000 tokens,至多历史的四分之一),以及新开会话(全部未命中缓存),并显示继续本会话相对新开因缓存可节省的费用。也可对照本 Harness 已配置且可计价的其他官方模型。仅为估算,不会自动压缩或换模型。
161
161
 
162
- 这些数字是公开标准价估算,不是官方账单。StepFun `step-5-preview` 在使用 2026-10-14 之后的标准缓存命中价时,会注明账户可能仍享受 0.35 元/百万的保留价,插件无法识别。Tokener 按 2026-11-03 目录快照计价,不套用原厂价格或 DeepSeek 峰谷倍率。
162
+ 估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。完整计算说明、峰谷规则和局限见 [估算是怎么算的](./docs/estimates.md)。
163
+
164
+ ![下轮费用估算卡片](./docs/dsh-advisor-card.png)
165
+
166
+ 窄屏(360px)深色主题:
167
+
168
+ <img src="./docs/dsh-advisor-dark-narrow-zh-tw.png" alt="窄屏深色主题的下轮费用估算(繁體中文)" width="280" />
169
+ <img src="./docs/dsh-usage-dark-narrow-zh-tw.png" alt="窄屏深色主题的用量页(繁體中文)" width="280" />
170
+
171
+ 这些数字是公开标准价估算,不是官方账单。StepFun `step-5-preview` 在使用 2026-10-14 之后的标准缓存命中价时,会注明账户可能仍享受 0.35 元/百万的保留价,插件无法识别。Tokener 按 2026-11-28 公开目录计价,已计入官方低谷价和上下文分档(如有),不套用原厂价格或 DeepSeek 的 2 倍峰谷倍率。无法定价的模型会被省略,不会显示为 $0。美元与原生人民币分别展示;只有配置了 `usdToCny` 才会给出人民币合计。
172
+
173
+ 本机只读接口为 `GET /dsh-balance/api/advice?session=…`(也可用 `sessionId`),仅本机可访问,响应不含 prompt 或会话正文。本版本尚未提供可供模型调用的 agent tool;只读的 `dsh_balance_advise` 仍在[路线图](./ROADMAP.md)中。
163
174
 
164
175
  ## 扩展与设计
165
176
 
@@ -176,7 +187,7 @@ pnpm check
176
187
  pnpm preview
177
188
  ```
178
189
 
179
- 预览不使用真实密钥。可使用 `?page=session` 检查会话消费页(124 次 StepFun 请求、7,161,128 tokens),使用 `?page=usage` 查看独立统计页,使用 `?page=usage&lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。实时模型余额和统计修复自 `0.7.0` 起提供。
190
+ 预览不使用真实密钥。可使用 `?page=session` 检查会话消费页与下轮估算卡片(124 次 StepFun 请求、7,161,128 tokens;预览夹具含现在 /compact),使用 `?page=usage` 查看独立统计页并下钻会话,使用 `?page=usage&lang=en&theme=dark` 或 `?lang=zh-tw` 检查英文、繁体中文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换与可展开的估算。估算计算说明见 [估算是怎么算的](./docs/estimates.md)。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。实时模型余额和统计修复自 `0.7.0` 起提供。
180
191
 
181
192
  ## License
182
193
 
package/README_EN.md CHANGED
@@ -23,7 +23,7 @@ The composer readout follows the current session’s provider and model. The Set
23
23
  - Cache query results with manual refresh support
24
24
  - Annotate the model list with catalogued reference rates (input/output per million tokens); models without published pricing are marked explicitly
25
25
  - Drill from the Sessions category into any session's full request breakdown and back to the overview
26
- - Estimate the next turn from this session’s recent priced token mix: the current period, after the next peak change, a fresh session (all cache-miss), and other official models already configured in this Harness that can actually be priced, plus how much cache saves by continuing versus starting over. These are estimates, not an official bill; the plugin never auto-switches models and never sends session text off the machine
26
+ - Estimate the next turn from this session’s recent priced token mix: the current period, after the next peak change, a fresh session (all cache-miss), compact now (summarizer request plus the first post-compact turn; about 4,000 summary tokens assumed), and other official models already configured in this Harness that can actually be priced, plus how much cache saves by continuing versus starting over. These are estimates, not an official bill; the plugin never auto-switches models and never sends session text off the machine. See [How estimates are computed](./docs/estimates.en.md) for the details.
27
27
  - Export the current view as JSON or CSV (overview: full summary or the visible category; session: request-level records) — data never leaves the machine
28
28
  - Enter a display-only USD→CNY rate on the usage page (kept in browser localStorage, no restart); the plugin's `usdToCny` config still takes precedence
29
29
  - Replace built-in prices with `pricingOverrides` (matched by provider + model, optional `effectiveFrom`); the model list and usage estimates follow
@@ -31,12 +31,12 @@ The composer readout follows the current session’s provider and model. The Set
31
31
  - Custom date ranges and twelve common time zones (browser default); month-to-date projection at the current pace, plus a comparison with the immediately preceding period for bounded ranges
32
32
  - Retry balance and model queries on 429 / 5xx (honoring `Retry-After`, exponential backoff, at most three attempts)
33
33
  - Follows DeepSeek peak/off-peak pricing: the balance indicator below the composer turns orange during peak hours (09:00–12:00 and 14:00–18:00 Beijing time, Monday–Friday, excluding Chinese public holidays)
34
- - Native Simplified Chinese and English that follows the Harness system language
34
+ - Native Simplified Chinese, Traditional Chinese (zh-TW, falling back to Simplified Chinese per key) and English that follows the Harness system language
35
35
  - Use the `DEEPSEEK_API_KEY` saved by Harness
36
36
 
37
37
  ## Compatibility
38
38
 
39
- Plugin `0.14.0` supports DSH **`>=0.2.1-rc.3 <1.0.0-0`** and requires Node.js **24.9+**. DSH includes prereleases in its install and startup checks. Versions in this range require no exemption. The DSH peer ranges explicitly include `0.2.2` prereleases starting at `0.2.2-rc.1` so package managers can resolve them under standard semver rules. The Cordis peer range is `^4.0.5`. Development dependencies are pinned to DSH `0.2.2-rc.1` and Cordis `~4.1.0` for reproducible builds.
39
+ Plugin `0.14.2` supports DSH **`>=0.2.1-rc.3 <1.0.0-0`** and requires Node.js **24.9+**. DSH includes prereleases in its install and startup checks. Versions in this range require no exemption. The DSH peer ranges explicitly include `0.2.2` prereleases starting at `0.2.2-rc.1` and `0.2.3` prereleases starting at `0.2.3-alpha.1`, so package managers can resolve them under standard semver rules. The Cordis peer range is `^4.0.5`. Development dependencies are pinned to DSH `0.2.2-rc.1` and Cordis `~4.1.0` for reproducible builds.
40
40
 
41
41
  Installation and startup were verified with the web profile on DSH `0.2.1-rc.3` and `0.2.2-rc.5`. For DSH `0.2.1-rc.2`, use plugin `0.11.0`. For DSH `0.2.0-rc.2`, use plugin `0.10.2`.
42
42
 
@@ -119,7 +119,7 @@ The Host queries the documented `GET /v1/models` with Bearer authentication; cre
119
119
 
120
120
  Statistics cover locally saved dsh sessions only, not other clients or organization-wide usage, and do not group by API key. Requests and tokens are grouped by provider, model, session, date and activity hour. DSH usage already separates cache reads from uncached input; the plugin does not count them twice.
121
121
 
122
- Conversation/reasoning model estimates use the [Tokener model catalog](https://www.tokener.ai/zh/models) USD reference snapshot checked on 2026-11-03, matching exact model IDs without vendor rates or DeepSeek peak multipliers. This snapshot also estimates older records; it does not reconstruct historical charges. Unknown models, missing usage, and requests with unpublished cache-write pricing retain their requests/tokens but stay unpriced. Account balances and actual bills remain in the [Tokener console](https://console.tokener.ai).
122
+ Estimates use USD reference rates re-checked on 2026-11-28 against the [machine-readable public catalog](https://console.tokener.ai/api/public/v1/models) and the [Tokener models guide](https://www.tokener.ai/docs/guides/models), matching exact model IDs, without vendor rates or DeepSeek's 2× peak multiplier. Models that publish official off-peak rates (currently `deepseek-flash` and `deepseek-v4-pro`) follow the [model page](https://www.tokener.ai/models/deepseek-flash): peak is Monday–Friday 09:00–12:00 and 14:00–18:00 Beijing time, excluding Chinese public holidays; all other times are off-peak, including weekend makeup workdays. Off-peak prices apply only from 2026-01-01 through 2027-12-31; outside that window, peak prices apply. Models with context price tiers (currently `claude-haiku-5-5`) use the official rule: the input count includes cached tokens, and the matching range sets the input, cache-read, and output prices for the whole request. Embedding models are priced on input only; when a cache-read rate is unpublished, requests that include cache reads stay unpriced. Model IDs that left the public catalog keep the 2026-11-03 snapshot so historical sessions can still be estimated. Models whose public rates changed at the 2026-11-28 check (`claude-haiku-5-5`, `grok-4.3`, `grok-4.6`) keep the earlier snapshot until 00:00 Beijing time on that day. These figures do not reconstruct historical charges. Unknown models, missing usage, and requests with unpublished cache-write pricing (or unpublished cache-read pricing on embedding models) retain their requests/tokens but stay unpriced. Account balances and actual bills remain in the [Tokener console](https://console.tokener.ai).
123
123
 
124
124
  ## StepFun setup
125
125
 
@@ -151,11 +151,24 @@ Built-in estimates use [official DeepSeek USD rates](https://api-docs.deepseek.c
151
151
 
152
152
  ## Next-turn estimates
153
153
 
154
- The session Usage tab shows a next-turn estimate card. The composer balance dock can expand the same estimate on demand; it stays collapsed by default so it does not clutter the row. The token shape is the per-bucket median of the session’s most recent priced requests (uncached input, cache read, cache write, output), priced through the existing billing engines rather than a second pricing path. The next turn may not match, for example after compaction, a large paste, or vision input.
154
+ The session Usage tab shows a next-turn estimate card; the same card appears when you drill into a session from Usage Statistics. The composer balance dock can expand the estimate on demand; it stays collapsed by default so it does not clutter the row.
155
155
 
156
- The response includes the current period, the next peak-change time, the sample size, the token shape, estimates for the current model now, after the change, and as a fresh session, plus other configured official models that can be priced. Unpriced models are omitted rather than shown as $0. Native USD and CNY are shown separately; a combined CNY total appears only when `usdToCny` is set. The Host route is `GET /dsh-balance/api/advice?session=…`, loopback-only, and the payload never includes prompt or session text.
156
+ The card compares four next steps: continue in the current period, wait for the next peak change, **`/compact` now** (summarizer request plus the first post-compact turn; about 4,000 summary tokens, at most a quarter of the history), and a fresh session (all cache-miss), plus how much cache saves by continuing versus starting over. It can also compare other official models already configured in this Harness that can be priced. These are estimates only; nothing is compacted or switched automatically.
157
157
 
158
- These figures are published-rate estimates, not an official bill. When the post-2026-10-14 standard StepFun `step-5-preview` cache-hit rate is used, the UI notes that some accounts may still be grandfathered at 0.35 CNY per million tokens; the plugin cannot detect that. Tokener estimates use the 2026-11-03 catalog snapshot, without vendor rates or the DeepSeek peak multiplier.
158
+ The token shape is the per-bucket median of the session’s most recent 8 priced requests (uncached input, cache read, cache write, output), priced through the same billing engines as usage totals rather than a second pricing path. The next turn may not match, for example after compaction, a large paste, or vision input. The full method, peak-hour rules, and limitations are in [How estimates are computed](./docs/estimates.en.md).
159
+
160
+ ![Next-turn estimate card](./docs/dsh-advisor-card-en.png)
161
+
162
+ ![Session drill-down with the estimate card](./docs/dsh-session-drilldown-en.png)
163
+
164
+ Narrow (360px) dark theme:
165
+
166
+ <img src="./docs/dsh-advisor-dark-narrow-en.png" alt="Next-turn estimate card, narrow dark theme" width="280" />
167
+ <img src="./docs/dsh-usage-dark-narrow-en.png" alt="Usage page, narrow dark theme" width="280" />
168
+
169
+ These figures are published-rate estimates, not an official bill. When the post-2026-10-14 standard StepFun `step-5-preview` cache-hit rate is used, the UI notes that some accounts may still be grandfathered at 0.35 CNY per million tokens; the plugin cannot detect that. Tokener estimates use the 2026-11-28 public catalog, including official off-peak and context-tier rates where published, without vendor rates or the DeepSeek peak multiplier. Unpriced models are omitted rather than shown as $0. Native USD and CNY are shown separately; a combined CNY total appears only when `usdToCny` is set.
170
+
171
+ The local read-only route is `GET /dsh-balance/api/advice?session=…` (`sessionId` is also accepted), loopback-only, and the payload never includes prompt or session text. This version has no agent tool the model can call; a read-only `dsh_balance_advise` tool is still on the [roadmap](./ROADMAP.md).
159
172
 
160
173
  ## Extension and design
161
174
 
@@ -172,7 +185,7 @@ pnpm check
172
185
  pnpm preview
173
186
  ```
174
187
 
175
- The preview uses no real credentials. Use `?lang=en&theme=dark` for English/dark mode, or `?state=missing`, `error`, `empty`, or `loading` to inspect those states. The sample model selector also exercises the composer readout. StepFun balance and model queries and the redesigned account page are available starting with `0.6.0`. Live model balances, and usage accounting fixes are available starting with `0.7.0`.
188
+ The preview uses no real credentials. Use `?page=session` for the conversation usage view and next-turn estimate card (the fixture includes compact now), or `?page=usage` for the statistics overview and session drill-down. Add `?lang=en&theme=dark` or `?lang=zh-tw` for English, Traditional Chinese, and dark mode, or `?state=missing`, `error`, `empty`, or `loading` to inspect those states. The sample model selector also exercises the composer readout and the expandable estimate. See [How estimates are computed](./docs/estimates.en.md) for the method. StepFun balance and model queries and the redesigned account page are available starting with `0.6.0`. Live model balances, and usage accounting fixes are available starting with `0.7.0`.
176
189
 
177
190
  ## License
178
191
 
Binary file
Binary file
Binary file
@@ -0,0 +1,54 @@
1
+ # How estimates are computed
2
+
3
+ The next-turn advisor compares four next steps: continue in the current period, wait for the next peak/off-peak change, run `/compact` now, or start a fresh session. The figures are published-rate estimates, **not an official bill**. The plugin never switches models or runs `/compact` on its own, and session text never leaves this machine.
4
+
5
+ For the shorter product summary see the [README](../README_EN.md#next-turn-estimates). 简体中文版见 [估算是怎么算的](./estimates.md).
6
+
7
+ ## Sampling and token shape
8
+
9
+ Estimates use only this session’s **most recent 8 priced requests** (or all of them if there are fewer). The advisor takes a median for each usage bucket and prices that shape through the same billing engines as the usage totals — not a second pricing path:
10
+
11
+ - uncached input
12
+ - cache read (hit)
13
+ - cache write
14
+ - output
15
+
16
+ The four medians are independent, so the synthetic “typical turn” may not match any single historical request. The next turn may also differ after compaction, a large paste, or vision input.
17
+
18
+ If the session has no priced requests, the card explains that it cannot estimate. It does not show $0.
19
+
20
+ ## The four next steps
21
+
22
+ | Option | How it is priced |
23
+ | --- | --- |
24
+ | Continue in the current period | The median usage, priced at **now** (peak, off-peak, or the provider’s standard rate). |
25
+ | Wait for the next peak change | The same usage, priced at the next peak↔off-peak switch. Official DeepSeek rates, and Tokener models that publish official off-peak prices (such as `deepseek-flash` and `deepseek-v4-pro`), show this row. StepFun and other flat-rate Tokener models do not use DeepSeek's 2× multiplier, so the row is omitted. |
26
+ | Compact now | Cost of the **summarizer request** plus the **first turn after compaction**. The summarizer reads the whole history (the already-cached prefix still hits) and is assumed to write about 4,000 output tokens, capped at one quarter of the history. After compaction, only the **smallest cache-hit prefix** seen in the session still hits; the summary and the new input miss. Output stays at the median. Actual summary length and the model used to compact may differ. |
27
+ | Fresh session | Cache reads are treated as cache misses; output and cache writes are unchanged. This simulates a new session with no reusable prefix. |
28
+
29
+ “Saved by continuing this session vs starting over” is the difference between the fresh-session estimate and the current-period estimate. The card may also compare other official models already configured in this Harness that can actually be priced (same median usage, current period). Unpriced models are omitted rather than shown as $0. Tokener models are compared only when they are already in the session or current selection; they are not expanded from a built-in alternative catalog.
30
+
31
+ ## Prices, peak hours, and limits
32
+
33
+ - **DeepSeek**: [official USD rates](https://api-docs.deepseek.com/quick_start/pricing/) with Beijing-time peak hours. Peak is Monday–Friday 09:00–12:00 and 14:00–18:00, excluding Chinese public holidays; weekends and those holidays are all-day off-peak. The built-in holiday calendar currently runs through 2027; later dates are estimated as ordinary weekdays and the card says so.
34
+ - **StepFun**: official standard CNY rates. The standard `step-5-preview` cache-hit rate is 0.70 CNY per million tokens from 2026-10-14; accounts that had already used the pay-as-you-go API before then may still be grandfathered at 0.35. The plugin cannot detect that, so it applies the standard effective-from date and notes the limitation.
35
+ - **Tokener**: USD reference rates from the 2026-11-28 public catalog, without vendor rates or DeepSeek's 2× peak multiplier. Official off-peak and context-tier rates are applied where the catalog publishes them. A turn that includes an unpublished cache-write price (or an unpublished cache-read price on an embedding model) is omitted from the estimate.
36
+ - `pricingOverrides` are shared with usage accounting. A combined CNY total appears only when `usdToCny` is configured (or a display rate is entered on the usage page), and it is labeled as a fixed-rate conversion.
37
+
38
+ Plans, discounts, account-specific rates, or unrecorded historical price changes can make the actual charge differ from the estimate.
39
+
40
+ ## Where to find it
41
+
42
+ - The current session’s Usage tab, and the usage-page drill-down after you click a session name, both show the full estimate card.
43
+ - The balance dock under the composer can expand the same estimate on demand; it stays collapsed by default.
44
+ - Local read-only API: `GET /dsh-balance/api/advice?session=…` (`sessionId` is also accepted; optional `provider`, `model`, and repeated `compare=provider:model`). Loopback only; the payload never includes prompt or session text.
45
+
46
+ This version has **no** agent tool the model can call. A read-only `dsh_balance_advise` tool is still on the [roadmap](../ROADMAP.md). Until then, use the UI or the local HTTP route above.
47
+
48
+ Local preview (no credentials):
49
+
50
+ ```bash
51
+ pnpm preview
52
+ ```
53
+
54
+ Then open `?page=session` for the conversation usage view and advisor card, or `?page=usage` for the statistics overview and session drill-down. Add `&lang=en`, `&lang=zh-tw`, or `&theme=dark` as needed.
@@ -0,0 +1,54 @@
1
+ # 估算是怎么算的
2
+
3
+ 下轮费用估算回答的是「下一步怎么走更省」:继续当前会话、等到下一个峰谷切换、现在执行 `/compact`,还是新开一个会话。这些数字是公开标准价估算,**不是官方账单**;插件不会自动换模型,也不会替你执行 `/compact`,更不会把会话正文送出本机。
4
+
5
+ 更短的功能说明见 [README](../README.md#下轮费用估算);英文版见 [How estimates are computed](./estimates.en.md)。
6
+
7
+ ## 取样与 token 构成
8
+
9
+ 估算只使用本会话**最近 8 次已计费请求**(不足 8 次则全用)。对四个用量桶分别取中位数,再送给与用量统计相同的计价引擎,而不是另建一套价格路径:
10
+
11
+ - 未缓存输入
12
+ - 缓存读取(命中)
13
+ - 缓存写入
14
+ - 输出
15
+
16
+ 四个桶的中位数是独立计算的,因此合成的「典型一轮」可能与任何单次历史请求都不完全相同。下轮实际用量也可能不同,例如上下文压缩、大段粘贴或视觉输入。
17
+
18
+ 没有已计费请求时,卡片会说明无法估算,而不会把费用显示为 $0。
19
+
20
+ ## 四种下一步
21
+
22
+ | 选项 | 怎么计价 |
23
+ | --- | --- |
24
+ | 当前时段继续 | 用上面的中位数用量,按**现在**的峰谷(或标准价)计价。 |
25
+ | 等待下个峰谷切换 | 用量不变,把计价时间推到下一次高峰↔低谷切换。DeepSeek 官方价,以及 Tokener 目录中公布了官方低谷价的模型(如 `deepseek-flash`、`deepseek-v4-pro`)会出现这一行;StepFun 与其他按标准价计价的 Tokener 模型不会套用 DeepSeek 的 2 倍倍率,因此不会出现这一行。 |
26
+ | 现在 `/compact` | **摘要请求**费用 + **压缩后首轮**费用。摘要请求读取整段历史(已缓存部分仍按命中计),输出按约 4,000 tokens 估算,且不超过历史长度的四分之一。压缩后的首轮里,仅会话中曾经出现过的**最小缓存命中前缀**仍命中,摘要文本与新的输入均按未命中计;输出仍用中位数。实际摘要长度和压缩所用模型可能不同。 |
27
+ | 新开会话 | 把当前的缓存读取全部改算为未命中,输出与缓存写入不变,模拟「没有前缀可命中」的新会话。 |
28
+
29
+ 「继续本会话相对新开可节省」来自「新开会话」与「当前时段」的差额。插件还可以对照本 Harness 已配置、且能按官方目录定价的其他模型(同一中位数用量、当前时段);无法定价的模型会被省略,不会显示为 $0。Tokener 模型只作为当前会话对照,不会被当作官方备选目录展开。
30
+
31
+ ## 价格、峰谷与局限
32
+
33
+ - **DeepSeek**:按[官方美元定价](https://api-docs.deepseek.com/quick_start/pricing/)和北京时间峰谷。高峰为周一至周五 09:00–12:00、14:00–18:00(不含中国法定节假日);周末和法定节假日全天低谷。内置节假日日历目前到 2027 年,超出后会按普通工作日估算并给出提示。
34
+ - **StepFun**:按官方人民币标准价。`step-5-preview` 缓存命中标准价自 2026-10-14 起为 0.70 元/百万 tokens;此前已按量调用的账户可能仍适用 0.35 元,插件无法识别该保留价,一律按标准生效时间计价,并在卡片上注明。
35
+ - **Tokener**:按 2026-11-28 公开目录的美元参考价,不套用原厂价格或 DeepSeek 的 2 倍峰谷倍率。已公布官方低谷价或上下文分档的模型按目录规则计价;含未公开价格的缓存写入(或嵌入模型的缓存读取)时,该次估算会被省略。
36
+ - 插件配置里的 `pricingOverrides` 与用量统计共用;配置了 `usdToCny`(或在统计页填写了显示汇率)时,才会出现人民币合计,并标明是固定汇率换算。
37
+
38
+ 套餐、折扣、账户特殊价格或不在目录里的历史调价,都可能导致实际扣款与估算不同。
39
+
40
+ ## 在哪里查看
41
+
42
+ - 当前会话的「消费」页,以及用量统计里点击会话名后的下钻页,都会显示完整估算卡片。
43
+ - 聊天框下方的余额条可按需展开同一估算,默认收起。
44
+ - 本机只读接口:`GET /dsh-balance/api/advice?session=…`(也可用 `sessionId`;可选 `provider`、`model` 与重复的 `compare=provider:model`)。仅本机可访问,响应不含 prompt 或会话正文。
45
+
46
+ 本版本**没有**可供模型调用的 agent tool。只读的 `dsh_balance_advise` 仍在[路线图](../ROADMAP.md)中;在此之前,请使用上面的界面或本机 HTTP 接口。
47
+
48
+ 本地预览(无需密钥):
49
+
50
+ ```bash
51
+ pnpm preview
52
+ ```
53
+
54
+ 然后打开 `?page=session` 查看会话消费页与估算卡片,或 `?page=usage` 查看统计总览并下钻到某个会话。可加 `&lang=en`、`&lang=zh-tw`、`&theme=dark`。