Skip to content

Commit 6e84142

Browse files
authored
fix(opencode): support MiniMax M3 thinking toggle (anomalyco#31426)
1 parent fc52c5a commit 6e84142

2 files changed

Lines changed: 81 additions & 1 deletion

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,15 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
641641
if (!model.capabilities.reasoning) return {}
642642

643643
const id = model.id.toLowerCase()
644+
if (
645+
model.api.id.toLowerCase().includes("minimax-m3") &&
646+
["@ai-sdk/anthropic", "@ai-sdk/openai-compatible"].includes(model.api.npm)
647+
) {
648+
return {
649+
none: { thinking: { type: "disabled" } },
650+
thinking: { thinking: { type: "adaptive" } },
651+
}
652+
}
644653
const adaptiveOpus = anthropicOpus47OrLater(model.api.id)
645654
const adaptiveEfforts = anthropicAdaptiveEfforts(model.api.id)
646655
if (
@@ -1076,8 +1085,13 @@ export function options(input: {
10761085
}
10771086
}
10781087

1079-
// Enable thinking by default for kimi models using anthropic SDK
10801088
const modelId = input.model.api.id.toLowerCase()
1089+
// MiniMax's Anthropic interface defaults thinking off, unlike Chat Completions.
1090+
if (modelId.includes("minimax-m3") && input.model.api.npm === "@ai-sdk/anthropic") {
1091+
result["thinking"] = { type: "adaptive" }
1092+
}
1093+
1094+
// Enable thinking by default for kimi models using anthropic SDK
10811095
if (
10821096
(input.model.api.npm === "@ai-sdk/anthropic" || input.model.api.npm === "@ai-sdk/google-vertex/anthropic") &&
10831097
(modelId.includes("k2p") || modelId.includes("kimi-k2.") || modelId.includes("kimi-k2p"))

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,39 @@ describe("ProviderTransform.options - zai/zhipuai thinking", () => {
175175
}
176176
})
177177

178+
describe("ProviderTransform.options - minimax m3 thinking", () => {
179+
const createModel = (npm: string) =>
180+
({
181+
id: "minimax/minimax-m3",
182+
providerID: "minimax",
183+
api: {
184+
id: "minimax-m3",
185+
url: "https://api.minimax.com",
186+
npm,
187+
},
188+
capabilities: { reasoning: true },
189+
limit: { output: 64_000 },
190+
}) as any
191+
192+
test("explicitly enables adaptive thinking with the anthropic SDK", () => {
193+
expect(
194+
ProviderTransform.options({
195+
model: createModel("@ai-sdk/anthropic"),
196+
sessionID: "test-session-123",
197+
}).thinking,
198+
).toEqual({ type: "adaptive" })
199+
})
200+
201+
test("uses the native default with the openai-compatible SDK", () => {
202+
expect(
203+
ProviderTransform.options({
204+
model: createModel("@ai-sdk/openai-compatible"),
205+
sessionID: "test-session-123",
206+
}).thinking,
207+
).toBeUndefined()
208+
})
209+
})
210+
178211
describe("ProviderTransform.options - google thinkingConfig gating", () => {
179212
const sessionID = "test-session-123"
180213

@@ -2452,6 +2485,39 @@ describe("ProviderTransform.variants", () => {
24522485
expect(result).toEqual({})
24532486
})
24542487

2488+
test("minimax m3 using anthropic returns thinking toggles", () => {
2489+
const model = createMockModel({
2490+
id: "minimax/minimax-m3",
2491+
providerID: "minimax",
2492+
api: {
2493+
id: "MiniMax-M3",
2494+
url: "https://api.minimax.com/anthropic/v1",
2495+
npm: "@ai-sdk/anthropic",
2496+
},
2497+
})
2498+
const result = ProviderTransform.variants(model)
2499+
expect(result).toEqual({
2500+
none: { thinking: { type: "disabled" } },
2501+
thinking: { thinking: { type: "adaptive" } },
2502+
})
2503+
})
2504+
2505+
test("minimax m3 using openai-compatible returns thinking toggles", () => {
2506+
const model = createMockModel({
2507+
id: "minimax/minimax-m3",
2508+
providerID: "minimax",
2509+
api: {
2510+
id: "minimax-m3",
2511+
url: "https://api.minimax.com/v1",
2512+
npm: "@ai-sdk/openai-compatible",
2513+
},
2514+
})
2515+
expect(ProviderTransform.variants(model)).toEqual({
2516+
none: { thinking: { type: "disabled" } },
2517+
thinking: { thinking: { type: "adaptive" } },
2518+
})
2519+
})
2520+
24552521
test("glm returns empty object", () => {
24562522
const model = createMockModel({
24572523
id: "glm/glm-4",

0 commit comments

Comments
 (0)