From e7463273c74403e3c876f9bd27fcb67e6d8af76b Mon Sep 17 00:00:00 2001 From: jZonG Date: Mon, 28 Apr 2025 16:24:38 +0800 Subject: [PATCH] conversation var --- .../store/workflow/debug/mock-data.ts | 10 +++ .../workflow/variable-inspect/group.tsx | 67 +++++++++---------- .../workflow/variable-inspect/left.tsx | 14 +++- .../workflow/variable-inspect/right.tsx | 11 ++- .../variable-inspect/value-content.tsx | 2 +- web/service/use-workflow.ts | 2 +- 6 files changed, 66 insertions(+), 40 deletions(-) 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 85bc574bba..03a37bd264 100644 --- a/web/app/components/workflow/store/workflow/debug/mock-data.ts +++ b/web/app/components/workflow/store/workflow/debug/mock-data.ts @@ -26,6 +26,16 @@ export const conversationVars: VarInInspect[] = [ value: 'conversation var value...', edited: false, }, + { + id: 'con2', + type: VarInInspectType.conversation, + name: 'conversationVar 2', + description: '', + selector: ['conversation', 'var2'], + value_type: VarType.number, + value: 456, + edited: false, + }, ] export const systemVars: VarInInspect[] = [ diff --git a/web/app/components/workflow/variable-inspect/group.tsx b/web/app/components/workflow/variable-inspect/group.tsx index 67a06e331d..d24a94c31f 100644 --- a/web/app/components/workflow/variable-inspect/group.tsx +++ b/web/app/components/workflow/variable-inspect/group.tsx @@ -5,79 +5,76 @@ import { // RiErrorWarningFill, // RiLoader2Line, } from '@remixicon/react' -import { useStore } from '../store' // import { BlockEnum } from '../types' // 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, + BubbleX, Env, } from '@/app/components/base/icons/src/vender/line/others' -// import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' -// import useCurrentVars from '../hooks/use-inspect-vars-crud' +import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import type { currentVarType } from './panel' +import { VarInInspectType } from '@/types/workflow' +import type { VarInInspect } from '@/types/workflow' import cn from '@/utils/classnames' type Props = { - isEnv?: boolean - isChatVar?: boolean - isSystem?: boolean currentVar?: currentVarType + varType: VarInInspectType + varList: VarInInspect[] handleSelect: (state: any) => void } const Group = ({ - isEnv, - isChatVar, - isSystem, currentVar, + varType, + varList, handleSelect, }: Props) => { const { t } = useTranslation() - - const environmentVariables = useStore(s => s.environmentVariables) - // const { - // conversationVars, - // systemVars, - // nodesWithInspectVars, - // } = useCurrentVars() - const [isCollapsed, setIsCollapsed] = useState(false) + const isEnv = varType === VarInInspectType.environment + const isChatVar = varType === VarInInspectType.conversation + const isSystem = varType === VarInInspectType.system + const handleSelectVar = (varItem: any, type?: string) => { - if (type === 'env') { + if (type === VarInInspectType.environment) { handleSelect({ nodeId: 'env', nodeTitle: 'env', - nodeType: 'env', + nodeType: VarInInspectType.environment, var: { ...varItem, - type: 'env', + type: VarInInspectType.environment, ...(varItem.value_type === 'secret' ? { value: '******************' } : {}), }, }) return } - if (type === 'chat') { + if (type === VarInInspectType.conversation) { handleSelect({ nodeId: 'conversation', nodeTitle: 'conversation', - nodeType: 'conversation', + nodeType: VarInInspectType.conversation, var: { ...varItem, - type: 'conversation', + type: VarInInspectType.conversation, }, }) return } - if (type === 'system') { + if (type === VarInInspectType.system) { handleSelect({ nodeId: 'sys', nodeTitle: 'sys', - nodeType: 'sys', - var: varItem, + nodeType: VarInInspectType.system, + var: { + ...varItem, + type: VarInInspectType.system, + }, }) return } @@ -105,18 +102,20 @@ const Group = ({ {/* var item list */} {!isCollapsed && (
- {environmentVariables.length > 0 && environmentVariables.map(env => ( + {varList.length > 0 && varList.map(varItem => (
handleSelectVar(env, 'env')} + onClick={() => handleSelectVar(varItem, varType)} > - -
{env.name}
-
{env.value_type}
+ {isEnv && } + {isChatVar && } + {isSystem && } +
{varItem.name}
+
{varItem.value_type}
))}
diff --git a/web/app/components/workflow/variable-inspect/left.tsx b/web/app/components/workflow/variable-inspect/left.tsx index 045a1e859b..e0be722a88 100644 --- a/web/app/components/workflow/variable-inspect/left.tsx +++ b/web/app/components/workflow/variable-inspect/left.tsx @@ -16,6 +16,8 @@ import { Variable02 } from '@/app/components/base/icons/src/vender/solid/develop import Group from './group' import useCurrentVars from '../hooks/use-inspect-vars-crud' import type { currentVarType } from './panel' +import type { VarInInspect } from '@/types/workflow' +import { VarInInspectType } from '@/types/workflow' import cn from '@/utils/classnames' type Props = { @@ -52,7 +54,17 @@ const Left = ({ {/* group ENV */} {environmentVariables.length > 0 && ( + )} + {/* group CHAT VAR */} + {conversationVars.length > 0 && ( + diff --git a/web/app/components/workflow/variable-inspect/right.tsx b/web/app/components/workflow/variable-inspect/right.tsx index 58e59bbee5..cb87a3c92d 100644 --- a/web/app/components/workflow/variable-inspect/right.tsx +++ b/web/app/components/workflow/variable-inspect/right.tsx @@ -16,7 +16,9 @@ import CopyFeedback from '@/app/components/base/copy-feedback' import Tooltip from '@/app/components/base/tooltip' import BlockIcon from '@/app/components/workflow/block-icon' import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' +import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import type { currentVarType } from './panel' +import { VarInInspectType } from '@/types/workflow' import cn from '@/utils/classnames' type Props = { @@ -53,13 +55,16 @@ const Right = ({
{currentNodeVar && ( <> - {currentNodeVar.nodeType === 'env' && ( + {currentNodeVar.nodeType === VarInInspectType.environment && ( )} - {currentNodeVar.nodeType === 'conversation' && ( + {currentNodeVar.nodeType === VarInInspectType.conversation && ( )} - {currentNodeVar.nodeType !== 'env' && currentNodeVar.nodeType !== 'conversation' && currentNodeVar.nodeType !== 'sys' && ( + {currentNodeVar.nodeType === VarInInspectType.system && ( + + )} + {currentNodeVar.nodeType !== VarInInspectType.environment && currentNodeVar.nodeType !== VarInInspectType.conversation && currentNodeVar.nodeType !== VarInInspectType.system && ( <> handleTextChange(e.target.value))} + onChange={e => handleTextChange(e.target.value)} /> )} {showJSONEditor && ( diff --git a/web/service/use-workflow.ts b/web/service/use-workflow.ts index e1ec169e7f..ecdd247972 100644 --- a/web/service/use-workflow.ts +++ b/web/service/use-workflow.ts @@ -147,7 +147,7 @@ export const useConversationVarValues = (appId: string) => { return Promise.resolve(conversationVars.map((item) => { return { ...item, - value: `${item.value}${index++}`, + value: item.value_type === 'string' ? `${item.value}${index++}` : item.value, } })) },