diff --git a/web/src/pages/agent/form-sheet/use-form-config-map.tsx b/web/src/pages/agent/form-sheet/use-form-config-map.tsx index 13c1e95f9..de09956ba 100644 --- a/web/src/pages/agent/form-sheet/use-form-config-map.tsx +++ b/web/src/pages/agent/form-sheet/use-form-config-map.tsx @@ -1,3 +1,4 @@ +import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent'; import { useTranslation } from 'react-i18next'; import { z } from 'zod'; import { Operator } from '../constant'; @@ -133,13 +134,17 @@ export function useFormConfigMap() { }, [Operator.Code]: { component: CodeForm, - defaultValues: { arguments: [] }, + defaultValues: { + lang: ProgrammingLanguage.Python, + script: CodeTemplateStrMap[ProgrammingLanguage.Python], + arguments: [], + }, schema: z.object({ + lang: z.string(), script: z.string(), arguments: z.array( z.object({ name: z.string(), component_id: z.string() }), ), - lang: z.string(), }), }, [Operator.Baidu]: { diff --git a/web/src/pages/agent/form/code-form/index.tsx b/web/src/pages/agent/form/code-form/index.tsx index c5282a6b1..4db2a96a5 100644 --- a/web/src/pages/agent/form/code-form/index.tsx +++ b/web/src/pages/agent/form/code-form/index.tsx @@ -1,6 +1,7 @@ import Editor, { loader } from '@monaco-editor/react'; import { INextOperatorForm } from '../../interface'; +import { FormContainer } from '@/components/form-container'; import { Form, FormControl, @@ -9,11 +10,17 @@ import { FormLabel, FormMessage, } from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; import { RAGFlowSelect } from '@/components/ui/select'; import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent'; import { ICodeForm } from '@/interfaces/database/flow'; import { useEffect } from 'react'; -import { DynamicInputVariable } from './next-variable'; +import { useTranslation } from 'react-i18next'; +import { + DynamicInputVariable, + TypeOptions, + VariableTitle, +} from './next-variable'; loader.config({ paths: { vs: '/vs' } }); @@ -24,6 +31,7 @@ const options = [ const CodeForm = ({ form, node }: INextOperatorForm) => { const formData = node?.data.form as ICodeForm; + const { t } = useTranslation(); useEffect(() => { // TODO: Direct operation zustand is more elegant @@ -35,42 +43,100 @@ const CodeForm = ({ form, node }: INextOperatorForm) => { return (
- - ( - - + { + e.preventDefault(); + }} + > + + ( + + + Code + ( + + + + + + + )} + /> + + + + + + + )} + /> + + {formData.lang === ProgrammingLanguage.Python ? ( + + ) : ( +
+ + ( + Name - + )} /> - - - ( + + Type + + + + + + )} /> - - - + +
)} - /> + ); }; diff --git a/web/src/pages/agent/form/code-form/next-variable.tsx b/web/src/pages/agent/form/code-form/next-variable.tsx index 90b2f8099..153257ad8 100644 --- a/web/src/pages/agent/form/code-form/next-variable.tsx +++ b/web/src/pages/agent/form/code-form/next-variable.tsx @@ -1,23 +1,19 @@ 'use client'; -import { SideDown } from '@/assets/icon/Icon'; +import { FormContainer } from '@/components/form-container'; 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 { Separator } from '@/components/ui/separator'; import { RAGFlowNodeType } from '@/interfaces/database/flow'; -import { Plus, Trash2 } from 'lucide-react'; +import { Plus, X } from 'lucide-react'; +import { ReactNode } from 'react'; import { useFieldArray, useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { useBuildComponentIdSelectOptions } from '../../hooks/use-get-begin-query'; @@ -27,6 +23,15 @@ interface IProps { name?: string; } +export const TypeOptions = [ + 'String', + 'Number', + 'Boolean', + 'Array[String]', + 'Array[Number]', + 'Object', +].map((x) => ({ label: x, value: x })); + export function DynamicVariableForm({ node, name = 'arguments' }: IProps) { const { t } = useTranslation(); const form = useFormContext(); @@ -42,17 +47,16 @@ export function DynamicVariableForm({ node, name = 'arguments' }: IProps) { ); return ( -
+
{fields.map((field, index) => { const typeField = `${name}.${index}.name`; return ( -
+
( - )} /> + ( - @@ -80,18 +86,16 @@ export function DynamicVariableForm({ node, name = 'arguments' }: IProps) { )} /> - remove(index)} - /> +
); })} - - - - - +
+ + + + +
); }