From aed7a25ea79d757d851a952af930d087edc43308 Mon Sep 17 00:00:00 2001 From: Jerome Date: Wed, 11 Jun 2025 18:26:06 +0100 Subject: [PATCH] Fix authentication state consistency across components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix ChatInterface to use context's reactive isAuthenticated value - Fix useAgentLoop to use context's reactive isAuthenticated value - Ensure consistent authentication state checking across the application - Add isAuthenticated to useCallback dependencies for proper reactivity 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/components/ChatInterface.tsx | 2 +- src/hooks/useAgentLoop.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ChatInterface.tsx b/src/components/ChatInterface.tsx index e1bf3eb..caf19ec 100644 --- a/src/components/ChatInterface.tsx +++ b/src/components/ChatInterface.tsx @@ -16,7 +16,7 @@ export function ChatInterface() { getAgentLoopState, } = useConversation(); - const { currentProvider } = useInference(); + const { provider: currentProvider, isAuthenticated } = useInference(); const [isLoading, setIsLoading] = useState(false); const messagesEndRef = useRef(null); diff --git a/src/hooks/useAgentLoop.ts b/src/hooks/useAgentLoop.ts index 53eac38..78e9ab6 100644 --- a/src/hooks/useAgentLoop.ts +++ b/src/hooks/useAgentLoop.ts @@ -126,7 +126,7 @@ const DEFAULT_CONFIG: AgentLoopConfig = { export function useAgentLoop(config: Partial = {}): UseAgentLoopReturn { const finalConfig = { ...DEFAULT_CONFIG, ...config }; - const { currentProvider } = useInference(); + const { provider: currentProvider, isAuthenticated } = useInference(); const { getAllTools, callTool: callMCPTool, connections } = useMCP(); // Track running loops @@ -255,7 +255,7 @@ export function useAgentLoop(config: Partial = {}): UseAgentLoo conversation: Conversation, onUpdate: (conversation: Conversation) => void ) => { - if (!currentProvider?.isAuthenticated) { + if (!isAuthenticated || !currentProvider) { throw new Error('No authenticated inference provider available'); } @@ -397,7 +397,7 @@ export function useAgentLoop(config: Partial = {}): UseAgentLoo } finally { loopStates.current.delete(conversationId); } - }, [currentProvider, finalConfig, toInferenceMessages, fromInferenceResponse, getAllTools, executeTool]); + }, [isAuthenticated, currentProvider, finalConfig, toInferenceMessages, fromInferenceResponse, getAllTools, executeTool]); const stopLoop = useCallback((conversationId: string) => { const loopState = loopStates.current.get(conversationId);