import { ReactNode, useEffect } from 'react'; import { toast as sonnerToast } from 'sonner'; import { useAgent, useSessionContext } from '@livekit/components-react'; import { WarningIcon } from '@phosphor-icons/react'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; interface ToastProps { title: ReactNode; description: ReactNode; } function toastAlert(toast: ToastProps) { const { title, description } = toast; return sonnerToast.custom( (id) => ( sonnerToast.dismiss(id)} className="bg-accent w-full md:w-[364px]"> {title} {description && {description}} ), { duration: 10_000 } ); } export function useAgentErrors() { const agent = useAgent(); const { isConnected, end } = useSessionContext(); useEffect(() => { if (isConnected && agent.state === 'failed') { const reasons = agent.failureReasons; toastAlert({ title: 'Session ended', description: ( <> {reasons.length > 1 && ( )} {reasons.length === 1 &&

{reasons[0]}

}

See quickstart guide .

), }); end(); } }, [agent, isConnected, end]); }