diff --git a/src/components/ModelSelector.tsx b/src/components/ModelSelector.tsx
new file mode 100644
index 00000000..57a84545
--- /dev/null
+++ b/src/components/ModelSelector.tsx
@@ -0,0 +1,158 @@
+import { useState, useEffect, useMemo } from 'react';
+import { Check, ChevronDown, Edit3 } from 'lucide-react';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
+import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from '@/components/ui/command';
+import { useAISettings } from '@/hooks/useAISettings';
+import { cn } from '@/lib/utils';
+
+interface ModelSelectorProps {
+ value: string;
+ onChange: (value: string) => void;
+ className?: string;
+ disabled?: boolean;
+ placeholder?: string;
+}
+
+export function ModelSelector({
+ value,
+ onChange,
+ className,
+ disabled = false,
+ placeholder = "Select or enter a model...",
+}: ModelSelectorProps) {
+ const [open, setOpen] = useState(false);
+ const [isCustomInput, setIsCustomInput] = useState(false);
+ const [customValue, setCustomValue] = useState('');
+ const { settings, addRecentlyUsedModel } = useAISettings();
+
+ const recentlyUsedModels = useMemo(() => settings.recentlyUsedModels || [], [settings.recentlyUsedModels]);
+
+ // Initialize with first recently used model if value is empty
+ useEffect(() => {
+ if (!value && recentlyUsedModels.length > 0) {
+ onChange(recentlyUsedModels[0]);
+ }
+ }, [value, recentlyUsedModels, onChange]);
+
+ const handleSelect = (selectedValue: string) => {
+ if (selectedValue === '__custom__') {
+ setIsCustomInput(true);
+ setCustomValue(value);
+ setOpen(false);
+ return;
+ }
+
+ onChange(selectedValue);
+ addRecentlyUsedModel(selectedValue);
+ setOpen(false);
+ };
+
+ const handleCustomSubmit = () => {
+ if (customValue.trim()) {
+ onChange(customValue.trim());
+ addRecentlyUsedModel(customValue.trim());
+ setIsCustomInput(false);
+ setCustomValue('');
+ }
+ };
+
+ const handleCustomKeyDown = (e: React.KeyboardEvent) => {
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ handleCustomSubmit();
+ } else if (e.key === 'Escape') {
+ setIsCustomInput(false);
+ setCustomValue('');
+ }
+ };
+
+ if (isCustomInput) {
+ return (
+
+ setCustomValue(e.target.value)}
+ onKeyDown={handleCustomKeyDown}
+ onBlur={handleCustomSubmit}
+ placeholder="provider/model (e.g., openrouter/anthropic/claude-sonnet-4)"
+ className="h-8 text-xs"
+ autoFocus
+ />
+
+
+ );
+ }
+
+ return (
+
+
+
+
+
+
+
+
+ No models found.
+
+ {recentlyUsedModels.length > 0 && (
+
+ {recentlyUsedModels.map((model) => (
+ handleSelect(model)}
+ className="cursor-pointer"
+ >
+
+ {model}
+
+ ))}
+
+ )}
+
+ {recentlyUsedModels.length > 0 && }
+
+
+ handleSelect('__custom__')}
+ className="cursor-pointer"
+ >
+
+ Enter custom model...
+
+
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx
index 86a8bb9e..26cb232f 100644
--- a/src/components/Shakespeare/ChatPane.tsx
+++ b/src/components/Shakespeare/ChatPane.tsx
@@ -1,7 +1,6 @@
import { useState, useRef, useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
import { Button } from '@/components/ui/button';
-import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Skeleton } from '@/components/ui/skeleton';
import { Send, Settings, Play, CloudUpload, Loader2, MessageSquarePlus, Square } from 'lucide-react';
@@ -10,6 +9,7 @@ import { useFS } from '@/hooks/useFS';
import { useJSRuntime } from '@/hooks/useJSRuntime';
import { useKeepAlive } from '@/hooks/useKeepAlive';
import { useAIChat } from '@/hooks/useAIChat';
+import { ModelSelector } from '@/components/ModelSelector';
import { copyDirectory } from '@/lib/copyFiles';
import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools';
import { bytesToHex } from 'nostr-tools/utils';
@@ -34,11 +34,14 @@ interface ChatPaneProps {
export function ChatPane({ projectId, projectName }: ChatPaneProps) {
const [input, setInput] = useState('');
- const [providerModel, setProviderModel] = useState('openrouter/anthropic/claude-sonnet-4');
const [isBuildLoading, setIsBuildLoading] = useState(false);
const [isDeployLoading, setIsDeployLoading] = useState(false);
const scrollAreaRef = useRef(null);
- const { isConfigured } = useAISettings();
+ const { isConfigured, settings, addRecentlyUsedModel } = useAISettings();
+ const [providerModel, setProviderModel] = useState(() => {
+ // Default to first recently used model or fallback
+ return settings.recentlyUsedModels?.[0] || 'openrouter/anthropic/claude-sonnet-4';
+ });
const { fs: browserFS } = useFS();
const { runtime } = useJSRuntime();
const [searchParams, setSearchParams] = useSearchParams();
@@ -125,10 +128,14 @@ When creating new components or pages, follow the existing patterns in the codeb
setSearchParams(newSearchParams, { replace: true });
// Start AI generation
- startGeneration(providerModel.trim() || undefined);
+ const modelToUse = providerModel.trim() || undefined;
+ if (modelToUse) {
+ addRecentlyUsedModel(modelToUse);
+ }
+ startGeneration(modelToUse);
}
}
- }, [searchParams, setSearchParams, isConfigured, messages, isLoading, startGeneration, providerModel]);
+ }, [searchParams, setSearchParams, isConfigured, messages, isLoading, startGeneration, providerModel, addRecentlyUsedModel]);
// Keep-alive functionality to prevent tab throttling during AI processing
const { updateMetadata } = useKeepAlive({
@@ -247,10 +254,16 @@ BASE_DOMAIN=nostrdeploy.com`);
if (!input.trim() || isLoading) return;
const messageContent = input;
+ const modelToUse = providerModel.trim() || undefined;
setInput('');
+ // Add model to recently used when sending a message
+ if (modelToUse) {
+ addRecentlyUsedModel(modelToUse);
+ }
+
try {
- await sendMessage(messageContent, providerModel.trim() || undefined);
+ await sendMessage(messageContent, modelToUse);
} catch (error) {
console.error('AI chat error:', error);
// Error handling is done in the useAIChat hook
@@ -464,14 +477,14 @@ BASE_DOMAIN=nostrdeploy.com`);
{/* Bottom Controls Row */}