Files
plugins/packages/trae/nonet.mjs
T
yetone 6c048c7fc2 trae 0.1.0: Trae CN (trae.cn) accounts, free tier included, with Trae's browser sign-in (experimental; Discord pdzebkbd0701)
Sign-in is trae.cn's authorization page back to a 127.0.0.1 /authorize
callback (userJwt + userInfo, or a refresh token exchanged), with a device
made at sign-in and kept for the account. ExchangeToken renews the JWT
through auth.refresh (refreshLead 10 min, one renewal per refresh token).
Requests go to the IDE agent's llm_utils_chat (chat_v3, then
solo_work_lite on 4001/4023/1005), its SSE events turned into OpenAI
chunks; tools named natively and as <tool_call> blocks. Usage is the
entitlement packs' credits. Worked out from wangqi233/trae2api and
autumnsentiment/Trae2api-cn; not run against a real account.
2026-10-03 14:34:31 +08:00

19 lines
871 B
JavaScript

// Imported first by every test here: nothing a test runs reaches Trae.
// fetch and HTTP/2 go to this machine (a test's fake) or fail, so a test
// left without its fake, or work still going after it, can't send a token
// to trae.cn, mchost.guru or any other of Trae's hosts.
import http2 from "node:http2"
const local = (u) => /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d+)?(\/|$)/.test(u)
const realFetch = globalThis.fetch
globalThis.fetch = async (input, init) => {
const u = typeof input === "string" ? input : input instanceof URL ? input.href : input.url
if (!local(u)) throw new Error("a test asked " + u + " with no fake in place")
return realFetch(input, init)
}
const connect = http2.connect
http2.connect = (origin, ...rest) => {
if (!local(String(origin))) throw new Error("a test connected to " + origin)
return connect(origin, ...rest)
}