mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 00:15:28 +08:00
fix(tool-sieve): keep mixed prose tool json in strict text mode
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user