import React, { useMemo, useState } from 'react'; import { EModelEndpoint, Constants } from 'librechat-data-provider'; import { ChevronDown } from 'lucide-react'; import type { TMessage } from 'librechat-data-provider'; import MessageIcon from '~/components/Share/MessageIcon'; import { useAgentsMapContext } from '~/Providers'; import { useLocalize } from '~/hooks'; import { cn } from '~/utils'; interface AgentHandoffProps { name: string; args: string | Record; output?: string | null; } const AgentHandoff: React.FC = ({ name, args: _args = '' }) => { const localize = useLocalize(); const agentsMap = useAgentsMapContext(); const [showInfo, setShowInfo] = useState(false); /** Extracted agent ID from tool name (e.g., "lc_transfer_to_agent_gUV0wMb7zHt3y3Xjz-8_4" -> "agent_gUV0wMb7zHt3y3Xjz-8_4") */ const targetAgentId = useMemo(() => { if (typeof name !== 'string' || !name.startsWith(Constants.LC_TRANSFER_TO_)) { return null; } return name.replace(Constants.LC_TRANSFER_TO_, ''); }, [name]); const targetAgent = useMemo(() => { if (!targetAgentId || !agentsMap) { return null; } return agentsMap[targetAgentId]; }, [agentsMap, targetAgentId]); const args = useMemo(() => { if (typeof _args === 'string') { return _args; } try { return JSON.stringify(_args, null, 2); } catch { return ''; } }, [_args]) as string; /** Requires more than 2 characters as can be an empty object: `{}` */ const hasInfo = useMemo(() => (args?.trim()?.length ?? 0) > 2, [args]); return (
hasInfo && setShowInfo(!showInfo)} >
{localize('com_ui_transferred_to')} {targetAgent?.name || localize('com_ui_agent')} {hasInfo && (
{hasInfo && showInfo && (
{localize('com_ui_handoff_instructions')}:
{args}
)}
); }; export default AgentHandoff;