From cf29632261edbb57a2db6f6fbfd7b3a7d7eb3f10 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 18:48:30 +0700 Subject: [PATCH] support presenting two options in quilly and for 400s suggest either a new convo or a model change --- src/components/Quilly.tsx | 83 +++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index f88c9990..7a8b20e3 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -21,10 +21,10 @@ export interface QuillyProps { interface ErrorBody { message: string; - action?: { + actions?: Array<{ label: string; onClick: () => void; - }; + }>; } export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onRequestConsoleErrorHelp, providerModel }: QuillyProps) { @@ -46,16 +46,16 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq const renderBody = (error: Error): ErrorBody => { // Handle Project Preview Console Errors if (error instanceof ProjectPreviewConsoleError) { - return { - message: 'I noticed some console errors in your project preview. Would you like me to take a look and help fix them?', - action: { - label: 'Help fix errors', - onClick: () => { - onRequestConsoleErrorHelp?.(error); - onDismiss(); - }, - }, - }; + return { + message: 'I noticed some console errors in your project preview. Would you like me to take a look and help fix them?', + actions: [{ + label: 'Help fix errors', + onClick: () => { + onRequestConsoleErrorHelp?.(error); + onDismiss(); + }, + }], + }; } // Handle OpenAI API errors with specific error codes @@ -65,28 +65,28 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq case 'invalid_request_error': return { message: 'Authentication error: Please check your API key in AI settings.', - action: { + actions: [{ label: 'Check API key', onClick: () => navigate('/settings/ai'), - } + }], }; case 'insufficient_quota': { if (credits.data) { return { message: `Your account has $${credits.data.amount.toFixed(2)} credits. Please add credits to keep creating.`, - action: { + actions: [{ label: 'Add credits', onClick: () => setShowCreditsDialog(true), - } + }], }; } else { return { message: 'Your API key has reached its usage limit. Please check your billing or try a different provider.', - action: { + actions: [{ label: 'Check AI settings', onClick: () => navigate('/settings/ai'), - } + }], }; } } @@ -94,53 +94,62 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq case 'rate_limit_exceeded': return { message: 'Rate limit exceeded. Please wait a moment before trying again.', + actions: [], }; case 'model_not_found': return { message: 'The selected AI model is not available. Please choose a different model.', - action: { + actions: [{ label: 'Choose model', onClick: onOpenModelSelector, - }, + }], }; case 'context_length_exceeded': return { message: 'Your conversation is too long for this model. Try starting a new chat or switching to a model with a larger context window.', - action: { + actions: [{ label: 'New chat', onClick: onNewChat, - }, + }, { + label: 'Change model', + onClick: onOpenModelSelector, + }], }; case 'bad_request': return { message: 'The AI provider did not understand the message / data it got. If it persists, try stating a new conversation or using a different model.', - action: { - label: 'Choose model', + actions: [{ + label: 'New chat', + onClick: onNewChat, + }, { + label: 'Change model', onClick: onOpenModelSelector, - }, + }], }; case 'unprocessable_entity': return { message: 'Request rejected by AI provider. Try a different model.', - action: { + actions: [{ label: 'Choose model', onClick: onOpenModelSelector, - }, + }], }; case 'server_error': case 'service_unavailable': return { message: 'The AI service is temporarily unavailable. Please try again in a moment.', + actions: [], }; default: return { message: `AI service error: ${error.message}`, + actions: [], }; } } @@ -150,10 +159,11 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq message: error.message ? `AI service error: ${error.message}` : 'Sorry, I encountered an unexpected error. Please try again.', + actions: [], }; }; - const { message, action } = renderBody(error); + const { message, actions = [] } = renderBody(error); return (
@@ -166,11 +176,18 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq

{message} - {' '} - {action && ( - + {actions.length > 0 && ( + <> + {' '} + {actions.map((action, i) => ( + + + {i < actions.length - 1 && <> or } + + ))} + )}