Brings back the token API that 0.15 removed with deployments, for models only, ported onto the current code (local models, lean client bundles, MiB-rounded disk space): - Scoped bearer tokens (models:read, downloads:create, models:verify, tags:write), stored as SHA-256, managed in Settings -> API tokens. Only /api/v1 accepts them; the rest stays OIDC-only. - /api/v1: Hub lookup, library with the search filters, download requests through the add-model/queue path (idempotent), repair of missing or broken files, verify / deep verify, tags, job status with ?wait=, cancelling or withdrawing the token's own jobs, disk space. - Guardrails for downloads and repairs: approval (default ask), max size per request, minimum free space incl. reserved bytes, agent jobs at once, author allowlist (new downloads only). Approve/reject in the UI, "requested by" badges and filter, activity log per token. - Migration 0027 adds api_tokens, agent_activity and requested_by columns on models and jobs; job state pending_approval. - docs/api.md, docs/agent/SKILL.md and the kaname curl helper; DB-backed API tests. The login gate test now expects /api/v1 to be left to token auth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
"use client";
|
|
|
|
import { BotIcon, CheckIcon, XIcon } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { approveJob, rejectJob } from "@/components/job-actions";
|
|
import { Button } from "@/components/ui/button";
|
|
import { formatBytes } from "@/lib/format";
|
|
|
|
const WHAT: Record<string, string> = {
|
|
add: " of additional files",
|
|
repair: " to repair missing or broken files",
|
|
};
|
|
|
|
/** A download requested through the API that waits for approval: who asked, how much, approve/reject. */
|
|
export function ApprovalBar({ job, onRemoved }: { job: { id: string; requestedBy: string | null; totalBytes: number; purpose: string | null }; onRemoved?: () => void }) {
|
|
const router = useRouter();
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
async function run(fn: () => Promise<unknown>) {
|
|
setBusy(true);
|
|
try {
|
|
await fn();
|
|
router.refresh();
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-col gap-2 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2.5 text-sm">
|
|
<p className="flex items-center gap-1.5">
|
|
<BotIcon className="size-4 shrink-0 text-amber-700 dark:text-amber-300" />
|
|
<span>
|
|
<strong>{job.requestedBy ?? "An API token"}</strong> asks to download {job.purpose === "repair" ? "up to " : ""}
|
|
{formatBytes(job.totalBytes)}
|
|
{WHAT[job.purpose ?? ""] ?? ""}. It starts once you approve it.
|
|
</span>
|
|
</p>
|
|
<div className="flex gap-2">
|
|
<Button size="sm" disabled={busy} onClick={() => run(() => approveJob(job.id))}>
|
|
<CheckIcon />
|
|
Approve
|
|
</Button>
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
disabled={busy}
|
|
onClick={() =>
|
|
run(async () => {
|
|
const r = await rejectJob(job.id);
|
|
if (r?.removedModel) onRemoved?.();
|
|
})
|
|
}
|
|
>
|
|
<XIcon />
|
|
Reject
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|