MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / updateSpawnAgentBlock

Function updateSpawnAgentBlock

cli/src/utils/sdk-event-handlers.ts:361–424  ·  view source on GitHub ↗
(
  block: ContentBlock,
  toolCallId: string,
  results: any[],
)

Source from the content-addressed store, hash-verified

359 * Recursively finds and updates agent blocks that match a spawn_agents tool call.
360 */
361const updateSpawnAgentBlock = (
362 block: ContentBlock,
363 toolCallId: string,
364 results: any[],
365): ContentBlock | null => {
366 if (block.type !== 'agent') {
367 return block
368 }
369
370 const spawnIndex = block.spawnIndex
371 const childBlocks = block.blocks
372 const isSpawnResultTarget =
373 block.spawnToolCallId === toolCallId &&
374 spawnIndex !== undefined &&
375 childBlocks
376
377 if (isSpawnResultTarget) {
378 const result = results[spawnIndex]
379 if (result?.value) {
380 const { content, hasError } = extractSpawnAgentResultContent(result.value)
381
382 if (hasError) {
383 if (childBlocks.length === 0) {
384 return null
385 }
386
387 return {
388 ...block,
389 blocks: content
390 ? [...childBlocks, { type: 'text', content } as ContentBlock]
391 : childBlocks,
392 status: 'complete' as const,
393 }
394 }
395
396 // Agents like thinker return all output at the end via lastMessage,
397 // while agents like basher may have already streamed their text.
398 const hasStreamedTextContent = childBlocks.some(
399 (b) => b.type === 'text' && b.textType === 'text',
400 )
401 const finalBlocks =
402 content && !hasStreamedTextContent
403 ? [...childBlocks, { type: 'text', content } as ContentBlock]
404 : childBlocks
405
406 if (finalBlocks.length > 0) {
407 return {
408 ...block,
409 blocks: finalBlocks,
410 status: 'complete' as const,
411 }
412 }
413 }
414 }
415
416 if (!childBlocks?.length) {
417 return block
418 }

Callers 1

updateSpawnAgentBlocksFunction · 0.85

Calls 2

updateSpawnAgentBlocksFunction · 0.85

Tested by

no test coverage detected