From 251959c18e83d8363c1880d284e3d6928551f3d7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 11 Sep 2025 15:33:24 -0500 Subject: [PATCH] Fix autostart --- src/components/Shakespeare/ChatPane.tsx | 44 +++++++++++-------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 3abd1002..7df319ea 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -12,7 +12,6 @@ import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useKeepAlive } from '@/hooks/useKeepAlive'; import { useAIChat } from '@/hooks/useAIChat'; import { useProviderModels } from '@/hooks/useProviderModels'; -import type { AIMessage } from '@/lib/SessionManager'; import { ModelSelector } from '@/components/ModelSelector'; import { AIMessageItem } from '@/components/AIMessageItem'; import { TextEditorViewTool } from '@/lib/tools/TextEditorViewTool'; @@ -200,33 +199,28 @@ export const ChatPane = forwardRef(({ const autostart = searchParams.get('autostart'); const urlModel = searchParams.get('model'); - if (autostart === 'true' && isConfigured && messages.length > 0 && !isLoading) { - const lastMessage = messages[messages.length - 1]; + if (autostart === 'true' && isConfigured && !isLoading) { + // Use model from URL if available, otherwise use current selection + const modelToUse = urlModel?.trim() || providerModel.trim(); - // If the last message is from the user, auto-start the AI - if (lastMessage.role === 'user') { - // Use model from URL if available, otherwise use current selection - const modelToUse = urlModel?.trim() || providerModel.trim(); - - if (modelToUse) { - // Update provider model if it came from URL - if (urlModel?.trim() && urlModel.trim() !== providerModel) { - setProviderModel(urlModel.trim()); - } - - // Clear the autostart and model parameters so they don't trigger again - const newSearchParams = new URLSearchParams(searchParams); - newSearchParams.delete('autostart'); - newSearchParams.delete('model'); - setSearchParams(newSearchParams, { replace: true }); - - // Start AI generation - addRecentlyUsedModel(modelToUse); - startGeneration(modelToUse); + if (modelToUse) { + // Update provider model if it came from URL + if (urlModel?.trim() && urlModel.trim() !== providerModel) { + setProviderModel(urlModel.trim()); } + + // Clear the autostart and model parameters so they don't trigger again + const newSearchParams = new URLSearchParams(searchParams); + newSearchParams.delete('autostart'); + newSearchParams.delete('model'); + setSearchParams(newSearchParams, { replace: true }); + + // Start AI generation + addRecentlyUsedModel(modelToUse); + startGeneration(modelToUse); } } - }, [searchParams, setSearchParams, isConfigured, messages, isLoading, startGeneration, providerModel, setProviderModel, addRecentlyUsedModel]); + }, [addRecentlyUsedModel, isConfigured, isLoading, providerModel, searchParams, setSearchParams, startGeneration]); // Function to check if user is at the bottom of the scroll area const checkScrollPosition = () => { @@ -378,7 +372,7 @@ export const ChatPane = forwardRef(({ streamingMessage.content ? ( ) : (