From 795eaa50c2cdb3026c4865e8ddd4511422a55440 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 29 Sep 2025 17:19:02 -0500 Subject: [PATCH] Make Quilly's "fix error" add assistant messages --- src/components/AIMessageItem.tsx | 7 +++++- src/components/Shakespeare/ChatPane.tsx | 31 ++++++++++++++++++++++--- src/lib/SessionManager.ts | 4 ---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/components/AIMessageItem.tsx b/src/components/AIMessageItem.tsx index f850d900..2287ac82 100644 --- a/src/components/AIMessageItem.tsx +++ b/src/components/AIMessageItem.tsx @@ -1,6 +1,6 @@ import { memo, useState } from 'react'; import { Streamdown } from 'streamdown'; -import { Wrench, Eye, FileText, Edit, Package, PackageMinus, GitCommit, BookOpen, Download, Hash, Tag, Network, List, Plus, Terminal, Globe, CheckCircle, Lightbulb, Loader2 } from 'lucide-react'; +import { Wrench, Eye, FileText, Edit, Package, PackageMinus, GitCommit, BookOpen, Download, Hash, Tag, Network, List, Plus, Terminal, Globe, CheckCircle, Lightbulb, Loader2, Logs } from 'lucide-react'; import type { AIMessage } from '@/lib/SessionManager'; import { cn } from '@/lib/utils'; import { UserMessage } from '@/components/UserMessage'; @@ -150,6 +150,11 @@ export const AIMessageItem = memo(({ icon: CheckCircle, title: 'TypeScript' }; + case 'read_console_messages': + return { + icon: Logs, + title: 'Read Console' + }; default: return { icon: Wrench, diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 02721a19..913011ad 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -203,6 +203,7 @@ export const ChatPane = forwardRef(({ isLoading: internalIsLoading, totalCost, lastInputTokens, + addMessage, sendMessage, startGeneration, stopGeneration, @@ -216,9 +217,33 @@ export const ChatPane = forwardRef(({ }); // Handle console error help requests - const handleConsoleErrorHelp = useCallback(() => { - sendMessage('Read the console messages and fix any errors present.', providerModel); - }, [sendMessage, providerModel]); + const handleConsoleErrorHelp = useCallback(async () => { + const tool = new ReadConsoleMessagesTool(); + const toolCallId = `call_${crypto.randomUUID().replace(/-/g, '')}`; + + await addMessage({ + role: 'assistant', + content: 'Let me take a look at the console messages to help diagnose the issue.', + tool_calls: [ + { + id: toolCallId, + type: 'function', + function: { + name: 'read_console_messages', + arguments: '{}', + } + } + ] + }); + + await addMessage({ + role: 'tool', + content: await tool.execute({ filter: 'error' }), + tool_call_id: toolCallId, + }); + + await startGeneration(providerModel); + }, [addMessage, providerModel, startGeneration]); // Handle error dismissal const handleErrorDismiss = useCallback(() => { diff --git a/src/lib/SessionManager.ts b/src/lib/SessionManager.ts index fde41dd3..22f416c1 100644 --- a/src/lib/SessionManager.ts +++ b/src/lib/SessionManager.ts @@ -188,10 +188,6 @@ export class SessionManager { throw new Error('No messages in session'); } - // Check if last message is from user - const lastMessage = session.messages[session.messages.length - 1]; - if (lastMessage.role !== 'user') return; - session.isLoading = true; session.abortController = new AbortController(); session.lastActivity = new Date();