trae 0.1.9: the daily check-in goes as it did on 0.1.6, with the chat's headers and {} (yetone/magpie#808, Hu9956 on magpie 0.1.880: TraeCN自动签到失效,中午还行来着,更新后就不行了) — 0.1.7 (published 13:12 Beijing on 10-04) sent api.trae.cn's /trae/api/v2/ug/ pages with only the JWT and the device's headers (ugHeaders: no x-uid, x-app-id, x-ide-token, x-machine-id, yet x-app-version still SOLO's 0.1.69) and {req_source:1} (ugBody); Hu9956's check-in, which went through at noon on 0.1.6, has failed since. Both are taken out: the check-in is sent as every other Trae page is (ideHeaders, the body magpie gives), and the test that checks it goes as the account with {} and x-uid is back (it fails on 0.1.8). bun test (30 pass) and bun scripts/check.mjs trae under a temp HOME pass. Not tried with a real Trae CN account (none here); the reporter's account is the check.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+6
-41
@@ -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()
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user