mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-25 09:53:29 +08:00
35 lines
838 B
TypeScript
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,
|
||
|
|
};
|
||
|
|
}
|