"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 { toast } from "sonner"; import { formatBytes } from "@/lib/format"; /** 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) { setBusy(true); try { await fn(); router.refresh(); } finally { setBusy(false); } } return (

{job.requestedBy ?? "An API token"} asks to download {formatBytes(job.totalBytes)} {job.purpose === "add" ? " of additional files" : ""}. It starts once you approve it.

); } /** Something else an API token asked for (a deployment start, a run, a sweep): approve or reject. */ export function AgentApprovalBar({ requestedBy, what, base }: { requestedBy: string | null; what: string; base: string }) { const router = useRouter(); const [busy, setBusy] = useState(false); async function decide(kind: "approve" | "reject") { setBusy(true); try { const res = await fetch(`${base}/${kind}`, { method: "POST" }); if (!res.ok) { const body = await res.json().catch(() => ({})); toast.error(body.error?.message ?? `Request failed (${res.status})`); return; } toast.success(kind === "approve" ? "Approved" : "Rejected"); router.refresh(); } finally { setBusy(false); } } return (

{requestedBy ?? "An API token"} asks to {what}. It goes ahead once you approve it.

); }