diff --git a/web/src/pages/data-flow/canvas/node/use-build-categorize-handle-positions.ts b/web/src/pages/data-flow/canvas/node/use-build-categorize-handle-positions.ts deleted file mode 100644 index 9973441e7..000000000 --- a/web/src/pages/data-flow/canvas/node/use-build-categorize-handle-positions.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { useUpdateNodeInternals } from '@xyflow/react'; -import { get } from 'lodash'; -import { useEffect, useMemo } from 'react'; -import { z } from 'zod'; -import { useCreateCategorizeFormSchema } from '../../form/categorize-form/use-form-schema'; - -export const useBuildCategorizeHandlePositions = ({ - data, - id, -}: { - id: string; - data: RAGFlowNodeType['data']; -}) => { - const updateNodeInternals = useUpdateNodeInternals(); - - const FormSchema = useCreateCategorizeFormSchema(); - - type FormSchemaType = z.infer; - - const items: Required = useMemo(() => { - return get(data, `form.items`, []); - }, [data]); - - const positions = useMemo(() => { - const list: Array<{ - top: number; - name: string; - uuid: string; - }> & - Required = []; - - items.forEach((x, idx) => { - list.push({ - ...x, - top: idx === 0 ? 86 : list[idx - 1].top + 8 + 24, - }); - }); - - return list; - }, [items]); - - useEffect(() => { - updateNodeInternals(id); - }, [id, updateNodeInternals, items]); - - return { positions }; -}; diff --git a/web/src/pages/data-flow/canvas/node/use-build-switch-handle-positions.ts b/web/src/pages/data-flow/canvas/node/use-build-switch-handle-positions.ts deleted file mode 100644 index ee221bf82..000000000 --- a/web/src/pages/data-flow/canvas/node/use-build-switch-handle-positions.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { ISwitchCondition, RAGFlowNodeType } from '@/interfaces/database/flow'; -import { useUpdateNodeInternals } from '@xyflow/react'; -import get from 'lodash/get'; -import { useEffect, useMemo } from 'react'; -import { SwitchElseTo } from '../../constant'; -import { generateSwitchHandleText } from '../../utils'; - -export const useBuildSwitchHandlePositions = ({ - data, - id, -}: { - id: string; - data: RAGFlowNodeType['data']; -}) => { - const updateNodeInternals = useUpdateNodeInternals(); - - const conditions: ISwitchCondition[] = useMemo(() => { - return get(data, 'form.conditions', []); - }, [data]); - - const positions = useMemo(() => { - const list: Array<{ - text: string; - top: number; - idx: number; - condition?: ISwitchCondition; - }> = []; - - [...conditions, ''].forEach((x, idx) => { - let top = idx === 0 ? 53 : list[idx - 1].top + 10 + 14 + 16 + 16; // case number (Case 1) height + flex gap - if (idx >= 1) { - const previousItems = conditions[idx - 1]?.items ?? []; - if (previousItems.length > 0) { - // top += 12; // ConditionBlock padding - top += previousItems.length * 26; // condition variable height - // top += (previousItems.length - 1) * 25; // operator height - } - } - - list.push({ - text: - idx < conditions.length - ? generateSwitchHandleText(idx) - : SwitchElseTo, - idx, - top, - condition: typeof x === 'string' ? undefined : x, - }); - }); - - return list; - }, [conditions]); - - useEffect(() => { - updateNodeInternals(id); - }, [id, updateNodeInternals, conditions]); - - return { positions }; -}; diff --git a/web/src/pages/data-flow/constant.tsx b/web/src/pages/data-flow/constant.tsx index 16649a8d1..3f04c5b00 100644 --- a/web/src/pages/data-flow/constant.tsx +++ b/web/src/pages/data-flow/constant.tsx @@ -1,21 +1,8 @@ -import { - initialKeywordsSimilarityWeightValue, - initialSimilarityThresholdValue, -} from '@/components/similarity-slider'; -import { - AgentGlobals, - CodeTemplateStrMap, - ProgrammingLanguage, -} from '@/constants/agent'; - import { ChatVariableEnabledField, variableEnabledFieldMap, } from '@/constants/chat'; -import { ModelVariableType } from '@/constants/knowledge'; -import i18n from '@/locales/config'; import { setInitialChatVariableEnabledFieldValue } from '@/utils/chat'; -import { t } from 'i18next'; import { Circle, @@ -89,29 +76,6 @@ export enum ImageParseMethod { OCR = 'ocr', } -const initialQueryBaseValues = { - query: [], -}; - -export const initialRetrievalValues = { - query: AgentGlobals.SysQuery, - top_n: 8, - top_k: 1024, - kb_ids: [], - rerank_id: '', - empty_response: '', - ...initialSimilarityThresholdValue, - ...initialKeywordsSimilarityWeightValue, - use_kg: false, - cross_languages: [], - outputs: { - formalized_content: { - type: 'string', - value: '', - }, - }, -}; - export const initialBeginValues = { mode: AgentDialogueMode.Conversational, prologue: `Hi! I'm your assistant. What can I do for you?`, @@ -126,175 +90,10 @@ export const variableCheckBoxFieldMap = Object.keys( return pre; }, {}); -const initialLlmBaseValues = { - ...variableCheckBoxFieldMap, - temperature: 0.1, - top_p: 0.3, - frequency_penalty: 0.7, - presence_penalty: 0.4, - max_tokens: 256, -}; - -export const initialGenerateValues = { - ...initialLlmBaseValues, - prompt: i18n.t('flow.promptText'), - cite: true, - message_history_window_size: 12, - parameters: [], -}; - -export const initialRewriteQuestionValues = { - ...initialLlmBaseValues, - language: '', - message_history_window_size: 6, -}; - -export const initialRelevantValues = { - ...initialLlmBaseValues, -}; - -export const initialCategorizeValues = { - ...initialLlmBaseValues, - query: AgentGlobals.SysQuery, - parameter: ModelVariableType.Precise, - message_history_window_size: 1, - items: [], - outputs: { - category_name: { - type: 'string', - }, - }, -}; - -export const initialMessageValues = { - content: [''], -}; - -export const initialKeywordExtractValues = { - ...initialLlmBaseValues, - top_n: 3, - ...initialQueryBaseValues, -}; - -export const initialExeSqlValues = { - sql: '', - db_type: 'mysql', - database: '', - username: '', - host: '', - port: 3306, - password: '', - max_records: 1024, - outputs: { - formalized_content: { - value: '', - type: 'string', - }, - json: { - value: [], - type: 'Array', - }, - }, -}; - -export const initialSwitchValues = { - conditions: [ - { - logical_operator: SwitchLogicOperatorOptions[0], - items: [ - { - operator: SwitchOperatorOptions[0].value, - }, - ], - to: [], - }, - ], - [SwitchElseTo]: [], -}; - -export const initialConcentratorValues = {}; - export const initialNoteValues = { text: '', }; -export const initialCrawlerValues = { - extract_type: 'markdown', - query: '', -}; - -export const initialInvokeValues = { - url: '', - method: 'GET', - timeout: 60, - headers: `{ - "Accept": "*/*", - "Cache-Control": "no-cache", - "Connection": "keep-alive" -}`, - proxy: '', - clean_html: false, - variables: [], - outputs: { - result: { - value: '', - type: 'string', - }, - }, -}; - -export const initialTemplateValues = { - content: '', - parameters: [], -}; - -export const initialEmailValues = { - smtp_server: '', - smtp_port: 465, - email: '', - password: '', - sender_name: '', - to_email: '', - cc_email: '', - subject: '', - content: '', - outputs: { - success: { - value: true, - type: 'boolean', - }, - }, -}; - -export const initialIterationValues = { - items_ref: '', - outputs: {}, -}; -export const initialIterationStartValues = { - outputs: { - item: { - type: 'unkown', - }, - index: { - type: 'integer', - }, - }, -}; - -export const initialCodeValues = { - lang: ProgrammingLanguage.Python, - script: CodeTemplateStrMap[ProgrammingLanguage.Python], - arguments: { - arg1: '', - arg2: '', - }, - outputs: {}, -}; - -export const initialWaitingDialogueValues = {}; - -export const initialChunkerValues = { outputs: {} }; - export const initialTokenizerValues = { search_method: [ TokenizerSearchMethod.Embedding, @@ -305,47 +104,6 @@ export const initialTokenizerValues = { outputs: {}, }; -export const initialAgentValues = { - ...initialLlmBaseValues, - description: '', - user_prompt: '', - sys_prompt: t('flow.sysPromptDefultValue'), - prompts: [{ role: PromptRole.User, content: `{${AgentGlobals.SysQuery}}` }], - message_history_window_size: 12, - max_retries: 3, - delay_after_error: 1, - visual_files_var: '', - max_rounds: 1, - exception_method: '', - exception_goto: [], - exception_default_value: '', - tools: [], - mcp: [], - cite: true, - outputs: { - // structured_output: { - // topic: { - // type: 'string', - // description: - // 'default:general. The category of the search.news is useful for retrieving real-time updates, particularly about politics, sports, and major current events covered by mainstream media sources. general is for broader, more general-purpose searches that may include a wide range of sources.', - // enum: ['general', 'news'], - // default: 'general', - // }, - // }, - content: { - type: 'string', - value: '', - }, - }, -}; - -export const initialUserFillUpValues = { - enable_tips: true, - tips: '', - inputs: [], - outputs: {}, -}; - export enum StringTransformMethod { Merge = 'merge', Split = 'split', @@ -360,18 +118,6 @@ export enum StringTransformDelimiter { Space = ' ', } -export const initialStringTransformValues = { - method: StringTransformMethod.Merge, - split_ref: '', - script: '', - delimiters: [StringTransformDelimiter.Comma], - outputs: { - result: { - type: 'string', - }, - }, -}; - export const initialParserValues = { outputs: {}, setups: [] }; export const initialSplitterValues = { 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 ac8ff52f2..707e48111 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,5 +1,4 @@ import { Operator } from '../constant'; -import BeginForm from '../form/begin-form'; import HierarchicalMergerForm from '../form/hierarchical-merger-form'; import ParserForm from '../form/parser-form'; import SplitterForm from '../form/splitter-form'; @@ -7,7 +6,7 @@ import TokenizerForm from '../form/tokenizer-form'; export const FormConfigMap = { [Operator.Begin]: { - component: BeginForm, + component: () => <>, }, [Operator.Note]: { component: () => <>, diff --git a/web/src/pages/data-flow/form-sheet/next.tsx b/web/src/pages/data-flow/form-sheet/next.tsx index aedd01b1b..6e9ce057a 100644 --- a/web/src/pages/data-flow/form-sheet/next.tsx +++ b/web/src/pages/data-flow/form-sheet/next.tsx @@ -15,7 +15,6 @@ import { AgentFormContext } from '../context'; import { useHandleNodeNameChange } from '../hooks/use-change-node-name'; import OperatorIcon from '../operator-icon'; import { FormConfigMap } from './form-config-map'; -import SingleDebugSheet from './single-debug-sheet'; interface IProps { node?: RAGFlowNodeType; @@ -31,9 +30,7 @@ const FormSheet = ({ visible, hideModal, node, - singleDebugDrawerVisible, chatVisible, - hideSingleDebugDrawer, }: IModalProps & IProps) => { const operatorName: Operator = node?.data.label as Operator; // const clickedToolId = useGraphStore((state) => state.clickedToolId); @@ -94,13 +91,6 @@ const FormSheet = ({ )} - {singleDebugDrawerVisible && ( - - )} ); }; diff --git a/web/src/pages/data-flow/form-sheet/single-debug-sheet/index.tsx b/web/src/pages/data-flow/form-sheet/single-debug-sheet/index.tsx deleted file mode 100644 index c5fe6e876..000000000 --- a/web/src/pages/data-flow/form-sheet/single-debug-sheet/index.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import CopyToClipboard from '@/components/copy-to-clipboard'; -import { Sheet, SheetContent, SheetHeader } from '@/components/ui/sheet'; -import { useDebugSingle, useFetchInputForm } from '@/hooks/use-agent-request'; -import { IModalProps } from '@/interfaces/common'; -import { cn } from '@/lib/utils'; -import { isEmpty } from 'lodash'; -import { X } from 'lucide-react'; -import { useCallback, useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import JsonView from 'react18-json-view'; -import 'react18-json-view/src/style.css'; -import DebugContent from '../../debug-content'; -import { transferInputsArrayToObject } from '../../form/begin-form/use-watch-change'; -import { buildBeginInputListFromObject } from '../../form/begin-form/utils'; - -interface IProps { - componentId?: string; -} - -const SingleDebugSheet = ({ - componentId, - visible, - hideModal, -}: IModalProps & IProps) => { - const { t } = useTranslation(); - const inputForm = useFetchInputForm(componentId); - const { debugSingle, data, loading } = useDebugSingle(); - - const list = useMemo(() => { - return buildBeginInputListFromObject(inputForm); - }, [inputForm]); - - const onOk = useCallback( - (nextValues: any[]) => { - if (componentId) { - debugSingle({ - component_id: componentId, - params: transferInputsArrayToObject(nextValues), - }); - } - }, - [componentId, debugSingle], - ); - - const content = JSON.stringify(data, null, 2); - - return ( - - - -
- {t('flow.testRun')} - -
-
-
- - {!isEmpty(data) ? ( -
-
- JSON - -
- -
- ) : null} -
-
-
- ); -}; - -export default SingleDebugSheet; diff --git a/web/src/pages/data-flow/form/begin-form/begin-dynamic-options.tsx b/web/src/pages/data-flow/form/begin-form/begin-dynamic-options.tsx deleted file mode 100644 index 12b2bfb4b..000000000 --- a/web/src/pages/data-flow/form/begin-form/begin-dynamic-options.tsx +++ /dev/null @@ -1,57 +0,0 @@ -'use client'; - -import { BlockButton, Button } from '@/components/ui/button'; -import { - FormControl, - FormField, - FormItem, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { X } from 'lucide-react'; -import { useFieldArray, useFormContext } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; - -export function BeginDynamicOptions() { - const { t } = useTranslation(); - const form = useFormContext(); - const name = 'options'; - - const { fields, remove, append } = useFieldArray({ - name: name, - control: form.control, - }); - - return ( -
- {fields.map((field, index) => { - const typeField = `${name}.${index}.value`; - return ( -
- ( - - - - - - - )} - /> - -
- ); - })} - append({ value: '' })} type="button"> - {t('flow.addField')} - -
- ); -} diff --git a/web/src/pages/data-flow/form/begin-form/index.tsx b/web/src/pages/data-flow/form/begin-form/index.tsx deleted file mode 100644 index ad4eb9d3e..000000000 --- a/web/src/pages/data-flow/form/begin-form/index.tsx +++ /dev/null @@ -1,205 +0,0 @@ -import { Collapse } from '@/components/collapse'; -import { Button } from '@/components/ui/button'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { RAGFlowSelect } from '@/components/ui/select'; -import { Switch } from '@/components/ui/switch'; -import { Textarea } from '@/components/ui/textarea'; -import { FormTooltip } from '@/components/ui/tooltip'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { t } from 'i18next'; -import { Plus } from 'lucide-react'; -import { memo, useEffect, useRef } from 'react'; -import { useForm, useWatch } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { z } from 'zod'; -import { AgentDialogueMode } from '../../constant'; -import { INextOperatorForm } from '../../interface'; -import { ParameterDialog } from './parameter-dialog'; -import { QueryTable } from './query-table'; -import { useEditQueryRecord } from './use-edit-query'; -import { useValues } from './use-values'; -import { useWatchFormChange } from './use-watch-change'; - -const ModeOptions = [ - { value: AgentDialogueMode.Conversational, label: t('flow.conversational') }, - { value: AgentDialogueMode.Task, label: t('flow.task') }, -]; - -function BeginForm({ node }: INextOperatorForm) { - const { t } = useTranslation(); - - const values = useValues(node); - - const FormSchema = z.object({ - enablePrologue: z.boolean().optional(), - prologue: z.string().trim().optional(), - mode: z.string(), - inputs: z - .array( - z.object({ - key: z.string(), - type: z.string(), - value: z.string(), - optional: z.boolean(), - name: z.string(), - options: z.array(z.union([z.number(), z.string(), z.boolean()])), - }), - ) - .optional(), - }); - - const form = useForm({ - defaultValues: values, - resolver: zodResolver(FormSchema), - }); - - useWatchFormChange(node?.id, form); - - const inputs = useWatch({ control: form.control, name: 'inputs' }); - const mode = useWatch({ control: form.control, name: 'mode' }); - - const enablePrologue = useWatch({ - control: form.control, - name: 'enablePrologue', - }); - - const previousModeRef = useRef(mode); - - useEffect(() => { - if ( - previousModeRef.current === AgentDialogueMode.Task && - mode === AgentDialogueMode.Conversational - ) { - form.setValue('enablePrologue', true); - } - previousModeRef.current = mode; - }, [mode, form]); - - const { - ok, - currentRecord, - visible, - hideModal, - showModal, - otherThanCurrentQuery, - handleDeleteRecord, - } = useEditQueryRecord({ - form, - node, - }); - - return ( -
-
- ( - - - {t('flow.mode')} - - - - - - - )} - /> - {mode === AgentDialogueMode.Conversational && ( - ( - - - {t('flow.openingSwitch')} - - - - - - - )} - /> - )} - {mode === AgentDialogueMode.Conversational && enablePrologue && ( - ( - - - {t('flow.openingCopy')} - - - - - - - )} - /> - )} - {/* Create a hidden field to make Form instance record this */} -
} - /> - - {t('flow.input')} - - - } - rightContent={ - - } - > - - - {visible && ( - - )} - -
- ); -} - -export default memo(BeginForm); diff --git a/web/src/pages/data-flow/form/begin-form/parameter-dialog.tsx b/web/src/pages/data-flow/form/begin-form/parameter-dialog.tsx deleted file mode 100644 index 3b9070437..000000000 --- a/web/src/pages/data-flow/form/begin-form/parameter-dialog.tsx +++ /dev/null @@ -1,226 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { - Dialog, - DialogContent, - DialogFooter, - DialogHeader, - DialogTitle, -} from '@/components/ui/dialog'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { RAGFlowSelect, RAGFlowSelectOptionType } from '@/components/ui/select'; -import { Switch } from '@/components/ui/switch'; -import { useTranslate } from '@/hooks/common-hooks'; -import { IModalProps } from '@/interfaces/common'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { isEmpty } from 'lodash'; -import { ChangeEvent, useEffect, useMemo } from 'react'; -import { useForm, useWatch } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { z } from 'zod'; -import { BeginQueryType, BeginQueryTypeIconMap } from '../../constant'; -import { BeginQuery } from '../../interface'; -import { BeginDynamicOptions } from './begin-dynamic-options'; - -type ModalFormProps = { - initialValue: BeginQuery; - otherThanCurrentQuery: BeginQuery[]; - submit(values: any): void; -}; - -const FormId = 'BeginParameterForm'; - -function ParameterForm({ - initialValue, - otherThanCurrentQuery, - submit, -}: ModalFormProps) { - const { t } = useTranslate('flow'); - const FormSchema = z.object({ - type: z.string(), - key: z - .string() - .trim() - .min(1) - .refine( - (value) => - !value || !otherThanCurrentQuery.some((x) => x.key === value), - { message: 'The key cannot be repeated!' }, - ), - optional: z.boolean(), - name: z.string().trim().min(1), - options: z - .array(z.object({ value: z.string().or(z.boolean()).or(z.number()) })) - .optional(), - }); - - const form = useForm>({ - resolver: zodResolver(FormSchema), - mode: 'onChange', - defaultValues: { - type: BeginQueryType.Line, - optional: false, - key: '', - name: '', - options: [], - }, - }); - - const options = useMemo(() => { - return Object.values(BeginQueryType).reduce( - (pre, cur) => { - const Icon = BeginQueryTypeIconMap[cur]; - - return [ - ...pre, - { - label: ( -
- - {t(cur.toLowerCase())} -
- ), - value: cur, - }, - ]; - }, - [], - ); - }, []); - - const type = useWatch({ - control: form.control, - name: 'type', - }); - - useEffect(() => { - if (!isEmpty(initialValue)) { - form.reset({ - ...initialValue, - options: initialValue.options?.map((x) => ({ value: x })), - }); - } - }, [form, initialValue]); - - function onSubmit(data: z.infer) { - const values = { ...data, options: data.options?.map((x) => x.value) }; - console.log('🚀 ~ onSubmit ~ values:', values); - - submit(values); - } - - const handleKeyChange = (e: ChangeEvent) => { - const name = form.getValues().name || ''; - form.setValue('key', e.target.value.trim()); - if (!name) { - form.setValue('name', e.target.value.trim()); - } - }; - return ( -
- - ( - - {t('type')} - - - - - - )} - /> - ( - - {t('key')} - - - - - - )} - /> - ( - - {t('name')} - - - - - - )} - /> - ( - - {t('optional')} - - - - - - )} - /> - {type === BeginQueryType.Options && ( - - )} - - - ); -} - -export function ParameterDialog({ - initialValue, - hideModal, - otherThanCurrentQuery, - submit, -}: ModalFormProps & IModalProps) { - const { t } = useTranslation(); - - return ( - - - - {t('flow.variableSettings')} - - - - - - - - ); -} diff --git a/web/src/pages/data-flow/form/begin-form/query-table.tsx b/web/src/pages/data-flow/form/begin-form/query-table.tsx deleted file mode 100644 index 5701c49b1..000000000 --- a/web/src/pages/data-flow/form/begin-form/query-table.tsx +++ /dev/null @@ -1,199 +0,0 @@ -'use client'; - -import { - ColumnDef, - ColumnFiltersState, - SortingState, - VisibilityState, - flexRender, - getCoreRowModel, - getFilteredRowModel, - getPaginationRowModel, - getSortedRowModel, - useReactTable, -} from '@tanstack/react-table'; -import { Pencil, Trash2 } from 'lucide-react'; -import * as React from 'react'; - -import { TableEmpty } from '@/components/table-skeleton'; -import { Button } from '@/components/ui/button'; -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from '@/components/ui/table'; -import { - Tooltip, - TooltipContent, - TooltipTrigger, -} from '@/components/ui/tooltip'; -import { cn } from '@/lib/utils'; -import { useTranslation } from 'react-i18next'; -import { BeginQuery } from '../../interface'; - -interface IProps { - data: BeginQuery[]; - deleteRecord(index: number): void; - showModal(index: number, record: BeginQuery): void; -} - -export function QueryTable({ data = [], deleteRecord, showModal }: IProps) { - const { t } = useTranslation(); - - const [sorting, setSorting] = React.useState([]); - const [columnFilters, setColumnFilters] = React.useState( - [], - ); - const [columnVisibility, setColumnVisibility] = - React.useState({}); - - const columns: ColumnDef[] = [ - { - accessorKey: 'key', - header: t('flow.key'), - meta: { cellClassName: 'max-w-30' }, - cell: ({ row }) => { - const key: string = row.getValue('key'); - return ( - - -
{key}
-
- -

{key}

-
-
- ); - }, - }, - { - accessorKey: 'name', - header: t('flow.name'), - meta: { cellClassName: 'max-w-30' }, - cell: ({ row }) => { - const name: string = row.getValue('name'); - return ( - - -
{name}
-
- -

{name}

-
-
- ); - }, - }, - { - accessorKey: 'type', - header: t('flow.type'), - cell: ({ row }) => ( -
- {t(`flow.${(row.getValue('type')?.toString() || '').toLowerCase()}`)} -
- ), - }, - { - accessorKey: 'optional', - header: t('flow.optional'), - cell: ({ row }) =>
{row.getValue('optional') ? 'Yes' : 'No'}
, - }, - { - id: 'actions', - enableHiding: false, - header: t('common.action'), - cell: ({ row }) => { - const record = row.original; - const idx = row.index; - - return ( -
- - -
- ); - }, - }, - ]; - - const table = useReactTable({ - data, - columns, - onSortingChange: setSorting, - onColumnFiltersChange: setColumnFilters, - getCoreRowModel: getCoreRowModel(), - getPaginationRowModel: getPaginationRowModel(), - getSortedRowModel: getSortedRowModel(), - getFilteredRowModel: getFilteredRowModel(), - onColumnVisibilityChange: setColumnVisibility, - state: { - sorting, - columnFilters, - columnVisibility, - }, - }); - - return ( -
-
- - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => { - return ( - - {header.isPlaceholder - ? null - : flexRender( - header.column.columnDef.header, - header.getContext(), - )} - - ); - })} - - ))} - - - {table.getRowModel().rows?.length ? ( - table.getRowModel().rows.map((row) => ( - - {row.getVisibleCells().map((cell) => ( - - {flexRender( - cell.column.columnDef.cell, - cell.getContext(), - )} - - ))} - - )) - ) : ( - - )} - -
-
-
- ); -} diff --git a/web/src/pages/data-flow/form/begin-form/use-edit-query.ts b/web/src/pages/data-flow/form/begin-form/use-edit-query.ts deleted file mode 100644 index 6942ba88b..000000000 --- a/web/src/pages/data-flow/form/begin-form/use-edit-query.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { useSetModalState } from '@/hooks/common-hooks'; -import { useSetSelectedRecord } from '@/hooks/logic-hooks'; -import { useCallback, useMemo, useState } from 'react'; -import { UseFormReturn, useWatch } from 'react-hook-form'; -import { BeginQuery, INextOperatorForm } from '../../interface'; - -export const useEditQueryRecord = ({ - form, -}: INextOperatorForm & { form: UseFormReturn }) => { - const { setRecord, currentRecord } = useSetSelectedRecord(); - const { visible, hideModal, showModal } = useSetModalState(); - const [index, setIndex] = useState(-1); - const inputs: BeginQuery[] = useWatch({ - control: form.control, - name: 'inputs', - }); - - const otherThanCurrentQuery = useMemo(() => { - return inputs.filter((item, idx) => idx !== index); - }, [index, inputs]); - - const handleEditRecord = useCallback( - (record: BeginQuery) => { - const inputs: BeginQuery[] = form?.getValues('inputs') || []; - - const nextQuery: BeginQuery[] = - index > -1 ? inputs.toSpliced(index, 1, record) : [...inputs, record]; - - form.setValue('inputs', nextQuery); - - hideModal(); - }, - [form, hideModal, index], - ); - - const handleShowModal = useCallback( - (idx?: number, record?: BeginQuery) => { - setIndex(idx ?? -1); - setRecord(record ?? ({} as BeginQuery)); - showModal(); - }, - [setRecord, showModal], - ); - - const handleDeleteRecord = useCallback( - (idx: number) => { - const inputs = form?.getValues('inputs') || []; - const nextInputs = inputs.filter( - (item: BeginQuery, index: number) => index !== idx, - ); - - form.setValue('inputs', nextInputs); - }, - [form], - ); - - return { - ok: handleEditRecord, - currentRecord, - setRecord, - visible, - hideModal, - showModal: handleShowModal, - otherThanCurrentQuery, - handleDeleteRecord, - }; -}; diff --git a/web/src/pages/data-flow/form/begin-form/use-values.ts b/web/src/pages/data-flow/form/begin-form/use-values.ts deleted file mode 100644 index 10326bae8..000000000 --- a/web/src/pages/data-flow/form/begin-form/use-values.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { isEmpty } from 'lodash'; -import { useMemo } from 'react'; -import { useTranslation } from 'react-i18next'; -import { AgentDialogueMode } from '../../constant'; -import { buildBeginInputListFromObject } from './utils'; - -export function useValues(node?: RAGFlowNodeType) { - const { t } = useTranslation(); - - const defaultValues = useMemo( - () => ({ - enablePrologue: true, - prologue: t('chat.setAnOpenerInitial'), - mode: AgentDialogueMode.Conversational, - inputs: [], - }), - [t], - ); - - const values = useMemo(() => { - const formData = node?.data?.form; - - if (isEmpty(formData)) { - return defaultValues; - } - - const inputs = buildBeginInputListFromObject(formData?.inputs); - - return { ...(formData || {}), inputs }; - }, [defaultValues, node?.data?.form]); - - return values; -} diff --git a/web/src/pages/data-flow/form/begin-form/use-watch-change.ts b/web/src/pages/data-flow/form/begin-form/use-watch-change.ts deleted file mode 100644 index f0da58068..000000000 --- a/web/src/pages/data-flow/form/begin-form/use-watch-change.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { omit } from 'lodash'; -import { useEffect } from 'react'; -import { UseFormReturn, useWatch } from 'react-hook-form'; -import { BeginQuery } from '../../interface'; -import useGraphStore from '../../store'; - -export function transferInputsArrayToObject(inputs: BeginQuery[] = []) { - return inputs.reduce>>((pre, cur) => { - pre[cur.key] = omit(cur, 'key'); - - return pre; - }, {}); -} - -export function useWatchFormChange(id?: string, form?: UseFormReturn) { - let values = useWatch({ control: form?.control }); - const updateNodeForm = useGraphStore((state) => state.updateNodeForm); - - useEffect(() => { - if (id) { - values = form?.getValues() || {}; - - const nextValues = { - ...values, - inputs: transferInputsArrayToObject(values.inputs), - }; - - updateNodeForm(id, nextValues); - } - }, [form?.formState.isDirty, id, updateNodeForm, values]); -} diff --git a/web/src/pages/data-flow/form/begin-form/utils.ts b/web/src/pages/data-flow/form/begin-form/utils.ts deleted file mode 100644 index 36038c4f6..000000000 --- a/web/src/pages/data-flow/form/begin-form/utils.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BeginQuery } from '../../interface'; - -export function buildBeginInputListFromObject( - inputs: Record>, -) { - return Object.entries(inputs || {}).reduce( - (pre, [key, value]) => { - pre.push({ ...(value || {}), key }); - - return pre; - }, - [], - ); -} diff --git a/web/src/pages/data-flow/form/components/api-key-field.tsx b/web/src/pages/data-flow/form/components/api-key-field.tsx deleted file mode 100644 index f9debfc4f..000000000 --- a/web/src/pages/data-flow/form/components/api-key-field.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { t } from 'i18next'; -import { useFormContext } from 'react-hook-form'; - -interface IApiKeyFieldProps { - placeholder?: string; -} -export function ApiKeyField({ placeholder }: IApiKeyFieldProps) { - const form = useFormContext(); - return ( - ( - - {t('flow.apiKey')} - - - - - - )} - /> - ); -} diff --git a/web/src/pages/data-flow/form/components/description-field.tsx b/web/src/pages/data-flow/form/components/description-field.tsx deleted file mode 100644 index 8fa2eef64..000000000 --- a/web/src/pages/data-flow/form/components/description-field.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { - FormControl, - FormField, - FormItem, - FormLabel, -} from '@/components/ui/form'; -import { Textarea } from '@/components/ui/textarea'; -import { t } from 'i18next'; -import { useFormContext } from 'react-hook-form'; - -export function DescriptionField() { - const form = useFormContext(); - return ( - ( - - {t('flow.description')} - - - - - )} - /> - ); -} diff --git a/web/src/pages/data-flow/form/components/dynamic-input-variable.tsx b/web/src/pages/data-flow/form/components/dynamic-input-variable.tsx deleted file mode 100644 index a5781fd16..000000000 --- a/web/src/pages/data-flow/form/components/dynamic-input-variable.tsx +++ /dev/null @@ -1,127 +0,0 @@ -import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; -import { Button, Collapse, Flex, Form, Input, Select } from 'antd'; -import { PropsWithChildren, useCallback } from 'react'; -import { useTranslation } from 'react-i18next'; -import { useBuildVariableOptions } from '../../hooks/use-get-begin-query'; - -import styles from './index.less'; - -interface IProps { - node?: RAGFlowNodeType; -} - -enum VariableType { - Reference = 'reference', - Input = 'input', -} - -const getVariableName = (type: string) => - type === VariableType.Reference ? 'component_id' : 'value'; - -const DynamicVariableForm = ({ node }: IProps) => { - const { t } = useTranslation(); - const valueOptions = useBuildVariableOptions(node?.id, node?.parentId); - const form = Form.useFormInstance(); - - const options = [ - { value: VariableType.Reference, label: t('flow.reference') }, - { value: VariableType.Input, label: t('flow.text') }, - ]; - - const handleTypeChange = useCallback( - (name: number) => () => { - setTimeout(() => { - form.setFieldValue(['query', name, 'component_id'], undefined); - form.setFieldValue(['query', name, 'value'], undefined); - }, 0); - }, - [form], - ); - - return ( - - {(fields, { add, remove }) => ( - <> - {fields.map(({ key, name, ...restField }) => ( - - - - - - {({ getFieldValue }) => { - const type = getFieldValue(['query', name, 'type']); - return ( - - {type === VariableType.Reference ? ( - - ) : ( - - )} - - ); - }} - - remove(name)} /> - - ))} - - - - - )} - - ); -}; - -export function FormCollapse({ - children, - title, -}: PropsWithChildren<{ title: string }>) { - return ( - {title}, - children, - }, - ]} - /> - ); -} - -const DynamicInputVariable = ({ node }: IProps) => { - const { t } = useTranslation(); - return ( - - - - ); -}; - -export default DynamicInputVariable; diff --git a/web/src/pages/data-flow/form/components/next-dynamic-input-variable.tsx b/web/src/pages/data-flow/form/components/next-dynamic-input-variable.tsx deleted file mode 100644 index 8b4cbd8a9..000000000 --- a/web/src/pages/data-flow/form/components/next-dynamic-input-variable.tsx +++ /dev/null @@ -1,135 +0,0 @@ -'use client'; - -import { SideDown } from '@/assets/icon/next-icon'; -import { Button } from '@/components/ui/button'; -import { - Collapsible, - CollapsibleContent, - CollapsibleTrigger, -} from '@/components/ui/collapsible'; -import { - FormControl, - FormDescription, - FormField, - FormItem, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; -import { RAGFlowSelect } from '@/components/ui/select'; -import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { Plus, Trash2 } from 'lucide-react'; -import { useFieldArray, useFormContext } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { useBuildVariableOptions } from '../../hooks/use-get-begin-query'; - -interface IProps { - node?: RAGFlowNodeType; -} - -enum VariableType { - Reference = 'reference', - Input = 'input', -} - -const getVariableName = (type: string) => - type === VariableType.Reference ? 'component_id' : 'value'; - -export function DynamicVariableForm({ node }: IProps) { - const { t } = useTranslation(); - const form = useFormContext(); - const { fields, remove, append } = useFieldArray({ - name: 'query', - control: form.control, - }); - - const valueOptions = useBuildVariableOptions(node?.id, node?.parentId); - - const options = [ - { value: VariableType.Reference, label: t('flow.reference') }, - { value: VariableType.Input, label: t('flow.text') }, - ]; - - return ( -
- {fields.map((field, index) => { - const typeField = `query.${index}.type`; - const typeValue = form.watch(typeField); - return ( -
- ( - - - - { - field.onChange(val); - form.resetField(`query.${index}.value`); - form.resetField(`query.${index}.component_id`); - }} - > - - - - )} - /> - ( - - - - {typeValue === VariableType.Reference ? ( - - ) : ( - - )} - - - - )} - /> - remove(index)} - /> -
- ); - })} - -
- ); -} - -export function DynamicInputVariable({ node }: IProps) { - const { t } = useTranslation(); - - return ( - - - - {t('flow.input')} - - - - - - - - ); -} diff --git a/web/src/pages/data-flow/form/components/prompt-editor/constant.ts b/web/src/pages/data-flow/form/components/prompt-editor/constant.ts deleted file mode 100644 index b6cf30ed9..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/constant.ts +++ /dev/null @@ -1 +0,0 @@ -export const ProgrammaticTag = 'programmatic'; diff --git a/web/src/pages/data-flow/form/components/prompt-editor/index.css b/web/src/pages/data-flow/form/components/prompt-editor/index.css deleted file mode 100644 index 8f3050647..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/index.css +++ /dev/null @@ -1,76 +0,0 @@ -.typeahead-popover { - background: #fff; - box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.3); - border-radius: 8px; - position: fixed; - z-index: 1000; -} - -.typeahead-popover ul { - list-style: none; - margin: 0; - max-height: 200px; - overflow-y: scroll; -} - -.typeahead-popover ul::-webkit-scrollbar { - display: none; -} - -.typeahead-popover ul { - -ms-overflow-style: none; - scrollbar-width: none; -} - -.typeahead-popover ul li { - margin: 0; - min-width: 180px; - font-size: 14px; - outline: none; - cursor: pointer; - border-radius: 8px; -} - -.typeahead-popover ul li.selected { - background: #eee; -} - -.typeahead-popover li { - margin: 0 8px 0 8px; - color: #050505; - cursor: pointer; - line-height: 16px; - font-size: 15px; - display: flex; - align-content: center; - flex-direction: row; - flex-shrink: 0; - background-color: #fff; - border: 0; -} - -.typeahead-popover li.active { - display: flex; - width: 20px; - height: 20px; - background-size: contain; -} - -.typeahead-popover li .text { - display: flex; - line-height: 20px; - flex-grow: 1; - min-width: 150px; -} - -.typeahead-popover li .icon { - display: flex; - width: 20px; - height: 20px; - user-select: none; - margin-right: 8px; - line-height: 16px; - background-size: contain; - background-repeat: no-repeat; - background-position: center; -} diff --git a/web/src/pages/data-flow/form/components/prompt-editor/index.tsx b/web/src/pages/data-flow/form/components/prompt-editor/index.tsx deleted file mode 100644 index caf6914b4..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/index.tsx +++ /dev/null @@ -1,181 +0,0 @@ -import { CodeHighlightNode, CodeNode } from '@lexical/code'; -import { - InitialConfigType, - LexicalComposer, -} from '@lexical/react/LexicalComposer'; -import { ContentEditable } from '@lexical/react/LexicalContentEditable'; -import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary'; -import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin'; -import { HeadingNode, QuoteNode } from '@lexical/rich-text'; -import { - $getRoot, - $getSelection, - EditorState, - Klass, - LexicalNode, -} from 'lexical'; - -import { - Tooltip, - TooltipContent, - TooltipTrigger, -} from '@/components/ui/tooltip'; -import { cn } from '@/lib/utils'; -import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { Variable } from 'lucide-react'; -import { ReactNode, useCallback, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { PasteHandlerPlugin } from './paste-handler-plugin'; -import theme from './theme'; -import { VariableNode } from './variable-node'; -import { VariableOnChangePlugin } from './variable-on-change-plugin'; -import VariablePickerMenuPlugin from './variable-picker-plugin'; - -// Catch any errors that occur during Lexical updates and log them -// or throw them as needed. If you don't throw them, Lexical will -// try to recover gracefully without losing user data. -function onError(error: Error) { - console.error(error); -} - -const Nodes: Array> = [ - HeadingNode, - QuoteNode, - CodeHighlightNode, - CodeNode, - VariableNode, -]; - -type PromptContentProps = { showToolbar?: boolean; multiLine?: boolean }; - -type IProps = { - value?: string; - onChange?: (value?: string) => void; - placeholder?: ReactNode; -} & PromptContentProps; - -function PromptContent({ - showToolbar = true, - multiLine = true, -}: PromptContentProps) { - const [editor] = useLexicalComposerContext(); - const [isBlur, setIsBlur] = useState(false); - const { t } = useTranslation(); - - const insertTextAtCursor = useCallback(() => { - editor.update(() => { - const selection = $getSelection(); - - if (selection !== null) { - selection.insertText(' /'); - } - }); - }, [editor]); - - const handleVariableIconClick = useCallback(() => { - insertTextAtCursor(); - }, [insertTextAtCursor]); - - const handleBlur = useCallback(() => { - setIsBlur(true); - }, []); - - const handleFocus = useCallback(() => { - setIsBlur(false); - }, []); - - return ( -
- {showToolbar && ( -
- - - - - - - -

{t('flow.insertVariableTip')}

-
-
-
- )} - -
- ); -} - -export function PromptEditor({ - value, - onChange, - placeholder, - showToolbar, - multiLine = true, -}: IProps) { - const { t } = useTranslation(); - const initialConfig: InitialConfigType = { - namespace: 'PromptEditor', - theme, - onError, - nodes: Nodes, - }; - - const onValueChange = useCallback( - (editorState: EditorState) => { - editorState?.read(() => { - // const listNodes = $nodesOfType(VariableNode); // to be removed - // const allNodes = $dfs(); - - const text = $getRoot().getTextContent(); - - onChange?.(text); - }); - }, - [onChange], - ); - - return ( -
- - - } - placeholder={ -
- {placeholder || t('common.promptPlaceholder')} -
- } - ErrorBoundary={LexicalErrorBoundary} - /> - - - -
-
- ); -} diff --git a/web/src/pages/data-flow/form/components/prompt-editor/paste-handler-plugin.tsx b/web/src/pages/data-flow/form/components/prompt-editor/paste-handler-plugin.tsx deleted file mode 100644 index a45a5e5fb..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/paste-handler-plugin.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { - $createParagraphNode, - $createTextNode, - $getSelection, - $isRangeSelection, - PASTE_COMMAND, -} from 'lexical'; -import { useEffect } from 'react'; - -function PasteHandlerPlugin() { - const [editor] = useLexicalComposerContext(); - useEffect(() => { - const removeListener = editor.registerCommand( - PASTE_COMMAND, - (clipboardEvent: ClipboardEvent) => { - const clipboardData = clipboardEvent.clipboardData; - if (!clipboardData) { - return false; - } - - const text = clipboardData.getData('text/plain'); - if (!text) { - return false; - } - - // Check if text contains line breaks - if (text.includes('\n')) { - editor.update(() => { - const selection = $getSelection(); - if (selection && $isRangeSelection(selection)) { - // Normalize line breaks, merge multiple consecutive line breaks into a single line break - const normalizedText = text.replace(/\n{2,}/g, '\n'); - - // Clear current selection - selection.removeText(); - - // Create a paragraph node to contain all content - const paragraph = $createParagraphNode(); - - // Split text by line breaks - const lines = normalizedText.split('\n'); - - // Process each line - lines.forEach((lineText, index) => { - // Add line text (if any) - if (lineText) { - const textNode = $createTextNode(lineText); - paragraph.append(textNode); - } - - // If not the last line, add a line break - if (index < lines.length - 1) { - const lineBreak = $createTextNode('\n'); - paragraph.append(lineBreak); - } - }); - - // Insert paragraph - selection.insertNodes([paragraph]); - } - }); - - // Prevent default paste behavior - clipboardEvent.preventDefault(); - return true; - } - - // If no line breaks, use default behavior - return false; - }, - 4, - ); - - return () => { - removeListener(); - }; - }, [editor]); - - return null; -} - -export { PasteHandlerPlugin }; diff --git a/web/src/pages/data-flow/form/components/prompt-editor/theme.ts b/web/src/pages/data-flow/form/components/prompt-editor/theme.ts deleted file mode 100644 index 1cc2bc155..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/theme.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - */ - -export default { - code: 'editor-code', - heading: { - h1: 'editor-heading-h1', - h2: 'editor-heading-h2', - h3: 'editor-heading-h3', - h4: 'editor-heading-h4', - h5: 'editor-heading-h5', - }, - image: 'editor-image', - link: 'editor-link', - list: { - listitem: 'editor-listitem', - nested: { - listitem: 'editor-nested-listitem', - }, - ol: 'editor-list-ol', - ul: 'editor-list-ul', - }, - ltr: 'ltr', - paragraph: 'editor-paragraph', - placeholder: 'editor-placeholder', - quote: 'editor-quote', - rtl: 'rtl', - text: { - bold: 'editor-text-bold', - code: 'editor-text-code', - hashtag: 'editor-text-hashtag', - italic: 'editor-text-italic', - overflowed: 'editor-text-overflowed', - strikethrough: 'editor-text-strikethrough', - underline: 'editor-text-underline', - underlineStrikethrough: 'editor-text-underlineStrikethrough', - }, -}; diff --git a/web/src/pages/data-flow/form/components/prompt-editor/variable-node.tsx b/web/src/pages/data-flow/form/components/prompt-editor/variable-node.tsx deleted file mode 100644 index 177c370c9..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/variable-node.tsx +++ /dev/null @@ -1,91 +0,0 @@ -import { BeginId } from '@/pages/flow/constant'; -import { DecoratorNode, LexicalNode, NodeKey } from 'lexical'; -import { ReactNode } from 'react'; -const prefix = BeginId + '@'; - -export class VariableNode extends DecoratorNode { - __value: string; - __label: string; - key?: NodeKey; - __parentLabel?: string | ReactNode; - __icon?: ReactNode; - - static getType(): string { - return 'variable'; - } - - static clone(node: VariableNode): VariableNode { - return new VariableNode( - node.__value, - node.__label, - node.__key, - node.__parentLabel, - node.__icon, - ); - } - - constructor( - value: string, - label: string, - key?: NodeKey, - parent?: string | ReactNode, - icon?: ReactNode, - ) { - super(key); - this.__value = value; - this.__label = label; - this.__parentLabel = parent; - this.__icon = icon; - } - - createDOM(): HTMLElement { - const dom = document.createElement('span'); - dom.className = 'mr-1'; - - return dom; - } - - updateDOM(): false { - return false; - } - - decorate(): ReactNode { - let content: ReactNode = ( -
{this.__label}
- ); - if (this.__parentLabel) { - content = ( -
-
{this.__icon}
-
{this.__parentLabel}
-
/
- {content} -
- ); - } - return ( -
- {content} -
- ); - } - - getTextContent(): string { - return `{${this.__value}}`; - } -} - -export function $createVariableNode( - value: string, - label: string, - parentLabel: string | ReactNode, - icon?: ReactNode, -): VariableNode { - return new VariableNode(value, label, undefined, parentLabel, icon); -} - -export function $isVariableNode( - node: LexicalNode | null | undefined, -): node is VariableNode { - return node instanceof VariableNode; -} diff --git a/web/src/pages/data-flow/form/components/prompt-editor/variable-on-change-plugin.tsx b/web/src/pages/data-flow/form/components/prompt-editor/variable-on-change-plugin.tsx deleted file mode 100644 index 86fa66db4..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/variable-on-change-plugin.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { EditorState, LexicalEditor } from 'lexical'; -import { useEffect } from 'react'; -import { ProgrammaticTag } from './constant'; - -interface IProps { - onChange: ( - editorState: EditorState, - editor?: LexicalEditor, - tags?: Set, - ) => void; -} - -export function VariableOnChangePlugin({ onChange }: IProps) { - // Access the editor through the LexicalComposerContext - const [editor] = useLexicalComposerContext(); - // Wrap our listener in useEffect to handle the teardown and avoid stale references. - useEffect(() => { - // most listeners return a teardown function that can be called to clean them up. - return editor.registerUpdateListener( - ({ editorState, tags, dirtyElements }) => { - // Check if there is a "programmatic" tag - const isProgrammaticUpdate = tags.has(ProgrammaticTag); - - // The onchange event is only triggered when the data is manually updated - // Otherwise, the content will be displayed incorrectly. - if (dirtyElements.size > 0 && !isProgrammaticUpdate) { - onChange(editorState); - } - }, - ); - }, [editor, onChange]); - - return null; -} diff --git a/web/src/pages/data-flow/form/components/prompt-editor/variable-picker-plugin.tsx b/web/src/pages/data-flow/form/components/prompt-editor/variable-picker-plugin.tsx deleted file mode 100644 index f429981c7..000000000 --- a/web/src/pages/data-flow/form/components/prompt-editor/variable-picker-plugin.tsx +++ /dev/null @@ -1,297 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - */ - -import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'; -import { - LexicalTypeaheadMenuPlugin, - MenuOption, - useBasicTypeaheadTriggerMatch, -} from '@lexical/react/LexicalTypeaheadMenuPlugin'; -import { - $createParagraphNode, - $createTextNode, - $getRoot, - $getSelection, - $isRangeSelection, - TextNode, -} from 'lexical'; -import React, { - ReactElement, - ReactNode, - useCallback, - useEffect, - useRef, -} from 'react'; -import * as ReactDOM from 'react-dom'; - -import { $createVariableNode } from './variable-node'; - -import { useBuildQueryVariableOptions } from '@/pages/agent/hooks/use-get-begin-query'; -import { ProgrammaticTag } from './constant'; -import './index.css'; -class VariableInnerOption extends MenuOption { - label: string; - value: string; - parentLabel: string | JSX.Element; - icon?: ReactNode; - - constructor( - label: string, - value: string, - parentLabel: string | JSX.Element, - icon?: ReactNode, - ) { - super(value); - this.label = label; - this.value = value; - this.parentLabel = parentLabel; - this.icon = icon; - } -} - -class VariableOption extends MenuOption { - label: ReactElement | string; - title: string; - options: VariableInnerOption[]; - - constructor( - label: ReactElement | string, - title: string, - options: VariableInnerOption[], - ) { - super(title); - this.label = label; - this.title = title; - this.options = options; - } -} - -function VariablePickerMenuItem({ - index, - option, - selectOptionAndCleanUp, -}: { - index: number; - option: VariableOption; - selectOptionAndCleanUp: ( - option: VariableOption | VariableInnerOption, - ) => void; -}) { - return ( -
  • -
    - {option.title} -
      - {option.options.map((x) => ( -
    • selectOptionAndCleanUp(x)} - className="hover:bg-slate-300 p-1" - > - {x.label} -
    • - ))} -
    -
    -
  • - ); -} - -export default function VariablePickerMenuPlugin({ - value, -}: { - value?: string; -}): JSX.Element { - const [editor] = useLexicalComposerContext(); - const isFirstRender = useRef(true); - - const checkForTriggerMatch = useBasicTypeaheadTriggerMatch('/', { - minLength: 0, - }); - - const [queryString, setQueryString] = React.useState(''); - - const options = useBuildQueryVariableOptions(); - - const buildNextOptions = useCallback(() => { - let filteredOptions = options; - if (queryString) { - const lowerQuery = queryString.toLowerCase(); - filteredOptions = options - .map((x) => ({ - ...x, - options: x.options.filter( - (y) => - y.label.toLowerCase().includes(lowerQuery) || - y.value.toLowerCase().includes(lowerQuery), - ), - })) - .filter((x) => x.options.length > 0); - } - - const nextOptions: VariableOption[] = filteredOptions.map( - (x) => - new VariableOption( - x.label, - x.title, - x.options.map((y) => { - return new VariableInnerOption(y.label, y.value, x.label, y.icon); - }), - ), - ); - return nextOptions; - }, [options, queryString]); - - const findItemByValue = useCallback( - (value: string) => { - const children = options.reduce< - Array<{ - label: string; - value: string; - parentLabel?: string | ReactNode; - icon?: ReactNode; - }> - >((pre, cur) => { - return pre.concat(cur.options); - }, []); - - return children.find((x) => x.value === value); - }, - [options], - ); - - const onSelectOption = useCallback( - ( - selectedOption: VariableOption | VariableInnerOption, - nodeToRemove: TextNode | null, - closeMenu: () => void, - ) => { - editor.update(() => { - const selection = $getSelection(); - - if (!$isRangeSelection(selection) || selectedOption === null) { - return; - } - - if (nodeToRemove) { - nodeToRemove.remove(); - } - const variableNode = $createVariableNode( - (selectedOption as VariableInnerOption).value, - selectedOption.label as string, - selectedOption.parentLabel as string | ReactNode, - selectedOption.icon as ReactNode, - ); - selection.insertNodes([variableNode]); - - closeMenu(); - }); - }, - [editor], - ); - - const parseTextToVariableNodes = useCallback( - (text: string) => { - const paragraph = $createParagraphNode(); - - // Regular expression to match content within {} - const regex = /{([^}]*)}/g; - let match; - let lastIndex = 0; - while ((match = regex.exec(text)) !== null) { - const { 1: content, index, 0: template } = match; - - // Add the previous text part (if any) - if (index > lastIndex) { - const textNode = $createTextNode(text.slice(lastIndex, index)); - - paragraph.append(textNode); - } - - // Add variable node or text node - const nodeItem = findItemByValue(content); - - if (nodeItem) { - paragraph.append( - $createVariableNode( - content, - nodeItem.label, - nodeItem.parentLabel, - nodeItem.icon, - ), - ); - } else { - paragraph.append($createTextNode(template)); - } - - // Update index - lastIndex = regex.lastIndex; - } - - // Add the last part of text (if any) - if (lastIndex < text.length) { - const textNode = $createTextNode(text.slice(lastIndex)); - paragraph.append(textNode); - } - - $getRoot().clear().append(paragraph); - - if ($isRangeSelection($getSelection())) { - $getRoot().selectEnd(); - } - }, - [findItemByValue], - ); - - useEffect(() => { - if (editor && value && isFirstRender.current) { - isFirstRender.current = false; - editor.update( - () => { - parseTextToVariableNodes(value); - }, - { tag: ProgrammaticTag }, - ); - } - }, [parseTextToVariableNodes, editor, value]); - - return ( - - onQueryChange={setQueryString} - onSelectOption={onSelectOption} - triggerFn={checkForTriggerMatch} - options={buildNextOptions()} - menuRenderFn={(anchorElementRef, { selectOptionAndCleanUp }) => { - const nextOptions = buildNextOptions(); - return anchorElementRef.current && nextOptions.length - ? ReactDOM.createPortal( -
    -
      - {nextOptions.map((option, i: number) => ( - - ))} -
    -
    , - anchorElementRef.current, - ) - : null; - }} - /> - ); -} diff --git a/web/src/pages/data-flow/form/components/query-variable.tsx b/web/src/pages/data-flow/form/components/query-variable.tsx deleted file mode 100644 index dafcb4cde..000000000 --- a/web/src/pages/data-flow/form/components/query-variable.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { SelectWithSearch } from '@/components/originui/select-with-search'; -import { - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { toLower } from 'lodash'; -import { ReactNode, useMemo } from 'react'; -import { useFormContext } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { VariableType } from '../../constant'; -import { useBuildQueryVariableOptions } from '../../hooks/use-get-begin-query'; - -type QueryVariableProps = { - name?: string; - type?: VariableType; - label?: ReactNode; -}; - -export function QueryVariable({ - name = 'query', - type, - label, -}: QueryVariableProps) { - const { t } = useTranslation(); - const form = useFormContext(); - - const nextOptions = useBuildQueryVariableOptions(); - - const finalOptions = useMemo(() => { - return type - ? nextOptions.map((x) => { - return { - ...x, - options: x.options.filter((y) => toLower(y.type).includes(type)), - }; - }) - : nextOptions; - }, [nextOptions, type]); - - return ( - ( - - {label || ( - - {t('flow.query')} - - )} - - - - - - )} - /> - ); -} diff --git a/web/src/pages/data-flow/form/splitter-form/index.tsx b/web/src/pages/data-flow/form/splitter-form/index.tsx index 26a0198c5..60676b5f6 100644 --- a/web/src/pages/data-flow/form/splitter-form/index.tsx +++ b/web/src/pages/data-flow/form/splitter-form/index.tsx @@ -65,26 +65,28 @@ const SplitterForm = ({ node }: INextOperatorForm) => { >
    {t('flow.delimiters')} - {fields.map((field, index) => ( -
    -
    - + {fields.map((field, index) => ( +
    +
    + + + +
    +
    - -
    - ))} + ))} +
    append({ value: '\n' })}> {t('common.add')} 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 e398a671f..3c10417e6 100644 --- a/web/src/pages/data-flow/hooks/use-add-node.ts +++ b/web/src/pages/data-flow/hooks/use-add-node.ts @@ -1,7 +1,5 @@ -import { useFetchModelId } from '@/hooks/logic-hooks'; import { Connection, Node, Position, ReactFlowInstance } from '@xyflow/react'; import humanId from 'human-id'; -import { t } from 'i18next'; import { lowerFirst } from 'lodash'; import { useCallback, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; @@ -9,32 +7,12 @@ import { NodeHandleId, NodeMap, Operator, - initialAgentValues, initialBeginValues, - initialCategorizeValues, - initialChunkerValues, - initialCodeValues, - initialConcentratorValues, - initialCrawlerValues, - initialEmailValues, - initialExeSqlValues, initialHierarchicalMergerValues, - initialInvokeValues, - initialIterationStartValues, - initialIterationValues, - initialKeywordExtractValues, - initialMessageValues, initialNoteValues, initialParserValues, - initialRelevantValues, - initialRetrievalValues, - initialRewriteQuestionValues, initialSplitterValues, - initialStringTransformValues, - initialSwitchValues, initialTokenizerValues, - initialUserFillUpValues, - initialWaitingDialogueValues, } from '../constant'; import useGraphStore from '../store'; import { @@ -42,63 +20,21 @@ import { getNodeDragHandle, } from '../utils'; -function isBottomSubAgent(type: string, position: Position) { - return ( - (type === Operator.Agent && position === Position.Bottom) || - type === Operator.Tool - ); -} export const useInitializeOperatorParams = () => { - const llmId = useFetchModelId(); - const initialFormValuesMap = useMemo(() => { return { [Operator.Begin]: initialBeginValues, - [Operator.Retrieval]: initialRetrievalValues, - [Operator.Categorize]: { ...initialCategorizeValues, llm_id: llmId }, - [Operator.Relevant]: { ...initialRelevantValues, llm_id: llmId }, - [Operator.RewriteQuestion]: { - ...initialRewriteQuestionValues, - llm_id: llmId, - }, - [Operator.Message]: initialMessageValues, - [Operator.KeywordExtract]: { - ...initialKeywordExtractValues, - llm_id: llmId, - }, - [Operator.ExeSQL]: initialExeSqlValues, - [Operator.Switch]: initialSwitchValues, - [Operator.Concentrator]: initialConcentratorValues, [Operator.Note]: initialNoteValues, - [Operator.Crawler]: initialCrawlerValues, - [Operator.Invoke]: initialInvokeValues, - [Operator.Email]: initialEmailValues, - [Operator.Iteration]: initialIterationValues, - [Operator.IterationStart]: initialIterationStartValues, - [Operator.Code]: initialCodeValues, - [Operator.WaitingDialogue]: initialWaitingDialogueValues, - [Operator.Agent]: { ...initialAgentValues, llm_id: llmId }, - [Operator.Tool]: {}, - [Operator.UserFillUp]: initialUserFillUpValues, - [Operator.StringTransform]: initialStringTransformValues, [Operator.Parser]: initialParserValues, - [Operator.Chunker]: initialChunkerValues, [Operator.Tokenizer]: initialTokenizerValues, [Operator.Splitter]: initialSplitterValues, [Operator.HierarchicalMerger]: initialHierarchicalMergerValues, }; - }, [llmId]); + }, []); const initializeOperatorParams = useCallback( - (operatorName: Operator, position: Position) => { + (operatorName: Operator) => { const initialValues = initialFormValuesMap[operatorName]; - if (isBottomSubAgent(operatorName, position)) { - return { - ...initialValues, - description: t('flow.descriptionMessage'), - user_prompt: t('flow.userPromptDefaultValue'), - }; - } return initialValues; }, @@ -175,95 +111,17 @@ function useAddChildEdge() { return { addChildEdge }; } -function useAddToolNode() { - const { nodes, edges, addEdge, getNode, addNode } = useGraphStore( - (state) => state, - ); - - const addToolNode = useCallback( - (newNode: Node, nodeId?: string): boolean => { - const agentNode = getNode(nodeId); - - if (agentNode) { - const childToolNodeIds = edges - .filter( - (x) => x.source === nodeId && x.sourceHandle === NodeHandleId.Tool, - ) - .map((x) => x.target); - - if ( - childToolNodeIds.length > 0 && - nodes.some((x) => x.id === childToolNodeIds[0]) - ) { - return false; - } - - newNode.position = { - x: agentNode.position.x - 82, - y: agentNode.position.y + 140, - }; - - addNode(newNode); - if (nodeId) { - addEdge({ - source: nodeId, - target: newNode.id, - sourceHandle: NodeHandleId.Tool, - targetHandle: NodeHandleId.End, - }); - } - return true; - } - return false; - }, - [addEdge, addNode, edges, getNode, nodes], - ); - - return { addToolNode }; -} - -function useResizeIterationNode() { - const { getNode, nodes, updateNode } = useGraphStore((state) => state); - - const resizeIterationNode = useCallback( - (type: string, position: Position, parentId?: string) => { - const parentNode = getNode(parentId); - if (parentNode && !isBottomSubAgent(type, position)) { - const MoveRightDistance = 310; - const childNodeList = nodes.filter((x) => x.parentId === parentId); - const maxX = Math.max(...childNodeList.map((x) => x.position.x)); - if (maxX + MoveRightDistance > parentNode.position.x) { - updateNode({ - ...parentNode, - width: (parentNode.width || 0) + MoveRightDistance, - position: { - x: parentNode.position.x + MoveRightDistance / 2, - y: parentNode.position.y, - }, - }); - } - } - }, - [getNode, nodes, updateNode], - ); - - return { resizeIterationNode }; -} type CanvasMouseEvent = Pick< React.MouseEvent, 'clientX' | 'clientY' >; export function useAddNode(reactFlowInstance?: ReactFlowInstance) { - const { edges, nodes, addEdge, addNode, getNode } = useGraphStore( - (state) => state, - ); + const { nodes, addNode } = useGraphStore((state) => state); const getNodeName = useGetNodeName(); const { initializeOperatorParams } = useInitializeOperatorParams(); const { calculateNewlyBackChildPosition } = useCalculateNewlyChildPosition(); const { addChildEdge } = useAddChildEdge(); - const { addToolNode } = useAddToolNode(); - const { resizeIterationNode } = useResizeIterationNode(); // const [reactFlowInstance, setReactFlowInstance] = // useState>(); @@ -281,7 +139,6 @@ export function useAddNode(reactFlowInstance?: ReactFlowInstance) { ) => (event?: CanvasMouseEvent): string | undefined => { const nodeId = params.nodeId; - const node = getNode(nodeId); // reactFlowInstance.project was renamed to reactFlowInstance.screenToFlowPosition // and you don't need to subtract the reactFlowBounds.left/top anymore @@ -312,112 +169,30 @@ export function useAddNode(reactFlowInstance?: ReactFlowInstance) { getNodeName(type), nodes, ), - form: initializeOperatorParams(type as Operator, params.position), + form: initializeOperatorParams(type as Operator), }, sourcePosition: Position.Right, targetPosition: Position.Left, dragHandle: getNodeDragHandle(type), }; - if (node && node.parentId) { - newNode.parentId = node.parentId; - newNode.extent = 'parent'; - const parentNode = getNode(node.parentId); - if (parentNode && !isBottomSubAgent(type, params.position)) { - resizeIterationNode(type, params.position, node.parentId); - } - } - - if (type === Operator.Iteration) { - newNode.width = 500; - newNode.height = 250; - const iterationStartNode: Node = { - id: `${Operator.IterationStart}:${humanId()}`, - type: 'iterationStartNode', - position: { x: 50, y: 100 }, - // draggable: false, - data: { - label: Operator.IterationStart, - name: Operator.IterationStart, - form: initialIterationStartValues, - }, - parentId: newNode.id, - extent: 'parent', - }; - addNode(newNode); - addNode(iterationStartNode); - if (nodeId) { - addEdge({ - source: nodeId, - target: newNode.id, - sourceHandle: NodeHandleId.Start, - targetHandle: NodeHandleId.End, - }); - } - return newNode.id; - } else if ( - type === Operator.Agent && - params.position === Position.Bottom - ) { - const agentNode = getNode(nodeId); - if (agentNode) { - // Calculate the coordinates of child nodes to prevent newly added child nodes from covering other child nodes - const allChildAgentNodeIds = edges - .filter( - (x) => - x.source === nodeId && - x.sourceHandle === NodeHandleId.AgentBottom, - ) - .map((x) => x.target); - - const xAxises = nodes - .filter((x) => allChildAgentNodeIds.some((y) => y === x.id)) - .map((x) => x.position.x); - - const maxX = Math.max(...xAxises); - - newNode.position = { - x: xAxises.length > 0 ? maxX + 262 : agentNode.position.x + 82, - y: agentNode.position.y + 140, - }; - } - addNode(newNode); - if (nodeId) { - addEdge({ - source: nodeId, - target: newNode.id, - sourceHandle: NodeHandleId.AgentBottom, - targetHandle: NodeHandleId.AgentTop, - }); - } - return newNode.id; - } else if (type === Operator.Tool) { - const toolNodeAdded = addToolNode(newNode, params.nodeId); - return toolNodeAdded ? newNode.id : undefined; - } else { - addNode(newNode); - addChildEdge(params.position, { - source: params.nodeId, - target: newNode.id, - sourceHandle: params.id, - }); - } + addNode(newNode); + addChildEdge(params.position, { + source: params.nodeId, + target: newNode.id, + sourceHandle: params.id, + }); return newNode.id; }, [ addChildEdge, - addEdge, addNode, - addToolNode, calculateNewlyBackChildPosition, - edges, - getNode, getNodeName, initializeOperatorParams, nodes, reactFlowInstance, - resizeIterationNode, ], ); diff --git a/web/src/pages/data-flow/hooks/use-before-delete.tsx b/web/src/pages/data-flow/hooks/use-before-delete.tsx index d08333c86..bbeeaae10 100644 --- a/web/src/pages/data-flow/hooks/use-before-delete.tsx +++ b/web/src/pages/data-flow/hooks/use-before-delete.tsx @@ -1,17 +1,12 @@ import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { Node, OnBeforeDelete } from '@xyflow/react'; +import { OnBeforeDelete } from '@xyflow/react'; import { Operator } from '../constant'; import useGraphStore from '../store'; -import { deleteAllDownstreamAgentsAndTool } from '../utils/delete-node'; -const UndeletableNodes = [Operator.Begin, Operator.IterationStart]; +const UndeletableNodes = [Operator.Begin]; export function useBeforeDelete() { - const { getOperatorTypeFromId, getNode } = useGraphStore((state) => state); - - const agentPredicate = (node: Node) => { - return getOperatorTypeFromId(node.id) === Operator.Agent; - }; + const { getOperatorTypeFromId } = useGraphStore((state) => state); const handleBeforeDelete: OnBeforeDelete = async ({ nodes, // Nodes to be deleted @@ -23,13 +18,6 @@ export function useBeforeDelete() { return false; } - if ( - operatorType === Operator.IterationStart && - !nodes.some((x) => x.id === node.parentId) - ) { - return false; - } - return true; }); @@ -51,27 +39,6 @@ export function useBeforeDelete() { return true; }); - // Delete the agent and tool nodes downstream of the agent node - if (nodes.some(agentPredicate)) { - nodes.filter(agentPredicate).forEach((node) => { - const { downstreamAgentAndToolEdges, downstreamAgentAndToolNodeIds } = - deleteAllDownstreamAgentsAndTool(node.id, edges); - - downstreamAgentAndToolNodeIds.forEach((nodeId) => { - const currentNode = getNode(nodeId); - if (toBeDeletedNodes.every((x) => x.id !== nodeId) && currentNode) { - toBeDeletedNodes.push(currentNode); - } - }); - - downstreamAgentAndToolEdges.forEach((edge) => { - if (toBeDeletedEdges.every((x) => x.id !== edge.id)) { - toBeDeletedEdges.push(edge); - } - }); - }, []); - } - return { nodes: toBeDeletedNodes, edges: toBeDeletedEdges, diff --git a/web/src/pages/data-flow/hooks/use-chat-logic.ts b/web/src/pages/data-flow/hooks/use-chat-logic.ts deleted file mode 100644 index 42b0533cb..000000000 --- a/web/src/pages/data-flow/hooks/use-chat-logic.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { MessageType } from '@/constants/chat'; -import { Message } from '@/interfaces/database/chat'; -import { IMessage } from '@/pages/chat/interface'; -import { get } from 'lodash'; -import { useCallback, useMemo } from 'react'; -import { BeginQuery } from '../interface'; -import { buildBeginQueryWithObject } from '../utils'; -type IAwaitCompentData = { - derivedMessages: IMessage[]; - sendFormMessage: (params: { - inputs: Record; - id: string; - }) => void; - canvasId: string; -}; -const useAwaitCompentData = (props: IAwaitCompentData) => { - const { derivedMessages, sendFormMessage, canvasId } = props; - - const getInputs = useCallback((message: Message) => { - return get(message, 'data.inputs', {}) as Record; - }, []); - - const buildInputList = useCallback( - (message: Message) => { - return Object.entries(getInputs(message)).map(([key, val]) => { - return { - ...val, - key, - }; - }); - }, - [getInputs], - ); - - const handleOk = useCallback( - (message: Message) => (values: BeginQuery[]) => { - const inputs = getInputs(message); - const nextInputs = buildBeginQueryWithObject(inputs, values); - sendFormMessage({ - inputs: nextInputs, - id: canvasId, - }); - }, - [getInputs, sendFormMessage, canvasId], - ); - - const isWaitting = useMemo(() => { - const temp = derivedMessages?.some((message, i) => { - const flag = - message.role === MessageType.Assistant && - derivedMessages.length - 1 === i && - message.data; - return flag; - }); - return temp; - }, [derivedMessages]); - return { getInputs, buildInputList, handleOk, isWaitting }; -}; - -export { useAwaitCompentData }; diff --git a/web/src/pages/data-flow/hooks/use-export-json.ts b/web/src/pages/data-flow/hooks/use-export-json.ts index 1efe6bb50..87a811cf5 100644 --- a/web/src/pages/data-flow/hooks/use-export-json.ts +++ b/web/src/pages/data-flow/hooks/use-export-json.ts @@ -1,71 +1,17 @@ -import { useToast } from '@/components/hooks/use-toast'; -import { FileMimeType, Platform } from '@/constants/common'; -import { useSetModalState } from '@/hooks/common-hooks'; import { useFetchAgent } from '@/hooks/use-agent-request'; -import { IGraph } from '@/interfaces/database/flow'; import { downloadJsonFile } from '@/utils/file-util'; -import { message } from 'antd'; -import isEmpty from 'lodash/isEmpty'; import { useCallback } from 'react'; -import { useTranslation } from 'react-i18next'; import { useBuildDslData } from './use-build-dsl'; -import { useSetGraphInfo } from './use-set-graph'; export const useHandleExportOrImportJsonFile = () => { const { buildDslData } = useBuildDslData(); - const { - visible: fileUploadVisible, - hideModal: hideFileUploadModal, - showModal: showFileUploadModal, - } = useSetModalState(); - const setGraphInfo = useSetGraphInfo(); const { data } = useFetchAgent(); - const { t } = useTranslation(); - const { toast } = useToast(); - - const onFileUploadOk = useCallback( - async ({ - fileList, - platform, - }: { - fileList: File[]; - platform: Platform; - }) => { - console.log('🚀 ~ useHandleExportOrImportJsonFile ~ platform:', platform); - if (fileList.length > 0) { - const file = fileList[0]; - if (file.type !== FileMimeType.Json) { - toast({ title: t('flow.jsonUploadTypeErrorMessage') }); - return; - } - - const graphStr = await file.text(); - const errorMessage = t('flow.jsonUploadContentErrorMessage'); - try { - const graph = JSON.parse(graphStr); - if (graphStr && !isEmpty(graph) && Array.isArray(graph?.nodes)) { - setGraphInfo(graph ?? ({} as IGraph)); - hideFileUploadModal(); - } else { - message.error(errorMessage); - } - } catch (error) { - message.error(errorMessage); - } - } - }, - [hideFileUploadModal, setGraphInfo, t, toast], - ); const handleExportJson = useCallback(() => { downloadJsonFile(buildDslData().graph, `${data.title}.json`); }, [buildDslData, data.title]); return { - fileUploadVisible, handleExportJson, - handleImportJson: showFileUploadModal, - hideFileUploadModal, - onFileUploadOk, }; }; diff --git a/web/src/pages/data-flow/hooks/use-find-mcp-by-id.ts b/web/src/pages/data-flow/hooks/use-find-mcp-by-id.ts deleted file mode 100644 index e4c5aed5a..000000000 --- a/web/src/pages/data-flow/hooks/use-find-mcp-by-id.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useListMcpServer } from '@/hooks/use-mcp-request'; - -export function useFindMcpById() { - const { data } = useListMcpServer(); - - const findMcpById = (id: string) => - data.mcp_servers.find((item) => item.id === id); - - return { - findMcpById, - }; -} diff --git a/web/src/pages/data-flow/hooks/use-get-begin-query.tsx b/web/src/pages/data-flow/hooks/use-get-begin-query.tsx deleted file mode 100644 index 83cda2078..000000000 --- a/web/src/pages/data-flow/hooks/use-get-begin-query.tsx +++ /dev/null @@ -1,317 +0,0 @@ -import { AgentGlobals } from '@/constants/agent'; -import { useFetchAgent } from '@/hooks/use-agent-request'; -import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { Edge } from '@xyflow/react'; -import { DefaultOptionType } from 'antd/es/select'; -import { t } from 'i18next'; -import { isEmpty } from 'lodash'; -import get from 'lodash/get'; -import { - ReactNode, - useCallback, - useContext, - useEffect, - useMemo, - useState, -} from 'react'; -import { - AgentDialogueMode, - BeginId, - BeginQueryType, - Operator, - VariableType, -} from '../constant'; -import { AgentFormContext } from '../context'; -import { buildBeginInputListFromObject } from '../form/begin-form/utils'; -import { BeginQuery } from '../interface'; -import OperatorIcon from '../operator-icon'; -import useGraphStore from '../store'; - -export function useSelectBeginNodeDataInputs() { - const getNode = useGraphStore((state) => state.getNode); - - return buildBeginInputListFromObject( - getNode(BeginId)?.data?.form?.inputs ?? {}, - ); -} - -export function useIsTaskMode() { - const getNode = useGraphStore((state) => state.getNode); - - return useMemo(() => { - const node = getNode(BeginId); - return node?.data?.form?.mode === AgentDialogueMode.Task; - }, [getNode]); -} - -export const useGetBeginNodeDataQuery = () => { - const getNode = useGraphStore((state) => state.getNode); - - const getBeginNodeDataQuery = useCallback(() => { - return buildBeginInputListFromObject( - get(getNode(BeginId), 'data.form.inputs', {}), - ); - }, [getNode]); - - return getBeginNodeDataQuery; -}; - -export const useGetBeginNodeDataInputs = () => { - const getNode = useGraphStore((state) => state.getNode); - - const inputs = get(getNode(BeginId), 'data.form.inputs', {}); - - const beginNodeDataInputs = useMemo(() => { - return buildBeginInputListFromObject(inputs); - }, [inputs]); - - return beginNodeDataInputs; -}; - -export const useGetBeginNodeDataQueryIsSafe = () => { - const [isBeginNodeDataQuerySafe, setIsBeginNodeDataQuerySafe] = - useState(false); - const inputs = useSelectBeginNodeDataInputs(); - const nodes = useGraphStore((state) => state.nodes); - - useEffect(() => { - const query: BeginQuery[] = inputs; - const isSafe = !query.some((q) => !q.optional && q.type === 'file'); - setIsBeginNodeDataQuerySafe(isSafe); - }, [inputs, nodes]); - - return isBeginNodeDataQuerySafe; -}; - -function filterAllUpstreamNodeIds(edges: Edge[], nodeIds: string[]) { - return nodeIds.reduce((pre, nodeId) => { - const currentEdges = edges.filter((x) => x.target === nodeId); - - const upstreamNodeIds: string[] = currentEdges.map((x) => x.source); - - const ids = upstreamNodeIds.concat( - filterAllUpstreamNodeIds(edges, upstreamNodeIds), - ); - - ids.forEach((x) => { - if (pre.every((y) => y !== x)) { - pre.push(x); - } - }); - - return pre; - }, []); -} - -export function buildOutputOptions( - outputs: Record = {}, - nodeId?: string, - parentLabel?: string | ReactNode, - icon?: ReactNode, -) { - return Object.keys(outputs).map((x) => ({ - label: x, - value: `${nodeId}@${x}`, - parentLabel, - icon, - type: outputs[x]?.type, - })); -} - -export function useBuildNodeOutputOptions(nodeId?: string) { - const nodes = useGraphStore((state) => state.nodes); - const edges = useGraphStore((state) => state.edges); - - const nodeOutputOptions = useMemo(() => { - if (!nodeId) { - return []; - } - const upstreamIds = filterAllUpstreamNodeIds(edges, [nodeId]); - - const nodeWithOutputList = nodes.filter( - (x) => - upstreamIds.some((y) => y === x.id) && !isEmpty(x.data?.form?.outputs), - ); - - return nodeWithOutputList - .filter((x) => x.id !== nodeId) - .map((x) => ({ - label: x.data.name, - value: x.id, - title: x.data.name, - options: buildOutputOptions( - x.data.form.outputs, - x.id, - x.data.name, - , - ), - })); - }, [edges, nodeId, nodes]); - - return nodeOutputOptions; -} - -// exclude nodes with branches -const ExcludedNodes = [ - Operator.Categorize, - Operator.Relevant, - Operator.Begin, - Operator.Note, -]; - -const StringList = [ - BeginQueryType.Line, - BeginQueryType.Paragraph, - BeginQueryType.Options, -]; - -function transferToVariableType(type: string) { - if (StringList.some((x) => x === type)) { - return VariableType.String; - } - return type; -} - -export function useBuildBeginVariableOptions() { - const inputs = useSelectBeginNodeDataInputs(); - - const options = useMemo(() => { - return [ - { - label: {t('flow.beginInput')}, - title: t('flow.beginInput'), - options: inputs.map((x) => ({ - label: x.name, - parentLabel: {t('flow.beginInput')}, - icon: , - value: `begin@${x.key}`, - type: transferToVariableType(x.type), - })), - }, - ]; - }, [inputs]); - - return options; -} - -export const useBuildVariableOptions = (nodeId?: string, parentId?: string) => { - const nodeOutputOptions = useBuildNodeOutputOptions(nodeId); - const parentNodeOutputOptions = useBuildNodeOutputOptions(parentId); - const beginOptions = useBuildBeginVariableOptions(); - - const options = useMemo(() => { - return [...beginOptions, ...nodeOutputOptions, ...parentNodeOutputOptions]; - }, [beginOptions, nodeOutputOptions, parentNodeOutputOptions]); - - return options; -}; - -export function useBuildQueryVariableOptions(n?: RAGFlowNodeType) { - const { data } = useFetchAgent(); - const node = useContext(AgentFormContext) || n; - const options = useBuildVariableOptions(node?.id, node?.parentId); - const nextOptions = useMemo(() => { - const globals = data?.dsl?.globals ?? {}; - const globalOptions = Object.entries(globals).map(([key, value]) => ({ - label: key, - value: key, - icon: , - parentLabel: {t('flow.beginInput')}, - type: Array.isArray(value) - ? `${VariableType.Array}${key === AgentGlobals.SysFiles ? '' : ''}` - : typeof value, - })); - return [ - { ...options[0], options: [...options[0]?.options, ...globalOptions] }, - ...options.slice(1), - ]; - }, [data.dsl?.globals, options]); - - return nextOptions; -} - -export function useBuildComponentIdOptions(nodeId?: string, parentId?: string) { - const nodes = useGraphStore((state) => state.nodes); - - // Limit the nodes inside iteration to only reference peer nodes with the same parentId and other external nodes other than their parent nodes - const filterChildNodesToSameParentOrExternal = useCallback( - (node: RAGFlowNodeType) => { - // Node inside iteration - if (parentId) { - return ( - (node.parentId === parentId || node.parentId === undefined) && - node.id !== parentId - ); - } - - return node.parentId === undefined; // The outermost node - }, - [parentId], - ); - - const componentIdOptions = useMemo(() => { - return nodes - .filter( - (x) => - x.id !== nodeId && - !ExcludedNodes.some((y) => y === x.data.label) && - filterChildNodesToSameParentOrExternal(x), - ) - .map((x) => ({ label: x.data.name, value: x.id })); - }, [nodes, nodeId, filterChildNodesToSameParentOrExternal]); - - return [ - { - label: Component Output, - title: 'Component Output', - options: componentIdOptions, - }, - ]; -} - -export function useBuildComponentIdAndBeginOptions( - nodeId?: string, - parentId?: string, -) { - const componentIdOptions = useBuildComponentIdOptions(nodeId, parentId); - const beginOptions = useBuildBeginVariableOptions(); - - return [...beginOptions, ...componentIdOptions]; -} - -export const useGetComponentLabelByValue = (nodeId: string) => { - const options = useBuildComponentIdAndBeginOptions(nodeId); - - const flattenOptions = useMemo(() => { - return options.reduce((pre, cur) => { - return [...pre, ...cur.options]; - }, []); - }, [options]); - - const getLabel = useCallback( - (val?: string) => { - return flattenOptions.find((x) => x.value === val)?.label; - }, - [flattenOptions], - ); - return getLabel; -}; - -export function useGetVariableLabelByValue(nodeId: string) { - const { getNode } = useGraphStore((state) => state); - const nextOptions = useBuildQueryVariableOptions(getNode(nodeId)); - - const flattenOptions = useMemo(() => { - return nextOptions.reduce((pre, cur) => { - return [...pre, ...cur.options]; - }, []); - }, [nextOptions]); - - const getLabel = useCallback( - (val?: string) => { - return flattenOptions.find((x) => x.value === val)?.label; - }, - [flattenOptions], - ); - return getLabel; -} diff --git a/web/src/pages/data-flow/hooks/use-iteration.ts b/web/src/pages/data-flow/hooks/use-iteration.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/web/src/pages/data-flow/hooks/use-run-dataflow.ts b/web/src/pages/data-flow/hooks/use-run-dataflow.ts index 9de8a7066..38bac8c7d 100644 --- a/web/src/pages/data-flow/hooks/use-run-dataflow.ts +++ b/web/src/pages/data-flow/hooks/use-run-dataflow.ts @@ -21,7 +21,6 @@ export function useRunDataflow(showLogSheet: () => void) { session_id: null, files: [fileResponseData.file], }); - console.log('🚀 ~ useRunDataflow ~ res:', res); if (res && res?.response.status === 200 && res?.data?.code === 0) { // fetch canvas diff --git a/web/src/pages/data-flow/hooks/use-show-drawer.tsx b/web/src/pages/data-flow/hooks/use-show-drawer.tsx index dd0fa5360..82a9bec85 100644 --- a/web/src/pages/data-flow/hooks/use-show-drawer.tsx +++ b/web/src/pages/data-flow/hooks/use-show-drawer.tsx @@ -5,7 +5,6 @@ import React, { useCallback, useEffect } from 'react'; import { BeginId, Operator } from '../constant'; import useGraphStore from '../store'; import { useCacheChatLog } from './use-cache-chat-log'; -import { useGetBeginNodeDataInputs } from './use-get-begin-query'; import { useSaveGraph } from './use-save-graph'; export const useShowFormDrawer = () => { @@ -84,20 +83,12 @@ export function useShowDrawer({ } = useShowSingleDebugDrawer(); const { formDrawerVisible, hideFormDrawer, showFormDrawer, clickedNode } = useShowFormDrawer(); - const inputs = useGetBeginNodeDataInputs(); useEffect(() => { if (drawerVisible) { showRunModal(); } - }, [ - hideChatModal, - hideRunModal, - showChatModal, - showRunModal, - drawerVisible, - inputs, - ]); + }, [hideChatModal, hideRunModal, showChatModal, showRunModal, drawerVisible]); const hideRunOrChatDrawer = useCallback(() => { hideChatModal(); diff --git a/web/src/pages/data-flow/index.tsx b/web/src/pages/data-flow/index.tsx index 10798b5e8..aa99e548c 100644 --- a/web/src/pages/data-flow/index.tsx +++ b/web/src/pages/data-flow/index.tsx @@ -21,7 +21,6 @@ import { ReactFlowProvider } from '@xyflow/react'; import { ChevronDown, CirclePlay, - Download, History, LaptopMinimalCheck, Settings, @@ -33,14 +32,12 @@ import DataFlowCanvas from './canvas'; import { DropdownProvider } from './canvas/context'; import { useHandleExportOrImportJsonFile } from './hooks/use-export-json'; import { useFetchDataOnMount } from './hooks/use-fetch-data'; -import { useGetBeginNodeDataInputs } from './hooks/use-get-begin-query'; import { useSaveGraph, useSaveGraphBeforeOpeningDebugDrawer, useWatchAgentChange, } from './hooks/use-save-graph'; import { SettingDialog } from './setting-dialog'; -import { UploadAgentDialog } from './upload-agent-dialog'; import { useAgentHistoryManager } from './use-agent-history-manager'; import { VersionDialog } from './version-dialog'; @@ -64,24 +61,13 @@ export default function DataFlow() { } = useSetModalState(); const { t } = useTranslation(); useAgentHistoryManager(); - const { - handleExportJson, - handleImportJson, - fileUploadVisible, - onFileUploadOk, - hideFileUploadModal, - } = useHandleExportOrImportJsonFile(); + const { handleExportJson } = useHandleExportOrImportJsonFile(); const { saveGraph, loading } = useSaveGraph(); const { flowDetail: agentDetail } = useFetchDataOnMount(); - const inputs = useGetBeginNodeDataInputs(); const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatDrawer); const handleRunAgent = useCallback(() => { - if (inputs.length > 0) { - showChatDrawer(); - } else { - handleRun(); - } - }, [handleRun, inputs, showChatDrawer]); + handleRun(); + }, [handleRun]); const { visible: versionDialogVisible, hideModal: hideVersionDialog, @@ -141,11 +127,6 @@ export default function DataFlow() { - - - {t('flow.import')} - - {t('flow.export')} @@ -167,12 +148,6 @@ export default function DataFlow() { > - {fileUploadVisible && ( - - )} {versionDialogVisible && ( diff --git a/web/src/pages/data-flow/options.ts b/web/src/pages/data-flow/options.ts deleted file mode 100644 index 63dd07a65..000000000 --- a/web/src/pages/data-flow/options.ts +++ /dev/null @@ -1,2174 +0,0 @@ -import { upperFirst } from 'lodash'; - -export const LanguageOptions = [ - { - value: 'af', - label: 'Afrikaans', - }, - { - value: 'pl', - label: 'Polski', - }, - { - value: 'ar', - label: 'العربية', - }, - { - value: 'ast', - label: 'Asturianu', - }, - { - value: 'az', - label: 'Azərbaycanca', - }, - { - value: 'bg', - label: 'Български', - }, - { - value: 'nan', - label: '閩南語 / Bân-lâm-gú', - }, - { - value: 'bn', - label: 'বাংলা', - }, - { - value: 'be', - label: 'Беларуская', - }, - { - value: 'ca', - label: 'Català', - }, - { - value: 'cs', - label: 'Čeština', - }, - { - value: 'cy', - label: 'Cymraeg', - }, - { - value: 'da', - label: 'Dansk', - }, - { - value: 'de', - label: 'Deutsch', - }, - { - value: 'fr', - label: 'Français', - }, - { - value: 'et', - label: 'Eesti', - }, - { - value: 'el', - label: 'Ελληνικά', - }, - { - value: 'en', - label: 'English', - }, - { - value: 'es', - label: 'Español', - }, - { - value: 'eo', - label: 'Esperanto', - }, - { - value: 'eu', - label: 'Euskara', - }, - { - value: 'fa', - label: 'فارسی', - }, - { - value: 'fr', - label: 'Français', - }, - { - value: 'gl', - label: 'Galego', - }, - { - value: 'ko', - label: '한국어', - }, - { - value: 'hy', - label: 'Հայերեն', - }, - { - value: 'hi', - label: 'हिन्दी', - }, - { - value: 'hr', - label: 'Hrvatski', - }, - { - value: 'id', - label: 'Bahasa Indonesia', - }, - { - value: 'it', - label: 'Italiano', - }, - { - value: 'he', - label: 'עברית', - }, - { - value: 'ka', - label: 'ქართული', - }, - { - value: 'lld', - label: 'Ladin', - }, - { - value: 'la', - label: 'Latina', - }, - { - value: 'lv', - label: 'Latviešu', - }, - { - value: 'lt', - label: 'Lietuvių', - }, - { - value: 'hu', - label: 'Magyar', - }, - { - value: 'mk', - label: 'Македонски', - }, - { - value: 'arz', - label: 'مصرى', - }, - { - value: 'ms', - label: 'Bahasa Melayu', - }, - { - value: 'min', - label: 'Bahaso Minangkabau', - }, - { - value: 'my', - label: 'မြန်မာဘာသာ', - }, - { - value: 'nl', - label: 'Nederlands', - }, - { - value: 'ja', - label: '日本語', - }, - { - value: 'no', - label: 'Norsk (bokmål)', - }, - { - value: 'nn', - label: 'Norsk (nynorsk)', - }, - { - value: 'ce', - label: 'Нохчийн', - }, - { - value: 'uz', - label: 'Oʻzbekcha / Ўзбекча', - }, - { - value: 'pt', - label: 'Português', - }, - { - value: 'kk', - label: 'Қазақша / Qazaqşa / قازاقشا', - }, - { - value: 'ro', - label: 'Română', - }, - { - value: 'ru', - label: 'Русский', - }, - { - value: 'ceb', - label: 'Sinugboanong Binisaya', - }, - { - value: 'sk', - label: 'Slovenčina', - }, - { - value: 'sl', - label: 'Slovenščina', - }, - { - value: 'sr', - label: 'Српски / Srpski', - }, - { - value: 'sh', - label: 'Srpskohrvatski / Српскохрватски', - }, - { - value: 'fi', - label: 'Suomi', - }, - { - value: 'sv', - label: 'Svenska', - }, - { - value: 'ta', - label: 'தமிழ்', - }, - { - value: 'tt', - label: 'Татарча / Tatarça', - }, - { - value: 'th', - label: 'ภาษาไทย', - }, - { - value: 'tg', - label: 'Тоҷикӣ', - }, - { - value: 'azb', - label: 'تۆرکجه', - }, - { - value: 'tr', - label: 'Türkçe', - }, - { - value: 'uk', - label: 'Українська', - }, - { - value: 'ur', - label: 'اردو', - }, - { - value: 'vi', - label: 'Tiếng Việt', - }, - { - value: 'war', - label: 'Winaray', - }, - { - value: 'zh', - label: '中文', - }, - { - value: 'yue', - label: '粵語', - }, -]; - -export const GoogleLanguageOptions = [ - { - language_code: 'af', - language_name: 'Afrikaans', - }, - { - language_code: 'ak', - language_name: 'Akan', - }, - { - language_code: 'sq', - language_name: 'Albanian', - }, - { - language_code: 'ws', - language_name: 'Samoa', - }, - { - language_code: 'am', - language_name: 'Amharic', - }, - { - language_code: 'ar', - language_name: 'Arabic', - }, - { - language_code: 'hy', - language_name: 'Armenian', - }, - { - language_code: 'az', - language_name: 'Azerbaijani', - }, - { - language_code: 'eu', - language_name: 'Basque', - }, - { - language_code: 'be', - language_name: 'Belarusian', - }, - { - language_code: 'bem', - language_name: 'Bemba', - }, - { - language_code: 'bn', - language_name: 'Bengali', - }, - { - language_code: 'bh', - language_name: 'Bihari', - }, - { - language_code: 'xx-bork', - language_name: 'Bork, bork, bork!', - }, - { - language_code: 'bs', - language_name: 'Bosnian', - }, - { - language_code: 'br', - language_name: 'Breton', - }, - { - language_code: 'bg', - language_name: 'Bulgarian', - }, - { - language_code: 'bt', - language_name: 'Bhutanese', - }, - { - language_code: 'km', - language_name: 'Cambodian', - }, - { - language_code: 'ca', - language_name: 'Catalan', - }, - { - language_code: 'chr', - language_name: 'Cherokee', - }, - { - language_code: 'ny', - language_name: 'Chichewa', - }, - { - language_code: 'zh-cn', - language_name: 'Chinese (Simplified)', - }, - { - language_code: 'zh-tw', - language_name: 'Chinese (Traditional)', - }, - { - language_code: 'co', - language_name: 'Corsican', - }, - { - language_code: 'hr', - language_name: 'Croatian', - }, - { - language_code: 'cs', - language_name: 'Czech', - }, - { - language_code: 'da', - language_name: 'Danish', - }, - { - language_code: 'nl', - language_name: 'Dutch', - }, - { - language_code: 'xx-elmer', - language_name: 'Elmer Fudd', - }, - { - language_code: 'en', - language_name: 'English', - }, - { - language_code: 'eo', - language_name: 'Esperanto', - }, - { - language_code: 'et', - language_name: 'Estonian', - }, - { - language_code: 'ee', - language_name: 'Ewe', - }, - { - language_code: 'fo', - language_name: 'Faroese', - }, - { - language_code: 'tl', - language_name: 'Filipino', - }, - { - language_code: 'fi', - language_name: 'Finnish', - }, - { - language_code: 'fr', - language_name: 'French', - }, - { - language_code: 'fy', - language_name: 'Frisian', - }, - { - language_code: 'gaa', - language_name: 'Ga', - }, - { - language_code: 'gl', - language_name: 'Galician', - }, - { - language_code: 'ka', - language_name: 'Georgian', - }, - { - language_code: 'de', - language_name: 'German', - }, - { - language_code: 'el', - language_name: 'Greek', - }, - { - language_code: 'kl', - language_name: 'Greenlandic', - }, - { - language_code: 'gn', - language_name: 'Guarani', - }, - { - language_code: 'gu', - language_name: 'Gujarati', - }, - { - language_code: 'xx-hacker', - language_name: 'Hacker', - }, - { - language_code: 'ht', - language_name: 'Haitian Creole', - }, - { - language_code: 'ha', - language_name: 'Hausa', - }, - { - language_code: 'haw', - language_name: 'Hawaiian', - }, - { - language_code: 'iw', - language_name: 'Hebrew', - }, - { - language_code: 'hi', - language_name: 'Hindi', - }, - { - language_code: 'hu', - language_name: 'Hungarian', - }, - { - language_code: 'is', - language_name: 'Icelandic', - }, - { - language_code: 'ig', - language_name: 'Igbo', - }, - { - language_code: 'id', - language_name: 'Indonesian', - }, - { - language_code: 'ia', - language_name: 'Interlingua', - }, - { - language_code: 'ga', - language_name: 'Irish', - }, - { - language_code: 'it', - language_name: 'Italian', - }, - { - language_code: 'ja', - language_name: 'Japanese', - }, - { - language_code: 'jw', - language_name: 'Javanese', - }, - { - language_code: 'kn', - language_name: 'Kannada', - }, - { - language_code: 'kk', - language_name: 'Kazakh', - }, - { - language_code: 'rw', - language_name: 'Kinyarwanda', - }, - { - language_code: 'rn', - language_name: 'Kirundi', - }, - { - language_code: 'xx-klingon', - language_name: 'Klingon', - }, - { - language_code: 'kg', - language_name: 'Kongo', - }, - { - language_code: 'ko', - language_name: 'Korean', - }, - { - language_code: 'kri', - language_name: 'Krio (Sierra Leone)', - }, - { - language_code: 'ku', - language_name: 'Kurdish', - }, - { - language_code: 'ckb', - language_name: 'Kurdish (Soranî)', - }, - { - language_code: 'ky', - language_name: 'Kyrgyz', - }, - { - language_code: 'lo', - language_name: 'Laothian', - }, - { - language_code: 'la', - language_name: 'Latin', - }, - { - language_code: 'lv', - language_name: 'Latvian', - }, - { - language_code: 'ln', - language_name: 'Lingala', - }, - { - language_code: 'lt', - language_name: 'Lithuanian', - }, - { - language_code: 'loz', - language_name: 'Lozi', - }, - { - language_code: 'lg', - language_name: 'Luganda', - }, - { - language_code: 'ach', - language_name: 'Luo', - }, - { - language_code: 'mk', - language_name: 'Macedonian', - }, - { - language_code: 'mg', - language_name: 'Malagasy', - }, - { - language_code: 'ms', - language_name: 'Malay', - }, - { - language_code: 'ml', - language_name: 'Malayalam', - }, - { - language_code: 'mt', - language_name: 'Maltese', - }, - { - language_code: 'mv', - language_name: 'Maldives', - }, - { - language_code: 'mi', - language_name: 'Maori', - }, - { - language_code: 'mr', - language_name: 'Marathi', - }, - { - language_code: 'mfe', - language_name: 'Mauritian Creole', - }, - { - language_code: 'mo', - language_name: 'Moldavian', - }, - { - language_code: 'mn', - language_name: 'Mongolian', - }, - { - language_code: 'sr-me', - language_name: 'Montenegrin', - }, - { - language_code: 'my', - language_name: 'Myanmar', - }, - { - language_code: 'ne', - language_name: 'Nepali', - }, - { - language_code: 'pcm', - language_name: 'Nigerian Pidgin', - }, - { - language_code: 'nso', - language_name: 'Northern Sotho', - }, - { - language_code: 'no', - language_name: 'Norwegian', - }, - { - language_code: 'nn', - language_name: 'Norwegian (Nynorsk)', - }, - { - language_code: 'oc', - language_name: 'Occitan', - }, - { - language_code: 'or', - language_name: 'Oriya', - }, - { - language_code: 'om', - language_name: 'Oromo', - }, - { - language_code: 'ps', - language_name: 'Pashto', - }, - { - language_code: 'fa', - language_name: 'Persian', - }, - { - language_code: 'xx-pirate', - language_name: 'Pirate', - }, - { - language_code: 'pl', - language_name: 'Polish', - }, - { - language_code: 'pt', - language_name: 'Portuguese', - }, - { - language_code: 'pt-br', - language_name: 'Portuguese (Brazil)', - }, - { - language_code: 'pt-pt', - language_name: 'Portuguese (Portugal)', - }, - { - language_code: 'pa', - language_name: 'Punjabi', - }, - { - language_code: 'qu', - language_name: 'Quechua', - }, - { - language_code: 'ro', - language_name: 'Romanian', - }, - { - language_code: 'rm', - language_name: 'Romansh', - }, - { - language_code: 'nyn', - language_name: 'Runyakitara', - }, - { - language_code: 'ru', - language_name: 'Russian', - }, - { - language_code: 'gd', - language_name: 'Scots Gaelic', - }, - { - language_code: 'sr', - language_name: 'Serbian', - }, - { - language_code: 'sh', - language_name: 'Serbo-Croatian', - }, - { - language_code: 'st', - language_name: 'Sesotho', - }, - { - language_code: 'tn', - language_name: 'Setswana', - }, - { - language_code: 'crs', - language_name: 'Seychellois Creole', - }, - { - language_code: 'sn', - language_name: 'Shona', - }, - { - language_code: 'sd', - language_name: 'Sindhi', - }, - { - language_code: 'si', - language_name: 'Sinhalese', - }, - { - language_code: 'sk', - language_name: 'Slovak', - }, - { - language_code: 'sl', - language_name: 'Slovenian', - }, - { - language_code: 'so', - language_name: 'Somali', - }, - { - language_code: 'es', - language_name: 'Spanish', - }, - { - language_code: 'es-419', - language_name: 'Spanish (Latin American)', - }, - { - language_code: 'su', - language_name: 'Sundanese', - }, - { - language_code: 'sw', - language_name: 'Swahili', - }, - { - language_code: 'sv', - language_name: 'Swedish', - }, - { - language_code: 'tg', - language_name: 'Tajik', - }, - { - language_code: 'ta', - language_name: 'Tamil', - }, - { - language_code: 'tt', - language_name: 'Tatar', - }, - { - language_code: 'te', - language_name: 'Telugu', - }, - { - language_code: 'th', - language_name: 'Thai', - }, - { - language_code: 'ti', - language_name: 'Tigrinya', - }, - { - language_code: 'to', - language_name: 'Tonga', - }, - { - language_code: 'lua', - language_name: 'Tshiluba', - }, - { - language_code: 'tum', - language_name: 'Tumbuka', - }, - { - language_code: 'tr', - language_name: 'Turkish', - }, - { - language_code: 'tk', - language_name: 'Turkmen', - }, - { - language_code: 'tw', - language_name: 'Twi', - }, - { - language_code: 'ug', - language_name: 'Uighur', - }, - { - language_code: 'uk', - language_name: 'Ukrainian', - }, - { - language_code: 'ur', - language_name: 'Urdu', - }, - { - language_code: 'uz', - language_name: 'Uzbek', - }, - { - language_code: 'vu', - language_name: 'Vanuatu', - }, - { - language_code: 'vi', - language_name: 'Vietnamese', - }, - { - language_code: 'cy', - language_name: 'Welsh', - }, - { - language_code: 'wo', - language_name: 'Wolof', - }, - { - language_code: 'xh', - language_name: 'Xhosa', - }, - { - language_code: 'yi', - language_name: 'Yiddish', - }, - { - language_code: 'yo', - language_name: 'Yoruba', - }, - { - language_code: 'zu', - language_name: 'Zulu', - }, -].map((x) => ({ label: x.language_name, value: x.language_code })); - -export const GoogleCountryOptions = [ - { - country_code: 'af', - country_name: 'Afghanistan', - }, - { - country_code: 'al', - country_name: 'Albania', - }, - { - country_code: 'dz', - country_name: 'Algeria', - }, - { - country_code: 'as', - country_name: 'American Samoa', - }, - { - country_code: 'ad', - country_name: 'Andorra', - }, - { - country_code: 'ao', - country_name: 'Angola', - }, - { - country_code: 'ai', - country_name: 'Anguilla', - }, - { - country_code: 'aq', - country_name: 'Antarctica', - }, - { - country_code: 'ag', - country_name: 'Antigua and Barbuda', - }, - { - country_code: 'ar', - country_name: 'Argentina', - }, - { - country_code: 'am', - country_name: 'Armenia', - }, - { - country_code: 'aw', - country_name: 'Aruba', - }, - { - country_code: 'au', - country_name: 'Australia', - }, - { - country_code: 'at', - country_name: 'Austria', - }, - { - country_code: 'az', - country_name: 'Azerbaijan', - }, - { - country_code: 'bs', - country_name: 'Bahamas', - }, - { - country_code: 'bh', - country_name: 'Bahrain', - }, - { - country_code: 'bd', - country_name: 'Bangladesh', - }, - { - country_code: 'bb', - country_name: 'Barbados', - }, - { - country_code: 'by', - country_name: 'Belarus', - }, - { - country_code: 'be', - country_name: 'Belgium', - }, - { - country_code: 'bz', - country_name: 'Belize', - }, - { - country_code: 'bj', - country_name: 'Benin', - }, - { - country_code: 'bm', - country_name: 'Bermuda', - }, - { - country_code: 'bt', - country_name: 'Bhutan', - }, - { - country_code: 'bo', - country_name: 'Bolivia', - }, - { - country_code: 'ba', - country_name: 'Bosnia and Herzegovina', - }, - { - country_code: 'bw', - country_name: 'Botswana', - }, - { - country_code: 'bv', - country_name: 'Bouvet Island', - }, - { - country_code: 'br', - country_name: 'Brazil', - }, - { - country_code: 'io', - country_name: 'British Indian Ocean Territory', - }, - { - country_code: 'bn', - country_name: 'Brunei Darussalam', - }, - { - country_code: 'bg', - country_name: 'Bulgaria', - }, - { - country_code: 'bf', - country_name: 'Burkina Faso', - }, - { - country_code: 'bi', - country_name: 'Burundi', - }, - { - country_code: 'kh', - country_name: 'Cambodia', - }, - { - country_code: 'cm', - country_name: 'Cameroon', - }, - { - country_code: 'ca', - country_name: 'Canada', - }, - { - country_code: 'cv', - country_name: 'Cape Verde', - }, - { - country_code: 'ky', - country_name: 'Cayman Islands', - }, - { - country_code: 'cf', - country_name: 'Central African Republic', - }, - { - country_code: 'td', - country_name: 'Chad', - }, - { - country_code: 'cl', - country_name: 'Chile', - }, - { - country_code: 'cn', - country_name: 'China', - }, - { - country_code: 'cx', - country_name: 'Christmas Island', - }, - { - country_code: 'cc', - country_name: 'Cocos (Keeling) Islands', - }, - { - country_code: 'co', - country_name: 'Colombia', - }, - { - country_code: 'km', - country_name: 'Comoros', - }, - { - country_code: 'cg', - country_name: 'Congo', - }, - { - country_code: 'cd', - country_name: 'Congo, the Democratic Republic of the', - }, - { - country_code: 'ck', - country_name: 'Cook Islands', - }, - { - country_code: 'cr', - country_name: 'Costa Rica', - }, - { - country_code: 'ci', - country_name: "Cote D'ivoire", - }, - { - country_code: 'hr', - country_name: 'Croatia', - }, - { - country_code: 'cu', - country_name: 'Cuba', - }, - { - country_code: 'cy', - country_name: 'Cyprus', - }, - { - country_code: 'cz', - country_name: 'Czech Republic', - }, - { - country_code: 'dk', - country_name: 'Denmark', - }, - { - country_code: 'dj', - country_name: 'Djibouti', - }, - { - country_code: 'dm', - country_name: 'Dominica', - }, - { - country_code: 'do', - country_name: 'Dominican Republic', - }, - { - country_code: 'ec', - country_name: 'Ecuador', - }, - { - country_code: 'eg', - country_name: 'Egypt', - }, - { - country_code: 'sv', - country_name: 'El Salvador', - }, - { - country_code: 'gq', - country_name: 'Equatorial Guinea', - }, - { - country_code: 'er', - country_name: 'Eritrea', - }, - { - country_code: 'ee', - country_name: 'Estonia', - }, - { - country_code: 'et', - country_name: 'Ethiopia', - }, - { - country_code: 'fk', - country_name: 'Falkland Islands (Malvinas)', - }, - { - country_code: 'fo', - country_name: 'Faroe Islands', - }, - { - country_code: 'fj', - country_name: 'Fiji', - }, - { - country_code: 'fi', - country_name: 'Finland', - }, - { - country_code: 'fr', - country_name: 'France', - }, - { - country_code: 'gf', - country_name: 'French Guiana', - }, - { - country_code: 'pf', - country_name: 'French Polynesia', - }, - { - country_code: 'tf', - country_name: 'French Southern Territories', - }, - { - country_code: 'ga', - country_name: 'Gabon', - }, - { - country_code: 'gm', - country_name: 'Gambia', - }, - { - country_code: 'ge', - country_name: 'Georgia', - }, - { - country_code: 'de', - country_name: 'Germany', - }, - { - country_code: 'gh', - country_name: 'Ghana', - }, - { - country_code: 'gi', - country_name: 'Gibraltar', - }, - { - country_code: 'gr', - country_name: 'Greece', - }, - { - country_code: 'gl', - country_name: 'Greenland', - }, - { - country_code: 'gd', - country_name: 'Grenada', - }, - { - country_code: 'gp', - country_name: 'Guadeloupe', - }, - { - country_code: 'gu', - country_name: 'Guam', - }, - { - country_code: 'gt', - country_name: 'Guatemala', - }, - { - country_code: 'gn', - country_name: 'Guinea', - }, - { - country_code: 'gw', - country_name: 'Guinea-Bissau', - }, - { - country_code: 'gy', - country_name: 'Guyana', - }, - { - country_code: 'ht', - country_name: 'Haiti', - }, - { - country_code: 'hm', - country_name: 'Heard Island and Mcdonald Islands', - }, - { - country_code: 'va', - country_name: 'Holy See (Vatican City State)', - }, - { - country_code: 'hn', - country_name: 'Honduras', - }, - { - country_code: 'hk', - country_name: 'Hong Kong', - }, - { - country_code: 'hu', - country_name: 'Hungary', - }, - { - country_code: 'is', - country_name: 'Iceland', - }, - { - country_code: 'in', - country_name: 'India', - }, - { - country_code: 'id', - country_name: 'Indonesia', - }, - { - country_code: 'ir', - country_name: 'Iran, Islamic Republic of', - }, - { - country_code: 'iq', - country_name: 'Iraq', - }, - { - country_code: 'ie', - country_name: 'Ireland', - }, - { - country_code: 'il', - country_name: 'Israel', - }, - { - country_code: 'it', - country_name: 'Italy', - }, - { - country_code: 'jm', - country_name: 'Jamaica', - }, - { - country_code: 'jp', - country_name: 'Japan', - }, - { - country_code: 'jo', - country_name: 'Jordan', - }, - { - country_code: 'kz', - country_name: 'Kazakhstan', - }, - { - country_code: 'ke', - country_name: 'Kenya', - }, - { - country_code: 'ki', - country_name: 'Kiribati', - }, - { - country_code: 'kp', - country_name: "Korea, Democratic People's Republic of", - }, - { - country_code: 'kr', - country_name: 'Korea, Republic of', - }, - { - country_code: 'kw', - country_name: 'Kuwait', - }, - { - country_code: 'kg', - country_name: 'Kyrgyzstan', - }, - { - country_code: 'la', - country_name: "Lao People's Democratic Republic", - }, - { - country_code: 'lv', - country_name: 'Latvia', - }, - { - country_code: 'lb', - country_name: 'Lebanon', - }, - { - country_code: 'ls', - country_name: 'Lesotho', - }, - { - country_code: 'lr', - country_name: 'Liberia', - }, - { - country_code: 'ly', - country_name: 'Libyan Arab Jamahiriya', - }, - { - country_code: 'li', - country_name: 'Liechtenstein', - }, - { - country_code: 'lt', - country_name: 'Lithuania', - }, - { - country_code: 'lu', - country_name: 'Luxembourg', - }, - { - country_code: 'mo', - country_name: 'Macao', - }, - { - country_code: 'mk', - country_name: 'Macedonia, the Former Yugosalv Republic of', - }, - { - country_code: 'mg', - country_name: 'Madagascar', - }, - { - country_code: 'mw', - country_name: 'Malawi', - }, - { - country_code: 'my', - country_name: 'Malaysia', - }, - { - country_code: 'mv', - country_name: 'Maldives', - }, - { - country_code: 'ml', - country_name: 'Mali', - }, - { - country_code: 'mt', - country_name: 'Malta', - }, - { - country_code: 'mh', - country_name: 'Marshall Islands', - }, - { - country_code: 'mq', - country_name: 'Martinique', - }, - { - country_code: 'mr', - country_name: 'Mauritania', - }, - { - country_code: 'mu', - country_name: 'Mauritius', - }, - { - country_code: 'yt', - country_name: 'Mayotte', - }, - { - country_code: 'mx', - country_name: 'Mexico', - }, - { - country_code: 'fm', - country_name: 'Micronesia, Federated States of', - }, - { - country_code: 'md', - country_name: 'Moldova, Republic of', - }, - { - country_code: 'mc', - country_name: 'Monaco', - }, - { - country_code: 'mn', - country_name: 'Mongolia', - }, - { - country_code: 'ms', - country_name: 'Montserrat', - }, - { - country_code: 'ma', - country_name: 'Morocco', - }, - { - country_code: 'mz', - country_name: 'Mozambique', - }, - { - country_code: 'mm', - country_name: 'Myanmar', - }, - { - country_code: 'na', - country_name: 'Namibia', - }, - { - country_code: 'nr', - country_name: 'Nauru', - }, - { - country_code: 'np', - country_name: 'Nepal', - }, - { - country_code: 'nl', - country_name: 'Netherlands', - }, - { - country_code: 'an', - country_name: 'Netherlands Antilles', - }, - { - country_code: 'nc', - country_name: 'New Caledonia', - }, - { - country_code: 'nz', - country_name: 'New Zealand', - }, - { - country_code: 'ni', - country_name: 'Nicaragua', - }, - { - country_code: 'ne', - country_name: 'Niger', - }, - { - country_code: 'ng', - country_name: 'Nigeria', - }, - { - country_code: 'nu', - country_name: 'Niue', - }, - { - country_code: 'nf', - country_name: 'Norfolk Island', - }, - { - country_code: 'mp', - country_name: 'Northern Mariana Islands', - }, - { - country_code: 'no', - country_name: 'Norway', - }, - { - country_code: 'om', - country_name: 'Oman', - }, - { - country_code: 'pk', - country_name: 'Pakistan', - }, - { - country_code: 'pw', - country_name: 'Palau', - }, - { - country_code: 'ps', - country_name: 'Palestinian Territory, Occupied', - }, - { - country_code: 'pa', - country_name: 'Panama', - }, - { - country_code: 'pg', - country_name: 'Papua New Guinea', - }, - { - country_code: 'py', - country_name: 'Paraguay', - }, - { - country_code: 'pe', - country_name: 'Peru', - }, - { - country_code: 'ph', - country_name: 'Philippines', - }, - { - country_code: 'pn', - country_name: 'Pitcairn', - }, - { - country_code: 'pl', - country_name: 'Poland', - }, - { - country_code: 'pt', - country_name: 'Portugal', - }, - { - country_code: 'pr', - country_name: 'Puerto Rico', - }, - { - country_code: 'qa', - country_name: 'Qatar', - }, - { - country_code: 're', - country_name: 'Reunion', - }, - { - country_code: 'ro', - country_name: 'Romania', - }, - { - country_code: 'ru', - country_name: 'Russian Federation', - }, - { - country_code: 'rw', - country_name: 'Rwanda', - }, - { - country_code: 'sh', - country_name: 'Saint Helena', - }, - { - country_code: 'kn', - country_name: 'Saint Kitts and Nevis', - }, - { - country_code: 'lc', - country_name: 'Saint Lucia', - }, - { - country_code: 'pm', - country_name: 'Saint Pierre and Miquelon', - }, - { - country_code: 'vc', - country_name: 'Saint Vincent and the Grenadines', - }, - { - country_code: 'ws', - country_name: 'Samoa', - }, - { - country_code: 'sm', - country_name: 'San Marino', - }, - { - country_code: 'st', - country_name: 'Sao Tome and Principe', - }, - { - country_code: 'sa', - country_name: 'Saudi Arabia', - }, - { - country_code: 'sn', - country_name: 'Senegal', - }, - { - country_code: 'rs', - country_name: 'Serbia and Montenegro', - }, - { - country_code: 'sc', - country_name: 'Seychelles', - }, - { - country_code: 'sl', - country_name: 'Sierra Leone', - }, - { - country_code: 'sg', - country_name: 'Singapore', - }, - { - country_code: 'sk', - country_name: 'Slovakia', - }, - { - country_code: 'si', - country_name: 'Slovenia', - }, - { - country_code: 'sb', - country_name: 'Solomon Islands', - }, - { - country_code: 'so', - country_name: 'Somalia', - }, - { - country_code: 'za', - country_name: 'South Africa', - }, - { - country_code: 'gs', - country_name: 'South Georgia and the South Sandwich Islands', - }, - { - country_code: 'es', - country_name: 'Spain', - }, - { - country_code: 'lk', - country_name: 'Sri Lanka', - }, - { - country_code: 'sd', - country_name: 'Sudan', - }, - { - country_code: 'sr', - country_name: 'Suriname', - }, - { - country_code: 'sj', - country_name: 'Svalbard and Jan Mayen', - }, - { - country_code: 'sz', - country_name: 'Swaziland', - }, - { - country_code: 'se', - country_name: 'Sweden', - }, - { - country_code: 'ch', - country_name: 'Switzerland', - }, - { - country_code: 'sy', - country_name: 'Syrian Arab Republic', - }, - { - country_code: 'tw', - country_name: 'Taiwan, Province of China', - }, - { - country_code: 'tj', - country_name: 'Tajikistan', - }, - { - country_code: 'tz', - country_name: 'Tanzania, United Republic of', - }, - { - country_code: 'th', - country_name: 'Thailand', - }, - { - country_code: 'tl', - country_name: 'Timor-Leste', - }, - { - country_code: 'tg', - country_name: 'Togo', - }, - { - country_code: 'tk', - country_name: 'Tokelau', - }, - { - country_code: 'to', - country_name: 'Tonga', - }, - { - country_code: 'tt', - country_name: 'Trinidad and Tobago', - }, - { - country_code: 'tn', - country_name: 'Tunisia', - }, - { - country_code: 'tr', - country_name: 'Turkiye', - }, - { - country_code: 'tm', - country_name: 'Turkmenistan', - }, - { - country_code: 'tc', - country_name: 'Turks and Caicos Islands', - }, - { - country_code: 'tv', - country_name: 'Tuvalu', - }, - { - country_code: 'ug', - country_name: 'Uganda', - }, - { - country_code: 'ua', - country_name: 'Ukraine', - }, - { - country_code: 'ae', - country_name: 'United Arab Emirates', - }, - { - country_code: 'uk', - country_name: 'United Kingdom', - }, - { - country_code: 'gb', - country_name: 'United Kingdom', - }, - { - country_code: 'us', - country_name: 'United States', - }, - { - country_code: 'um', - country_name: 'United States Minor Outlying Islands', - }, - { - country_code: 'uy', - country_name: 'Uruguay', - }, - { - country_code: 'uz', - country_name: 'Uzbekistan', - }, - { - country_code: 'vu', - country_name: 'Vanuatu', - }, - { - country_code: 've', - country_name: 'Venezuela', - }, - { - country_code: 'vn', - country_name: 'Viet Nam', - }, - { - country_code: 'vg', - country_name: 'Virgin Islands, British', - }, - { - country_code: 'vi', - country_name: 'Virgin Islands, U.S.', - }, - { - country_code: 'wf', - country_name: 'Wallis and Futuna', - }, - { - country_code: 'eh', - country_name: 'Western Sahara', - }, - { - country_code: 'ye', - country_name: 'Yemen', - }, - { - country_code: 'zm', - country_name: 'Zambia', - }, - { - country_code: 'zw', - country_name: 'Zimbabwe', - }, -].map((x) => ({ label: x.country_name, value: x.country_code })); - -export const BingCountryOptions = [ - { label: 'Argentina AR', value: 'AR' }, - { label: 'Australia AU', value: 'AU' }, - { label: 'Austria AT', value: 'AT' }, - { label: 'Belgium BE', value: 'BE' }, - { label: 'Brazil BR', value: 'BR' }, - { label: 'Canada CA', value: 'CA' }, - { label: 'Chile CL', value: 'CL' }, - { label: 'Denmark DK', value: 'DK' }, - { label: 'Finland FI', value: 'FI' }, - { label: 'France FR', value: 'FR' }, - { label: 'Germany DE', value: 'DE' }, - { label: 'Hong Kong SAR HK', value: 'HK' }, - { label: 'India IN', value: 'IN' }, - { label: 'Indonesia ID', value: 'ID' }, - { label: 'Italy IT', value: 'IT' }, - { label: 'Japan JP', value: 'JP' }, - { label: 'Korea KR', value: 'KR' }, - { label: 'Malaysia MY', value: 'MY' }, - { label: 'Mexico MX', value: 'MX' }, - { label: 'Netherlands NL', value: 'NL' }, - { label: 'New Zealand NZ', value: 'NZ' }, - { label: 'Norway NO', value: 'NO' }, - { label: "People's Republic of China CN", value: 'CN' }, - { label: 'Poland PL', value: 'PL' }, - { label: 'Portugal PT', value: 'PT' }, - { label: 'Republic of the Philippines PH', value: 'PH' }, - { label: 'Russia RU', value: 'RU' }, - { label: 'Saudi Arabia SA', value: 'SA' }, - { label: 'South Africa ZA', value: 'ZA' }, - { label: 'Spain ES', value: 'ES' }, - { label: 'Sweden SE', value: 'SE' }, - { label: 'Switzerland CH', value: 'CH' }, - { label: 'Taiwan TW', value: 'TW' }, - { label: 'Türkiye TR', value: 'TR' }, - { label: 'United Kingdom GB', value: 'GB' }, - { label: 'United States US', value: 'US' }, -]; - -export const BingLanguageOptions = [ - { label: 'Arabic ar', value: 'ar' }, - { label: 'Basque eu', value: 'eu' }, - { label: 'Bengali bn', value: 'bn' }, - { label: 'Bulgarian bg', value: 'bg' }, - { label: 'Catalan ca', value: 'ca' }, - { label: 'Chinese (Simplified) zh-hans', value: 'ns' }, - { label: 'Chinese (Traditional) zh-hant', value: 'nt' }, - { label: 'Croatian hr', value: 'hr' }, - { label: 'Czech cs', value: 'cs' }, - { label: 'Danish da', value: 'da' }, - { label: 'Dutch nl', value: 'nl' }, - { label: 'English en', value: 'en' }, - { label: 'English-United Kingdom en-gb', value: 'gb' }, - { label: 'Estonian et', value: 'et' }, - { label: 'Finnish fi', value: 'fi' }, - { label: 'French fr', value: 'fr' }, - { label: 'Galician gl', value: 'gl' }, - { label: 'German de', value: 'de' }, - { label: 'Gujarati gu', value: 'gu' }, - { label: 'Hebrew he', value: 'he' }, - { label: 'Hindi hi', value: 'hi' }, - { label: 'Hungarian hu', value: 'hu' }, - { label: 'Icelandic is', value: 'is' }, - { label: 'Italian it', value: 'it' }, - { label: 'Japanese jp', value: 'jp' }, - { label: 'Kannada kn', value: 'kn' }, - { label: 'Korean ko', value: 'ko' }, - { label: 'Latvian lv', value: 'lv' }, - { label: 'Lithuanian lt', value: 'lt' }, - { label: 'Malay ms', value: 'ms' }, - { label: 'Malayalam ml', value: 'ml' }, - { label: 'Marathi mr', value: 'mr' }, - { label: 'Norwegian (Bokmål) nb', value: 'nb' }, - { label: 'Polish pl', value: 'pl' }, - { label: 'Portuguese (Brazil) pt-br', value: 'br' }, - { label: 'Portuguese (Portugal) pt-pt', value: 'pt' }, - { label: 'Punjabi pa', value: 'pa' }, - { label: 'Romanian ro', value: 'ro' }, - { label: 'Russian ru', value: 'ru' }, - { label: 'Serbian (Cyrylic) sr', value: 'sr' }, - { label: 'Slovak sk', value: 'sk' }, - { label: 'Slovenian sl', value: 'sl' }, - { label: 'Spanish es', value: 'es' }, - { label: 'Swedish sv', value: 'sv' }, - { label: 'Tamil ta', value: 'ta' }, - { label: 'Telugu te', value: 'te' }, - { label: 'Thai th', value: 'th' }, - { label: 'Turkish tr', value: 'tr' }, - { label: 'Ukrainian uk', value: 'uk' }, - { label: 'Vietnamese vi', value: 'vi' }, -]; - -export const DeepLSourceLangOptions = [ - { label: 'Arabic [1]', value: 'AR' }, - { label: 'Bulgarian', value: 'BG' }, - { label: 'Czech', value: 'CS' }, - { label: 'Danish', value: 'DA' }, - { label: 'German', value: 'DE' }, - { label: 'Greek', value: 'EL' }, - { label: 'English', value: 'EN' }, - { label: 'Spanish', value: 'ES' }, - { label: 'Estonian', value: 'ET' }, - { label: 'Finnish', value: 'FI' }, - { label: 'French', value: 'FR' }, - { label: 'Hungarian', value: 'HU' }, - { label: 'Indonesian', value: 'ID' }, - { label: 'Italian', value: 'IT' }, - { label: 'Japanese', value: 'JA' }, - { label: 'Korean', value: 'KO' }, - { label: 'Lithuanian', value: 'LT' }, - { label: 'Latvian', value: 'LV' }, - { label: 'Norwegian Bokmål', value: 'NB' }, - { label: 'Dutch', value: 'NL' }, - { label: 'Polish', value: 'PL' }, - { label: 'Portuguese (all Portuguese varieties mixed)', value: 'PT' }, - { label: 'Romanian', value: 'RO' }, - { label: 'Russian', value: 'RU' }, - { label: 'Slovak', value: 'SK' }, - { label: 'Slovenian', value: 'SL' }, - { label: 'Swedish', value: 'SV' }, - { label: 'Turkish', value: 'TR' }, - { label: 'Ukrainian', value: 'UK' }, - { label: 'Chinese', value: 'ZH' }, -]; -export const DeepLTargetLangOptions = [ - { label: 'Arabic [1]', value: 'AR' }, - { label: 'Bulgarian', value: 'BG' }, - { label: 'Czech', value: 'CS' }, - { label: 'Danish', value: 'DA' }, - { label: 'German', value: 'DE' }, - { label: 'Greek', value: 'EL' }, - { label: 'English (British)', value: 'EN-GB' }, - { label: 'English (American)', value: 'EN-US' }, - { label: 'Spanish', value: 'ES' }, - { label: 'Estonian', value: 'ET' }, - { label: 'Finnish', value: 'FI' }, - { label: 'French', value: 'FR' }, - { label: 'Hungarian', value: 'HU' }, - { label: 'Indonesian', value: 'ID' }, - { label: 'Italian', value: 'IT' }, - { label: 'Japanese', value: 'JA' }, - { label: 'Korean', value: 'KO' }, - { label: 'Lithuanian', value: 'LT' }, - { label: 'Latvian', value: 'LV' }, - { label: 'Norwegian Bokmål', value: 'NB' }, - { label: 'Dutch', value: 'NL' }, - { label: 'Polish', value: 'PL' }, - { label: 'Portuguese (Brazilian)', value: 'PT-BR' }, - { - label: - 'Portuguese (all Portuguese varieties excluding Brazilian Portuguese)', - value: 'PT-PT', - }, - { label: 'Romanian', value: 'RO' }, - { label: 'Russian', value: 'RU' }, - { label: 'Slovak', value: 'SK' }, - { label: 'Slovenian', value: 'SL' }, - { label: 'Swedish', value: 'SV' }, - { label: 'Turkish', value: 'TR' }, - { label: 'Ukrainian', value: 'UK' }, - { label: 'Chinese (simplified)', value: 'ZH' }, -]; - -export const BaiduFanyiDomainOptions = [ - 'it', - 'finance', - 'machinery', - 'senimed', - 'novel', - 'academic', - 'aerospace', - 'wiki', - 'news', - 'law', - 'contract', -]; - -export const BaiduFanyiSourceLangOptions = [ - 'auto', - 'zh', - 'en', - 'yue', - 'wyw', - 'jp', - 'kor', - 'fra', - 'spa', - 'th', - 'ara', - 'ru', - 'pt', - 'de', - 'it', - 'el', - 'nl', - 'pl', - 'bul', - 'est', - 'dan', - 'fin', - 'cs', - 'rom', - 'slo', - 'swe', - 'hu', - 'cht', - 'vie', -]; - -export const QWeatherLangOptions = [ - 'zh', - 'zh-hant', - 'en', - 'de', - 'es', - 'fr', - 'it', - 'ja', - 'ko', - 'ru', - 'hi', - 'th', - 'ar', - 'pt', - 'bn', - 'ms', - 'nl', - 'el', - 'la', - 'sv', - 'id', - 'pl', - 'tr', - 'cs', - 'et', - 'vi', - 'fil', - 'fi', - 'he', - 'is', - 'nb', -]; - -export const QWeatherTypeOptions = ['weather', 'indices', 'airquality']; - -export const QWeatherUserTypeOptions = ['free', 'paid']; - -export const QWeatherTimePeriodOptions = [ - 'now', - '3d', - '7d', - '10d', - '15d', - '30d', -]; - -export const ExeSQLOptions = ['mysql', 'postgres', 'mariadb', 'mssql'].map( - (x) => ({ - label: upperFirst(x), - value: x, - }), -); - -export const WenCaiQueryTypeOptions = [ - 'stock', - 'zhishu', - 'fund', - 'hkstock', - 'usstock', - 'threeboard', - 'conbond', - 'insurance', - 'futures', - 'lccp', - 'foreign_exchange', -]; - -export const Jin10TypeOptions = ['flash', 'calendar', 'symbols', 'news']; -export const Jin10FlashTypeOptions = new Array(5) - .fill(1) - .map((x, idx) => (idx + 1).toString()); -export const Jin10CalendarTypeOptions = ['cj', 'qh', 'hk', 'us']; -export const Jin10CalendarDatashapeOptions = ['data', 'event', 'holiday']; -export const Jin10SymbolsTypeOptions = ['GOODS', 'FOREX', 'FUTURE', 'CRYPTO']; -export const Jin10SymbolsDatatypeOptions = ['symbols', 'quotes']; -export const TuShareSrcOptions = [ - 'sina', - 'wallstreetcn', - '10jqka', - 'eastmoney', - 'yuncaijing', - 'fenghuang', - 'jinrongjie', -]; -export const CrawlerResultOptions = ['markdown', 'html', 'content']; diff --git a/web/src/pages/data-flow/upload-agent-dialog/index.tsx b/web/src/pages/data-flow/upload-agent-dialog/index.tsx deleted file mode 100644 index 45f9ec882..000000000 --- a/web/src/pages/data-flow/upload-agent-dialog/index.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { - Dialog, - DialogContent, - DialogFooter, - DialogHeader, - DialogTitle, -} from '@/components/ui/dialog'; -import { LoadingButton } from '@/components/ui/loading-button'; -import { IModalProps } from '@/interfaces/common'; -import { TagRenameId } from '@/pages/add-knowledge/constant'; -import { useTranslation } from 'react-i18next'; -import { UploadAgentForm } from './upload-agent-form'; - -export function UploadAgentDialog({ - hideModal, - onOk, - loading, -}: IModalProps) { - const { t } = useTranslation(); - - return ( - - - - {t('fileManager.uploadFile')} - - - - - {t('common.save')} - - - - - ); -} diff --git a/web/src/pages/data-flow/upload-agent-dialog/upload-agent-form.tsx b/web/src/pages/data-flow/upload-agent-dialog/upload-agent-form.tsx deleted file mode 100644 index 39a4ac012..000000000 --- a/web/src/pages/data-flow/upload-agent-dialog/upload-agent-form.tsx +++ /dev/null @@ -1,89 +0,0 @@ -'use client'; - -import { zodResolver } from '@hookform/resolvers/zod'; -import { useForm } from 'react-hook-form'; -import { z } from 'zod'; - -import { FileUploader } from '@/components/file-uploader'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { FileMimeType, Platform } from '@/constants/common'; -import { IModalProps } from '@/interfaces/common'; -import { TagRenameId } from '@/pages/add-knowledge/constant'; -import { useTranslation } from 'react-i18next'; - -// const options = Object.values(Platform).map((x) => ({ label: x, value: x })); - -export function UploadAgentForm({ hideModal, onOk }: IModalProps) { - const { t } = useTranslation(); - const FormSchema = z.object({ - platform: z - .string() - .min(1, { - message: t('common.namePlaceholder'), - }) - .trim(), - fileList: z.array(z.instanceof(File)), - }); - - const form = useForm>({ - resolver: zodResolver(FormSchema), - defaultValues: { platform: Platform.RAGFlow }, - }); - - async function onSubmit(data: z.infer) { - console.log('🚀 ~ onSubmit ~ data:', data); - const ret = await onOk?.(data); - if (ret) { - hideModal?.(); - } - } - - return ( -
    - - ( - - {t('common.name')} - - - - - - )} - /> - {/* ( - - {t('common.name')} - - - - - - )} - /> */} - - - ); -} diff --git a/web/src/pages/data-flow/utils/chat.ts b/web/src/pages/data-flow/utils/chat.ts deleted file mode 100644 index 15c8ff850..000000000 --- a/web/src/pages/data-flow/utils/chat.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { MessageType } from '@/constants/chat'; -import { IReference } from '@/interfaces/database/chat'; -import { IMessage } from '@/pages/chat/interface'; -import { isEmpty } from 'lodash'; - -export const buildAgentMessageItemReference = ( - conversation: { message: IMessage[]; reference: IReference[] }, - message: IMessage, -) => { - const assistantMessages = conversation.message?.filter( - (x) => x.role === MessageType.Assistant, - ); - const referenceIndex = assistantMessages.findIndex( - (x) => x.id === message.id, - ); - const reference = !isEmpty(message?.reference) - ? message?.reference - : (conversation?.reference ?? [])[referenceIndex]; - - return reference ?? { doc_aggs: [], chunks: [], total: 0 }; -};