@@ -68,21 +68,21 @@ interface StreamingState {
6868function processChatCompletionToolCalls ( toolCalls : ChatCompletionToolCall [ ] , state : StreamingState ) : void {
6969 for ( const toolCall of toolCalls ) {
7070 const index = toolCall . index ;
71- if ( index === undefined ) continue ;
71+ if ( index === undefined || ! toolCall . function ) continue ;
7272
7373 // Initialize tool call if this is the first chunk for this index
7474 if ( ! ( index in state . chatCompletionToolCalls ) ) {
7575 state . chatCompletionToolCalls [ index ] = {
7676 ...toolCall ,
7777 function : {
78- name : toolCall . function ? .name || '' ,
79- arguments : toolCall . function ? .arguments || '' ,
78+ name : toolCall . function . name ,
79+ arguments : toolCall . function . arguments || '' ,
8080 } ,
8181 } ;
8282 } else {
8383 // Accumulate function arguments from subsequent chunks
8484 const existingToolCall = state . chatCompletionToolCalls [ index ] ;
85- if ( toolCall . function ? .arguments && existingToolCall ?. function ) {
85+ if ( toolCall . function . arguments && existingToolCall ?. function ) {
8686 existingToolCall . function . arguments += toolCall . function . arguments ;
8787 }
8888 }
@@ -169,7 +169,7 @@ function processResponsesApiEvent(
169169 if ( recordOutputs ) {
170170 // Handle tool call events for Responses API
171171 if ( event . type === 'response.output_item.done' && 'item' in event ) {
172- state . responsesApiToolCalls . push ( event . item as ResponseFunctionCall | unknown ) ;
172+ state . responsesApiToolCalls . push ( event . item ) ;
173173 }
174174
175175 if ( event . type === 'response.output_text.delta' && 'delta' in event && event . delta ) {
0 commit comments