import type { FC } from 'react' import React from 'react' import type { EndNodeType } from './types' import type { NodeProps, ValueSelector, Variable } from '@/app/components/workflow/types' import { toNodeOutputVars } from '@/app/components/workflow/nodes/_base/components/variable/utils' import { useIsChatMode, useWorkflow, } from '@/app/components/workflow/hooks' import { VarBlockIcon } from '@/app/components/workflow/block-icon' import { Line3 } from '@/app/components/base/icons/src/public/common' import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development' import { BlockEnum, VarType } from '@/app/components/workflow/types' const Node: FC> = ({ id, data, }) => { const { getBeforeNodesInSameBranch } = useWorkflow() const availableNodes = getBeforeNodesInSameBranch(id) const isChatMode = useIsChatMode() const outputVars = toNodeOutputVars(availableNodes, isChatMode) const getNode = (id: string) => { return availableNodes.find(node => node.id === id) } const getVarType = (nodeId: string, value: ValueSelector) => { const targetVar = outputVars.find(v => v.nodeId === nodeId) if (!targetVar) return 'undefined' let type: VarType = VarType.string let curr: any = targetVar.vars; (value).slice(1).forEach((key, i) => { const isLast = i === value.length - 2 curr = curr.find((v: any) => v.variable === key) if (isLast) { type = curr.type } else { if (curr.type === VarType.object) curr = curr.children } }) return type } const { outputs } = data return (
{(outputs as Variable[]).filter(({ value_selector }) => value_selector.length > 0).map(({ value_selector }, index) => { const node = getNode(value_selector[0]) const varName = value_selector[value_selector.length - 1] return (
{node?.data.title}
{varName}
{getVarType(node?.id || '', value_selector)}
) })}
) } export default React.memo(Node)