import { useRef } from "react"; import { Check, Cloud, KeyRound, Laptop } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { cn } from "@/lib/utils"; import type { ModelSetupAvailability, ModelSetupIntent } from "@/lib/model-setup"; const SETUP_OPTIONS = [ { intent: "account", icon: Cloud, titleKey: "thread.composer.modelSetup.account.title", title: "Connect an account", descriptionKey: "thread.composer.modelSetup.account.description", description: "Use a supported AI subscription.", }, { intent: "apiKey", icon: KeyRound, titleKey: "thread.composer.modelSetup.apiKey.title", title: "Use an API key", descriptionKey: "thread.composer.modelSetup.apiKey.description", description: "Bring a key from your preferred provider.", }, { intent: "local", icon: Laptop, titleKey: "thread.composer.modelSetup.local.title", title: "Run locally", descriptionKey: "thread.composer.modelSetup.local.description", description: "Connect Ollama, LM Studio, or vLLM.", }, ] as const; export function ModelSetupDialog({ availability, open, onOpenChange, onReturnFocus, onSelect, }: { availability: ModelSetupAvailability; open: boolean; onOpenChange: (open: boolean) => void; onReturnFocus: () => void; onSelect: (intent: ModelSetupIntent) => void; }) { const { t } = useTranslation(); const selectedRef = useRef(false); return ( { if (nextOpen) selectedRef.current = false; onOpenChange(nextOpen); }} > { event.preventDefault(); if (!selectedRef.current) onReturnFocus(); selectedRef.current = false; }} > {t("thread.composer.modelSetup.title", { defaultValue: "Choose your AI" })} {t("thread.composer.modelSetup.description", { defaultValue: "Pick a starting point. You can change models at any time.", })}
{SETUP_OPTIONS.map((option) => { const Icon = option.icon; const ready = availability[option.intent]; return ( ); })}
); }