@@ -68,21 +68,21 @@ interface StreamingState {
68
68
function processChatCompletionToolCalls ( toolCalls : ChatCompletionToolCall [ ] , state : StreamingState ) : void {
69
69
for ( const toolCall of toolCalls ) {
70
70
const index = toolCall . index ;
71
- if ( index === undefined ) continue ;
71
+ if ( index === undefined || ! toolCall . function ) continue ;
72
72
73
73
// Initialize tool call if this is the first chunk for this index
74
74
if ( ! ( index in state . chatCompletionToolCalls ) ) {
75
75
state . chatCompletionToolCalls [ index ] = {
76
76
...toolCall ,
77
77
function : {
78
- name : toolCall . function ? .name || '' ,
79
- arguments : toolCall . function ? .arguments || '' ,
78
+ name : toolCall . function . name ,
79
+ arguments : toolCall . function . arguments || '' ,
80
80
} ,
81
81
} ;
82
82
} else {
83
83
// Accumulate function arguments from subsequent chunks
84
84
const existingToolCall = state . chatCompletionToolCalls [ index ] ;
85
- if ( toolCall . function ? .arguments && existingToolCall ?. function ) {
85
+ if ( toolCall . function . arguments && existingToolCall ?. function ) {
86
86
existingToolCall . function . arguments += toolCall . function . arguments ;
87
87
}
88
88
}
@@ -169,7 +169,7 @@ function processResponsesApiEvent(
169
169
if ( recordOutputs ) {
170
170
// Handle tool call events for Responses API
171
171
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 ) ;
173
173
}
174
174
175
175
if ( event . type === 'response.output_text.delta' && 'delta' in event && event . delta ) {
0 commit comments