diff --git a/web/src/pages/agent/chat/box.tsx b/web/src/pages/agent/chat/box.tsx index 14cebe967..8404ee556 100644 --- a/web/src/pages/agent/chat/box.tsx +++ b/web/src/pages/agent/chat/box.tsx @@ -21,6 +21,7 @@ import { useAwaitCompentData } from '../hooks/use-chat-logic'; import { useIsTaskMode } from '../hooks/use-get-begin-query'; function AgentChatBox() { + const { data: canvasInfo, refetch } = useFetchAgent(); const { value, scrollRef, @@ -33,13 +34,12 @@ function AgentChatBox() { sendFormMessage, findReferenceByMessageId, appendUploadResponseList, - } = useSendAgentMessage(); + } = useSendAgentMessage({ refetch }); const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } = useClickDrawer(); useGetFileIcon(); const { data: userInfo } = useFetchUserInfo(); - const { data: canvasInfo } = useFetchAgent(); const { id: canvasId } = useParams(); const { uploadCanvasFile, loading } = useUploadCanvasFileWithProgress(); diff --git a/web/src/pages/agent/chat/use-send-agent-message.ts b/web/src/pages/agent/chat/use-send-agent-message.ts index 952e67e28..7d16a4715 100644 --- a/web/src/pages/agent/chat/use-send-agent-message.ts +++ b/web/src/pages/agent/chat/use-send-agent-message.ts @@ -194,12 +194,19 @@ export const buildRequestBody = (value: string = '') => { return msgBody; }; -export const useSendAgentMessage = ( - url?: string, - addEventList?: (data: IEventList, messageId: string) => void, - beginParams?: any[], - isShared?: boolean, -) => { +export const useSendAgentMessage = ({ + url, + addEventList, + beginParams, + isShared, + refetch, +}: { + url?: string; + addEventList?: (data: IEventList, messageId: string) => void; + beginParams?: any[]; + isShared?: boolean; + refetch?: () => void; +}) => { const { id: agentId } = useParams(); const { handleInputChange, value, setValue } = useHandleMessageInputChange(); const inputs = useSelectBeginNodeDataInputs(); @@ -212,8 +219,6 @@ export const useSendAgentMessage = ( const isTaskMode = useIsTaskMode(); - // const { refetch } = useFetchAgent(); // This will cause the shared page to also send a request - const { findReferenceByMessageId } = useFindMessageReference(answerList); const prologue = useGetBeginNodePrologue(); const { @@ -277,7 +282,7 @@ export const useSendAgentMessage = ( setValue(message.content); removeLatestMessage(); } else { - // refetch(); // pull the message list after sending the message successfully + refetch?.(); // pull the message list after sending the message successfully } } catch (error) { console.log('🚀 ~ useSendAgentMessage ~ error:', error); @@ -293,6 +298,7 @@ export const useSendAgentMessage = ( clearUploadResponseList, setValue, removeLatestMessage, + refetch, ], ); @@ -305,9 +311,9 @@ export const useSendAgentMessage = ( role: MessageType.User, }); await send({ ...body, session_id: sessionId }); - // refetch(); + refetch?.(); }, - [addNewestOneQuestion, send, sessionId], + [addNewestOneQuestion, refetch, send, sessionId], ); // reset session diff --git a/web/src/pages/agent/hooks/use-send-shared-message.ts b/web/src/pages/agent/hooks/use-send-shared-message.ts index d8e2d61de..61570edc0 100644 --- a/web/src/pages/agent/hooks/use-send-shared-message.ts +++ b/web/src/pages/agent/hooks/use-send-shared-message.ts @@ -48,7 +48,12 @@ export const useSendNextSharedMessage = ( showModal: showParameterDialog, } = useSetModalState(); - const ret = useSendAgentMessage(url, addEventList, params, true); + const ret = useSendAgentMessage({ + url, + addEventList, + beginParams: params, + isShared: true, + }); const ok = useCallback( (params: any[]) => { diff --git a/web/src/pages/data-flow/canvas/index.tsx b/web/src/pages/data-flow/canvas/index.tsx index eb91ee584..c34d94f2e 100644 --- a/web/src/pages/data-flow/canvas/index.tsx +++ b/web/src/pages/data-flow/canvas/index.tsx @@ -14,6 +14,7 @@ import { NodeTypes, Position, ReactFlow, + ReactFlowInstance, } from '@xyflow/react'; import '@xyflow/react/dist/style.css'; import { NotebookPen } from 'lucide-react'; @@ -23,11 +24,7 @@ import { AgentBackground } from '../components/background'; import { AgentInstanceContext, HandleContext } from '../context'; import FormSheet from '../form-sheet/next'; -import { - useHandleDrop, - useSelectCanvasData, - useValidateConnection, -} from '../hooks'; +import { useSelectCanvasData, useValidateConnection } from '../hooks'; import { useAddNode } from '../hooks/use-add-node'; import { useBeforeDelete } from '../hooks/use-before-delete'; import { useMoveNote } from '../hooks/use-move-note'; @@ -104,8 +101,8 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) { } = useSelectCanvasData(); const isValidConnection = useValidateConnection(); - const { onDrop, onDragOver, setReactFlowInstance, reactFlowInstance } = - useHandleDrop(); + const [reactFlowInstance, setReactFlowInstance] = + useState>(); const { onNodeClick, @@ -237,10 +234,8 @@ function AgentCanvas({ drawerVisible, hideDrawer }: IProps) { onConnect={onConnect} nodeTypes={nodeTypes} edgeTypes={edgeTypes} - onDrop={onDrop} onConnectStart={OnConnectStart} onConnectEnd={OnConnectEnd} - onDragOver={onDragOver} onNodeClick={onNodeClick} onPaneClick={onPaneClick} onInit={setReactFlowInstance} diff --git a/web/src/pages/data-flow/constant.tsx b/web/src/pages/data-flow/constant.tsx index 7e57c4abc..bef95fb8d 100644 --- a/web/src/pages/data-flow/constant.tsx +++ b/web/src/pages/data-flow/constant.tsx @@ -89,6 +89,9 @@ export enum Operator { UserFillUp = 'UserFillUp', StringTransform = 'StringTransform', SearXNG = 'SearXNG', + Parser = 'Parser', + Chunker = 'Chunker', + Tokenizer = 'Tokenizer', } export const SwitchLogicOperatorOptions = ['and', 'or']; diff --git a/web/src/pages/data-flow/form-sheet/form-config-map.tsx b/web/src/pages/data-flow/form-sheet/form-config-map.tsx index 0fc1b9e2a..44dc2ca2e 100644 --- a/web/src/pages/data-flow/form-sheet/form-config-map.tsx +++ b/web/src/pages/data-flow/form-sheet/form-config-map.tsx @@ -1,42 +1,22 @@ import { Operator } from '../constant'; import AgentForm from '../form/agent-form'; -import AkShareForm from '../form/akshare-form'; -import ArXivForm from '../form/arxiv-form'; -import BaiduFanyiForm from '../form/baidu-fanyi-form'; -import BaiduForm from '../form/baidu-form'; import BeginForm from '../form/begin-form'; -import BingForm from '../form/bing-form'; import CategorizeForm from '../form/categorize-form'; import CodeForm from '../form/code-form'; import CrawlerForm from '../form/crawler-form'; -import DeepLForm from '../form/deepl-form'; -import DuckDuckGoForm from '../form/duckduckgo-form'; import EmailForm from '../form/email-form'; import ExeSQLForm from '../form/exesql-form'; -import GithubForm from '../form/github-form'; -import GoogleForm from '../form/google-form'; -import GoogleScholarForm from '../form/google-scholar-form'; import InvokeForm from '../form/invoke-form'; import IterationForm from '../form/iteration-form'; import IterationStartForm from '../form/iteration-start-from'; -import Jin10Form from '../form/jin10-form'; import KeywordExtractForm from '../form/keyword-extract-form'; import MessageForm from '../form/message-form'; -import PubMedForm from '../form/pubmed-form'; -import QWeatherForm from '../form/qweather-form'; import RelevantForm from '../form/relevant-form'; import RetrievalForm from '../form/retrieval-form/next'; import RewriteQuestionForm from '../form/rewrite-question-form'; -import SearXNGForm from '../form/searxng-form'; import StringTransformForm from '../form/string-transform-form'; import SwitchForm from '../form/switch-form'; -import TavilyExtractForm from '../form/tavily-extract-form'; -import TavilyForm from '../form/tavily-form'; -import TuShareForm from '../form/tushare-form'; import UserFillUpForm from '../form/user-fill-up-form'; -import WenCaiForm from '../form/wencai-form'; -import WikipediaForm from '../form/wikipedia-form'; -import YahooFinanceForm from '../form/yahoo-finance-form'; export const FormConfigMap = { [Operator.Begin]: { @@ -66,75 +46,21 @@ export const FormConfigMap = { [Operator.Agent]: { component: AgentForm, }, - [Operator.Baidu]: { - component: BaiduForm, - }, - [Operator.DuckDuckGo]: { - component: DuckDuckGoForm, - }, [Operator.KeywordExtract]: { component: KeywordExtractForm, }, - [Operator.Wikipedia]: { - component: WikipediaForm, - }, - [Operator.PubMed]: { - component: PubMedForm, - }, - [Operator.ArXiv]: { - component: ArXivForm, - }, - [Operator.Google]: { - component: GoogleForm, - }, - [Operator.Bing]: { - component: BingForm, - }, - [Operator.GoogleScholar]: { - component: GoogleScholarForm, - }, - [Operator.DeepL]: { - component: DeepLForm, - }, - [Operator.GitHub]: { - component: GithubForm, - }, - [Operator.BaiduFanyi]: { - component: BaiduFanyiForm, - }, - [Operator.QWeather]: { - component: QWeatherForm, - }, [Operator.ExeSQL]: { component: ExeSQLForm, }, [Operator.Switch]: { component: SwitchForm, }, - [Operator.WenCai]: { - component: WenCaiForm, - }, - [Operator.AkShare]: { - component: AkShareForm, - }, - [Operator.YahooFinance]: { - component: YahooFinanceForm, - }, - [Operator.Jin10]: { - component: Jin10Form, - }, - [Operator.TuShare]: { - component: TuShareForm, - }, [Operator.Crawler]: { component: CrawlerForm, }, [Operator.Invoke]: { component: InvokeForm, }, - [Operator.SearXNG]: { - component: SearXNGForm, - }, [Operator.Concentrator]: { component: () => <>, }, @@ -150,16 +76,10 @@ export const FormConfigMap = { [Operator.IterationStart]: { component: IterationStartForm, }, - [Operator.TavilySearch]: { - component: TavilyForm, - }, [Operator.UserFillUp]: { component: UserFillUpForm, }, [Operator.StringTransform]: { component: StringTransformForm, }, - [Operator.TavilyExtract]: { - component: TavilyExtractForm, - }, }; diff --git a/web/src/pages/data-flow/form/akshare-form/index.tsx b/web/src/pages/data-flow/form/akshare-form/index.tsx deleted file mode 100644 index 1cfd554b1..000000000 --- a/web/src/pages/data-flow/form/akshare-form/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { TopNFormField } from '@/components/top-n-item'; -import { Form } from '@/components/ui/form'; -import { INextOperatorForm } from '../../interface'; -import { DynamicInputVariable } from '../components/next-dynamic-input-variable'; - -const AkShareForm = ({ form, node }: INextOperatorForm) => { - return ( -
- { - e.preventDefault(); - }} - > - - -
- - ); -}; - -export default AkShareForm; diff --git a/web/src/pages/data-flow/form/arxiv-form/index.tsx b/web/src/pages/data-flow/form/arxiv-form/index.tsx deleted file mode 100644 index a6e1b7c45..000000000 --- a/web/src/pages/data-flow/form/arxiv-form/index.tsx +++ /dev/null @@ -1,96 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -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 { zodResolver } from '@hookform/resolvers/zod'; -import { memo, useMemo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { z } from 'zod'; -import { initialArXivValues } from '../../constant'; -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 { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -export const ArXivFormPartialSchema = { - top_n: z.number(), - sort_by: z.string(), -}; - -export const FormSchema = z.object({ - ...ArXivFormPartialSchema, - query: z.string(), -}); - -export function ArXivFormWidgets() { - const form = useFormContext(); - const { t } = useTranslate('flow'); - - const options = useMemo(() => { - return ['submittedDate', 'lastUpdatedDate', 'relevance'].map((x) => ({ - value: x, - label: t(x), - })); - }, [t]); - - return ( - <> - - ( - - {t('sortBy')} - - - - - - )} - /> - - ); -} - -const outputList = buildOutputList(initialArXivValues.outputs); - -function ArXivForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialArXivValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - - - -
- -
-
- ); -} - -export default memo(ArXivForm); diff --git a/web/src/pages/data-flow/form/baidu-fanyi-form/index.tsx b/web/src/pages/data-flow/form/baidu-fanyi-form/index.tsx deleted file mode 100644 index c02b3dd85..000000000 --- a/web/src/pages/data-flow/form/baidu-fanyi-form/index.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { useTranslate } from '@/hooks/common-hooks'; -import { Form, Input, Select } from 'antd'; -import { useMemo } from 'react'; -import { IOperatorForm } from '../../interface'; -import { - BaiduFanyiDomainOptions, - BaiduFanyiSourceLangOptions, -} from '../../options'; -import DynamicInputVariable from '../components/dynamic-input-variable'; - -const BaiduFanyiForm = ({ onValuesChange, form, node }: IOperatorForm) => { - const { t } = useTranslate('flow'); - const options = useMemo(() => { - return ['translate', 'fieldtranslate'].map((x) => ({ - value: x, - label: t(`baiduSecretKeyOptions.${x}`), - })); - }, [t]); - - const baiduFanyiOptions = useMemo(() => { - return BaiduFanyiDomainOptions.map((x) => ({ - value: x, - label: t(`baiduDomainOptions.${x}`), - })); - }, [t]); - - const baiduFanyiSourceLangOptions = useMemo(() => { - return BaiduFanyiSourceLangOptions.map((x) => ({ - value: x, - label: t(`baiduSourceLangOptions.${x}`), - })); - }, [t]); - - return ( -
- - - - - - - - - - - - {({ getFieldValue }) => - getFieldValue('trans_type') === 'fieldtranslate' && ( - - - - ) - } - - - - - - - -
- ); -}; - -export default BaiduFanyiForm; diff --git a/web/src/pages/data-flow/form/baidu-form/index.tsx b/web/src/pages/data-flow/form/baidu-form/index.tsx deleted file mode 100644 index 0861ef829..000000000 --- a/web/src/pages/data-flow/form/baidu-form/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { TopNFormField } from '@/components/top-n-item'; -import { Form } from '@/components/ui/form'; -import { INextOperatorForm } from '../../interface'; -import { DynamicInputVariable } from '../components/next-dynamic-input-variable'; - -const BaiduForm = ({ form, node }: INextOperatorForm) => { - return ( -
- { - e.preventDefault(); - }} - > - - -
- - ); -}; - -export default BaiduForm; diff --git a/web/src/pages/data-flow/form/bing-form/index.tsx b/web/src/pages/data-flow/form/bing-form/index.tsx deleted file mode 100644 index fae75aa12..000000000 --- a/web/src/pages/data-flow/form/bing-form/index.tsx +++ /dev/null @@ -1,131 +0,0 @@ -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 { Input } from '@/components/ui/input'; -import { useTranslate } from '@/hooks/common-hooks'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { memo, useMemo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { z } from 'zod'; -import { initialBingValues } from '../../constant'; -import { useFormValues } from '../../hooks/use-form-values'; -import { useWatchFormChange } from '../../hooks/use-watch-form-change'; -import { INextOperatorForm } from '../../interface'; -import { BingCountryOptions, BingLanguageOptions } from '../../options'; -import { FormWrapper } from '../components/form-wrapper'; -import { QueryVariable } from '../components/query-variable'; - -export const BingFormSchema = { - channel: z.string(), - api_key: z.string(), - country: z.string(), - language: z.string(), - top_n: z.number(), -}; - -export const FormSchema = z.object({ - query: z.string().optional(), - ...BingFormSchema, -}); - -export function BingFormWidgets() { - const form = useFormContext(); - const { t } = useTranslate('flow'); - - const options = useMemo(() => { - return ['Webpages', 'News'].map((x) => ({ label: x, value: x })); - }, []); - - return ( - <> - - ( - - {t('channel')} - - - - - - )} - /> - ( - - {t('apiKey')} - - - - - - )} - /> - ( - - {t('country')} - - - - - - )} - /> - ( - - {t('language')} - - - - - - )} - /> - - ); -} - -function BingForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialBingValues, node); - - const form = useForm>({ - resolver: zodResolver(FormSchema), - defaultValues, - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - -
- ); -} - -export default memo(BingForm); diff --git a/web/src/pages/data-flow/form/deepl-form/index.tsx b/web/src/pages/data-flow/form/deepl-form/index.tsx deleted file mode 100644 index 55240b3c1..000000000 --- a/web/src/pages/data-flow/form/deepl-form/index.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import TopNItem from '@/components/top-n-item'; -import { useTranslate } from '@/hooks/common-hooks'; -import { Form, Select } from 'antd'; -import { useBuildSortOptions } from '../../form-hooks'; -import { IOperatorForm } from '../../interface'; -import { DeepLSourceLangOptions, DeepLTargetLangOptions } from '../../options'; -import DynamicInputVariable from '../components/dynamic-input-variable'; - -const DeepLForm = ({ onValuesChange, form, node }: IOperatorForm) => { - const { t } = useTranslate('flow'); - const options = useBuildSortOptions(); - - return ( -
- - - - - - - - - - - -
- ); -}; - -export default DeepLForm; diff --git a/web/src/pages/data-flow/form/duckduckgo-form/index.tsx b/web/src/pages/data-flow/form/duckduckgo-form/index.tsx deleted file mode 100644 index 776635d3c..000000000 --- a/web/src/pages/data-flow/form/duckduckgo-form/index.tsx +++ /dev/null @@ -1,91 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { TopNFormField } from '@/components/top-n-item'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { RAGFlowSelect } from '@/components/ui/select'; -import { useTranslate } from '@/hooks/common-hooks'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { memo, useMemo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { z } from 'zod'; -import { Channel, initialDuckValues } from '../../constant'; -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 { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -export const DuckDuckGoFormPartialSchema = { - top_n: z.string(), - channel: z.string(), -}; - -const FormSchema = z.object({ - query: z.string(), - ...DuckDuckGoFormPartialSchema, -}); - -export function DuckDuckGoWidgets() { - const { t } = useTranslate('flow'); - const form = useFormContext(); - - const options = useMemo(() => { - return Object.values(Channel).map((x) => ({ value: x, label: t(x) })); - }, [t]); - - return ( - <> - - ( - - {t('channel')} - - - - - - )} - /> - - ); -} - -const outputList = buildOutputList(initialDuckValues.outputs); - -function DuckDuckGoForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialDuckValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - -
- -
-
- ); -} - -export default memo(DuckDuckGoForm); diff --git a/web/src/pages/data-flow/form/github-form/index.tsx b/web/src/pages/data-flow/form/github-form/index.tsx deleted file mode 100644 index 2e514a3e7..000000000 --- a/web/src/pages/data-flow/form/github-form/index.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { TopNFormField } from '@/components/top-n-item'; -import { Form } from '@/components/ui/form'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { memo } from 'react'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; -import { initialGithubValues } from '../../constant'; -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 { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -export const FormSchema = z.object({ - query: z.string(), - top_n: z.number(), -}); - -const outputList = buildOutputList(initialGithubValues.outputs); - -function GithubForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialGithubValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - mode: 'onChange', - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - - - -
- -
-
- ); -} - -export default memo(GithubForm); diff --git a/web/src/pages/data-flow/form/google-scholar-form/index.tsx b/web/src/pages/data-flow/form/google-scholar-form/index.tsx deleted file mode 100644 index 00f54056a..000000000 --- a/web/src/pages/data-flow/form/google-scholar-form/index.tsx +++ /dev/null @@ -1,166 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -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 { Switch } from '@/components/ui/switch'; -import { useTranslate } from '@/hooks/common-hooks'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { DatePicker, DatePickerProps } from 'antd'; -import dayjs from 'dayjs'; -import { memo, useCallback, useMemo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { z } from 'zod'; -import { initialGoogleScholarValues } from '../../constant'; -import { useBuildSortOptions } from '../../form-hooks'; -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 { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -// TODO: To be replaced -const YearPicker = ({ - onChange, - value, -}: { - onChange?: (val: number | undefined) => void; - value?: number | undefined; -}) => { - const handleChange: DatePickerProps['onChange'] = useCallback( - (val: any) => { - const nextVal = val?.format('YYYY'); - onChange?.(nextVal ? Number(nextVal) : undefined); - }, - [onChange], - ); - // The year needs to be converted into a number and saved to the backend - const nextValue = useMemo(() => { - if (value) { - return dayjs(value.toString()); - } - return undefined; - }, [value]); - - return ; -}; - -export function GoogleScholarFormWidgets() { - const form = useFormContext(); - const { t } = useTranslate('flow'); - - const options = useBuildSortOptions(); - - return ( - <> - - ( - - {t('sortBy')} - - - - - - )} - /> - ( - - {t('yearLow')} - - - - - - )} - /> - ( - - {t('yearHigh')} - - - - - - )} - /> - ( - - {t('patents')} - - - - - - )} - /> - - ); -} - -export const GoogleScholarFormPartialSchema = { - top_n: z.number(), - sort_by: z.string(), - year_low: z.number(), - year_high: z.number(), - patents: z.boolean(), -}; - -export const FormSchema = z.object({ - ...GoogleScholarFormPartialSchema, - query: z.string(), -}); - -const outputList = buildOutputList(initialGoogleScholarValues.outputs); - -function GoogleScholarForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialGoogleScholarValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - - - -
- -
-
- ); -} - -export default memo(GoogleScholarForm); diff --git a/web/src/pages/data-flow/form/jin10-form/index.tsx b/web/src/pages/data-flow/form/jin10-form/index.tsx deleted file mode 100644 index 2bc6d774a..000000000 --- a/web/src/pages/data-flow/form/jin10-form/index.tsx +++ /dev/null @@ -1,145 +0,0 @@ -import { useTranslate } from '@/hooks/common-hooks'; -import { Form, Input, Select } from 'antd'; -import { useMemo } from 'react'; -import { IOperatorForm } from '../../interface'; -import { - Jin10CalendarDatashapeOptions, - Jin10CalendarTypeOptions, - Jin10FlashTypeOptions, - Jin10SymbolsDatatypeOptions, - Jin10SymbolsTypeOptions, - Jin10TypeOptions, -} from '../../options'; -import DynamicInputVariable from '../components/dynamic-input-variable'; - -const Jin10Form = ({ onValuesChange, form, node }: IOperatorForm) => { - const { t } = useTranslate('flow'); - - const jin10TypeOptions = useMemo(() => { - return Jin10TypeOptions.map((x) => ({ - value: x, - label: t(`jin10TypeOptions.${x}`), - })); - }, [t]); - - const jin10FlashTypeOptions = useMemo(() => { - return Jin10FlashTypeOptions.map((x) => ({ - value: x, - label: t(`jin10FlashTypeOptions.${x}`), - })); - }, [t]); - - const jin10CalendarTypeOptions = useMemo(() => { - return Jin10CalendarTypeOptions.map((x) => ({ - value: x, - label: t(`jin10CalendarTypeOptions.${x}`), - })); - }, [t]); - - const jin10CalendarDatashapeOptions = useMemo(() => { - return Jin10CalendarDatashapeOptions.map((x) => ({ - value: x, - label: t(`jin10CalendarDatashapeOptions.${x}`), - })); - }, [t]); - - const jin10SymbolsTypeOptions = useMemo(() => { - return Jin10SymbolsTypeOptions.map((x) => ({ - value: x, - label: t(`jin10SymbolsTypeOptions.${x}`), - })); - }, [t]); - - const jin10SymbolsDatatypeOptions = useMemo(() => { - return Jin10SymbolsDatatypeOptions.map((x) => ({ - value: x, - label: t(`jin10SymbolsDatatypeOptions.${x}`), - })); - }, [t]); - - return ( -
- - - - - - - - - {({ getFieldValue }) => { - const type = getFieldValue('type'); - switch (type) { - case 'flash': - return ( - <> - - - - - - - - - - - ); - - case 'calendar': - return ( - <> - - - - - - - - ); - - case 'symbols': - return ( - <> - - - - - - - - ); - - case 'news': - return ( - <> - - - - - - - - ); - - default: - return <>; - } - }} - -
- ); -}; - -export default Jin10Form; diff --git a/web/src/pages/data-flow/form/google-form/index.tsx b/web/src/pages/data-flow/form/parser-form/index.tsx similarity index 97% rename from web/src/pages/data-flow/form/google-form/index.tsx rename to web/src/pages/data-flow/form/parser-form/index.tsx index cec5ae4c7..3418d83a9 100644 --- a/web/src/pages/data-flow/form/google-form/index.tsx +++ b/web/src/pages/data-flow/form/parser-form/index.tsx @@ -11,6 +11,7 @@ import { } from '@/components/ui/form'; import { useTranslate } from '@/hooks/common-hooks'; import { zodResolver } from '@hookform/resolvers/zod'; +import { memo } from 'react'; import { useForm, useFormContext } from 'react-hook-form'; import { z } from 'zod'; import { initialGoogleValues } from '../../constant'; @@ -81,7 +82,7 @@ export function GoogleFormWidgets() { ); } -const GoogleForm = ({ node }: INextOperatorForm) => { +const ParserForm = ({ node }: INextOperatorForm) => { const { t } = useTranslate('flow'); const defaultValues = useFormValues(initialGoogleValues, node); @@ -136,4 +137,4 @@ const GoogleForm = ({ node }: INextOperatorForm) => { ); }; -export default GoogleForm; +export default memo(ParserForm); diff --git a/web/src/pages/data-flow/form/pubmed-form/index.tsx b/web/src/pages/data-flow/form/pubmed-form/index.tsx deleted file mode 100644 index a2c35d55c..000000000 --- a/web/src/pages/data-flow/form/pubmed-form/index.tsx +++ /dev/null @@ -1,90 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { TopNFormField } from '@/components/top-n-item'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { useTranslate } from '@/hooks/common-hooks'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { memo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { z } from 'zod'; -import { initialPubMedValues } from '../../constant'; -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 { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -export const PubMedFormPartialSchema = { - top_n: z.number(), - email: z.string().email(), -}; - -export const FormSchema = z.object({ - ...PubMedFormPartialSchema, - query: z.string(), -}); - -export function PubMedFormWidgets() { - const form = useFormContext(); - const { t } = useTranslate('flow'); - - return ( - <> - - ( - - {t('email')} - - - - - - )} - /> - - ); -} - -const outputList = buildOutputList(initialPubMedValues.outputs); - -function PubMedForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialPubMedValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - mode: 'onChange', - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - - - -
- -
-
- ); -} - -export default memo(PubMedForm); diff --git a/web/src/pages/data-flow/form/qweather-form/index.tsx b/web/src/pages/data-flow/form/qweather-form/index.tsx deleted file mode 100644 index eee088762..000000000 --- a/web/src/pages/data-flow/form/qweather-form/index.tsx +++ /dev/null @@ -1,157 +0,0 @@ -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { RAGFlowSelect } from '@/components/ui/select'; -import { useCallback, useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import { INextOperatorForm } from '../../interface'; -import { - QWeatherLangOptions, - QWeatherTimePeriodOptions, - QWeatherTypeOptions, - QWeatherUserTypeOptions, -} from '../../options'; -import { DynamicInputVariable } from '../components/next-dynamic-input-variable'; - -enum FormFieldName { - Type = 'type', - UserType = 'user_type', -} - -const QWeatherForm = ({ form, node }: INextOperatorForm) => { - const { t } = useTranslation(); - const typeValue = form.watch(FormFieldName.Type); - - const qWeatherLangOptions = useMemo(() => { - return QWeatherLangOptions.map((x) => ({ - value: x, - label: t(`flow.qWeatherLangOptions.${x}`), - })); - }, [t]); - - const qWeatherTypeOptions = useMemo(() => { - return QWeatherTypeOptions.map((x) => ({ - value: x, - label: t(`flow.qWeatherTypeOptions.${x}`), - })); - }, [t]); - - const qWeatherUserTypeOptions = useMemo(() => { - return QWeatherUserTypeOptions.map((x) => ({ - value: x, - label: t(`flow.qWeatherUserTypeOptions.${x}`), - })); - }, [t]); - - const getQWeatherTimePeriodOptions = useCallback(() => { - let options = QWeatherTimePeriodOptions; - const userType = form.getValues(FormFieldName.UserType); - if (userType === 'free') { - options = options.slice(0, 3); - } - return options.map((x) => ({ - value: x, - label: t(`flow.qWeatherTimePeriodOptions.${x}`), - })); - }, [form, t]); - - return ( -
- { - e.preventDefault(); - }} - > - - ( - - {t('flow.webApiKey')} - - - - - - )} - /> - ( - - {t('flow.lang')} - - - - - - )} - /> - ( - - {t('flow.type')} - - - - - - )} - /> - ( - - {t('flow.userType')} - - - - - - )} - /> - {typeValue === 'weather' && ( - ( - - {t('flow.timePeriod')} - - - - - - )} - /> - )} - - - ); -}; - -export default QWeatherForm; diff --git a/web/src/pages/data-flow/form/searxng-form/index.tsx b/web/src/pages/data-flow/form/searxng-form/index.tsx deleted file mode 100644 index 193e5d84e..000000000 --- a/web/src/pages/data-flow/form/searxng-form/index.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { TopNFormField } from '@/components/top-n-item'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { useTranslate } from '@/hooks/common-hooks'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { memo } from 'react'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; -import { initialSearXNGValues } from '../../constant'; -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 { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -const FormSchema = z.object({ - query: z.string(), - searxng_url: z.string().min(1), - top_n: z.string(), -}); - -const outputList = buildOutputList(initialSearXNGValues.outputs); - -function SearXNGForm({ node }: INextOperatorForm) { - const { t } = useTranslate('flow'); - const defaultValues = useFormValues(initialSearXNGValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - ( - - SearXNG URL - - - - - - )} - /> - - -
- -
-
- ); -} - -export default memo(SearXNGForm); diff --git a/web/src/pages/data-flow/form/tavily-extract-form/index.tsx b/web/src/pages/data-flow/form/tavily-extract-form/index.tsx deleted file mode 100644 index 45a9e0fe7..000000000 --- a/web/src/pages/data-flow/form/tavily-extract-form/index.tsx +++ /dev/null @@ -1,121 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { RAGFlowSelect } from '@/components/ui/select'; -import { buildOptions } from '@/utils/form'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { t } from 'i18next'; -import { memo } from 'react'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; -import { - TavilyExtractDepth, - TavilyExtractFormat, - initialTavilyExtractValues, -} from '../../constant'; -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 { PromptEditor } from '../components/prompt-editor'; -import { TavilyFormSchema } from '../tavily-form'; - -const outputList = buildOutputList(initialTavilyExtractValues.outputs); - -function TavilyExtractForm({ node }: INextOperatorForm) { - const values = useFormValues(initialTavilyExtractValues, node); - - const FormSchema = z.object({ - ...TavilyFormSchema, - urls: z.string(), - extract_depth: z.enum([ - TavilyExtractDepth.Advanced, - TavilyExtractDepth.Basic, - ]), - format: z.enum([TavilyExtractFormat.Text, TavilyExtractFormat.Markdown]), - }); - - const form = useForm>({ - defaultValues: values, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - ( - - URL - - - - - - )} - /> - ( - - {t('flow.extractDepth')} - - - - - - )} - /> - ( - - {t('flow.format')} - - - - - - )} - /> - - -
- -
-
- ); -} - -export default memo(TavilyExtractForm); diff --git a/web/src/pages/data-flow/form/tavily-form/dynamic-domain.tsx b/web/src/pages/data-flow/form/tavily-form/dynamic-domain.tsx deleted file mode 100644 index 4c34dc946..000000000 --- a/web/src/pages/data-flow/form/tavily-form/dynamic-domain.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import { BlockButton, Button } from '@/components/ui/button'; -import { - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { t } from 'i18next'; -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: '' })}> - {t('common.add')} - -
- ); -}; diff --git a/web/src/pages/data-flow/form/tavily-form/index.tsx b/web/src/pages/data-flow/form/tavily-form/index.tsx deleted file mode 100644 index afa8d859b..000000000 --- a/web/src/pages/data-flow/form/tavily-form/index.tsx +++ /dev/null @@ -1,214 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} 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 { t } from 'i18next'; -import { memo } from 'react'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; -import { - TavilySearchDepth, - TavilyTopic, - initialTavilyValues, -} from '../../constant'; -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 { QueryVariable } from '../components/query-variable'; -import { DynamicDomain } from './dynamic-domain'; -import { useValues } from './use-values'; -import { useWatchFormChange } from './use-watch-change'; - -export const TavilyFormSchema = { - api_key: z.string(), -}; - -const outputList = buildOutputList(initialTavilyValues.outputs); - -function TavilyForm({ node }: INextOperatorForm) { - const values = useValues(node); - - const FormSchema = z.object({ - ...TavilyFormSchema, - query: z.string(), - search_depth: z.enum([TavilySearchDepth.Advanced, TavilySearchDepth.Basic]), - topic: z.enum([TavilyTopic.News, TavilyTopic.General]), - max_results: z.coerce.number(), - days: z.coerce.number(), - include_answer: z.boolean(), - include_raw_content: z.boolean(), - include_images: z.boolean(), - include_image_descriptions: z.boolean(), - 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>({ - defaultValues: values, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - - ( - - {t('flow.searchDepth')} - - - - - - )} - /> - ( - - {t('flow.tavilyTopic')} - - - - - - )} - /> - ( - - {t('flow.maxResults')} - - - - - - )} - /> - ( - - {t('flow.days')} - - - - - - )} - /> - ( - - {t('flow.includeAnswer')} - - - - - - )} - /> - ( - - {t('flow.includeRawContent')} - - - - - - )} - /> - ( - - {t('flow.includeImages')} - - - - - - )} - /> - ( - - {t('flow.includeImageDescriptions')} - - - - - - )} - /> - - - - -
- -
-
- ); -} - -export default memo(TavilyForm); diff --git a/web/src/pages/data-flow/form/tavily-form/use-values.ts b/web/src/pages/data-flow/form/tavily-form/use-values.ts deleted file mode 100644 index 011e04005..000000000 --- a/web/src/pages/data-flow/form/tavily-form/use-values.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { RAGFlowNodeType } from '@/interfaces/database/agent'; -import { isEmpty } from 'lodash'; -import { useMemo } from 'react'; -import { initialTavilyValues } from '../../constant'; -import { convertToObjectArray } from '../../utils'; - -export function useValues(node?: RAGFlowNodeType) { - const values = useMemo(() => { - const formData = node?.data?.form; - - if (isEmpty(formData)) { - return initialTavilyValues; - } - - return { - ...formData, - include_domains: convertToObjectArray(formData.include_domains), - exclude_domains: convertToObjectArray(formData.exclude_domains), - }; - }, [node?.data?.form]); - - return values; -} diff --git a/web/src/pages/data-flow/form/tavily-form/use-watch-change.ts b/web/src/pages/data-flow/form/tavily-form/use-watch-change.ts deleted file mode 100644 index cb24dce68..000000000 --- a/web/src/pages/data-flow/form/tavily-form/use-watch-change.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useEffect } from 'react'; -import { UseFormReturn, useWatch } from 'react-hook-form'; -import useGraphStore from '../../store'; -import { convertToStringArray } from '../../utils'; - -export function useWatchFormChange(id?: string, form?: UseFormReturn) { - let values = useWatch({ control: form?.control }); - const updateNodeForm = useGraphStore((state) => state.updateNodeForm); - - useEffect(() => { - // Manually triggered form updates are synchronized to the canvas - if (id) { - values = form?.getValues(); - let nextValues: any = { - ...values, - include_domains: convertToStringArray(values.include_domains), - exclude_domains: convertToStringArray(values.exclude_domains), - }; - - updateNodeForm(id, nextValues); - } - }, [form?.formState.isDirty, id, updateNodeForm, values]); -} diff --git a/web/src/pages/data-flow/form/tushare-form/index.tsx b/web/src/pages/data-flow/form/tushare-form/index.tsx deleted file mode 100644 index a64bf25bf..000000000 --- a/web/src/pages/data-flow/form/tushare-form/index.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { useTranslate } from '@/hooks/common-hooks'; -import { DatePicker, DatePickerProps, Form, Input, Select } from 'antd'; -import dayjs from 'dayjs'; -import { useCallback, useMemo } from 'react'; -import { IOperatorForm } from '../../interface'; -import { TuShareSrcOptions } from '../../options'; -import DynamicInputVariable from '../components/dynamic-input-variable'; - -const DateTimePicker = ({ - onChange, - value, -}: { - onChange?: (val: number | undefined) => void; - value?: number | undefined; -}) => { - const handleChange: DatePickerProps['onChange'] = useCallback( - (val: any) => { - const nextVal = val?.format('YYYY-MM-DD HH:mm:ss'); - onChange?.(nextVal ? nextVal : undefined); - }, - [onChange], - ); - // The value needs to be converted into a string and saved to the backend - const nextValue = useMemo(() => { - if (value) { - return dayjs(value); - } - return undefined; - }, [value]); - - return ( - - ); -}; - -const TuShareForm = ({ onValuesChange, form, node }: IOperatorForm) => { - const { t } = useTranslate('flow'); - - const tuShareSrcOptions = useMemo(() => { - return TuShareSrcOptions.map((x) => ({ - value: x, - label: t(`tuShareSrcOptions.${x}`), - })); - }, [t]); - - return ( -
- - - - - - - - - - - - - - - - -
- ); -}; - -export default TuShareForm; diff --git a/web/src/pages/data-flow/form/wencai-form/index.tsx b/web/src/pages/data-flow/form/wencai-form/index.tsx deleted file mode 100644 index a4e668ed9..000000000 --- a/web/src/pages/data-flow/form/wencai-form/index.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { TopNFormField } from '@/components/top-n-item'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { RAGFlowSelect } from '@/components/ui/select'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { memo, useMemo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { z } from 'zod'; -import { initialWenCaiValues } from '../../constant'; -import { useFormValues } from '../../hooks/use-form-values'; -import { useWatchFormChange } from '../../hooks/use-watch-form-change'; -import { INextOperatorForm } from '../../interface'; -import { WenCaiQueryTypeOptions } from '../../options'; -import { buildOutputList } from '../../utils/build-output-list'; -import { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -export const WenCaiPartialSchema = { - top_n: z.number(), - query_type: z.string(), -}; - -export const FormSchema = z.object({ - ...WenCaiPartialSchema, - query: z.string(), -}); - -export function WenCaiFormWidgets() { - const { t } = useTranslation(); - const form = useFormContext(); - - const wenCaiQueryTypeOptions = useMemo(() => { - return WenCaiQueryTypeOptions.map((x) => ({ - value: x, - label: t(`flow.wenCaiQueryTypeOptions.${x}`), - })); - }, [t]); - - return ( - <> - - ( - - {t('flow.queryType')} - - - - - - )} - /> - - ); -} - -const outputList = buildOutputList(initialWenCaiValues.outputs); - -function WenCaiForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialWenCaiValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - - - -
- -
-
- ); -} - -export default memo(WenCaiForm); diff --git a/web/src/pages/data-flow/form/wikipedia-form/index.tsx b/web/src/pages/data-flow/form/wikipedia-form/index.tsx deleted file mode 100644 index 1603d802e..000000000 --- a/web/src/pages/data-flow/form/wikipedia-form/index.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -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 { zodResolver } from '@hookform/resolvers/zod'; -import { memo } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { z } from 'zod'; -import { initialWikipediaValues } from '../../constant'; -import { useFormValues } from '../../hooks/use-form-values'; -import { useWatchFormChange } from '../../hooks/use-watch-form-change'; -import { INextOperatorForm } from '../../interface'; -import { LanguageOptions } from '../../options'; -import { buildOutputList } from '../../utils/build-output-list'; -import { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -export const WikipediaFormPartialSchema = { - top_n: z.string(), - language: z.string(), -}; - -const FormSchema = z.object({ - query: z.string(), - ...WikipediaFormPartialSchema, -}); - -export function WikipediaFormWidgets() { - const { t } = useTranslate('common'); - const form = useFormContext(); - - return ( - <> - - ( - - {t('language')} - - - - - - )} - /> - - ); -} - -const outputList = buildOutputList(initialWikipediaValues.outputs); - -function WikipediaForm({ node }: INextOperatorForm) { - const defaultValues = useFormValues(initialWikipediaValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - -
- -
-
- ); -} - -export default memo(WikipediaForm); diff --git a/web/src/pages/data-flow/form/yahoo-finance-form/index.tsx b/web/src/pages/data-flow/form/yahoo-finance-form/index.tsx deleted file mode 100644 index 68a34836b..000000000 --- a/web/src/pages/data-flow/form/yahoo-finance-form/index.tsx +++ /dev/null @@ -1,125 +0,0 @@ -import { FormContainer } from '@/components/form-container'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Switch } from '@/components/ui/switch'; -import { useTranslate } from '@/hooks/common-hooks'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { ReactNode } from 'react'; -import { useForm, useFormContext } from 'react-hook-form'; -import { z } from 'zod'; -import { initialYahooFinanceValues } from '../../constant'; -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 { FormWrapper } from '../components/form-wrapper'; -import { Output } from '../components/output'; -import { QueryVariable } from '../components/query-variable'; - -export const YahooFinanceFormPartialSchema = { - info: z.boolean(), - history: z.boolean(), - financials: z.boolean(), - balance_sheet: z.boolean(), - cash_flow_statement: z.boolean(), - news: z.boolean(), -}; - -const FormSchema = z.object({ - stock_code: z.string(), - ...YahooFinanceFormPartialSchema, -}); - -interface SwitchFormFieldProps { - name: string; - label: ReactNode; -} -function SwitchFormField({ name, label }: SwitchFormFieldProps) { - const form = useFormContext(); - - return ( - ( - - {label} - - - - - - )} - /> - ); -} - -export function YahooFinanceFormWidgets() { - const { t } = useTranslate('flow'); - return ( - <> - - - - - - - - - - ); -} - -const outputList = buildOutputList(initialYahooFinanceValues.outputs); - -const YahooFinanceForm = ({ node }: INextOperatorForm) => { - const { t } = useTranslate('flow'); - - const defaultValues = useFormValues(initialYahooFinanceValues, node); - - const form = useForm>({ - defaultValues, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - return ( -
- - - - - - - - -
- -
-
- ); -}; - -export default YahooFinanceForm; diff --git a/web/src/pages/data-flow/hooks.tsx b/web/src/pages/data-flow/hooks.tsx index 5d1537623..779ba0928 100644 --- a/web/src/pages/data-flow/hooks.tsx +++ b/web/src/pages/data-flow/hooks.tsx @@ -18,7 +18,6 @@ import { initialAkShareValues, initialArXivValues, initialBaiduFanyiValues, - initialBaiduValues, initialBeginValues, initialBingValues, initialCategorizeValues, @@ -103,7 +102,6 @@ export const useInitializeOperatorParams = () => { llm_id: llmId, }, [Operator.DuckDuckGo]: initialDuckValues, - [Operator.Baidu]: initialBaiduValues, [Operator.Wikipedia]: initialWikipediaValues, [Operator.PubMed]: initialPubMedValues, [Operator.ArXiv]: initialArXivValues, diff --git a/web/src/pages/data-flow/hooks/use-add-node.ts b/web/src/pages/data-flow/hooks/use-add-node.ts index 625eeb5cd..e3dad598e 100644 --- a/web/src/pages/data-flow/hooks/use-add-node.ts +++ b/web/src/pages/data-flow/hooks/use-add-node.ts @@ -13,7 +13,6 @@ import { initialAkShareValues, initialArXivValues, initialBaiduFanyiValues, - initialBaiduValues, initialBeginValues, initialBingValues, initialCategorizeValues, @@ -82,7 +81,6 @@ export const useInitializeOperatorParams = () => { llm_id: llmId, }, [Operator.DuckDuckGo]: initialDuckValues, - [Operator.Baidu]: initialBaiduValues, [Operator.Wikipedia]: initialWikipediaValues, [Operator.PubMed]: initialPubMedValues, [Operator.ArXiv]: initialArXivValues, diff --git a/web/src/pages/data-flow/hooks/use-send-shared-message.ts b/web/src/pages/data-flow/hooks/use-send-shared-message.ts deleted file mode 100644 index d8e2d61de..000000000 --- a/web/src/pages/data-flow/hooks/use-send-shared-message.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { SharedFrom } from '@/constants/chat'; -import { useSetModalState } from '@/hooks/common-hooks'; -import { IEventList } from '@/hooks/use-send-message'; -import { - buildRequestBody, - useSendAgentMessage, -} from '@/pages/agent/chat/use-send-agent-message'; -import trim from 'lodash/trim'; -import { useCallback, useState } from 'react'; -import { useSearchParams } from 'umi'; - -export const useSendButtonDisabled = (value: string) => { - return trim(value) === ''; -}; - -export const useGetSharedChatSearchParams = () => { - const [searchParams] = useSearchParams(); - const data_prefix = 'data_'; - const data = Object.fromEntries( - searchParams - .entries() - .filter(([key]) => key.startsWith(data_prefix)) - .map(([key, value]) => [key.replace(data_prefix, ''), value]), - ); - return { - from: searchParams.get('from') as SharedFrom, - sharedId: searchParams.get('shared_id'), - locale: searchParams.get('locale'), - data: data, - visibleAvatar: searchParams.get('visible_avatar') - ? searchParams.get('visible_avatar') !== '1' - : true, - }; -}; - -export const useSendNextSharedMessage = ( - addEventList: (data: IEventList, messageId: string) => void, - isTaskMode: boolean, -) => { - const { from, sharedId: conversationId } = useGetSharedChatSearchParams(); - const url = `/api/v1/${from === SharedFrom.Agent ? 'agentbots' : 'chatbots'}/${conversationId}/completions`; - - const [params, setParams] = useState([]); - - const { - visible: parameterDialogVisible, - hideModal: hideParameterDialog, - showModal: showParameterDialog, - } = useSetModalState(); - - const ret = useSendAgentMessage(url, addEventList, params, true); - - const ok = useCallback( - (params: any[]) => { - if (isTaskMode) { - const msgBody = buildRequestBody(''); - - ret.sendMessage({ - message: msgBody, - beginInputs: params, - }); - } else { - setParams(params); - } - - hideParameterDialog(); - }, - [hideParameterDialog, isTaskMode, ret], - ); - - return { - ...ret, - hasError: false, - parameterDialogVisible, - hideParameterDialog, - showParameterDialog, - ok, - }; -}; diff --git a/web/src/pages/data-flow/share/index.tsx b/web/src/pages/data-flow/share/index.tsx deleted file mode 100644 index 26cdb0248..000000000 --- a/web/src/pages/data-flow/share/index.tsx +++ /dev/null @@ -1,223 +0,0 @@ -import { EmbedContainer } from '@/components/embed-container'; -import { FileUploadProps } from '@/components/file-upload'; -import { NextMessageInput } from '@/components/message-input/next'; -import MessageItem from '@/components/next-message-item'; -import PdfDrawer from '@/components/pdf-drawer'; -import { useClickDrawer } from '@/components/pdf-drawer/hooks'; -import { MessageType } from '@/constants/chat'; -import { - useFetchExternalAgentInputs, - useUploadCanvasFileWithProgress, -} from '@/hooks/use-agent-request'; -import { cn } from '@/lib/utils'; -import i18n from '@/locales/config'; -import DebugContent from '@/pages/agent/debug-content'; -import { useCacheChatLog } from '@/pages/agent/hooks/use-cache-chat-log'; -import { useAwaitCompentData } from '@/pages/agent/hooks/use-chat-logic'; -import { useSendButtonDisabled } from '@/pages/chat/hooks'; -import { buildMessageUuidWithRole } from '@/utils/chat'; -import { isEmpty } from 'lodash'; -import React, { forwardRef, useCallback } from 'react'; -import { AgentDialogueMode } from '../constant'; -import { - useGetSharedChatSearchParams, - useSendNextSharedMessage, -} from '../hooks/use-send-shared-message'; -import { ParameterDialog } from './parameter-dialog'; - -const ChatContainer = () => { - const { - sharedId: conversationId, - locale, - visibleAvatar, - } = useGetSharedChatSearchParams(); - const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } = - useClickDrawer(); - - const { uploadCanvasFile, loading } = - useUploadCanvasFileWithProgress(conversationId); - const { - addEventList, - setCurrentMessageId, - currentEventListWithoutMessageById, - clearEventList, - } = useCacheChatLog(); - - const { data: inputsData } = useFetchExternalAgentInputs(); - const isTaskMode = inputsData.mode === AgentDialogueMode.Task; - - const { - handlePressEnter, - handleInputChange, - value, - sendLoading, - scrollRef, - messageContainerRef, - derivedMessages, - hasError, - stopOutputMessage, - findReferenceByMessageId, - appendUploadResponseList, - parameterDialogVisible, - showParameterDialog, - sendFormMessage, - addNewestOneAnswer, - ok, - resetSession, - } = useSendNextSharedMessage(addEventList, isTaskMode); - const { buildInputList, handleOk, isWaitting } = useAwaitCompentData({ - derivedMessages, - sendFormMessage, - canvasId: conversationId as string, - }); - const sendDisabled = useSendButtonDisabled(value); - - const handleUploadFile: NonNullable = - useCallback( - async (files, options) => { - const ret = await uploadCanvasFile({ files, options }); - appendUploadResponseList(ret.data, files); - }, - [appendUploadResponseList, uploadCanvasFile], - ); - - React.useEffect(() => { - if (locale && i18n.language !== locale) { - i18n.changeLanguage(locale); - } - }, [locale, visibleAvatar]); - - React.useEffect(() => { - if (!isTaskMode && inputsData.prologue) { - addNewestOneAnswer({ - answer: inputsData.prologue, - }); - } - }, [inputsData.prologue, addNewestOneAnswer, isTaskMode]); - - React.useEffect(() => { - if (inputsData && inputsData.inputs && !isEmpty(inputsData.inputs)) { - showParameterDialog(); - } - }, [inputsData, showParameterDialog]); - - const handleInputsModalOk = (params: any[]) => { - ok(params); - }; - const handleReset = () => { - resetSession(); - clearEventList(); - }; - if (!conversationId) { - return
empty
; - } - return ( - <> - -
-
-
- {derivedMessages?.map((message, i) => { - return ( - - {message.role === MessageType.Assistant && - derivedMessages.length - 1 === i && ( - - )} - {message.role === MessageType.Assistant && - derivedMessages.length - 1 !== i && ( -
-
{message?.data?.tips}
- -
- {buildInputList(message)?.map((item) => item.value)} -
-
- )} -
- ); - })} -
-
-
- {isTaskMode || ( -
-
- -
-
- )} -
- - {visible && ( - - )} - {parameterDialogVisible && ( - - )} - - ); -}; - -export default forwardRef(ChatContainer); diff --git a/web/src/pages/data-flow/share/parameter-dialog.tsx b/web/src/pages/data-flow/share/parameter-dialog.tsx deleted file mode 100644 index 7b363836e..000000000 --- a/web/src/pages/data-flow/share/parameter-dialog.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { Modal } from '@/components/ui/modal/modal'; -import { IModalProps } from '@/interfaces/common'; -import DebugContent from '@/pages/agent/debug-content'; -import { buildBeginInputListFromObject } from '@/pages/agent/form/begin-form/utils'; -import { BeginQuery } from '@/pages/agent/interface'; - -interface IProps extends IModalProps { - ok(parameters: any[]): void; - data: Record>; -} -export function ParameterDialog({ ok, data }: IProps) { - return ( - -
- -
-
- ); -}