This commit is contained in:
CJACK
2026-03-29 19:49:52 +08:00
parent 621599f8ad
commit c3c644ff8c
2 changed files with 21 additions and 2 deletions

View File

@@ -116,8 +116,11 @@ function flushToolSieve(state, toolNames) {
events.push({ type: 'text', text: consumed.suffix });
}
} else if (state.capture) {
noteText(state, state.capture);
events.push({ type: 'text', text: state.capture });
const content = state.capture;
if (!hasOpenXMLToolTag(content) && !looksLikeXMLToolTagFragment(content)) {
noteText(state, content);
events.push({ type: 'text', text: content });
}
}
state.capture = '';
state.capturing = false;

View File

@@ -213,6 +213,22 @@ test('sieve flushes incomplete captured tool json as text on stream finalize', (
assert.equal(leakedText.includes('{'), true);
});
test('sieve flushes incomplete captured XML tool blocks without leaking raw tags', () => {
const events = runSieve(
[
'前置正文G。',
'<tool_calls>\n',
' <tool_call>\n',
' <tool_name>read_file</tool_name>\n',
],
['read_file'],
);
const leakedText = collectText(events);
assert.equal(leakedText.includes('前置正文G。'), true);
assert.equal(leakedText.toLowerCase().includes('tool_calls'), false);
assert.equal(leakedText.includes('<tool_call'), false);
});
test('sieve still intercepts large tool json payloads over previous capture limit', () => {
const large = 'a'.repeat(9000);
const payload = `{"tool_calls":[{"name":"read_file","input":{"path":"${large}"}}]}`;