dsh-packycode-api 1.0.1 → 1.0.4

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/lib/client.js CHANGED
@@ -106,12 +106,16 @@ window.__ModuleLoader__.load({
106
106
  refresh: "刷新",
107
107
  refreshing: "刷新中…",
108
108
  keysTitle: "API Key",
109
- keysHint: "按顺序使用:当前 Key 不可用时自动切到下一个可用 Key。上方的账户余额按 PackyCode 账户名逐条列出。",
109
+ keysHint: "按顺序使用:当前 Key 不可用时自动切到下一个可用 Key。上方的账户余额按备注名逐条列出,可用「重命名」修改备注。",
110
110
  keyActive: "使用中",
111
111
  keyDisabled: "已停用",
112
112
  keyUse: "切到此 Key",
113
113
  keyEnable: "重新启用",
114
114
  keyRemove: "删除",
115
+ keyRename: "重命名",
116
+ keyRenameSave: "保存",
117
+ keyRenameCancel: "取消",
118
+ keyRenamePlaceholder: "新的备注名",
115
119
  keyUnlimited: "不限额度",
116
120
  keyNoBalance: "余额未知",
117
121
  keyRemaining: "剩余",
@@ -159,7 +163,26 @@ window.__ModuleLoader__.load({
159
163
  cliNetwork: "下载失败,请检查网络或 npm 镜像设置后重试。",
160
164
  cliTimeout: "安装超时,请检查网络后重试。",
161
165
  cliNotFoundAfterInstall: "npm 显示安装完成,但仍找不到 claude 命令。请在终端执行 claude --version 确认,然后点「重新检测」。",
162
- cliWindowsNote: "Windows 上 Claude Code 还需要 Git for Windows(https://git-scm.com/downloads/win)。"
166
+ cliWindowsNote: "Windows 上 Claude Code 还需要 Git for Windows(https://git-scm.com/downloads/win)。",
167
+ versionTitle: "插件版本",
168
+ versionCurrent: "当前版本",
169
+ versionLatest: "最新版本",
170
+ versionCheck: "检查更新",
171
+ versionChecking: "正在检查更新…",
172
+ versionFailed: "无法检查最新版本。",
173
+ versionUpToDate: "已是最新版本。",
174
+ versionAvailable: "发现新版本 v{version}。",
175
+ versionLinked: "当前是本地开发安装,请在插件仓库拉取代码并重新构建。",
176
+ versionManual: "无法在这里更新。请在桌面应用的插件页重新安装 dsh-packycode-api。",
177
+ versionUpdate: "更新插件",
178
+ versionUpdating: "正在更新…",
179
+ versionUpdateFailed: "更新失败,请重试,或在插件页重新安装。",
180
+ versionUpdated: "已更新到 v{version}。",
181
+ versionUpdatedHint: "新版本需要完全退出并重新打开桌面应用才会生效;只刷新页面不会重载 Host 里的插件。",
182
+ versionRestart: "如何重启",
183
+ versionRestartHint: "插件无法安全地重启桌面应用。请完全退出 DSH,再重新打开。",
184
+ versionRefresh: "刷新界面",
185
+ versionLater: "稍后"
163
186
  };
164
187
  const en = {
165
188
  nav: "PackyCode",
@@ -173,12 +196,16 @@ window.__ModuleLoader__.load({
173
196
  refresh: "Refresh",
174
197
  refreshing: "Refreshing…",
175
198
  keysTitle: "API keys",
176
- keysHint: "Used in order: when the active key cannot serve a request, the next usable one takes over. The balances above are listed per PackyCode account.",
199
+ keysHint: "Used in order: when the active key cannot serve a request, the next usable one takes over. The balances above are listed by these names; use Rename to change one.",
177
200
  keyActive: "Active",
178
201
  keyDisabled: "Disabled",
179
202
  keyUse: "Use this key",
180
203
  keyEnable: "Re-enable",
181
204
  keyRemove: "Remove",
205
+ keyRename: "Rename",
206
+ keyRenameSave: "Save",
207
+ keyRenameCancel: "Cancel",
208
+ keyRenamePlaceholder: "New name",
182
209
  keyUnlimited: "No quota limit",
183
210
  keyNoBalance: "Balance unknown",
184
211
  keyRemaining: "Remaining",
@@ -226,7 +253,26 @@ window.__ModuleLoader__.load({
226
253
  cliNetwork: "The download failed. Check your network or npm registry settings and retry.",
227
254
  cliTimeout: "The install timed out. Check your network and retry.",
228
255
  cliNotFoundAfterInstall: "npm reported success, but the claude command still cannot be found. Run claude --version in a terminal, then click Check again.",
229
- cliWindowsNote: "On Windows, Claude Code also needs Git for Windows (https://git-scm.com/downloads/win)."
256
+ cliWindowsNote: "On Windows, Claude Code also needs Git for Windows (https://git-scm.com/downloads/win).",
257
+ versionTitle: "Plugin version",
258
+ versionCurrent: "Current version",
259
+ versionLatest: "Latest version",
260
+ versionCheck: "Check for updates",
261
+ versionChecking: "Checking for updates…",
262
+ versionFailed: "Could not check the latest version.",
263
+ versionUpToDate: "You are on the latest version.",
264
+ versionAvailable: "A new version v{version} is available.",
265
+ versionLinked: "Installed from a local checkout. Pull and rebuild the plugin repository instead.",
266
+ versionManual: "This install cannot be updated here. Reinstall dsh-packycode-api from the desktop Plugins page.",
267
+ versionUpdate: "Update plugin",
268
+ versionUpdating: "Updating…",
269
+ versionUpdateFailed: "The update failed. Try again, or reinstall from the Plugins page.",
270
+ versionUpdated: "Updated to v{version}.",
271
+ versionUpdatedHint: "Quit and reopen the desktop application. Refreshing the page does not reload the plugin inside the Host.",
272
+ versionRestart: "How to restart",
273
+ versionRestartHint: "The plugin cannot safely restart the desktop application. Quit DSH completely, then open it again.",
274
+ versionRefresh: "Refresh page",
275
+ versionLater: "Later"
230
276
  };
231
277
  const STYLE = `
232
278
  .packyCodeSection{display:flex;flex-direction:column;gap:16px;font-size:13px;line-height:20px}
@@ -261,6 +307,9 @@ window.__ModuleLoader__.load({
261
307
  .packyCodeWarning{color:var(--dsw-alias-state-warning-primary,#c27c0e);font-weight:500}
262
308
  .packyCodeDetail{margin:0;padding:8px 10px;border-radius:8px;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;white-space:pre-wrap;word-break:break-all;max-height:160px;overflow:auto}
263
309
  .packyCodeMono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;word-break:break-all}
310
+ .packyCodeVersionRows{display:flex;flex-direction:column;gap:6px}
311
+ .packyCodeVersionRow{display:flex;justify-content:space-between;gap:12px}
312
+ .packyCodeVersionValue{font-variant-numeric:tabular-nums;font-weight:600}
264
313
  .packyCodeComposer{display:inline-flex;align-items:center;flex:0 0 auto;height:28px;box-sizing:border-box;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:20px;font-weight:500;font-variant-numeric:tabular-nums;white-space:nowrap;user-select:none}
265
314
  @media(max-width:640px){.packyCodeRow{align-items:flex-start;flex-direction:column}.packyCodeActions{width:100%}}
266
315
  `;
@@ -443,6 +492,156 @@ window.__ModuleLoader__.load({
443
492
  ]
444
493
  });
445
494
  }
495
+ function VersionCard({ call, t }) {
496
+ const [info, setInfo] = react.useState();
497
+ const [loading, setLoading] = react.useState(true);
498
+ const [error, setError] = react.useState(false);
499
+ const [updating, setUpdating] = react.useState(false);
500
+ const [updateFailed, setUpdateFailed] = react.useState(false);
501
+ const [updated, setUpdated] = react.useState();
502
+ const [restartHint, setRestartHint] = react.useState(false);
503
+ const generation = react.useRef(0);
504
+ const load = (force) => {
505
+ const current = ++generation.current;
506
+ setLoading(true);
507
+ setError(false);
508
+ call("plugin/version", { force }).then((value) => {
509
+ if (generation.current === current) setInfo(value);
510
+ }).catch(() => {
511
+ if (generation.current === current) setError(true);
512
+ }).finally(() => {
513
+ if (generation.current === current) setLoading(false);
514
+ });
515
+ };
516
+ react.useEffect(() => {
517
+ load(false);
518
+ return () => {
519
+ generation.current += 1;
520
+ };
521
+ }, []);
522
+ const update = () => {
523
+ setUpdating(true);
524
+ setUpdateFailed(false);
525
+ call("plugin/update").then((value) => {
526
+ setUpdated(value);
527
+ setRestartHint(false);
528
+ }).catch(() => setUpdateFailed(true)).finally(() => setUpdating(false));
529
+ };
530
+ const installKind = info?.install?.kind;
531
+ const showStatus = info !== void 0 && updated === void 0;
532
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
533
+ className: "packyCodeCard",
534
+ children: [
535
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
536
+ className: "packyCodeCardHeader",
537
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
538
+ className: "packyCodeCardTitle",
539
+ children: t("versionTitle")
540
+ }), updated === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
541
+ type: "button",
542
+ className: "packyCodeButton",
543
+ disabled: loading || updating,
544
+ onClick: () => load(true),
545
+ children: loading ? t("versionChecking") : t("versionCheck")
546
+ })]
547
+ }),
548
+ loading && info === void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
549
+ className: "packyCodeNote",
550
+ role: "status",
551
+ children: t("versionChecking")
552
+ }),
553
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
554
+ className: "packyCodeError",
555
+ role: "alert",
556
+ children: t("versionFailed")
557
+ }),
558
+ info !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
559
+ className: "packyCodeVersionRows",
560
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
561
+ className: "packyCodeVersionRow",
562
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("versionCurrent") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
563
+ className: "packyCodeVersionValue",
564
+ children: ["v", info.current]
565
+ })]
566
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
567
+ className: "packyCodeVersionRow",
568
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("versionLatest") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
569
+ className: "packyCodeVersionValue",
570
+ children: ["v", info.latest]
571
+ })]
572
+ })]
573
+ }),
574
+ showStatus && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
575
+ className: "packyCodeNote",
576
+ role: "status",
577
+ children: info.updateAvailable ? t("versionAvailable").replace("{version}", info.latest) : t("versionUpToDate")
578
+ }),
579
+ showStatus && info.updateAvailable && installKind === "npm" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
580
+ className: "packyCodeActions",
581
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
582
+ type: "button",
583
+ className: "packyCodeButton packyCodeButtonPrimary",
584
+ disabled: updating,
585
+ onClick: update,
586
+ children: updating ? t("versionUpdating") : t("versionUpdate")
587
+ })
588
+ }),
589
+ showStatus && installKind === "link" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
590
+ className: "packyCodeNote",
591
+ children: t("versionLinked")
592
+ }),
593
+ showStatus && info.updateAvailable && installKind === "unknown" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
594
+ className: "packyCodeNote",
595
+ children: t("versionManual")
596
+ }),
597
+ updateFailed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
598
+ className: "packyCodeError",
599
+ role: "alert",
600
+ children: t("versionUpdateFailed")
601
+ }),
602
+ updated !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
603
+ role: "status",
604
+ children: [
605
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
606
+ className: "packyCodeNote",
607
+ children: t("versionUpdated").replace("{version}", updated.version)
608
+ }),
609
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
610
+ className: "packyCodeNote",
611
+ children: t("versionUpdatedHint")
612
+ }),
613
+ restartHint && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
614
+ className: "packyCodeNote",
615
+ children: t("versionRestartHint")
616
+ }),
617
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
618
+ className: "packyCodeActions",
619
+ children: [
620
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
621
+ type: "button",
622
+ className: "packyCodeButton",
623
+ onClick: () => setRestartHint(true),
624
+ children: t("versionRestart")
625
+ }),
626
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
627
+ type: "button",
628
+ className: "packyCodeButton packyCodeButtonPrimary",
629
+ onClick: () => window.location.reload(),
630
+ children: t("versionRefresh")
631
+ }),
632
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
633
+ type: "button",
634
+ className: "packyCodeButton",
635
+ onClick: () => setUpdated(void 0),
636
+ children: t("versionLater")
637
+ })
638
+ ]
639
+ })
640
+ ]
641
+ })
642
+ ]
643
+ });
644
+ }
446
645
  function PackyCodeSection({ rpc, t }) {
447
646
  const call = react.useMemo(() => (endpoint, payload = {}) => rpc.call(CHANNEL, endpoint, payload).then(unwrap), [rpc]);
448
647
  const [status, setStatus] = react.useState();
@@ -453,6 +652,7 @@ window.__ModuleLoader__.load({
453
652
  key: "",
454
653
  label: ""
455
654
  });
655
+ const [renaming, setRenaming] = react.useState();
456
656
  const generation = react.useRef(0);
457
657
  const load = react.useCallback((force = false) => {
458
658
  const current = ++generation.current;
@@ -493,6 +693,14 @@ window.__ModuleLoader__.load({
493
693
  label: ""
494
694
  }));
495
695
  };
696
+ const submitRename = (event) => {
697
+ event.preventDefault();
698
+ if (renaming === void 0 || renaming.label.trim() === "") return;
699
+ mutate("keys/rename")({
700
+ id: renaming.id,
701
+ label: renaming.label
702
+ }).then(() => setRenaming(void 0));
703
+ };
496
704
  const rows = balance?.keys ?? [];
497
705
  const usageOf = (id) => rows.find((row) => row.id === id);
498
706
  const keys = status?.keys ?? [];
@@ -506,6 +714,7 @@ window.__ModuleLoader__.load({
506
714
  usage?.limitUsd === void 0 ? void 0 : `${t("accountLimit")} ${formatUsd(usage.limitUsd)}`,
507
715
  resetLabel(usage?.resetPeriod, t) === void 0 ? void 0 : resetLabel(usage.resetPeriod, t)
508
716
  ].filter(Boolean);
717
+ const tokenName = usage?.name !== void 0 && usage.name !== row.label ? `${t("keyName")} ${usage.name}` : void 0;
509
718
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
510
719
  className: "packyCodeRow",
511
720
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
@@ -513,7 +722,7 @@ window.__ModuleLoader__.load({
513
722
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
514
723
  className: "packyCodeRowName",
515
724
  children: [
516
- usage?.name ?? row.label,
725
+ row.label,
517
726
  row.id === status?.activeId && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
518
727
  className: "packyCodeChip packyCodeChipActive",
519
728
  children: t("keyActive")
@@ -525,7 +734,7 @@ window.__ModuleLoader__.load({
525
734
  ]
526
735
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
527
736
  className: "packyCodeRowMeta",
528
- children: figures.length > 0 ? figures.join(" · ") : row.error === void 0 ? t("keyNoBalance") : `${t("loadFailed")}: ${row.error}`
737
+ children: figures.length > 0 ? [tokenName, ...figures].filter(Boolean).join(" · ") : row.error === void 0 ? t("keyNoBalance") : `${t("loadFailed")}: ${row.error}`
529
738
  })]
530
739
  })
531
740
  }, row.id);
@@ -537,6 +746,10 @@ window.__ModuleLoader__.load({
537
746
  className: "packyCodeIntro",
538
747
  children: t("intro")
539
748
  }),
749
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(VersionCard, {
750
+ call,
751
+ t
752
+ }),
540
753
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ClaudeCliCard, {
541
754
  call,
542
755
  t
@@ -638,7 +851,37 @@ window.__ModuleLoader__.load({
638
851
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
639
852
  className: "packyCodeRowName",
640
853
  children: [
641
- key.label,
854
+ renaming?.id === key.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
855
+ className: "packyCodeForm",
856
+ onSubmit: submitRename,
857
+ children: [
858
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
859
+ className: "packyCodeInput",
860
+ type: "text",
861
+ maxLength: 60,
862
+ autoFocus: true,
863
+ placeholder: t("keyRenamePlaceholder"),
864
+ value: renaming.label,
865
+ onChange: (event) => setRenaming({
866
+ id: key.id,
867
+ label: event.target.value
868
+ }),
869
+ onKeyDown: (event) => event.key === "Escape" && setRenaming(void 0)
870
+ }),
871
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
872
+ type: "submit",
873
+ className: "packyCodeButton",
874
+ disabled: busy || renaming.label.trim() === "",
875
+ children: t("keyRenameSave")
876
+ }),
877
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
878
+ type: "button",
879
+ className: "packyCodeButton",
880
+ onClick: () => setRenaming(void 0),
881
+ children: t("keyRenameCancel")
882
+ })
883
+ ]
884
+ }) : key.label,
642
885
  key.active && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
643
886
  className: "packyCodeChip packyCodeChipActive",
644
887
  children: t("keyActive")
@@ -669,6 +912,16 @@ window.__ModuleLoader__.load({
669
912
  onClick: () => mutate("keys/enable")({ id: key.id }),
670
913
  children: t("keyEnable")
671
914
  }),
915
+ renaming?.id !== key.id && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
916
+ type: "button",
917
+ className: "packyCodeButton",
918
+ disabled: busy,
919
+ onClick: () => setRenaming({
920
+ id: key.id,
921
+ label: key.label
922
+ }),
923
+ children: t("keyRename")
924
+ }),
672
925
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
673
926
  type: "button",
674
927
  className: "packyCodeButton",