Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion packages/opencode/src/provider/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> | undefined): Record<string, unknown> | undefined => {
if (!opts) return opts
let out = opts
for (const k of keys) {
const bucket = out[k] as Record<string, unknown> | 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<string, unknown> }
const cleaned = strip(p.providerOptions)
return cleaned !== p.providerOptions ? { ...part, providerOptions: cleaned } : part
}) as typeof content
}
const cleaned = strip(msg.providerOptions as Record<string, unknown> | 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 &&
Expand Down Expand Up @@ -679,7 +722,7 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
{
reasoningConfig: {
type: "adaptive",
maxReasoningEffort: effort,
maxReasoningEffort: effort === "xhigh" ? "max" : effort,
...(model.api.id.includes("opus-4-7") || model.api.id.includes("opus-4.7")
? { display: "summarized" }
: {}),
Expand Down
4 changes: 2 additions & 2 deletions packages/opencode/test/provider/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ describe("ProviderTransform.variants", () => {
})
})

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",
Expand All @@ -3019,7 +3019,7 @@ describe("ProviderTransform.variants", () => {
expect(result.xhigh).toEqual({
reasoningConfig: {
type: "adaptive",
maxReasoningEffort: "xhigh",
maxReasoningEffort: "max",
display: "summarized",
},
})
Expand Down
Loading