Download more, file labels, split-file grouping, settings for labels and tags
- Files tab: "Download more" adds files to a model's selection and queues them - Colored file labels (Model, MTP, Vision/mmproj, imatrix, Config, …) - Split GGUF/safetensors parts shown and selected as one entry everywhere - Settings page with a Labels section: file label names/colors, tag rename/recolor/delete; new settings table and tags.color - Quants only count model weights Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5211ec9064
commit
df18415e02
34 files changed
+2256
-132
No files matched your search
+41
-3
@@ -1,16 +1,17 @@
|
||||
import "server-only";
|
||||
import { and, eq, sql } from "drizzle-orm";
|
||||
import { and, eq, inArray, sql } from "drizzle-orm";
|
||||
import { ulid } from "ulid";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { jobs, modelFiles, modelRevisions, models, modelTags } from "@/lib/db/schema";
|
||||
import { checkFileAccess, getAuthorAvatar, getRepoInfo, listFiles } from "@/lib/hub/client";
|
||||
import { metadataColumns } from "@/lib/hub/refresh";
|
||||
import { isSelected, type SelectionRule } from "@/lib/selection";
|
||||
import { queueDownload } from "@/lib/jobs";
|
||||
import { escapeGlob, isSelected, matchesAny, type SelectionRule } from "@/lib/selection";
|
||||
import { deleteUnusedTags } from "@/lib/tags";
|
||||
|
||||
export class ModelError extends Error {
|
||||
constructor(
|
||||
public code: "already_exists" | "empty_selection" | "not_found" | "not_removable",
|
||||
public code: "already_exists" | "empty_selection" | "not_found" | "not_removable" | "busy",
|
||||
message: string,
|
||||
public status: number,
|
||||
) {
|
||||
@@ -107,3 +108,40 @@ function chunk<T>(items: T[], size: number): T[][] {
|
||||
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add files to a model's selection and queue a download. The paths are added to the selection
|
||||
* rule as exact includes; exclude patterns that would block one of them are dropped, then the
|
||||
* rule is re-applied to the whole file list so `selected` always matches the stored rule.
|
||||
*/
|
||||
export async function addFilesToModel(modelId: string, paths: string[]): Promise<{ jobId: string; added: number }> {
|
||||
const d = db();
|
||||
const model = await d.query.models.findFirst({ where: eq(models.id, modelId) });
|
||||
if (!model) throw new ModelError("not_found", "Model not found.", 404);
|
||||
|
||||
const open = await d.query.jobs.findFirst({
|
||||
columns: { id: true },
|
||||
where: and(eq(jobs.modelId, modelId), inArray(jobs.state, ["queued", "downloading", "verifying"])),
|
||||
});
|
||||
if (open) throw new ModelError("busy", "A download for this model is still queued or running. Add files when it has finished.", 409);
|
||||
|
||||
const files = await d.select().from(modelFiles).where(eq(modelFiles.modelId, modelId));
|
||||
const known = new Map(files.map((f) => [f.path, f]));
|
||||
const wanted = [...new Set(paths)].filter((p) => known.has(p) && !known.get(p)!.selected);
|
||||
if (wanted.length === 0) throw new ModelError("empty_selection", "No new files selected.", 400);
|
||||
|
||||
const rule: SelectionRule = {
|
||||
include: [...model.includePatterns, ...wanted.map(escapeGlob)],
|
||||
exclude: model.excludePatterns.filter((p) => !wanted.some((path) => matchesAny(path, [p]))),
|
||||
};
|
||||
const changed = files.filter((f) => f.selected !== isSelected(f.path, rule));
|
||||
|
||||
await d.batch([
|
||||
d.update(models).set({ includePatterns: rule.include, excludePatterns: rule.exclude }).where(eq(models.id, modelId)),
|
||||
...changed.map((f) =>
|
||||
d.update(modelFiles).set({ selected: !f.selected, state: "pending" }).where(eq(modelFiles.id, f.id)),
|
||||
),
|
||||
]);
|
||||
const { jobId } = await queueDownload(modelId, "add");
|
||||
return { jobId, added: changed.filter((f) => !f.selected).length };
|
||||
}
|
||||
Reference in new issue
Block a user