@pinkbanana/dsh-balance 0.15.2 → 0.17.3

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 构成估算下轮费用:当前时段、下个峰谷切换后、新开会话(全部未命中缓存)、现在 /compact(摘要请求 + 压缩后首轮;摘要长度按约 4,000 tokens 假设),以及本 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 匹配,支持生效时间),模型列表与计费估算同步生效
@@ -34,13 +34,13 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额,以及 De
34
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.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`,以保持构建可复现。
41
+ 插件 `0.16.1` 支持 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` 起,已确认包含 `0.2.3-alpha.3`),以便包管理器使用标准 semver 规则解析这些版本。Cordis peer 范围为 `^4.0.5`。React / React DOM peer 范围为 `^18.2.0 || ^19.0.0`,以同时支持 DSH 0.2.2(React 18)和 0.2.3(React 19)。开发依赖仍固定在 DSH `0.2.2-rc.1`、Cordis `~4.1.0` 和 React 18,以保持构建可复现,且不中断对 React 18 宿主的支持。
42
42
 
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`。
43
+ 已在 DSH `0.2.1-rc.3` 和 `0.2.2-rc.5` 的 Web profile 验证安装和启动。对 DSH `0.2.3-alpha.3`,本版本通过 peer/semver 测试、API 兼容检查和会话计费夹具验证(完整 GUI 启动未在本环境执行)。仍使用 DSH `0.2.1-rc.2` 的用户可使用插件 `0.11.0`,DSH `0.2.0-rc.2` 的用户可使用插件 `0.10.2`。
44
44
 
45
45
  也可在本地构建并打包源码,再用 `dsh plugin --profile web add /absolute/path/to/package.tgz` 安装生成的 `.tgz` 文件,随后重启 Harness:
46
46
 
@@ -49,7 +49,7 @@ pnpm install --frozen-lockfile
49
49
  pnpm pack
50
50
  ```
51
51
 
52
- 消费统计通过新版只读会话句柄读取,以 `inheritedEventCount` 排除分叉继承的记录;会话页在 token 用量变化或一轮运行结束后刷新;统计页面每 15 秒检查更新,重新聚焦或返回页面时刷新,隐藏页面暂停查询。兼容 `assistant/message` 和重试/取消请求的 `assistant/attempt`,读取最后一条 stream usage,并以重试边界区分独立请求,同一次请求的重复结算仅计一次。
52
+ 消费统计通过 `SessionPersistence` 的只读会话句柄读取(包括官方 SQLite 存储,以及闲置归档后再次打开的会话),以 `inheritedEventCount` 排除分叉、子智能体和 `/side` 侧栏会话从父会话继承的记录,避免与父会话重复计费;会话页在 token 用量变化或一轮运行结束后刷新;统计页面每 15 秒检查更新,重新聚焦或返回页面时刷新,隐藏页面暂停查询。兼容 `assistant/message` 和重试/取消请求的 `assistant/attempt`,读取最后一条 stream usage,并以重试边界区分独立请求,同一次请求的重复结算仅计一次。
53
53
 
54
54
  全局统计会跳过当前 dsh 无法读取的旧格式或损坏会话,并显示未纳入统计的会话数量;其余会话仍正常统计。部分汇总结果不缓存,下次刷新会重试失败会话;已成功读取且 revision 未变化的会话复用精简用量记录。单个会话无法读取或所有会话都读取失败时,仍明确显示读取错误,不将失败记录当作零消费。
55
55
 
@@ -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,19 +155,28 @@ providers:
155
155
 
156
156
  ## 下轮费用估算
157
157
 
158
- 除继续、等待下个峰谷切换、新开会话外,卡片新增「现在 /compact」估算:一次读取整段历史的摘要请求(假设输出约 4,000 tokens,至多历史的四分之一)加压缩后的首轮(仅会话中最小的缓存命中前缀仍命中)。仅为估算,不会自动压缩。
158
+ 会话「消费」页会展示下轮费用估算卡片;在用量统计里点击会话名下钻时也会看到同一卡片。聊天框下方的余额摘要可按需展开该估算,默认收起以免占用空间。同一标签页内的导航(包括切换会话或模型)会记住展开或收起;刷新或关闭标签页后仍默认收起。
159
159
 
160
- 会话「消费」页会展示下轮费用估算卡片;聊天框下方的余额摘要可按需展开同一估算,默认收起以免占用空间。估算使用本会话最近若干次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过现有计价引擎计算,不另建第二套价格路径。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。
160
+ 卡片对照四种下一步的费用:当前时段继续、等待下个峰谷切换、现在 `/compact`(摘要请求 + 压缩后首轮;摘要约 4,000 tokens,至多历史的四分之一),以及新开会话(全部未命中缓存),并显示继续本会话相对新开因缓存可节省的费用。也可对照本 Harness 已配置且可计价的其他官方模型。当前模型下最便宜的一步会标上“最便宜”(按单轮费用比较,因此 `/compact` 很少在单轮胜出)。仅为估算,不会自动压缩或换模型。
161
161
 
162
- 返回结果包括当前时段、下一次峰谷切换时间、样本数量、token 构成,以及当前模型此刻、切换后、新开会话的估算,还有其他已配置且可计价官方模型的对照。无法定价的模型会被省略,不会显示为 $0。美元与原生人民币分别展示;只有配置了 `usdToCny` 才会给出人民币合计。接口为 `GET /dsh-balance/api/advice?session=…`,仅本机可访问,响应不含 prompt 或会话正文。
162
+ 估算使用本会话最近 8 次已计费请求各 token 桶(未缓存输入 / 缓存读取 / 缓存写入 / 输出)的中位数,通过与用量统计相同的计价引擎计算。下轮实际用量可能不同,例如上下文压缩、大段粘贴或视觉输入。没有已计价样本或估算加载失败时,卡片会说明原因,并提示重新估算或打开用量统计。完整计算说明、峰谷规则和局限见 [估算是怎么算的](./docs/estimates.md)。
163
163
 
164
- 这些数字是公开标准价估算,不是官方账单。StepFun `step-5-preview` 在使用 2026-10-14 之后的标准缓存命中价时,会注明账户可能仍享受 0.35 元/百万的保留价,插件无法识别。Tokener 按 2026-11-03 目录快照计价,不套用原厂价格或 DeepSeek 峰谷倍率。
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)中。
165
174
 
166
175
  ## 扩展与设计
167
176
 
168
177
  - `src/providers.ts` 保存可在前后端共享的 provider 元数据;`src/balance.ts` 的 adapter 表只负责端点与响应解析,传输、错误分类和缓存由公共逻辑处理。
169
178
  - `GET /dsh-balance/api/balance?provider=StepFun` 查询 StepFun;省略 provider 保持 DeepSeek 兼容,`refresh=1` 绕过对应缓存。不支持的 provider 返回 `UNSUPPORTED_PROVIDER`。
170
- - `GET /dsh-balance/api/advice?session=…` 返回当前会话的下轮费用估算(也可用 `sessionId`);可选 `provider`、`model` 与重复的 `compare=provider:model`。响应不含 prompt 内容。
179
+ - `GET /dsh-balance/api/advice?session=…` 返回当前会话的下轮费用估算(也可用 `sessionId`);可选 `provider`、`model`、`refresh=1` 与重复的 `compare=provider:model`。响应不含 prompt 内容。
171
180
  - 通过原生 `sidebar.panellist` 与 `main` 插槽接入侧栏和主页面,菜单、选中态、侧栏折叠和页面导航由 Harness 管理;插件使用 Harness 的颜色、圆角和布局变量,支持深浅色主题与窄屏。
172
181
 
173
182
  ## 开发
@@ -175,10 +184,13 @@ providers:
175
184
  ```bash
176
185
  pnpm install
177
186
  pnpm check
187
+ pnpm check-prices
178
188
  pnpm preview
179
189
  ```
180
190
 
181
- 预览不使用真实密钥。可使用 `?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` 起提供。
191
+ `pnpm check-prices` 会抓取 DeepSeek(中/英)、StepFun 官方定价页和 Tokener 公开目录,与内置费率表比对;不在 `pnpm check` 里运行,以免依赖外网。工作日定时工作流发现模型、费率、低谷窗口或节假日日历有实质差异时会开 issue;仅 Tokener `catalogRevision` 哈希变化不会判失败。
192
+
193
+ 预览不使用真实密钥。可使用 `?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` 起提供。
182
194
 
183
195
  ## License
184
196
 
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
@@ -36,9 +36,9 @@ The composer readout follows the current session’s provider and model. The Set
36
36
 
37
37
  ## Compatibility
38
38
 
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.
39
+ Plugin `0.16.1` 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` (confirmed to admit `0.2.3-alpha.3`), so package managers can resolve them under standard semver rules. The Cordis peer range is `^4.0.5`. The React / React DOM peer range is `^18.2.0 || ^19.0.0`, so the plugin can load on DSH 0.2.2 (React 18) and DSH 0.2.3 (React 19). Development dependencies remain pinned to DSH `0.2.2-rc.1`, Cordis `~4.1.0`, and React 18 for reproducible builds, without dropping React 18 hosts.
40
40
 
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`.
41
+ Installation and startup were verified with the web profile on DSH `0.2.1-rc.3` and `0.2.2-rc.5`. Compatibility with DSH `0.2.3-alpha.3` is covered by peer/semver tests, API checks, and session-billing fixtures (a full GUI start was not run in this environment). 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
 
43
43
  To install from source, build and pack it locally, then pass the generated `.tgz` path to `dsh plugin --profile web add /absolute/path/to/package.tgz` and restart Harness:
44
44
 
@@ -47,7 +47,7 @@ pnpm install --frozen-lockfile
47
47
  pnpm pack
48
48
  ```
49
49
 
50
- Usage reads the current read-only session handles and excludes fork-inherited events using `inheritedEventCount`. The conversation tab refreshes when token usage changes or a turn finishes.
50
+ Usage reads current read-only `SessionPersistence` handles — including the official SQLite session store and idle-archived sessions after they are reopened — and uses `inheritedEventCount` to exclude events a fork, subagent, or `/side` sidebar branch inherited from its parent, so that usage is not double-counted. The conversation tab refreshes when token usage changes or a turn finishes.
51
51
 
52
52
  Global statistics skip sessions that the current dsh cannot read, such as unsupported historical formats or damaged logs, and show how many sessions were excluded. Partial summaries are retried on the next refresh; unchanged successful sessions reuse compact usage records while failed sessions are retried. An unreadable selected session, or a collection where every session fails to read, still reports an error instead of showing zero usage.
53
53
 
@@ -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,19 +151,30 @@ Built-in estimates use [official DeepSeek USD rates](https://api-docs.deepseek.c
151
151
 
152
152
  ## Next-turn estimates
153
153
 
154
- Besides continue / wait for the next peak change / fresh session, the card now prices **`/compact` now**: one summarizer request over the whole history (about 4,000 output tokens assumed, at most a quarter of the history) plus the first turn afterwards, where only the smallest cache-hit prefix seen in the session still hits. Estimate only; nothing is compacted automatically.
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. The tab remembers whether you left it open or closed while you navigate (including session or model switches); a refresh or closing the tab returns to the default collapsed state.
155
155
 
156
- 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.
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. The cheapest of these four steps for the current model gets a “Cheapest” badge (single-turn cost, so `/compact` rarely wins one turn). These are estimates only; nothing is compacted or switched automatically.
157
157
 
158
- 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.
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. When there is no priced sample or the estimate fails to load, the card explains why and suggests refreshing or opening Usage. The full method, peak-hour rules, and limitations are in [How estimates are computed](./docs/estimates.en.md).
159
159
 
160
- 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.
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).
161
172
 
162
173
  ## Extension and design
163
174
 
164
175
  - `src/providers.ts` holds shared provider metadata. The adapter table in `src/balance.ts` defines endpoints and response parsers; transport, errors, and caching are shared.
165
176
  - `GET /dsh-balance/api/balance?provider=StepFun` selects StepFun. Omitting provider preserves DeepSeek compatibility; `refresh=1` bypasses that provider's cache. Unknown providers return `UNSUPPORTED_PROVIDER`.
166
- - `GET /dsh-balance/api/advice?session=…` returns the next-turn estimate for a session (`sessionId` is also accepted), with optional `provider`, `model`, and repeated `compare=provider:model`. The response never includes prompt text.
177
+ - `GET /dsh-balance/api/advice?session=…` returns the next-turn estimate for a session (`sessionId` is also accepted), with optional `provider`, `model`, `refresh=1`, and repeated `compare=provider:model`. The response never includes prompt text.
167
178
  - The layout draws on [Codrops' Kononenko case study](https://tympanus.net/codrops/2026/09/18/kononenko-architectural-bureau/): oversized type, negative space, architectural grids, and geometric linework, implemented in original CSS with light/dark themes, narrow layouts, and reduced-motion support.
168
179
 
169
180
  ## Development
@@ -171,10 +182,13 @@ These figures are published-rate estimates, not an official bill. When the post-
171
182
  ```bash
172
183
  pnpm install
173
184
  pnpm check
185
+ pnpm check-prices
174
186
  pnpm preview
175
187
  ```
176
188
 
177
- 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`.
189
+ `pnpm check-prices` fetches the official DeepSeek (zh/en) and StepFun pricing pages plus Tokener's public catalog and diffs them against the built-in tables. It is not part of `pnpm check`, so CI does not depend on those sites. A weekday workflow opens an issue when models, rates, off-peak windows or holiday dates drift; a Tokener `catalogRevision` hash change alone does not fail the check.
190
+
191
+ 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`.
178
192
 
179
193
  ## License
180
194
 
@@ -186,7 +200,7 @@ The preview uses no real credentials. Use `?lang=en&theme=dark` for English/dark
186
200
 
187
201
  A **Usage Statistics** entry below **Plugins** in the native sidebar opens a standalone page. It defaults to all providers and all time, with provider/date-range filters and breakdowns by provider, model, session, and day. Native `sidebar.panellist` and `main` slots keep navigation, collapsed sidebar behavior, and active styling consistent with Harness. Plugin surfaces use Harness theme colors and radii.
188
202
 
189
- Usage includes completed messages and failed, retried, or cancelled attempts with a reported stream usage sample. The final sample wins within an attempt; retry boundaries count separate calls. Inherited fork events are excluded. Open statistics refresh every 15 seconds and on focus/visibility return, without polling hidden pages. Manual refresh also populates the normal revision cache. Unknown prices remain unpriced.
203
+ Usage includes completed messages and failed, retried, or cancelled attempts with a reported stream usage sample. The final sample wins within an attempt; retry boundaries count separate calls. Inherited fork, subagent, and `/side` branch events are excluded. Open statistics refresh every 15 seconds and on focus/visibility return, without polling hidden pages. Manual refresh also populates the normal revision cache. Unknown prices remain unpriced.
190
204
 
191
205
  Run `pnpm preview` and open `?page=usage` (or `?page=usage&lang=en&theme=dark`) to inspect the fixture page.
192
206
 
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 current model cannot be priced, or the estimate fails to load, the card and the composer dock explain why and suggest refreshing or opening Usage. They do 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. The tab remembers the open/closed state while you navigate; a refresh or closing the tab returns to the default.
44
+ - Local read-only API: `GET /dsh-balance/api/advice?session=…` (`sessionId` is also accepted; optional `provider`, `model`, `refresh=1`, 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. Empty and error guidance: `&advice=empty`, `&advice=unpriced`, or `&advice=error`.
@@ -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`、`refresh=1` 与重复的 `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`。空态与失败引导可用 `&advice=empty`、`&advice=unpriced`、`&advice=error`。