Reported on magpie's Discord (#help): through magpie, Trae CN's doubao
model said it couldn't read images, while in Trae it reads them.
Every model was listed as text-only (MODEL's modalities), and partText
put "[an image, which this model can't see]" in every image's place, so
no image ever reached Trae.
What changed:
- Trae's lists mark each entry `multimodal` true or false
(config_info_list). A listed model's flag now decides
capabilities.input.image, attachment and modalities, over a fallback
entry's word. Doubao-Seed, Kimi K3/K2.6, Qwen 3.7 Plus and MiniMax M3
are true; GLM-5.x and DeepSeek V4 are false.
- An image sent to a model that takes images goes to llm_utils_chat as
an OpenAI image_url part ({url}) after the text part. That is the
shape TRAE's ai-agent carries (LLMRawMultiContent/LLMRawChatImageURL,
in the ai-agent binary's strings) and what autumnsentiment/Trae2api-cn
passes llm_utils_chat unchanged.
- A model marked false still gets the placeholder.
- The fallback list marks kimi-k2.6 and qwen-3.7-plus as taking images,
as Trae's SOLO list does.
The list fixture is two entries of a relay's capture of the SOLO list
(wangqi233/trae2api scripts/_solo-models-clean.json).
Run:
- images.test.mjs: 6 pass on this change; 5 of 6 fail on 0.2.14's
index.mjs (only the text-only case passes there).
- packages/trae: 146 tests, 0 fail.
- HOME=$(mktemp -d) bun test across the repo: 1616 pass, 0 fail.
- bun scripts/check.mjs: ok.
Not tried: a real Trae account. Magpie's owner has none signed in, so no
real image request was sent to Trae.
91 lines
6.1 KiB
JavaScript
91 lines
6.1 KiB
JavaScript
// Images (magpie's Discord: Trae CN's doubao said it can't read images
|
||
// through magpie, while it reads them in Trae). Trae's model lists mark
|
||
// each model multimodal true or false; a model marked true is told to
|
||
// magpie as one that takes images, and its images go to llm_utils_chat as
|
||
// OpenAI image_url parts, the shape TRAE's ai-agent sends
|
||
// (LLMRawMultiContent / LLMRawChatImageURL). A model marked false is still
|
||
// told there was an image it can't see.
|
||
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())
|
||
|
||
// two entries of TRAE SOLO CN's list as Trae sends them (the fields a
|
||
// relay's capture of the solo_agent list kept, wangqi233/trae2api
|
||
// scripts/_solo-models-clean.json), with the __dev model the request needs
|
||
const seed = { config_name: "Doubao-Seed-2.1-Pro", display_name: "Seed-2.1-Pro", capability: "reasoning_model", multimodal: true, ctx_dev: 256000, is_default: false, is_custom_model: false, usage: "chat_completion", model_detail_list: [{ model_name: "Doubao-Seed-2.1-Pro__dev" }] }
|
||
const glm = { config_name: "glm-5.3", display_name: "GLM-5.3", capability: "reasoning_model", multimodal: false, ctx_dev: 200000, is_default: false, is_custom_model: false, usage: "chat_completion", model_detail_list: [{ model_name: "glm-5.3__dev" }] }
|
||
|
||
// a 1×1 PNG, as an agent attaches a screenshot
|
||
const PNG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
|
||
const said = (text) => ({ role: "user", content: [{ type: "text", text }, { type: "image_url", image_url: { url: PNG } }] })
|
||
|
||
async function plugin() {
|
||
f = fakeTrae()
|
||
f.route("POST /api/ide/v1/batch_get_detail_param", () => json({ function_configs: [{ function: "chat_v3", config_info_list: [seed, glm] }] }))
|
||
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { response: "a red dot" }], ["done", {}]]))
|
||
return TraeCNAuthPlugin({ client: {} })
|
||
}
|
||
|
||
async function ask(hooks, body) {
|
||
const opts = await hooks.auth.loader(async () => signedIn())
|
||
const res = await opts.fetch(opts.baseURL + "/chat/completions", { method: "POST", body: JSON.stringify(body) })
|
||
await res.text()
|
||
return f.seen.filter((r) => r.path === "/api/agent/v3/llm_utils_chat").at(-1).json
|
||
}
|
||
|
||
test("a model Trae's list marks multimodal is one that takes images, and one marked otherwise isn't", async () => {
|
||
const ms = await (await plugin()).provider.models({ models: {} }, { auth: signedIn() })
|
||
expect(ms["Doubao-Seed-2.1-Pro"].capabilities.input.image).toBe(true)
|
||
expect(ms["Doubao-Seed-2.1-Pro"].capabilities.attachment).toBe(true)
|
||
expect(ms["Doubao-Seed-2.1-Pro"].modalities.input).toEqual(["text", "image"])
|
||
expect(ms["glm-5.3"].capabilities.input.image).toBe(false)
|
||
expect(ms["glm-5.3"].capabilities.attachment).toBe(false)
|
||
})
|
||
|
||
test("the list's word wins over a fallback entry's capabilities", async () => {
|
||
const was = { capabilities: { reasoning: true, temperature: true, toolcall: true, 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 (await plugin()).provider.models({ models: { "Doubao-Seed-2.1-Pro": was } }, { auth: signedIn() })
|
||
expect(ms["Doubao-Seed-2.1-Pro"].capabilities.input).toEqual({ text: true, image: true, audio: false, video: false, pdf: false })
|
||
})
|
||
|
||
test("a multimodal model's image goes to Trae as an image_url part beside the text", async () => {
|
||
const hooks = await plugin()
|
||
await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||
const b = await ask(hooks, { model: "Doubao-Seed-2.1-Pro", stream: true, messages: [said("what is this?")] })
|
||
expect(b.messages).toEqual([{ role: "user", content: [{ type: "text", text: "what is this?" }, { type: "image_url", image_url: { url: PNG } }] }])
|
||
expect(JSON.stringify(b)).not.toContain("can't see")
|
||
})
|
||
|
||
test("a model Trae marks text-only is told of the image, not sent it", async () => {
|
||
const hooks = await plugin()
|
||
await hooks.provider.models({ models: {} }, { auth: signedIn() })
|
||
const b = await ask(hooks, { model: "glm-5.3", stream: true, messages: [said("what is this?")] })
|
||
expect(b.messages).toEqual([{ role: "user", content: [{ type: "text", text: "what is this?\n[an image, which this model can't see]" }] }])
|
||
})
|
||
|
||
test("an image alone, a tool's image and two user turns in a row keep every image in order", () => {
|
||
const m = _internal.traeMessages({ messages: [
|
||
{ role: "user", content: [{ type: "image_url", image_url: { url: PNG } }] },
|
||
{ role: "user", content: [{ type: "text", text: "and this" }, { type: "image_url", image_url: "https://example.invalid/b.png" }] },
|
||
{ role: "assistant", content: null, tool_calls: [{ id: "c1", type: "function", function: { name: "shot", arguments: "{}" } }] },
|
||
{ role: "tool", tool_call_id: "c1", content: [{ type: "text", text: "taken" }, { type: "image_url", image_url: { url: PNG } }] },
|
||
] }, true)
|
||
expect(m.map((x) => x.role)).toEqual(["user", "assistant", "user"])
|
||
expect(m[0].content).toEqual([{ type: "text", text: "and this" }, { type: "image_url", image_url: { url: PNG } }, { type: "image_url", image_url: { url: "https://example.invalid/b.png" } }])
|
||
expect(m[2].content).toEqual([{ type: "text", text: "Result of shot (call c1):\ntaken" }, { type: "image_url", image_url: { url: PNG } }])
|
||
})
|
||
|
||
test("a fallback model that Trae marks multimodal is sent its images before the list is read", async () => {
|
||
f = fakeTrae()
|
||
f.route("POST /api/agent/v3/llm_utils_chat", () => sse([["output", { response: "ok" }], ["done", {}]]))
|
||
const hooks = await TraeCNAuthPlugin({ client: {} })
|
||
expect((await ask(hooks, { model: "kimi-k2.6", stream: true, messages: [said("see")] })).messages[0].content[1]).toEqual({ type: "image_url", image_url: { url: PNG } })
|
||
expect((await ask(hooks, { model: "glm-5", stream: true, messages: [said("see")] })).messages[0].content).toEqual([{ type: "text", text: "see\n[an image, which this model can't see]" }])
|
||
})
|