MCPcopy Create free account
hub / github.com/simstudioai/sim / sanitizeBlock

Function sanitizeBlock

apps/sim/lib/workflows/sanitization/json-sanitizer.ts:483–559  ·  view source on GitHub ↗
(blockId: string, block: BlockState)

Source from the content-addressed store, hash-verified

481
482 // Helper to recursively sanitize a block and its children
483 const sanitizeBlock = (blockId: string, block: BlockState): CopilotBlockState => {
484 const connections = extractConnectionsForBlock(blockId, state.edges, block)
485
486 // For loop/parallel blocks, extract config from block.data instead of subBlocks
487 let inputs: Record<string, string | number | string[][] | object>
488
489 if (block.type === 'loop' || block.type === 'parallel') {
490 // Extract configuration from block.data (only include type-appropriate fields)
491 const loopInputs: Record<string, string | number | string[][] | object> = {}
492
493 if (block.type === 'loop') {
494 const loopType = block.data?.loopType || 'for'
495 loopInputs.loopType = loopType
496 // Only export fields relevant to the current loopType
497 if (loopType === 'for' && block.data?.count !== undefined) {
498 loopInputs.iterations = block.data.count
499 }
500 if (loopType === 'forEach' && block.data?.collection !== undefined) {
501 loopInputs.collection = block.data.collection
502 }
503 if (loopType === 'while' && block.data?.whileCondition !== undefined) {
504 loopInputs.condition = block.data.whileCondition
505 }
506 if (loopType === 'doWhile' && block.data?.doWhileCondition !== undefined) {
507 loopInputs.condition = block.data.doWhileCondition
508 }
509 } else if (block.type === 'parallel') {
510 const parallelType = block.data?.parallelType || 'count'
511 loopInputs.parallelType = parallelType
512 // Only export fields relevant to the current parallelType
513 if (parallelType === 'count' && block.data?.count !== undefined) {
514 loopInputs.iterations = block.data.count
515 }
516 if (parallelType === 'collection' && block.data?.collection !== undefined) {
517 loopInputs.collection = block.data.collection
518 }
519 }
520
521 inputs = loopInputs
522 } else {
523 // For regular blocks, sanitize subBlocks
524 inputs = sanitizeSubBlocks(block.subBlocks)
525 }
526
527 // Check if this is a loop or parallel (has children)
528 const childBlockIds = findChildBlocks(blockId)
529 const nestedNodes: Record<string, CopilotBlockState> = {}
530
531 if (childBlockIds.length > 0) {
532 // Recursively sanitize child blocks
533 childBlockIds.forEach((childId) => {
534 const childBlock = state.blocks[childId]
535 if (childBlock) {
536 nestedNodes[childId] = sanitizeBlock(childId, childBlock)
537 processedBlocks.add(childId)
538 }
539 })
540 }

Callers 1

sanitizeForCopilotFunction · 0.85

Calls 4

sanitizeSubBlocksFunction · 0.85
findChildBlocksFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected