diff --git a/packages/trae/README.md b/packages/trae/README.md index f5f87df..b923d06 100644 --- a/packages/trae/README.md +++ b/packages/trae/README.md @@ -231,7 +231,9 @@ which levels it takes — its `reasoning_effort_config`, with the options (`light`, `high`, `extra_high`) and the default. The request takes the same 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`), and sends nothing +(`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 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 diff --git a/packages/trae/index.mjs b/packages/trae/index.mjs index 808607b..caa28e3 100644 --- a/packages/trae/index.mjs +++ b/packages/trae/index.mjs @@ -2593,13 +2593,16 @@ const MAX = "-max" // (light, high, extra_high) and the one it defaults to. The request takes the // same names, as reasoning_effort, so a level an agent picks is sent as Trae // spells it. OpenCode knows the three as low/high/xhigh, so the map goes both -// ways. +// ways. Trae's client names two more, medium and max (its bundle's +// reasoning_effort.{low,medium,high,extra_high,max}), handed out per model: +// its app offers DeepSeek V4.1 Flash max (#434), so they are spelled here too, +// and still offered only for a model whose entry names them. // // 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 // entry that names none is the exception rather than the rule. -const LEVELS = { light: "low", high: "high", extra_high: "xhigh" } +const LEVELS = { light: "low", medium: "medium", high: "high", extra_high: "xhigh", max: "max" } // levelsOf is an entry's levels in OpenCode's names, in Trae's order: [] when // the entry names none, null when it names ones this map can't spell (so a diff --git a/packages/trae/package.json b/packages/trae/package.json index c414640..2f43785 100644 --- a/packages/trae/package.json +++ b/packages/trae/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-trae-auth", - "version": "0.2.22", + "version": "0.2.23", "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": "./index.mjs", diff --git a/packages/trae/reasoning.test.mjs b/packages/trae/reasoning.test.mjs index 45436b8..9ac1b8c 100644 --- a/packages/trae/reasoning.test.mjs +++ b/packages/trae/reasoning.test.mjs @@ -50,6 +50,41 @@ test("an entry's levels are offered as the variants agents pick, named as OpenCo expect(m.capabilities.reasoning).toBe(true) }) +// Trae's client names five levels (its bundle's +// reasoning_effort.{low,medium,high,extra_high,max}), handed out per model. +// Its app offers DeepSeek V4.1 Flash max (#434, huajii); a list naming max +// beside light/high/extra_high lost it, so no agent could pick it. +test("max and medium an entry names are offered and sent as Trae names them (#434)", async () => { + expect(levelsOf({ reasoning_effort_config: { options: ["light", "high", "extra_high", "max"] } })).toEqual(["low", "high", "xhigh", "max"]) + expect(levelsOf({ reasoning_effort_config: { options: ["light", "medium", "high"] } })).toEqual(["low", "medium", "high"]) + const ms = await live([entry("deepseek-v4.1-flash", ["light", "high", "extra_high", "max"], { default_level: "high" })]) + expect(Object.keys(ms["deepseek-v4.1-flash"].variants)).toEqual(["low", "high", "xhigh", "max"]) + expect(ms["deepseek-v4.1-flash"].variants.max).toEqual({ reasoningEffort: "max" }) + const req = (effort) => ({ model: "deepseek-v4.1-flash", messages: [{ role: "user", content: "hi" }], reasoning_effort: effort }) + 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() +}) + +test("max reaches Trae's request for a model whose entry names it (#434)", async () => { + f = fakeTrae() + f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [ + { function: "chat_v3", config_info_list: [entry("deepseek-v4.1-flash", ["light", "high", "extra_high", "max"], { 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: "deepseek-v4.1-flash", 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("max") +}) + test("an entry with no levels carries no variants: Trae serves it at its own default", async () => { const ms = await live([entry("glm-5.3", undefined)]) expect(ms["glm-5.3"].variants).toEqual({})