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

Function extractBlockById

cli/src/utils/message-block-helpers.ts:435–461  ·  view source on GitHub ↗
(
  blocks: ContentBlock[],
  targetAgentId: string,
)

Source from the content-addressed store, hash-verified

433 * Returns the remaining blocks and the extracted block (if found).
434 */
435export const extractBlockById = (
436 blocks: ContentBlock[],
437 targetAgentId: string,
438): { remainingBlocks: ContentBlock[]; extractedBlock: ContentBlock | null } => {
439 let extractedBlock: ContentBlock | null = null
440
441 const extractRecursively = (blocks: ContentBlock[]): ContentBlock[] => {
442 const result: ContentBlock[] = []
443 for (const block of blocks) {
444 if (block.type === 'agent' && block.agentId === targetAgentId) {
445 extractedBlock = block
446 // Don't add to result - we're extracting it
447 } else if (block.type === 'agent' && block.blocks) {
448 result.push({
449 ...block,
450 blocks: extractRecursively(block.blocks),
451 })
452 } else {
453 result.push(block)
454 }
455 }
456 return result
457 }
458
459 const remainingBlocks = extractRecursively(blocks)
460 return { remainingBlocks, extractedBlock }
461}
462
463export const moveSpawnAgentBlock = (
464 blocks: ContentBlock[],

Callers 2

moveSpawnAgentBlockFunction · 0.85

Calls 1

extractRecursivelyFunction · 0.85

Tested by

no test coverage detected