55 assistantMessage ,
66 userMessage ,
77} from '@codebuff/common/util/messages'
8+ import { generateCompactId } from '@codebuff/common/util/string'
89
910import { processStreamWithTools } from '../tool-stream-parser'
1011import { INCLUDE_REASONING_IN_MESSAGE_HISTORY } from '../constants'
@@ -13,7 +14,6 @@ import {
1314 executeToolCall ,
1415 tryTransformAgentToolCall ,
1516} 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,7 +91,6 @@ export async function processStream(
9191 const toolCalls : ( CodebuffToolCall | CustomToolCall ) [ ] = [ ]
9292 const toolCallsToAddToMessageHistory : ( CodebuffToolCall | CustomToolCall ) [ ] = [ ]
9393 const assistantMessages : Message [ ] = [ ]
94- const getToolCallId = createToolCallIdGenerator ( params . messages )
9594 let hadToolCallError = false
9695 const errorMessages : Message [ ] = [ ]
9796 const { promise : streamDonePromise , resolve : resolveStreamDonePromise } =
@@ -138,6 +137,7 @@ export async function processStream(
138137 if ( signal . aborted ) {
139138 return
140139 }
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,20 +160,19 @@ 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 )
166163 // Use executeToolCall for native tools or transformed agent calls
167164 toolPromise = executeToolCall ( {
168165 ...params ,
169- toolName : effectiveToolName ,
166+ toolName : transformed
167+ ? transformed . toolName
168+ : ( toolName as ToolName ) ,
170169 input : transformed ? transformed . input : input ,
171170 fromHandleSteps : false ,
172171
173172 fileProcessingState,
174173 fullResponse : fullResponseChunks . join ( '' ) ,
175174 previousToolCallFinished : previousPromise ,
176- toolCallId : getToolCallId ( effectiveToolName ) ,
175+ toolCallId,
177176 toolCalls,
178177 toolCallsToAddToMessageHistory,
179178 toolResults,
@@ -192,7 +191,7 @@ export async function processStream(
192191 fileProcessingState,
193192 fullResponse : fullResponseChunks . join ( '' ) ,
194193 previousToolCallFinished : previousPromise ,
195- toolCallId : getToolCallId ( toolName ) ,
194+ toolCallId,
196195 toolCalls,
197196 toolCallsToAddToMessageHistory,
198197 toolResults,
0 commit comments