Flag models deleted from the Hub; tag picker, tags in settings, account menu

- Worker checks each model's repo and pinned commit on the Hub every
  UPDATE_CHECK_INTERVAL_HOURS and after failed downloads; missing repos or
  commits are flagged (badge, banner, Status filter) and block new
  downloads. Local files are never touched. "Check now" on the model page.
- Tag picker dropdown ("Create new tag…" first, then existing tags) on the
  model page and in Add model.
- Settings: separate File labels and Tags pages; create tags there. Unused
  tags are no longer deleted automatically.
- Header: app icon, nav with active state, account menu with the OIDC
  profile picture, theme switch and sign out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-05 22:53:57 +02:00
1 parent df18415e02
commit 3603742637
33 files changed
+1708 -122

No files matched your search

+8
View File
@@ -46,6 +46,10 @@ export const MODEL_STATUSES = [
] as const;
export type ModelStatus = (typeof MODEL_STATUSES)[number];
/** Is the repo (at the pinned commit) still on the Hub? Local files are never touched either way. */
export const HUB_STATES = ["available", "repo_missing", "commit_missing"] as const;
export type HubState = (typeof HUB_STATES)[number];
export const models = sqliteTable(
"models",
{
@@ -73,6 +77,10 @@ export const models = sqliteTable(
remoteSha: text("remote_sha"),
lastCheckedAt: ts("last_checked_at"),
lastCheckError: text("last_check_error"),
/** Result of the last successful Hub check; null until checked. */
hubState: text("hub_state", { enum: HUB_STATES }),
/** When the repo or pinned commit was first seen missing; cleared when it's back. */
hubMissingSince: ts("hub_missing_since"),
lastVerifiedAt: ts("last_verified_at"),
downloadedAt: ts("downloaded_at"),
// Hub metadata (for search/filters), refreshed by the worker. Null until fetched.
+73
View File
@@ -0,0 +1,73 @@
import { asc, eq, isNull, lt, or } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { models, type HubState } from "@/lib/db/schema";
import { getRepoInfo, HubError } from "./client";
type CheckedModel = Pick<typeof models.$inferSelect, "id" | "repoId" | "pinnedSha" | "hubMissingSince">;
/** Why new downloads are impossible, or null if the Hub still has the repo at the pinned commit. */
export function hubMissingMessage(model: { repoId: string; hubState: HubState | null }): string | null {
if (model.hubState === "repo_missing") {
return `${model.repoId} is no longer on Hugging Face (deleted, or made private), so nothing more can be downloaded. Your local files are kept.`;
}
if (model.hubState === "commit_missing") {
return `The pinned commit of ${model.repoId} is no longer on Hugging Face (history rewritten), so nothing more can be downloaded from it. Your local files are kept.`;
}
return null;
}
export type HubCheckResult = { state: HubState } | { state: null; error: string };
/**
* Is the repo, and the pinned commit, still on the Hub? Stores the result on the model. Only a
* definite answer changes `hubState`; network errors, rate limits or a bad token are kept as
* `lastCheckError`. Never touches local files.
*/
export async function checkHubAvailability(model: CheckedModel): Promise<HubCheckResult> {
let result: HubCheckResult;
try {
await getRepoInfo(model.repoId, model.pinnedSha);
result = { state: "available" };
} catch (err) {
if (err instanceof HubError && err.code === "repo_not_found") result = { state: "repo_missing" };
else if (err instanceof HubError && err.code === "revision_not_found") result = { state: "commit_missing" };
// Gated repos exist; access is a download concern, not availability.
else if (err instanceof HubError && (err.code === "gated_no_token" || err.code === "gated_no_access")) {
result = { state: "available" };
} else result = { state: null, error: err instanceof Error ? err.message : String(err) };
}
const now = new Date();
await db()
.update(models)
.set(
result.state === null
? { lastCheckedAt: now, lastCheckError: result.error }
: {
lastCheckedAt: now,
lastCheckError: null,
hubState: result.state,
hubMissingSince: result.state === "available" ? null : (model.hubMissingSince ?? now),
},
)
.where(eq(models.id, model.id));
return result;
}
/** Models whose last Hub check is older than `intervalMs` (or never ran), oldest first. */
export async function modelsDueForHubCheck(intervalMs: number, limit = 50): Promise<CheckedModel[]> {
const cutoff = new Date(Date.now() - intervalMs);
return db()
.select({ id: models.id, repoId: models.repoId, pinnedSha: models.pinnedSha, hubMissingSince: models.hubMissingSince })
.from(models)
.where(or(isNull(models.lastCheckedAt), lt(models.lastCheckedAt, cutoff)))
.orderBy(asc(models.lastCheckedAt))
.limit(limit);
}
export async function getCheckedModel(id: string): Promise<CheckedModel | undefined> {
return db().query.models.findFirst({
columns: { id: true, repoId: true, pinnedSha: true, hubMissingSince: true },
where: eq(models.id, id),
});
}
+4 -1
View File
@@ -2,6 +2,7 @@ import "server-only";
import { and, asc, desc, eq, gt, gte, inArray, isNull, or } from "drizzle-orm";
import { ulid } from "ulid";
import { db } from "@/lib/db/client";
import { hubMissingMessage } from "@/lib/hub/availability";
import {
ACTIVE_JOB_STATES,
type JobPurpose,
@@ -14,7 +15,7 @@ import {
export class JobError extends Error {
constructor(
public code: "not_found" | "busy" | "nothing_selected" | "not_cancellable",
public code: "not_found" | "busy" | "nothing_selected" | "not_cancellable" | "hub_missing",
message: string,
public status: number,
) {
@@ -30,6 +31,8 @@ export async function queueDownload(modelId: string, purpose: JobPurpose = "init
const d = db();
const model = await d.query.models.findFirst({ where: eq(models.id, modelId) });
if (!model) throw new JobError("not_found", "Model not found.", 404);
const missing = hubMissingMessage(model);
if (missing) throw new JobError("hub_missing", missing, 409);
const open = await d.query.jobs.findFirst({
columns: { id: true },
+1
View File
@@ -20,6 +20,7 @@ export async function listLibrary() {
pinnedSha: models.pinnedSha,
remoteSha: models.remoteSha,
status: models.status,
hubState: models.hubState,
createdAt: models.createdAt,
downloadedAt: models.downloadedAt,
baseModels: models.baseModels,
+4 -3
View File
@@ -3,15 +3,15 @@ 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 { hubMissingMessage } from "@/lib/hub/availability";
import { checkFileAccess, getAuthorAvatar, getRepoInfo, listFiles } from "@/lib/hub/client";
import { metadataColumns } from "@/lib/hub/refresh";
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" | "busy",
public code: "already_exists" | "empty_selection" | "not_found" | "not_removable" | "busy" | "hub_missing",
message: string,
public status: number,
) {
@@ -100,7 +100,6 @@ export async function removeModel(id: string): Promise<void> {
d.delete(modelRevisions).where(eq(modelRevisions.modelId, id)),
d.delete(models).where(eq(models.id, id)),
]);
await deleteUnusedTags();
}
function chunk<T>(items: T[], size: number): T[][] {
@@ -118,6 +117,8 @@ export async function addFilesToModel(modelId: string, paths: string[]): Promise
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 missing = hubMissingMessage(model);
if (missing) throw new ModelError("hub_missing", missing, 409);
const open = await d.query.jobs.findFirst({
columns: { id: true },
+11
View File
@@ -55,6 +55,7 @@ const model = (over: Partial<SearchableModel>): SearchableModel => ({
pipelineTag: "text-generation",
license: "apache-2.0",
status: "ready",
hubStatus: null,
...over,
});
@@ -70,6 +71,16 @@ describe("matchesQuery", () => {
});
});
describe("hub status", () => {
it("is searchable and an extra Status filter value", () => {
const gone = model({ hubStatus: "deleted on Hub" });
assert.ok(matchesQuery(gone, "deleted"));
assert.ok(!matchesQuery(model({}), "deleted"));
assert.ok(matchesFilters(gone, { ...EMPTY_FILTERS, status: ["deleted on hub"] }));
assert.ok(matchesFilters(gone, { ...EMPTY_FILTERS, status: ["ready"] }));
});
});
describe("filters and facet counts", () => {
const models = [
model({}),
+4 -1
View File
@@ -12,6 +12,8 @@ export type SearchableModel = {
pipelineTag: string | null;
license: string | null;
status: string;
/** Extra status value when the repo or commit is gone from the Hub, e.g. "deleted on Hub". */
hubStatus: string | null;
};
export const FACETS = ["author", "family", "quant", "tag", "status"] as const;
@@ -31,7 +33,7 @@ export function facetValues(m: SearchableModel, facet: Facet): string[] {
case "tag":
return m.tags;
case "status":
return [m.status];
return m.hubStatus ? [m.status, m.hubStatus] : [m.status];
}
}
@@ -48,6 +50,7 @@ function haystack(m: SearchableModel): string {
m.pipelineTag,
m.license,
m.status,
m.hubStatus,
]
.filter(Boolean)
.join(" ")
+15 -6
View File
@@ -60,15 +60,24 @@ export async function addTag(modelId: string, rawName: string): Promise<Tag> {
return tag;
}
/** Detach a tag; tags no model uses anymore are deleted. */
/** Detach a tag from a model. The tag itself stays (delete it in Settings). */
export async function removeTag(modelId: string, tagId: string): Promise<void> {
const d = db();
await d.delete(modelTags).where(and(eq(modelTags.modelId, modelId), eq(modelTags.tagId, tagId)));
await deleteUnusedTags();
await db().delete(modelTags).where(and(eq(modelTags.modelId, modelId), eq(modelTags.tagId, tagId)));
}
export async function deleteUnusedTags(): Promise<void> {
await db().run(sql`delete from ${tags} where ${tags.id} not in (select ${modelTags.tagId} from ${modelTags})`);
/** Create a tag without attaching it (Settings). 409 if the name exists (case-insensitive). */
export async function createTag(input: { name: string; color?: string | null }): Promise<Tag> {
const { name, slug } = normalizeTagName(input.name);
const color = input.color ?? null;
if (color !== null && !isLabelColor(color)) throw new TagError("invalid", "Unknown color.", 400);
const d = db();
const inserted = await d
.insert(tags)
.values({ id: ulid(), name, slug, color })
.onConflictDoNothing({ target: tags.slug })
.returning({ id: tags.id, name: tags.name, color: tags.color });
if (inserted.length === 0) throw new TagError("invalid", `A tag named "${name}" already exists.`, 409);
return inserted[0];
}
/** Rename a tag and/or set its color (null = automatic). */