Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(workflow): fix var-selector not update when edges change #8259

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
iamjoel marked this conversation as resolved.
Show resolved Hide resolved
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