"use client"; import { RefreshCwIcon } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; /** Check the Hub right now: repo and pinned commit still there, newer commit on the tracked revision. */ export function HubCheckButton({ modelId, label = "Check now" }: { modelId: string; label?: string }) { const router = useRouter(); const [busy, setBusy] = useState(false); async function check() { setBusy(true); try { const res = await fetch(`/api/models/${modelId}/hub-check`, { method: "POST" }); const json = await res.json().catch(() => ({})); if (!res.ok) toast.error(json.error?.message ?? `Check failed (${res.status})`); else if (json.state === "available" && json.update) toast.info("Update available"); else if (json.state === "available") toast.success(json.warning ?? "Up to date"); else if (json.state === "repo_missing") toast.warning("The repo is no longer on Hugging Face"); else if (json.state === "commit_missing") toast.warning("The pinned commit is no longer on Hugging Face"); else toast.error(`Could not check: ${json.error ?? "unknown error"}`); router.refresh(); } finally { setBusy(false); } } return ( ); }