From 64c9e6c34c7256900040aa9239f7eeb9c620266b Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 5 Oct 2026 00:34:11 +0800 Subject: [PATCH] =?UTF-8?q?trae=200.1.9:=20the=20daily=20check-in=20goes?= =?UTF-8?q?=20as=20it=20did=20on=200.1.6,=20with=20the=20chat's=20headers?= =?UTF-8?q?=20and=20{}=20(yetone/magpie#808,=20Hu9956=20on=20magpie=200.1.?= =?UTF-8?q?880:=20TraeCN=E8=87=AA=E5=8A=A8=E7=AD=BE=E5=88=B0=E5=A4=B1?= =?UTF-8?q?=E6=95=88=EF=BC=8C=E4=B8=AD=E5=8D=88=E8=BF=98=E8=A1=8C=E6=9D=A5?= =?UTF-8?q?=E7=9D=80=EF=BC=8C=E6=9B=B4=E6=96=B0=E5=90=8E=E5=B0=B1=E4=B8=8D?= =?UTF-8?q?=E8=A1=8C=E4=BA=86)=20=E2=80=94=200.1.7=20(published=2013:12=20?= =?UTF-8?q?Beijing=20on=2010-04)=20sent=20api.trae.cn's=20/trae/api/v2/ug/?= =?UTF-8?q?=20pages=20with=20only=20the=20JWT=20and=20the=20device's=20hea?= =?UTF-8?q?ders=20(ugHeaders:=20no=20x-uid,=20x-app-id,=20x-ide-token,=20x?= =?UTF-8?q?-machine-id,=20yet=20x-app-version=20still=20SOLO's=200.1.69)?= =?UTF-8?q?=20and=20{req=5Fsource:1}=20(ugBody);=20Hu9956's=20check-in,=20?= =?UTF-8?q?which=20went=20through=20at=20noon=20on=200.1.6,=20has=20failed?= =?UTF-8?q?=20since.=20Both=20are=20taken=20out:=20the=20check-in=20is=20s?= =?UTF-8?q?ent=20as=20every=20other=20Trae=20page=20is=20(ideHeaders,=20th?= =?UTF-8?q?e=20body=20magpie=20gives),=20and=20the=20test=20that=20checks?= =?UTF-8?q?=20it=20goes=20as=20the=20account=20with=20{}=20and=20x-uid=20i?= =?UTF-8?q?s=20back=20(it=20fails=20on=200.1.8).=20bun=20test=20(30=20pass?= =?UTF-8?q?)=20and=20bun=20scripts/check.mjs=20trae=20under=20a=20temp=20H?= =?UTF-8?q?OME=20pass.=20Not=20tried=20with=20a=20real=20Trae=20CN=20accou?= =?UTF-8?q?nt=20(none=20here);=20the=20reporter's=20account=20is=20the=20c?= =?UTF-8?q?heck.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/trae/README.md | 10 +++----- packages/trae/checkin.test.mjs | 21 ++------------- packages/trae/index.mjs | 47 +++++----------------------------- packages/trae/package.json | 2 +- 4 files changed, 13 insertions(+), 67 deletions(-) diff --git a/packages/trae/README.md b/packages/trae/README.md index 49d4c37..5843e6c 100644 --- a/packages/trae/README.md +++ b/packages/trae/README.md @@ -114,15 +114,13 @@ magpie's usage card shows the account's credits: Trae CN gives credits for a daily check-in (每日签到). magpie can press it once a day for each account (Settings, or the switch on the usage card). It asks Trae CN's own pages through -this plugin's fetch, which sends them as the account, as Trae CN's IDE -does: its Cloud-IDE-JWT (renewed first when near its end) and its -device's headers (`x-device-id`, `x-device-brand`, `x-device-type`, -`x-os-version`, `x-app-version`), and no others. +this plugin's fetch, which sends them as the account: its Cloud-IDE-JWT +(renewed first when near its end) and its device id. - **Status:** `POST api.trae.cn/trae/api/v2/ug/checkin_credits/status`, - body `{"req_source":1}`: `enable`, `checked_in`, `credits`. + body `{}`: `enable`, `checked_in`, `credits`. - **Claim:** `POST api.trae.cn/trae/api/v2/ug/checkin_credits/claim`, - body `{"req_source":1}`, only while it is on and today's isn't in. + body `{}`, only while it is on and today's isn't in. - **What comes back:** Trae's answer as it is. A 401 or code 1001 marks the account for a new sign-in. Code 9095 means this device has checked in today; nothing sends another device id to get round it. diff --git a/packages/trae/checkin.test.mjs b/packages/trae/checkin.test.mjs index 04eaa93..5b49e49 100644 --- a/packages/trae/checkin.test.mjs +++ b/packages/trae/checkin.test.mjs @@ -28,27 +28,10 @@ test("a check-in page is sent as the account, its answer back as it is", async ( expect(f.seen.map((r) => r.path)).toEqual(["/trae/api/v2/ug/checkin_credits/status", "/trae/api/v2/ug/checkin_credits/claim"]) for (const r of f.seen) { expect(r.method).toBe("POST") + expect(r.json).toEqual({}) expect(r.headers.get("authorization")).toBe("Cloud-IDE-JWT jwt-1") expect(r.headers.get("x-device-id")).toBe("1234567890123456789") - } -}) - -// Trae CN's IDE (3.3.104, out/main.js eb()/fb()) posts the check-in with -// {req_source: 1} and only the JWT and the device's headers; the chat's -// own (x-uid, x-app-id, x-ide-token …) aren't among them -test("the check-in is sent as Trae CN's IDE sends it", async () => { - f = fakeTrae() - f.route("POST /trae/api/v2/ug/checkin_credits/status", () => json({ code: 0, enable: true, checked_in: false, credits: 100 })) - f.route("POST /trae/api/v2/ug/checkin_credits/claim", () => json({ code: 0 })) - const o = await fetcher() - await o.fetch(f.origin + "/trae/api/v2/ug/checkin_credits/status", { method: "POST", body: "{}" }) - await o.fetch(f.origin + "/trae/api/v2/ug/checkin_credits/claim", { method: "POST" }) - expect(f.seen.length).toBe(2) - for (const r of f.seen) { - expect(r.json).toEqual({ req_source: 1 }) - const names = [...r.headers.keys()].filter((k) => k === "authorization" || k.startsWith("x-")).sort() - expect(names).toEqual(["authorization", "x-app-version", "x-device-brand", "x-device-id", "x-device-type", "x-os-version"]) - expect(r.headers.get("content-type")).toBe("application/json") + expect(r.headers.get("x-uid")).toBe("u-1") } }) diff --git a/packages/trae/index.mjs b/packages/trae/index.mjs index 20e6ef5..7c52e6b 100644 --- a/packages/trae/index.mjs +++ b/packages/trae/index.mjs @@ -366,42 +366,6 @@ function ideHeaders(a, extra = {}) { } } -// ugHeaders are the headers Trae CN's IDE sends its growth pages -// (api.trae.cn/trae/api/v2/ug/…, the daily check-in) with, and no others: -// its eb()/fb() (Trae CN 3.3.104's out/main.js) send Content-Type, the -// Cloud-IDE-JWT and the device (x-device-id, x-device-brand, -// x-device-type, x-os-version, x-app-version), none of the chat's -// x-uid, x-app-id, x-ide-token and the like -function ugHeaders(a, extra = {}) { - return { - "Content-Type": "application/json", - Authorization: `Cloud-IDE-JWT ${a.token}`, - "x-device-id": a.deviceId, - "x-device-brand": BRAND, - "x-device-type": "windows", - "x-os-version": "Windows 10", - "x-app-version": CLIENT_VERSION, - ...extra, - } -} - -// ugBody is the body the IDE posts a growth page: {req_source: 1}, its -// own (2 is SOLO Lite's), where magpie gave none or {}; anything else -// given goes as it is -function ugBody(body) { - const s = typeof body === "string" ? body.trim() : "" - if (s === "" || s === "{}") return JSON.stringify({ req_source: 1 }) - return s -} - -const ugPage = (url) => { - try { - return new URL(url).pathname.startsWith("/trae/api/v2/ug/") - } catch { - return false - } -} - // Trae's chat takes text only and has no turn for a tool call or its // result. The agent's tools are named to it natively and in a system // prompt that asks for each call as a tagged block; earlier calls and @@ -922,13 +886,14 @@ export const TraeCNAuthPlugin = async ({ client }) => { if (e instanceof Expired) return errorResponse(401, `${a0.name || a0.uid}: ${e.message}`, "expired") throw e } - // the check-in goes as the IDE sends it (ugHeaders, ugBody); Trae's - // other pages with the chat's headers - const ug = ugPage(url) + // Trae's pages, the check-in among them, go with the chat's headers and + // the body given ({}): 0.1.7 sent the check-in with the IDE's growth + // headers and {req_source: 1} instead, and a check-in that worked on + // 0.1.6 failed from then on (yetone/magpie#808) const res = await fetch(url, { method, - headers: ug ? ugHeaders(a, { Accept: "application/json" }) : ideHeaders(a, { Accept: "application/json" }), - body: method === "GET" || method === "HEAD" ? undefined : ug ? ugBody(body) : typeof body === "string" ? body : "{}", + headers: ideHeaders(a, { Accept: "application/json" }), + body: method === "GET" || method === "HEAD" ? undefined : typeof body === "string" ? body : "{}", signal: signal ?? AbortSignal.timeout(20_000), }) const text = await res.text() diff --git a/packages/trae/package.json b/packages/trae/package.json index 85fe507..b34ea75 100644 --- a/packages/trae/package.json +++ b/packages/trae/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-trae-auth", - "version": "0.1.8", + "version": "0.1.9", "description": "OpenCode provider plugin for Trae CN (trae.cn): your Trae CN account's models, free tier included, with Trae's own browser sign-in", "type": "module", "main": "./index.mjs",