@@ -351,7 +351,7 @@ export async function importWorkflowFromYaml(
351351 } ,
352352 targetWorkflowId ?: string
353353) : Promise < { success : boolean ; errors : string [ ] ; warnings : string [ ] ; summary ?: string } > {
354- logger . info ( 'Starting YAML workflow import (complete state creation)' )
354+
355355
356356 try {
357357 // Parse YAML
@@ -368,13 +368,7 @@ export async function importWorkflowFromYaml(
368368 return { success : false , errors, warnings }
369369 }
370370
371- logger . info (
372- `Creating complete workflow state with ${ blocks . length } blocks and ${ edges . length } edges`
373- )
374- logger . debug (
375- 'Blocks to import:' ,
376- blocks . map ( ( b ) => `${ b . id } (${ b . type } ): ${ b . name } ` )
377- )
371+
378372
379373 // Get the existing workflow state (to preserve starter blocks if they exist)
380374 let existingBlocks : Record < string , any > = { }
@@ -386,23 +380,19 @@ export async function importWorkflowFromYaml(
386380 if ( response . ok ) {
387381 const workflowData = await response . json ( )
388382 existingBlocks = workflowData . data ?. state ?. blocks || { }
389- logger . debug (
390- `Fetched existing blocks for target workflow ${ targetWorkflowId } :` ,
391- Object . keys ( existingBlocks )
392- )
383+
393384 }
394- } catch ( error ) {
395- logger . warn ( `Failed to fetch existing blocks for workflow ${ targetWorkflowId } :` , error )
385+ } catch ( error ) {
386+ logger . warn ( `Failed to fetch existing blocks for workflow ${ targetWorkflowId } :` , error )
387+ }
388+ } else {
389+ // For active workflow, use from store
390+ existingBlocks = workflowActions . getExistingBlocks ( )
396391 }
397- } else {
398- // For active workflow, use from store
399- existingBlocks = workflowActions . getExistingBlocks ( )
400- }
401-
402- const existingStarterBlocks = Object . values ( existingBlocks ) . filter (
403- ( block : any ) => block . type === 'starter'
404- )
405- logger . debug ( `Found ${ existingStarterBlocks . length } existing starter blocks` )
392+
393+ const existingStarterBlocks = Object . values ( existingBlocks ) . filter (
394+ ( block : any ) => block . type === 'starter'
395+ )
406396
407397 // Get stores and current workflow info
408398 const { useWorkflowStore } = require ( '@/stores/workflows/workflow/store' )
@@ -417,9 +407,7 @@ export async function importWorkflowFromYaml(
417407 return { success : false , errors : [ 'No active workflow' ] , warnings : [ ] }
418408 }
419409
420- logger . info (
421- `Importing YAML into workflow: ${ activeWorkflowId } ${ targetWorkflowId ? '(specified target)' : '(active workflow)' } `
422- )
410+
423411
424412 // Build complete blocks object
425413 const completeBlocks : Record < string , any > = { }
@@ -456,7 +444,7 @@ export async function importWorkflowFromYaml(
456444 ...starterBlock . inputs , // Override with YAML values
457445 }
458446
459- logger . debug ( `Using existing starter block: ${ existingStarter . id } ` )
447+
460448 } else {
461449 // Create new starter block
462450 starterBlockId = crypto . randomUUID ( )
@@ -491,7 +479,7 @@ export async function importWorkflowFromYaml(
491479 // Set starter block values
492480 completeSubBlockValues [ starterBlockId ] = { ...starterBlock . inputs }
493481
494- logger . debug ( `Created new starter block: ${ starterBlockId } ` )
482+
495483 }
496484 }
497485 }
@@ -500,7 +488,7 @@ export async function importWorkflowFromYaml(
500488 let blocksProcessed = 0
501489 for ( const block of blocks ) {
502490 if ( block . type === 'starter' ) {
503- logger . debug ( `Skipping starter block: ${ block . id } (already handled)` )
491+
504492 continue // Already handled above
505493 }
506494
@@ -528,7 +516,6 @@ export async function importWorkflowFromYaml(
528516
529517 completeSubBlockValues [ blockId ] = { ...block . inputs }
530518 blocksProcessed ++
531- logger . debug ( `Prepared ${ block . type } block: ${ blockId } -> ${ block . name } ` )
532519 } else if ( blockConfig ) {
533520 // Handle regular blocks
534521 const subBlocks : Record < string , any > = { }
@@ -557,15 +544,12 @@ export async function importWorkflowFromYaml(
557544 // Set block input values
558545 completeSubBlockValues [ blockId ] = { ...block . inputs }
559546 blocksProcessed ++
560- logger . debug ( `Prepared ${ block . type } block: ${ blockId } -> ${ block . name } ` )
561547 } else {
562548 logger . warn ( `No block config found for type: ${ block . type } (block: ${ block . id } )` )
563549 }
564550 }
565551
566- logger . info (
567- `Processed ${ blocksProcessed } non-starter blocks, total blocks in state: ${ Object . keys ( completeBlocks ) . length } `
568- )
552+
569553
570554 // Create complete edges using the ID mapping
571555 const completeEdges : any [ ] = [ ]
@@ -579,14 +563,13 @@ export async function importWorkflowFromYaml(
579563 source : sourceId ,
580564 target : targetId ,
581565 } )
582- logger . debug ( `Prepared edge: ${ sourceId } -> ${ targetId } ` )
566+
583567 } else {
584568 logger . warn ( `Skipping edge - missing blocks: ${ edge . source } -> ${ edge . target } ` )
585569 }
586570 }
587571
588572 // Create complete workflow state with values already set in subBlocks
589- logger . info ( 'Creating complete workflow state with embedded values...' )
590573
591574 // Merge subblock values directly into block subBlocks
592575 for ( const [ blockId , blockData ] of Object . entries ( completeBlocks ) ) {
@@ -596,9 +579,6 @@ export async function importWorkflowFromYaml(
596579 for ( const [ subBlockId , subBlockData ] of Object . entries ( blockData . subBlocks || { } ) ) {
597580 if ( blockValues [ subBlockId ] !== undefined && blockValues [ subBlockId ] !== null ) {
598581 ; ( subBlockData as any ) . value = blockValues [ subBlockId ]
599- logger . debug (
600- `Embedded value in block: ${ blockId } .${ subBlockId } = ${ blockValues [ subBlockId ] } `
601- )
602582 }
603583 }
604584 }
@@ -617,14 +597,7 @@ export async function importWorkflowFromYaml(
617597 hasActiveWebhook : false ,
618598 }
619599
620- // Save directly to database via API
621- logger . info ( 'Saving complete workflow state directly to database...' )
622- logger . debug ( 'Sample block being saved:' , {
623- firstBlockId : Object . keys ( completeBlocks ) [ 0 ] ,
624- firstBlock : Object . values ( completeBlocks ) [ 0 ] ,
625- firstBlockSubBlocks : Object . values ( completeBlocks ) [ 0 ] ?. subBlocks ,
626- } )
627-
600+ // Save directly to database via API
628601 const response = await fetch ( `/api/workflows/${ activeWorkflowId } /state` , {
629602 method : 'PUT' ,
630603 headers : {
@@ -644,42 +617,30 @@ export async function importWorkflowFromYaml(
644617 }
645618
646619 const saveResponse = await response . json ( )
647- logger . info ( 'Successfully saved to database:' , saveResponse )
648620
649621 // Update local state for immediate UI display (only if importing into active workflow)
650622 if ( ! targetWorkflowId ) {
651- logger . info ( 'Updating local state for immediate display (active workflow)...' )
652623 useWorkflowStore . setState ( completeWorkflowState )
653624
654- // Set subblock values in local store
655- logger . debug ( 'Setting SubBlockStore with values:' , completeSubBlockValues )
625+ // Set subblock values in local store
656626 useSubBlockStore . setState ( ( state : any ) => ( {
657627 workflowValues : {
658628 ...state . workflowValues ,
659629 [ activeWorkflowId ] : completeSubBlockValues ,
660630 } ,
661631 } ) )
662-
663- // Verify SubBlockStore was updated
664- const subBlockStoreValues = useSubBlockStore . getState ( ) . workflowValues [ activeWorkflowId ]
665- logger . debug ( 'SubBlockStore after update:' , subBlockStoreValues )
666- } else {
667- logger . info ( 'Skipping local state update (importing into non-active workflow)' )
668- }
632+ }
669633
670634 // Brief delay for UI to update
671635 await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) )
672636
673637 // Apply auto layout
674- logger . info ( 'Applying auto layout...' )
675638 workflowActions . applyAutoLayout ( )
676639
677640 const totalBlocksCreated =
678641 Object . keys ( completeBlocks ) . length - ( existingStarterBlocks . length > 0 ? 1 : 0 )
679642
680- logger . info (
681- `Successfully imported workflow: ${ totalBlocksCreated } blocks created, ${ completeEdges . length } edges, values set for ${ Object . keys ( completeSubBlockValues ) . length } blocks`
682- )
643+
683644
684645 return {
685646 success : true ,
0 commit comments