From 3c1914c566fc8d6d0dd46b44ab4b34412d264224 Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Wed, 9 Jul 2025 10:23:44 -0700 Subject: [PATCH] Fix loop/parallel yaml --- apps/sim/lib/workflows/yaml-generator.ts | 15 +++++++++----- apps/sim/stores/workflows/yaml/importer.ts | 24 +++++++++++----------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/apps/sim/lib/workflows/yaml-generator.ts b/apps/sim/lib/workflows/yaml-generator.ts index 668c2932b0..e51cd6b0ee 100644 --- a/apps/sim/lib/workflows/yaml-generator.ts +++ b/apps/sim/lib/workflows/yaml-generator.ts @@ -41,8 +41,13 @@ function extractBlockInputs( if (blockState.data) { Object.entries(blockState.data).forEach(([key, value]) => { // Include relevant configuration properties - if (key === 'count' || key === 'loopType' || key === 'collection' || - key === 'parallelType' || key === 'distribution') { + if ( + key === 'count' || + key === 'loopType' || + key === 'collection' || + key === 'parallelType' || + key === 'distribution' + ) { if (value !== undefined && value !== null && value !== '') { inputs[key] = value } @@ -54,14 +59,14 @@ function extractBlockInputs( } }) } - + // Include any additional values from subBlockValues that might not be in data Object.entries(blockSubBlockValues).forEach(([key, value]) => { - if (value !== undefined && value !== null && value !== '' && !inputs.hasOwnProperty(key)) { + if (value !== undefined && value !== null && value !== '' && !Object.hasOwn(inputs, key)) { inputs[key] = value } }) - + return inputs } diff --git a/apps/sim/stores/workflows/yaml/importer.ts b/apps/sim/stores/workflows/yaml/importer.ts index 8157aab69e..18c5305864 100644 --- a/apps/sim/stores/workflows/yaml/importer.ts +++ b/apps/sim/stores/workflows/yaml/importer.ts @@ -266,17 +266,17 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[] const sorted: ImportedBlock[] = [] const processed = new Set() const visiting = new Set() // Track blocks currently being processed to detect cycles - + // Create a map for quick lookup const blockMap = new Map() - blocks.forEach(block => blockMap.set(block.id, block)) - + blocks.forEach((block) => blockMap.set(block.id, block)) + // Process blocks recursively, ensuring parents are added first function processBlock(block: ImportedBlock) { if (processed.has(block.id)) { return // Already processed } - + if (visiting.has(block.id)) { // Circular dependency detected - break the cycle by processing this block without its parent logger.warn(`Circular parent-child dependency detected for block ${block.id}, breaking cycle`) @@ -284,9 +284,9 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[] processed.add(block.id) return } - + visiting.add(block.id) - + // If this block has a parent, ensure the parent is processed first if (block.parentId) { const parentBlock = blockMap.get(block.parentId) @@ -294,16 +294,16 @@ function sortBlocksByParentChildOrder(blocks: ImportedBlock[]): ImportedBlock[] processBlock(parentBlock) } } - + // Now process this block visiting.delete(block.id) sorted.push(block) processed.add(block.id) } - + // Process all blocks - blocks.forEach(block => processBlock(block)) - + blocks.forEach((block) => processBlock(block)) + return sorted } @@ -623,8 +623,8 @@ export async function importWorkflowFromYaml( } else { logger.warn(`Parent block not found for mapping: ${blockData.data.parentId}`) // Remove invalid parent reference - delete blockData.data.parentId - delete blockData.data.extent + blockData.data.parentId = undefined + blockData.data.extent = undefined } } }