Files
plugins/packages/minimax/modalities.test.mjs
T
yetone 80c9b495fc minimax 0.2.6: a model takes the video its config says, in magpie (#985)
configModels() and modelOf() said image or nothing: video, audio and pdf
were hard-coded false, so MiniMax-M3.1-Flash and M3 (whose model config
says modalities.input ["text","image","video"], attachment true) showed
as text and image only in magpie's /v1/models, on both sites.

Now parseModels keeps the config's modalities.input (text, image, audio,
video, pdf; unknown kinds dropped) and attachment, and the built-in list
says video for M3.1-Flash-Preview and M3. Where the plugin runs decides
what is advertised:
- magpie's host (the plugin input has `magpie`): every kind said. magpie's
  gateway writes the Anthropic body and the loader's fetch sends it to
  MiniMax byte for byte; the new test sends the issue's video block and
  checks the upstream got the same body.
- OpenCode: @ai-sdk/anthropic builds the body and throws on a file part
  that isn't an image, a PDF or text ("media type: video/mp4",
  dist/index.js in 4.0.102), so video and audio stay out there and
  OpenCode keeps saying the model can't read them. pdf is passed on.

Still dropping video before it reaches this plugin: magpie's gateway
(parseAnthropicRequest has no video block, and groups don't merge
Inputs): yetone/magpie#6135, the reporter's own issue.

Run at the pushed head, rebased on 4a78bec3 (wsl-run, magpie-desktop,
Bun 1.4.2, temp HOME):
- bun test packages/minimax: 159 pass, 0 fail
- bun scripts/check.mjs: exit 0
- modalities.test.mjs is new; its fixture is the issue's literal model
  config ({"modalities":{"input":["text","image","video"],"output":
  ["text"]},"attachment":true}) for minimax-code (MiniMax-M3.1-Flash)
  and minimax-code-global (MiniMax-M3.1-Flash-Preview).

Broken by hand:
- video kept false again in inputsOf: 5 of 8 modalities tests red
  (both sites' live and built-in lists, the every-kind test)
- video advertised in OpenCode too: 4 red (both sites' OpenCode tests,
  the every-kind test, models.test's config test)

Not tried: a real MiniMax account or a real video through magpie (the
gateway drops it until #6135); OpenCode itself with a video attachment
(read from @ai-sdk/anthropic's source, not run).

Reported-by: LingYingNX
2026-11-11 18:10:50 +08:00

117 lines
5.7 KiB
JavaScript

// What a model takes is what MiniMax Code's model config says (#985,
// LingYingNX): the platform's modalities.input, video included, not image
// alone. In magpie the gateway writes the Anthropic body and the plugin
// sends it on as it is, so a video block reaches MiniMax; in OpenCode,
// @ai-sdk/anthropic throws on a video file part, so there video is left
// out and OpenCode says the model can't read it.
import "./nonet.mjs"
import { afterEach, expect, test } from "bun:test"
import { MiniMaxCodeAuthPlugin, MiniMaxCodeGlobalAuthPlugin } 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 }
const magpie = { option: () => undefined, options: () => ({}) }
// the reporter's, from GET /mavis/api/v1/models?region=cn&buildEnv=prod
const flash = { "modalities": { "input": ["text", "image", "video"], "output": ["text"] }, "attachment": true }
const plugins = [
["minimax-code", MiniMaxCodeAuthPlugin, "MiniMax-M3.1-Flash"],
["minimax-code-global", MiniMaxCodeGlobalAuthPlugin, "MiniMax-M3.1-Flash-Preview"],
]
function list(id) {
return json({
providers: [{ providerId: "minimax", config: {
model_order: [id, "MiniMax-M3", "MiniMax-M2.7"],
models: {
[id]: { name: id, ...flash },
"MiniMax-M3": { name: "MiniMax-M3", modalities: { input: ["text", "image", "video"], output: ["text"] }, attachment: true },
"MiniMax-M2.7": { name: "MiniMax-M2.7", modalities: { input: ["text"] } },
},
} }],
})
}
async function given(hooks, id) {
const cfg = { provider: {} }
await hooks.config(cfg)
const p = cfg.provider[id]
return { cfg: p, provider: { id, models: Object.fromEntries(Object.entries(p.models).map(([k, m]) => [k, { id: k, ...m }])) } }
}
for (const [id, Plugin, model] of plugins) {
test(`${id}: in magpie, the live list's video reaches the model (#985)`, async () => {
f = fakeMiniMax()
f.route("GET /mavis/api/v1/models", () => list(model))
const hooks = await Plugin({ client: {}, magpie })
const { provider } = await given(hooks, id)
const ms = await hooks.provider.models(provider, { auth })
expect(ms[model].capabilities.input).toEqual({ text: true, image: true, audio: false, video: true, pdf: false })
expect(ms[model].capabilities.attachment).toBe(true)
expect(ms["MiniMax-M3"].capabilities.input.video).toBe(true)
expect(ms["MiniMax-M2.7"].capabilities.input).toEqual({ text: true, image: false, audio: false, video: false, pdf: false })
expect(ms["MiniMax-M2.7"].capabilities.attachment).toBe(false)
})
test(`${id}: in magpie, the built-in list says video too`, async () => {
const hooks = await Plugin({ client: {}, magpie })
const { cfg } = await given(hooks, id)
expect(cfg.models["MiniMax-M3.1-Flash-Preview"].modalities.input).toEqual(["text", "image", "video"])
expect(cfg.models["MiniMax-M3"].modalities.input).toEqual(["text", "image", "video"])
expect(cfg.models["MiniMax-M2.7"].modalities.input).toEqual(["text"])
expect(cfg.models["MiniMax-M2.7"].attachment).toBe(false)
})
test(`${id}: in OpenCode, whose Anthropic SDK can't send video, it is left out`, async () => {
f = fakeMiniMax()
f.route("GET /mavis/api/v1/models", () => list(model))
const hooks = await Plugin({ client: {} })
const { cfg, provider } = await given(hooks, id)
expect(cfg.models["MiniMax-M3"].modalities.input).toEqual(["text", "image"])
const ms = await hooks.provider.models(provider, { auth })
expect(ms[model].capabilities.input).toEqual({ text: true, image: true, audio: false, video: false, pdf: false })
})
}
test("every kind the config says is passed on, pdf and audio too; unknown ones are not", async () => {
f = fakeMiniMax()
f.route("GET /mavis/api/v1/models", () => json({
providers: [{ providerId: "minimax", config: { models: {
"X-All": { name: "X-All", modalities: { input: ["text", "image", "audio", "video", "pdf", "hologram"] } },
// an attachment model with no list takes images, as before
"X-Att": { name: "X-Att", attachment: true },
} } }],
}))
const hooks = await MiniMaxCodeAuthPlugin({ client: {}, magpie })
const { provider } = await given(hooks, "minimax-code")
const ms = await hooks.provider.models(provider, { auth })
expect(ms["X-All"].capabilities.input).toEqual({ text: true, image: true, audio: true, video: true, pdf: true })
expect(ms["X-Att"].capabilities.input).toEqual({ text: true, image: true, audio: false, video: false, pdf: false })
expect(ms["X-Att"].capabilities.attachment).toBe(true)
// OpenCode's SDK sends a PDF as a document block, so pdf stays there
const oc = await MiniMaxCodeAuthPlugin({ client: {} })
const ms2 = await oc.provider.models((await given(oc, "minimax-code")).provider, { auth })
expect(ms2["X-All"].capabilities.input).toEqual({ text: true, image: true, audio: false, video: false, pdf: true })
})
test("a chat's video block goes to MiniMax as it came", async () => {
f = fakeMiniMax()
f.route("POST /mavis/api/v1/llm/v1/messages", () => json({ type: "message", content: [] }))
const body = JSON.stringify({
model: "MiniMax-M3.1-Flash", max_tokens: 64,
messages: [{ role: "user", content: [
{ type: "video", source: { type: "base64", media_type: "video/mp4", data: "AAAAIGZ0eXBpc29t" } },
{ type: "text", text: "描述这个视频" },
] }],
})
const hooks = await MiniMaxCodeAuthPlugin({ client: {}, magpie })
const opts = await hooks.auth.loader(async () => auth)
const res = await opts.fetch(opts.baseURL + "/messages", { method: "POST", headers: { "content-type": "application/json" }, body })
expect(res.status).toBe(200)
expect(f.seen.at(-1).text).toBe(body)
})