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.
101 lines
5.9 KiB
JavaScript
101 lines
5.9 KiB
JavaScript
// An enterprise's own built-in models (Trae CN's client: config_source 2,
|
|
// "Enterprise-builtin" in its picker). They are not Trae's presets, so their
|
|
// entries say is_custom_model, and the list dropped them with the personal
|
|
// custom models a seat's IDE alone holds the key for. A seat that typed one
|
|
// in by hand got a bare 502 with nothing saying what was asked.
|
|
import "./nonet.mjs"
|
|
import { afterEach, expect, test } from "bun:test"
|
|
import { TraeCNAuthPlugin, _internal } from "./index.mjs"
|
|
import { fakeTrae, json, signedIn, sse } from "./fake.mjs"
|
|
|
|
let f
|
|
afterEach(() => f?.close())
|
|
|
|
// an enterprise built-in as the detail lists are expected to carry it: the
|
|
// fields Trae CN 3.4.20's client reads of one (not yet seen from a real seat)
|
|
const ent = { config_name: "custom_model_acme_qwen", usage: "chat_completion", config_source: 2, is_preset: false,
|
|
is_custom_model: true, display_config: { display_name: "Acme Qwen", is_custom_model: true },
|
|
custom_model_id: "cm-42", provider: "volcengine", status: true }
|
|
// a personal custom model: its provider key is in the user's IDE only
|
|
const own = { config_name: "custom_model_mine", usage: "chat_completion", config_source: 3, is_preset: false,
|
|
is_custom_model: true, display_config: { display_name: "My GPT", is_custom_model: true }, custom_model_id: "cm-7" }
|
|
const preset = { config_name: "glm-5", usage: "chat_completion", config_source: 1, is_preset: true, display_config: { display_name: "GLM-5" } }
|
|
|
|
async function plugin(configs) {
|
|
f = fakeTrae()
|
|
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [{ function: "chat_v3", config_info_list: configs }] }))
|
|
return TraeCNAuthPlugin({ client: {} })
|
|
}
|
|
|
|
test("an enterprise built-in model is listed; a personal custom one and a disabled one are not", async () => {
|
|
const hooks = await plugin([preset, ent, own, { ...ent, config_name: "custom_model_off", status: false }])
|
|
const ms = await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
|
expect(Object.keys(ms).sort()).toEqual(["custom_model_acme_qwen", "glm-5"])
|
|
expect(ms.custom_model_acme_qwen.name).toBe("Acme Qwen")
|
|
})
|
|
|
|
test("chatModel keeps config_source 2 only", () => {
|
|
expect(_internal.chatModel(ent)).toBe(true)
|
|
expect(_internal.chatModel(own)).toBe(false)
|
|
expect(_internal.chatModel({ ...ent, config_source: 3 })).toBe(false)
|
|
expect(_internal.chatModel({ ...ent, usage: "summary" })).toBe(false)
|
|
expect(_internal.chatModel(preset)).toBe(true)
|
|
})
|
|
|
|
// 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() })
|
|
// 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 ["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.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 () => {
|
|
const hooks = await plugin([preset, ent])
|
|
await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
|
f.route("POST /api/agent/v3/llm_utils_chat", () => json({ code: 5000, message: "model not found" }))
|
|
const opts = await hooks.auth.loader(async () => signedIn())
|
|
const ask = (model) => opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify({ model, messages: [{ role: "user", content: "hi" }] }) })
|
|
|
|
let res = await ask("custom_model_acme_qwen")
|
|
expect(res.status).toBe(502)
|
|
let msg = (await res.json()).error.message
|
|
expect(msg).toContain("model not found (code 5000)")
|
|
expect(msg).toContain("enterprise built-in model custom_model_acme_qwen asked through chat_v3")
|
|
expect(msg).toContain("127.0.0.1")
|
|
expect(msg).not.toContain("doesn't have")
|
|
|
|
// typed in by hand: a name the account's list doesn't have
|
|
res = await ask("Acme-Qwen-72B")
|
|
expect(res.status).toBe(502)
|
|
msg = (await res.json()).error.message
|
|
expect(msg).toContain("model Acme-Qwen-72B asked through chat_v3")
|
|
expect(msg).toContain("this account's model list doesn't have Acme-Qwen-72B")
|
|
})
|