@pinkbanana/dsh-balance 0.4.1 → 0.6.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
@@ -2,17 +2,23 @@
2
2
 
3
3
  [简体中文](./README.md) | [English](./README_EN.md)
4
4
 
5
- DeepSeek Harness 插件,用于查询 API 余额和当前可用模型。API Key 仅由本机 Host 使用,不会发送到浏览器。
5
+ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供方的可用模型和多维消费统计。API Key 仅由本机 Host 使用,不会发送到浏览器。
6
6
 
7
- ![DeepSeek 余额设置面板](./docs/dsh-balance-settings-v040.png)
7
+ 设置页采用账户总览布局,支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
8
8
 
9
9
  ![聊天框下方的 DeepSeek 余额](./docs/dsh-balance-composer-v040.png)
10
10
 
11
11
  ## 功能
12
12
 
13
- - 查看总余额、充值余额和赠送余额
14
- - 在聊天框下方持续显示余额摘要
15
- - 查看当前 API Key 可用的模型
13
+ - DeepSeek:查看总余额、充值余额和赠送余额
14
+ - StepFun:查看可用余额、总充值金额、总赠送金额及预付费 / 后付费账户类型
15
+ - 提供方独立缓存;支持大小写不敏感的 Provider ID
16
+ - 在聊天框下方持续显示 DeepSeek 余额摘要
17
+ - 从当前提供方的 `/models` 接口读取可用模型、所属组织与创建时间
18
+ - 在设置页按模型、会话和日期查看实际 usage 消费,并在当前会话的“消费”Tab 查看请求明细
19
+ - 缺少 provider usage、未知 provider 或未知模型时标记为“未计费”,不进行 token 估算
20
+ - 日期按浏览器 IANA 时区分组;DeepSeek 峰谷价格始终按北京时间计算
21
+ - 默认显示 USD;配置 `usdToCny` 后额外显示固定汇率换算的 CNY
16
22
  - 缓存查询结果并支持手动刷新
17
23
  - 依据 DeepSeek 峰谷定价,在高峰时段(北京时间 9:00–12:00、14:00–18:00)将聊天框下方的余额指示灯变为橙色
18
24
  - 原生支持简体中文和英文,并跟随 Harness 系统语言切换
@@ -25,15 +31,49 @@ dsh plugin --profile web add @pinkbanana/dsh-balance@latest
25
31
  dsh --profile web
26
32
  ```
27
33
 
28
- 打开 <http://127.0.0.1:3080/>,进入“设置 → DeepSeek 余额”。该入口位于“Agent 预设”下方,余额摘要也会显示在已有会话的聊天框下方。API Key 可在“设置 → 模型”中保存,或通过 `DEEPSEEK_API_KEY` 环境变量提供。
34
+ 打开 <http://127.0.0.1:3080/>,进入“设置 → 模型余额”。该入口位于“Agent 预设”下方,余额摘要也会显示在已有会话的聊天框下方。API Key 可在“设置 → 模型”中保存,或通过 `DEEPSEEK_API_KEY` 环境变量提供。
35
+
36
+ 消费统计从已保存会话和当前运行中的 live session 读取,不展示 prompt 内容。可在插件配置中增加固定汇率,例如:
37
+
38
+ ```yaml
39
+ usdToCny: 7.2
40
+ ```
41
+
42
+ ## StepFun 配置
43
+
44
+ 在“设置 → 模型”中添加自定义提供方,Provider ID 填写 `StepFun`(`stepfun`、`STEPFUN` 等大小写写法均可),保存 API Key。Harness 默认将其保存为 `STEPFUN_API_KEY`;也可以直接设置该环境变量。在“设置 → 模型余额”选择 StepFun 即可查询。
45
+
46
+ 按 [StepFun 账户 API](https://platform.stepfun.com/docs/zh/api-reference/accounts/get) 使用 Bearer 认证请求 `GET https://api.stepfun.com/v1/accounts`。金额按 CNY 展示;总充值 / 总赠送金额按文档展示为累计金额,不与当前余额相加。接口没有服务可用性字段,后付费账户不会因为余额为零或负数而显示“服务不可用”。
47
+
48
+ 若模型配置使用其他凭据引用,可在本插件配置中覆盖(`baseUrl` 是 API 前缀,StepFun 应包含 `/v1`):
49
+
50
+ ```yaml
51
+ providers:
52
+ - id: StepFun
53
+ apiKeyRef: MY_STEPFUN_KEY
54
+ baseUrl: https://api.stepfun.com/v1
55
+ ```
56
+
57
+ 已有的顶层 `apiKeyRef` / `baseUrl` 继续用于 DeepSeek;`providers` 覆盖对应提供方的余额与模型查询。配置不读取自定义模型的 Base URL,默认查询官方 API。可用模型随所选提供方切换,聊天框摘要仍属于 DeepSeek;消费统计保持原有定价覆盖,未支持的 StepFun 价格会标为未计费。
58
+
59
+ 模型列表按 [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` 强制刷新。
60
+
61
+ ## 扩展与设计
62
+
63
+ - `src/providers.ts` 保存可在前后端共享的 provider 元数据;`src/balance.ts` 的 adapter 表只负责端点与响应解析,传输、错误分类和缓存由公共逻辑处理。
64
+ - `GET /dsh-balance/api/balance?provider=StepFun` 查询 StepFun;省略 provider 保持 DeepSeek 兼容,`refresh=1` 绕过对应缓存。不支持的 provider 返回 `UNSUPPORTED_PROVIDER`。
65
+ - 排版参考 [Codrops 的 Kononenko 案例](https://tympanus.net/codrops/2026/09/18/kononenko-architectural-bureau/):大字号、留白、建筑式网格和几何线条,使用原创 CSS 实现;支持深浅色主题、窄屏与减少动态效果偏好。
29
66
 
30
67
  ## 开发
31
68
 
32
69
  ```bash
33
70
  pnpm install
34
71
  pnpm check
72
+ pnpm preview
35
73
  ```
36
74
 
75
+ 预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。
76
+
37
77
  ## License
38
78
 
39
79
  [MIT](./LICENSE)
package/README_EN.md CHANGED
@@ -2,17 +2,23 @@
2
2
 
3
3
  [简体中文](./README.md) | [English](./README_EN.md)
4
4
 
5
- A DeepSeek Harness plugin for checking API balances and available models. 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, available provider models, and multidimensional usage costs. The API key is used only by the local Host and is never sent to the browser.
6
6
 
7
- ![DeepSeek balance settings panel](./docs/dsh-balance-settings-v040.png)
7
+ The redesigned account ledger switches between DeepSeek and StepFun. Run `pnpm preview` to explore it with sample data.
8
8
 
9
9
  ![DeepSeek balance below the chat composer](./docs/dsh-balance-composer-v040.png)
10
10
 
11
11
  ## Features
12
12
 
13
- - View total, topped-up, and granted balances
14
- - Keep a compact balance summary below the chat composer
15
- - View models available to the current API key
13
+ - DeepSeek: total, topped-up, and granted balances
14
+ - StepFun: available balance, total cash credited, total vouchers granted, and prepaid / postpaid account type
15
+ - Independent provider caches and case-insensitive Provider IDs
16
+ - Keep a compact DeepSeek balance summary below the chat composer
17
+ - Fetch available models, owners, and creation dates from the selected provider’s `/models` API
18
+ - View actual usage costs by model, session, and day in Settings, plus request details in the current session's Usage tab
19
+ - Mark missing usage, unknown providers, and unknown models as unpriced without estimating tokens
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`
16
22
  - Cache query results with manual refresh support
17
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)
18
24
  - Native Simplified Chinese and English that follows the Harness system language
@@ -25,15 +31,49 @@ dsh plugin --profile web add @pinkbanana/dsh-balance@latest
25
31
  dsh --profile web
26
32
  ```
27
33
 
28
- Open <http://127.0.0.1:3080/> and go to Settings → DeepSeek Balance. 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.
34
+ 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
+
36
+ Usage statistics read saved sessions and prefer the current live session. Prompt content is never exposed. To show a fixed-rate CNY conversion, add for example:
37
+
38
+ ```yaml
39
+ usdToCny: 7.2
40
+ ```
41
+
42
+ ## StepFun setup
43
+
44
+ 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.
45
+
46
+ The [StepFun account API](https://platform.stepfun.com/docs/zh/api-reference/accounts/get) uses Bearer authentication at `GET https://api.stepfun.com/v1/accounts`. Amounts are shown in CNY. Cash and voucher totals are cumulative amounts as documented, not remaining balance components. The API does not report service availability, so a zero or negative postpaid balance is not labeled as unavailable service.
47
+
48
+ To use another credential reference, override the balance provider in this plugin's configuration (`baseUrl` is an API prefix; include `/v1` for StepFun):
49
+
50
+ ```yaml
51
+ providers:
52
+ - id: StepFun
53
+ apiKeyRef: MY_STEPFUN_KEY
54
+ baseUrl: https://api.stepfun.com/v1
55
+ ```
56
+
57
+ Existing top-level `apiKeyRef` / `baseUrl` settings continue to serve DeepSeek. The `providers` entries override both balance and model queries. Custom model base URLs are not read automatically; balance queries default to official APIs. Available models follow the selected provider; the composer summary remains DeepSeek-specific. Usage pricing coverage is unchanged; unsupported StepFun prices remain unpriced.
58
+
59
+ Model lists use the [StepFun list API](https://platform.stepfun.com/docs/zh/api-reference/models/list) at `GET /v1/models`, parsing `id`, `owned_by`, and `created` (Unix seconds) from each [Model object](https://platform.stepfun.com/docs/zh/api-reference/models/object). These fields are already returned in the list, so individual model retrieval is unnecessary. The Host route is `GET /dsh-balance/api/models?provider=StepFun`, with isolated provider caches and `refresh=1` to force a refresh.
60
+
61
+ ## Extension and design
62
+
63
+ - `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.
64
+ - `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`.
65
+ - 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.
29
66
 
30
67
  ## Development
31
68
 
32
69
  ```bash
33
70
  pnpm install
34
71
  pnpm check
72
+ pnpm preview
35
73
  ```
36
74
 
75
+ 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. StepFun balance and model queries and the redesigned account page are available starting with `0.6.0`.
76
+
37
77
  ## License
38
78
 
39
79
  [MIT](./LICENSE)