Files
ragflow/web/src/pages/agent/utils/delete-node.ts
balibabu 07545fbfd3 Feat: Delete the agent and tool nodes downstream of the agent node #3221 (#8450)
### What problem does this PR solve?

Feat: Delete the agent and tool nodes downstream of the agent node #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
2025-06-24 11:33:01 +08:00

35 lines
838 B
TypeScript

import { Edge } from '@xyflow/react';
import { filterAllDownstreamAgentAndToolNodeIds } from './filter-downstream-nodes';
// Delete all downstream agent and tool operators of the current agent operator
export function deleteAllDownstreamAgentsAndTool(
nodeId: string,
edges: Edge[],
) {
const downstreamAgentAndToolNodeIds = filterAllDownstreamAgentAndToolNodeIds(
edges,
[nodeId],
);
const downstreamAgentAndToolEdges = downstreamAgentAndToolNodeIds.reduce<
Edge[]
>((pre, cur) => {
const relatedEdges = edges.filter(
(x) => x.source === cur || x.target === cur,
);
relatedEdges.forEach((x) => {
if (!pre.some((y) => y.id !== x.id)) {
pre.push(x);
}
});
return pre;
}, []);
return {
downstreamAgentAndToolNodeIds,
downstreamAgentAndToolEdges,
};
}