diff --git a/src/ui/hooks/useChat.ts b/src/ui/hooks/useChat.ts index b9a099329..af47e19ee 100644 --- a/src/ui/hooks/useChat.ts +++ b/src/ui/hooks/useChat.ts @@ -494,8 +494,12 @@ export function useChat({ ]); try { + if (!llmApi) { + throw new Error("LLM API is not available for auto-compaction"); + } + // Compact the history WITHOUT the current user message - const result = await compactChatHistory(chatHistory, model, llmApi!); + const result = await compactChatHistory(chatHistory, model, llmApi); // Update local variables immediately currentChatHistory = result.compactedHistory;