diff --git a/src/App.tsx b/src/App.tsx index d798eb2a6..2b8c22de2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,6 +10,7 @@ import { StatusBar } from './components/StatusBar'; import { FileTreePanel } from './components/FileTreePanel'; import { CodeReferencesPanel } from './components/CodeReferencesPanel'; import { FileEntry } from './services/zip'; +import { getActiveProviderConfig } from './core/llm/settings-service'; const AppContent = () => { const { @@ -49,6 +50,12 @@ const AppContent = () => { setGraph(result.graph); setFileContents(result.fileContents); setViewMode('exploring'); + + // Initialize (or re-initialize) the agent AFTER a repo loads so it captures + // the current codebase context (file contents + graph tools) in the worker. + if (getActiveProviderConfig()) { + initializeAgent(); + } // Auto-start embeddings pipeline in background // Uses WebGPU if available, falls back to WASM @@ -73,7 +80,7 @@ const AppContent = () => { setProgress(null); }, 3000); } - }, [setViewMode, setGraph, setFileContents, setProgress, setProjectName, runPipeline, startEmbeddings]); + }, [setViewMode, setGraph, setFileContents, setProgress, setProjectName, runPipeline, startEmbeddings, initializeAgent]); const handleGitClone = useCallback(async (files: FileEntry[]) => { // Extract project name from first file path (e.g., "owner-repo-123/src/..." -> "owner-repo") @@ -91,6 +98,12 @@ const AppContent = () => { setGraph(result.graph); setFileContents(result.fileContents); setViewMode('exploring'); + + // Initialize (or re-initialize) the agent AFTER a repo loads so it captures + // the current codebase context (file contents + graph tools) in the worker. + if (getActiveProviderConfig()) { + initializeAgent(); + } // Auto-start embeddings pipeline in background // Uses WebGPU if available, falls back to WASM @@ -115,7 +128,7 @@ const AppContent = () => { setProgress(null); }, 3000); } - }, [setViewMode, setGraph, setFileContents, setProgress, setProjectName, runPipelineFromFiles, startEmbeddings]); + }, [setViewMode, setGraph, setFileContents, setProgress, setProjectName, runPipelineFromFiles, startEmbeddings, initializeAgent]); const handleFocusNode = useCallback((nodeId: string) => { graphCanvasRef.current?.focusNode(nodeId); diff --git a/src/components/RightPanel.tsx b/src/components/RightPanel.tsx index 06d15319e..5b4ea57aa 100644 --- a/src/components/RightPanel.tsx +++ b/src/components/RightPanel.tsx @@ -8,6 +8,7 @@ import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism'; import ReactMarkdown from 'react-markdown'; import { useAppState } from '../hooks/useAppState'; import { ToolCallCard } from './ToolCallCard'; +import { isProviderConfigured } from '../core/llm/settings-service'; // Custom syntax theme const customTheme = { @@ -492,7 +493,11 @@ export const RightPanel = () => { {!isAgentReady && !isAgentInitializing && (
- Configure an LLM provider to enable chat. + + {isProviderConfigured() + ? 'Initializing AI agent...' + : 'Configure an LLM provider to enable chat.'} +
)} diff --git a/src/hooks/useAppState.tsx b/src/hooks/useAppState.tsx index 3f034a749..86309a84f 100644 --- a/src/hooks/useAppState.tsx +++ b/src/hooks/useAppState.tsx @@ -520,6 +520,23 @@ export const AppStateProvider = ({ children }: { children: ReactNode }) => { timestamp: Date.now(), }; setChatMessages(prev => [...prev, userMessage]); + + // If embeddings are running and we're currently creating the vector index, + // avoid a confusing "Embeddings not ready" error and give a clear wait message. + if (embeddingStatus === 'indexing') { + const assistantMessage: ChatMessage = { + id: `assistant-${Date.now()}`, + role: 'assistant', + content: 'Wait a moment, vector index is being created.', + timestamp: Date.now(), + }; + setChatMessages(prev => [...prev, assistantMessage]); + setAgentError(null); + setIsChatLoading(false); + setCurrentToolCalls([]); + return; + } + setIsChatLoading(true); setCurrentToolCalls([]); @@ -778,7 +795,7 @@ export const AppStateProvider = ({ children }: { children: ReactNode }) => { setIsChatLoading(false); setCurrentToolCalls([]); } - }, [chatMessages, isAgentReady, initializeAgent, resolveFilePath, findFileNodeId, addCodeReference, clearAICodeReferences, clearAIToolHighlights, graph]); + }, [chatMessages, isAgentReady, initializeAgent, resolveFilePath, findFileNodeId, addCodeReference, clearAICodeReferences, clearAIToolHighlights, graph, embeddingStatus]); const clearChat = useCallback(() => { setChatMessages([]);