diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/index.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/index.tsx index befed2ef1d..2f04afe84a 100644 --- a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/index.tsx +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/index.tsx @@ -9,6 +9,7 @@ import JsonImporter from './json-importer' import { useTranslation } from 'react-i18next' import Button from '@/app/components/base/button' import VisualEditor from './visual-editor' +import SchemaEditor from './schema-editor' type JsonSchemaConfigModalProps = { isShow: boolean @@ -43,6 +44,7 @@ const JsonSchemaConfigModal: FC = ({ const { t } = useTranslation() const [currentTab, setCurrentTab] = useState(SchemaView.VisualEditor) const [jsonSchema, setJsonSchema] = useState(defaultSchema || DEFAULT_SCHEMA) + const [json, setJson] = useState(JSON.stringify(jsonSchema, null, 2)) const [btnWidth, setBtnWidth] = useState(0) const updateBtnWidth = useCallback((width: number) => { @@ -57,6 +59,10 @@ const JsonSchemaConfigModal: FC = ({ setJsonSchema(schema) }, []) + const handleSchemaEditorUpdate = useCallback((schema: string) => { + setJson(schema) + }, []) + const handleResetDefaults = useCallback(() => { setJsonSchema(defaultSchema || DEFAULT_SCHEMA) }, [defaultSchema]) @@ -118,7 +124,10 @@ const JsonSchemaConfigModal: FC = ({ /> )} {currentTab === SchemaView.JsonSchema && ( -
JSON Schema
+ )} {/* Footer */} diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-importer.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-importer.tsx index 3741ed8c37..8f863d23a4 100644 --- a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-importer.tsx +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-importer.tsx @@ -166,7 +166,6 @@ const JsonImporter: FC = ({ alwaysConsumeMouseWheel: false, }, }} - /> diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/generated-result.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/generated-result.tsx index 5a50a4afb8..72915c7ec2 100644 --- a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/generated-result.tsx +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-generator/generated-result.tsx @@ -131,7 +131,6 @@ const GeneratedResult: FC = ({ alwaysConsumeMouseWheel: false, }, }} - /> diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/schema-editor.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/schema-editor.tsx new file mode 100644 index 0000000000..c3ab2b121a --- /dev/null +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/schema-editor.tsx @@ -0,0 +1,102 @@ +import { Editor } from '@monaco-editor/react' +import { RiClipboardLine, RiIndentIncrease } from '@remixicon/react' +import copy from 'copy-to-clipboard' +import React, { type FC, useCallback, useRef } from 'react' + +type SchemaEditorProps = { + schema: string + onUpdate: (schema: string) => void +} + +const SchemaEditor: FC = ({ + schema, + onUpdate, +}) => { + const monacoRef = useRef(null) + const editorRef = useRef(null) + + const handleEditorDidMount = useCallback((editor: any, monaco: any) => { + editorRef.current = editor + monacoRef.current = monaco + monaco.editor.defineTheme('light-theme', { + base: 'vs', + inherit: true, + rules: [], + colors: { + 'editor.background': '#00000000', + 'editor.lineHighlightBackground': '#00000000', + 'focusBorder': '#00000000', + }, + }) + monaco.editor.setTheme('light-theme') + }, []) + + const formatJsonContent = useCallback(() => { + if (editorRef.current) + editorRef.current.getAction('editor.action.formatDocument')?.run() + }, []) + + const handleEditorChange = useCallback((value: string | undefined) => { + if (!value) + return + onUpdate(value) + }, [onUpdate]) + + return ( +
+
+
+ JSON +
+
+ + +
+
+
+ +
+
+ ) +} + +export default SchemaEditor diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/add-field.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/add-field.tsx new file mode 100644 index 0000000000..62a5153160 --- /dev/null +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/add-field.tsx @@ -0,0 +1,31 @@ +import { type FC, useState } from 'react' +import type { Field } from '../../../types' +import Button from '@/app/components/base/button' +import { RiAddCircleFill } from '@remixicon/react' +import { useTranslation } from 'react-i18next' + +type AddToRootProps = { + addField: (path: string[], updates: Field) => void +} + +const AddField: FC = ({ + addField, +}) => { + const { t } = useTranslation() + const [isEditing, setIsEditing] = useState(false) + + const handleAddField = () => { + setIsEditing(true) + } + + return ( + <> + + + ) +} + +export default AddField