import React from 'react'; import { RiChat3Line, RiRestartLine } from '@remixicon/react'; import { Button } from '../ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '../ui/card'; interface ChatErrorBoundaryState { hasError: boolean; error?: Error; errorInfo?: React.ErrorInfo; } interface ChatErrorBoundaryProps { children: React.ReactNode; sessionId?: string; } export class ChatErrorBoundary extends React.Component { constructor(props: ChatErrorBoundaryProps) { 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 (
Chat Error

The chat interface encountered an error. This might be due to a temporary network issue or corrupted message data.

{this.props.sessionId && (
Session: {this.props.sessionId}
)} {this.state.error && (
Error details
                    {this.state.error.toString()}
                  
)}
If the problem persists, try refreshing the page.
); } return this.props.children; } }