Files
Kaname/src/app/api/settings/agent/route.ts
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

31 lines
1014 B
TypeScript

import { NextResponse } from "next/server";
import { z } from "zod";
import { APPROVAL_MODES } from "@/lib/agent-guardrails";
import { withAuth } from "@/lib/api-auth";
import { apiError, handleApiError } from "@/lib/api-errors";
import { getGuardrails, saveGuardrails, SettingsError } from "@/lib/settings";
export const dynamic = "force-dynamic";
/** Guardrails for downloads requested through the API. */
export const GET = withAuth(async () => NextResponse.json(await getGuardrails()));
const Body = z
.object({
approvalMode: z.enum(APPROVAL_MODES),
maxRequestBytes: z.number(),
minFreeBytes: z.number(),
maxOpenJobs: z.number().int(),
allowedAuthors: z.array(z.string()).max(100),
})
.partial();
export const PUT = withAuth(async (req) => {
try {
return NextResponse.json(await saveGuardrails(Body.parse(await req.json())));
} catch (err) {
if (err instanceof SettingsError) return apiError(err.status, err.code, err.message);
return handleApiError(err);
}
});