diff --git a/web/src/pages/agent/form/components/output.tsx b/web/src/pages/agent/form/components/output.tsx index 89ccfa8ca..3f7e4ae27 100644 --- a/web/src/pages/agent/form/components/output.tsx +++ b/web/src/pages/agent/form/components/output.tsx @@ -1,4 +1,4 @@ -type OutputType = { +export type OutputType = { title: string; type: string; }; diff --git a/web/src/pages/agent/form/tavily-form/dynamic-domain.tsx b/web/src/pages/agent/form/tavily-form/dynamic-domain.tsx new file mode 100644 index 000000000..199e24c17 --- /dev/null +++ b/web/src/pages/agent/form/tavily-form/dynamic-domain.tsx @@ -0,0 +1,57 @@ +import { BlockButton, Button } from '@/components/ui/button'; +import { + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; +import { X } from 'lucide-react'; +import { ReactNode } from 'react'; +import { useFieldArray, useFormContext } from 'react-hook-form'; + +type DynamicDomainProps = { name: string; label: ReactNode }; + +export const DynamicDomain = ({ name, label }: DynamicDomainProps) => { + const form = useFormContext(); + + const { fields, append, remove } = useFieldArray({ + name: name, + control: form.control, + }); + + return ( + + {label} +
+ {fields.map((field, index) => ( +
+
+ ( + + + + + + )} + /> +
+ +
+ ))} +
+ + append({ value: '' })}>Add +
+ ); +}; diff --git a/web/src/pages/agent/form/tavily-form/index.tsx b/web/src/pages/agent/form/tavily-form/index.tsx index 89b19d2f7..3ff58b37f 100644 --- a/web/src/pages/agent/form/tavily-form/index.tsx +++ b/web/src/pages/agent/form/tavily-form/index.tsx @@ -9,18 +9,23 @@ import { } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { RAGFlowSelect } from '@/components/ui/select'; +import { Switch } from '@/components/ui/switch'; import { buildOptions } from '@/utils/form'; import { zodResolver } from '@hookform/resolvers/zod'; +import { useMemo } from 'react'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; +import { Output, OutputType } from '../components/output'; import { QueryVariable } from '../components/query-variable'; -import { SearchDepth, Topic, useValues } from './use-values'; +import { DynamicDomain } from './dynamic-domain'; +import { SearchDepth, Topic, defaultValues, useValues } from './use-values'; import { useWatchFormChange } from './use-watch-change'; const TavilyForm = () => { const values = useValues(); const FormSchema = z.object({ + api_key: z.string(), query: z.string(), search_depth: z.enum([SearchDepth.Advanced, SearchDepth.Basic]), topic: z.enum([Topic.News, Topic.General]), @@ -30,15 +35,25 @@ const TavilyForm = () => { include_raw_content: z.boolean(), include_images: z.boolean(), include_image_descriptions: z.boolean(), - include_domains: z.array(z.string()), - exclude_domains: z.array(z.string()), + include_domains: z.array(z.object({ value: z.any() })), // TODO: z.string should be used, but an error will be reported + exclude_domains: z.array(z.object({ value: z.any() })), }); - const form = useForm({ + const form = useForm>({ defaultValues: values, resolver: zodResolver(FormSchema), }); + const outputList = useMemo(() => { + return Object.entries(defaultValues.outputs).reduce( + (pre, [key, val]) => { + pre.push({ title: key, type: val.type }); + return pre; + }, + [], + ); + }, []); + useWatchFormChange(form); return ( @@ -50,9 +65,23 @@ const TavilyForm = () => { e.preventDefault(); }} > + + ( + + Api Key + + + + + + )} + /> + - { )} /> + ( + + Days + + + + + + )} + /> + ( + + Include Answer + + + + + + )} + /> + ( + + Include Raw Content + + + + + + )} + /> + ( + + Include Images + + + + + + )} + /> + ( + + Include Image Descriptions + + + + + + )} + /> + + +
+ +
); }; diff --git a/web/src/pages/agent/form/tavily-form/use-values.ts b/web/src/pages/agent/form/tavily-form/use-values.ts index 677e08962..486c06622 100644 --- a/web/src/pages/agent/form/tavily-form/use-values.ts +++ b/web/src/pages/agent/form/tavily-form/use-values.ts @@ -1,7 +1,8 @@ +import { AgentGlobals } from '@/constants/agent'; import { isEmpty } from 'lodash'; import { useMemo } from 'react'; import useGraphStore from '../../store'; -import { getAgentNodeTools } from '../../utils'; +import { convertToObjectArray, getAgentNodeTools } from '../../utils'; export enum SearchDepth { Basic = 'basic', @@ -13,8 +14,9 @@ export enum Topic { General = 'general', } -const defaultValues = { - query: '', +export const defaultValues = { + api_key: '', + query: AgentGlobals.SysQuery, search_depth: SearchDepth.Basic, topic: Topic.General, max_results: 5, @@ -25,6 +27,16 @@ const defaultValues = { include_image_descriptions: false, include_domains: [], exclude_domains: [], + outputs: { + formalized_content: { + value: '', + type: 'string', + }, + json: { + value: {}, + type: 'Object', + }, + }, }; export function useValues() { @@ -46,6 +58,8 @@ export function useValues() { return { ...formData, + include_domains: convertToObjectArray(formData.include_domains), + exclude_domains: convertToObjectArray(formData.exclude_domains), }; }, [clickedNodeId, clickedToolId, findUpstreamNodeById]); diff --git a/web/src/pages/agent/form/tavily-form/use-watch-change.ts b/web/src/pages/agent/form/tavily-form/use-watch-change.ts index 39ae2fef8..31927e9ed 100644 --- a/web/src/pages/agent/form/tavily-form/use-watch-change.ts +++ b/web/src/pages/agent/form/tavily-form/use-watch-change.ts @@ -1,7 +1,7 @@ import { useEffect } from 'react'; import { UseFormReturn, useWatch } from 'react-hook-form'; import useGraphStore from '../../store'; -import { getAgentNodeTools } from '../../utils'; +import { convertToStringArray, getAgentNodeTools } from '../../utils'; export function useWatchFormChange(form?: UseFormReturn) { let values = useWatch({ control: form?.control }); @@ -18,7 +18,14 @@ export function useWatchFormChange(form?: UseFormReturn) { values = form?.getValues(); const nextTools = tools.map((x) => { if (x.component_name === clickedToolId) { - return { ...x, params: { ...values } }; + return { + ...x, + params: { + ...values, + include_domains: convertToStringArray(values.include_domains), + exclude_domains: convertToStringArray(values.exclude_domains), + }, + }; } return x; });