"use client"; import { useState } from "react"; import { useAtomValue } from "jotai/react"; import { availableModelsAtom } from "@/store/chat"; import { ChevronDown, Check } from "lucide-react"; import { cn } from "@/lib/utils"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, } from "@/components/ui/command"; function formatModelLabel(id: string): string { const parts = id.split("/"); return parts.length > 1 ? parts.slice(1).join("/") : id; } function formatProvider(id: string): string { const parts = id.split("/"); if (parts.length > 1) return parts[0]; return ""; } interface ModelSelectorProps { value: string; onChange: (model: string) => void; } export function ModelSelector({ value, onChange }: ModelSelectorProps) { const [open, setOpen] = useState(false); const models = useAtomValue(availableModelsAtom); const providers = new Map(); for (const m of models) { const provider = formatProvider(m.id) || "other"; if (!providers.has(provider)) providers.set(provider, []); providers.get(provider)!.push(m); } return ( No models found. {models.length > 0 ? ( Array.from(providers.entries()).map(([provider, providerModels]) => ( {providerModels.map((m) => ( { onChange(m.id); setOpen(false); }} > {formatModelLabel(m.id)} ))} )) ) : ( setOpen(false)}> {value} )} ); }