From d2449d53e68acef2163b0431e64bdb8aff196aa5 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 4 Oct 2026 10:26:56 +0800 Subject: [PATCH] =?UTF-8?q?trae=200.1.5:=20a=20model=20chat=5Fv3=20gives?= =?UTF-8?q?=20another=20model's=20name=20is=20named=20and=20asked=20as=20S?= =?UTF-8?q?OLO=20lists=20it=20(yetone/magpie#681,=20ChenstarMr:=20Trae's?= =?UTF-8?q?=20usage=20page=20booked=20magpie's=20DeepSeek=20V4.1=20Flash?= =?UTF-8?q?=20as=20"DeepSeek-V4-Flash=20=E6=AD=A3=E5=BC=8F=E7=89=88")=20?= =?UTF-8?q?=E2=80=94=20Trae=20CN's=20chat=5Fv3=20list=20names=20deepseek-v?= =?UTF-8?q?4.1-flash=20"DeepSeek-V4-Flash=20=E6=AD=A3=E5=BC=8F=E7=89=88",?= =?UTF-8?q?=20the=20name=20it=20gives=20DeepSeek-V4-Flash-Official=20too,?= =?UTF-8?q?=20while=20solo=5Fwork=5Flite,=20solo=5Fagent=20and=20solo=5Fag?= =?UTF-8?q?ent=5Flite=20name=20it=20DeepSeek-V4.1-Flash=20(the=20reporter'?= =?UTF-8?q?s=20batch=5Fget=5Fdetail=5Fparam=20answer).=20Both=20entries=20?= =?UTF-8?q?name=20the=20same=20upstream=20model,=20deepseek-v4.1-flash=5F?= =?UTF-8?q?=5Fdev,=20so=20the=20request=20reached=20V4.1=20Flash,=20but=20?= =?UTF-8?q?the=20list=20showed=20two=20models=20with=20one=20name,=20and?= =?UTF-8?q?=20Trae's=20usage=20page=20booked=20the=20request=20under=20cha?= =?UTF-8?q?t=5Fv3's=20name=20(TraeCode),=20where=20SOLO's=20request=20was?= =?UTF-8?q?=20booked=20as=20DeepSeek-V4.1-Flash=20(TraeWork).=20liveModels?= =?UTF-8?q?=20now=20marks=20an=20entry=20misnamed=20when=20another=20model?= =?UTF-8?q?=20in=20the=20same=20list=20has=20its=20name=20and=20another=20?= =?UTF-8?q?list=20names=20it=20otherwise,=20and=20takes=20for=20each=20mod?= =?UTF-8?q?el=20the=20first=20function=20whose=20entry=20names=20a=20=5F?= =?UTF-8?q?=5Fdev=20model=20and=20isn't=20misnamed=20(else=20the=20first?= =?UTF-8?q?=20naming=20a=20=5F=5Fdev=20model,=20else=20the=20first,=20as?= =?UTF-8?q?=20before):=20deepseek-v4.1-flash=20is=20named=20DeepSeek-V4.1-?= =?UTF-8?q?Flash=20and=20asked=20through=20solo=5Fwork=5Flite=20with=20dee?= =?UTF-8?q?pseek-v4.1-flash=5F=5Fdev,=20while=20DeepSeek-V4-Flash-Official?= =?UTF-8?q?,=20named=20alike=20everywhere,=20stays=20on=20chat=5Fv3.=20usa?= =?UTF-8?q?ge.test.mjs=20gains=20the=20reporter's=20shape;=20it=20fails=20?= =?UTF-8?q?on=200.1.4=20and=20passes;=20bun=20test=20(29=20pass)=20and=20b?= =?UTF-8?q?un=20scripts/check.mjs=20trae=20pass.=20Not=20tried=20with=20a?= =?UTF-8?q?=20real=20Trae=20CN=20account=20(none=20here).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/trae/index.mjs | 27 +++++++++++++++++++++++-- packages/trae/package.json | 2 +- packages/trae/usage.test.mjs | 38 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/packages/trae/index.mjs b/packages/trae/index.mjs index 70eed08..11ad04f 100644 --- a/packages/trae/index.mjs +++ b/packages/trae/index.mjs @@ -930,7 +930,8 @@ export const TraeCNAuthPlugin = async ({ client }) => { // The lists come from batch_get_detail_param, as TRAE SOLO CN asks them; // when that gives none, from get_detail_param, one function at a time. // A model several functions list is asked through the first whose entry - // names a __dev model (one Trae serves), else the first. + // names a __dev model (one Trae serves) and isn't misnamed, else the + // first that names one, else the first. const liveModels = async (a) => { let lists = null try { @@ -948,13 +949,35 @@ export const TraeCNAuthPlugin = async ({ client }) => { if (g.status === "fulfilled") lists[FUNCTIONS[i]] = g.value }) } + // a function can give a model another's name: chat_v3 calls + // deepseek-v4.1-flash "DeepSeek-V4-Flash 正式版", as it does + // DeepSeek-V4-Flash-Official, where SOLO's lists call it + // DeepSeek-V4.1-Flash (yetone/magpie#681) — Trae's usage page then books + // it under that name too. Such an entry is misnamed: its name is another + // model's in the same list, and other lists name it otherwise. + const nameOf = (m) => String(m.display_config?.display_name || m.display_name || m.display_model_name || m.config_name) + const names = new Map() // id → the names its lists give it + for (const fn of FUNCTIONS) { + for (const m of lists[fn] ?? []) { + if (!chatModel(m)) continue + const id = String(m.config_name) + names.set(id, (names.get(id) ?? new Set()).add(nameOf(m))) + } + } + const misnamed = (fn, m) => { + const id = String(m.config_name), name = nameOf(m) + return names.get(id).size > 1 && (lists[fn] ?? []).some((o) => chatModel(o) && String(o.config_name) !== id && nameOf(o) === name) + } + // a function's entry is worth more when it names a __dev model, then + // when it isn't misnamed; the first of the best is taken + const worth = (fn, m) => (devModel(m) ? 2 : 0) + (misnamed(fn, m) ? 0 : 1) const out = new Map() for (const fn of FUNCTIONS) { for (const m of lists[fn] ?? []) { if (!chatModel(m)) continue const id = String(m.config_name) const was = out.get(id) - if (!was || (!devModel(was.m) && devModel(m))) out.set(id, { m, fn }) + if (!was || worth(fn, m) > was.worth) out.set(id, { m, fn, worth: worth(fn, m) }) } } for (const [id, { m, fn }] of out) { diff --git a/packages/trae/package.json b/packages/trae/package.json index 23f1be5..e9637ff 100644 --- a/packages/trae/package.json +++ b/packages/trae/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-trae-auth", - "version": "0.1.4", + "version": "0.1.5", "description": "OpenCode provider plugin for Trae CN (trae.cn): your Trae CN account's models, free tier included, with Trae's own browser sign-in", "type": "module", "main": "./index.mjs", diff --git a/packages/trae/usage.test.mjs b/packages/trae/usage.test.mjs index 9362057..2fcbd74 100644 --- a/packages/trae/usage.test.mjs +++ b/packages/trae/usage.test.mjs @@ -173,3 +173,41 @@ test("when the list can't be read, the known models stand", async () => { const p = await given(hooks) expect(await hooks.provider.models(p, { auth: signedIn() })).toBe(p.models) }) + +// as Trae CN answered the reporter (yetone/magpie#681): chat_v3 lists +// deepseek-v4.1-flash with its __dev model but under DeepSeek-V4-Flash-Official's +// name, and Trae's usage page books it under that name; SOLO's lists name it +// DeepSeek-V4.1-Flash +const SAME_NAME = { function_configs: [ + { function: "chat_v3", config_info_list: [ + { config_name: "deepseek-v4.1-flash", usage: "chat_completion", display_config: { display_name: "DeepSeek-V4-Flash 正式版" }, model_detail_list: [{ model_name: "deepseek-v4.1-flash__dev" }, { model_name: "deepseek-v4.1-flash__max" }] }, + { config_name: "DeepSeek-V4-Flash-Official", usage: "chat_completion", display_config: { display_name: "DeepSeek-V4-Flash 正式版" }, model_detail_list: [{ model_name: "DeepSeek-V4-Flash-Official__dev" }] }, + ] }, + { function: "solo_work_lite", config_info_list: [ + { config_name: "deepseek-v4.1-flash", usage: "chat_completion", display_config: { display_name: "DeepSeek-V4.1-Flash" }, model_detail_list: [{ model_name: "deepseek-v4.1-flash__dev" }] }, + { config_name: "DeepSeek-V4-Flash-Official", usage: "chat_completion", display_config: { display_name: "DeepSeek-V4-Flash 正式版" }, model_detail_list: [{ model_name: "DeepSeek-V4-Flash-Official__dev" }] }, + ] }, + { function: "solo_agent", config_info_list: [ + { config_name: "deepseek-v4.1-flash", usage: "chat_completion", display_config: { display_name: "DeepSeek-V4.1-Flash" }, model_detail_list: [{ model_name: "deepseek-v4.1-flash__dev" }] }, + ] }, +] } + +test("a model chat_v3 gives another's name is named and asked as SOLO lists it (yetone/magpie#681)", async () => { + f = fakeTrae() + f.route("POST /api/ide/v1/batch_get_detail_param", () => json(SAME_NAME)) + f.route("POST /api/agent/v3/llm_utils_chat", (r) => sse([["output", { response: r.json.function + " " + (r.json.model_name ?? "-") }], ["done", {}]])) + const hooks = await TraeCNAuthPlugin({ client: {} }) + const p = await given(hooks) + const live = await hooks.provider.models(p, { auth: signedIn() }) + expect(live["deepseek-v4.1-flash"].name).toBe("DeepSeek-V4.1-Flash") + expect(live["DeepSeek-V4-Flash-Official"].name).toBe("DeepSeek-V4-Flash 正式版") + const opts = await hooks.auth.loader(async () => signedIn()) + const ask = async (model) => { + const res = await opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify({ model, messages: [{ role: "user", content: "hi" }] }) }) + return (await res.json()).choices[0].message.content + } + // the first list that names it rightly, with its __dev model + expect(await ask("deepseek-v4.1-flash")).toBe("solo_work_lite deepseek-v4.1-flash__dev") + // named alike everywhere: kept on chat_v3, as before + expect(await ask("DeepSeek-V4-Flash-Official")).toBe("chat_v3 DeepSeek-V4-Flash-Official__dev") +})