import React, { useRef, useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { Dialog, Button, DotsIcon, DialogContent, useToastContext } from '@librechat/client'; import type t from 'librechat-data-provider'; import { renderAgentAvatar } from '~/utils'; import { useLocalize } from '~/hooks'; interface SupportContact { name?: string; email?: string; } interface AgentWithSupport extends t.Agent { support_contact?: SupportContact; } interface AgentDetailProps { agent: AgentWithSupport; // The agent data to display isOpen: boolean; // Whether the detail dialog is open onClose: () => void; // Callback when dialog is closed } /** * Dialog for displaying agent details */ const AgentDetail: React.FC = ({ agent, isOpen, onClose }) => { const localize = useLocalize(); const navigate = useNavigate(); const { showToast } = useToastContext(); const dialogRef = useRef(null); const dropdownRef = useRef(null); const [dropdownOpen, setDropdownOpen] = useState(false); // Close dropdown when clicking outside the dropdown menu useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( dropdownOpen && dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setDropdownOpen(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [dropdownOpen]); /** * Navigate to chat with the selected agent */ const handleStartChat = () => { if (agent) { navigate(`/c/new?agent_id=${agent.id}`); } }; /** * Copy the agent's shareable link to clipboard */ const handleCopyLink = () => { const baseUrl = new URL(window.location.origin); const chatUrl = `${baseUrl.origin}/c/new?agent_id=${agent.id}`; navigator.clipboard .writeText(chatUrl) .then(() => { showToast({ message: 'Link copied', }); }) .catch(() => { showToast({ message: localize('com_agents_link_copy_failed'), }); }); }; /** * Format contact information with mailto links when appropriate */ const formatContact = () => { if (!agent?.support_contact) return null; const { name, email } = agent.support_contact; if (name && email) { return ( {name} ); } if (email) { return ( {email} ); } if (name) { return {name}; } return null; }; return ( !open && onClose()}> {/* Context menu - top right */}
{/* Simple dropdown menu */} {dropdownOpen && (
)}
{/* Agent avatar - top center */}
{renderAgentAvatar(agent, { size: 'xl' })}
{/* Agent name - center aligned below image */}

{agent?.name || localize('com_agents_loading')}

{/* Contact info - center aligned below name */} {agent?.support_contact && formatContact() && (
{localize('com_agents_contact')}: {formatContact()}
)} {/* Agent description - below contact */}
{agent?.description || ( {localize('com_agents_no_description')} )}
{/* Action button */}
); }; export default AgentDetail;