| 42 | collected.add(nodeId) |
| 43 | |
| 44 | function collect(targetId: string) { |
| 45 | // In AgentFlow V2, targetHandle === targetNodeId for node-level connections |
| 46 | const inputEdges = edges.filter((e) => e.target === targetId) |
| 47 | |
| 48 | for (const edge of inputEdges) { |
| 49 | if (collected.has(edge.source)) continue |
| 50 | |
| 51 | const parentNode = nodes.find((n) => n.id === edge.source) |
| 52 | if (!parentNode) continue |
| 53 | |
| 54 | // Exclude startAgentflow unless explicitly requested |
| 55 | if (parentNode.data.name === 'startAgentflow' && !includeStart) { |
| 56 | continue |
| 57 | } |
| 58 | |
| 59 | collected.add(parentNode.id) |
| 60 | // Recurse to collect the full ancestor chain |
| 61 | collect(parentNode.id) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | collect(nodeId) |
| 66 | |