Heavily reduce console log detection.

This commit is contained in:
Chad Curtis committed 2025-09-25 04:32:11 +00:00
1 parent c46077af67
commit 18a276a44e
7 files changed
+90 -220

No files matched your search

+4 -8
View File
@@ -34,13 +34,15 @@ 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 { toolToOpenAI } from '@/lib/tools/openai-adapter';
import { Tool } from '@/lib/tools/Tool';
import OpenAI from 'openai';
import { ReadConsoleMessagesTool } from '@/lib/tools/ReadConsoleMessagesTool';
import { saveFileToTmp } from '@/lib/fileUtils';
import { useGit } from '@/hooks/useGit';
import { Quilly } from '@/components/Quilly';
import { getConsoleMessages } from '@/lib/consoleMessages';
// Clean interfaces now handled by proper hooks
@@ -104,13 +106,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
const { user } = useCurrentUser();
const { models } = useProviderModels();
// Use ref to maintain stable reference to console messages for tools
const consoleMessagesRef = useRef<ConsoleMessage[]>([]);
// Update ref when console messages change
useEffect(() => {
consoleMessagesRef.current = consoleMessages;
}, [consoleMessages]);
// Initialize AI chat with tools
const cwd = `/projects/${projectId}`;
@@ -132,7 +128,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
nostr_read_nips_index: new NostrReadNipsIndexTool(),
nostr_generate_kind: new NostrGenerateKindTool(),
shell: new ShellTool(fs, cwd, git),
read_console_messages: new ReadConsoleMessagesTool(() => consoleMessagesRef.current),
read_console_messages: new ReadConsoleMessagesTool(getConsoleMessages),
};
// Add deploy tool only if user is logged in
+10 -4
View File
@@ -3,7 +3,7 @@ import { useState, useEffect, useCallback, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useProjectsManager } from '@/hooks/useProjectsManager';
import { useFS } from '@/hooks/useFS';
import { useProjectConsoleMessages, addProjectConsoleMessage } from '@/hooks/useProjectConsoleMessages';
import { addConsoleMessage, getConsoleMessages } from '@/lib/consoleMessages';
import { useBuildProject } from '@/hooks/useBuildProject';
import { Tabs, TabsContent } from '@/components/ui/tabs';
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
@@ -93,7 +93,7 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
const { fs } = useFS();
const projectsManager = useProjectsManager();
const { messages: consoleMessages } = useProjectConsoleMessages(projectId);
const [consoleMessages, setConsoleMessages] = useState<ConsoleMessage[]>([]);
const { mutate: buildProject, isPending: isBuildLoading } = useBuildProject(projectId);
const [searchParams, setSearchParams] = useSearchParams();
@@ -119,6 +119,11 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
}
}, [searchParams, setSearchParams]);
// Load console messages when project changes
useEffect(() => {
setConsoleMessages(getConsoleMessages());
}, []);
// Build automatically if "build" parameter was present
useEffect(() => {
if (shouldBuild && isPreviewable && !isBuildLoading) {
@@ -266,11 +271,12 @@ export function PreviewPane({ projectId, activeTab, onToggleView, projectName, o
}
// Add to project-specific console messages
addProjectConsoleMessage(projectId, normalizedLevel, params.message);
addConsoleMessage(normalizedLevel, params.message);
setConsoleMessages(getConsoleMessages());
// Log to parent console for debugging with appropriate level
console[normalizedLevel](`[IFRAME ${params.level.toUpperCase()}] ${params.message}`);
}, [projectId]);
}, []);
const handleFetch = useCallback(async (request: JSONRPCRequest) => {
const { params, id } = request;