@pinkbanana/dsh-balance 0.9.0 → 0.10.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
@@ -4,7 +4,7 @@
4
4
 
5
5
  DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供方的可用模型和多维消费统计。API Key 仅由本机 Host 使用,不会发送到浏览器。
6
6
 
7
- 设置页采用账户总览布局,支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
7
+ 界面使用 Harness 原生侧栏、主页面和主题变量。侧栏“插件”下方新增“用量统计”,独立查看所有对话的提供方、模型、会话和日期统计;默认显示全部提供方与全部时间,支持提供方和日期范围筛选。活动打卡图按浏览器时区的星期 × 24 小时汇总请求次数,圆点大小随次数变化;悬停或使用方向键可查看请求数与 token 明细。选择器采用主题化浮层菜单,支持方向键、Home/End、Enter、Escape 和按名称检索。设置页支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
8
8
 
9
9
  聊天框底部会跟随当前会话所选的提供方与模型更新余额;设置页可独立切换提供方。
10
10
 
@@ -18,15 +18,17 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供
18
18
  - 在设置页按所选 provider、模型、会话和日期查看实际 usage 消费,并在当前会话的“消费”Tab 查看请求明细
19
19
  - 缺少 provider usage、未知 provider 或未知模型时标记为“未计费”,不进行 token 估算
20
20
  - 日期按浏览器 IANA 时区分组;DeepSeek 峰谷价格始终按北京时间计算
21
- - 默认显示 USD;配置 `usdToCny` 后额外显示固定汇率换算的 CNY
21
+ - DeepSeek 费用显示 USD、StepFun 显示原生 CNY;配置 `usdToCny` 后显示人民币合计
22
22
  - 缓存查询结果并支持手动刷新
23
23
  - 依据 DeepSeek 峰谷定价,在高峰时段(北京时间 9:00–12:00、14:00–18:00)将聊天框下方的余额指示灯变为橙色
24
24
  - 原生支持简体中文和英文,并跟随 Harness 系统语言切换
25
25
  - 支持 Harness 已保存的 `DEEPSEEK_API_KEY`
26
26
 
27
+ ![会话消费页示例](./docs/dsh-session-usage-v0100.jpg)
28
+
27
29
  ## 兼容性
28
30
 
29
- 0.9.0 适配 DeepSeek Harness **0.2.0-rc.2**([上游提交 639ed01](https://github.com/deepseek-ai/deepseek-harness/commit/639ed015397290b3745d163aafe02ffee4aa3f84)),需要 Node.js **22.19+(22.x)或 24+**。本次源码不再兼容 Harness 0.1 的接口。
31
+ 0.10.0 适配 DeepSeek Harness **0.2.0-rc.2**([上游提交 639ed01](https://github.com/deepseek-ai/deepseek-harness/commit/639ed015397290b3745d163aafe02ffee4aa3f84)),需要 Node.js **22.19+(22.x)或 24+**。本次源码不再兼容 Harness 0.1 的接口。
30
32
 
31
33
  也可在本地构建并打包源码,再用 `dsh plugin --profile web add /absolute/path/to/package.tgz` 安装生成的 `.tgz` 文件,随后重启 Harness:
32
34
 
@@ -35,7 +37,7 @@ pnpm install --frozen-lockfile
35
37
  pnpm pack
36
38
  ```
37
39
 
38
- 消费统计通过新版只读会话句柄读取,以 `inheritedEventCount` 排除分叉继承的记录;会话页在 token 用量变化或一轮运行结束后刷新。
40
+ 消费统计通过新版只读会话句柄读取,以 `inheritedEventCount` 排除分叉继承的记录;会话页在 token 用量变化或一轮运行结束后刷新;统计页面每 15 秒检查更新,重新聚焦或返回页面时刷新,隐藏页面暂停查询。兼容 `assistant/message` 和重试/取消请求的 `assistant/attempt`,读取最后一条 stream usage,并以重试边界区分独立请求,同一次请求的重复结算仅计一次。
39
41
 
40
42
  ## 安装
41
43
 
@@ -77,13 +79,15 @@ providers:
77
79
 
78
80
  每条请求按实际返回消息的 provider / model 归属,兼容旧日志的请求头;日期和峰谷价格按该次请求时间计算。Token 总量包括未缓存输入、输出、缓存读取与缓存写入。设置页默认筛选所选 provider,也可选择“全部提供方”;会话页保留混用模型的完整历史。
79
81
 
80
- 当前内置价格仅覆盖 DeepSeek 官方定价。StepFun 等没有可靠历史价格的数据保留请求数与 token,显示“未计费”;不会套用同名 DeepSeek 模型价格,也不会将全部未知费用显示为 $0。混合统计仅累加已知价格,并注明不完整。账户余额是实时查询值,与本地用量估算独立。
82
+ 内置 DeepSeek 美元定价,以及 2026-09-30 核验的 [StepFun 官方人民币标准价](https://platform.stepfun.com/docs/zh/guides/pricing/details):`step-5-preview`、`step-3.7-flash`、`step-3.5-flash` 和 `step-3.5-flash-2603`。StepFun 未缓存输入(含缓存写入)、缓存读取、输出分别计价,不套用 DeepSeek 峰谷倍率。费用是公开标准价估算,不代表账户实际账单;套餐、折扣和未保存的历史调价不包含在内。
83
+
84
+ 美元和原生人民币费用分别展示;设置 `usdToCny` 后,人民币合计才会包含美元折算金额。未知 provider / model 和缺失 usage 的请求保留请求数与 token,显示“未计费”;混合统计注明费用不完整。账户余额是实时查询值,与本地用量估算独立。会话消费页采用居中内容宽度、响应式外边距,并为底部输入框保留空间。
81
85
 
82
86
  ## 扩展与设计
83
87
 
84
88
  - `src/providers.ts` 保存可在前后端共享的 provider 元数据;`src/balance.ts` 的 adapter 表只负责端点与响应解析,传输、错误分类和缓存由公共逻辑处理。
85
89
  - `GET /dsh-balance/api/balance?provider=StepFun` 查询 StepFun;省略 provider 保持 DeepSeek 兼容,`refresh=1` 绕过对应缓存。不支持的 provider 返回 `UNSUPPORTED_PROVIDER`。
86
- - 排版参考 [Codrops 的 Kononenko 案例](https://tympanus.net/codrops/2026/09/18/kononenko-architectural-bureau/):大字号、留白、建筑式网格和几何线条,使用原创 CSS 实现;支持深浅色主题、窄屏与减少动态效果偏好。
90
+ - 通过原生 `sidebar.panellist` 与 `main` 插槽接入侧栏和主页面,菜单、选中态、侧栏折叠和页面导航由 Harness 管理;插件使用 Harness 的颜色、圆角和布局变量,支持深浅色主题与窄屏。
87
91
 
88
92
  ## 开发
89
93
 
@@ -93,7 +97,7 @@ pnpm check
93
97
  pnpm preview
94
98
  ```
95
99
 
96
- 预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。实时模型余额和统计修复自 `0.7.0` 起提供。
100
+ 预览不使用真实密钥。可使用 `?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` 起提供。
97
101
 
98
102
  ## License
99
103
 
package/README_EN.md CHANGED
@@ -18,7 +18,7 @@ The composer readout follows the current session’s provider and model. The Set
18
18
  - View actual usage costs by selected provider, model, session, and day in Settings, plus request details in the current session's Usage tab
19
19
  - Mark missing usage, unknown providers, and unknown models as unpriced without estimating tokens
20
20
  - Group dates in the browser's IANA timezone while applying DeepSeek peak pricing in Beijing time
21
- - Show USD by default, with optional fixed-rate CNY conversion through `usdToCny`
21
+ - Show native USD and CNY costs separately; `usdToCny` enables a combined CNY total
22
22
  - Cache query results with manual refresh support
23
23
  - Follows DeepSeek peak/off-peak pricing: the balance indicator below the composer turns orange during peak hours (09:00–12:00, 14:00–18:00 Beijing time)
24
24
  - Native Simplified Chinese and English that follows the Harness system language
@@ -26,7 +26,7 @@ The composer readout follows the current session’s provider and model. The Set
26
26
 
27
27
  ## Compatibility
28
28
 
29
- Version 0.9.0 targets DeepSeek Harness **0.2.0-rc.2** ([upstream commit 639ed01](https://github.com/deepseek-ai/deepseek-harness/commit/639ed015397290b3745d163aafe02ffee4aa3f84)). Use Node.js **22.19+ (22.x) or 24+**. Harness 0.1 APIs are no longer supported by this checkout.
29
+ Version 0.10.0 targets DeepSeek Harness **0.2.0-rc.2** ([upstream commit 639ed01](https://github.com/deepseek-ai/deepseek-harness/commit/639ed015397290b3745d163aafe02ffee4aa3f84)). Use Node.js **22.19+ (22.x) or 24+**. Harness 0.1 APIs are no longer supported by this checkout.
30
30
 
31
31
  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:
32
32
 
@@ -77,7 +77,7 @@ Model lists use the [StepFun list API](https://platform.stepfun.com/docs/zh/api-
77
77
 
78
78
  Each request is attributed to its actual message source, with request headers as a fallback for older logs. Request time determines date grouping and peak pricing. Token totals include uncached input, output, cache reads, and cache writes. Settings defaults to the selected provider, with an All providers option; the session view keeps mixed-provider history.
79
79
 
80
- Built-in prices currently cover official DeepSeek pricing only. StepFun and other requests without reliable historical pricing keep their token and request counts and show as unpriced. A similarly named DeepSeek model does not inherit official DeepSeek pricing on another provider. Entirely unpriced totals do not show $0; mixed totals include only known charges and carry a partial-cost label. Live account balances are separate from local usage estimates.
80
+ Built-in estimates cover official DeepSeek USD rates and verified StepFun mainland CNY reference rates. Requests without supported pricing keep their token and request counts and show as unpriced. A similarly named DeepSeek model does not inherit official DeepSeek pricing on another provider. Entirely unpriced totals do not show $0; mixed totals include only known charges and carry a partial-cost label. Live account balances are separate from local usage estimates.
81
81
 
82
82
  ## Extension and design
83
83
 
@@ -100,3 +100,19 @@ The preview uses no real credentials. Use `?lang=en&theme=dark` for English/dark
100
100
  [MIT](./LICENSE)
101
101
 
102
102
  <a href="https://www.buymeacoffee.com/pinkbanana"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Crazywoola a coffee" width="199" height="55" /></a>
103
+
104
+ ## Native usage page
105
+
106
+ 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.
107
+
108
+ 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.
109
+
110
+ Run `pnpm preview` and open `?page=usage` (or `?page=usage&lang=en&theme=dark`) to inspect the fixture page.
111
+
112
+ The activity punchcard groups requests by weekday and hour in the selected browser timezone. Dot area tracks request counts and follows provider/date filters, including DST repeated hours. Hover or use arrow keys for request/token details. Filters use themed, portaled listboxes with keyboard navigation, selection checks, Escape/outside-click dismissal, and typeahead.
113
+
114
+ ### v0.10.0 usage accounting
115
+
116
+ The conversation usage view has centered content, responsive padding and space for the composer. Cache input is counted once; duplicate settlements replace the previous sample, retries remain separate, and fork prefixes are excluded.
117
+
118
+ StepFun mainland API estimates use [official standard CNY rates](https://platform.stepfun.com/docs/zh/guides/pricing/details), verified on 2026-09-30, for `step-5-preview`, `step-3.7-flash`, `step-3.5-flash` and `step-3.5-flash-2603`. These reference estimates do not account for plans, discounts or unrecorded historical rate changes. USD and native CNY are shown separately; only an explicitly configured `usdToCny` rate enables a combined CNY total. Unknown rates remain unpriced. `?page=session` previews the conversation view with 124 StepFun requests.
Binary file
Binary file
Binary file
Binary file
Binary file