Skip to content

Commit 68abdce

Browse files
fix(opencode): let config opt out of Anthropic thinking blockBinding (anomalyco#46820)
Co-authored-by: Aiden Cline <[email protected]>
1 parent ef27925 commit 68abdce

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,17 +706,29 @@ function anthropicBindsThinking(apiId: string) {
706706
const ANTHROPIC_BLOCK_BINDING = { prefixMismatchBehavior: "drop_block" }
707707

708708
function anthropicBlockBinding(model: Provider.Model, options: { [x: string]: any }) {
709+
const sdk = sdkKey(model.api.npm)
710+
const key = sdk === "bedrock" ? "reasoningConfig" : sdk === "anthropic" ? "thinking" : undefined
711+
// Consume the OpenCode-only opt-out even on models outside the default scope.
712+
if (key && options[key]?.blockBinding === false) {
713+
const result = { ...options, [key]: { ...options[key] } }
714+
delete result[key].blockBinding
715+
if (Object.keys(result[key]).length === 0) delete result[key]
716+
return result
717+
}
718+
709719
if (!anthropicBindsThinking(model.api.id)) return options
710720
switch (model.api.npm) {
711721
case "@ai-sdk/anthropic":
712722
case "@ai-sdk/google-vertex/anthropic": {
713723
const thinking = options.thinking ?? { type: "adaptive" }
714724
if (thinking.type !== "adaptive" && thinking.type !== "enabled") return options
725+
if (thinking.blockBinding !== undefined) return options
715726
return { ...options, thinking: { ...thinking, blockBinding: ANTHROPIC_BLOCK_BINDING } }
716727
}
717728
case "@ai-sdk/amazon-bedrock": {
718729
const reasoningConfig = options.reasoningConfig ?? { type: "adaptive" }
719730
if (reasoningConfig.type !== "adaptive" && reasoningConfig.type !== "enabled") return options
731+
if (reasoningConfig.blockBinding !== undefined) return options
720732
return { ...options, reasoningConfig: { ...reasoningConfig, blockBinding: ANTHROPIC_BLOCK_BINDING } }
721733
}
722734
}

‎packages/opencode/test/provider/transform.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,21 @@ describe("ProviderTransform.providerOptions", () => {
938938
).toEqual({ [sdk.key]: { [sdk.option]: { type: "enabled", budgetTokens: 4000 } } })
939939
})
940940

941+
test.each(["claude-fable-5-1", "claude-opus-5"])("honors explicit binding controls for %s", (id) => {
942+
const model = claude(sdk.npm, id)
943+
const options = Object.freeze({
944+
[sdk.option]: Object.freeze({ type: "adaptive", blockBinding: false }),
945+
})
946+
expect(ProviderTransform.providerOptions(model, options)).toEqual({
947+
[sdk.key]: { [sdk.option]: { type: "adaptive" } },
948+
})
949+
expect(ProviderTransform.providerOptions(model, { [sdk.option]: { blockBinding: false } })).toEqual({
950+
[sdk.key]: {},
951+
})
952+
const custom = { [sdk.option]: { type: "adaptive", blockBinding: { prefixMismatchBehavior: "error" } } }
953+
expect(ProviderTransform.providerOptions(model, custom)).toEqual({ [sdk.key]: custom })
954+
})
955+
941956
test.each([
942957
["claude-opus-5", "default"],
943958
["claude-opus-5", "high"],

0 commit comments

Comments
 (0)