@pinkbanana/dsh-balance 0.11.0 → 0.12.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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [简体中文](./README.md) | [English](./README_EN.md)
4
4
 
5
- DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供方的可用模型和多维消费统计。API Key 仅由本机 Host 使用,不会发送到浏览器。
5
+ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额,以及 DeepSeek / StepFun / Tokener 的可用模型和多维消费统计。API Key 仅由本机 Host 使用,不会发送到浏览器。
6
6
 
7
- 界面使用 Harness 原生侧栏、主页面和主题变量。侧栏“插件”下方新增“用量统计”,独立查看所有对话的提供方、模型、会话和日期统计;默认显示全部提供方与全部时间,支持提供方和日期范围筛选。活动打卡图按浏览器时区的星期 × 24 小时汇总请求次数,圆点大小随次数变化;悬停或使用方向键可查看请求数与 token 明细。选择器采用主题化浮层菜单,支持方向键、Home/End、Enter、Escape 和按名称检索。设置页支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
7
+ 界面使用 Harness 原生侧栏、主页面和主题变量。侧栏“插件”下方新增“用量统计”,独立查看所有对话的提供方、模型、会话和日期统计;默认显示全部提供方与全部时间,支持提供方和日期范围筛选。活动打卡图按浏览器时区的星期 × 24 小时汇总请求次数,圆点大小随次数变化;悬停或使用方向键可查看请求数与 token 明细。选择器采用主题化浮层菜单,支持方向键、Home/End、Enter、Escape 和按名称检索。设置页支持 DeepSeek / StepFun / Tokener 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
8
8
 
9
9
  聊天框底部会跟随当前会话所选的提供方与模型更新余额;设置页可独立切换提供方。
10
10
 
@@ -12,6 +12,7 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供
12
12
 
13
13
  - DeepSeek:查看总余额、充值余额和赠送余额
14
14
  - StepFun:查看可用余额、总充值金额、总赠送金额及预付费 / 后付费账户类型
15
+ - Tokener:按提供方、模型、会话、日期统计本地请求和 token,以公开目录价估算美元费用;通过官方 `/v1/models` 查询模型
15
16
  - 提供方独立缓存;支持大小写不敏感的 Provider ID
16
17
  - 在聊天框下方显示当前 provider、模型和余额,兼容模型选择器与 `/model` 切换
17
18
  - 从当前提供方的 `/models` 接口读取可用模型、所属组织与创建时间
@@ -28,7 +29,9 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供
28
29
 
29
30
  ## 兼容性
30
31
 
31
- 0.11.0 适配 DeepSeek Harness **0.2.1-rc.2**([上游版本](https://github.com/deepseek-ai/deepseek-harness/releases/tag/dsh-v0.2.1-rc.2)),需要 Node.js **22.19+(22.x)或 24+**。所有 DSH peer 依赖和开发依赖均锁定为 `0.2.1-rc.2`。Harness `0.2.0-rc.2` 用户请继续使用插件 `0.10.2`;本次源码不再兼容 Harness 0.1 的接口。
32
+ 0.12.1 适配 DeepSeek Harness **0.2.1-rc.5**([上游版本](https://github.com/deepseek-ai/deepseek-harness/releases/tag/dsh-v0.2.1-rc.5)),需要 Node.js **22.19+(22.x)或 24+**。所有 DSH peer 依赖和开发依赖均锁定为 `0.2.1-rc.5`。Harness `0.2.0-rc.2` 用户请继续使用插件 `0.10.2`;本次源码不再兼容 Harness 0.1 的接口。
33
+
34
+ 新版 dsh 会在安装及启动时校验插件兼容版本。旧插件锁定 `rc.2`,会被 `rc.5` 拒绝加载;请升级到插件 `0.12.1`,无需添加版本豁免。仍使用 dsh `0.2.1-rc.2` 的用户请保留插件 `0.11.0`。
32
35
 
33
36
  也可在本地构建并打包源码,再用 `dsh plugin --profile web add /absolute/path/to/package.tgz` 安装生成的 `.tgz` 文件,随后重启 Harness:
34
37
 
@@ -39,7 +42,9 @@ pnpm pack
39
42
 
40
43
  消费统计通过新版只读会话句柄读取,以 `inheritedEventCount` 排除分叉继承的记录;会话页在 token 用量变化或一轮运行结束后刷新;统计页面每 15 秒检查更新,重新聚焦或返回页面时刷新,隐藏页面暂停查询。兼容 `assistant/message` 和重试/取消请求的 `assistant/attempt`,读取最后一条 stream usage,并以重试边界区分独立请求,同一次请求的重复结算仅计一次。
41
44
 
42
- 全局统计会跳过当前 dsh 无法读取的旧格式或损坏会话,并显示未纳入统计的会话数量;其余会话仍正常统计。部分读取结果不缓存,下次刷新会重试。单个会话无法读取或所有会话都读取失败时,仍明确显示读取错误,不将失败记录当作零消费。
45
+ 全局统计会跳过当前 dsh 无法读取的旧格式或损坏会话,并显示未纳入统计的会话数量;其余会话仍正常统计。部分汇总结果不缓存,下次刷新会重试失败会话;已成功读取且 revision 未变化的会话复用精简用量记录。单个会话无法读取或所有会话都读取失败时,仍明确显示读取错误,不将失败记录当作零消费。
46
+
47
+ 自 `0.12.1` 起,统计查询逐个读取会话,提取请求用量后即释放完整日志;所有请求共享读取队列,同一会话的并发读取合并。缓存仅保留用量与标题,不保留消息或工具输出。切换提供方、日期范围或重复刷新不再同时加载多份完整历史,避免大量会话引起堆内存耗尽。手动强制刷新会重新读取日志。
43
48
 
44
49
  分类明细采用带数量的 Tab 面板,在模型、提供方、会话和日期之间切换;窄屏自动改用主题化选择器。每页默认 10 条,可选择 5 / 10 / 20 条。会话消费页分别查看模型汇总与请求明细,请求支持模型筛选。长名称省略显示,悬停保留完整名称。
45
50
 
@@ -48,6 +53,7 @@ pnpm pack
48
53
  ## 安装
49
54
 
50
55
  ```bash
56
+ npm install -g @deepseek-ai/dsh@latest
51
57
  dsh plugin --profile web add @pinkbanana/dsh-balance@latest
52
58
  dsh --profile web
53
59
  ```
@@ -81,6 +87,23 @@ providers:
81
87
 
82
88
  模型列表按 [StepFun 列表 API](https://platform.stepfun.com/docs/zh/api-reference/models/list) 请求 `GET /v1/models`,解析 [Model 对象](https://platform.stepfun.com/docs/zh/api-reference/models/object) 的 `id`、`owned_by`、`created`(秒级 Unix 时间戳)。列表已包含这些信息,不需要逐个调用单模型详情接口。Host 路由为 `GET /dsh-balance/api/models?provider=StepFun`,模型缓存按 provider 隔离,`refresh=1` 强制刷新。
83
89
 
90
+ ## Tokener 配置与统计
91
+
92
+ 在“设置 → 模型”中添加自定义提供方,Provider ID 使用 `Tokener`(大小写不限,也支持 `tokener.ai`),Base URL 使用 `https://api.tokener.ai/v1`,并保存 API Key。插件默认使用 `TOKENER_API_KEY`,也支持 `providers` 配置覆盖:
93
+
94
+ ```yaml
95
+ providers:
96
+ - id: tokener
97
+ apiKeyRef: TOKENER_API_KEY
98
+ baseUrl: https://api.tokener.ai/v1
99
+ ```
100
+
101
+ 根据 [Tokener API 文档](https://www.tokener.ai/zh/docs/reference/api-endpoint),可用模型由 Host 使用 Bearer 认证查询 `/v1/models`,密钥不发送到浏览器。文档没有公开 API Key 可访问的余额或组织用量接口,因此设置页提供控制台入口,聊天框提示查看“用量统计”,不尝试未知端点。
102
+
103
+ 统计仅覆盖当前 dsh 保存的本地会话,不包含其他客户端或整个组织的调用,也不提供 API Key 维度。请求数、输入、输出、缓存读取与缓存写入按 dsh 标准化的 usage 统计;缓存读取已从标准化输入中拆出,不重复计数。支持提供方、模型、会话、日期和活动时段明细,提供方别名统一归为 Tokener。
104
+
105
+ 内置 2026-11-03 核验的 [Tokener 模型目录](https://www.tokener.ai/zh/models) 对话/推理模型美元参考价,逐个匹配完整模型 ID。使用 Tokener 目录价格,不套用原厂价格或 DeepSeek 峰谷倍率。参考价快照同样用于已有历史记录的估算,不代表历史实际扣款。未知模型、缺少 usage,以及包含未公开价格的缓存写入请求,保留请求数与 token 并标为“未计费”。账户余额、折扣和实际消费以 [Tokener 控制台](https://console.tokener.ai) 为准。
106
+
84
107
  ## 统计口径
85
108
 
86
109
  每条请求按实际返回消息的 provider / model 归属,兼容旧日志的请求头;日期和峰谷价格按该次请求时间计算。Token 总量包括未缓存输入、输出、缓存读取与缓存写入。设置页默认筛选所选 provider,也可选择“全部提供方”;会话页保留混用模型的完整历史。
package/README_EN.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [简体中文](./README.md) | [English](./README_EN.md)
4
4
 
5
- A DeepSeek Harness plugin for checking DeepSeek / StepFun API balances, available provider models, and multidimensional usage costs. The API key is used only by the local Host and is never sent to the browser.
5
+ A DeepSeek Harness plugin for checking DeepSeek / StepFun API balances, plus available models and multidimensional usage costs for DeepSeek / StepFun / Tokener. The API key is used only by the local Host and is never sent to the browser.
6
6
 
7
- The redesigned account ledger switches between DeepSeek and StepFun. Run `pnpm preview` to explore it with sample data.
7
+ The redesigned account ledger switches between DeepSeek, StepFun, and Tokener. Run `pnpm preview` to explore it with sample data.
8
8
 
9
9
  The composer readout follows the current session’s provider and model. The Settings provider selection is independent.
10
10
 
@@ -12,6 +12,7 @@ The composer readout follows the current session’s provider and model. The Set
12
12
 
13
13
  - DeepSeek: total, topped-up, and granted balances
14
14
  - StepFun: available balance, total cash credited, total vouchers granted, and prepaid / postpaid account type
15
+ - Tokener: local requests/tokens grouped by provider, model, session and date, USD estimates from its published catalog, and models from `/v1/models`
15
16
  - Independent provider caches and case-insensitive Provider IDs
16
17
  - Show the current provider, model, and balance below the composer, following both the selector and `/model`
17
18
  - Fetch available models, owners, and creation dates from the selected provider’s `/models` API
@@ -26,7 +27,7 @@ The composer readout follows the current session’s provider and model. The Set
26
27
 
27
28
  ## Compatibility
28
29
 
29
- Version 0.11.0 targets DeepSeek Harness **0.2.1-rc.2** ([upstream release](https://github.com/deepseek-ai/deepseek-harness/releases/tag/dsh-v0.2.1-rc.2)). Use Node.js **22.19+ (22.x) or 24+**. All DSH peer and development dependencies are pinned to `0.2.1-rc.2`. Harness `0.2.0-rc.2` users should keep plugin `0.10.2`; Harness 0.1 APIs are no longer supported by this checkout.
30
+ Version 0.12.1 targets DeepSeek Harness **0.2.1-rc.5** ([upstream release](https://github.com/deepseek-ai/deepseek-harness/releases/tag/dsh-v0.2.1-rc.5)). Use Node.js **22.19+ (22.x) or 24+**. All DSH peer and development dependencies are pinned to `0.2.1-rc.5`. Harness `0.2.0-rc.2` users should keep plugin `0.10.2`; Harness 0.1 APIs are no longer supported by this checkout.
30
31
 
31
32
  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
33
 
@@ -37,15 +38,18 @@ pnpm pack
37
38
 
38
39
  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.
39
40
 
40
- 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 results are retried on the next refresh without caching. An unreadable selected session, or a collection where every session fails to read, still reports an error instead of showing zero usage.
41
+ 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.
41
42
 
42
43
  Usage breakdowns use counted tabs for models, providers, sessions, and dates, with a themed category selector on narrow screens. Lists default to 10 rows per page, with 5 / 10 / 20 options. The conversation page separates model summaries and requests, and requests can be filtered by model. Long names are truncated with their full value available on hover.
43
44
 
44
45
  ![Tabbed breakdown and pagination](./docs/dsh-usage-tabs.jpg)
45
46
 
47
+ Since `0.12.1`, usage queries read one session log at a time across all HTTP requests, extract compact request metadata, and release the full log before continuing. Concurrent reads of the same session are shared. Unchanged successful sessions reuse revision-keyed usage records even when another session is unreadable; explicit refresh re-reads logs. Cached records exclude message bodies and tool output, preventing full-history retention and overlapping scans from exhausting the JavaScript heap.
48
+
46
49
  ## Install
47
50
 
48
51
  ```bash
52
+ npm install -g @deepseek-ai/dsh@latest
49
53
  dsh plugin --profile web add @pinkbanana/dsh-balance@latest
50
54
  dsh --profile web
51
55
  ```
@@ -60,6 +64,25 @@ usdToCny: 7.2
60
64
 
61
65
  Both the official provider ID `deepseek-official` and legacy `deepseek` are supported case-insensitively and share DeepSeek credentials, balance caches, and model caches. The composer retains the actual model ID, such as `deepseek-flash`; new models with unknown pricing remain unpriced.
62
66
 
67
+ ## Tokener configuration and usage
68
+
69
+ Add a custom provider in Settings → Models with ID `Tokener` (case-insensitive; `tokener.ai` is also accepted), base URL `https://api.tokener.ai/v1`, and your API key. The default credential reference is `TOKENER_API_KEY`; it can be overridden:
70
+
71
+ ```yaml
72
+ providers:
73
+ - id: tokener
74
+ apiKeyRef: TOKENER_API_KEY
75
+ baseUrl: https://api.tokener.ai/v1
76
+ ```
77
+
78
+ The Host queries the documented `GET /v1/models` with Bearer authentication; credentials never reach the browser. [Tokener's API documentation](https://www.tokener.ai/zh/docs/reference/api-endpoint) does not publish an API-key balance or organization-usage endpoint. Settings link to the console, and the composer points to Usage Statistics without querying an undocumented endpoint.
79
+
80
+ 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.
81
+
82
+ 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).
83
+
84
+ New dsh versions validate compatibility before installation and startup. Plugin `0.11.0` declares `rc.2` peers and is rejected on `rc.5`; upgrade to `0.12.1` without a version exemption. Keep plugin `0.11.0` if you remain on dsh `0.2.1-rc.2`.
85
+
63
86
  ## StepFun setup
64
87
 
65
88
  Add a custom provider in Settings → Models with Provider ID `StepFun` (`stepfun`, `STEPFUN`, and other case variants work) and save its API key. Harness derives the credential reference `STEPFUN_API_KEY`; setting that environment variable also works. Select StepFun in Settings → Model Balances.