Skip to content

Commit 3bead8b

Browse files
authored
Merge pull request #7266 from continuedev/dallin/args-streaming-fix
fix HOTFIX remove cumulative args case
2 parents 5d23ffb + a175385 commit 3bead8b

File tree

2 files changed

+5
-77
lines changed

2 files changed

+5
-77
lines changed

gui/src/util/toolCallState.test.ts

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -480,76 +480,6 @@ describe("addToolCallDeltaToState", () => {
480480
expect(currentState.parsedArgs).toEqual({ location: "Paris, France" });
481481
});
482482

483-
it("should handle arguments streamed in full progressive chunks", () => {
484-
// Test case where model streams args progressively but includes full prefix each time
485-
// e.g. '{"query":"te' -> '{"query":"tes' -> '{"query":"test"}'
486-
const currentState: ToolCallState = {
487-
status: "generating",
488-
toolCall: {
489-
id: "call123",
490-
type: "function",
491-
function: {
492-
name: "searchFiles",
493-
arguments: '{"query":"te',
494-
},
495-
},
496-
toolCallId: "call123",
497-
parsedArgs: { query: "te" },
498-
};
499-
500-
const delta: ToolCallDelta = {
501-
function: {
502-
arguments: '{"query":"tes',
503-
},
504-
};
505-
506-
const result = addToolCallDeltaToState(delta, currentState);
507-
expect(result.toolCall.function.arguments).toBe('{"query":"tes');
508-
expect(result.parsedArgs).toEqual({ query: "tes" });
509-
510-
// Continue the streaming
511-
const nextDelta: ToolCallDelta = {
512-
function: {
513-
arguments: '{"query":"test"}',
514-
},
515-
};
516-
517-
const finalResult = addToolCallDeltaToState(nextDelta, result);
518-
expect(finalResult.toolCall.function.arguments).toBe('{"query":"test"}');
519-
expect(finalResult.parsedArgs).toEqual({ query: "test" });
520-
});
521-
522-
it("should handle when args delta is a superset of current args", () => {
523-
// Test case where model sends a subset of the current arguments
524-
// This can happen in certain LLM implementations
525-
const currentState: ToolCallState = {
526-
status: "generating",
527-
toolCall: {
528-
id: "call123",
529-
type: "function",
530-
function: {
531-
name: "searchFiles",
532-
arguments: '{"query":"test"',
533-
},
534-
},
535-
toolCallId: "call123",
536-
parsedArgs: { query: "test" },
537-
};
538-
539-
const delta: ToolCallDelta = {
540-
function: {
541-
arguments: '{"query":"test","limit":10}',
542-
},
543-
};
544-
545-
// The subset should be ignored, keeping the current state
546-
const result = addToolCallDeltaToState(delta, currentState);
547-
expect(result.toolCall.function.arguments).toBe(
548-
'{"query":"test","limit":10}',
549-
);
550-
expect(result.parsedArgs).toEqual({ query: "test", limit: 10 });
551-
});
552-
553483
it("should handle when args are complete JSON and new deltas arrive", () => {
554484
// When args are already a valid JSON object, new deltas should not modify it
555485
const currentState: ToolCallState = {

gui/src/util/toolCallState.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ export function addToolCallDeltaToState(
4444
// If args is JSON parseable, it is complete, don't add to it
4545
JSON.parse(currentArgs);
4646
} catch (e) {
47-
if (argsDelta.startsWith(currentArgs)) {
48-
// Case where model progresssively streams args but full args each time e.g. "{"file": "file1"}" -> "{"file": "file1", "line": 1}"
49-
mergedArgs = argsDelta;
50-
} else if (!currentArgs.startsWith(argsDelta)) {
51-
// Case where model streams in args in parts e.g. "{"file": "file1"" -> ", "line": 1}"
52-
mergedArgs = currentArgs + argsDelta;
53-
}
47+
// Model streams in args in parts e.g. "{"file": "file1"" -> ", "line": 1}"
48+
mergedArgs = currentArgs + argsDelta;
49+
50+
// Note, removed case where model progresssively streams args but full args each time e.g. "{"file": "file1"}" -> "{"file": "file1", "line": 1}"
51+
// Because no apis do this and difficult to detect reliably
5452
}
5553

5654
const [_, parsedArgs] = incrementalParseJson(mergedArgs || "{}");

0 commit comments

Comments
 (0)