Files
Kaname/src/components/job-progress.tsx
T
Pascal LinxweilerandClaude Opus 5.5 7b1c8070b3 API for agents: tokens, /api/v1, guardrails, approval
- Scoped bearer tokens (models:read, downloads:create), stored as SHA-256, managed in
  Settings -> API tokens. Only /api/v1 accepts them; the rest stays OIDC-only.
- /api/v1: Hub lookup, library list with the search filters, download requests through the
  existing add-model/queue path (idempotent), compact job status, disk space.
- Guardrails: approval mode (default approve), max size per request, minimum free space incl.
  reserved bytes, max open agent jobs, author allowlist. Approve/reject in the UI; "requested by"
  shown and filterable.
- docs/api.md (incl. Traefik forward-auth bypass), docs/agent/SKILL.md, DB-backed API tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 16:14:45 +02:00

49 lines
1.8 KiB
TypeScript

import { Badge } from "@/components/ui/badge";
import { Progress } from "@/components/ui/progress";
import { formatBytes, formatDuration, formatSpeed, percent } from "@/lib/format";
import type { JobSnapshot } from "@/lib/jobs";
const STATE_VARIANT: Record<string, "default" | "secondary" | "destructive" | "outline"> = {
pending_approval: "outline",
queued: "outline",
downloading: "secondary",
verifying: "secondary",
completed: "default",
failed: "destructive",
cancelled: "outline",
interrupted: "destructive",
};
export function JobStateBadge({ job }: { job: Pick<JobSnapshot, "state" | "cancelRequested"> }) {
const label =
job.cancelRequested && !["cancelled", "completed", "failed"].includes(job.state)
? "cancelling"
: job.state === "pending_approval"
? "awaiting approval"
: job.state;
return <Badge variant={STATE_VARIANT[job.state] ?? "outline"}>{label}</Badge>;
}
/** Overall progress line for a job: bar, bytes, %, speed, ETA. */
export function JobProgress({ job, compact = false }: { job: JobSnapshot; compact?: boolean }) {
const pct = percent(job.doneBytes, job.totalBytes);
const running = job.state === "downloading" || job.state === "verifying";
return (
<div className="flex min-w-0 flex-col gap-1.5">
<Progress value={pct} />
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground tabular-nums">
{!compact && <JobStateBadge job={job} />}
<span>
{formatBytes(job.doneBytes)} / {formatBytes(job.totalBytes)} · {pct.toFixed(1)}%
</span>
{running && (
<>
<span>{formatSpeed(job.speedBps)}</span>
<span>ETA {formatDuration(job.etaSeconds)}</span>
</>
)}
</div>
</div>
);
}