Skip to content

Commit

Permalink
fix(workflow): fix var-selector not update when edges change (langgen…
Browse files Browse the repository at this point in the history
…ius#8259)

Co-authored-by: Chen(MAC) <[email protected]>
  • Loading branch information
2 people authored and JunXu01 committed Nov 9, 2024
1 parent 276f143 commit 6753dcc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@remixicon/react'
import produce from 'immer'
import { useStoreApi } from 'reactflow'
import useAvailableVarList from '../../hooks/use-available-var-list'
import VarReferencePopup from './var-reference-popup'
import { getNodeInfoById, isConversationVar, isENV, isSystemVar } from './utils'
import ConstantField from './constant-field'
Expand All @@ -26,7 +27,6 @@ import {
} from '@/app/components/base/portal-to-follow-elem'
import {
useIsChatMode,
useWorkflow,
useWorkflowVariables,
} from '@/app/components/workflow/hooks'
import { VarType as VarKindType } from '@/app/components/workflow/nodes/tool/types'
Expand Down Expand Up @@ -67,7 +67,7 @@ const VarReferencePicker: FC<Props> = ({
onlyLeafNodeVar,
filterVar = () => true,
availableNodes: passedInAvailableNodes,
availableVars,
availableVars: passedInAvailableVars,
isAddBtnTrigger,
schema,
valueTypePlaceHolder,
Expand All @@ -79,11 +79,12 @@ const VarReferencePicker: FC<Props> = ({
} = store.getState()
const isChatMode = useIsChatMode()

const { getTreeLeafNodes, getBeforeNodesInSameBranch } = useWorkflow()
const { getCurrentVariableType, getNodeAvailableVars } = useWorkflowVariables()
const availableNodes = useMemo(() => {
return passedInAvailableNodes || (onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId))
}, [getBeforeNodesInSameBranch, getTreeLeafNodes, nodeId, onlyLeafNodeVar, passedInAvailableNodes])
const { getCurrentVariableType } = useWorkflowVariables()
const { availableNodes, availableVars } = useAvailableVarList(nodeId, {
onlyLeafNodeVar,
passedInAvailableNodes,
filterVar,
})
const startNode = availableNodes.find((node: any) => {
return node.data.type === BlockEnum.Start
})
Expand All @@ -102,19 +103,8 @@ const VarReferencePicker: FC<Props> = ({

const [varKindType, setVarKindType] = useState<VarKindType>(defaultVarKindType)
const isConstant = isSupportConstantValue && varKindType === VarKindType.constant
const outputVars = useMemo(() => {
if (availableVars)
return availableVars

const vars = getNodeAvailableVars({
parentNode: iterationNode,
beforeNodes: availableNodes,
isChatMode,
filterVar,
})

return vars
}, [iterationNode, availableNodes, isChatMode, filterVar, availableVars, getNodeAvailableVars])
const outputVars = useMemo(() => (passedInAvailableVars || availableVars), [passedInAvailableVars, availableVars])

const [open, setOpen] = useState(false)
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import {
useWorkflow,
useWorkflowVariables,
} from '@/app/components/workflow/hooks'
import type { ValueSelector, Var } from '@/app/components/workflow/types'
import type { Node, ValueSelector, Var } from '@/app/components/workflow/types'
type Params = {
onlyLeafNodeVar?: boolean
hideEnv?: boolean
hideChatVar?: boolean
filterVar: (payload: Var, selector: ValueSelector) => boolean
passedInAvailableNodes?: Node[]
}

const useAvailableVarList = (nodeId: string, {
onlyLeafNodeVar,
filterVar,
hideEnv,
hideChatVar,
passedInAvailableNodes,
}: Params = {
onlyLeafNodeVar: false,
filterVar: () => true,
Expand All @@ -25,7 +27,7 @@ const useAvailableVarList = (nodeId: string, {
const { getNodeAvailableVars } = useWorkflowVariables()
const isChatMode = useIsChatMode()

const availableNodes = onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId)
const availableNodes = passedInAvailableNodes || (onlyLeafNodeVar ? getTreeLeafNodes(nodeId) : getBeforeNodesInSameBranch(nodeId))

const {
parentNode: iterationNode,
Expand Down

0 comments on commit 6753dcc

Please sign in to comment.