Picking model weights in Add model or Download more also selects the files that usually go with them (chat template, MTP head, mmproj, ...), shown in a strip where each can be unchecked. Variants are matched by quant, otherwise the best single one; kinds already selected aren't added twice. Which kinds is set in Settings -> Downloads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
190 lines
7.8 KiB
TypeScript
190 lines
7.8 KiB
TypeScript
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<ModelFileState, { label: string; icon: React.ReactNode; className: string }> = {
|
|
pending: { label: "Not downloaded", icon: <CircleDashedIcon className="size-3.5" />, className: "text-muted-foreground" },
|
|
present: { label: "Downloaded", icon: <CheckCircle2Icon className="size-3.5" />, className: "text-emerald-600 dark:text-emerald-400" },
|
|
verified: { label: "Verified", icon: <ShieldCheckIcon className="size-3.5" />, className: "text-emerald-600 dark:text-emerald-400" },
|
|
missing: { label: "Missing", icon: <XCircleIcon className="size-3.5" />, className: "text-destructive" },
|
|
size_mismatch: { label: "Size mismatch", icon: <AlertTriangleIcon className="size-3.5" />, className: "text-amber-600 dark:text-amber-400" },
|
|
hash_mismatch: { label: "Hash mismatch", icon: <AlertTriangleIcon className="size-3.5" />, 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 <BoxIcon className={cls} />;
|
|
if (ext === "json") return <FileJsonIcon className={cls} />;
|
|
if (["md", "txt"].includes(ext)) return <FileTextIcon className={cls} />;
|
|
if (["png", "jpg", "jpeg", "gif", "webp", "svg"].includes(ext)) return <FileImageIcon className={cls} />;
|
|
return <FileIcon className={cls} />;
|
|
}
|
|
|
|
function FileName({ path }: { path: string }) {
|
|
const slash = path.lastIndexOf("/");
|
|
return (
|
|
<span className="min-w-0 truncate font-mono text-[13px]" title={path}>
|
|
{slash >= 0 && <span className="text-muted-foreground">{path.slice(0, slash + 1)}</span>}
|
|
{path.slice(slash + 1)}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
type Entry = FileGroup<FileRow>;
|
|
|
|
/** 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 (
|
|
<li>
|
|
<a
|
|
href={href}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
title={split ? entry.parts.map((p) => 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",
|
|
)}
|
|
>
|
|
<FileTypeIcon path={entry.path} />
|
|
<FileRoleBadge path={entry.path} className={muted ? "opacity-70" : undefined} />
|
|
<span className="flex min-w-0 items-center gap-2">
|
|
<FileName path={entry.path} />
|
|
{split && (
|
|
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">
|
|
{entry.parts.length === entry.totalParts
|
|
? `${entry.totalParts} parts`
|
|
: `${entry.parts.length} of ${entry.totalParts} parts`}
|
|
</span>
|
|
)}
|
|
{entry.parts[0].lfsSha256 && (
|
|
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">LFS</span>
|
|
)}
|
|
</span>
|
|
<span className="hidden text-right text-sm tabular-nums sm:block">{formatBytes(entry.size)}</span>
|
|
{showState ? (
|
|
<span className={cn("flex items-center justify-end gap-1.5 text-xs whitespace-nowrap", state.className)}>
|
|
{state.icon}
|
|
<span className="hidden md:inline">{label}</span>
|
|
</span>
|
|
) : (
|
|
<span className="text-right text-sm tabular-nums sm:hidden">{formatBytes(entry.size)}</span>
|
|
)}
|
|
</a>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
/** "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 (
|
|
<div>
|
|
<FilesHeader
|
|
modelId={modelId}
|
|
sha={sha}
|
|
selectedCount={selectedEntries.length}
|
|
totalBytes={totalBytes}
|
|
localCount={localEntries.length}
|
|
localBytes={localBytes}
|
|
candidates={others.map((f) => ({ path: f.path, size: f.size }))}
|
|
selectedPaths={selected.map((f) => f.path)}
|
|
freeBytes={freeBytes}
|
|
busy={busy}
|
|
hubMissing={hubMissing}
|
|
/>
|
|
|
|
<ul className="divide-y">
|
|
{selectedEntries.map((e) => (
|
|
<Row key={e.path} entry={e} href={href(e)} showState />
|
|
))}
|
|
</ul>
|
|
|
|
{otherEntries.length > 0 && (
|
|
<details className="group border-t">
|
|
<summary className="flex cursor-pointer list-none items-center gap-2 px-5 py-3 text-sm hover:bg-muted/50">
|
|
<ChevronRightIcon className="size-4 text-muted-foreground transition-transform group-open:rotate-90" />
|
|
<span className="font-medium">Not selected</span>
|
|
<span className="text-muted-foreground">
|
|
{otherEntries.length} file{otherEntries.length === 1 ? "" : "s"} ·{" "}
|
|
{formatBytes(others.reduce((s, f) => s + f.size, 0))}
|
|
</span>
|
|
</summary>
|
|
<ul className="divide-y border-t">
|
|
{otherEntries.map((e) => (
|
|
<Row key={e.path} entry={e} href={href(e)} muted showState={false} />
|
|
))}
|
|
</ul>
|
|
</details>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|