@magpie-community/opencode-trae-auth 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/index.mjs +6 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -114,15 +114,13 @@ magpie's usage card shows the account's credits:
|
|
|
114
114
|
Trae CN gives credits for a daily check-in (每日签到). magpie can press it
|
|
115
115
|
once a day for each account (Settings, or the switch on the usage card).
|
|
116
116
|
It asks Trae CN's own pages through
|
|
117
|
-
this plugin's fetch, which sends them as the account
|
|
118
|
-
|
|
119
|
-
device's headers (`x-device-id`, `x-device-brand`, `x-device-type`,
|
|
120
|
-
`x-os-version`, `x-app-version`), and no others.
|
|
117
|
+
this plugin's fetch, which sends them as the account: its Cloud-IDE-JWT
|
|
118
|
+
(renewed first when near its end) and its device id.
|
|
121
119
|
|
|
122
120
|
- **Status:** `POST api.trae.cn/trae/api/v2/ug/checkin_credits/status`,
|
|
123
|
-
body `{
|
|
121
|
+
body `{}`: `enable`, `checked_in`, `credits`.
|
|
124
122
|
- **Claim:** `POST api.trae.cn/trae/api/v2/ug/checkin_credits/claim`,
|
|
125
|
-
body `{
|
|
123
|
+
body `{}`, only while it is on and today's isn't in.
|
|
126
124
|
- **What comes back:** Trae's answer as it is. A 401 or code 1001 marks
|
|
127
125
|
the account for a new sign-in. Code 9095 means this device has checked
|
|
128
126
|
in today; nothing sends another device id to get round it.
|
package/index.mjs
CHANGED
|
@@ -366,42 +366,6 @@ function ideHeaders(a, extra = {}) {
|
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
// ugHeaders are the headers Trae CN's IDE sends its growth pages
|
|
370
|
-
// (api.trae.cn/trae/api/v2/ug/…, the daily check-in) with, and no others:
|
|
371
|
-
// its eb()/fb() (Trae CN 3.3.104's out/main.js) send Content-Type, the
|
|
372
|
-
// Cloud-IDE-JWT and the device (x-device-id, x-device-brand,
|
|
373
|
-
// x-device-type, x-os-version, x-app-version), none of the chat's
|
|
374
|
-
// x-uid, x-app-id, x-ide-token and the like
|
|
375
|
-
function ugHeaders(a, extra = {}) {
|
|
376
|
-
return {
|
|
377
|
-
"Content-Type": "application/json",
|
|
378
|
-
Authorization: `Cloud-IDE-JWT ${a.token}`,
|
|
379
|
-
"x-device-id": a.deviceId,
|
|
380
|
-
"x-device-brand": BRAND,
|
|
381
|
-
"x-device-type": "windows",
|
|
382
|
-
"x-os-version": "Windows 10",
|
|
383
|
-
"x-app-version": CLIENT_VERSION,
|
|
384
|
-
...extra,
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// ugBody is the body the IDE posts a growth page: {req_source: 1}, its
|
|
389
|
-
// own (2 is SOLO Lite's), where magpie gave none or {}; anything else
|
|
390
|
-
// given goes as it is
|
|
391
|
-
function ugBody(body) {
|
|
392
|
-
const s = typeof body === "string" ? body.trim() : ""
|
|
393
|
-
if (s === "" || s === "{}") return JSON.stringify({ req_source: 1 })
|
|
394
|
-
return s
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const ugPage = (url) => {
|
|
398
|
-
try {
|
|
399
|
-
return new URL(url).pathname.startsWith("/trae/api/v2/ug/")
|
|
400
|
-
} catch {
|
|
401
|
-
return false
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
369
|
// Trae's chat takes text only and has no turn for a tool call or its
|
|
406
370
|
// result. The agent's tools are named to it natively and in a system
|
|
407
371
|
// prompt that asks for each call as a tagged block; earlier calls and
|
|
@@ -922,13 +886,14 @@ export const TraeCNAuthPlugin = async ({ client }) => {
|
|
|
922
886
|
if (e instanceof Expired) return errorResponse(401, `${a0.name || a0.uid}: ${e.message}`, "expired")
|
|
923
887
|
throw e
|
|
924
888
|
}
|
|
925
|
-
// the check-in
|
|
926
|
-
//
|
|
927
|
-
|
|
889
|
+
// Trae's pages, the check-in among them, go with the chat's headers and
|
|
890
|
+
// the body given ({}): 0.1.7 sent the check-in with the IDE's growth
|
|
891
|
+
// headers and {req_source: 1} instead, and a check-in that worked on
|
|
892
|
+
// 0.1.6 failed from then on (yetone/magpie#808)
|
|
928
893
|
const res = await fetch(url, {
|
|
929
894
|
method,
|
|
930
|
-
headers:
|
|
931
|
-
body: method === "GET" || method === "HEAD" ? undefined :
|
|
895
|
+
headers: ideHeaders(a, { Accept: "application/json" }),
|
|
896
|
+
body: method === "GET" || method === "HEAD" ? undefined : typeof body === "string" ? body : "{}",
|
|
932
897
|
signal: signal ?? AbortSignal.timeout(20_000),
|
|
933
898
|
})
|
|
934
899
|
const text = await res.text()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-trae-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"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",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|