fix(tool-sieve): keep mixed prose tool json in strict text mode

This commit is contained in:
CJACK.
2026-03-20 01:15:15 +08:00
parent 52e7e7aae8
commit 2d5103997b

View File

@@ -235,6 +235,17 @@ function consumeToolCapture(state, toolNames) {
};
}
// Strict standalone mode: if the stream already produced meaningful prose,
// treat later tool-looking JSON as plain text instead of intercepting.
if ((state.recentTextTail || '').trim() !== '' && prefixPart.trim() === '') {
return {
ready: true,
prefix: captured,
calls: [],
suffix: '',
};
}
const parsed = parseStandaloneToolCallsDetailed(captured.slice(actualStart, obj.end), toolNames);
if (!Array.isArray(parsed.calls) || parsed.calls.length === 0) {
if (parsed.sawToolCallSyntax && parsed.rejectedByPolicy) {
@@ -253,6 +264,18 @@ function consumeToolCapture(state, toolNames) {
};
}
// Strict standalone mode: only intercept when the tool payload stands alone
// (allowing only surrounding whitespace). If there is non-whitespace prose
// before/after the JSON object, keep everything as normal text.
if (prefixPart.trim() !== '' || suffixPart.trim() !== '') {
return {
ready: true,
prefix: captured,
calls: [],
suffix: '',
};
}
return {
ready: true,
prefix: prefixPart,