mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-10 19:27:41 +08:00
Fix tool detection when unclosed backtick precedes tool call
Handles cases where a stray backtick opens an inline code span but is never closed. Previously, any subsequent XML tool tag was treated as inside markdown code and ignored. Now, tool tags are detected after an unclosed backtick, and the markdown state is reset when the backtick is confirmed to be literal text at stream boundaries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -632,6 +632,27 @@ test('sieve ignores inline markdown tool example split across chunks', () => {
|
||||
assert.equal(text.includes('完毕'), true);
|
||||
});
|
||||
|
||||
test('sieve emits real tool after unclosed inline markdown in same chunk', () => {
|
||||
const events = runSieve([
|
||||
'note with stray ` before real call <tool_calls><invoke name="read_file"><parameter name="path">real.md</parameter></invoke></tool_calls>',
|
||||
], ['read_file']);
|
||||
const text = collectText(events);
|
||||
const finalCalls = events.filter((evt) => evt.type === 'tool_calls').flatMap((evt) => evt.calls || []);
|
||||
assert.equal(finalCalls.length, 1);
|
||||
assert.equal(finalCalls[0].input.path, 'real.md');
|
||||
assert.equal(text.includes('stray ` before real call'), true);
|
||||
});
|
||||
|
||||
test('sieve emits real tool after unclosed inline markdown across chunks', () => {
|
||||
const events = runSieve([
|
||||
'note with stray ` before real call ',
|
||||
'<tool_calls><invoke name="read_file"><parameter name="path">real.md</parameter></invoke></tool_calls>',
|
||||
], ['read_file']);
|
||||
const finalCalls = events.filter((evt) => evt.type === 'tool_calls').flatMap((evt) => evt.calls || []);
|
||||
assert.equal(finalCalls.length, 1);
|
||||
assert.equal(finalCalls[0].input.path, 'real.md');
|
||||
});
|
||||
|
||||
test('sieve emits real tool after split inline markdown tool example closes', () => {
|
||||
const events = runSieve([
|
||||
'示例:`',
|
||||
|
||||
Reference in New Issue
Block a user