import { AlertTriangleIcon, BoxIcon, CheckCircle2Icon, ChevronRightIcon, CircleDashedIcon, FileIcon, FileImageIcon, FileJsonIcon, FileTextIcon, ShieldCheckIcon, XCircleIcon, } from "lucide-react"; import { FileRoleBadge } from "@/components/labels"; import type { ModelFileState } from "@/lib/db/schema"; import { formatBytes } from "@/lib/format"; import { type FileGroup, groupSplitFiles } from "@/lib/file-groups"; import { cn } from "@/lib/utils"; import { FilesHeader } from "./download-more"; type FileRow = { id: string; path: string; size: number; lfsSha256: string | null; state: ModelFileState }; const STATE: Record = { pending: { label: "Not downloaded", icon: , className: "text-muted-foreground" }, present: { label: "Downloaded", icon: , className: "text-emerald-600 dark:text-emerald-400" }, verified: { label: "Verified", icon: , className: "text-emerald-600 dark:text-emerald-400" }, missing: { label: "Missing", icon: , className: "text-destructive" }, size_mismatch: { label: "Size mismatch", icon: , className: "text-amber-600 dark:text-amber-400" }, hash_mismatch: { label: "Hash mismatch", icon: , className: "text-amber-600 dark:text-amber-400" }, }; function FileTypeIcon({ path }: { path: string }) { const ext = path.toLowerCase().split(".").pop() ?? ""; const cls = "size-4 text-muted-foreground"; if (["gguf", "safetensors", "bin", "pt", "onnx"].includes(ext)) return ; if (ext === "json") return ; if (["md", "txt"].includes(ext)) return ; if (["png", "jpg", "jpeg", "gif", "webp", "svg"].includes(ext)) return ; return ; } function FileName({ path }: { path: string }) { const slash = path.lastIndexOf("/"); return ( {slash >= 0 && {path.slice(0, slash + 1)}} {path.slice(slash + 1)} ); } type Entry = FileGroup; /** One status for a whole entry (all parts of a split file). */ function entryState(e: Entry): { state: ModelFileState; label: string } { const states = e.parts.map((p) => p.state); const done = states.filter((st) => st === "present" || st === "verified").length; const worst = (["missing", "hash_mismatch", "size_mismatch"] as const).find((st) => states.includes(st)); if (worst) return { state: worst, label: STATE[worst].label }; if (done === states.length) { const state = states.every((st) => st === "verified") ? "verified" : "present"; return { state, label: STATE[state].label }; } if (done > 0) return { state: "pending", label: `${done} of ${states.length} parts` }; return { state: "pending", label: STATE.pending.label }; } const isLocal = (e: Entry) => e.parts.every((p) => p.state === "present" || p.state === "verified"); function Row({ entry, href, muted, showState }: { entry: Entry; href: string; muted?: boolean; showState: boolean }) { const { state: stateKey, label } = entryState(entry); const state = STATE[stateKey]; const split = entry.totalParts > 1; return (
  • p.path).join("\n") : undefined} className={cn( // Fixed status column so sizes line up between selected and unselected rows. "grid grid-cols-[1rem_auto_minmax(0,1fr)_auto] items-center gap-x-3 px-5 py-2.5 transition-colors hover:bg-muted/50 sm:grid-cols-[1rem_auto_minmax(0,1fr)_5rem_1rem] md:grid-cols-[1rem_auto_minmax(0,1fr)_5rem_7.5rem]", muted && "text-muted-foreground", )} > {split && ( {entry.parts.length === entry.totalParts ? `${entry.totalParts} parts` : `${entry.parts.length} of ${entry.totalParts} parts`} )} {entry.parts[0].lfsSha256 && ( LFS )} {formatBytes(entry.size)} {showState ? ( {state.icon} {label} ) : ( {formatBytes(entry.size)} )}
  • ); } /** "Files and versions"-style list: selected files with their local state, the rest collapsed. */ export function FilesTab({ modelId, repoId, sha, selected, others, freeBytes, busy, hubMissing, }: { modelId: string; repoId: string; sha: string; selected: FileRow[]; others: FileRow[]; freeBytes: number | null; busy: boolean; hubMissing: boolean; }) { const hub = `https://huggingface.co/${repoId}`; // Split files link to their folder (all parts), single files to the file itself. const href = (e: Entry) => { const dir = e.path.includes("/") ? e.path.slice(0, e.path.lastIndexOf("/")) : null; return e.totalParts > 1 && dir ? `${hub}/tree/${sha}/${dir}` : `${hub}/blob/${sha}/${e.parts[0].path}`; }; const selectedEntries = groupSplitFiles(selected); const otherEntries = groupSplitFiles(others); const totalBytes = selected.reduce((s, f) => s + f.size, 0); const localEntries = selectedEntries.filter(isLocal); const localBytes = selected.filter((f) => f.state === "present" || f.state === "verified").reduce((s, f) => s + f.size, 0); return (
    ({ path: f.path, size: f.size }))} selectedPaths={selected.map((f) => f.path)} freeBytes={freeBytes} busy={busy} hubMissing={hubMissing} />
      {selectedEntries.map((e) => ( ))}
    {otherEntries.length > 0 && (
    Not selected {otherEntries.length} file{otherEntries.length === 1 ? "" : "s"} ยท{" "} {formatBytes(others.reduce((s, f) => s + f.size, 0))}
      {otherEntries.map((e) => ( ))}
    )}
    ); }