dsh-sub2api 0.4.0 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.2
4
+
5
+ Recharge and key handling, which are the two places where a mistake costs
6
+ something real.
7
+
8
+ - **Order countdown and recovery.** The pay centre expires an unpaid order after
9
+ 30 minutes; the panel now counts it down, says so in plain words when it runs
10
+ out, and offers "重新打开支付页" so a closed tab is not a lost order.
11
+ - **"去支付" cannot be double-clicked** into two tabs, and a failed status poll
12
+ now says so instead of quietly stopping.
13
+ - **Rebuilding the key takes two clicks.** It revokes the key DSH is using right
14
+ now, so it asks once — with the button turning red — and offers 取消.
15
+ - **A revealed key puts itself back behind the mask** after eight seconds; the
16
+ clipboard already has it.
17
+ - Model refresh failures surface as a toast instead of an unhandled rejection.
18
+ - Which sections you left open is remembered per browser, and toasts announce
19
+ themselves to screen readers.
20
+
21
+ ## 0.4.1
22
+
23
+ - The panel shows the site as **Psapi** instead of Sub2API, matching the
24
+ rebranded site. Internal identifiers are untouched: the provider id stays
25
+ `sub2api`, so existing sessions and model selections keep working.
26
+ - The account card no longer shows the concurrency limit.
27
+ - The pay-centre error matcher accepts either spelling, since the gateway and
28
+ the billing page are deployed separately and can drift.
29
+
3
30
  ## 0.4.0 — panel rebuilt around what people actually check
4
31
 
5
32
  - A status header answers "connected? funded? how many models?" in one line,
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # dsh-sub2api
2
2
 
3
- 把 [Sub2API](https://github.com/Wei-Shaw/sub2api) 中转站接进 DeepSeek Harness(DSH)。
3
+ 把自建的 **Psapi**(`sub.pscly.cc`,网关软件是开源的 [sub2api](https://github.com/Wei-Shaw/sub2api))接进 DeepSeek Harness(DSH)。
4
4
 
5
- 装完之后,在 **设置 → Sub2API** 里填一次邮箱和密码就能用:插件自己判断该登录还是注册,注册后自动创建名为 `dsh` 的 API 密钥、写进本机凭据库,并把上游模型同步进模型选择器。余额、用量、订阅、兑换码、充值和技术支持都在同一个面板里。
5
+ 装完之后,在 **设置 → Psapi** 里填一次邮箱和密码就能用:插件自己判断该登录还是注册,注册后自动创建名为 `dsh` 的 API 密钥、写进本机凭据库,并把上游模型同步进模型选择器。余额、用量、订阅、兑换码、充值和技术支持都在同一个面板里。
6
6
 
7
7
  ```
8
8
  npm: dsh-sub2api https://www.npmjs.com/package/dsh-sub2api
@@ -33,7 +33,7 @@ dsh plugin --profile web add dsh-sub2api
33
33
 
34
34
  也可以直接在 **插件 → 添加插件** 里搜 `dsh-sub2api`。
35
35
 
36
- 重启后打开 **设置 → Sub2API**。
36
+ 重启后打开 **设置 → Psapi**。
37
37
 
38
38
  ### 从 GitHub 装
39
39
 
@@ -96,7 +96,7 @@ dsh plugin add dsh-sub2api
96
96
 
97
97
  ### 账户
98
98
 
99
- 邮箱、余额、并发数、今日/累计用量,以及订阅进度条(日/周/月)。未登录时是登录表单:一个邮箱 + 一个密码 + 一个「继续」按钮。
99
+ 邮箱、余额、今日/累计用量,以及订阅进度条(日/周/月)。并发数不展示(站点侧也已对用户隐藏)。未登录时是登录表单:一个邮箱 + 一个密码 + 一个「继续」按钮。
100
100
 
101
101
  **一个表单两种结果**:先试登录,只有「凭据错误」才自动注册。所以
102
102
 
@@ -203,7 +203,7 @@ Agent 工具(只读):`sub2api_status`、`sub2api_models`。模型可以回
203
203
 
204
204
  ### 2. 余额为 0 拿不到模型,到账后自动同步
205
205
 
206
- Sub2API 的网关对 `/v1/models` 有余额门槛,零余额直接 `403 INSUFFICIENT_BALANCE`:
206
+ Psapi 的网关对 `/v1/models` 有余额门槛,零余额直接 `403 INSUFFICIENT_BALANCE`:
207
207
 
208
208
  ```
209
209
  [200] POST /api/v1/keys → 正常返回明文 key
package/lib/adapter.js CHANGED
@@ -87,7 +87,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
87
87
  connections: liveRef(() => [
88
88
  {
89
89
  id: PROVIDER,
90
- name: "Sub2API",
90
+ name: "Psapi",
91
91
  baseUrl: `${deps.apiBase()}/v1`,
92
92
  apiKeyRef: deps.apiKeyEnv(),
93
93
  },
@@ -95,7 +95,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
95
95
  llmRoutes: liveRef(() => [
96
96
  {
97
97
  id: PROVIDER,
98
- name: "Sub2API",
98
+ name: "Psapi",
99
99
  connection: PROVIDER,
100
100
  models: deps.catalog.llmModels(),
101
101
  maxCompletionTokens: false,
@@ -116,7 +116,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
116
116
  }
117
117
 
118
118
  providerInfo(provider) {
119
- return { id: provider, name: "Sub2API" };
119
+ return { id: provider, name: "Psapi" };
120
120
  }
121
121
 
122
122
  async listModels(provider) {
@@ -155,7 +155,7 @@ export class Sub2ApiAdapter extends LlmAdapter {
155
155
  // An empty `models` array still yields a route object; without this check
156
156
  // the transport would build a request with no model and fail at the wire.
157
157
  if (route === undefined || route.models.length === 0) {
158
- throw new Sub2ApiError("尚未同步到可用模型,请先在 Sub2API 面板登录或刷新模型", {
158
+ throw new Sub2ApiError("尚未同步到可用模型,请先在 Psapi 面板登录或刷新模型", {
159
159
  code: "no_models",
160
160
  });
161
161
  }
package/lib/client.js CHANGED
@@ -212,6 +212,8 @@ window.__ModuleLoader__.load({
212
212
  const variants = {
213
213
  primary: { border: "1px solid transparent", background: C.accent, color: "#fff" },
214
214
  ghost: { border: "0.5px solid transparent", background: "transparent", color: C.second },
215
+ // Destructive: rebuilding the key revokes the one in use.
216
+ danger: { border: "1px solid " + C.bad, background: "transparent", color: C.bad },
215
217
  };
216
218
  return h("button", { style: { ...base, ...(variants[variant] || {}), ...style }, ...rest }, children);
217
219
  }
@@ -357,7 +359,7 @@ window.__ModuleLoader__.load({
357
359
  }
358
360
  render() {
359
361
  if (this.state.error) {
360
- return h(Alert, { tone: "error", title: "Sub2API 面板渲染失败" },
362
+ return h(Alert, { tone: "error", title: "Psapi 面板渲染失败" },
361
363
  asText(this.state.error) || "未知错误",
362
364
  h("div", { style: { ...T.hint, marginTop: 6 } }, "把这段信息发给我即可定位。"));
363
365
  }
@@ -440,7 +442,11 @@ window.__ModuleLoader__.load({
440
442
 
441
443
  function Toasts({ items }) {
442
444
  if (items.length === 0) return null;
445
+ const worst = items.some((item) => item.tone === "error") ? "assertive" : "polite";
443
446
  return h("div", {
447
+ role: "status",
448
+ "aria-live": worst,
449
+ "aria-atomic": "false",
444
450
  style: {
445
451
  position: "sticky",
446
452
  top: 0,
@@ -472,6 +478,25 @@ window.__ModuleLoader__.load({
472
478
 
473
479
  // ----------------------------------------------------------- section
474
480
 
481
+ /**
482
+ * Which blocks the user left open, remembered per browser.
483
+ *
484
+ * The panel is reopened often and every block resets to the same default
485
+ * otherwise, which means scrolling past the ones you never look at.
486
+ */
487
+ const OPEN_KEY = "dsh-sub2api:sections";
488
+ const DEFAULT_OPEN = { models: true, recharge: false, account: false, key: false, diagnose: false };
489
+
490
+ function readOpenSections() {
491
+ try {
492
+ const raw = window.localStorage.getItem(OPEN_KEY);
493
+ const parsed = raw ? JSON.parse(raw) : null;
494
+ return parsed && typeof parsed === "object" ? { ...DEFAULT_OPEN, ...parsed } : DEFAULT_OPEN;
495
+ } catch {
496
+ return DEFAULT_OPEN;
497
+ }
498
+ }
499
+
475
500
  /** A titled block that can be folded away, so the page stays scannable. */
476
501
  function Collapsible({ title, meta, open, onToggle, children, id }) {
477
502
  return h("section", { id, style: T.card },
@@ -540,7 +565,7 @@ window.__ModuleLoader__.load({
540
565
  }),
541
566
  h("div", { style: { display: "flex", flexDirection: "column", gap: 1, minWidth: 0 } },
542
567
  h("span", { style: { fontSize: 13.5, fontWeight: 600, color: C.text, overflow: "hidden", textOverflow: "ellipsis" } },
543
- state.loggedIn ? (state.email || "已连接") : "未连接 Sub2API"),
568
+ state.loggedIn ? (state.email || "已连接") : "未连接 Psapi"),
544
569
  h("span", { style: T.hint },
545
570
  state.loggedIn
546
571
  ? models > 0
@@ -661,9 +686,7 @@ window.__ModuleLoader__.load({
661
686
  return h("div", null,
662
687
  h(Row, { label: "账号" }, state.email || "已登录"),
663
688
  h(Row, { label: "余额" }, money(profile.balance)),
664
- Number.isFinite(Number(profile.concurrency))
665
- ? h(Row, { label: "并发" }, String(profile.concurrency))
666
- : null,
689
+
667
690
  today || total || Number.isFinite(Number(requests))
668
691
  ? h(Row, { label: "用量" },
669
692
  [today ? `今日 ${today}` : null, total ? `累计 ${total}` : null,
@@ -691,6 +714,10 @@ window.__ModuleLoader__.load({
691
714
 
692
715
  function KeyDetail({ state, pending, onCreate, onReveal }) {
693
716
  const [revealed, setRevealed] = useState("");
717
+ const [confirming, setConfirming] = useState(false);
718
+ const hideTimer = useRef(null);
719
+
720
+ useEffect(() => () => { if (hideTimer.current) clearTimeout(hideTimer.current); }, []);
694
721
 
695
722
  const copy = async () => {
696
723
  try {
@@ -698,11 +725,25 @@ window.__ModuleLoader__.load({
698
725
  setRevealed(text);
699
726
  if (text) await navigator.clipboard.writeText(text);
700
727
  toastStore.push("密钥已复制");
728
+ // Put the mask back: a plaintext key left on screen is a screenshot away
729
+ // from leaking, and the clipboard already has it.
730
+ if (hideTimer.current) clearTimeout(hideTimer.current);
731
+ hideTimer.current = setTimeout(() => setRevealed(""), 8000);
701
732
  } catch {
702
733
  toastStore.push("复制失败,请手动选择", "error");
703
734
  }
704
735
  };
705
736
 
737
+ // Rebuilding revokes the key DSH is using right now, so it takes two clicks.
738
+ const rebuild = async () => {
739
+ if (!confirming) {
740
+ setConfirming(true);
741
+ return;
742
+ }
743
+ setConfirming(false);
744
+ await onCreate();
745
+ };
746
+
706
747
  return h("div", null,
707
748
  h("div", { style: T.row },
708
749
  h("code", {
@@ -720,8 +761,22 @@ window.__ModuleLoader__.load({
720
761
  },
721
762
  }, revealed || state.keyMasked || "尚未创建"),
722
763
  h(Button, { onClick: copy, disabled: !state.hasKey }, "复制"),
723
- h(Button, { onClick: onCreate, disabled: pending.key },
724
- pending.key ? "处理中…" : state.hasKey ? "重建" : "创建"),
764
+ h(Button, {
765
+ onClick: rebuild,
766
+ disabled: pending.key,
767
+ variant: confirming && state.hasKey ? "danger" : "default",
768
+ title: confirming ? "再点一次将作废旧密钥" : undefined,
769
+ },
770
+ pending.key
771
+ ? "处理中…"
772
+ : !state.hasKey
773
+ ? "创建"
774
+ : confirming
775
+ ? "确认重建"
776
+ : "重建"),
777
+ confirming
778
+ ? h(Button, { variant: "ghost", onClick: () => setConfirming(false) }, "取消")
779
+ : null,
725
780
  ),
726
781
  h("div", { style: { ...T.hint, marginTop: 10 } },
727
782
  "密钥固定命名为 ", h("code", { style: T.mono }, state.keyName || "dsh"),
@@ -733,6 +788,16 @@ window.__ModuleLoader__.load({
733
788
 
734
789
  const PRESETS = [10, 20, 50, 100];
735
790
 
791
+ /** How long the pay centre keeps an unpaid order open. */
792
+ const ORDER_TTL_MS = 30 * 60 * 1000;
793
+
794
+ function mmss(ms) {
795
+ const total = Math.max(0, Math.floor(ms / 1000));
796
+ const m = Math.floor(total / 60);
797
+ const sec = total % 60;
798
+ return `${m}:${String(sec).padStart(2, "0")}`;
799
+ }
800
+
736
801
  function RechargeDetail({ state, pending, onRecharge, onPoll, onRefresh, onRedeem }) {
737
802
  const [amount, setAmount] = useState(20);
738
803
  const [custom, setCustom] = useState("");
@@ -740,14 +805,28 @@ window.__ModuleLoader__.load({
740
805
  const [status, setStatus] = useState(null);
741
806
  const [code, setCode] = useState("");
742
807
  const [showRedeem, setShowRedeem] = useState(false);
808
+ const [opening, setOpening] = useState(false);
809
+ const [now, setNow] = useState(() => Date.now());
743
810
  const timer = useRef(null);
744
811
 
745
812
  const multiplier = Number(state.rechargeMultiplier) > 0 ? Number(state.rechargeMultiplier) : 2;
746
813
  const value = custom !== "" ? Number(custom) : amount;
747
814
  const credit = Number.isFinite(value) ? value * multiplier : 0;
748
815
 
816
+ // An order expires in 30 minutes; showing the clock beats leaving the user
817
+ // staring at "等待付款…" that will never resolve.
749
818
  useEffect(() => {
750
819
  if (!order) return undefined;
820
+ const tick = setInterval(() => setNow(Date.now()), 1000);
821
+ return () => clearInterval(tick);
822
+ }, [order]);
823
+
824
+ const expiresAt = order && order.createdAt ? order.createdAt + ORDER_TTL_MS : null;
825
+ const leftMs = expiresAt === null ? null : expiresAt - now;
826
+ const expired = leftMs !== null && leftMs <= 0;
827
+
828
+ useEffect(() => {
829
+ if (!order || expired) return undefined;
751
830
  timer.current = setInterval(async () => {
752
831
  try {
753
832
  const result = await onPoll(order.orderNo);
@@ -760,28 +839,42 @@ window.__ModuleLoader__.load({
760
839
  await onRefresh();
761
840
  }
762
841
  }
763
- } catch {
842
+ } catch (e) {
764
843
  clearInterval(timer.current);
765
844
  timer.current = null;
845
+ toastStore.push(
846
+ "查询订单失败:" + (e instanceof Error ? e.message : String(e)) + ";可点「刷新」看余额",
847
+ "error",
848
+ );
766
849
  }
767
850
  }, 5000);
768
851
  return () => { if (timer.current) clearInterval(timer.current); };
769
- }, [order, onPoll, onRefresh]);
852
+ }, [order, onPoll, onRefresh, expired]);
770
853
 
771
854
  const start = async () => {
855
+ if (opening) return;
772
856
  const tab = window.open("", "_blank");
857
+ setOpening(true);
773
858
  try {
774
859
  const data = await onRecharge(value);
775
860
  const target = data.checkoutUrl || data.url;
776
861
  if (tab) tab.location.href = target;
777
862
  else window.open(target, "_blank", "noopener");
778
- if (data.orderNo) setOrder(data);
863
+ if (data.orderNo) setOrder({ ...data, createdAt: Date.now() });
779
864
  } catch (e) {
780
865
  if (tab) tab.close();
781
866
  toastStore.push(e instanceof Error ? e.message : String(e), "error");
867
+ } finally {
868
+ setOpening(false);
782
869
  }
783
870
  };
784
871
 
872
+ const reopen = () => {
873
+ const target = order && (order.checkoutUrl || order.url);
874
+ if (target) window.open(target, "_blank", "noopener");
875
+ else toastStore.push("没有可用的支付链接,请重新下单", "error");
876
+ };
877
+
785
878
  const redeem = async () => {
786
879
  try {
787
880
  const result = await onRedeem(code.trim());
@@ -824,16 +917,30 @@ window.__ModuleLoader__.load({
824
917
  h(Button, {
825
918
  variant: "primary",
826
919
  onClick: start,
827
- disabled: !state.loggedIn || !Number.isFinite(value) || value <= 0,
828
- }, "去支付"),
920
+ disabled: !state.loggedIn || !Number.isFinite(value) || value <= 0 || opening,
921
+ }, opening ? "正在下单…" : "去支付"),
829
922
  ),
830
923
  ),
831
924
  order
832
925
  ? h("div", { style: { marginTop: 12 } },
833
926
  h(Alert, {
834
- tone: status ? (status.tone === "done" ? "ok" : status.tone === "error" ? "error" : "info") : "info",
835
- title: "订单 " + order.orderNo,
836
- }, status ? status.text : "已打开支付页,等待付款…"))
927
+ tone: expired
928
+ ? "warn"
929
+ : status
930
+ ? status.tone === "done" ? "ok" : status.tone === "error" ? "error" : "info"
931
+ : "info",
932
+ title: "订单 " + order.orderNo + (leftMs !== null && !expired ? ` · 剩余 ${mmss(leftMs)}` : ""),
933
+ action: h(Button, {
934
+ size: "sm",
935
+ onClick: reopen,
936
+ style: { color: "inherit", borderColor: "currentColor", background: "transparent" },
937
+ }, expired ? "重新下单" : "重新打开支付页"),
938
+ },
939
+ expired
940
+ ? "订单已过 30 分钟有效期,没有支付的话已经作废,重新下单即可。"
941
+ : status
942
+ ? status.text
943
+ : "已打开支付页,等待付款…到账后余额会自动更新,这页不用守着。"))
837
944
  : null,
838
945
  h("div", { style: { marginTop: 12, display: "flex", gap: 8, alignItems: "center" } },
839
946
  h(Button, {
@@ -996,7 +1103,7 @@ window.__ModuleLoader__.load({
996
1103
  style: { color: "inherit", borderColor: "currentColor", background: "transparent" },
997
1104
  }, "去充值"),
998
1105
  },
999
- "Sub2API 在余额为 0 时会拒绝 /v1/models;充值到账后自动同步。"));
1106
+ "Psapi 在余额为 0 时会拒绝 /v1/models;充值到账后自动同步。"));
1000
1107
  }
1001
1108
 
1002
1109
  if (everything.length === 0) {
@@ -1015,8 +1122,17 @@ window.__ModuleLoader__.load({
1015
1122
  h("span", { style: { ...T.small, fontWeight: 500 } },
1016
1123
  showingAll && !dirty ? `全部 ${everything.length} 个` : `已选 ${checked.length} / ${everything.length}`),
1017
1124
  h("div", { style: { marginLeft: "auto", display: "flex", gap: 8 } },
1018
- h(Button, { size: "sm", onClick: onRefreshModels, disabled: pending.models },
1019
- pending.models ? "同步中…" : "刷新"),
1125
+ h(Button, {
1126
+ size: "sm",
1127
+ onClick: async () => {
1128
+ try {
1129
+ await onRefreshModels();
1130
+ } catch (e) {
1131
+ toastStore.push(e instanceof Error ? e.message : String(e), "error");
1132
+ }
1133
+ },
1134
+ disabled: pending.models,
1135
+ }, pending.models ? "同步中…" : "刷新"),
1020
1136
  h(Button, { size: "sm", onClick: () => setExpanded((v) => !v) },
1021
1137
  expanded ? "收起" : "管理"),
1022
1138
  ),
@@ -1117,7 +1233,15 @@ window.__ModuleLoader__.load({
1117
1233
  const [steps, setSteps] = useState(null);
1118
1234
  const [ready, setReady] = useState(undefined);
1119
1235
  const [announcements, setAnnouncements] = useState([]);
1120
- const [open, setOpen] = useState({ models: true, recharge: false, account: false, key: false, diagnose: false });
1236
+ const [open, setOpen] = useState(readOpenSections);
1237
+
1238
+ useEffect(() => {
1239
+ try {
1240
+ window.localStorage.setItem(OPEN_KEY, JSON.stringify(open));
1241
+ } catch {
1242
+ // Private mode or a full quota: folding still works, it just forgets.
1243
+ }
1244
+ }, [open]);
1121
1245
 
1122
1246
  const setBusy = (key, value) => setPending((prev) => ({ ...prev, [key]: value }));
1123
1247
  const run = useCallback(async (key, fn) => {
@@ -1210,7 +1334,7 @@ window.__ModuleLoader__.load({
1210
1334
  const failure = error || "";
1211
1335
  if (failure) {
1212
1336
  return h("div", { style: { padding: "4px 0 18px" } },
1213
- h(Card, { title: "Sub2API" },
1337
+ h(Card, { title: "Psapi" },
1214
1338
  h(Alert, { tone: "error", title: "面板无法连接插件后端" }, failure),
1215
1339
  h("div", { style: { ...T.hint, marginTop: 12 } },
1216
1340
  "常见原因:插件装上了但宿主那一半没有加载(版本不匹配、依赖缺失、或安装后没有重启)。"),
@@ -1358,7 +1482,7 @@ window.__ModuleLoader__.load({
1358
1482
  return h("button", {
1359
1483
  type: "button",
1360
1484
  title: detail,
1361
- "aria-label": `Sub2API ${known ? "余额 " + money(balance) : "余额未知"},点击${low ? "去充值" : "刷新"}`,
1485
+ "aria-label": `Psapi ${known ? "余额 " + money(balance) : "余额未知"},点击${low ? "去充值" : "刷新"}`,
1362
1486
  onClick,
1363
1487
  style: {
1364
1488
  display: "inline-flex",
@@ -1396,7 +1520,7 @@ window.__ModuleLoader__.load({
1396
1520
  },
1397
1521
  });
1398
1522
  return h("div", { style: { padding: "4px 0 18px" } },
1399
- h(Card, { title: "Sub2API" },
1523
+ h(Card, { title: "Psapi" },
1400
1524
  bar("40%", 14),
1401
1525
  h("div", { style: { height: 10 } }),
1402
1526
  bar("70%", 12),
@@ -1425,7 +1549,7 @@ window.__ModuleLoader__.load({
1425
1549
  lineHeight: "18px",
1426
1550
  },
1427
1551
  },
1428
- h("span", { style: { fontWeight: 600, color: C.text } }, "Sub2API"),
1552
+ h("span", { style: { fontWeight: 600, color: C.text } }, "Psapi"),
1429
1553
  h("span", { style: { marginLeft: "auto", color: low ? C.bad : C.muted } },
1430
1554
  Number.isFinite(balance) ? (low ? "余额不足" : money(balance)) : "已登录"),
1431
1555
  );
@@ -1439,7 +1563,7 @@ window.__ModuleLoader__.load({
1439
1563
  try {
1440
1564
  ctx.slots.inject("settings.section", () =>
1441
1565
  ctx.slots.register(
1442
- { name: "settings.section", id: "sub2api", order: 300, label: () => "Sub2API" },
1566
+ { name: "settings.section", id: "sub2api", order: 300, label: () => "Psapi" },
1443
1567
  Section,
1444
1568
  ),
1445
1569
  );
@@ -1469,6 +1593,8 @@ window.__ModuleLoader__.load({
1469
1593
  exports.inject = inject;
1470
1594
  exports.Section = Section;
1471
1595
  exports.BalanceBadge = BalanceBadge;
1596
+ // Exposed for the load test: pure read/write of the remembered layout.
1597
+ exports.__sections = { readOpenSections, DEFAULT_OPEN, OPEN_KEY };
1472
1598
  return module.exports;
1473
1599
  },
1474
1600
  });
package/lib/commands.js CHANGED
@@ -27,7 +27,7 @@ const HELP = [
27
27
  export function commandDefinition(deps) {
28
28
  return {
29
29
  name: "sub2api",
30
- description: "Sub2API 中转站:账号、密钥、余额与可用模型",
30
+ description: "Psapi 中转站:账号、密钥、余额与可用模型",
31
31
  input: { hint: "[status|models|balance|recharge]" },
32
32
  handler: async (invocation) => {
33
33
  const verb = String(invocation?.rawInput ?? "").trim().split(/\s+/)[0]?.toLowerCase() ?? "";
@@ -42,7 +42,7 @@ export function commandDefinition(deps) {
42
42
  } catch (error) {
43
43
  return {
44
44
  kind: "error",
45
- text: `Sub2API:${error instanceof Error ? error.message : String(error)}`,
45
+ text: `Psapi:${error instanceof Error ? error.message : String(error)}`,
46
46
  };
47
47
  }
48
48
  },
@@ -67,8 +67,8 @@ async function statusText(deps) {
67
67
 
68
68
  if (session === undefined) {
69
69
  return [
70
- "Sub2API:尚未登录。",
71
- `在 DSH 的 设置 → Sub2API 里用一个邮箱和密码登录或注册即可(${deps.cfg().apiBase})。`,
70
+ "Psapi:尚未登录。",
71
+ `在 DSH 的 设置 → Psapi 里用一个邮箱和密码登录或注册即可(${deps.cfg().apiBase})。`,
72
72
  ].join("\n");
73
73
  }
74
74
 
@@ -77,7 +77,7 @@ async function statusText(deps) {
77
77
  const models = deps.catalog.visible();
78
78
 
79
79
  const lines = [
80
- `Sub2API · ${deps.cfg().apiBase}`,
80
+ `Psapi · ${deps.cfg().apiBase}`,
81
81
  `账号   ${profile?.email ?? session.email ?? "已登录"}`,
82
82
  `余额   ${money(profile?.balance)}`,
83
83
  `密钥   ${apiKey ? maskSecret(apiKey) : "尚未创建"}`,
@@ -126,7 +126,7 @@ async function modelsText(deps) {
126
126
  const reason = deps.catalog.lastError?.message;
127
127
  return reason
128
128
  ? `没有可用模型:${reason}`
129
- : "没有可用模型。登录后在 设置 → Sub2API 里点「刷新模型」。";
129
+ : "没有可用模型。登录后在 设置 → Psapi 里点「刷新模型」。";
130
130
  }
131
131
  const lines = models.map((model) => {
132
132
  const bits = [`${Math.round((model.contextWindow ?? 0) / 1000)}k`];
package/lib/constants.js CHANGED
@@ -47,7 +47,7 @@ export const TOKEN_REFRESH_LEAD_MS = 60 * 1000;
47
47
  export const KEY_PAGE_SIZE = 100;
48
48
 
49
49
  /**
50
- * Currency of every amount this plugin shows. Sub2API quotes quota in yuan and
50
+ * Currency of every amount this plugin shows. Psapi quotes quota in yuan and
51
51
  * treats one quota unit as one yuan ("1 额度 = 1 元"), so the panel never uses a
52
52
  * foreign-currency figure.
53
53
  */
package/lib/index.js CHANGED
@@ -53,7 +53,7 @@ export const VERSION = (() => {
53
53
  const SECTION_ORDER = 172;
54
54
 
55
55
  const GUIDANCE =
56
- "本机已安装 dsh-sub2api 插件:它把 sub2api(sub.pscly.cc)中转站接入 DSH。用户在 设置 → Sub2API 用一个邮箱和密码完成登录或注册,插件会自动在该账号下创建名为 dsh 的 API 密钥、写入本机凭据库,并同步上游模型目录,模型随后出现在模型选择器的 Sub2API 分组里。余额、订阅进度与充值入口也在同一面板;充值走 pay.pscly.cc,点「去支付」会在新标签页打开。可用命令 /sub2api 查看状态。用户提到「sub2api / 中转站 / 我的网关 / 余额充值」时即指本插件。";
56
+ "本机已安装 dsh-sub2api 插件:它把 sub2api(sub.pscly.cc)中转站接入 DSH。用户在 设置 → Psapi 用一个邮箱和密码完成登录或注册,插件会自动在该账号下创建名为 dsh 的 API 密钥、写入本机凭据库,并同步上游模型目录,模型随后出现在模型选择器的 Psapi 分组里。余额、订阅进度与充值入口也在同一面板;充值走 pay.pscly.cc,点「去支付」会在新标签页打开。可用命令 /sub2api 查看状态。用户提到「sub2api / 中转站 / 我的网关 / 余额充值」时即指本插件。";
57
57
 
58
58
  /**
59
59
  * Mount the provider, panel routes and tools.
@@ -152,7 +152,7 @@ export function apply(ctx, rawConfig = {}) {
152
152
  const providers = llmCtx.llm.registerConfigurableProviders([
153
153
  {
154
154
  provider: PROVIDER,
155
- displayName: "Sub2API",
155
+ displayName: "Psapi",
156
156
  settingsNs: SETTINGS_NS,
157
157
  settingsPath: [],
158
158
  },
package/lib/pay.js CHANGED
@@ -235,7 +235,11 @@ async function payFailureMessage(response, fallback) {
235
235
  .replace(/<[^>]+>/g, " ")
236
236
  .replace(/\s+/g, " ")
237
237
  .trim();
238
- const known = visible.match(/(缺少 Sub2API 用户上下文|Sub2API 用户校验失败[^ ]*|Sub2API 用户身份不匹配)/);
238
+ // The pay centre spells the site name its own way; accept either, because the
239
+ // two services are deployed separately and their wording can drift.
240
+ const known = visible.match(
241
+ /(缺少 (?:Psapi|Sub2API) 用户上下文|(?:Psapi|Sub2API) 用户校验失败[^ ]*|(?:Psapi|Sub2API) 用户身份不匹配)/,
242
+ );
239
243
  if (known) return known[0];
240
244
  if (response.status === 403) return `${fallback}:登录状态已失效(403)`;
241
245
  if (response.status === 419) return `${fallback}:支付页会话过期(419)`;
@@ -94,7 +94,7 @@ export function isEmailTaken(error) {
94
94
  /** Re-word a transport failure so the panel can say something actionable. */
95
95
  function translateLogin(error) {
96
96
  if (error instanceof Sub2ApiError && error.code === "network") {
97
- return new Sub2ApiError("连不上 Sub2API,请检查网络或服务地址", { code: "network" });
97
+ return new Sub2ApiError("连不上 Psapi,请检查网络或服务地址", { code: "network" });
98
98
  }
99
99
  return error;
100
100
  }
@@ -84,7 +84,7 @@ export class SessionStore {
84
84
  async accessToken(signal) {
85
85
  const session = await this.read();
86
86
  if (session === undefined) {
87
- throw new Sub2ApiError("尚未登录 Sub2API", { code: "not_logged_in" });
87
+ throw new Sub2ApiError("尚未登录 Psapi", { code: "not_logged_in" });
88
88
  }
89
89
  if (session.expiresAt > Date.now() + TOKEN_REFRESH_LEAD_MS || !session.refreshToken) {
90
90
  return session.accessToken;
package/lib/tools.js CHANGED
@@ -27,7 +27,7 @@ function statusTool(deps) {
27
27
  return defineTool({
28
28
  name: "sub2api_status",
29
29
  description:
30
- "查看 Sub2API(sub.pscly.cc 中转站)在本机的接入状态:是否已登录、账号邮箱、余额、API 密钥是否已保存(只返回掩码)、订阅进度、已同步的模型数量。不会返回任何明文密钥。",
30
+ "查看 Psapi(sub.pscly.cc 中转站)在本机的接入状态:是否已登录、账号邮箱、余额、API 密钥是否已保存(只返回掩码)、订阅进度、已同步的模型数量。不会返回任何明文密钥。",
31
31
  parameters: {},
32
32
  output: {
33
33
  schema: {
@@ -55,7 +55,7 @@ function statusTool(deps) {
55
55
  if (stored === undefined) {
56
56
  return {
57
57
  ok: false,
58
- message: `尚未登录 Sub2API。请让用户在 DSH 的 设置 → Sub2API 面板用一个邮箱和密码完成登录或注册(插件会自动创建名为 dsh 的密钥)。站点:${deps.cfg().apiBase}`,
58
+ message: `尚未登录 Psapi。请让用户在 DSH 的 设置 → Psapi 面板用一个邮箱和密码完成登录或注册(插件会自动创建名为 dsh 的密钥)。站点:${deps.cfg().apiBase}`,
59
59
  loggedIn: false,
60
60
  hasKey: false,
61
61
  modelCount: deps.catalog.visible().length,
@@ -93,7 +93,7 @@ function modelsTool(deps) {
93
93
  return defineTool({
94
94
  name: "sub2api_models",
95
95
  description:
96
- "列出 Sub2API 中转站当前可用的模型 id(来自上游 /v1/models,与模型选择器一致)。需要先登录。返回 id、显示名、上下文窗口与是否支持图片。",
96
+ "列出 Psapi 中转站当前可用的模型 id(来自上游 /v1/models,与模型选择器一致)。需要先登录。返回 id、显示名、上下文窗口与是否支持图片。",
97
97
  parameters: {
98
98
  limit: {
99
99
  type: "number",
@@ -133,7 +133,7 @@ function modelsTool(deps) {
133
133
  if (models.length === 0) {
134
134
  return {
135
135
  ok: false,
136
- message: "还没有同步到任何模型。请在 设置 → Sub2API 面板登录后点「刷新模型」。",
136
+ message: "还没有同步到任何模型。请在 设置 → Psapi 面板登录后点「刷新模型」。",
137
137
  count: 0,
138
138
  models: [],
139
139
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-sub2api",
3
- "version": "0.4.0",
4
- "description": "Sub2API provider for DeepSeek Harness: zero-friction signup, auto-provisioned API key, upstream model sync, balance and recharge",
3
+ "version": "0.4.2",
4
+ "description": "Psapi (sub.pscly.cc) provider for DeepSeek Harness: zero-friction signup, auto-provisioned API key, upstream model sync, balance and recharge",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",
7
7
  "main": "./lib/index.js",
@@ -60,7 +60,7 @@
60
60
  "dsh",
61
61
  "dsh-plugin",
62
62
  "deepseek-harness",
63
- "sub2api",
63
+ "psapi",
64
64
  "provider",
65
65
  "llm",
66
66
  "relay",