@@ -4,8 +4,6 @@ import OpenAI from "openai"
44import { rooDefaultModelId , getApiProtocol , type ImageGenerationApiMethod } from "@roo-code/types"
55import { CloudService } from "@roo-code/cloud"
66
7- import { NativeToolCallParser } from "../../core/assistant-message/NativeToolCallParser"
8-
97import { Package } from "../../shared/package"
108import type { ApiHandlerOptions } from "../../shared/api"
119import { ApiStream } from "../transform/stream"
@@ -142,6 +140,7 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
142140 const stream = await this . createStream ( systemPrompt , messages , metadata , { headers } )
143141
144142 let lastUsage : RooUsage | undefined = undefined
143+ const activeToolCallIds = new Set < string > ( )
145144 // Accumulator for reasoning_details FROM the API.
146145 // We preserve the original shape of reasoning_details to prevent malformed responses.
147146 const reasoningDetailsAccumulator = new Map <
@@ -257,6 +256,9 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
257256 // Emit raw tool call chunks - NativeToolCallParser handles state management
258257 if ( "tool_calls" in delta && Array . isArray ( delta . tool_calls ) ) {
259258 for ( const toolCall of delta . tool_calls ) {
259+ if ( toolCall . id ) {
260+ activeToolCallIds . add ( toolCall . id )
261+ }
260262 yield {
261263 type : "tool_call_partial" ,
262264 index : toolCall . index ,
@@ -275,11 +277,11 @@ export class RooHandler extends BaseOpenAiCompatibleProvider<string> {
275277 }
276278 }
277279
278- if ( finishReason ) {
279- const endEvents = NativeToolCallParser . processFinishReason ( finishReason )
280- for ( const event of endEvents ) {
281- yield event
280+ if ( finishReason === "tool_calls" && activeToolCallIds . size > 0 ) {
281+ for ( const id of activeToolCallIds ) {
282+ yield { type : "tool_call_end" , id }
282283 }
284+ activeToolCallIds . clear ( )
283285 }
284286
285287 if ( chunk . usage ) {
0 commit comments