import LLMLabel from '@/components/llm-select/llm-label'; import { IAgentNode } from '@/interfaces/database/flow'; import { Handle, NodeProps, Position } from '@xyflow/react'; import { get } from 'lodash'; import { memo, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { AgentExceptionMethod, NodeHandleId } from '../../constant'; import useGraphStore from '../../store'; import { isBottomSubAgent } from '../../utils'; import { CommonHandle } from './handle'; import { LeftHandleStyle, RightHandleStyle } from './handle-icon'; import styles from './index.less'; import NodeHeader from './node-header'; import { NodeWrapper } from './node-wrapper'; import { ToolBar } from './toolbar'; function InnerAgentNode({ id, data, isConnectable = true, selected, }: NodeProps) { const edges = useGraphStore((state) => state.edges); const { t } = useTranslation(); const isHeadAgent = useMemo(() => { return !isBottomSubAgent(edges, id); }, [edges, id]); const exceptionMethod = useMemo(() => { return get(data, 'form.exception_method'); }, [data]); const isGotoMethod = useMemo(() => { return exceptionMethod === AgentExceptionMethod.Goto; }, [exceptionMethod]); return ( {isHeadAgent && ( <> )}
{(isGotoMethod || exceptionMethod === AgentExceptionMethod.Comment) && (
{t('flow.onFailure')} {t(`flow.${exceptionMethod}`)}
)}
{isGotoMethod && ( )}
); } export const AgentNode = memo(InnerAgentNode);