From 521ac53ff8372a1a9349ee9cb58a93595c84bc71 Mon Sep 17 00:00:00 2001 From: Spencer Hong <11135652+spencer-hong@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:17:54 -0400 Subject: [PATCH] Revert "fix: filter empty assistant messages for all providers" --- packages/opencode/src/provider/transform.ts | 38 ++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index c784c4f8e3ca..f651a5b91aaf 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -51,27 +51,27 @@ export namespace ProviderTransform { model: Provider.Model, options: Record, ): ModelMessage[] { - // Filter out messages with empty content - many providers (Anthropic, Bedrock, - // Moonshot/Kimi, OpenAI-compatible) reject empty assistant messages. - // Apply unconditionally since no provider accepts truly empty messages. - // See: https://github.com/anomalyco/opencode/issues/6056 - msgs = msgs - .map((msg) => { - if (typeof msg.content === "string") { - if (msg.content === "") return undefined - return msg - } - if (!Array.isArray(msg.content)) return msg - const filtered = msg.content.filter((part) => { - if (part.type === "text" || part.type === "reasoning") { - return part.text !== "" + // Anthropic rejects messages with empty content - filter out empty string messages + // and remove empty text/reasoning parts from array content + if (model.api.npm === "@ai-sdk/anthropic" || model.api.npm === "@ai-sdk/amazon-bedrock") { + msgs = msgs + .map((msg) => { + if (typeof msg.content === "string") { + if (msg.content === "") return undefined + return msg } - return true + if (!Array.isArray(msg.content)) return msg + const filtered = msg.content.filter((part) => { + if (part.type === "text" || part.type === "reasoning") { + return part.text !== "" + } + return true + }) + if (filtered.length === 0) return undefined + return { ...msg, content: filtered } }) - if (filtered.length === 0) return undefined - return { ...msg, content: filtered } - }) - .filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "") + .filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "") + } if (model.api.id.includes("claude")) { const scrub = (id: string) => id.replace(/[^a-zA-Z0-9_-]/g, "_")