Skip to content

Commit 6d41b25

Browse files
committed
feat(opencode): add Mistral Small/Medium 3.5 + Claude Opus 4.7 reasoning variants
Cherry-picked from anomalyco/opencode origin/dev: - Replace boolean isAnthropicAdaptive with anthropicAdaptiveEfforts() that returns the per-model effort list. Adds opus-4-7/4.7 with the 5-tier ladder [low, medium, high, xhigh, max], keeping opus-4-6/sonnet-4-6 on the existing 4-tier ladder. Affects @ai-sdk/gateway, anthropic, google-vertex/anthropic, amazon-bedrock, sap-ai-provider-v2 cases (upstream 378c05f). - Drop mistral from the early-return blacklist in variants() and replace the empty @ai-sdk/mistral case with reasoning-effort variants for Mistral Small 4 (mistral-small-2603, mistral-small-latest) and Medium 3.5 (mistral-medium-3.5). Models without capabilities.reasoning still short-circuit (upstream 1a20703 + 639e27c). Verified: typecheck clean; transform.test.ts 119/122 (3 failing tests are pre-existing baseline failures unrelated to provider variants).
1 parent 7e4939e commit 6d41b25

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,25 @@ export namespace ProviderTransform {
412412
const WIDELY_SUPPORTED_EFFORTS = ["low", "medium", "high"]
413413
const OPENAI_EFFORTS = ["none", "minimal", ...WIDELY_SUPPORTED_EFFORTS, "xhigh"]
414414

415+
function anthropicAdaptiveEfforts(apiId: string): string[] | null {
416+
if (["opus-4-7", "opus-4.7"].some((v) => apiId.includes(v))) {
417+
return ["low", "medium", "high", "xhigh", "max"]
418+
}
419+
if (["opus-4-6", "opus-4.6", "sonnet-4-6", "sonnet-4.6"].some((v) => apiId.includes(v))) {
420+
return ["low", "medium", "high", "max"]
421+
}
422+
return null
423+
}
424+
415425
export function variants(model: Provider.Model): Record<string, Record<string, any>> {
416426
if (!model.capabilities.reasoning) return {}
417427

418428
const id = model.id.toLowerCase()
419-
const isAnthropicAdaptive = ["opus-4-6", "opus-4.6", "sonnet-4-6", "sonnet-4.6"].some((v) =>
420-
model.api.id.includes(v),
421-
)
422-
const adaptiveEfforts = ["low", "medium", "high", "max"]
429+
const adaptiveEfforts = anthropicAdaptiveEfforts(model.api.id)
423430
if (
424431
id.includes("deepseek") ||
425432
id.includes("minimax") ||
426433
id.includes("glm") ||
427-
id.includes("mistral") ||
428434
id.includes("kimi") ||
429435
// TODO: Remove this after models.dev data is fixed to use "kimi-k2.5" instead of "k2p5"
430436
id.includes("k2p5")
@@ -453,7 +459,7 @@ export namespace ProviderTransform {
453459

454460
case "@ai-sdk/gateway":
455461
if (model.id.includes("anthropic")) {
456-
if (isAnthropicAdaptive) {
462+
if (adaptiveEfforts) {
457463
return Object.fromEntries(
458464
adaptiveEfforts.map((effort) => [
459465
effort,
@@ -609,7 +615,7 @@ export namespace ProviderTransform {
609615
case "@ai-sdk/google-vertex/anthropic":
610616
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/google-vertex#anthropic-provider
611617

612-
if (isAnthropicAdaptive) {
618+
if (adaptiveEfforts) {
613619
return Object.fromEntries(
614620
adaptiveEfforts.map((effort) => [
615621
effort,
@@ -640,7 +646,7 @@ export namespace ProviderTransform {
640646

641647
case "@ai-sdk/amazon-bedrock":
642648
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock
643-
if (isAnthropicAdaptive) {
649+
if (adaptiveEfforts) {
644650
return Object.fromEntries(
645651
adaptiveEfforts.map((effort) => [
646652
effort,
@@ -723,7 +729,15 @@ export namespace ProviderTransform {
723729

724730
case "@ai-sdk/mistral":
725731
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/mistral
726-
return {}
732+
// https://docs.mistral.ai/capabilities/reasoning/adjustable
733+
if (!model.capabilities.reasoning) return {}
734+
// Only Mistral Small 4 and Medium 3.5 support reasoning
735+
const MISTRAL_REASONING_IDS = ["mistral-small-2603", "mistral-small-latest", "mistral-medium-3.5"]
736+
const mistralId = model.api.id.toLowerCase()
737+
if (!MISTRAL_REASONING_IDS.some((rid) => mistralId.includes(rid))) return {}
738+
return {
739+
high: { reasoningEffort: "high" },
740+
}
727741

728742
case "@ai-sdk/cohere":
729743
// https://v5.ai-sdk.dev/providers/ai-sdk-providers/cohere
@@ -747,7 +761,7 @@ export namespace ProviderTransform {
747761

748762
case "@jerome-benoit/sap-ai-provider-v2":
749763
if (model.api.id.includes("anthropic")) {
750-
if (isAnthropicAdaptive) {
764+
if (adaptiveEfforts) {
751765
return Object.fromEntries(
752766
adaptiveEfforts.map((effort) => [
753767
effort,

0 commit comments

Comments
 (0)