fix(opencode): support sap-ai-core anthropic opus 4.7+ adaptive reasoning (#29991)

This commit is contained in:
Jérôme Benoit
2026-05-31 01:30:21 +02:00
committed by GitHub
parent 30f9780561
commit f4f508e659
2 changed files with 82 additions and 124 deletions

View File

@@ -597,10 +597,12 @@ function openaiCompatibleReasoningEfforts(id: string) {
}
function anthropicOpus47OrLater(apiId: string) {
const version = /opus-(\d+)[.-](\d+)(?:[.@-]|$)/i.exec(apiId)
// Matches "opus-4.7" (Anthropic/Bedrock/Vertex) and "claude-4.7-opus" (SAP AI Core inverted).
// Greedy \d+ correctly extends to multi-digit majors (e.g. "claude-10.0-opus") for forward compatibility.
const version = /opus-(\d+)[.-](\d+)(?:[.@-]|$)|claude-(\d+)[.-](\d+)-opus(?:[.@-]|$)/i.exec(apiId)
if (!version) return false
const major = Number(version[1])
const minor = Number(version[2])
const major = Number(version[1] ?? version[3])
const minor = Number(version[2] ?? version[4])
return major > 4 || (major === 4 && minor >= 7)
}
@@ -608,7 +610,18 @@ function anthropicAdaptiveEfforts(apiId: string): string[] | null {
if (anthropicOpus47OrLater(apiId)) {
return ["low", "medium", "high", "xhigh", "max"]
}
if (["opus-4-6", "opus-4.6", "sonnet-4-6", "sonnet-4.6"].some((v) => apiId.includes(v))) {
if (
[
"opus-4-6",
"opus-4.6",
"4-6-opus",
"4.6-opus",
"sonnet-4-6",
"sonnet-4.6",
"4-6-sonnet",
"4.6-sonnet",
].some((v) => apiId.includes(v))
) {
return ["low", "medium", "high", "max"]
}
return null
@@ -999,6 +1012,7 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
{
thinking: {
type: "adaptive",
...(adaptiveOpus ? { display: "summarized" } : {}),
},
effort,
},