trae 0.2.33: a model whose top level is extra_high reaches max, sent as extra_high

@avalongarden6 on X (11-09, with screenshots): TRAE CN's app offers
DeepSeek-V4.1-Flash, GLM-5.3 and Kimi-K3 思考强度 轻/高/极高, and 极高 is
the model's maximum. magpie ranged the Trae CN member of a routing group
低–很高 (low–xhigh) while WorkBuddy, Qoder and WENMAI members ranged
…–最高 (max). magpie offers a group the levels its members share
(buildGroupEntries in internal/provider/group.go), so with Trae CN in it
the group lost max for every member.

A list entry whose top level is extra_high and that names no max of its
own is now offered max beside low/high/xhigh (offered, in variantsOf), and
effortOf sends max as extra_high, as it sends xhigh. magpie reads the
variants' keys as the model's Efforts (internal/provider/plugins.go), so
the member ranges 低–最高 (effortSpan in app.js) and a group set to max
fits max to the member's own levels (fitFor, catalog.NearestEffort), finds
it, and the plugin sends Trae extra_high. An entry that names Trae's own
max keeps it: max is max, extra_high is xhigh. A model topping lower
(light/high) is offered no max and sent none for it, as before.

Trae has no mover in magpie (no trae in internal/provider/migrate*.go), so
no min is raised.

Run on mote: packages/trae bun test with HOME under a temp dir, 246 pass
0 fail; bun scripts/check.mjs trae ok (registry ok).
Broken by hand: without effortOf's max -> extra_high line, 4 reasoning
tests go red (the #434 chatBody case, the variant round trip, the new
max/xhigh mapping test and the fetch-level max test); with variantsOf
offering the entry's own levels only, 4 go red (the variant lists and the
new test).
Not tried: a real TRAE CN account (no request with extra_high from max
was sent to Trae itself), nor a magpie routing group end to end; the
range and the group's max are read from magpie's code, not seen in its
GUI. A user who ticked a Trae model's levels by hand in magpie keeps that
list, without max, until they tick it.
This commit is contained in:
yetone
2026-11-09 14:51:21 +08:00
parent 1aab125bf1
commit 065758f58b
4 changed files with 100 additions and 14 deletions
+7 -2
View File
@@ -251,8 +251,13 @@ which levels it takes — its `reasoning_effort_config`, with the options
names as `reasoning_effort`, so a level an agent picks is sent as Trae
spells it: the plugin offers each model's own levels as `variants`
(`low`/`high`/`xhigh` for `light`/`high`/`extra_high`; `medium` and `max`
keep their names, offered only where the entry names them, as for DeepSeek
V4.1 Flash's `max` in Trae's app), and sends nothing
keep their names where the entry names them). A model whose top level is
`extra_high` and that names no `max` — TRAE CN's DeepSeek-V4.1-Flash,
GLM-5.3 and Kimi-K3, 轻/高/极高 in Trae's app — is offered `max` too, sent
as `extra_high` (as `xhigh` is): 极高 is that model's max, so in a magpie
routing group it ranges up to max beside members that have one, and a
group set to max sends it `extra_high`. An entry naming Trae's own `max`
keeps it, with `extra_high` as `xhigh`. The plugin sends nothing
for a level the model doesn't name, or for a model whose entry names none —
Trae then serves it at its own default. An entry naming levels this map
can't spell offers none, rather than being sent one Trae would reject. A
+20 -3
View File
@@ -2996,6 +2996,15 @@ const MAX = "-max"
// 更大上下文 (Max) 1M-window switch, which is the model id + MAX below, not a
// level (#434's screenshot).
//
// TRAE CN's 极高 (extra_high) is the top of a model that names no max of its
// own — DeepSeek-V4.1-Flash, GLM-5.3 and Kimi-K3 offer 轻/高/极高 — so it is
// that model's max too (@avalongarden6 on X, 11-09). Offered as xhigh alone,
// such a member ranged 低–很高 beside WorkBuddy's and Qoder's …–最高 in a
// routing group, and the group, which offers the levels its members share,
// lost max for every member. So such a model is offered max as well, and max
// is sent as extra_high (topsAtXhigh). An entry that names Trae's own max
// keeps it: max is max and extra_high is xhigh.
//
// An entry without the config takes no level: Trae serves it at its own
// default and nothing is sent. The plugin used to send none for every model,
// which read as "Trae takes no level" — it takes them, per model, and an
@@ -3020,19 +3029,27 @@ const levelsOf = (m) => {
// spelling here would make the body say "light", which is not one of the
// levels this plugin offers, and the field would then be dropped. {} when the
// model takes none.
const variantsOf = (levels) => Object.fromEntries((levels ?? []).map((level) => [level, { reasoningEffort: level }]))
const variantsOf = (levels) => Object.fromEntries(offered(levels).map((level) => [level, { reasoningEffort: level }]))
// topsAtXhigh: the entry's top level is extra_high, with no max of its own
const topsAtXhigh = (levels) => Array.isArray(levels) && levels.includes("xhigh") && !levels.includes("max")
// offered is the levels agents are offered for a model: its own, and max
// beside an extra_high that is its top (sent as extra_high, effortOf)
const offered = (levels) => (topsAtXhigh(levels) ? [...levels, "max"] : levels ?? [])
// effortOf is the name to send Trae for an effort the request carries, or
// undefined when the model doesn't take that one: a level Trae has no entry for
// is rejected, so nothing is sent instead. The effort arrives in either
// spelling — this plugin's own (low/high/xhigh) from its variants, or Trae's
// (light/extra_high) from a client that read them off the list — and both name
// the same level.
// the same level. max is sent as extra_high to a model whose top that is.
const effortOf = (levels, effort) => {
if (typeof effort !== "string" || !levels) return undefined
const mine = Object.values(LEVELS).includes(effort) ? effort
: Object.prototype.hasOwnProperty.call(LEVELS, effort) ? LEVELS[effort]
: undefined
if (mine === "max" && topsAtXhigh(levels)) return "extra_high"
if (mine === undefined || !levels.includes(mine)) return undefined
return Object.keys(LEVELS).find((k) => LEVELS[k] === mine)
}
@@ -3823,4 +3840,4 @@ const makePlugin = (site) => async ({ client }) => {
export const TraeCNAuthPlugin = makePlugin(SITES["trae-cn"])
export const TraeGlobalAuthPlugin = makePlugin(SITES["trae-global"])
export const _internal = { ownClient, clientStoragePaths, clientDevice, clientProfiles, deviceNote, clientDecode, thisMachine, traeHost, accountOf, HOSTS: SITES["trae-cn"].hosts, MODELS: SITES["trae-cn"].models, TextTools, NativeCalls, looseJSON, glmCall, nameCall, toolNamed, unwrapped, traeMessages, chatBody, nativeTools, moonshotSchema, credits, dollarUsageOf, whenOf, newDevice, ugDevice, proofOf, SITES, SESSION, conversationID, LEVELS, levelsOf, variantsOf, effortOf, traeRateOf }
export const _internal = { ownClient, clientStoragePaths, clientDevice, clientProfiles, deviceNote, clientDecode, thisMachine, traeHost, accountOf, HOSTS: SITES["trae-cn"].hosts, MODELS: SITES["trae-cn"].models, TextTools, NativeCalls, looseJSON, glmCall, nameCall, toolNamed, unwrapped, traeMessages, chatBody, nativeTools, moonshotSchema, credits, dollarUsageOf, whenOf, newDevice, ugDevice, proofOf, SITES, SESSION, conversationID, LEVELS, levelsOf, variantsOf, effortOf, offered, traeRateOf }
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-trae-auth",
"version": "0.2.32",
"version": "0.2.33",
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
"type": "module",
"main": "./opencode.mjs",
+72 -8
View File
@@ -40,12 +40,15 @@ async function live(configs) {
test("an entry's levels are offered as the variants agents pick, named as OpenCode names them", async () => {
const ms = await live([entry("deepseek-v4.1-flash", ["light", "high", "extra_high"], { default_level: "high" })])
const m = ms["deepseek-v4.1-flash"]
expect(Object.keys(m.variants)).toEqual(["low", "high", "xhigh"])
// extra_high is this model's top, so it is offered as max too (sent as
// extra_high): a routing group with it in can offer max
expect(Object.keys(m.variants)).toEqual(["low", "high", "xhigh", "max"])
// the value is what OpenCode writes into the body, so it is this plugin's
// name for the level; effortOf turns it into Trae's on the way out
expect(m.variants.low).toEqual({ reasoningEffort: "low" })
expect(m.variants.high).toEqual({ reasoningEffort: "high" })
expect(m.variants.xhigh).toEqual({ reasoningEffort: "xhigh" })
expect(m.variants.max).toEqual({ reasoningEffort: "max" })
// the model reasons, as it did before the levels came
expect(m.capabilities.reasoning).toBe(true)
})
@@ -65,8 +68,10 @@ test("max and medium an entry names are offered and sent as Trae names them (#43
const levels = ["low", "medium", "high", "xhigh", "max"]
expect(chatBody(req("max"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBe("max")
expect(chatBody(req("medium"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBe("medium")
// a model that names no max still sends nothing for it
expect(chatBody(req("max"), "chat_v3", "", 0, null, "s", false, ["low", "high", "xhigh"]).reasoning_effort).toBeUndefined()
// a model that names no max and tops at extra_high is sent extra_high for it
expect(chatBody(req("max"), "chat_v3", "", 0, null, "s", false, ["low", "high", "xhigh"]).reasoning_effort).toBe("extra_high")
// one whose top is lower still sends nothing for it
expect(chatBody(req("max"), "chat_v3", "", 0, null, "s", false, ["low", "high"]).reasoning_effort).toBeUndefined()
})
test("max reaches Trae's request for a model whose entry names it (#434)", async () => {
@@ -107,7 +112,7 @@ test("the levels an agent picks are sent as Trae's own names, and left out when
expect(chatBody(req("high"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBe("high")
expect(chatBody(req("xhigh"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBe("extra_high")
// a level the model doesn't take is not sent: Trae has no entry for it
expect(chatBody(req("max"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBeUndefined()
expect(chatBody(req("medium"), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBeUndefined()
// no effort asked, or a model with no levels: nothing sent
expect(chatBody(req(), "chat_v3", "", 0, null, "s", false, levels).reasoning_effort).toBeUndefined()
expect(chatBody(req("high"), "chat_v3", "", 0, null, "s", false, []).reasoning_effort).toBeUndefined()
@@ -146,7 +151,7 @@ test("every variant's own value survives the round trip to Trae's request", asyn
const variants = ms["deepseek-v4.1-flash"].variants
const opts = await hooks.auth.loader(async () => signedIn())
const expectSent = { low: "light", high: "high", xhigh: "extra_high" }
const expectSent = { low: "light", high: "high", xhigh: "extra_high", max: "extra_high" }
for (const [name, v] of Object.entries(variants)) {
await opts.fetch(opts.baseURL + "/chat/completions", {
method: "POST",
@@ -181,8 +186,8 @@ test("a model in the fallback table keeps the levels its entry names", async ()
const ms = await hooks.provider.models(provider, { auth: signedIn() })
// glm-5.2 is in the fallback table, so its config entry is the empty one
expect(Object.keys(ms["glm-5.2"].variants)).toEqual(["high", "xhigh"])
expect(Object.keys(ms["glm-5.3"].variants)).toEqual(["low", "high", "xhigh"])
expect(Object.keys(ms["glm-5.2"].variants)).toEqual(["high", "xhigh", "max"])
expect(Object.keys(ms["glm-5.3"].variants)).toEqual(["low", "high", "xhigh", "max"])
})
test("a request for a model with no levels carries no reasoning_effort", async () => {
@@ -384,7 +389,7 @@ test("of two entries a model has, the one naming levels is kept, so its levels a
] }))
const hooks = await TraeCNAuthPlugin({ client: {} })
const ms = await hooks.provider.models({ models: {} }, { auth: signedIn() })
expect(Object.keys(ms["glm-5.3"].variants)).toEqual(["low", "high", "xhigh"])
expect(Object.keys(ms["glm-5.3"].variants)).toEqual(["low", "high", "xhigh", "max"])
})
test("a name the lists agree on still outranks an entry's levels", async () => {
@@ -405,3 +410,62 @@ test("a name the lists agree on still outranks an entry's levels", async () => {
expect(Object.keys(ms["glm-5.3"].variants)).toEqual([])
expect(ms["glm-5.3"].name).toBe("GLM-5.3")
})
// @avalongarden6 on X (11-09): TRAE CN's app offers DeepSeek-V4.1-Flash,
// GLM-5.3 and Kimi-K3 轻/高/极高, and 极高 is the model's top. magpie ranged
// the Trae member 低–很高 beside WorkBuddy's and Qoder's …–最高, and a
// routing group, which offers the levels its members share, lost max. A
// model whose top is extra_high is offered max, sent as extra_high.
test("a model whose top is extra_high is offered max, and max and xhigh both go as extra_high", async () => {
const { offered } = _internal
for (const name of ["deepseek-v4.1-flash", "glm-5.3", "kimi-k3"]) {
const ms = await live([entry(name, ["light", "high", "extra_high"], { default_level: "high" })])
expect(Object.keys(ms[name].variants)).toEqual(["low", "high", "xhigh", "max"])
f.close()
}
const levels = ["low", "high", "xhigh"]
expect(offered(levels)).toEqual(["low", "high", "xhigh", "max"])
expect(effortOf(levels, "max")).toBe("extra_high")
expect(effortOf(levels, "xhigh")).toBe("extra_high")
expect(effortOf(levels, "extra_high")).toBe("extra_high")
// low and high are as they were
expect(effortOf(levels, "low")).toBe("light")
expect(effortOf(levels, "light")).toBe("light")
expect(effortOf(levels, "high")).toBe("high")
// a model that tops lower is offered no max, and sent none for it
expect(offered(["low", "high"])).toEqual(["low", "high"])
expect(effortOf(["low", "high"], "max")).toBeUndefined()
// nor one with no levels
expect(offered([])).toEqual([])
expect(offered(null)).toEqual([])
expect(effortOf([], "max")).toBeUndefined()
})
test("an entry that names Trae's own max keeps it: max is max, extra_high is xhigh", () => {
const { offered } = _internal
const levels = levelsOf({ reasoning_effort_config: { options: ["light", "high", "extra_high", "max"] } })
expect(offered(levels)).toEqual(["low", "high", "xhigh", "max"])
expect(effortOf(levels, "max")).toBe("max")
expect(effortOf(levels, "xhigh")).toBe("extra_high")
expect(effortOf(levels, "low")).toBe("light")
})
// a routing group set to max: magpie fits max to the member's own levels
// (catalog.NearestEffort over the variants), finds max among them and sends
// the plugin max, which must reach Trae as extra_high
test("max asked of a model whose top is extra_high reaches Trae as extra_high", async () => {
f = fakeTrae()
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
{ function: "chat_v3", config_info_list: [entry("kimi-k3", ["light", "high", "extra_high"], { default_level: "high" })] },
] }))
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { content: "ok" }], ["finish", { finish_reason: "stop" }]]))
const hooks = await TraeCNAuthPlugin({ client: {} })
const opts = await hooks.auth.loader(async () => signedIn())
await opts.fetch(opts.baseURL + "/chat/completions", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ model: "kimi-k3", stream: true, messages: [{ role: "user", content: "hi" }], reasoning_effort: "max" }),
})
const sent = f.seen.find((r) => r.path === "/api/agent/v3/llm_utils_chat")
expect(sent.json.reasoning_effort).toBe("extra_high")
})