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

+58
View File
@@ -0,0 +1,58 @@
import "server-only";
import { and, asc, desc, eq, sql } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { modelFiles, models } from "@/lib/db/schema";
import { quantGroup } from "@/lib/selection";
export type LibraryRow = Awaited<ReturnType<typeof listLibrary>>[number];
/** Models with their selected-file totals and a short "which quant" label. */
export async function listLibrary() {
const d = db();
const rows = await d
.select({
id: models.id,
repoId: models.repoId,
trackedRevision: models.trackedRevision,
pinnedSha: models.pinnedSha,
remoteSha: models.remoteSha,
status: models.status,
createdAt: models.createdAt,
downloadedAt: models.downloadedAt,
fileCount: sql<number>`count(${modelFiles.id})`,
totalBytes: sql<number>`coalesce(sum(${modelFiles.size}), 0)`,
})
.from(models)
.leftJoin(modelFiles, and(eq(modelFiles.modelId, models.id), eq(modelFiles.selected, true)))
.groupBy(models.id)
.orderBy(desc(models.createdAt));
const selected = await d
.select({ modelId: modelFiles.modelId, path: modelFiles.path })
.from(modelFiles)
.where(eq(modelFiles.selected, true));
const quants = new Map<string, Set<string>>();
for (const f of selected) {
const g = quantGroup(f.path);
if (!g) continue;
if (!quants.has(f.modelId)) quants.set(f.modelId, new Set());
quants.get(f.modelId)!.add(g);
}
return rows.map((r) => ({
...r,
quants: [...(quants.get(r.id) ?? [])].sort(),
}));
}
export async function getModel(id: string) {
const d = db();
const model = await d.query.models.findFirst({ where: eq(models.id, id) });
if (!model) return null;
const files = await d
.select()
.from(modelFiles)
.where(eq(modelFiles.modelId, id))
.orderBy(asc(modelFiles.path));
return { model, files };
}