fix(tool-sieve): allow mixed prose + tool json interception

This commit is contained in:
CJACK. committed 2026-03-20 01:15:32 +08:00
1 parent 2d5103997b
commit 145501d4a5
2 files changed
+9 -29

No files matched your search

+3 -23
View File
@@ -46,6 +46,9 @@ function processToolSieveChunk(state, chunk, toolNames) {
if (Array.isArray(consumed.calls) && consumed.calls.length > 0) {
state.pendingToolRaw = captured;
state.pendingToolCalls = consumed.calls;
if (consumed.suffix) {
state.pending = consumed.suffix + state.pending;
}
continue;
}
if (consumed.prefix) {
@@ -235,17 +238,6 @@ 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) {
@@ -264,18 +256,6 @@ 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,