@pinkbanana/dsh-balance 0.6.0 → 0.7.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 +33 -7
- package/README_EN.md +33 -7
- package/lib/client.js +196 -99
- package/lib/client.js.map +1 -1
- package/lib/index.js +104 -38
- package/lib/index.js.map +1 -1
- package/lib/types/balance.d.ts +1 -0
- package/lib/types/billing.d.ts +3 -2
- package/lib/types/client/BalanceDock.d.ts +9 -2
- package/lib/types/client/BillingTab.d.ts +5 -2
- package/lib/types/client/locales.d.ts +6 -2
- package/lib/types/client/styles.d.ts +1 -1
- package/lib/types/index.d.ts +4 -2
- package/lib/types/providers.d.ts +19 -0
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -2,20 +2,21 @@
|
|
|
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 / Tokener API 余额、各提供方的可用模型和多维消费统计。API Key 仅由本机 Host 使用,不会发送到浏览器。
|
|
6
6
|
|
|
7
|
-
设置页采用账户总览布局,支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
|
|
7
|
+
设置页采用账户总览布局,支持 DeepSeek / StepFun / Tokener 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
聊天框底部会跟随当前会话所选的提供方与模型更新余额;设置页可独立切换提供方。
|
|
10
10
|
|
|
11
11
|
## 功能
|
|
12
12
|
|
|
13
13
|
- DeepSeek:查看总余额、充值余额和赠送余额
|
|
14
14
|
- StepFun:查看可用余额、总充值金额、总赠送金额及预付费 / 后付费账户类型
|
|
15
|
+
- Tokener:查看美元可用余额、充值余额与赠送余额;余额使用管理令牌,模型列表使用 API Key
|
|
15
16
|
- 提供方独立缓存;支持大小写不敏感的 Provider ID
|
|
16
|
-
-
|
|
17
|
+
- 在聊天框下方显示当前 provider、模型和余额,兼容模型选择器与 `/model` 切换
|
|
17
18
|
- 从当前提供方的 `/models` 接口读取可用模型、所属组织与创建时间
|
|
18
|
-
-
|
|
19
|
+
- 在设置页按所选 provider、模型、会话和日期查看实际 usage 消费,并在当前会话的“消费”Tab 查看请求明细
|
|
19
20
|
- 缺少 provider usage、未知 provider 或未知模型时标记为“未计费”,不进行 token 估算
|
|
20
21
|
- 日期按浏览器 IANA 时区分组;DeepSeek 峰谷价格始终按北京时间计算
|
|
21
22
|
- 默认显示 USD;配置 `usdToCny` 后额外显示固定汇率换算的 CNY
|
|
@@ -54,10 +55,35 @@ providers:
|
|
|
54
55
|
baseUrl: https://api.stepfun.com/v1
|
|
55
56
|
```
|
|
56
57
|
|
|
57
|
-
已有的顶层 `apiKeyRef` / `baseUrl` 继续用于 DeepSeek;`providers` 覆盖对应提供方的余额与模型查询。配置不读取自定义模型的 Base URL,默认查询官方 API
|
|
58
|
+
已有的顶层 `apiKeyRef` / `baseUrl` 继续用于 DeepSeek;`providers` 覆盖对应提供方的余额与模型查询。配置不读取自定义模型的 Base URL,默认查询官方 API。余额、可用模型与设置页统计随所选提供方切换。聊天框摘要使用当前会话的实时选择;会话“消费”保留该会话历史上所有 provider 的用量。
|
|
58
59
|
|
|
59
60
|
模型列表按 [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
|
+
## Tokener 配置
|
|
63
|
+
|
|
64
|
+
在“设置 → 模型”添加自定义提供方,Provider ID 为 `Tokener`(大小写不限),Base URL 为 `https://api.tokener.ai/v1`,保存 API Key(默认凭据 `TOKENER_API_KEY`)。模型列表请求 `GET /v1/models`。
|
|
65
|
+
|
|
66
|
+
余额使用独立的个人访问令牌(PAT),请在 Tokener 账户设置创建后,将 `TOKENER_MANAGEMENT_TOKEN` 配置到启动 Harness 的环境或凭据存储中。**模型 API Key 不能替代此令牌。** 默认余额端点为 `GET https://console.tokener.ai/api/v1/billing/balance`,使用 Bearer 认证。金额从美元整数微单位精确转换,充值与赠送字段均为剩余余额。
|
|
67
|
+
|
|
68
|
+
自定义凭据或自托管环境可分别覆盖:
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
providers:
|
|
72
|
+
- id: Tokener
|
|
73
|
+
apiKeyRef: MY_TOKENER_API_KEY
|
|
74
|
+
baseUrl: https://api.tokener.ai/v1
|
|
75
|
+
balanceApiKeyRef: MY_TOKENER_PAT
|
|
76
|
+
balanceBaseUrl: https://console.tokener.ai/api/v1
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Tokener 的 `apiKeyRef` / `baseUrl` 只用于模型接口;余额默认独立,避免把管理令牌发往推理端点。接入依据 [Tokener 文档](https://www.tokener.ai/zh/docs)、[官方余额路由](https://github.com/langgenius/ai-gateway/blob/main/apps/console/src/app/api/v1/billing/balance/route.ts) 与[响应字段](https://github.com/langgenius/ai-gateway/blob/main/apps/console/src/server/billing.ts)。
|
|
80
|
+
|
|
81
|
+
## 统计口径
|
|
82
|
+
|
|
83
|
+
每条请求按实际返回消息的 provider / model 归属,兼容旧日志的请求头;日期和峰谷价格按该次请求时间计算。Token 总量包括未缓存输入、输出、缓存读取与缓存写入。设置页默认筛选所选 provider,也可选择“全部提供方”;会话页保留混用模型的完整历史。
|
|
84
|
+
|
|
85
|
+
当前内置价格仅覆盖 DeepSeek 官方定价。StepFun、Tokener 等没有可靠历史价格的数据保留请求数与 token,显示“未计费”;不会套用同名 DeepSeek 模型价格,也不会将全部未知费用显示为 $0。混合统计仅累加已知价格,并注明不完整。账户余额是实时查询值,与本地用量估算独立。
|
|
86
|
+
|
|
61
87
|
## 扩展与设计
|
|
62
88
|
|
|
63
89
|
- `src/providers.ts` 保存可在前后端共享的 provider 元数据;`src/balance.ts` 的 adapter 表只负责端点与响应解析,传输、错误分类和缓存由公共逻辑处理。
|
|
@@ -72,7 +98,7 @@ pnpm check
|
|
|
72
98
|
pnpm preview
|
|
73
99
|
```
|
|
74
100
|
|
|
75
|
-
预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading`
|
|
101
|
+
预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。Tokener、实时模型余额和统计修复自 `0.7.0` 起提供。
|
|
76
102
|
|
|
77
103
|
## License
|
|
78
104
|
|
package/README_EN.md
CHANGED
|
@@ -2,20 +2,21 @@
|
|
|
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 / Tokener 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
|
-
The redesigned account ledger switches between DeepSeek and
|
|
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
|
|
|
11
11
|
## Features
|
|
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: available USD, purchased and granted balances, with separate management and inference credentials
|
|
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
|
|
18
|
-
- View actual usage costs by model, session, and day in Settings, plus request details in the current session's Usage tab
|
|
19
|
+
- View actual usage costs by selected provider, model, session, and day in Settings, plus request details in the current session's Usage tab
|
|
19
20
|
- Mark missing usage, unknown providers, and unknown models as unpriced without estimating tokens
|
|
20
21
|
- Group dates in the browser's IANA timezone while applying DeepSeek peak pricing in Beijing time
|
|
21
22
|
- Show USD by default, with optional fixed-rate CNY conversion through `usdToCny`
|
|
@@ -54,10 +55,35 @@ providers:
|
|
|
54
55
|
baseUrl: https://api.stepfun.com/v1
|
|
55
56
|
```
|
|
56
57
|
|
|
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.
|
|
58
|
+
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. Balances, models, and Settings usage follow the selected provider. The composer follows the live session selection; the session Usage tab preserves historical usage across all providers.
|
|
58
59
|
|
|
59
60
|
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
|
|
|
62
|
+
## Tokener setup
|
|
63
|
+
|
|
64
|
+
Add a custom provider with ID `Tokener` (case-insensitive), base URL `https://api.tokener.ai/v1`, and its inference API key (default reference `TOKENER_API_KEY`). Available models are read from `GET /v1/models`.
|
|
65
|
+
|
|
66
|
+
For balances, create a personal access token (PAT) in Tokener account settings and configure `TOKENER_MANAGEMENT_TOKEN` in the Harness launch environment or credential store. **An inference API key cannot replace this token.** Balances use Bearer authentication at `GET https://console.tokener.ai/api/v1/billing/balance`. Integer USD millionths are converted exactly; purchased and granted amounts are remaining balances.
|
|
67
|
+
|
|
68
|
+
Override credentials or self-hosted endpoints separately:
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
providers:
|
|
72
|
+
- id: Tokener
|
|
73
|
+
apiKeyRef: MY_TOKENER_API_KEY
|
|
74
|
+
baseUrl: https://api.tokener.ai/v1
|
|
75
|
+
balanceApiKeyRef: MY_TOKENER_PAT
|
|
76
|
+
balanceBaseUrl: https://console.tokener.ai/api/v1
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Tokener’s inference overrides do not change its management credentials or endpoint. See [Tokener documentation](https://www.tokener.ai/zh/docs), the [official balance route](https://github.com/langgenius/ai-gateway/blob/main/apps/console/src/app/api/v1/billing/balance/route.ts), and [response fields](https://github.com/langgenius/ai-gateway/blob/main/apps/console/src/server/billing.ts).
|
|
80
|
+
|
|
81
|
+
## Usage accounting
|
|
82
|
+
|
|
83
|
+
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.
|
|
84
|
+
|
|
85
|
+
Built-in prices currently cover official DeepSeek pricing only. StepFun, Tokener, 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.
|
|
86
|
+
|
|
61
87
|
## Extension and design
|
|
62
88
|
|
|
63
89
|
- `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.
|
|
@@ -72,7 +98,7 @@ pnpm check
|
|
|
72
98
|
pnpm preview
|
|
73
99
|
```
|
|
74
100
|
|
|
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`.
|
|
101
|
+
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`. Tokener support, live model balances, and usage accounting fixes are available starting with `0.7.0`.
|
|
76
102
|
|
|
77
103
|
## License
|
|
78
104
|
|