fix: reset tool call state between separate tool blocks to ensure unique IDs across stream segments

This commit is contained in:
CJACK.
2026-04-22 20:10:06 +00:00
parent c291d333c4
commit 5cf56e7628
10 changed files with 175 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ const {
normalizePreparedToolNames,
boolDefaultTrue,
filterIncrementalToolCallDeltasByAllowed,
resetStreamToolCallState,
buildUsage,
estimateTokens,
shouldSkipPath,
@@ -107,6 +108,16 @@ test('incremental and final tool formatting share stable id via idStore', () =>
assert.equal(incremental[0].id, finalCalls[0].id);
});
test('resetStreamToolCallState gives each completed block a fresh id', () => {
const idStore = new Map();
const first = formatIncrementalToolCallDeltas([{ index: 0, name: 'read_file' }], idStore);
resetStreamToolCallState(idStore);
const second = formatIncrementalToolCallDeltas([{ index: 0, name: 'search' }], idStore);
assert.equal(first.length, 1);
assert.equal(second.length, 1);
assert.notEqual(first[0].id, second[0].id);
});
test('formatIncrementalToolCallDeltas drops empty deltas (Go parity)', () => {
const idStore = new Map();
const formatted = formatIncrementalToolCallDeltas([{ index: 0 }], idStore);