@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 +46 -6
- package/README_EN.md +46 -6
- package/lib/client.js +1026 -192
- package/lib/client.js.map +1 -1
- package/lib/index.js +695 -84
- package/lib/index.js.map +1 -1
- package/lib/types/balance.d.ts +8 -8
- package/lib/types/billing.d.ts +119 -0
- package/lib/types/client/BalanceTab.d.ts +6 -3
- package/lib/types/client/BillingTab.d.ts +18 -0
- package/lib/types/client/DeepSeekPanel.d.ts +4 -3
- package/lib/types/client/ModelsTab.d.ts +7 -4
- package/lib/types/client/index.d.ts +1 -0
- package/lib/types/client/locales.d.ts +74 -15
- package/lib/types/client/pricing.d.ts +1 -15
- package/lib/types/client/styles.d.ts +1 -1
- package/lib/types/index.d.ts +14 -3
- package/lib/types/models.d.ts +11 -6
- package/lib/types/pricing.d.ts +7 -0
- package/lib/types/providers.d.ts +24 -0
- package/lib/types/types.d.ts +23 -12
- package/package.json +14 -4
package/lib/client.js
CHANGED
|
@@ -9,46 +9,16 @@ window.__ModuleLoader__.load({
|
|
|
9
9
|
//#region src/types.ts
|
|
10
10
|
/** The same-origin endpoint exposed by the plugin's Host half. */
|
|
11
11
|
const BALANCE_ROUTE = "/dsh-balance/api/balance";
|
|
12
|
-
/** The same-origin endpoint that proxies
|
|
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/
|
|
16
|
-
|
|
17
|
-
return new Intl.DateTimeFormat(locale, {
|
|
18
|
-
hour: "2-digit",
|
|
19
|
-
minute: "2-digit"
|
|
20
|
-
}).format(date);
|
|
21
|
-
}
|
|
22
|
-
function displayAmount(value, currency, locale) {
|
|
23
|
-
const amount = Number(value);
|
|
24
|
-
if (!Number.isFinite(amount)) return `${value} ${currency}`;
|
|
25
|
-
try {
|
|
26
|
-
return new Intl.NumberFormat(locale, {
|
|
27
|
-
style: "currency",
|
|
28
|
-
currency,
|
|
29
|
-
minimumFractionDigits: 2,
|
|
30
|
-
maximumFractionDigits: 8
|
|
31
|
-
}).format(amount);
|
|
32
|
-
} catch {
|
|
33
|
-
return `${value} ${currency}`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/client/pricing.ts
|
|
38
|
-
/**
|
|
39
|
-
* DeepSeek API peak / off-peak pricing schedule.
|
|
40
|
-
*
|
|
41
|
-
* Official announcement (effective 2026-08-17, Beijing time):
|
|
42
|
-
* peak: 09:00–12:00 and 14:00–18:00 (UTC+8)
|
|
43
|
-
* off-peak: everything else, billed at half the peak price
|
|
44
|
-
*
|
|
45
|
-
* Windows are half-open: [09:00, 12:00) and [14:00, 18:00).
|
|
46
|
-
*/
|
|
15
|
+
//#region src/pricing.ts
|
|
16
|
+
/** Shared DeepSeek pricing schedule used by Host billing and the client indicator. */
|
|
47
17
|
const BEIJING_OFFSET_MS = 288e5;
|
|
48
|
-
|
|
18
|
+
const DAY_MS = 864e5;
|
|
19
|
+
/** The current V4 schedule became effective at 00:00 Beijing time on 2026-08-17. */
|
|
49
20
|
const PEAK_EFFECTIVE_FROM = Date.parse("2026-08-17T00:00:00+08:00");
|
|
50
21
|
const PEAK_WINDOWS = [[9, 12], [14, 18]];
|
|
51
|
-
const DAY_MS = 864e5;
|
|
52
22
|
const BOUNDARY_SECONDS = [
|
|
53
23
|
32400,
|
|
54
24
|
43200,
|
|
@@ -76,6 +46,68 @@ window.__ModuleLoader__.load({
|
|
|
76
46
|
return /* @__PURE__ */ new Date(dayStartMs + boundary * 1e3 - BEIJING_OFFSET_MS);
|
|
77
47
|
}
|
|
78
48
|
//#endregion
|
|
49
|
+
//#region src/billing.ts
|
|
50
|
+
const USAGE_ROUTE = "/dsh-balance/api/usage";
|
|
51
|
+
const BILLING_PRICING_VERSION = "deepseek-v4-2026-08-17";
|
|
52
|
+
const CURRENT_PRICES = {
|
|
53
|
+
"deepseek-v4-flash": {
|
|
54
|
+
cacheHitUsdPerMillion: .007,
|
|
55
|
+
cacheMissUsdPerMillion: .22,
|
|
56
|
+
outputUsdPerMillion: .66
|
|
57
|
+
},
|
|
58
|
+
"deepseek-v4-pro": {
|
|
59
|
+
cacheHitUsdPerMillion: .022,
|
|
60
|
+
cacheMissUsdPerMillion: .66,
|
|
61
|
+
outputUsdPerMillion: 1.98
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
[...Object.entries({
|
|
65
|
+
"deepseek-chat": {
|
|
66
|
+
cacheHitUsdPerMillion: .07,
|
|
67
|
+
cacheMissUsdPerMillion: .27,
|
|
68
|
+
outputUsdPerMillion: 1.1
|
|
69
|
+
},
|
|
70
|
+
"deepseek-reasoner": {
|
|
71
|
+
cacheHitUsdPerMillion: .14,
|
|
72
|
+
cacheMissUsdPerMillion: .55,
|
|
73
|
+
outputUsdPerMillion: 2.19
|
|
74
|
+
}
|
|
75
|
+
}).map(([model, rates]) => ({
|
|
76
|
+
provider: "deepseek",
|
|
77
|
+
model,
|
|
78
|
+
effectiveFrom: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
79
|
+
pricingVersion: "deepseek-legacy",
|
|
80
|
+
...rates
|
|
81
|
+
})), ...Object.entries(CURRENT_PRICES).map(([model, rates]) => ({
|
|
82
|
+
provider: "deepseek",
|
|
83
|
+
model,
|
|
84
|
+
effectiveFrom: new Date(PEAK_EFFECTIVE_FROM).toISOString(),
|
|
85
|
+
pricingVersion: BILLING_PRICING_VERSION,
|
|
86
|
+
...rates
|
|
87
|
+
}))];
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/client/format.ts
|
|
90
|
+
function formatClockTime(date, locale) {
|
|
91
|
+
return new Intl.DateTimeFormat(locale, {
|
|
92
|
+
hour: "2-digit",
|
|
93
|
+
minute: "2-digit"
|
|
94
|
+
}).format(date);
|
|
95
|
+
}
|
|
96
|
+
function displayAmount(value, currency, locale) {
|
|
97
|
+
const amount = Number(value);
|
|
98
|
+
if (!Number.isFinite(amount)) return `${value} ${currency}`;
|
|
99
|
+
try {
|
|
100
|
+
return new Intl.NumberFormat(locale, {
|
|
101
|
+
style: "currency",
|
|
102
|
+
currency,
|
|
103
|
+
minimumFractionDigits: 2,
|
|
104
|
+
maximumFractionDigits: 8
|
|
105
|
+
}).format(amount);
|
|
106
|
+
} catch {
|
|
107
|
+
return `${value} ${currency}`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
79
111
|
//#region src/client/BalanceDock.tsx
|
|
80
112
|
const REFRESH_INTERVAL_MS = 6e4;
|
|
81
113
|
const PEAK_TICK_MS = 3e4;
|
|
@@ -151,33 +183,109 @@ window.__ModuleLoader__.load({
|
|
|
151
183
|
});
|
|
152
184
|
}
|
|
153
185
|
//#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
|
|
154
203
|
//#region src/client/locales.ts
|
|
155
204
|
const LOCALE_NS = "dsh-balance";
|
|
156
205
|
/** Simplified Chinese dictionary and source of truth for the namespace key set. */
|
|
157
206
|
const zh = {
|
|
158
207
|
"locale.tag": "zh-CN",
|
|
159
|
-
"
|
|
208
|
+
"panel.ledger": "账户总览",
|
|
209
|
+
"panel.private": "密钥仅存本机",
|
|
210
|
+
"panel.title": "账户余额",
|
|
211
|
+
"panel.copy": "查看各提供方的账户余额与 API 消费。",
|
|
212
|
+
"panel.providers": "选择提供方",
|
|
213
|
+
"panel.models": "可用模型",
|
|
214
|
+
"panel.activity": "消费记录",
|
|
215
|
+
"panel.allProviders": "全部提供方",
|
|
216
|
+
"panel.account": "账户余额",
|
|
217
|
+
"balance.availableAmount": "当前可用余额",
|
|
218
|
+
"balance.totalCash": "总充值金额",
|
|
219
|
+
"balance.totalVoucher": "总赠送金额",
|
|
220
|
+
"balance.prepaid": "预付费账户",
|
|
221
|
+
"balance.postpaid": "后付费账户",
|
|
222
|
+
"balance.totalsNote": "总充值与总赠送金额为账户累计金额,不代表当前剩余余额;账户类型不表示服务可用状态。",
|
|
223
|
+
"balance.setupDeepSeek": "在“设置 → 模型”保存 DeepSeek API 密钥,或配置 {ref} 环境变量。",
|
|
224
|
+
"balance.setup": "在“设置 → 模型”添加自定义提供方,Provider ID 填写 {provider}(大小写不限),并保存 API 密钥。默认凭据为 {ref};自定义凭据请检查插件配置。",
|
|
225
|
+
"error.UNSUPPORTED_PROVIDER": "暂不支持此提供方的余额查询",
|
|
226
|
+
"nav.balance": "模型余额",
|
|
160
227
|
"action.loading": "查询中…",
|
|
161
|
-
"balance.title": "
|
|
228
|
+
"balance.title": "{provider} 账户",
|
|
162
229
|
"balance.copy": "余额由本机 Host 使用已保存的 API 密钥查询,密钥不会发送到浏览器。",
|
|
163
230
|
"balance.refresh": "刷新余额",
|
|
164
|
-
"balance.loading": "
|
|
231
|
+
"balance.loading": "正在查询账户余额…",
|
|
165
232
|
"balance.available": "当前账户有可用余额",
|
|
166
233
|
"balance.unavailable": "当前账户没有可用余额",
|
|
167
|
-
"balance.empty": "
|
|
234
|
+
"balance.empty": "提供方未返回任何币种余额。",
|
|
168
235
|
"balance.toppedUp": "充值余额",
|
|
169
236
|
"balance.granted": "赠送余额",
|
|
170
237
|
"dock.label": "DeepSeek 余额",
|
|
171
238
|
"dock.loading": "查询中…",
|
|
172
239
|
"dock.unavailable": "暂时无法获取",
|
|
173
240
|
"dock.empty": "暂无余额信息",
|
|
174
|
-
"models.title": "
|
|
175
|
-
"models.copy": "
|
|
241
|
+
"models.title": "{provider} 可用模型",
|
|
242
|
+
"models.copy": "查看 {provider} 返回的可用模型。",
|
|
176
243
|
"models.refresh": "刷新模型",
|
|
177
|
-
"models.loading": "
|
|
244
|
+
"models.loading": "正在查询模型列表…",
|
|
178
245
|
"models.count": "当前可用 {count} 个模型",
|
|
179
|
-
"models.empty": "
|
|
246
|
+
"models.empty": "提供方未返回任何可用模型。",
|
|
180
247
|
"models.owner": "由 {owner} 提供",
|
|
248
|
+
"models.created": "创建于 {date}",
|
|
249
|
+
"billing.tab": "消费",
|
|
250
|
+
"billing.title": "API 消费统计",
|
|
251
|
+
"billing.copy": "按会话、模型和日期统计实际 provider usage;日期按 {timeZone} 分组。",
|
|
252
|
+
"billing.range": "统计范围",
|
|
253
|
+
"billing.todayRange": "今日",
|
|
254
|
+
"billing.sevenDays": "最近 7 天",
|
|
255
|
+
"billing.thirtyDays": "最近 30 天",
|
|
256
|
+
"billing.allTime": "全部时间",
|
|
257
|
+
"billing.refresh": "刷新消费",
|
|
258
|
+
"billing.loading": "正在读取消费记录…",
|
|
259
|
+
"billing.empty": "暂无消费记录。",
|
|
260
|
+
"billing.totalCost": "总消费",
|
|
261
|
+
"billing.todayCost": "今日消费",
|
|
262
|
+
"billing.today": "日期 {date}",
|
|
263
|
+
"billing.pricedRequests": "已计费请求 {count} 次",
|
|
264
|
+
"billing.tokens": "Token 总量",
|
|
265
|
+
"billing.requestCount": "{count} 次请求",
|
|
266
|
+
"billing.share": "占已知消费 {percent}",
|
|
267
|
+
"billing.unpriced": "未计费请求",
|
|
268
|
+
"billing.unpricedHint": "缺少 usage 或价格未知,不进行估算",
|
|
269
|
+
"billing.fixedRate": "固定汇率换算",
|
|
270
|
+
"billing.tokensBreakdown": "输入 {input} · 输出 {output} · Cache hit {cacheHit} · Cache write {cacheWrite}",
|
|
271
|
+
"billing.byModel": "按模型",
|
|
272
|
+
"billing.bySession": "按会话",
|
|
273
|
+
"billing.byDay": "按日期",
|
|
274
|
+
"billing.sessionTitle": "当前会话消费",
|
|
275
|
+
"billing.sessionCopy": "仅展示当前会话的 token 与计费结果,不展示 prompt 内容。",
|
|
276
|
+
"billing.requestDetails": "请求明细",
|
|
277
|
+
"billing.unknownModel": "未知模型",
|
|
278
|
+
"billing.inputOutput": "输入 {input} · 输出 {output}",
|
|
279
|
+
"billing.notPriced": "未计费",
|
|
280
|
+
"billing.reason.missing-usage": "缺少 provider usage",
|
|
281
|
+
"billing.reason.unknown-provider": "未知 provider",
|
|
282
|
+
"billing.reason.unknown-model": "未知模型价格",
|
|
283
|
+
"billing.reason.missing-request-metadata": "缺少请求模型信息",
|
|
284
|
+
"billing.error.FORBIDDEN": "此统计仅允许从本机访问",
|
|
285
|
+
"billing.error.INVALID_REQUEST": "消费统计参数无效",
|
|
286
|
+
"billing.error.METHOD_NOT_ALLOWED": "请求方法不受支持",
|
|
287
|
+
"billing.error.SESSION_NOT_FOUND": "找不到指定会话",
|
|
288
|
+
"billing.error.UPSTREAM_UNAVAILABLE": "无法读取会话消费记录",
|
|
181
289
|
"pricing.peak": "高峰时段",
|
|
182
290
|
"pricing.offPeak": "低谷时段",
|
|
183
291
|
"pricing.peakHint": "DeepSeek 高峰时段,API 价格为低谷的两倍,{time} 恢复低谷价",
|
|
@@ -185,40 +293,99 @@ window.__ModuleLoader__.load({
|
|
|
185
293
|
"meta.updated": "更新于 {time}",
|
|
186
294
|
"meta.cached": " · 缓存",
|
|
187
295
|
"error.FORBIDDEN": "此查询仅允许从本机访问",
|
|
188
|
-
"error.INVALID_API_KEY": "
|
|
189
|
-
"error.INVALID_RESPONSE": "
|
|
296
|
+
"error.INVALID_API_KEY": "API 密钥无效或没有查询权限",
|
|
297
|
+
"error.INVALID_RESPONSE": "返回了无法识别的响应",
|
|
190
298
|
"error.METHOD_NOT_ALLOWED": "请求方法不受支持",
|
|
191
|
-
"error.MISSING_API_KEY": "未配置
|
|
192
|
-
"error.RATE_LIMITED": "
|
|
193
|
-
"error.UPSTREAM_ERROR": "
|
|
194
|
-
"error.UPSTREAM_TIMEOUT": "查询
|
|
195
|
-
"error.UPSTREAM_UNAVAILABLE": "无法连接到
|
|
299
|
+
"error.MISSING_API_KEY": "未配置 API 密钥,请先在“模型”设置中保存",
|
|
300
|
+
"error.RATE_LIMITED": "API 请求过于频繁,请稍后重试",
|
|
301
|
+
"error.UPSTREAM_ERROR": "API 返回了错误",
|
|
302
|
+
"error.UPSTREAM_TIMEOUT": "查询 API 超时",
|
|
303
|
+
"error.UPSTREAM_UNAVAILABLE": "无法连接到 API"
|
|
196
304
|
};
|
|
197
305
|
/** English dictionary, checked complete against the Chinese key set. */
|
|
198
306
|
const en = {
|
|
199
307
|
"locale.tag": "en-US",
|
|
200
|
-
"
|
|
308
|
+
"panel.ledger": "ACCOUNT LEDGER",
|
|
309
|
+
"panel.private": "Keys stay local",
|
|
310
|
+
"panel.title": "Account balances",
|
|
311
|
+
"panel.copy": "View account balances and API usage by provider.",
|
|
312
|
+
"panel.providers": "Select provider",
|
|
313
|
+
"panel.models": "AVAILABLE MODELS",
|
|
314
|
+
"panel.activity": "USAGE ACTIVITY",
|
|
315
|
+
"panel.allProviders": "All providers",
|
|
316
|
+
"panel.account": "ACCOUNT BALANCE",
|
|
317
|
+
"balance.availableAmount": "Available balance",
|
|
318
|
+
"balance.totalCash": "Total cash credited",
|
|
319
|
+
"balance.totalVoucher": "Total vouchers granted",
|
|
320
|
+
"balance.prepaid": "Prepaid account",
|
|
321
|
+
"balance.postpaid": "Postpaid account",
|
|
322
|
+
"balance.totalsNote": "Cash and voucher totals are cumulative amounts, not remaining balances. Account type does not indicate service availability.",
|
|
323
|
+
"balance.setupDeepSeek": "Save your DeepSeek API key in Settings → Models, or set the {ref} environment variable.",
|
|
324
|
+
"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.",
|
|
325
|
+
"error.UNSUPPORTED_PROVIDER": "Balance queries are not supported for this provider",
|
|
326
|
+
"nav.balance": "Model Balances",
|
|
201
327
|
"action.loading": "Loading…",
|
|
202
|
-
"balance.title": "
|
|
328
|
+
"balance.title": "{provider} account",
|
|
203
329
|
"balance.copy": "The local Host queries your balance with the saved API key. The key is never sent to the browser.",
|
|
204
330
|
"balance.refresh": "Refresh balance",
|
|
205
|
-
"balance.loading": "Loading your
|
|
331
|
+
"balance.loading": "Loading your account balance…",
|
|
206
332
|
"balance.available": "This account has available balance",
|
|
207
333
|
"balance.unavailable": "This account has no available balance",
|
|
208
|
-
"balance.empty": "
|
|
334
|
+
"balance.empty": "The provider returned no currency balances.",
|
|
209
335
|
"balance.toppedUp": "Topped-up balance",
|
|
210
336
|
"balance.granted": "Granted balance",
|
|
211
337
|
"dock.label": "DeepSeek Balance",
|
|
212
338
|
"dock.loading": "Loading…",
|
|
213
339
|
"dock.unavailable": "Temporarily unavailable",
|
|
214
340
|
"dock.empty": "No balance information",
|
|
215
|
-
"models.title": "Available
|
|
216
|
-
"models.copy": "
|
|
341
|
+
"models.title": "Available {provider} models",
|
|
342
|
+
"models.copy": "Models available from {provider}.",
|
|
217
343
|
"models.refresh": "Refresh models",
|
|
218
|
-
"models.loading": "Loading the
|
|
344
|
+
"models.loading": "Loading the model list…",
|
|
219
345
|
"models.count": "{count} models available",
|
|
220
|
-
"models.empty": "
|
|
346
|
+
"models.empty": "The provider returned no available models.",
|
|
221
347
|
"models.owner": "Provided by {owner}",
|
|
348
|
+
"models.created": "Created {date}",
|
|
349
|
+
"billing.tab": "Usage",
|
|
350
|
+
"billing.title": "API Usage",
|
|
351
|
+
"billing.copy": "Actual provider usage grouped by session, model, and date; dates use {timeZone}.",
|
|
352
|
+
"billing.range": "Usage range",
|
|
353
|
+
"billing.todayRange": "Today",
|
|
354
|
+
"billing.sevenDays": "Last 7 days",
|
|
355
|
+
"billing.thirtyDays": "Last 30 days",
|
|
356
|
+
"billing.allTime": "All time",
|
|
357
|
+
"billing.refresh": "Refresh usage",
|
|
358
|
+
"billing.loading": "Loading usage records…",
|
|
359
|
+
"billing.empty": "No usage records.",
|
|
360
|
+
"billing.totalCost": "Total cost",
|
|
361
|
+
"billing.todayCost": "Today’s cost",
|
|
362
|
+
"billing.today": "Date {date}",
|
|
363
|
+
"billing.pricedRequests": "{count} priced requests",
|
|
364
|
+
"billing.tokens": "Total tokens",
|
|
365
|
+
"billing.requestCount": "{count} requests",
|
|
366
|
+
"billing.share": "{percent} of priced cost",
|
|
367
|
+
"billing.unpriced": "Unpriced requests",
|
|
368
|
+
"billing.unpricedHint": "Missing usage or unknown pricing; no estimate is made",
|
|
369
|
+
"billing.fixedRate": "fixed-rate conversion",
|
|
370
|
+
"billing.tokensBreakdown": "Input {input} · Output {output} · Cache hit {cacheHit} · Cache write {cacheWrite}",
|
|
371
|
+
"billing.byModel": "By model",
|
|
372
|
+
"billing.bySession": "By session",
|
|
373
|
+
"billing.byDay": "By day",
|
|
374
|
+
"billing.sessionTitle": "Current session usage",
|
|
375
|
+
"billing.sessionCopy": "Token and billing metadata only; prompt content is never shown.",
|
|
376
|
+
"billing.requestDetails": "Request details",
|
|
377
|
+
"billing.unknownModel": "Unknown model",
|
|
378
|
+
"billing.inputOutput": "Input {input} · Output {output}",
|
|
379
|
+
"billing.notPriced": "Unpriced",
|
|
380
|
+
"billing.reason.missing-usage": "Provider usage is missing",
|
|
381
|
+
"billing.reason.unknown-provider": "Unknown provider",
|
|
382
|
+
"billing.reason.unknown-model": "Unknown model pricing",
|
|
383
|
+
"billing.reason.missing-request-metadata": "Request model metadata is missing",
|
|
384
|
+
"billing.error.FORBIDDEN": "This usage view is available only from the local machine",
|
|
385
|
+
"billing.error.INVALID_REQUEST": "The usage query is invalid",
|
|
386
|
+
"billing.error.METHOD_NOT_ALLOWED": "This request method is not supported",
|
|
387
|
+
"billing.error.SESSION_NOT_FOUND": "The requested session was not found",
|
|
388
|
+
"billing.error.UPSTREAM_UNAVAILABLE": "Could not read session usage records",
|
|
222
389
|
"pricing.peak": "Peak hours",
|
|
223
390
|
"pricing.offPeak": "Off-peak hours",
|
|
224
391
|
"pricing.peakHint": "DeepSeek peak hours — API prices are double. Off-peak pricing resumes at {time}",
|
|
@@ -226,14 +393,14 @@ window.__ModuleLoader__.load({
|
|
|
226
393
|
"meta.updated": "Updated {time}",
|
|
227
394
|
"meta.cached": " · Cached",
|
|
228
395
|
"error.FORBIDDEN": "This query is available only from the local machine",
|
|
229
|
-
"error.INVALID_API_KEY": "The
|
|
230
|
-
"error.INVALID_RESPONSE": "
|
|
396
|
+
"error.INVALID_API_KEY": "The API key is invalid or lacks permission",
|
|
397
|
+
"error.INVALID_RESPONSE": "The provider returned an unrecognized response",
|
|
231
398
|
"error.METHOD_NOT_ALLOWED": "This request method is not supported",
|
|
232
|
-
"error.MISSING_API_KEY": "No
|
|
233
|
-
"error.RATE_LIMITED": "Too many
|
|
234
|
-
"error.UPSTREAM_ERROR": "The
|
|
235
|
-
"error.UPSTREAM_TIMEOUT": "The
|
|
236
|
-
"error.UPSTREAM_UNAVAILABLE": "Could not connect to the
|
|
399
|
+
"error.MISSING_API_KEY": "No API key is configured. Save one in Models settings first.",
|
|
400
|
+
"error.RATE_LIMITED": "Too many API requests. Try again later.",
|
|
401
|
+
"error.UPSTREAM_ERROR": "The API returned an error",
|
|
402
|
+
"error.UPSTREAM_TIMEOUT": "The API request timed out",
|
|
403
|
+
"error.UPSTREAM_UNAVAILABLE": "Could not connect to the API"
|
|
237
404
|
};
|
|
238
405
|
function errorLocaleKey(code) {
|
|
239
406
|
return `error.${code}`;
|
|
@@ -241,91 +408,116 @@ window.__ModuleLoader__.load({
|
|
|
241
408
|
//#endregion
|
|
242
409
|
//#region src/client/BalanceTab.tsx
|
|
243
410
|
function BalanceCard({ info, t }) {
|
|
411
|
+
const details = [
|
|
412
|
+
["balance.toppedUp", info.toppedUpBalance],
|
|
413
|
+
["balance.granted", info.grantedBalance],
|
|
414
|
+
["balance.totalCash", info.totalCashBalance],
|
|
415
|
+
["balance.totalVoucher", info.totalVoucherBalance]
|
|
416
|
+
];
|
|
244
417
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
245
418
|
className: "dsh-balance-card",
|
|
246
419
|
children: [
|
|
247
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
420
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
248
421
|
className: "dsh-balance-card-head",
|
|
249
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
422
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("balance.availableAmount") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
250
423
|
className: "dsh-balance-currency",
|
|
251
424
|
children: info.currency
|
|
252
|
-
})
|
|
425
|
+
})]
|
|
253
426
|
}),
|
|
254
427
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
255
428
|
className: "dsh-balance-total",
|
|
256
429
|
children: displayAmount(info.totalBalance, info.currency, t("locale.tag"))
|
|
257
430
|
}),
|
|
258
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
431
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dl", {
|
|
259
432
|
className: "dsh-balance-breakdown",
|
|
260
|
-
children: [
|
|
261
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("balance.toppedUp") }),
|
|
262
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(info.toppedUpBalance, info.currency, t("locale.tag")) }),
|
|
263
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("balance.granted") }),
|
|
264
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(info.grantedBalance, info.currency, t("locale.tag")) })
|
|
265
|
-
]
|
|
433
|
+
children: details.filter(([, value]) => value !== void 0).map(([label, value]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t(label) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(value, info.currency, t("locale.tag")) })] }, label))
|
|
266
434
|
})
|
|
267
435
|
]
|
|
268
436
|
});
|
|
269
437
|
}
|
|
270
|
-
function BalanceSection({ loadBalance, t }) {
|
|
438
|
+
function BalanceSection({ loadBalance, t, provider = "deepseek" }) {
|
|
271
439
|
const [result, setResult] = (0, react.useState)();
|
|
272
440
|
const [loading, setLoading] = (0, react.useState)(true);
|
|
273
|
-
const
|
|
441
|
+
const active = (0, react.useRef)();
|
|
442
|
+
const providerName = findBalanceProvider(provider).name;
|
|
443
|
+
const load = (0, react.useCallback)(async (forceRefresh) => {
|
|
444
|
+
active.current?.abort();
|
|
445
|
+
const controller = new AbortController();
|
|
446
|
+
active.current = controller;
|
|
447
|
+
const { signal } = controller;
|
|
274
448
|
setLoading(true);
|
|
275
449
|
try {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
setResult({
|
|
450
|
+
const value = await loadBalance(forceRefresh, signal, provider);
|
|
451
|
+
if (!signal.aborted) setResult(value);
|
|
452
|
+
} catch {
|
|
453
|
+
if (!signal.aborted) setResult({
|
|
280
454
|
ok: false,
|
|
281
455
|
code: "UPSTREAM_UNAVAILABLE",
|
|
282
|
-
message:
|
|
456
|
+
message: ""
|
|
283
457
|
});
|
|
284
458
|
} finally {
|
|
285
459
|
if (!signal.aborted) setLoading(false);
|
|
286
460
|
}
|
|
287
|
-
}, [loadBalance]);
|
|
461
|
+
}, [loadBalance, provider]);
|
|
288
462
|
(0, react.useEffect)(() => {
|
|
289
|
-
|
|
290
|
-
load(false
|
|
463
|
+
setResult(void 0);
|
|
464
|
+
load(false);
|
|
291
465
|
return () => {
|
|
292
|
-
|
|
466
|
+
active.current?.abort();
|
|
293
467
|
};
|
|
294
468
|
}, [load]);
|
|
295
|
-
const refresh = () => {
|
|
296
|
-
const controller = new AbortController();
|
|
297
|
-
load(true, controller.signal);
|
|
298
|
-
};
|
|
299
469
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
300
470
|
className: "dsh-balance-section",
|
|
301
471
|
"aria-labelledby": "dsh-balance-title",
|
|
472
|
+
"aria-busy": loading,
|
|
473
|
+
"data-provider": provider,
|
|
302
474
|
children: [
|
|
303
475
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
304
476
|
className: "dsh-balance-summary",
|
|
305
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
477
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
478
|
+
className: "dsh-ledger-kicker",
|
|
479
|
+
children: ["01 / ", t("panel.account")]
|
|
480
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
306
481
|
id: "dsh-balance-title",
|
|
307
482
|
className: "dsh-balance-heading",
|
|
308
|
-
children: t("balance.title")
|
|
309
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.
|
|
310
|
-
className: "dsh-balance-copy",
|
|
311
|
-
children: t("balance.copy")
|
|
312
|
-
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
483
|
+
children: t("balance.title", { provider: providerName })
|
|
484
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
313
485
|
className: "dsh-balance-refresh",
|
|
314
486
|
type: "button",
|
|
315
487
|
disabled: loading,
|
|
316
|
-
onClick:
|
|
317
|
-
|
|
488
|
+
onClick: () => {
|
|
489
|
+
load(true);
|
|
490
|
+
},
|
|
491
|
+
children: [
|
|
492
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
493
|
+
"aria-hidden": "true",
|
|
494
|
+
children: "↻"
|
|
495
|
+
}),
|
|
496
|
+
" ",
|
|
497
|
+
loading ? t("action.loading") : t("balance.refresh")
|
|
498
|
+
]
|
|
318
499
|
})]
|
|
319
500
|
}),
|
|
320
|
-
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.
|
|
321
|
-
className: "dsh-balance-
|
|
501
|
+
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
502
|
+
className: "dsh-balance-skeleton",
|
|
322
503
|
role: "status",
|
|
323
|
-
children:
|
|
504
|
+
children: [
|
|
505
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("balance.loading") }),
|
|
506
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
|
|
507
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {})
|
|
508
|
+
]
|
|
324
509
|
}) : null,
|
|
325
|
-
result?.ok === false ? /* @__PURE__ */ (0, react_jsx_runtime.
|
|
510
|
+
result?.ok === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
326
511
|
className: "dsh-balance-error",
|
|
327
512
|
role: "alert",
|
|
328
|
-
children:
|
|
513
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("strong", { children: [
|
|
514
|
+
providerName,
|
|
515
|
+
" / ",
|
|
516
|
+
t(errorLocaleKey(result.code))
|
|
517
|
+
] }), result.code === "MISSING_API_KEY" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t(provider === "deepseek" ? "balance.setupDeepSeek" : "balance.setup", {
|
|
518
|
+
provider: providerName,
|
|
519
|
+
ref: findBalanceProvider(provider).apiKeyRef
|
|
520
|
+
}) }) : null]
|
|
329
521
|
}) : null,
|
|
330
522
|
result?.ok === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
331
523
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -334,7 +526,7 @@ window.__ModuleLoader__.load({
|
|
|
334
526
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
335
527
|
className: "dsh-balance-dot",
|
|
336
528
|
"aria-hidden": "true"
|
|
337
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(result.isAvailable ? "balance.available" : "balance.unavailable") })]
|
|
529
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: result.accountType !== void 0 ? t(`balance.${result.accountType}`) : t(result.isAvailable ? "balance.available" : "balance.unavailable") })]
|
|
338
530
|
}),
|
|
339
531
|
result.balanceInfos.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
340
532
|
className: "dsh-balance-grid",
|
|
@@ -346,9 +538,16 @@ window.__ModuleLoader__.load({
|
|
|
346
538
|
className: "dsh-balance-status",
|
|
347
539
|
children: t("balance.empty")
|
|
348
540
|
}),
|
|
349
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
350
|
-
className: "dsh-balance-
|
|
351
|
-
children:
|
|
541
|
+
result.accountType !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
542
|
+
className: "dsh-balance-copy",
|
|
543
|
+
children: t("balance.totalsNote")
|
|
544
|
+
}) : null,
|
|
545
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
546
|
+
className: "dsh-balance-footer",
|
|
547
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
548
|
+
className: "dsh-balance-meta",
|
|
549
|
+
children: [t("meta.updated", { time: new Date(result.fetchedAt).toLocaleString(t("locale.tag")) }), result.source === "cache" ? t("meta.cached") : ""]
|
|
550
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.private") })]
|
|
352
551
|
})
|
|
353
552
|
] }) : null
|
|
354
553
|
]
|
|
@@ -359,62 +558,74 @@ window.__ModuleLoader__.load({
|
|
|
359
558
|
function ModelCard({ model, t }) {
|
|
360
559
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
361
560
|
className: "dsh-model-card",
|
|
362
|
-
children: [
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
561
|
+
children: [
|
|
562
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
563
|
+
className: "dsh-model-id",
|
|
564
|
+
children: model.id
|
|
565
|
+
}),
|
|
566
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
567
|
+
className: "dsh-model-owner",
|
|
568
|
+
children: t("models.owner", { owner: model.ownedBy })
|
|
569
|
+
}),
|
|
570
|
+
model.created === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
571
|
+
className: "dsh-model-owner",
|
|
572
|
+
children: t("models.created", { date: (/* @__PURE__ */ new Date(model.created * 1e3)).toLocaleDateString(t("locale.tag")) })
|
|
573
|
+
})
|
|
574
|
+
]
|
|
369
575
|
});
|
|
370
576
|
}
|
|
371
|
-
function ModelsSection({ loadModels, t }) {
|
|
577
|
+
function ModelsSection({ loadModels, t, provider = "deepseek" }) {
|
|
372
578
|
const [result, setResult] = (0, react.useState)();
|
|
373
579
|
const [loading, setLoading] = (0, react.useState)(true);
|
|
374
|
-
const
|
|
580
|
+
const active = (0, react.useRef)();
|
|
581
|
+
const providerName = findBalanceProvider(provider).name;
|
|
582
|
+
const load = (0, react.useCallback)(async (forceRefresh) => {
|
|
583
|
+
active.current?.abort();
|
|
584
|
+
const controller = new AbortController();
|
|
585
|
+
active.current = controller;
|
|
586
|
+
const { signal } = controller;
|
|
375
587
|
setLoading(true);
|
|
376
588
|
try {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
setResult({
|
|
589
|
+
const value = await loadModels(forceRefresh, signal, provider);
|
|
590
|
+
if (!signal.aborted) setResult(value);
|
|
591
|
+
} catch {
|
|
592
|
+
if (!signal.aborted) setResult({
|
|
381
593
|
ok: false,
|
|
382
594
|
code: "UPSTREAM_UNAVAILABLE",
|
|
383
|
-
message:
|
|
595
|
+
message: ""
|
|
384
596
|
});
|
|
385
597
|
} finally {
|
|
386
598
|
if (!signal.aborted) setLoading(false);
|
|
387
599
|
}
|
|
388
|
-
}, [loadModels]);
|
|
600
|
+
}, [loadModels, provider]);
|
|
389
601
|
(0, react.useEffect)(() => {
|
|
390
|
-
|
|
391
|
-
load(false
|
|
602
|
+
setResult(void 0);
|
|
603
|
+
load(false);
|
|
392
604
|
return () => {
|
|
393
|
-
|
|
605
|
+
active.current?.abort();
|
|
394
606
|
};
|
|
395
607
|
}, [load]);
|
|
396
|
-
const refresh = () => {
|
|
397
|
-
const controller = new AbortController();
|
|
398
|
-
load(true, controller.signal);
|
|
399
|
-
};
|
|
400
608
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
401
609
|
className: "dsh-models-section",
|
|
402
610
|
"aria-labelledby": "dsh-models-title",
|
|
611
|
+
"aria-busy": loading,
|
|
403
612
|
children: [
|
|
404
613
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
405
614
|
className: "dsh-balance-summary",
|
|
406
615
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
407
616
|
id: "dsh-models-title",
|
|
408
617
|
className: "dsh-balance-heading",
|
|
409
|
-
children: t("models.title")
|
|
618
|
+
children: t("models.title", { provider: providerName })
|
|
410
619
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
411
620
|
className: "dsh-balance-copy",
|
|
412
|
-
children: t("models.copy")
|
|
621
|
+
children: t("models.copy", { provider: providerName })
|
|
413
622
|
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
414
623
|
className: "dsh-balance-refresh",
|
|
415
624
|
type: "button",
|
|
416
625
|
disabled: loading,
|
|
417
|
-
onClick:
|
|
626
|
+
onClick: () => {
|
|
627
|
+
load(true);
|
|
628
|
+
},
|
|
418
629
|
children: loading ? t("action.loading") : t("models.refresh")
|
|
419
630
|
})]
|
|
420
631
|
}),
|
|
@@ -455,23 +666,510 @@ window.__ModuleLoader__.load({
|
|
|
455
666
|
});
|
|
456
667
|
}
|
|
457
668
|
//#endregion
|
|
669
|
+
//#region src/client/BillingTab.tsx
|
|
670
|
+
function formatTokens(value) {
|
|
671
|
+
return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(value);
|
|
672
|
+
}
|
|
673
|
+
function amount(value, currency, locale) {
|
|
674
|
+
return value === null ? "—" : displayAmount(String(value), currency, locale);
|
|
675
|
+
}
|
|
676
|
+
function localDateKey(timeZone, date = /* @__PURE__ */ new Date()) {
|
|
677
|
+
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
678
|
+
timeZone,
|
|
679
|
+
year: "numeric",
|
|
680
|
+
month: "2-digit",
|
|
681
|
+
day: "2-digit"
|
|
682
|
+
}).formatToParts(date);
|
|
683
|
+
const values = Object.fromEntries(parts.map((part) => [part.type, part.value]));
|
|
684
|
+
return `${values.year ?? "0000"}-${values.month ?? "00"}-${values.day ?? "00"}`;
|
|
685
|
+
}
|
|
686
|
+
function dateDaysAgo(timeZone, days) {
|
|
687
|
+
const local = new Date((/* @__PURE__ */ new Date()).toLocaleString("en-US", { timeZone }));
|
|
688
|
+
local.setDate(local.getDate() - days);
|
|
689
|
+
return localDateKey(timeZone, local);
|
|
690
|
+
}
|
|
691
|
+
function totalForDay(summary, date) {
|
|
692
|
+
return summary.byDay.find((item) => item.date === date) ?? {
|
|
693
|
+
requests: 0,
|
|
694
|
+
pricedRequests: 0,
|
|
695
|
+
unpricedRequests: 0,
|
|
696
|
+
inputTokens: 0,
|
|
697
|
+
outputTokens: 0,
|
|
698
|
+
cacheReadTokens: 0,
|
|
699
|
+
cacheWriteTokens: 0,
|
|
700
|
+
costUsd: 0,
|
|
701
|
+
costCny: summary.usdToCny === null ? null : 0
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function ErrorMessage({ result, t }) {
|
|
705
|
+
if (result.ok === true) return null;
|
|
706
|
+
const key = `billing.error.${result.code}`;
|
|
707
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
708
|
+
className: "dsh-balance-error",
|
|
709
|
+
role: "alert",
|
|
710
|
+
children: [t(key), result.message ? ` (${result.message})` : ""]
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
function CostLabel({ totals, t }) {
|
|
714
|
+
const locale = t("locale.tag");
|
|
715
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
716
|
+
className: "dsh-billing-cost-value",
|
|
717
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: amount(totals.costUsd, "USD", locale) }), totals.costCny !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
718
|
+
amount(totals.costCny, "CNY", locale),
|
|
719
|
+
" ",
|
|
720
|
+
t("billing.fixedRate")
|
|
721
|
+
] }) : null]
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
function SummaryCards({ summary, t }) {
|
|
725
|
+
const today = totalForDay(summary, localDateKey(summary.timeZone));
|
|
726
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
727
|
+
className: "dsh-billing-card-grid",
|
|
728
|
+
children: [
|
|
729
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
730
|
+
className: "dsh-billing-card dsh-billing-card-primary",
|
|
731
|
+
children: [
|
|
732
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.totalCost") }),
|
|
733
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
734
|
+
totals: summary.totals,
|
|
735
|
+
t
|
|
736
|
+
}),
|
|
737
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.pricedRequests", { count: summary.totals.pricedRequests }) })
|
|
738
|
+
]
|
|
739
|
+
}),
|
|
740
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
741
|
+
className: "dsh-billing-card",
|
|
742
|
+
children: [
|
|
743
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.todayCost") }),
|
|
744
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
745
|
+
totals: today,
|
|
746
|
+
t
|
|
747
|
+
}),
|
|
748
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.today", { date: localDateKey(summary.timeZone) }) })
|
|
749
|
+
]
|
|
750
|
+
}),
|
|
751
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
752
|
+
className: "dsh-billing-card",
|
|
753
|
+
children: [
|
|
754
|
+
/* @__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) }),
|
|
756
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
757
|
+
totals: summary.totals,
|
|
758
|
+
t
|
|
759
|
+
}),
|
|
760
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.requestCount", { count: summary.totals.requests }) })
|
|
761
|
+
]
|
|
762
|
+
}),
|
|
763
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
764
|
+
className: "dsh-billing-card",
|
|
765
|
+
"data-warning": summary.totals.unpricedRequests > 0 ? "true" : "false",
|
|
766
|
+
children: [
|
|
767
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.unpriced") }),
|
|
768
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: formatTokens(summary.totals.unpricedRequests) }),
|
|
769
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.unpricedHint") })
|
|
770
|
+
]
|
|
771
|
+
})
|
|
772
|
+
]
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
function TotalsCaption({ totals, t }) {
|
|
776
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
777
|
+
className: "dsh-billing-secondary",
|
|
778
|
+
children: t("billing.tokensBreakdown", {
|
|
779
|
+
input: formatTokens(totals.inputTokens),
|
|
780
|
+
output: formatTokens(totals.outputTokens),
|
|
781
|
+
cacheHit: formatTokens(totals.cacheReadTokens),
|
|
782
|
+
cacheWrite: formatTokens(totals.cacheWriteTokens)
|
|
783
|
+
})
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
function ModelRows({ summary, t }) {
|
|
787
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
788
|
+
className: "dsh-billing-list",
|
|
789
|
+
children: summary.byModel.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
790
|
+
className: "dsh-balance-status",
|
|
791
|
+
children: t("billing.empty")
|
|
792
|
+
}) : summary.byModel.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
793
|
+
className: "dsh-billing-list-row",
|
|
794
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("code", { children: [
|
|
795
|
+
item.provider,
|
|
796
|
+
"/",
|
|
797
|
+
item.model
|
|
798
|
+
] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
799
|
+
totals: item,
|
|
800
|
+
t
|
|
801
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
802
|
+
className: "dsh-billing-list-value",
|
|
803
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
804
|
+
totals: item,
|
|
805
|
+
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
|
+
] })]
|
|
811
|
+
})]
|
|
812
|
+
}, `${item.provider}/${item.model}`))
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
function UsageTables({ summary, t }) {
|
|
816
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
817
|
+
className: "dsh-billing-table-grid",
|
|
818
|
+
children: [
|
|
819
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
820
|
+
className: "dsh-billing-list-section",
|
|
821
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.byModel") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelRows, {
|
|
822
|
+
summary,
|
|
823
|
+
t
|
|
824
|
+
})]
|
|
825
|
+
}),
|
|
826
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
827
|
+
className: "dsh-billing-list-section",
|
|
828
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.bySession") }), summary.bySession.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
829
|
+
className: "dsh-balance-status",
|
|
830
|
+
children: t("billing.empty")
|
|
831
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
832
|
+
className: "dsh-billing-list",
|
|
833
|
+
children: summary.bySession.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
834
|
+
className: "dsh-billing-list-row",
|
|
835
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
836
|
+
className: "dsh-billing-session-title",
|
|
837
|
+
children: item.title
|
|
838
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
839
|
+
totals: item,
|
|
840
|
+
t
|
|
841
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
842
|
+
className: "dsh-billing-list-value",
|
|
843
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
844
|
+
totals: item,
|
|
845
|
+
t
|
|
846
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.requestCount", { count: item.requests }) })]
|
|
847
|
+
})]
|
|
848
|
+
}, item.sessionId))
|
|
849
|
+
})]
|
|
850
|
+
}),
|
|
851
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
852
|
+
className: "dsh-billing-list-section dsh-billing-list-wide",
|
|
853
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.byDay") }), summary.byDay.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
854
|
+
className: "dsh-balance-status",
|
|
855
|
+
children: t("billing.empty")
|
|
856
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
857
|
+
className: "dsh-billing-list",
|
|
858
|
+
children: summary.byDay.map((item) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
859
|
+
className: "dsh-billing-list-row",
|
|
860
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
861
|
+
className: "dsh-billing-session-title",
|
|
862
|
+
children: item.date
|
|
863
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TotalsCaption, {
|
|
864
|
+
totals: item,
|
|
865
|
+
t
|
|
866
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
867
|
+
className: "dsh-billing-list-value",
|
|
868
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CostLabel, {
|
|
869
|
+
totals: item,
|
|
870
|
+
t
|
|
871
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("billing.requestCount", { count: item.requests }) })]
|
|
872
|
+
})]
|
|
873
|
+
}, item.date))
|
|
874
|
+
})]
|
|
875
|
+
})
|
|
876
|
+
]
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
function RequestRows({ requests, t }) {
|
|
880
|
+
const locale = t("locale.tag");
|
|
881
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
882
|
+
className: "dsh-billing-request-list",
|
|
883
|
+
children: requests.map((request) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
|
|
884
|
+
className: "dsh-billing-request-row",
|
|
885
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
886
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: new Date(request.time).toLocaleString(locale) }),
|
|
887
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: request.model ?? t("billing.unknownModel") }),
|
|
888
|
+
request.unknownReason !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
889
|
+
className: "dsh-billing-secondary",
|
|
890
|
+
children: t(`billing.reason.${request.unknownReason}`)
|
|
891
|
+
}) : null
|
|
892
|
+
] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
893
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("billing.inputOutput", {
|
|
894
|
+
input: formatTokens(request.inputTokens),
|
|
895
|
+
output: formatTokens(request.outputTokens)
|
|
896
|
+
}) }),
|
|
897
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
898
|
+
className: "dsh-billing-secondary",
|
|
899
|
+
children: t("billing.tokensBreakdown", {
|
|
900
|
+
input: formatTokens(request.inputTokens),
|
|
901
|
+
output: formatTokens(request.outputTokens),
|
|
902
|
+
cacheHit: formatTokens(request.cacheReadTokens),
|
|
903
|
+
cacheWrite: formatTokens(request.cacheWriteTokens)
|
|
904
|
+
})
|
|
905
|
+
}),
|
|
906
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: request.costUsd === null ? t("billing.notPriced") : amount(request.costUsd, "USD", locale) })
|
|
907
|
+
] })]
|
|
908
|
+
}, `${request.turn}:${request.step}:${request.time}`))
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
function useUsageResult(loadUsage, options, revision) {
|
|
912
|
+
const [result, setResult] = (0, react.useState)();
|
|
913
|
+
const [loading, setLoading] = (0, react.useState)(true);
|
|
914
|
+
const load = (0, react.useCallback)(async (forceRefresh, signal) => {
|
|
915
|
+
setLoading(true);
|
|
916
|
+
try {
|
|
917
|
+
setResult(await loadUsage({
|
|
918
|
+
...options,
|
|
919
|
+
forceRefresh
|
|
920
|
+
}, signal));
|
|
921
|
+
} catch (error) {
|
|
922
|
+
if (!signal.aborted) setResult({
|
|
923
|
+
ok: false,
|
|
924
|
+
code: "UPSTREAM_UNAVAILABLE",
|
|
925
|
+
message: error instanceof Error ? error.message : ""
|
|
926
|
+
});
|
|
927
|
+
} finally {
|
|
928
|
+
if (!signal.aborted) setLoading(false);
|
|
929
|
+
}
|
|
930
|
+
}, [loadUsage, options]);
|
|
931
|
+
(0, react.useEffect)(() => {
|
|
932
|
+
const controller = new AbortController();
|
|
933
|
+
load(false, controller.signal);
|
|
934
|
+
return () => {
|
|
935
|
+
controller.abort();
|
|
936
|
+
};
|
|
937
|
+
}, [load, revision]);
|
|
938
|
+
return {
|
|
939
|
+
result,
|
|
940
|
+
loading,
|
|
941
|
+
refresh: () => {
|
|
942
|
+
const controller = new AbortController();
|
|
943
|
+
load(true, controller.signal);
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
function BillingOverview({ loadUsage, t }) {
|
|
948
|
+
const timeZone = (0, react.useMemo)(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", []);
|
|
949
|
+
const [range, setRange] = (0, react.useState)("30d");
|
|
950
|
+
const options = (0, react.useMemo)(() => ({
|
|
951
|
+
scope: "all",
|
|
952
|
+
timeZone,
|
|
953
|
+
...range === "all" ? {} : {
|
|
954
|
+
from: range === "today" ? localDateKey(timeZone) : dateDaysAgo(timeZone, range === "7d" ? 6 : 29),
|
|
955
|
+
to: localDateKey(timeZone)
|
|
956
|
+
}
|
|
957
|
+
}), [range, timeZone]);
|
|
958
|
+
const { result, loading, refresh } = useUsageResult(loadUsage, options, JSON.stringify(options));
|
|
959
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
960
|
+
className: "dsh-billing-section",
|
|
961
|
+
"aria-labelledby": "dsh-billing-title",
|
|
962
|
+
children: [
|
|
963
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
964
|
+
className: "dsh-balance-summary",
|
|
965
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
966
|
+
id: "dsh-billing-title",
|
|
967
|
+
className: "dsh-balance-heading",
|
|
968
|
+
children: t("billing.title")
|
|
969
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
970
|
+
className: "dsh-balance-copy",
|
|
971
|
+
children: t("billing.copy", { timeZone })
|
|
972
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
973
|
+
className: "dsh-billing-actions",
|
|
974
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
975
|
+
"aria-label": t("billing.range"),
|
|
976
|
+
value: range,
|
|
977
|
+
onChange: (event) => setRange(event.target.value),
|
|
978
|
+
children: [
|
|
979
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
|
|
980
|
+
value: "today",
|
|
981
|
+
children: t("billing.todayRange")
|
|
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", {
|
|
992
|
+
value: "all",
|
|
993
|
+
children: t("billing.allTime")
|
|
994
|
+
})
|
|
995
|
+
]
|
|
996
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
997
|
+
className: "dsh-balance-refresh",
|
|
998
|
+
type: "button",
|
|
999
|
+
disabled: loading,
|
|
1000
|
+
onClick: refresh,
|
|
1001
|
+
children: loading ? t("action.loading") : t("billing.refresh")
|
|
1002
|
+
})]
|
|
1003
|
+
})]
|
|
1004
|
+
}),
|
|
1005
|
+
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1006
|
+
className: "dsh-balance-status",
|
|
1007
|
+
role: "status",
|
|
1008
|
+
children: t("billing.loading")
|
|
1009
|
+
}) : null,
|
|
1010
|
+
result !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
|
|
1011
|
+
result,
|
|
1012
|
+
t
|
|
1013
|
+
}) : null,
|
|
1014
|
+
result?.ok === true && result.scope === "all" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1015
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryCards, {
|
|
1016
|
+
summary: result.summary,
|
|
1017
|
+
t
|
|
1018
|
+
}),
|
|
1019
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageTables, {
|
|
1020
|
+
summary: result.summary,
|
|
1021
|
+
t
|
|
1022
|
+
}),
|
|
1023
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1024
|
+
className: "dsh-balance-meta",
|
|
1025
|
+
children: [t("meta.updated", { time: new Date(result.fetchedAt).toLocaleString(t("locale.tag")) }), result.source === "cache" ? t("meta.cached") : ""]
|
|
1026
|
+
})
|
|
1027
|
+
] }) : null
|
|
1028
|
+
]
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
function BillingView({ loadUsage, sessionId, useSession, t }) {
|
|
1032
|
+
const timeZone = (0, react.useMemo)(() => Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC", []);
|
|
1033
|
+
const lastAssistant = useSession((snapshot) => {
|
|
1034
|
+
for (let index = snapshot.nodes.length - 1; index >= 0; index -= 1) {
|
|
1035
|
+
const node = snapshot.nodes[index];
|
|
1036
|
+
if (node?.kind === "assistant") return `${node.seq}:${node.time}`;
|
|
1037
|
+
}
|
|
1038
|
+
return "empty";
|
|
1039
|
+
});
|
|
1040
|
+
const { result, loading, refresh } = useUsageResult(loadUsage, (0, react.useMemo)(() => ({
|
|
1041
|
+
scope: "session",
|
|
1042
|
+
sessionId,
|
|
1043
|
+
timeZone
|
|
1044
|
+
}), [sessionId, timeZone]), `${sessionId}:${lastAssistant}`);
|
|
1045
|
+
const sessionResult = result?.ok === true && result.scope === "session" ? result : void 0;
|
|
1046
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1047
|
+
className: "dsh-billing-view",
|
|
1048
|
+
"aria-labelledby": "dsh-billing-view-title",
|
|
1049
|
+
children: [
|
|
1050
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1051
|
+
className: "dsh-balance-summary",
|
|
1052
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
1053
|
+
id: "dsh-billing-view-title",
|
|
1054
|
+
className: "dsh-balance-heading",
|
|
1055
|
+
children: t("billing.sessionTitle")
|
|
1056
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1057
|
+
className: "dsh-balance-copy",
|
|
1058
|
+
children: t("billing.sessionCopy")
|
|
1059
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
1060
|
+
className: "dsh-balance-refresh",
|
|
1061
|
+
type: "button",
|
|
1062
|
+
disabled: loading,
|
|
1063
|
+
onClick: refresh,
|
|
1064
|
+
children: loading ? t("action.loading") : t("billing.refresh")
|
|
1065
|
+
})]
|
|
1066
|
+
}),
|
|
1067
|
+
loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
1068
|
+
className: "dsh-balance-status",
|
|
1069
|
+
role: "status",
|
|
1070
|
+
children: t("billing.loading")
|
|
1071
|
+
}) : null,
|
|
1072
|
+
result !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorMessage, {
|
|
1073
|
+
result,
|
|
1074
|
+
t
|
|
1075
|
+
}) : null,
|
|
1076
|
+
sessionResult !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1077
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SummaryCards, {
|
|
1078
|
+
summary: sessionResult.summary,
|
|
1079
|
+
t
|
|
1080
|
+
}),
|
|
1081
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1082
|
+
className: "dsh-billing-list-section",
|
|
1083
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.byModel") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelRows, {
|
|
1084
|
+
summary: sessionResult.summary,
|
|
1085
|
+
t
|
|
1086
|
+
})]
|
|
1087
|
+
}),
|
|
1088
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
1089
|
+
className: "dsh-billing-session-breakdown",
|
|
1090
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("billing.requestDetails") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RequestRows, {
|
|
1091
|
+
requests: sessionResult.requests,
|
|
1092
|
+
t
|
|
1093
|
+
})]
|
|
1094
|
+
}),
|
|
1095
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
1096
|
+
className: "dsh-balance-meta",
|
|
1097
|
+
children: [t("meta.updated", { time: new Date(sessionResult.fetchedAt).toLocaleString(t("locale.tag")) }), sessionResult.source === "cache" ? t("meta.cached") : ""]
|
|
1098
|
+
})
|
|
1099
|
+
] }) : null
|
|
1100
|
+
]
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
//#endregion
|
|
458
1104
|
//#region src/client/DeepSeekPanel.tsx
|
|
459
|
-
/**
|
|
460
|
-
function DeepSeekPanel({ loadBalance, loadModels, t }) {
|
|
1105
|
+
/** Provider-neutral settings workspace. The exported name preserves existing integrations. */
|
|
1106
|
+
function DeepSeekPanel({ loadBalance, loadModels, loadUsage, t }) {
|
|
1107
|
+
const [provider, setProvider] = (0, react.useState)("deepseek");
|
|
461
1108
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
462
1109
|
className: "dsh-deepseek-panel",
|
|
463
1110
|
children: [
|
|
1111
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
|
|
1112
|
+
className: "dsh-ledger-header",
|
|
1113
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1114
|
+
className: "dsh-ledger-eyebrow",
|
|
1115
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["DSH / ", t("panel.ledger")] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.private") })]
|
|
1116
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1117
|
+
className: "dsh-ledger-intro",
|
|
1118
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: t("panel.title") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("panel.copy") })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1119
|
+
className: "dsh-ledger-orbit",
|
|
1120
|
+
"aria-hidden": "true",
|
|
1121
|
+
children: [
|
|
1122
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
|
|
1123
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
|
|
1124
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
|
|
1125
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "↗" })
|
|
1126
|
+
]
|
|
1127
|
+
})]
|
|
1128
|
+
})]
|
|
1129
|
+
}),
|
|
1130
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1131
|
+
className: "dsh-provider-switch",
|
|
1132
|
+
role: "group",
|
|
1133
|
+
"aria-label": t("panel.providers"),
|
|
1134
|
+
children: BALANCE_PROVIDERS.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
1135
|
+
type: "button",
|
|
1136
|
+
"aria-pressed": provider === item.id,
|
|
1137
|
+
onClick: () => setProvider(item.id),
|
|
1138
|
+
children: [
|
|
1139
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1140
|
+
className: "dsh-provider-index",
|
|
1141
|
+
children: ["0", index + 1]
|
|
1142
|
+
}),
|
|
1143
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: item.name }),
|
|
1144
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1145
|
+
className: "dsh-provider-arrow",
|
|
1146
|
+
"aria-hidden": "true",
|
|
1147
|
+
children: "↗"
|
|
1148
|
+
})
|
|
1149
|
+
]
|
|
1150
|
+
}, item.id))
|
|
1151
|
+
}),
|
|
464
1152
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BalanceSection, {
|
|
1153
|
+
provider,
|
|
465
1154
|
loadBalance,
|
|
466
1155
|
t
|
|
467
|
-
}),
|
|
468
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
469
|
-
className: "dsh-
|
|
470
|
-
"
|
|
1156
|
+
}, `balance-${provider}`),
|
|
1157
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1158
|
+
className: "dsh-ledger-section-label",
|
|
1159
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["02 / ", t("panel.models")] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: findBalanceProvider(provider).name })]
|
|
471
1160
|
}),
|
|
472
1161
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelsSection, {
|
|
1162
|
+
provider,
|
|
473
1163
|
loadModels,
|
|
474
1164
|
t
|
|
1165
|
+
}, `models-${provider}`),
|
|
1166
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1167
|
+
className: "dsh-ledger-section-label",
|
|
1168
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: ["03 / ", t("panel.activity")] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("panel.allProviders") })]
|
|
1169
|
+
}),
|
|
1170
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BillingOverview, {
|
|
1171
|
+
loadUsage,
|
|
1172
|
+
t
|
|
475
1173
|
})
|
|
476
1174
|
]
|
|
477
1175
|
});
|
|
@@ -480,75 +1178,172 @@ window.__ModuleLoader__.load({
|
|
|
480
1178
|
//#region src/client/styles.ts
|
|
481
1179
|
const balanceStyles = `
|
|
482
1180
|
.dsh-deepseek-panel {
|
|
1181
|
+
--ledger-ink: var(--dsw-alias-label-primary, #202421);
|
|
1182
|
+
--ledger-muted: var(--dsw-alias-label-secondary, #60665f);
|
|
1183
|
+
--ledger-line: var(--dsw-alias-border-l2, #d7dbd3);
|
|
1184
|
+
--ledger-paper: var(--dsw-alias-bg-layer-3, #f5f6f0);
|
|
483
1185
|
display: flex;
|
|
484
1186
|
flex-direction: column;
|
|
485
|
-
gap:
|
|
486
|
-
max-width:
|
|
487
|
-
|
|
1187
|
+
gap: 24px;
|
|
1188
|
+
max-width: 1040px;
|
|
1189
|
+
min-width: 0;
|
|
1190
|
+
color: var(--ledger-ink);
|
|
1191
|
+
container-type: inline-size;
|
|
488
1192
|
}
|
|
489
|
-
.dsh-
|
|
490
|
-
.dsh-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
1193
|
+
.dsh-deepseek-panel *, .dsh-deepseek-panel *::before, .dsh-deepseek-panel *::after { box-sizing: border-box; }
|
|
1194
|
+
.dsh-ledger-header { border-top: 2px solid var(--ledger-ink); padding-top: 14px; }
|
|
1195
|
+
.dsh-ledger-eyebrow, .dsh-ledger-section-label, .dsh-ledger-kicker {
|
|
1196
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
1197
|
+
font-size: 11px;
|
|
1198
|
+
letter-spacing: .08em;
|
|
1199
|
+
line-height: 1.6;
|
|
1200
|
+
color: var(--ledger-muted);
|
|
494
1201
|
}
|
|
495
|
-
.dsh-
|
|
496
|
-
|
|
497
|
-
|
|
1202
|
+
.dsh-ledger-eyebrow, .dsh-ledger-section-label { display: flex; justify-content: space-between; gap: 16px; }
|
|
1203
|
+
.dsh-ledger-intro { display: grid; grid-template-columns: 1fr 150px; align-items: center; gap: 24px; padding: 32px 0 20px; }
|
|
1204
|
+
.dsh-ledger-intro h1 { max-width: 650px; margin: 0; font-size: 24px; font-weight: 500; line-height: 1.4; }
|
|
1205
|
+
.dsh-ledger-intro p { margin: 18px 0 0; color: var(--ledger-muted); font-size: 13px; line-height: 1.7; }
|
|
1206
|
+
.dsh-ledger-orbit { position: relative; display: grid; place-items: center; width: 148px; height: 148px; }
|
|
1207
|
+
.dsh-ledger-orbit i { position: absolute; width: 112px; height: 112px; border: 1px solid var(--ledger-muted); border-radius: 50%; transform: rotate(-35deg) scaleX(.5); }
|
|
1208
|
+
.dsh-ledger-orbit i:nth-child(2) { transform: rotate(25deg) scaleX(.5); }
|
|
1209
|
+
.dsh-ledger-orbit i:nth-child(3) { transform: rotate(85deg) scaleX(.5); }
|
|
1210
|
+
.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
|
+
.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; max-width: 270px; 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
|
+
.dsh-provider-switch button:hover { background: var(--ledger-paper); transform: translateY(-2px); }
|
|
1215
|
+
.dsh-provider-switch button[aria-pressed='true'] { color: #e5f6bd; background: #25352e; border-color: #25352e; }
|
|
1216
|
+
.dsh-provider-index { font-family: ui-monospace, monospace; font-size: 10px; opacity: .7; }
|
|
1217
|
+
.dsh-provider-arrow { margin-left: auto; transition: transform .2s; }
|
|
1218
|
+
.dsh-provider-switch button[aria-pressed='true'] .dsh-provider-arrow { transform: rotate(45deg); }
|
|
1219
|
+
.dsh-ledger-kicker { margin: 0 0 8px; }
|
|
1220
|
+
.dsh-ledger-section-label { border-top: 1px solid var(--ledger-line); padding-top: 18px; margin-top: 12px; }
|
|
1221
|
+
.dsh-balance-section,
|
|
1222
|
+
.dsh-models-section,
|
|
1223
|
+
.dsh-billing-section,
|
|
1224
|
+
.dsh-billing-view { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
|
|
1225
|
+
.dsh-balance-section { animation: dsh-ledger-reveal .3s ease-out; }
|
|
1226
|
+
.dsh-balance-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
|
|
1227
|
+
.dsh-balance-heading { margin: 0; font-size: 20px; font-weight: 550; line-height: 1.4; letter-spacing: -.025em; }
|
|
1228
|
+
.dsh-balance-copy { margin: 4px 0 0; color: var(--dsw-alias-label-secondary, #60665f); font-size: 12px; line-height: 1.7; }
|
|
1229
|
+
.dsh-balance-refresh { flex: none; appearance: none; border: 1px solid var(--dsw-alias-border-l2, #d7dbd3); border-radius: 4px; min-height: 36px; padding: 0 14px; background: transparent; color: var(--dsw-alias-label-primary, #202421); font: inherit; font-size: 12px; cursor: pointer; transition: background .2s; }
|
|
1230
|
+
.dsh-balance-refresh:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, #e9edde); }
|
|
1231
|
+
.dsh-balance-refresh:focus-visible, .dsh-provider-switch button:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary, #628537); outline-offset: 3px; }
|
|
1232
|
+
.dsh-balance-refresh:disabled { cursor: default; opacity: .55; }
|
|
1233
|
+
.dsh-balance-status, .dsh-balance-error { margin: 0; border: 1px solid var(--dsw-alias-border-l2, #d7dbd3); border-radius: 4px; padding: 24px; background: var(--dsw-alias-bg-layer-3, #f5f6f0); color: var(--dsw-alias-label-secondary, #60665f); font-size: 13px; line-height: 1.7; }
|
|
1234
|
+
.dsh-balance-error { border-left: 3px solid var(--dsw-alias-state-error-primary, #b04734); }
|
|
1235
|
+
.dsh-balance-error strong { color: var(--dsw-alias-state-error-primary, #b04734); }
|
|
1236
|
+
.dsh-balance-error p { margin: 10px 0 0; }
|
|
1237
|
+
.dsh-balance-availability { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ledger-muted); }
|
|
1238
|
+
.dsh-balance-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--dsw-alias-state-error-primary, #b04734); }
|
|
1239
|
+
.dsh-balance-availability[data-available='true'] .dsh-balance-dot { background: var(--dsw-alias-state-success-primary, #568434); }
|
|
1240
|
+
.dsh-balance-availability[data-available='null'] .dsh-balance-dot { background: var(--ledger-muted); }
|
|
1241
|
+
.dsh-balance-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; }
|
|
1242
|
+
.dsh-balance-card { position: relative; min-width: 0; overflow: hidden; border: 1px solid var(--ledger-line); border-radius: 4px; padding: 26px; background: var(--ledger-paper); }
|
|
1243
|
+
.dsh-balance-card:first-child { background: #25352e; border-color: #25352e; color: #f2f5eb; }
|
|
1244
|
+
.dsh-balance-card::before { content: ''; position: absolute; top: 0; right: 22px; height: 9px; width: 30px; border-left: 1px solid currentColor; border-right: 1px solid currentColor; opacity: .4; }
|
|
1245
|
+
.dsh-balance-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
|
|
1246
|
+
.dsh-balance-currency { font-family: ui-monospace, monospace; font-size: 11px; letter-spacing: .1em; padding: 4px 7px; border: 1px solid currentColor; border-radius: 3px; }
|
|
1247
|
+
.dsh-balance-total { margin: 24px 0 32px; font-size: clamp(32px, 6cqi, 64px); font-weight: 450; letter-spacing: -.045em; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
1248
|
+
.dsh-balance-card:first-child .dsh-balance-total { color: #d7ed9d; }
|
|
1249
|
+
.dsh-balance-breakdown { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 0; padding-top: 18px; border-top: 1px solid color-mix(in srgb, currentColor 20%, transparent); }
|
|
1250
|
+
.dsh-balance-breakdown dt { font-size: 11px; opacity: .75; line-height: 1.5; }
|
|
1251
|
+
.dsh-balance-breakdown dd { margin: 8px 0 0; font-size: 17px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
1252
|
+
.dsh-balance-meta { margin: 0; color: var(--dsw-alias-label-secondary, #60665f); font-size: 11px; line-height: 1.6; }
|
|
1253
|
+
.dsh-balance-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; color: var(--ledger-muted); font-size: 11px; }
|
|
1254
|
+
.dsh-balance-skeleton { min-height: 245px; display: flex; flex-direction: column; align-items: flex-start; gap: 28px; padding: 26px; border: 1px solid var(--ledger-line); background: var(--ledger-paper); font-size: 12px; color: var(--ledger-muted); }
|
|
1255
|
+
.dsh-balance-skeleton i { width: 60%; height: 42px; background: var(--ledger-line); animation: dsh-ledger-pulse 1.4s ease-in-out infinite alternate; }
|
|
1256
|
+
.dsh-balance-skeleton i:last-child { width: 35%; height: 16px; }
|
|
1257
|
+
@keyframes dsh-ledger-reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
|
|
1258
|
+
@keyframes dsh-ledger-pulse { to { opacity: .4; } }
|
|
1259
|
+
@container (max-width: 540px) {
|
|
1260
|
+
.dsh-ledger-intro { grid-template-columns: 1fr; padding-top: 24px; }
|
|
1261
|
+
.dsh-ledger-orbit { display: none; }
|
|
1262
|
+
.dsh-provider-switch button { padding: 12px; gap: 10px; }
|
|
1263
|
+
.dsh-balance-grid, .dsh-deepseek-panel .dsh-model-grid, .dsh-deepseek-panel .dsh-billing-card-grid, .dsh-deepseek-panel .dsh-billing-table-grid { grid-template-columns: 1fr; }
|
|
1264
|
+
.dsh-balance-card { padding: 20px; }
|
|
1265
|
+
.dsh-deepseek-panel .dsh-balance-summary { flex-wrap: wrap; }
|
|
498
1266
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
align-items: center;
|
|
502
|
-
justify-content: space-between;
|
|
503
|
-
gap: 16px;
|
|
1267
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1268
|
+
.dsh-deepseek-panel *, .dsh-deepseek-panel *::before, .dsh-deepseek-panel *::after { animation: none !important; transition: none !important; }
|
|
504
1269
|
}
|
|
505
|
-
.dsh-
|
|
506
|
-
.dsh-
|
|
507
|
-
.dsh-
|
|
508
|
-
|
|
509
|
-
appearance: none;
|
|
1270
|
+
.dsh-deepseek-panel .dsh-model-card, .dsh-deepseek-panel .dsh-billing-card, .dsh-deepseek-panel .dsh-billing-list-section { border-radius: 4px; }
|
|
1271
|
+
.dsh-billing-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
|
|
1272
|
+
.dsh-billing-actions select {
|
|
1273
|
+
min-height: 32px;
|
|
510
1274
|
border: 1px solid var(--dsw-alias-border-l2);
|
|
511
1275
|
border-radius: 16px;
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
background: transparent;
|
|
1276
|
+
padding: 0 12px;
|
|
1277
|
+
background: var(--dsw-alias-bg-layer-3);
|
|
515
1278
|
color: var(--dsw-alias-label-primary);
|
|
516
1279
|
font: inherit;
|
|
517
1280
|
font-size: 13px;
|
|
518
|
-
cursor: pointer;
|
|
519
1281
|
}
|
|
520
|
-
.dsh-
|
|
521
|
-
.dsh-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
1282
|
+
.dsh-billing-card-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
|
|
1283
|
+
.dsh-billing-card {
|
|
1284
|
+
display: flex;
|
|
1285
|
+
flex-direction: column;
|
|
1286
|
+
gap: 8px;
|
|
1287
|
+
min-height: 104px;
|
|
526
1288
|
border: 1px solid var(--dsw-alias-border-l2);
|
|
527
1289
|
border-radius: 12px;
|
|
528
|
-
padding:
|
|
1290
|
+
padding: 16px;
|
|
529
1291
|
background: var(--dsw-alias-bg-layer-3);
|
|
530
|
-
color: var(--dsw-alias-label-secondary);
|
|
531
|
-
font-size: 13px;
|
|
532
|
-
line-height: 1.6;
|
|
533
1292
|
}
|
|
534
|
-
.dsh-
|
|
535
|
-
.dsh-
|
|
536
|
-
.dsh-
|
|
537
|
-
.dsh-
|
|
538
|
-
.dsh-
|
|
539
|
-
.dsh-
|
|
1293
|
+
.dsh-billing-card > span,
|
|
1294
|
+
.dsh-billing-card > small { color: var(--dsw-alias-label-tertiary); font-size: 12px; }
|
|
1295
|
+
.dsh-billing-card > small { margin-top: auto; line-height: 1.45; }
|
|
1296
|
+
.dsh-billing-card-primary { border-color: color-mix(in srgb, var(--dsw-alias-brand-primary) 35%, var(--dsw-alias-border-l2)); }
|
|
1297
|
+
.dsh-billing-card[data-warning='true'] { border-color: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 45%, var(--dsw-alias-border-l2)); }
|
|
1298
|
+
.dsh-billing-card > strong { font-size: 22px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
|
|
1299
|
+
.dsh-billing-cost-value { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
|
|
1300
|
+
.dsh-billing-cost-value strong { font-size: 20px; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
|
|
1301
|
+
.dsh-billing-cost-value span { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 1.35; }
|
|
1302
|
+
.dsh-billing-table-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
|
|
1303
|
+
.dsh-billing-list-section {
|
|
1304
|
+
min-width: 0;
|
|
540
1305
|
border: 1px solid var(--dsw-alias-border-l2);
|
|
541
1306
|
border-radius: 12px;
|
|
542
1307
|
padding: 16px;
|
|
543
1308
|
background: var(--dsw-alias-bg-layer-3);
|
|
544
1309
|
}
|
|
545
|
-
.dsh-
|
|
546
|
-
.dsh-
|
|
547
|
-
.dsh-
|
|
548
|
-
.dsh-
|
|
549
|
-
.dsh-
|
|
550
|
-
|
|
551
|
-
|
|
1310
|
+
.dsh-billing-list-section h3,
|
|
1311
|
+
.dsh-billing-session-breakdown h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
|
|
1312
|
+
.dsh-billing-list-wide { grid-column: 1 / -1; }
|
|
1313
|
+
.dsh-billing-list { display: flex; flex-direction: column; gap: 2px; }
|
|
1314
|
+
.dsh-billing-list-row {
|
|
1315
|
+
display: flex;
|
|
1316
|
+
align-items: center;
|
|
1317
|
+
justify-content: space-between;
|
|
1318
|
+
gap: 16px;
|
|
1319
|
+
min-height: 54px;
|
|
1320
|
+
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
|
1321
|
+
padding: 9px 0;
|
|
1322
|
+
}
|
|
1323
|
+
.dsh-billing-list-row:last-child { border-bottom: 0; }
|
|
1324
|
+
.dsh-billing-list-row > div:first-child { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
1325
|
+
.dsh-billing-list-row code { color: var(--dsw-alias-label-primary); font-size: 12px; overflow-wrap: anywhere; }
|
|
1326
|
+
.dsh-billing-secondary { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 1.35; }
|
|
1327
|
+
.dsh-billing-list-value { display: flex; flex: none; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; }
|
|
1328
|
+
.dsh-billing-list-value > small { color: var(--dsw-alias-label-tertiary); font-size: 11px; }
|
|
1329
|
+
.dsh-billing-session-title { overflow: hidden; color: var(--dsw-alias-label-primary); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
|
|
1330
|
+
.dsh-billing-session-breakdown { border: 1px solid var(--dsw-alias-border-l2); border-radius: 12px; padding: 16px; background: var(--dsw-alias-bg-layer-3); }
|
|
1331
|
+
.dsh-billing-request-list { display: flex; flex-direction: column; }
|
|
1332
|
+
.dsh-billing-request-row {
|
|
1333
|
+
display: flex;
|
|
1334
|
+
align-items: center;
|
|
1335
|
+
justify-content: space-between;
|
|
1336
|
+
gap: 16px;
|
|
1337
|
+
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
|
1338
|
+
padding: 11px 0;
|
|
1339
|
+
font-size: 12px;
|
|
1340
|
+
}
|
|
1341
|
+
.dsh-billing-request-row:last-child { border-bottom: 0; }
|
|
1342
|
+
.dsh-billing-request-row > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
|
|
1343
|
+
.dsh-billing-request-row > div:last-child { align-items: flex-end; text-align: right; }
|
|
1344
|
+
.dsh-billing-request-row span { color: var(--dsw-alias-label-tertiary); }
|
|
1345
|
+
.dsh-billing-request-row code { color: var(--dsw-alias-label-secondary); overflow-wrap: anywhere; }
|
|
1346
|
+
.dsh-billing-request-row strong { font-variant-numeric: tabular-nums; }
|
|
552
1347
|
.dsh-model-count { display: flex; align-items: center; gap: 8px; font-size: 13px; }
|
|
553
1348
|
.dsh-model-count .dsh-balance-dot { background: var(--dsw-alias-state-success-primary); }
|
|
554
1349
|
.dsh-model-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
|
|
@@ -608,14 +1403,23 @@ window.__ModuleLoader__.load({
|
|
|
608
1403
|
@media (max-width: 640px) {
|
|
609
1404
|
.dsh-balance-summary { align-items: flex-start; }
|
|
610
1405
|
.dsh-balance-grid,
|
|
611
|
-
.dsh-model-grid
|
|
1406
|
+
.dsh-model-grid,
|
|
1407
|
+
.dsh-billing-card-grid,
|
|
1408
|
+
.dsh-billing-table-grid { grid-template-columns: 1fr; }
|
|
1409
|
+
.dsh-billing-list-wide { grid-column: auto; }
|
|
1410
|
+
.dsh-billing-actions { justify-content: flex-start; }
|
|
1411
|
+
.dsh-billing-request-row { align-items: flex-start; flex-direction: column; }
|
|
1412
|
+
.dsh-billing-request-row > div:last-child { align-items: flex-start; text-align: left; }
|
|
612
1413
|
}
|
|
613
1414
|
`;
|
|
614
1415
|
//#endregion
|
|
615
1416
|
//#region src/client/index.tsx
|
|
616
1417
|
const inject = ["slots", "locale"];
|
|
617
|
-
async function loadBalance(forceRefresh, signal) {
|
|
618
|
-
const
|
|
1418
|
+
async function loadBalance(forceRefresh, signal, provider = "deepseek") {
|
|
1419
|
+
const params = new URLSearchParams({ provider });
|
|
1420
|
+
if (forceRefresh) params.set("refresh", "1");
|
|
1421
|
+
const url = `${BALANCE_ROUTE}?${params}`;
|
|
1422
|
+
const value = await (await fetch(url, {
|
|
619
1423
|
method: "GET",
|
|
620
1424
|
headers: { accept: "application/json" },
|
|
621
1425
|
cache: "no-store",
|
|
@@ -624,8 +1428,11 @@ window.__ModuleLoader__.load({
|
|
|
624
1428
|
if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("余额插件收到了无法识别的 Host 响应");
|
|
625
1429
|
return value;
|
|
626
1430
|
}
|
|
627
|
-
async function loadModels(forceRefresh, signal) {
|
|
628
|
-
const
|
|
1431
|
+
async function loadModels(forceRefresh, signal, provider = "deepseek") {
|
|
1432
|
+
const params = new URLSearchParams({ provider });
|
|
1433
|
+
if (forceRefresh) params.set("refresh", "1");
|
|
1434
|
+
const url = `${MODELS_ROUTE}?${params}`;
|
|
1435
|
+
const value = await (await fetch(url, {
|
|
629
1436
|
method: "GET",
|
|
630
1437
|
headers: { accept: "application/json" },
|
|
631
1438
|
cache: "no-store",
|
|
@@ -634,6 +1441,24 @@ window.__ModuleLoader__.load({
|
|
|
634
1441
|
if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("模型插件收到了无法识别的 Host 响应");
|
|
635
1442
|
return value;
|
|
636
1443
|
}
|
|
1444
|
+
async function loadUsage(options, signal) {
|
|
1445
|
+
const params = new URLSearchParams({
|
|
1446
|
+
scope: options.scope,
|
|
1447
|
+
timeZone: options.timeZone
|
|
1448
|
+
});
|
|
1449
|
+
if (options.sessionId !== void 0) params.set("sessionId", options.sessionId);
|
|
1450
|
+
if (options.from !== void 0) params.set("from", options.from);
|
|
1451
|
+
if (options.to !== void 0) params.set("to", options.to);
|
|
1452
|
+
if (options.forceRefresh === true) params.set("refresh", "1");
|
|
1453
|
+
const value = await (await fetch(`${USAGE_ROUTE}?${params.toString()}`, {
|
|
1454
|
+
method: "GET",
|
|
1455
|
+
headers: { accept: "application/json" },
|
|
1456
|
+
cache: "no-store",
|
|
1457
|
+
signal
|
|
1458
|
+
})).json();
|
|
1459
|
+
if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("消费统计插件收到了无法识别的 Host 响应");
|
|
1460
|
+
return value;
|
|
1461
|
+
}
|
|
637
1462
|
/** Register a standalone Settings page and an ambient composer balance readout. */
|
|
638
1463
|
function apply(ctx) {
|
|
639
1464
|
ctx.effect(() => ctx.locale.register(LOCALE_NS, {
|
|
@@ -659,9 +1484,18 @@ window.__ModuleLoader__.load({
|
|
|
659
1484
|
locale: LOCALE_NS,
|
|
660
1485
|
inject: () => ({
|
|
661
1486
|
loadBalance,
|
|
662
|
-
loadModels
|
|
1487
|
+
loadModels,
|
|
1488
|
+
loadUsage
|
|
663
1489
|
})
|
|
664
1490
|
}, DeepSeekPanel));
|
|
1491
|
+
ctx.slots.inject("conversation.view", () => ctx.slots.register({
|
|
1492
|
+
name: "conversation.view",
|
|
1493
|
+
id: "deepseek-billing",
|
|
1494
|
+
order: 30,
|
|
1495
|
+
label: () => t("billing.tab"),
|
|
1496
|
+
locale: LOCALE_NS,
|
|
1497
|
+
inject: () => ({ loadUsage })
|
|
1498
|
+
}, BillingView));
|
|
665
1499
|
ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
|
|
666
1500
|
name: "conversation.composer.dock",
|
|
667
1501
|
id: "deepseek-balance",
|