trae 0.2.4: a model outside the fallback list is served with capabilities, so magpie reads it as one that reasons (#28)
magpie's host builds a provider's models from the plugin's config first (internal/plugin/host.js: the config's flat fields are spread into capabilities), then lets the provider.models hook replace the list. The hook handed back each model without capabilities, and magpie reads capabilities.reasoning alone for a model a plugin lists, so every model the site's fallback table doesn't have was listed as one that doesn't reason. On Trae CN that was every model but the table's six; on Trae Global every model but its five. A routing group with one of them in it lost reasoning for the whole group (magpie's groups take a member that thinks), and the agent turned thinking off for it. modelOf now gives each model it builds capabilities: the fallback table's own where it has an entry, else MODEL's flat fields (reasoning, temperature, tool_call, the input modalities) with an empty variants, as Trae's request takes no effort or thinking level. The Max twin takes them through the same path. packages/trae/models.test.mjs (5 tests) fails without the change: capabilities.reasoning is undefined for deepseek-v4-flash-0731-max, for the whole list, and for the Max twin; the fallback table's own entry and Trae Global's models pass either way. bun test packages/trae: 79 pass. bun scripts/check.mjs: every package ok. The whole suite has the same 40 failures before and after (Windows-only, other packages).
This commit is contained in:
@@ -122,7 +122,12 @@ it, as Max mode does.
|
||||
|
||||
Reasoning: the models reason, but Trae's request takes no effort or
|
||||
thinking level, so the plugin lists no variants and a level an agent
|
||||
picks does nothing.
|
||||
picks does nothing. Every model it lists says so in its `capabilities`
|
||||
(`reasoning: true`, with `toolcall`, `temperature`, `attachment`, the
|
||||
input and output modalities and an empty `variants`), the fallback
|
||||
list's own capabilities kept where it has an entry: magpie reads
|
||||
`capabilities.reasoning` alone for a model a plugin lists, and a model
|
||||
without it is shown as one that doesn't reason (0.2.4).
|
||||
|
||||
When no
|
||||
list can be read, the plugin uses the realm's own fallback list. Trae CN's
|
||||
|
||||
+24
-1
@@ -1804,6 +1804,13 @@ const makePlugin = (site) => async ({ client }) => {
|
||||
return [...out.values()].map((x) => x.m)
|
||||
}
|
||||
|
||||
// modelOf is a model of the account's list as OpenCode's provider
|
||||
// carries one. A model of the site's fallback list has capabilities
|
||||
// already (magpie's host spreads the config's into them); one the list
|
||||
// doesn't have gets them from MODEL's flat fields, so that magpie reads
|
||||
// it as a model that reasons rather than one that doesn't (its host
|
||||
// reads capabilities.reasoning alone, host.js). The fallback list stays
|
||||
// the authority where it has an entry.
|
||||
const modelOf = (provider, m) => {
|
||||
const id = String(m.config_name)
|
||||
const was = provider.models?.[id] ?? {}
|
||||
@@ -1811,7 +1818,23 @@ const makePlugin = (site) => async ({ client }) => {
|
||||
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 || 0
|
||||
const name = m.display_config?.display_name || m.display_name || m.display_model_name || was.name || id
|
||||
return { ...MODEL, ...was, id, providerID: site.id, name: String(name), limit: { context: ctx, output: out }, api: was.api ?? { id, url: site.hosts.api, npm: "@ai-sdk/openai-compatible" } }
|
||||
const input = (k) => (MODEL.modalities?.input ?? []).includes(k)
|
||||
return {
|
||||
...MODEL, ...was, id, providerID: site.id, name: String(name), limit: { context: ctx, output: out },
|
||||
api: was.api ?? { id, url: site.hosts.api, npm: "@ai-sdk/openai-compatible" },
|
||||
capabilities: {
|
||||
...(was.capabilities ?? {}),
|
||||
reasoning: was.capabilities?.reasoning ?? MODEL.reasoning,
|
||||
temperature: was.capabilities?.temperature ?? MODEL.temperature,
|
||||
attachment: was.capabilities?.attachment ?? MODEL.attachment,
|
||||
toolcall: was.capabilities?.toolcall ?? MODEL.tool_call,
|
||||
input: was.capabilities?.input ?? { text: true, image: input("image"), audio: input("audio"), video: input("video"), pdf: input("pdf") },
|
||||
output: was.capabilities?.output ?? { text: true, image: false, audio: false, video: false, pdf: false },
|
||||
},
|
||||
// Trae's request takes no effort or thinking level, so a model has
|
||||
// none to pick from (see the README's Reasoning)
|
||||
variants: was.variants ?? {},
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// What magpie reads of a Trae model: capabilities.reasoning. magpie builds
|
||||
// a provider's models from the plugin's config first (its host spreads the
|
||||
// config's flat fields into capabilities, internal/plugin/host.js), then
|
||||
// lets the provider.models hook replace the list. A hook that hands back a
|
||||
// model without capabilities replaces a model that reasons with one magpie
|
||||
// reads as one that doesn't: every model outside the site's fallback table
|
||||
// came out 不支持推理, and a routing group with one of them in it lost
|
||||
// reasoning for the whole group (magpie's groups take a member that thinks).
|
||||
// So every model the hook returns carries capabilities.
|
||||
import "./nonet.mjs"
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { TraeCNAuthPlugin, _internal } from "./index.mjs"
|
||||
import { fakeTrae, json, signedIn } from "./fake.mjs"
|
||||
|
||||
let f
|
||||
afterEach(() => f?.close())
|
||||
|
||||
// live serves the account's list (one chat function's entries) and hands
|
||||
// back the models the provider.models hook built from it.
|
||||
async function live(configs, provider = { models: {} }) {
|
||||
f = fakeTrae()
|
||||
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||
{ function: "chat_v3", config_info_list: configs },
|
||||
] }))
|
||||
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||||
return hooks.provider.models(provider, { auth: signedIn() })
|
||||
}
|
||||
|
||||
// a model the account's list has and the fallback table doesn't (magpie's
|
||||
// report: deepseek-v4-flash-0731-max was 不支持推理)
|
||||
const offTable = { config_name: "deepseek-v4-flash-0731-max", usage: "chat_completion",
|
||||
display_config: { display_name: "DeepSeek V4 Flash 0731 Max" },
|
||||
context_window_tokens: { dev: 1_000_000 },
|
||||
model_detail_list: [{ model_name: "deepseek-v4-flash-0731-max__dev", max_tokens: 32000 }] }
|
||||
|
||||
test("a model the fallback table doesn't have is served with capabilities", async () => {
|
||||
const ms = await live([offTable])
|
||||
const m = ms["deepseek-v4-flash-0731-max"]
|
||||
expect(m.capabilities.reasoning).toBe(true)
|
||||
expect(m.capabilities.toolcall).toBe(true)
|
||||
expect(m.capabilities.temperature).toBe(true)
|
||||
expect(m.capabilities.attachment).toBe(false)
|
||||
expect(m.capabilities.input).toEqual({ text: true, image: false, audio: false, video: false, pdf: false })
|
||||
expect(m.capabilities.output).toEqual({ text: true, image: false, audio: false, video: false, pdf: false })
|
||||
// Trae's request takes no effort or thinking level: no variants
|
||||
expect(m.variants).toEqual({})
|
||||
})
|
||||
|
||||
test("the fallback table stays the authority where it has an entry", async () => {
|
||||
// what magpie's host hands the hook for a model of the config: the
|
||||
// fallback table's flat fields already spread into capabilities
|
||||
const was = { id: "minimax-m2", name: "MiniMax M2", reasoning: false, tool_call: false, temperature: false,
|
||||
capabilities: { reasoning: false, temperature: false, toolcall: false, attachment: false,
|
||||
input: { text: true, image: false, audio: false, video: false, pdf: false },
|
||||
output: { text: true, image: false, audio: false, video: false, pdf: false } } }
|
||||
const ms = await live([{ config_name: "minimax-m2", usage: "chat_completion", display_config: { display_name: "MiniMax M2" } }],
|
||||
{ models: { "minimax-m2": was } })
|
||||
const m = ms["minimax-m2"]
|
||||
expect(m.capabilities.reasoning).toBe(false)
|
||||
expect(m.capabilities.toolcall).toBe(false)
|
||||
expect(m.capabilities.temperature).toBe(false)
|
||||
})
|
||||
|
||||
test("every model of the account's list, the fallback ones included, carries capabilities", async () => {
|
||||
const ms = await live([offTable,
|
||||
{ config_name: "glm-5.2", usage: "chat_completion", display_config: { display_name: "GLM-5.2" },
|
||||
context_window_tokens: { dev: 200000 }, model_detail_list: [{ model_name: "glm-5.2__dev", max_tokens: 32000 }] }])
|
||||
expect(Object.keys(ms)).toEqual(["deepseek-v4-flash-0731-max", "glm-5.2"])
|
||||
for (const m of Object.values(ms)) {
|
||||
expect(m.capabilities?.reasoning).toBe(true)
|
||||
expect(m.capabilities.input.text).toBe(true)
|
||||
expect(m.capabilities.output.text).toBe(true)
|
||||
expect(m.variants).toEqual({})
|
||||
}
|
||||
// the model of the fallback table keeps its own name and window
|
||||
expect(ms["glm-5.2"].name).toBe("GLM-5.2")
|
||||
expect(ms["glm-5.2"].limit.context).toBe(200000)
|
||||
// the off-table one is named and windowed from the list
|
||||
expect(ms["deepseek-v4-flash-0731-max"].name).toBe("DeepSeek V4 Flash 0731 Max")
|
||||
expect(ms["deepseek-v4-flash-0731-max"].limit.context).toBe(1_000_000)
|
||||
})
|
||||
|
||||
test("a model's Max is a model of its own and reasons too", async () => {
|
||||
const max = { config_name: "deepseek-v4-flash-0731-max", usage: "chat_completion",
|
||||
display_config: { display_name: "DeepSeek V4 Flash 0731" },
|
||||
context_window_tokens: { dev: 200000, max: 1000000 },
|
||||
model_detail_list: [{ model_name: "deepseek-v4-flash-0731__dev", max_tokens: 32000 },
|
||||
{ model_name: "deepseek-v4-flash-0731__max", max_tokens: 64000 }] }
|
||||
const ms = await live([max])
|
||||
expect(Object.keys(ms).sort()).toEqual(["deepseek-v4-flash-0731-max", "deepseek-v4-flash-0731-max-max"])
|
||||
expect(ms["deepseek-v4-flash-0731-max-max"].capabilities.reasoning).toBe(true)
|
||||
expect(ms["deepseek-v4-flash-0731-max-max"].name).toBe("DeepSeek V4 Flash 0731 (Max)")
|
||||
expect(ms["deepseek-v4-flash-0731-max-max"].limit.context).toBe(1_000_000)
|
||||
})
|
||||
|
||||
// The two realms share the machinery, so the fix is one: Trae Global's
|
||||
// models carry capabilities too.
|
||||
test("Trae Global's models carry capabilities as well", async () => {
|
||||
f = fakeTrae("trae-global")
|
||||
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [
|
||||
{ function: "chat_v3", config_info_list: [{ config_name: "gemini-3.1-pro-paygo", usage: "chat_completion",
|
||||
display_config: { display_name: "Gemini 3.1 Pro" }, model_detail_list: [{ model_name: "gemini-3.1-pro-paygo__dev" }] }] },
|
||||
] }))
|
||||
const { TraeGlobalAuthPlugin } = await import("./index.mjs")
|
||||
const hooks = await TraeGlobalAuthPlugin({ client: {} })
|
||||
const ms = await hooks.provider.models({ models: { ..._internal.SITES["trae-global"].models } }, { auth: signedIn() })
|
||||
expect(ms["gemini-3.1-pro-paygo"].capabilities.reasoning).toBe(true)
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-trae-auth",
|
||||
"version": "0.2.3",
|
||||
"version": "0.2.4",
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user