mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-24 07:26:47 +08:00
### What problem does this PR solve? Add support for multiple Retrieval tools under an agent ### Type of change - [x] New Feature (non-breaking change which adds functionality)
39 lines
941 B
TypeScript
39 lines
941 B
TypeScript
import { useEffect } from 'react';
|
|
import { UseFormReturn, useWatch } from 'react-hook-form';
|
|
import useGraphStore from '../../store';
|
|
|
|
export function useWatchFormChange(form?: UseFormReturn<any>) {
|
|
let values = useWatch({ control: form?.control });
|
|
|
|
const {
|
|
clickedToolId,
|
|
clickedNodeId,
|
|
findUpstreamNodeById,
|
|
getAgentToolById,
|
|
updateAgentToolById,
|
|
updateNodeForm,
|
|
} = useGraphStore();
|
|
|
|
useEffect(() => {
|
|
const agentNode = findUpstreamNodeById(clickedNodeId);
|
|
// Manually triggered form updates are synchronized to the canvas
|
|
if (agentNode && form?.formState.isDirty) {
|
|
updateAgentToolById(agentNode, clickedToolId, {
|
|
params: {
|
|
...(values ?? {}),
|
|
},
|
|
});
|
|
}
|
|
}, [
|
|
clickedNodeId,
|
|
clickedToolId,
|
|
findUpstreamNodeById,
|
|
form,
|
|
form?.formState.isDirty,
|
|
getAgentToolById,
|
|
updateAgentToolById,
|
|
updateNodeForm,
|
|
values,
|
|
]);
|
|
}
|