mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Attempt peace with Quilly once more.
This commit is contained in:
1 parent
7ab30af944
commit
93e992f128
4 files changed
+229
-6
No files matched your search
@@ -7,6 +7,7 @@ import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import { useAICredits } from '@/hooks/useAICredits';
|
||||
import { CreditsDialog } from './CreditsDialog';
|
||||
import { ProjectPreviewConsoleError } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { useState } from 'react';
|
||||
|
||||
export interface QuillyProps {
|
||||
@@ -14,6 +15,7 @@ export interface QuillyProps {
|
||||
onDismiss: () => void;
|
||||
onNewChat: () => void;
|
||||
onOpenModelSelector: () => void;
|
||||
onRequestConsoleErrorHelp?: (error: ProjectPreviewConsoleError) => void;
|
||||
providerModel: string;
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ interface ErrorBody {
|
||||
};
|
||||
}
|
||||
|
||||
export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, providerModel }: QuillyProps) {
|
||||
export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, onRequestConsoleErrorHelp, providerModel }: QuillyProps) {
|
||||
const navigate = useNavigate();
|
||||
const { settings } = useAISettings();
|
||||
const { provider } = parseProviderModel(providerModel, settings.providers);
|
||||
@@ -33,6 +35,33 @@ export function Quilly({ error, onDismiss, onNewChat, onOpenModelSelector, provi
|
||||
const [showCreditsDialog, setShowCreditsDialog] = useState(false);
|
||||
|
||||
const renderBody = (error: Error): ErrorBody => {
|
||||
// Handle Project Preview Console Errors
|
||||
if (error instanceof ProjectPreviewConsoleError) {
|
||||
const errorCount = error.logs.filter(log => log.level === 'error').length;
|
||||
const warningCount = error.logs.filter(log => log.level === 'warn').length;
|
||||
|
||||
let message = 'I noticed some console errors in your project preview.';
|
||||
|
||||
if (errorCount > 1) {
|
||||
message = `I noticed ${errorCount} console errors in your project preview.`;
|
||||
} else if (errorCount === 1 && warningCount > 0) {
|
||||
message = `I noticed ${errorCount} console error and ${warningCount} warning${warningCount > 1 ? 's' : ''} in your project preview.`;
|
||||
} else if (warningCount > 0) {
|
||||
message = `I noticed ${warningCount} console warning${warningCount > 1 ? 's' : ''} in your project preview.`;
|
||||
}
|
||||
|
||||
return {
|
||||
message: message + ' Would you like me to take a look and help fix them?',
|
||||
action: {
|
||||
label: 'Help fix errors',
|
||||
onClick: () => {
|
||||
onRequestConsoleErrorHelp?.(error);
|
||||
onDismiss();
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// Handle OpenAI API errors with specific error codes
|
||||
if (error instanceof OpenAI.APIError) {
|
||||
switch (error.code) {
|
||||
|
||||
@@ -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 } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { ReadConsoleMessagesTool, ProjectPreviewConsoleError, addErrorListener, removeErrorListener } from '@/lib/tools/ReadConsoleMessagesTool';
|
||||
import { toolToOpenAI } from '@/lib/tools/openai-adapter';
|
||||
import { Tool } from '@/lib/tools/Tool';
|
||||
import OpenAI from 'openai';
|
||||
@@ -75,6 +75,19 @@ 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]);
|
||||
|
||||
// Use external state if provided, otherwise default to false
|
||||
const isBuildLoading = externalIsBuildLoading || false;
|
||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||
@@ -189,6 +202,25 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
onAIError,
|
||||
});
|
||||
|
||||
// Handle console error help requests
|
||||
const handleConsoleErrorHelp = useCallback((error: ProjectPreviewConsoleError) => {
|
||||
const errorMessages = error.logs.filter(log => log.level === 'error').map(log => log.message);
|
||||
const warningMessages = error.logs.filter(log => log.level === 'warn').map(log => log.message);
|
||||
|
||||
let consoleOutput = '';
|
||||
if (errorMessages.length > 0) {
|
||||
consoleOutput += `Console Errors:\n${errorMessages.map(msg => `- ${msg}`).join('\n')}\n\n`;
|
||||
}
|
||||
if (warningMessages.length > 0) {
|
||||
consoleOutput += `Console Warnings:\n${warningMessages.map(msg => `- ${msg}`).join('\n')}\n\n`;
|
||||
}
|
||||
|
||||
const helpMessage = `I noticed some console issues in the project preview:\n\n${consoleOutput}Could you help me understand what's causing these issues and how to fix them?`;
|
||||
|
||||
// Send the console error information as a user message
|
||||
sendMessage(helpMessage, providerModel);
|
||||
}, [sendMessage, providerModel]);
|
||||
|
||||
// Use external loading state if provided, otherwise use internal state
|
||||
const isLoading = externalIsLoading !== undefined ? externalIsLoading : internalIsLoading;
|
||||
|
||||
@@ -598,6 +630,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
onDismiss={() => setAIError(null)}
|
||||
onNewChat={onNewChat}
|
||||
onOpenModelSelector={openModelSelector}
|
||||
onRequestConsoleErrorHelp={handleConsoleErrorHelp}
|
||||
providerModel={providerModel}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user