import { Button } from '@/components/ui/button'; import { QuillySVG } from '@/components/ui/QuillySVG'; import { X } from 'lucide-react'; export interface QuillyProps { error: Error; onDismiss: () => void; action?: { label: string; onClick: () => void }; } export function Quilly({ error, onDismiss, action }: QuillyProps) { // Generate user-friendly message from error const getMessage = (error: Error): string => { const errorMsg = error.message || ''; if (error.name === 'TypeError' && errorMsg.includes('fetch')) { return 'Network error: Unable to connect to AI service. Please check your internet connection and AI settings.'; } else if (errorMsg.includes('API key')) { return 'Authentication error: Please check your API key in AI settings.'; } else if (errorMsg.includes('rate limit')) { return 'Rate limit exceeded. Please wait a moment before trying again.'; } else if (errorMsg.includes('insufficient_quota')) { return 'Quota exceeded: Your API key has reached its usage limit. Please check your billing or try a different provider.'; } else if (errorMsg.includes('model_not_found') || errorMsg.includes('does not exist')) { return 'Model not found: The selected AI model is not available. Please choose a different model.'; } else if (errorMsg.includes('maximum context length') || errorMsg.includes('context length')) { return 'Your conversation is too long for this model. Try starting a new chat or switching to a model with a larger context window.'; } else if (errorMsg.includes('422') || errorMsg.includes('Provider returned error')) { return 'The AI model encountered an issue. Try switching to a different model or starting a new chat.'; } else if (errorMsg.includes('too many requests')) { return 'You\'re sending requests too quickly. Please wait a moment before trying again.'; } else if (errorMsg) { return `AI service error: ${errorMsg}`; } else { return 'Sorry, I encountered an unexpected error. Please try again.'; } }; const message = getMessage(error); return (
{message} {' '} {action && ( )}