@@ -7,6 +7,7 @@ import { MCP_TOOL_SEPARATOR } from '../mcp-constants'
77import { getMCPToolData } from '../mcp'
88import { getAgentShortName } from '../templates/prompts'
99import { codebuffToolHandlers } from './handlers/list'
10+ import { transformSpawnAgentsInput } from './handlers/tool/spawn-agent-utils'
1011import { ensureZodSchema } from './prompts'
1112
1213import type { AgentTemplateType } from '@codebuff/common/types/session-state'
@@ -187,12 +188,19 @@ export function executeToolCall<T extends ToolName>(
187188 return previousToolCallFinished
188189 }
189190
191+ // Transform spawn_agents input to use commander-lite fallback before streaming
192+ // This ensures the UI shows the correct agent type from the start
193+ const transformedInput =
194+ toolName === 'spawn_agents'
195+ ? transformSpawnAgentsInput ( input , agentTemplate . spawnableAgents )
196+ : input
197+
190198 // Only emit tool_call event after permission check passes
191199 onResponseChunk ( {
192200 type : 'tool_call' ,
193201 toolCallId,
194202 toolName,
195- input,
203+ input : transformedInput ,
196204 agentId : agentState . agentId ,
197205 parentAgentId : agentState . parentId ,
198206 includeToolCall : ! excludeToolFromMessageHistory ,
@@ -204,8 +212,16 @@ export function executeToolCall<T extends ToolName>(
204212 const handler = codebuffToolHandlers [
205213 toolName
206214 ] as unknown as CodebuffToolHandlerFunction < T >
215+
216+ // Use transformed input for spawn_agents so the handler receives the correct agent types
217+ const finalToolCall =
218+ toolName === 'spawn_agents'
219+ ? { ...toolCall , input : transformedInput }
220+ : toolCall
221+
207222 const toolResultPromise = handler ( {
208223 ...params ,
224+ toolCall : finalToolCall ,
209225 previousToolCallFinished,
210226 writeToClient : onResponseChunk ,
211227 requestClientToolCall : ( async (
@@ -222,7 +238,6 @@ export function executeToolCall<T extends ToolName>(
222238 } )
223239 return clientToolResult . output as CodebuffToolOutput < T >
224240 } ) as any ,
225- toolCall,
226241 } )
227242
228243 return toolResultPromise . then ( async ( { output, creditsUsed } ) => {
0 commit comments