import React from 'react'; import { Button } from '../ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '../ui/card'; import { useI18n } from '@/lib/i18n'; import { Icon } from "@/components/icon/Icon"; interface ChatErrorBoundaryState { hasError: boolean; error?: Error; errorInfo?: React.ErrorInfo; } interface ChatErrorBoundaryProps { children: React.ReactNode; sessionId?: string; } interface ChatErrorBoundaryTexts { title: string; description: string; sessionLabel: string; detailsSummary: string; resetAction: string; persistentHint: string; } interface ChatErrorBoundaryViewProps extends ChatErrorBoundaryProps { texts: ChatErrorBoundaryTexts; } class ChatErrorBoundaryView extends React.Component { constructor(props: ChatErrorBoundaryViewProps) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error: Error): ChatErrorBoundaryState { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { this.setState({ error, errorInfo }); if (process.env.NODE_ENV === 'development') { console.error('Chat error caught by boundary:', error, errorInfo); } } handleReset = () => { this.setState({ hasError: false, error: undefined, errorInfo: undefined }); }; render() { if (this.state.hasError) { return (
{this.props.texts.title}

{this.props.texts.description}

{this.props.sessionId && (
{this.props.texts.sessionLabel}: {this.props.sessionId}
)} {this.state.error && (
{this.props.texts.detailsSummary}
                    {this.state.error.toString()}
                  
)}
{this.props.texts.persistentHint}
); } return this.props.children; } } export function ChatErrorBoundary(props: ChatErrorBoundaryProps) { const { t } = useI18n(); return ( ); }