dsh-model-allowance 1.1.0 → 1.1.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.
package/README.md CHANGED
@@ -15,6 +15,18 @@ lists the provider's models and moves the conversation to the one you pick.
15
15
  The card shows the provider's remaining balance or allowance and the model
16
16
  of the current conversation, next to the input box.
17
17
 
18
+ ## Configure credentials
19
+
20
+ Open **Settings → Model Allowance** to store the vendor credentials the
21
+ balance queries need, such as the Alibaba Cloud AccessKey ID/Secret behind
22
+ Qwen Token Plan readings. A testable pair is verified against the vendor's
23
+ own endpoints before it is saved; stored values can be edited or removed
24
+ later. Values live in DSH's credential store: they are never written into
25
+ configuration, never shown back, and reach nothing but the vendor's own
26
+ query endpoint. The guide under
27
+ [docs/qwen-token-plen-cn](docs/qwen-token-plen-cn/README.md) walks obtaining
28
+ the AccessKey pair.
29
+
18
30
  ## Supported
19
31
 
20
32
  - DeepSeek
@@ -23,6 +35,8 @@ of the current conversation, next to the input box.
23
35
  - Kimi for Coding
24
36
  - OpenCode Go
25
37
  - Xiaomi MiMo (pay-as-you-go balance and Token Plan)
38
+ - Qwen Token Plan (CN personal plan; needs the Alibaba Cloud AccessKey pair
39
+ from **Settings → Model Allowance**)
26
40
 
27
41
  ### Not supported
28
42
 
@@ -30,8 +44,6 @@ These vendors publish no balance API. As long as they are configured here,
30
44
  they still appear in the card: the panel says there is no balance API, and
31
45
  their models stay switchable.
32
46
 
33
- - Qwen Token Plan: the vendor publishes no balance API
34
-
35
47
  ## Installation
36
48
 
37
49
  ### Install from npm (recommended)
package/README.zh.md CHANGED
@@ -13,6 +13,15 @@
13
13
 
14
14
  卡片显示厂商的余额或剩余额度,以及当前会话所用的模型,位于输入框旁。
15
15
 
16
+ ## 配置凭据
17
+
18
+ 打开 **设置 → Model Allowance**,即可录入余额查询所需的厂商凭据(例如千问
19
+ Token Plan 用量查询用的阿里云 AccessKey ID/Secret)。可测试的凭据在保存前会
20
+ 先经过厂商自己的接口验证,通过后才会落库;已保存的凭据支持修改和删除。密钥
21
+ 保存在 DSH 的凭据存储中:不写入配置文件、不会回显,也不会发往除厂商查询接口
22
+ 外的任何地方。获取 AccessKey 的步骤见
23
+ [配置指南](docs/qwen-token-plen-cn/README.md)。
24
+
16
25
  ## 支持
17
26
 
18
27
  - DeepSeek
@@ -21,14 +30,13 @@
21
30
  - Kimi for Coding
22
31
  - OpenCode Go
23
32
  - Xiaomi MiMo(按量付费余额与 Token Plan)
33
+ - 千问 Token Plan(国内个人版;需在 **设置 → Model Allowance** 配置阿里云 AccessKey)
24
34
 
25
35
  ### 不支持
26
36
 
27
37
  以下厂商没有余额接口,但只要本地配置了它们,它们依然会出现在卡片里:
28
38
  面板会提示“目前无余额接口”,模型列表照常可以切换。
29
39
 
30
- - 千问 Token Plan:官方未提供余额接口
31
-
32
40
  ## 安装
33
41
 
34
42
  ### 从 npm 安装(推荐)
package/client.js CHANGED
@@ -42,7 +42,7 @@ __export(index_exports, {
42
42
  inject: () => inject
43
43
  });
44
44
  module.exports = __toCommonJS(index_exports);
45
- var import_react8 = require("react");
45
+ var import_react9 = require("react");
46
46
 
47
47
  // src/client/badge.js
48
48
  var React6 = __toESM(require("react"), 1);
@@ -484,7 +484,28 @@ var zh = {
484
484
  "duration.daysHours": "{days} \u5929 {hours} \u5C0F\u65F6",
485
485
  "duration.hoursMinutes": "{hours} \u5C0F\u65F6 {minutes} \u5206",
486
486
  "duration.minutes": "{minutes} \u5206\u949F",
487
- "duration.lessThanMinute": "\u4E0D\u5230 1 \u5206\u949F"
487
+ "duration.lessThanMinute": "\u4E0D\u5230 1 \u5206\u949F",
488
+ "settings.nav": "Model Allowance",
489
+ "settings.title": "Model Allowance",
490
+ "settings.loading": "\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u2026",
491
+ "settings.unavailable": "\u672C\u673A\u672A\u63D0\u4F9B\u51ED\u636E\u670D\u52A1\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u51ED\u636E\u3002",
492
+ "settings.edit": "\u4FEE\u6539",
493
+ "settings.delete": "\u5220\u9664",
494
+ "settings.cancel": "\u53D6\u6D88",
495
+ "settings.save": "\u4FDD\u5B58",
496
+ "settings.testing": "\u9A8C\u8BC1\u4E2D\u2026",
497
+ "settings.fillAll": "\u8BF7\u586B\u5199\u5B8C\u6574\u7684\u51ED\u636E\u540E\u518D\u4FDD\u5B58",
498
+ "settings.testFailed": "\u51ED\u636E\u9A8C\u8BC1\u672A\u901A\u8FC7\uFF0C\u672A\u4FDD\u5B58",
499
+ "settings.testRejected": "\u5382\u5546\u62D2\u7EDD\u4E86\u8FD9\u5BF9\u51ED\u636E",
500
+ "settings.doc": "\u5982\u4F55\u83B7\u53D6\u51ED\u636E\uFF1F",
501
+ "settings.saved": "\u5DF2\u4FDD\u5B58",
502
+ "settings.configured": "\u5DF2\u914D\u7F6E",
503
+ "settings.deleted": "\u5DF2\u5220\u9664",
504
+ "settings.saveFailed": "\u4FDD\u5B58\u5931\u8D25",
505
+ "settings.deleteFailed": "\u5220\u9664\u5931\u8D25",
506
+ "settings.loadFailed": "\u8BFB\u53D6\u51ED\u636E\u72B6\u6001\u5931\u8D25",
507
+ "badge.setupHint": "\u5C1A\u672A\u914D\u7F6E\u8BE5\u5382\u5546\u7684\u67E5\u8BE2\u51ED\u636E\u3002\u6253\u5F00 \u8BBE\u7F6E \u2192 Model Allowance \u5F55\u5165\u3002",
508
+ "badge.setupDoc": "\u67E5\u770B\u914D\u7F6E\u6307\u5357"
488
509
  };
489
510
  var en = {
490
511
  "badge.loading": "Loading\u2026",
@@ -548,7 +569,28 @@ var en = {
548
569
  "duration.daysHours": "{days}d {hours}h",
549
570
  "duration.hoursMinutes": "{hours}h {minutes}m",
550
571
  "duration.minutes": "{minutes}m",
551
- "duration.lessThanMinute": "under a minute"
572
+ "duration.lessThanMinute": "under a minute",
573
+ "settings.nav": "Model Allowance",
574
+ "settings.title": "Model Allowance",
575
+ "settings.loading": "Reading credential status\u2026",
576
+ "settings.unavailable": "This host provides no credential store, so credentials cannot be saved.",
577
+ "settings.edit": "Edit",
578
+ "settings.delete": "Delete",
579
+ "settings.cancel": "Cancel",
580
+ "settings.save": "Save",
581
+ "settings.testing": "Verifying\u2026",
582
+ "settings.fillAll": "Fill in every field before saving",
583
+ "settings.testFailed": "The credentials were rejected and were not saved",
584
+ "settings.testRejected": "the vendor refused this credential pair",
585
+ "settings.doc": "How do I get the credentials?",
586
+ "settings.saved": "Saved",
587
+ "settings.configured": "Configured",
588
+ "settings.deleted": "Deleted",
589
+ "settings.saveFailed": "Save failed",
590
+ "settings.deleteFailed": "Delete failed",
591
+ "settings.loadFailed": "Could not read credential status",
592
+ "badge.setupHint": "No credentials are stored for this provider yet. Open Settings \u2192 Model Allowance to add them.",
593
+ "badge.setupDoc": "Open the setup guide"
552
594
  };
553
595
  function activeLanguage() {
554
596
  const tag = typeof document !== "undefined" ? document.documentElement?.lang : void 0;
@@ -1410,7 +1452,23 @@ function BalancePanel({
1410
1452
  { className: "dsh-model-allowance-reason" },
1411
1453
  t("badge.unsupportedWithName", { name: nameOf(activeProvider) })
1412
1454
  ) : null,
1413
- view?.status === "unconfigured" ? (0, import_react6.createElement)("div", { className: "dsh-model-allowance-reason" }, t("badge.unconfigured")) : null,
1455
+ view?.status === "unconfigured" ? (0, import_react6.createElement)(
1456
+ "div",
1457
+ { className: "dsh-model-allowance-reason" },
1458
+ t("badge.setupHint"),
1459
+ // The reading carries the provider's setup guide; it is the walk
1460
+ // from "no credential" to a stored pair, so it is one click away.
1461
+ view.setupUrl ? (0, import_react6.createElement)(
1462
+ "a",
1463
+ {
1464
+ className: "dsh-model-allowance-setup-link",
1465
+ href: view.setupUrl,
1466
+ target: "_blank",
1467
+ rel: "noreferrer noopener"
1468
+ },
1469
+ `${t("badge.setupDoc")} \u2197`
1470
+ ) : null
1471
+ ) : null,
1414
1472
  // A vendor that prices by the wall clock gets its phase and
1415
1473
  // countdown here, above the footer.
1416
1474
  schedule && schedule.provider === activeProvider ? scheduleView(schedule, now, t) : null,
@@ -2069,6 +2127,10 @@ var STYLES = [
2069
2127
  ".dsh-model-allowance-error{padding:4px 0;color:var(--dsw-alias-state-error-primary)}",
2070
2128
  ".dsh-model-allowance-reason{padding:2px 0;color:var(--dsw-alias-label-secondary);",
2071
2129
  "font-size:11px;word-break:break-word}",
2130
+ ".dsh-model-allowance-setup-link{margin-left:6px;color:var(--dsw-alias-state-business-primary);",
2131
+ "text-decoration:none;white-space:nowrap}",
2132
+ ".dsh-model-allowance-setup-link:hover,.dsh-model-allowance-setup-link:focus-visible",
2133
+ "{text-decoration:underline}",
2072
2134
  // The footer is one right-aligned cluster: the reading time sits directly
2073
2135
  // left of the two icon buttons.
2074
2136
  ".dsh-model-allowance-actions{display:flex;align-items:center;",
@@ -2455,6 +2517,9 @@ function createBalanceContribution() {
2455
2517
  at: z.number()
2456
2518
  }).optional(),
2457
2519
  consoleUrl: z.string().optional(),
2520
+ // The setup guide rides an unconfigured reading: the card links it so the
2521
+ // user lands on the walkthrough for this provider's credentials.
2522
+ setupUrl: z.string().optional(),
2458
2523
  updatedAt: z.number().optional(),
2459
2524
  error: z.string().optional()
2460
2525
  });
@@ -2556,6 +2621,38 @@ function createBalanceContribution() {
2556
2621
  "dsh-model-allowance#defaultProvider"
2557
2622
  )
2558
2623
  },
2624
+ "balance/testCredentials": {
2625
+ service: "balanceController",
2626
+ description: "Walk a provider's credential chain against the live endpoints.",
2627
+ invocation: { kind: "direct" },
2628
+ parameters: [
2629
+ {
2630
+ name: "accessKeyId",
2631
+ wire: "accessKeyId",
2632
+ source: "json",
2633
+ codec: strict(
2634
+ z.string().min(1),
2635
+ "AccessKey ID candidate.",
2636
+ "dsh-model-allowance#accessKeyId"
2637
+ )
2638
+ },
2639
+ {
2640
+ name: "secretAccessKey",
2641
+ wire: "secretAccessKey",
2642
+ source: "json",
2643
+ codec: strict(
2644
+ z.string().min(1),
2645
+ "AccessKey secret candidate.",
2646
+ "dsh-model-allowance#secretAccessKey"
2647
+ )
2648
+ }
2649
+ ],
2650
+ result: strict(
2651
+ z.object({ ok: z.boolean(), error: z.string().optional() }),
2652
+ "The outcome.",
2653
+ "dsh-model-allowance#testOutcome"
2654
+ )
2655
+ },
2559
2656
  "balance/refresh": {
2560
2657
  service: "balanceController",
2561
2658
  description: "Force a fresh reading for one provider, bypassing the cache.",
@@ -2594,6 +2691,334 @@ function createBalanceContribution() {
2594
2691
  };
2595
2692
  }
2596
2693
 
2694
+ // src/client/credentials-page.js
2695
+ var React7 = __toESM(require("react"), 1);
2696
+ var import_react8 = require("react");
2697
+
2698
+ // src/client/credential-groups.js
2699
+ var CREDENTIAL_GROUPS = Object.freeze([
2700
+ {
2701
+ id: "aliyun",
2702
+ name: {
2703
+ zh: "\u963F\u91CC\u4E91\uFF08\u5343\u95EE Token Plan\uFF09",
2704
+ en: "Alibaba Cloud (Qwen Token Plan)"
2705
+ },
2706
+ docLabel: {
2707
+ zh: "\u5982\u4F55\u83B7\u53D6 AccessKey\uFF1F",
2708
+ en: "How do I get an AccessKey?"
2709
+ },
2710
+ docUrl: "https://github.com/MeiK2333/dsh-model-allowance/blob/master/docs/qwen-token-plen-cn/README.md",
2711
+ test: "qwen",
2712
+ fields: [
2713
+ {
2714
+ ref: "ALIBABA_CLOUD_ACCESS_KEY_ID",
2715
+ label: { zh: "AccessKey ID", en: "AccessKey ID" }
2716
+ },
2717
+ {
2718
+ ref: "ALIBABA_CLOUD_ACCESS_KEY_SECRET",
2719
+ label: { zh: "AccessKey Secret", en: "AccessKey Secret" }
2720
+ }
2721
+ ]
2722
+ }
2723
+ ]);
2724
+ var CREDENTIAL_REFS = Object.freeze(
2725
+ CREDENTIAL_GROUPS.flatMap((group) => group.fields.map((field) => field.ref))
2726
+ );
2727
+
2728
+ // src/client/credentials-page.js
2729
+ var STYLES2 = [
2730
+ ".dsh-allowance-cfg{display:flex;flex-direction:column;gap:12px;max-width:720px;",
2731
+ "color:var(--dsw-alias-label-primary)}",
2732
+ ".dsh-allowance-cfg-title{margin:0;font-size:16px;line-height:24px;font-weight:500;",
2733
+ "color:var(--dsw-alias-label-primary)}",
2734
+ ".dsh-allowance-cfg-card{display:flex;flex-direction:column;gap:12px;padding:12px 14px;",
2735
+ "border:0.5px solid var(--dsw-alias-settings-card-stroke);",
2736
+ "background:var(--dsw-alias-settings-card-fill);border-radius:var(--dsw-radius-xl)}",
2737
+ ".dsh-allowance-cfg-card-title{margin:0;font-size:14px;line-height:22px;font-weight:500;",
2738
+ "color:var(--dsw-alias-label-primary)}",
2739
+ ".dsh-allowance-cfg-card-head{display:flex;align-items:center;gap:8px}",
2740
+ ".dsh-allowance-cfg-field{display:flex;flex-direction:column;gap:6px}",
2741
+ ".dsh-allowance-cfg-field-label{font-size:12px;line-height:18px;font-weight:500;",
2742
+ "color:var(--dsw-alias-label-secondary)}",
2743
+ ".dsh-allowance-cfg-text{font-size:14px;line-height:22px;",
2744
+ "color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}",
2745
+ ".dsh-allowance-cfg-status{display:inline-flex;align-items:center;height:22px;",
2746
+ "padding:0 8px;border-radius:var(--dsw-radius-sm);font-size:12px;line-height:18px;",
2747
+ "border:0.5px solid var(--dsw-alias-state-success-primary);",
2748
+ "color:var(--dsw-alias-state-success-primary)}",
2749
+ ".dsh-allowance-cfg-input{box-sizing:border-box;width:100%;height:32px;padding:0 10px;",
2750
+ "border:0.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);",
2751
+ "font:inherit;font-size:14px;line-height:22px;background:var(--dsw-alias-bg-layer-1);",
2752
+ "color:var(--dsw-alias-label-primary)}",
2753
+ ".dsh-allowance-cfg-input:focus{outline:none;",
2754
+ "border-color:var(--dsw-alias-state-business-primary)}",
2755
+ ".dsh-allowance-cfg-input:disabled{opacity:.6;cursor:default}",
2756
+ ".dsh-allowance-cfg-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
2757
+ ".dsh-allowance-cfg-button{box-sizing:border-box;display:inline-flex;align-items:center;",
2758
+ "justify-content:center;height:32px;padding:0 14px;border:none;",
2759
+ "border-radius:var(--dsw-radius-md);font:inherit;font-size:14px;line-height:22px;",
2760
+ "cursor:pointer}",
2761
+ '.dsh-allowance-cfg-button[data-tone="primary"]{',
2762
+ "background:var(--dsw-alias-button-primary-fill);",
2763
+ "color:var(--dsw-alias-label-primary-foreground)}",
2764
+ '.dsh-allowance-cfg-button[data-tone="primary"]:hover:not(:disabled){',
2765
+ "background:var(--dsw-alias-button-primary-hover)}",
2766
+ '.dsh-allowance-cfg-button[data-tone="secondary"]{',
2767
+ "border:0.5px solid var(--dsw-alias-border-l3);background:transparent;",
2768
+ "color:var(--dsw-alias-label-primary)}",
2769
+ '.dsh-allowance-cfg-button[data-tone="secondary"]:hover:not(:disabled){',
2770
+ "background:var(--dsw-alias-interactive-bg-hover-solid)}",
2771
+ ".dsh-allowance-cfg-button:disabled{opacity:.5;cursor:default}",
2772
+ ".dsh-allowance-cfg-link{font-size:12px;line-height:18px;",
2773
+ "color:var(--dsw-alias-state-business-primary);text-decoration:none}",
2774
+ ".dsh-allowance-cfg-link:hover{text-decoration:underline}",
2775
+ ".dsh-allowance-cfg-saved{margin:0;font-size:12px;line-height:18px;",
2776
+ "color:var(--dsw-alias-state-success-primary)}",
2777
+ ".dsh-allowance-cfg-error{margin:0;font-size:12px;line-height:18px;",
2778
+ "color:var(--dsw-alias-state-error-primary)}",
2779
+ ".dsh-allowance-cfg-hint{margin:0;font-size:12px;line-height:18px;",
2780
+ "color:var(--dsh-alias-label-tertiary)}"
2781
+ ].join("");
2782
+ function pick(bilingual) {
2783
+ return bilingual[activeLanguage()] ?? bilingual.en ?? bilingual.zh;
2784
+ }
2785
+ function errorText(error) {
2786
+ return error instanceof Error ? error.message : String(error);
2787
+ }
2788
+ async function testGroup(group, drafts, refId, refSecret, t) {
2789
+ if (group.test !== "qwen") return { ok: true };
2790
+ try {
2791
+ const api = await getBalanceApi();
2792
+ if (!api || typeof api.testCredentials !== "function") return { ok: true };
2793
+ const result = await api.testCredentials(drafts[refId] ?? "", drafts[refSecret] ?? "");
2794
+ if (result.ok && result.value?.ok === true) return { ok: true };
2795
+ if (result.ok && result.value?.ok === false) {
2796
+ return { ok: false, error: result.value.error ?? t("settings.testRejected") };
2797
+ }
2798
+ return { ok: false, error: errorText(result.error ?? t("settings.testRejected")) };
2799
+ } catch (error) {
2800
+ return { ok: false, error: errorText(error) };
2801
+ }
2802
+ }
2803
+ function unwrap(response) {
2804
+ if (response?.ok) return response.value;
2805
+ const detail = response?.error;
2806
+ throw new Error(
2807
+ detail instanceof Error ? detail.message : typeof detail?.message === "string" ? detail.message : typeof detail === "string" ? detail : "the Host refused the call"
2808
+ );
2809
+ }
2810
+ function CredentialsSection({ ctx, t }) {
2811
+ const credentials = ctx.get("remote.credentials");
2812
+ const [infos, setInfos] = React7.useState(void 0);
2813
+ const [drafts, setDrafts] = React7.useState({});
2814
+ const [editing, setEditing] = React7.useState({});
2815
+ const [busy, setBusy] = React7.useState(false);
2816
+ const [notice, setNotice] = React7.useState(void 0);
2817
+ const load = React7.useCallback(async () => {
2818
+ if (credentials === void 0) return;
2819
+ try {
2820
+ setInfos(unwrap(await credentials.describe([...CREDENTIAL_REFS])));
2821
+ } catch (error) {
2822
+ setInfos({});
2823
+ setNotice({ tone: "error", text: `${t("settings.loadFailed")}: ${errorText(error)}` });
2824
+ }
2825
+ }, [credentials, t]);
2826
+ React7.useEffect(() => {
2827
+ void load();
2828
+ }, [load]);
2829
+ const resetGroup = (group) => {
2830
+ setDrafts((previous) => {
2831
+ const next = { ...previous };
2832
+ for (const field of group.fields) delete next[field.ref];
2833
+ return next;
2834
+ });
2835
+ setEditing((previous) => ({ ...previous, [group.id]: false }));
2836
+ };
2837
+ const saveGroup = async (group) => {
2838
+ const values = group.fields.map((field) => (drafts[field.ref] ?? "").trim());
2839
+ if (values.some((value) => value === "")) {
2840
+ setNotice({ tone: "error", text: t("settings.fillAll") });
2841
+ return;
2842
+ }
2843
+ setBusy(true);
2844
+ setNotice(void 0);
2845
+ try {
2846
+ const [idField, secretField] = group.fields;
2847
+ const tested = await testGroup(
2848
+ group,
2849
+ Object.fromEntries(
2850
+ group.fields.map((field) => [field.ref, (drafts[field.ref] ?? "").trim()])
2851
+ ),
2852
+ idField.ref,
2853
+ secretField.ref,
2854
+ t
2855
+ );
2856
+ if (!tested.ok) {
2857
+ setNotice({ tone: "error", text: `${t("settings.testFailed")}: ${tested.error}` });
2858
+ return;
2859
+ }
2860
+ for (const field of group.fields) {
2861
+ unwrap(await credentials.set(field.ref, (drafts[field.ref] ?? "").trim()));
2862
+ }
2863
+ resetGroup(group);
2864
+ setNotice({ tone: "ok", text: t("settings.saved") });
2865
+ } catch (error) {
2866
+ setNotice({ tone: "error", text: `${t("settings.saveFailed")}: ${errorText(error)}` });
2867
+ } finally {
2868
+ setBusy(false);
2869
+ await load();
2870
+ }
2871
+ };
2872
+ const deleteGroup = async (group) => {
2873
+ setBusy(true);
2874
+ setNotice(void 0);
2875
+ try {
2876
+ for (const field of group.fields) {
2877
+ unwrap(await credentials.unset(field.ref));
2878
+ }
2879
+ resetGroup(group);
2880
+ setNotice({ tone: "ok", text: t("settings.deleted") });
2881
+ } catch (error) {
2882
+ setNotice({ tone: "error", text: `${t("settings.deleteFailed")}: ${errorText(error)}` });
2883
+ } finally {
2884
+ setBusy(false);
2885
+ await load();
2886
+ }
2887
+ };
2888
+ const renderField = (field, editMode) => {
2889
+ const info = infos?.[field.ref];
2890
+ return (0, import_react8.createElement)(
2891
+ "div",
2892
+ { key: field.ref, className: "dsh-allowance-cfg-field" },
2893
+ (0, import_react8.createElement)(
2894
+ editMode ? "label" : "div",
2895
+ {
2896
+ className: "dsh-allowance-cfg-field-label",
2897
+ htmlFor: editMode ? `dsh-allowance-cfg-${field.ref}` : void 0
2898
+ },
2899
+ pick(field.label)
2900
+ ),
2901
+ editMode ? (0, import_react8.createElement)("input", {
2902
+ id: `dsh-allowance-cfg-${field.ref}`,
2903
+ className: "dsh-allowance-cfg-input",
2904
+ type: "password",
2905
+ autoComplete: "off",
2906
+ spellCheck: false,
2907
+ disabled: busy || info?.writable === false,
2908
+ value: drafts[field.ref] ?? "",
2909
+ onChange: (event) => setDrafts((previous) => ({ ...previous, [field.ref]: event.target.value }))
2910
+ }) : (
2911
+ // A stored record reads as text, not as a box that mimics the
2912
+ // entry form: the two states must be told apart at a glance.
2913
+ (0, import_react8.createElement)(
2914
+ "span",
2915
+ { className: "dsh-allowance-cfg-text" },
2916
+ typeof info?.masked === "string" && info.masked !== "" ? info.masked : "********"
2917
+ )
2918
+ )
2919
+ );
2920
+ };
2921
+ const renderGroup = (group) => {
2922
+ const allStored = group.fields.every((field) => infos?.[field.ref]?.configured === true);
2923
+ const editMode = !allStored || editing[group.id] === true;
2924
+ return (0, import_react8.createElement)(
2925
+ "section",
2926
+ { key: group.id, className: "dsh-allowance-cfg-card" },
2927
+ (0, import_react8.createElement)(
2928
+ "div",
2929
+ { className: "dsh-allowance-cfg-card-head" },
2930
+ (0, import_react8.createElement)("h3", { className: "dsh-allowance-cfg-card-title" }, pick(group.name)),
2931
+ // The stored state names itself, so the card reads as configured or
2932
+ // as a form to fill without reading any field.
2933
+ allStored ? (0, import_react8.createElement)("span", { className: "dsh-allowance-cfg-status" }, t("settings.configured")) : null
2934
+ ),
2935
+ group.docUrl ? (0, import_react8.createElement)(
2936
+ "a",
2937
+ {
2938
+ className: "dsh-allowance-cfg-link",
2939
+ href: group.docUrl,
2940
+ target: "_blank",
2941
+ rel: "noreferrer noopener"
2942
+ },
2943
+ `${group.docLabel ? pick(group.docLabel) : t("settings.doc")} \u2197`
2944
+ ) : null,
2945
+ group.fields.map((field) => renderField(field, editMode)),
2946
+ (0, import_react8.createElement)(
2947
+ "div",
2948
+ { className: "dsh-allowance-cfg-actions" },
2949
+ editMode ? (0, import_react8.createElement)(
2950
+ "button",
2951
+ {
2952
+ type: "button",
2953
+ className: "dsh-allowance-cfg-button",
2954
+ "data-tone": "primary",
2955
+ disabled: busy,
2956
+ onClick: () => void saveGroup(group)
2957
+ },
2958
+ busy ? t("settings.testing") : t("settings.save")
2959
+ ) : [
2960
+ (0, import_react8.createElement)(
2961
+ "button",
2962
+ {
2963
+ type: "button",
2964
+ key: "edit",
2965
+ className: "dsh-allowance-cfg-button",
2966
+ "data-tone": "secondary",
2967
+ disabled: busy,
2968
+ onClick: () => setEditing((previous) => ({ ...previous, [group.id]: true }))
2969
+ },
2970
+ t("settings.edit")
2971
+ ),
2972
+ (0, import_react8.createElement)(
2973
+ "button",
2974
+ {
2975
+ type: "button",
2976
+ key: "delete",
2977
+ className: "dsh-allowance-cfg-button",
2978
+ "data-tone": "secondary",
2979
+ disabled: busy,
2980
+ onClick: () => void deleteGroup(group)
2981
+ },
2982
+ t("settings.delete")
2983
+ )
2984
+ ],
2985
+ allStored && editMode ? (0, import_react8.createElement)(
2986
+ "button",
2987
+ {
2988
+ type: "button",
2989
+ className: "dsh-allowance-cfg-button",
2990
+ "data-tone": "secondary",
2991
+ disabled: busy,
2992
+ onClick: () => resetGroup(group)
2993
+ },
2994
+ t("settings.cancel")
2995
+ ) : null
2996
+ )
2997
+ );
2998
+ };
2999
+ return (0, import_react8.createElement)(
3000
+ React7.Fragment,
3001
+ null,
3002
+ // Component-local styles: React removes them with the component.
3003
+ (0, import_react8.createElement)("style", { key: "styles" }, STYLES2),
3004
+ (0, import_react8.createElement)(
3005
+ "div",
3006
+ { className: "dsh-allowance-cfg" },
3007
+ (0, import_react8.createElement)("h2", { className: "dsh-allowance-cfg-title" }, t("settings.title")),
3008
+ credentials === void 0 ? (0, import_react8.createElement)("p", { className: "dsh-allowance-cfg-error" }, t("settings.unavailable")) : infos === void 0 ? (0, import_react8.createElement)("p", { className: "dsh-allowance-cfg-hint" }, t("settings.loading")) : CREDENTIAL_GROUPS.map((group) => renderGroup(group)),
3009
+ notice === void 0 ? null : (0, import_react8.createElement)(
3010
+ "p",
3011
+ {
3012
+ key: "notice",
3013
+ role: "status",
3014
+ className: notice.tone === "error" ? "dsh-allowance-cfg-error" : "dsh-allowance-cfg-saved"
3015
+ },
3016
+ notice.text
3017
+ )
3018
+ )
3019
+ );
3020
+ }
3021
+
2597
3022
  // src/client/index.js
2598
3023
  var inject = ["slots", "locale", "remote"];
2599
3024
  function apply(ctx) {
@@ -2658,7 +3083,20 @@ function apply(ctx) {
2658
3083
  id: "model-allowance",
2659
3084
  order: 10
2660
3085
  },
2661
- (props) => (0, import_react8.createElement)(BalanceBadge, { ...props, ctx, t })
3086
+ (props) => (0, import_react9.createElement)(BalanceBadge, { ...props, ctx, t })
3087
+ )
3088
+ );
3089
+ const SECTION = "settings.section";
3090
+ ctx.slots.inject(
3091
+ SECTION,
3092
+ () => ctx.slots.register(
3093
+ {
3094
+ name: SECTION,
3095
+ id: "model-allowance",
3096
+ order: 30,
3097
+ label: () => t("settings.nav")
3098
+ },
3099
+ (props) => (0, import_react9.createElement)(CredentialsSection, { ...props, ctx, t })
2662
3100
  )
2663
3101
  );
2664
3102
  }
package/lib/balance.js CHANGED
@@ -542,6 +542,7 @@ export class BalanceService {
542
542
  status: 'unconfigured',
543
543
  kind: adapter.kind,
544
544
  consoleUrl: adapter.consoleUrl,
545
+ ...(adapter.setupUrl === undefined ? {} : { setupUrl: adapter.setupUrl }),
545
546
  }
546
547
  }
547
548
  // A reading is bounded by the request timeout alone. Cordis has no
@@ -563,8 +564,16 @@ export class BalanceService {
563
564
  })
564
565
  // The console link is a property of the route, not of the response, so
565
566
  // every reading carries it — including one that failed authorization and
566
- // is exactly when the user needs the way back to the console.
567
- return { ...view, consoleUrl: view.consoleUrl ?? adapter.consoleUrl, updatedAt: Date.now() }
567
+ // is exactly when the user needs the way back to the console. The setup
568
+ // guide rides the unconfigured reading, where the card links it.
569
+ return {
570
+ ...view,
571
+ consoleUrl: view.consoleUrl ?? adapter.consoleUrl,
572
+ ...(view.status === 'unconfigured' && adapter.setupUrl !== undefined
573
+ ? { setupUrl: adapter.setupUrl }
574
+ : {}),
575
+ updatedAt: Date.now(),
576
+ }
568
577
  } catch (error) {
569
578
  const reason = error instanceof Error ? error.message : String(error)
570
579
  // An aborted request is a cancellation, not a provider failure.
@@ -402,48 +402,6 @@ export const openrouterAdapters = [
402
402
  }),
403
403
  ]
404
404
 
405
- // ============================================================================
406
- // Qwen Token Plan
407
- // ============================================================================
408
- export const qwenTokenPlanAdapters = [
409
- placeholderAdapter({
410
- id: 'qwen-token-plan',
411
- routes: ['qwen-token-plan'],
412
- name: { zh: '通义千问 Token Plan', en: 'Qwen Token Plan' },
413
- color: '#082DFF',
414
- icon: 'qwen',
415
- consoleUrl: 'https://platform.qianwenai.com/home/analytics/token-plan/individual',
416
- }),
417
- ]
418
-
419
- // ============================================================================
420
- // Qwen Token Plan CN
421
- // ============================================================================
422
- export const qwenTokenPlanCnAdapters = [
423
- placeholderAdapter({
424
- id: 'qwen-token-plan-cn',
425
- routes: ['qwen-token-plan-cn'],
426
- name: { zh: '通义千问 Token Plan (国内)', en: 'Qwen Token Plan (CN)' },
427
- color: '#082DFF',
428
- icon: 'qwen',
429
- consoleUrl: 'https://platform.qianwenai.com/home/analytics/token-plan/individual',
430
- }),
431
- ]
432
-
433
- // ============================================================================
434
- // Qwen Token Plan Individual
435
- // ============================================================================
436
- export const qwenTokenPlanIndividualAdapters = [
437
- placeholderAdapter({
438
- id: 'qwen-token-plan-individual',
439
- routes: ['qwen-token-plan-individual'],
440
- name: { zh: '通义千问个人版', en: 'Qwen Token Plan Individual' },
441
- color: '#082DFF',
442
- icon: 'qwen',
443
- consoleUrl: 'https://platform.qianwenai.com/home/analytics/token-plan/individual',
444
- }),
445
- ]
446
-
447
405
  // ============================================================================
448
406
  // Radius
449
407
  // ============================================================================