File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 34
34
"prepare" : " pnpm run build" ,
35
35
"test" : " vitest run" ,
36
36
"check" : " tsc" ,
37
- "agent " : " tsx cli.ts"
37
+ "cli " : " tsx cli.ts"
38
38
},
39
39
"files" : [
40
40
" src" ,
Original file line number Diff line number Diff line change @@ -160,13 +160,18 @@ export class McpClient {
160
160
for ( const toolCall of delta . tool_calls ?? [ ] ) {
161
161
// aggregating chunks into an encoded arguments JSON object
162
162
if ( ! finalToolCalls [ toolCall . index ] ) {
163
+ /// first chunk of the tool call
163
164
finalToolCalls [ toolCall . index ] = toolCall ;
164
- }
165
- if ( finalToolCalls [ toolCall . index ] . function . arguments === undefined ) {
166
- finalToolCalls [ toolCall . index ] . function . arguments = "" ;
167
- }
168
- if ( toolCall . function . arguments ) {
169
- finalToolCalls [ toolCall . index ] . function . arguments += toolCall . function . arguments ;
165
+
166
+ /// ensure .function.arguments is always a string
167
+ if ( finalToolCalls [ toolCall . index ] . function . arguments === undefined ) {
168
+ finalToolCalls [ toolCall . index ] . function . arguments = "" ;
169
+ }
170
+ } else {
171
+ /// any subsequent chunk to the same tool call
172
+ if ( toolCall . function . arguments ) {
173
+ finalToolCalls [ toolCall . index ] . function . arguments += toolCall . function . arguments ;
174
+ }
170
175
}
171
176
}
172
177
if ( opts . exitIfFirstChunkNoTool && numOfChunks <= 2 && Object . keys ( finalToolCalls ) . length === 0 ) {
You can’t perform that action at this time.
0 commit comments