11import type { Edge } from "@xyflow/react" ;
22
33import type { NodeManager } from "@/nodeManager" ;
4- import type { ComponentSpec , GraphImplementation } from "@/utils/componentSpec" ;
4+ import {
5+ type ComponentSpec ,
6+ isGraphImplementation ,
7+ } from "@/utils/componentSpec" ;
58import { outputIdToOutputName } from "@/utils/nodes/conversions" ;
69
710import { setGraphOutputValue } from "./setGraphOutputValue" ;
@@ -12,34 +15,67 @@ export const removeEdge = (
1215 componentSpec : ComponentSpec ,
1316 nodeManager : NodeManager ,
1417) => {
15- const graphSpec = ( componentSpec . implementation as GraphImplementation )
16- ?. graph ;
17-
18- const inputName = edge . targetHandle ?. replace ( / ^ i n p u t _ / , "" ) ;
19-
20- const updatedComponentSpec = {
21- ...componentSpec ,
22- } ;
23-
24- const taskId = nodeManager . getTaskId ( edge . target ) ;
25- if ( ! taskId ) return componentSpec ;
26-
27- if ( inputName !== undefined && graphSpec ) {
28- const newGraphSpec = setTaskArgument ( graphSpec , taskId , inputName ) ;
29- updatedComponentSpec . implementation = {
30- ...updatedComponentSpec . implementation ,
31- graph : newGraphSpec ,
32- } ;
33-
34- return updatedComponentSpec ;
35- } else {
36- const outputName = outputIdToOutputName ( taskId ) ;
37- const newGraphSpec = setGraphOutputValue ( graphSpec , outputName ) ;
38- updatedComponentSpec . implementation = {
39- ...updatedComponentSpec . implementation ,
40- graph : newGraphSpec ,
41- } ;
42-
43- return updatedComponentSpec ;
18+ if ( ! isGraphImplementation ( componentSpec . implementation ) ) {
19+ return componentSpec ;
4420 }
21+
22+ const graphSpec = componentSpec . implementation . graph ;
23+ const updatedComponentSpec = { ...componentSpec } ;
24+
25+ const targetNodeId = edge . target ;
26+ const targetTaskId = nodeManager . getTaskId ( targetNodeId ) ;
27+ const targetNodeType = nodeManager . getNodeType ( targetNodeId ) ;
28+
29+ if ( ! targetTaskId || ! targetNodeType ) {
30+ console . error ( "Could not resolve target node information:" , {
31+ targetNodeId,
32+ targetTaskId,
33+ targetNodeType,
34+ } ) ;
35+ return componentSpec ;
36+ }
37+
38+ switch ( targetNodeType ) {
39+ case "task" : {
40+ if ( ! edge . targetHandle ) {
41+ console . error ( "No target handle found for task connection" ) ;
42+ return componentSpec ;
43+ }
44+
45+ const targetHandleInfo = nodeManager . getHandleInfo ( edge . targetHandle ) ;
46+ if ( ! targetHandleInfo ) {
47+ console . error ( "Could not resolve target handle info" ) ;
48+ return componentSpec ;
49+ }
50+
51+ const inputName = targetHandleInfo . handleName ;
52+ const newGraphSpec = setTaskArgument ( graphSpec , targetTaskId , inputName ) ;
53+
54+ updatedComponentSpec . implementation = {
55+ ...updatedComponentSpec . implementation ,
56+ graph : newGraphSpec ,
57+ } ;
58+ break ;
59+ }
60+
61+ case "output" : {
62+ const outputName = outputIdToOutputName ( targetTaskId ) ;
63+ const newGraphSpec = setGraphOutputValue ( graphSpec , outputName ) ;
64+
65+ updatedComponentSpec . implementation = {
66+ ...updatedComponentSpec . implementation ,
67+ graph : newGraphSpec ,
68+ } ;
69+ break ;
70+ }
71+
72+ default :
73+ console . error (
74+ "Unsupported target node type for edge removal:" ,
75+ targetNodeType ,
76+ ) ;
77+ return componentSpec ;
78+ }
79+
80+ return updatedComponentSpec ;
4581} ;
0 commit comments