dsh-zcode-startplan 0.5.2 → 1.0.3
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 -672
- package/README.md +92 -472
- package/bin/cli.mjs +509 -450
- package/client.js +2459 -1002
- package/cordis.patch.yml +4 -2
- package/index.js +109 -11
- package/lib/adapter.js +476 -449
- package/lib/anthropic-body.js +513 -469
- package/lib/assemble.js +808 -542
- 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 -652
- 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 -611
- package/lib/upstream.js +294 -134
- package/lib/version-probe.js +110 -0
- package/package.json +84 -81
- 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 -116
- package/scripts/test-claimed-pending.mjs +152 -0
- package/scripts/verify_compat.mjs +75 -64
- package/scripts/watch-marketing.mjs +155 -0
- package/tests/auto-claim.test.mjs +318 -0
- package/tests/claim-routes.test.mjs +438 -293
- package/tests/client-panel.test.mjs +1141 -356
- package/tests/distribution-keys.test.mjs +123 -0
- package/tests/e2e.test.mjs +388 -353
- package/tests/fallback-scrub.test.mjs +105 -0
- package/tests/launch-command.test.mjs +68 -0
- package/tests/openai-gateway.test.mjs +454 -0
- package/tests/pinned-models.test.mjs +505 -497
- package/tests/plan-client.test.mjs +582 -222
- package/tests/pool.test.mjs +319 -93
- 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/support/hanging-stream.mjs +48 -0
- package/tests/upstream-error-200.test.mjs +164 -125
- package/tests/upstream.test.mjs +330 -250
- package/tests/version-probe.test.mjs +172 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 原始探针:绕过 /claimable 的静默降级,直接看 marketing/touch 与 billing/preview
|
|
4
|
+
* 的**原始**状态码、业务 code 与 deliveries 结构。
|
|
5
|
+
*
|
|
6
|
+
* 用法:
|
|
7
|
+
* node scripts/probe-marketing.mjs <ACCOUNT_ID> [--raw]
|
|
8
|
+
*
|
|
9
|
+
* 凭据从本地账号库读取(与插件同一份 SQLite)。只读:
|
|
10
|
+
* - 不 claim(claim 会消耗活动资格 + 烧设备 captcha)
|
|
11
|
+
* - 不发 marketing/touch/action 的 confirm/cancel(confirm 会让服务端停止投放,
|
|
12
|
+
* cancel 更糟:等于告诉服务端「别再给我看」)
|
|
13
|
+
* - 不改任何账号状态
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
17
|
+
import { join } from 'node:path'
|
|
18
|
+
|
|
19
|
+
const GATED_MIN = '3.16.3'
|
|
20
|
+
const ORIGIN = 'https://zcode.z.ai'
|
|
21
|
+
const PRINT_RAW = process.argv.includes('--raw')
|
|
22
|
+
|
|
23
|
+
/** 账号库位置解析:环境变量 → 插件默认目录。 */
|
|
24
|
+
function resolveDataDir() {
|
|
25
|
+
const env = process.env
|
|
26
|
+
for (const key of ['ZCODE_START_PLAN_DATA_DIR', 'ZSP_DATA_DIR', 'ZCODE_DATA_DIR']) {
|
|
27
|
+
if (typeof env[key] === 'string' && env[key].trim().length > 0) return env[key].trim()
|
|
28
|
+
}
|
|
29
|
+
const home = env.USERPROFILE ?? env.HOME ?? '.'
|
|
30
|
+
/** 插件默认目录是 `~/.dsh/zcode-start-plan`(与 pool.resolveDataDir 一致)。 */
|
|
31
|
+
const candidates = [
|
|
32
|
+
join(home, '.dsh', 'zcode-start-plan'),
|
|
33
|
+
join(env.APPDATA ?? join(home, 'AppData', 'Roaming'), 'deepseek-harness', 'zcode-start-plan'),
|
|
34
|
+
]
|
|
35
|
+
return candidates.find((dir) => existsSync(dir)) ?? candidates[0]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function cmpVersion(a, b) {
|
|
39
|
+
const seg = (v) => String(v).split('.').map((p) => { const m = /^\s*(\d+)/.exec(p); return m ? Number(m[1]) : 0 })
|
|
40
|
+
const l = seg(a), r = seg(b)
|
|
41
|
+
for (let i = 0; i < Math.max(l.length, r.length); i += 1) {
|
|
42
|
+
const x = l[i] ?? 0, y = r[i] ?? 0
|
|
43
|
+
if (x !== y) return x < y ? -1 : 1
|
|
44
|
+
}
|
|
45
|
+
return 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function gatedVersion(credential) {
|
|
49
|
+
const v = typeof credential?.app_version === 'string' ? credential.app_version.trim() : ''
|
|
50
|
+
if (!/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(v)) return GATED_MIN
|
|
51
|
+
return cmpVersion(v, GATED_MIN) < 0 ? GATED_MIN : v
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function headersFor(credential, extra = {}) {
|
|
55
|
+
const version = gatedVersion(credential)
|
|
56
|
+
return {
|
|
57
|
+
'User-Agent': `ZCode/${version}`,
|
|
58
|
+
'HTTP-Referer': ORIGIN,
|
|
59
|
+
'X-Title': 'Z Code@electron',
|
|
60
|
+
'X-ZCode-App-Version': version,
|
|
61
|
+
'X-Release-Channel': 'production',
|
|
62
|
+
'X-Client-Language': 'zh-CN',
|
|
63
|
+
'X-Client-Timezone': 'Asia/Shanghai',
|
|
64
|
+
'X-Device-Mid': credential.device_mid,
|
|
65
|
+
'X-Platform': 'win32-x64',
|
|
66
|
+
'X-Os-Category': 'windows',
|
|
67
|
+
'X-Os-Version': '10.0.19045',
|
|
68
|
+
'X-ZCode-Agent': 'glm',
|
|
69
|
+
'X-Session-Id': credential.session_id ?? crypto.randomUUID(),
|
|
70
|
+
'X-ZCode-Session-Type': 'other',
|
|
71
|
+
'X-Request-Id': crypto.randomUUID(),
|
|
72
|
+
'X-ZCode-Trace-Id': crypto.randomUUID(),
|
|
73
|
+
'anthropic-version': '2023-06-01',
|
|
74
|
+
'Accept': 'application/json',
|
|
75
|
+
...extra,
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function loadAccounts() {
|
|
80
|
+
const dataDir = resolveDataDir()
|
|
81
|
+
const candidates = ['accounts.db', 'pool.db', 'zcode-start-plan.db']
|
|
82
|
+
const file = candidates.map((n) => join(dataDir, n)).find((p) => existsSync(p))
|
|
83
|
+
if (file === undefined) throw new Error(`找不到账号库:${dataDir} 下 ${candidates.join(' / ')}`)
|
|
84
|
+
let DatabaseSync
|
|
85
|
+
try { ({ DatabaseSync } = await import('node:sqlite')) } catch {
|
|
86
|
+
throw new Error('当前 Node 不支持 node:sqlite(需 Node 22.19+ 或 24+)')
|
|
87
|
+
}
|
|
88
|
+
const db = new DatabaseSync(file, { readOnly: true })
|
|
89
|
+
const tables = db.prepare("select name from sqlite_master where type='table'").all()
|
|
90
|
+
const names = tables.map((t) => t.name)
|
|
91
|
+
const table = ['accounts', 'account', 'pool'].find((n) => names.includes(n))
|
|
92
|
+
if (table === undefined) throw new Error(`账号库里没有 accounts 表,现有表:${names.join(', ')}`)
|
|
93
|
+
const rows = db.prepare(`select * from ${table}`).all()
|
|
94
|
+
db.close()
|
|
95
|
+
return { file, rows, table }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 从行里抽出 credential(可能是 JSON 列,也可能散列)。 */
|
|
99
|
+
function credentialOf(row) {
|
|
100
|
+
if (typeof row.credential === 'string') {
|
|
101
|
+
try { return JSON.parse(row.credential) } catch { return undefined }
|
|
102
|
+
}
|
|
103
|
+
if (row.credential !== null && typeof row.credential === 'object') return row.credential
|
|
104
|
+
return {
|
|
105
|
+
zcode_jwt: row.zcode_jwt ?? row.jwt,
|
|
106
|
+
device_mid: row.device_mid,
|
|
107
|
+
app_version: row.app_version,
|
|
108
|
+
user_id: row.user_id,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 递归找 deliveries 里所有 claim_zcode_plan 按钮(含被改名 / 换层的)。 */
|
|
113
|
+
function findClaimButtons(node, depth = 0, out = []) {
|
|
114
|
+
if (depth > 10 || node === null || typeof node !== 'object') return out
|
|
115
|
+
if (Array.isArray(node)) { for (const item of node) findClaimButtons(item, depth + 1, out); return out }
|
|
116
|
+
const type = node.action?.type ?? node.action_type ?? node.type
|
|
117
|
+
if (typeof type === 'string' && /claim/i.test(type)) out.push(node)
|
|
118
|
+
for (const value of Object.values(node)) findClaimButtons(value, depth + 1, out)
|
|
119
|
+
return out
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function probe(label, url, headers) {
|
|
123
|
+
const started = Date.now()
|
|
124
|
+
let status, body, error
|
|
125
|
+
try {
|
|
126
|
+
const response = await fetch(url, { method: 'GET', headers, signal: AbortSignal.timeout(25_000) })
|
|
127
|
+
status = response.status
|
|
128
|
+
body = await response.text()
|
|
129
|
+
} catch (caught) {
|
|
130
|
+
error = caught instanceof Error ? caught.message : String(caught)
|
|
131
|
+
}
|
|
132
|
+
const elapsed = Date.now() - started
|
|
133
|
+
console.log(`\n--- ${label} ---`)
|
|
134
|
+
console.log(`URL ${url}`)
|
|
135
|
+
console.log(`HTTP ${status ?? `ERR (${error})`} ${elapsed}ms`)
|
|
136
|
+
let parsed
|
|
137
|
+
try { parsed = JSON.parse(body ?? '') } catch { parsed = undefined }
|
|
138
|
+
if (parsed === undefined) {
|
|
139
|
+
if (body !== undefined) console.log(`BODY ${body.slice(0, 600)}`)
|
|
140
|
+
return { status, parsed }
|
|
141
|
+
}
|
|
142
|
+
console.log(`code ${JSON.stringify(parsed.code ?? parsed.error?.code ?? null)} msg=${JSON.stringify(parsed.message ?? parsed.error?.message ?? parsed.msg ?? null)}`)
|
|
143
|
+
const deliveries = parsed?.data?.deliveries
|
|
144
|
+
console.log(`deliveries ${Array.isArray(deliveries) ? `${deliveries.length} 条` : `非数组 (${typeof deliveries})`}`)
|
|
145
|
+
if (Array.isArray(deliveries)) {
|
|
146
|
+
for (const [i, delivery] of deliveries.entries()) {
|
|
147
|
+
const buttons = findClaimButtons(delivery)
|
|
148
|
+
console.log(` [${i}] campaign_id=${JSON.stringify(delivery?.campaign_id)} priority=${delivery?.priority}` +
|
|
149
|
+
` title=${JSON.stringify(delivery?.banner?.title?.content ?? delivery?.popup?.title?.content ?? null)}` +
|
|
150
|
+
` claimButtons=${buttons.length}`)
|
|
151
|
+
for (const button of buttons) {
|
|
152
|
+
console.log(` action=${JSON.stringify(button.action ?? button.action_type)}` +
|
|
153
|
+
` text=${JSON.stringify(button?.text?.content ?? button?.label ?? null)}`)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (PRINT_RAW) console.log(`RAW ${(body ?? '').slice(0, 4000)}`)
|
|
158
|
+
return { status, parsed, deliveries }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function main() {
|
|
162
|
+
const id = process.argv[2]
|
|
163
|
+
if (typeof id !== 'string' || id.length === 0) throw new Error('用法:node scripts/probe-marketing.mjs <ACCOUNT_ID> [--raw]')
|
|
164
|
+
const { file, rows, table } = await loadAccounts()
|
|
165
|
+
console.log(`账号库 ${file}(表 ${table},${rows.length} 行)`)
|
|
166
|
+
const row = rows.find((r) => (r.id ?? r.account_id) === id)
|
|
167
|
+
if (row === undefined) throw new Error(`账号不存在:${id}`)
|
|
168
|
+
const credential = credentialOf(row)
|
|
169
|
+
const nickname = row.nickname ?? row.name ?? row.id
|
|
170
|
+
console.log(`目标 ${nickname} (${id}) channel=${row.channel ?? '-'} app_version=${credential?.app_version ?? '(缺)'} device_mid=${credential?.device_mid ?? '(缺)'}`)
|
|
171
|
+
if (typeof credential?.zcode_jwt !== 'string' || credential.zcode_jwt.length === 0) {
|
|
172
|
+
throw new Error('该账号没有 zcode_jwt(bigmodel 渠道用 bigmodel 自己的鉴权,marketing 端点不适用)')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const auth = { authorization: `Bearer ${credential.zcode_jwt}` }
|
|
176
|
+
const marketing = await probe('marketing/touch', `${ORIGIN}/api/v1/marketing/touch?seq=0`, headersFor(credential, auth))
|
|
177
|
+
|
|
178
|
+
const version = gatedVersion(credential)
|
|
179
|
+
await probe('billing/preview', `${ORIGIN}/api/v1/zcode-plan/billing/preview?app_version=${encodeURIComponent(version)}&platform=win32`, headersFor(credential, auth))
|
|
180
|
+
await probe('billing/balance', `${ORIGIN}/api/v1/zcode-plan/billing/balance`, headersFor(credential, auth))
|
|
181
|
+
|
|
182
|
+
const claims = (marketing.deliveries ?? []).flatMap((d) => findClaimButtons(d))
|
|
183
|
+
console.log('\n=== 判读 ===')
|
|
184
|
+
if (marketing.status === undefined) {
|
|
185
|
+
console.log('marketing 请求本身失败(网络/超时)→ 空列表是故障,不是「没有活动」。')
|
|
186
|
+
} else if (marketing.status === 401 || marketing.status === 403) {
|
|
187
|
+
console.log('marketing 鉴权失败 → jwt 过期或无效;插件会把这种情况静默显示成「无活动」。')
|
|
188
|
+
} else if (marketing.status !== 200) {
|
|
189
|
+
console.log(`marketing 返回 ${marketing.status} → 非 200 被插件吞成 [],不可据此判断有无活动。`)
|
|
190
|
+
} else if (Array.isArray(marketing.deliveries) && marketing.deliveries.length === 0) {
|
|
191
|
+
console.log('marketing 200 且 deliveries 确实为空 → 服务端此刻未向该账号投放(或已领后停投)。')
|
|
192
|
+
} else if (claims.length === 0) {
|
|
193
|
+
console.log('marketing 有 deliveries 但找不到 claim 按钮 → 投放 schema 可能改版,插件的按钮路径解析失配。')
|
|
194
|
+
} else {
|
|
195
|
+
console.log(`marketing 有 ${claims.length} 个领取按钮 → 活动存在,但插件没能呈现(看上面 action 的 type/args 是否还是 claim_zcode_plan)。`)
|
|
196
|
+
}
|
|
197
|
+
console.log('(只读:未 claim、未发 marketing confirm/cancel、未改账号状态)')
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
main().catch((error) => {
|
|
201
|
+
console.error(`探针失败:${error instanceof Error ? error.message : String(error)}`)
|
|
202
|
+
process.exitCode = 1
|
|
203
|
+
})
|
package/scripts/restart-dsh.ps1
CHANGED
|
@@ -1,116 +1,119 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
Write-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1
|
+
# 准备「带调试端口的 DSH 启动方式」,供用户在需要 captcha 时**自己**重启用。
|
|
2
|
+
#
|
|
3
|
+
# ── 设计原则(0.6.6 重写:安全优先) ────────────────────────────────────────
|
|
4
|
+
#
|
|
5
|
+
# 旧版做的是「替用户自动重启」,它同时具备「结束进程、注册计划任务、绕过执行策略、
|
|
6
|
+
# 写临时脚本再执行、隐藏窗口」这组动作 —— 与恶意软件的持久化/提权手法高度重合,
|
|
7
|
+
# 被火绒类 AV 拦截是**正确行为**(用户实际遇到了报毒)。
|
|
8
|
+
#
|
|
9
|
+
# 新版**不再做任何高危动作**:
|
|
10
|
+
# · 不结束任何进程
|
|
11
|
+
# · 不注册任何计划任务、不写临时脚本、不提权
|
|
12
|
+
# · 不隐藏任何窗口
|
|
13
|
+
# · 只做两件事:① 输出现成的启动命令;② 可选地把启动命令写到**插件自己的
|
|
14
|
+
# dataDir 下**(用户可读可删),方便用户复制。
|
|
15
|
+
#
|
|
16
|
+
# 用户看到提示后自行退出并重新打开 DSH —— 重启本来就是用户的决定,
|
|
17
|
+
# 而且宿主侧的 `app.relaunch()` 语义(原样重放 argv)也由用户手动等效完成。
|
|
18
|
+
#
|
|
19
|
+
# 用法:
|
|
20
|
+
# powershell -NoProfile -File restart-dsh.ps1 -DebugPort 9229
|
|
21
|
+
# powershell -NoProfile -File restart-dsh.ps1 -DebugPort 9229 -WriteCommandFile
|
|
22
|
+
|
|
23
|
+
param(
|
|
24
|
+
# 想要的调试端口;0 或不传 = 只给普通重启指引。
|
|
25
|
+
[int]$DebugPort = 9229,
|
|
26
|
+
# 把启动命令写一份到 dataDir(用户可读、可删)。默认不写。
|
|
27
|
+
[switch]$WriteCommandFile,
|
|
28
|
+
# 写入位置(默认插件数据目录)。
|
|
29
|
+
[string]$OutDir = (Join-Path $env:USERPROFILE '.dsh\zcode-start-plan')
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
$ErrorActionPreference = 'Stop'
|
|
33
|
+
|
|
34
|
+
function Write-Step([string]$Message) {
|
|
35
|
+
Write-Host "[zcode-start-plan] $Message"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
<#
|
|
39
|
+
定位宿主可执行文件。
|
|
40
|
+
|
|
41
|
+
⚠ 只做**只读**查询:从正在运行的进程读 ExecutablePath,或查常见安装位置。
|
|
42
|
+
不结束、不修改任何进程。
|
|
43
|
+
#>
|
|
44
|
+
function Resolve-HostExe {
|
|
45
|
+
$main = Get-CimInstance Win32_Process -Filter "Name='DeepSeek Harness.exe'" -ErrorAction SilentlyContinue |
|
|
46
|
+
Where-Object {
|
|
47
|
+
$cmd = [string]$_.CommandLine
|
|
48
|
+
$cmd -notmatch '--type=' -and
|
|
49
|
+
$cmd -notmatch 'dsh-desktop-host' -and
|
|
50
|
+
$cmd -notmatch 'runner\.js' -and
|
|
51
|
+
$cmd -notmatch '--expose-internals'
|
|
52
|
+
} | Select-Object -First 1
|
|
53
|
+
if ($main -and $main.ExecutablePath -and (Test-Path $main.ExecutablePath)) {
|
|
54
|
+
return $main.ExecutablePath
|
|
55
|
+
}
|
|
56
|
+
foreach ($candidate in @(
|
|
57
|
+
'D:\software\dsh\DeepSeek Harness.exe',
|
|
58
|
+
(Join-Path $env:LOCALAPPDATA 'Programs\DeepSeek Harness\DeepSeek Harness.exe'),
|
|
59
|
+
(Join-Path ${env:ProgramFiles} 'DeepSeek Harness\DeepSeek Harness.exe')
|
|
60
|
+
)) {
|
|
61
|
+
if ($candidate -and (Test-Path $candidate)) { return $candidate }
|
|
62
|
+
}
|
|
63
|
+
return ''
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
$exe = Resolve-HostExe
|
|
68
|
+
if (-not $exe) {
|
|
69
|
+
Write-Step '找不到 DeepSeek Harness.exe,无法生成启动命令。'
|
|
70
|
+
Write-Step '请在开始菜单里右键 DSH 图标 →「打开文件位置」找到它后手动重启。'
|
|
71
|
+
exit 1
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
$exeDir = Split-Path $exe
|
|
75
|
+
if ($DebugPort -gt 0) {
|
|
76
|
+
# ⚠ 前缀 & :带引号路径直接跟参数会被 PowerShell 当成输出语句(用户实测踩坑)。
|
|
77
|
+
$command = '& "' + $exe + '" --remote-debugging-port=' + $DebugPort
|
|
78
|
+
$why = "要让 captcha 可用,需要以调试端口 $DebugPort 启动一次。"
|
|
79
|
+
} else {
|
|
80
|
+
$command = '& "' + $exe + '"'
|
|
81
|
+
$why = '要重载插件(普通重启,不带调试端口)。'
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Write-Step '────────────────────────────────────────────────────────'
|
|
85
|
+
Write-Step $why
|
|
86
|
+
Write-Step '请**手动**完成重启(插件不会替你结束进程):'
|
|
87
|
+
Write-Step ' 1. 在当前窗口菜单里退出 DSH(或右键托盘图标退出)'
|
|
88
|
+
Write-Step ' 2. 在「运行」(Win+R) 或 PowerShell 里执行下面这行:'
|
|
89
|
+
Write-Step ''
|
|
90
|
+
Write-Host " $command" -ForegroundColor Cyan
|
|
91
|
+
Write-Step ''
|
|
92
|
+
Write-Step " 工作目录:$exeDir"
|
|
93
|
+
if ($DebugPort -gt 0) {
|
|
94
|
+
Write-Step " 起来后访问 http://127.0.0.1:$DebugPort/json/version 可确认端口已开。"
|
|
95
|
+
}
|
|
96
|
+
Write-Step '────────────────────────────────────────────────────────'
|
|
97
|
+
|
|
98
|
+
if ($WriteCommandFile) {
|
|
99
|
+
try {
|
|
100
|
+
if (-not (Test-Path $OutDir)) { New-Item -ItemType Directory -Path $OutDir -Force | Out-Null }
|
|
101
|
+
$file = Join-Path $OutDir 'restart-command.txt'
|
|
102
|
+
$body = @(
|
|
103
|
+
'# 由 dsh-zcode-startplan 生成:需要重启 DSH 时手动执行下面这行。',
|
|
104
|
+
'# 本文件只含一条命令,不含任何脚本;可随时删除。',
|
|
105
|
+
$command
|
|
106
|
+
) -join "`r`n"
|
|
107
|
+
[System.IO.File]::WriteAllText($file, $body, (New-Object System.Text.UTF8Encoding($false)))
|
|
108
|
+
Write-Step "启动命令已写入:$file"
|
|
109
|
+
} catch {
|
|
110
|
+
Write-Step "写入命令文件失败(不影响使用):$($_.Exception.Message)"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exit 0
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
Write-Step "失败:$($_.Exception.Message)"
|
|
118
|
+
exit 1
|
|
119
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 回归用例:领取记录解析(`fetchClaimedPlans`)必须贴合**上游真实响应形状**。
|
|
4
|
+
*
|
|
5
|
+
* 数据来源(2026-11-03/06/07 原始响应实测,非臆测):
|
|
6
|
+
*
|
|
7
|
+
* data.plans[]: {
|
|
8
|
+
* plan_id, name, status, priority, starts_at(秒), ends_at(秒),
|
|
9
|
+
* entitlements: [{ show_name, unit_type, grant_units, effective_at(秒) }]
|
|
10
|
+
* }
|
|
11
|
+
* data.server_time: 秒
|
|
12
|
+
* ⚠ 上游没有顶层 `pending` —— 「已领未生效」按 effective_at > server_time 判。
|
|
13
|
+
* ⚠ `name` 是活动名(ZCODE WEEKEND BUILD),`show_name` 是模型名,别混。
|
|
14
|
+
* ⚠ 多条 entitlement 按 unit_type 求和;不同单位不混加。
|
|
15
|
+
*
|
|
16
|
+
* 运行:node scripts/test-claimed-pending.mjs
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import assert from 'node:assert/strict'
|
|
20
|
+
import { fetchClaimedPlans } from '../lib/upstream-api.js'
|
|
21
|
+
|
|
22
|
+
const credential = { zcode_jwt: 'test-jwt', device_mid: 'test-mid', app_version: '3.14.3' }
|
|
23
|
+
|
|
24
|
+
/** 造一个只回固定 JSON 的 fetch。 */
|
|
25
|
+
function fakeFetch(payload, status = 200) {
|
|
26
|
+
return async () => new Response(JSON.stringify(payload), { status, headers: { 'content-type': 'application/json' } })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cases = []
|
|
30
|
+
function test(name, fn) {
|
|
31
|
+
cases.push({ name, fn })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 1106-wk 真实形状(节选自 2026-11-06 23:00 原始响应)。 */
|
|
35
|
+
const REAL_1106 = {
|
|
36
|
+
code: 0,
|
|
37
|
+
msg: '',
|
|
38
|
+
data: {
|
|
39
|
+
server_time: 1793977241, // 2026-11-06 23:00:41 +08
|
|
40
|
+
plans: [{
|
|
41
|
+
user_plan_id: 'upl_2117601318960766976',
|
|
42
|
+
plan_id: 'zcode-v3-start-plan-1106-wk',
|
|
43
|
+
name: 'ZCODE WEEKEND BUILD',
|
|
44
|
+
description: '',
|
|
45
|
+
priority: 101,
|
|
46
|
+
status: 'active',
|
|
47
|
+
starts_at: 1793710472,
|
|
48
|
+
ends_at: 1793754000, // 2026-11-09 09:00 +08(秒)
|
|
49
|
+
entitlements: [{
|
|
50
|
+
entitlement_id: 'ent-zcode-v3-start-plan-1106-wk-1',
|
|
51
|
+
show_name: 'GLM-5.3-Flash',
|
|
52
|
+
meter: 'model_usage',
|
|
53
|
+
unit_type: 'token',
|
|
54
|
+
capabilities: ['model:glm-5.3-flash'],
|
|
55
|
+
grant_units: 500000000,
|
|
56
|
+
period: 'one_time',
|
|
57
|
+
priority: 101,
|
|
58
|
+
effective_at: 1793718000, // 2026-11-06 23:00 +08(秒)
|
|
59
|
+
}],
|
|
60
|
+
}],
|
|
61
|
+
balances: [{
|
|
62
|
+
plan_id: 'zcode-v3-start-plan-1106-wk',
|
|
63
|
+
total_units: 500000000,
|
|
64
|
+
used_units: 6827270,
|
|
65
|
+
remaining_units: 293172730,
|
|
66
|
+
expires_at: 1793754000,
|
|
67
|
+
}],
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
test('真实形状:name 取活动名,entitlements 求和,秒级归一为毫秒', async () => {
|
|
72
|
+
const plans = await fetchClaimedPlans(credential, fakeFetch(REAL_1106))
|
|
73
|
+
assert.equal(plans.size, 1)
|
|
74
|
+
const plan = plans.get('zcode-v3-start-plan-1106-wk')
|
|
75
|
+
assert.equal(plan.claimed, true)
|
|
76
|
+
assert.equal(plan.name, 'ZCODE WEEKEND BUILD')
|
|
77
|
+
assert.equal(plan.unitType, 'token')
|
|
78
|
+
assert.equal(plan.grantUnits, 500000000)
|
|
79
|
+
assert.equal(plan.effectiveAt, 1793718000000) // 秒 → 毫秒
|
|
80
|
+
assert.equal(plan.expiresAt, 1793754000000)
|
|
81
|
+
assert.equal(plan.priority, 101)
|
|
82
|
+
assert.equal(plan.status, 'active')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('effective_at 已过点(server_time 更晚)→ pending=false(已生效)', async () => {
|
|
86
|
+
const plans = await fetchClaimedPlans(credential, fakeFetch(REAL_1106))
|
|
87
|
+
// server_time=1793977241 > effective_at=1793718000
|
|
88
|
+
assert.equal(plans.get('zcode-v3-start-plan-1106-wk').pending, false)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test('effective_at 未到点(server_time 更早)→ pending=true(待生效)', async () => {
|
|
92
|
+
const payload = structuredClone(REAL_1106)
|
|
93
|
+
payload.data.server_time = 1793710000 // 早于 effective_at=1793718000
|
|
94
|
+
const plans = await fetchClaimedPlans(credential, fakeFetch(payload))
|
|
95
|
+
assert.equal(plans.get('zcode-v3-start-plan-1106-wk').pending, true)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('同 unit_type 多条 entitlement 求和(1024 活动教训:3 亿 + 2 亿 = 5 亿)', async () => {
|
|
99
|
+
const payload = structuredClone(REAL_1106)
|
|
100
|
+
payload.data.plans[0].entitlements.push({
|
|
101
|
+
show_name: 'GLM-5.3-Flash', unit_type: 'token', grant_units: 200000000, effective_at: 1793718000,
|
|
102
|
+
})
|
|
103
|
+
const plans = await fetchClaimedPlans(credential, fakeFetch(payload))
|
|
104
|
+
assert.equal(plans.get('zcode-v3-start-plan-1106-wk').grantUnits, 700000000)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('不同 unit_type 不混加(宁可少报)', async () => {
|
|
108
|
+
const payload = structuredClone(REAL_1106)
|
|
109
|
+
payload.data.plans[0].entitlements.push({
|
|
110
|
+
show_name: '积分', unit_type: 'point', grant_units: 50, effective_at: 1793718000,
|
|
111
|
+
})
|
|
112
|
+
const plans = await fetchClaimedPlans(credential, fakeFetch(payload))
|
|
113
|
+
const plan = plans.get('zcode-v3-start-plan-1106-wk')
|
|
114
|
+
assert.equal(plan.grantUnits, 500000000) // 只有 token 被累加
|
|
115
|
+
assert.equal(plan.unitType, 'token')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('订阅类 plan 也在结果里(前缀过滤是调用方的职责,不是这里的)', async () => {
|
|
119
|
+
const payload = structuredClone(REAL_1106)
|
|
120
|
+
payload.data.plans.push({
|
|
121
|
+
plan_id: 'zcode-v3-pro-monthly', name: 'Pro 订阅', status: 'active', ends_at: 1799999999,
|
|
122
|
+
entitlements: [{ unit_type: 'token', grant_units: 1, effective_at: 1793718000 }],
|
|
123
|
+
})
|
|
124
|
+
const plans = await fetchClaimedPlans(credential, fakeFetch(payload))
|
|
125
|
+
assert.equal(plans.size, 2)
|
|
126
|
+
assert.ok(plans.has('zcode-v3-pro-monthly'))
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('空 plans / 非 2xx / 缺字段 → 空或跳过,不抛', async () => {
|
|
130
|
+
assert.equal((await fetchClaimedPlans(credential, fakeFetch({ code: 0, data: { plans: [], balances: [] } }))).size, 0)
|
|
131
|
+
assert.equal((await fetchClaimedPlans(credential, fakeFetch({ code: 401 }, 401))).size, 0)
|
|
132
|
+
const partial = await fetchClaimedPlans(credential, fakeFetch({
|
|
133
|
+
code: 0,
|
|
134
|
+
data: { server_time: 1, plans: [{ status: 'active' }, { plan_id: '' }, { plan_id: 'ok-1' }] },
|
|
135
|
+
}))
|
|
136
|
+
assert.equal(partial.size, 1)
|
|
137
|
+
assert.ok(partial.has('ok-1'))
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
let passed = 0
|
|
141
|
+
for (const { name, fn } of cases) {
|
|
142
|
+
try {
|
|
143
|
+
await fn()
|
|
144
|
+
passed += 1
|
|
145
|
+
console.log(`✓ ${name}`)
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(`✗ ${name}`)
|
|
148
|
+
console.error(` ${error instanceof Error ? error.message : String(error)}`)
|
|
149
|
+
process.exitCode = 1
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
console.log(`\n${passed}/${cases.length} 通过`)
|