@pinkbanana/dsh-balance 0.7.0 → 0.8.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 +4 -24
- package/README_EN.md +4 -24
- package/lib/client.js +12 -25
- package/lib/client.js.map +1 -1
- package/lib/index.js +25 -77
- package/lib/index.js.map +1 -1
- package/lib/types/balance.d.ts +0 -1
- package/lib/types/client/locales.d.ts +0 -1
- package/lib/types/index.d.ts +2 -4
- package/lib/types/providers.d.ts +0 -19
- package/package.json +1 -2
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
|
|
5
|
+
DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供方的可用模型和多维消费统计。API Key 仅由本机 Host 使用,不会发送到浏览器。
|
|
6
6
|
|
|
7
|
-
设置页采用账户总览布局,支持 DeepSeek / StepFun
|
|
7
|
+
设置页采用账户总览布局,支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
|
|
8
8
|
|
|
9
9
|
聊天框底部会跟随当前会话所选的提供方与模型更新余额;设置页可独立切换提供方。
|
|
10
10
|
|
|
@@ -12,7 +12,6 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun / Tokener API 余额
|
|
|
12
12
|
|
|
13
13
|
- DeepSeek:查看总余额、充值余额和赠送余额
|
|
14
14
|
- StepFun:查看可用余额、总充值金额、总赠送金额及预付费 / 后付费账户类型
|
|
15
|
-
- Tokener:查看美元可用余额、充值余额与赠送余额;余额使用管理令牌,模型列表使用 API Key
|
|
16
15
|
- 提供方独立缓存;支持大小写不敏感的 Provider ID
|
|
17
16
|
- 在聊天框下方显示当前 provider、模型和余额,兼容模型选择器与 `/model` 切换
|
|
18
17
|
- 从当前提供方的 `/models` 接口读取可用模型、所属组织与创建时间
|
|
@@ -59,30 +58,11 @@ providers:
|
|
|
59
58
|
|
|
60
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` 强制刷新。
|
|
61
60
|
|
|
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
61
|
## 统计口径
|
|
82
62
|
|
|
83
63
|
每条请求按实际返回消息的 provider / model 归属,兼容旧日志的请求头;日期和峰谷价格按该次请求时间计算。Token 总量包括未缓存输入、输出、缓存读取与缓存写入。设置页默认筛选所选 provider,也可选择“全部提供方”;会话页保留混用模型的完整历史。
|
|
84
64
|
|
|
85
|
-
当前内置价格仅覆盖 DeepSeek 官方定价。StepFun
|
|
65
|
+
当前内置价格仅覆盖 DeepSeek 官方定价。StepFun 等没有可靠历史价格的数据保留请求数与 token,显示“未计费”;不会套用同名 DeepSeek 模型价格,也不会将全部未知费用显示为 $0。混合统计仅累加已知价格,并注明不完整。账户余额是实时查询值,与本地用量估算独立。
|
|
86
66
|
|
|
87
67
|
## 扩展与设计
|
|
88
68
|
|
|
@@ -98,7 +78,7 @@ pnpm check
|
|
|
98
78
|
pnpm preview
|
|
99
79
|
```
|
|
100
80
|
|
|
101
|
-
预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换。StepFun 余额与模型查询、新版账户页面自 `0.6.0`
|
|
81
|
+
预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。实时模型余额和统计修复自 `0.7.0` 起提供。
|
|
102
82
|
|
|
103
83
|
## License
|
|
104
84
|
|
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
|
|
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
|
-
The redesigned account ledger switches between DeepSeek
|
|
7
|
+
The redesigned account ledger switches between DeepSeek and StepFun. 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,7 +12,6 @@ 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: available USD, purchased and granted balances, with separate management and inference credentials
|
|
16
15
|
- Independent provider caches and case-insensitive Provider IDs
|
|
17
16
|
- Show the current provider, model, and balance below the composer, following both the selector and `/model`
|
|
18
17
|
- Fetch available models, owners, and creation dates from the selected provider’s `/models` API
|
|
@@ -59,30 +58,11 @@ Existing top-level `apiKeyRef` / `baseUrl` settings continue to serve DeepSeek.
|
|
|
59
58
|
|
|
60
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.
|
|
61
60
|
|
|
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
61
|
## Usage accounting
|
|
82
62
|
|
|
83
63
|
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
64
|
|
|
85
|
-
Built-in prices currently cover official DeepSeek pricing only. StepFun
|
|
65
|
+
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.
|
|
86
66
|
|
|
87
67
|
## Extension and design
|
|
88
68
|
|
|
@@ -98,7 +78,7 @@ pnpm check
|
|
|
98
78
|
pnpm preview
|
|
99
79
|
```
|
|
100
80
|
|
|
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`.
|
|
81
|
+
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`. Live model balances, and usage accounting fixes are available starting with `0.7.0`.
|
|
102
82
|
|
|
103
83
|
## License
|
|
104
84
|
|
package/lib/client.js
CHANGED
|
@@ -14,28 +14,17 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/providers.ts
|
|
16
16
|
/** Browser-safe provider metadata. Credentials and wire parsers stay on the Host. */
|
|
17
|
-
const BALANCE_PROVIDERS = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
baseUrl: "https://api.stepfun.com/v1"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id: "tokener",
|
|
32
|
-
name: "Tokener",
|
|
33
|
-
apiKeyRef: "TOKENER_API_KEY",
|
|
34
|
-
baseUrl: "https://api.tokener.ai/v1",
|
|
35
|
-
balanceApiKeyRef: "TOKENER_MANAGEMENT_TOKEN",
|
|
36
|
-
balanceBaseUrl: "https://console.tokener.ai/api/v1"
|
|
37
|
-
}
|
|
38
|
-
];
|
|
17
|
+
const BALANCE_PROVIDERS = [{
|
|
18
|
+
id: "deepseek",
|
|
19
|
+
name: "DeepSeek",
|
|
20
|
+
apiKeyRef: "DEEPSEEK_API_KEY",
|
|
21
|
+
baseUrl: "https://api.deepseek.com"
|
|
22
|
+
}, {
|
|
23
|
+
id: "stepfun",
|
|
24
|
+
name: "StepFun",
|
|
25
|
+
apiKeyRef: "STEPFUN_API_KEY",
|
|
26
|
+
baseUrl: "https://api.stepfun.com/v1"
|
|
27
|
+
}];
|
|
39
28
|
function findBalanceProvider(id) {
|
|
40
29
|
return BALANCE_PROVIDERS.find((provider) => provider.id === id.trim().toLowerCase());
|
|
41
30
|
}
|
|
@@ -260,7 +249,6 @@ window.__ModuleLoader__.load({
|
|
|
260
249
|
"balance.prepaid": "预付费账户",
|
|
261
250
|
"balance.postpaid": "后付费账户",
|
|
262
251
|
"balance.totalsNote": "总充值与总赠送金额为账户累计金额,不代表当前剩余余额;账户类型不表示服务可用状态。",
|
|
263
|
-
"balance.setupTokener": "在 Tokener 账户设置创建个人访问令牌(PAT),配置为 TOKENER_MANAGEMENT_TOKEN;模型列表使用独立的 TOKENER_API_KEY。自定义凭据请配置 balanceApiKeyRef 与 apiKeyRef。",
|
|
264
252
|
"balance.setupDeepSeek": "在“设置 → 模型”保存 DeepSeek API 密钥,或配置 {ref} 环境变量。",
|
|
265
253
|
"balance.setup": "在“设置 → 模型”添加自定义提供方,Provider ID 填写 {provider}(大小写不限),并保存 API 密钥。默认凭据为 {ref};自定义凭据请检查插件配置。",
|
|
266
254
|
"error.UNSUPPORTED_PROVIDER": "暂不支持此提供方的余额查询",
|
|
@@ -364,7 +352,6 @@ window.__ModuleLoader__.load({
|
|
|
364
352
|
"balance.prepaid": "Prepaid account",
|
|
365
353
|
"balance.postpaid": "Postpaid account",
|
|
366
354
|
"balance.totalsNote": "Cash and voucher totals are cumulative amounts, not remaining balances. Account type does not indicate service availability.",
|
|
367
|
-
"balance.setupTokener": "Create a personal access token (PAT) in Tokener account settings and configure TOKENER_MANAGEMENT_TOKEN. Models use a separate TOKENER_API_KEY. Set balanceApiKeyRef and apiKeyRef for custom credentials.",
|
|
368
355
|
"balance.setupDeepSeek": "Save your DeepSeek API key in Settings → Models, or set the {ref} environment variable.",
|
|
369
356
|
"balance.setup": "Add a custom provider in Settings → Models with Provider ID {provider} (case-insensitive), then save your API key. The default credential is {ref}; check plugin configuration for custom references.",
|
|
370
357
|
"error.UNSUPPORTED_PROVIDER": "Balance queries are not supported for this provider",
|
|
@@ -562,7 +549,7 @@ window.__ModuleLoader__.load({
|
|
|
562
549
|
providerName,
|
|
563
550
|
" / ",
|
|
564
551
|
t(errorLocaleKey(result.code))
|
|
565
|
-
] }), result.code === "MISSING_API_KEY" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t(provider === "
|
|
552
|
+
] }), result.code === "MISSING_API_KEY" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t(provider === "deepseek" ? "balance.setupDeepSeek" : "balance.setup", {
|
|
566
553
|
provider: providerName,
|
|
567
554
|
ref: findBalanceProvider(provider).apiKeyRef
|
|
568
555
|
}) }) : null]
|