fix: gate minimax XML stripping (#809) (thanks @latitudeki5223)

This commit is contained in:
Peter Steinberger
2026-01-13 00:36:39 +00:00
parent 1eb924739b
commit e2ea20f862
3 changed files with 41 additions and 6 deletions

View File

@@ -23,7 +23,7 @@
- Sandbox: support tool-policy groups in `tools.sandbox.tools` (e.g. `group:memory`, `group:fs`) to reduce config churn.
### Fixes
- Models/MiniMax: strip malformed tool invocation XML (`<invoke>...</invoke>` and `</minimax:tool_call>`) from assistant text to prevent tool call leaks into user messages.
- Models/MiniMax: strip malformed tool invocation XML (`<invoke>...</invoke>` and `</minimax:tool_call>`) from assistant text to prevent tool call leaks into user messages. (#809 — thanks @latitudeki5223)
- Tools/Models: MiniMax vision now uses the Coding Plan VLM endpoint (`/v1/coding_plan/vlm`) so the `image` tool works with MiniMax keys (also accepts `@/path/to/file.png`-style inputs).
- Gateway/macOS: reduce noisy loopback WS "closed before connect" logs during tests.
- Auto-reply: resolve ambiguous `/model` fuzzy matches by picking the best candidate instead of erroring.

View File

@@ -41,6 +41,24 @@ describe("extractAssistantText", () => {
expect(result).toBe("Let me check that.");
});
it("keeps invoke snippets without Minimax markers", () => {
const msg: AssistantMessage = {
role: "assistant",
content: [
{
type: "text",
text: `Example:\n<invoke name="Bash">\n<parameter name="command">ls</parameter>\n</invoke>`,
},
],
timestamp: Date.now(),
};
const result = extractAssistantText(msg);
expect(result).toBe(
`Example:\n<invoke name="Bash">\n<parameter name="command">ls</parameter>\n</invoke>`,
);
});
it("preserves normal text without tool invocations", () => {
const msg: AssistantMessage = {
role: "assistant",
@@ -57,6 +75,22 @@ describe("extractAssistantText", () => {
expect(result).toBe("This is a normal response without any tool calls.");
});
it("strips Minimax tool invocations with extra attributes", () => {
const msg: AssistantMessage = {
role: "assistant",
content: [
{
type: "text",
text: `Before<invoke name='Bash' data-foo="bar">\n<parameter name="command">ls</parameter>\n</invoke>\n</minimax:tool_call>After`,
},
],
timestamp: Date.now(),
};
const result = extractAssistantText(msg);
expect(result).toBe("Before\nAfter");
});
it("strips tool XML mixed with regular content", () => {
const msg: AssistantMessage = {
role: "assistant",

View File

@@ -10,14 +10,15 @@ import { formatToolDetail, resolveToolDisplay } from "./tool-display.js";
*/
function stripMinimaxToolCallXml(text: string): string {
if (!text) return text;
if (!/minimax:tool_call/i.test(text)) return text;
// Remove <invoke name="...">...</invoke> blocks (non-greedy to handle multiple)
let cleaned = text.replace(/<invoke\s+name="[^"]*">[\s\S]*?<\/invoke>/gi, "");
// Remove <invoke ...>...</invoke> blocks (non-greedy to handle multiple).
let cleaned = text.replace(/<invoke\b[^>]*>[\s\S]*?<\/invoke>/gi, "");
// Remove stray </minimax:tool_call> tags
cleaned = cleaned.replace(/<\/minimax:tool_call>/gi, "");
// Remove stray minimax tool tags.
cleaned = cleaned.replace(/<\/?minimax:tool_call>/gi, "");
return cleaned.trim();
return cleaned;
}
export function extractAssistantText(msg: AssistantMessage): string {