Skip to content

Commit 193013a

Browse files
xfdwcympxu-bittctevrekram1-node
authored
feat(opencode): support adaptive thinking for claude sonnet 4.6 (#14283)
Co-authored-by: tctev <224793535+tctev@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
1 parent 824ab4c commit 193013a

2 files changed

Lines changed: 119 additions & 6 deletions

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ export namespace ProviderTransform {
333333
if (!model.capabilities.reasoning) return {}
334334

335335
const id = model.id.toLowerCase()
336+
const isAnthropicAdaptive = ["opus-4-6", "opus-4.6", "sonnet-4-6", "sonnet-4.6"].some((v) => model.api.id.includes(v))
337+
const adaptiveEfforts = ["low", "medium", "high", "max"]
336338
if (
337339
id.includes("deepseek") ||
338340
id.includes("minimax") ||
@@ -366,6 +368,19 @@ export namespace ProviderTransform {
366368

367369
case "@ai-sdk/gateway":
368370
if (model.id.includes("anthropic")) {
371+
if (isAnthropicAdaptive) {
372+
return Object.fromEntries(
373+
adaptiveEfforts.map((effort) => [
374+
effort,
375+
{
376+
thinking: {
377+
type: "adaptive",
378+
},
379+
effort,
380+
},
381+
]),
382+
)
383+
}
369384
return {
370385
high: {
371386
thinking: {
@@ -502,10 +517,9 @@ export namespace ProviderTransform {
502517
case "@ai-sdk/google-vertex/anthropic":
503518
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex#anthropic-provider
504519

505-
if (model.api.id.includes("opus-4-6") || model.api.id.includes("opus-4.6")) {
506-
const efforts = ["low", "medium", "high", "max"]
520+
if (isAnthropicAdaptive) {
507521
return Object.fromEntries(
508-
efforts.map((effort) => [
522+
adaptiveEfforts.map((effort) => [
509523
effort,
510524
{
511525
thinking: {
@@ -534,10 +548,9 @@ export namespace ProviderTransform {
534548

535549
case "@ai-sdk/amazon-bedrock":
536550
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock
537-
if (model.api.id.includes("opus-4-6") || model.api.id.includes("opus-4.6")) {
538-
const efforts = ["low", "medium", "high", "max"]
551+
if (isAnthropicAdaptive) {
539552
return Object.fromEntries(
540-
efforts.map((effort) => [
553+
adaptiveEfforts.map((effort) => [
541554
effort,
542555
{
543556
reasoningConfig: {

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,66 @@ describe("ProviderTransform.variants", () => {
17051705
})
17061706

17071707
describe("@ai-sdk/gateway", () => {
1708+
test("anthropic sonnet 4.6 models return adaptive thinking options", () => {
1709+
const model = createMockModel({
1710+
id: "anthropic/claude-sonnet-4-6",
1711+
providerID: "gateway",
1712+
api: {
1713+
id: "anthropic/claude-sonnet-4-6",
1714+
url: "https://gateway.ai",
1715+
npm: "@ai-sdk/gateway",
1716+
},
1717+
})
1718+
const result = ProviderTransform.variants(model)
1719+
expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
1720+
expect(result.medium).toEqual({
1721+
thinking: {
1722+
type: "adaptive",
1723+
},
1724+
effort: "medium",
1725+
})
1726+
})
1727+
1728+
test("anthropic sonnet 4.6 dot-format models return adaptive thinking options", () => {
1729+
const model = createMockModel({
1730+
id: "anthropic/claude-sonnet-4-6",
1731+
providerID: "gateway",
1732+
api: {
1733+
id: "anthropic/claude-sonnet-4.6",
1734+
url: "https://gateway.ai",
1735+
npm: "@ai-sdk/gateway",
1736+
},
1737+
})
1738+
const result = ProviderTransform.variants(model)
1739+
expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
1740+
expect(result.medium).toEqual({
1741+
thinking: {
1742+
type: "adaptive",
1743+
},
1744+
effort: "medium",
1745+
})
1746+
})
1747+
1748+
test("anthropic opus 4.6 dot-format models return adaptive thinking options", () => {
1749+
const model = createMockModel({
1750+
id: "anthropic/claude-opus-4-6",
1751+
providerID: "gateway",
1752+
api: {
1753+
id: "anthropic/claude-opus-4.6",
1754+
url: "https://gateway.ai",
1755+
npm: "@ai-sdk/gateway",
1756+
},
1757+
})
1758+
const result = ProviderTransform.variants(model)
1759+
expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
1760+
expect(result.high).toEqual({
1761+
thinking: {
1762+
type: "adaptive",
1763+
},
1764+
effort: "high",
1765+
})
1766+
})
1767+
17081768
test("anthropic models return anthropic thinking options", () => {
17091769
const model = createMockModel({
17101770
id: "anthropic/claude-sonnet-4",
@@ -2064,6 +2124,26 @@ describe("ProviderTransform.variants", () => {
20642124
})
20652125

20662126
describe("@ai-sdk/anthropic", () => {
2127+
test("sonnet 4.6 returns adaptive thinking options", () => {
2128+
const model = createMockModel({
2129+
id: "anthropic/claude-sonnet-4-6",
2130+
providerID: "anthropic",
2131+
api: {
2132+
id: "claude-sonnet-4-6",
2133+
url: "https://api.anthropic.com",
2134+
npm: "@ai-sdk/anthropic",
2135+
},
2136+
})
2137+
const result = ProviderTransform.variants(model)
2138+
expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
2139+
expect(result.high).toEqual({
2140+
thinking: {
2141+
type: "adaptive",
2142+
},
2143+
effort: "high",
2144+
})
2145+
})
2146+
20672147
test("returns high and max with thinking config", () => {
20682148
const model = createMockModel({
20692149
id: "anthropic/claude-4",
@@ -2092,6 +2172,26 @@ describe("ProviderTransform.variants", () => {
20922172
})
20932173

20942174
describe("@ai-sdk/amazon-bedrock", () => {
2175+
test("anthropic sonnet 4.6 returns adaptive reasoning options", () => {
2176+
const model = createMockModel({
2177+
id: "bedrock/anthropic-claude-sonnet-4-6",
2178+
providerID: "bedrock",
2179+
api: {
2180+
id: "anthropic.claude-sonnet-4-6",
2181+
url: "https://bedrock.amazonaws.com",
2182+
npm: "@ai-sdk/amazon-bedrock",
2183+
},
2184+
})
2185+
const result = ProviderTransform.variants(model)
2186+
expect(Object.keys(result)).toEqual(["low", "medium", "high", "max"])
2187+
expect(result.max).toEqual({
2188+
reasoningConfig: {
2189+
type: "adaptive",
2190+
maxReasoningEffort: "max",
2191+
},
2192+
})
2193+
})
2194+
20952195
test("returns WIDELY_SUPPORTED_EFFORTS with reasoningConfig", () => {
20962196
const model = createMockModel({
20972197
id: "bedrock/llama-4",

0 commit comments

Comments
 (0)