55 assistantMessage ,
66 userMessage ,
77} from '@codebuff/common/util/messages'
8- import { generateCompactId } from '@codebuff/common/util/string'
98
109import { processStreamWithTools } from '../tool-stream-parser'
1110import { INCLUDE_REASONING_IN_MESSAGE_HISTORY } from '../constants'
@@ -14,6 +13,7 @@ import {
1413 executeToolCall ,
1514 tryTransformAgentToolCall ,
1615} from './tool-executor'
16+ import { createToolCallIdGenerator } from '../util/tool-call-id'
1717import { withSystemTags } from '../util/messages'
1818
1919import type { CustomToolCall , ExecuteToolCallParams } from './tool-executor'
@@ -91,6 +91,7 @@ export async function processStream(
9191 const toolCalls : ( CodebuffToolCall | CustomToolCall ) [ ] = [ ]
9292 const toolCallsToAddToMessageHistory : ( CodebuffToolCall | CustomToolCall ) [ ] = [ ]
9393 const assistantMessages : Message [ ] = [ ]
94+ const getToolCallId = createToolCallIdGenerator ( params . messages )
9495 let hadToolCallError = false
9596 const errorMessages : Message [ ] = [ ]
9697 const { promise : streamDonePromise , resolve : resolveStreamDonePromise } =
@@ -137,7 +138,6 @@ export async function processStream(
137138 if ( signal . aborted ) {
138139 return
139140 }
140- const toolCallId = generateCompactId ( )
141141 const isNativeTool = toolNames . includes ( toolName as ToolName )
142142
143143 // Check if this is an agent tool call that should be transformed to spawn_agents
@@ -160,19 +160,20 @@ export async function processStream(
160160 // Determine which executor to use and with what parameters
161161 let toolPromise : Promise < void >
162162 if ( isNativeTool || transformed ) {
163+ const effectiveToolName = transformed
164+ ? transformed . toolName
165+ : ( toolName as ToolName )
163166 // Use executeToolCall for native tools or transformed agent calls
164167 toolPromise = executeToolCall ( {
165168 ...params ,
166- toolName : transformed
167- ? transformed . toolName
168- : ( toolName as ToolName ) ,
169+ toolName : effectiveToolName ,
169170 input : transformed ? transformed . input : input ,
170171 fromHandleSteps : false ,
171172
172173 fileProcessingState,
173174 fullResponse : fullResponseChunks . join ( '' ) ,
174175 previousToolCallFinished : previousPromise ,
175- toolCallId,
176+ toolCallId : getToolCallId ( effectiveToolName ) ,
176177 toolCalls,
177178 toolCallsToAddToMessageHistory,
178179 toolResults,
@@ -191,7 +192,7 @@ export async function processStream(
191192 fileProcessingState,
192193 fullResponse : fullResponseChunks . join ( '' ) ,
193194 previousToolCallFinished : previousPromise ,
194- toolCallId,
195+ toolCallId : getToolCallId ( toolName ) ,
195196 toolCalls,
196197 toolCallsToAddToMessageHistory,
197198 toolResults,
0 commit comments