"use client"; import { FolderInputIcon, RefreshCwIcon } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { formatBytes, shortSha } from "@/lib/format"; import { cn } from "@/lib/utils"; import { AddModelForm, type ImportFolder } from "./add-model-form"; type Folder = ImportFolder & { totalBytes: number }; /** * Library header with an "Add model" toggle that opens the lookup/selection form inline, and the * folders in the models folder that aren't in the library yet, each with "Import". */ export function AddModelPanel({ freeBytes, defaultOpen, folders, }: { freeBytes: number | null; defaultOpen: boolean; folders: Folder[]; }) { const router = useRouter(); const [open, setOpen] = useState(defaultOpen); const [importing, setImporting] = useState(null); const [scanning, setScanning] = useState(false); function close() { setOpen(false); setImporting(null); } async function rescan() { setScanning(true); try { const res = await fetch("/api/local-folders/scan", { method: "POST" }); if (!res.ok) { toast.error(`Could not start a scan (${res.status})`); return; } // The worker picks the request up with its next heartbeat (every 5 s). await new Promise((r) => setTimeout(r, 7_000)); router.refresh(); } finally { setScanning(false); } } return ( <>

Library

{open && ( { close(); router.refresh(); }} /> )} {!open && folders.length > 0 && ( Found in the models folder {folders.length} folder{folders.length === 1 ? " isn't" : "s aren't"} in the library yet. Import matches {folders.length === 1 ? " it" : " them"} with the Hub repo and verifies the files instead of downloading them again.
    {folders.map((f) => (
  • {f.path} {f.fileCount} file{f.fileCount === 1 ? "" : "s"} · {formatBytes(f.totalBytes)} {f.commit && <> · hf commit {shortSha(f.commit)}}
  • ))}
)} ); }