@pinkbanana/dsh-balance 0.8.1 → 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 +23 -6
- package/README_EN.md +32 -3
- package/docs/dsh-balance-settings.jpg +0 -0
- package/docs/dsh-models-settings.jpg +0 -0
- package/docs/dsh-session-usage-v0100.jpg +0 -0
- package/docs/dsh-usage-native.jpg +0 -0
- package/docs/dsh-usage-punchcard.jpg +0 -0
- package/lib/client.js +1311 -893
- package/lib/client.js.map +1 -1
- package/lib/index.js +159 -71
- package/lib/index.js.map +1 -1
- package/lib/types/billing.d.ts +32 -5
- package/lib/types/client/BalanceDock.d.ts +1 -1
- package/lib/types/client/BillingTab.d.ts +1 -1
- package/lib/types/client/Dropdown.d.ts +12 -0
- package/lib/types/client/Punchcard.d.ts +7 -0
- package/lib/types/client/UsagePage.d.ts +6 -0
- package/lib/types/client/index.d.ts +3 -2
- package/lib/types/client/locales.d.ts +14 -2
- package/lib/types/client/styles.d.ts +1 -1
- package/lib/types/index.d.ts +1 -1
- package/package.json +57 -40
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供方的可用模型和多维消费统计。API Key 仅由本机 Host 使用,不会发送到浏览器。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
界面使用 Harness 原生侧栏、主页面和主题变量。侧栏“插件”下方新增“用量统计”,独立查看所有对话的提供方、模型、会话和日期统计;默认显示全部提供方与全部时间,支持提供方和日期范围筛选。活动打卡图按浏览器时区的星期 × 24 小时汇总请求次数,圆点大小随次数变化;悬停或使用方向键可查看请求数与 token 明细。选择器采用主题化浮层菜单,支持方向键、Home/End、Enter、Escape 和按名称检索。设置页支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
|
|
8
8
|
|
|
9
9
|
聊天框底部会跟随当前会话所选的提供方与模型更新余额;设置页可独立切换提供方。
|
|
10
10
|
|
|
@@ -18,12 +18,27 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供
|
|
|
18
18
|
- 在设置页按所选 provider、模型、会话和日期查看实际 usage 消费,并在当前会话的“消费”Tab 查看请求明细
|
|
19
19
|
- 缺少 provider usage、未知 provider 或未知模型时标记为“未计费”,不进行 token 估算
|
|
20
20
|
- 日期按浏览器 IANA 时区分组;DeepSeek 峰谷价格始终按北京时间计算
|
|
21
|
-
-
|
|
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
|
+

|
|
28
|
+
|
|
29
|
+
## 兼容性
|
|
30
|
+
|
|
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 的接口。
|
|
32
|
+
|
|
33
|
+
也可在本地构建并打包源码,再用 `dsh plugin --profile web add /absolute/path/to/package.tgz` 安装生成的 `.tgz` 文件,随后重启 Harness:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pnpm install --frozen-lockfile
|
|
37
|
+
pnpm pack
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
消费统计通过新版只读会话句柄读取,以 `inheritedEventCount` 排除分叉继承的记录;会话页在 token 用量变化或一轮运行结束后刷新;统计页面每 15 秒检查更新,重新聚焦或返回页面时刷新,隐藏页面暂停查询。兼容 `assistant/message` 和重试/取消请求的 `assistant/attempt`,读取最后一条 stream usage,并以重试边界区分独立请求,同一次请求的重复结算仅计一次。
|
|
41
|
+
|
|
27
42
|
## 安装
|
|
28
43
|
|
|
29
44
|
```bash
|
|
@@ -33,7 +48,7 @@ dsh --profile web
|
|
|
33
48
|
|
|
34
49
|
打开 <http://127.0.0.1:3080/>,进入“设置 → 模型余额”。该入口位于“Agent 预设”下方,余额摘要也会显示在已有会话的聊天框下方。API Key 可在“设置 → 模型”中保存,或通过 `DEEPSEEK_API_KEY` 环境变量提供。
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
消费统计从已保存会话日志读取,包含当前运行会话已写入的记录,不展示 prompt 内容。可在插件配置中增加固定汇率,例如:
|
|
37
52
|
|
|
38
53
|
```yaml
|
|
39
54
|
usdToCny: 7.2
|
|
@@ -64,13 +79,15 @@ providers:
|
|
|
64
79
|
|
|
65
80
|
每条请求按实际返回消息的 provider / model 归属,兼容旧日志的请求头;日期和峰谷价格按该次请求时间计算。Token 总量包括未缓存输入、输出、缓存读取与缓存写入。设置页默认筛选所选 provider,也可选择“全部提供方”;会话页保留混用模型的完整历史。
|
|
66
81
|
|
|
67
|
-
|
|
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,显示“未计费”;混合统计注明费用不完整。账户余额是实时查询值,与本地用量估算独立。会话消费页采用居中内容宽度、响应式外边距,并为底部输入框保留空间。
|
|
68
85
|
|
|
69
86
|
## 扩展与设计
|
|
70
87
|
|
|
71
88
|
- `src/providers.ts` 保存可在前后端共享的 provider 元数据;`src/balance.ts` 的 adapter 表只负责端点与响应解析,传输、错误分类和缓存由公共逻辑处理。
|
|
72
89
|
- `GET /dsh-balance/api/balance?provider=StepFun` 查询 StepFun;省略 provider 保持 DeepSeek 兼容,`refresh=1` 绕过对应缓存。不支持的 provider 返回 `UNSUPPORTED_PROVIDER`。
|
|
73
|
-
-
|
|
90
|
+
- 通过原生 `sidebar.panellist` 与 `main` 插槽接入侧栏和主页面,菜单、选中态、侧栏折叠和页面导航由 Harness 管理;插件使用 Harness 的颜色、圆角和布局变量,支持深浅色主题与窄屏。
|
|
74
91
|
|
|
75
92
|
## 开发
|
|
76
93
|
|
|
@@ -80,7 +97,7 @@ pnpm check
|
|
|
80
97
|
pnpm preview
|
|
81
98
|
```
|
|
82
99
|
|
|
83
|
-
预览不使用真实密钥。可使用 `?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` 起提供。
|
|
84
101
|
|
|
85
102
|
## License
|
|
86
103
|
|
package/README_EN.md
CHANGED
|
@@ -18,12 +18,25 @@ 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
|
|
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
|
|
25
25
|
- Use the `DEEPSEEK_API_KEY` saved by Harness
|
|
26
26
|
|
|
27
|
+
## Compatibility
|
|
28
|
+
|
|
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
|
+
|
|
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
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm install --frozen-lockfile
|
|
35
|
+
pnpm pack
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
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
|
+
|
|
27
40
|
## Install
|
|
28
41
|
|
|
29
42
|
```bash
|
|
@@ -33,7 +46,7 @@ dsh --profile web
|
|
|
33
46
|
|
|
34
47
|
Open <http://127.0.0.1:3080/> and go to Settings → Model Balances. The panel sits directly below Agent presets, and the balance summary also appears below the composer in existing sessions. Save the API key in Settings → Models or provide it through the `DEEPSEEK_API_KEY` environment variable.
|
|
35
48
|
|
|
36
|
-
Usage statistics read
|
|
49
|
+
Usage statistics read persisted session logs, including writes visible from active sessions. Prompt content is never exposed. To show a fixed-rate CNY conversion, add for example:
|
|
37
50
|
|
|
38
51
|
```yaml
|
|
39
52
|
usdToCny: 7.2
|
|
@@ -64,7 +77,7 @@ Model lists use the [StepFun list API](https://platform.stepfun.com/docs/zh/api-
|
|
|
64
77
|
|
|
65
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.
|
|
66
79
|
|
|
67
|
-
Built-in
|
|
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.
|
|
68
81
|
|
|
69
82
|
## Extension and design
|
|
70
83
|
|
|
@@ -87,3 +100,19 @@ The preview uses no real credentials. Use `?lang=en&theme=dark` for English/dark
|
|
|
87
100
|
[MIT](./LICENSE)
|
|
88
101
|
|
|
89
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
|