trae 0.2.42: an enterprise model's chat says its config_source at the top (#1258)
On 0.2.41 the reporter's enterprise seat (@liuyuexue2020 on X, Trae CN,
console.enterprise.trae.cn) now lists its enterprise built-in models, but
a chat with one, AI/deekseek-v4.1-flash, got 502 with Trae's 4001 "We're
sorry, the param is invalid. Please try with a valid param." on chat_v3,
solo_work_lite, solo_agent, solo_agent_lite and solo_coder (their
screenshot on #1258). The error also confirms the list entry carries
config_source 2, the first real-seat sight of that field.
0.2.41 sent config_source, is_preset, custom_model_id and provider under
user_message_context.model_info, which is the agent task's model info.
Trae CN 3.4.20's own llm_utils_chat request (libharness,
worktree/branch_name.rs, asked with the user's selected model) is
usage, function, messages, conversation_id, access_type, config_name,
model_name, config_source, is_custom_model, provider: those fields go at
the top of the body. chatBody now sends config_source 2, is_custom_model
true and the entry's provider there, and no model_info for it. A preset's
body is unchanged.
Run (mote, HOME=$(mktemp -d), at this tree on 324acd60):
packages/trae bun test, 282 pass, 0 fail (24 files);
bun scripts/check.mjs trae ok.
Broken by hand: with the enterprise block in chatBody turned off, both
new entmodels tests went red (the fake answers the reporter's 4001 to an
enterprise config sent without config_source), and green again once
restored.
Not tried: a real enterprise seat; we have none. The field set comes from
the 3.4.20 client binary, and whether Trae's server wants more (model_name,
access_type) for an enterprise config is not known. The reporter couldn't
capture the IDE's chat in DevTools because the native ai-agent process
sends it, not the renderer.
This commit is contained in:
@@ -245,10 +245,12 @@ custom-model slots. An enterprise's own built-in models
|
||||
(`config_source` 2, "Enterprise-builtin" in Trae CN's picker) are listed
|
||||
since 0.2.41 (#1258), unless the admin switched one off (`status` false); a
|
||||
personal custom model (`config_source` 3) is not, its key being in the
|
||||
user's IDE only. A chat with an enterprise model carries
|
||||
`user_message_context.model_info` as Trae CN 3.4.20's client builds it
|
||||
(`config_source`, `is_preset` false, `custom_model_id`, `provider`) —
|
||||
**not verified with a real enterprise seat**. A refused chat's error names
|
||||
user's IDE only. A chat with an enterprise model carries `config_source`
|
||||
2, `is_custom_model` true and the entry's `provider` at the top of the
|
||||
body, as Trae CN 3.4.20's own `llm_utils_chat` request does (0.2.42; 0.2.41
|
||||
put them under `user_message_context.model_info`, and an enterprise seat got
|
||||
4001 "the param is invalid" on every function) — **not verified with a real
|
||||
enterprise seat**. A refused chat's error names
|
||||
the model, the functions tried and the host, and says when the account's
|
||||
list doesn't have the model. Context is the list's `context_window_tokens.dev`,
|
||||
output the `__dev` model's `max_tokens`. A model with a `__max` model and
|
||||
|
||||
@@ -42,20 +42,38 @@ test("chatModel keeps config_source 2 only", () => {
|
||||
expect(_internal.chatModel(preset)).toBe(true)
|
||||
})
|
||||
|
||||
test("a chat with an enterprise model carries its model info; a preset's doesn't", async () => {
|
||||
const hooks = await plugin([preset, ent])
|
||||
// the reporter's own model and error (#1258, 0.2.41, console.enterprise.trae.cn):
|
||||
// the enterprise config asked without its config_source got 4001 on every function
|
||||
const REPORTED = "We're sorry, the param is invalid. Please try with a valid param."
|
||||
const theirs = { ...ent, config_name: "AI/deekseek-v4.1-flash", display_config: { display_name: "deekseek-v4.1-flash", is_custom_model: true } }
|
||||
|
||||
test("a chat with an enterprise model says its config_source at the top, as Trae's own llm_utils_chat does; a preset's doesn't", async () => {
|
||||
const hooks = await plugin([preset, theirs])
|
||||
await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||||
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { response: "ok" }], ["done", {}]]))
|
||||
// Trae as the reporter met it: an enterprise config asked as if it were
|
||||
// one of Trae's presets is "the param is invalid"
|
||||
f.route("POST /api/agent/v3/llm_utils_chat", (r) => (r.json.config_name === theirs.config_name && r.json.config_source !== 2
|
||||
? sse([["error", { code: 4001, message: REPORTED }]])
|
||||
: sse([["output", { response: "ok" }], ["done", {}]])))
|
||||
const opts = await hooks.auth.loader(async () => signedIn())
|
||||
for (const model of ["custom_model_acme_qwen", "glm-5"]) {
|
||||
for (const model of ["AI/deekseek-v4.1-flash", "glm-5"]) {
|
||||
const res = await opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify({ model, messages: [{ role: "user", content: "hi" }] }) })
|
||||
expect(res.status).toBe(200)
|
||||
expect((await res.json()).choices[0].message.content).toBe("ok")
|
||||
}
|
||||
const chats = f.seen.filter((r) => r.path === "/api/agent/v3/llm_utils_chat")
|
||||
expect(chats[0].json.model).toBe("custom_model_acme_qwen")
|
||||
expect(chats[0].json.user_message_context.model_info).toEqual({ config_name: "custom_model_acme_qwen", config_source: 2, is_preset: false,
|
||||
use_remote_service: true, display_model_name: "Acme Qwen", custom_model_id: "cm-42", provider: "volcengine" })
|
||||
expect(chats[1].json.user_message_context).toBeUndefined()
|
||||
expect(chats.length).toBe(2)
|
||||
expect(chats[0].json).toMatchObject({ config_name: "AI/deekseek-v4.1-flash", model: "AI/deekseek-v4.1-flash", config_source: 2, is_custom_model: true, provider: "volcengine" })
|
||||
expect(chats[0].json.user_message_context).toBeUndefined()
|
||||
for (const k of ["config_source", "is_custom_model", "provider", "user_message_context"]) expect(chats[1].json[k]).toBeUndefined()
|
||||
})
|
||||
|
||||
test("an enterprise entry with no provider sends none", async () => {
|
||||
const { provider, ...bare } = theirs
|
||||
const body = _internal.chatBody({ model: bare.config_name, messages: [{ role: "user", content: "hi" }] }, "chat_v3", "", 0, null, "s", false, null, bare)
|
||||
expect(body.config_source).toBe(2)
|
||||
expect(body.is_custom_model).toBe(true)
|
||||
expect("provider" in body).toBe(false)
|
||||
})
|
||||
|
||||
test("a refused chat names the model, the functions tried and the host", async () => {
|
||||
|
||||
+14
-14
@@ -1638,21 +1638,21 @@ function chatBody(req, fn, modelName, most = 0, max = null, session = "", sees =
|
||||
if (!body.max_tokens && most > 0) body.max_tokens = most
|
||||
body.user_message_context = { model_info: { prompt_max_tokens: max.window - (body.max_tokens || 0) } }
|
||||
}
|
||||
// an enterprise's built-in model goes with the model info Trae CN's own
|
||||
// client gives it (ai-modules-chat's model info: config_source, is_preset
|
||||
// false, its custom_model_id, served remotely). Not confirmed against an
|
||||
// enterprise seat's real request: a Trae preset is sent as before.
|
||||
// an enterprise's built-in model says where its config comes from beside
|
||||
// config_name, at the top of the body: Trae CN 3.4.20's own llm_utils_chat
|
||||
// request (libharness, worktree/branch_name.rs, asked with the user's
|
||||
// selected model) is usage, function, messages, conversation_id,
|
||||
// access_type, config_name, model_name, config_source, is_custom_model,
|
||||
// provider. Without them Trae looks the config up among its own presets
|
||||
// and answers 4001 "the param is invalid" on every function (#1258, an
|
||||
// enterprise seat on console.enterprise.trae.cn, 0.2.41, which sent them
|
||||
// under user_message_context.model_info, the agent task's shape). Not yet
|
||||
// seen answering from a real enterprise seat: a Trae preset is sent as
|
||||
// before.
|
||||
if (enterpriseModel(entry)) {
|
||||
const info = body.user_message_context?.model_info ?? {}
|
||||
info.config_name = config
|
||||
info.config_source = ENTERPRISE
|
||||
info.is_preset = false
|
||||
info.use_remote_service = true
|
||||
const shown = entry.display_config?.display_name || entry.display_name
|
||||
if (shown) info.display_model_name = String(shown)
|
||||
if (entry.custom_model_id) info.custom_model_id = String(entry.custom_model_id)
|
||||
if (entry.provider) info.provider = String(entry.provider)
|
||||
body.user_message_context = { ...body.user_message_context, model_info: info }
|
||||
body.config_source = ENTERPRISE
|
||||
body.is_custom_model = true
|
||||
if (entry.provider) body.provider = String(entry.provider)
|
||||
}
|
||||
if (typeof req.temperature === "number") body.temperature = req.temperature
|
||||
if (Array.isArray(req.tools) && req.tools.length && req.tool_choice !== "none") {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-trae-auth",
|
||||
"version": "0.2.41",
|
||||
"version": "0.2.42",
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user