mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-25 16:26:51 +08:00
### 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)
This commit is contained in:
34
web/src/pages/agent/utils/delete-node.ts
Normal file
34
web/src/pages/agent/utils/delete-node.ts
Normal file
@ -0,0 +1,34 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
31
web/src/pages/agent/utils/filter-downstream-nodes.ts
Normal file
31
web/src/pages/agent/utils/filter-downstream-nodes.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Edge } from '@xyflow/react';
|
||||
import { NodeHandleId } from '../constant';
|
||||
|
||||
// Get all downstream agent operators of the current agent operator
|
||||
export function filterAllDownstreamAgentAndToolNodeIds(
|
||||
edges: Edge[],
|
||||
nodeIds: string[],
|
||||
) {
|
||||
return nodeIds.reduce<string[]>((pre, nodeId) => {
|
||||
const currentEdges = edges.filter(
|
||||
(x) =>
|
||||
x.source === nodeId &&
|
||||
(x.sourceHandle === NodeHandleId.AgentBottom ||
|
||||
x.sourceHandle === NodeHandleId.Tool),
|
||||
);
|
||||
|
||||
const downstreamNodeIds: string[] = currentEdges.map((x) => x.target);
|
||||
|
||||
const ids = downstreamNodeIds.concat(
|
||||
filterAllDownstreamAgentAndToolNodeIds(edges, downstreamNodeIds),
|
||||
);
|
||||
|
||||
ids.forEach((x) => {
|
||||
if (pre.every((y) => y !== x)) {
|
||||
pre.push(x);
|
||||
}
|
||||
});
|
||||
|
||||
return pre;
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user