Milestone (b): repo lookup and file selection

- Hub API client: resolve revision to SHA, paginated recursive file tree,
  gated-access probe, readable error mapping
- Add-model page with quant quick-select, fnmatch-compatible include/exclude
  globs, selection summary and free-space hint
- Models stored pinned to the reviewed SHA with full file list and selection rule
- Library list, model detail page, remove (never-downloaded models only)
- Worker reports MODELS_DIR free space; unit tests for selection logic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-05 15:39:45 +02:00
1 parent 891e496157
commit 8f7ac60ccf
35 files changed
+2567 -19

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { withAuth } from "@/lib/api-auth";
import { handleApiError } from "@/lib/api-errors";
import { lookupRepo, normalizeRepoInput } from "@/lib/hub/lookup";
const Body = z.object({
repo: z.string().trim().min(1),
revision: z.string().trim().optional(),
});
/** Resolve a repo + revision to a commit SHA and list its files with sizes. */
export const POST = withAuth(async (req) => {
try {
const body = Body.parse(await req.json());
const { repoId, revision: urlRevision } = normalizeRepoInput(body.repo);
const revision = body.revision || urlRevision || "main";
return NextResponse.json(await lookupRepo(repoId, revision));
} catch (err) {
return handleApiError(err);
}
});
+15
View File
@@ -0,0 +1,15 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { apiError } from "@/lib/api-errors";
import { ModelError, removeModel } from "@/lib/models";
export const DELETE = withAuth<RouteContext<"/api/models/[id]">>(async (_req, { params }) => {
const { id } = await params;
try {
await removeModel(id);
return new NextResponse(null, { status: 204 });
} catch (err) {
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
throw err;
}
});
+31
View File
@@ -0,0 +1,31 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { withAuth } from "@/lib/api-auth";
import { apiError, handleApiError } from "@/lib/api-errors";
import { REPO_ID_RE, SHA_RE } from "@/lib/hub/client";
import { addModel, ModelError } from "@/lib/models";
const Body = z.object({
repoId: z.string().regex(REPO_ID_RE),
revision: z.string().trim().min(1).max(255),
sha: z.string().regex(SHA_RE, "must be a full 40-character commit SHA"),
include: z.array(z.string().min(1).max(1024)).max(10_000),
exclude: z.array(z.string().min(1).max(1024)).max(1_000),
});
/** Add a model to the library, pinned to the SHA the user reviewed. */
export const POST = withAuth(async (req) => {
try {
const body = Body.parse(await req.json());
const { id } = await addModel({
repoId: body.repoId,
revision: body.revision,
sha: body.sha,
rule: { include: body.include, exclude: body.exclude },
});
return NextResponse.json({ id }, { status: 201 });
} catch (err) {
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
return handleApiError(err);
}
});