@@ -367,8 +367,13 @@ export async function importWorkflowFromYaml(
367367 return { success : false , errors, warnings }
368368 }
369369
370- logger . info ( `Creating complete workflow state with ${ blocks . length } blocks and ${ edges . length } edges` )
371- logger . debug ( 'Blocks to import:' , blocks . map ( b => `${ b . id } (${ b . type } ): ${ b . name } ` ) )
370+ logger . info (
371+ `Creating complete workflow state with ${ blocks . length } blocks and ${ edges . length } edges`
372+ )
373+ logger . debug (
374+ 'Blocks to import:' ,
375+ blocks . map ( ( b ) => `${ b . id } (${ b . type } ): ${ b . name } ` )
376+ )
372377
373378 // Get the existing workflow state (to preserve starter blocks if they exist)
374379 const existingBlocks = workflowActions . getExistingBlocks ( )
@@ -397,39 +402,40 @@ export async function importWorkflowFromYaml(
397402
398403 // Handle starter block
399404 let starterBlockId : string | null = null
400- const starterBlock = blocks . find ( block => block . type === 'starter' )
401-
405+ const starterBlock = blocks . find ( ( block ) => block . type === 'starter' )
406+
402407 if ( starterBlock ) {
403408 if ( existingStarterBlocks . length > 0 ) {
404409 // Use existing starter block
405410 const existingStarter = existingStarterBlocks [ 0 ] as any
406411 starterBlockId = existingStarter . id
407412 yamlIdToActualId . set ( starterBlock . id , existingStarter . id )
408-
413+
409414 // Keep existing starter but update its inputs
410415 completeBlocks [ existingStarter . id ] = {
411416 ...existingStarter ,
412417 // Update name if provided in YAML
413418 name : starterBlock . name !== 'Start' ? starterBlock . name : existingStarter . name ,
414419 }
415-
420+
416421 // Set starter block values
417422 completeSubBlockValues [ existingStarter . id ] = {
418- ...currentWorkflowState . blocks [ existingStarter . id ] ?. subBlocks ?
419- Object . fromEntries (
420- Object . entries ( currentWorkflowState . blocks [ existingStarter . id ] . subBlocks ) . map (
421- ( [ key , subBlock ] : [ string , any ] ) => [ key , subBlock . value ]
423+ ...( currentWorkflowState . blocks [ existingStarter . id ] ?. subBlocks
424+ ? Object . fromEntries (
425+ Object . entries ( currentWorkflowState . blocks [ existingStarter . id ] . subBlocks ) . map (
426+ ( [ key , subBlock ] : [ string , any ] ) => [ key , subBlock . value ]
427+ )
422428 )
423- ) : { } ,
424- ...starterBlock . inputs // Override with YAML values
429+ : { } ) ,
430+ ...starterBlock . inputs , // Override with YAML values
425431 }
426-
432+
427433 logger . debug ( `Using existing starter block: ${ existingStarter . id } ` )
428434 } else {
429435 // Create new starter block
430436 starterBlockId = crypto . randomUUID ( )
431437 yamlIdToActualId . set ( starterBlock . id , starterBlockId )
432-
438+
433439 // Create complete starter block from block config
434440 const blockConfig = getBlock ( 'starter' )
435441 if ( blockConfig ) {
@@ -441,7 +447,7 @@ export async function importWorkflowFromYaml(
441447 value : null ,
442448 }
443449 } )
444-
450+
445451 completeBlocks [ starterBlockId ] = {
446452 id : starterBlockId ,
447453 type : 'starter' ,
@@ -455,10 +461,10 @@ export async function importWorkflowFromYaml(
455461 height : 0 ,
456462 data : starterBlock . data || { } ,
457463 }
458-
464+
459465 // Set starter block values
460466 completeSubBlockValues [ starterBlockId ] = { ...starterBlock . inputs }
461-
467+
462468 logger . debug ( `Created new starter block: ${ starterBlockId } ` )
463469 }
464470 }
@@ -477,7 +483,7 @@ export async function importWorkflowFromYaml(
477483
478484 // Create complete block from block config
479485 const blockConfig = getBlock ( block . type )
480-
486+
481487 if ( ! blockConfig && ( block . type === 'loop' || block . type === 'parallel' ) ) {
482488 // Handle loop/parallel blocks
483489 completeBlocks [ blockId ] = {
@@ -493,7 +499,7 @@ export async function importWorkflowFromYaml(
493499 height : 0 ,
494500 data : block . data || { } ,
495501 }
496-
502+
497503 completeSubBlockValues [ blockId ] = { ...block . inputs }
498504 blocksProcessed ++
499505 logger . debug ( `Prepared ${ block . type } block: ${ blockId } -> ${ block . name } ` )
@@ -521,7 +527,7 @@ export async function importWorkflowFromYaml(
521527 height : 0 ,
522528 data : block . data || { } ,
523529 }
524-
530+
525531 // Set block input values
526532 completeSubBlockValues [ blockId ] = { ...block . inputs }
527533 blocksProcessed ++
@@ -530,15 +536,17 @@ export async function importWorkflowFromYaml(
530536 logger . warn ( `No block config found for type: ${ block . type } (block: ${ block . id } )` )
531537 }
532538 }
533-
534- logger . info ( `Processed ${ blocksProcessed } non-starter blocks, total blocks in state: ${ Object . keys ( completeBlocks ) . length } ` )
539+
540+ logger . info (
541+ `Processed ${ blocksProcessed } non-starter blocks, total blocks in state: ${ Object . keys ( completeBlocks ) . length } `
542+ )
535543
536544 // Create complete edges using the ID mapping
537545 const completeEdges : any [ ] = [ ]
538546 for ( const edge of edges ) {
539547 const sourceId = yamlIdToActualId . get ( edge . source )
540548 const targetId = yamlIdToActualId . get ( edge . target )
541-
549+
542550 if ( sourceId && targetId ) {
543551 completeEdges . push ( {
544552 ...edge ,
@@ -553,16 +561,18 @@ export async function importWorkflowFromYaml(
553561
554562 // Create complete workflow state with values already set in subBlocks
555563 logger . info ( 'Creating complete workflow state with embedded values...' )
556-
564+
557565 // Merge subblock values directly into block subBlocks
558566 for ( const [ blockId , blockData ] of Object . entries ( completeBlocks ) ) {
559567 const blockValues = completeSubBlockValues [ blockId ] || { }
560-
568+
561569 // Update subBlock values in place
562570 for ( const [ subBlockId , subBlockData ] of Object . entries ( blockData . subBlocks || { } ) ) {
563571 if ( blockValues [ subBlockId ] !== undefined && blockValues [ subBlockId ] !== null ) {
564- ( subBlockData as any ) . value = blockValues [ subBlockId ]
565- logger . debug ( `Embedded value in block: ${ blockId } .${ subBlockId } = ${ blockValues [ subBlockId ] } ` )
572+ ; ( subBlockData as any ) . value = blockValues [ subBlockId ]
573+ logger . debug (
574+ `Embedded value in block: ${ blockId } .${ subBlockId } = ${ blockValues [ subBlockId ] } `
575+ )
566576 }
567577 }
568578 }
@@ -623,16 +633,21 @@ export async function importWorkflowFromYaml(
623633 logger . info ( 'Applying auto layout...' )
624634 workflowActions . applyAutoLayout ( )
625635
626- const totalBlocksCreated = Object . keys ( completeBlocks ) . length - ( existingStarterBlocks . length > 0 ? 1 : 0 )
627-
628- logger . info ( `Successfully imported workflow: ${ totalBlocksCreated } blocks created, ${ completeEdges . length } edges, values set for ${ Object . keys ( completeSubBlockValues ) . length } blocks` )
636+ const totalBlocksCreated =
637+ Object . keys ( completeBlocks ) . length - ( existingStarterBlocks . length > 0 ? 1 : 0 )
638+
639+ logger . info (
640+ `Successfully imported workflow: ${ totalBlocksCreated } blocks created, ${ completeEdges . length } edges, values set for ${ Object . keys ( completeSubBlockValues ) . length } blocks`
641+ )
629642
630643 return {
631644 success : true ,
632645 errors : [ ] ,
633646 warnings,
634647 summary : `Imported ${ totalBlocksCreated } new blocks and ${ completeEdges . length } connections. ${
635- existingStarterBlocks . length > 0 ? 'Updated existing starter block.' : 'Created new starter block.'
648+ existingStarterBlocks . length > 0
649+ ? 'Updated existing starter block.'
650+ : 'Created new starter block.'
636651 } `,
637652 }
638653 } catch ( error ) {
0 commit comments