diff --git a/packages/autoclaw/README.en.md b/packages/autoclaw/README.en.md index d789075..56890f8 100644 --- a/packages/autoclaw/README.en.md +++ b/packages/autoclaw/README.en.md @@ -108,7 +108,7 @@ AutoClaw's chat gateway enforces a strict request shape; missing any item return - **max_tokens removed**: the gateway refuses `max_tokens` / `max_completion_tokens`; the plugin strips them before sending - **No X-Harness-Type**: the upstream 406s on that header; the legacy header is deleted - **External harness identity lines rewritten**: the upstream intercepts system messages that announce an external agent identity ("You are Codex", "You are Claude Code", …); the plugin's `unflag` rewrites them into compatible wording -- **Official client fingerprint (international chat)**: international chat requests carry the full header set of the official AutoClaw 2.0.3 desktop client (`official` channel), taken from its AppImage's `dist/main.cjs`: `X-Channel: official`, `X-Version: 2.0.3`, `X-Lang: en`, `X-Client-Type: pc`, `X-Product: autoclaw`, `x_trace_id: autoclaw-desktop`, `X-Auth-Appid/X-Auth-TimeStamp/X-Auth-Sign` (`md5("100003&&")`, the same signature as sign-in and credits), `X-Request-Id` = `X-Trace-Id` (one UUID per request), `X-Session-Id` (a UUID constant per conversation, derived from the first message), OpenAI SDK 6.26.0's `User-Agent` and `X-Stainless-*`. `X-Tm` follows the official `managedPlatform()`: macOS `mac`, Windows `win`, Linux `linux` (x64/arm64 alike). Next to a **non-official** fingerprint the gateway refuses `X-Tm: linux` (403 `forbidden`, #367); the `linux-x64` sent by 0.2.7–0.2.11 was a workaround, not the official value. +- **Official client fingerprint (international chat)**: international chat requests carry the full header set of the official AutoClaw 2.0.3 desktop client (`official` channel), taken from its AppImage's `dist/main.cjs`: `X-Channel: official`, `X-Version: 2.0.3`, `X-Lang: en`, `X-Client-Type: pc`, `X-Product: autoclaw`, `x_trace_id: autoclaw-desktop`, `X-Auth-Appid/X-Auth-TimeStamp/X-Auth-Sign` (`md5("100003&&")`, the same signature as sign-in and credits), `X-Request-Id` = `X-Trace-Id` (one UUID per request), `X-Session-Id` (a UUID constant per conversation, derived from the first message), OpenAI SDK 6.26.0's `User-Agent` and `X-Stainless-*`. macOS / Windows keep the official `managedPlatform()` value (`mac` / `win`). International chat omits `X-Tm` on Linux because the gateway still rejects the exact `linux` value for plugin accounts (403 `forbidden` on both x64 and arm64, #367); reporters verified omission works, and it does not impersonate another OS. The CN build `autoclaw-cn` goes through AutoClaw 2.1.0's managed gateway (`autoglm-acceleration-api.zhipuai.cn`); the international `autoclaw` goes through the overseas direct gateway (`autoglm-api.autoglm.ai`). Both verified with real calls and inference. @@ -120,7 +120,7 @@ A 406's upstream body is empty and magpie keeps only token counts — diagnosing ## Known behavior -- Phone-number accounts only ever use the CN host (managed gateway; 401/403 mark the sign-in expired); z.ai/Google accounts only the international host (401/403 retries the other side, both refusing marks it expired). +- Phone-number accounts only ever use the CN host (managed gateway; 401/403 mark the sign-in expired); z.ai/Google accounts only the international host (401/403 retries the other side, both refusing marks it expired). Exception: on an exact bare `403 forbidden`, the plugin checks the credits route: a healthy credential keeps the sign-in and surfaces the client-fingerprint refusal; a credential refused there expires; a failed check passes the upstream 403 through without guessing the sign-in state. - An exhausted quota is not a signed-out account: a `403` + `{"code":810000,"message":"GLM-5.3 免费额度已用完,…"}` answer (or a 403 body about quotas/balances) becomes a `429` carrying the upstream's own words, the sign-in is kept (`X-Magpie-Sign-In: kept`), and the international side stops host-hopping (plugins#274). - A banned account is not a signed-out account: a `403` + `{"code":410004,"message":"The account has been banned"}` answer (or code/message fields saying banned / 封禁 / 账号异常 / 账号被冻结) flows through on chat, refresh, credits and check-in with the upstream's own words; chat becomes a `403 permission_error`, the sign-in is kept, no host-hopping. Other 401/403s still mark the sign-in expired. - A request too large is not a signed-out account (plugins#891): the CN gateway answers a ~200k-token request `401 AutoClaw 登录状态失效` while the same token's smaller requests seconds before and after get 200. A 401/403 for a body larger than the largest this process has seen answered has its sign-in checked on the credits route: a sign-in that holds turns it into `413 request_too_large` with the sign-in kept, so magpie tries another route or has the agent compact. A sign-in refused there too, a check that fails, or a body no larger than one answered is still the sign-in. No threshold is guessed; the comparison is with the largest request answered. diff --git a/packages/autoclaw/README.md b/packages/autoclaw/README.md index 26e47f6..ac1feb1 100644 --- a/packages/autoclaw/README.md +++ b/packages/autoclaw/README.md @@ -108,7 +108,7 @@ AutoClaw 对话网关对请求形状有硬性要求,缺任一条都回 `406 No - **删除 max_tokens**:网关拒收 `max_tokens` / `max_completion_tokens`,插件会在发送前自动剔除 - **不发送 X-Harness-Type**:上游收到 `X-Harness-Type` 即报 406,已删除该残留请求头 - **改写外部 Harness 身份声明**:上游拦截 system 中包含的外部 agent 身份句(如 `You are Codex`、`You are Claude Code` 等),插件的 `unflag` 会自动将其替换为兼容措辞,避免 406 拦截 -- **官方客户端指纹(国际版对话)**:国际版对话请求带官方 AutoClaw 2.0.3 桌面端(`official` 渠道)的整套请求头,取自其 AppImage 的 `dist/main.cjs`:`X-Channel: official`、`X-Version: 2.0.3`、`X-Lang: en`、`X-Client-Type: pc`、`X-Product: autoclaw`、`x_trace_id: autoclaw-desktop`、`X-Auth-Appid/X-Auth-TimeStamp/X-Auth-Sign`(`md5("100003&<秒级时间戳>&")`,与登录/积分接口同一签名)、`X-Request-Id` = `X-Trace-Id`(每次请求一个 UUID)、`X-Session-Id`(同一对话不变的 UUID,插件由对话首条消息导出)、OpenAI SDK 6.26.0 的 `User-Agent` 与 `X-Stainless-*`。`X-Tm` 与官方 `managedPlatform()` 一致:macOS `mac`、Windows `win`、Linux `linux`(x64/arm64 相同)。网关只在**非官方指纹**旁拒收 `X-Tm: linux`(403 `forbidden`,#367);0.2.7–0.2.11 发的 `linux-x64` 只是绕过,不是官方值。 +- **官方客户端指纹(国际版对话)**:国际版对话请求带官方 AutoClaw 2.0.3 桌面端(`official` 渠道)的整套请求头,取自其 AppImage 的 `dist/main.cjs`:`X-Channel: official`、`X-Version: 2.0.3`、`X-Lang: en`、`X-Client-Type: pc`、`X-Product: autoclaw`、`x_trace_id: autoclaw-desktop`、`X-Auth-Appid/X-Auth-TimeStamp/X-Auth-Sign`(`md5("100003&<秒级时间戳>&")`,与登录/积分接口同一签名)、`X-Request-Id` = `X-Trace-Id`(每次请求一个 UUID)、`X-Session-Id`(同一对话不变的 UUID,插件由对话首条消息导出)、OpenAI SDK 6.26.0 的 `User-Agent` 与 `X-Stainless-*`。macOS / Windows 的 `X-Tm` 与官方 `managedPlatform()` 一致(`mac` / `win`);Linux 国际版省略该头,因为网关仍会对插件账号精确拒收 `X-Tm: linux`(x64/arm64 都是 403 `forbidden`,#367),而省略已由报告者验证可用,也不会伪装成别的系统。 国内版 `autoclaw-cn` 走 AutoClaw 2.1.0 managed gateway(`autoglm-acceleration-api.zhipuai.cn`);国际版 `autoclaw` 走海外直连网关(`autoglm-api.autoglm.ai`)。两者均已通过真实调用与推理验证。 @@ -120,7 +120,7 @@ AutoClaw 对话网关对请求形状有硬性要求,缺任一条都回 `406 No ## 已知行为 -- 手机号账号只认国内 host(走 managed gateway,401/403 标记登录失效);z.ai/Google 账号只认国际 host(401/403 自动换侧重试,均拒绝时标记失效)。 +- 手机号账号只认国内 host(走 managed gateway,401/403 标记登录失效);z.ai/Google 账号只认国际 host(401/403 自动换侧重试,均拒绝时标记失效)。例外:国际网关精确返回裸 `403 forbidden` 时,插件用积分接口确认登录:凭据有效则按客户端指纹拒绝显示上游错误并保留登录;凭据也被拒则标记失效;确认失败则原样透传 403,不猜登录状态。 - 额度用完不算登录失效:上游以 `403` + `{"code":810000,"message":"GLM-5.3 免费额度已用完,…"}` 回答时(或 403 正文说额度/余额已用完),插件转成 `429`,原样带上游文案,登录保留(`X-Magpie-Sign-In: kept`),国际版也不再换 host 重试(plugins#274)。 - 账号被封不算登录失效:上游以 `403` + `{"code":410004,"message":"The account has been banned"}` 回答时(或 code/message 字段说 banned / 封禁 / 账号异常 / 账号被冻结等),对话、刷新、积分与签到都原样带上游文案,对话转成 `403 permission_error`,登录保留(`X-Magpie-Sign-In: kept`),不再换 host 重试。其他 401/403 仍按登录失效处理。 - 请求过大不算登录失效(plugins#891):国内网关会对约 200k tokens 的请求回 `401 AutoClaw 登录状态失效`,而同一凭据前后几秒的小请求都是 200。请求体比本进程见过的最大成功请求还大时遇到 401/403,插件先用积分接口确认登录:登录有效就转成 `413 request_too_large`(登录保留),magpie 换一条路由或让 agent 压缩对话;登录也被拒、确认失败,或请求不比已成功的大,仍按登录失效处理。不猜阈值,只拿已成功的最大请求作比较。 diff --git a/packages/autoclaw/index.mjs b/packages/autoclaw/index.mjs index b146e33..5abfd1d 100644 --- a/packages/autoclaw/index.mjs +++ b/packages/autoclaw/index.mjs @@ -35,8 +35,9 @@ const PLATFORM = process.platform === "darwin" ? "mac" : process.platform === "w /** X-Tm as the official AutoClaw 2.0.3 client builds it (managedPlatform() * in its main.cjs): darwin is "mac", win32 is "win", anything else is * process.platform as is, so Linux is "linux" on x64 and arm64 alike. - * The overseas gateway refuses "linux" only beside a non-official - * fingerprint (#367), so the overseas chat sends the official one. */ + * The overseas gateway still refuses "linux" for plugin-only accounts even + * with the official fingerprint (#367), so overseas chat omits it on Linux; + * other routes keep the official platform value. */ function platformTm(platform = process.platform) { return platform === "darwin" ? "mac" : platform === "win32" ? "win" : platform; } @@ -335,6 +336,30 @@ async function accountRefusal(res) { }); } +/** + * fingerprintRefusal reads the overseas WAF's exact bare request-fingerprint + * rejection, or null. It only identifies the response shape; the wallets route + * must still confirm whether the sign-in holds before magpie keeps it (#367). + */ +async function fingerprintRefusal(res) { + if (res.status !== 403) return null; + const text = await res.clone().text().catch(() => ""); + let message = ""; + try { + const fields = said(JSON.parse(text)); + if (fields.code != null) return null; + message = fields.message; + } catch { + message = text.trim(); + } + if (message.toLowerCase() !== "forbidden") return null; + return { + text, + statusText: res.statusText, + contentType: res.headers.get("content-type"), + }; +} + /** refusedNotSignIn is a 401/403 that is the account's (quota or ban), not its sign-in, or null. */ async function refusedNotSignIn(res) { return (await quotaRefusal(res)) ?? (await accountRefusal(res)); @@ -367,8 +392,9 @@ function noteServed(providerId, bytes) { /** signInHolds is true when a host's wallets route takes the token, false when every answer refused it, null when unknown. */ async function signInHolds(accessToken, hosts) { - let refused = false; - for (const host of dedupe(hosts)) { + let refused = 0; + const uniqueHosts = dedupe(hosts); + for (const host of uniqueHosts) { try { const res = await fetch(host + WALLETS_PATH, { method: "GET", @@ -377,7 +403,7 @@ async function signInHolds(accessToken, hosts) { signal: AbortSignal.timeout(10_000), }); if (res.status === 401 || res.status === 403) { - refused = true; + refused++; try { res.body?.cancel?.(); } catch {} continue; } @@ -389,7 +415,7 @@ async function signInHolds(accessToken, hosts) { if (payload && payload.code === 0) return true; } catch {} } - return refused ? false : null; + return refused === uniqueHosts.length ? false : null; } /** sizeRefusal is a 401/403 for a body larger than any answered, its sign-in holding, as a 413; or null. */ @@ -594,7 +620,11 @@ function setOfficialChatHeaders(headers, { accessToken, model, sessionId, now = headers.set("X-Stainless-Runtime", "node"); headers.set("X-Stainless-Runtime-Version", OFFICIAL_NODE_VERSION); headers.set("X-Version", OFFICIAL_CLIENT_VERSION); - headers.set("X-Tm", platformTm(platform)); + // The official client says "linux", but the overseas WAF still rejects that + // exact value for plugin-only accounts even after user-info (#367). Omission + // is accepted and does not pretend to be another OS; macOS/Windows stay exact. + if (platform === "linux") headers.delete("X-Tm"); + else headers.set("X-Tm", platformTm(platform)); headers.set("X-Product", PRODUCT); headers.set("X-Auth-Appid", APP_ID); headers.set("X-Auth-TimeStamp", ts); @@ -1408,8 +1438,8 @@ function makeAutoclawPlugin({ providerId, providerName, homeHost, loginMethod }) routeModel = String(sent?.model ?? ""); } catch {} } - // the official 2.0.3 fingerprint: with it the gateway takes X-Tm - // "linux"; with the old AutoClaw4/1.18.1 one it refuses it (#367) + // The official 2.0.3 fingerprint, except Linux omits X-Tm because + // the gateway still refuses its official "linux" value (#367). setOfficialChatHeaders(headers, { accessToken, model: routeModel, sessionId: conversationSessionId(sent) }); const tryFetch = (host) => @@ -1424,10 +1454,39 @@ function makeAutoclawPlugin({ providerId, providerName, homeHost, loginMethod }) // a spent quota or a ban is the account's on every host: not asked again const spent1 = await refusedNotSignIn(res1); if (spent1) return spent1; + const fingerprint1 = await fingerprintRefusal(res1); try { res1.body?.cancel?.(); } catch {} const res2 = await tryFetch(hosts[1]); const spent2 = await refusedNotSignIn(res2); if (spent2) return spent2; + const fingerprint2 = await fingerprintRefusal(res2); + const fingerprint = fingerprint2 ?? fingerprint1; + if (fingerprint && (res2.status === 401 || res2.status === 403)) { + try { res2.body?.cancel?.(); } catch {} + const holds = await signInHolds(accessToken, hosts); + if (holds === true) { + return new Response(JSON.stringify({ error: { + message: "AutoClaw: forbidden — 上游拒绝了当前客户端指纹,登录仍然有效", + type: "permission_error", + code: null, + } }), { + status: 403, + headers: { "Content-Type": "application/json", "X-Magpie-Sign-In": "kept" }, + }); + } + if (holds === null) { + const response = new Response(fingerprint.text, { + status: 403, + statusText: fingerprint.statusText, + headers: fingerprint.contentType ? { "Content-Type": fingerprint.contentType } : undefined, + }); + return response; + } + return new Response(JSON.stringify({ error: { message: "AutoClaw 登录已失效(两个 host 均拒绝该 token)", type: "invalid_request_error" } }), { + status: 401, + headers: { "Content-Type": "application/json", "X-Magpie-Sign-In": "expired" }, + }); + } if (res2.status === 401 || res2.status === 403) { try { res2.body?.cancel?.(); } catch {} const tooBig = await sizeRefusal(providerId, sentBytes, res2.status, accessToken, hosts); @@ -2182,7 +2241,7 @@ export const AutoclawCnAuthPlugin = makeAutoclawPlugin({ /** 测试辅助(magpie/OpenCode 不会把它当插件调用)。 */ export const _internal = { - quotaRefusal, accountRefusal, bannedSaid, + quotaRefusal, accountRefusal, fingerprintRefusal, bannedSaid, signInHolds, clearLargestServed: () => largestServed.clear(), makePluginForTest: makeAutoclawPlugin, platformTm, setOfficialChatHeaders, conversationSessionId, stainlessOs, stainlessArch, md5Hex, jwtClaim, tokenFields, codeValue, bizHeaders, bareToken, newDeviceId, diff --git a/packages/autoclaw/index.test.mjs b/packages/autoclaw/index.test.mjs index 1c8f1c1..dcb7ce0 100644 --- a/packages/autoclaw/index.test.mjs +++ b/packages/autoclaw/index.test.mjs @@ -1135,11 +1135,9 @@ test("usage: the credit balance and its wallets are the balance, never a window } }) -// #367 (menhouran): the overseas gateway refuses X-Tm "linux" only beside a -// non-official fingerprint. The official AutoClaw 2.0.3 client sends "linux" -// (managedPlatform() in its main.cjs: darwin mac, win32 win, else -// process.platform) with channel "official", version 2.0.3 and a signed -// X-Auth-*; 0.2.7's "linux-x64" was a bypass, not what it sends. +// #367 (menhouran, freebai, Casper-Sun): the official AutoClaw client says +// "linux", but the overseas WAF still rejects that exact X-Tm for plugin-only +// Linux accounts. Omitting it is accepted and does not pretend to be mac/win. test("X-Tm is the official client's platform id: mac, win, and linux as is", () => { const { platformTm, bizHeaders } = _internal expect(platformTm("darwin")).toBe("mac") @@ -1168,7 +1166,7 @@ test("the overseas chat carries the official AutoClaw 2.0.3 fingerprint", async expect(sent[0].url).toBe("https://autoglm-api.autoglm.ai/autoclaw-proxy/proxy/autoclaw/v1/chat/completions") expect(h.get("X-Channel")).toBe("official") expect(h.get("X-Version")).toBe("2.0.3") - expect(h.get("X-Tm")).toBe(platformTm(process.platform)) + expect(h.get("X-Tm")).toBe(process.platform === "linux" ? null : platformTm(process.platform)) expect(h.get("X-Product")).toBe("autoclaw") expect(h.get("X-Lang")).toBe("en") expect(h.get("X-Client-Type")).toBe("pc") @@ -1205,11 +1203,11 @@ test("the overseas chat carries the official AutoClaw 2.0.3 fingerprint", async } }) -test("on Linux the official fingerprint says linux, x64 and arm64 alike", () => { +test("on Linux overseas chat omits the WAF-rejected X-Tm, x64 and arm64 alike", () => { const { setOfficialChatHeaders } = _internal for (const arch of ["x64", "arm64"]) { const h = setOfficialChatHeaders(new Headers(), { accessToken: "a1", model: "m", sessionId: "s", platform: "linux", arch }) - expect(h.get("X-Tm")).toBe("linux") + expect(h.get("X-Tm")).toBeNull() expect(h.get("X-Stainless-OS")).toBe("Linux") expect(h.get("X-Stainless-Arch")).toBe(arch) expect(h.get("X-Channel")).toBe("official") @@ -1271,9 +1269,9 @@ test("overseas chat: a spent quota on the first host isn't asked of the second, expect(spent.headers.get("X-Magpie-Sign-In")).toBe("kept") expect(urls.length).toBe(1) - // both hosts refusing the token is still the sign-in + // a real token refusal on both hosts is still the sign-in urls.length = 0 - answer = () => new Response("forbidden", { status: 403 }) + answer = () => new Response('{"code":401,"message":"token invalid"}', { status: 403 }) const dead = await loader.fetch("x", { method: "POST", body }) expect(dead.status).toBe(401) expect(dead.headers.get("X-Magpie-Sign-In")).toBe("expired") @@ -1283,6 +1281,124 @@ test("overseas chat: a spent quota on the first host isn't asked of the second, } }) +test("overseas chat: only an exact uncoded forbidden enters the fingerprint path", async () => { + const realFetch = globalThis.fetch + try { + const hooks = await AutoclawAuthPlugin({ client: { auth: { set: async () => {} } } }) + const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "a1" })) + const body = JSON.stringify({ model: "zai_glm-5.3-flash", messages: [{ role: "user", content: "hi" }] }) + const cases = [ + () => new Response("", { status: 403 }), + () => Response.json({ message: "some other refusal" }, { status: 403 }), + () => Response.json({ code: 401, message: "forbidden" }, { status: 403 }), + ] + for (const answer of cases) { + let calls = 0 + globalThis.fetch = async () => { calls++; return answer() } + const expired = await loader.fetch("x", { method: "POST", body }) + expect(expired.status).toBe(401) + expect(expired.headers.get("X-Magpie-Sign-In")).toBe("expired") + expect(calls).toBe(2) + } + } finally { + globalThis.fetch = realFetch + } +}) + +test("overseas chat: plain-text forbidden is kept only after wallets confirms the sign-in", async () => { + const realFetch = globalThis.fetch + const urls = [] + let chats = 0 + globalThis.fetch = async (input, init) => { + urls.push(String(input)) + if (init?.method === "GET") return Response.json({ code: 0 }) + chats++ + return chats === 1 + ? new Response("forbidden", { status: 403, headers: { "content-type": "text/plain" } }) + : Response.json({ code: 401, message: "token invalid" }, { status: 403 }) + } + try { + const hooks = await AutoclawAuthPlugin({ client: { auth: { set: async () => {} } } }) + const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "a1" })) + const body = JSON.stringify({ model: "zai_glm-5.3-flash", messages: [{ role: "user", content: "hi" }] }) + const refused = await loader.fetch("x", { method: "POST", body }) + expect(refused.status).toBe(403) + expect(refused.headers.get("X-Magpie-Sign-In")).toBe("kept") + const error = (await refused.json()).error + expect(error.message).toContain("forbidden") + expect(error.message).toContain("登录仍然有效") + expect(error.type).toBe("permission_error") + expect(urls.length).toBe(3) + expect(urls[2]).toContain("/wallets") + } finally { + globalThis.fetch = realFetch + } +}) + +test("overseas chat: bare forbidden expires when wallets refuses the token", async () => { + const realFetch = globalThis.fetch + let calls = 0 + globalThis.fetch = async (_input, init) => { + calls++ + if (init?.method === "GET") return new Response("", { status: 401 }) + return Response.json({ message: "forbidden" }, { status: 403 }) + } + try { + const hooks = await AutoclawAuthPlugin({ client: { auth: { set: async () => {} } } }) + const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "a1" })) + const body = JSON.stringify({ model: "zai_glm-5.3-flash", messages: [{ role: "user", content: "hi" }] }) + const expired = await loader.fetch("x", { method: "POST", body }) + expect(expired.status).toBe(401) + expect(expired.headers.get("X-Magpie-Sign-In")).toBe("expired") + expect(calls).toBe(4) + } finally { + globalThis.fetch = realFetch + } +}) + +test("overseas chat: bare forbidden stays unknown when wallets cannot check the sign-in", async () => { + const realFetch = globalThis.fetch + let calls = 0 + globalThis.fetch = async (_input, init) => { + calls++ + if (init?.method === "GET") return new Response("", { status: calls === 3 ? 401 : 500 }) + return Response.json({ message: "forbidden" }, { status: 403 }) + } + try { + const hooks = await AutoclawAuthPlugin({ client: { auth: { set: async () => {} } } }) + const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "a1" })) + const body = JSON.stringify({ model: "zai_glm-5.3-flash", messages: [{ role: "user", content: "hi" }] }) + const unknown = await loader.fetch("x", { method: "POST", body }) + expect(unknown.status).toBe(403) + expect(unknown.headers.get("X-Magpie-Sign-In")).toBeNull() + expect(await unknown.json()).toEqual({ message: "forbidden" }) + expect(calls).toBe(4) + } finally { + globalThis.fetch = realFetch + } +}) + +test("overseas chat: a second host that accepts after bare forbidden still wins", async () => { + const realFetch = globalThis.fetch + let calls = 0 + globalThis.fetch = async () => { + calls++ + return calls === 1 + ? Response.json({ message: "forbidden" }, { status: 403 }) + : Response.json({ choices: [] }) + } + try { + const hooks = await AutoclawAuthPlugin({ client: { auth: { set: async () => {} } } }) + const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "a1" })) + const body = JSON.stringify({ model: "zai_glm-5.3-flash", messages: [{ role: "user", content: "hi" }] }) + const recovered = await loader.fetch("x", { method: "POST", body }) + expect(recovered.status).toBe(200) + expect(calls).toBe(2) + } finally { + globalThis.fetch = realFetch + } +}) + // 小八 (Discord, 2026-10-23): a banned AutoClaw account answers every route // with exactly these bytes. It is the account, not an expired sign-in: // magpie must keep the token and show the vendor's words. diff --git a/packages/autoclaw/package.json b/packages/autoclaw/package.json index 96ccdca..07ab224 100644 --- a/packages/autoclaw/package.json +++ b/packages/autoclaw/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-autoclaw-auth", - "version": "0.2.21", + "version": "0.2.22", "description": "OpenCode provider plugin for AutoClaw (Zhipu OpenClaw): oversea web sign-in (Google/z.ai) and CN phone SMS, multi-account pool, credit balance and daily check-in", "type": "module", "main": "./opencode.mjs",