"use client"; import { DownloadIcon } from "lucide-react"; import Link from "next/link"; import { useState } from "react"; import { cancelJob, startDownload } from "@/components/job-actions"; import { JobProgress, JobStateBadge } from "@/components/job-progress"; import { Button } from "@/components/ui/button"; import { Progress } from "@/components/ui/progress"; import { useLive } from "@/hooks/use-live"; import type { ModelStatus } from "@/lib/db/schema"; import { groupJobFiles } from "@/lib/file-groups"; import { formatBytes, percent } from "@/lib/format"; const OPEN = ["queued", "downloading", "verifying"]; /** Sidebar card: current download state, actions and (while running) per-file progress. */ export function DownloadCard({ modelId, status, hubMissing, }: { modelId: string; status: ModelStatus; /** The repo or pinned commit is gone from the Hub; no new downloads. */ hubMissing: boolean; }) { const { snapshot } = useLive({ model: modelId }); const [busy, setBusy] = useState(false); const latest = snapshot?.jobs[0]; const open = latest && OPEN.includes(latest.state) ? latest : undefined; const files = open ? groupJobFiles(snapshot?.files ?? []) : []; async function run(fn: () => Promise) { setBusy(true); try { await fn(); } finally { setBusy(false); } } let hint = "Downloads the selected files at the pinned commit."; if (open?.state === "queued") hint = snapshot?.worker.online ? "Waiting for a free download slot." : "Queued, but the worker is offline."; else if (open) hint = "Runs in the background; you can close this page."; else if (status === "ready") hint = "All selected files are present."; else if (hubMissing) hint = "Can't download: no longer available on Hugging Face. Local files are kept."; return (

Download

{latest && }

{hint}

{latest && !(latest.state === "completed" && status === "ready") && } {latest?.state === "failed" && latest.errorMessage && (
          {latest.errorMessage}
        
)} {files.length > 0 && (
    {files.map((f) => (
  • {f.path} {f.parts > 1 && · {f.parts} parts} {formatBytes(f.expectedBytes)}
  • ))}
)}
{open ? ( ) : ( status !== "ready" && !hubMissing && snapshot && ( ) )} {latest && ( View log )}
); }