dsh-sub2api 0.9.2 → 0.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.1
4
+
5
+ - **A key without a group is replaced instead of reused.** After the domain move
6
+ an account could hold a `dsh` key with no group; the plugin matched it by name,
7
+ reported "复用已有密钥" as a success, and then every request failed with 403
8
+ "API Key is not assigned to any group". The stale key is now deleted and a
9
+ grouped one created, so the login actually produces a working key.
10
+ - The check normalises `group_id: null` — the gateway sends null, not undefined,
11
+ and a bare `=== undefined` test would have missed exactly this case.
12
+
13
+ ## 0.10.0
14
+
15
+ - **The gateway and the pay centre moved.** Defaults are now
16
+ `https://sub.svpai.net` and `https://pay.svpai.net`. The old hosts
17
+ (`sub.pscly.cc`, `pay.pscly.cc`) no longer answer at all, so this is a required
18
+ migration, not a preference.
19
+ - **Existing installs follow automatically.** A profile that still names the old
20
+ host has it rewritten to the new one with the rest of the URL preserved — the
21
+ user does not have to find the setting. A self-hosted gateway is left
22
+ completely alone: only those two exact hosts are rewritten.
23
+ - The model cache records which gateway produced it and is ignored when that
24
+ changes, so a cache filled from the old host cannot keep offering a catalogue
25
+ the new one no longer serves.
26
+ - Registry rebuilt for the 52 models the gateway lists today, which brings the
27
+ measured windows for the whole gpt and deepseek families along with the Claude
28
+ entries the open registry knows (1,000,000).
29
+
3
30
  ## 0.9.2
4
31
 
5
32
  - README opens with what the plugin is and what installing it gets you, not with
@@ -382,7 +409,7 @@ something real.
382
409
 
383
410
  - Drop the manual-reconciliation copy. The recharge hint no longer promises a
384
411
  human review step, and the order-status wording says "正在确认到账" instead of
385
- "正在核账". The equivalent wording on pay.pscly.cc's checkout page and status
412
+ "正在核账". The equivalent wording on pay.svpai.net's checkout page and status
386
413
  payload was changed to match.
387
414
 
388
415
  ## 0.1.2
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-sub2api
2
2
 
3
- **Psapi 官方 DSH 插件**:在 DeepSeek Harness 里接入 Psapi AI 网关(`sub.pscly.cc`,网关内核为开源项目 [sub2api](https://github.com/Wei-Shaw/sub2api)),安装后即可开箱使用。
3
+ **Psapi 官方 DSH 插件**:在 DeepSeek Harness 里接入 Psapi AI 网关(`sub.svpai.net`,网关内核为开源项目 [sub2api](https://github.com/Wei-Shaw/sub2api)),安装后即可开箱使用。
4
4
 
5
5
  装完只需在 **设置 → dsh-sub2api** 填入一次邮箱和密码,其余全部自动完成:
6
6
 
@@ -198,15 +198,15 @@ Agent 工具(只读):`sub2api_status`、`sub2api_models`。模型可以回
198
198
  - id: llm-sub2api
199
199
  name: "dsh-sub2api"
200
200
  config:
201
- apiBase: "https://sub.pscly.cc"
202
- payBase: "https://pay.pscly.cc"
201
+ apiBase: "https://sub.svpai.net"
202
+ payBase: "https://pay.svpai.net"
203
203
  apiKeyEnv: SUB2API_API_KEY
204
204
  ```
205
205
 
206
206
  | 字段 | 默认值 | 说明 |
207
207
  |---|---|---|
208
- | `apiBase` | `https://sub.pscly.cc` | 中转站地址,末尾 `/v1` 会被去掉 |
209
- | `payBase` | `https://pay.pscly.cc` | 充值中转站地址 |
208
+ | `apiBase` | `https://sub.svpai.net` | 中转站地址,末尾 `/v1` 会被去掉 |
209
+ | `payBase` | `https://pay.svpai.net` | 充值中转站地址 |
210
210
  | `apiKeyEnv` | `SUB2API_API_KEY` | 存 API Key 的凭据引用名 |
211
211
  | `keyName` | `dsh` | 自动创建/复用的密钥名 |
212
212
  | `groupId` | 自动选择 | 强制指定密钥所属分组 |
@@ -369,7 +369,7 @@ llm-sub2api:
369
369
 
370
370
  ## 常见报错
371
371
 
372
- ### `https://sub.pscly.cc/v1 could not be reached or the connection dropped: fetch failed`
372
+ ### `https://sub.svpai.net/v1 could not be reached or the connection dropped: fetch failed`
373
373
 
374
374
  这是**传输层**的失败(不是网关返回的业务错误):TCP/TLS 连接没建立起来,或者建立后被对端断开。
375
375
 
package/lib/config.js CHANGED
@@ -56,13 +56,46 @@ export function field(config, key, fallback) {
56
56
  * announceToAgent: boolean,
57
57
  * }}
58
58
  */
59
+ /**
60
+ * Hosts this plugin used to ship with, and where they moved.
61
+ *
62
+ * A user who configured the plugin before the move has the old host written
63
+ * into their profile config, so changing the default alone would leave them
64
+ * pointing at a domain that no longer resolves. The old host is only rewritten
65
+ * when the configured value still names it — a self-hosted gateway is left
66
+ * completely alone.
67
+ * @type {Record<string, string>}
68
+ */
69
+ const MOVED_HOSTS = {
70
+ "sub.pscly.cc": "sub.svpai.net",
71
+ "pay.pscly.cc": "pay.svpai.net",
72
+ };
73
+
74
+ /**
75
+ * Follow a moved host, preserving the rest of the URL.
76
+ * @param {string} url
77
+ * @returns {string}
78
+ */
79
+ function followMovedHost(url) {
80
+ let parsed;
81
+ try {
82
+ parsed = new URL(url);
83
+ } catch {
84
+ return url;
85
+ }
86
+ const moved = MOVED_HOSTS[parsed.hostname.toLowerCase()];
87
+ if (moved === undefined) return url;
88
+ parsed.hostname = moved;
89
+ return parsed.toString().replace(/\/+$/, "");
90
+ }
91
+
59
92
  export function resolveConfig(config) {
60
93
  const dshHome = process.env.DSH_HOME ?? join(homedir(), ".dsh");
61
94
  const configuredKeyName = String(field(config, "keyName", "")).trim();
62
95
 
63
96
  return {
64
- apiBase: normalizeBaseUrl(field(config, "apiBase", "https://sub.pscly.cc")),
65
- payBase: normalizeBaseUrl(field(config, "payBase", "https://pay.pscly.cc")),
97
+ apiBase: followMovedHost(normalizeBaseUrl(field(config, "apiBase", "https://sub.svpai.net"))),
98
+ payBase: followMovedHost(normalizeBaseUrl(field(config, "payBase", "https://pay.svpai.net"))),
66
99
  apiKeyEnv: String(field(config, "apiKeyEnv", API_KEY_REF)),
67
100
  groupId: toPositiveInt(field(config, "groupId", undefined)),
68
101
  keyName: configuredKeyName === "" ? KEY_NAME : configuredKeyName,
package/lib/constants.js CHANGED
@@ -89,7 +89,7 @@ export const BUILTIN_MODEL = {
89
89
  };
90
90
 
91
91
  export const KNOWN_CONTEXT = [
92
- // Measured on sub.pscly.cc: 897,791 tokens accepted, 1,050,041 rejected with
92
+ // Measured on sub.svpai.net: 897,791 tokens accepted, 1,050,041 rejected with
93
93
  // "maximum context length is 1048576 tokens".
94
94
  { match: "deepseek-v4.1-flash", contextWindow: 1048576 },
95
95
  { match: "deepseek-flash", contextWindow: 1048576 },
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。用户在 设置 → dsh-sub2api 用一个邮箱和密码完成登录或注册,插件会自动在该账号下创建名为 dsh 的 API 密钥、写入本机凭据库,并同步上游模型目录,模型随后出现在模型选择器的 dsh-sub2api 分组里。余额、订阅进度与充值入口也在同一面板;充值走 pay.pscly.cc,点「去支付」会在新标签页打开。可用命令 /sub2api 查看状态。用户提到「sub2api / 中转站 / 我的网关 / 余额充值」时即指本插件。";
56
+ "本机已安装 dsh-sub2api 插件:它把 sub2api(sub.svpai.net)中转站接入 DSH。用户在 设置 → dsh-sub2api 用一个邮箱和密码完成登录或注册,插件会自动在该账号下创建名为 dsh 的 API 密钥、写入本机凭据库,并同步上游模型目录,模型随后出现在模型选择器的 dsh-sub2api 分组里。余额、订阅进度与充值入口也在同一面板;充值走 pay.svpai.net,点「去支付」会在新标签页打开。可用命令 /sub2api 查看状态。用户提到「sub2api / 中转站 / 我的网关 / 余额充值」时即指本插件。";
57
57
 
58
58
  /**
59
59
  * Mount the provider, panel routes and tools.
@@ -21,6 +21,13 @@
21
21
  */
22
22
  export const MODEL_REGISTRY = {
23
23
  "claude-haiku-5-5": { contextWindow: 1000000, source: "open" },
24
+ "claude-opus-4-7": { contextWindow: 1000000, source: "open" },
25
+ "claude-opus-4-8": { contextWindow: 1000000, source: "open" },
26
+ "claude-opus-5": { contextWindow: 1000000, source: "open" },
27
+ "claude-opus-5-5": { contextWindow: 1000000, source: "open" },
28
+ "claude-sonnet-4-6": { contextWindow: 1000000, source: "open" },
29
+ "claude-sonnet-5": { contextWindow: 1000000, source: "open" },
30
+ "claude-sonnet-5-5": { contextWindow: 1000000, source: "open" },
24
31
  "codex-auto-review": { contextWindow: 950272, source: "measured" },
25
32
  "deepseek-flash": { contextWindow: 1048576, source: "measured" },
26
33
  "deepseek-pro": { contextWindow: 1048576, source: "measured" },
@@ -96,10 +103,10 @@ export function registryFacts(id) {
96
103
  if (!lower.startsWith(name)) continue;
97
104
  const next = lower.charAt(name.length);
98
105
  // A prefix match must stop at a model boundary, not inside a version.
99
- // `glm-5` is not `glm-5.2`: a dot (or digit) after a known id that itself
100
- // ends in a digit is a version continuation, so the shorter id does not
101
- // describe the longer one. `.` stays a valid separator for namespaces such
102
- // as `zai-org.GLM`, which do not end in a digit.
106
+ // "glm-5" is not "glm-5.2": a dot or digit after a known id that itself ends
107
+ // in a digit is a version continuation, so the shorter id does not describe
108
+ // the longer one. A dot stays a valid separator for namespaces such as
109
+ // "zai-org.GLM", which do not end in a digit.
103
110
  if (next !== "") {
104
111
  const endsInDigit = /[0-9]$/.test(name);
105
112
  const versionish = next === "." || /[0-9]/.test(next);
package/lib/schema.js CHANGED
@@ -21,8 +21,8 @@ const text = (fallback, description) =>
21
21
  const count = (description) => z.natural().description(description).volatile();
22
22
 
23
23
  export const Config = z.object({
24
- apiBase: text("https://sub.pscly.cc", "中转站地址;末尾的 /v1 会被自动去掉"),
25
- payBase: text("https://pay.pscly.cc", "充值中转站地址(独立服务)"),
24
+ apiBase: text("https://sub.svpai.net", "中转站地址;末尾的 /v1 会被自动去掉"),
25
+ payBase: text("https://pay.svpai.net", "充值中转站地址(独立服务)"),
26
26
  apiKeyEnv: text(API_KEY_REF, "存放 API Key 的凭据引用名"),
27
27
  keyName: text(KEY_NAME, "自动创建/复用的密钥名称"),
28
28
  groupId: count("强制指定密钥所属分组;留空则跟随账号的默认分组"),
@@ -76,6 +76,12 @@ export class ModelCatalog {
76
76
  try {
77
77
  const text = await readFile(this.deps.cachePath(), "utf8");
78
78
  const parsed = JSON.parse(text);
79
+ const current = this.deps.apiBase?.() ?? "";
80
+ const cachedFor = typeof parsed?.base === "string" ? parsed.base : "";
81
+ if (cachedFor !== "" && current !== "" && cachedFor !== current) {
82
+ this.logger.info?.(`[sub2api] 缓存来自 ${cachedFor},与当前 ${current} 不符,忽略`);
83
+ return;
84
+ }
79
85
  if (Array.isArray(parsed?.models)) {
80
86
  this.models = parsed.models.filter(isModelRecord);
81
87
  this.fetchedAt = Number(parsed.fetchedAt) || 0;
@@ -375,7 +381,18 @@ export class ModelCatalog {
375
381
  await mkdir(dirname(path), { recursive: true });
376
382
  await writeFile(
377
383
  path,
378
- JSON.stringify({ fetchedAt: this.fetchedAt, models: this.models }, null, 0),
384
+ JSON.stringify(
385
+ {
386
+ fetchedAt: this.fetchedAt,
387
+ // A cache filled from a different gateway describes a different
388
+ // catalogue; using it would offer models the current one may not
389
+ // serve.
390
+ base: this.deps.apiBase?.() ?? "",
391
+ models: this.models,
392
+ },
393
+ null,
394
+ 0,
395
+ ),
379
396
  { mode: 0o600 },
380
397
  );
381
398
  } catch (error) {
@@ -55,9 +55,17 @@ export async function provisionAccount(deps) {
55
55
  );
56
56
 
57
57
  let key = existing?.key;
58
- let groupId = existing?.group_id ?? undefined;
58
+ // `?? undefined` normalises both null and undefined; the gateway sends null.
59
+ const rawGroup = existing?.group_id;
60
+ let groupId = rawGroup === null || rawGroup === undefined ? undefined : rawGroup;
59
61
 
60
- if (typeof key === "string" && key !== "") {
62
+ // A key that exists but carries no group is unusable: the gateway answers
63
+ // every request with 403 "API Key is not assigned to any group". Reusing it
64
+ // because the name matches would look like a successful login and fail on the
65
+ // first message, so an ungrouped key is treated as one that needs replacing.
66
+ const ungrouped = typeof key === "string" && key !== "" && groupId === undefined;
67
+
68
+ if (typeof key === "string" && key !== "" && !ungrouped) {
61
69
  steps.push(step("key", "API 密钥", true, `复用已有密钥 ${keyName}`));
62
70
  } else {
63
71
  const chosenGroup = chooseGroup({
@@ -65,6 +73,12 @@ export async function provisionAccount(deps) {
65
73
  groups,
66
74
  allowed: profile.ok ? profile.value?.allowed_groups : undefined,
67
75
  });
76
+ if (ungrouped) {
77
+ // Keep the account tidy: the old key cannot be used, and leaving it means
78
+ // the next login picks the same broken one again.
79
+ await attempt(() => api.deleteKey?.(accessToken, existing.id));
80
+ steps.push(step("key", "API 密钥", true, `已替换未分组的旧密钥 ${keyName}`));
81
+ }
68
82
  const created = await attempt(() =>
69
83
  api.createKey(accessToken, { name: keyName, groupId: chosenGroup }),
70
84
  );
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
- "查看 dsh-sub2api(sub.pscly.cc 中转站)在本机的接入状态:是否已登录、账号邮箱、余额、API 密钥是否已保存(只返回掩码)、订阅进度、已同步的模型数量。不会返回任何明文密钥。",
30
+ "查看 dsh-sub2api(sub.svpai.net 中转站)在本机的接入状态:是否已登录、账号邮箱、余额、API 密钥是否已保存(只返回掩码)、订阅进度、已同步的模型数量。不会返回任何明文密钥。",
31
31
  parameters: {},
32
32
  output: {
33
33
  schema: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sub2api",
3
- "version": "0.9.2",
3
+ "version": "0.10.1",
4
4
  "description": "Official Psapi provider for DeepSeek Harness: email sign-in or sign-up, automatic key and model provisioning, one panel for balance and recharge",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",