import { useState } from "react"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useAiSettings, useSaveAiSettings, useOllamaModels } from "@/hooks/use-ai"; import { Settings, RefreshCw, Loader2 } from "lucide-react"; import { toast } from "sonner"; export function AiSettingsPopover() { const { data: settings } = useAiSettings(); const saveMutation = useSaveAiSettings(); const [url, setUrl] = useState(null); const [model, setModel] = useState(null); const currentUrl = url ?? settings?.ollama_url ?? "http://localhost:11434"; const currentModel = model ?? settings?.model ?? ""; const { data: models, isLoading: modelsLoading, isError: modelsError, refetch: refetchModels, } = useOllamaModels(currentUrl); const handleSave = () => { saveMutation.mutate( { ollama_url: currentUrl, model: currentModel }, { onSuccess: () => toast.success("AI settings saved"), onError: (err) => toast.error("Failed to save AI settings", { description: String(err), }), } ); }; return (

Ollama Settings

setUrl(e.target.value)} placeholder="http://localhost:11434" className="h-8 text-xs" />
{modelsError ? (

Cannot connect to Ollama

) : ( )}
); }