diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.ts index 2fa7649c75f9..c612728f4284 100644 --- a/packages/opencode/src/provider/transform.ts +++ b/packages/opencode/src/provider/transform.ts @@ -214,6 +214,49 @@ function normalizeMessages( }) } + if ( + model.api.npm === "@ai-sdk/amazon-bedrock" && + !model.api.id.includes("anthropic") && + !model.api.id.includes("mistral") + ) { + const keys = ["bedrock", model.providerID] + const strip = (opts: Record | undefined): Record | undefined => { + if (!opts) return opts + let out = opts + for (const k of keys) { + const bucket = out[k] as Record | undefined + if (bucket?.cachePoint) { + const { cachePoint: _, ...rest } = bucket + out = { ...out, [k]: Object.keys(rest).length > 0 ? rest : undefined } + } + } + return out + } + return msgs.map((msg) => { + let content = msg.content + if (msg.role === "assistant" && Array.isArray(content)) { + content = content.filter( + (part) => + (part as { type: string }).type !== "reasoning" && + (part as { type: string }).type !== "redacted-reasoning", + ) as typeof content + if (content.length === 0) + content = [{ type: "text" as const, text: "..." }] as typeof content + } + if (Array.isArray(content)) { + content = content.map((part) => { + const p = part as { providerOptions?: Record } + const cleaned = strip(p.providerOptions) + return cleaned !== p.providerOptions ? { ...part, providerOptions: cleaned } : part + }) as typeof content + } + const cleaned = strip(msg.providerOptions as Record | undefined) + if (content !== msg.content || cleaned !== msg.providerOptions) + return { ...msg, content, providerOptions: cleaned } as typeof msg + return msg + }) + } + if ( typeof model.capabilities.interleaved === "object" && model.capabilities.interleaved.field && @@ -679,7 +722,7 @@ export function variants(model: Provider.Model): Record { }) }) - test("anthropic opus 4.7 returns adaptive reasoning options with xhigh", () => { + test("anthropic opus 4.7 returns adaptive reasoning options with xhigh mapped to max", () => { const model = createMockModel({ id: "bedrock/anthropic-claude-opus-4-7", providerID: "bedrock", @@ -3019,7 +3019,7 @@ describe("ProviderTransform.variants", () => { expect(result.xhigh).toEqual({ reasoningConfig: { type: "adaptive", - maxReasoningEffort: "xhigh", + maxReasoningEffort: "max", display: "summarized", }, })