diff --git a/web/src/pages/agent/form/code-form/expanded-editor.tsx b/web/src/pages/agent/form/code-form/expanded-editor.tsx new file mode 100644 index 0000000000..f4f8b9e1e5 --- /dev/null +++ b/web/src/pages/agent/form/code-form/expanded-editor.tsx @@ -0,0 +1,47 @@ +import { Button } from '@/components/ui/button'; +import Editor from '@monaco-editor/react'; +import { Minimize2 } from 'lucide-react'; +import { CodeEditorOptions } from './monaco-config'; + +interface ExpandedEditorProps { + visible: boolean; + onClose: () => void; + theme: string; + language: string; + value: string; + onChange: (value: string) => void; +} + +export function ExpandedEditor({ + visible, + onClose, + theme, + language, + value, + onChange, +}: ExpandedEditorProps) { + if (!visible) return null; + + return ( +
+
+ Code + +
+
+ { + onChange(val ?? ''); + }} + /> +
+
+ ); +} diff --git a/web/src/pages/agent/form/code-form/index.tsx b/web/src/pages/agent/form/code-form/index.tsx index 131348a2f1..b2f954e386 100644 --- a/web/src/pages/agent/form/code-form/index.tsx +++ b/web/src/pages/agent/form/code-form/index.tsx @@ -3,6 +3,7 @@ import { INextOperatorForm } from '../../interface'; import { FormContainer } from '@/components/form-container'; import { useIsDarkTheme } from '@/components/theme-provider'; +import { Button } from '@/components/ui/button'; import { Form, FormControl, @@ -16,13 +17,15 @@ import { RAGFlowSelect } from '@/components/ui/select'; import { ProgrammingLanguage } from '@/constants/agent'; import { ICodeForm } from '@/interfaces/database/agent'; import { zodResolver } from '@hookform/resolvers/zod'; -import { AlertTriangle } from 'lucide-react'; -import { memo } from 'react'; +import { AlertTriangle, Maximize2 } from 'lucide-react'; +import { memo, useState } from 'react'; import { useForm } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { buildOutputList } from '../../utils/build-output-list'; import { FormWrapper } from '../components/form-wrapper'; import { Output } from '../components/output'; +import { ExpandedEditor } from './expanded-editor'; +import { CodeEditorOptions, RAGFlowMonacoTheme } from './monaco-config'; import { DynamicInputVariable, TypeOptions, @@ -47,6 +50,8 @@ const options = [ ProgrammingLanguage.Javascript, ].map((x) => ({ value: x, label: x })); +const ScriptFieldName = 'script'; + function CodeForm({ node }: INextOperatorForm) { const formData = node?.data.form as ICodeForm; const { t } = useTranslation(); @@ -61,6 +66,7 @@ function CodeForm({ node }: INextOperatorForm) { useWatchFormChange(node?.id, form); const handleLanguageChange = useHandleLanguageChange(node?.id, form); + const [isExpanded, setIsExpanded] = useState(false); const lang = form.watch('lang'); const currentOutput = form.watch('output'); const outputFieldDirty = !!form.formState.dirtyFields?.output; @@ -69,114 +75,136 @@ function CodeForm({ node }: INextOperatorForm) { ? getBusinessOutputs(formData?.outputs) : serializeCodeOutputContract(currentOutput); + const theme = isDarkTheme + ? RAGFlowMonacoTheme.Dark + : RAGFlowMonacoTheme.Light; + return (
- - - ( - - - Code - ( - - - { - field.onChange(val); - handleLanguageChange(val); - }} - options={options} - /> - - - - )} - /> - - - + + + ( + + +
+ Code +
+ ( + + + { + field.onChange(val); + handleLanguageChange(val); + }} + options={options} + /> + + + + )} + /> + +
+
+
+ + + + + setIsExpanded(false)} + theme={theme} language={lang} - options={{ - minimap: { enabled: false }, - automaticLayout: true, - }} - {...field} + value={field.value} + onChange={field.onChange} /> -
- -
- )} - /> + + )} + /> -
- - {legacyOutputs.length > 0 && ( -
- -

- This CodeExec node uses the deprecated multi-output schema:{' '} - {legacyOutputs.join(', ')}. Keep one business output here and - move field extraction to downstream nodes. -

-
- )} - - ( - - Name - - - - - - )} - /> - ( - - Type - - - - - - )} - /> - +
+ + {legacyOutputs.length > 0 && ( +
+ +

+ This CodeExec node uses the deprecated multi-output schema:{' '} + {legacyOutputs.join(', ')}. Keep one business output here and + move field extraction to downstream nodes. +

+
+ )} + + ( + + Name + + + + + + )} + /> + ( + + Type + + + + + + )} + /> + +
+ +
+ + Business + + + System +
- -
- - Business - - - System -
); diff --git a/web/src/pages/agent/form/code-form/monaco-config.ts b/web/src/pages/agent/form/code-form/monaco-config.ts new file mode 100644 index 0000000000..f44948cb17 --- /dev/null +++ b/web/src/pages/agent/form/code-form/monaco-config.ts @@ -0,0 +1,13 @@ +export const CodeEditorOptions = { + minimap: { enabled: false }, + automaticLayout: true, + scrollbar: { + verticalScrollbarSize: 10, + horizontalScrollbarSize: 10, + }, +}; + +export const RAGFlowMonacoTheme = { + Light: 'vs', + Dark: 'vs-dark', +} as const; diff --git a/web/src/pages/next-search/search-home.tsx b/web/src/pages/next-search/search-home.tsx index 281546c3bc..05ee5a1244 100644 --- a/web/src/pages/next-search/search-home.tsx +++ b/web/src/pages/next-search/search-home.tsx @@ -8,7 +8,7 @@ import { useTranslation } from 'react-i18next'; import './index.less'; import { RAGFlowLogo } from './ragflow-log'; -export default function SearchPage({ +export default function SearchHome({ isSearching, setIsSearching, searchText,