trae 0.1.12: a reply limit Trae doesn't give is none, not a made-up 32K, and a request asking more than Trae's is held to it (ARNO on magpie's Discord: Trae CN's deepseek-v4.1-flash said maxTokens 32000) — a model whose list names no __dev max_tokens (deepseek-v4.1-flash in chat_v3, kimi-k2.6, the fallback list's) was given MODEL's 32_000, which agents were told as its reply limit. It is now 0, which magpie reads as unknown and fills from models.dev (DeepSeek V4.1 Flash's 384K); one Trae gives (glm-5.2__dev's 32000, deepseek-v4.1-flash__dev's 64000 in solo_agent) is kept, and a request asking more than it is sent with Trae's. The new test fails on 0.1.11; bun test (35 pass) and bun scripts/check.mjs trae under a temp HOME pass. Not tried with a real Trae CN account (none here).

This commit is contained in:
yetone
2026-10-05 04:29:12 +08:00
parent 20cd6f1bb2
commit c172d93901
3 changed files with 46 additions and 9 deletions
+13 -8
View File
@@ -39,12 +39,15 @@ const DAY = 24 * 3600 * 1000
// then SOLO Lite's agent
const FUNCTIONS = ["chat_v3", "solo_work_lite", "solo_agent", "solo_agent_lite"]
const MODEL = { attachment: false, tool_call: true, reasoning: true, temperature: true, limit: { context: 128_000, output: 32_000 }, modalities: { input: ["text"], output: ["text"] } }
// a reply limit of 0 is one Trae doesn't say: magpie then takes models.dev's
// for the model (magpie's catalog), where a made-up 32K told agents a far
// smaller one than DeepSeek V4.1 Flash's (ARNO on magpie's Discord)
const MODEL = { attachment: false, tool_call: true, reasoning: true, temperature: true, limit: { context: 128_000, output: 0 }, modalities: { input: ["text"], output: ["text"] } }
// what Trae CN's chat_v3 is known to serve; the live list replaces it
const MODELS = {
"glm-5.2": { name: "GLM-5.2", ...MODEL, limit: { context: 200_000, output: 32_000 } },
"glm-5": { name: "GLM-5", ...MODEL },
"kimi-k2.6": { name: "Kimi K2.6", ...MODEL, limit: { context: 256_000, output: 32_000 } },
"kimi-k2.6": { name: "Kimi K2.6", ...MODEL, limit: { context: 256_000, output: 0 } },
"qwen-3.7-plus": { name: "Qwen 3.7 Plus", ...MODEL },
"DeepSeek-V4-Pro": { name: "DeepSeek V4 Pro", ...MODEL },
"DeepSeek-V4-Flash": { name: "DeepSeek V4 Flash", ...MODEL },
@@ -444,8 +447,10 @@ const nativeTools = (tools) =>
})
// chatBody is the request for llm_utils_chat; modelName is the model the
// function's list names for the config (its __dev one), when it named one
function chatBody(req, fn, modelName) {
// function's list names for the config (its __dev one), when it named one,
// and most the max_tokens it gives that model (0: none given), which a
// request asking more is held to
function chatBody(req, fn, modelName, most = 0) {
const session = randomUUID()
const body = {
messages: traeMessages(req),
@@ -458,7 +463,7 @@ function chatBody(req, fn, modelName) {
session_id: session,
}
const max = req.max_completion_tokens ?? req.max_tokens
if (Number.isFinite(max) && max > 0) body.max_tokens = Math.floor(max)
if (Number.isFinite(max) && max > 0) body.max_tokens = most > 0 ? Math.min(Math.floor(max), most) : Math.floor(max)
if (typeof req.temperature === "number") body.temperature = req.temperature
if (Array.isArray(req.tools) && req.tools.length && req.tool_choice !== "none") {
body.tools = nativeTools(req.tools)
@@ -1197,7 +1202,7 @@ export const TraeCNAuthPlugin = async ({ client }) => {
for (const [id, { m, fn }] of out) {
listedBy.set(id, fn)
const dev = devModel(m)
if (dev) modelNames.set(id, { fn, name: dev.model_name })
if (dev) modelNames.set(id, { fn, name: dev.model_name, most: Number(dev.max_tokens) || 0 })
else modelNames.delete(id)
}
return [...out.values()].map((x) => x.m)
@@ -1208,7 +1213,7 @@ export const TraeCNAuthPlugin = async ({ client }) => {
const was = provider.models?.[id] ?? {}
// context_window_tokens: dev is what a request gets, max only in Max mode
const ctx = Number(m.context_window_tokens?.dev ?? m.context_window_size?.max?.[0] ?? m.context_window_size?.max ?? m.context_window_tokens?.max ?? m.prompt_max_tokens) || was.limit?.context || MODEL.limit.context
const out = Number(devModel(m)?.max_tokens) || was.limit?.output || MODEL.limit.output
const out = Number(devModel(m)?.max_tokens) || was.limit?.output || 0
const name = m.display_config?.display_name || m.display_name || m.display_model_name || was.name || id
return { ...MODEL, ...was, id, providerID: ID, name: String(name), limit: { context: ctx, output: out }, api: was.api ?? { id, url: HOSTS.api, npm: "@ai-sdk/openai-compatible" } }
}
@@ -1281,7 +1286,7 @@ export const TraeCNAuthPlugin = async ({ client }) => {
const res = await fetch(apiOf(a) + "/api/agent/v3/llm_utils_chat", {
method: "POST",
headers: ideHeaders(a, { Accept: "text/event-stream", "X-Request-ID": randomUUID() }),
body: JSON.stringify(chatBody(req, fn, named?.fn === fn ? named.name : "")),
body: JSON.stringify(chatBody(req, fn, named?.fn === fn ? named.name : "", named?.fn === fn ? named.most : 0)),
signal: init.signal ?? r0?.signal,
})
if (!res.ok) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-trae-auth",
"version": "0.1.11",
"version": "0.1.12",
"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",
+32
View File
@@ -211,3 +211,35 @@ test("a model chat_v3 gives another's name is named and asked as SOLO lists it (
// named alike everywhere: kept on chat_v3, as before
expect(await ask("DeepSeek-V4-Flash-Official")).toBe("chat_v3 DeepSeek-V4-Flash-Official__dev")
})
// ARNO on magpie's Discord: Trae CN's DeepSeek V4.1 Flash said a 32K reply
// limit, one Trae never gave: a model whose list names no max_tokens says
// none (0), and magpie tells agents models.dev's. One Trae gives is kept,
// and a request asking more than it is held to it.
test("a reply limit is Trae's own or none, and a request is held to Trae's", async () => {
f = fakeTrae()
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
{ function: "chat_v3", config_info_list: [
{ config_name: "glm-5.2", usage: "chat_completion", model_detail_list: [{ model_name: "glm-5.2__dev", max_tokens: 32000 }] },
{ config_name: "deepseek-v4.1-flash", usage: "chat_completion", context_window_tokens: { dev: 200000 }, model_detail_list: [{ model_name: "deepseek-v4.1-flash__dev" }] },
{ config_name: "kimi-k2.6", usage: "chat_completion" },
] },
] }))
f.route("POST /api/agent/v3/llm_utils_chat", (r) => sse([["output", { response: String(r.json.max_tokens) }], ["done", {}]]))
const hooks = await TraeCNAuthPlugin({ client: {} })
const p = await given(hooks)
expect(p.models["kimi-k2.6"].limit.output).toBe(0)
expect(p.models["DeepSeek-V4-Flash"].limit.output).toBe(0)
const live = await hooks.provider.models(p, { auth: signedIn() })
expect(live["glm-5.2"].limit.output).toBe(32000)
expect(live["deepseek-v4.1-flash"].limit).toEqual({ context: 200000, output: 0 })
expect(live["kimi-k2.6"].limit.output).toBe(0)
const opts = await hooks.auth.loader(async () => signedIn())
const ask = async (model, max_tokens) => {
const res = await opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify({ model, max_tokens, messages: [{ role: "user", content: "hi" }] }) })
return (await res.json()).choices[0].message.content
}
expect(await ask("glm-5.2", 131072)).toBe("32000")
expect(await ask("glm-5.2", 8000)).toBe("8000")
expect(await ask("deepseek-v4.1-flash", 384000)).toBe("384000")
})