dsh-metaontic-newapi-lite 0.0.1

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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -0
  3. package/cordis.patch.yml +4 -0
  4. package/dist/client.js +2134 -0
  5. package/dist/client.js.map +7 -0
  6. package/dist/host/api-keys.d.ts +48 -0
  7. package/dist/host/api-keys.js +182 -0
  8. package/dist/host/api-keys.js.map +1 -0
  9. package/dist/host/constants.d.ts +16 -0
  10. package/dist/host/constants.js +17 -0
  11. package/dist/host/constants.js.map +1 -0
  12. package/dist/host/errors.d.ts +9 -0
  13. package/dist/host/errors.js +17 -0
  14. package/dist/host/errors.js.map +1 -0
  15. package/dist/host/handlers.d.ts +55 -0
  16. package/dist/host/handlers.js +242 -0
  17. package/dist/host/handlers.js.map +1 -0
  18. package/dist/host/http.d.ts +17 -0
  19. package/dist/host/http.js +156 -0
  20. package/dist/host/http.js.map +1 -0
  21. package/dist/host/login-store.d.ts +2 -0
  22. package/dist/host/login-store.js +141 -0
  23. package/dist/host/login-store.js.map +1 -0
  24. package/dist/host/models.d.ts +17 -0
  25. package/dist/host/models.js +80 -0
  26. package/dist/host/models.js.map +1 -0
  27. package/dist/host/payments.d.ts +14 -0
  28. package/dist/host/payments.js +92 -0
  29. package/dist/host/payments.js.map +1 -0
  30. package/dist/host/platform.d.ts +16 -0
  31. package/dist/host/platform.js +54 -0
  32. package/dist/host/platform.js.map +1 -0
  33. package/dist/host/subscription.d.ts +55 -0
  34. package/dist/host/subscription.js +129 -0
  35. package/dist/host/subscription.js.map +1 -0
  36. package/dist/host/topup.d.ts +22 -0
  37. package/dist/host/topup.js +64 -0
  38. package/dist/host/topup.js.map +1 -0
  39. package/dist/host/types.d.ts +50 -0
  40. package/dist/host/types.js +2 -0
  41. package/dist/host/types.js.map +1 -0
  42. package/dist/index.d.ts +19 -0
  43. package/dist/index.js +68 -0
  44. package/dist/index.js.map +1 -0
  45. package/icon.svg +4 -0
  46. package/llms.txt +106 -0
  47. package/locale/en.json +6 -0
  48. package/locale/zh.json +6 -0
  49. package/package.json +106 -0
package/dist/client.js ADDED
@@ -0,0 +1,2134 @@
1
+ "use strict";
2
+ (() => {
3
+ // src/client/constants.ts
4
+ var PANEL_ID = "dsh-metaontic-newapi-lite";
5
+ var NS = "sidebar.metaonticAiTool";
6
+ var QUERY_PATH = "/api/dsh-metaontic-newapi-lite.query";
7
+ var SESSION_PATH = "/api/dsh-metaontic-newapi-lite.session";
8
+ var API_KEYS_PATH = "/api/dsh-metaontic-newapi-lite.api-keys";
9
+ var TOPUP_PATH = "/api/dsh-metaontic-newapi-lite.topup";
10
+ var SUBSCRIPTION_PATH = "/api/dsh-metaontic-newapi-lite.subscription";
11
+ var MODELS_PATH = "/api/dsh-metaontic-newapi-lite.models";
12
+ var DEFAULT_BASE_URL = "https://ai.bileego.com/";
13
+ var REGISTER_URL = "https://ai.bileego.com/sign-up?aff=VzYr";
14
+
15
+ // src/client/runtime.ts
16
+ function formatNumber(value) {
17
+ const number = Number(value);
18
+ if (!Number.isFinite(number)) return "0";
19
+ const text = Math.abs(number) >= 1 ? number.toFixed(2) : number.toFixed(4);
20
+ return text.replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
21
+ }
22
+ function currency(platform) {
23
+ const type = String(platform?.quota_display_type || "USD").toUpperCase();
24
+ if (type === "CNY") {
25
+ return { symbol: "\xA5", code: "CNY", rate: Number(platform?.usd_exchange_rate) || 1 };
26
+ }
27
+ if (type === "CUSTOM") {
28
+ return {
29
+ symbol: String(platform?.custom_currency_symbol || "\xA4"),
30
+ code: "CUSTOM",
31
+ rate: Number(platform?.custom_currency_exchange_rate) || 1
32
+ };
33
+ }
34
+ return { symbol: "$", code: "USD", rate: 1 };
35
+ }
36
+ function topupAmountCurrency() {
37
+ return { symbol: "$", code: "USD", rate: 1 };
38
+ }
39
+ function paymentCurrency() {
40
+ return { symbol: "\xA5", code: "CNY", rate: 1 };
41
+ }
42
+ function formatQuota(quota, platform) {
43
+ const perUnit = Number(platform?.quota_per_unit) || 5e5;
44
+ const unit = currency(platform);
45
+ return `${unit.symbol}${formatNumber((Number(quota) || 0) / perUnit * unit.rate)}`;
46
+ }
47
+ function formatPercent(value) {
48
+ return value.toFixed(1).replace(/\.0$/, "");
49
+ }
50
+ function displayQuotaToUnits(value, platform) {
51
+ const amount = Number(value);
52
+ if (!Number.isFinite(amount) || amount < 0) return null;
53
+ const perUnit = Number(platform?.quota_per_unit) || 5e5;
54
+ const rate = currency(platform).rate || 1;
55
+ const units = Math.round(amount * perUnit / rate);
56
+ return Number.isSafeInteger(units) && units >= 0 ? units : null;
57
+ }
58
+ function expiryTimeFromDays(value) {
59
+ const days = Number(value ?? 0);
60
+ if (!Number.isFinite(days) || days < 0 || days > 36500) return null;
61
+ if (days === 0) return -1;
62
+ return Math.floor(Date.now() / 1e3 + days * 86400);
63
+ }
64
+ function apiKeyStatusLabel(t, status) {
65
+ const value = Number(status);
66
+ if (value === 1) return t("apiKeyStatusEnabled");
67
+ if (value === 2) return t("apiKeyStatusDisabled");
68
+ if (value === 3) return t("apiKeyStatusExpired");
69
+ if (value === 4) return t("apiKeyStatusExhausted");
70
+ return t("apiKeyStatusUnknown");
71
+ }
72
+ function apiKeyStatusTone(status) {
73
+ return Number(status) === 1 ? "mat-badge-ok" : "mat-badge-warn";
74
+ }
75
+ function apiKeyExpiryLabel(t, expiredTime) {
76
+ const seconds = Number(expiredTime);
77
+ if (seconds === -1) return t("neverExpires");
78
+ if (!Number.isFinite(seconds) || seconds <= 0) return t("empty");
79
+ return new Date(seconds * 1e3).toLocaleString();
80
+ }
81
+ function roleLabel(t, role) {
82
+ const value = Number(role);
83
+ if (value >= 100) return t("roleRoot");
84
+ if (value >= 10) return t("roleAdmin");
85
+ if (value === 1) return t("roleUser");
86
+ return t("roleUnknown");
87
+ }
88
+
89
+ // src/client/api-keys-page.ts
90
+ function createApiKeysPage({ React, h, t }) {
91
+ return function ApiKeysPage({ data }) {
92
+ const [keys, setKeys] = React.useState([]);
93
+ const [loading, setLoading] = React.useState(true);
94
+ const [error, setError] = React.useState("");
95
+ const [notice, setNotice] = React.useState("");
96
+ const [busyId, setBusyId] = React.useState(null);
97
+ const [createOpen, setCreateOpen] = React.useState(false);
98
+ const [creating, setCreating] = React.useState(false);
99
+ const [name, setName] = React.useState("");
100
+ const [unlimited, setUnlimited] = React.useState(true);
101
+ const [quota, setQuota] = React.useState("");
102
+ const [expiryDays, setExpiryDays] = React.useState("0");
103
+ const [groups, setGroups] = React.useState([]);
104
+ const [group, setGroup] = React.useState("");
105
+ const [revealed, setRevealed] = React.useState({});
106
+ function preferredGroup(list) {
107
+ const accountGroup = String(data.account.group || "");
108
+ if (accountGroup && list.some((item) => item.name === accountGroup)) return accountGroup;
109
+ const fallback = list.find((item) => item.name === "default") || list[0];
110
+ return fallback?.name || accountGroup;
111
+ }
112
+ function groupLabel(item) {
113
+ const details = [item.desc, item.ratio !== null ? `${formatNumber(item.ratio)}x` : ""].filter(Boolean);
114
+ return details.length > 0 ? `${item.name} \xB7 ${details.join(" \xB7 ")}` : item.name;
115
+ }
116
+ async function loadKeys(showLoading = true) {
117
+ if (showLoading) setLoading(true);
118
+ setError("");
119
+ try {
120
+ const response = await fetch(API_KEYS_PATH, { method: "GET", cache: "no-store" });
121
+ let payload;
122
+ try {
123
+ payload = await response.json();
124
+ } catch {
125
+ throw new Error(t("invalidResponse"));
126
+ }
127
+ if (!response.ok || !payload?.ok) {
128
+ throw new Error(payload?.error?.message || t("apiKeyLoadFailed"));
129
+ }
130
+ const nextGroups = Array.isArray(payload.data?.groups) ? payload.data.groups : [];
131
+ setKeys(Array.isArray(payload.data?.keys) ? payload.data.keys : []);
132
+ setGroups(nextGroups);
133
+ setGroup((previous) => previous && nextGroups.some((item) => item.name === previous) ? previous : preferredGroup(nextGroups));
134
+ setRevealed({});
135
+ } catch (failure) {
136
+ setError(failure instanceof Error && failure.message ? failure.message : t("apiKeyLoadFailed"));
137
+ } finally {
138
+ if (showLoading) setLoading(false);
139
+ }
140
+ }
141
+ React.useEffect(() => {
142
+ void loadKeys();
143
+ }, [data.baseUrl]);
144
+ React.useEffect(() => {
145
+ if (!createOpen || typeof document === "undefined") return;
146
+ const previous = document.body.style.overflow;
147
+ document.body.style.overflow = "hidden";
148
+ return () => {
149
+ document.body.style.overflow = previous;
150
+ };
151
+ }, [createOpen]);
152
+ function resetCreateForm() {
153
+ setName("");
154
+ setUnlimited(true);
155
+ setQuota("");
156
+ setExpiryDays("0");
157
+ setGroup(preferredGroup(groups));
158
+ }
159
+ function closeCreate() {
160
+ if (creating) return;
161
+ setCreateOpen(false);
162
+ resetCreateForm();
163
+ setError("");
164
+ }
165
+ function handleBackdrop(event) {
166
+ if (event.target === event.currentTarget) closeCreate();
167
+ }
168
+ function handleDialogKeyDown(event) {
169
+ if (event.key === "Escape") closeCreate();
170
+ }
171
+ async function createKey(event) {
172
+ event?.preventDefault?.();
173
+ const keyName = name.trim();
174
+ if (!keyName) {
175
+ setError(t("apiKeyNameRequired"));
176
+ return;
177
+ }
178
+ let remainQuota = 0;
179
+ if (!unlimited) {
180
+ const units = displayQuotaToUnits(quota, data.platform);
181
+ if (units === null) {
182
+ setError(t("apiKeyQuotaInvalid"));
183
+ return;
184
+ }
185
+ remainQuota = units;
186
+ }
187
+ const expiredTime = expiryTimeFromDays(expiryDays);
188
+ if (expiredTime === null) {
189
+ setError(t("apiKeyExpiryInvalid"));
190
+ return;
191
+ }
192
+ setCreating(true);
193
+ setError("");
194
+ setNotice("");
195
+ try {
196
+ const response = await fetch(API_KEYS_PATH, {
197
+ method: "POST",
198
+ headers: { "content-type": "application/json" },
199
+ body: JSON.stringify({
200
+ name: keyName,
201
+ unlimitedQuota: unlimited,
202
+ remainQuota,
203
+ expiredTime,
204
+ group: group || preferredGroup(groups)
205
+ })
206
+ });
207
+ let payload;
208
+ try {
209
+ payload = await response.json();
210
+ } catch {
211
+ throw new Error(t("invalidResponse"));
212
+ }
213
+ if (!response.ok || !payload?.ok) {
214
+ throw new Error(payload?.error?.message || t("apiKeyActionFailed"));
215
+ }
216
+ setCreateOpen(false);
217
+ resetCreateForm();
218
+ setNotice(t("apiKeyCreated"));
219
+ await loadKeys(false);
220
+ } catch (failure) {
221
+ setError(failure instanceof Error && failure.message ? failure.message : t("apiKeyActionFailed"));
222
+ } finally {
223
+ setCreating(false);
224
+ }
225
+ }
226
+ async function toggleStatus(apiKey) {
227
+ const id = Number(apiKey.id);
228
+ if (!Number.isSafeInteger(id) || id <= 0) return;
229
+ const nextStatus = Number(apiKey.status) === 1 ? 2 : 1;
230
+ setBusyId(id);
231
+ setError("");
232
+ setNotice("");
233
+ try {
234
+ const response = await fetch(API_KEYS_PATH, {
235
+ method: "PATCH",
236
+ headers: { "content-type": "application/json" },
237
+ body: JSON.stringify({ id, status: nextStatus })
238
+ });
239
+ let payload;
240
+ try {
241
+ payload = await response.json();
242
+ } catch {
243
+ throw new Error(t("invalidResponse"));
244
+ }
245
+ if (!response.ok || !payload?.ok) {
246
+ throw new Error(payload?.error?.message || t("apiKeyActionFailed"));
247
+ }
248
+ setNotice(nextStatus === 1 ? t("apiKeyEnabledNotice") : t("apiKeyDisabledNotice"));
249
+ await loadKeys(false);
250
+ } catch (failure) {
251
+ setError(failure instanceof Error && failure.message ? failure.message : t("apiKeyActionFailed"));
252
+ } finally {
253
+ setBusyId(null);
254
+ }
255
+ }
256
+ async function deleteKey(apiKey) {
257
+ const id = Number(apiKey.id);
258
+ if (!Number.isSafeInteger(id) || id <= 0) return;
259
+ const keyName = String(apiKey.name || id);
260
+ if (typeof confirm === "function" && !confirm(t("apiKeyDeleteConfirm", { name: keyName }))) return;
261
+ setBusyId(id);
262
+ setError("");
263
+ setNotice("");
264
+ try {
265
+ const response = await fetch(API_KEYS_PATH, {
266
+ method: "DELETE",
267
+ headers: { "content-type": "application/json" },
268
+ body: JSON.stringify({ id })
269
+ });
270
+ let payload;
271
+ try {
272
+ payload = await response.json();
273
+ } catch {
274
+ throw new Error(t("invalidResponse"));
275
+ }
276
+ if (!response.ok || !payload?.ok) {
277
+ throw new Error(payload?.error?.message || t("apiKeyActionFailed"));
278
+ }
279
+ setNotice(t("apiKeyDeleted"));
280
+ await loadKeys(false);
281
+ } catch (failure) {
282
+ setError(failure instanceof Error && failure.message ? failure.message : t("apiKeyActionFailed"));
283
+ } finally {
284
+ setBusyId(null);
285
+ }
286
+ }
287
+ async function toggleReveal(apiKey) {
288
+ const id = Number(apiKey.id);
289
+ if (!Number.isSafeInteger(id) || id <= 0) return;
290
+ if (revealed[String(id)]) {
291
+ setRevealed((previous) => {
292
+ const next = { ...previous };
293
+ delete next[String(id)];
294
+ return next;
295
+ });
296
+ return;
297
+ }
298
+ setBusyId(id);
299
+ setError("");
300
+ setNotice("");
301
+ try {
302
+ const response = await fetch(API_KEYS_PATH, {
303
+ method: "PUT",
304
+ headers: { "content-type": "application/json" },
305
+ body: JSON.stringify({ id })
306
+ });
307
+ let payload;
308
+ try {
309
+ payload = await response.json();
310
+ } catch {
311
+ throw new Error(t("invalidResponse"));
312
+ }
313
+ const key = payload?.data?.key;
314
+ if (!response.ok || !payload?.ok || typeof key !== "string" || !key) {
315
+ throw new Error(payload?.error?.message || t("apiKeyRevealFailed"));
316
+ }
317
+ setRevealed((previous) => ({ ...previous, [String(id)]: key }));
318
+ } catch (failure) {
319
+ setError(failure instanceof Error && failure.message ? failure.message : t("apiKeyRevealFailed"));
320
+ } finally {
321
+ setBusyId(null);
322
+ }
323
+ }
324
+ async function copyKey(apiKey) {
325
+ const key = revealed[String(apiKey.id)];
326
+ if (!key) return;
327
+ try {
328
+ if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
329
+ await navigator.clipboard.writeText(key);
330
+ setNotice(t("apiKeyCopied"));
331
+ } else {
332
+ setNotice(t("apiKeyCopyUnavailable"));
333
+ }
334
+ } catch {
335
+ setNotice(t("apiKeyCopyUnavailable"));
336
+ }
337
+ }
338
+ const createForm = createOpen ? h("div", { key: "create-modal", className: "mat-modal-backdrop", onClick: handleBackdrop }, [
339
+ h("form", {
340
+ key: "create",
341
+ className: "mat-key-create mat-modal",
342
+ role: "dialog",
343
+ "aria-modal": "true",
344
+ "aria-labelledby": "mat-key-dialog-title",
345
+ onSubmit: createKey,
346
+ onKeyDown: handleDialogKeyDown
347
+ }, [
348
+ h("div", { key: "head", className: "mat-modal-head" }, [
349
+ h("div", { key: "copy", className: "mat-modal-copy" }, [
350
+ h("div", { key: "title", id: "mat-key-dialog-title", className: "mat-modal-title" }, t("apiKeyNew")),
351
+ h("div", { key: "hint", className: "mat-hint" }, t("apiKeyCreateHint"))
352
+ ]),
353
+ h("button", {
354
+ key: "close",
355
+ type: "button",
356
+ className: "mat-modal-close",
357
+ "aria-label": t("apiKeyCancel"),
358
+ onClick: closeCreate,
359
+ disabled: creating
360
+ }, "\xD7")
361
+ ]),
362
+ h("label", { key: "name", className: "mat-field mat-modal-wide" }, [
363
+ h("span", { key: "label", className: "mat-label" }, t("apiKeyName")),
364
+ h("input", {
365
+ key: "input",
366
+ className: "mat-input",
367
+ value: name,
368
+ onChange: (event) => setName(event.target.value),
369
+ placeholder: t("apiKeyNamePlaceholder"),
370
+ maxLength: 50,
371
+ autoComplete: "off",
372
+ autoFocus: true,
373
+ disabled: creating,
374
+ required: true
375
+ })
376
+ ]),
377
+ h("label", { key: "quota", className: "mat-field" }, [
378
+ h("span", { key: "label", className: "mat-label" }, t("apiKeyQuota")),
379
+ h("input", {
380
+ key: "input",
381
+ className: "mat-input",
382
+ type: "number",
383
+ min: 0,
384
+ step: 0.01,
385
+ value: quota,
386
+ onChange: (event) => setQuota(event.target.value),
387
+ placeholder: t("apiKeyQuotaPlaceholder"),
388
+ disabled: creating || unlimited
389
+ }),
390
+ h("span", { key: "hint", className: "mat-hint" }, t("apiKeyQuotaHint"))
391
+ ]),
392
+ h("label", { key: "expiry", className: "mat-field" }, [
393
+ h("span", { key: "label", className: "mat-label" }, t("apiKeyExpiryDays")),
394
+ h("input", {
395
+ key: "input",
396
+ className: "mat-input",
397
+ type: "number",
398
+ min: 0,
399
+ step: 1,
400
+ value: expiryDays,
401
+ onChange: (event) => setExpiryDays(event.target.value),
402
+ disabled: creating
403
+ }),
404
+ h("span", { key: "hint", className: "mat-hint" }, t("apiKeyNeverExpiresHint"))
405
+ ]),
406
+ h("label", { key: "group", className: "mat-field mat-modal-wide" }, [
407
+ h("span", { key: "label", className: "mat-label" }, t("apiKeyGroup")),
408
+ h("select", {
409
+ key: "select",
410
+ className: "mat-input",
411
+ value: group,
412
+ onChange: (event) => setGroup(event.target.value),
413
+ disabled: creating || groups.length === 0
414
+ }, groups.length > 0 ? groups.map((item) => h("option", { key: item.name, value: item.name }, groupLabel(item))) : [h("option", { key: "account", value: String(data.account.group || "") }, String(data.account.group || t("apiKeyGroup")))]),
415
+ h("span", { key: "hint", className: "mat-hint" }, t("apiKeyGroupHint"))
416
+ ]),
417
+ h("label", { key: "unlimited", className: "mat-key-check mat-modal-wide" }, [
418
+ h("input", {
419
+ key: "input",
420
+ type: "checkbox",
421
+ checked: unlimited,
422
+ onChange: (event) => setUnlimited(Boolean(event.target.checked)),
423
+ disabled: creating
424
+ }),
425
+ h("span", { key: "label" }, t("apiKeyUnlimited"))
426
+ ]),
427
+ h("div", { key: "actions", className: "mat-key-create-actions" }, [
428
+ h("button", { key: "cancel", type: "button", className: "mat-btn mat-btn-sm", onClick: closeCreate, disabled: creating }, t("apiKeyCancel")),
429
+ h(
430
+ "button",
431
+ { key: "submit", type: "submit", className: "mat-btn mat-btn-primary mat-btn-sm", disabled: creating },
432
+ creating ? t("apiKeyCreating") : t("apiKeyCreate")
433
+ )
434
+ ])
435
+ ])
436
+ ]) : null;
437
+ const keyList = loading && keys.length === 0 ? h("p", { key: "loading", className: "mat-hint" }, t("apiKeyRefreshing")) : keys.length === 0 ? h("p", { key: "empty", className: "mat-hint" }, t("apiKeyNone")) : h("div", { key: "list", className: "mat-key-list" }, keys.map((apiKey) => {
438
+ const id = Number(apiKey.id);
439
+ const keyText = revealed[String(id)];
440
+ const enabled = Number(apiKey.status) === 1;
441
+ return h("div", { key: String(apiKey.id), className: "mat-key-item" }, [
442
+ h("div", { key: "head", className: "mat-key-head" }, [
443
+ h("div", { key: "name", className: "mat-key-name" }, apiKey.name || t("empty")),
444
+ h(
445
+ "span",
446
+ { key: "status", className: `mat-badge ${apiKeyStatusTone(apiKey.status)}` },
447
+ apiKeyStatusLabel(t, apiKey.status)
448
+ ),
449
+ apiKey.group ? h("span", { key: "group", className: "mat-badge" }, apiKey.group) : null
450
+ ]),
451
+ keyText ? h("code", {
452
+ key: "secret",
453
+ className: "mat-key-secret"
454
+ }, keyText) : null,
455
+ h("div", { key: "meta", className: "mat-key-meta" }, [
456
+ h("div", { key: "quota" }, [
457
+ h("div", { key: "label", className: "mat-key-meta-label" }, t("apiKeyQuotaLabel")),
458
+ h(
459
+ "div",
460
+ { key: "value", className: "mat-key-meta-value" },
461
+ apiKey.unlimited_quota ? t("unlimited") : formatQuota(apiKey.remain_quota, data.platform)
462
+ )
463
+ ]),
464
+ h("div", { key: "used" }, [
465
+ h("div", { key: "label", className: "mat-key-meta-label" }, t("apiKeyUsedLabel")),
466
+ h("div", { key: "value", className: "mat-key-meta-value" }, formatQuota(apiKey.used_quota, data.platform))
467
+ ]),
468
+ h("div", { key: "expires" }, [
469
+ h("div", { key: "label", className: "mat-key-meta-label" }, t("apiKeyExpires")),
470
+ h("div", { key: "value", className: "mat-key-meta-value" }, apiKeyExpiryLabel(t, apiKey.expired_time))
471
+ ])
472
+ ]),
473
+ h("div", { key: "actions", className: "mat-key-actions" }, [
474
+ h("button", {
475
+ key: "reveal",
476
+ type: "button",
477
+ className: "mat-btn mat-btn-sm",
478
+ onClick: () => void toggleReveal(apiKey),
479
+ disabled: busyId === id
480
+ }, keyText ? t("apiKeyHide") : t("apiKeyShow")),
481
+ keyText ? h("button", {
482
+ key: "copy",
483
+ type: "button",
484
+ className: "mat-btn mat-btn-sm",
485
+ onClick: () => void copyKey(apiKey)
486
+ }, t("apiKeyCopy")) : null,
487
+ h("button", {
488
+ key: "toggle",
489
+ type: "button",
490
+ className: "mat-btn mat-btn-sm",
491
+ onClick: () => void toggleStatus(apiKey),
492
+ disabled: busyId === id
493
+ }, enabled ? t("apiKeyDisable") : t("apiKeyEnable")),
494
+ h("button", {
495
+ key: "delete",
496
+ type: "button",
497
+ className: "mat-btn mat-btn-sm mat-btn-danger",
498
+ onClick: () => void deleteKey(apiKey),
499
+ disabled: busyId === id
500
+ }, t("apiKeyDelete"))
501
+ ])
502
+ ]);
503
+ }));
504
+ return h("section", { className: "mat-card mat-api-keys" }, [
505
+ h("div", { key: "head", className: "mat-card-head" }, [
506
+ h("div", { key: "copy", className: "mat-card-head-copy" }, [
507
+ h("div", { key: "title", className: "mat-card-title" }, t("apiKeys")),
508
+ h("div", { key: "hint", className: "mat-hint" }, t("apiKeysHint"))
509
+ ]),
510
+ h("div", { key: "head-actions", className: "mat-actions" }, [
511
+ h("button", {
512
+ key: "refresh",
513
+ type: "button",
514
+ className: "mat-btn mat-btn-sm",
515
+ onClick: () => void loadKeys(),
516
+ disabled: loading
517
+ }, loading ? t("apiKeyRefreshing") : t("apiKeyRefresh")),
518
+ h("button", {
519
+ key: "new",
520
+ type: "button",
521
+ className: "mat-btn mat-btn-primary mat-btn-sm",
522
+ onClick: () => {
523
+ if (createOpen) {
524
+ closeCreate();
525
+ } else {
526
+ setCreateOpen(true);
527
+ }
528
+ setError("");
529
+ setNotice("");
530
+ }
531
+ }, createOpen ? t("apiKeyCancel") : t("apiKeyNew"))
532
+ ])
533
+ ]),
534
+ error ? h("div", { key: "error", className: "mat-error", role: "alert", style: { marginBottom: 10 } }, error) : null,
535
+ notice ? h("div", { key: "notice", className: "mat-notice", role: "status", style: { marginBottom: 10 } }, notice) : null,
536
+ h("div", { key: "list-head", className: "mat-key-list-head" }, [
537
+ h("div", { key: "title", className: "mat-card-title" }, t("apiKeyListTitle", { count: keys.length })),
538
+ h("span", { key: "count", className: "mat-badge" }, String(keys.length))
539
+ ]),
540
+ keyList,
541
+ createForm
542
+ ]);
543
+ };
544
+ }
545
+
546
+ // src/client/models-page.ts
547
+ function createModelsPage({ React, h, t }) {
548
+ return function ModelsPage({ data }) {
549
+ const [models, setModels] = React.useState([]);
550
+ const [groups, setGroups] = React.useState([]);
551
+ const [query, setQuery] = React.useState("");
552
+ const [group, setGroup] = React.useState("");
553
+ const [loading, setLoading] = React.useState(true);
554
+ const [error, setError] = React.useState("");
555
+ async function loadModels() {
556
+ setLoading(true);
557
+ setError("");
558
+ try {
559
+ const response = await fetch(MODELS_PATH, { method: "GET", cache: "no-store" });
560
+ let payload;
561
+ try {
562
+ payload = await response.json();
563
+ } catch {
564
+ throw new Error(t("invalidResponse"));
565
+ }
566
+ if (!response.ok || !payload?.ok || !payload.data) {
567
+ throw new Error(payload?.error?.message || t("modelsLoadFailed"));
568
+ }
569
+ const nextModels = Array.isArray(payload.data.models) ? payload.data.models : [];
570
+ const nextGroups = Array.isArray(payload.data.groups) ? payload.data.groups : [];
571
+ setModels(nextModels);
572
+ setGroups(nextGroups);
573
+ setGroup((previous) => previous && nextGroups.includes(previous) ? previous : "");
574
+ } catch (failure) {
575
+ setError(failure instanceof Error && failure.message ? failure.message : t("modelsLoadFailed"));
576
+ } finally {
577
+ setLoading(false);
578
+ }
579
+ }
580
+ React.useEffect(() => {
581
+ void loadModels();
582
+ }, [data.baseUrl]);
583
+ const keyword = query.trim().toLowerCase();
584
+ const filtered = models.filter((model) => {
585
+ if (group && !model.groups.includes(group)) return false;
586
+ if (!keyword) return true;
587
+ const haystack = [model.name, model.description, ...model.tags, ...model.groups, ...model.endpoints].join(" ").toLowerCase();
588
+ return haystack.includes(keyword);
589
+ });
590
+ const toolbar = h("div", { key: "toolbar", className: "mat-model-toolbar" }, [
591
+ h("label", { key: "search", className: "mat-field" }, [
592
+ h("span", { key: "label", className: "mat-label" }, t("modelsSearch")),
593
+ h("input", {
594
+ key: "input",
595
+ className: "mat-input",
596
+ type: "search",
597
+ value: query,
598
+ onChange: (event) => setQuery(event.target.value),
599
+ placeholder: t("modelsSearchPlaceholder"),
600
+ disabled: loading
601
+ })
602
+ ]),
603
+ h("label", { key: "group", className: "mat-field" }, [
604
+ h("span", { key: "label", className: "mat-label" }, t("modelsGroupFilter")),
605
+ h("select", {
606
+ key: "select",
607
+ className: "mat-input",
608
+ value: group,
609
+ onChange: (event) => setGroup(event.target.value),
610
+ disabled: loading || groups.length === 0
611
+ }, [
612
+ h("option", { key: "all", value: "" }, t("modelsAllGroups")),
613
+ ...groups.map((item) => h("option", { key: item, value: item }, item))
614
+ ])
615
+ ])
616
+ ]);
617
+ const list = loading && models.length === 0 ? h("p", { key: "loading", className: "mat-hint" }, t("modelsLoading")) : filtered.length === 0 ? h("p", { key: "empty", className: "mat-hint" }, t("modelsEmpty")) : h("div", { key: "list", className: "mat-model-list" }, filtered.map((model) => {
618
+ const price = model.price !== null && model.price > 0 ? t("modelsPrice", { price: `$${formatNumber(model.price)}` }) : model.ratio !== null ? t("modelsRatio", { ratio: formatNumber(model.ratio) }) : "";
619
+ return h("article", { key: model.name, className: "mat-model-item" }, [
620
+ h("div", { key: "head", className: "mat-model-head" }, [
621
+ h("div", { key: "name", className: "mat-model-name" }, model.name),
622
+ price ? h("span", { key: "price", className: "mat-badge mat-model-price" }, price) : null
623
+ ]),
624
+ model.description ? h("p", { key: "desc", className: "mat-model-desc" }, model.description) : null,
625
+ model.tags.length > 0 ? h("div", { key: "tags", className: "mat-model-tags" }, model.tags.slice(0, 6).map((tag) => h("span", { key: tag, className: "mat-model-tag" }, tag))) : null,
626
+ h("div", { key: "meta", className: "mat-model-meta" }, [
627
+ model.groups.length > 0 ? h("div", { key: "groups", className: "mat-model-meta-row" }, [
628
+ h("span", { key: "label", className: "mat-model-meta-label" }, t("modelsGroups")),
629
+ ...model.groups.slice(0, 8).map((item) => h("span", { key: item, className: "mat-badge" }, item))
630
+ ]) : null,
631
+ model.endpoints.length > 0 ? h("div", { key: "endpoints", className: "mat-model-meta-row" }, [
632
+ h("span", { key: "label", className: "mat-model-meta-label" }, t("modelsEndpoints")),
633
+ ...model.endpoints.map((item) => h("span", { key: item, className: "mat-badge" }, item))
634
+ ]) : null
635
+ ])
636
+ ]);
637
+ }));
638
+ return h("section", { className: "mat-card mat-models" }, [
639
+ h("div", { key: "head", className: "mat-card-head" }, [
640
+ h("div", { key: "copy", className: "mat-card-head-copy" }, [
641
+ h("div", { key: "title", className: "mat-card-title" }, t("modelsPage")),
642
+ h("div", { key: "hint", className: "mat-hint" }, t("modelsHint"))
643
+ ]),
644
+ h("button", {
645
+ key: "refresh",
646
+ type: "button",
647
+ className: "mat-btn mat-btn-sm",
648
+ onClick: () => void loadModels(),
649
+ disabled: loading
650
+ }, loading ? t("apiKeyRefreshing") : t("modelsRefresh"))
651
+ ]),
652
+ error ? h("div", { key: "error", className: "mat-error", role: "alert", style: { marginBottom: 10 } }, error) : null,
653
+ toolbar,
654
+ h("div", { key: "count", className: "mat-model-count" }, t("modelsCount", { count: filtered.length })),
655
+ list
656
+ ]);
657
+ };
658
+ }
659
+
660
+ // src/client/overview-page.ts
661
+ function createOverviewPage({ h, t }) {
662
+ return function OverviewPage({ data }) {
663
+ const { account, platform, fetchedAt } = data;
664
+ const remaining = Number(account.quota) || 0;
665
+ const used = Number(account.used_quota) || 0;
666
+ const total = remaining + used;
667
+ const remainingPercentage = total > 0 ? Math.min(100, Math.max(0, remaining / total * 100)) : 0;
668
+ const progressTone = remainingPercentage <= 5 ? " mat-progress-danger" : remainingPercentage <= 20 ? " mat-progress-warn" : "";
669
+ const statusActive = Number(account.status) !== 2;
670
+ const unit = currency(platform);
671
+ const showDisplayName = Boolean(account.display_name && account.display_name !== account.username);
672
+ const accountParts = [];
673
+ if (account.username) accountParts.push(String(account.username));
674
+ if (showDisplayName) accountParts.push(String(account.display_name));
675
+ if (account.group) accountParts.push(String(account.group));
676
+ accountParts.push(roleLabel(t, account.role));
677
+ if (account.id !== void 0 && account.id !== null && account.id !== "") {
678
+ accountParts.push(`${t("accountId")} ${account.id}`);
679
+ }
680
+ const platformParts = [
681
+ platform.version ? `${t("version")} ${platform.version}` : "",
682
+ unit.code,
683
+ `${t("fetchedAt")} ${new Date(fetchedAt).toLocaleString()}`
684
+ ].filter(Boolean);
685
+ return h("section", { className: "mat-card mat-overview" }, [
686
+ h("div", { key: "head", className: "mat-card-head" }, [
687
+ h("div", { key: "title", className: "mat-card-title" }, t("accountPlatform")),
688
+ h("div", { key: "badges", className: "mat-badges" }, [
689
+ h(
690
+ "span",
691
+ { key: "status", className: `mat-badge ${statusActive ? "mat-badge-ok" : "mat-badge-warn"}` },
692
+ statusActive ? t("enabled") : t("disabled")
693
+ ),
694
+ h("span", { key: "currency", className: "mat-badge" }, `${unit.code} ${unit.symbol}`)
695
+ ])
696
+ ]),
697
+ h("div", { key: "metrics", className: "mat-metrics" }, [
698
+ h("div", { key: "balance", className: "mat-metric" }, [
699
+ h("div", { key: "label", className: "mat-metric-label" }, t("balance")),
700
+ h("div", { key: "value", className: "mat-metric-value" }, formatQuota(remaining, platform))
701
+ ]),
702
+ h("div", { key: "used", className: "mat-metric" }, [
703
+ h("div", { key: "label", className: "mat-metric-label" }, t("usedQuota")),
704
+ h("div", { key: "value", className: "mat-metric-value" }, formatQuota(used, platform))
705
+ ]),
706
+ h("div", { key: "requests", className: "mat-metric" }, [
707
+ h("div", { key: "label", className: "mat-metric-label" }, t("requests")),
708
+ h("div", { key: "value", className: "mat-metric-value" }, String(Number(account.request_count) || 0))
709
+ ])
710
+ ]),
711
+ h("div", { key: "ratio-label", className: "mat-ratio-head" }, [
712
+ h("div", { key: "label", className: "mat-hint" }, t("usageRatio")),
713
+ h("div", { key: "value", className: "mat-ratio-value" }, t("usageRemainingPercent", {
714
+ percent: formatPercent(remainingPercentage)
715
+ }))
716
+ ]),
717
+ h("div", {
718
+ key: "progress",
719
+ className: "mat-progress",
720
+ role: "progressbar",
721
+ "aria-valuemin": 0,
722
+ "aria-valuemax": 100,
723
+ "aria-valuenow": Math.round(remainingPercentage),
724
+ "aria-valuetext": t("usageRemainingPercent", { percent: formatPercent(remainingPercentage) }),
725
+ title: t("rawQuota", {
726
+ quota: formatQuota(remaining, platform),
727
+ used: formatQuota(used, platform)
728
+ })
729
+ }, h("div", { className: `mat-progress-bar${progressTone}`, style: { width: `${remainingPercentage}%` } })),
730
+ h("div", { key: "summary", className: "mat-compact-lines" }, [
731
+ h("div", { key: "account", className: "mat-compact-line" }, [
732
+ h("span", { key: "label", className: "mat-compact-label" }, t("account")),
733
+ h("span", { key: "value", className: "mat-compact-value" }, accountParts.join(" \xB7 ") || t("empty"))
734
+ ]),
735
+ h("div", { key: "platform", className: "mat-compact-line" }, [
736
+ h("span", { key: "label", className: "mat-compact-label" }, t("platform")),
737
+ h("span", { key: "value", className: "mat-compact-value" }, platformParts.join(" \xB7 "))
738
+ ])
739
+ ])
740
+ ]);
741
+ };
742
+ }
743
+
744
+ // src/client/shell.ts
745
+ function createPanelIconView({ h }) {
746
+ return function PanelIconView({ size = 18, active = false }) {
747
+ const pixels = Number(size) || 18;
748
+ return h("svg", {
749
+ width: pixels,
750
+ height: pixels,
751
+ viewBox: "0 0 24 24",
752
+ fill: "none",
753
+ stroke: "currentColor",
754
+ strokeWidth: 1.7,
755
+ strokeLinecap: "round",
756
+ strokeLinejoin: "round",
757
+ "aria-hidden": true,
758
+ style: { display: "block", color: active ? "var(--dsw-alias-brand-primary,#2563eb)" : "currentColor" }
759
+ }, [
760
+ h("path", { key: "outer", d: "M12 2.8 20 7.4v9.2l-8 4.6-8-4.6V7.4z" }),
761
+ h("path", { key: "inner", d: "M8.2 12h7.6M12 8.2v7.6" })
762
+ ]);
763
+ };
764
+ }
765
+ function createHeader(runtime) {
766
+ const { h, t } = runtime;
767
+ const PanelIconView = createPanelIconView(runtime);
768
+ return function Header() {
769
+ return h("div", { className: "mat-hero" }, [
770
+ h("div", { key: "mark", className: "mat-mark", "aria-hidden": true }, h(PanelIconView, { size: 25 })),
771
+ h("div", { key: "copy" }, [
772
+ h("h2", { key: "title", className: "mat-title" }, t("title")),
773
+ h("p", { key: "intro", className: "mat-intro" }, t("intro"))
774
+ ])
775
+ ]);
776
+ };
777
+ }
778
+ function createLoginForm({ h, t }) {
779
+ return function LoginForm({ baseUrl, setBaseUrl, token, setToken, showToken, setShowToken, pending, error, onSubmit }) {
780
+ return h("form", { className: "mat-card mat-login", onSubmit }, [
781
+ h("label", { key: "url-field", className: "mat-field" }, [
782
+ h("span", { key: "label", className: "mat-label" }, t("baseUrl")),
783
+ h("input", {
784
+ key: "input",
785
+ className: "mat-input mat-mono",
786
+ type: "url",
787
+ value: baseUrl,
788
+ onChange: (event) => setBaseUrl(event.target.value),
789
+ placeholder: DEFAULT_BASE_URL,
790
+ autoComplete: "url",
791
+ disabled: pending,
792
+ required: true
793
+ })
794
+ ]),
795
+ h("label", { key: "token-field", className: "mat-field" }, [
796
+ h("span", { key: "label", className: "mat-label" }, t("accessToken")),
797
+ h("div", { key: "wrap", className: "mat-input-wrap" }, [
798
+ h("input", {
799
+ key: "input",
800
+ className: "mat-input mat-mono",
801
+ type: showToken ? "text" : "password",
802
+ value: token,
803
+ onChange: (event) => setToken(event.target.value),
804
+ placeholder: t("accessTokenPlaceholder"),
805
+ autoComplete: "off",
806
+ spellCheck: false,
807
+ disabled: pending,
808
+ required: true
809
+ }),
810
+ h("button", {
811
+ key: "toggle",
812
+ type: "button",
813
+ className: "mat-btn",
814
+ onClick: () => setShowToken((value) => !value),
815
+ disabled: pending
816
+ }, showToken ? t("hideToken") : t("showToken"))
817
+ ]),
818
+ h("p", { key: "hint", className: "mat-hint" }, t("accessTokenHint")),
819
+ h("p", { key: "privacy", className: "mat-hint" }, t("tokenPrivacy")),
820
+ !token.trim() && !pending ? h("div", { key: "register", className: "mat-register" }, [
821
+ h("span", { key: "prompt", className: "mat-hint" }, t("registerPrompt")),
822
+ h("a", {
823
+ key: "link",
824
+ className: "mat-btn mat-btn-register",
825
+ href: REGISTER_URL,
826
+ target: "_blank",
827
+ rel: "noopener noreferrer",
828
+ referrerPolicy: "no-referrer"
829
+ }, t("registerNow"))
830
+ ]) : null
831
+ ]),
832
+ error ? h("div", { key: "error", className: "mat-error", role: "alert" }, error) : null,
833
+ h(
834
+ "div",
835
+ { key: "actions", className: "mat-actions" },
836
+ h("button", {
837
+ type: "submit",
838
+ className: "mat-btn mat-btn-primary",
839
+ disabled: pending
840
+ }, pending ? t("loginPending") : t("login"))
841
+ )
842
+ ]);
843
+ };
844
+ }
845
+
846
+ // src/client/styles.ts
847
+ var PANEL_CSS = `
848
+ .mat-root{box-sizing:border-box;width:100%;max-width:920px;margin:0 auto;padding:22px 24px 40px;color:var(--dsw-alias-label-primary,#1f2329);font-size:13px;line-height:1.5}
849
+ .mat-hero{display:flex;align-items:flex-start;gap:14px;margin-bottom:14px;padding:17px 18px;border:1px solid color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 14%,var(--dsw-alias-border-l1,#e4e8ee));border-radius:18px;background:linear-gradient(135deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 9%,transparent),transparent 62%),var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 10px 30px rgba(15,23,42,.05)}
850
+ .mat-mark{flex:0 0 auto;display:grid;place-items:center;width:46px;height:46px;border-radius:14px;background:linear-gradient(145deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 18%,transparent),color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 8%,transparent));color:var(--dsw-alias-brand-primary,#2563eb);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 18%,transparent)}
851
+ .mat-title{margin:0;font-size:20px;font-weight:680;letter-spacing:-.015em;line-height:1.35}
852
+ .mat-intro{margin:4px 0 0;color:var(--dsw-alias-label-secondary,#67707c);font-size:12.5px;line-height:1.6}
853
+ .mat-card{border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:16px;background:var(--dsw-alias-settings-card-fill,var(--dsw-alias-bg-layer-1,#fff));padding:18px;box-shadow:0 10px 28px rgba(15,23,42,.045)}
854
+ .mat-login{display:flex;flex-direction:column;gap:16px;max-width:560px}
855
+ .mat-field{display:flex;flex-direction:column;gap:8px}
856
+ .mat-label{font-size:12px;font-weight:600;color:var(--dsw-alias-label-primary,#1f2329)}
857
+ .mat-input-wrap{display:flex;gap:8px}
858
+ .mat-input{box-sizing:border-box;width:100%;min-width:0;height:40px;border:1px solid var(--dsw-alias-border-l1,#d9dee6);border-radius:10px;background:var(--dsw-alias-bg-layer-1,#fff);color:inherit;padding:0 12px;font:inherit;outline:none;transition:border-color .15s ease,box-shadow .15s ease,background .15s ease}
859
+ .mat-input:hover{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 24%,var(--dsw-alias-border-l1,#d9dee6))}
860
+ .mat-input:focus{border-color:var(--dsw-alias-brand-primary,#2563eb);box-shadow:0 0 0 3px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 13%,transparent)}
861
+ .mat-hint{margin:0;color:var(--dsw-alias-label-secondary,#67707c);font-size:11.5px;line-height:1.55}
862
+ .mat-register{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
863
+ .mat-btn{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:6px;height:36px;border:1px solid var(--dsw-alias-border-l1,#d9dee6);border-radius:10px;background:var(--dsw-alias-bg-layer-1,#fff);color:inherit;padding:0 14px;font:inherit;font-size:12.5px;font-weight:600;cursor:pointer;white-space:nowrap;transition:background .15s ease,border-color .15s ease,box-shadow .15s ease,transform .15s ease}
864
+ .mat-btn:hover{background:var(--dsw-alias-bg-layer-2,#f5f7fa);border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 18%,var(--dsw-alias-border-l1,#d9dee6))}
865
+ .mat-btn:active{transform:translateY(1px)}
866
+ .mat-btn:focus-visible{outline:2px solid color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 42%,transparent);outline-offset:2px}
867
+ .mat-btn:disabled{cursor:not-allowed;opacity:.55}
868
+ .mat-btn-primary{border-color:transparent;background:var(--dsw-alias-brand-primary,#2563eb);color:#fff;box-shadow:0 5px 14px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 24%,transparent)}
869
+ .mat-btn-primary:hover{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 88%,#000)}
870
+ .mat-btn-register{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 32%,transparent);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 7%,transparent);color:var(--dsw-alias-brand-primary,#2563eb);text-decoration:none}
871
+ .mat-btn-register:hover{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 13%,transparent)}
872
+ .mat-actions{display:flex;flex-wrap:wrap;align-items:center;gap:9px}
873
+ .mat-actions .mat-btn-primary{flex:1 1 210px}
874
+ .mat-error{display:flex;gap:8px;align-items:flex-start;border-radius:9px;background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#c62828) 8%,transparent);color:var(--dsw-alias-state-error-primary,#c62828);padding:9px 11px;font-size:12px;line-height:1.55}
875
+ .mat-notice{display:flex;gap:8px;align-items:flex-start;border-radius:9px;background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#2e7d32) 8%,transparent);color:var(--dsw-alias-state-success-primary,#2e7d32);padding:9px 11px;font-size:12px;line-height:1.55}
876
+ .mat-topbar{display:flex;flex-wrap:wrap;align-items:center;gap:9px;margin-bottom:14px;border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:14px;background:var(--dsw-alias-bg-layer-1,#fff);padding:12px 14px;box-shadow:0 6px 18px rgba(15,23,42,.035)}
877
+ .mat-topbar-title{flex:1 1 220px;min-width:0}
878
+ .mat-platform-name{margin:0;font-size:16.5px;font-weight:680;letter-spacing:-.01em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
879
+ .mat-subtle{color:var(--dsw-alias-label-secondary,#67707c);font-size:11.5px;line-height:1.5}
880
+ .mat-page-tabs{display:flex;gap:4px;margin:0 0 16px;border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:12px;background:var(--dsw-alias-bg-layer-2,#f5f7fa);padding:4px;overflow-x:auto;scrollbar-width:none}
881
+ .mat-page-tabs::-webkit-scrollbar{display:none}
882
+ .mat-page-tab{flex:0 0 auto;height:32px;border:0;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary,#67707c);padding:0 14px;font:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:background .15s ease,color .15s ease,box-shadow .15s ease}
883
+ .mat-page-tab:hover{background:color-mix(in srgb,var(--dsw-alias-bg-layer-1,#fff) 58%,transparent);color:var(--dsw-alias-label-primary,#1f2329)}
884
+ .mat-page-tab-active{background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-brand-primary,#2563eb);box-shadow:0 1px 4px rgba(15,23,42,.08),inset 0 0 0 1px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 16%,transparent)}
885
+ .mat-overview{margin-top:0;padding:16px 18px}
886
+ .mat-overview .mat-card-head{margin-bottom:9px}
887
+ .mat-overview .mat-metrics{gap:8px}
888
+ .mat-overview .mat-metric{padding:11px 12px}
889
+ .mat-overview .mat-metric-value{font-size:18px}
890
+ .mat-overview .mat-progress{margin:7px 0 0}
891
+ .mat-overview-stack{display:grid;overflow:hidden;border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:16px;background:var(--dsw-alias-settings-card-fill,var(--dsw-alias-bg-layer-1,#fff));box-shadow:0 10px 28px rgba(15,23,42,.045)}
892
+ .mat-overview-stack>.mat-card{margin:0;border:0;border-radius:0;background:transparent;padding:16px 18px;box-shadow:none}
893
+ .mat-overview-stack>.mat-card+.mat-card{border-top:1px dashed var(--dsw-alias-border-l1,#e4e8ee)}
894
+ .mat-badges{display:flex;flex-wrap:wrap;gap:6px}
895
+ .mat-compact-lines{display:grid;gap:5px;margin-top:10px;border-top:1px dashed var(--dsw-alias-border-l1,#e4e8ee);padding-top:9px}
896
+ .mat-compact-line{display:flex;gap:8px;font-size:11.5px;line-height:1.5}
897
+ .mat-compact-label{flex:0 0 60px;color:var(--dsw-alias-label-secondary,#67707c)}
898
+ .mat-compact-value{min-width:0;overflow-wrap:anywhere}
899
+ .mat-card-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px}
900
+ .mat-card-title{font-size:13.5px;font-weight:680;letter-spacing:-.01em}
901
+ .mat-badge{border-radius:999px;background:var(--dsw-alias-bg-layer-2,#f1f4f8);color:var(--dsw-alias-label-secondary,#67707c);padding:3px 9px;font-size:10.5px;font-weight:600;line-height:1.35}
902
+ .mat-badge-ok{background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#2e7d32) 10%,transparent);color:var(--dsw-alias-state-success-primary,#2e7d32)}
903
+ .mat-badge-warn{background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#b26a00) 10%,transparent);color:var(--dsw-alias-state-warn-primary,#b26a00)}
904
+ .mat-metrics{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:9px}
905
+ .mat-metric{border:1px solid color-mix(in srgb,var(--dsw-alias-border-l1,#e4e8ee) 82%,transparent);border-radius:12px;background:linear-gradient(180deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 4%,transparent),transparent);padding:12px 13px}
906
+ .mat-metric-label{color:var(--dsw-alias-label-secondary,#67707c);font-size:10.5px}
907
+ .mat-metric-value{margin-top:6px;font-size:19px;font-weight:700;letter-spacing:-.02em;line-height:1.2;overflow-wrap:anywhere}
908
+ .mat-progress{height:8px;border-radius:999px;background:var(--dsw-alias-bg-layer-2,#eef1f5);overflow:hidden;margin:13px 0 7px}
909
+ .mat-progress-bar{height:100%;border-radius:inherit;background:var(--dsw-alias-brand-primary,#2563eb)}
910
+ .mat-progress-bar.mat-progress-warn{background:#d97706}
911
+ .mat-progress-bar.mat-progress-danger{background:#dc2626}
912
+ .mat-ratio-head{display:flex;align-items:baseline;justify-content:space-between;gap:12px;margin-top:14px}
913
+ .mat-ratio-value{color:var(--dsw-alias-label-secondary,#67707c);font-size:11.5px;font-variant-numeric:tabular-nums;white-space:nowrap}
914
+ .mat-mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px}
915
+ .mat-foot{margin-top:14px;text-align:right}
916
+ .mat-api-keys{margin-top:0}
917
+ .mat-card-head-copy{min-width:0}
918
+ .mat-card-head-copy .mat-hint{margin-top:3px}
919
+ .mat-key-create{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(120px,.8fr) minmax(120px,.8fr);gap:10px;align-items:end;border:1px dashed var(--dsw-alias-border-l1,#e4e8ee);border-radius:11px;padding:12px;margin:0 0 12px}
920
+ .mat-key-create .mat-field{gap:5px}
921
+ .mat-key-check{display:flex;align-items:center;gap:7px;min-height:38px;font-size:12px;font-weight:600}
922
+ .mat-key-create-actions{display:flex;flex-wrap:wrap;gap:8px;grid-column:1/-1;justify-content:flex-end}
923
+ .mat-key-list{display:flex;flex-direction:column;gap:8px;max-height:min(58vh,520px);overflow-y:auto;overscroll-behavior:contain;touch-action:pan-y;padding-right:4px;scrollbar-gutter:stable}
924
+ .mat-key-list-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:2px 0 7px}
925
+ .mat-key-item{flex:0 0 auto;border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:10px;padding:10px 12px;background:var(--dsw-alias-bg-layer-1,#fff);transition:border-color .15s ease,box-shadow .15s ease}
926
+ .mat-key-item:hover{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 20%,var(--dsw-alias-border-l1,#e4e8ee));box-shadow:0 4px 14px rgba(15,23,42,.04)}
927
+ .mat-key-head{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-bottom:5px}
928
+ .mat-key-name{min-width:0;flex:1 1 180px;font-size:12.5px;font-weight:650;overflow-wrap:anywhere}
929
+ .mat-key-secret{display:block;box-sizing:border-box;width:100%;border-radius:7px;background:var(--dsw-alias-bg-layer-2,#f5f7fa);padding:5px 7px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11px;overflow-wrap:anywhere;user-select:all;margin-top:5px}
930
+ .mat-key-meta{display:flex;flex-wrap:wrap;align-items:baseline;gap:3px 14px;margin:5px 0 0}
931
+ .mat-key-meta>div{display:flex;align-items:baseline;gap:4px;min-width:0}
932
+ .mat-key-meta-label{color:var(--dsw-alias-label-secondary,#67707c);font-size:10px}
933
+ .mat-key-meta-value{margin-top:0;font-size:11px;font-weight:600;overflow-wrap:anywhere}
934
+ .mat-key-actions{display:flex;flex-wrap:wrap;gap:5px;margin-top:6px}
935
+ .mat-topup{margin-top:0}
936
+ .mat-topup .mat-card-head{margin-bottom:9px}
937
+ .mat-topup .mat-card-title{font-size:14px}
938
+ .mat-topup-status{display:flex;flex-wrap:wrap;align-items:center;gap:7px;margin-bottom:9px}
939
+ .mat-topup-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(180px,.8fr);gap:12px;align-items:end}
940
+ .mat-choice-row{display:flex;flex-wrap:wrap;gap:6px;margin-top:7px}
941
+ .mat-choice{height:30px;border:1px solid var(--dsw-alias-border-l1,#d9dee6);border-radius:9px;background:var(--dsw-alias-bg-layer-1,#fff);color:inherit;padding:0 11px;font:inherit;font-size:11px;font-weight:600;cursor:pointer;transition:background .15s ease,border-color .15s ease,color .15s ease}
942
+ .mat-topup .mat-choice{height:28px;padding:0 9px;font-size:10.5px}
943
+ .mat-choice:hover{background:var(--dsw-alias-bg-layer-2,#f5f7fa)}
944
+ .mat-choice-active{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 45%,transparent);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 9%,transparent);color:var(--dsw-alias-brand-primary,#2563eb)}
945
+ .mat-pay-result{display:grid;gap:8px;margin-top:12px;border-top:1px dashed var(--dsw-alias-border-l1,#e4e8ee);padding-top:10px}
946
+ .mat-topup-pay{display:grid;gap:10px;border:1px solid color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 16%,var(--dsw-alias-border-l1,#e4e8ee));border-radius:12px;background:linear-gradient(135deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 5%,transparent),transparent 72%),var(--dsw-alias-bg-layer-2,#f7f9fc);padding:14px}
947
+ .mat-pay-line{display:flex;align-items:baseline;justify-content:space-between;gap:12px;font-size:11.5px}
948
+ .mat-pay-line span{color:var(--dsw-alias-label-secondary,#67707c)}
949
+ .mat-pay-line strong{font-size:13px;overflow-wrap:anywhere;text-align:right}
950
+ .mat-pay-actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:8px;margin-top:2px}
951
+ .mat-pay-actions .mat-btn-primary{flex:1 1 180px}
952
+ .mat-models{margin-top:0;padding:18px}
953
+ .mat-model-toolbar{display:grid;grid-template-columns:minmax(0,1fr) minmax(140px,200px);gap:12px;align-items:end;margin:4px 0 12px}
954
+ .mat-model-count{margin:0 0 8px;color:var(--dsw-alias-label-secondary,#67707c);font-size:11px}
955
+ .mat-model-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:10px}
956
+ .mat-model-item{display:flex;flex-direction:column;gap:8px;min-width:0;border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:12px;background:linear-gradient(180deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 2.5%,transparent),transparent 58%),var(--dsw-alias-bg-layer-1,#fff);padding:13px 14px;transition:border-color .15s ease,box-shadow .15s ease}
957
+ .mat-model-item:hover{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 22%,var(--dsw-alias-border-l1,#e4e8ee));box-shadow:0 6px 18px rgba(15,23,42,.045)}
958
+ .mat-model-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px}
959
+ .mat-model-name{min-width:0;font-size:12.5px;font-weight:650;line-height:1.45;overflow-wrap:anywhere}
960
+ .mat-model-price{flex:0 0 auto;white-space:nowrap}
961
+ .mat-model-desc{display:-webkit-box;margin:0;overflow:hidden;color:var(--dsw-alias-label-secondary,#67707c);font-size:11px;line-height:1.55;white-space:pre-line;-webkit-box-orient:vertical;-webkit-line-clamp:3}
962
+ .mat-model-tags{display:flex;flex-wrap:wrap;gap:4px}
963
+ .mat-model-tag{border-radius:999px;background:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 10%,transparent);color:var(--dsw-alias-brand-primary,#2563eb);padding:3px 8px;font-size:10px;line-height:1.3}
964
+ .mat-model-meta{display:grid;gap:4px}
965
+ .mat-model-meta-row{display:flex;flex-wrap:wrap;align-items:center;gap:4px;min-width:0}
966
+ .mat-model-meta-label{color:var(--dsw-alias-label-secondary,#67707c);font-size:10px}
967
+ .mat-btn-sm{height:28px;padding:0 8px;font-size:11px}
968
+ .mat-btn-danger{border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary,#c62828) 28%,transparent);color:var(--dsw-alias-state-error-primary,#c62828)}
969
+ .mat-btn-danger:hover{background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#c62828) 8%,transparent)}
970
+ .mat-modal-backdrop{position:fixed;inset:0;z-index:1000;display:flex;align-items:center;justify-content:center;padding:20px;background:rgba(15,23,42,.48);backdrop-filter:blur(2px)}
971
+ .mat-key-create.mat-modal{position:relative;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));align-items:stretch;gap:12px;width:min(500px,100%);max-height:calc(100vh - 40px);overflow-y:auto;margin:0;padding:18px;border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:16px;background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:0 24px 70px rgba(15,23,42,.28);animation:mat-modal-in .16s ease-out}
972
+ .mat-key-create.mat-modal .mat-field{gap:6px}
973
+ .mat-modal-head{grid-column:1/-1;display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
974
+ .mat-modal-copy{min-width:0}
975
+ .mat-modal-title{font-size:15px;font-weight:650;line-height:1.4}
976
+ .mat-modal-close{flex:0 0 auto;width:30px;height:30px;border:0;border-radius:8px;background:var(--dsw-alias-bg-layer-2,#f5f7fa);color:var(--dsw-alias-label-secondary,#67707c);font:inherit;font-size:18px;line-height:1;cursor:pointer}
977
+ .mat-modal-close:hover{background:var(--dsw-alias-bg-layer-3,#eef1f5);color:var(--dsw-alias-label-primary,#1f2329)}
978
+ .mat-modal-wide{grid-column:1/-1}
979
+ .mat-subscription{margin-top:0;padding:18px}
980
+ .mat-sub-section{margin-top:14px}
981
+ .mat-sub-section:first-of-type{margin-top:0}
982
+ .mat-sub-section-title{margin-bottom:8px;font-size:12px;font-weight:650}
983
+ .mat-sub-current-list{display:grid;gap:10px}
984
+ .mat-sub-current{border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:12px;background:linear-gradient(135deg,color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 3%,transparent),transparent 66%),var(--dsw-alias-bg-layer-2,#f7f9fc);padding:11px 13px}
985
+ .mat-sub-current-head{display:flex;align-items:center;justify-content:space-between;gap:10px}
986
+ .mat-sub-current-title{min-width:0;font-size:13px;overflow-wrap:anywhere}
987
+ .mat-sub-meta{display:flex;flex-wrap:wrap;gap:5px 14px;margin-top:6px;color:var(--dsw-alias-label-secondary,#67707c);font-size:11px}
988
+ .mat-sub-quota-line{display:flex;align-items:center;gap:10px;margin-top:7px}
989
+ .mat-sub-quota-line .mat-progress{flex:1 1 auto;margin:0}
990
+ .mat-sub-quota-text{flex:0 0 auto;color:var(--dsw-alias-label-secondary,#67707c);font-size:10.5px;font-variant-numeric:tabular-nums}
991
+ .mat-sub-plans{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:10px}
992
+ .mat-sub-plan{display:flex;flex-direction:column;gap:8px;width:100%;border:1px solid var(--dsw-alias-border-l1,#e4e8ee);border-radius:12px;background:var(--dsw-alias-bg-layer-1,#fff);color:inherit;padding:13px 14px;text-align:left;font:inherit;cursor:pointer;transition:background .15s ease,border-color .15s ease,box-shadow .15s ease}
993
+ .mat-sub-plan:hover{background:var(--dsw-alias-bg-layer-2,#f5f7fa);border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 20%,var(--dsw-alias-border-l1,#e4e8ee))}
994
+ .mat-sub-plan:disabled{cursor:not-allowed;opacity:.6}
995
+ .mat-sub-plan-active{border-color:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 48%,transparent);background:color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 6%,var(--dsw-alias-bg-layer-1,#fff));box-shadow:0 0 0 1px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 28%,transparent) inset,0 6px 18px color-mix(in srgb,var(--dsw-alias-brand-primary,#2563eb) 8%,transparent)}
996
+ .mat-sub-plan-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px}
997
+ .mat-sub-plan-title{min-width:0;font-size:12.5px;line-height:1.45;overflow-wrap:anywhere}
998
+ .mat-sub-plan-price{flex:0 0 auto;color:var(--dsw-alias-brand-primary,#2563eb);font-size:15px;font-weight:700;white-space:nowrap}
999
+ .mat-sub-plan-subtitle{margin:0;color:var(--dsw-alias-label-secondary,#67707c);font-size:11px;line-height:1.55}
1000
+ .mat-sub-plan-meta{display:flex;flex-wrap:wrap;gap:4px}
1001
+ .mat-sub-pay{display:flex;flex-wrap:wrap;align-items:flex-end;justify-content:space-between;gap:12px;margin-top:12px;border-top:1px dashed var(--dsw-alias-border-l1,#e4e8ee);padding-top:12px}
1002
+ .mat-sub-pay .mat-field{flex:1 1 240px}
1003
+ .mat-sub-pay-actions{display:flex;flex:1 1 240px;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:10px}
1004
+ @keyframes mat-modal-in{from{opacity:0;transform:translateY(4px) scale(.985)}to{opacity:1;transform:none}}
1005
+ @media (prefers-reduced-motion:reduce){.mat-key-create.mat-modal{animation:none}}
1006
+ @media (max-width:620px){.mat-root{padding:16px 14px 30px}.mat-hero{padding:14px;border-radius:16px}.mat-topbar{padding:10px 12px}.mat-metrics{grid-template-columns:1fr}.mat-overview-stack>.mat-card{padding:14px}.mat-key-create{grid-template-columns:1fr}.mat-key-create.mat-modal{grid-template-columns:1fr}.mat-topup-grid{grid-template-columns:1fr}.mat-model-toolbar{grid-template-columns:1fr}.mat-model-list{grid-template-columns:1fr}.mat-pay-actions .mat-btn{flex:1 1 100%}.mat-sub-plans{grid-template-columns:1fr}.mat-sub-pay-actions{justify-content:flex-start}}
1007
+ `;
1008
+
1009
+ // src/client/subscription-page.ts
1010
+ function planPrice(plan, platform) {
1011
+ const code = String(plan.currency || "").toUpperCase();
1012
+ const symbol = code === "USD" ? "$" : code === "CNY" ? "\xA5" : code === "EUR" ? "\u20AC" : currency(platform).symbol;
1013
+ return `${symbol}${formatNumber(plan.priceAmount)}`;
1014
+ }
1015
+ function dateTime(value, fallback) {
1016
+ const seconds = Number(value);
1017
+ if (!Number.isFinite(seconds) || seconds <= 0) return fallback;
1018
+ return new Date(seconds * 1e3).toLocaleString();
1019
+ }
1020
+ function durationLabel(t, plan) {
1021
+ const count = Math.max(1, Number(plan.durationValue) || 1);
1022
+ switch (String(plan.durationUnit || "").toLowerCase()) {
1023
+ case "day":
1024
+ return t("subscriptionDays", { count });
1025
+ case "week":
1026
+ return t("subscriptionWeeks", { count });
1027
+ case "month":
1028
+ return t("subscriptionMonths", { count });
1029
+ case "year":
1030
+ return t("subscriptionYears", { count });
1031
+ case "hour":
1032
+ return t("subscriptionHours", { count });
1033
+ case "minute":
1034
+ return t("subscriptionMinutes", { count });
1035
+ case "second":
1036
+ return t("subscriptionSeconds", { count });
1037
+ case "custom":
1038
+ return t("subscriptionCustomDuration", { count: Math.max(1, Number(plan.customSeconds) || 1) });
1039
+ default:
1040
+ return `${count} ${plan.durationUnit || ""}`.trim();
1041
+ }
1042
+ }
1043
+ function resetLabel(t, plan) {
1044
+ const period = String(plan.quotaResetPeriod || "").toLowerCase();
1045
+ if (!period || period === "never") return t("subscriptionNeverReset");
1046
+ const unitKey = {
1047
+ day: "subscriptionResetDay",
1048
+ week: "subscriptionResetWeek",
1049
+ month: "subscriptionResetMonth",
1050
+ year: "subscriptionResetYear"
1051
+ }[period];
1052
+ if (unitKey) return t(unitKey);
1053
+ if (period === "custom") {
1054
+ return t("subscriptionResetCustom", { count: Math.max(1, Number(plan.quotaResetCustomSeconds) || 1) });
1055
+ }
1056
+ return t("subscriptionResetOther", { period });
1057
+ }
1058
+ function statusLabel(t, status) {
1059
+ switch (String(status || "").toLowerCase()) {
1060
+ case "active":
1061
+ return t("subscriptionStatusActive");
1062
+ case "expired":
1063
+ return t("subscriptionStatusExpired");
1064
+ case "cancelled":
1065
+ case "canceled":
1066
+ return t("subscriptionStatusCancelled");
1067
+ case "pending":
1068
+ return t("subscriptionStatusPending");
1069
+ default:
1070
+ return t("subscriptionStatusUnknown");
1071
+ }
1072
+ }
1073
+ function statusTone(status) {
1074
+ const value = String(status || "").toLowerCase();
1075
+ return value === "active" ? "mat-badge-ok" : "mat-badge-warn";
1076
+ }
1077
+ function createSubscriptionPage({ React, h, t }) {
1078
+ return function SubscriptionPage({ data }) {
1079
+ const [config, setConfig] = React.useState(null);
1080
+ const [loading, setLoading] = React.useState(true);
1081
+ const [error, setError] = React.useState("");
1082
+ const [notice, setNotice] = React.useState("");
1083
+ const [selectedPlanId, setSelectedPlanId] = React.useState(null);
1084
+ const [paymentMethod, setPaymentMethod] = React.useState("");
1085
+ const [creating, setCreating] = React.useState(false);
1086
+ const [payment, setPayment] = React.useState(null);
1087
+ async function loadConfig(showLoading = true) {
1088
+ if (showLoading) setLoading(true);
1089
+ setError("");
1090
+ try {
1091
+ const response = await fetch(SUBSCRIPTION_PATH, { method: "GET", cache: "no-store" });
1092
+ let payload;
1093
+ try {
1094
+ payload = await response.json();
1095
+ } catch {
1096
+ throw new Error(t("invalidResponse"));
1097
+ }
1098
+ if (!response.ok || !payload?.ok || !payload.data) {
1099
+ throw new Error(payload?.error?.message || t("subscriptionLoadFailed"));
1100
+ }
1101
+ const next = payload.data;
1102
+ const plans2 = Array.isArray(next.plans) ? next.plans : [];
1103
+ const methods2 = Array.isArray(next.paymentMethods) ? next.paymentMethods : [];
1104
+ setConfig({ ...next, plans: plans2, paymentMethods: methods2 });
1105
+ setSelectedPlanId((previous) => plans2.some((plan) => plan.id === previous) ? previous : plans2[0]?.id ?? null);
1106
+ setPaymentMethod((previous) => methods2.some((method) => method.type === previous) ? previous : methods2[0]?.type || "");
1107
+ } catch (failure) {
1108
+ setError(failure instanceof Error && failure.message ? failure.message : t("subscriptionLoadFailed"));
1109
+ } finally {
1110
+ if (showLoading) setLoading(false);
1111
+ }
1112
+ }
1113
+ React.useEffect(() => {
1114
+ void loadConfig();
1115
+ }, [data.baseUrl]);
1116
+ async function submit(event) {
1117
+ event?.preventDefault?.();
1118
+ if (!selectedPlanId || !paymentMethod) {
1119
+ setError(t("subscriptionSelectRequired"));
1120
+ return;
1121
+ }
1122
+ setCreating(true);
1123
+ setError("");
1124
+ setNotice("");
1125
+ setPayment(null);
1126
+ try {
1127
+ const response = await fetch(SUBSCRIPTION_PATH, {
1128
+ method: "POST",
1129
+ headers: { "content-type": "application/json" },
1130
+ body: JSON.stringify({ planId: selectedPlanId, paymentMethod })
1131
+ });
1132
+ let payload;
1133
+ try {
1134
+ payload = await response.json();
1135
+ } catch {
1136
+ throw new Error(t("invalidResponse"));
1137
+ }
1138
+ if (!response.ok || !payload?.ok || !payload.data?.payUrl) {
1139
+ throw new Error(payload?.error?.message || t("subscriptionCreateFailed"));
1140
+ }
1141
+ setPayment(payload.data);
1142
+ setNotice(t("subscriptionPaymentCreated"));
1143
+ } catch (failure) {
1144
+ setError(failure instanceof Error && failure.message ? failure.message : t("subscriptionCreateFailed"));
1145
+ } finally {
1146
+ setCreating(false);
1147
+ }
1148
+ }
1149
+ const plans = config?.plans ?? [];
1150
+ const methods = config?.paymentMethods ?? [];
1151
+ const current = config?.subscriptions ?? [];
1152
+ const selectedPlan = plans.find((plan) => plan.id === selectedPlanId) ?? null;
1153
+ const currentList = current.length === 0 ? h("p", { key: "empty-current", className: "mat-hint" }, t("subscriptionNone")) : h("div", { key: "current-list", className: "mat-sub-current-list" }, current.map((record) => {
1154
+ const total = Math.max(0, Number(record.amountTotal) || 0);
1155
+ const used = Math.max(0, Number(record.amountUsed) || 0);
1156
+ const remaining = Math.max(0, total - used);
1157
+ const remainingPercent = total > 0 ? Math.min(100, remaining / total * 100) : 100;
1158
+ const tone = remainingPercent <= 5 ? " mat-progress-danger" : remainingPercent <= 20 ? " mat-progress-warn" : "";
1159
+ return h("div", { key: String(record.id), className: "mat-sub-current" }, [
1160
+ h("div", { key: "head", className: "mat-sub-current-head" }, [
1161
+ h("strong", { key: "title", className: "mat-sub-current-title" }, record.planTitle),
1162
+ h("span", { key: "status", className: `mat-badge ${statusTone(record.status)}` }, statusLabel(t, record.status))
1163
+ ]),
1164
+ h("div", { key: "meta", className: "mat-sub-meta" }, [
1165
+ h("span", { key: "end" }, `${t("subscriptionEndsAt")} ${dateTime(record.endTime, t("empty"))}`),
1166
+ h("span", { key: "remaining" }, `${t("subscriptionRemainingQuota")} ${formatQuota(remaining, data.platform)}`),
1167
+ record.nextResetTime > 0 ? h("span", { key: "reset" }, `${t("subscriptionNextReset")} ${dateTime(record.nextResetTime, t("empty"))}`) : null
1168
+ ]),
1169
+ total > 0 ? h("div", { key: "quota", className: "mat-sub-quota-line" }, [
1170
+ h(
1171
+ "div",
1172
+ { key: "progress", className: "mat-progress", role: "progressbar", "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.round(remainingPercent) },
1173
+ h("div", { className: `mat-progress-bar${tone}`, style: { width: `${remainingPercent}%` } })
1174
+ ),
1175
+ h("span", { key: "text", className: "mat-sub-quota-text" }, t("subscriptionUsage", {
1176
+ used: formatQuota(used, data.platform),
1177
+ total: formatQuota(total, data.platform),
1178
+ percent: formatPercent(remainingPercent)
1179
+ }))
1180
+ ]) : null
1181
+ ]);
1182
+ }));
1183
+ const planList = plans.length === 0 ? h("p", { key: "empty-plans", className: "mat-hint" }, t("subscriptionNoPlans")) : h("div", { key: "plans", className: "mat-sub-plans" }, plans.map((plan) => {
1184
+ const selected = plan.id === selectedPlanId;
1185
+ return h("button", {
1186
+ key: String(plan.id),
1187
+ type: "button",
1188
+ className: `mat-sub-plan${selected ? " mat-sub-plan-active" : ""}`,
1189
+ onClick: () => {
1190
+ setSelectedPlanId(plan.id);
1191
+ setPayment(null);
1192
+ setNotice("");
1193
+ },
1194
+ disabled: creating
1195
+ }, [
1196
+ h("div", { key: "head", className: "mat-sub-plan-head" }, [
1197
+ h("strong", { key: "title", className: "mat-sub-plan-title" }, plan.title),
1198
+ h("span", { key: "price", className: "mat-sub-plan-price" }, planPrice(plan, data.platform))
1199
+ ]),
1200
+ plan.subtitle ? h("p", { key: "subtitle", className: "mat-sub-plan-subtitle" }, plan.subtitle) : null,
1201
+ h("div", { key: "meta", className: "mat-sub-plan-meta" }, [
1202
+ h("span", { key: "duration", className: "mat-badge" }, durationLabel(t, plan)),
1203
+ plan.totalQuota !== null ? h("span", { key: "quota", className: "mat-badge" }, formatQuota(plan.totalQuota, data.platform)) : null,
1204
+ h("span", { key: "reset", className: "mat-badge" }, resetLabel(t, plan)),
1205
+ plan.maxPurchasePerUser > 0 ? h("span", { key: "limit", className: "mat-badge" }, t("subscriptionPurchaseLimit", { count: plan.maxPurchasePerUser })) : null
1206
+ ]),
1207
+ plan.upgradeGroup ? h("span", { key: "group", className: "mat-hint" }, t("subscriptionUpgradeGroup", { group: plan.upgradeGroup })) : null
1208
+ ]);
1209
+ }));
1210
+ const methodChoices = methods.length > 0 ? h("div", { key: "methods", className: "mat-choice-row" }, methods.map((method) => {
1211
+ const type = String(method.type || "");
1212
+ return h("button", {
1213
+ key: type,
1214
+ type: "button",
1215
+ className: `mat-choice${paymentMethod === type ? " mat-choice-active" : ""}`,
1216
+ onClick: () => {
1217
+ setPaymentMethod(type);
1218
+ setPayment(null);
1219
+ setNotice("");
1220
+ },
1221
+ disabled: creating
1222
+ }, String(method.name || type));
1223
+ })) : null;
1224
+ const payForm = plans.length > 0 && methods.length > 0 ? h("form", { key: "pay", className: "mat-sub-pay", onSubmit: submit }, [
1225
+ h("div", { key: "method", className: "mat-field" }, [
1226
+ h("span", { key: "label", className: "mat-label" }, t("subscriptionPayment")),
1227
+ methodChoices
1228
+ ]),
1229
+ h("div", { key: "actions", className: "mat-sub-pay-actions" }, [
1230
+ selectedPlan ? h("span", { key: "selection", className: "mat-hint" }, t("subscriptionSelected", {
1231
+ title: selectedPlan.title,
1232
+ price: planPrice(selectedPlan, data.platform)
1233
+ })) : null,
1234
+ h("button", {
1235
+ key: "submit",
1236
+ type: "submit",
1237
+ className: "mat-btn mat-btn-primary",
1238
+ disabled: creating || !selectedPlanId || !paymentMethod
1239
+ }, creating ? t("subscriptionSubmitting") : t("subscriptionSubmit"))
1240
+ ])
1241
+ ]) : null;
1242
+ const paymentUnavailable = plans.length > 0 && methods.length === 0 ? h("div", { key: "no-methods", className: "mat-error", role: "alert", style: { marginTop: 10 } }, t("subscriptionNoMethods")) : null;
1243
+ return h("section", { className: "mat-card mat-subscription" }, [
1244
+ h("div", { key: "head", className: "mat-card-head" }, [
1245
+ h("div", { key: "copy", className: "mat-card-head-copy" }, [
1246
+ h("div", { key: "title", className: "mat-card-title" }, t("subscription")),
1247
+ h("div", { key: "hint", className: "mat-hint" }, t("subscriptionHint"))
1248
+ ]),
1249
+ h("button", {
1250
+ key: "refresh",
1251
+ type: "button",
1252
+ className: "mat-btn mat-btn-sm",
1253
+ onClick: () => void loadConfig(),
1254
+ disabled: loading || creating
1255
+ }, loading ? t("apiKeyRefreshing") : t("apiKeyRefresh"))
1256
+ ]),
1257
+ loading ? h("p", { key: "loading", className: "mat-hint" }, t("subscriptionLoading")) : config ? h(React.Fragment, null, [
1258
+ h("div", { key: "current-section", className: "mat-sub-section" }, [
1259
+ h("div", { key: "title", className: "mat-sub-section-title" }, t("subscriptionCurrent")),
1260
+ currentList
1261
+ ]),
1262
+ h("div", { key: "plans-section", className: "mat-sub-section" }, [
1263
+ h("div", { key: "title", className: "mat-sub-section-title" }, t("subscriptionPlans")),
1264
+ planList,
1265
+ paymentUnavailable,
1266
+ payForm
1267
+ ])
1268
+ ]) : null,
1269
+ error ? h("div", { key: "error", className: "mat-error", role: "alert", style: { marginTop: 12 } }, error) : null,
1270
+ notice ? h("div", { key: "notice", className: "mat-notice", role: "status", style: { marginTop: 12 } }, notice) : null,
1271
+ payment?.payUrl ? h("div", { key: "payment", className: "mat-pay-result" }, [
1272
+ payment.payMoney ? h("div", { key: "money", className: "mat-pay-line" }, [
1273
+ h("span", { key: "label" }, t("subscriptionPayMoney")),
1274
+ h("strong", { key: "value" }, `${paymentCurrency().symbol}${payment.payMoney}`)
1275
+ ]) : null,
1276
+ payment.outTradeNo ? h("div", { key: "order", className: "mat-pay-line" }, [
1277
+ h("span", { key: "label" }, t("topupOrderNo")),
1278
+ h("strong", { key: "value", className: "mat-mono" }, payment.outTradeNo)
1279
+ ]) : null,
1280
+ h("div", { key: "actions", className: "mat-pay-actions" }, h("a", {
1281
+ className: "mat-btn mat-btn-primary",
1282
+ href: payment.payUrl,
1283
+ target: "_blank",
1284
+ rel: "noopener noreferrer",
1285
+ referrerPolicy: "no-referrer"
1286
+ }, t("subscriptionOpenPayment")))
1287
+ ]) : null
1288
+ ]);
1289
+ };
1290
+ }
1291
+
1292
+ // src/client/topup-page.ts
1293
+ function createTopupPage({ React, h, t }) {
1294
+ return function TopupPage({ data }) {
1295
+ const [config, setConfig] = React.useState(null);
1296
+ const [loading, setLoading] = React.useState(true);
1297
+ const [error, setError] = React.useState("");
1298
+ const [notice, setNotice] = React.useState("");
1299
+ const [amount, setAmount] = React.useState("");
1300
+ const [paymentMethod, setPaymentMethod] = React.useState("");
1301
+ const [creating, setCreating] = React.useState(false);
1302
+ const [payment, setPayment] = React.useState(null);
1303
+ const methods = Array.isArray(config?.paymentMethods) ? config.paymentMethods : [];
1304
+ const amountOptions = Array.isArray(config?.amountOptions) ? config.amountOptions : [];
1305
+ const minTopup = Number(config?.minTopup) || 1;
1306
+ const unit = topupAmountCurrency();
1307
+ const payUnit = paymentCurrency();
1308
+ async function loadConfig() {
1309
+ setLoading(true);
1310
+ setError("");
1311
+ try {
1312
+ const response = await fetch(TOPUP_PATH, { method: "GET", cache: "no-store" });
1313
+ let payload;
1314
+ try {
1315
+ payload = await response.json();
1316
+ } catch {
1317
+ throw new Error(t("invalidResponse"));
1318
+ }
1319
+ if (!response.ok || !payload?.ok || !payload.data) {
1320
+ throw new Error(payload?.error?.message || t("topupLoadFailed"));
1321
+ }
1322
+ const next = payload.data;
1323
+ const nextMethods = Array.isArray(next.paymentMethods) ? next.paymentMethods : [];
1324
+ const nextAmounts = Array.isArray(next.amountOptions) ? next.amountOptions : [];
1325
+ const nextMin = Number(next.minTopup) || 1;
1326
+ setConfig(next);
1327
+ setAmount(String(nextAmounts[0] || nextMin));
1328
+ setPaymentMethod(String(nextMethods[0]?.type || ""));
1329
+ } catch (failure) {
1330
+ setError(failure instanceof Error && failure.message ? failure.message : t("topupLoadFailed"));
1331
+ } finally {
1332
+ setLoading(false);
1333
+ }
1334
+ }
1335
+ React.useEffect(() => {
1336
+ void loadConfig();
1337
+ }, [data.baseUrl]);
1338
+ React.useEffect(() => {
1339
+ if (!payment?.payUrl || typeof document === "undefined") return;
1340
+ const node = document.querySelector(".mat-pay-inline");
1341
+ node?.scrollIntoView?.({ block: "nearest", behavior: "smooth" });
1342
+ }, [payment?.payUrl]);
1343
+ async function submit(event) {
1344
+ event?.preventDefault?.();
1345
+ if (creating || !config) return;
1346
+ const value = Number(amount);
1347
+ if (!Number.isSafeInteger(value) || value <= 0) {
1348
+ setError(t("topupAmountInvalid"));
1349
+ return;
1350
+ }
1351
+ if (value < minTopup) {
1352
+ setError(t("topupAmountTooSmall", { amount: `${unit.symbol}${formatNumber(minTopup)}` }));
1353
+ return;
1354
+ }
1355
+ if (!paymentMethod || !methods.some((method) => method.type === paymentMethod)) {
1356
+ setError(t("topupNoMethods"));
1357
+ return;
1358
+ }
1359
+ setCreating(true);
1360
+ setError("");
1361
+ setNotice("");
1362
+ setPayment(null);
1363
+ try {
1364
+ const response = await fetch(TOPUP_PATH, {
1365
+ method: "POST",
1366
+ headers: { "content-type": "application/json" },
1367
+ body: JSON.stringify({ amount: value, paymentMethod })
1368
+ });
1369
+ let payload;
1370
+ try {
1371
+ payload = await response.json();
1372
+ } catch {
1373
+ throw new Error(t("invalidResponse"));
1374
+ }
1375
+ if (!response.ok || !payload?.ok || !payload.data?.payUrl) {
1376
+ throw new Error(payload?.error?.message || t("topupCreateFailed"));
1377
+ }
1378
+ setPayment(payload.data);
1379
+ setNotice(t("topupCreated"));
1380
+ } catch (failure) {
1381
+ setError(failure instanceof Error && failure.message ? failure.message : t("topupCreateFailed"));
1382
+ } finally {
1383
+ setCreating(false);
1384
+ }
1385
+ }
1386
+ function restart() {
1387
+ setPayment(null);
1388
+ setError("");
1389
+ setNotice("");
1390
+ }
1391
+ const form = config?.onlineTopupEnabled && methods.length > 0 ? h("form", { key: "form", className: "mat-topup-grid", onSubmit: submit }, [
1392
+ h("label", { key: "amount-field", className: "mat-field" }, [
1393
+ h("span", { key: "label", className: "mat-label" }, t("topupAmount")),
1394
+ h("input", {
1395
+ key: "input",
1396
+ className: "mat-input",
1397
+ type: "number",
1398
+ min: minTopup,
1399
+ step: 1,
1400
+ value: amount,
1401
+ onChange: (event) => {
1402
+ setAmount(event.target.value);
1403
+ setPayment(null);
1404
+ setNotice("");
1405
+ },
1406
+ placeholder: t("topupAmountPlaceholder"),
1407
+ disabled: creating,
1408
+ required: true
1409
+ }),
1410
+ amountOptions.length > 0 ? h("div", { key: "amounts", className: "mat-choice-row" }, amountOptions.map((option) => {
1411
+ const selected = Number(amount) === Number(option);
1412
+ return h("button", {
1413
+ key: String(option),
1414
+ type: "button",
1415
+ className: `mat-choice${selected ? " mat-choice-active" : ""}`,
1416
+ onClick: () => {
1417
+ setAmount(String(option));
1418
+ setPayment(null);
1419
+ setNotice("");
1420
+ },
1421
+ disabled: creating
1422
+ }, `${unit.symbol}${formatNumber(option)}`);
1423
+ })) : null,
1424
+ h("span", { key: "hint", className: "mat-hint" }, t("topupMinAmount", {
1425
+ amount: `${unit.symbol}${formatNumber(minTopup)}`
1426
+ }))
1427
+ ]),
1428
+ h("div", { key: "method-field", className: "mat-field" }, [
1429
+ h("span", { key: "label", className: "mat-label" }, t("topupPayment")),
1430
+ h("div", { key: "methods", className: "mat-choice-row" }, methods.map((method) => {
1431
+ const type = String(method.type || "");
1432
+ const selected = paymentMethod === type;
1433
+ return h("button", {
1434
+ key: type,
1435
+ type: "button",
1436
+ className: `mat-choice${selected ? " mat-choice-active" : ""}`,
1437
+ onClick: () => setPaymentMethod(type),
1438
+ disabled: creating
1439
+ }, String(method.name || type));
1440
+ }))
1441
+ ]),
1442
+ h("div", { key: "actions", className: "mat-actions", style: { gridColumn: "1/-1" } }, h("button", {
1443
+ type: "submit",
1444
+ className: "mat-btn mat-btn-primary",
1445
+ disabled: creating
1446
+ }, creating ? t("topupSubmitting") : t("topupSubmit")))
1447
+ ]) : null;
1448
+ const paidMoney = payment?.payMoney ? `${payUnit.symbol}${payment.payMoney}` : "";
1449
+ const paymentPanel = payment?.payUrl ? h("div", { key: "payment", className: "mat-topup-pay mat-pay-inline" }, [
1450
+ h("div", { key: "money", className: "mat-pay-line" }, [
1451
+ h("span", { key: "label" }, paidMoney ? t("topupPayMoney") : t("topupAmount")),
1452
+ h("strong", { key: "value" }, paidMoney || `${unit.symbol}${formatNumber(payment.amount || amount)}`)
1453
+ ]),
1454
+ payment.outTradeNo ? h("div", { key: "order", className: "mat-pay-line" }, [
1455
+ h("span", { key: "label" }, t("topupOrderNo")),
1456
+ h("strong", { key: "value", className: "mat-mono" }, payment.outTradeNo)
1457
+ ]) : null,
1458
+ h("div", { key: "actions", className: "mat-pay-actions" }, [
1459
+ h("button", { key: "again", type: "button", className: "mat-btn", onClick: restart }, t("topupAgain")),
1460
+ h("a", {
1461
+ key: "open",
1462
+ className: "mat-btn mat-btn-primary",
1463
+ href: payment.payUrl,
1464
+ target: "_blank",
1465
+ rel: "noopener noreferrer",
1466
+ referrerPolicy: "no-referrer"
1467
+ }, t("topupOpenPayment"))
1468
+ ])
1469
+ ]) : null;
1470
+ return h("section", { className: "mat-card mat-topup" }, [
1471
+ h("div", { key: "head", className: "mat-card-head" }, [
1472
+ h("div", { key: "copy", className: "mat-card-head-copy" }, [
1473
+ h("div", { key: "title", className: "mat-card-title" }, t("topup")),
1474
+ h("div", { key: "hint", className: "mat-hint" }, t("topupHint"))
1475
+ ]),
1476
+ h("button", {
1477
+ key: "refresh",
1478
+ type: "button",
1479
+ className: "mat-btn mat-btn-sm",
1480
+ onClick: () => void loadConfig(),
1481
+ disabled: loading || creating
1482
+ }, loading ? t("apiKeyRefreshing") : t("apiKeyRefresh"))
1483
+ ]),
1484
+ loading ? h("p", { key: "loading", className: "mat-hint" }, t("topupLoading")) : config ? h(React.Fragment, null, [
1485
+ h("div", { key: "status", className: "mat-topup-status" }, [
1486
+ h("span", {
1487
+ key: "online",
1488
+ className: `mat-badge ${config.onlineTopupEnabled ? "mat-badge-ok" : "mat-badge-warn"}`
1489
+ }, config.onlineTopupEnabled ? t("topupOnline") : t("topupOffline"))
1490
+ ]),
1491
+ !config.onlineTopupEnabled ? h("div", { key: "offline", className: "mat-error", role: "alert" }, t("topupUnavailable")) : methods.length === 0 ? h("div", { key: "no-methods", className: "mat-error", role: "alert" }, t("topupNoMethods")) : paymentPanel || form
1492
+ ]) : null,
1493
+ error ? h("div", { key: "error", className: "mat-error", role: "alert", style: { marginTop: 12 } }, error) : null,
1494
+ notice ? h("div", { key: "notice", className: "mat-notice", role: "status", style: { marginTop: 12 } }, notice) : null
1495
+ ]);
1496
+ };
1497
+ }
1498
+
1499
+ // src/client/dashboard.ts
1500
+ function createDashboard(runtime) {
1501
+ const { React, h, t } = runtime;
1502
+ const Header = createHeader(runtime);
1503
+ const LoginForm = createLoginForm(runtime);
1504
+ const OverviewPage = createOverviewPage(runtime);
1505
+ const SubscriptionPage = createSubscriptionPage(runtime);
1506
+ const ModelsPage = createModelsPage(runtime);
1507
+ const ApiKeysPage = createApiKeysPage(runtime);
1508
+ const TopupPage = createTopupPage(runtime);
1509
+ return function Dashboard() {
1510
+ const [baseUrl, setBaseUrl] = React.useState(DEFAULT_BASE_URL);
1511
+ const [token, setToken] = React.useState("");
1512
+ const [showToken, setShowToken] = React.useState(false);
1513
+ const [status, setStatus] = React.useState("restoring");
1514
+ const [data, setData] = React.useState(null);
1515
+ const [error, setError] = React.useState("");
1516
+ const [notice, setNotice] = React.useState("");
1517
+ const [persisted, setPersisted] = React.useState(false);
1518
+ const [view, setView] = React.useState("overview");
1519
+ const pending = status === "pending";
1520
+ async function fetchSession() {
1521
+ const response = await fetch(SESSION_PATH, { method: "GET", cache: "no-store" });
1522
+ let payload;
1523
+ try {
1524
+ payload = await response.json();
1525
+ } catch {
1526
+ throw new Error(t("invalidResponse"));
1527
+ }
1528
+ return { response, payload };
1529
+ }
1530
+ function acceptSession(payload) {
1531
+ const value = payload?.data;
1532
+ if (!value?.authenticated) return false;
1533
+ setBaseUrl(value.baseUrl || DEFAULT_BASE_URL);
1534
+ setData(value);
1535
+ setPersisted(value.persisted !== false);
1536
+ setError("");
1537
+ setNotice("");
1538
+ setStatus("ready");
1539
+ return true;
1540
+ }
1541
+ React.useEffect(() => {
1542
+ let cancelled = false;
1543
+ (async () => {
1544
+ try {
1545
+ const { response, payload } = await fetchSession();
1546
+ if (cancelled) return;
1547
+ if (acceptSession(payload)) return;
1548
+ if (payload?.data?.baseUrl) setBaseUrl(payload.data.baseUrl);
1549
+ if (payload?.data?.savedLoginInvalid) {
1550
+ setError(t("savedLoginExpired"));
1551
+ } else if (!response.ok) {
1552
+ setError(payload?.error?.message || t("restoreFailed"));
1553
+ }
1554
+ setStatus("idle");
1555
+ } catch {
1556
+ if (!cancelled) {
1557
+ setError(t("restoreFailed"));
1558
+ setStatus("idle");
1559
+ }
1560
+ }
1561
+ })();
1562
+ return () => {
1563
+ cancelled = true;
1564
+ };
1565
+ }, []);
1566
+ async function query(event) {
1567
+ event?.preventDefault?.();
1568
+ if (pending) return;
1569
+ if (!token.trim()) {
1570
+ setError(t("tokenRequired"));
1571
+ return;
1572
+ }
1573
+ setStatus("pending");
1574
+ setError("");
1575
+ setNotice("");
1576
+ try {
1577
+ const response = await fetch(QUERY_PATH, {
1578
+ method: "POST",
1579
+ headers: { "content-type": "application/json" },
1580
+ body: JSON.stringify({ baseUrl, accessToken: token })
1581
+ });
1582
+ let payload;
1583
+ try {
1584
+ payload = await response.json();
1585
+ } catch {
1586
+ throw new Error(t("invalidResponse"));
1587
+ }
1588
+ if (!response.ok || !payload?.ok || !payload.data) {
1589
+ throw new Error(payload?.error?.message || t("requestFailed"));
1590
+ }
1591
+ setBaseUrl(payload.data.baseUrl || baseUrl);
1592
+ setData(payload.data);
1593
+ setPersisted(payload.data.persisted === true);
1594
+ if (payload.data.persisted) {
1595
+ setToken("");
1596
+ setShowToken(false);
1597
+ } else {
1598
+ setNotice(t("notPersisted"));
1599
+ }
1600
+ setStatus("ready");
1601
+ setView("overview");
1602
+ } catch (failure) {
1603
+ setError(failure instanceof Error && failure.message ? failure.message : t("requestFailed"));
1604
+ setStatus(data ? "ready" : "idle");
1605
+ }
1606
+ }
1607
+ async function refresh(event) {
1608
+ event?.preventDefault?.();
1609
+ if (pending) return;
1610
+ if (token.trim()) return query(event);
1611
+ setStatus("pending");
1612
+ setError("");
1613
+ setNotice("");
1614
+ try {
1615
+ const { response, payload } = await fetchSession();
1616
+ if (acceptSession(payload)) return;
1617
+ if (payload?.data?.baseUrl) setBaseUrl(payload.data.baseUrl);
1618
+ if (payload?.data?.savedLoginInvalid) {
1619
+ setData(null);
1620
+ setPersisted(false);
1621
+ setStatus("idle");
1622
+ setError(t("savedLoginExpired"));
1623
+ return;
1624
+ }
1625
+ throw new Error(!response.ok ? payload?.error?.message || t("restoreFailed") : t("restoreFailed"));
1626
+ } catch (failure) {
1627
+ setError(failure instanceof Error && failure.message ? failure.message : t("restoreFailed"));
1628
+ setStatus(data ? "ready" : "idle");
1629
+ }
1630
+ }
1631
+ async function logout(event) {
1632
+ event?.preventDefault?.();
1633
+ if (pending) return;
1634
+ setStatus("pending");
1635
+ try {
1636
+ await fetch(SESSION_PATH, { method: "DELETE", cache: "no-store" });
1637
+ } catch {
1638
+ }
1639
+ setToken("");
1640
+ setShowToken(false);
1641
+ setData(null);
1642
+ setError("");
1643
+ setNotice("");
1644
+ setPersisted(false);
1645
+ setView("overview");
1646
+ setStatus("idle");
1647
+ }
1648
+ return h(React.Fragment, null, [
1649
+ h("style", { key: "style" }, PANEL_CSS),
1650
+ h("div", { key: "panel", className: "mat-root" }, [
1651
+ h(Header, { key: "header" }),
1652
+ status === "restoring" && !data ? h("div", { key: "restoring", className: "mat-card mat-login" }, h("p", { className: "mat-hint" }, t("restoringLogin"))) : data ? h(React.Fragment, { key: "result" }, [
1653
+ h("div", { key: "bar", className: "mat-topbar" }, [
1654
+ h("div", { key: "name", className: "mat-topbar-title" }, [
1655
+ h("h3", { key: "title", className: "mat-platform-name" }, data.platform.system_name || baseUrl),
1656
+ h("div", { key: "url", className: "mat-subtle mat-mono" }, data.baseUrl)
1657
+ ]),
1658
+ persisted ? h("span", { key: "saved", className: "mat-badge mat-badge-ok" }, t("savedLogin")) : null,
1659
+ h(
1660
+ "button",
1661
+ { key: "refresh", type: "button", className: "mat-btn", disabled: pending, onClick: refresh },
1662
+ pending ? t("refreshing") : t("refresh")
1663
+ ),
1664
+ h("button", { key: "logout", type: "button", className: "mat-btn", disabled: pending, onClick: logout }, t("logout"))
1665
+ ]),
1666
+ h("div", { key: "tabs", className: "mat-page-tabs", role: "tablist", "aria-label": t("title") }, [
1667
+ h("button", {
1668
+ key: "overview",
1669
+ type: "button",
1670
+ role: "tab",
1671
+ "aria-selected": view === "overview",
1672
+ className: `mat-page-tab${view === "overview" ? " mat-page-tab-active" : ""}`,
1673
+ onClick: () => setView("overview")
1674
+ }, t("overviewPage")),
1675
+ h("button", {
1676
+ key: "subscription",
1677
+ type: "button",
1678
+ role: "tab",
1679
+ "aria-selected": view === "subscription",
1680
+ className: `mat-page-tab${view === "subscription" ? " mat-page-tab-active" : ""}`,
1681
+ onClick: () => setView("subscription")
1682
+ }, t("subscription")),
1683
+ h("button", {
1684
+ key: "models",
1685
+ type: "button",
1686
+ role: "tab",
1687
+ "aria-selected": view === "models",
1688
+ className: `mat-page-tab${view === "models" ? " mat-page-tab-active" : ""}`,
1689
+ onClick: () => setView("models")
1690
+ }, t("modelsPage")),
1691
+ h("button", {
1692
+ key: "api-keys",
1693
+ type: "button",
1694
+ role: "tab",
1695
+ "aria-selected": view === "apiKeys",
1696
+ className: `mat-page-tab${view === "apiKeys" ? " mat-page-tab-active" : ""}`,
1697
+ onClick: () => setView("apiKeys")
1698
+ }, t("apiKeys"))
1699
+ ]),
1700
+ error ? h("div", { key: "error", className: "mat-error", role: "alert", style: { marginBottom: 12 } }, error) : null,
1701
+ notice ? h("div", { key: "notice", className: "mat-notice", role: "status", style: { marginBottom: 12 } }, notice) : null,
1702
+ view === "overview" ? h("div", { key: "overview", className: "mat-overview-stack" }, [
1703
+ h(OverviewPage, { key: "overview-card", data }),
1704
+ h(TopupPage, { key: "topup-card", data })
1705
+ ]) : view === "models" ? h(ModelsPage, { key: "models", data }) : view === "subscription" ? h(SubscriptionPage, { key: "subscription", data }) : view === "apiKeys" ? h(ApiKeysPage, { key: "api-keys", data }) : null
1706
+ ]) : h(LoginForm, {
1707
+ key: "login",
1708
+ baseUrl,
1709
+ setBaseUrl,
1710
+ token,
1711
+ setToken,
1712
+ showToken,
1713
+ setShowToken,
1714
+ pending,
1715
+ error,
1716
+ onSubmit: query
1717
+ })
1718
+ ])
1719
+ ]);
1720
+ };
1721
+ }
1722
+
1723
+ // src/client/dictionaries.ts
1724
+ var zh = {
1725
+ sidebarLabel: "MetaOntic\u6A21\u578B\u4E2D\u8F6C\u52A9\u624B",
1726
+ title: "MetaOntic\u6A21\u578B\u4E2D\u8F6C\u52A9\u624B",
1727
+ intro: "MetaOntic AI \u662F\u591A\u6A21\u578B\u805A\u5408\u5E73\u53F0\uFF0C\u63D0\u4F9B\u7A33\u5B9A\u53EF\u9760\u7684\u6A21\u578B\u670D\u52A1\u3002",
1728
+ baseUrl: "\u5E73\u53F0\u5730\u5740",
1729
+ accessToken: "\u8BBF\u95EE\u4EE4\u724C",
1730
+ accessTokenPlaceholder: "\u8BF7\u8F93\u5165\u8BBF\u95EE\u4EE4\u724C",
1731
+ accessTokenHint: "\u4EE4\u724C\u7531\u7528\u6237\u5728 MetaOntic AI \u63A7\u5236\u53F0\u521B\u5EFA\uFF0C\u4EC5\u7528\u4E8E\u672C\u6B21\u67E5\u8BE2\u3002",
1732
+ tokenPrivacy: "\u767B\u5F55\u6210\u529F\u540E\uFF0C\u8BBF\u95EE\u4EE4\u724C\u7531 Host \u4FDD\u5B58\u5728\u672C\u673A profile \u7684\u79C1\u6709\u6587\u4EF6\u4E2D\uFF0C\u6D4F\u89C8\u5668\u4E0D\u4FDD\u5B58\u4EE4\u724C\u3002",
1733
+ login: "\u8BBF\u95EE\u4EE4\u724C\u767B\u5F55",
1734
+ loginPending: "\u6B63\u5728\u9A8C\u8BC1\u8BBF\u95EE\u4EE4\u724C\u2026",
1735
+ registerPrompt: "\u8FD8\u6CA1\u6709\u8BBF\u95EE\u4EE4\u724C\uFF1F",
1736
+ registerNow: "\u6CE8\u518C\u8D26\u53F7",
1737
+ restoringLogin: "\u6B63\u5728\u6062\u590D\u672C\u673A\u767B\u5F55\u2026",
1738
+ savedLogin: "\u767B\u5F55\u4FE1\u606F\u5DF2\u4FDD\u5B58\u5230\u672C\u673A",
1739
+ notPersisted: "\u767B\u5F55\u6210\u529F\uFF0C\u4F46\u767B\u5F55\u4FE1\u606F\u672A\u80FD\u4FDD\u5B58\u5230\u672C\u673A\u3002",
1740
+ savedLoginExpired: "\u4FDD\u5B58\u7684\u8BBF\u95EE\u4EE4\u724C\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002",
1741
+ restoreFailed: "\u65E0\u6CD5\u6062\u590D\u672C\u673A\u767B\u5F55\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002",
1742
+ showToken: "\u663E\u793A\u4EE4\u724C",
1743
+ hideToken: "\u9690\u85CF\u4EE4\u724C",
1744
+ logout: "\u9000\u51FA\u767B\u5F55",
1745
+ refresh: "\u5237\u65B0\u67E5\u8BE2",
1746
+ refreshing: "\u6B63\u5728\u5237\u65B0\u2026",
1747
+ tokenRequired: "\u8BF7\u586B\u5199\u8BBF\u95EE\u4EE4\u724C\u3002",
1748
+ requestFailed: "\u67E5\u8BE2\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
1749
+ invalidResponse: "\u5E73\u53F0\u8FD4\u56DE\u4E86\u65E0\u6CD5\u8BC6\u522B\u7684\u6570\u636E\u3002",
1750
+ account: "\u8D26\u6237\u4FE1\u606F",
1751
+ platform: "\u5E73\u53F0\u4FE1\u606F",
1752
+ accountPlatform: "\u8D26\u6237\u4E0E\u5E73\u53F0",
1753
+ balance: "\u53EF\u7528\u4F59\u989D",
1754
+ usedQuota: "\u5DF2\u7528\u989D\u5EA6",
1755
+ requests: "\u8BF7\u6C42\u6B21\u6570",
1756
+ usageRatio: "\u989D\u5EA6\u5269\u4F59\u60C5\u51B5",
1757
+ usageRemainingPercent: "\u5269\u4F59 {percent}%",
1758
+ username: "\u7528\u6237\u540D",
1759
+ displayName: "\u663E\u793A\u540D\u79F0",
1760
+ group: "\u7528\u6237\u5206\u7EC4",
1761
+ role: "\u8D26\u6237\u89D2\u8272",
1762
+ accountId: "\u7528\u6237 ID",
1763
+ accountStatus: "\u8D26\u6237\u72B6\u6001",
1764
+ systemName: "\u5E73\u53F0\u540D\u79F0",
1765
+ version: "\u5E73\u53F0\u7248\u672C",
1766
+ serverAddress: "\u670D\u52A1\u5730\u5740",
1767
+ currency: "\u7ED3\u7B97\u5E01\u79CD",
1768
+ fetchedAt: "\u67E5\u8BE2\u65F6\u95F4",
1769
+ rawQuota: "\u4F59\u989D {quota} \xB7 \u7D2F\u8BA1\u5DF2\u7528 {used}",
1770
+ overviewPage: "\u6982\u51B5\u4E0E\u5145\u503C",
1771
+ modelsPage: "\u6A21\u578B\u5E7F\u573A",
1772
+ modelsHint: "\u67E5\u770B\u5E73\u53F0\u5F53\u524D\u53EF\u7528\u6A21\u578B\u3001\u652F\u6301\u5206\u7EC4\u4E0E\u8BA1\u8D39\u4FE1\u606F\u3002",
1773
+ modelsLoading: "\u6B63\u5728\u52A0\u8F7D\u6A21\u578B\u2026",
1774
+ modelsRefresh: "\u5237\u65B0",
1775
+ modelsSearch: "\u641C\u7D22\u6A21\u578B",
1776
+ modelsSearchPlaceholder: "\u6A21\u578B\u540D\u79F0\u3001\u6807\u7B7E\u6216\u8BF4\u660E",
1777
+ modelsGroupFilter: "\u5206\u7EC4",
1778
+ modelsAllGroups: "\u5168\u90E8\u5206\u7EC4",
1779
+ modelsCount: "\u5171 {count} \u4E2A\u6A21\u578B",
1780
+ modelsEmpty: "\u6CA1\u6709\u5339\u914D\u7684\u6A21\u578B\u3002",
1781
+ modelsLoadFailed: "\u6A21\u578B\u5217\u8868\u52A0\u8F7D\u5931\u8D25\u3002",
1782
+ modelsRatio: "\u500D\u7387 {ratio}",
1783
+ modelsPrice: "\u4EF7\u683C {price}",
1784
+ modelsTags: "\u6807\u7B7E",
1785
+ modelsGroups: "\u53EF\u7528\u5206\u7EC4",
1786
+ modelsEndpoints: "\u63A5\u53E3",
1787
+ apiKeys: "API Key \u7BA1\u7406",
1788
+ apiKeysHint: "\u4E3A\u5E94\u7528\u521B\u5EFA\u548C\u7BA1\u7406\u8BBF\u95EE\u5BC6\u94A5\u3002\u5B8C\u6574\u5BC6\u94A5\u4EC5\u5728\u70B9\u51FB\u663E\u793A\u65F6\u8BFB\u53D6\uFF0C\u4E0D\u4F1A\u968F\u5217\u8868\u4E0B\u53D1\u3002",
1789
+ apiKeyListTitle: "Key \u5217\u8868\uFF08{count}\uFF09",
1790
+ apiKeyRefresh: "\u5237\u65B0",
1791
+ apiKeyRefreshing: "\u6B63\u5728\u5237\u65B0\u2026",
1792
+ apiKeyNew: "\u65B0\u5EFA API Key",
1793
+ apiKeyCreateHint: "\u521B\u5EFA\u540E\u53EA\u663E\u793A\u4E00\u6B21\u5B8C\u6574\u5BC6\u94A5\uFF0C\u8BF7\u53CA\u65F6\u4FDD\u5B58\u3002",
1794
+ apiKeyCreate: "\u521B\u5EFA",
1795
+ apiKeyCreating: "\u6B63\u5728\u521B\u5EFA\u2026",
1796
+ apiKeyCancel: "\u53D6\u6D88",
1797
+ apiKeyName: "\u540D\u79F0",
1798
+ apiKeyNamePlaceholder: "\u4F8B\u5982 dsh-desktop",
1799
+ apiKeyGroup: "\u5206\u7EC4",
1800
+ apiKeyGroupHint: "\u9009\u62E9\u8BE5 Key \u53EF\u4F7F\u7528\u7684\u6A21\u578B\u5206\u7EC4\u3002",
1801
+ apiKeyUnlimited: "\u65E0\u9650\u989D\u5EA6",
1802
+ apiKeyQuota: "\u989D\u5EA6",
1803
+ apiKeyQuotaPlaceholder: "\u4F8B\u5982 10",
1804
+ apiKeyQuotaHint: "\u6309\u5E73\u53F0\u5F53\u524D\u7ED3\u7B97\u5E01\u79CD\u586B\u5199\u3002",
1805
+ apiKeyExpiryDays: "\u6709\u6548\u671F\uFF08\u5929\uFF09",
1806
+ apiKeyNeverExpiresHint: "\u586B 0 \u8868\u793A\u6C38\u4E0D\u8FC7\u671F\u3002",
1807
+ apiKeyNone: "\u6682\u65E0 API Key\uFF0C\u70B9\u51FB\u201C\u65B0\u5EFA API Key\u201D\u521B\u5EFA\u3002",
1808
+ apiKeyHidden: "\u70B9\u51FB\u201C\u663E\u793A\u5BC6\u94A5\u201D\u67E5\u770B",
1809
+ apiKeyShow: "\u663E\u793A\u5BC6\u94A5",
1810
+ apiKeyHide: "\u9690\u85CF\u5BC6\u94A5",
1811
+ apiKeyCopy: "\u590D\u5236",
1812
+ apiKeyCopied: "API Key \u5DF2\u590D\u5236\u3002",
1813
+ apiKeyCopyUnavailable: "\u65E0\u6CD5\u8BBF\u95EE\u526A\u8D34\u677F\uFF0C\u8BF7\u624B\u52A8\u9009\u62E9\u5E76\u590D\u5236\u5BC6\u94A5\u3002",
1814
+ apiKeyCreated: "API Key \u5DF2\u521B\u5EFA\uFF0C\u8BF7\u663E\u793A\u5E76\u59A5\u5584\u4FDD\u5B58\u5BC6\u94A5\u3002",
1815
+ apiKeyDeleted: "API Key \u5DF2\u5220\u9664\u3002",
1816
+ apiKeyEnabledNotice: "API Key \u5DF2\u542F\u7528\u3002",
1817
+ apiKeyDisabledNotice: "API Key \u5DF2\u7981\u7528\u3002",
1818
+ apiKeyDeleteConfirm: "\u786E\u5B9A\u5220\u9664 API Key\u201C{name}\u201D\u5417\uFF1F\u6B64\u64CD\u4F5C\u4E0D\u53EF\u64A4\u9500\u3002",
1819
+ apiKeyDelete: "\u5220\u9664",
1820
+ apiKeyEnable: "\u542F\u7528",
1821
+ apiKeyDisable: "\u7981\u7528",
1822
+ apiKeyStatusEnabled: "\u5DF2\u542F\u7528",
1823
+ apiKeyStatusDisabled: "\u5DF2\u7981\u7528",
1824
+ apiKeyStatusExpired: "\u5DF2\u8FC7\u671F",
1825
+ apiKeyStatusExhausted: "\u989D\u5EA6\u7528\u5C3D",
1826
+ apiKeyStatusUnknown: "\u672A\u77E5\u72B6\u6001",
1827
+ apiKeyQuotaLabel: "\u5269\u4F59\u989D\u5EA6",
1828
+ apiKeyUsedLabel: "\u5DF2\u7528\u989D\u5EA6",
1829
+ apiKeyExpires: "\u8FC7\u671F\u65F6\u95F4",
1830
+ apiKeyCreatedAt: "\u521B\u5EFA\u65F6\u95F4",
1831
+ neverExpires: "\u6C38\u4E0D\u8FC7\u671F",
1832
+ unlimited: "\u65E0\u9650",
1833
+ apiKeyLoadFailed: "API Key \u5217\u8868\u52A0\u8F7D\u5931\u8D25\u3002",
1834
+ apiKeyActionFailed: "API Key \u64CD\u4F5C\u5931\u8D25\u3002",
1835
+ apiKeyRevealFailed: "\u8BFB\u53D6 API Key \u5931\u8D25\u3002",
1836
+ apiKeyNameRequired: "\u8BF7\u586B\u5199 API Key \u540D\u79F0\u3002",
1837
+ apiKeyQuotaInvalid: "\u989D\u5EA6\u683C\u5F0F\u65E0\u6548\u3002",
1838
+ apiKeyExpiryInvalid: "\u6709\u6548\u671F\u683C\u5F0F\u65E0\u6548\u3002",
1839
+ topup: "\u5145\u503C",
1840
+ topupHint: "\u9009\u62E9\u5145\u503C\u91D1\u989D\u548C\u652F\u4ED8\u65B9\u5F0F\uFF0C\u7531\u5E73\u53F0\u751F\u6210\u652F\u4ED8\u94FE\u63A5\u3002\u5230\u8D26\u72B6\u6001\u4EE5\u5E73\u53F0\u4E3A\u51C6\u3002",
1841
+ topupLoading: "\u6B63\u5728\u52A0\u8F7D\u5145\u503C\u914D\u7F6E\u2026",
1842
+ topupOnline: "\u5728\u7EBF\u5145\u503C\u5DF2\u5F00\u542F",
1843
+ topupOffline: "\u5728\u7EBF\u5145\u503C\u672A\u5F00\u542F",
1844
+ topupUnavailable: "\u5E73\u53F0\u6682\u672A\u5F00\u542F\u5728\u7EBF\u5145\u503C\u3002",
1845
+ topupNoMethods: "\u5E73\u53F0\u6682\u672A\u914D\u7F6E\u53EF\u7528\u7684\u652F\u4ED8\u65B9\u5F0F\u3002",
1846
+ topupAmount: "\u5145\u503C\u91D1\u989D\uFF08USD\uFF09",
1847
+ topupAmountPlaceholder: "\u8BF7\u8F93\u5165\u5145\u503C\u91D1\u989D",
1848
+ topupMinAmount: "\u6700\u4F4E\u5145\u503C {amount}",
1849
+ topupPayment: "\u652F\u4ED8\u65B9\u5F0F",
1850
+ topupSubmit: "\u53D1\u8D77\u5145\u503C",
1851
+ topupSubmitting: "\u6B63\u5728\u751F\u6210\u652F\u4ED8\u94FE\u63A5\u2026",
1852
+ topupCreated: "\u652F\u4ED8\u94FE\u63A5\u5DF2\u751F\u6210\uFF0C\u8BF7\u524D\u5F80\u652F\u4ED8\u9875\u9762\u5B8C\u6210\u5145\u503C\u3002",
1853
+ topupPayMoney: "\u5B9E\u4ED8\u91D1\u989D\uFF08CNY\uFF09",
1854
+ topupOrderNo: "\u8BA2\u5355\u53F7",
1855
+ topupOpenPayment: "\u524D\u5F80\u652F\u4ED8",
1856
+ topupAgain: "\u91CD\u65B0\u5145\u503C",
1857
+ topupAmountInvalid: "\u5145\u503C\u91D1\u989D\u5FC5\u987B\u662F\u6709\u6548\u7684\u6B63\u6574\u6570\u3002",
1858
+ topupAmountTooSmall: "\u5145\u503C\u91D1\u989D\u4E0D\u80FD\u4F4E\u4E8E {amount}\u3002",
1859
+ topupLoadFailed: "\u5145\u503C\u914D\u7F6E\u52A0\u8F7D\u5931\u8D25\u3002",
1860
+ topupCreateFailed: "\u5145\u503C\u4E0B\u5355\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
1861
+ subscription: "\u8BA2\u9605",
1862
+ subscriptionHint: "\u67E5\u770B\u5F53\u524D\u5957\u9910\u5E76\u8D2D\u4E70\u8BA2\u9605\u3002\u652F\u4ED8\u7531\u5E73\u53F0\u751F\u6210\u7B7E\u540D\u94FE\u63A5\uFF0C\u6743\u76CA\u5230\u8D26\u4EE5\u5E73\u53F0\u4E3A\u51C6\u3002",
1863
+ subscriptionLoading: "\u6B63\u5728\u52A0\u8F7D\u8BA2\u9605\u4FE1\u606F\u2026",
1864
+ subscriptionCurrent: "\u5F53\u524D\u8BA2\u9605",
1865
+ subscriptionNone: "\u5F53\u524D\u6CA1\u6709\u6709\u6548\u8BA2\u9605\u3002",
1866
+ subscriptionPlans: "\u8BA2\u9605\u5957\u9910",
1867
+ subscriptionNoPlans: "\u5E73\u53F0\u6682\u672A\u63D0\u4F9B\u53EF\u8D2D\u4E70\u7684\u8BA2\u9605\u5957\u9910\u3002",
1868
+ subscriptionPayment: "\u652F\u4ED8\u65B9\u5F0F",
1869
+ subscriptionSubmit: "\u8BA2\u9605\u5E76\u652F\u4ED8",
1870
+ subscriptionSubmitting: "\u6B63\u5728\u751F\u6210\u652F\u4ED8\u94FE\u63A5\u2026",
1871
+ subscriptionPaymentCreated: "\u8BA2\u9605\u652F\u4ED8\u94FE\u63A5\u5DF2\u751F\u6210\uFF0C\u8BF7\u524D\u5F80\u652F\u4ED8\u9875\u9762\u5B8C\u6210\u8D2D\u4E70\u3002",
1872
+ subscriptionPayMoney: "\u5B9E\u4ED8\u91D1\u989D\uFF08CNY\uFF09",
1873
+ subscriptionOpenPayment: "\u524D\u5F80\u652F\u4ED8",
1874
+ subscriptionSelectRequired: "\u8BF7\u9009\u62E9\u8BA2\u9605\u5957\u9910\u548C\u652F\u4ED8\u65B9\u5F0F\u3002",
1875
+ subscriptionLoadFailed: "\u8BA2\u9605\u4FE1\u606F\u52A0\u8F7D\u5931\u8D25\u3002",
1876
+ subscriptionCreateFailed: "\u8BA2\u9605\u4E0B\u5355\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
1877
+ subscriptionStatusActive: "\u751F\u6548\u4E2D",
1878
+ subscriptionStatusExpired: "\u5DF2\u8FC7\u671F",
1879
+ subscriptionStatusCancelled: "\u5DF2\u53D6\u6D88",
1880
+ subscriptionStatusPending: "\u5F85\u652F\u4ED8",
1881
+ subscriptionStatusUnknown: "\u672A\u77E5\u72B6\u6001",
1882
+ subscriptionEndsAt: "\u5230\u671F\u65F6\u95F4",
1883
+ subscriptionRemainingQuota: "\u5269\u4F59\u989D\u5EA6",
1884
+ subscriptionNextReset: "\u4E0B\u6B21\u91CD\u7F6E",
1885
+ subscriptionUsage: "\u5DF2\u7528 {used} / {total} \xB7 \u5269\u4F59 {percent}%",
1886
+ subscriptionDays: "{count} \u5929",
1887
+ subscriptionWeeks: "{count} \u5468",
1888
+ subscriptionMonths: "{count} \u4E2A\u6708",
1889
+ subscriptionYears: "{count} \u5E74",
1890
+ subscriptionHours: "{count} \u5C0F\u65F6",
1891
+ subscriptionMinutes: "{count} \u5206\u949F",
1892
+ subscriptionSeconds: "{count} \u79D2",
1893
+ subscriptionCustomDuration: "{count} \u79D2",
1894
+ subscriptionNeverReset: "\u989D\u5EA6\u4E0D\u91CD\u7F6E",
1895
+ subscriptionResetDay: "\u6BCF\u65E5\u91CD\u7F6E",
1896
+ subscriptionResetWeek: "\u6BCF\u5468\u91CD\u7F6E",
1897
+ subscriptionResetMonth: "\u6BCF\u6708\u91CD\u7F6E",
1898
+ subscriptionResetYear: "\u6BCF\u5E74\u91CD\u7F6E",
1899
+ subscriptionResetCustom: "\u6BCF {count} \u79D2\u91CD\u7F6E",
1900
+ subscriptionResetOther: "\u6309 {period} \u91CD\u7F6E",
1901
+ subscriptionPurchaseLimit: "\u9650\u8D2D {count} \u6B21",
1902
+ subscriptionUpgradeGroup: "\u8BA2\u9605\u540E\u7528\u6237\u5206\u7EC4\uFF1A{group}",
1903
+ subscriptionSelected: "\u5DF2\u9009\uFF1A{title} \xB7 {price}",
1904
+ subscriptionNoMethods: "\u5E73\u53F0\u6682\u672A\u914D\u7F6E\u53EF\u7528\u7684\u8BA2\u9605\u652F\u4ED8\u65B9\u5F0F\u3002",
1905
+ enabled: "\u6B63\u5E38",
1906
+ disabled: "\u5DF2\u7981\u7528",
1907
+ roleUser: "\u666E\u901A\u7528\u6237",
1908
+ roleAdmin: "\u7BA1\u7406\u5458",
1909
+ roleRoot: "\u8D85\u7EA7\u7BA1\u7406\u5458",
1910
+ roleUnknown: "\u672A\u77E5\u89D2\u8272",
1911
+ empty: "\u6682\u65E0\u6570\u636E"
1912
+ };
1913
+ var en = {
1914
+ sidebarLabel: "MetaOntic\u6A21\u578B\u4E2D\u8F6C\u52A9\u624B",
1915
+ title: "MetaOntic AI Management Tool",
1916
+ intro: "MetaOntic AI is a multi-model aggregation platform offering stable, reliable model services. Sign in with an access token to inspect the platform and your account.",
1917
+ baseUrl: "Platform URL",
1918
+ accessToken: "Access token",
1919
+ accessTokenPlaceholder: "Enter access token",
1920
+ accessTokenHint: "Create the token in the MetaOntic AI console. It is used only for this query.",
1921
+ tokenPrivacy: "After sign-in, the Host stores the token in a private local profile file. The browser does not store it.",
1922
+ login: "Sign in with access token",
1923
+ loginPending: "Verifying access token\u2026",
1924
+ registerPrompt: "Need an access token?",
1925
+ registerNow: "Create account",
1926
+ restoringLogin: "Restoring saved local login\u2026",
1927
+ savedLogin: "Login saved on this device",
1928
+ notPersisted: "Signed in, but the login could not be saved on this device.",
1929
+ savedLoginExpired: "The saved access token has expired. Sign in again.",
1930
+ restoreFailed: "Could not restore the saved login. Sign in again.",
1931
+ showToken: "Show token",
1932
+ hideToken: "Hide token",
1933
+ logout: "Sign out",
1934
+ refresh: "Refresh query",
1935
+ refreshing: "Refreshing\u2026",
1936
+ tokenRequired: "Enter an access token.",
1937
+ requestFailed: "Query failed. Try again later.",
1938
+ invalidResponse: "The platform returned an unrecognized response.",
1939
+ account: "Account",
1940
+ platform: "Platform",
1941
+ accountPlatform: "Account & platform",
1942
+ balance: "Available balance",
1943
+ usedQuota: "Used quota",
1944
+ requests: "Requests",
1945
+ usageRatio: "Remaining quota",
1946
+ usageRemainingPercent: "Remaining {percent}%",
1947
+ username: "Username",
1948
+ displayName: "Display name",
1949
+ group: "Group",
1950
+ role: "Role",
1951
+ accountId: "User ID",
1952
+ accountStatus: "Account status",
1953
+ systemName: "Platform name",
1954
+ version: "Version",
1955
+ serverAddress: "Server address",
1956
+ currency: "Currency",
1957
+ fetchedAt: "Queried at",
1958
+ rawQuota: "Balance {quota} \xB7 Cumulative used {used}",
1959
+ overviewPage: "Overview & Recharge",
1960
+ modelsPage: "Model plaza",
1961
+ modelsHint: "Browse available models, supported groups, and billing information.",
1962
+ modelsLoading: "Loading models\u2026",
1963
+ modelsRefresh: "Refresh",
1964
+ modelsSearch: "Search models",
1965
+ modelsSearchPlaceholder: "Name, tag, or description",
1966
+ modelsGroupFilter: "Group",
1967
+ modelsAllGroups: "All groups",
1968
+ modelsCount: "{count} model(s)",
1969
+ modelsEmpty: "No matching models.",
1970
+ modelsLoadFailed: "Could not load the model list.",
1971
+ modelsRatio: "Ratio {ratio}",
1972
+ modelsPrice: "Price {price}",
1973
+ modelsTags: "Tags",
1974
+ modelsGroups: "Available groups",
1975
+ modelsEndpoints: "Endpoints",
1976
+ apiKeys: "API Key management",
1977
+ apiKeysHint: "Create and manage access keys for applications. Full keys are read only when explicitly shown and are never included in the list response.",
1978
+ apiKeyListTitle: "Key list ({count})",
1979
+ apiKeyRefresh: "Refresh",
1980
+ apiKeyRefreshing: "Refreshing\u2026",
1981
+ apiKeyNew: "New API Key",
1982
+ apiKeyCreateHint: "The full key is shown only once after creation. Save it securely.",
1983
+ apiKeyCreate: "Create",
1984
+ apiKeyCreating: "Creating\u2026",
1985
+ apiKeyCancel: "Cancel",
1986
+ apiKeyName: "Name",
1987
+ apiKeyNamePlaceholder: "For example, dsh-desktop",
1988
+ apiKeyGroup: "Group",
1989
+ apiKeyGroupHint: "Choose the model group this key can use.",
1990
+ apiKeyUnlimited: "Unlimited quota",
1991
+ apiKeyQuota: "Quota",
1992
+ apiKeyQuotaPlaceholder: "For example, 10",
1993
+ apiKeyQuotaHint: "Enter an amount in the platform display currency.",
1994
+ apiKeyExpiryDays: "Valid for (days)",
1995
+ apiKeyNeverExpiresHint: "Use 0 for no expiration.",
1996
+ apiKeyNone: "No API keys yet. Click \u201CNew API Key\u201D to create one.",
1997
+ apiKeyHidden: "Click \u201CShow key\u201D to reveal",
1998
+ apiKeyShow: "Show key",
1999
+ apiKeyHide: "Hide key",
2000
+ apiKeyCopy: "Copy",
2001
+ apiKeyCopied: "API Key copied.",
2002
+ apiKeyCopyUnavailable: "Clipboard access is unavailable. Select and copy the key manually.",
2003
+ apiKeyCreated: "API Key created. Show it and store it securely.",
2004
+ apiKeyDeleted: "API Key deleted.",
2005
+ apiKeyEnabledNotice: "API Key enabled.",
2006
+ apiKeyDisabledNotice: "API Key disabled.",
2007
+ apiKeyDeleteConfirm: "Delete API Key \u201C{name}\u201D? This cannot be undone.",
2008
+ apiKeyDelete: "Delete",
2009
+ apiKeyEnable: "Enable",
2010
+ apiKeyDisable: "Disable",
2011
+ apiKeyStatusEnabled: "Enabled",
2012
+ apiKeyStatusDisabled: "Disabled",
2013
+ apiKeyStatusExpired: "Expired",
2014
+ apiKeyStatusExhausted: "Quota exhausted",
2015
+ apiKeyStatusUnknown: "Unknown status",
2016
+ apiKeyQuotaLabel: "Remaining quota",
2017
+ apiKeyUsedLabel: "Used quota",
2018
+ apiKeyExpires: "Expires",
2019
+ apiKeyCreatedAt: "Created",
2020
+ neverExpires: "Never expires",
2021
+ unlimited: "Unlimited",
2022
+ apiKeyLoadFailed: "Could not load API keys.",
2023
+ apiKeyActionFailed: "API Key operation failed.",
2024
+ apiKeyRevealFailed: "Could not read the API Key.",
2025
+ apiKeyNameRequired: "Enter an API Key name.",
2026
+ apiKeyQuotaInvalid: "Invalid quota amount.",
2027
+ apiKeyExpiryInvalid: "Invalid expiration period.",
2028
+ topup: "Recharge",
2029
+ topupHint: "Choose an amount and payment method. The platform creates the payment link; delivery is confirmed by the platform.",
2030
+ topupLoading: "Loading recharge options\u2026",
2031
+ topupOnline: "Online recharge enabled",
2032
+ topupOffline: "Online recharge disabled",
2033
+ topupUnavailable: "Online recharge is not enabled on this platform.",
2034
+ topupNoMethods: "No payment method is configured on this platform.",
2035
+ topupAmount: "Recharge amount (USD)",
2036
+ topupAmountPlaceholder: "Enter an amount",
2037
+ topupMinAmount: "Minimum {amount}",
2038
+ topupPayment: "Payment method",
2039
+ topupSubmit: "Create payment",
2040
+ topupSubmitting: "Creating payment link\u2026",
2041
+ topupCreated: "Payment link created. Continue in the payment page.",
2042
+ topupPayMoney: "Amount to pay (CNY)",
2043
+ topupOrderNo: "Order number",
2044
+ topupOpenPayment: "Go to payment",
2045
+ topupAgain: "Recharge again",
2046
+ topupAmountInvalid: "Enter a valid positive whole-number amount.",
2047
+ topupAmountTooSmall: "The amount must be at least {amount}.",
2048
+ topupLoadFailed: "Could not load recharge options.",
2049
+ topupCreateFailed: "Could not create the payment. Try again later.",
2050
+ subscription: "Subscriptions",
2051
+ subscriptionHint: "Review your current plan and purchase a subscription. The platform creates the signed payment link and confirms activation.",
2052
+ subscriptionLoading: "Loading subscription details\u2026",
2053
+ subscriptionCurrent: "Current subscription",
2054
+ subscriptionNone: "No active subscription.",
2055
+ subscriptionPlans: "Plans",
2056
+ subscriptionNoPlans: "No subscription plans are available right now.",
2057
+ subscriptionPayment: "Payment method",
2058
+ subscriptionSubmit: "Subscribe and pay",
2059
+ subscriptionSubmitting: "Creating payment link\u2026",
2060
+ subscriptionPaymentCreated: "Subscription payment link created. Continue in the payment page.",
2061
+ subscriptionPayMoney: "Amount to pay (CNY)",
2062
+ subscriptionOpenPayment: "Go to payment",
2063
+ subscriptionSelectRequired: "Select a plan and payment method.",
2064
+ subscriptionLoadFailed: "Could not load subscription details.",
2065
+ subscriptionCreateFailed: "Could not create the subscription payment. Try again later.",
2066
+ subscriptionStatusActive: "Active",
2067
+ subscriptionStatusExpired: "Expired",
2068
+ subscriptionStatusCancelled: "Cancelled",
2069
+ subscriptionStatusPending: "Pending payment",
2070
+ subscriptionStatusUnknown: "Unknown status",
2071
+ subscriptionEndsAt: "Ends",
2072
+ subscriptionRemainingQuota: "Remaining quota",
2073
+ subscriptionNextReset: "Next reset",
2074
+ subscriptionUsage: "Used {used} / {total} \xB7 {percent}% remaining",
2075
+ subscriptionDays: "{count} day(s)",
2076
+ subscriptionWeeks: "{count} week(s)",
2077
+ subscriptionMonths: "{count} month(s)",
2078
+ subscriptionYears: "{count} year(s)",
2079
+ subscriptionHours: "{count} hour(s)",
2080
+ subscriptionMinutes: "{count} minute(s)",
2081
+ subscriptionSeconds: "{count} second(s)",
2082
+ subscriptionCustomDuration: "{count} second(s)",
2083
+ subscriptionNeverReset: "Quota never resets",
2084
+ subscriptionResetDay: "Resets daily",
2085
+ subscriptionResetWeek: "Resets weekly",
2086
+ subscriptionResetMonth: "Resets monthly",
2087
+ subscriptionResetYear: "Resets yearly",
2088
+ subscriptionResetCustom: "Resets every {count} second(s)",
2089
+ subscriptionResetOther: "Resets by {period}",
2090
+ subscriptionPurchaseLimit: "Limit {count} purchase(s)",
2091
+ subscriptionUpgradeGroup: "Group after purchase: {group}",
2092
+ subscriptionSelected: "Selected: {title} \xB7 {price}",
2093
+ subscriptionNoMethods: "No subscription payment method is available on this platform.",
2094
+ enabled: "Active",
2095
+ disabled: "Disabled",
2096
+ roleUser: "User",
2097
+ roleAdmin: "Administrator",
2098
+ roleRoot: "Super administrator",
2099
+ roleUnknown: "Unknown role",
2100
+ empty: "No data"
2101
+ };
2102
+
2103
+ // src/client.ts
2104
+ window.__ModuleLoader__.load({
2105
+ id: PANEL_ID,
2106
+ factory(require2) {
2107
+ const React = require2("react");
2108
+ const h = React.createElement;
2109
+ return {
2110
+ inject: ["slots", "locale"],
2111
+ apply(ctx) {
2112
+ ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-metaontic-newapi-lite: dictionaries");
2113
+ const t = ctx.locale.bind(NS);
2114
+ const runtime = { React, h, t };
2115
+ const Dashboard = createDashboard(runtime);
2116
+ const PanelIconView = createPanelIconView(runtime);
2117
+ ctx.effect(() => ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({
2118
+ name: "sidebar.panellist",
2119
+ id: PANEL_ID,
2120
+ order: 40,
2121
+ locale: NS,
2122
+ label: () => t("sidebarLabel")
2123
+ }, PanelIconView)), "dsh-metaontic-newapi-lite: sidebar entry");
2124
+ ctx.effect(() => ctx.slots.inject("main", () => ctx.slots.register({
2125
+ name: "main",
2126
+ key: PANEL_ID,
2127
+ locale: NS
2128
+ }, Dashboard)), "dsh-metaontic-newapi-lite: main panel");
2129
+ }
2130
+ };
2131
+ }
2132
+ });
2133
+ })();
2134
+ //# sourceMappingURL=client.js.map