trae 0.1.7: the daily check-in is sent as Trae CN's IDE sends it (Discord, ARNO on magpie v0.1.813: trae-cn的签到功能会失败) — ownRequest sent api.trae.cn's check-in pages with the chat's headers (x-uid, x-app-id, X-Cloudide-Token, x-ide-token, x-machine-id, x-ide-version… as TRAE SOLO CN's ai-agent sends llm_utils_chat) and the body magpie gave ({}). Trae CN 3.3.104's own client (out/main.js, eb()/fb(), from the linux tarball the version API names) posts /trae/api/v2/ug/checkin_credits/status and /claim with {req_source: 1} (2 only for SOLO Lite/enterprise) and only Content-Type, Authorization: Cloud-IDE-JWT and the device's x-device-id, x-device-brand, x-device-type, x-os-version, x-app-version. Pages under /trae/api/v2/ug/ now go with those headers (ugHeaders) and {req_source:1} where none or {} was given (ugBody); Trae's other pages are sent as before. Trae's 9074 (当前参与用户太多) is a device-level risk control that both open-source check-in clients say trips on requests that don't look like the client's; whether that is what ARNO saw is not known (no error text, and no Trae CN account to try with). checkin.test.mjs gains "the check-in is sent as Trae CN's IDE sends it" (body and header set; fails on 0.1.6); bun test (30 pass) and bun scripts/check.mjs trae under a temp HOME pass; the plugin's fetch against the real api.trae.cn with a placeholder token answers 200 code 1001 marked expired, so the route is reached. Not tried with a real Trae CN account.
This commit is contained in:
@@ -114,13 +114,15 @@ 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: its Cloud-IDE-JWT
|
||||
(renewed first when near its end) and its device id.
|
||||
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.
|
||||
|
||||
- **Status:** `POST api.trae.cn/trae/api/v2/ug/checkin_credits/status`,
|
||||
body `{}`: `enable`, `checked_in`, `credits`.
|
||||
body `{"req_source":1}`: `enable`, `checked_in`, `credits`.
|
||||
- **Claim:** `POST api.trae.cn/trae/api/v2/ug/checkin_credits/claim`,
|
||||
body `{}`, only while it is on and today's isn't in.
|
||||
body `{"req_source":1}`, 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.
|
||||
|
||||
@@ -28,10 +28,27 @@ 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")
|
||||
expect(r.headers.get("x-uid")).toBe("u-1")
|
||||
}
|
||||
})
|
||||
|
||||
// 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")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+41
-2
@@ -366,6 +366,42 @@ 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
|
||||
@@ -848,10 +884,13 @@ 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)
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: ideHeaders(a, { Accept: "application/json" }),
|
||||
body: method === "GET" || method === "HEAD" ? undefined : typeof body === "string" ? body : "{}",
|
||||
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 : "{}",
|
||||
signal: signal ?? AbortSignal.timeout(20_000),
|
||||
})
|
||||
const text = await res.text()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-trae-auth",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user