@@ -36,8 +36,6 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
3636 private lastResponseId : string | undefined
3737 // Accumulate partial tool calls: call_id -> { name, arguments }
3838 private currentToolCalls : Map < string , { name : string ; arguments : string } > = new Map ( )
39- // Track yielded tool calls to avoid duplicates
40- private yieldedCallIds : Set < string > = new Set ( )
4139 // Abort controller for cancelling ongoing requests
4240 private abortController ?: AbortController
4341
@@ -157,7 +155,6 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
157155 this . lastResponseId = undefined
158156 // Reset tool call accumulator
159157 this . currentToolCalls . clear ( )
160- this . yieldedCallIds . clear ( )
161158
162159 // Use Responses API for ALL models
163160 const { verbosity, reasoning } = this . getModel ( )
@@ -1097,16 +1094,13 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
10971094 ) {
10981095 const callId = event . call_id || event . tool_call_id || event . id
10991096 if ( callId && this . currentToolCalls . has ( callId ) ) {
1100- if ( ! this . yieldedCallIds . has ( callId ) ) {
1101- const toolCall = this . currentToolCalls . get ( callId ) !
1102- // Yield the complete tool call with default empty JSON if arguments are missing
1103- yield {
1104- type : "tool_call" ,
1105- id : callId ,
1106- name : toolCall . name ,
1107- arguments : toolCall . arguments || "{}" ,
1108- }
1109- this . yieldedCallIds . add ( callId )
1097+ const toolCall = this . currentToolCalls . get ( callId ) !
1098+ // Yield the complete tool call
1099+ yield {
1100+ type : "tool_call" ,
1101+ id : callId ,
1102+ name : toolCall . name ,
1103+ arguments : toolCall . arguments ,
11101104 }
11111105 // Remove from accumulator
11121106 this . currentToolCalls . delete ( callId )
@@ -1135,15 +1129,14 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
11351129 ) {
11361130 // Handle complete tool/function call item
11371131 const callId = item . call_id || item . tool_call_id || item . id
1138- if ( callId && ! this . yieldedCallIds . has ( callId ) ) {
1132+ if ( callId && ! this . currentToolCalls . has ( callId ) ) {
11391133 const args = item . arguments || item . function ?. arguments || item . function_arguments
11401134 yield {
11411135 type : "tool_call" ,
11421136 id : callId ,
11431137 name : item . name || item . function ?. name || item . function_name || "" ,
11441138 arguments : typeof args === "string" ? args : "{}" ,
11451139 }
1146- this . yieldedCallIds . add ( callId )
11471140 }
11481141 }
11491142 }
@@ -1152,17 +1145,14 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
11521145
11531146 // Completion events that may carry usage
11541147 if ( event ?. type === "response.done" || event ?. type === "response.completed" ) {
1155- // Yield any pending tool calls that didn't get a 'done' event
1148+ // Yield any pending tool calls that didn't get a 'done' event (fallback)
11561149 if ( this . currentToolCalls . size > 0 ) {
11571150 for ( const [ callId , toolCall ] of this . currentToolCalls ) {
1158- if ( ! this . yieldedCallIds . has ( callId ) ) {
1159- yield {
1160- type : "tool_call" ,
1161- id : callId ,
1162- name : toolCall . name ,
1163- arguments : toolCall . arguments || "{}" ,
1164- }
1165- this . yieldedCallIds . add ( callId )
1151+ yield {
1152+ type : "tool_call" ,
1153+ id : callId ,
1154+ name : toolCall . name ,
1155+ arguments : toolCall . arguments || "{}" ,
11661156 }
11671157 }
11681158 this . currentToolCalls . clear ( )
0 commit comments