@@ -16,48 +16,60 @@ import { setTaskArgument } from "./setTaskArgument";
1616
1717type NodeInfo = {
1818 id : string ;
19- handle ?: string ;
2019 type ?: NodeType ;
20+ handle ?: {
21+ taskId : string ;
22+ handleName : string ;
23+ } ;
2124} ;
2225
2326export const handleConnection = (
2427 graphSpec : GraphSpec ,
2528 connection : Connection ,
2629 nodeManager : NodeManager ,
2730) => {
28- const sourceId = nodeManager . getTaskId ( connection . source ) ;
29- const targetId = nodeManager . getTaskId ( connection . target ) ;
30-
31- if ( ! sourceId || ! targetId ) {
32- console . warn ( "Source or Target ID is missing in the connection." ) ;
31+ const sourceId = nodeManager . getTaskId ( connection . source ! ) ;
32+ const sourceType = nodeManager . getNodeType ( connection . source ! ) ;
33+
34+ const targetId = nodeManager . getTaskId ( connection . target ! ) ;
35+ const targetType = nodeManager . getNodeType ( connection . target ! ) ;
36+
37+ if ( ! sourceId || ! targetId || ! sourceType || ! targetType ) {
38+ console . error ( "Could not resolve node information:" , {
39+ sourceId,
40+ sourceType,
41+ targetId,
42+ targetType,
43+ } ) ;
3344 return graphSpec ;
3445 }
3546
3647 if ( sourceId === targetId ) {
37- console . warn (
38- "Source and Target IDs are the same. Self-connections are not allowed." ,
39- ) ;
48+ console . warn ( "Cannot connect node to itself" ) ;
4049 return graphSpec ;
4150 }
4251
43- const sourceHandleId = connection . sourceHandle
44- ? nodeManager . getTaskId ( connection . sourceHandle )
45- : undefined ;
52+ let sourceHandleInfo : { taskId : string ; handleName : string } | undefined ;
53+ let targetHandleInfo : { taskId : string ; handleName : string } | undefined ;
54+
55+ if ( connection . sourceHandle ) {
56+ sourceHandleInfo = nodeManager . getHandleInfo ( connection . sourceHandle ) ;
57+ }
4658
47- const targetHandleId = connection . targetHandle
48- ? nodeManager . getTaskId ( connection . targetHandle )
49- : undefined ;
59+ if ( connection . targetHandle ) {
60+ targetHandleInfo = nodeManager . getHandleInfo ( connection . targetHandle ) ;
61+ }
5062
5163 const source : NodeInfo = {
5264 id : sourceId ,
53- handle : sourceHandleId ,
54- type : nodeManager . getNodeType ( connection . source ) ,
65+ type : sourceType ,
66+ handle : sourceHandleInfo ,
5567 } ;
5668
5769 const target : NodeInfo = {
5870 id : targetId ,
59- handle : targetHandleId ,
60- type : nodeManager . getNodeType ( connection . target ) ,
71+ type : targetType ,
72+ handle : targetHandleInfo ,
6173 } ;
6274
6375 const connectionType = `${ source . type } _to_${ target . type } ` as const ;
@@ -73,7 +85,7 @@ export const handleConnection = (
7385 return handleTaskToGraphOutput ( graphSpec , source , target ) ;
7486
7587 default :
76- console . warn ( "Unsupported connection pattern:" , connectionType ) ;
88+ console . error ( "Unsupported connection pattern:" , connectionType ) ;
7789 return graphSpec ;
7890 }
7991} ;
@@ -83,16 +95,19 @@ const handleGraphInputToTask = (
8395 source : NodeInfo ,
8496 target : NodeInfo ,
8597) : GraphSpec => {
86- if ( ! target . handle ) {
87- console . warn ( "Handle ID is missing for target task node." ) ;
98+ if ( ! target . handle ?. handleName ) {
99+ console . error (
100+ "Target handle name missing for graph input to task connection" ,
101+ ) ;
88102 return graphSpec ;
89103 }
90104
91- const sourceInputName = inputIdToInputName ( source . id ) ;
92- const targetInputName = inputIdToInputName ( target . handle ) ;
105+ const inputId = source . id ;
106+ const inputName = inputIdToInputName ( inputId ) ;
107+ const targetInputName = target . handle . handleName ;
93108
94109 const graphInputArgument : GraphInputArgument = {
95- graphInput : { inputName : sourceInputName } ,
110+ graphInput : { inputName } ,
96111 } ;
97112
98113 return setTaskArgument (
@@ -108,18 +123,18 @@ const handleTaskToTask = (
108123 source : NodeInfo ,
109124 target : NodeInfo ,
110125) : GraphSpec => {
111- if ( ! source . handle ) {
112- console . warn ( "Handle ID is missing for source task node. ") ;
126+ if ( ! source . handle ?. handleName ) {
127+ console . error ( "Source handle name missing for task to task connection ") ;
113128 return graphSpec ;
114129 }
115130
116- if ( ! target . handle ) {
117- console . warn ( "Handle ID is missing for target task node. ") ;
131+ if ( ! target . handle ?. handleName ) {
132+ console . error ( "Target handle name missing for task to task connection ") ;
118133 return graphSpec ;
119134 }
120135
121- const sourceOutputName = outputIdToOutputName ( source . handle ) ;
122- const targetInputName = inputIdToInputName ( target . handle ) ;
136+ const sourceOutputName = source . handle . handleName ;
137+ const targetInputName = target . handle . handleName ;
123138
124139 const taskOutputArgument : TaskOutputArgument = {
125140 taskOutput : {
@@ -141,12 +156,16 @@ const handleTaskToGraphOutput = (
141156 source : NodeInfo ,
142157 target : NodeInfo ,
143158) : GraphSpec => {
144- if ( ! source . handle ) {
145- console . warn ( "Handle ID is missing for source task node." ) ;
159+ if ( ! source . handle ?. handleName ) {
160+ console . error (
161+ "Source handle name missing for task to graph output connection" ,
162+ ) ;
146163 return graphSpec ;
147164 }
148165
149- const sourceOutputName = outputIdToOutputName ( source . handle ) ;
166+ const sourceOutputName = source . handle . handleName ;
167+ const outputId = target . id ;
168+ const outputName = outputIdToOutputName ( outputId ) ;
150169
151170 const taskOutputArgument : TaskOutputArgument = {
152171 taskOutput : {
@@ -155,5 +174,5 @@ const handleTaskToGraphOutput = (
155174 } ,
156175 } ;
157176
158- return setGraphOutputValue ( graphSpec , target . id , taskOutputArgument ) ;
177+ return setGraphOutputValue ( graphSpec , outputName , taskOutputArgument ) ;
159178} ;
0 commit comments