diff --git a/web/src/pages/agent/form/crawler-form/index.tsx b/web/src/pages/agent/form/crawler-form/index.tsx index 4a4c729cd..8c8da6b08 100644 --- a/web/src/pages/agent/form/crawler-form/index.tsx +++ b/web/src/pages/agent/form/crawler-form/index.tsx @@ -10,8 +10,8 @@ import { import { Input } from '@/components/ui/input'; import { useTranslate } from '@/hooks/common-hooks'; import { zodResolver } from '@hookform/resolvers/zod'; -import { useMemo } from 'react'; -import { useForm } from 'react-hook-form'; +import { memo, useMemo } from 'react'; +import { useForm, useFormContext } from 'react-hook-form'; import { z } from 'zod'; import { initialCrawlerValues } from '../../constant'; import { useWatchFormChange } from '../../hooks/use-watch-form-change'; @@ -19,13 +19,65 @@ import { INextOperatorForm } from '../../interface'; import { CrawlerResultOptions } from '../../options'; import { QueryVariable } from '../components/query-variable'; -const FormSchema = z.object({ - query: z.string().optional(), +export function CrawlerProxyFormField() { + const { t } = useTranslate('flow'); + const form = useFormContext(); + + return ( + ( + + {t('proxy')} + + + + + + )} + /> + ); +} + +export function CrawlerExtractTypeFormField() { + const { t } = useTranslate('flow'); + const form = useFormContext(); + const crawlerResultOptions = useMemo(() => { + return CrawlerResultOptions.map((x) => ({ + value: x, + label: t(`crawlerResultOptions.${x}`), + })); + }, [t]); + + return ( + ( + + {t('extractType')} + + + + + + )} + /> + ); +} + +export const CrawlerFormSchema = { proxy: z.string().url(), extract_type: z.string(), +}; + +const FormSchema = z.object({ + query: z.string().optional(), + ...CrawlerFormSchema, }); + function CrawlerForm({ node }: INextOperatorForm) { - const { t } = useTranslate('flow'); const form = useForm>({ resolver: zodResolver(FormSchema), defaultValues: initialCrawlerValues, @@ -34,13 +86,6 @@ function CrawlerForm({ node }: INextOperatorForm) { useWatchFormChange(node?.id, form); - const crawlerResultOptions = useMemo(() => { - return CrawlerResultOptions.map((x) => ({ - value: x, - label: t(`crawlerResultOptions.${x}`), - })); - }, [t]); - return (
- ( - - {t('proxy')} - - - - - - )} - /> - ( - - {t('extractType')} - - - - - - )} - /> + + ); } -export default CrawlerForm; +export default memo(CrawlerForm); diff --git a/web/src/pages/agent/form/tool-form/constant.tsx b/web/src/pages/agent/form/tool-form/constant.tsx index 708e2542f..7adcb93a1 100644 --- a/web/src/pages/agent/form/tool-form/constant.tsx +++ b/web/src/pages/agent/form/tool-form/constant.tsx @@ -2,7 +2,6 @@ import { Operator } from '../../constant'; import AkShareForm from '../akshare-form'; import ArXivForm from '../arxiv-form'; import BingForm from '../bing-form'; -import CrawlerForm from '../crawler-form'; import DeepLForm from '../deepl-form'; import DuckDuckGoForm from '../duckduckgo-form'; import EmailForm from '../email-form'; @@ -13,6 +12,7 @@ import GoogleScholarForm from '../google-scholar-form'; import PubMedForm from '../pubmed-form'; import WikipediaForm from '../wikipedia-form'; import YahooFinanceForm from '../yahoo-finance-form'; +import CrawlerForm from './crawler-form'; import RetrievalForm from './retrieval-form'; import TavilyForm from './tavily-form'; diff --git a/web/src/pages/agent/form/tool-form/crawler-form/index.tsx b/web/src/pages/agent/form/tool-form/crawler-form/index.tsx new file mode 100644 index 000000000..338a492c3 --- /dev/null +++ b/web/src/pages/agent/form/tool-form/crawler-form/index.tsx @@ -0,0 +1,43 @@ +import { Form } from '@/components/ui/form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useForm } from 'react-hook-form'; +import { z } from 'zod'; +import { + CrawlerExtractTypeFormField, + CrawlerFormSchema, + CrawlerProxyFormField, +} from '../../crawler-form'; +import { useValues } from '../use-values'; +import { useWatchFormChange } from '../use-watch-change'; + +export const FormSchema = z.object({ + ...CrawlerFormSchema, +}); + +const CrawlerForm = () => { + const defaultValues = useValues(); + + const form = useForm({ + defaultValues: defaultValues, + resolver: zodResolver(FormSchema), + mode: 'onChange', + }); + + useWatchFormChange(form); + + return ( +
+ { + e.preventDefault(); + }} + > + + +
+ + ); +}; + +export default CrawlerForm;