From 2b87fad98d513432ebd69a6389f23b0f25372b19 Mon Sep 17 00:00:00 2001 From: Klarkxy Date: Wed, 11 Nov 2026 23:44:15 +0800 Subject: [PATCH] minimax 0.2.7: opt-in compactTools lists only the four dispatcher tools (#1014) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the plugin option `compactTools` (default false, declared in package.json `magpie.options`). Only an explicit `true` leaves the sixteen named Matrix tools out of the tools plugin's advertised list; `list_tools`, `tool_schema`, `call_tool` and `web_search` stay, built by the same code, with descriptions and schemas unchanged. `call_tool` still checks arguments against the live catalog. This is option A as decided on #1005; option B (rewritten descriptions) is not in it. Run at the reviewed head a2d18183, on mote with a temp HOME: - bun test packages/minimax: 165 pass, 0 fail - bun scripts/check.mjs: exit 0 - Advertised list (name, description, args) hashed with MiniMaxCodeToolsPlugin at origin/main dba24067 and at the head: for no options, {}, and {compactTools:false} both give sha256 3cacc575d5abf786… (32300 chars), so off is byte-identical to main; {compactTools:true} gives 3890 chars at the head. - git merge-tree with origin/main dba24067: clean. Broken by hand, each red then restored: - off path builds the Matrix tools after the dispatchers (order change): "compactTools off leaves the advertised tool list byte-for-byte" and "discovery stays scoped to Matrix" go red. - on path appends text to list_tools' description: both "on ... unchanged" tests (connector-tools and the tools plugin) go red. - compactToolsOn(options) as Boolean(options?.compactTools): "only true for an explicit true" and the off byte-for-byte test go red. Not tried: a real MiniMax account or a live agy catalog; fake fetch only. Co-authored-by: Klarkxy <6316992+klarkxy@users.noreply.github.com> --- packages/minimax/README.md | 10 +++++ packages/minimax/compact-tools.test.mjs | 43 ++++++++++++++++++++ packages/minimax/connector-tools.mjs | 18 +++++++-- packages/minimax/connector-tools.test.mjs | 48 ++++++++++++++++++++++- packages/minimax/index.mjs | 7 ++-- packages/minimax/package.json | 5 ++- 6 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 packages/minimax/compact-tools.test.mjs diff --git a/packages/minimax/README.md b/packages/minimax/README.md index 04adc32..aeec6a2 100644 --- a/packages/minimax/README.md +++ b/packages/minimax/README.md @@ -85,6 +85,16 @@ 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`. +The sixteen named Matrix tools are advertised by default. The plugin option +`compactTools` (default `false`) leaves them out of the tool list when set +to `true`, and keeps only `list_tools`, `tool_schema`, `call_tool`, and +`web_search`, with those four descriptions and schemas unchanged. `call_tool` +still checks arguments against the account's live catalog. Turn it on with: + +```sh +magpie plugin options @magpie-community/opencode-minimax-auth '{"compactTools": true}' +``` + 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 diff --git a/packages/minimax/compact-tools.test.mjs b/packages/minimax/compact-tools.test.mjs new file mode 100644 index 0000000..458f2d3 --- /dev/null +++ b/packages/minimax/compact-tools.test.mjs @@ -0,0 +1,43 @@ +// The tools plugin's advertised list with compactTools on and off: +// default stays today's twenty tools; on keeps only the four dispatchers, +// with their descriptions and schemas unchanged. +import "./nonet.mjs" +import { expect, test } from "bun:test" +import { compactToolsOn } from "./connector-tools.mjs" +import { MiniMaxCodeToolsPlugin } from "./magpie.mjs" +import { createWebTools } from "./web-tools.mjs" + +const advertised = (tool) => JSON.stringify(Object.fromEntries( + Object.entries(tool).map(([name, t]) => [name, { description: t.description, args: t.args }]), +)) + +test("compactToolsOn is only true for an explicit true", () => { + expect(compactToolsOn()).toBe(false) + expect(compactToolsOn({})).toBe(false) + expect(compactToolsOn({ compactTools: false })).toBe(false) + expect(compactToolsOn({ compactTools: "true" })).toBe(false) + expect(compactToolsOn({ compactTools: 1 })).toBe(false) + expect(compactToolsOn({ compactTools: true })).toBe(true) +}) + +test("the tools plugin with compactTools off matches today's advertised list", async () => { + const today = advertised((await MiniMaxCodeToolsPlugin({ directory: "/tmp" })).tool) + expect(advertised((await MiniMaxCodeToolsPlugin({ directory: "/tmp" }, {})).tool)).toBe(today) + expect(advertised((await MiniMaxCodeToolsPlugin({ directory: "/tmp" }, { compactTools: false })).tool)).toBe(today) + const names = Object.keys((await MiniMaxCodeToolsPlugin({ directory: "/tmp" })).tool) + expect(names.at(-1)).toBe("web_search") + expect(names).toHaveLength(20) +}) + +test("the tools plugin with compactTools on lists only the four dispatchers, unchanged", async () => { + const full = (await MiniMaxCodeToolsPlugin({ directory: "/tmp" })).tool + const compact = (await MiniMaxCodeToolsPlugin({ directory: "/tmp" }, { compactTools: true })).tool + expect(Object.keys(compact)).toEqual(["list_tools", "tool_schema", "call_tool", "web_search"]) + for (const name of Object.keys(compact)) { + expect(compact[name].description).toBe(full[name].description) + expect(JSON.stringify(compact[name].args)).toBe(JSON.stringify(full[name].args)) + } + const web = createWebTools(async () => ({})).web_search + expect(compact.web_search.description).toBe(web.description) + expect(JSON.stringify(compact.web_search.args)).toBe(JSON.stringify(web.args)) +}) diff --git a/packages/minimax/connector-tools.mjs b/packages/minimax/connector-tools.mjs index 2cfdf21..288fb1f 100644 --- a/packages/minimax/connector-tools.mjs +++ b/packages/minimax/connector-tools.mjs @@ -256,12 +256,22 @@ function parseSchema(json) { } catch { throw new Error("MiniMax connector list: malformed input_schema_json") } } -export function createConnectorTools(request) { +// compactTools is opt-in and off by default. Only an explicit true hides +// the sixteen named Matrix tools from the advertised list; their +// descriptions are not rewritten. list_tools, tool_schema and call_tool +// are always advertised, built by the same path either way. +export function compactToolsOn(options) { + return options?.compactTools === true +} + +export function createConnectorTools(request, options = {}) { if (typeof request !== "function") throw new Error("createConnectorTools needs the request transport") const tool = {} - // the named matrix tools, each its own first-class magpie tool - for (const [name, def] of Object.entries(MATRIX_TOOLS)) tool[name] = directTool(request, name, def) + // the named matrix tools, each its own first-class magpie tool, + // omitted from the advertised list when compactTools is on + if (!compactToolsOn(options)) + for (const [name, def] of Object.entries(MATRIX_TOOLS)) tool[name] = directTool(request, name, def) tool.list_tools = { description: @@ -359,4 +369,4 @@ export function createConnectorTools(request) { return { tool } } -export const _internal = { check, checked, catalog, find, invoke, routing, MATRIX_TOOLS, SITES } +export const _internal = { check, checked, catalog, find, invoke, routing, MATRIX_TOOLS, SITES, compactToolsOn } diff --git a/packages/minimax/connector-tools.test.mjs b/packages/minimax/connector-tools.test.mjs index 804a524..dc90d01 100644 --- a/packages/minimax/connector-tools.test.mjs +++ b/packages/minimax/connector-tools.test.mjs @@ -6,7 +6,7 @@ import "./nonet.mjs" import { expect, test } from "bun:test" import { readFileSync } from "node:fs" -import { createConnectorTools } from "./connector-tools.mjs" +import { createConnectorTools, _internal } from "./connector-tools.mjs" const LIST = "/minimax-cloud/api/v1/connectors/connected-tools/list" const CALL = "/minimax-cloud/api/v1/connectors/tools/call" @@ -320,3 +320,49 @@ test("discovery stays scoped to Matrix and generic arguments are checked before await expect(tool.get_voice_list.execute(null)).rejects.toThrow("object") expect(t.sent.length).toBe(before) }) + +const advertised = (tool) => JSON.stringify(Object.fromEntries( + Object.entries(tool).map(([name, t]) => [name, { description: t.description, args: t.args }]), +)) + +test("compactTools off leaves the advertised tool list byte-for-byte as today", () => { + const request = async () => ({}) + const today = advertised(createConnectorTools(request).tool) + expect(advertised(createConnectorTools(request, {}).tool)).toBe(today) + expect(advertised(createConnectorTools(request, { compactTools: false }).tool)).toBe(today) + for (const options of [undefined, { compactTools: 0 }, { compactTools: "true" }, { compactTools: null }]) { + const tool = options === undefined ? createConnectorTools(request).tool : createConnectorTools(request, options).tool + expect(advertised(tool)).toBe(today) + } + const names = Object.keys(createConnectorTools(request).tool) + expect(names.slice(0, 16)).toEqual(Object.keys(_internal.MATRIX_TOOLS)) + expect(names.slice(16)).toEqual(["list_tools", "tool_schema", "call_tool"]) +}) + +test("compactTools on advertises only list_tools, tool_schema and call_tool, unchanged", () => { + const request = async () => ({}) + const full = createConnectorTools(request).tool + const compact = createConnectorTools(request, { compactTools: true }).tool + expect(Object.keys(compact)).toEqual(["list_tools", "tool_schema", "call_tool"]) + for (const name of Object.keys(compact)) { + expect(compact[name].description).toBe(full[name].description) + expect(JSON.stringify(compact[name].args)).toBe(JSON.stringify(full[name].args)) + } + const kept = Object.fromEntries(Object.entries(full).filter(([name]) => name in compact).map(([name, t]) => [name, { description: t.description, args: t.args }])) + expect(advertised(compact)).toBe(JSON.stringify(kept)) +}) + +test("call_tool still refuses bad arguments against the live schema when compactTools is on", async () => { + const t = transport({ + [LIST]: catalog([entry("generate_image", { + input_schema_json: JSON.stringify({ type: "object", properties: { requests: { type: "array" } }, required: ["requests"], additionalProperties: false }), + })]), + }) + const { tool } = createConnectorTools(t.request, { compactTools: true }) + expect(tool.generate_image).toBeUndefined() + await expect( + tool.call_tool.execute({ tool_name: "connector__matrix__generate_image", arguments: { prompt: "x" } }, {}), + ).rejects.toThrow(/bad arguments/) + expect(t.sent.map((r) => r.path)).toEqual([LIST]) + expect(t.sent.some((r) => r.path === CALL)).toBe(false) +}) diff --git a/packages/minimax/index.mjs b/packages/minimax/index.mjs index 185619b..31ed64b 100644 --- a/packages/minimax/index.mjs +++ b/packages/minimax/index.mjs @@ -13,7 +13,7 @@ import { createHash, randomBytes, randomUUID } from "node:crypto" import { readFile } from "node:fs/promises" import { join } from "node:path" -import { createConnectorTools } from "./connector-tools.mjs" +import { compactToolsOn, createConnectorTools } from "./connector-tools.mjs" import { createWebTools } from "./web-tools.mjs" const CLIENT_ID = "mcode-public" @@ -1350,9 +1350,10 @@ function createToolRequest({ client, directory }) { } } -export const MiniMaxCodeToolsPlugin = async (input) => { +export const MiniMaxCodeToolsPlugin = async (input, options = {}) => { const request = createToolRequest(input) - return { tool: { ...createConnectorTools(request).tool, ...createWebTools(request) } } + const compact = { compactTools: compactToolsOn(options) } + return { tool: { ...createConnectorTools(request, compact).tool, ...createWebTools(request) } } } export const MiniMaxCodeAuthPlugin = makePlugin(SITES["minimax-code"]) diff --git a/packages/minimax/package.json b/packages/minimax/package.json index 46132c4..e347a93 100644 --- a/packages/minimax/package.json +++ b/packages/minimax/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-minimax-auth", - "version": "0.2.6", + "version": "0.2.7", "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", @@ -8,5 +8,6 @@ "files": ["index.mjs", "opencode.mjs", "opencode2.mjs", "magpie.mjs", "connector-tools.mjs", "matrix-tools.json", "web-tools.mjs", "README.md"], "keywords": ["opencode", "opencode-plugin", "minimax", "mcode", "minimax-code"], "license": "MIT", - "repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/minimax" } + "repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/minimax" }, + "magpie": { "options": { "compactTools": false } } }