mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Deleting the last tool of the agent will delete the tool node #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
25 lines
634 B
TypeScript
25 lines
634 B
TypeScript
import { useCallback } from 'react';
|
|
import { NodeHandleId } from '../../constant';
|
|
import useGraphStore from '../../store';
|
|
|
|
export function useDeleteToolNode() {
|
|
const { edges, deleteEdgeById, deleteNodeById } = useGraphStore(
|
|
(state) => state,
|
|
);
|
|
const deleteToolNode = useCallback(
|
|
(agentNodeId: string) => {
|
|
const edge = edges.find(
|
|
(x) => x.source === agentNodeId && x.sourceHandle === NodeHandleId.Tool,
|
|
);
|
|
|
|
if (edge) {
|
|
deleteEdgeById(edge.id);
|
|
deleteNodeById(edge.target);
|
|
}
|
|
},
|
|
[deleteEdgeById, deleteNodeById, edges],
|
|
);
|
|
|
|
return { deleteToolNode };
|
|
}
|