dsh-zcode-startplan 0.4.5 → 1.0.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 +1963 -405
- package/README.md +88 -405
- package/bin/cli.mjs +509 -450
- package/client.js +2459 -716
- package/cordis.patch.yml +4 -2
- package/index.js +144 -14
- package/lib/adapter.js +476 -422
- package/lib/anthropic-body.js +513 -469
- package/lib/assemble.js +808 -420
- package/lib/auto-claim.js +229 -0
- package/lib/captcha/minter.js +61 -7
- package/lib/distribution-keys.js +202 -0
- package/lib/errors.js +281 -125
- package/lib/fallback.js +120 -0
- package/lib/local-endpoint.js +367 -352
- package/lib/manage-routes.js +1245 -489
- package/lib/model-catalog.js +57 -0
- package/lib/openai-gateway.js +776 -0
- package/lib/plan-client.js +942 -532
- package/lib/pool.js +771 -478
- package/lib/sse.js +429 -317
- package/lib/upstream-api.js +948 -570
- package/lib/upstream.js +294 -134
- package/lib/version-probe.js +110 -0
- package/package.json +84 -80
- package/scripts/analyze-grant-intervals.mjs +171 -0
- package/scripts/check-compat-rc3.mjs +21 -11
- package/scripts/debug-claimable.mjs +130 -0
- package/scripts/probe-marketing.mjs +203 -0
- package/scripts/restart-dsh.ps1 +119 -76
- package/scripts/test-claimed-pending.mjs +152 -0
- package/scripts/verify_compat.mjs +75 -64
- package/scripts/watch-marketing.mjs +155 -0
- package/tests/anthropic-body.test.mjs +305 -0
- package/tests/assembler-contract.test.mjs +256 -0
- package/tests/auto-claim.test.mjs +318 -0
- package/tests/claim-routes.test.mjs +438 -0
- package/tests/client-panel.test.mjs +1141 -0
- package/tests/distribution-keys.test.mjs +123 -0
- package/tests/e2e.test.mjs +388 -0
- package/tests/fallback-scrub.test.mjs +105 -0
- package/tests/fixtures/quota-200.json +1 -0
- package/tests/launch-command.test.mjs +68 -0
- package/tests/login-channel.test.mjs +102 -0
- package/tests/openai-gateway.test.mjs +454 -0
- package/tests/pinned-models.test.mjs +505 -0
- package/tests/plan-client.test.mjs +582 -0
- package/tests/pool.test.mjs +319 -0
- package/tests/quota-blackhole.test.mjs +409 -0
- package/tests/restart-script.test.mjs +53 -0
- package/tests/routing-quota.test.mjs +251 -0
- package/tests/sse.test.mjs +86 -0
- package/tests/stream-translator.test.mjs +137 -0
- package/tests/support/hanging-stream.mjs +48 -0
- package/tests/support/resolve-profile-deps.mjs +52 -0
- package/tests/upstream-error-200.test.mjs +164 -0
- package/tests/upstream.test.mjs +330 -0
- package/tests/version-probe.test.mjs +172 -0
package/package.json
CHANGED
|
@@ -1,80 +1,84 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-zcode-startplan",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "DSH 接入 ZCode 赠送免费 plan(account:bigmodel-start-plan):多账号池 + 按需阿里云 captcha + 直连 zcode-plan/anthropic 的 llm 适配器。移植自 gitee.com/iJetLi/bonus-plan-4-open-zcode。",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "GPL-3.0-or-later",
|
|
7
|
-
"author": "Venshell",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/Venshell/dsh-zcode-startplan.git"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://github.com/Venshell/dsh-zcode-startplan#readme",
|
|
13
|
-
"bugs": "https://github.com/Venshell/dsh-zcode-startplan/issues",
|
|
14
|
-
"keywords": [
|
|
15
|
-
"dsh-plugin",
|
|
16
|
-
"deepseek-harness",
|
|
17
|
-
"zcode",
|
|
18
|
-
"zhipu",
|
|
19
|
-
"glm",
|
|
20
|
-
"model-provider",
|
|
21
|
-
"captcha",
|
|
22
|
-
"anthropic-messages"
|
|
23
|
-
],
|
|
24
|
-
"main": "./index.js",
|
|
25
|
-
"exports": {
|
|
26
|
-
".": "./index.js",
|
|
27
|
-
"./client": "./client.js",
|
|
28
|
-
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
29
|
-
"./package.json": "./package.json",
|
|
30
|
-
"./locale/*.json": "./locale/*.json",
|
|
31
|
-
"./icon": "./icon.svg"
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"index.js",
|
|
35
|
-
"client.js",
|
|
36
|
-
"lib",
|
|
37
|
-
"bin",
|
|
38
|
-
"scripts",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-zcode-startplan",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "DSH 接入 ZCode 赠送免费 plan(account:bigmodel-start-plan):多账号池 + 按需阿里云 captcha + 直连 zcode-plan/anthropic 的 llm 适配器。移植自 gitee.com/iJetLi/bonus-plan-4-open-zcode。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "GPL-3.0-or-later",
|
|
7
|
+
"author": "Venshell",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Venshell/dsh-zcode-startplan.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Venshell/dsh-zcode-startplan#readme",
|
|
13
|
+
"bugs": "https://github.com/Venshell/dsh-zcode-startplan/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"dsh-plugin",
|
|
16
|
+
"deepseek-harness",
|
|
17
|
+
"zcode",
|
|
18
|
+
"zhipu",
|
|
19
|
+
"glm",
|
|
20
|
+
"model-provider",
|
|
21
|
+
"captcha",
|
|
22
|
+
"anthropic-messages"
|
|
23
|
+
],
|
|
24
|
+
"main": "./index.js",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./index.js",
|
|
27
|
+
"./client": "./client.js",
|
|
28
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
29
|
+
"./package.json": "./package.json",
|
|
30
|
+
"./locale/*.json": "./locale/*.json",
|
|
31
|
+
"./icon": "./icon.svg"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"index.js",
|
|
35
|
+
"client.js",
|
|
36
|
+
"lib",
|
|
37
|
+
"bin",
|
|
38
|
+
"scripts",
|
|
39
|
+
"tests",
|
|
40
|
+
"locale/*.json",
|
|
41
|
+
"icon.svg",
|
|
42
|
+
"cordis.patch.yml",
|
|
43
|
+
"README.md",
|
|
44
|
+
"CHANGELOG.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"bin": {
|
|
48
|
+
"zcode-start-plan": "./bin/cli.mjs"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"check": "node --check index.js && node --check bin/cli.mjs",
|
|
52
|
+
"test": "node scripts/run-tests.mjs",
|
|
53
|
+
"smoke": "node scripts/smoke-install.mjs",
|
|
54
|
+
"verify:compat": "node scripts/verify_compat.mjs",
|
|
55
|
+
"login": "node bin/cli.mjs login",
|
|
56
|
+
"status": "node bin/cli.mjs status",
|
|
57
|
+
"probe": "node bin/cli.mjs probe"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@deepseek-ai/dsh-llm": ">=0.2.1-alpha.1 <0.2.2 || >=0.2.2-0 <0.3.0-0"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": "^22.19 || >=24"
|
|
64
|
+
},
|
|
65
|
+
"dsh": {
|
|
66
|
+
"id": "dsh-zcode-startplan",
|
|
67
|
+
"name": "ZCode Start Plan",
|
|
68
|
+
"version": "1.0.1",
|
|
69
|
+
"permissions": "模型供应商接入, 账号池管理",
|
|
70
|
+
"bundle": {
|
|
71
|
+
"patch": "./cordis.patch.yml"
|
|
72
|
+
},
|
|
73
|
+
"client": {
|
|
74
|
+
"platform": "web",
|
|
75
|
+
"immediately": true,
|
|
76
|
+
"inject": [
|
|
77
|
+
"@deepseek-ai/dsh-api-remotes",
|
|
78
|
+
"@deepseek-ai/dsh-client-ui-renderer",
|
|
79
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
80
|
+
"@deepseek-ai/dsh-client-ui-model-selection"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 采集下发间隔:把所有账号的 plan 授予时间(starts_at / effective_at /
|
|
4
|
+
* period_start)与 server_time 摆在一起,看服务端按什么节奏下发。
|
|
5
|
+
*
|
|
6
|
+
* 用法:
|
|
7
|
+
* node scripts/analyze-grant-intervals.mjs [--json]
|
|
8
|
+
*
|
|
9
|
+
* 只读:只打 billing/balance,不 claim、不 mint captcha、不发 touch/action。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync } from 'node:fs'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
|
|
15
|
+
const ORIGIN = 'https://zcode.z.ai'
|
|
16
|
+
const GATED = '3.16.3'
|
|
17
|
+
const AS_JSON = process.argv.includes('--json')
|
|
18
|
+
|
|
19
|
+
function gated(c) {
|
|
20
|
+
const v = typeof c?.app_version === 'string' ? c.app_version.trim() : ''
|
|
21
|
+
const ok = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(v)
|
|
22
|
+
if (!ok) return GATED
|
|
23
|
+
return v < GATED ? GATED : v
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function loadAccounts() {
|
|
27
|
+
const dir = join(process.env.USERPROFILE ?? process.env.HOME ?? '.', '.dsh', 'zcode-start-plan')
|
|
28
|
+
if (!existsSync(dir)) throw new Error('找不到 ~/.dsh/zcode-start-plan')
|
|
29
|
+
const { DatabaseSync } = await import('node:sqlite')
|
|
30
|
+
const db = new DatabaseSync(join(dir, 'accounts.db'), { readOnly: true })
|
|
31
|
+
const rows = db.prepare('select id, nickname, credential from accounts').all()
|
|
32
|
+
db.close()
|
|
33
|
+
return rows.map((r) => ({
|
|
34
|
+
id: r.id,
|
|
35
|
+
nickname: r.nickname ?? r.id,
|
|
36
|
+
credential: typeof r.credential === 'string' ? JSON.parse(r.credential) : r.credential,
|
|
37
|
+
}))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function headers(c) {
|
|
41
|
+
const ver = gated(c)
|
|
42
|
+
return {
|
|
43
|
+
'User-Agent': `ZCode/${ver}`,
|
|
44
|
+
'HTTP-Referer': ORIGIN,
|
|
45
|
+
'X-Title': 'Z Code@electron',
|
|
46
|
+
'X-ZCode-App-Version': ver,
|
|
47
|
+
'X-Release-Channel': 'production',
|
|
48
|
+
'X-Client-Language': 'zh-CN',
|
|
49
|
+
'X-Client-Timezone': 'Asia/Shanghai',
|
|
50
|
+
'X-Device-Mid': c.device_mid,
|
|
51
|
+
'X-Platform': 'win32-x64',
|
|
52
|
+
'X-Os-Category': 'windows',
|
|
53
|
+
'X-Os-Version': '10.0.19045',
|
|
54
|
+
'X-ZCode-Agent': 'glm',
|
|
55
|
+
'X-Session-Id': c.session_id ?? crypto.randomUUID(),
|
|
56
|
+
'X-ZCode-Session-Type': 'other',
|
|
57
|
+
'X-Request-Id': crypto.randomUUID(),
|
|
58
|
+
'X-ZCode-Trace-Id': crypto.randomUUID(),
|
|
59
|
+
'anthropic-version': '2023-06-01',
|
|
60
|
+
Accept: 'application/json',
|
|
61
|
+
authorization: `Bearer ${c.zcode_jwt}`,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const fmt = (s) =>
|
|
66
|
+
typeof s === 'number' && s > 0 ? new Date(s * 1000).toLocaleString('zh-CN', { hour12: false }) : '-'
|
|
67
|
+
const rel = (s, base) =>
|
|
68
|
+
typeof s === 'number' && s > 0 && typeof base === 'number'
|
|
69
|
+
? `${((s - base) / 60).toFixed(1)}m`
|
|
70
|
+
: '-'
|
|
71
|
+
|
|
72
|
+
const accounts = await loadAccounts()
|
|
73
|
+
const rows = []
|
|
74
|
+
for (const account of accounts) {
|
|
75
|
+
let payload
|
|
76
|
+
try {
|
|
77
|
+
const response = await fetch(`${ORIGIN}/api/v1/zcode-plan/billing/balance`, {
|
|
78
|
+
headers: headers(account.credential),
|
|
79
|
+
signal: AbortSignal.timeout(20_000),
|
|
80
|
+
})
|
|
81
|
+
payload = await response.json().catch(() => undefined)
|
|
82
|
+
} catch (error) {
|
|
83
|
+
rows.push({ nickname: account.nickname, error: String(error?.message ?? error) })
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
const data = payload?.data ?? {}
|
|
87
|
+
rows.push({
|
|
88
|
+
nickname: account.nickname,
|
|
89
|
+
serverTime: data.server_time,
|
|
90
|
+
plans: (Array.isArray(data.plans) ? data.plans : []).map((p) => ({
|
|
91
|
+
planId: p.plan_id,
|
|
92
|
+
status: p.status,
|
|
93
|
+
startsAt: p.starts_at,
|
|
94
|
+
endsAt: p.ends_at,
|
|
95
|
+
entitlements: (Array.isArray(p.entitlements) ? p.entitlements : []).map((e) => ({
|
|
96
|
+
showName: e.show_name,
|
|
97
|
+
grantUnits: e.grant_units,
|
|
98
|
+
effectiveAt: e.effective_at,
|
|
99
|
+
})),
|
|
100
|
+
})),
|
|
101
|
+
balances: (Array.isArray(data.balances) ? data.balances : []).map((b) => ({
|
|
102
|
+
planId: b.plan_id,
|
|
103
|
+
total: b.total_units,
|
|
104
|
+
used: b.used_units,
|
|
105
|
+
remaining: b.remaining_units,
|
|
106
|
+
periodStart: b.period_start,
|
|
107
|
+
expiresAt: b.expires_at,
|
|
108
|
+
})),
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (AS_JSON) {
|
|
113
|
+
console.log(JSON.stringify(rows, null, 2))
|
|
114
|
+
process.exit(0)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const row of rows) {
|
|
118
|
+
if (row.error !== undefined) {
|
|
119
|
+
console.log(`\n${row.nickname} ERR ${row.error}`)
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
console.log(`\n=== ${row.nickname} server_time=${row.serverTime} (${fmt(row.serverTime)}) ===`)
|
|
123
|
+
if (row.plans.length === 0) console.log(' plans: 空(未收到任何活动)')
|
|
124
|
+
for (const plan of row.plans) {
|
|
125
|
+
const ent = plan.entitlements
|
|
126
|
+
.map((e) => `${e.showName}:${e.grantUnits} eff=${fmt(e.effectiveAt)}(+${rel(e.effectiveAt, row.serverTime)})`)
|
|
127
|
+
.join(' | ')
|
|
128
|
+
console.log(
|
|
129
|
+
` ${plan.planId} status=${plan.status}` +
|
|
130
|
+
` starts_at=${fmt(plan.startsAt)}(+${rel(plan.startsAt, row.serverTime)})` +
|
|
131
|
+
` ends_at=${fmt(plan.endsAt)}`,
|
|
132
|
+
)
|
|
133
|
+
if (ent.length > 0) console.log(` entitlements: ${ent}`)
|
|
134
|
+
}
|
|
135
|
+
for (const bucket of row.balances) {
|
|
136
|
+
console.log(
|
|
137
|
+
` bucket ${bucket.planId} total=${bucket.total} used=${bucket.used} remaining=${bucket.remaining}` +
|
|
138
|
+
` period_start=${fmt(bucket.periodStart)}(+${rel(bucket.periodStart, row.serverTime)})` +
|
|
139
|
+
` expires=${fmt(bucket.expiresAt)}`,
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 跨账号聚合:同一 plan_id 在各账号上的授予时刻差 = 下发间隔。 */
|
|
145
|
+
const byPlan = new Map()
|
|
146
|
+
for (const row of rows) {
|
|
147
|
+
if (row.plans === undefined) continue
|
|
148
|
+
for (const plan of row.plans) {
|
|
149
|
+
const list = byPlan.get(plan.planId) ?? []
|
|
150
|
+
list.push({ nickname: row.nickname, at: plan.startsAt, effectiveAt: plan.entitlements[0]?.effectiveAt })
|
|
151
|
+
byPlan.set(plan.planId, list)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
console.log('\n=== 下发间隔(同一 plan 在各账号的 starts_at 差) ===')
|
|
155
|
+
if (byPlan.size === 0) console.log(' 没有任何账号持有 plan。')
|
|
156
|
+
for (const [planId, entries] of byPlan) {
|
|
157
|
+
const sorted = [...entries].sort((a, b) => (a.at ?? 0) - (b.at ?? 0))
|
|
158
|
+
console.log(`\n${planId}`)
|
|
159
|
+
for (let i = 0; i < sorted.length; i += 1) {
|
|
160
|
+
const item = sorted[i]
|
|
161
|
+
const gap = i === 0 ? '—' : `${(((item.at ?? 0) - (sorted[i - 1].at ?? 0)) / 60).toFixed(1)} 分钟`
|
|
162
|
+
console.log(` ${String(i + 1).padStart(2)}. ${item.nickname.padEnd(10)} starts_at=${fmt(item.at)} 与上一账号间隔=${gap}`)
|
|
163
|
+
}
|
|
164
|
+
const gaps = sorted.slice(1).map((item, i) => (item.at ?? 0) - (sorted[i].at ?? 0))
|
|
165
|
+
if (gaps.length > 0) {
|
|
166
|
+
const avg = gaps.reduce((a, b) => a + b, 0) / gaps.length / 60
|
|
167
|
+
const min = Math.min(...gaps) / 60
|
|
168
|
+
const max = Math.max(...gaps) / 60
|
|
169
|
+
console.log(` 平均间隔 ${avg.toFixed(1)} 分钟,最小 ${min.toFixed(1)},最大 ${max.toFixed(1)}`)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
// 用宿主自带的 evaluatePluginCompatibility 校验本插件 manifest
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
// 用宿主自带的 evaluatePluginCompatibility 校验本插件 manifest(覆盖 0.2.x 整条发布线)。
|
|
2
|
+
// 覆盖 alpha / rc / 正式版与下一个元组的预发布版,正是 peer 区间最容易漏掉的那几档。
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { pathToFileURL } from 'node:url'
|
|
5
|
+
|
|
6
|
+
const host = pathToFileURL(process.cwd() + '/.tmp-dsh-extract-full/node_modules/@deepseek-ai/dsh-app-boot/lib/index.js').href
|
|
7
|
+
const m = await import(host)
|
|
8
|
+
const pkg = JSON.parse(readFileSync(process.cwd() + '/package.json', 'utf8'))
|
|
9
|
+
for (const rv of [
|
|
10
|
+
'0.2.1-rc.2',
|
|
11
|
+
'0.2.1-rc.3',
|
|
12
|
+
'0.2.1-rc.4',
|
|
13
|
+
'0.2.1',
|
|
14
|
+
'0.2.2-alpha.2',
|
|
15
|
+
'0.2.2',
|
|
16
|
+
'0.1.7-rc.2',
|
|
17
|
+
'0.3.0',
|
|
18
|
+
]) {
|
|
19
|
+
const issue = m.evaluatePluginCompatibility(pkg, {}, rv)
|
|
20
|
+
console.log(rv, '=>', issue === undefined ? 'COMPATIBLE' : JSON.stringify(issue.requirements))
|
|
21
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 诊断脚本:为什么「活动存在但 /claimable 列表为空」。
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* node scripts/debug-claimable.mjs <ACCOUNT_ID|--all>
|
|
7
|
+
*
|
|
8
|
+
* 需要宿主管理端点可达(默认 http://127.0.0.1:56357,可用 ZSP_HOST 覆盖),
|
|
9
|
+
* 且 Host 头必须是 localhost(manage-routes 的 loopback 栅栏认 hostname)。
|
|
10
|
+
*
|
|
11
|
+
* 只做**只读**请求:balance / preview / marketing touch,绝不 claim、绝不 mint
|
|
12
|
+
* captcha、绝不发 confirm 回执(后者会让服务端不再投放该 campaign)。
|
|
13
|
+
*
|
|
14
|
+
* 输出每个来源的原始状态码 + 业务 code + 解析出的 plan_id,并逐条对照
|
|
15
|
+
* `fetchClaimablePlans` 的合并规则,指明列表为空的**具体**环节。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 宿主端口:每次 DSH 重启都会变(实测 56357 → 61944 → 55241 → 49273),
|
|
20
|
+
* 硬编码只会让脚本在重启后失效。按优先级:
|
|
21
|
+
* 1. `ZSP_HOST` 显式指定;
|
|
22
|
+
* 2. 从环境变量 `DSH_WEB_URL` / 常见端口段自动探测(能应答 `/summary` 的那个)。
|
|
23
|
+
*/
|
|
24
|
+
async function resolveHost() {
|
|
25
|
+
if (typeof process.env.ZSP_HOST === 'string' && process.env.ZSP_HOST.trim().length > 0) {
|
|
26
|
+
return process.env.ZSP_HOST.trim().replace(/\/$/, '')
|
|
27
|
+
}
|
|
28
|
+
const candidates = []
|
|
29
|
+
const explicit = process.env.DSH_WEB_URL ?? process.env.DSH_URL ?? ''
|
|
30
|
+
const match = /^https?:\/\/[^:/]+:(\d+)/.exec(explicit)
|
|
31
|
+
if (match !== null) candidates.push(Number(match[1]))
|
|
32
|
+
/** DSH 桌面端分配的高位端口,扫一段足够覆盖实际取值。 */
|
|
33
|
+
for (let port = 49000; port <= 66000; port += 1) candidates.push(port)
|
|
34
|
+
|
|
35
|
+
for (const port of candidates) {
|
|
36
|
+
const host = `http://127.0.0.1:${port}`
|
|
37
|
+
try {
|
|
38
|
+
const response = await fetch(`${host}${PREFIX}/summary`, {
|
|
39
|
+
headers: { host: `localhost:${port}`, accept: 'application/json' },
|
|
40
|
+
signal: AbortSignal.timeout(300),
|
|
41
|
+
})
|
|
42
|
+
if (response.status === 200) {
|
|
43
|
+
const body = await response.json().catch(() => undefined)
|
|
44
|
+
if (body?.ok === true) return host
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// 端口不通,继续。
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
throw new Error('找不到 DSH 宿主端口:请设置 ZSP_HOST=http://127.0.0.1:<端口>')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const PREFIX = '/api/zcode-start-plan'
|
|
54
|
+
let HOST = ''
|
|
55
|
+
|
|
56
|
+
/** 直接打上游时用的凭据来源:宿主面板不会把 jwt 吐出来,故从本地库读。 */
|
|
57
|
+
const ORIGIN = 'https://zcode.z.ai'
|
|
58
|
+
const GATED_MIN_VERSION = '3.16.3'
|
|
59
|
+
|
|
60
|
+
const arg = process.argv[2]
|
|
61
|
+
|
|
62
|
+
async function hostJson(path) {
|
|
63
|
+
const response = await fetch(`${HOST}${PREFIX}${path}`, {
|
|
64
|
+
headers: { host: new URL(HOST).host.replace(/^127\.0\.0\.1/, 'localhost'), accept: 'application/json' },
|
|
65
|
+
})
|
|
66
|
+
const text = await response.text()
|
|
67
|
+
let parsed
|
|
68
|
+
try {
|
|
69
|
+
parsed = JSON.parse(text)
|
|
70
|
+
} catch {
|
|
71
|
+
parsed = undefined
|
|
72
|
+
}
|
|
73
|
+
return { status: response.status, parsed, text }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function listAccounts() {
|
|
77
|
+
const { status, parsed, text } = await hostJson('/summary')
|
|
78
|
+
if (status !== 200) throw new Error(`summary HTTP ${status}: ${text.slice(0, 200)}`)
|
|
79
|
+
return parsed.accounts ?? []
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function describeAccount(account) {
|
|
83
|
+
const lines = []
|
|
84
|
+
const id = account.id
|
|
85
|
+
lines.push(`\n=== ${account.nickname} (${id}) channel=${account.channel} enabled=${account.enabled} ===`)
|
|
86
|
+
|
|
87
|
+
const balance = await hostJson(`/balance?id=${encodeURIComponent(id)}`)
|
|
88
|
+
lines.push(`balance HTTP ${balance.status} -> ${JSON.stringify(balance.parsed?.balance ?? balance.parsed)}`)
|
|
89
|
+
|
|
90
|
+
const claimable = await hostJson(`/claimable?id=${encodeURIComponent(id)}`)
|
|
91
|
+
lines.push(`claimable HTTP ${claimable.status} -> ${JSON.stringify(claimable.parsed)}`)
|
|
92
|
+
|
|
93
|
+
const plans = Array.isArray(claimable.parsed?.plans) ? claimable.parsed.plans : []
|
|
94
|
+
if (plans.length === 0) {
|
|
95
|
+
lines.push('诊断:两个来源都没给出 plan。可能环节:')
|
|
96
|
+
lines.push(' 1. marketing/touch 的 deliveries 为空 —— 版本门控(<3.16.3 恒空)或该 campaign 已对该账号停止投放(领过即停);')
|
|
97
|
+
lines.push(' 2. preview 的 data.plans 为空 —— 每日包已领 / 账号无资格;')
|
|
98
|
+
lines.push(' 3. billing/balance 的 plans[] 里也没有 → 无法回填「已领取」标记,面板只能显示空列表。')
|
|
99
|
+
} else {
|
|
100
|
+
for (const plan of plans) {
|
|
101
|
+
lines.push(
|
|
102
|
+
` plan ${plan.planId} claimed=${plan.claimed === true} priority=${plan.priority ?? '-'}` +
|
|
103
|
+
` name=${plan.name ?? '-'} campaignId=${plan.campaignId ?? '(缺)'}`,
|
|
104
|
+
)
|
|
105
|
+
if (plan.campaignId === undefined) {
|
|
106
|
+
lines.push(' ⚠ 无 campaignId:领取成功后发不了 confirm 回执,服务端会继续重复投放同一 campaign。')
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return lines.join('\n')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function main() {
|
|
114
|
+
HOST = await resolveHost()
|
|
115
|
+
let accounts
|
|
116
|
+
if (arg === '--all' || arg === undefined) {
|
|
117
|
+
accounts = await listAccounts()
|
|
118
|
+
} else {
|
|
119
|
+
accounts = (await listAccounts()).filter((item) => item.id === arg)
|
|
120
|
+
if (accounts.length === 0) throw new Error(`账号不存在:${arg}`)
|
|
121
|
+
}
|
|
122
|
+
console.log(`宿主:${HOST} 账号数:${accounts.length}`)
|
|
123
|
+
for (const account of accounts) console.log(await describeAccount(account))
|
|
124
|
+
console.log('\n(只读诊断结束:未 mint captcha、未 claim、未发送 marketing confirm/cancel)')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
main().catch((error) => {
|
|
128
|
+
console.error(`诊断失败:${error instanceof Error ? error.message : String(error)}`)
|
|
129
|
+
process.exitCode = 1
|
|
130
|
+
})
|