mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-03 11:05:30 +08:00
feat: supports multiple retrieval tool under an agent (#12046)
### 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)
This commit is contained in:
@ -1,39 +1,38 @@
|
||||
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);
|
||||
|
||||
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) {
|
||||
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;
|
||||
updateAgentToolById(agentNode, clickedToolId, {
|
||||
params: {
|
||||
...(values ?? {}),
|
||||
},
|
||||
});
|
||||
|
||||
const nextValues = {
|
||||
...(agentNode?.data?.form ?? {}),
|
||||
tools: nextTools,
|
||||
};
|
||||
|
||||
updateNodeForm(agentNodeId, nextValues);
|
||||
}
|
||||
}, [form?.formState.isDirty, updateNodeForm, values]);
|
||||
}, [
|
||||
clickedNodeId,
|
||||
clickedToolId,
|
||||
findUpstreamNodeById,
|
||||
form,
|
||||
form?.formState.isDirty,
|
||||
getAgentToolById,
|
||||
updateAgentToolById,
|
||||
updateNodeForm,
|
||||
values,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user