Skip to content

Commit 3d533b6

Browse files
rekram1-nodePhuc Le
authored andcommitted
fix(opencode): support MiniMax M3 thinking toggle (anomalyco#31426)
(cherry picked from commit 6e84142)
1 parent 1e91c72 commit 3d533b6

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
@@ -672,6 +672,15 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
672672
if (!model.capabilities.reasoning) return {}
673673

674674
const id = model.id.toLowerCase()
675+
if (
676+
model.api.id.toLowerCase().includes("minimax-m3") &&
677+
["@ai-sdk/anthropic", "@ai-sdk/openai-compatible"].includes(model.api.npm)
678+
) {
679+
return {
680+
none: { thinking: { type: "disabled" } },
681+
thinking: { thinking: { type: "adaptive" } },
682+
}
683+
}
675684
const adaptiveOpus = anthropicOpus47OrLater(model.api.id)
676685
const adaptiveEfforts = anthropicAdaptiveEfforts(model.api.id)
677686
if (
@@ -1112,8 +1121,13 @@ export function options(input: {
11121121
}
11131122
}
11141123

1115-
// Enable thinking by default for kimi models using anthropic SDK
11161124
const modelId = input.model.api.id.toLowerCase()
1125+
// MiniMax's Anthropic interface defaults thinking off, unlike Chat Completions.
1126+
if (modelId.includes("minimax-m3") && input.model.api.npm === "@ai-sdk/anthropic") {
1127+
result["thinking"] = { type: "adaptive" }
1128+
}
1129+
1130+
// Enable thinking by default for kimi models using anthropic SDK
11171131
if (
11181132
(input.model.api.npm === "@ai-sdk/anthropic" || input.model.api.npm === "@ai-sdk/google-vertex/anthropic") &&
11191133
(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
@@ -172,6 +172,39 @@ describe("ProviderTransform.options - zai/zhipuai thinking", () => {
172172
}
173173
})
174174

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

@@ -2444,6 +2477,39 @@ describe("ProviderTransform.variants", () => {
24442477
expect(result).toEqual({})
24452478
})
24462479

2480+
test("minimax m3 using anthropic returns thinking toggles", () => {
2481+
const model = createMockModel({
2482+
id: "minimax/minimax-m3",
2483+
providerID: "minimax",
2484+
api: {
2485+
id: "MiniMax-M3",
2486+
url: "https://api.minimax.com/anthropic/v1",
2487+
npm: "@ai-sdk/anthropic",
2488+
},
2489+
})
2490+
const result = ProviderTransform.variants(model)
2491+
expect(result).toEqual({
2492+
none: { thinking: { type: "disabled" } },
2493+
thinking: { thinking: { type: "adaptive" } },
2494+
})
2495+
})
2496+
2497+
test("minimax m3 using openai-compatible returns thinking toggles", () => {
2498+
const model = createMockModel({
2499+
id: "minimax/minimax-m3",
2500+
providerID: "minimax",
2501+
api: {
2502+
id: "minimax-m3",
2503+
url: "https://api.minimax.com/v1",
2504+
npm: "@ai-sdk/openai-compatible",
2505+
},
2506+
})
2507+
expect(ProviderTransform.variants(model)).toEqual({
2508+
none: { thinking: { type: "disabled" } },
2509+
thinking: { thinking: { type: "adaptive" } },
2510+
})
2511+
})
2512+
24472513
test("glm returns empty object", () => {
24482514
const model = createMockModel({
24492515
id: "glm/glm-4",

0 commit comments

Comments
 (0)