From 8a0071563f812426dcf7954c42cbc5c40912bc12 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 25 Aug 2025 22:34:15 -0500 Subject: [PATCH] Add model selector to new project input --- src/components/Shakespeare/ChatPane.tsx | 31 ++++++++++----- src/pages/Index.tsx | 51 +++++++++++++++++++++---- 2 files changed, 65 insertions(+), 17 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 1ab87317..e6de0e0d 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -116,24 +116,35 @@ When creating new components or pages, follow the existing patterns in the codeb // Check for autostart parameter and trigger AI generation useEffect(() => { const autostart = searchParams.get('autostart'); + const urlModel = searchParams.get('model'); - if (autostart === 'true' && isConfigured && messages.length > 0 && !isLoading && providerModel.trim()) { + if (autostart === 'true' && isConfigured && messages.length > 0 && !isLoading) { const lastMessage = messages[messages.length - 1]; // If the last message is from the user, auto-start the AI if (lastMessage.role === 'user') { - // Clear the autostart parameter so it doesn't trigger again - const newSearchParams = new URLSearchParams(searchParams); - newSearchParams.delete('autostart'); - setSearchParams(newSearchParams, { replace: true }); + // Use model from URL if available, otherwise use current selection + const modelToUse = urlModel?.trim() || providerModel.trim(); - // Start AI generation - const modelToUse = providerModel.trim(); - 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, addRecentlyUsedModel]); + }, [searchParams, setSearchParams, isConfigured, messages, isLoading, startGeneration, providerModel, setProviderModel, addRecentlyUsedModel]); // Keep-alive functionality to prevent tab throttling during AI processing const { updateMetadata } = useKeepAlive({ diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 152924bd..21db9f5f 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -6,12 +6,14 @@ import { useFS } from '@/hooks/useFS'; import { useLocalStorage } from '@/hooks/useLocalStorage'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useIsMobile } from '@/hooks/useIsMobile'; +import { useAISettings } from '@/hooks/useAISettings'; import { AppLayout } from '@/components/AppLayout'; import { DotAI } from '@/lib/DotAI'; import type { AIMessage } from '@/hooks/useAIChat'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; +import { ModelSelector } from '@/components/ModelSelector'; import { Plus } from 'lucide-react'; import { useSeoMeta } from '@unhead/react'; @@ -24,6 +26,11 @@ export default function Index() { const { fs } = useFS(); const { user: _user } = useCurrentUser(); const { generateProjectId, isLoading: isGeneratingId, isConfigured: isAIConfigured } = useAIProjectId(); + const { settings, addRecentlyUsedModel } = useAISettings(); + const [providerModel, setProviderModel] = useState(() => { + // Initialize with first recently used model if available, otherwise empty + return settings.recentlyUsedModels?.[0] || ''; + }); const isMobile = useIsMobile(); useSeoMeta({ @@ -78,7 +85,10 @@ export default function Index() { try { let projectId: string; - if (isAIConfigured) { + if (isAIConfigured && providerModel.trim()) { + // Add model to recently used when creating project with AI + addRecentlyUsedModel(providerModel.trim()); + // Use AI to generate project ID try { projectId = await generateProjectId(prompt.trim()); @@ -90,7 +100,7 @@ export default function Index() { return; } } else { - // Fallback to manual project creation if AI not configured + // Fallback to manual project creation if AI not configured or no model selected const project = await projectsManager.createProject(prompt.trim()); navigate(`/project/${project.id}`); return; @@ -108,8 +118,12 @@ export default function Index() { }; await dotAI.setHistory(sessionName, [initialMessage]); - // Navigate to the project with autostart parameter - navigate(`/project/${project.id}?autostart=true`); + // Navigate to the project with autostart parameter and model + const searchParams = new URLSearchParams({ + autostart: 'true', + ...(providerModel.trim() && { model: providerModel.trim() }) + }); + navigate(`/project/${project.id}?${searchParams.toString()}`); } catch (error) { console.error('Failed to create project:', error); } finally { @@ -137,7 +151,11 @@ export default function Index() { {/* Chat Input Container - matching the ChatPane style */}