Skip to content

Commit 3c5df1e

Browse files
committed
fix(mimo): flatten list-type tool message content to string (upstream #32613)
Root cause finally verified via upstream issue anomalyco/opencode#32613 'Xiaomi MiMo rejects list-type tool message content (400 text is not set)': Xiaomi MiMo API requires role:'tool' message content to be a plain string, NOT a list of content parts. MiMo accepts multimodal content in user/assistant messages but strictly rejects list-type content in tool messages. The OpenCode Go gateway passes list-type content through unchanged, so we must flatten it client-side. Verified in user log (2026-07-25 13:05): messages=3 payloadBytes=151626 -> 200 OK (tool result without image) messages=5 payloadBytes=426159 -> 400 Upstream request failed (same + tool result WITH image_url list-type content) Previous 4 fix attempts (top-level guard, history trim, reasoning echo, TDZ) were all red herrings — the real issue is the tool message shape itself. Fix: for MiMo family, when a tool result contains image parts, emit plain string content by joining text parts and replacing each image with a short placeholder note (the model cannot see tool images on MiMo upstream anyway). Other providers (Kimi, GLM-5.1, MiniMax, Qwen) keep the multimodal array because they accept list-type tool content. Upstream PR anomalyco/opencode#32966 exists but was closed by automated cleanup before merge, so this workaround is necessary until the gateway handles the translation. - src/extension.ts: convertMessage() tool-result branch gates multimodal array on model family; MiMo gets flattened string.
1 parent fb9f824 commit 3c5df1e

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

‎src/extension.ts‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,13 +3383,37 @@ function convertMessage(
33833383

33843384
let toolContent: string | OpenAiContentPart[];
33853385
if (toolImageParts.length > 0) {
3386-
const multimodal: OpenAiContentPart[] = [];
3387-
const joinedText = toolTextParts.join("\n");
3388-
if (joinedText) {
3389-
multimodal.push({ type: "text", text: joinedText });
3386+
// PROVIDER QUIRK: Xiaomi MiMo (and GLM-5.2) reject list-type tool
3387+
// message content with HTTP 400 "text is not set" (upstream issue
3388+
// anomalyco/opencode#32613). MiMo accepts multimodal content in
3389+
// user/assistant messages but strictly requires `role: "tool"`
3390+
// messages to have a plain string content. The OpenCode Go gateway
3391+
// passes list-type content through unchanged, so we must flatten it
3392+
// client-side for MiMo.
3393+
//
3394+
// For MiMo: emit a plain string — join text parts, and replace each
3395+
// image with a short placeholder note (the model cannot see tool
3396+
// images on MiMo upstream anyway, so we lose nothing and gain a
3397+
// working request). For other providers: keep the multimodal array
3398+
// (Kimi, GLM-5.1, MiniMax, Qwen all accept list-type tool content).
3399+
const isMimoModel = rawModelId !== undefined && /^mimo-/i.test(rawModelId);
3400+
if (isMimoModel) {
3401+
const flattened: string[] = [...toolTextParts];
3402+
for (let i = 0; i < toolImageParts.length; i++) {
3403+
flattened.push(
3404+
`[Tool returned an image attachment, but the MiMo upstream provider does not accept images in tool messages. Image ${i + 1} of ${toolImageParts.length} was dropped to keep the request valid.]`
3405+
);
3406+
}
3407+
toolContent = flattened.join("\n");
3408+
} else {
3409+
const multimodal: OpenAiContentPart[] = [];
3410+
const joinedText = toolTextParts.join("\n");
3411+
if (joinedText) {
3412+
multimodal.push({ type: "text", text: joinedText });
3413+
}
3414+
multimodal.push(...toolImageParts);
3415+
toolContent = multimodal;
33903416
}
3391-
multimodal.push(...toolImageParts);
3392-
toolContent = multimodal;
33933417
} else {
33943418
toolContent = toolTextParts.join("\n");
33953419
}

0 commit comments

Comments
 (0)