import type { NodeProps } from '../../types' import type { AgentV2NodeType } from './types' import type { AppIconType } from '@/types/app' import { useTranslation } from 'react-i18next' import AppIcon from '@/app/components/base/app-icon' import { SettingItem } from '../_base/components/setting-item' import { useAgentRosterDetail, useWorkflowInlineAgentDetail } from './hooks' import { hasInlineAgentBinding, hasValidRosterAgentBinding } from './types' const getAppIconType = (iconType?: string | null): AppIconType | null => { if (iconType === 'emoji' || iconType === 'image' || iconType === 'link') return iconType return null } function AgentNodeAvatar({ agent, isInlineAgent, }: { agent?: ReturnType['data'] isInlineAgent: boolean }) { if (isInlineAgent) { return ( ) } if (!agent) return return ( ) } function AgentNodeAvatarPlaceholder() { return } function AgentNodeModel({ data, agent, inlineAgentName, isLoading, }: { data: AgentV2NodeType agent?: ReturnType['data'] inlineAgentName?: string isLoading: boolean }) { const { t } = useTranslation() const isInlineAgent = hasInlineAgentBinding(data) const name = isInlineAgent ? (inlineAgentName || t('nodes.agent.roster.inlineSetup.name', { ns: 'workflow' })) : agent?.name const role = isInlineAgent ? t('nodes.agent.roster.inlineSetup.type', { ns: 'workflow' }) : '' const showPlaceholder = isLoading || (!isInlineAgent && !agent) return (
{t('nodes.agent.roster.label', { ns: 'workflow' })}
{showPlaceholder ? : }
{showPlaceholder ? (
) : ( <>
{name}
{role}
)}
) } export function AgentV2Node({ id, data }: NodeProps) { const { t } = useTranslation() const hasValidAgent = hasValidRosterAgentBinding(data) const isInlineAgent = hasInlineAgentBinding(data) const rosterAgentId = data.agent_binding?.binding_type === 'roster_agent' ? data.agent_binding.agent_id : undefined const inlineAgentId = data.agent_binding?.binding_type === 'inline_agent' ? data.agent_binding.agent_id : undefined const rosterAgentQuery = useAgentRosterDetail(rosterAgentId) const inlineAgentQuery = useWorkflowInlineAgentDetail(id, inlineAgentId) const isInlineAgentDetailLoading = isInlineAgent && !!inlineAgentId && inlineAgentQuery.isPending if (isInlineAgent || hasValidAgent) return return (
{rosterAgentQuery.data?.name}
) }