diff --git a/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx b/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx index 388741d6b..268a68373 100644 --- a/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx +++ b/web/src/pages/agent/canvas/node/dropdown/next-step-dropdown.tsx @@ -102,7 +102,7 @@ function AccordionOperators() { Operator.TavilySearch, Operator.TavilyExtract, Operator.ExeSQL, - Operator.Bing, + Operator.Google, ]} > diff --git a/web/src/pages/agent/constant.tsx b/web/src/pages/agent/constant.tsx index 4d26074f5..5f66f735f 100644 --- a/web/src/pages/agent/constant.tsx +++ b/web/src/pages/agent/constant.tsx @@ -368,11 +368,23 @@ export const initialArXivValues = { }; export const initialGoogleValues = { + q: AgentGlobals.SysQuery, + start: 0, + num: 12, top_n: 10, - api_key: 'YOUR_API_KEY (obtained from https://serpapi.com/manage-api-key)', + api_key: '', country: 'cn', language: 'en', - ...initialQueryBaseValues, + outputs: { + formalized_content: { + value: '', + type: 'string', + }, + json: { + value: [], + type: 'Array', + }, + }, }; export const initialBingValues = { diff --git a/web/src/pages/agent/form/code-form/index.tsx b/web/src/pages/agent/form/code-form/index.tsx index d34f5da3d..304971c6c 100644 --- a/web/src/pages/agent/form/code-form/index.tsx +++ b/web/src/pages/agent/form/code-form/index.tsx @@ -19,6 +19,7 @@ import { memo } from 'react'; import { useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { buildOutputList } from '../../utils/build-output-list'; +import { FormWrapper } from '../components/form-wrapper'; import { Output } from '../components/output'; import { DynamicInputVariable, @@ -57,12 +58,7 @@ function CodeForm({ node }: INextOperatorForm) { return (
- { - e.preventDefault(); - }} - > + )} - +
diff --git a/web/src/pages/agent/form/components/api-key-field.tsx b/web/src/pages/agent/form/components/api-key-field.tsx new file mode 100644 index 000000000..cebca931b --- /dev/null +++ b/web/src/pages/agent/form/components/api-key-field.tsx @@ -0,0 +1,31 @@ +import { + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; +import { useFormContext } from 'react-hook-form'; + +interface IApiKeyFieldProps { + placeholder?: string; +} +export function ApiKeyField({ placeholder }: IApiKeyFieldProps) { + const form = useFormContext(); + return ( + ( + + Api Key + + + + + + )} + /> + ); +} diff --git a/web/src/pages/agent/form/google-form/index.tsx b/web/src/pages/agent/form/google-form/index.tsx index c2abb1915..a96d90f06 100644 --- a/web/src/pages/agent/form/google-form/index.tsx +++ b/web/src/pages/agent/form/google-form/index.tsx @@ -1,32 +1,122 @@ -import TopNItem from '@/components/top-n-item'; +import { FormContainer } from '@/components/form-container'; +import NumberInput from '@/components/originui/number-input'; +import { SelectWithSearch } from '@/components/originui/select-with-search'; +import { TopNFormField } from '@/components/top-n-item'; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from '@/components/ui/form'; import { useTranslate } from '@/hooks/common-hooks'; -import { Form, Input, Select } from 'antd'; -import { IOperatorForm } from '../../interface'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { initialGoogleValues } from '../../constant'; +import { useFormValues } from '../../hooks/use-form-values'; +import { INextOperatorForm } from '../../interface'; import { GoogleCountryOptions, GoogleLanguageOptions } from '../../options'; -import DynamicInputVariable from '../components/dynamic-input-variable'; +import { buildOutputList } from '../../utils/build-output-list'; +import { ApiKeyField } from '../components/api-key-field'; +import { FormWrapper } from '../components/form-wrapper'; +import { Output } from '../components/output'; +import { QueryVariable } from '../components/query-variable'; -const GoogleForm = ({ onValuesChange, form, node }: IOperatorForm) => { +const outputList = buildOutputList(initialGoogleValues.outputs); + +export const FormSchema = z.object({ + top_n: z.number(), + api_key: z.string(), + country: z.string(), + language: z.string(), + q: z.string(), + start: z.number(), + num: z.number(), +}); + +const GoogleForm = ({ node }: INextOperatorForm) => { const { t } = useTranslate('flow'); + const defaultValues = useFormValues(initialGoogleValues, node); + + const form = useForm>({ + defaultValues, + resolver: zodResolver(FormSchema), + }); return ( -
- - - - - - - - - - - + + + + + + + + ( + + {t('start')} + + + + + + )} + /> + ( + + {t('num')} + + + + + + )} + /> + + ( + + {t('country')} + + + + + + )} + /> + ( + + {t('language')} + + + + + + )} + /> + + +
+ +
); }; diff --git a/web/src/pages/agent/form/tavily-extract-form/index.tsx b/web/src/pages/agent/form/tavily-extract-form/index.tsx index 0293d530d..23cadcefc 100644 --- a/web/src/pages/agent/form/tavily-extract-form/index.tsx +++ b/web/src/pages/agent/form/tavily-extract-form/index.tsx @@ -23,9 +23,10 @@ import { useFormValues } from '../../hooks/use-form-values'; import { useWatchFormChange } from '../../hooks/use-watch-form-change'; import { INextOperatorForm } from '../../interface'; import { buildOutputList } from '../../utils/build-output-list'; +import { ApiKeyField } from '../components/api-key-field'; import { FormWrapper } from '../components/form-wrapper'; import { Output } from '../components/output'; -import { TavilyApiKeyField, TavilyFormSchema } from '../tavily-form'; +import { TavilyFormSchema } from '../tavily-form'; const outputList = buildOutputList(initialTavilyExtractValues.outputs); @@ -53,7 +54,7 @@ function TavilyExtractForm({ node }: INextOperatorForm) {
- + ( - - Api Key - - - - - - )} - /> - ); -} - export const TavilyFormSchema = { api_key: z.string(), }; @@ -90,7 +72,7 @@ function TavilyForm({ node }: INextOperatorForm) { - + diff --git a/web/src/pages/agent/form/tool-form/constant.tsx b/web/src/pages/agent/form/tool-form/constant.tsx index bc341e83b..419e8abb8 100644 --- a/web/src/pages/agent/form/tool-form/constant.tsx +++ b/web/src/pages/agent/form/tool-form/constant.tsx @@ -5,7 +5,6 @@ import DeepLForm from '../deepl-form'; import DuckDuckGoForm from '../duckduckgo-form'; import EmailForm from '../email-form'; import GithubForm from '../github-form'; -import GoogleForm from '../google-form'; import GoogleScholarForm from '../google-scholar-form'; import PubMedForm from '../pubmed-form'; import WikipediaForm from '../wikipedia-form'; @@ -23,7 +22,7 @@ export const ToolFormConfigMap = { [Operator.Wikipedia]: WikipediaForm, [Operator.PubMed]: PubMedForm, [Operator.ArXiv]: ArXivForm, - [Operator.Google]: GoogleForm, + [Operator.Google]: TavilyForm, [Operator.Bing]: BingForm, [Operator.GoogleScholar]: GoogleScholarForm, [Operator.DeepL]: DeepLForm, diff --git a/web/src/pages/agent/form/tool-form/tavily-form/index.tsx b/web/src/pages/agent/form/tool-form/tavily-form/index.tsx index 01bede4b1..5c0ea70b5 100644 --- a/web/src/pages/agent/form/tool-form/tavily-form/index.tsx +++ b/web/src/pages/agent/form/tool-form/tavily-form/index.tsx @@ -3,8 +3,9 @@ import { Form } from '@/components/ui/form'; import { zodResolver } from '@hookform/resolvers/zod'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; +import { ApiKeyField } from '../../components/api-key-field'; import { FormWrapper } from '../../components/form-wrapper'; -import { TavilyApiKeyField, TavilyFormSchema } from '../../tavily-form'; +import { TavilyFormSchema } from '../../tavily-form'; import { useValues } from '../use-values'; import { useWatchFormChange } from '../use-watch-change'; @@ -24,7 +25,7 @@ const TavilyForm = () => { - + diff --git a/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts b/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts index 75026f603..fd0de1c42 100644 --- a/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts +++ b/web/src/pages/agent/hooks/use-agent-tool-initial-values.ts @@ -16,7 +16,7 @@ export function useAgentToolInitialValues() { ...omit(initialValues, 'query'), description: '', }; - case (Operator.TavilySearch, Operator.TavilyExtract): + case (Operator.TavilySearch, Operator.TavilyExtract, Operator.Google): return { api_key: '', };