mslxdff 0.1.188 → 0.1.197
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/bin/mslxdff.js +3 -3
- package/package.json +1 -1
- package/src/anthropic/count-tokens.js +10 -3
- package/src/auto.js +254 -254
- package/src/bench/cline-bench.js +42 -42
- package/src/bench/probe.js +70 -70
- package/src/bench/report.js +162 -162
- package/src/bench/runner.js +77 -77
- package/src/bench/via-probe.js +124 -124
- package/src/bench/via-routes.js +87 -87
- package/src/bench/workbuddy-bench.js +54 -54
- package/src/chat/engine.js +160 -160
- package/src/chat/gateway.js +163 -163
- package/src/chat/orchestrator.js +234 -234
- package/src/chat/prompt.js +70 -70
- package/src/chat/repl.js +88 -88
- package/src/chat/terminal.js +135 -135
- package/src/chat/tools.js +306 -306
- package/src/chat-pipeline/index.js +173 -173
- package/src/chat-pipeline/policy.js +84 -84
- package/src/chat-pipeline/terminal-verdict.js +15 -6
- package/src/cli/commands/group.js +249 -249
- package/src/cli/commands/model/picks.js +50 -50
- package/src/cli/commands/provider/bench-via.js +247 -247
- package/src/cli/commands/provider/bench.js +141 -141
- package/src/cli/commands/provider/index.js +136 -136
- package/src/cli/commands/provider/models.js +145 -145
- package/src/cli/commands/provider/qwenwork-login.js +119 -119
- package/src/cli/commands/provider/raccoon-login.js +37 -16
- package/src/cli/commands/sync.js +310 -310
- package/src/cli/status.js +279 -279
- package/src/daemon.js +232 -232
- package/src/logs.js +11 -1
- package/src/model-capabilities/enrich.js +86 -86
- package/src/model-capabilities/index.js +183 -183
- package/src/model-capabilities/parse.js +70 -70
- package/src/model-trace.js +8 -1
- package/src/models.js +225 -225
- package/src/providers/cline/auth.js +228 -228
- package/src/providers/cline/chat.js +307 -307
- package/src/providers/cline.js +2 -2
- package/src/providers/codearts/chat.js +182 -182
- package/src/providers/globalqwenwork/cosy.js +123 -123
- package/src/providers/globalqwenwork/crypto.js +218 -218
- package/src/providers/globalqwenwork/http.js +20 -20
- package/src/providers/globalqwenwork/rsa.js +54 -54
- package/src/providers/globalqwenwork/sse.js +268 -268
- package/src/providers/globalqwenwork/stream.js +130 -130
- package/src/providers/globalqwenwork/upstream.js +122 -122
- package/src/providers/keyring.js +60 -60
- package/src/providers/qoder/chat.js +203 -203
- package/src/providers/qoder/index.js +249 -249
- package/src/providers/qoder/sse.js +145 -145
- package/src/providers/qwenwork/account-store.js +133 -133
- package/src/providers/qwenwork/constants.js +67 -67
- package/src/providers/qwenwork/cosy.js +120 -120
- package/src/providers/qwenwork/crypto.js +218 -218
- package/src/providers/qwenwork/http.js +20 -20
- package/src/providers/qwenwork/index.js +337 -337
- package/src/providers/qwenwork/payload.js +144 -144
- package/src/providers/qwenwork/rsa.js +54 -54
- package/src/providers/qwenwork/sse.js +268 -268
- package/src/providers/qwenwork/stream.js +130 -130
- package/src/providers/qwenwork/upstream.js +120 -120
- package/src/providers/qwenwork.js +1 -1
- package/src/providers/raccoon/chat.js +28 -12
- package/src/providers/raccoon/const.js +35 -6
- package/src/providers/raccoon/credits.js +26 -12
- package/src/providers/raccoon/envelope.js +10 -2
- package/src/providers/raccoon/login.js +114 -30
- package/src/providers/registry.js +79 -79
- package/src/providers/workbuddy/auth.js +26 -1
- package/src/providers/workbuddy/chat.js +264 -248
- package/src/providers/workbuddy/index.js +1 -1
- package/src/providers/workbuddy/reshape.js +152 -152
- package/src/providers/workbuddy/rotation-log.js +30 -2
- package/src/providers/workbuddy.js +2 -2
- package/src/reasoning.js +32 -32
- package/src/responses/translate.js +5 -1
- package/src/routes/chat/gateway.js +46 -46
- package/src/routes/chat/relay-pipeline.js +282 -282
- package/src/routes/chat/via-route-handler.js +146 -146
- package/src/routes/hedge.js +260 -253
- package/src/routes/models-route.js +167 -167
- package/src/routes/peers.js +335 -335
- package/src/routes/stream-hold.js +66 -15
- package/src/routes/stream-scan.js +24 -4
- package/src/routes/stream.js +347 -343
- package/src/runtime/bootstrap.js +67 -67
- package/src/runtime/provider-gate.js +36 -36
- package/src/runtime/providers-setup.js +168 -168
- package/src/server.js +78 -78
- package/src/state/schemas/allowlist.js +92 -92
- package/src/sync-opencode.js +280 -280
- package/src/transport/index.js +244 -244
- package/src/transport/pool.js +56 -56
- package/src/transport/retry.js +24 -24
- package/src/transport/sse.js +93 -93
- package/src/upstream-engine/sdk/sse.js +15 -1
- package/src/upstream-probe/display.js +52 -52
- package/src/upstream-probe/probe.js +49 -49
- package/src/upstream-probe/rotate.js +110 -110
- package/src/upstream-probe/start.js +45 -45
- package/src/upstream.js +293 -293
- package/docs/cli_help_mini.md +0 -145
- package/src/providers/AGENTS.md +0 -49
- package/src/routes/AGENTS.md +0 -37
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
raccoonLoginGrantUrl,
|
|
15
15
|
} from "./const.js";
|
|
16
16
|
import { raccoonAuthHeaders } from "./headers.js";
|
|
17
|
+
import { confirmRaccoonSession } from "./login.js";
|
|
17
18
|
import { parseRaccoonEnvelope, raccoonEnvelopeText } from "./envelope.js";
|
|
18
19
|
|
|
19
20
|
const num = (v) => {
|
|
@@ -22,20 +23,33 @@ const num = (v) => {
|
|
|
22
23
|
return undefined;
|
|
23
24
|
};
|
|
24
25
|
|
|
26
|
+
/** 上游「新会话未确认」闸门码:先 POST /iam/confirm 再重试一次(与 chat.js 同款兜底)。 */
|
|
27
|
+
const IAM_CONFIRM_REQUIRED = 200901;
|
|
28
|
+
|
|
25
29
|
async function request(url, { credential, fetchImpl = fetch, env = process.env, method = "GET", body, timeoutMs = RACCOON_REQUEST_TIMEOUT_MS } = {}) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const once = async () => {
|
|
31
|
+
const res = await fetchImpl(url, {
|
|
32
|
+
method,
|
|
33
|
+
headers: raccoonAuthHeaders(credential, { env }),
|
|
34
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
35
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
36
|
+
});
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = await res.json();
|
|
40
|
+
} catch {
|
|
41
|
+
throw new Error(`raccoon: 响应不是 JSON(HTTP ${res.status})`);
|
|
42
|
+
}
|
|
43
|
+
return { res, envelope: parseRaccoonEnvelope(parsed, res.status) };
|
|
44
|
+
};
|
|
45
|
+
let { res, envelope } = await once();
|
|
46
|
+
// 未确认会话闸门:确认一次后重试(老号 / CLI 直连都可能撞上,登录时已确认的号不会走到这)
|
|
47
|
+
if (res.status === 400 && Number(envelope.code) === IAM_CONFIRM_REQUIRED) {
|
|
48
|
+
if (await confirmRaccoonSession(credential, { fetchImpl, env })) {
|
|
49
|
+
({ res, envelope } = await once());
|
|
50
|
+
}
|
|
37
51
|
}
|
|
38
|
-
return
|
|
52
|
+
return envelope;
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
/** 余额五分项(缺项即省略,合计优先取上游的 available_points)。 */
|
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
// raccoon 上游统一信封:`{ code, message, details, data }`(与 pack.js 的 parseEnvelope 同形)。
|
|
2
|
-
//
|
|
2
|
+
// ⚠ 两代通道的成功码不同(2026-10 上游改版):旧 /api/web/* 用数字 `0`,新 /api/iam/v1/* 用字符串 `"OK"`。
|
|
3
|
+
// 故 `code` 原样保留(数字或字符串),判成功一律走 isRaccoonOk()——**不能**再用 `code === 0`:
|
|
4
|
+
// 字符串码一律不等于 0(把 "OK" 判成失败),而把它兜底成 0 又会把 `AUTH_QRCODE_EXPIRED` 判成成功。
|
|
3
5
|
// 登录态类业务码:200001 未带 token、200003 登录态过期 —— 见 const.js 的 RACCOON_ERROR_KINDS。
|
|
4
6
|
export function parseRaccoonEnvelope(payload, status = 200) {
|
|
5
7
|
const record = typeof payload === "object" && payload !== null && !Array.isArray(payload) ? payload : {};
|
|
6
|
-
const
|
|
8
|
+
const raw = record.code;
|
|
9
|
+
const code = typeof raw === "number" || typeof raw === "string" ? raw : status >= 400 ? status : 0;
|
|
7
10
|
const message = typeof record.message === "string" ? record.message : "";
|
|
8
11
|
const details = typeof record.details === "string" ? record.details : "";
|
|
9
12
|
const data = typeof record.data === "object" && record.data !== null && !Array.isArray(record.data) ? record.data : undefined;
|
|
10
13
|
return { code, message, details, data, status };
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
/** 业务成功判据(两代通道通用):数字 0,或新 IAM 通道的字符串 "OK"。 */
|
|
17
|
+
export function isRaccoonOk(envelope) {
|
|
18
|
+
return envelope?.code === 0 || envelope?.code === "OK";
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
/** 人话错误文本:`message: details`,都没有时用调用方给的兜底句。 */
|
|
14
22
|
export function raccoonEnvelopeText(envelope, fallback = "请求失败") {
|
|
15
23
|
const parts = [envelope?.message, envelope?.details].filter((s) => typeof s === "string" && s.length > 0);
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// raccoon 扫码登录状态机与会话续期。
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
2
|
+
// ⚠ 2026-10 上游改版(本机实测):扫码登录**不再是**「客户端自造 code + 旧 web 端点」。
|
|
3
|
+
// 新链路 `/api/iam/v1/auth/mp/qrcode` 里 code 由**服务端签发**(`qr-<uuid>`)并下发
|
|
4
|
+
// scan_path / expires_in / poll_interval。旧写法(`randomBytes(16)` 当 code)在新通道下
|
|
5
|
+
// 没有服务端会话 —— 微信扫码后查不到该码,症状正是「二维码已过期或已被使用」。
|
|
6
|
+
// 新通道同样匿名可达、不需要验证码,故整条链路仍不需要浏览器组件(短信登录才要滑块,本期不做)。
|
|
5
7
|
import {
|
|
6
8
|
RACCOON_LOGIN_POLL_INTERVAL_MS,
|
|
7
9
|
RACCOON_LOGIN_TIMEOUT_MS,
|
|
8
10
|
RACCOON_REQUEST_TIMEOUT_MS,
|
|
9
|
-
|
|
11
|
+
raccoonIamConfirmUrl,
|
|
12
|
+
raccoonQrCancelUrl,
|
|
13
|
+
raccoonQrCreateUrl,
|
|
10
14
|
raccoonQrPageUrl,
|
|
15
|
+
raccoonQrPollUrl,
|
|
11
16
|
raccoonRefreshUrl,
|
|
12
17
|
raccoonUserInfoUrl,
|
|
13
18
|
} from "./const.js";
|
|
14
19
|
import { raccoonAnonymousHeaders, raccoonAuthHeaders } from "./headers.js";
|
|
15
20
|
import { decodeJwtExpMs } from "./auth.js";
|
|
16
|
-
import { parseRaccoonEnvelope, raccoonEnvelopeText } from "./envelope.js";
|
|
21
|
+
import { isRaccoonOk, parseRaccoonEnvelope, raccoonEnvelopeText } from "./envelope.js";
|
|
17
22
|
|
|
18
|
-
/** 上游 `data.status`
|
|
23
|
+
/** 上游 `data.status` 四态(与网站登录页 chunk 实测一致)。 */
|
|
19
24
|
export const RACCOON_QR_STATUS = Object.freeze({
|
|
20
25
|
pending: "pending",
|
|
21
26
|
logging: "logging",
|
|
@@ -23,24 +28,17 @@ export const RACCOON_QR_STATUS = Object.freeze({
|
|
|
23
28
|
success: "success",
|
|
24
29
|
});
|
|
25
30
|
|
|
26
|
-
/**
|
|
27
|
-
export
|
|
28
|
-
return randomBytes(16).toString("hex");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** 二维码/链接内容:用户用手机扫码或直接打开它完成确认。 */
|
|
32
|
-
export function buildQrUrl(code) {
|
|
33
|
-
return raccoonQrPageUrl(code);
|
|
34
|
-
}
|
|
31
|
+
/** 码在服务端不存在/已作废时 IAM 通道回的业务码。 */
|
|
32
|
+
export const RACCOON_QR_EXPIRED_CODE = "AUTH_QRCODE_EXPIRED";
|
|
35
33
|
|
|
36
34
|
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
37
35
|
|
|
38
|
-
async function postJson(url, body, { fetchImpl = fetch, env = process.env, timeoutMs = RACCOON_REQUEST_TIMEOUT_MS } = {}) {
|
|
36
|
+
async function postJson(url, body, { fetchImpl = fetch, env = process.env, timeoutMs = RACCOON_REQUEST_TIMEOUT_MS, method = "POST" } = {}) {
|
|
39
37
|
let res;
|
|
40
38
|
try {
|
|
41
39
|
res = await fetchImpl(url, {
|
|
42
|
-
method
|
|
43
|
-
headers: raccoonAnonymousHeaders({ env }),
|
|
40
|
+
method,
|
|
41
|
+
headers: { ...raccoonAnonymousHeaders({ env }), "Accept-Language": "zh-CN" },
|
|
44
42
|
body: JSON.stringify(body),
|
|
45
43
|
signal: AbortSignal.timeout(timeoutMs),
|
|
46
44
|
});
|
|
@@ -56,6 +54,46 @@ async function postJson(url, body, { fetchImpl = fetch, env = process.env, timeo
|
|
|
56
54
|
return parseRaccoonEnvelope(parsed, res.status);
|
|
57
55
|
}
|
|
58
56
|
|
|
57
|
+
/**
|
|
58
|
+
* 请服务端签发一个二维码会话。
|
|
59
|
+
*
|
|
60
|
+
* 返回 `{ qrcodeCode, scanPath, expiresIn, pollInterval, qrUrl }`。
|
|
61
|
+
* 任何字段不合契约都**抛错**而不是产出降级码 —— 自造 code 正是这次故障的根因,
|
|
62
|
+
* 再"兜底"一个扫不出来的码等于把同一类故障换个说法。
|
|
63
|
+
*/
|
|
64
|
+
export async function createQrSession(opts = {}) {
|
|
65
|
+
const envelope = await postJson(raccoonQrCreateUrl(), { product_codes: [] }, opts);
|
|
66
|
+
if (!isRaccoonOk(envelope)) throw new Error(`raccoon: 二维码签发失败:${raccoonEnvelopeText(envelope)}`);
|
|
67
|
+
const code = typeof envelope.data?.qrcode_code === "string" ? envelope.data.qrcode_code.trim() : "";
|
|
68
|
+
if (!code) throw new Error("raccoon: 二维码签发响应缺少 qrcode_code");
|
|
69
|
+
const scanPath = typeof envelope.data.scan_path === "string" ? envelope.data.scan_path : "/login/mp";
|
|
70
|
+
const expiresIn = Number(envelope.data.expires_in);
|
|
71
|
+
const pollInterval = Number(envelope.data.poll_interval);
|
|
72
|
+
return {
|
|
73
|
+
qrcodeCode: code,
|
|
74
|
+
scanPath,
|
|
75
|
+
expiresInMs: Number.isFinite(expiresIn) && expiresIn > 0 ? expiresIn * 1000 : RACCOON_LOGIN_TIMEOUT_MS,
|
|
76
|
+
pollIntervalMs: Number.isFinite(pollInterval) && pollInterval > 0
|
|
77
|
+
? Math.max(1000, Math.min(60_000, pollInterval * 1000))
|
|
78
|
+
: RACCOON_LOGIN_POLL_INTERVAL_MS,
|
|
79
|
+
qrUrl: raccoonQrPageUrl(code, scanPath),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 递归渲染用的二维码内容;scanPath 由签发响应给出。 */
|
|
84
|
+
export function buildQrUrl(code, scanPath) {
|
|
85
|
+
return raccoonQrPageUrl(code, scanPath);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 回收服务端会话(过期/退出时调用,失败不影响用户)。 */
|
|
89
|
+
export async function cancelQrSession(code, opts = {}) {
|
|
90
|
+
try {
|
|
91
|
+
await postJson(raccoonQrCancelUrl(), { qrcode_code: String(code || ""), status: "canceled" }, { ...opts, method: "PUT" });
|
|
92
|
+
} catch {
|
|
93
|
+
// 取消是礼貌动作,不是流程一部分:网络不通时静默即可(码自己会到期)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
59
97
|
/** 从登录成功信封里取凭据;缺 access_token 视为失败(不写半截凭据)。 */
|
|
60
98
|
export function raccoonCredentialFromEnvelope(envelope) {
|
|
61
99
|
const data = envelope?.data ?? {};
|
|
@@ -74,32 +112,44 @@ export function raccoonCredentialFromEnvelope(envelope) {
|
|
|
74
112
|
|
|
75
113
|
/**
|
|
76
114
|
* 轮询一轮。网络抖动一律折成 `pending`(用户还在扫码,不该因为一次超时把整轮打断);
|
|
77
|
-
* `canceled` / `success` 是终态。
|
|
115
|
+
* `canceled` / `expired` / `success` 是终态。
|
|
78
116
|
*/
|
|
79
117
|
export async function pollQrLoginOnce(code, opts = {}) {
|
|
80
118
|
let envelope;
|
|
81
119
|
try {
|
|
82
|
-
envelope = await postJson(
|
|
120
|
+
envelope = await postJson(raccoonQrPollUrl(), { qrcode_code: String(code || "") }, opts);
|
|
83
121
|
} catch {
|
|
84
122
|
return { status: RACCOON_QR_STATUS.pending };
|
|
85
123
|
}
|
|
86
|
-
if (envelope
|
|
124
|
+
if (!isRaccoonOk(envelope)) {
|
|
125
|
+
// 码在服务端不存在/已作废 —— 必须区分出来:继续轮询只会一直失败,用户却以为还在等扫描
|
|
126
|
+
if (String(envelope.code) === RACCOON_QR_EXPIRED_CODE) return { status: "expired" };
|
|
127
|
+
return { status: RACCOON_QR_STATUS.pending };
|
|
128
|
+
}
|
|
129
|
+
if (envelope.data === undefined) return { status: RACCOON_QR_STATUS.pending };
|
|
87
130
|
const status = typeof envelope.data.status === "string" ? envelope.data.status : "";
|
|
88
131
|
const expiredAt = typeof envelope.data.expired_at === "string" ? envelope.data.expired_at : undefined;
|
|
132
|
+
const pollIntervalMs = Number.isFinite(Number(envelope.data.poll_interval)) && Number(envelope.data.poll_interval) > 0
|
|
133
|
+
? Number(envelope.data.poll_interval) * 1000
|
|
134
|
+
: undefined;
|
|
135
|
+
const jitter = pollIntervalMs === undefined ? {} : { pollIntervalMs };
|
|
89
136
|
if (status === RACCOON_QR_STATUS.canceled) return { status: RACCOON_QR_STATUS.canceled };
|
|
90
|
-
if (status === RACCOON_QR_STATUS.logging) return { status: RACCOON_QR_STATUS.logging, ...(expiredAt ? { expiredAt } : {}) };
|
|
137
|
+
if (status === RACCOON_QR_STATUS.logging) return { status: RACCOON_QR_STATUS.logging, ...jitter, ...(expiredAt ? { expiredAt } : {}) };
|
|
91
138
|
if (status === RACCOON_QR_STATUS.success) {
|
|
92
139
|
try {
|
|
93
|
-
return { status: RACCOON_QR_STATUS.success, credential: raccoonCredentialFromEnvelope(envelope) };
|
|
140
|
+
return { status: RACCOON_QR_STATUS.success, ...jitter, credential: raccoonCredentialFromEnvelope(envelope) };
|
|
94
141
|
} catch {
|
|
95
|
-
return { status: RACCOON_QR_STATUS.pending };
|
|
142
|
+
return { status: RACCOON_QR_STATUS.pending, ...jitter };
|
|
96
143
|
}
|
|
97
144
|
}
|
|
98
|
-
return { status: RACCOON_QR_STATUS.pending };
|
|
145
|
+
return { status: RACCOON_QR_STATUS.pending, ...jitter };
|
|
99
146
|
}
|
|
100
147
|
|
|
101
148
|
/**
|
|
102
|
-
* 轮询直到终态。返回 `{ status, credential? }
|
|
149
|
+
* 轮询直到终态。返回 `{ status, credential? }`。
|
|
150
|
+
*
|
|
151
|
+
* `deadlineMs` 用**服务端下发的有效期**(不是本地常量):码的生死由上游决定,
|
|
152
|
+
* 本地猜一个更长的窗口只会在码已作废后继续空转,把「已过期」拖成「超时」。
|
|
103
153
|
* 超时返回 `{ status: "timeout" }`(调用方据此输出人话并非零退出)。
|
|
104
154
|
*/
|
|
105
155
|
export async function pollQrLogin(code, {
|
|
@@ -113,6 +163,7 @@ export async function pollQrLogin(code, {
|
|
|
113
163
|
} = {}) {
|
|
114
164
|
const deadline = now() + timeoutMs;
|
|
115
165
|
let ticks = 0;
|
|
166
|
+
let interval = intervalMs;
|
|
116
167
|
for (;;) {
|
|
117
168
|
const result = await pollQrLoginOnce(code, { fetchImpl, env });
|
|
118
169
|
ticks += 1;
|
|
@@ -121,8 +172,11 @@ export async function pollQrLogin(code, {
|
|
|
121
172
|
}
|
|
122
173
|
if (result.status === RACCOON_QR_STATUS.success) return result;
|
|
123
174
|
if (result.status === RACCOON_QR_STATUS.canceled) return { status: RACCOON_QR_STATUS.canceled };
|
|
175
|
+
if (result.status === "expired") return { status: "expired" };
|
|
176
|
+
// 服务端可以调快/调慢节奏,以它下发的为准(夹在 1s–60s,防被一个坏值卡住)
|
|
177
|
+
if (Number.isFinite(result.pollIntervalMs)) interval = Math.max(1000, Math.min(60_000, result.pollIntervalMs));
|
|
124
178
|
if (now() >= deadline) return { status: "timeout" };
|
|
125
|
-
await sleepFn(
|
|
179
|
+
await sleepFn(interval);
|
|
126
180
|
}
|
|
127
181
|
}
|
|
128
182
|
|
|
@@ -150,12 +204,13 @@ export async function refreshRaccoonCredential(credential, opts = {}) {
|
|
|
150
204
|
throw new Error(`raccoon: 续期响应不是 JSON(HTTP ${res.status})`);
|
|
151
205
|
}
|
|
152
206
|
const envelope = parseRaccoonEnvelope(parsed, res.status);
|
|
153
|
-
|
|
207
|
+
// 登录态失效判据两代都收:旧通道数字 200003,IAM 通道字符串 AUTH_ACCESS_TOKEN_EXPIRED
|
|
208
|
+
if (res.status === 401 || envelope.code === 200003 || String(envelope.code) === "AUTH_ACCESS_TOKEN_EXPIRED") {
|
|
154
209
|
const err = new Error("raccoon: 登录态已过期,请重新登录");
|
|
155
210
|
err.authExpired = true;
|
|
156
211
|
throw err;
|
|
157
212
|
}
|
|
158
|
-
if (envelope
|
|
213
|
+
if (!isRaccoonOk(envelope)) throw new Error(`raccoon: 续期失败:${raccoonEnvelopeText(envelope)}`);
|
|
159
214
|
const accessToken = typeof envelope.data?.access_token === "string" ? envelope.data.access_token : "";
|
|
160
215
|
if (!accessToken) throw new Error("raccoon: 续期响应缺少 access_token");
|
|
161
216
|
const nextRefresh = typeof envelope.data.refresh_token === "string" && envelope.data.refresh_token.length > 0
|
|
@@ -170,6 +225,35 @@ export async function refreshRaccoonCredential(credential, opts = {}) {
|
|
|
170
225
|
};
|
|
171
226
|
}
|
|
172
227
|
|
|
228
|
+
/**
|
|
229
|
+
* IAM 会话确认(POST /api/web/auth/v1/iam/confirm,body `{}`,带 Bearer)。
|
|
230
|
+
*
|
|
231
|
+
* 2026-10-18 故障取证:上游新登录的会话未确认前,业务端点一律回
|
|
232
|
+
* `400 {"code":200901,"message":"iam_confirm_required"}`(桌面端旧会话早已确认,
|
|
233
|
+
* 所以官方 App 无感)。官方前端(c6.js)的处理是「撞 200901 → confirm → 重试原请求」,
|
|
234
|
+
* 我们对齐同款:chat.js 兜底重试 + 登录成功后主动确认一次。
|
|
235
|
+
* 返回是否确认成功;任何失败都吞掉返回 false(由调用方的懒重试兜底,绝不阻断主流程)。
|
|
236
|
+
*/
|
|
237
|
+
export async function confirmRaccoonSession(credential, { fetchImpl = fetch, env = process.env, timeoutMs = RACCOON_REQUEST_TIMEOUT_MS } = {}) {
|
|
238
|
+
try {
|
|
239
|
+
const res = await fetchImpl(raccoonIamConfirmUrl(), {
|
|
240
|
+
method: "POST",
|
|
241
|
+
headers: raccoonAuthHeaders(credential, { env }),
|
|
242
|
+
body: "{}",
|
|
243
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
244
|
+
});
|
|
245
|
+
let parsed = null;
|
|
246
|
+
try {
|
|
247
|
+
parsed = await res.json();
|
|
248
|
+
} catch {
|
|
249
|
+
parsed = null;
|
|
250
|
+
}
|
|
251
|
+
return res.ok && isRaccoonOk(parseRaccoonEnvelope(parsed, res.status));
|
|
252
|
+
} catch {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
173
257
|
/** 取用户信息(uid/昵称/手机号/office_identity);任何失败都返回空对象,不阻断登录。 */
|
|
174
258
|
export async function fetchRaccoonUserInfo(credential, opts = {}) {
|
|
175
259
|
const { fetchImpl = fetch, env = process.env, timeoutMs = RACCOON_REQUEST_TIMEOUT_MS } = opts;
|
|
@@ -181,7 +265,7 @@ export async function fetchRaccoonUserInfo(credential, opts = {}) {
|
|
|
181
265
|
});
|
|
182
266
|
if (!res.ok) return {};
|
|
183
267
|
const envelope = parseRaccoonEnvelope(await res.json(), res.status);
|
|
184
|
-
if (envelope
|
|
268
|
+
if (!isRaccoonOk(envelope) || envelope.data === undefined) return {};
|
|
185
269
|
const pick = (k) => (typeof envelope.data[k] === "string" ? envelope.data[k] : "");
|
|
186
270
|
return {
|
|
187
271
|
userId: pick("id"),
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 可扩展供应商注册表:新增特殊供应商时,仅在此文件注册 + 新增对应 provider 文件即可
|
|
3
|
-
* 每个条目:{ id, match(id, baseUrl) => bool, load() => Promise<factory> }
|
|
4
|
-
* 匹配优先级:按数组顺序,首个命中即用;未命中走通用 generic
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const customProviders = [
|
|
8
|
-
{
|
|
9
|
-
id: "workbuddy",
|
|
10
|
-
match: (id, baseUrl) => id === "workbuddy" || String(baseUrl).includes("copilot.tencent"),
|
|
11
|
-
load: () => import("./workbuddy.js").then((m) => m.createWorkbuddyProvider),
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
id: "traework",
|
|
15
|
-
match: (id, baseUrl) => id === "traework" || String(baseUrl).includes("trae"),
|
|
16
|
-
load: () => import("./traework.js").then((m) => m.createTraeworkProvider),
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
id: "cline",
|
|
20
|
-
match: (id, baseUrl) => id === "cline" || String(baseUrl).includes("cline.bot"),
|
|
21
|
-
load: () => import("./cline.js").then((m) => m.createClineProvider),
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
id: "codearts",
|
|
25
|
-
match: (id, baseUrl) => id === "codearts" || String(baseUrl).includes("myhuaweicloud.com"),
|
|
26
|
-
load: () => import("./codearts.js").then((m) => m.createCodeartsProvider),
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: "qoder",
|
|
30
|
-
match: (id, baseUrl) => id === "qoder" || String(baseUrl).includes("qoder"),
|
|
31
|
-
load: () => import("./qoder/index.js").then((m) => m.createQoderProvider),
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
// ⚠ 必须排在 qwenwork 之前:qwenwork 的 match 用 `includes("qwenwork")`,
|
|
35
|
-
// 而 "globalqwenwork" 与 "gateway.qwenwork.ai"/"globalqwenwork://native" 都含该子串,
|
|
36
|
-
// 若后置会被 cn 条目抢先命中(first-match-wins),把国际站 token 打到 cn 网关。
|
|
37
|
-
id: "globalqwenwork",
|
|
38
|
-
match: (id, baseUrl) => id === "globalqwenwork" || String(baseUrl).includes("qwenwork.ai"),
|
|
39
|
-
load: () => import("./globalqwenwork/index.js").then((m) => m.createGlobalQwenworkProvider),
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: "qwenwork",
|
|
43
|
-
match: (id, baseUrl) => id === "qwenwork" || String(baseUrl).includes("qwenwork"),
|
|
44
|
-
load: () => import("./qwenwork/index.js").then((m) => m.createQwenworkProvider),
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: "zcode",
|
|
48
|
-
match: (id, baseUrl) => id === "zcode" || String(baseUrl).includes("zcode.z.ai"),
|
|
49
|
-
load: () => import("./zcode/index.js").then((m) => m.createZcodeProvider),
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
id: "raccoon",
|
|
53
|
-
match: (id, baseUrl) => id === "raccoon" || String(baseUrl).includes("xiaohuanxiong.com"),
|
|
54
|
-
load: () => import("./raccoon/index.js").then((m) => m.createRaccoonProvider),
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
// 供 bench/probe 等需要定制化解析模型列表的场景
|
|
59
|
-
export const customNormalizers = [
|
|
60
|
-
{
|
|
61
|
-
id: "cline",
|
|
62
|
-
match: (baseUrl) => String(baseUrl).includes("cline.bot"),
|
|
63
|
-
normalize: (json) => Array.isArray(json?.free) ? json.free : null,
|
|
64
|
-
},
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
export async function getCustomProviderFactory(id, baseUrl) {
|
|
68
|
-
for (const entry of customProviders) {
|
|
69
|
-
try { if (entry.match(id, baseUrl)) return await entry.load(); } catch {}
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getCustomNormalizer(baseUrl) {
|
|
75
|
-
for (const entry of customNormalizers) {
|
|
76
|
-
try { if (entry.match(baseUrl)) return entry.normalize; } catch {}
|
|
77
|
-
}
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 可扩展供应商注册表:新增特殊供应商时,仅在此文件注册 + 新增对应 provider 文件即可
|
|
3
|
+
* 每个条目:{ id, match(id, baseUrl) => bool, load() => Promise<factory> }
|
|
4
|
+
* 匹配优先级:按数组顺序,首个命中即用;未命中走通用 generic
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const customProviders = [
|
|
8
|
+
{
|
|
9
|
+
id: "workbuddy",
|
|
10
|
+
match: (id, baseUrl) => id === "workbuddy" || String(baseUrl).includes("copilot.tencent"),
|
|
11
|
+
load: () => import("./workbuddy.js").then((m) => m.createWorkbuddyProvider),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: "traework",
|
|
15
|
+
match: (id, baseUrl) => id === "traework" || String(baseUrl).includes("trae"),
|
|
16
|
+
load: () => import("./traework.js").then((m) => m.createTraeworkProvider),
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "cline",
|
|
20
|
+
match: (id, baseUrl) => id === "cline" || String(baseUrl).includes("cline.bot"),
|
|
21
|
+
load: () => import("./cline.js").then((m) => m.createClineProvider),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "codearts",
|
|
25
|
+
match: (id, baseUrl) => id === "codearts" || String(baseUrl).includes("myhuaweicloud.com"),
|
|
26
|
+
load: () => import("./codearts.js").then((m) => m.createCodeartsProvider),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "qoder",
|
|
30
|
+
match: (id, baseUrl) => id === "qoder" || String(baseUrl).includes("qoder"),
|
|
31
|
+
load: () => import("./qoder/index.js").then((m) => m.createQoderProvider),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
// ⚠ 必须排在 qwenwork 之前:qwenwork 的 match 用 `includes("qwenwork")`,
|
|
35
|
+
// 而 "globalqwenwork" 与 "gateway.qwenwork.ai"/"globalqwenwork://native" 都含该子串,
|
|
36
|
+
// 若后置会被 cn 条目抢先命中(first-match-wins),把国际站 token 打到 cn 网关。
|
|
37
|
+
id: "globalqwenwork",
|
|
38
|
+
match: (id, baseUrl) => id === "globalqwenwork" || String(baseUrl).includes("qwenwork.ai"),
|
|
39
|
+
load: () => import("./globalqwenwork/index.js").then((m) => m.createGlobalQwenworkProvider),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "qwenwork",
|
|
43
|
+
match: (id, baseUrl) => id === "qwenwork" || String(baseUrl).includes("qwenwork"),
|
|
44
|
+
load: () => import("./qwenwork/index.js").then((m) => m.createQwenworkProvider),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "zcode",
|
|
48
|
+
match: (id, baseUrl) => id === "zcode" || String(baseUrl).includes("zcode.z.ai"),
|
|
49
|
+
load: () => import("./zcode/index.js").then((m) => m.createZcodeProvider),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "raccoon",
|
|
53
|
+
match: (id, baseUrl) => id === "raccoon" || String(baseUrl).includes("xiaohuanxiong.com"),
|
|
54
|
+
load: () => import("./raccoon/index.js").then((m) => m.createRaccoonProvider),
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
// 供 bench/probe 等需要定制化解析模型列表的场景
|
|
59
|
+
export const customNormalizers = [
|
|
60
|
+
{
|
|
61
|
+
id: "cline",
|
|
62
|
+
match: (baseUrl) => String(baseUrl).includes("cline.bot"),
|
|
63
|
+
normalize: (json) => Array.isArray(json?.free) ? json.free : null,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
export async function getCustomProviderFactory(id, baseUrl) {
|
|
68
|
+
for (const entry of customProviders) {
|
|
69
|
+
try { if (entry.match(id, baseUrl)) return await entry.load(); } catch {}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function getCustomNormalizer(baseUrl) {
|
|
75
|
+
for (const entry of customNormalizers) {
|
|
76
|
+
try { if (entry.match(baseUrl)) return entry.normalize; } catch {}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
@@ -27,6 +27,32 @@ export function isInsufficientStatus(status, bodyText, cached) {
|
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// 频率限制:上游「这个号这一秒用量超了」——该换号顶,但**不是**这个号没额度了。
|
|
31
|
+
// 与 isInsufficientStatus 严格分开:后者命中会被 chat.js 把该号余额标 0(永久跳过),
|
|
32
|
+
// 而腾讯 workbuddy 的 6004 是「使用量已超出频率限制,将在 <时间> 重置」+ 中文措辞,
|
|
33
|
+
// 既不含任何英文字样也没有额度码——历史上正是这里不认,导致 429 原样吐给客户端、从不换号。
|
|
34
|
+
// Note: 为什么 6004 必须走独立判定而不是并入 insufficient — 见 .agents/notes/implemented/bug-fix/2026-10-18-workbuddy-6004-rate-limit-rotate.md
|
|
35
|
+
export function isRateLimitedStatus(status, bodyText) {
|
|
36
|
+
if (status !== 429) return false;
|
|
37
|
+
const t = String(bodyText || "");
|
|
38
|
+
if (/"code"\s*:\s*6004\b/.test(t)) return true;
|
|
39
|
+
const lower = t.toLowerCase();
|
|
40
|
+
if (lower.includes("frequency limit") || lower.includes("rate limit") || lower.includes("too many requests")) return true;
|
|
41
|
+
if (t.includes("频率限制") || t.includes("请求过于频繁") || t.includes("使用量已超出")) return true;
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 上游 msg 里的重置时刻("将在 2026-10-18 21:14:48 UTC+8 重置")→ 建议冷却毫秒数;
|
|
46
|
+
// 解析不出返回 0,调用方退回到固定冷却档,绝不因此把号判死。
|
|
47
|
+
export function parseRateLimitResetMs(bodyText, clock = Date.now) {
|
|
48
|
+
const m = String(bodyText || "").match(/(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2})\s*(?:UTC\+8)?\s*重置/);
|
|
49
|
+
if (!m) return 0;
|
|
50
|
+
const at = Date.parse(`${m[1]}T${m[2]}+08:00`);
|
|
51
|
+
if (!Number.isFinite(at)) return 0;
|
|
52
|
+
const ms = at - clock();
|
|
53
|
+
return ms > 0 ? ms : 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
30
56
|
export function isAuthError(status, bodyText) {
|
|
31
57
|
if (status === 401 || status === 403) return true;
|
|
32
58
|
const t = String(bodyText || "").toLowerCase();
|
|
@@ -35,7 +61,6 @@ export function isAuthError(status, bodyText) {
|
|
|
35
61
|
if (status === 400 && t.includes("token")) return true;
|
|
36
62
|
return false;
|
|
37
63
|
}
|
|
38
|
-
|
|
39
64
|
export function createAuthService({
|
|
40
65
|
baseUrl,
|
|
41
66
|
fetchImpl,
|