(newComponentNodeData, edges)
| 359 | } |
| 360 | |
| 361 | export const updateOutdatedNodeEdge = (newComponentNodeData, edges) => { |
| 362 | const removedEdges = [] |
| 363 | |
| 364 | const isAgentFlowV2 = newComponentNodeData.category === 'Agent Flows' |
| 365 | |
| 366 | // Helper to compare handle/anchor IDs while ignoring trailing base-class/type suffixes |
| 367 | // Example: |
| 368 | // azureChatOpenAI_0-output-azureChatOpenAI-A|B|C vs azureChatOpenAI_0-output-azureChatOpenAI-A|B |
| 369 | // We compare by stripping the last "-..." segment if it contains pipes. |
| 370 | const handlesEqual = (a, b) => { |
| 371 | if (a === b) return true |
| 372 | const stripPipeSuffix = (s) => { |
| 373 | if (!s) return s |
| 374 | const lastDash = s.lastIndexOf('-') |
| 375 | if (lastDash === -1) return s |
| 376 | const suffix = s.substring(lastDash + 1) |
| 377 | return suffix.includes('|') ? s.substring(0, lastDash) : s |
| 378 | } |
| 379 | return stripPipeSuffix(a) === stripPipeSuffix(b) |
| 380 | } |
| 381 | |
| 382 | for (const edge of edges) { |
| 383 | const targetNodeId = edge.targetHandle.split('-')[0] |
| 384 | const sourceNodeId = edge.sourceHandle.split('-')[0] |
| 385 | |
| 386 | if (targetNodeId === newComponentNodeData.id) { |
| 387 | if (isAgentFlowV2) { |
| 388 | if (edge.targetHandle !== newComponentNodeData.id) { |
| 389 | removedEdges.push(edge) |
| 390 | } |
| 391 | } else { |
| 392 | // Check if targetHandle is in inputParams or inputAnchors |
| 393 | const inputParam = newComponentNodeData.inputParams.find((param) => handlesEqual(param.id, edge.targetHandle)) |
| 394 | const inputAnchor = newComponentNodeData.inputAnchors.find((param) => handlesEqual(param.id, edge.targetHandle)) |
| 395 | |
| 396 | if (!inputParam && !inputAnchor) { |
| 397 | removedEdges.push(edge) |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | if (sourceNodeId === newComponentNodeData.id) { |
| 403 | if (isAgentFlowV2) { |
| 404 | // AgentFlow v2 doesn't have specific output anchors, connections are directly from node |
| 405 | // No need to remove edges for AgentFlow v2 outputs |
| 406 | } else if (newComponentNodeData.outputAnchors?.length) { |
| 407 | for (const outputAnchor of newComponentNodeData.outputAnchors) { |
| 408 | const outputAnchorType = outputAnchor.type |
| 409 | if (outputAnchorType === 'options') { |
| 410 | if (!outputAnchor.options.find((outputOption) => handlesEqual(outputOption.id, edge.sourceHandle))) { |
| 411 | removedEdges.push(edge) |
| 412 | } |
| 413 | } else { |
| 414 | if (!handlesEqual(outputAnchor.id, edge.sourceHandle)) { |
| 415 | removedEdges.push(edge) |
| 416 | } |
| 417 | } |
| 418 | } |
no test coverage detected