From 185cdc51fb148a33566542ee93dabcb20b9efb55 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 18:08:17 +0700 Subject: [PATCH 01/19] handle 422s and surface to quilly --- src/components/Quilly.tsx | 9 +++++++++ src/lib/SessionManager.ts | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index b0b97f05..c4185076 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -114,6 +114,15 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }, }; + case 'unprocessable_entity': + return { + message: 'Request rejected by AI provider. Try a different model.', + action: { + label: 'Choose model', + onClick: onOpenModelSelector, + }, + }; + case 'server_error': case 'service_unavailable': return { diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index fde41dd3..923c69bb 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -408,6 +408,17 @@ export class SessionManager { return; // User cancelled } + // Convert UnprocessableEntityError to standard OpenAI APIError with code + if (error?.constructor?.name === 'UnprocessableEntityError') { + const apiError = new OpenAI.APIError({ + status: 422, + code: 'unprocessable_entity', + message: '422 Provider returned error' + }); + apiError.code = 'unprocessable_entity'; + throw apiError; + } + // Re-throw service errors to be handled at the UI level throw error; } finally { From 52198a0a3ca4eae14352faf7b907f5855d6444a7 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 18:34:54 +0700 Subject: [PATCH 02/19] handle 400s too --- src/components/Quilly.tsx | 9 +++++++++ src/lib/SessionManager.ts | 23 +++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index c4185076..9ac094f0 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -114,6 +114,15 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }, }; + case 'bad_request': + return { + message: 'Invalid request parameters. Try a different model.', + action: { + label: 'Choose model', + onClick: onOpenModelSelector, + }, + }; + case 'unprocessable_entity': return { message: 'Request rejected by AI provider. Try a different model.', diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index 923c69bb..2d30daef 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -408,14 +408,25 @@ export class SessionManager { return; // User cancelled } - // Convert UnprocessableEntityError to standard OpenAI APIError with code - if (error?.constructor?.name === 'UnprocessableEntityError') { + // Convert provider errors to standard OpenAI APIError with appropriate code + if (error?.status === 400) { + const code = 'bad_request'; const apiError = new OpenAI.APIError({ - status: 422, - code: 'unprocessable_entity', - message: '422 Provider returned error' + status: error.status, + code, + message: `${error.status} Provider returned error` }); - apiError.code = 'unprocessable_entity'; + apiError.code = code; + throw apiError; + } + if (error?.status === 422) { + const code = 'unprocessable_entity' + const apiError = new OpenAI.APIError({ + status: error.status, + code, + message: `${error.status} Provider returned error` + }); + apiError.code = code; throw apiError; } From ecdb33460d0031a3e7446a508ee94b78b7706c93 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 18:39:48 +0700 Subject: [PATCH 03/19] broader error desc --- src/components/Quilly.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index 9ac094f0..f88c9990 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -116,7 +116,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq case 'bad_request': return { - message: 'Invalid request parameters. Try a different model.', + 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', onClick: onOpenModelSelector, From cf29632261edbb57a2db6f6fbfd7b3a7d7eb3f10 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 18:48:30 +0700 Subject: [PATCH 04/19] 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 } + + ))} + )}

From 4ce51b3659ac34fe3f8ad8fd88a692624ab955bf Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 19:13:10 +0700 Subject: [PATCH 05/19] handle 403s --- src/components/Quilly.tsx | 6 ++++++ src/lib/SessionManager.ts | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index 7a8b20e3..88db0970 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -118,6 +118,12 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; + case 'key_limit_exceeded': + return { + message: `It seems your API key has been used up. Check your API provider's settings, or try a different API key or different provider/model combo`, + actions: [], + }; + 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.', diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index 2d30daef..b375e1a4 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -419,6 +419,16 @@ export class SessionManager { apiError.code = code; throw apiError; } + if (error?.status === 403) { + const code = 'key_limit_exceeded'; + const apiError = new OpenAI.APIError({ + status: error.status, + code, + message: `${error.status} Provider returned error` + }); + apiError.code = code; + throw apiError; + } if (error?.status === 422) { const code = 'unprocessable_entity' const apiError = new OpenAI.APIError({ From 5a5bec28c43ba45ef4d9d329fed748a43614abc2 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 19:17:17 +0700 Subject: [PATCH 06/19] offer the user two routes forward when their keys run dry --- src/components/Quilly.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index 88db0970..d17f63d4 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -118,11 +118,17 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'key_limit_exceeded': - return { - message: `It seems your API key has been used up. Check your API provider's settings, or try a different API key or different provider/model combo`, - actions: [], - }; + case 'key_limit_exceeded': + return { + message: `It seems your API key has been used up. Check your API provider's settings, or try a different API key or different provider/model combo:`, + actions: [{ + label: 'Check API settings', + onClick: () => navigate('/settings/ai'), + }, { + label: 'Change model', + onClick: onOpenModelSelector, + }], + }; case 'bad_request': return { From d02d8959f6c06a7676858c46885d58a3e0401fd6 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 21:08:25 +0700 Subject: [PATCH 07/19] lint --- src/lib/SessionManager.ts | 41 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index b375e1a4..3de7da47 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -411,33 +411,30 @@ export class SessionManager { // Convert provider errors to standard OpenAI APIError with appropriate code if (error?.status === 400) { const code = 'bad_request'; - const apiError = new OpenAI.APIError({ - status: error.status, - code, - message: `${error.status} Provider returned error` - }); - apiError.code = code; - throw apiError; + throw new OpenAI.APIError( + { status: error.status, code, message: `${error.status} Provider returned error` }, + { method: 'POST', url: '', body: {}, status: error.status }, + error.name, + error.cause + ); } if (error?.status === 403) { const code = 'key_limit_exceeded'; - const apiError = new OpenAI.APIError({ - status: error.status, - code, - message: `${error.status} Provider returned error` - }); - apiError.code = code; - throw apiError; + throw new OpenAI.APIError( + { status: error.status, code, message: `${error.status} Provider returned error` }, + { method: 'POST', url: '', body: {}, status: error.status }, + error.name, + error.cause + ); } if (error?.status === 422) { - const code = 'unprocessable_entity' - const apiError = new OpenAI.APIError({ - status: error.status, - code, - message: `${error.status} Provider returned error` - }); - apiError.code = code; - throw apiError; + const code = 'unprocessable_entity'; + throw new OpenAI.APIError( + { status: error.status, code, message: `${error.status} Provider returned error` }, + { method: 'POST', url: '', body: {}, status: error.status }, + error.name, + error.cause + ); } // Re-throw service errors to be handled at the UI level From 00d9d4d005489cc4361ce3598821c8fdda305729 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 21:28:41 +0700 Subject: [PATCH 08/19] Revert "lint" This reverts commit d02d8959f6c06a7676858c46885d58a3e0401fd6. --- src/lib/SessionManager.ts | 41 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index 3de7da47..b375e1a4 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -411,30 +411,33 @@ export class SessionManager { // Convert provider errors to standard OpenAI APIError with appropriate code if (error?.status === 400) { const code = 'bad_request'; - throw new OpenAI.APIError( - { status: error.status, code, message: `${error.status} Provider returned error` }, - { method: 'POST', url: '', body: {}, status: error.status }, - error.name, - error.cause - ); + const apiError = new OpenAI.APIError({ + status: error.status, + code, + message: `${error.status} Provider returned error` + }); + apiError.code = code; + throw apiError; } if (error?.status === 403) { const code = 'key_limit_exceeded'; - throw new OpenAI.APIError( - { status: error.status, code, message: `${error.status} Provider returned error` }, - { method: 'POST', url: '', body: {}, status: error.status }, - error.name, - error.cause - ); + const apiError = new OpenAI.APIError({ + status: error.status, + code, + message: `${error.status} Provider returned error` + }); + apiError.code = code; + throw apiError; } if (error?.status === 422) { - const code = 'unprocessable_entity'; - throw new OpenAI.APIError( - { status: error.status, code, message: `${error.status} Provider returned error` }, - { method: 'POST', url: '', body: {}, status: error.status }, - error.name, - error.cause - ); + const code = 'unprocessable_entity' + const apiError = new OpenAI.APIError({ + status: error.status, + code, + message: `${error.status} Provider returned error` + }); + apiError.code = code; + throw apiError; } // Re-throw service errors to be handled at the UI level From 10ea68547c9d152c22f741f5db46845decd654ce Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 21:38:48 +0700 Subject: [PATCH 09/19] use specific openai errors --- src/lib/SessionManager.ts | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index b375e1a4..110f9844 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -410,34 +410,13 @@ export class SessionManager { // Convert provider errors to standard OpenAI APIError with appropriate code if (error?.status === 400) { - const code = 'bad_request'; - const apiError = new OpenAI.APIError({ - status: error.status, - code, - message: `${error.status} Provider returned error` - }); - apiError.code = code; - throw apiError; + throw new OpenAI.BadRequestError(400, { code: 'bad_request' }, error.message, new Headers()); } if (error?.status === 403) { - const code = 'key_limit_exceeded'; - const apiError = new OpenAI.APIError({ - status: error.status, - code, - message: `${error.status} Provider returned error` - }); - apiError.code = code; - throw apiError; + throw new OpenAI.PermissionDeniedError(403, { code: 'key_limit_exceeded' }, error.message, new Headers()); } if (error?.status === 422) { - const code = 'unprocessable_entity' - const apiError = new OpenAI.APIError({ - status: error.status, - code, - message: `${error.status} Provider returned error` - }); - apiError.code = code; - throw apiError; + throw new OpenAI.UnprocessableEntityError(422, { code: 'unprocessable_entity' }, error.message, new Headers()); } // Re-throw service errors to be handled at the UI level From a474cd8cee137fb22df5d1476c7ec9da4555b965 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 27 Sep 2025 21:39:42 +0700 Subject: [PATCH 10/19] use generic openai error types but with specific codes --- src/lib/SessionManager.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index 110f9844..31bdff21 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -410,13 +410,13 @@ export class SessionManager { // Convert provider errors to standard OpenAI APIError with appropriate code if (error?.status === 400) { - throw new OpenAI.BadRequestError(400, { code: 'bad_request' }, error.message, new Headers()); + throw new OpenAI.APIError(400, { code: 'bad_request' }, error.message, new Headers()); } if (error?.status === 403) { - throw new OpenAI.PermissionDeniedError(403, { code: 'key_limit_exceeded' }, error.message, new Headers()); + throw new OpenAI.APIError(403, { code: 'key_limit_exceeded' }, error.message, new Headers()); } if (error?.status === 422) { - throw new OpenAI.UnprocessableEntityError(422, { code: 'unprocessable_entity' }, error.message, new Headers()); + throw new OpenAI.APIError(422, { code: 'unprocessable_entity' }, error.message, new Headers()); } // Re-throw service errors to be handled at the UI level From f8350e1d629e4c88b159c9efe331e2a904b5759d Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 28 Sep 2025 14:13:33 +0700 Subject: [PATCH 11/19] fix junk indentation --- src/components/Quilly.tsx | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index d17f63d4..445bc87a 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -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?', - actions: [{ - 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 @@ -118,17 +118,17 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'key_limit_exceeded': - return { - message: `It seems your API key has been used up. Check your API provider's settings, or try a different API key or different provider/model combo:`, - actions: [{ - label: 'Check API settings', - onClick: () => navigate('/settings/ai'), - }, { - label: 'Change model', - onClick: onOpenModelSelector, - }], - }; + case 'key_limit_exceeded': + return { + message: `It seems your API key has been used up. Check your API provider's settings, or try a different API key or different provider/model combo:`, + actions: [{ + label: 'Check API settings', + onClick: () => navigate('/settings/ai'), + }, { + label: 'Change model', + onClick: onOpenModelSelector, + }], + }; case 'bad_request': return { From 8ce69023af7014152a74299b7c33c85a8dfb7e8f Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 28 Sep 2025 14:57:34 +0700 Subject: [PATCH 12/19] functional -> imperative :| --- src/lib/SessionManager.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index 31bdff21..90d89634 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -287,7 +287,7 @@ export class SessionManager { // LiteLLM, Z.ai, etc. use 'reasoning_content' if (delta && 'reasoning_content' in delta && typeof delta.reasoning_content === 'string') { reasoningContent = delta.reasoning_content; - // ollama uses 'reasoning' + // ollama uses 'reasoning' } else if (delta && 'reasoning' in delta && typeof delta.reasoning === 'string') { reasoningContent = delta.reasoning; } @@ -410,13 +410,13 @@ export class SessionManager { // Convert provider errors to standard OpenAI APIError with appropriate code if (error?.status === 400) { - throw new OpenAI.APIError(400, { code: 'bad_request' }, error.message, new Headers()); + error.code = 'bad_request'; } if (error?.status === 403) { - throw new OpenAI.APIError(403, { code: 'key_limit_exceeded' }, error.message, new Headers()); + error.code = 'key_limit_exceeded'; } if (error?.status === 422) { - throw new OpenAI.APIError(422, { code: 'unprocessable_entity' }, error.message, new Headers()); + error.code = 'unprocessable_entity'; } // Re-throw service errors to be handled at the UI level From 77d37f071a031c86d1bd68a2bf29ba83ee54517f Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 5 Oct 2025 07:26:54 +0700 Subject: [PATCH 13/19] no error normalisation in session manager, let quilly look more closely at the open ai error to deduce what to do --- src/components/Quilly.tsx | 32 ++++++++++++++++---------------- src/lib/SessionManager.ts | 11 ----------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index d5598e23..3aa6fa67 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -44,7 +44,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq const credits = useAICredits(provider || { id: '', name: '', apiKey: '', nostr: false }); const [showCreditsDialog, setShowCreditsDialog] = useState(false); - const renderBody = (error: Error): ErrorBody => { + const renderBody = (error: Error | OpenAI.APIError | MalformedToolCallError | ProjectPreviewConsoleError): ErrorBody => { // Handle Project Preview Console Errors if (error instanceof ProjectPreviewConsoleError) { return { @@ -62,18 +62,18 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq if (error instanceof MalformedToolCallError) { return { message: 'The AI sent an incomplete response, possibly due to a network issue or provider problem. Try sending your message again, or switch to a different model if this persists.', - action: { + actions: [{ label: 'Change model', onClick: onOpenModelSelector, - }, + }], }; - } + } // Handle OpenAI API errors with specific error codes if (error instanceof OpenAI.APIError) { - switch (error.code) { - case 'invalid_api_key': - case 'invalid_request_error': + switch (true) { + case error.code ==='invalid_api_key': + case error.code === 'invalid_request_error': return { message: 'Authentication error: Please check your API key in AI settings.', actions: [{ @@ -82,7 +82,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'insufficient_quota': { + case error.code === 'insufficient_quota': { if (credits.data) { return { message: `Your account has $${credits.data.amount.toFixed(2)} credits. Please add credits to keep creating.`, @@ -102,13 +102,13 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq } } - case 'rate_limit_exceeded': + case error.code === 'rate_limit_exceeded': return { message: 'Rate limit exceeded. Please wait a moment before trying again.', actions: [], }; - case 'model_not_found': + case error.code === 'model_not_found': return { message: 'The selected AI model is not available. Please choose a different model.', actions: [{ @@ -117,7 +117,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'context_length_exceeded': + case error.code === '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.', actions: [{ @@ -129,7 +129,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'key_limit_exceeded': + case error.status === 403: return { message: `It seems your API key has been used up. Check your API provider's settings, or try a different API key or different provider/model combo:`, actions: [{ @@ -141,7 +141,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'bad_request': + case error.status === 400: 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.', actions: [{ @@ -153,7 +153,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'unprocessable_entity': + case error.status === 422: return { message: 'Request rejected by AI provider. Try a different model.', actions: [{ @@ -162,8 +162,8 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }], }; - case 'server_error': - case 'service_unavailable': + case error.code === 'server_error': + case error.code === 'service_unavailable': return { message: 'The AI service is temporarily unavailable. Please try again in a moment.', actions: [], diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index 1f99c1c7..7f9431ee 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -433,17 +433,6 @@ export class SessionManager { return; // User cancelled } - // Convert provider errors to standard OpenAI APIError with appropriate code - if (error?.status === 400) { - error.code = 'bad_request'; - } - if (error?.status === 403) { - error.code = 'key_limit_exceeded'; - } - if (error?.status === 422) { - error.code = 'unprocessable_entity'; - } - // Re-throw service errors to be handled at the UI level throw error; } finally { From 462bbb429837cbdd82d3f650e64e0a6696c9a3f6 Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 5 Oct 2025 11:15:53 +0700 Subject: [PATCH 14/19] lint fix --- src/components/Quilly.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index 3aa6fa67..04f20d15 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -1,4 +1,4 @@ -import OpenAI from 'openai'; +import { APIError } from 'openai'; import { useNavigate } from 'react-router-dom'; import { X } from 'lucide-react'; import { Button } from '@/components/ui/button'; @@ -44,7 +44,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq const credits = useAICredits(provider || { id: '', name: '', apiKey: '', nostr: false }); const [showCreditsDialog, setShowCreditsDialog] = useState(false); - const renderBody = (error: Error | OpenAI.APIError | MalformedToolCallError | ProjectPreviewConsoleError): ErrorBody => { + const renderBody = (error: Error | APIError | MalformedToolCallError | ProjectPreviewConsoleError): ErrorBody => { // Handle Project Preview Console Errors if (error instanceof ProjectPreviewConsoleError) { return { @@ -70,7 +70,7 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq } // Handle OpenAI API errors with specific error codes - if (error instanceof OpenAI.APIError) { + if (error instanceof APIError) { switch (true) { case error.code ==='invalid_api_key': case error.code === 'invalid_request_error': From ca45f62585189b7299d9812c6a9cd9174a8ef1fb Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 7 Oct 2025 20:37:10 -0500 Subject: [PATCH 15/19] ModelSelector: display warning if model isn't in providers models list --- src/components/ModelSelector.test.tsx | 159 +++++++++++++++++++++++++- src/components/ModelSelector.tsx | 30 ++++- 2 files changed, 184 insertions(+), 5 deletions(-) diff --git a/src/components/ModelSelector.test.tsx b/src/components/ModelSelector.test.tsx index 43e97dbd..880afd98 100644 --- a/src/components/ModelSelector.test.tsx +++ b/src/components/ModelSelector.test.tsx @@ -429,7 +429,7 @@ describe('ModelSelector', () => { ); - const cautionButton = screen.getByRole('button', { name: 'Free model warning' }); + const cautionButton = screen.getByRole('button', { name: 'Model warning' }); expect(cautionButton).toBeInTheDocument(); expect(cautionButton).toHaveAttribute('tabIndex', '0'); // Should be tappable on mobile @@ -472,8 +472,163 @@ describe('ModelSelector', () => { ); - const cautionButton = screen.getByRole('button', { name: 'Free model warning' }); + const cautionButton = screen.getByRole('button', { name: 'Model warning' }); expect(cautionButton).toBeInTheDocument(); expect(cautionButton).toHaveAttribute('tabIndex', '-1'); // Should not be focusable on desktop }); + + it('shows warning icon when selected model is not in provider models list', () => { + const availableModels = [ + { fullId: 'provider1/model1', provider: 'provider1', id: 'model1' }, + { fullId: 'provider1/model2', provider: 'provider1', id: 'model2' }, + ]; + + mockUseProviderModels.mockReturnValue({ + models: availableModels, + isLoading: false, + error: null, + refetch: vi.fn(), + }); + + render( + + + + ); + + // Should show warning icon for model not in list + expect(screen.getByTestId('triangle-alert')).toBeInTheDocument(); + }); + + it('does not show warning icon when selected model is in provider models list', () => { + const availableModels = [ + { fullId: 'provider1/model1', provider: 'provider1', id: 'model1' }, + { fullId: 'provider1/model2', provider: 'provider1', id: 'model2' }, + ]; + + mockUseProviderModels.mockReturnValue({ + models: availableModels, + isLoading: false, + error: null, + refetch: vi.fn(), + }); + + render( + + + + ); + + // Should not show warning icon when model is in list + expect(screen.queryByTestId('triangle-alert')).not.toBeInTheDocument(); + }); + + it('does not show warning icon while models are loading', () => { + mockUseProviderModels.mockReturnValue({ + models: [], + isLoading: true, + error: null, + refetch: vi.fn(), + }); + + render( + + + + ); + + // Should not show warning icon while loading + expect(screen.queryByTestId('triangle-alert')).not.toBeInTheDocument(); + }); + + it('does not show warning icon when no models are loaded', () => { + mockUseProviderModels.mockReturnValue({ + models: [], + isLoading: false, + error: null, + refetch: vi.fn(), + }); + + render( + + + + ); + + // Should not show warning icon when no models loaded + expect(screen.queryByTestId('triangle-alert')).not.toBeInTheDocument(); + }); + + it('shows correct tooltip message for model not in list', async () => { + const user = userEvent.setup(); + + const availableModels = [ + { fullId: 'provider1/model1', provider: 'provider1', id: 'model1' }, + ]; + + mockUseProviderModels.mockReturnValue({ + models: availableModels, + isLoading: false, + error: null, + refetch: vi.fn(), + }); + + render( + + + + ); + + const warningIcon = screen.getByTestId('triangle-alert'); + expect(warningIcon).toBeInTheDocument(); + + // Hover over the warning icon + await user.hover(warningIcon); + + // Wait for tooltip to appear + await waitFor(() => { + expect(screen.getAllByText("This model is not available in your provider's model list. It may not work or may have been deprecated.").length).toBeGreaterThan(0); + }); + }); + + it('prioritizes "not in list" warning over "free model" warning in tooltip', async () => { + const user = userEvent.setup(); + + const freeModel = { + fullId: 'provider1/free-model', + provider: 'provider1', + id: 'free-model', + pricing: { + prompt: new Decimal('0'), + completion: new Decimal('0'), + }, + }; + + mockUseProviderModels.mockReturnValue({ + models: [freeModel], + isLoading: false, + error: null, + refetch: vi.fn(), + }); + + render( + + + + ); + + const warningIcon = screen.getByTestId('triangle-alert'); + expect(warningIcon).toBeInTheDocument(); + + // Hover over the warning icon + await user.hover(warningIcon); + + // Wait for tooltip to appear - should show "not in list" message, not "free model" message + await waitFor(() => { + expect(screen.getAllByText("This model is not available in your provider's model list. It may not work or may have been deprecated.").length).toBeGreaterThan(0); + }); + + // Should not show the free model message + expect(screen.queryByText('You are using a free model. For better results, switch to a paid model.')).not.toBeInTheDocument(); + }); }); \ No newline at end of file diff --git a/src/components/ModelSelector.tsx b/src/components/ModelSelector.tsx index ad2eb95d..3e992d01 100644 --- a/src/components/ModelSelector.tsx +++ b/src/components/ModelSelector.tsx @@ -104,6 +104,30 @@ export function ModelSelector({ return currentModel.pricing.prompt.equals(0) && currentModel.pricing.completion.equals(0); }, [value, models]); + // Check if the current model is not in the provider's model list + const isCurrentModelNotInList = useMemo(() => { + if (!value) return false; + if (isLoading) return false; // Don't show warning while loading + if (models.length === 0) return false; // Don't show warning if no models loaded + + const currentModel = models.find(model => model.fullId === value); + return !currentModel; + }, [value, models, isLoading]); + + // Determine if we should show the warning icon + const shouldShowWarning = isCurrentModelFree || isCurrentModelNotInList; + + // Get the warning message + const warningMessage = useMemo(() => { + if (isCurrentModelNotInList) { + return "This model is not available in your provider's model list. It may not work or may have been deprecated."; + } + if (isCurrentModelFree) { + return "You are using a free model. For better results, switch to a paid model."; + } + return ""; + }, [isCurrentModelNotInList, isCurrentModelFree]); + // Don't auto-initialize with recently used models // Let the parent component handle initialization @@ -198,7 +222,7 @@ export function ModelSelector({ return (
- {isCurrentModelFree && ( + {shouldShowWarning && ( { e.preventDefault(); @@ -242,7 +266,7 @@ export function ModelSelector({ avoidCollisions={true} collisionPadding={8} > -

You are using a free model. For better results, switch to a paid model.

+

{warningMessage}

)} From 496ab8722a212f6986a650ce8d6a2ae8c8182b7b Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 7 Oct 2025 21:13:04 -0500 Subject: [PATCH 16/19] Throw an error if the AI service return an empty assistant message --- src/components/AIMessageItem.tsx | 9 +- src/components/Quilly.tsx | 20 +++- src/components/Shakespeare/ChatPane.tsx | 1 + src/lib/SessionManager.ts | 16 +++ src/lib/errors/EmptyMessageError.ts | 13 +++ src/lib/isEmptyMessage.test.ts | 141 ++++++++++++++++++++++++ src/lib/isEmptyMessage.ts | 52 +++++++++ 7 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 src/lib/errors/EmptyMessageError.ts create mode 100644 src/lib/isEmptyMessage.test.ts create mode 100644 src/lib/isEmptyMessage.ts diff --git a/src/components/AIMessageItem.tsx b/src/components/AIMessageItem.tsx index 952addbb..60f81b80 100644 --- a/src/components/AIMessageItem.tsx +++ b/src/components/AIMessageItem.tsx @@ -6,6 +6,7 @@ import { cn } from '@/lib/utils'; import { UserMessage } from '@/components/UserMessage'; import OpenAI from 'openai'; import { useTheme } from '@/hooks/useTheme'; +import { isEmptyMessage } from '@/lib/isEmptyMessage'; // Type guard to check if message has reasoning content function hasReasoningContent(message: AIMessage): message is AIMessage & { reasoning_content: string } { @@ -299,8 +300,12 @@ export const AIMessageItem = memo(({ ); } - // If there's no reasoning content and the main content is empty, render nothing - if (!hasReasoningContent(message) && !getContent().trim()) { + if (message.role !== 'assistant') { + return null; // Only render assistant and user messages + } + + // If the message is empty (no content or reasoning), render nothing + if (isEmptyMessage({ ...message, tool_calls: [] })) { return null; } diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index a951d6ef..bc1d353c 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -10,12 +10,14 @@ import { CreditsDialog } from './CreditsDialog'; import { ProjectPreviewConsoleError } from '@/lib/consoleMessages'; import { useState } from 'react'; import { MalformedToolCallError } from '@/lib/errors/MalformedToolCallError'; +import { EmptyMessageError } from '@/lib/errors/EmptyMessageError'; export interface QuillyProps { error: Error; onDismiss: () => void; onNewChat: () => void; onOpenModelSelector: () => void; + onTryAgain?: () => void; onRequestConsoleErrorHelp?: (error: ProjectPreviewConsoleError) => void; providerModel: string; } @@ -28,7 +30,7 @@ interface ErrorBody { }; } -export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onRequestConsoleErrorHelp, providerModel }: QuillyProps) { +export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onTryAgain, onRequestConsoleErrorHelp, providerModel }: QuillyProps) { const navigate = useNavigate(); const { settings } = useAISettings(); @@ -69,6 +71,22 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onReq }; } + if (error instanceof EmptyMessageError) { + return { + message: 'The AI generated an empty response. This may be due to a provider issue or model configuration problem. Try generating again, or switch to a different model.', + action: onTryAgain ? { + label: 'Try again', + onClick: () => { + onTryAgain(); + onDismiss(); + }, + } : { + label: 'Change model', + onClick: onOpenModelSelector, + }, + }; + } + // Handle OpenAI API errors with specific error codes if (error instanceof OpenAI.APIError) { switch (error.code) { diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 78021f31..6d08e63f 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -649,6 +649,7 @@ export const ChatPane = forwardRef(({ onDismiss={handleErrorDismiss} onNewChat={onNewChat} onOpenModelSelector={openModelSelector} + onTryAgain={() => startGeneration(providerModel)} onRequestConsoleErrorHelp={handleConsoleErrorHelp} providerModel={providerModel} /> diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index 7f9431ee..dfa7740b 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -9,6 +9,8 @@ import type { AIProvider } from '@/contexts/AISettingsContext'; import { makeSystemPrompt } from './system'; import { NostrMetadata } from '@nostrify/nostrify'; import { MalformedToolCallError } from './errors/MalformedToolCallError'; +import { EmptyMessageError } from './errors/EmptyMessageError'; +import { isEmptyMessage } from './isEmptyMessage'; export type AIMessage = OpenAI.Chat.Completions.ChatCompletionMessageParam | { role: 'assistant'; @@ -362,6 +364,20 @@ export class SessionManager { ...(accumulatedToolCalls.length > 0 && { tool_calls: accumulatedToolCalls }) }; + // Check if the assistant message is empty (no content, reasoning, or tool calls) + if (isEmptyMessage(assistantMessage)) { + console.error('Empty assistant message detected', { + projectId, + providerModel, + finishReason, + }); + + throw new EmptyMessageError( + 'The AI generated an empty response. This may be due to a provider issue or model configuration problem.', + providerModel, + ); + } + // Add final message but keep streaming message until finally block await this.addMessage(projectId, assistantMessage); diff --git a/src/lib/errors/EmptyMessageError.ts b/src/lib/errors/EmptyMessageError.ts new file mode 100644 index 00000000..4c9202dd --- /dev/null +++ b/src/lib/errors/EmptyMessageError.ts @@ -0,0 +1,13 @@ +/** + * Error thrown when the AI generates an empty message with no content, reasoning, or tool calls. + * This typically indicates an issue with the AI provider or model configuration. + */ +export class EmptyMessageError extends Error { + constructor( + message: string, + public readonly providerModel: string, + ) { + super(message); + this.name = 'EmptyMessageError'; + } +} diff --git a/src/lib/isEmptyMessage.test.ts b/src/lib/isEmptyMessage.test.ts new file mode 100644 index 00000000..69e04e3a --- /dev/null +++ b/src/lib/isEmptyMessage.test.ts @@ -0,0 +1,141 @@ +import { describe, it, expect } from 'vitest'; +import { isEmptyMessage } from './isEmptyMessage'; +import type { AIMessage } from './SessionManager'; + +describe('isEmptyMessage', () => { + it('returns false for user messages', () => { + const message: AIMessage = { + role: 'user', + content: 'Hello', + }; + + expect(isEmptyMessage(message)).toBe(false); + }); + + it('returns false for tool messages', () => { + const message: AIMessage = { + role: 'tool', + content: 'Tool result', + tool_call_id: 'call_123', + }; + + expect(isEmptyMessage(message)).toBe(false); + }); + + it('returns true for assistant message with no content, reasoning, or tool calls', () => { + const message: AIMessage = { + role: 'assistant', + content: '', + }; + + expect(isEmptyMessage(message)).toBe(true); + }); + + it('returns true for assistant message with only whitespace content', () => { + const message: AIMessage = { + role: 'assistant', + content: ' \n\t ', + }; + + expect(isEmptyMessage(message)).toBe(true); + }); + + it('returns false for assistant message with content', () => { + const message: AIMessage = { + role: 'assistant', + content: 'Hello, how can I help?', + }; + + expect(isEmptyMessage(message)).toBe(false); + }); + + it('returns false for assistant message with reasoning content', () => { + const message: AIMessage = { + role: 'assistant', + content: '', + reasoning_content: 'Let me think about this...', + }; + + expect(isEmptyMessage(message)).toBe(false); + }); + + it('returns false for assistant message with tool calls', () => { + const message: AIMessage = { + role: 'assistant', + content: '', + tool_calls: [ + { + id: 'call_123', + type: 'function', + function: { + name: 'text_editor_view', + arguments: '{"path": "test.txt"}', + }, + }, + ], + }; + + expect(isEmptyMessage(message)).toBe(false); + }); + + it('returns false for assistant message with array content', () => { + const message: AIMessage = { + role: 'assistant', + content: [ + { + type: 'text', + text: 'Hello', + }, + ], + }; + + expect(isEmptyMessage(message)).toBe(false); + }); + + it('returns true for assistant message with empty array content', () => { + const message: AIMessage = { + role: 'assistant', + content: [], + }; + + expect(isEmptyMessage(message)).toBe(true); + }); + + it('returns true for assistant message with array content containing only whitespace', () => { + const message: AIMessage = { + role: 'assistant', + content: [ + { + type: 'text', + text: ' ', + }, + { + type: 'text', + text: '\n\t', + }, + ], + }; + + expect(isEmptyMessage(message)).toBe(true); + }); + + it('returns false for assistant message with content and reasoning', () => { + const message: AIMessage = { + role: 'assistant', + content: 'Here is the answer', + reasoning_content: 'I thought about this carefully', + }; + + expect(isEmptyMessage(message)).toBe(false); + }); + + it('returns true for assistant message with empty reasoning and no content', () => { + const message: AIMessage = { + role: 'assistant', + content: '', + reasoning_content: ' ', + }; + + expect(isEmptyMessage(message)).toBe(true); + }); +}); diff --git a/src/lib/isEmptyMessage.ts b/src/lib/isEmptyMessage.ts new file mode 100644 index 00000000..b2411160 --- /dev/null +++ b/src/lib/isEmptyMessage.ts @@ -0,0 +1,52 @@ +import type { AIMessage } from './SessionManager'; + +/** + * Type guard to check if message has reasoning content + */ +function hasReasoningContent(message: AIMessage): message is AIMessage & { reasoning_content: string } { + return ( + message.role === 'assistant' && + 'reasoning_content' in message && + typeof (message as { reasoning_content?: unknown }).reasoning_content === 'string' + ); +} + +/** + * Get the text content from a message, handling both string and array formats + */ +function getMessageContent(message: AIMessage): string { + if (typeof message.content === 'string') { + return message.content; + } + if (Array.isArray(message.content)) { + return message.content + .map(item => { + if (typeof item === 'string') return item; + if (item.type === 'text') return item.text; + return ''; + }) + .join('\n'); + } + return ''; +} + +/** + * Check if an assistant message is considered "empty" + * A message is empty if: + * - Its trimmed text content is empty + * - Its reasoning content (if present) is empty + * - It has no tool calls + */ +export function isEmptyMessage(message: AIMessage): boolean { + // Only check assistant messages + if (message.role !== 'assistant') { + return false; + } + + const content = getMessageContent(message).trim(); + const reasoningContent = hasReasoningContent(message) ? message.reasoning_content.trim() : ''; + const hasToolCalls = message.tool_calls && message.tool_calls.length > 0; + + // Message is empty if there's no content, no reasoning, and no tool calls + return !content && !reasoningContent && !hasToolCalls; +} From 104d95d5abfa09fb398baf89eb8f5b145b897d31 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 7 Oct 2025 21:15:20 -0500 Subject: [PATCH 17/19] Filter out empty assistant messages when saving the history file --- src/lib/DotAI.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/DotAI.ts b/src/lib/DotAI.ts index 56864b77..20b246fc 100644 --- a/src/lib/DotAI.ts +++ b/src/lib/DotAI.ts @@ -1,6 +1,7 @@ import { join } from "path-browserify"; import type OpenAI from "openai"; import type { JSRuntimeFS } from "./JSRuntime"; +import { isEmptyMessage } from "./isEmptyMessage"; /** AI message history manager and .git/ai directory utilities */ export class DotAI { @@ -46,6 +47,9 @@ export class DotAI { sessionName: string, messages: OpenAI.Chat.Completions.ChatCompletionMessageParam[], ): Promise { + // Filter out empty assistant messages + messages = messages.filter((msg) => !isEmptyMessage(msg)); + // Validate messages before saving this.validateMessages(messages); From a4228adf749001fedf7a4d7cab178eb1a5ab6412 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 7 Oct 2025 21:27:15 -0500 Subject: [PATCH 18/19] Simplify Act1Dialog --- src/components/Act1Dialog.tsx | 75 +++++++---------------------------- 1 file changed, 14 insertions(+), 61 deletions(-) diff --git a/src/components/Act1Dialog.tsx b/src/components/Act1Dialog.tsx index e31611b7..360028f6 100644 --- a/src/components/Act1Dialog.tsx +++ b/src/components/Act1Dialog.tsx @@ -4,10 +4,8 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/u import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; - -// import { useAISettings } from '@/hooks/useAISettings'; import { useAICredits } from '@/hooks/useAICredits'; -// import { useLocalStorage } from '@/hooks/useLocalStorage'; +import { getShakespeareProvider } from '@/lib/aiProviderPresets'; interface Act1DialogProps { open: boolean; @@ -16,42 +14,12 @@ interface Act1DialogProps { type DialogStep = 'welcome' | 'migration' | 'credits' | 'conclusion'; -const SHAKESPEARE_PROVIDER = { - id: "shakespeare", - baseURL: "https://ai.shakespeare.diy/v1", - nostr: true, -}; - -// const MKSTACK_NSP_ADDR = '31999:4bcaa7b5606e3c14df05cd497e588f5d3fe559b4e9a425e8b418a43af1ffb015:mkstack'; - export function Act1Dialog({ open, onOpenChange }: Act1DialogProps) { const [step, setStep] = useState('welcome'); - // const { setProvider, updateSettings } = useAISettings(); - - // // Get the selectedNSPAddr from localStorage - // const [selectedNSPAddr] = useLocalStorage('selectedNSPAddr', null); - - // Get user's credits - const { data: creditsData } = useAICredits(SHAKESPEARE_PROVIDER); + const { data: creditsData } = useAICredits(getShakespeareProvider()); const handleGetStarted = async () => { try { - // // Add Shakespeare provider to their config - // setProvider(SHAKESPEARE_PROVIDER); - - // // Configure recently used models based on credits or NSP - // const hasCredits = creditsData?.amount && creditsData.amount > 0; - // const hasMKStackNSP = selectedNSPAddr === MKSTACK_NSP_ADDR; - - // if (hasCredits || hasMKStackNSP) { - // // User has credits or MKStack NSP - set to shakespeare model - // updateSettings({ recentlyUsedModels: ['shakespeare/shakespeare'] }); - // } else { - // // No credits - set to tybalt model (free) - // updateSettings({ recentlyUsedModels: ['shakespeare/tybalt'] }); - // } - - // Move to migration step setStep('migration'); } catch (error) { console.error('Failed to configure Shakespeare provider:', error); @@ -269,36 +237,21 @@ export function Act1Dialog({ open, onOpenChange }: Act1DialogProps) { - {creditsData?.amount && creditsData.amount > 0 ? ( -
-
-
- ${creditsData.amount.toFixed(2)} -
-

- Available credits -

-
-
-

- ✅ You're all set! We've configured the premium Shakespeare model for you. -

+
+
+
+ ${(creditsData?.amount ?? 0).toFixed(2)}
+

+ Available credits +

- ) : ( -
-
-
🆓
-

Free Access

-
-
-

- You can continue using Shakespeare for free with the Tybalt model. - It's perfect for learning and building amazing projects! -

-
+
+

+ ✅ You're all set! We've configured the premium Shakespeare model for you. +

- )} +
From bda50285af4e5f8352b5a070b7929718da190ba0 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 7 Oct 2025 21:31:50 -0500 Subject: [PATCH 19/19] Fix Quilly --- src/components/Quilly.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index eaaafc43..88ca308c 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -74,16 +74,16 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onTry if (error instanceof EmptyMessageError) { return { message: 'The AI generated an empty response. This may be due to a provider issue or model configuration problem. Try generating again, or switch to a different model.', - action: onTryAgain ? { + actions: onTryAgain ? [{ label: 'Try again', onClick: () => { onTryAgain(); onDismiss(); }, - } : { + }] : [{ label: 'Change model', onClick: onOpenModelSelector, - }, + }], }; }