import { IAgentNode } from '@/interfaces/database/flow'; import { cn } from '@/lib/utils'; 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 { AgentFormSchemaType } from '../../form/agent-form'; import useGraphStore from '../../store'; import { hasSubAgent, isBottomSubAgent } from '../../utils'; import { LLMLabelCard } from './card'; import { CommonHandle, LeftEndHandle } from './handle'; import { RightHandleStyle } from './handle-icon'; 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 hasTools = useMemo(() => { const tools = get(data, 'form.tools', []); const mcp = get(data, 'form.mcp', []); return tools.length > 0 || mcp.length > 0; }, [data]); const isGotoMethod = useMemo(() => { return exceptionMethod === AgentExceptionMethod.Goto; }, [exceptionMethod]); return ( {isHeadAgent && ( <> )} {isHeadAgent || ( )}
{(isGotoMethod || exceptionMethod === AgentExceptionMethod.Comment) && (
{t('flow.onFailure')} {t(`flow.${exceptionMethod}`)}
)}
{isGotoMethod && ( )}
); } export const AgentNode = memo(InnerAgentNode);