Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions internal/js/helpers/stream-tool-sieve/sieve.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,6 @@ function consumeToolCapture(state, toolNames) {
}
const parsed = parseStandaloneToolCalls(captured.slice(start, obj.end), toolNames);
if (parsed.length === 0) {
if (state.toolNameSent) {
return {
ready: true,
prefix: prefixPart,
calls: [],
suffix: suffixPart,
};
}
return {
ready: true,
prefix: captured,
Expand Down
22 changes: 22 additions & 0 deletions tests/node/stream-tool-sieve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,28 @@ test('sieve emits incremental tool_call_deltas for split arguments payload', ()
assert.equal(argsJoined.includes('"mode":"head"'), true);
});

test('sieve preserves filtered tool json as text after incremental probe', () => {
const state = createToolSieveState();
const first = processToolSieveChunk(
state,
'{"tool_calls":[{"name":"unknown_tool","input":{"q":"hel',
['read_file'],
);
const second = processToolSieveChunk(
state,
'lo"}}]}继续正文。',
['read_file'],
);
const tail = flushToolSieve(state, ['read_file']);
const events = [...first, ...second, ...tail];
const leakedText = collectText(events);
const hasToolCall = events.some((evt) => evt.type === 'tool_calls' && evt.calls?.length > 0);
assert.equal(hasToolCall, false);
assert.equal(leakedText.toLowerCase().includes('tool_calls'), true);
assert.equal(leakedText.includes('unknown_tool'), true);
assert.equal(leakedText.includes('继续正文。'), true);
});

test('sieve still intercepts tool call after leading plain text without suffix', () => {
const events = runSieve(
['我将调用工具。', '{"tool_calls":[{"name":"read_file","input":{"path":"README.MD"}}]}'],
Expand Down