Files
plugins/packages/minimax/models.test.mjs
T
Klarkxy 97fdba8ca6 minimax 0.2.8: native Magpie image, video and web search (#1008)
MiniMax Code accounts now serve magpie's image, video and web search natively: /v1/images/generations and /v1/images/edits through generate_image, video through submit_video_generation, and search through the connector's web tools.

- Edits: magpie's multipart body (model, prompt, n, size, quality, image / image[] parts) is parsed, and each image goes through the live catalog's upload_temp_url signed-form flow. A mask part is refused with a 400 (generate_image takes no mask). A video frame sent as data: is uploaded the same way, and https refs pass through.
- A 401 is renewed per tool call, and only that call is sent again, so a 401 on get_asset_url never runs a paid generate_image twice.
- Upload hosts are https only. A video download drops content-encoding and content-length (fetch already decoded it).
- Envelope refusals carry a status: 1002, 1039, 1041, 1045, 2045, 2056 and 2062 are 429; 1008 and 2053 are 402 (MiniMax's published error codes, not confirmed for the MiniMax Code agent API).
- 0.2.8, since 0.2.7 (#1014) is on npm. native.mjs is in files.

What was run at c020d32e51f9b28e29528ea59d38bc167baf8624 (temp HOME, fake fetch only, no real MiniMax calls):
- mote (macOS): bun test packages/minimax, 193 pass, 0 fail. bun scripts/check.mjs exit 0.
- WSL Ubuntu 24.04: 193 pass, 0 fail.
- Broken by hand, one at a time, each turned a test red: no per-call 401 renewal (2), mask accepted (1), http upload host accepted (1), no envelope status (2), content-encoding kept (1). Earlier rounds broke multipart parsing, the status in toolHttpError and mediaRef's schemes, each red too.
- Merges cleanly onto main 234e073c.

Not tried: the real upload_temp_url answer, the /visible/ wait (8s) against MiniMax, and a real magpie drawing through a MiniMax account.
2026-11-12 08:47:15 +08:00

126 lines
7.0 KiB
JavaScript

// The model list: MiniMax Code's live config when it answers, MiniMax
// Code's built-in four when it doesn't.
import "./nonet.mjs"
import { afterEach, expect, test } from "bun:test"
import { MiniMaxCodeAuthPlugin, _internal } from "./index.mjs"
import { fakeMiniMax, json } from "./fake.mjs"
let f
afterEach(() => f?.close())
const auth = { type: "oauth", access: "tok", refresh: "r", expires: Date.now() + 3600_000 }
async function given(hooks) {
const cfg = { provider: {} }
await hooks.config(cfg)
// as the host hands provider.models what the config declared
const p = cfg.provider["minimax-code"]
return { id: "minimax-code", models: Object.fromEntries(Object.entries(p.models).map(([id, m]) => [id, { id, ...m }])) }
}
test("the config declares MiniMax Code's chat models on the Anthropic API, plus image and video models", async () => {
const hooks = await MiniMaxCodeAuthPlugin({ client: {} })
const cfg = { provider: {} }
await hooks.config(cfg)
const p = cfg.provider["minimax-code"]
expect(p.npm).toBe("@ai-sdk/anthropic")
expect(p.api).toBe(_internal.SITES["minimax-code"].llm + "/mavis/api/v1/llm/v1")
const chat = ["MiniMax-M2.7", "MiniMax-M2.7-highspeed", "MiniMax-M3", "MiniMax-M3.1-Flash-Preview"]
const media = ["MiniMax-H3", "MiniMax-H3-Max", "MiniMax-Hailuo-2.3", "MiniMax-Image"]
expect(Object.keys(p.models).sort()).toEqual([...chat, ...media].sort())
expect(p.models["MiniMax-Image"].modalities).toEqual({ input: ["text", "image"], output: ["image"] })
expect(p.models["MiniMax-Image"].provider).toEqual({ npm: "@ai-sdk/openai-compatible" })
expect(p.models["MiniMax-H3"].modalities.output).toEqual(["video"])
expect(p.models["MiniMax-M3"].modalities.output).toEqual(["text"])
expect(p.models["MiniMax-M3"].variants).toEqual({ none: { thinking: { type: "disabled" } }, high: { thinking: { type: "adaptive" } } })
expect(Object.keys(p.models["MiniMax-M3.1-Flash-Preview"].variants)).toEqual(["low", "medium", "high", "xhigh", "max"])
expect(p.models["MiniMax-M3.1-Flash-Preview"].variants.xhigh).toEqual({ thinking: { type: "adaptive" }, effort: "xhigh" })
expect(p.models["MiniMax-M3"].modalities.input).toEqual(["text", "image"])
expect(p.models["MiniMax-M2.7"].modalities.input).toEqual(["text"])
expect(p.models["MiniMax-M3"].limit).toEqual({ context: 1048576, output: 524288 })
expect(p.models["MiniMax-M3.1-Flash-Preview"].limit).toEqual({ context: 1048576, output: 524288 })
expect(p.models["MiniMax-M2.7"].limit).toEqual({ context: 200000, output: 128000 })
})
test("a model whose advertised limits are under the real ones gets the real ones", async () => {
f = fakeMiniMax()
f.route("GET /mavis/api/v1/models", () => json({
version: "7", ttlSeconds: 300,
providers: [
{ providerId: "minimax", config: {
model_order: ["MiniMax-M3.1-Flash", "MiniMax-M2.7"],
models: {
// what MiniMax Code's own list says today
"MiniMax-M3.1-Flash": { name: "M3.1-Flash", limit: { context: 512000, output: 128000 }, modalities: { input: ["text", "image"] }, reasoning: true, thinking_config: { mode: "forced_on" } },
"MiniMax-M2.7": { name: "MiniMax-M2.7", limit: { context: 200000, output: 128000 }, modalities: { input: ["text"] }, reasoning: true },
},
} },
],
}))
const hooks = await MiniMaxCodeAuthPlugin({ client: {} })
const ms = await hooks.provider.models(await given(hooks), { auth })
// the endpoint allows 1,048,576 input and 524,288 output tokens for it
expect(ms["MiniMax-M3.1-Flash"].limit).toEqual({ context: 1048576, output: 524288 })
// a model with no verified limits keeps the ones the list gave
expect(ms["MiniMax-M2.7"].limit).toEqual({ context: 200000, output: 128000 })
})
test("the live list is MiniMax Code's model config", async () => {
f = fakeMiniMax()
f.route("GET /mavis/api/v1/models", () => json({
version: "7", ttlSeconds: 300,
providers: [
{ providerId: "other", config: { models: { x: {} } } },
{ providerId: "minimax", config: {
model_order: ["MiniMax-M4", "MiniMax-M3"],
models: {
"MiniMax-M3": { name: "MiniMax-M3", limit: { context: 512000, output: 128000 }, modalities: { input: ["text", "image", "video"] }, reasoning: true, thinking_config: { mode: "switchable", default_value: "true" } },
"MiniMax-M4": { name: "M4", limit: { context: 1000000, output: 128000 }, modalities: { input: ["text"] }, reasoning: true, thinking_config: { mode: "forced_on" }, thinking: { effortOptions: ["default", "low", "high"], defaultEffort: "default" } },
"MiniMax-M2.7": { name: "MiniMax-M2.7", limit: { context: 200000, output: 128000 }, modalities: { input: ["text"] }, reasoning: true },
},
} },
],
}))
const hooks = await MiniMaxCodeAuthPlugin({ client: {} })
const p = await given(hooks)
const ms = await hooks.provider.models(p, { auth })
expect(Object.keys(ms)).toEqual(["MiniMax-M4", "MiniMax-M3", "MiniMax-M2.7", "MiniMax-Image", "MiniMax-H3", "MiniMax-H3-Max", "MiniMax-Hailuo-2.3"])
expect(ms["MiniMax-M4"]).toMatchObject({ id: "MiniMax-M4", providerID: "minimax-code", name: "M4", api: { id: "MiniMax-M4", npm: "@ai-sdk/anthropic" }, limit: { context: 1000000, output: 128000 } })
expect(ms["MiniMax-M4"].variants).toEqual({ low: { thinking: { type: "adaptive" }, effort: "low" }, high: { thinking: { type: "adaptive" }, effort: "high" } })
expect(ms["MiniMax-M3"].capabilities.input.image).toBe(true)
expect(ms["MiniMax-M3"].variants.none).toEqual({ thinking: { type: "disabled" } })
expect(ms["MiniMax-M2.7"].variants).toEqual({})
const r = f.seen[0]
expect(r.query.get("region")).toBe("cn")
expect(r.query.get("buildEnv")).toBe("prod")
expect(r.headers.get("authorization")).toBe("Bearer tok")
})
test("a list refused with the account is asked again without it", async () => {
f = fakeMiniMax()
f.route("GET /mavis/api/v1/models", (r) => (r.headers.get("authorization")
? json({}, 401)
: json({ providers: [{ providerId: "minimax", config: { models: { "MiniMax-M3": { name: "MiniMax-M3" } } } }] })))
const hooks = await MiniMaxCodeAuthPlugin({ client: {} })
const ms = await hooks.provider.models(await given(hooks), { auth })
expect(Object.keys(ms)).toEqual(["MiniMax-M3", "MiniMax-Image", "MiniMax-H3", "MiniMax-H3-Max", "MiniMax-Hailuo-2.3"])
expect(f.seen.length).toBe(2)
})
test("when the list can't be had, the built-in one is given back as it came", async () => {
for (const reply of [() => json({ error: "down" }, 500), () => new Response("not json"), () => json({ providers: [] })]) {
f = fakeMiniMax()
f.route("GET /mavis/api/v1/models", reply)
const hooks = await MiniMaxCodeAuthPlugin({ client: {} })
const p = await given(hooks)
// the very object it was given, which magpie reads as a fallback
expect(await hooks.provider.models(p, { auth })).toBe(p.models)
f.close()
f = null
}
// signed out: not asked at all
const hooks = await MiniMaxCodeAuthPlugin({ client: {} })
const p = await given(hooks)
expect(await hooks.provider.models(p, { auth: undefined })).toBe(p.models)
})