mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add Manage Providers option into model dropdown
This commit is contained in:
2 files changed
+65
-31
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import { Check, ChevronDown, Edit3, RefreshCw, AlertCircle } from 'lucide-react';
|
||||
import { Check, ChevronDown, Edit3, RefreshCw, AlertCircle, Settings } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
@@ -8,6 +8,7 @@ import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useProviderModels } from '@/hooks/useProviderModels';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { AISettingsDialog } from '@/components/ai/AISettingsDialog';
|
||||
|
||||
interface ModelSelectorProps {
|
||||
value: string;
|
||||
@@ -27,6 +28,7 @@ export function ModelSelector({
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isCustomInput, setIsCustomInput] = useState(false);
|
||||
const [customValue, setCustomValue] = useState('');
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const { settings, addRecentlyUsedModel } = useAISettings();
|
||||
const { models, isLoading, error, refetch } = useProviderModels();
|
||||
|
||||
@@ -55,6 +57,12 @@ export function ModelSelector({
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedValue === '__manage_providers__') {
|
||||
setSettingsOpen(true);
|
||||
setOpen(false);
|
||||
return;
|
||||
}
|
||||
|
||||
onChange(selectedValue);
|
||||
addRecentlyUsedModel(selectedValue);
|
||||
setOpen(false);
|
||||
@@ -104,29 +112,34 @@ export function ModelSelector({
|
||||
}
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className={cn(
|
||||
"h-8 justify-between text-xs border-0 bg-transparent hover:bg-transparent hover:text-foreground focus-visible:ring-0 focus-visible:ring-offset-0 text-muted-foreground text-right",
|
||||
className
|
||||
)}
|
||||
disabled={disabled}
|
||||
>
|
||||
<span className="w-full truncate">
|
||||
{value || placeholder}
|
||||
</span>
|
||||
<ChevronDown className="ml-2 h-3 w-3 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<>
|
||||
<AISettingsDialog
|
||||
open={settingsOpen}
|
||||
onOpenChange={setSettingsOpen}
|
||||
/>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className={cn(
|
||||
"h-8 justify-between text-xs border-0 bg-transparent hover:bg-transparent hover:text-foreground focus-visible:ring-0 focus-visible:ring-offset-0 text-muted-foreground text-right",
|
||||
className
|
||||
)}
|
||||
disabled={disabled}
|
||||
>
|
||||
<span className="w-full truncate">
|
||||
{value || placeholder}
|
||||
</span>
|
||||
<ChevronDown className="ml-2 h-3 w-3 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80 p-0" align="end">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search models..." className="h-9" />
|
||||
<CommandList className="max-h-[300px]">
|
||||
{/* Custom model option - always visible at the top */}
|
||||
{/* Custom model option and manage providers - always visible at the top */}
|
||||
<CommandGroup>
|
||||
<CommandItem
|
||||
value="__custom_model_option__"
|
||||
@@ -136,6 +149,14 @@ export function ModelSelector({
|
||||
<Edit3 className="mr-2 h-4 w-4" />
|
||||
Enter custom model...
|
||||
</CommandItem>
|
||||
<CommandItem
|
||||
value="__manage_providers_option__"
|
||||
onSelect={() => handleSelect('__manage_providers__')}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<Settings className="mr-2 h-4 w-4" />
|
||||
Manage providers...
|
||||
</CommandItem>
|
||||
</CommandGroup>
|
||||
|
||||
<CommandSeparator />
|
||||
@@ -234,5 +255,6 @@ export function ModelSelector({
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -57,9 +57,18 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
}
|
||||
];
|
||||
|
||||
export function AISettingsDialog() {
|
||||
interface AISettingsDialogProps {
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISettingsDialogProps = {}) {
|
||||
const { settings, updateSettings, isConfigured } = useAISettings();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [internalOpen, setInternalOpen] = useState(false);
|
||||
|
||||
// Use controlled or internal state
|
||||
const open = controlledOpen !== undefined ? controlledOpen : internalOpen;
|
||||
const setOpen = onOpenChange || setInternalOpen;
|
||||
const [localProviders, setLocalProviders] = useState(settings.providers);
|
||||
const [customProviderName, setCustomProviderName] = useState('');
|
||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||
@@ -126,15 +135,18 @@ export function AISettingsDialog() {
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="gap-2">
|
||||
<Settings className="h-4 w-4" />
|
||||
AI Settings
|
||||
{!isConfigured && (
|
||||
<span className="ml-1 h-2 w-2 rounded-full bg-red-500" />
|
||||
)}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
{/* Only show trigger if not controlled externally */}
|
||||
{controlledOpen === undefined && (
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="gap-2">
|
||||
<Settings className="h-4 w-4" />
|
||||
AI Settings
|
||||
{!isConfigured && (
|
||||
<span className="ml-1 h-2 w-2 rounded-full bg-red-500" />
|
||||
)}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
)}
|
||||
<DialogContent className="sm:max-w-[700px] max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>AI Settings</DialogTitle>
|
||||
|
||||
Reference in new issue
Block a user