@pinkbanana/dsh-balance 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-balance contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # dsh-balance
2
+
3
+ [简体中文](./README.md) | [English](./README_EN.md)
4
+
5
+ DeepSeek Harness 设置插件,用于查询 API 余额和当前可用模型。API Key 仅由本机 Host 使用,不会发送到浏览器。
6
+
7
+ ![DeepSeek 余额插件界面](./docs/dsh-balance-settings.jpg)
8
+
9
+ ![DeepSeek 模型插件界面](./docs/dsh-models-settings.jpg)
10
+
11
+ ## 功能
12
+
13
+ - 查看总余额、充值余额和赠送余额
14
+ - 查看当前 API Key 可用的模型
15
+ - 缓存查询结果并支持手动刷新
16
+ - 原生支持简体中文和英文,并跟随 Harness 系统语言切换
17
+ - 支持 Harness 已保存的 `DEEPSEEK_API_KEY`
18
+
19
+ ## 安装
20
+
21
+ ```bash
22
+ dsh plugin --profile web add @pinkbanana/dsh-balance
23
+ dsh --profile web
24
+ ```
25
+
26
+ 打开 <http://127.0.0.1:3080/>,进入“设置 → 插件 → DeepSeek 余额 / DeepSeek 模型”。API Key 可在“设置 → 模型”中保存,或通过 `DEEPSEEK_API_KEY` 环境变量提供。
27
+
28
+ ## 开发
29
+
30
+ ```bash
31
+ pnpm install
32
+ pnpm check
33
+ ```
34
+
35
+ ## License
36
+
37
+ [MIT](./LICENSE)
38
+
39
+ <a href="https://www.buymeacoffee.com/pinkbanana"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Crazywoola a coffee" width="199" height="55" /></a>
package/README_EN.md ADDED
@@ -0,0 +1,39 @@
1
+ # dsh-balance
2
+
3
+ [简体中文](./README.md) | [English](./README_EN.md)
4
+
5
+ A DeepSeek Harness Settings plugin for checking API balances and available models. The API key is used only by the local Host and is never sent to the browser.
6
+
7
+ ![DeepSeek balance settings](./docs/dsh-balance-settings.jpg)
8
+
9
+ ![DeepSeek models settings](./docs/dsh-models-settings.jpg)
10
+
11
+ ## Features
12
+
13
+ - View total, topped-up, and granted balances
14
+ - View models available to the current API key
15
+ - Cache query results with manual refresh support
16
+ - Native Simplified Chinese and English that follows the Harness system language
17
+ - Use the `DEEPSEEK_API_KEY` saved by Harness
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ dsh plugin --profile web add @pinkbanana/dsh-balance
23
+ dsh --profile web
24
+ ```
25
+
26
+ Open <http://127.0.0.1:3080/> and go to Settings → Plugins → DeepSeek Balance / DeepSeek Models. Save the API key in Settings → Models or provide it through the `DEEPSEEK_API_KEY` environment variable.
27
+
28
+ ## Development
29
+
30
+ ```bash
31
+ pnpm install
32
+ pnpm check
33
+ ```
34
+
35
+ ## License
36
+
37
+ [MIT](./LICENSE)
38
+
39
+ <a href="https://www.buymeacoffee.com/pinkbanana"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Crazywoola a coffee" width="199" height="55" /></a>
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: dsh-balance
3
+ name: dsh-balance
Binary file
Binary file
package/lib/client.js ADDED
@@ -0,0 +1,472 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-balance",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ //#region src/types.ts
10
+ /** The same-origin endpoint exposed by the plugin's Host half. */
11
+ const BALANCE_ROUTE = "/dsh-balance/api/balance";
12
+ /** The same-origin endpoint that proxies DeepSeek's `/models` API. */
13
+ const MODELS_ROUTE = "/dsh-balance/api/models";
14
+ //#endregion
15
+ //#region src/client/locales.ts
16
+ const LOCALE_NS = "dsh-balance";
17
+ /** Simplified Chinese dictionary and source of truth for the namespace key set. */
18
+ const zh = {
19
+ "locale.tag": "zh-CN",
20
+ "tab.balance": "DeepSeek 余额",
21
+ "tab.models": "DeepSeek 模型",
22
+ "action.loading": "查询中…",
23
+ "balance.title": "DeepSeek API 余额",
24
+ "balance.copy": "余额由本机 Host 使用已保存的 API 密钥查询,密钥不会发送到浏览器。",
25
+ "balance.refresh": "刷新余额",
26
+ "balance.loading": "正在查询 DeepSeek 账户余额…",
27
+ "balance.available": "当前账户有可用余额",
28
+ "balance.unavailable": "当前账户没有可用余额",
29
+ "balance.empty": "DeepSeek 未返回任何币种余额。",
30
+ "balance.toppedUp": "充值余额",
31
+ "balance.granted": "赠送余额",
32
+ "models.title": "DeepSeek 可用模型",
33
+ "models.copy": "从 DeepSeek 官方 /models 接口读取当前 API Key 可访问的模型。",
34
+ "models.refresh": "刷新模型",
35
+ "models.loading": "正在查询 DeepSeek 模型列表…",
36
+ "models.count": "当前可用 {count} 个模型",
37
+ "models.empty": "DeepSeek 未返回任何可用模型。",
38
+ "models.owner": "由 {owner} 提供",
39
+ "meta.updated": "更新于 {time}",
40
+ "meta.cached": " · 缓存",
41
+ "error.FORBIDDEN": "此查询仅允许从本机访问",
42
+ "error.INVALID_API_KEY": "DeepSeek API 密钥无效或没有查询权限",
43
+ "error.INVALID_RESPONSE": "DeepSeek 返回了无法识别的响应",
44
+ "error.METHOD_NOT_ALLOWED": "请求方法不受支持",
45
+ "error.MISSING_API_KEY": "未配置 DeepSeek API 密钥,请先在“模型”设置中保存",
46
+ "error.RATE_LIMITED": "DeepSeek API 请求过于频繁,请稍后重试",
47
+ "error.UPSTREAM_ERROR": "DeepSeek API 返回了错误",
48
+ "error.UPSTREAM_TIMEOUT": "查询 DeepSeek API 超时",
49
+ "error.UPSTREAM_UNAVAILABLE": "无法连接到 DeepSeek API"
50
+ };
51
+ /** English dictionary, checked complete against the Chinese key set. */
52
+ const en = {
53
+ "locale.tag": "en-US",
54
+ "tab.balance": "DeepSeek Balance",
55
+ "tab.models": "DeepSeek Models",
56
+ "action.loading": "Loading…",
57
+ "balance.title": "DeepSeek API Balance",
58
+ "balance.copy": "The local Host queries your balance with the saved API key. The key is never sent to the browser.",
59
+ "balance.refresh": "Refresh balance",
60
+ "balance.loading": "Loading your DeepSeek API balance…",
61
+ "balance.available": "This account has available balance",
62
+ "balance.unavailable": "This account has no available balance",
63
+ "balance.empty": "DeepSeek returned no currency balances.",
64
+ "balance.toppedUp": "Topped-up balance",
65
+ "balance.granted": "Granted balance",
66
+ "models.title": "Available DeepSeek Models",
67
+ "models.copy": "Lists the models available to the current API key using the official DeepSeek /models endpoint.",
68
+ "models.refresh": "Refresh models",
69
+ "models.loading": "Loading the DeepSeek model list…",
70
+ "models.count": "{count} models available",
71
+ "models.empty": "DeepSeek returned no available models.",
72
+ "models.owner": "Provided by {owner}",
73
+ "meta.updated": "Updated {time}",
74
+ "meta.cached": " · Cached",
75
+ "error.FORBIDDEN": "This query is available only from the local machine",
76
+ "error.INVALID_API_KEY": "The DeepSeek API key is invalid or lacks permission",
77
+ "error.INVALID_RESPONSE": "DeepSeek returned an unrecognized response",
78
+ "error.METHOD_NOT_ALLOWED": "This request method is not supported",
79
+ "error.MISSING_API_KEY": "No DeepSeek API key is configured. Save one in Models settings first.",
80
+ "error.RATE_LIMITED": "Too many DeepSeek API requests. Try again later.",
81
+ "error.UPSTREAM_ERROR": "The DeepSeek API returned an error",
82
+ "error.UPSTREAM_TIMEOUT": "The DeepSeek API request timed out",
83
+ "error.UPSTREAM_UNAVAILABLE": "Could not connect to the DeepSeek API"
84
+ };
85
+ function errorLocaleKey(code) {
86
+ return `error.${code}`;
87
+ }
88
+ //#endregion
89
+ //#region src/client/BalanceTab.tsx
90
+ function displayAmount(value, currency, locale) {
91
+ const amount = Number(value);
92
+ if (!Number.isFinite(amount)) return `${value} ${currency}`;
93
+ try {
94
+ return new Intl.NumberFormat(locale, {
95
+ style: "currency",
96
+ currency,
97
+ minimumFractionDigits: 2,
98
+ maximumFractionDigits: 8
99
+ }).format(amount);
100
+ } catch {
101
+ return `${value} ${currency}`;
102
+ }
103
+ }
104
+ function BalanceCard({ info, t }) {
105
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
106
+ className: "dsh-balance-card",
107
+ children: [
108
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
109
+ className: "dsh-balance-card-head",
110
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
111
+ className: "dsh-balance-currency",
112
+ children: info.currency
113
+ })
114
+ }),
115
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
116
+ className: "dsh-balance-total",
117
+ children: displayAmount(info.totalBalance, info.currency, t("locale.tag"))
118
+ }),
119
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dl", {
120
+ className: "dsh-balance-breakdown",
121
+ children: [
122
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("balance.toppedUp") }),
123
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(info.toppedUpBalance, info.currency, t("locale.tag")) }),
124
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("balance.granted") }),
125
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: displayAmount(info.grantedBalance, info.currency, t("locale.tag")) })
126
+ ]
127
+ })
128
+ ]
129
+ });
130
+ }
131
+ function BalanceTab({ loadBalance, t }) {
132
+ const [result, setResult] = (0, react.useState)();
133
+ const [loading, setLoading] = (0, react.useState)(true);
134
+ const load = (0, react.useCallback)(async (forceRefresh, signal) => {
135
+ setLoading(true);
136
+ try {
137
+ setResult(await loadBalance(forceRefresh, signal));
138
+ } catch (error) {
139
+ if (signal.aborted) return;
140
+ setResult({
141
+ ok: false,
142
+ code: "UPSTREAM_UNAVAILABLE",
143
+ message: error instanceof Error ? error.message : ""
144
+ });
145
+ } finally {
146
+ if (!signal.aborted) setLoading(false);
147
+ }
148
+ }, [loadBalance]);
149
+ (0, react.useEffect)(() => {
150
+ const controller = new AbortController();
151
+ load(false, controller.signal);
152
+ return () => {
153
+ controller.abort();
154
+ };
155
+ }, [load]);
156
+ const refresh = () => {
157
+ const controller = new AbortController();
158
+ load(true, controller.signal);
159
+ };
160
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
161
+ className: "dsh-balance-tab",
162
+ "aria-labelledby": "dsh-balance-title",
163
+ children: [
164
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
165
+ className: "dsh-balance-summary",
166
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
167
+ id: "dsh-balance-title",
168
+ className: "dsh-balance-heading",
169
+ children: t("balance.title")
170
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
171
+ className: "dsh-balance-copy",
172
+ children: t("balance.copy")
173
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
174
+ className: "dsh-balance-refresh",
175
+ type: "button",
176
+ disabled: loading,
177
+ onClick: refresh,
178
+ children: loading ? t("action.loading") : t("balance.refresh")
179
+ })]
180
+ }),
181
+ loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
182
+ className: "dsh-balance-status",
183
+ role: "status",
184
+ children: t("balance.loading")
185
+ }) : null,
186
+ result?.ok === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
187
+ className: "dsh-balance-error",
188
+ role: "alert",
189
+ children: t(errorLocaleKey(result.code))
190
+ }) : null,
191
+ result?.ok === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
192
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
193
+ className: "dsh-balance-availability",
194
+ "data-available": String(result.isAvailable),
195
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
196
+ className: "dsh-balance-dot",
197
+ "aria-hidden": "true"
198
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(result.isAvailable ? "balance.available" : "balance.unavailable") })]
199
+ }),
200
+ result.balanceInfos.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
201
+ className: "dsh-balance-grid",
202
+ children: result.balanceInfos.map((info) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BalanceCard, {
203
+ info,
204
+ t
205
+ }, info.currency))
206
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
207
+ className: "dsh-balance-status",
208
+ children: t("balance.empty")
209
+ }),
210
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
211
+ className: "dsh-balance-meta",
212
+ children: [t("meta.updated", { time: new Date(result.fetchedAt).toLocaleString(t("locale.tag")) }), result.source === "cache" ? t("meta.cached") : ""]
213
+ })
214
+ ] }) : null
215
+ ]
216
+ });
217
+ }
218
+ //#endregion
219
+ //#region src/client/ModelsTab.tsx
220
+ function ModelCard({ model, t }) {
221
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("article", {
222
+ className: "dsh-model-card",
223
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
224
+ className: "dsh-model-id",
225
+ children: model.id
226
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
227
+ className: "dsh-model-owner",
228
+ children: t("models.owner", { owner: model.ownedBy })
229
+ })]
230
+ });
231
+ }
232
+ function ModelsTab({ loadModels, t }) {
233
+ const [result, setResult] = (0, react.useState)();
234
+ const [loading, setLoading] = (0, react.useState)(true);
235
+ const load = (0, react.useCallback)(async (forceRefresh, signal) => {
236
+ setLoading(true);
237
+ try {
238
+ setResult(await loadModels(forceRefresh, signal));
239
+ } catch (error) {
240
+ if (signal.aborted) return;
241
+ setResult({
242
+ ok: false,
243
+ code: "UPSTREAM_UNAVAILABLE",
244
+ message: error instanceof Error ? error.message : ""
245
+ });
246
+ } finally {
247
+ if (!signal.aborted) setLoading(false);
248
+ }
249
+ }, [loadModels]);
250
+ (0, react.useEffect)(() => {
251
+ const controller = new AbortController();
252
+ load(false, controller.signal);
253
+ return () => {
254
+ controller.abort();
255
+ };
256
+ }, [load]);
257
+ const refresh = () => {
258
+ const controller = new AbortController();
259
+ load(true, controller.signal);
260
+ };
261
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
262
+ className: "dsh-models-tab",
263
+ "aria-labelledby": "dsh-models-title",
264
+ children: [
265
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
266
+ className: "dsh-balance-summary",
267
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
268
+ id: "dsh-models-title",
269
+ className: "dsh-balance-heading",
270
+ children: t("models.title")
271
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
272
+ className: "dsh-balance-copy",
273
+ children: t("models.copy")
274
+ })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
275
+ className: "dsh-balance-refresh",
276
+ type: "button",
277
+ disabled: loading,
278
+ onClick: refresh,
279
+ children: loading ? t("action.loading") : t("models.refresh")
280
+ })]
281
+ }),
282
+ loading && result === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
283
+ className: "dsh-balance-status",
284
+ role: "status",
285
+ children: t("models.loading")
286
+ }) : null,
287
+ result?.ok === false ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
288
+ className: "dsh-balance-error",
289
+ role: "alert",
290
+ children: t(errorLocaleKey(result.code))
291
+ }) : null,
292
+ result?.ok === true ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
293
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
294
+ className: "dsh-model-count",
295
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
296
+ className: "dsh-balance-dot",
297
+ "aria-hidden": "true"
298
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("models.count", { count: result.models.length }) })]
299
+ }),
300
+ result.models.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
301
+ className: "dsh-model-grid",
302
+ children: result.models.map((model) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelCard, {
303
+ model,
304
+ t
305
+ }, model.id))
306
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
307
+ className: "dsh-balance-status",
308
+ children: t("models.empty")
309
+ }),
310
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
311
+ className: "dsh-balance-meta",
312
+ children: [t("meta.updated", { time: new Date(result.fetchedAt).toLocaleString(t("locale.tag")) }), result.source === "cache" ? t("meta.cached") : ""]
313
+ })
314
+ ] }) : null
315
+ ]
316
+ });
317
+ }
318
+ //#endregion
319
+ //#region src/client/styles.ts
320
+ const balanceStyles = `
321
+ .dsh-balance-tab {
322
+ display: flex;
323
+ flex-direction: column;
324
+ gap: 14px;
325
+ max-width: 760px;
326
+ color: var(--dsw-alias-label-primary);
327
+ }
328
+ .dsh-balance-summary {
329
+ display: flex;
330
+ align-items: center;
331
+ justify-content: space-between;
332
+ gap: 16px;
333
+ }
334
+ .dsh-balance-heading { margin: 0; font-size: 18px; font-weight: 600; }
335
+ .dsh-balance-copy { margin: 4px 0 0; color: var(--dsw-alias-label-tertiary); font-size: 13px; line-height: 1.5; }
336
+ .dsh-balance-refresh {
337
+ flex: none;
338
+ appearance: none;
339
+ border: 1px solid var(--dsw-alias-border-l2);
340
+ border-radius: 8px;
341
+ padding: 6px 13px;
342
+ background: var(--dsw-alias-bg-layer-3);
343
+ color: var(--dsw-alias-label-primary);
344
+ font: inherit;
345
+ font-size: 13px;
346
+ cursor: pointer;
347
+ }
348
+ .dsh-balance-refresh:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
349
+ .dsh-balance-refresh:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }
350
+ .dsh-balance-refresh:disabled { cursor: default; opacity: .55; }
351
+ .dsh-balance-status,
352
+ .dsh-balance-error {
353
+ margin: 0;
354
+ border: 1px solid var(--dsw-alias-border-l2);
355
+ border-radius: 12px;
356
+ padding: 18px;
357
+ background: var(--dsw-alias-bg-layer-3);
358
+ color: var(--dsw-alias-label-secondary);
359
+ font-size: 13px;
360
+ line-height: 1.6;
361
+ }
362
+ .dsh-balance-error { color: var(--dsw-alias-state-error-primary); }
363
+ .dsh-balance-availability { display: flex; align-items: center; gap: 8px; font-size: 13px; }
364
+ .dsh-balance-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--dsw-alias-state-error-primary); }
365
+ .dsh-balance-availability[data-available='true'] .dsh-balance-dot { background: var(--dsw-alias-state-success-primary); }
366
+ .dsh-balance-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
367
+ .dsh-balance-card {
368
+ border: 1px solid var(--dsw-alias-border-l2);
369
+ border-radius: 12px;
370
+ padding: 16px;
371
+ background: var(--dsw-alias-bg-layer-3);
372
+ }
373
+ .dsh-balance-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
374
+ .dsh-balance-currency { color: var(--dsw-alias-label-tertiary); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
375
+ .dsh-balance-total { margin: 12px 0 16px; font-size: 28px; font-weight: 650; line-height: 1.15; }
376
+ .dsh-balance-breakdown { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; margin: 0; font-size: 12px; }
377
+ .dsh-balance-breakdown dt { color: var(--dsw-alias-label-tertiary); }
378
+ .dsh-balance-breakdown dd { margin: 0; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }
379
+ .dsh-balance-meta { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 12px; }
380
+ .dsh-models-tab {
381
+ display: flex;
382
+ flex-direction: column;
383
+ gap: 14px;
384
+ max-width: 760px;
385
+ color: var(--dsw-alias-label-primary);
386
+ }
387
+ .dsh-model-count { display: flex; align-items: center; gap: 8px; font-size: 13px; }
388
+ .dsh-model-count .dsh-balance-dot { background: var(--dsw-alias-state-success-primary); }
389
+ .dsh-model-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
390
+ .dsh-model-card {
391
+ display: flex;
392
+ flex-direction: column;
393
+ gap: 10px;
394
+ border: 1px solid var(--dsw-alias-border-l2);
395
+ border-radius: 12px;
396
+ padding: 16px;
397
+ background: var(--dsw-alias-bg-layer-3);
398
+ }
399
+ .dsh-model-id {
400
+ color: var(--dsw-alias-label-primary);
401
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
402
+ font-size: 15px;
403
+ font-weight: 600;
404
+ overflow-wrap: anywhere;
405
+ }
406
+ .dsh-model-owner { color: var(--dsw-alias-label-tertiary); font-size: 12px; }
407
+ `;
408
+ //#endregion
409
+ //#region src/client/index.tsx
410
+ const inject = ["slots", "locale"];
411
+ async function loadBalance(forceRefresh, signal) {
412
+ const value = await (await fetch(forceRefresh ? `${BALANCE_ROUTE}?refresh=1` : BALANCE_ROUTE, {
413
+ method: "GET",
414
+ headers: { accept: "application/json" },
415
+ cache: "no-store",
416
+ signal
417
+ })).json();
418
+ if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("余额插件收到了无法识别的 Host 响应");
419
+ return value;
420
+ }
421
+ async function loadModels(forceRefresh, signal) {
422
+ const value = await (await fetch(forceRefresh ? `${MODELS_ROUTE}?refresh=1` : MODELS_ROUTE, {
423
+ method: "GET",
424
+ headers: { accept: "application/json" },
425
+ cache: "no-store",
426
+ signal
427
+ })).json();
428
+ if (typeof value !== "object" || value === null || !("ok" in value) || typeof value.ok !== "boolean") throw new Error("模型插件收到了无法识别的 Host 响应");
429
+ return value;
430
+ }
431
+ /** Register one feature-owned page inside the existing Plugins settings section. */
432
+ function apply(ctx) {
433
+ ctx.effect(() => ctx.locale.register(LOCALE_NS, {
434
+ zh,
435
+ en
436
+ }), "dsh-balance: dictionaries");
437
+ const t = ctx.locale.bind(LOCALE_NS);
438
+ ctx.effect(() => {
439
+ const style = document.createElement("style");
440
+ style.dataset.plugin = "dsh-balance";
441
+ style.dataset.pluginCss = "dsh-balance/styles";
442
+ style.textContent = balanceStyles;
443
+ document.head.append(style);
444
+ return () => {
445
+ style.remove();
446
+ };
447
+ }, "dsh-balance: styles");
448
+ ctx.slots.inject("settings.plugins.tab", () => ctx.slots.register({
449
+ name: "settings.plugins.tab",
450
+ id: "deepseek-balance",
451
+ order: 20,
452
+ label: () => t("tab.balance"),
453
+ locale: LOCALE_NS,
454
+ inject: () => ({ loadBalance })
455
+ }, BalanceTab));
456
+ ctx.slots.inject("settings.plugins.tab", () => ctx.slots.register({
457
+ name: "settings.plugins.tab",
458
+ id: "deepseek-models",
459
+ order: 21,
460
+ label: () => t("tab.models"),
461
+ locale: LOCALE_NS,
462
+ inject: () => ({ loadModels })
463
+ }, ModelsTab));
464
+ }
465
+ //#endregion
466
+ exports.apply = apply;
467
+ exports.inject = inject;
468
+ return module.exports;
469
+ }
470
+ });
471
+
472
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":["useState","useCallback","useState","useCallback"],"sources":["../src/types.ts","../src/client/locales.ts","../src/client/BalanceTab.tsx","../src/client/ModelsTab.tsx","../src/client/styles.ts","../src/client/index.tsx"],"sourcesContent":["/** The same-origin endpoint exposed by the plugin's Host half. */\nexport const BALANCE_ROUTE = '/dsh-balance/api/balance'\n\n/** The same-origin endpoint that proxies DeepSeek's `/models` API. */\nexport const MODELS_ROUTE = '/dsh-balance/api/models'\n\n/** One currency row returned by DeepSeek's `/user/balance` API. */\nexport interface BalanceInfo {\n currency: string\n totalBalance: string\n grantedBalance: string\n toppedUpBalance: string\n}\n\n/** A successful, browser-safe balance response. */\nexport interface BalanceSuccess {\n ok: true\n isAvailable: boolean\n balanceInfos: BalanceInfo[]\n fetchedAt: string\n source: 'live' | 'cache'\n}\n\nexport type DeepSeekApiErrorCode =\n | 'FORBIDDEN'\n | 'INVALID_API_KEY'\n | 'INVALID_RESPONSE'\n | 'METHOD_NOT_ALLOWED'\n | 'MISSING_API_KEY'\n | 'RATE_LIMITED'\n | 'UPSTREAM_ERROR'\n | 'UPSTREAM_TIMEOUT'\n | 'UPSTREAM_UNAVAILABLE'\n\n/** @deprecated Prefer the feature-neutral `DeepSeekApiErrorCode`. */\nexport type BalanceErrorCode = DeepSeekApiErrorCode\n\n/** A failed, browser-safe response. It intentionally contains no upstream body or credential. */\nexport interface BalanceFailure {\n ok: false\n code: DeepSeekApiErrorCode\n message: string\n}\n\nexport type BalanceApiResponse = BalanceSuccess | BalanceFailure\n\n/** One model returned by DeepSeek's `/models` API. */\nexport interface ModelInfo {\n id: string\n ownedBy: string\n}\n\n/** A successful, browser-safe model-list response. */\nexport interface ModelsSuccess {\n ok: true\n models: ModelInfo[]\n fetchedAt: string\n source: 'live' | 'cache'\n}\n\nexport type ModelsFailure = BalanceFailure\nexport type ModelsApiResponse = ModelsSuccess | ModelsFailure\n","import type { LocaleDictOf } from '@deepseek-ai/dsh-client-ui-slots'\nimport type { DeepSeekApiErrorCode } from '../types.ts'\n\nexport const LOCALE_NS = 'dsh-balance'\n\n/** Simplified Chinese dictionary and source of truth for the namespace key set. */\nexport const zh = {\n 'locale.tag': 'zh-CN',\n 'tab.balance': 'DeepSeek 余额',\n 'tab.models': 'DeepSeek 模型',\n 'action.loading': '查询中…',\n 'balance.title': 'DeepSeek API 余额',\n 'balance.copy': '余额由本机 Host 使用已保存的 API 密钥查询,密钥不会发送到浏览器。',\n 'balance.refresh': '刷新余额',\n 'balance.loading': '正在查询 DeepSeek 账户余额…',\n 'balance.available': '当前账户有可用余额',\n 'balance.unavailable': '当前账户没有可用余额',\n 'balance.empty': 'DeepSeek 未返回任何币种余额。',\n 'balance.toppedUp': '充值余额',\n 'balance.granted': '赠送余额',\n 'models.title': 'DeepSeek 可用模型',\n 'models.copy': '从 DeepSeek 官方 /models 接口读取当前 API Key 可访问的模型。',\n 'models.refresh': '刷新模型',\n 'models.loading': '正在查询 DeepSeek 模型列表…',\n 'models.count': '当前可用 {count} 个模型',\n 'models.empty': 'DeepSeek 未返回任何可用模型。',\n 'models.owner': '由 {owner} 提供',\n 'meta.updated': '更新于 {time}',\n 'meta.cached': ' · 缓存',\n 'error.FORBIDDEN': '此查询仅允许从本机访问',\n 'error.INVALID_API_KEY': 'DeepSeek API 密钥无效或没有查询权限',\n 'error.INVALID_RESPONSE': 'DeepSeek 返回了无法识别的响应',\n 'error.METHOD_NOT_ALLOWED': '请求方法不受支持',\n 'error.MISSING_API_KEY': '未配置 DeepSeek API 密钥,请先在“模型”设置中保存',\n 'error.RATE_LIMITED': 'DeepSeek API 请求过于频繁,请稍后重试',\n 'error.UPSTREAM_ERROR': 'DeepSeek API 返回了错误',\n 'error.UPSTREAM_TIMEOUT': '查询 DeepSeek API 超时',\n 'error.UPSTREAM_UNAVAILABLE': '无法连接到 DeepSeek API',\n} as const\n\nexport type DshBalanceLocaleKey = keyof typeof zh\n\ndeclare module '@deepseek-ai/dsh-client-ui-slots' {\n interface LocaleNamespaceMap {\n /** Balance and model-list settings copy owned by this plugin. */\n 'dsh-balance': DshBalanceLocaleKey\n }\n}\n\n/** English dictionary, checked complete against the Chinese key set. */\nexport const en: LocaleDictOf<typeof LOCALE_NS> = {\n 'locale.tag': 'en-US',\n 'tab.balance': 'DeepSeek Balance',\n 'tab.models': 'DeepSeek Models',\n 'action.loading': 'Loading…',\n 'balance.title': 'DeepSeek API Balance',\n 'balance.copy': 'The local Host queries your balance with the saved API key. The key is never sent to the browser.',\n 'balance.refresh': 'Refresh balance',\n 'balance.loading': 'Loading your DeepSeek API balance…',\n 'balance.available': 'This account has available balance',\n 'balance.unavailable': 'This account has no available balance',\n 'balance.empty': 'DeepSeek returned no currency balances.',\n 'balance.toppedUp': 'Topped-up balance',\n 'balance.granted': 'Granted balance',\n 'models.title': 'Available DeepSeek Models',\n 'models.copy': 'Lists the models available to the current API key using the official DeepSeek /models endpoint.',\n 'models.refresh': 'Refresh models',\n 'models.loading': 'Loading the DeepSeek model list…',\n 'models.count': '{count} models available',\n 'models.empty': 'DeepSeek returned no available models.',\n 'models.owner': 'Provided by {owner}',\n 'meta.updated': 'Updated {time}',\n 'meta.cached': ' · Cached',\n 'error.FORBIDDEN': 'This query is available only from the local machine',\n 'error.INVALID_API_KEY': 'The DeepSeek API key is invalid or lacks permission',\n 'error.INVALID_RESPONSE': 'DeepSeek returned an unrecognized response',\n 'error.METHOD_NOT_ALLOWED': 'This request method is not supported',\n 'error.MISSING_API_KEY': 'No DeepSeek API key is configured. Save one in Models settings first.',\n 'error.RATE_LIMITED': 'Too many DeepSeek API requests. Try again later.',\n 'error.UPSTREAM_ERROR': 'The DeepSeek API returned an error',\n 'error.UPSTREAM_TIMEOUT': 'The DeepSeek API request timed out',\n 'error.UPSTREAM_UNAVAILABLE': 'Could not connect to the DeepSeek API',\n}\n\nexport function errorLocaleKey(code: DeepSeekApiErrorCode): DshBalanceLocaleKey {\n return `error.${code}`\n}\n","import { useCallback, useEffect, useState } from 'react'\nimport type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'\nimport type { BalanceApiResponse, BalanceInfo } from '../types.ts'\nimport { errorLocaleKey } from './locales.ts'\nimport type { LOCALE_NS } from './locales.ts'\n\nexport interface BalanceTabInjected {\n loadBalance: (forceRefresh: boolean, signal: AbortSignal) => Promise<BalanceApiResponse>\n}\n\nexport type BalanceTabProps = PropsRuntime<'settings.plugins.tab'> & InjectFace<BalanceTabInjected> & PropsLocale<typeof LOCALE_NS>\n\nfunction displayAmount(value: string, currency: string, locale: string): string {\n const amount = Number(value)\n if (!Number.isFinite(amount)) return `${value} ${currency}`\n try {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n minimumFractionDigits: 2,\n maximumFractionDigits: 8,\n }).format(amount)\n } catch {\n return `${value} ${currency}`\n }\n}\n\nfunction BalanceCard({ info, t }: { info: BalanceInfo; t: BalanceTabProps['t'] }) {\n return (\n <article className=\"dsh-balance-card\">\n <div className=\"dsh-balance-card-head\">\n <span className=\"dsh-balance-currency\">{info.currency}</span>\n </div>\n <p className=\"dsh-balance-total\">{displayAmount(info.totalBalance, info.currency, t('locale.tag'))}</p>\n <dl className=\"dsh-balance-breakdown\">\n <dt>{t('balance.toppedUp')}</dt>\n <dd>{displayAmount(info.toppedUpBalance, info.currency, t('locale.tag'))}</dd>\n <dt>{t('balance.granted')}</dt>\n <dd>{displayAmount(info.grantedBalance, info.currency, t('locale.tag'))}</dd>\n </dl>\n </article>\n )\n}\n\nexport function BalanceTab({ loadBalance, t }: BalanceTabProps) {\n const [result, setResult] = useState<BalanceApiResponse>()\n const [loading, setLoading] = useState(true)\n\n const load = useCallback(async (forceRefresh: boolean, signal: AbortSignal) => {\n setLoading(true)\n try {\n setResult(await loadBalance(forceRefresh, signal))\n } catch (error) {\n if (signal.aborted) return\n setResult({\n ok: false,\n code: 'UPSTREAM_UNAVAILABLE',\n message: error instanceof Error ? error.message : '',\n })\n } finally {\n if (!signal.aborted) setLoading(false)\n }\n }, [loadBalance])\n\n useEffect(() => {\n const controller = new AbortController()\n void load(false, controller.signal)\n return () => { controller.abort() }\n }, [load])\n\n const refresh = () => {\n const controller = new AbortController()\n void load(true, controller.signal)\n }\n\n return (\n <section className=\"dsh-balance-tab\" aria-labelledby=\"dsh-balance-title\">\n <div className=\"dsh-balance-summary\">\n <div>\n <h2 id=\"dsh-balance-title\" className=\"dsh-balance-heading\">{t('balance.title')}</h2>\n <p className=\"dsh-balance-copy\">{t('balance.copy')}</p>\n </div>\n <button className=\"dsh-balance-refresh\" type=\"button\" disabled={loading} onClick={refresh}>\n {loading ? t('action.loading') : t('balance.refresh')}\n </button>\n </div>\n\n {loading && result === undefined ? <p className=\"dsh-balance-status\" role=\"status\">{t('balance.loading')}</p> : null}\n {result?.ok === false ? <p className=\"dsh-balance-error\" role=\"alert\">{t(errorLocaleKey(result.code))}</p> : null}\n {result?.ok === true ? (\n <>\n <div className=\"dsh-balance-availability\" data-available={String(result.isAvailable)}>\n <span className=\"dsh-balance-dot\" aria-hidden=\"true\" />\n <span>{t(result.isAvailable ? 'balance.available' : 'balance.unavailable')}</span>\n </div>\n {result.balanceInfos.length > 0\n ? <div className=\"dsh-balance-grid\">{result.balanceInfos.map(info => <BalanceCard key={info.currency} info={info} t={t} />)}</div>\n : <p className=\"dsh-balance-status\">{t('balance.empty')}</p>}\n <p className=\"dsh-balance-meta\">\n {t('meta.updated', { time: new Date(result.fetchedAt).toLocaleString(t('locale.tag')) })}{result.source === 'cache' ? t('meta.cached') : ''}\n </p>\n </>\n ) : null}\n </section>\n )\n}\n","import { useCallback, useEffect, useState } from 'react'\nimport type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'\nimport type { ModelInfo, ModelsApiResponse } from '../types.ts'\nimport { errorLocaleKey } from './locales.ts'\nimport type { LOCALE_NS } from './locales.ts'\n\nexport interface ModelsTabInjected {\n loadModels: (forceRefresh: boolean, signal: AbortSignal) => Promise<ModelsApiResponse>\n}\n\nexport type ModelsTabProps = PropsRuntime<'settings.plugins.tab'> & InjectFace<ModelsTabInjected> & PropsLocale<typeof LOCALE_NS>\n\nfunction ModelCard({ model, t }: { model: ModelInfo; t: ModelsTabProps['t'] }) {\n return (\n <article className=\"dsh-model-card\">\n <code className=\"dsh-model-id\">{model.id}</code>\n <span className=\"dsh-model-owner\">{t('models.owner', { owner: model.ownedBy })}</span>\n </article>\n )\n}\n\nexport function ModelsTab({ loadModels, t }: ModelsTabProps) {\n const [result, setResult] = useState<ModelsApiResponse>()\n const [loading, setLoading] = useState(true)\n\n const load = useCallback(async (forceRefresh: boolean, signal: AbortSignal) => {\n setLoading(true)\n try {\n setResult(await loadModels(forceRefresh, signal))\n } catch (error) {\n if (signal.aborted) return\n setResult({\n ok: false,\n code: 'UPSTREAM_UNAVAILABLE',\n message: error instanceof Error ? error.message : '',\n })\n } finally {\n if (!signal.aborted) setLoading(false)\n }\n }, [loadModels])\n\n useEffect(() => {\n const controller = new AbortController()\n void load(false, controller.signal)\n return () => { controller.abort() }\n }, [load])\n\n const refresh = () => {\n const controller = new AbortController()\n void load(true, controller.signal)\n }\n\n return (\n <section className=\"dsh-models-tab\" aria-labelledby=\"dsh-models-title\">\n <div className=\"dsh-balance-summary\">\n <div>\n <h2 id=\"dsh-models-title\" className=\"dsh-balance-heading\">{t('models.title')}</h2>\n <p className=\"dsh-balance-copy\">{t('models.copy')}</p>\n </div>\n <button className=\"dsh-balance-refresh\" type=\"button\" disabled={loading} onClick={refresh}>\n {loading ? t('action.loading') : t('models.refresh')}\n </button>\n </div>\n\n {loading && result === undefined ? <p className=\"dsh-balance-status\" role=\"status\">{t('models.loading')}</p> : null}\n {result?.ok === false ? <p className=\"dsh-balance-error\" role=\"alert\">{t(errorLocaleKey(result.code))}</p> : null}\n {result?.ok === true ? (\n <>\n <div className=\"dsh-model-count\">\n <span className=\"dsh-balance-dot\" aria-hidden=\"true\" />\n <span>{t('models.count', { count: result.models.length })}</span>\n </div>\n {result.models.length > 0\n ? <div className=\"dsh-model-grid\">{result.models.map(model => <ModelCard key={model.id} model={model} t={t} />)}</div>\n : <p className=\"dsh-balance-status\">{t('models.empty')}</p>}\n <p className=\"dsh-balance-meta\">\n {t('meta.updated', { time: new Date(result.fetchedAt).toLocaleString(t('locale.tag')) })}{result.source === 'cache' ? t('meta.cached') : ''}\n </p>\n </>\n ) : null}\n </section>\n )\n}\n","export const balanceStyles = `\n.dsh-balance-tab {\n display: flex;\n flex-direction: column;\n gap: 14px;\n max-width: 760px;\n color: var(--dsw-alias-label-primary);\n}\n.dsh-balance-summary {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 16px;\n}\n.dsh-balance-heading { margin: 0; font-size: 18px; font-weight: 600; }\n.dsh-balance-copy { margin: 4px 0 0; color: var(--dsw-alias-label-tertiary); font-size: 13px; line-height: 1.5; }\n.dsh-balance-refresh {\n flex: none;\n appearance: none;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n padding: 6px 13px;\n background: var(--dsw-alias-bg-layer-3);\n color: var(--dsw-alias-label-primary);\n font: inherit;\n font-size: 13px;\n cursor: pointer;\n}\n.dsh-balance-refresh:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dsh-balance-refresh:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 2px; }\n.dsh-balance-refresh:disabled { cursor: default; opacity: .55; }\n.dsh-balance-status,\n.dsh-balance-error {\n margin: 0;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 12px;\n padding: 18px;\n background: var(--dsw-alias-bg-layer-3);\n color: var(--dsw-alias-label-secondary);\n font-size: 13px;\n line-height: 1.6;\n}\n.dsh-balance-error { color: var(--dsw-alias-state-error-primary); }\n.dsh-balance-availability { display: flex; align-items: center; gap: 8px; font-size: 13px; }\n.dsh-balance-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--dsw-alias-state-error-primary); }\n.dsh-balance-availability[data-available='true'] .dsh-balance-dot { background: var(--dsw-alias-state-success-primary); }\n.dsh-balance-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }\n.dsh-balance-card {\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 12px;\n padding: 16px;\n background: var(--dsw-alias-bg-layer-3);\n}\n.dsh-balance-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }\n.dsh-balance-currency { color: var(--dsw-alias-label-tertiary); font-size: 12px; font-weight: 600; letter-spacing: .04em; }\n.dsh-balance-total { margin: 12px 0 16px; font-size: 28px; font-weight: 650; line-height: 1.15; }\n.dsh-balance-breakdown { display: grid; grid-template-columns: 1fr auto; gap: 7px 12px; margin: 0; font-size: 12px; }\n.dsh-balance-breakdown dt { color: var(--dsw-alias-label-tertiary); }\n.dsh-balance-breakdown dd { margin: 0; color: var(--dsw-alias-label-secondary); font-variant-numeric: tabular-nums; }\n.dsh-balance-meta { margin: 0; color: var(--dsw-alias-label-tertiary); font-size: 12px; }\n.dsh-models-tab {\n display: flex;\n flex-direction: column;\n gap: 14px;\n max-width: 760px;\n color: var(--dsw-alias-label-primary);\n}\n.dsh-model-count { display: flex; align-items: center; gap: 8px; font-size: 13px; }\n.dsh-model-count .dsh-balance-dot { background: var(--dsw-alias-state-success-primary); }\n.dsh-model-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }\n.dsh-model-card {\n display: flex;\n flex-direction: column;\n gap: 10px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 12px;\n padding: 16px;\n background: var(--dsw-alias-bg-layer-3);\n}\n.dsh-model-id {\n color: var(--dsw-alias-label-primary);\n font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n font-size: 15px;\n font-weight: 600;\n overflow-wrap: anywhere;\n}\n.dsh-model-owner { color: var(--dsw-alias-label-tertiary); font-size: 12px; }\n`\n","import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'\nimport type {} from '@deepseek-ai/dsh-client-locale/client'\nimport type {} from '@deepseek-ai/dsh-client-ui-settings/client'\nimport type { BalanceApiResponse, ModelsApiResponse } from '../types.ts'\nimport { BALANCE_ROUTE, MODELS_ROUTE } from '../types.ts'\nimport { BalanceTab } from './BalanceTab.tsx'\nimport type { BalanceTabInjected } from './BalanceTab.tsx'\nimport { ModelsTab } from './ModelsTab.tsx'\nimport type { ModelsTabInjected } from './ModelsTab.tsx'\nimport { en, LOCALE_NS, zh } from './locales.ts'\nimport { balanceStyles } from './styles.ts'\n\nexport type { BalanceTabInjected, BalanceTabProps } from './BalanceTab.tsx'\nexport type { ModelsTabInjected, ModelsTabProps } from './ModelsTab.tsx'\n\nexport const inject = ['slots', 'locale']\n\nasync function loadBalance(forceRefresh: boolean, signal: AbortSignal): Promise<BalanceApiResponse> {\n const url = forceRefresh ? `${BALANCE_ROUTE}?refresh=1` : BALANCE_ROUTE\n const response = await fetch(url, {\n method: 'GET',\n headers: { accept: 'application/json' },\n cache: 'no-store',\n signal,\n })\n const value: unknown = await response.json()\n if (typeof value !== 'object' || value === null || !('ok' in value) || typeof value.ok !== 'boolean') {\n throw new Error('余额插件收到了无法识别的 Host 响应')\n }\n return value as BalanceApiResponse\n}\n\nasync function loadModels(forceRefresh: boolean, signal: AbortSignal): Promise<ModelsApiResponse> {\n const url = forceRefresh ? `${MODELS_ROUTE}?refresh=1` : MODELS_ROUTE\n const response = await fetch(url, {\n method: 'GET',\n headers: { accept: 'application/json' },\n cache: 'no-store',\n signal,\n })\n const value: unknown = await response.json()\n if (typeof value !== 'object' || value === null || !('ok' in value) || typeof value.ok !== 'boolean') {\n throw new Error('模型插件收到了无法识别的 Host 响应')\n }\n return value as ModelsApiResponse\n}\n\n/** Register one feature-owned page inside the existing Plugins settings section. */\nexport function apply(ctx: ClientContext): void {\n ctx.effect(\n () => ctx.locale.register(LOCALE_NS, { zh, en }),\n 'dsh-balance: dictionaries',\n )\n const t = ctx.locale.bind(LOCALE_NS)\n\n ctx.effect(() => {\n const style = document.createElement('style')\n style.dataset.plugin = 'dsh-balance'\n style.dataset.pluginCss = 'dsh-balance/styles'\n style.textContent = balanceStyles\n document.head.append(style)\n return () => { style.remove() }\n }, 'dsh-balance: styles')\n\n ctx.slots.inject('settings.plugins.tab', () => ctx.slots.register({\n name: 'settings.plugins.tab',\n id: 'deepseek-balance',\n order: 20,\n label: () => t('tab.balance'),\n locale: LOCALE_NS,\n inject: (): BalanceTabInjected => ({ loadBalance }),\n }, BalanceTab))\n ctx.slots.inject('settings.plugins.tab', () => ctx.slots.register({\n name: 'settings.plugins.tab',\n id: 'deepseek-models',\n order: 21,\n label: () => t('tab.models'),\n locale: LOCALE_NS,\n inject: (): ModelsTabInjected => ({ loadModels }),\n }, ModelsTab))\n}\n"],"mappings":";;;;;;;;;;EACA,MAAa,gBAAgB;;EAG7B,MAAa,eAAe;;;ECD5B,MAAa,YAAY;;EAGzB,MAAa,KAAK;GAChB,cAAc;GACd,eAAe;GACf,cAAc;GACd,kBAAkB;GAClB,iBAAiB;GACjB,gBAAgB;GAChB,mBAAmB;GACnB,mBAAmB;GACnB,qBAAqB;GACrB,uBAAuB;GACvB,iBAAiB;GACjB,oBAAoB;GACpB,mBAAmB;GACnB,gBAAgB;GAChB,eAAe;GACf,kBAAkB;GAClB,kBAAkB;GAClB,gBAAgB;GAChB,gBAAgB;GAChB,gBAAgB;GAChB,gBAAgB;GAChB,eAAe;GACf,mBAAmB;GACnB,yBAAyB;GACzB,0BAA0B;GAC1B,4BAA4B;GAC5B,yBAAyB;GACzB,sBAAsB;GACtB,wBAAwB;GACxB,0BAA0B;GAC1B,8BAA8B;EAChC;;EAYA,MAAa,KAAqC;G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