autoclaw 0.2.7: on Linux, X-Tm is "linux-x64" as the official client sends, not the "linux" the overseas gateway refuses (#367)

menhouran found that autoglm-api.autoglm.ai answers X-Tm "linux" with
403 {"message":"forbidden"} for a valid token, and "linux-x64" (what the
official AutoClaw Linux client sends) with 200. The plugin built X-Tm
from process.platform, so every overseas chat on Linux failed and read as
"AutoClaw 登录已失效". X-Tm is now mac / win / linux-x64; the User-Agent
keeps "(linux-x64)" from process.platform and process.arch as before.

Not changed: both hosts answering 403 is still reported as an expired
sign-in. The plugin's tests deliberately treat a bare 403 that way, and
what an expired token gets from this gateway hasn't been seen, so the
mapping is left alone.

Run: HOME=<scratch> bun test packages/autoclaw, 37 pass; the new test is
red on 0.2.6. bun scripts/check.mjs autoclaw ok. Not tried against the
real API or on Linux.
This commit is contained in:
yetone
2026-10-25 14:25:33 +08:00
parent ba343b84ea
commit ae2ed19e47
3 changed files with 35 additions and 5 deletions
+10 -4
View File
@@ -29,8 +29,14 @@ const CHANNEL = "AutoClaw4";
const CLIENT_VERSION = "1.18.1";
const CN_CHANNEL = "AutoClaw26";
const CN_CLIENT_VERSION = "2.1.0";
const PLATFORM_TM = process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : "linux";
const USER_AGENT = `AutoClaw/${CLIENT_VERSION} (${PLATFORM_TM}-${process.arch})`;
const PLATFORM = process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : "linux";
/** X-Tm: the official Linux client sends "linux-x64"; the overseas gateway
* answers the bare "linux" with 403 {"message":"forbidden"} (#367). */
function platformTm(platform = process.platform) {
return platform === "darwin" ? "mac" : platform === "win32" ? "win" : "linux-x64";
}
const PLATFORM_TM = platformTm();
const USER_AGENT = `AutoClaw/${CLIENT_VERSION} (${PLATFORM}-${process.arch})`;
const GLOBAL_HOST = "https://autoglm-api.autoglm.ai";
const CN_HOST = "https://autoglm-api.zhipuai.cn";
@@ -619,7 +625,7 @@ function managedHeaders(token, model) {
const rid = randomHex(16);
const headers = new Headers(bizHeaders());
headers.set("Accept", "application/json");
headers.set("User-Agent", `AutoClaw/${CN_CLIENT_VERSION} (${PLATFORM_TM}-${process.arch})`);
headers.set("User-Agent", `AutoClaw/${CN_CLIENT_VERSION} (${PLATFORM}-${process.arch})`);
headers.set("X-Channel", CN_CHANNEL);
headers.set("X-Version", CN_CLIENT_VERSION);
headers.set("X-Trace-Id", rid);
@@ -1342,7 +1348,7 @@ export const AutoclawCnAuthPlugin = makeAutoclawPlugin({
export const _internal = {
quotaRefusal, accountRefusal, bannedSaid,
makePluginForTest: makeAutoclawPlugin,
md5Hex, jwtClaim, tokenFields, codeValue, bizHeaders, bareToken, newDeviceId,
platformTm, md5Hex, jwtClaim, tokenFields, codeValue, bizHeaders, bareToken, newDeviceId,
dailySignin, signinStatus, maybeSignin, signinAccountKey, signinConfig, checkinOutcome, refreshTokens,
fetchUserProfile, accountDeviceId, accountDisplayName, startLocalOAuth,
FLAGGED, unflagged, unflag, autoclawRewriteBody, explained, OFFICIAL_SYSTEM_PROMPT, REFUSED_HINT,
+24
View File
@@ -612,6 +612,30 @@ test("signinOnUsage signs every account, also two with the same name", async ()
}
})
// #367 (menhouran): the overseas gateway answers X-Tm "linux" with
// 403 {"message":"forbidden"} for a valid token; the official Linux client
// sends "linux-x64", which it takes
test("X-Tm is the official client's platform id: mac, win, linux-x64, never the bare linux", async () => {
const { platformTm, bizHeaders } = _internal
expect(platformTm("darwin")).toBe("mac")
expect(platformTm("win32")).toBe("win")
expect(platformTm("linux")).toBe("linux-x64")
expect(bizHeaders("t")["X-Tm"]).toBe(platformTm(process.platform))
expect(bizHeaders("t")["User-Agent"]).not.toMatch(/x64-x64|linux-x64-/)
const realFetch = globalThis.fetch
let sent
globalThis.fetch = async (input, init) => { sent = new Headers(init?.headers); return new Response("{}") }
try {
const hooks = await AutoclawAuthPlugin({ client: { auth: { set: async () => {} } } })
const loader = await hooks.auth.loader(async () => ({ type: "oauth", access: "a1" }))
await loader.fetch("x", { method: "POST", body: JSON.stringify({ model: "zai_glm-5.3-flash", messages: [{ role: "user", content: "hi" }] }) })
expect(sent.get("X-Tm")).toBe(platformTm(process.platform))
expect(sent.get("X-Tm")).not.toBe("linux")
} finally {
globalThis.fetch = realFetch
}
})
// plugins#274: the CN managed gateway answers a spent quota with a 403 whose
// body says so (code 810000); the same token's next request gets as far as
// the model check, so it is the quota, not the sign-in
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-autoclaw-auth",
"version": "0.2.6",
"version": "0.2.7",
"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": "./index.mjs",