@pinkbanana/dsh-balance 0.6.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 +11 -5
- package/README_EN.md +11 -5
- package/lib/client.js +182 -98
- package/lib/client.js.map +1 -1
- package/lib/index.js +28 -14
- package/lib/index.js.map +1 -1
- 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 +5 -2
- package/lib/types/client/styles.d.ts +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -6,16 +6,16 @@ DeepSeek Harness 插件,用于查询 DeepSeek / StepFun API 余额、各提供
|
|
|
6
6
|
|
|
7
7
|
设置页采用账户总览布局,支持 DeepSeek / StepFun 切换。运行 `pnpm preview` 可查看使用示例数据的新版界面。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
聊天框底部会跟随当前会话所选的提供方与模型更新余额;设置页可独立切换提供方。
|
|
10
10
|
|
|
11
11
|
## 功能
|
|
12
12
|
|
|
13
13
|
- DeepSeek:查看总余额、充值余额和赠送余额
|
|
14
14
|
- StepFun:查看可用余额、总充值金额、总赠送金额及预付费 / 后付费账户类型
|
|
15
15
|
- 提供方独立缓存;支持大小写不敏感的 Provider ID
|
|
16
|
-
-
|
|
16
|
+
- 在聊天框下方显示当前 provider、模型和余额,兼容模型选择器与 `/model` 切换
|
|
17
17
|
- 从当前提供方的 `/models` 接口读取可用模型、所属组织与创建时间
|
|
18
|
-
-
|
|
18
|
+
- 在设置页按所选 provider、模型、会话和日期查看实际 usage 消费,并在当前会话的“消费”Tab 查看请求明细
|
|
19
19
|
- 缺少 provider usage、未知 provider 或未知模型时标记为“未计费”,不进行 token 估算
|
|
20
20
|
- 日期按浏览器 IANA 时区分组;DeepSeek 峰谷价格始终按北京时间计算
|
|
21
21
|
- 默认显示 USD;配置 `usdToCny` 后额外显示固定汇率换算的 CNY
|
|
@@ -54,10 +54,16 @@ providers:
|
|
|
54
54
|
baseUrl: https://api.stepfun.com/v1
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
已有的顶层 `apiKeyRef` / `baseUrl` 继续用于 DeepSeek;`providers` 覆盖对应提供方的余额与模型查询。配置不读取自定义模型的 Base URL,默认查询官方 API
|
|
57
|
+
已有的顶层 `apiKeyRef` / `baseUrl` 继续用于 DeepSeek;`providers` 覆盖对应提供方的余额与模型查询。配置不读取自定义模型的 Base URL,默认查询官方 API。余额、可用模型与设置页统计随所选提供方切换。聊天框摘要使用当前会话的实时选择;会话“消费”保留该会话历史上所有 provider 的用量。
|
|
58
58
|
|
|
59
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
60
|
|
|
61
|
+
## 统计口径
|
|
62
|
+
|
|
63
|
+
每条请求按实际返回消息的 provider / model 归属,兼容旧日志的请求头;日期和峰谷价格按该次请求时间计算。Token 总量包括未缓存输入、输出、缓存读取与缓存写入。设置页默认筛选所选 provider,也可选择“全部提供方”;会话页保留混用模型的完整历史。
|
|
64
|
+
|
|
65
|
+
当前内置价格仅覆盖 DeepSeek 官方定价。StepFun 等没有可靠历史价格的数据保留请求数与 token,显示“未计费”;不会套用同名 DeepSeek 模型价格,也不会将全部未知费用显示为 $0。混合统计仅累加已知价格,并注明不完整。账户余额是实时查询值,与本地用量估算独立。
|
|
66
|
+
|
|
61
67
|
## 扩展与设计
|
|
62
68
|
|
|
63
69
|
- `src/providers.ts` 保存可在前后端共享的 provider 元数据;`src/balance.ts` 的 adapter 表只负责端点与响应解析,传输、错误分类和缓存由公共逻辑处理。
|
|
@@ -72,7 +78,7 @@ pnpm check
|
|
|
72
78
|
pnpm preview
|
|
73
79
|
```
|
|
74
80
|
|
|
75
|
-
预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading`
|
|
81
|
+
预览不使用真实密钥。可使用 `?lang=en&theme=dark` 检查英文与深色主题,`?state=missing` / `error` / `empty` / `loading` 检查不同状态。顶部示例模型选择器可验证底部 provider / 模型切换。StepFun 余额与模型查询、新版账户页面自 `0.6.0` 起提供。实时模型余额和统计修复自 `0.7.0` 起提供。
|
|
76
82
|
|
|
77
83
|
## License
|
|
78
84
|
|
package/README_EN.md
CHANGED
|
@@ -6,16 +6,16 @@ A DeepSeek Harness plugin for checking DeepSeek / StepFun API balances, availabl
|
|
|
6
6
|
|
|
7
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
|
|
|
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
15
|
- Independent provider caches and case-insensitive Provider IDs
|
|
16
|
-
-
|
|
16
|
+
- Show the current provider, model, and balance below the composer, following both the selector and `/model`
|
|
17
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
|
|
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
21
|
- Show USD by default, with optional fixed-rate CNY conversion through `usdToCny`
|
|
@@ -54,10 +54,16 @@ providers:
|
|
|
54
54
|
baseUrl: https://api.stepfun.com/v1
|
|
55
55
|
```
|
|
56
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.
|
|
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. 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
58
|
|
|
59
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
60
|
|
|
61
|
+
## Usage accounting
|
|
62
|
+
|
|
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.
|
|
64
|
+
|
|
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.
|
|
66
|
+
|
|
61
67
|
## Extension and design
|
|
62
68
|
|
|
63
69
|
- `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 +78,7 @@ pnpm check
|
|
|
72
78
|
pnpm preview
|
|
73
79
|
```
|
|
74
80
|
|
|
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`.
|
|
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`.
|
|
76
82
|
|
|
77
83
|
## License
|
|
78
84
|
|
package/lib/client.js
CHANGED
|
@@ -12,6 +12,23 @@ window.__ModuleLoader__.load({
|
|
|
12
12
|
/** The same-origin endpoint that proxies the selected provider’s `/models` API. */
|
|
13
13
|
const MODELS_ROUTE = "/dsh-balance/api/models";
|
|
14
14
|
//#endregion
|
|
15
|
+
//#region src/providers.ts
|
|
16
|
+
/** Browser-safe provider metadata. Credentials and wire parsers stay on the Host. */
|
|
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
|
+
}];
|
|
28
|
+
function findBalanceProvider(id) {
|
|
29
|
+
return BALANCE_PROVIDERS.find((provider) => provider.id === id.trim().toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
15
32
|
//#region src/pricing.ts
|
|
16
33
|
/** Shared DeepSeek pricing schedule used by Host billing and the client indicator. */
|
|
17
34
|
const BEIJING_OFFSET_MS = 288e5;
|
|
@@ -112,7 +129,22 @@ window.__ModuleLoader__.load({
|
|
|
112
129
|
const REFRESH_INTERVAL_MS = 6e4;
|
|
113
130
|
const PEAK_TICK_MS = 3e4;
|
|
114
131
|
/** Compact ambient balance readout below the active-session composer card. */
|
|
115
|
-
function BalanceDock({ loadBalance, t }) {
|
|
132
|
+
function BalanceDock({ selection, loadBalance, t, sessionId }) {
|
|
133
|
+
const snapshot = (0, react.useSyncExternalStore)(selection.store.subscribe, selection.store.getSnapshot);
|
|
134
|
+
(0, react.useEffect)(() => {
|
|
135
|
+
if (selection.store.getSnapshot().status === "idle") selection.load().catch(() => {});
|
|
136
|
+
}, [selection]);
|
|
137
|
+
const current = snapshot.current;
|
|
138
|
+
const provider = current === null ? void 0 : findBalanceProvider(current.provider);
|
|
139
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderBalanceDock, {
|
|
140
|
+
provider: provider?.id,
|
|
141
|
+
providerName: provider?.name ?? current?.provider,
|
|
142
|
+
model: current?.model,
|
|
143
|
+
loadBalance,
|
|
144
|
+
t
|
|
145
|
+
}, `${sessionId}:${current?.provider ?? ""}`);
|
|
146
|
+
}
|
|
147
|
+
function ProviderBalanceDock({ provider, providerName, model, loadBalance, t }) {
|
|
116
148
|
const [result, setResult] = (0, react.useState)();
|
|
117
149
|
const [now, setNow] = (0, react.useState)(() => /* @__PURE__ */ new Date());
|
|
118
150
|
(0, react.useEffect)(() => {
|
|
@@ -122,12 +154,13 @@ window.__ModuleLoader__.load({
|
|
|
122
154
|
};
|
|
123
155
|
}, []);
|
|
124
156
|
(0, react.useEffect)(() => {
|
|
157
|
+
if (provider === void 0) return;
|
|
125
158
|
let controller;
|
|
126
159
|
const load = () => {
|
|
127
160
|
controller?.abort();
|
|
128
161
|
controller = new AbortController();
|
|
129
162
|
const signal = controller.signal;
|
|
130
|
-
loadBalance(false, signal).then((value) => {
|
|
163
|
+
loadBalance(false, signal, provider).then((value) => {
|
|
131
164
|
if (!signal.aborted) setResult(value);
|
|
132
165
|
}).catch(() => {
|
|
133
166
|
if (!signal.aborted) setResult({
|
|
@@ -143,16 +176,24 @@ window.__ModuleLoader__.load({
|
|
|
143
176
|
window.clearInterval(timer);
|
|
144
177
|
controller?.abort();
|
|
145
178
|
};
|
|
146
|
-
}, [loadBalance]);
|
|
179
|
+
}, [loadBalance, provider]);
|
|
147
180
|
const summary = (0, react.useMemo)(() => {
|
|
181
|
+
if (providerName === void 0) return t("dock.noSelection");
|
|
182
|
+
if (provider === void 0) return t("error.UNSUPPORTED_PROVIDER");
|
|
148
183
|
if (result === void 0) return t("dock.loading");
|
|
149
184
|
if (!result.ok) return t("dock.unavailable");
|
|
150
185
|
if (result.balanceInfos.length === 0) return t("dock.empty");
|
|
151
186
|
return result.balanceInfos.map((info) => `${info.currency} ${displayAmount(info.totalBalance, info.currency, t("locale.tag"))}`).join(" · ");
|
|
152
|
-
}, [
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
187
|
+
}, [
|
|
188
|
+
result,
|
|
189
|
+
t,
|
|
190
|
+
provider,
|
|
191
|
+
providerName
|
|
192
|
+
]);
|
|
193
|
+
const state = provider === void 0 ? "unknown" : result === void 0 ? "loading" : !result.ok ? "error" : result.isAvailable === null ? "unknown" : result.isAvailable ? "available" : "empty";
|
|
194
|
+
const accessibleState = result?.ok === true && result.isAvailable !== null ? t(result.isAvailable ? "balance.available" : "balance.unavailable") : void 0;
|
|
195
|
+
const label = providerName === void 0 ? t("nav.balance") : t("dock.label", { provider: providerName });
|
|
196
|
+
const pricingActive = provider === "deepseek" && now.getTime() >= PEAK_EFFECTIVE_FROM;
|
|
156
197
|
const isPeak = pricingActive && isPeakHour(now);
|
|
157
198
|
const periodLabel = pricingActive ? t(isPeak ? "pricing.peak" : "pricing.offPeak") : void 0;
|
|
158
199
|
const periodTitle = pricingActive ? t(isPeak ? "pricing.peakHint" : "pricing.offPeakHint", { time: formatClockTime(nextPeriodChange(now), t("locale.tag")) }) : void 0;
|
|
@@ -161,7 +202,7 @@ window.__ModuleLoader__.load({
|
|
|
161
202
|
role: "status",
|
|
162
203
|
"aria-live": "polite",
|
|
163
204
|
title: periodTitle,
|
|
164
|
-
"aria-label": `${
|
|
205
|
+
"aria-label": `${label}${model === void 0 ? "" : ` / ${model}`}: ${summary}${accessibleState === void 0 ? "" : `. ${accessibleState}`}${periodLabel === void 0 ? "" : `. ${periodLabel}`}`,
|
|
165
206
|
children: [
|
|
166
207
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
167
208
|
className: "dsh-balance-dock-dot",
|
|
@@ -169,7 +210,12 @@ window.__ModuleLoader__.load({
|
|
|
169
210
|
"data-peak": isPeak ? "true" : void 0,
|
|
170
211
|
"aria-hidden": "true"
|
|
171
212
|
}),
|
|
172
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children:
|
|
213
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }),
|
|
214
|
+
model === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
215
|
+
className: "dsh-balance-dock-model",
|
|
216
|
+
title: model,
|
|
217
|
+
children: model
|
|
218
|
+
}),
|
|
173
219
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
174
220
|
className: "dsh-balance-dock-separator",
|
|
175
221
|
"aria-hidden": "true",
|
|
@@ -183,23 +229,6 @@ window.__ModuleLoader__.load({
|
|
|
183
229
|
});
|
|
184
230
|
}
|
|
185
231
|
//#endregion
|
|
186
|
-
//#region src/providers.ts
|
|
187
|
-
/** Browser-safe provider metadata. Credentials and wire parsers stay on the Host. */
|
|
188
|
-
const BALANCE_PROVIDERS = [{
|
|
189
|
-
id: "deepseek",
|
|
190
|
-
name: "DeepSeek",
|
|
191
|
-
apiKeyRef: "DEEPSEEK_API_KEY",
|
|
192
|
-
baseUrl: "https://api.deepseek.com"
|
|
193
|
-
}, {
|
|
194
|
-
id: "stepfun",
|
|
195
|
-
name: "StepFun",
|
|
196
|
-
apiKeyRef: "STEPFUN_API_KEY",
|
|
197
|
-
baseUrl: "https://api.stepfun.com/v1"
|
|
198
|
-
}];
|
|
199
|
-
function findBalanceProvider(id) {
|
|
200
|
-
return BALANCE_PROVIDERS.find((provider) => provider.id === id.trim().toLowerCase());
|
|
201
|
-
}
|
|
202
|
-
//#endregion
|
|
203
232
|
//#region src/client/locales.ts
|
|
204
233
|
const LOCALE_NS = "dsh-balance";
|
|
205
234
|
/** Simplified Chinese dictionary and source of truth for the namespace key set. */
|
|
@@ -234,7 +263,8 @@ window.__ModuleLoader__.load({
|
|
|
234
263
|
"balance.empty": "提供方未返回任何币种余额。",
|
|
235
264
|
"balance.toppedUp": "充值余额",
|
|
236
265
|
"balance.granted": "赠送余额",
|
|
237
|
-
"dock.label": "
|
|
266
|
+
"dock.label": "{provider} 余额",
|
|
267
|
+
"dock.noSelection": "尚未获取当前模型",
|
|
238
268
|
"dock.loading": "查询中…",
|
|
239
269
|
"dock.unavailable": "暂时无法获取",
|
|
240
270
|
"dock.empty": "暂无余额信息",
|
|
@@ -249,6 +279,7 @@ window.__ModuleLoader__.load({
|
|
|
249
279
|
"billing.tab": "消费",
|
|
250
280
|
"billing.title": "API 消费统计",
|
|
251
281
|
"billing.copy": "按会话、模型和日期统计实际 provider usage;日期按 {timeZone} 分组。",
|
|
282
|
+
"billing.provider": "统计提供方",
|
|
252
283
|
"billing.range": "统计范围",
|
|
253
284
|
"billing.todayRange": "今日",
|
|
254
285
|
"billing.sevenDays": "最近 7 天",
|
|
@@ -277,6 +308,7 @@ window.__ModuleLoader__.load({
|
|
|
277
308
|
"billing.unknownModel": "未知模型",
|
|
278
309
|
"billing.inputOutput": "输入 {input} · 输出 {output}",
|
|
279
310
|
"billing.notPriced": "未计费",
|
|
311
|
+
"billing.partial": "仅包含已知价格的请求",
|
|
280
312
|
"billing.reason.missing-usage": "缺少 provider usage",
|
|
281
313
|
"billing.reason.unknown-provider": "未知 provider",
|
|
282
314
|
"billing.reason.unknown-model": "未知模型价格",
|
|
@@ -296,7 +328,7 @@ window.__ModuleLoader__.load({
|
|
|
296
328
|
"error.INVALID_API_KEY": "API 密钥无效或没有查询权限",
|
|
297
329
|
"error.INVALID_RESPONSE": "返回了无法识别的响应",
|
|
298
330
|
"error.METHOD_NOT_ALLOWED": "请求方法不受支持",
|
|
299
|
-
"error.MISSING_API_KEY": "
|
|
331
|
+
"error.MISSING_API_KEY": "未配置查询凭据",
|
|
300
332
|
"error.RATE_LIMITED": "API 请求过于频繁,请稍后重试",
|
|
301
333
|
"error.UPSTREAM_ERROR": "API 返回了错误",
|
|
302
334
|
"error.UPSTREAM_TIMEOUT": "查询 API 超时",
|
|
@@ -334,7 +366,8 @@ window.__ModuleLoader__.load({
|
|
|
334
366
|
"balance.empty": "The provider returned no currency balances.",
|
|
335
367
|
"balance.toppedUp": "Topped-up balance",
|
|
336
368
|
"balance.granted": "Granted balance",
|
|
337
|
-
"dock.label": "
|
|
369
|
+
"dock.label": "{provider} Balance",
|
|
370
|
+
"dock.noSelection": "Current model not available yet",
|
|
338
371
|
"dock.loading": "Loading…",
|
|
339
372
|
"dock.unavailable": "Temporarily unavailable",
|
|
340
373
|
"dock.empty": "No balance information",
|
|
@@ -349,6 +382,7 @@ window.__ModuleLoader__.load({
|
|
|
349
382
|
"billing.tab": "Usage",
|
|
350
383
|
"billing.title": "API Usage",
|
|
351
384
|
"billing.copy": "Actual provider usage grouped by session, model, and date; dates use {timeZone}.",
|
|
385
|
+
"billing.provider": "Usage provider",
|
|
352
386
|
"billing.range": "Usage range",
|
|
353
387
|
"billing.todayRange": "Today",
|
|
354
388
|
"billing.sevenDays": "Last 7 days",
|
|
@@ -377,6 +411,7 @@ window.__ModuleLoader__.load({
|
|
|
377
411
|
"billing.unknownModel": "Unknown model",
|
|
378
412
|
"billing.inputOutput": "Input {input} · Output {output}",
|
|
379
413
|
"billing.notPriced": "Unpriced",
|
|
414
|
+
"billing.partial": "Requests with known pricing only",
|
|
380
415
|
"billing.reason.missing-usage": "Provider usage is missing",
|
|
381
416
|
"billing.reason.unknown-provider": "Unknown provider",
|
|
382
417
|
"billing.reason.unknown-model": "Unknown model pricing",
|
|
@@ -396,7 +431,7 @@ window.__ModuleLoader__.load({
|
|
|
396
431
|
"error.INVALID_API_KEY": "The API key is invalid or lacks permission",
|
|
397
432
|
"error.INVALID_RESPONSE": "The provider returned an unrecognized response",
|
|
398
433
|
"error.METHOD_NOT_ALLOWED": "This request method is not supported",
|
|
399
|
-
"error.MISSING_API_KEY": "
|
|
434
|
+
"error.MISSING_API_KEY": "Query credentials are not configured.",
|
|
400
435
|
"error.RATE_LIMITED": "Too many API requests. Try again later.",
|
|
401
436
|
"error.UPSTREAM_ERROR": "The API returned an error",
|
|
402
437
|
"error.UPSTREAM_TIMEOUT": "The API request timed out",
|
|
@@ -684,9 +719,9 @@ window.__ModuleLoader__.load({
|
|
|
684
719
|
return `${values.year ?? "0000"}-${values.month ?? "00"}-${values.day ?? "00"}`;
|
|
685
720
|
}
|
|
686
721
|
function dateDaysAgo(timeZone, days) {
|
|
687
|
-
const local =
|
|
688
|
-
local.
|
|
689
|
-
return
|
|
722
|
+
const local = /* @__PURE__ */ new Date(`${localDateKey(timeZone)}T12:00:00Z`);
|
|
723
|
+
local.setUTCDate(local.getUTCDate() - days);
|
|
724
|
+
return local.toISOString().slice(0, 10);
|
|
690
725
|
}
|
|
691
726
|
function totalForDay(summary, date) {
|
|
692
727
|
return summary.byDay.find((item) => item.date === date) ?? {
|
|
@@ -712,13 +747,18 @@ window.__ModuleLoader__.load({
|
|
|
712
747
|
}
|
|
713
748
|
function CostLabel({ totals, t }) {
|
|
714
749
|
const locale = t("locale.tag");
|
|
750
|
+
const unpriced = totals.requests > 0 && totals.pricedRequests === 0;
|
|
715
751
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
716
752
|
className: "dsh-billing-cost-value",
|
|
717
|
-
children: [
|
|
718
|
-
amount(totals.
|
|
719
|
-
" ",
|
|
720
|
-
|
|
721
|
-
|
|
753
|
+
children: [
|
|
754
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: unpriced ? t("billing.notPriced") : amount(totals.costUsd, "USD", locale) }),
|
|
755
|
+
totals.unpricedRequests > 0 && !unpriced ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.partial") }) : null,
|
|
756
|
+
totals.costCny !== null && !unpriced ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
757
|
+
amount(totals.costCny, "CNY", locale),
|
|
758
|
+
" ",
|
|
759
|
+
t("billing.fixedRate")
|
|
760
|
+
] }) : null
|
|
761
|
+
]
|
|
722
762
|
});
|
|
723
763
|
}
|
|
724
764
|
function SummaryCards({ summary, t }) {
|
|
@@ -752,7 +792,7 @@ window.__ModuleLoader__.load({
|
|
|
752
792
|
className: "dsh-billing-card",
|
|
753
793
|
children: [
|
|
754
794
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.tokens") }),
|
|
755
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.inputTokens + summary.totals.outputTokens) }),
|
|
795
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.inputTokens + summary.totals.outputTokens + summary.totals.cacheReadTokens + summary.totals.cacheWriteTokens) }),
|
|
756
796
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
757
797
|
totals: summary.totals,
|
|
758
798
|
t
|
|
@@ -803,13 +843,9 @@ window.__ModuleLoader__.load({
|
|
|
803
843
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
804
844
|
totals: item,
|
|
805
845
|
t
|
|
806
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [
|
|
807
|
-
t("billing.requestCount", { count: item.requests }),
|
|
808
|
-
" · ",
|
|
809
|
-
t("billing.share", { percent: `${summary.totals.costUsd === 0 ? 0 : Math.round(item.costUsd / summary.totals.costUsd * 100)}%` })
|
|
810
|
-
] })]
|
|
846
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [t("billing.requestCount", { count: item.requests }), item.pricedRequests > 0 && summary.totals.costUsd > 0 ? ` · ${t("billing.share", { percent: `${Math.round(item.costUsd / summary.totals.costUsd * 100)}%` })}` : ""] })]
|
|
811
847
|
})]
|
|
812
|
-
},
|
|
848
|
+
}, JSON.stringify([item.provider, item.model])))
|
|
813
849
|
});
|
|
814
850
|
}
|
|
815
851
|
function UsageTables({ summary, t }) {
|
|
@@ -884,7 +920,11 @@ window.__ModuleLoader__.load({
|
|
|
884
920
|
className: "dsh-billing-request-row",
|
|
885
921
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
886
922
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: new Date(request.time).toLocaleString(locale) }),
|
|
887
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
923
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("code", { children: [
|
|
924
|
+
request.provider ?? "?",
|
|
925
|
+
" / ",
|
|
926
|
+
request.model ?? t("billing.unknownModel")
|
|
927
|
+
] }),
|
|
888
928
|
request.unknownReason !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
889
929
|
className: "dsh-billing-secondary",
|
|
890
930
|
children: t(`billing.reason.${request.unknownReason}`)
|
|
@@ -909,52 +949,69 @@ window.__ModuleLoader__.load({
|
|
|
909
949
|
});
|
|
910
950
|
}
|
|
911
951
|
function useUsageResult(loadUsage, options, revision) {
|
|
912
|
-
const [
|
|
952
|
+
const [state, setState] = (0, react.useState)();
|
|
913
953
|
const [loading, setLoading] = (0, react.useState)(true);
|
|
914
|
-
const
|
|
954
|
+
const active = (0, react.useRef)();
|
|
955
|
+
const load = (0, react.useCallback)(async (forceRefresh) => {
|
|
956
|
+
active.current?.abort();
|
|
957
|
+
const controller = new AbortController();
|
|
958
|
+
active.current = controller;
|
|
959
|
+
const { signal } = controller;
|
|
915
960
|
setLoading(true);
|
|
916
961
|
try {
|
|
917
|
-
|
|
962
|
+
const result = await loadUsage({
|
|
918
963
|
...options,
|
|
919
964
|
forceRefresh
|
|
920
|
-
}, signal)
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
965
|
+
}, signal);
|
|
966
|
+
if (!signal.aborted) setState({
|
|
967
|
+
options,
|
|
968
|
+
result
|
|
969
|
+
});
|
|
970
|
+
} catch {
|
|
971
|
+
if (!signal.aborted) setState({
|
|
972
|
+
options,
|
|
973
|
+
result: {
|
|
974
|
+
ok: false,
|
|
975
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
976
|
+
message: ""
|
|
977
|
+
}
|
|
926
978
|
});
|
|
927
979
|
} finally {
|
|
928
980
|
if (!signal.aborted) setLoading(false);
|
|
929
981
|
}
|
|
930
982
|
}, [loadUsage, options]);
|
|
931
983
|
(0, react.useEffect)(() => {
|
|
932
|
-
|
|
933
|
-
load(false, controller.signal);
|
|
984
|
+
load(false);
|
|
934
985
|
return () => {
|
|
935
|
-
|
|
986
|
+
active.current?.abort();
|
|
936
987
|
};
|
|
937
988
|
}, [load, revision]);
|
|
938
989
|
return {
|
|
939
|
-
result,
|
|
990
|
+
result: state?.options === options ? state.result : void 0,
|
|
940
991
|
loading,
|
|
941
992
|
refresh: () => {
|
|
942
|
-
|
|
943
|
-
load(true, controller.signal);
|
|
993
|
+
load(true);
|
|
944
994
|
}
|
|
945
995
|
};
|
|
946
996
|
}
|
|
947
|
-
function BillingOverview({ loadUsage, t }) {
|
|
997
|
+
function BillingOverview({ loadUsage, t, provider }) {
|
|
998
|
+
const [providerScope, setProviderScope] = (0, react.useState)("selected");
|
|
999
|
+
const selectedProvider = providerScope === "all" ? void 0 : provider;
|
|
948
1000
|
const timeZone = (0, react.useMemo)(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", []);
|
|
949
1001
|
const [range, setRange] = (0, react.useState)("30d");
|
|
950
1002
|
const options = (0, react.useMemo)(() => ({
|
|
951
1003
|
scope: "all",
|
|
1004
|
+
...selectedProvider === void 0 ? {} : { provider: selectedProvider },
|
|
952
1005
|
timeZone,
|
|
953
1006
|
...range === "all" ? {} : {
|
|
954
1007
|
from: range === "today" ? localDateKey(timeZone) : dateDaysAgo(timeZone, range === "7d" ? 6 : 29),
|
|
955
1008
|
to: localDateKey(timeZone)
|
|
956
1009
|
}
|
|
957
|
-
}), [
|
|
1010
|
+
}), [
|
|
1011
|
+
range,
|
|
1012
|
+
timeZone,
|
|
1013
|
+
selectedProvider
|
|
1014
|
+
]);
|
|
958
1015
|
const { result, loading, refresh } = useUsageResult(loadUsage, options, JSON.stringify(options));
|
|
959
1016
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
960
1017
|
className: "dsh-billing-section",
|
|
@@ -971,35 +1028,50 @@ window.__ModuleLoader__.load({
|
|
|
971
1028
|
children: t("billing.copy", { timeZone })
|
|
972
1029
|
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
973
1030
|
className: "dsh-billing-actions",
|
|
974
|
-
children: [
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
980
|
-
value: "
|
|
981
|
-
children:
|
|
982
|
-
}),
|
|
983
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
984
|
-
value: "7d",
|
|
985
|
-
children: t("billing.sevenDays")
|
|
986
|
-
}),
|
|
987
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
988
|
-
value: "30d",
|
|
989
|
-
children: t("billing.thirtyDays")
|
|
990
|
-
}),
|
|
991
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1031
|
+
children: [
|
|
1032
|
+
provider === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
1033
|
+
"aria-label": t("billing.provider"),
|
|
1034
|
+
value: providerScope,
|
|
1035
|
+
onChange: (event) => setProviderScope(event.target.value),
|
|
1036
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1037
|
+
value: "selected",
|
|
1038
|
+
children: findBalanceProvider(provider)?.name ?? provider
|
|
1039
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
992
1040
|
value: "all",
|
|
993
|
-
children: t("
|
|
994
|
-
})
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1041
|
+
children: t("panel.allProviders")
|
|
1042
|
+
})]
|
|
1043
|
+
}),
|
|
1044
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
1045
|
+
"aria-label": t("billing.range"),
|
|
1046
|
+
value: range,
|
|
1047
|
+
onChange: (event) => setRange(event.target.value),
|
|
1048
|
+
children: [
|
|
1049
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1050
|
+
value: "today",
|
|
1051
|
+
children: t("billing.todayRange")
|
|
1052
|
+
}),
|
|
1053
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1054
|
+
value: "7d",
|
|
1055
|
+
children: t("billing.sevenDays")
|
|
1056
|
+
}),
|
|
1057
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1058
|
+
value: "30d",
|
|
1059
|
+
children: t("billing.thirtyDays")
|
|
1060
|
+
}),
|
|
1061
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
1062
|
+
value: "all",
|
|
1063
|
+
children: t("billing.allTime")
|
|
1064
|
+
})
|
|
1065
|
+
]
|
|
1066
|
+
}),
|
|
1067
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1068
|
+
className: "dsh-balance-refresh",
|
|
1069
|
+
type: "button",
|
|
1070
|
+
disabled: loading,
|
|
1071
|
+
onClick: refresh,
|
|
1072
|
+
children: loading ? t("action.loading") : t("billing.refresh")
|
|
1073
|
+
})
|
|
1074
|
+
]
|
|
1003
1075
|
})]
|
|
1004
1076
|
}),
|
|
1005
1077
|
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
@@ -1163,11 +1235,12 @@ window.__ModuleLoader__.load({
|
|
|
1163
1235
|
loadModels,
|
|
1164
1236
|
t
|
|
1165
1237
|
}, `models-${provider}`),
|
|
1166
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
1238
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1167
1239
|
className: "dsh-ledger-section-label",
|
|
1168
|
-
children:
|
|
1240
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["03 / ", t("panel.activity")] })
|
|
1169
1241
|
}),
|
|
1170
1242
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BillingOverview, {
|
|
1243
|
+
provider,
|
|
1171
1244
|
loadUsage,
|
|
1172
1245
|
t
|
|
1173
1246
|
})
|
|
@@ -1209,8 +1282,8 @@ window.__ModuleLoader__.load({
|
|
|
1209
1282
|
.dsh-ledger-orbit i:nth-child(3) { transform: rotate(85deg) scaleX(.5); }
|
|
1210
1283
|
.dsh-ledger-orbit span { display: grid; place-items: center; width: 40px; height: 40px; background: #d7ed9d; color: #233316; border-radius: 50%; font-size: 24px; transition: transform .4s ease; }
|
|
1211
1284
|
.dsh-ledger-header:hover .dsh-ledger-orbit span { transform: rotate(45deg); }
|
|
1212
|
-
.dsh-provider-switch { display: flex; gap: 8px; padding-bottom: 24px; border-bottom: 1px solid var(--ledger-line); }
|
|
1213
|
-
.dsh-provider-switch button { display: flex; align-items: center; gap: 14px; flex: 1;
|
|
1285
|
+
.dsh-provider-switch { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 24px; border-bottom: 1px solid var(--ledger-line); }
|
|
1286
|
+
.dsh-provider-switch button { display: flex; align-items: center; gap: 14px; flex: 1 1 140px; min-width: 0; min-height: 58px; padding: 12px 18px; border: 1px solid var(--ledger-line); border-radius: 4px; color: var(--ledger-ink); background: transparent; font: inherit; font-size: 16px; cursor: pointer; transition: background .2s, transform .2s; }
|
|
1214
1287
|
.dsh-provider-switch button:hover { background: var(--ledger-paper); transform: translateY(-2px); }
|
|
1215
1288
|
.dsh-provider-switch button[aria-pressed='true'] { color: #e5f6bd; background: #25352e; border-color: #25352e; }
|
|
1216
1289
|
.dsh-provider-index { font-family: ui-monospace, monospace; font-size: 10px; opacity: .7; }
|
|
@@ -1370,7 +1443,7 @@ window.__ModuleLoader__.load({
|
|
|
1370
1443
|
width: 100%;
|
|
1371
1444
|
max-width: var(--dsh-chat-content-width);
|
|
1372
1445
|
margin: 0 auto;
|
|
1373
|
-
padding: 4px calc(var(--dsh-composer-side-clearance) + 16px) 0;
|
|
1446
|
+
padding: 4px calc(var(--dsh-composer-side-clearance, 0px) + 16px) 0;
|
|
1374
1447
|
color: var(--dsw-alias-label-tertiary);
|
|
1375
1448
|
font-size: 12px;
|
|
1376
1449
|
line-height: 20px;
|
|
@@ -1379,6 +1452,7 @@ window.__ModuleLoader__.load({
|
|
|
1379
1452
|
overflow: hidden;
|
|
1380
1453
|
text-overflow: ellipsis;
|
|
1381
1454
|
}
|
|
1455
|
+
.dsh-balance-dock-model { display: inline-block; max-width: 40%; margin-left: 8px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
|
|
1382
1456
|
.dsh-balance-dock-dot {
|
|
1383
1457
|
display: inline-block;
|
|
1384
1458
|
width: 6px;
|
|
@@ -1397,10 +1471,12 @@ window.__ModuleLoader__.load({
|
|
|
1397
1471
|
color: var(--dsw-alias-separator-primary);
|
|
1398
1472
|
}
|
|
1399
1473
|
.dsh-balance-dock-value {
|
|
1474
|
+
display: inline-block;
|
|
1400
1475
|
color: var(--dsw-alias-label-secondary);
|
|
1401
1476
|
font-variant-numeric: tabular-nums;
|
|
1402
1477
|
}
|
|
1403
1478
|
@media (max-width: 640px) {
|
|
1479
|
+
.dsh-balance-dock { white-space: normal; }
|
|
1404
1480
|
.dsh-balance-summary { align-items: flex-start; }
|
|
1405
1481
|
.dsh-balance-grid,
|
|
1406
1482
|
.dsh-model-grid,
|
|
@@ -1414,7 +1490,11 @@ window.__ModuleLoader__.load({
|
|
|
1414
1490
|
`;
|
|
1415
1491
|
//#endregion
|
|
1416
1492
|
//#region src/client/index.tsx
|
|
1417
|
-
const inject = [
|
|
1493
|
+
const inject = [
|
|
1494
|
+
"slots",
|
|
1495
|
+
"locale",
|
|
1496
|
+
"modelDirectories"
|
|
1497
|
+
];
|
|
1418
1498
|
async function loadBalance(forceRefresh, signal, provider = "deepseek") {
|
|
1419
1499
|
const params = new URLSearchParams({ provider });
|
|
1420
1500
|
if (forceRefresh) params.set("refresh", "1");
|
|
@@ -1446,6 +1526,7 @@ window.__ModuleLoader__.load({
|
|
|
1446
1526
|
scope: options.scope,
|
|
1447
1527
|
timeZone: options.timeZone
|
|
1448
1528
|
});
|
|
1529
|
+
if (options.provider !== void 0) params.set("provider", options.provider);
|
|
1449
1530
|
if (options.sessionId !== void 0) params.set("sessionId", options.sessionId);
|
|
1450
1531
|
if (options.from !== void 0) params.set("from", options.from);
|
|
1451
1532
|
if (options.to !== void 0) params.set("to", options.to);
|
|
@@ -1501,7 +1582,10 @@ window.__ModuleLoader__.load({
|
|
|
1501
1582
|
id: "deepseek-balance",
|
|
1502
1583
|
order: 10,
|
|
1503
1584
|
locale: LOCALE_NS,
|
|
1504
|
-
inject: () => ({
|
|
1585
|
+
inject: (sessionId) => ({
|
|
1586
|
+
loadBalance,
|
|
1587
|
+
selection: ctx.modelDirectories.directoryFor(sessionId)
|
|
1588
|
+
})
|
|
1505
1589
|
}, BalanceDock));
|
|
1506
1590
|
}
|
|
1507
1591
|
//#endregion
|