diff --git a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts
index f2bd945c70..10b6924ae6 100644
--- a/web/app/components/workflow/hooks/use-inspect-vars-crud.ts
+++ b/web/app/components/workflow/hooks/use-inspect-vars-crud.ts
@@ -79,7 +79,6 @@ const useInspectVarsCrud = () => {
const editInspectVarValue = useCallback(async (nodeId: string, varId: string, value: any) => {
await doEditInspectorVar({
- nodeId,
varId,
value,
})
@@ -101,7 +100,6 @@ const useInspectVarsCrud = () => {
const renameInspectVarName = async (nodeId: string, varId: string, selector: ValueSelector) => {
await doEditInspectorVar({
- nodeId,
varId,
name: selector[1],
})
diff --git a/web/app/components/workflow/store/workflow/debug/mock-data.ts b/web/app/components/workflow/store/workflow/debug/mock-data.ts
index 03a37bd264..41a55f3624 100644
--- a/web/app/components/workflow/store/workflow/debug/mock-data.ts
+++ b/web/app/components/workflow/store/workflow/debug/mock-data.ts
@@ -49,4 +49,14 @@ export const systemVars: VarInInspect[] = [
value: 'Hello robot!',
edited: false,
},
+ {
+ id: 'sys2',
+ type: VarInInspectType.system,
+ name: 'user_id',
+ description: '',
+ selector: ['sys', 'user_id'],
+ value_type: VarType.string,
+ value: 'djflakjerlkjdlksfjslakjsdfl',
+ edited: false,
+ },
]
diff --git a/web/app/components/workflow/variable-inspect/left.tsx b/web/app/components/workflow/variable-inspect/left.tsx
index e0be722a88..2fec6b1b01 100644
--- a/web/app/components/workflow/variable-inspect/left.tsx
+++ b/web/app/components/workflow/variable-inspect/left.tsx
@@ -11,7 +11,6 @@ import Button from '@/app/components/base/button'
// import ActionButton from '@/app/components/base/action-button'
// import Tooltip from '@/app/components/base/tooltip'
import BlockIcon from '@/app/components/workflow/block-icon'
-import { BubbleX } from '@/app/components/base/icons/src/vender/line/others'
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
import Group from './group'
import useCurrentVars from '../hooks/use-inspect-vars-crud'
@@ -39,6 +38,8 @@ const Left = ({
deleteAllInspectorVars,
} = useCurrentVars()
+ const showDivider = environmentVariables.length > 0 || conversationVars.length > 0 || systemVars.length > 0
+
// TODO node selection
const selectedNode = 3 < 4
@@ -69,34 +70,21 @@ const Left = ({
handleSelect={handleVarSelect}
/>
)}
- {/* group CHAT VAR */}
-
- {/* node item */}
-
-
-
-
{t('workflow.chatVariable.panelTitle')}
-
-
- {/* var item list */}
-
-
-
-
chat_history
-
array
-
-
- {selectedNode &&
}
-
-
custom_chat_history
-
array
-
-
-
+ {/* group SYSTEM VAR */}
+ {conversationVars.length > 0 && (
+
+ )}
{/* divider */}
-
+ {showDivider && (
+
+ )}
{/* group nodes */}
{/* node item */}
diff --git a/web/app/components/workflow/variable-inspect/right.tsx b/web/app/components/workflow/variable-inspect/right.tsx
index cb87a3c92d..22a6eefcd6 100644
--- a/web/app/components/workflow/variable-inspect/right.tsx
+++ b/web/app/components/workflow/variable-inspect/right.tsx
@@ -36,8 +36,14 @@ const Right = ({
const {
resetToLastRunVar,
+ editInspectVarValue,
} = useCurrentVars()
+ const handleValueChange = (varId: string, value: any) => {
+ if (!currentNodeVar) return
+ editInspectVarValue(currentNodeVar.nodeId, varId, value)
+ }
+
const resetValue = () => {
if (!currentNodeVar) return
resetToLastRunVar(currentNodeVar.nodeId, currentNodeVar.var.name)
@@ -109,7 +115,7 @@ const Right = ({
{/* content */}
{!currentNodeVar && }
- {currentNodeVar && }
+ {currentNodeVar && }
)
diff --git a/web/app/components/workflow/variable-inspect/value-content.tsx b/web/app/components/workflow/variable-inspect/value-content.tsx
index 4a00b5479e..418fe97627 100644
--- a/web/app/components/workflow/variable-inspect/value-content.tsx
+++ b/web/app/components/workflow/variable-inspect/value-content.tsx
@@ -1,6 +1,5 @@
import { useEffect, useRef, useState } from 'react'
-// import { useTranslation } from 'react-i18next'
-import { debounce } from 'lodash-es'
+import { useDebounceFn } from 'ahooks'
import Textarea from '@/app/components/base/textarea'
import SchemaEditor from '@/app/components/workflow/nodes/llm/components/json-schema-config-modal/schema-editor'
import { FileUploaderInAttachmentWrapper } from '@/app/components/base/file-uploader'
@@ -23,38 +22,14 @@ import type { VarInInspect } from '@/types/workflow'
import { VarInInspectType } from '@/types/workflow'
import cn from '@/utils/classnames'
-export const MOCK_DATA = {
- id: 'var-jfkldjjfkldaf-dfhekdfj',
- type: 'node',
- // type: 'conversation',
- // type: 'environment',
- name: 'out_put',
- // value_type: 'string',
- // value_type: 'number',
- // value_type: 'object',
- // value_type: 'array[string]',
- // value_type: 'array[number]',
- // value_type: 'array[object]',
- // value_type: 'file',
- value_type: 'array[file]',
- // value: 'tuituitui',
- // value: ['aaa', 'bbb', 'ccc'],
- // value: {
- // abc: '123',
- // def: 456,
- // fff: true,
- // },
- value: [],
- edited: true,
-}
-
type Props = {
currentVar: VarInInspect
+ handleValueChange: (varId: string, value: any) => void
}
const ValueContent = ({
- // currentVar = MOCK_DATA as any, // TODO remove this line
currentVar,
+ handleValueChange,
}: Props) => {
const contentContainerRef = useRef(null)
const errorMessageRef = useRef(null)
@@ -62,6 +37,7 @@ const ValueContent = ({
const showTextEditor = currentVar.value_type === 'secret' || currentVar.value_type === 'string' || currentVar.value_type === 'number'
const showJSONEditor = currentVar.value_type === 'object' || currentVar.value_type === 'array[string]' || currentVar.value_type === 'array[number]' || currentVar.value_type === 'array[object]'
const showFileEditor = currentVar.value_type === 'file' || currentVar.value_type === 'array[file]'
+ const textEditorDisabled = currentVar.type === VarInInspectType.environment || (currentVar.type === VarInInspectType.system && currentVar.name !== 'query')
const [value, setValue] = useState()
const [jsonSchema, setJsonSchema] = useState()
@@ -77,8 +53,11 @@ const ValueContent = ({
: [],
)
+ const { run: debounceValueChange } = useDebounceFn(handleValueChange, { wait: 500 })
+
// update default value when id changed
useEffect(() => {
+ console.log('currentVar', currentVar)
if (showTextEditor) {
if (!currentVar.value)
return setValue('')
@@ -107,7 +86,7 @@ const ValueContent = ({
if (/^-?\d+(\.)?(\d+)?$/.test(value))
setValue(value)
}
- // TODO call api of value update
+ debounceValueChange(currentVar.id, value)
}
const jsonValueValidate = (value: string, type: string) => {
@@ -152,21 +131,26 @@ const ValueContent = ({
if (jsonValueValidate(value, currentVar.value_type)) {
const parsed = JSON.parse(value)
setJsonSchema(parsed)
- // TODO call api of value update
+ debounceValueChange(currentVar.id, parsed)
}
}
- const handleFileChange = (value: any) => {
- console.log('value', value)
+ const fileValueValidate = (fileList: any[]) => {
+ if (fileList.every(file => file.upload_file_id))
+ return true
+ return false
+ }
+
+ const handleFileChange = (value: any[]) => {
setFileValue(value)
- // TODO check every file upload progress
+ // check every file upload progress
// invoke update api after every file uploaded
- if (currentVar.value_type === 'file') {
- // TODO call api of value update
- }
- if (currentVar.value_type === 'array[file]') {
- // TODO call api of value update
- }
+ if (!fileValueValidate(value))
+ return
+ if (currentVar.value_type === 'file')
+ debounceValueChange(currentVar.id, value[0])
+ if (currentVar.value_type === 'array[file]')
+ debounceValueChange(currentVar.id, value)
}
// get editor height
@@ -194,8 +178,8 @@ const ValueContent = ({
{showTextEditor && (