File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -160,13 +160,18 @@ export class McpClient {
160160 for ( const toolCall of delta . tool_calls ?? [ ] ) {
161161 // aggregating chunks into an encoded arguments JSON object
162162 if ( ! finalToolCalls [ toolCall . index ] ) {
163+ /// first chunk of the tool call
163164 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+ }
170175 }
171176 }
172177 if ( opts . exitIfFirstChunkNoTool && numOfChunks <= 2 && Object . keys ( finalToolCalls ) . length === 0 ) {
You can’t perform that action at this time.
0 commit comments