From 5201d44e14ae891518abef58bfb1bff48f82a3eb Mon Sep 17 00:00:00 2001 From: Chaitanya Eranki Date: Wed, 14 Jan 2026 10:09:22 -0600 Subject: [PATCH 1/2] Added fixes for tool call id bug --- src/core/api/providers/oca.ts | 50 +++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/core/api/providers/oca.ts b/src/core/api/providers/oca.ts index 7b9cacc284c..8e1f7b77295 100644 --- a/src/core/api/providers/oca.ts +++ b/src/core/api/providers/oca.ts @@ -165,9 +165,38 @@ export class OcaHandler implements ApiHandler { } } + convertToolsToChatFormat( + messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[], + ): OpenAI.Chat.Completions.ChatCompletionMessageParam[] { + const updateToolCallId = (toolCallId: string) => { + return toolCallId.replace("fc", "call").substring(0, 29) + } + + return messages.map((message) => { + if (message.role == "tool") { + const tool_call_id = message.tool_call_id + if (tool_call_id.startsWith("fc")) { + message.tool_call_id = updateToolCallId(tool_call_id) + } + } else if (message.role == "assistant" && message.tool_calls) { + const new_tool_calls = message.tool_calls.map((toolCall) => { + if (toolCall.id.startsWith("fc")) { + toolCall.id = updateToolCallId(toolCall.id) + } + return toolCall + }) + message.tool_calls = new_tool_calls + } + return message + }) + } + async *createMessageChatApi(systemPrompt: string, messages: ClineStorageMessage[], tools?: OpenAITool[]): ApiStream { const client = this.ensureClient() - const formattedMessages = convertToOpenAiMessages(messages) + + let formattedMessages = convertToOpenAiMessages(messages) + formattedMessages = this.convertToolsToChatFormat(formattedMessages) + const systemMessage: OpenAI.Chat.ChatCompletionSystemMessageParam = { role: "system", content: systemPrompt, @@ -302,14 +331,31 @@ export class OcaHandler implements ApiHandler { } } + convertIdToResponseFormat(input: OpenAI.Responses.ResponseInputItem[]): OpenAI.Responses.ResponseInputItem[] { + return input.map((message) => { + if (message.type == "function_call" || message.type == "function_call_output") { + const id = message.id + const callId = message.call_id + if (id && id.startsWith("call")) { + message.id = id.replace("call", "fc") + } + if (callId && callId.startsWith("call")) { + message.call_id = callId.replace("call", "fc") + } + } + return message + }) + } + async *createMessageResponsesApi(systemPrompt: string, messages: ClineStorageMessage[], tools?: OpenAITool[]): ApiStream { const client = this.ensureClient() // Convert messages to Responses API input format - const input: OpenAI.Responses.ResponseInputItem[] = [ + let input: OpenAI.Responses.ResponseInputItem[] = [ { role: "system", content: systemPrompt }, ...convertToOpenAIResponsesInput(messages), ] + input = this.convertIdToResponseFormat(input) // Convert ChatCompletion tools to Responses API format if provided const responseTools = tools From bbf43416039c5f9e4dbeda1206a71b5e34e66828 Mon Sep 17 00:00:00 2001 From: Chaitanya Eranki Date: Wed, 14 Jan 2026 10:20:32 -0600 Subject: [PATCH 2/2] Made changes to make code cleaner --- src/core/api/providers/oca.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/api/providers/oca.ts b/src/core/api/providers/oca.ts index 8e1f7b77295..8cd71710a11 100644 --- a/src/core/api/providers/oca.ts +++ b/src/core/api/providers/oca.ts @@ -332,15 +332,19 @@ export class OcaHandler implements ApiHandler { } convertIdToResponseFormat(input: OpenAI.Responses.ResponseInputItem[]): OpenAI.Responses.ResponseInputItem[] { + const updateToolCallId = (toolCallId: string) => { + return toolCallId.replace("call", "fc") + } + return input.map((message) => { if (message.type == "function_call" || message.type == "function_call_output") { const id = message.id const callId = message.call_id if (id && id.startsWith("call")) { - message.id = id.replace("call", "fc") + message.id = updateToolCallId(id) } if (callId && callId.startsWith("call")) { - message.call_id = callId.replace("call", "fc") + message.call_id = updateToolCallId(callId) } } return message