diff --git a/src/components/Quilly.test.tsx b/src/components/Quilly.test.tsx
index 6e50e06c..e3657f19 100644
--- a/src/components/Quilly.test.tsx
+++ b/src/components/Quilly.test.tsx
@@ -35,27 +35,44 @@ describe('Quilly', () => {
expect(onDismiss).toHaveBeenCalledTimes(1);
});
- it('renders action button when provided', () => {
- const error = new Error('Test error');
+ it('renders action button for console errors', () => {
+ const error = new Error('Console errors detected in your app. Would you like me to help fix them?');
const onDismiss = vi.fn();
- const actionOnClick = vi.fn();
+ const onFixConsoleErrors = vi.fn();
render(
);
- const actionButton = screen.getByRole('button', { name: 'Fix it' });
+ const actionButton = screen.getByRole('button', { name: 'Fix errors' });
expect(actionButton).toBeInTheDocument();
fireEvent.click(actionButton);
- expect(actionOnClick).toHaveBeenCalledTimes(1);
+ expect(onFixConsoleErrors).toHaveBeenCalledTimes(1);
+ });
+
+ it('renders action button for model not found errors', () => {
+ const error = new Error('model_not_found: The specified model does not exist');
+ const onDismiss = vi.fn();
+ const onOpenModelSelector = vi.fn();
+
+ render(
+
+ );
+
+ const actionButton = screen.getByRole('button', { name: 'Choose model' });
+ expect(actionButton).toBeInTheDocument();
+
+ fireEvent.click(actionButton);
+ expect(onOpenModelSelector).toHaveBeenCalledTimes(1);
});
it('formats network error messages correctly', () => {
diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx
index d8a08d44..b335d00c 100644
--- a/src/components/Quilly.tsx
+++ b/src/components/Quilly.tsx
@@ -5,10 +5,12 @@ import { X } from 'lucide-react';
export interface QuillyProps {
error: Error;
onDismiss: () => void;
- action?: { label: string; onClick: () => void };
+ onNewChat?: () => void;
+ onOpenModelSelector?: () => void;
+ onFixConsoleErrors?: () => void;
}
-export function Quilly({ error, onDismiss, action }: QuillyProps) {
+export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onFixConsoleErrors }: QuillyProps) {
// Generate user-friendly message from error
const getMessage = (error: Error): string => {
const errorMsg = error.message || '';
@@ -36,7 +38,62 @@ export function Quilly({ error, onDismiss, action }: QuillyProps) {
}
};
+ // Determine action based on error
+ const getAction = (error: Error): { label: string; onClick: () => void } | undefined => {
+ const errorMsg = error.message || '';
+
+ // Check for console error messages first
+ if (errorMsg.includes('Console') && errorMsg.includes('detected in your app') && onFixConsoleErrors) {
+ const isPlural = errorMsg.includes('errors detected');
+ return {
+ label: `Fix ${isPlural ? 'errors' : 'error'}`,
+ onClick: onFixConsoleErrors
+ };
+ }
+
+ if (error.name === 'TypeError' && errorMsg.includes('fetch')) {
+ return {
+ label: 'Check AI settings',
+ onClick: () => {
+ window.location.href = '/settings/ai';
+ }
+ };
+ } else if (errorMsg.includes('API key')) {
+ return {
+ label: 'Check API key',
+ onClick: () => {
+ window.location.href = '/settings/ai';
+ }
+ };
+ } else if (errorMsg.includes('insufficient_quota')) {
+ return {
+ label: 'Check AI settings',
+ onClick: () => {
+ window.location.href = '/settings/ai';
+ }
+ };
+ } else if (errorMsg.includes('model_not_found') || errorMsg.includes('does not exist')) {
+ return onOpenModelSelector ? {
+ label: 'Choose model',
+ onClick: onOpenModelSelector
+ } : undefined;
+ } else if (errorMsg.includes('maximum context length') || errorMsg.includes('context length')) {
+ return onNewChat ? {
+ label: 'New chat',
+ onClick: onNewChat
+ } : undefined;
+ } else if (errorMsg.includes('422') || errorMsg.includes('Provider returned error')) {
+ return onOpenModelSelector ? {
+ label: 'Change model',
+ onClick: onOpenModelSelector
+ } : undefined;
+ }
+
+ return undefined;
+ };
+
const message = getMessage(error);
+ const action = getAction(error);
return (
diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx
index 38ef71ba..ee22914e 100644
--- a/src/components/Shakespeare/ChatPane.tsx
+++ b/src/components/Shakespeare/ChatPane.tsx
@@ -47,7 +47,6 @@ import { Quilly } from '@/components/Quilly';
interface ChatPaneProps {
projectId: string;
onNewChat?: () => void;
- onBuild?: () => void;
onFirstInteraction?: () => void;
onLoadingChange?: (isLoading: boolean) => void;
isLoading?: boolean;
@@ -60,8 +59,7 @@ export interface ChatPaneRef {
export const ChatPane = forwardRef(({
projectId,
- onNewChat: _onNewChat,
- onBuild: _onBuild,
+ onNewChat,
onFirstInteraction,
onLoadingChange,
isLoading: externalIsLoading,
@@ -240,71 +238,14 @@ export const ChatPane = forwardRef(({
// Clean alert hooks with proper interfaces
const consoleAlert = useConsoleErrorAlert(messages, isBuildLoading, internalIsLoading);
- // Create AI error alert object
- const aiErrorAlert = useMemo(() => {
- if (!aiError) {
- return { hasError: false, dismiss: () => {}, action: undefined };
- }
-
- let action: { label: string; onClick: () => void } | undefined;
-
- const errorMsg = aiError.message || '';
-
- if (aiError.name === 'TypeError' && errorMsg.includes('fetch')) {
- action = {
- label: 'Check AI settings',
- onClick: () => {
- // Navigate to AI settings
- window.location.href = '/settings/ai';
- }
- };
- } else if (errorMsg.includes('API key')) {
- action = {
- label: 'Check API key',
- onClick: () => {
- // Navigate to AI settings
- window.location.href = '/settings/ai';
- }
- };
- } else if (errorMsg.includes('insufficient_quota')) {
- action = {
- label: 'Check AI settings',
- onClick: () => {
- window.location.href = '/settings/ai';
- }
- };
- } else if (errorMsg.includes('model_not_found') || errorMsg.includes('does not exist')) {
- action = {
- label: 'Choose model',
- onClick: openModelSelector
- };
- } else if (errorMsg.includes('maximum context length') || errorMsg.includes('context length')) {
- action = _onNewChat ? {
- label: 'New chat',
- onClick: _onNewChat
- } : undefined;
- } else if (errorMsg.includes('422') || errorMsg.includes('Provider returned error')) {
- action = openModelSelector ? {
- label: 'Change model',
- onClick: openModelSelector
- } : undefined;
- }
-
- return {
- hasError: true,
- dismiss: () => setAIError(null),
- action
- };
- }, [aiError, openModelSelector, _onNewChat]);
-
// Scroll to bottom when alerts appear
useEffect(() => {
- if (consoleAlert.hasError || aiErrorAlert.hasError) {
+ if (consoleAlert.hasError || aiError) {
setTimeout(() => {
scrollToBottom();
}, 50);
}
- }, [consoleAlert.hasError, aiErrorAlert.hasError, scrollToBottom]);
+ }, [consoleAlert.hasError, aiError, scrollToBottom]);
// Check for autostart parameter and trigger AI generation
useEffect(() => {
@@ -664,19 +605,17 @@ export const ChatPane = forwardRef(({
suggestErrorFix(consoleAlert.errorSummary || '')
- }}
+ onFixConsoleErrors={() => suggestErrorFix(consoleAlert.errorSummary || '')}
/>
)}
{/* AI Error Alert */}
- {aiErrorAlert.hasError && (
+ {aiError && (
setAIError(null)}
+ onNewChat={onNewChat}
+ onOpenModelSelector={openModelSelector}
/>
)}
diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx
index c4cdef53..5fe49405 100644
--- a/src/pages/ProjectView.tsx
+++ b/src/pages/ProjectView.tsx
@@ -14,7 +14,6 @@ import { ArrowLeft, MessageSquare, Eye, Code, Menu } from 'lucide-react';
import { useNavigate } from 'react-router-dom';
import { ActionsMenu } from '@/components/ActionsMenu';
import { useIsMobile } from '@/hooks/useIsMobile';
-import { useKeepAlive } from '@/hooks/useKeepAlive';
import { GitStatusIndicator } from '@/components/GitStatusIndicator';
import { StarButton } from '@/components/StarButton';
@@ -40,20 +39,6 @@ export function ProjectView() {
const build = useBuildProject(projectId!);
const { data: isPreviewable = false } = useIsProjectPreviewable(projectId!);
- // Keep-alive functionality to prevent tab throttling during AI processing
- const { updateMetadata } = useKeepAlive({
- enabled: isAILoading || build.isPending,
- title: 'Shakespeare',
- artist: project ? `Working on ${project.name}...` : 'Working...',
- artwork: [
- {
- src: '/favicon.png',
- sizes: '512x512',
- type: 'image/png'
- }
- ]
- });
-
const loadProject = useCallback(async () => {
if (!projectId) return;
@@ -91,20 +76,6 @@ export function ProjectView() {
}
}, [isPreviewable, mobileView, activeTab]);
- const runBuild = async () => {
- if (build.isPending || !project) return;
- updateMetadata('Shakespeare', `Building ${project.name}...`);
-
- await build.mutateAsync(undefined, {
- onSuccess(result) {
- console.log('Project built:', result);
- },
- onError(error) {
- console.error('Build failed:', error);
- },
- });
- };
-
const handleNewChat = () => {
// Reset to chat view on mobile when starting new chat
if (isMobile) {
@@ -234,7 +205,6 @@ export function ProjectView() {
ref={chatPaneRef}
projectId={project.id}
onNewChat={handleNewChat}
- onBuild={runBuild}
onFirstInteraction={handleFirstInteraction}
onLoadingChange={handleAILoadingChange}
isLoading={isAILoading}
@@ -414,7 +384,6 @@ export function ProjectView() {
ref={chatPaneRef}
projectId={project.id}
onNewChat={handleNewChat}
- onBuild={runBuild}
onFirstInteraction={handleFirstInteraction}
onLoadingChange={handleAILoadingChange}
isLoading={isAILoading}