Files
Kaname/src/lib/api-v1-filters.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

27 lines
877 B
TypeScript

// Query-string filters for GET /api/v1/models, with the library's search semantics
// (terms AND-ed in `q`; OR within a facet, AND across facets). Pure.
import { EMPTY_FILTERS, type Facet, type Filters } from "@/lib/search";
/** Query parameter per facet; each may repeat or hold a comma-separated list. */
const PARAM: Record<Facet, string> = {
author: "author",
family: "family",
quant: "quant",
tag: "tag",
status: "status",
requester: "requested_by",
};
export function parseModelFilters(params: URLSearchParams): { query: string; filters: Filters } {
const filters = { ...EMPTY_FILTERS };
for (const facet of Object.keys(PARAM) as Facet[]) {
filters[facet] = params
.getAll(PARAM[facet])
.flatMap((v) => v.split(","))
.map((v) => v.trim())
.filter(Boolean);
}
return { query: params.get("q")?.trim() ?? "", filters };
}