Skip to content

Commit e97a3d2

Browse files
committed
refactor(opencode): share Google thinking variants between native and SAP
- Extract googleThinkingVariants(model) from @ai-sdk/google[/-vertex] and reuse it in the SAP case. SAP now inherits Gemini 3.x thinkingLevel tiers via googleThinkingLevelEfforts, matching the forward-compat coverage already in place for GPT (openaiReasoningEfforts) and Anthropic (anthropicAdaptiveEfforts). - Drop sapGeminiReasoningParams and inline sapOpenaiReasoningParams per AGENTS.md single-use rule. - Fix @ai-sdk/gateway Google 2.5 max budget hardcoded to 24576 \u2014 now uses googleThinkingBudgetMax (32k for 2.5 Pro, 24k for Flash). - Brace SAP case if-bodies for consistency with the rest of the switch. - Add Gemini 3 SAP test (gemini-3.1-flash-lite) and missing result.high assertion on gemini-2.5-flash.
1 parent ebce9b1 commit e97a3d2

2 files changed

Lines changed: 44 additions & 46 deletions

File tree

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

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -666,19 +666,22 @@ function sapAnthropicReasoningParams(
666666
}
667667
}
668668

669-
function sapGeminiReasoningParams(model: Provider.Model): Record<string, Record<string, any>> {
670-
if (!model.api.id.includes("2.5")) return {}
671-
return {
672-
high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
673-
max: {
674-
thinkingConfig: { includeThoughts: true, thinkingBudget: googleThinkingBudgetMax(model.api.id) },
675-
},
669+
function googleThinkingVariants(model: Provider.Model): Record<string, Record<string, any>> {
670+
const id = model.api.id.toLowerCase()
671+
if (id.includes("2.5")) {
672+
return {
673+
high: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
674+
max: {
675+
thinkingConfig: { includeThoughts: true, thinkingBudget: googleThinkingBudgetMax(model.api.id) },
676+
},
677+
}
676678
}
677-
}
678-
679-
function sapOpenaiReasoningParams(model: Provider.Model): Record<string, Record<string, any>> {
680-
const efforts = openaiReasoningEfforts(model.api.id, model.release_date)
681-
return Object.fromEntries(efforts.map((effort) => [effort, { reasoning_effort: effort }]))
679+
return Object.fromEntries(
680+
googleThinkingLevelEfforts(model.api.id).map((effort) => [
681+
effort,
682+
{ thinkingConfig: { includeThoughts: true, thinkingLevel: effort } },
683+
]),
684+
)
682685
}
683686

684687
export function variants(model: Provider.Model): Record<string, Record<string, any>> {
@@ -786,7 +789,7 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
786789
max: {
787790
thinkingConfig: {
788791
includeThoughts: true,
789-
thinkingBudget: 24576,
792+
thinkingBudget: googleThinkingBudgetMax(model.api.id),
790793
},
791794
},
792795
}
@@ -976,34 +979,7 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
976979
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex
977980
case "@ai-sdk/google":
978981
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai
979-
if (id.includes("2.5")) {
980-
return {
981-
high: {
982-
thinkingConfig: {
983-
includeThoughts: true,
984-
thinkingBudget: 16000,
985-
},
986-
},
987-
max: {
988-
thinkingConfig: {
989-
includeThoughts: true,
990-
thinkingBudget: googleThinkingBudgetMax(id),
991-
},
992-
},
993-
}
994-
}
995-
996-
return Object.fromEntries(
997-
googleThinkingLevelEfforts(id).map((effort) => [
998-
effort,
999-
{
1000-
thinkingConfig: {
1001-
includeThoughts: true,
1002-
thinkingLevel: effort,
1003-
},
1004-
},
1005-
]),
1006-
)
982+
return googleThinkingVariants(model)
1007983

1008984
case "@ai-sdk/mistral":
1009985
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/mistral
@@ -1042,13 +1018,21 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
10421018
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/perplexity
10431019
return {}
10441020

1045-
case "@jerome-benoit/sap-ai-provider-v2":
1046-
if (model.api.id.includes("anthropic"))
1021+
case "@jerome-benoit/sap-ai-provider-v2": {
1022+
if (model.api.id.includes("anthropic")) {
10471023
return wrapInSapModelParams(sapAnthropicReasoningParams(adaptiveEfforts, adaptiveOpus))
1048-
if (model.api.id.includes("gemini")) return wrapInSapModelParams(sapGeminiReasoningParams(model))
1049-
if (model.api.id.includes("gpt") || /\bo[1-9]/.test(model.api.id))
1050-
return wrapInSapModelParams(sapOpenaiReasoningParams(model))
1024+
}
1025+
if (model.api.id.includes("gemini")) {
1026+
return wrapInSapModelParams(googleThinkingVariants(model))
1027+
}
1028+
if (model.api.id.includes("gpt") || /\bo[1-9]/.test(model.api.id)) {
1029+
const efforts = openaiReasoningEfforts(model.api.id, model.release_date)
1030+
return wrapInSapModelParams(
1031+
Object.fromEntries(efforts.map((effort) => [effort, { reasoning_effort: effort }])),
1032+
)
1033+
}
10511034
return {}
1035+
}
10521036
}
10531037
return {}
10541038
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,11 +3660,25 @@ describe("ProviderTransform.variants", () => {
36603660
test("gemini 2.5 flash returns thinkingConfig with 24k budget under modelParams", () => {
36613661
const result = ProviderTransform.variants(sapModel("gemini-2.5-flash"))
36623662
expect(Object.keys(result)).toEqual(["high", "max"])
3663+
expect(result.high).toEqual({
3664+
modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: 16000 } },
3665+
})
36633666
expect(result.max).toEqual({
36643667
modelParams: { thinkingConfig: { includeThoughts: true, thinkingBudget: 24576 } },
36653668
})
36663669
})
36673670

3671+
test("gemini 3 flash-lite picks up thinkingLevel tiers from googleThinkingLevelEfforts", () => {
3672+
const result = ProviderTransform.variants(sapModel("gemini-3.1-flash-lite"))
3673+
expect(Object.keys(result)).toEqual(["minimal", "low", "medium", "high"])
3674+
expect(result.minimal).toEqual({
3675+
modelParams: { thinkingConfig: { includeThoughts: true, thinkingLevel: "minimal" } },
3676+
})
3677+
expect(result.high).toEqual({
3678+
modelParams: { thinkingConfig: { includeThoughts: true, thinkingLevel: "high" } },
3679+
})
3680+
})
3681+
36683682
for (const apiId of ["gpt-5", "gpt-5-mini", "gpt-5-nano"]) {
36693683
test(`${apiId} returns reasoning_effort variants under modelParams with minimal tier`, () => {
36703684
const result = ProviderTransform.variants(sapModel(apiId, "2025-08-07"))

0 commit comments

Comments
 (0)