import React, { useRef } from 'react'; import { Link } from 'lucide-react'; import { useQueryClient } from '@tanstack/react-query'; import { OGDialog, OGDialogContent, Button, useToastContext } from '@librechat/client'; import { QueryKeys, Constants, EModelEndpoint, PermissionBits, LocalStorageKeys, AgentListResponse, } from 'librechat-data-provider'; import type t from 'librechat-data-provider'; import { useChatContext } from '~/Providers'; 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 { conversation, newConversation } = useChatContext(); const { showToast } = useToastContext(); const dialogRef = useRef(null); const queryClient = useQueryClient(); /** * Navigate to chat with the selected agent */ const handleStartChat = () => { if (agent) { const keys = [QueryKeys.agents, { requiredPermission: PermissionBits.EDIT }]; const listResp = queryClient.getQueryData(keys); if (listResp != null) { if (!listResp.data.some((a) => a.id === agent.id)) { const currentAgents = [agent, ...JSON.parse(JSON.stringify(listResp.data))]; queryClient.setQueryData(keys, { ...listResp, data: currentAgents }); } } localStorage.setItem(`${LocalStorageKeys.AGENT_ID_PREFIX}0`, agent.id); queryClient.setQueryData( [QueryKeys.messages, conversation?.conversationId ?? Constants.NEW_CONVO], [], ); queryClient.invalidateQueries([QueryKeys.messages]); newConversation({ template: { conversationId: Constants.NEW_CONVO as string, endpoint: EModelEndpoint.agents, agent_id: agent.id, title: `Chat with ${agent.name || 'Agent'}`, }, }); } }; /** * 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: localize('com_agents_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()}> {/* Copy link button - positioned next to close button */} {/* 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;