|
|
@@ -147,6 +147,9 @@ const peddingHandlePayload = ref<{
|
|
|
|
|
|
const runningStatusStartedAt = new Map<string, number>()
|
|
|
const pendingNodeStatusTimers = new Map<string, number>()
|
|
|
+const pendingEdges = ref<
|
|
|
+ Array<Connection & { id: string; type?: string; data?: Record<string, unknown> }>
|
|
|
+>([])
|
|
|
|
|
|
const removeNodeLibaryPopoverAnchor = () => {
|
|
|
nodeLibaryPopoverAnchorRef.value?.remove()
|
|
|
@@ -276,9 +279,17 @@ const workflowWithExecutionState = computed(() => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+ const stableEdgeKeys = new Set(
|
|
|
+ (baseWorkflow.edges || []).map((edge) => `${edge.source}->${edge.target}->${edge.sourceHandle || ''}`)
|
|
|
+ )
|
|
|
+ const displayPendingEdges = pendingEdges.value.filter(
|
|
|
+ (edge) => !stableEdgeKeys.has(`${edge.source}->${edge.target}->${edge.sourceHandle || ''}`)
|
|
|
+ )
|
|
|
+
|
|
|
return {
|
|
|
...baseWorkflow,
|
|
|
- nodes
|
|
|
+ nodes,
|
|
|
+ edges: [...(baseWorkflow.edges || []), ...displayPendingEdges]
|
|
|
} as IWorkflow
|
|
|
})
|
|
|
|
|
|
@@ -677,6 +688,7 @@ const handleDrop = (position: XYPosition, event: DragEvent) => {
|
|
|
const onCreateConnection = async (connection: Connection) => {
|
|
|
const { sourceHandle } = connection
|
|
|
const { source, target } = normalizeConnectionEndpoints(connection)
|
|
|
+ const edgeKey = `${source}->${target}->${sourceHandle || ''}`
|
|
|
|
|
|
const params: {
|
|
|
appAgentId: string
|
|
|
@@ -695,7 +707,30 @@ const onCreateConnection = async (connection: Connection) => {
|
|
|
params.sourceHandle = sourceHandle
|
|
|
}
|
|
|
|
|
|
- if (!props.workflow?.edges.some((edge) => edge.source === source && edge.target === target)) {
|
|
|
+ const existsInWorkflow = props.workflow?.edges.some(
|
|
|
+ (edge) => `${edge.source}->${edge.target}->${edge.sourceHandle || ''}` === edgeKey
|
|
|
+ )
|
|
|
+ const existsInPending = pendingEdges.value.some(
|
|
|
+ (edge) => `${edge.source}->${edge.target}->${edge.sourceHandle || ''}` === edgeKey
|
|
|
+ )
|
|
|
+ if (existsInWorkflow || existsInPending) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const pendingId = `pending-edge-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
|
+ pendingEdges.value.push({
|
|
|
+ id: pendingId,
|
|
|
+ type: 'canvas-edge',
|
|
|
+ source,
|
|
|
+ target,
|
|
|
+ sourceHandle: params.sourceHandle,
|
|
|
+ targetHandle: connection.targetHandle,
|
|
|
+ data: {
|
|
|
+ pending: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ try {
|
|
|
const response = await agent.postAgentDoNewEdge(params)
|
|
|
|
|
|
if (
|
|
|
@@ -707,6 +742,11 @@ const onCreateConnection = async (connection: Connection) => {
|
|
|
) {
|
|
|
await props.reloadWorkflow(props.workflow.id)
|
|
|
}
|
|
|
+ } catch (error) {
|
|
|
+ console.error('postAgentDoNewEdge error', error)
|
|
|
+ ElMessage.error(t('pages.nodeView.messages.createEdgeFailed'))
|
|
|
+ } finally {
|
|
|
+ pendingEdges.value = pendingEdges.value.filter((edge) => edge.id !== pendingId)
|
|
|
}
|
|
|
}
|
|
|
|