From 73f164de4104981e5c9b401fe946b11e105a82e7 Mon Sep 17 00:00:00 2001 From: Carlos Gutierrez Date: Sat, 31 Jan 2026 23:19:32 -0500 Subject: [PATCH] Fixing the appstore issue --- .../components/chat/mcp/handle-mcp.ts | 2 +- src/tui-solid/context/app.tsx | 102 +++++++++++------- 2 files changed, 67 insertions(+), 37 deletions(-) diff --git a/src/commands/components/chat/mcp/handle-mcp.ts b/src/commands/components/chat/mcp/handle-mcp.ts index 3cf0b33..f3d59cc 100644 --- a/src/commands/components/chat/mcp/handle-mcp.ts +++ b/src/commands/components/chat/mcp/handle-mcp.ts @@ -20,7 +20,7 @@ import { MCP_CATEGORY_ICONS, } from "@constants/mcp-registry"; import { showMCPStatus } from "@commands/components/chat/mcp/show-mcp-status"; -import { appStore } from "@tui-solid/context/app"; +import { appStore } from "@tui/index"; /** * Handle MCP subcommands diff --git a/src/tui-solid/context/app.tsx b/src/tui-solid/context/app.tsx index 0dc1063..3feea83 100644 --- a/src/tui-solid/context/app.tsx +++ b/src/tui-solid/context/app.tsx @@ -793,9 +793,39 @@ export const setAppStoreRef = (store: AppContextValue): void => { storeRef = store; }; +// Default state for when store is not yet initialized +const defaultAppState = { + mode: "idle" as AppMode, + screenMode: "home" as ScreenMode, + interactionMode: "agent" as InteractionMode, + currentAgent: "default", + inputBuffer: "", + logs: [] as LogEntry[], + currentToolCall: null, + permissionRequest: null, + learningPrompt: null, + thinkingMessage: null, + sessionId: null, + provider: "copilot", + model: "", + version: "0.1.0", + sessionStats: createInitialSessionStats(), + cascadeEnabled: true, + todosVisible: true, + debugLogVisible: false, + interruptPending: false, + exitPending: false, + isCompacting: false, + streamingLog: createInitialStreamingState(), + suggestions: createInitialSuggestionState(), +}; + export const appStore = { getState: () => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) { + // Return default state when store is not yet initialized + return defaultAppState; + } return { mode: storeRef.mode(), screenMode: storeRef.screenMode(), @@ -824,177 +854,177 @@ export const appStore = { }, addLog: (entry: Omit): string => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return ""; return storeRef.addLog(entry); }, updateLog: (id: string, updates: Partial): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.updateLog(id, updates); }, setMode: (mode: AppMode): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setMode(mode); }, toggleInteractionMode: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.toggleInteractionMode(); }, setCurrentAgent: (agent: string): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setCurrentAgent(agent); }, setCurrentToolCall: (toolCall: ToolCall | null): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setCurrentToolCall(toolCall); }, updateToolCall: (updates: Partial): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.updateToolCall(updates); }, setThinkingMessage: (message: string | null): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setThinkingMessage(message); }, setPermissionRequest: (request: PermissionRequest | null): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setPermissionRequest(request); }, setLearningPrompt: (prompt: LearningPrompt | null): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setLearningPrompt(prompt); }, clearInput: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.clearInput(); }, clearLogs: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.clearLogs(); }, openCommandMenu: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.openCommandMenu(); }, closeCommandMenu: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.closeCommandMenu(); }, transitionFromCommandMenu: (newMode: AppMode): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.transitionFromCommandMenu(newMode); }, setAvailableModels: (models: ProviderModel[]): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setAvailableModels(models); }, setModel: (model: string): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setModel(model); }, startThinking: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.startThinking(); }, stopThinking: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.stopThinking(); }, addTokens: (input: number, output: number): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.addTokens(input, output); }, resetSessionStats: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.resetSessionStats(); }, toggleTodos: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.toggleTodos(); }, toggleDebugLog: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.toggleDebugLog(); }, setInterruptPending: (pending: boolean): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setInterruptPending(pending); }, setIsCompacting: (compacting: boolean): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setIsCompacting(compacting); }, startStreaming: (): string => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return ""; return storeRef.startStreaming(); }, appendStreamContent: (content: string): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.appendStreamContent(content); }, completeStreaming: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.completeStreaming(); }, cancelStreaming: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.cancelStreaming(); }, setSuggestions: (suggestions: SuggestionPrompt[]): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setSuggestions(suggestions); }, clearSuggestions: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.clearSuggestions(); }, hideSuggestions: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.hideSuggestions(); }, setProvider: (provider: string): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setProvider(provider); }, setCascadeEnabled: (enabled: boolean): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.setCascadeEnabled(enabled); }, toggleCascadeEnabled: (): void => { - if (!storeRef) throw new Error("AppStore not initialized"); + if (!storeRef) return; storeRef.toggleCascadeEnabled(); }, };