wip, bring error handling up to the project level to exist across mobile tabs

This commit is contained in:
sam committed 2025-09-28 08:37:45 +07:00
1 parent a9a5cafcac
commit 124e9d5937
2 files changed
+40 -19

No files matched your search

+20 -17
View File
@@ -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<ChatPaneRef, ChatPaneProps>(({
onLoadingChange,
isLoading: externalIsLoading,
isBuildLoading: externalIsBuildLoading,
consoleError,
onDismissConsoleError,
}, ref) => {
const { t } = useTranslation();
const [searchParams, setSearchParams] = useSearchParams();
@@ -80,18 +84,8 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
const [isStuck, setIsStuck] = useState(false);
const [aiError, setAIError] = useState<Error | null>(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<ChatPaneRef, ChatPaneProps>(({
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<ChatPaneRef, ChatPaneProps>(({
</div>
)}
{/* AI Error Alert */}
{aiError && (
{/* Error Alert (Console or AI) */}
{displayError && (
<Quilly
error={aiError}
onDismiss={() => setAIError(null)}
error={displayError}
onDismiss={handleErrorDismiss}
onNewChat={onNewChat}
onOpenModelSelector={openModelSelector}
onRequestConsoleErrorHelp={handleConsoleErrorHelp}
+20 -2
View File
@@ -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<ProjectPreviewConsoleError | null>(null);
const projectsManager = useProjectsManager();
const chatPaneRef = useRef<ChatPaneRef>(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}
/>
) : (
<div className="h-full p-4 space-y-4">