"use client"; import { ShieldCheckIcon } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { NativeSelect } from "@/components/ui/native-select"; import { type ApprovalMode, type Guardrails, parseAuthorList } from "@/lib/agent-guardrails"; const GB = 1_000_000_000; const toGb = (b: number) => String(Math.round((b / GB) * 1000) / 1000); /** Limits for downloads requested through the API. Saved together with one button. */ export function GuardrailSettings({ initial }: { initial: Guardrails }) { const router = useRouter(); const [mode, setMode] = useState(initial.approvalMode); const [maxGb, setMaxGb] = useState(toGb(initial.maxRequestBytes)); const [minFreeGb, setMinFreeGb] = useState(toGb(initial.minFreeBytes)); const [maxJobs, setMaxJobs] = useState(String(initial.maxOpenJobs)); const [authors, setAuthors] = useState(initial.allowedAuthors.join(", ")); const [busy, setBusy] = useState(false); let authorError: string | null = null; let authorList: string[] = []; try { authorList = parseAuthorList(authors); } catch (err) { authorError = err instanceof Error ? err.message : String(err); } const num = (s: string) => Number(s.replace(",", ".")); async function save(e: React.FormEvent) { e.preventDefault(); if (authorError) return; setBusy(true); try { const res = await fetch("/api/settings/agent", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ approvalMode: mode, maxRequestBytes: Math.round(num(maxGb) * GB), minFreeBytes: Math.round(num(minFreeGb) * GB), maxOpenJobs: Math.round(num(maxJobs)), allowedAuthors: authorList, }), }); const json = await res.json().catch(() => ({})); if (!res.ok) return toast.error(json.error?.message ?? `Could not save (${res.status})`); toast.success("Guardrails saved"); router.refresh(); } finally { setBusy(false); } } return ( Guardrails for API downloads Apply to every download requested with a token, across all tokens. Downloads you start in the UI are not affected.
setMode(e.target.value as ApprovalMode)} className="max-w-md">
setMaxGb(e.target.value.replace(/[^\d.,]/g, ""))} inputMode="decimal" />
setMinFreeGb(e.target.value.replace(/[^\d.,]/g, ""))} inputMode="decimal" />
setMaxJobs(e.target.value.replace(/\D/g, ""))} inputMode="numeric" />
setAuthors(e.target.value)} placeholder="Empty: any author. e.g. unsloth, ggml-org, Qwen" aria-invalid={!!authorError} />

{authorError ?? "Hugging Face users or organizations (the part before the slash), comma-separated."}

“Agent jobs at once” counts requests that are pending approval, queued or downloading. The free-space check also subtracts what other open downloads still need.

); }