mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-04 08:25:26 +08:00
refactor(js): align tool-sieve segment start and tail window with go
This commit is contained in:
@@ -197,11 +197,7 @@ function findToolSegmentStart(state, s) {
|
||||
}
|
||||
const keyIdx = bestKeyIdx;
|
||||
const start = s.slice(0, keyIdx).lastIndexOf('{');
|
||||
if (start < 0) {
|
||||
offset = keyIdx + matchedKeyword.length;
|
||||
continue;
|
||||
}
|
||||
let candidateStart = start;
|
||||
let candidateStart = start >= 0 ? start : keyIdx;
|
||||
// If the keyword matched inside an XML tag (e.g. "tool_calls" in "<tool_calls>"),
|
||||
// back up past the '<' to capture the full tag.
|
||||
if (candidateStart > 0 && s[candidateStart - 1] === '<') {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const TOOL_SIEVE_CONTEXT_TAIL_LIMIT = 4096;
|
||||
const TOOL_SIEVE_CONTEXT_TAIL_LIMIT = 256;
|
||||
|
||||
function createToolSieveState() {
|
||||
return {
|
||||
|
||||
@@ -252,7 +252,7 @@ test('sieve keeps plain text intact in tool mode when no tool call appears', ()
|
||||
assert.equal(leakedText, '你好,这是普通文本回复。请继续。');
|
||||
});
|
||||
|
||||
test('sieve does not start capture on plain "tool_calls" prose without opening json brace', () => {
|
||||
test('sieve keeps plain "tool_calls" prose as text when no valid payload follows', () => {
|
||||
const events = runSieve(
|
||||
['前置。', '这里提到 tool_calls 只是解释,不是调用。', '后置。'],
|
||||
['read_file'],
|
||||
|
||||
Reference in New Issue
Block a user