diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index f9d724c0..4fb8905a 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -34,7 +34,7 @@ import { NostrReadNipsIndexTool } from '@/lib/tools/NostrReadNipsIndexTool'; import { NostrGenerateKindTool } from '@/lib/tools/NostrGenerateKindTool'; import { ShellTool } from '@/lib/tools/ShellTool'; import { TypecheckTool } from '@/lib/tools/TypecheckTool'; -import { ReadConsoleMessagesTool, ProjectPreviewConsoleError, addErrorListener, removeErrorListener } from '@/lib/tools/ReadConsoleMessagesTool'; +import { ReadConsoleMessagesTool, ProjectPreviewConsoleError } from '@/lib/tools/ReadConsoleMessagesTool'; import { toolToOpenAI } from '@/lib/tools/openai-adapter'; import { Tool } from '@/lib/tools/Tool'; import OpenAI from 'openai'; @@ -51,6 +51,8 @@ interface ChatPaneProps { onLoadingChange?: (isLoading: boolean) => void; isLoading?: boolean; isBuildLoading?: boolean; + consoleError?: ProjectPreviewConsoleError | null; + onDismissConsoleError?: () => void; } export interface ChatPaneRef { @@ -64,6 +66,8 @@ export const ChatPane = forwardRef(({ onLoadingChange, isLoading: externalIsLoading, isBuildLoading: externalIsBuildLoading, + consoleError, + onDismissConsoleError, }, ref) => { const { t } = useTranslation(); const [searchParams, setSearchParams] = useSearchParams(); @@ -80,18 +84,8 @@ export const ChatPane = forwardRef(({ const [isStuck, setIsStuck] = useState(false); const [aiError, setAIError] = useState(null); - // Console error handling - useEffect(() => { - const handleConsoleError = (error: ProjectPreviewConsoleError) => { - // Only show console errors if there's no existing AI error - if (!aiError) { - setAIError(error); - } - }; - - addErrorListener(handleConsoleError); - return () => removeErrorListener(handleConsoleError); - }, [aiError]); + // Determine which error to show - console error takes priority over AI errors + const displayError = consoleError || aiError; // Use external state if provided, otherwise default to false const isBuildLoading = externalIsBuildLoading || false; @@ -225,6 +219,15 @@ export const ChatPane = forwardRef(({ sendMessage('Read the console messages and fix any errors present.', providerModel); }, [sendMessage, providerModel]); + // Handle error dismissal + const handleErrorDismiss = useCallback(() => { + if (consoleError && onDismissConsoleError) { + onDismissConsoleError(); + } else { + setAIError(null); + } + }, [consoleError, onDismissConsoleError]); + // Use external loading state if provided, otherwise use internal state const isLoading = externalIsLoading !== undefined ? externalIsLoading : internalIsLoading; @@ -608,11 +611,11 @@ export const ChatPane = forwardRef(({ )} - {/* AI Error Alert */} - {aiError && ( + {/* Error Alert (Console or AI) */} + {displayError && ( setAIError(null)} + error={displayError} + onDismiss={handleErrorDismiss} onNewChat={onNewChat} onOpenModelSelector={openModelSelector} onRequestConsoleErrorHelp={handleConsoleErrorHelp} diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index 8dd43d1c..f73f3a3b 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -18,7 +18,7 @@ import { GitStatusIndicator } from '@/components/GitStatusIndicator'; import { StarButton } from '@/components/StarButton'; import { useBuildProject } from '@/hooks/useBuildProject'; import { useIsProjectPreviewable } from '@/hooks/useIsProjectPreviewable'; -import { clearConsoleMessages } from '@/lib/tools/ReadConsoleMessagesTool'; +import { clearConsoleMessages, ProjectPreviewConsoleError, addErrorListener, removeErrorListener } from '@/lib/tools/ReadConsoleMessagesTool'; export function ProjectView() { const { projectId } = useParams<{ projectId: string }>(); @@ -29,6 +29,7 @@ export function ProjectView() { const [mobileView, setMobileView] = useState<'chat' | 'preview' | 'code'>('chat'); const [isAILoading, setIsAILoading] = useState(false); const [isProjectDetailsOpen, setIsProjectDetailsOpen] = useState(false); + const [consoleError, setConsoleError] = useState(null); const projectsManager = useProjectsManager(); const chatPaneRef = useRef(null); @@ -46,8 +47,9 @@ export function ProjectView() { try { const projectData = await projectsManager.getProject(projectId); setProject(projectData); - // Clear console messages when switching projects + // Clear console messages and error state when switching projects clearConsoleMessages(); + setConsoleError(null); } catch (error) { console.error('Failed to load project:', error); } finally { @@ -79,6 +81,16 @@ export function ProjectView() { } }, [isPreviewable, mobileView, activeTab]); + // Global console error listener (always active regardless of current tab) + useEffect(() => { + const handleConsoleError = (error: ProjectPreviewConsoleError) => { + setConsoleError(error); + }; + + addErrorListener(handleConsoleError); + return () => removeErrorListener(handleConsoleError); + }, []); + const handleNewChat = () => { // Reset to chat view on mobile when starting new chat if (isMobile) { @@ -100,6 +112,10 @@ export function ProjectView() { // when isAILoading becomes true after user interaction }; + const handleDismissConsoleError = () => { + setConsoleError(null); + }; + const handleProjectDeleted = async () => { setProject(null); navigate('/'); @@ -212,6 +228,8 @@ export function ProjectView() { onLoadingChange={handleAILoadingChange} isLoading={isAILoading} isBuildLoading={build.isPending} + consoleError={consoleError} + onDismissConsoleError={handleDismissConsoleError} /> ) : (