From ec5d84d3f71382b783b87d298c4235d9c5dc4674 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 24 Sep 2025 21:23:31 -0500 Subject: [PATCH] Disconnect Quilly from console errors temporarily --- src/components/Quilly.tsx | 15 +- src/components/Shakespeare/ChatPane.test.tsx | 313 ------------------- src/components/Shakespeare/ChatPane.tsx | 30 +- src/hooks/useErrorDetection.ts | 72 ----- 4 files changed, 2 insertions(+), 428 deletions(-) delete mode 100644 src/components/Shakespeare/ChatPane.test.tsx delete mode 100644 src/hooks/useErrorDetection.ts diff --git a/src/components/Quilly.tsx b/src/components/Quilly.tsx index 71d0ad22..5ca08602 100644 --- a/src/components/Quilly.tsx +++ b/src/components/Quilly.tsx @@ -9,7 +9,6 @@ export interface QuillyProps { onDismiss: () => void; onNewChat: () => void; onOpenModelSelector: () => void; - onFixConsoleErrors: () => void; } interface ErrorBody { @@ -20,7 +19,7 @@ interface ErrorBody { }; } -export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onFixConsoleErrors }: QuillyProps) { +export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector }: QuillyProps) { const navigate = useNavigate(); const renderBody = (error: Error): ErrorBody => { @@ -82,18 +81,6 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onFix } } - // Handle console error messages - if (error.message.includes('Console') && error.message.includes('detected in your app') && onFixConsoleErrors) { - const isPlural = error.message.includes('errors detected'); - return { - message: error.message, - action: { - label: `Fix ${isPlural ? 'errors' : 'error'}`, - onClick: onFixConsoleErrors, - } - }; - } - // Default fallback return { message: error.message diff --git a/src/components/Shakespeare/ChatPane.test.tsx b/src/components/Shakespeare/ChatPane.test.tsx deleted file mode 100644 index 2345596b..00000000 --- a/src/components/Shakespeare/ChatPane.test.tsx +++ /dev/null @@ -1,313 +0,0 @@ -import { describe, it, expect, vi } from 'vitest'; -import { render, screen, fireEvent, act } from '@testing-library/react'; -import { TestApp } from '@/test/TestApp'; -import { ChatPane } from './ChatPane'; - -// Mock the AI settings hook to return configured state -vi.mock('@/hooks/useAISettings', () => ({ - useAISettings: () => ({ - isConfigured: true, - settings: { - providers: [], - recentlyUsedModels: ['gpt-4'], - }, - setProvider: vi.fn(), - removeProvider: vi.fn(), - setProviders: vi.fn(), - - addRecentlyUsedModel: vi.fn(), - updateSettings: vi.fn(), - }), -})); - -// Mock other hooks -vi.mock('@/hooks/useFS', () => ({ - useFS: () => ({ - fs: {}, - }), -})); - -vi.mock('@/hooks/useCurrentUser', () => ({ - useCurrentUser: () => ({ - user: null, - metadata: null, - }), -})); - -vi.mock('@/hooks/useKeepAlive', () => ({ - useKeepAlive: () => ({ - updateMetadata: vi.fn(), - }), -})); - -vi.mock('@/hooks/useAIChat', () => ({ - useAIChat: () => ({ - messages: [], - streamingMessage: null, - isLoading: false, - totalCost: 0, - lastInputTokens: 0, - sendMessage: vi.fn(), - startGeneration: vi.fn(), - stopGeneration: vi.fn(), - startNewSession: vi.fn(), - }), -})); - -vi.mock('@/hooks/useProviderModels', () => ({ - useProviderModels: () => ({ - models: [ - { - fullId: 'gpt-4', - contextLength: 8192, - }, - ], - }), -})); - -vi.mock('@/hooks/useToast', () => ({ - useToast: () => ({ - toast: vi.fn(), - }), -})); - -describe('ChatPane', () => { - describe('Placeholder switching', () => { - it('shows "Please select a model" placeholder when providerModel is empty', () => { - // Create a test that doesn't require modifying mocks - // Instead, we'll test the existing behavior which shows the placeholder when configured - render( - - - - ); - - const textarea = screen.getByPlaceholderText(/Ask me to add features/); - expect(textarea).toBeInTheDocument(); - }); - - it('shows "Ask me to add features" placeholder when providerModel is set', () => { - render( - - - - ); - - const textarea = screen.getByPlaceholderText(/Ask me to add features/); - expect(textarea).toBeInTheDocument(); - }); - }); - - describe('Drag and drop functionality', () => { - it('handles dropping a single valid file', () => { - render( - - - - ); - - const chatContainer = screen.getByPlaceholderText(/Ask me to add features/).closest('div')?.parentElement; - expect(chatContainer).toBeInTheDocument(); - - const validFile = new File(['test content'], 'test.txt', { type: 'text/plain' }); - - // Simulate drag and drop events - act(() => { - if (chatContainer) { - fireEvent.dragEnter(chatContainer, { - dataTransfer: { files: [] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - - fireEvent.dragOver(chatContainer, { - dataTransfer: { files: [validFile] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - - fireEvent.drop(chatContainer, { - dataTransfer: { files: [validFile] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - } - }); - - // Verify the drop was handled (no errors thrown) - expect(chatContainer).toBeInTheDocument(); - }); - - it('handles dropping multiple valid files', () => { - render( - - - - ); - - const chatContainer = screen.getByPlaceholderText(/Ask me to add features/).closest('div')?.parentElement; - expect(chatContainer).toBeInTheDocument(); - - const files = [ - new File(['content1'], 'file1.txt', { type: 'text/plain' }), - new File(['content2'], 'file2.txt', { type: 'text/plain' }), - ]; - - // Simulate drag and drop events - act(() => { - if (chatContainer) { - fireEvent.dragEnter(chatContainer, { - dataTransfer: { files: [] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - - fireEvent.dragOver(chatContainer, { - dataTransfer: { files }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - - fireEvent.drop(chatContainer, { - dataTransfer: { files }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - } - }); - - // Verify the drop was handled (no errors thrown) - expect(chatContainer).toBeInTheDocument(); - }); - - it('handles dropping an unsupported file type', () => { - // Test that the drop handler exists and doesn't throw errors - render( - - - - ); - - const chatContainer = screen.getByPlaceholderText(/Ask me to add features/).closest('div')?.parentElement; - expect(chatContainer).toBeInTheDocument(); - - const unsupportedFile = new File(['malicious content'], 'virus.exe', { type: 'application/x-executable' }); - - // Simulate drag and drop events - should not throw errors - act(() => { - if (chatContainer) { - fireEvent.dragEnter(chatContainer, { - dataTransfer: { files: [] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - - fireEvent.dragOver(chatContainer, { - dataTransfer: { files: [unsupportedFile] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - - fireEvent.drop(chatContainer, { - dataTransfer: { files: [unsupportedFile] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - } - }); - - // Test passes if no errors are thrown during drop - expect(chatContainer).toBeInTheDocument(); - }); - - it('adds visual drag-over state during drag operations', () => { - render( - - - - ); - - const chatContainer = screen.getByPlaceholderText(/Ask me to add features/).closest('div')?.parentElement; - expect(chatContainer).toBeInTheDocument(); - - const _file = new File(['test content'], 'test.txt', { type: 'text/plain' }); - - // Simulate drag enter - should not throw errors - act(() => { - if (chatContainer) { - fireEvent.dragEnter(chatContainer, { - dataTransfer: { files: [] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - }); - } - }); - - // Test passes if no errors are thrown during drag operations - expect(chatContainer).toBeInTheDocument(); - - // Simulate drag leave - act(() => { - if (chatContainer) { - fireEvent.dragLeave(chatContainer, { - dataTransfer: { files: [] }, - preventDefault: vi.fn(), - stopPropagation: vi.fn(), - relatedTarget: null, // Simulate leaving the container - }); - } - }); - - // Test passes if no errors are thrown during drag operations - expect(chatContainer).toBeInTheDocument(); - }); - }); - - it('handles image paste from clipboard', async () => { - render( - - - - ); - - const textarea = screen.getByPlaceholderText(/Ask me to add features/); - expect(textarea).toBeInTheDocument(); - - // Create a mock image file - const imageFile = new File(['fake-image-data'], 'test.png', { - type: 'image/png', - }); - - // Create mock clipboard data - const mockClipboardItem = { - type: 'image/png', - getAsFile: () => imageFile, - } as DataTransferItem; - - const mockClipboardData = { - items: [mockClipboardItem], - length: 1, - } as unknown as DataTransfer; - - // Fire the paste event on the textarea using fireEvent - fireEvent.paste(textarea, { - clipboardData: mockClipboardData, - }); - - // The file should be added to the attached files - // We can't easily test the internal state, but we can verify the event was handled - // without throwing an error - expect(textarea).toBeInTheDocument(); - }); - - it('renders welcome message when no messages exist', () => { - render( - - - - ); - - expect(screen.getByText('Welcome to Shakespeare')).toBeInTheDocument(); - expect(screen.getByText(/Your AI-powered development assistant/)).toBeInTheDocument(); - }); -}); \ No newline at end of file diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index ee22914e..52ec50bf 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -39,14 +39,13 @@ import { Tool } from '@/lib/tools/Tool'; import OpenAI from 'openai'; import { saveFileToTmp } from '@/lib/fileUtils'; import { useGit } from '@/hooks/useGit'; -import { useConsoleErrorAlert } from '@/hooks/useErrorDetection'; import { Quilly } from '@/components/Quilly'; // Clean interfaces now handled by proper hooks interface ChatPaneProps { projectId: string; - onNewChat?: () => void; + onNewChat: () => void; onFirstInteraction?: () => void; onLoadingChange?: (isLoading: boolean) => void; isLoading?: boolean; @@ -234,19 +233,6 @@ export const ChatPane = forwardRef(({ setIsModelSelectorOpen(true); }, []); - // Function to suggest error fix - // Clean alert hooks with proper interfaces - const consoleAlert = useConsoleErrorAlert(messages, isBuildLoading, internalIsLoading); - - // Scroll to bottom when alerts appear - useEffect(() => { - if (consoleAlert.hasError || aiError) { - setTimeout(() => { - scrollToBottom(); - }, 50); - } - }, [consoleAlert.hasError, aiError, scrollToBottom]); - // Check for autostart parameter and trigger AI generation useEffect(() => { if (autostartedRef.current) return; @@ -504,10 +490,6 @@ export const ChatPane = forwardRef(({ } }), [internalStartNewSession]); - const suggestErrorFix = useCallback(async (errorMessage: string) => { - await send(errorMessage, attachedFiles); - }, [send, attachedFiles]); - return (
@@ -600,15 +582,6 @@ export const ChatPane = forwardRef(({
)} - {/* Console Error Alert */} - {consoleAlert.hasError && ( - suggestErrorFix(consoleAlert.errorSummary || '')} - /> - )} - {/* AI Error Alert */} {aiError && ( (({ onOpenModelSelector={openModelSelector} /> )} - diff --git a/src/hooks/useErrorDetection.ts b/src/hooks/useErrorDetection.ts deleted file mode 100644 index c530f646..00000000 --- a/src/hooks/useErrorDetection.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { useState, useCallback, useMemo } from 'react'; -import type { AIMessage } from '@/lib/SessionManager'; -import { useConsoleMessages } from './useConsoleMessages'; - -export interface ConsoleErrorAlert { - hasError: boolean; - errorSummary: string | null; - errorCount: number; - dismiss: () => void; -} - -export const useConsoleErrorAlert = ( - aiMessages: AIMessage[], - isBuilding?: boolean, - isLoading?: boolean -): ConsoleErrorAlert => { - const { messages } = useConsoleMessages(); - const [dismissedErrorSummary, setDismissedErrorSummary] = useState(''); - - const { hasError, errorSummary, errorCount } = useMemo(() => { - // Don't show alerts while building or AI is working - if (isBuilding || isLoading) { - return { hasError: false, errorSummary: null, errorCount: 0 }; - } - - // Find the timestamp of the last AI assistant message - // Since AIMessage doesn't have timestamps, we'll use a different approach: - // Only show errors if there are any errors at all and no recent user activity - const lastMessage = aiMessages[aiMessages.length - 1]; - const isLastMessageFromAssistant = lastMessage?.role === 'assistant'; - - // Only show console errors if the last message was from assistant (AI just responded) - if (!isLastMessageFromAssistant) { - return { hasError: false, errorSummary: null, errorCount: 0 }; - } - - // Get recent errors (last 10 seconds worth to catch errors from recent AI actions) - const recentTimeThreshold = Date.now() - (10 * 1000); // 10 seconds ago - const recentErrors = messages.filter(msg => - msg.level === 'error' && - msg.timestamp > recentTimeThreshold - ); - - if (recentErrors.length === 0) { - return { hasError: false, errorSummary: null, errorCount: 0 }; - } - - // Just return the raw error messages, no formatting - const summary = recentErrors.slice(-3).map(e => e.message).join('\n'); - - return { - hasError: dismissedErrorSummary !== summary, - errorSummary: summary, - errorCount: recentErrors.length - }; - }, [messages, dismissedErrorSummary, aiMessages, isBuilding, isLoading]); - - const dismiss = useCallback(() => { - if (errorSummary) { - setDismissedErrorSummary(errorSummary); - } - }, [errorSummary]); - - return { - hasError, - errorSummary, - errorCount, - dismiss - }; -}; - -