"use client" import { AlertCircle, Check, ChevronRight, Eye, EyeOff, Key, Loader2, Plus, RefreshCw, Server, Settings2, Sparkles, Trash2, X, Zap, } from "lucide-react" import { useCallback, useEffect, useRef, useState } from "react" import { ProviderCredentialsFields, type SecretField, } from "@/components/provider-credentials-fields" import { ProviderLogo } from "@/components/provider-logo" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" import { Command, CommandEmpty, CommandInput, CommandItem, CommandList, } from "@/components/ui/command" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { ScrollArea } from "@/components/ui/scroll-area" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Switch } from "@/components/ui/switch" import { useDictionary } from "@/hooks/use-dictionary" import type { UseModelConfigReturn } from "@/hooks/use-model-config" import { getApiEndpoint } from "@/lib/base-path" import { formatMessage } from "@/lib/i18n/utils" import type { ListedModel } from "@/lib/provider-models" import { STORAGE_KEYS } from "@/lib/storage" import type { ModelConfig, ProviderConfig, ProviderName, } from "@/lib/types/model-config" import { PROVIDER_INFO, SUGGESTED_MODELS } from "@/lib/types/model-config" import { cn } from "@/lib/utils" interface ModelConfigDialogProps { open: boolean modelConfig: UseModelConfigReturn } type ValidationStatus = "idle" | "validating" | "success" | "error" // Configuration section with title and optional action function ConfigSection({ title, icon: Icon, action, children, }: { title: string icon: React.ComponentType<{ className?: string }> action?: React.ReactNode children: React.ReactNode }) { return (
{dict.modelConfig.addProviderHint}
{selectedProvider.models .length === 0 ? dict.modelConfig .noModelsConfigured : formatMessage( dict.modelConfig .modelsConfiguredCount, { count: selectedProvider .models .length, }, )}
{duplicateError}
)}{fetchModelsError}
)} {/* Model List */}{ dict.modelConfig .noModelsConfigured }
{emptyStateSuggestions.length > 0 && ({ model.validationError }
)} {!model.validationWarning && getModelInfo?.( selectedProvider.provider, model.modelId, )?.tools === false && ({ dict .modelConfig .mayNotDraw }
)} {model.validated && model.validationWarning && ({ model.validationWarning }
)} {/* Show edit error inline */} {editError?.modelId === model.id && ({ editError.message }
)}{config.providers.length === 0 ? dict.modelConfig.noProvidersHint : dict.modelConfig.selectProviderHint}