- Delete any model (incl. failed ones); the worker removes the repo's files (keeps foreign files and empty-folder cleanup), then the rows. - Verify (existence, size, hf metadata) and deep verify (SHA-256 / git blob SHA-1 against the Hub) with missing/mismatch/extra report. - Repair = download of the selection; broken files are deleted first because hf skips files whose metadata matches without checking them. - Hub check resolves the tracked revision and stores which selected files a newer commit changes/adds/removes; Update pins it (old commit kept in model_revisions), downloads, then removes dropped files. - Worker runs verify/delete jobs next to downloads (2 local slots). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
122 lines
4.6 KiB
TypeScript
122 lines
4.6 KiB
TypeScript
"use client";
|
|
|
|
import { ArrowUpCircleIcon } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { startUpdate } from "@/components/job-actions";
|
|
import { LocalTime } from "@/components/local-time";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
AlertDialogTrigger,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import type { UpdateDiff, UpdateDiffFile } from "@/lib/db/schema";
|
|
import { formatBytes, shortSha } from "@/lib/format";
|
|
|
|
function FileGroup({ title, files, tone }: { title: string; files: UpdateDiffFile[]; tone: string }) {
|
|
if (files.length === 0) return null;
|
|
return (
|
|
<div className="flex flex-col gap-0.5">
|
|
<span className={`text-xs font-medium ${tone}`}>
|
|
{title} ({files.length})
|
|
</span>
|
|
<ul className="flex flex-col gap-0.5 text-xs">
|
|
{files.slice(0, 20).map((f) => (
|
|
<li key={f.path} className="flex justify-between gap-3">
|
|
<span className="font-mono break-all">{f.path}</span>
|
|
<span className="shrink-0 text-muted-foreground tabular-nums">
|
|
{f.oldSize != null && f.oldSize !== f.size ? `${formatBytes(f.oldSize)} → ` : ""}
|
|
{formatBytes(f.size)}
|
|
</span>
|
|
</li>
|
|
))}
|
|
{files.length > 20 && <li className="text-muted-foreground">… {files.length - 20} more</li>}
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/** "Update available": what would change in the selection, and the deliberate Update action. */
|
|
export function UpdateBanner({
|
|
modelId,
|
|
revision,
|
|
pinnedSha,
|
|
diff,
|
|
hubUrl,
|
|
}: {
|
|
modelId: string;
|
|
revision: string;
|
|
pinnedSha: string;
|
|
diff: UpdateDiff;
|
|
hubUrl: string;
|
|
}) {
|
|
const router = useRouter();
|
|
const [busy, setBusy] = useState(false);
|
|
const changes = diff.changed.length + diff.added.length + diff.removed.length;
|
|
const download = [...diff.changed, ...diff.added].reduce((s, f) => s + f.size, 0);
|
|
|
|
async function update() {
|
|
setBusy(true);
|
|
try {
|
|
if (await startUpdate(modelId)) router.refresh();
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-col gap-3 rounded-xl border border-sky-500/30 bg-sky-500/10 px-4 py-3 text-sm">
|
|
<div className="flex flex-wrap items-start gap-3">
|
|
<ArrowUpCircleIcon className="mt-0.5 size-4 shrink-0 text-sky-600 dark:text-sky-400" />
|
|
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
|
<p className="font-medium text-sky-900 dark:text-sky-100">
|
|
Update available: {revision} is at{" "}
|
|
<a href={`${hubUrl}/commit/${diff.sha}`} target="_blank" rel="noreferrer" className="font-mono hover:underline">
|
|
{shortSha(diff.sha)}
|
|
</a>
|
|
</p>
|
|
<p className="text-muted-foreground">
|
|
You have <span className="font-mono">{shortSha(pinnedSha)}</span>.{" "}
|
|
{changes === 0
|
|
? "None of your selected files changed; updating only moves the pin."
|
|
: `${changes} of your selected files would change (${formatBytes(download)} to download).`}{" "}
|
|
Checked <LocalTime value={diff.checkedAt} />.
|
|
</p>
|
|
</div>
|
|
<AlertDialog>
|
|
<AlertDialogTrigger render={<Button size="sm" disabled={busy} />}>Update</AlertDialogTrigger>
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Update to {shortSha(diff.sha)}?</AlertDialogTitle>
|
|
<AlertDialogDescription>
|
|
The model is pinned to the new commit (the old one stays in the history) and changed or new files are
|
|
downloaded. Files that are no longer part of your selection are deleted after the download succeeded.
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction onClick={update} disabled={busy}>
|
|
Update
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div>
|
|
{changes > 0 && (
|
|
<div className="grid gap-3 rounded-lg bg-background/60 px-3 py-2.5 md:grid-cols-3">
|
|
<FileGroup title="Changed" files={diff.changed} tone="text-amber-700 dark:text-amber-300" />
|
|
<FileGroup title="Added" files={diff.added} tone="text-emerald-700 dark:text-emerald-300" />
|
|
<FileGroup title="Removed" files={diff.removed} tone="text-destructive" />
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|