mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Add Tavily operator #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { UseFormReturn, useWatch } from 'react-hook-form';
|
|
import useGraphStore from '../../store';
|
|
import { getAgentNodeTools } from '../../utils';
|
|
|
|
export function useWatchFormChange(form?: UseFormReturn<any>) {
|
|
let values = useWatch({ control: form?.control });
|
|
const { clickedToolId, clickedNodeId, findUpstreamNodeById, updateNodeForm } =
|
|
useGraphStore((state) => state);
|
|
|
|
useEffect(() => {
|
|
const agentNode = findUpstreamNodeById(clickedNodeId);
|
|
// Manually triggered form updates are synchronized to the canvas
|
|
if (agentNode && form?.formState.isDirty) {
|
|
const agentNodeId = agentNode?.id;
|
|
const tools = getAgentNodeTools(agentNode);
|
|
|
|
values = form?.getValues();
|
|
const nextTools = tools.map((x) => {
|
|
if (x.component_name === clickedToolId) {
|
|
return {
|
|
...x,
|
|
params: {
|
|
...values,
|
|
},
|
|
};
|
|
}
|
|
return x;
|
|
});
|
|
|
|
const nextValues = {
|
|
...(agentNode?.data?.form ?? {}),
|
|
tools: nextTools,
|
|
};
|
|
|
|
updateNodeForm(agentNodeId, nextValues);
|
|
}
|
|
}, [form?.formState.isDirty, updateNodeForm, values]);
|
|
}
|