mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Disconnect Quilly from console errors temporarily
This commit is contained in:
4 files changed
+2
-428
No files matched your search
@@ -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
|
||||
|
||||
@@ -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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
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(
|
||||
<TestApp>
|
||||
<ChatPane projectId="test-project" />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByText('Welcome to Shakespeare')).toBeInTheDocument();
|
||||
expect(screen.getByText(/Your AI-powered development assistant/)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -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<ChatPaneRef, ChatPaneProps>(({
|
||||
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<ChatPaneRef, ChatPaneProps>(({
|
||||
}
|
||||
}), [internalStartNewSession]);
|
||||
|
||||
const suggestErrorFix = useCallback(async (errorMessage: string) => {
|
||||
await send(errorMessage, attachedFiles);
|
||||
}, [send, attachedFiles]);
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col relative">
|
||||
|
||||
@@ -600,15 +582,6 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Console Error Alert */}
|
||||
{consoleAlert.hasError && (
|
||||
<Quilly
|
||||
error={new Error(`Console ${consoleAlert.errorCount === 1 ? 'error' : 'errors'} detected in your app. Would you like me to help fix ${consoleAlert.errorCount === 1 ? 'it' : 'them'}?`)}
|
||||
onDismiss={consoleAlert.dismiss}
|
||||
onFixConsoleErrors={() => suggestErrorFix(consoleAlert.errorSummary || '')}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* AI Error Alert */}
|
||||
{aiError && (
|
||||
<Quilly
|
||||
@@ -618,7 +591,6 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
onOpenModelSelector={openModelSelector}
|
||||
/>
|
||||
)}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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<string>('');
|
||||
|
||||
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
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user