@@ -9,8 +9,18 @@ interface YamlBlock {
99 type : string
1010 name : string
1111 inputs ?: Record < string , any >
12- preceding ?: string [ ]
13- following ?: string [ ]
12+ connections ?: {
13+ incoming ?: Array < {
14+ source : string
15+ sourceHandle ?: string
16+ targetHandle ?: string
17+ } >
18+ outgoing ?: Array < {
19+ target : string
20+ sourceHandle ?: string
21+ targetHandle ?: string
22+ } >
23+ }
1424 parentId ?: string // Add parentId for nested blocks
1525}
1626
@@ -120,23 +130,28 @@ function validateBlockReferences(yamlWorkflow: YamlWorkflow): string[] {
120130 const blockIds = new Set ( Object . keys ( yamlWorkflow . blocks ) )
121131
122132 Object . entries ( yamlWorkflow . blocks ) . forEach ( ( [ blockId , block ] ) => {
123- // Check preceding references
124- if ( block . preceding ) {
125- block . preceding . forEach ( ( precedingId ) => {
126- if ( ! blockIds . has ( precedingId ) ) {
127- errors . push ( `Block '${ blockId } ' references non-existent preceding block '${ precedingId } '` )
133+ // Check incoming connection references
134+ if ( block . connections ?. incoming ) {
135+ block . connections . incoming . forEach ( ( connection ) => {
136+ if ( ! blockIds . has ( connection . source ) ) {
137+ errors . push ( `Block '${ blockId } ' references non-existent source block '${ connection . source } '` )
128138 }
129139 } )
130140 }
131141
132- // Check following references
133- if ( block . following ) {
134- block . following . forEach ( ( followingId ) => {
135- if ( ! blockIds . has ( followingId ) ) {
136- errors . push ( `Block '${ blockId } ' references non-existent following block '${ followingId } '` )
142+ // Check outgoing connection references
143+ if ( block . connections ?. outgoing ) {
144+ block . connections . outgoing . forEach ( ( connection ) => {
145+ if ( ! blockIds . has ( connection . target ) ) {
146+ errors . push ( `Block '${ blockId } ' references non-existent target block '${ connection . target } '` )
137147 }
138148 } )
139149 }
150+
151+ // Check parent references
152+ if ( block . parentId && ! blockIds . has ( block . parentId ) ) {
153+ errors . push ( `Block '${ blockId } ' references non-existent parent block '${ block . parentId } '` )
154+ }
140155 } )
141156
142157 return errors
@@ -190,10 +205,10 @@ function calculateBlockPositions(
190205 const positions : Record < string , { x : number ; y : number } > = { }
191206 const blockIds = Object . keys ( yamlWorkflow . blocks )
192207
193- // Find starter blocks (no preceding connections)
208+ // Find starter blocks (no incoming connections)
194209 const starterBlocks = blockIds . filter ( ( id ) => {
195210 const block = yamlWorkflow . blocks [ id ]
196- return ! block . preceding || block . preceding . length === 0
211+ return ! block . connections ?. incoming || block . connections . incoming . length === 0
197212 } )
198213
199214 // If no starter blocks found, use first block as starter
@@ -220,10 +235,10 @@ function calculateBlockPositions(
220235
221236 // Add following blocks to queue
222237 const block = yamlWorkflow . blocks [ blockId ]
223- if ( block . following ) {
224- block . following . forEach ( ( followingId ) => {
225- if ( ! visited . has ( followingId ) ) {
226- queue . push ( followingId )
238+ if ( block . connections ?. outgoing ) {
239+ block . connections . outgoing . forEach ( ( connection ) => {
240+ if ( ! visited . has ( connection . target ) ) {
241+ queue . push ( connection . target )
227242 }
228243 } )
229244 }
@@ -375,16 +390,16 @@ export function convertYamlToWorkflow(yamlWorkflow: YamlWorkflow): ImportResult
375390
376391 // Convert edges from connections
377392 Object . entries ( yamlWorkflow . blocks ) . forEach ( ( [ blockId , yamlBlock ] ) => {
378- if ( yamlBlock . following ) {
379- yamlBlock . following . forEach ( ( targetId ) => {
380- const edgeId = `${ blockId } -${ targetId } -${ Date . now ( ) } `
393+ if ( yamlBlock . connections ?. outgoing ) {
394+ yamlBlock . connections . outgoing . forEach ( ( connection ) => {
395+ const edgeId = `${ blockId } -${ connection . target } -${ Date . now ( ) } `
381396
382397 const edge : ImportedEdge = {
383398 id : edgeId ,
384399 source : blockId ,
385- target : targetId ,
386- sourceHandle : 'source' ,
387- targetHandle : 'target' ,
400+ target : connection . target ,
401+ sourceHandle : connection . sourceHandle || 'source' ,
402+ targetHandle : connection . targetHandle || 'target' ,
388403 type : 'workflowEdge' ,
389404 }
390405
0 commit comments