Files
Kaname/src/app/api/v1/models/[id]/verify/route.ts
T
Pascal LinxweilerandClaude Opus 5.5 0e0445a418 API for agents: tokens, /api/v1 for downloads, verify, repair, tags
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>
2026-11-11 21:52:28 +01:00

22 lines
888 B
TypeScript

import { z } from "zod";
import { act } from "@/lib/agent-activity";
import { requestVerify } from "@/lib/agent-downloads";
import { withToken } from "@/lib/api-tokens";
import { optionalJson, v1Catch, v1Json } from "@/lib/api-v1";
export const dynamic = "force-dynamic";
const Body = z.object({ deep: z.boolean().optional() }).strict();
/** Check the model's selected files: presence and size, or with {"deep": true} their hashes. */
export const POST = withToken<RouteContext<"/api/v1/models/[id]/verify">>("models:verify", async (req, { params, token }) => {
try {
const { id } = await params;
const { deep = false } = Body.parse(await optionalJson(req));
const r = await act(token, deep ? "model.deep_verify" : "model.verify", { type: "model", id }, () => requestVerify(token, id, deep));
return v1Json(r, 201);
} catch (err) {
return v1Catch(err);
}
});