conversation var

This commit is contained in:
jZonG 2025-04-28 16:24:38 +08:00
parent b288258e4d
commit e7463273c7
6 changed files with 66 additions and 40 deletions

View File

@ -26,6 +26,16 @@ export const conversationVars: VarInInspect[] = [
value: 'conversation var value...', value: 'conversation var value...',
edited: false, 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[] = [ export const systemVars: VarInInspect[] = [

View File

@ -5,79 +5,76 @@ import {
// RiErrorWarningFill, // RiErrorWarningFill,
// RiLoader2Line, // RiLoader2Line,
} from '@remixicon/react' } from '@remixicon/react'
import { useStore } from '../store'
// import { BlockEnum } from '../types' // import { BlockEnum } from '../types'
// import Button from '@/app/components/base/button' // import Button from '@/app/components/base/button'
// import ActionButton from '@/app/components/base/action-button' // import ActionButton from '@/app/components/base/action-button'
// import Tooltip from '@/app/components/base/tooltip' // import Tooltip from '@/app/components/base/tooltip'
// import BlockIcon from '@/app/components/workflow/block-icon' // import BlockIcon from '@/app/components/workflow/block-icon'
import { import {
// BubbleX, BubbleX,
Env, Env,
} from '@/app/components/base/icons/src/vender/line/others' } from '@/app/components/base/icons/src/vender/line/others'
// import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
// import useCurrentVars from '../hooks/use-inspect-vars-crud'
import type { currentVarType } from './panel' import type { currentVarType } from './panel'
import { VarInInspectType } from '@/types/workflow'
import type { VarInInspect } from '@/types/workflow'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
type Props = { type Props = {
isEnv?: boolean
isChatVar?: boolean
isSystem?: boolean
currentVar?: currentVarType currentVar?: currentVarType
varType: VarInInspectType
varList: VarInInspect[]
handleSelect: (state: any) => void handleSelect: (state: any) => void
} }
const Group = ({ const Group = ({
isEnv,
isChatVar,
isSystem,
currentVar, currentVar,
varType,
varList,
handleSelect, handleSelect,
}: Props) => { }: Props) => {
const { t } = useTranslation() const { t } = useTranslation()
const environmentVariables = useStore(s => s.environmentVariables)
// const {
// conversationVars,
// systemVars,
// nodesWithInspectVars,
// } = useCurrentVars()
const [isCollapsed, setIsCollapsed] = useState(false) 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) => { const handleSelectVar = (varItem: any, type?: string) => {
if (type === 'env') { if (type === VarInInspectType.environment) {
handleSelect({ handleSelect({
nodeId: 'env', nodeId: 'env',
nodeTitle: 'env', nodeTitle: 'env',
nodeType: 'env', nodeType: VarInInspectType.environment,
var: { var: {
...varItem, ...varItem,
type: 'env', type: VarInInspectType.environment,
...(varItem.value_type === 'secret' ? { value: '******************' } : {}), ...(varItem.value_type === 'secret' ? { value: '******************' } : {}),
}, },
}) })
return return
} }
if (type === 'chat') { if (type === VarInInspectType.conversation) {
handleSelect({ handleSelect({
nodeId: 'conversation', nodeId: 'conversation',
nodeTitle: 'conversation', nodeTitle: 'conversation',
nodeType: 'conversation', nodeType: VarInInspectType.conversation,
var: { var: {
...varItem, ...varItem,
type: 'conversation', type: VarInInspectType.conversation,
}, },
}) })
return return
} }
if (type === 'system') { if (type === VarInInspectType.system) {
handleSelect({ handleSelect({
nodeId: 'sys', nodeId: 'sys',
nodeTitle: 'sys', nodeTitle: 'sys',
nodeType: 'sys', nodeType: VarInInspectType.system,
var: varItem, var: {
...varItem,
type: VarInInspectType.system,
},
}) })
return return
} }
@ -105,18 +102,20 @@ const Group = ({
{/* var item list */} {/* var item list */}
{!isCollapsed && ( {!isCollapsed && (
<div className='px-0.5'> <div className='px-0.5'>
{environmentVariables.length > 0 && environmentVariables.map(env => ( {varList.length > 0 && varList.map(varItem => (
<div <div
key={env.id} key={varItem.id}
className={cn( className={cn(
'relative flex cursor-pointer items-center gap-1 rounded-md px-3 py-1 hover:bg-state-base-hover', 'relative flex cursor-pointer items-center gap-1 rounded-md px-3 py-1 hover:bg-state-base-hover',
env.id === currentVar?.var.id && 'bg-state-base-hover-alt hover:bg-state-base-hover-alt', varItem.id === currentVar?.var.id && 'bg-state-base-hover-alt hover:bg-state-base-hover-alt',
)} )}
onClick={() => handleSelectVar(env, 'env')} onClick={() => handleSelectVar(varItem, varType)}
> >
<Env className='h-4 w-4 shrink-0 text-util-colors-violet-violet-600' /> {isEnv && <Env className='h-4 w-4 shrink-0 text-util-colors-violet-violet-600' />}
<div className='system-sm-medium grow truncate text-text-secondary'>{env.name}</div> {isChatVar && <BubbleX className='h-4 w-4 shrink-0 text-util-colors-teal-teal-700' />}
<div className='system-xs-regular shrink-0 text-text-tertiary'>{env.value_type}</div> {isSystem && <Variable02 className='h-4 w-4 shrink-0 text-text-accent' />}
<div className='system-sm-medium grow truncate text-text-secondary'>{varItem.name}</div>
<div className='system-xs-regular shrink-0 text-text-tertiary'>{varItem.value_type}</div>
</div> </div>
))} ))}
</div> </div>

View File

@ -16,6 +16,8 @@ import { Variable02 } from '@/app/components/base/icons/src/vender/solid/develop
import Group from './group' import Group from './group'
import useCurrentVars from '../hooks/use-inspect-vars-crud' import useCurrentVars from '../hooks/use-inspect-vars-crud'
import type { currentVarType } from './panel' import type { currentVarType } from './panel'
import type { VarInInspect } from '@/types/workflow'
import { VarInInspectType } from '@/types/workflow'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
type Props = { type Props = {
@ -52,7 +54,17 @@ const Left = ({
{/* group ENV */} {/* group ENV */}
{environmentVariables.length > 0 && ( {environmentVariables.length > 0 && (
<Group <Group
isEnv varType={VarInInspectType.environment}
varList={environmentVariables as VarInInspect[]}
currentVar={currentNodeVar}
handleSelect={handleVarSelect}
/>
)}
{/* group CHAT VAR */}
{conversationVars.length > 0 && (
<Group
varType={VarInInspectType.conversation}
varList={conversationVars}
currentVar={currentNodeVar} currentVar={currentNodeVar}
handleSelect={handleVarSelect} handleSelect={handleVarSelect}
/> />

View File

@ -16,7 +16,9 @@ import CopyFeedback from '@/app/components/base/copy-feedback'
import Tooltip from '@/app/components/base/tooltip' import Tooltip from '@/app/components/base/tooltip'
import BlockIcon from '@/app/components/workflow/block-icon' import BlockIcon from '@/app/components/workflow/block-icon'
import { BubbleX, Env } from '@/app/components/base/icons/src/vender/line/others' 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 type { currentVarType } from './panel'
import { VarInInspectType } from '@/types/workflow'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
type Props = { type Props = {
@ -53,13 +55,16 @@ const Right = ({
<div className='flex w-0 grow items-center gap-1'> <div className='flex w-0 grow items-center gap-1'>
{currentNodeVar && ( {currentNodeVar && (
<> <>
{currentNodeVar.nodeType === 'env' && ( {currentNodeVar.nodeType === VarInInspectType.environment && (
<Env className='h-4 w-4 shrink-0 text-util-colors-violet-violet-600' /> <Env className='h-4 w-4 shrink-0 text-util-colors-violet-violet-600' />
)} )}
{currentNodeVar.nodeType === 'conversation' && ( {currentNodeVar.nodeType === VarInInspectType.conversation && (
<BubbleX className='h-4 w-4 shrink-0 text-util-colors-teal-teal-700' /> <BubbleX className='h-4 w-4 shrink-0 text-util-colors-teal-teal-700' />
)} )}
{currentNodeVar.nodeType !== 'env' && currentNodeVar.nodeType !== 'conversation' && currentNodeVar.nodeType !== 'sys' && ( {currentNodeVar.nodeType === VarInInspectType.system && (
<Variable02 className='h-4 w-4 shrink-0 text-text-accent' />
)}
{currentNodeVar.nodeType !== VarInInspectType.environment && currentNodeVar.nodeType !== VarInInspectType.conversation && currentNodeVar.nodeType !== VarInInspectType.system && (
<> <>
<BlockIcon <BlockIcon
className='shrink-0' className='shrink-0'

View File

@ -198,7 +198,7 @@ const ValueContent = ({
disabled={currentVar.type === VarInInspectType.environment} disabled={currentVar.type === VarInInspectType.environment}
className='h-full' className='h-full'
value={value as any} value={value as any}
onChange={debounce(e => handleTextChange(e.target.value))} onChange={e => handleTextChange(e.target.value)}
/> />
)} )}
{showJSONEditor && ( {showJSONEditor && (

View File

@ -147,7 +147,7 @@ export const useConversationVarValues = (appId: string) => {
return Promise.resolve(conversationVars.map((item) => { return Promise.resolve(conversationVars.map((item) => {
return { return {
...item, ...item,
value: `${item.value}${index++}`, value: item.value_type === 'string' ? `${item.value}${index++}` : item.value,
} }
})) }))
}, },