|
|
|
|
@ -3,7 +3,6 @@ import produce from 'immer'
|
|
|
|
|
import type { NodeWithVar, VarInInspect } from '@/types/workflow'
|
|
|
|
|
import type { ValueSelector } from '../../../types'
|
|
|
|
|
import type { Node } from '@/app/components/workflow/types'
|
|
|
|
|
import { isConversationVar, isENV, isSystemVar } from '../../../nodes/_base/components/variable/utils'
|
|
|
|
|
|
|
|
|
|
type InspectVarsState = {
|
|
|
|
|
currentFocusNodeId: string | null
|
|
|
|
|
@ -15,18 +14,12 @@ type InspectVarsActions = {
|
|
|
|
|
setCurrentFocusNodeId: (nodeId: string | null) => void
|
|
|
|
|
setNodesWithInspectVars: (payload: NodeWithVar[]) => void
|
|
|
|
|
deleteAllInspectVars: () => void
|
|
|
|
|
getAllInspectVars: () => NodeWithVar[]
|
|
|
|
|
setNodeInspectVars: (nodeId: string, payload: VarInInspect[]) => void
|
|
|
|
|
appendNodeInspectVars: (nodeId: string, payload: VarInInspect[], allNodes: Node[]) => void
|
|
|
|
|
deleteNodeInspectVars: (nodeId: string) => void
|
|
|
|
|
getNodeInspectVars: (nodeId: string) => NodeWithVar | undefined
|
|
|
|
|
getVarId: (nodeId: string, varName: string) => string | undefined
|
|
|
|
|
setInspectVarValue: (nodeId: string, name: string, value: any) => void
|
|
|
|
|
renameInspectVarName: (nodeId: string, varId: string, selector: ValueSelector) => void
|
|
|
|
|
deleteInspectVar: (nodeId: string, varId: string) => void
|
|
|
|
|
getInspectVar: (nodeId: string, name: string) => any
|
|
|
|
|
hasSetInspectVar: (nodeId: string, name: string, sysVars: VarInInspect[], conversationVars: VarInInspect[]) => boolean
|
|
|
|
|
isInspectVarEdited: (nodeId: string, name: string) => boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type InspectVarsSliceShape = InspectVarsState & InspectVarsActions
|
|
|
|
|
@ -46,9 +39,6 @@ export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set,
|
|
|
|
|
nodesWithInspectVars: payload,
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
getAllInspectVars: () => {
|
|
|
|
|
return get().nodesWithInspectVars
|
|
|
|
|
},
|
|
|
|
|
deleteAllInspectVars: () => {
|
|
|
|
|
set(() => ({
|
|
|
|
|
nodesWithInspectVars: [],
|
|
|
|
|
@ -101,19 +91,6 @@ export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set,
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
},
|
|
|
|
|
getNodeInspectVars: (nodeId) => {
|
|
|
|
|
const nodes = get().nodesWithInspectVars
|
|
|
|
|
return nodes.find(node => node.nodeId === nodeId)
|
|
|
|
|
},
|
|
|
|
|
getVarId: (nodeId: string, varName: string) => {
|
|
|
|
|
const node = get().getNodeInspectVars(nodeId)
|
|
|
|
|
if (!node)
|
|
|
|
|
return undefined
|
|
|
|
|
const varId = node.vars.find((varItem) => {
|
|
|
|
|
return varItem.selector[1] === varName
|
|
|
|
|
})?.id
|
|
|
|
|
return varId
|
|
|
|
|
},
|
|
|
|
|
setInspectVarValue: (nodeId, varId, value) => {
|
|
|
|
|
set(produce((state: InspectVarsSliceShape) => {
|
|
|
|
|
const nodes = state.nodesWithInspectVars.map((node) => {
|
|
|
|
|
@ -167,34 +144,5 @@ export const createInspectVarsSlice: StateCreator<InspectVarsSliceShape> = (set,
|
|
|
|
|
state.nodesWithInspectVars = nodes
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
getInspectVar: (nodeId, name) => {
|
|
|
|
|
const node = get().getNodeInspectVars(nodeId)
|
|
|
|
|
if (!node)
|
|
|
|
|
return undefined
|
|
|
|
|
|
|
|
|
|
const variable = node.vars.find((varItem) => {
|
|
|
|
|
return varItem.selector[1] === name
|
|
|
|
|
})?.value
|
|
|
|
|
return variable
|
|
|
|
|
},
|
|
|
|
|
hasSetInspectVar: (nodeId, name, sysVars, conversationVars) => {
|
|
|
|
|
const isEnv = isENV([nodeId])
|
|
|
|
|
if (isEnv) // always have value
|
|
|
|
|
return true
|
|
|
|
|
const isSys = isSystemVar([nodeId])
|
|
|
|
|
if (isSys)
|
|
|
|
|
return sysVars.some(varItem => varItem.selector?.[1] === name)
|
|
|
|
|
const isChatVar = isConversationVar([nodeId])
|
|
|
|
|
if (isChatVar)
|
|
|
|
|
return conversationVars.some(varItem => varItem.selector?.[1] === name)
|
|
|
|
|
return get().getInspectVar(nodeId, name) !== undefined
|
|
|
|
|
},
|
|
|
|
|
isInspectVarEdited: (nodeId, name) => {
|
|
|
|
|
const inspectVar = get().getInspectVar(nodeId, name)
|
|
|
|
|
if (!inspectVar)
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
return inspectVar.edited
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|