
















@@ -10,7 +10,7 @@ import {
10101111const MEMORY_TAG_RE = /<\s*(\/?)\s*relevant[-_]memories\b[^<>]*>/gi;
1212const MEMORY_TAG_QUICK_RE = /<\s*\/?\s*relevant[-_]memories\b/i;
13-const LEGACY_BRACKET_TOOL_CALL_QUICK_RE = /\[\s*\/?\s*TOOL_CALL\s*\]/i;
13+const LEGACY_BRACKET_TOOL_BLOCK_QUICK_RE = /\[\s*\/?\s*TOOL_(?:CALL|RESULT)\s*\]/i;
14141515/**
1616 * Strip XML-style tool call tags that models sometimes emit as plain text.
@@ -361,20 +361,29 @@ function isLegacyBracketToolCallPayload(value: string): boolean {
361361);
362362}
363363364+function isLegacyBracketToolResultPayload(value: string): boolean {
365+return (
366+/^\s*[{[]/.test(value) ||
367+/\b(?:tool|result|output|content)\s*=>/i.test(value) ||
368+/\b(?:tool|result|output|content)\s*:/i.test(value)
369+);
370+}
371+364372export function stripLegacyBracketToolCallBlocks(text: string): string {
365-if (!text || !LEGACY_BRACKET_TOOL_CALL_QUICK_RE.test(text)) {
373+if (!text || !LEGACY_BRACKET_TOOL_BLOCK_QUICK_RE.test(text)) {
366374return text;
367375}
368376369377const codeRegions = findCodeRegions(text);
370378let result = "";
371379let cursor = 0;
372380while (cursor < text.length) {
373-const openMatch = /\[\s*TOOL_CALL\s*\]/gi.exec(text.slice(cursor));
381+const openMatch = /\[\s*TOOL_(CALL|RESULT)\s*\]/gi.exec(text.slice(cursor));
374382if (!openMatch?.[0]) {
375383result += text.slice(cursor);
376384break;
377385}
386+const blockKind = openMatch[1]?.toUpperCase();
378387const openStart = cursor + (openMatch.index ?? 0);
379388const payloadStart = openStart + openMatch[0].length;
380389if (isInsideCode(openStart, codeRegions)) {
@@ -383,14 +392,20 @@ export function stripLegacyBracketToolCallBlocks(text: string): string {
383392continue;
384393}
385394386-const closeMatch = /\[\s*\/\s*TOOL_CALL\s*\]/gi.exec(text.slice(payloadStart));
395+const closeRe =
396+blockKind === "RESULT" ? /\[\s*\/\s*TOOL_RESULT\s*\]/gi : /\[\s*\/\s*TOOL_CALL\s*\]/gi;
397+const closeMatch = closeRe.exec(text.slice(payloadStart));
387398const closeStart =
388399closeMatch?.[0] && !isInsideCode(payloadStart + (closeMatch.index ?? 0), codeRegions)
389400 ? payloadStart + (closeMatch.index ?? 0)
390401 : -1;
391402const payloadEnd = closeStart >= 0 ? closeStart : text.length;
392403const payload = text.slice(payloadStart, payloadEnd);
393-if (!isLegacyBracketToolCallPayload(payload)) {
404+const shouldStrip =
405+blockKind === "RESULT"
406+ ? isLegacyBracketToolResultPayload(payload)
407+ : isLegacyBracketToolCallPayload(payload);
408+if (!shouldStrip) {
394409result += text.slice(cursor, payloadStart);
395410cursor = payloadStart;
396411continue;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。