diff --git a/packages/minimax/README.md b/packages/minimax/README.md index 0318506..4c20afd 100644 --- a/packages/minimax/README.md +++ b/packages/minimax/README.md @@ -85,6 +85,11 @@ On the combined MCP server these are named `minimax_generate_image`, `minimax_submit_video_generation`, and so on. In the Library's routed server, the separator is `minimax__generate_image`. +Each named tool shows a schema bundled with the plugin, so loading it asks +no network. A call is checked against the schema in the account's live +catalog, read on each call, so a parameter MiniMax added since the bundled +copy still goes through. `tool_schema` prints the live schema. + Webpage reading is available through Magpie's search MCP server, whose `web_fetch` protects loopback and private network addresses. diff --git a/packages/minimax/connector-tools.mjs b/packages/minimax/connector-tools.mjs index 8af9c89..2cfdf21 100644 --- a/packages/minimax/connector-tools.mjs +++ b/packages/minimax/connector-tools.mjs @@ -7,9 +7,12 @@ // // The bundled matrix-tools.json is a copy of the catalog's real schemas, // taken from mcode-tools (connector tool ) on 2026-11-03, so loading -// this plugin never asks the network. The live catalog still routes every -// call (provider/provider_tool_name/runtime_tool_name), and is re-read on -// each operation: another signed-in account may connect different tools. +// this plugin never asks the network. It is what agents are shown, never +// what a call is held to: the live catalog, re-read on each operation, +// routes every call (provider/provider_tool_name/runtime_tool_name) and its +// input_schema_json checks the arguments. The copy goes stale as MiniMax +// adds parameters (#955: area, n, output_format, reference_images), and +// another signed-in account may connect different tools. import { readFileSync } from "node:fs" const LIST_PATH = "/minimax-cloud/api/v1/connectors/connected-tools/list" @@ -106,11 +109,13 @@ const same = (a, b) => a === b || (obj(a) && obj(b) && JSON.stringify(a) === JSO // checked(schema, args) validates a tool call's own arguments (site and // account already stripped) against its input_schema; a failure means the // call never left, which for a priced generation is the point. -function checked(schema, args) { +// against, when given, names the schema in the error, so a refusal says +// whose rule it was. +function checked(schema, args, against) { if (!obj(args)) throw new Error("tool arguments must be an object") const errs = [] check(schema, args, "arguments", errs) - if (errs.length) throw new Error("bad arguments: " + errs.join("; ")) + if (errs.length) throw new Error("bad arguments: " + errs.join("; ") + (against ? " (checked against " + against + ")" : "")) return args } @@ -213,9 +218,15 @@ function routing(args, callCtx) { return { site, account: a.account, args: rest, signal: callCtx?.abort } } +// routingOnly is what a direct tool's call is checked against before its +// catalog is read: the two routing fields, and nothing about the tool's +// own arguments, which the catalog's schema judges in execute. +const routingOnly = { type: "object", properties: { site: siteArg, account: accountArg } } +const DIRECT = new WeakSet() + function directTool(request, name, def) { const inner = def.input_schema ?? { type: "object", properties: {} } - return { + const t = { description: def.description, args: { ...inner, @@ -228,10 +239,14 @@ function directTool(request, name, def) { const r = routing(args, callCtx) const cat = await catalog(request, r.site, r.signal, r.account) const entry = find(cat, MATRIX + name) - const checkedArgs = checked(entry.input_schema_json ? parseSchema(entry.input_schema_json) : inner, r.args) + const checkedArgs = entry.input_schema_json + ? checked(parseSchema(entry.input_schema_json), r.args, "the account's catalog schema for " + entry.runtime_tool_name) + : checked(inner, r.args, "the bundled schema for " + entry.runtime_tool_name + " (the catalog gave none)") return invoke(request, r.site, entry, checkedArgs, r.signal, LONG.has(name) ? GEN_MS : CALL_MS, r.account) }, } + DIRECT.add(t) + return t } function parseSchema(json) { try { @@ -329,10 +344,14 @@ export function createConnectorTools(request) { }, } + // A direct tool's advertised args are the bundled copy, which can be + // behind the catalog; holding a call to them refused area on a catalog + // that accepts it (#955). Its own arguments are checked in execute. for (const t of Object.values(tool)) { const execute = t.execute + const pre = DIRECT.has(t) ? routingOnly : t.args t.execute = async (args, ctx) => { - checked(t.args, args) + checked(pre, args) ctx?.abort?.throwIfAborted() return execute(args, ctx) } diff --git a/packages/minimax/connector-tools.test.mjs b/packages/minimax/connector-tools.test.mjs index 1b0cee5..804a524 100644 --- a/packages/minimax/connector-tools.test.mjs +++ b/packages/minimax/connector-tools.test.mjs @@ -5,6 +5,7 @@ // they could be sent, abort propagation, and the matrix-only call guard. import "./nonet.mjs" import { expect, test } from "bun:test" +import { readFileSync } from "node:fs" import { createConnectorTools } from "./connector-tools.mjs" const LIST = "/minimax-cloud/api/v1/connectors/connected-tools/list" @@ -159,7 +160,7 @@ test("a broken result_json is an error, not a silent null", async () => { ).rejects.toThrow(/result_json is not valid JSON/) }) -test("bad arguments are refused before any request leaves", async () => { +test("bad arguments are refused before the call leaves", async () => { const t = transport({ [LIST]: catalog([entry("generate_image", { input_schema_json: JSON.stringify({ type: "object", properties: { requests: { type: "array" } }, required: ["requests"], additionalProperties: false }), @@ -168,7 +169,52 @@ test("bad arguments are refused before any request leaves", async () => { const { tool } = createConnectorTools(t.request) // 'requests' is required by the catalog schema await expect(tool.generate_image.execute({ prompt: "x" }, {})).rejects.toThrow(/bad arguments/) - expect(t.sent).toHaveLength(0) // bundled schema catches it before reading the catalog + // the catalog is read to judge them; the priced call never goes out + expect(t.sent.map((r) => r.path)).toEqual([LIST]) +}) + +// #955: the catalog's generate_image schema as hokaii6990-boop's +// `magpie tool minimax_tool_schema --tool_name connector__matrix__generate_image --json` +// printed it on a CN-site account on 2026-11-11. +const liveImage = readFileSync(new URL("./testdata/generate-image-schema-955.json", import.meta.url), "utf8") + +test("generate_image takes the catalog's area, n, output_format and reference_images (#955)", async () => { + const t = transport({ + [LIST]: catalog([entry("generate_image", { input_schema_json: liveImage })]), + [CALL]: { result_json: JSON.stringify({ success_items: [{ node_id: "n1", file_name: "image_1.png" }] }) }, + }) + const { tool } = createConnectorTools(t.request) + const request = { prompt: "a fox, as 图1", aspect_ratio: "21:9", area: "2K", n: 2, output_format: "png", reference_images: [{ url: "https://upload.example/a.png", mime_type: "image/png" }] } + await tool.generate_image.execute({ requests: [request] }, {}) + const calls = t.sent.filter((r) => r.path === CALL) + expect(calls).toHaveLength(1) + expect(JSON.parse(calls[0].body.arguments_json)).toEqual({ requests: [request] }) +}) + +test("generate_image is refused by the catalog's schema, and says so (#955)", async () => { + const t = transport({ [LIST]: catalog([entry("generate_image", { input_schema_json: liveImage })]) }) + const { tool } = createConnectorTools(t.request) + // resolution is the old name; the catalog took it away + await expect(tool.generate_image.execute({ requests: [{ prompt: "x", resolution: "2K" }] }, {})) + .rejects.toThrow("arguments.requests[0].resolution is not an accepted argument (checked against the account's catalog schema for connector__matrix__generate_image)") + expect(t.sent.filter((r) => r.path === CALL)).toHaveLength(0) +}) + +test("a tool the catalog gives no schema is held to the bundled copy, and says so", async () => { + const t = transport({ [LIST]: catalog([entry("generate_image", { input_schema_json: "" })]) }) + const { tool } = createConnectorTools(t.request) + await expect(tool.generate_image.execute({ requests: [{ prompt: "x", model: "image-01" }] }, {})) + .rejects.toThrow("(checked against the bundled schema for connector__matrix__generate_image (the catalog gave none))") + expect(t.sent.filter((r) => r.path === CALL)).toHaveLength(0) +}) + +test("the bundled generate_image schema is the catalog's of 2026-11-11 (#955)", () => { + const { tool } = createConnectorTools(async () => ({})) + const shown = tool.generate_image.args + expect(shown.properties.requests).toEqual(JSON.parse(liveImage).properties.requests) + expect(Object.keys(shown.properties.requests.items.properties)).not.toContain("resolution") + expect(Object.keys(shown.properties.requests.items.properties)).not.toContain("input_urls") + expect(tool.generate_image.description).not.toContain("input_urls") }) test("video validation follows the per-model allOf rules", async () => { diff --git a/packages/minimax/matrix-tools.json b/packages/minimax/matrix-tools.json index 03674f8..44fd74b 100644 --- a/packages/minimax/matrix-tools.json +++ b/packages/minimax/matrix-tools.json @@ -1,9 +1,9 @@ { - "_verified": "verified against mcode-tools connector tool (mcode CLI, minimax-cloud /connectors) on 2026-11-03; runtime_tool_name = connector__matrix__. get_asset_url is CLI-hidden in 'connector tools' output but callable through the same tools/call gateway.", + "_verified": "verified against mcode-tools connector tool (mcode CLI, minimax-cloud /connectors) on 2026-11-03 (generate_image refreshed on 2026-11-11 from a CN-site account's tool_schema output, plugins#955); runtime_tool_name = connector__matrix__. get_asset_url is CLI-hidden in 'connector tools' output but callable through the same tools/call gateway.", "tools": { "generate_image": { - "description": "Text-to-image (or image-to-image via input_urls). Wrap each request in a 'requests' array, NOT as a flat prompt. Successful items return success_items[].node_id and success_items[].file_name; file_name is the final base filename including its actual extension. To use the generated image, call get_asset_url with this node_id to obtain a short-lived file URL. Optional requests[].output_file sets the downloaded base filename; directory components are ignored. Do not construct an OSS/CDN URL from node_id. Do NOT pass input_files/output_path.", - "input_schema": {"additionalProperties":false,"properties":{"requests":{"items":{"additionalProperties":false,"properties":{"aspect_ratio":{"enum":["1:1","16:9","9:16","4:3","3:4","21:9"],"type":"string"},"input_urls":{"items":{"type":"string"},"type":"array"},"output_file":{"description":"Optional downloaded base filename. Directory components are ignored.","minLength":1,"type":"string"},"prompt":{"type":"string"},"resolution":{"enum":["1K","2K","4K"],"type":"string"}},"required":["prompt"],"type":"object"},"minItems":1,"type":"array"}},"required":["requests"],"type":"object"}, + "description": "Text-to-image, or editing and combining images via reference_images. Wrap each request in a 'requests' array, NOT as a flat prompt. Successful items return success_items[].node_id and success_items[].file_name; file_name is the final base filename including its actual extension. To use the generated image, call get_asset_url with this node_id to obtain a short-lived file URL. Optional requests[].output_file sets the downloaded base filename; directory components are ignored. Do not construct an OSS/CDN URL from node_id. Do NOT pass input_files/output_path.", + "input_schema": {"additionalProperties":false,"properties":{"requests":{"items":{"additionalProperties":false,"properties":{"area":{"description":"Output size tier used with aspect_ratio; defaults to 4K.","enum":["1K","2K","4K"],"type":"string"},"aspect_ratio":{"description":"\"auto\" or \"X:Y\" with integers 1-300 between 1:3 and 3:1, for example 16:9. Use with optional area.","type":"string"},"n":{"description":"Number of images for this request; defaults to 1. Each delivered image is charged once.","maximum":10,"minimum":1,"type":"integer"},"output_file":{"description":"Optional downloaded base filename. Directory components are ignored.","minLength":1,"type":"string"},"output_format":{"description":"Defaults to jpeg. jpg is the same as jpeg.","enum":["png","jpeg","jpg"],"type":"string"},"prompt":{"description":"Image description. With reference_images, refer to them as 图1, 图2, ... in the order given.","minLength":1,"type":"string"},"reference_images":{"description":"Optional 1-16 reference images to edit or combine. JPG, JPEG, PNG, WEBP, HEIC or HEIF; each at most 64 MB, 128-8192 px per side, aspect ratio at most 4:1.","items":{"additionalProperties":false,"properties":{"mime_type":{"enum":["image/jpeg","image/png","image/webp","image/heic","image/heif"],"type":"string"},"url":{"description":"temp_url from a completed upload_temp_url upload (upload local files first), or an existing upload URL from this environment.","type":"string"}},"required":["url"],"type":"object"},"maxItems":16,"type":"array"}},"required":["prompt"],"type":"object"},"maxItems":10,"minItems":1,"type":"array"}},"required":["requests"],"type":"object"}, "output_schema": null }, "submit_video_generation": { diff --git a/packages/minimax/package.json b/packages/minimax/package.json index aeedd15..2e52653 100644 --- a/packages/minimax/package.json +++ b/packages/minimax/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-minimax-auth", - "version": "0.2.3", + "version": "0.2.4", "description": "OpenCode provider plugins for MiniMax Code accounts: their credits and M Plan, China (minimax-code) and international (minimax-code-global), with MiniMax Code's own device sign-in", "type": "module", "main": "./opencode.mjs", diff --git a/packages/minimax/testdata/generate-image-schema-955.json b/packages/minimax/testdata/generate-image-schema-955.json new file mode 100644 index 0000000..cdc70c6 --- /dev/null +++ b/packages/minimax/testdata/generate-image-schema-955.json @@ -0,0 +1,63 @@ +{ + "additionalProperties": false, + "properties": { + "requests": { + "items": { + "additionalProperties": false, + "properties": { + "area": { + "description": "Output size tier used with aspect_ratio; defaults to 4K.", + "enum": ["1K", "2K", "4K"], + "type": "string" + }, + "aspect_ratio": { + "description": "\"auto\" or \"X:Y\" with integers 1-300 between 1:3 and 3:1, for example 16:9. Use with optional area.", + "type": "string" + }, + "n": { + "description": "Number of images for this request; defaults to 1. Each delivered image is charged once.", + "maximum": 10, + "minimum": 1, + "type": "integer" + }, + "output_file": { + "description": "Optional downloaded base filename. Directory components are ignored.", + "minLength": 1, + "type": "string" + }, + "output_format": { + "description": "Defaults to jpeg. jpg is the same as jpeg.", + "enum": ["png", "jpeg", "jpg"], + "type": "string" + }, + "prompt": { + "description": "Image description. With reference_images, refer to them as 图1, 图2, ... in the order given.", + "minLength": 1, + "type": "string" + }, + "reference_images": { + "description": "Optional 1-16 reference images to edit or combine. JPG, JPEG, PNG, WEBP, HEIC or HEIF; each at most 64 MB, 128-8192 px per side, aspect ratio at most 4:1.", + "items": { + "additionalProperties": false, + "properties": { + "mime_type": { "enum": ["image/jpeg", "image/png", "image/webp", "image/heic", "image/heif"], "type": "string" }, + "url": { "description": "temp_url from a completed upload_temp_url upload (upload local files first), or an existing upload URL from this environment.", "type": "string" } + }, + "required": ["url"], + "type": "object" + }, + "maxItems": 16, + "type": "array" + } + }, + "required": ["prompt"], + "type": "object" + }, + "maxItems": 10, + "minItems": 1, + "type": "array" + } + }, + "required": ["requests"], + "type": "object" +}