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:
1 parent
df18415e02
commit
3603742637
33 files changed
+1708
-122
No files matched your search
+1
-1
@@ -37,7 +37,7 @@ KANAME_VERSION=
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
MAX_CONCURRENT_DOWNLOADS=1
|
||||
# Hub update check interval; 0 disables it
|
||||
# How often the worker checks every model on the Hub (still there? later: newer commits); 0 disables it
|
||||
UPDATE_CHECK_INTERVAL_HOURS=12
|
||||
# 1 (default): hf downloads over plain HTTP, so progress can be measured from bytes on disk.
|
||||
# 0: use Xet (chunk-level dedup on updates), but progress only advances in large jumps.
|
||||
|
||||
@@ -31,6 +31,17 @@ step 1 (Hugging Face downloader) is released as a minor version.
|
||||
tree (base model → quantized/finetuned → this repo) listing other local models of the same base.
|
||||
- Hub metadata now includes the author's avatar and the relation to the base model; existing models
|
||||
are refetched once by the worker.
|
||||
- Models deleted from Hugging Face are flagged, never deleted locally: the worker checks every model
|
||||
every `UPDATE_CHECK_INTERVAL_HOURS` (and right after a failed download) whether the repo and the
|
||||
pinned commit still exist. A deleted repo (or one made private) or a rewritten history shows a
|
||||
warning badge in the library (searchable, and a value of the Status filter), a banner on the model
|
||||
page, and blocks new downloads and "Download more". "On the Hub" in the sidebar shows the last
|
||||
check, with "Check now".
|
||||
- Create tags in Settings (name and color), before any model uses them.
|
||||
- Tag picker on the model page and in Add model: a dropdown with "Create new tag…" first, then your
|
||||
existing tags with their colors, and "Manage tags…".
|
||||
- Account menu in the header with your profile picture from the OIDC provider (initials as
|
||||
fallback): name and email, links to the settings, theme (system/light/dark) and sign out.
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -40,6 +51,9 @@ step 1 (Hugging Face downloader) is released as a minor version.
|
||||
can't bypass it.
|
||||
- Quant labels (library column, Quant filter, "Local copy") only count model weights, not MTP,
|
||||
mmproj or imatrix files.
|
||||
- Tags are no longer deleted automatically when no model uses them anymore; delete them in Settings.
|
||||
- Settings has separate pages for **File labels** and **Tags**.
|
||||
- Header: app icon, navigation with icons and the current page highlighted.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `models` ADD `hub_state` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `hub_missing_since` integer;
|
||||
@@ -0,0 +1,960 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "4bf01375-42a2-440f-aeba-69644c7bca95",
|
||||
"prevId": "84e7c88b-53c4-4eba-8f2f-7de08b494316",
|
||||
"tables": {
|
||||
"job_files": {
|
||||
"name": "job_files",
|
||||
"columns": {
|
||||
"job_id": {
|
||||
"name": "job_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"model_file_id": {
|
||||
"name": "model_file_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"path": {
|
||||
"name": "path",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"expected_bytes": {
|
||||
"name": "expected_bytes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"done_bytes": {
|
||||
"name": "done_bytes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"state": {
|
||||
"name": "state",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'pending'"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"job_files_job_id_jobs_id_fk": {
|
||||
"name": "job_files_job_id_jobs_id_fk",
|
||||
"tableFrom": "job_files",
|
||||
"tableTo": "jobs",
|
||||
"columnsFrom": [
|
||||
"job_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"job_files_model_file_id_model_files_id_fk": {
|
||||
"name": "job_files_model_file_id_model_files_id_fk",
|
||||
"tableFrom": "job_files",
|
||||
"tableTo": "model_files",
|
||||
"columnsFrom": [
|
||||
"model_file_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {
|
||||
"job_files_job_id_model_file_id_pk": {
|
||||
"columns": [
|
||||
"job_id",
|
||||
"model_file_id"
|
||||
],
|
||||
"name": "job_files_job_id_model_file_id_pk"
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"job_logs": {
|
||||
"name": "job_logs",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"job_id": {
|
||||
"name": "job_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"ts": {
|
||||
"name": "ts",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"stream": {
|
||||
"name": "stream",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"line": {
|
||||
"name": "line",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"job_logs_job_idx": {
|
||||
"name": "job_logs_job_idx",
|
||||
"columns": [
|
||||
"job_id",
|
||||
"id"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"job_logs_job_id_jobs_id_fk": {
|
||||
"name": "job_logs_job_id_jobs_id_fk",
|
||||
"tableFrom": "job_logs",
|
||||
"tableTo": "jobs",
|
||||
"columnsFrom": [
|
||||
"job_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"jobs": {
|
||||
"name": "jobs",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"model_id": {
|
||||
"name": "model_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"kind": {
|
||||
"name": "kind",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"purpose": {
|
||||
"name": "purpose",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"target_sha": {
|
||||
"name": "target_sha",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"state": {
|
||||
"name": "state",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'queued'"
|
||||
},
|
||||
"attempt": {
|
||||
"name": "attempt",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"total_bytes": {
|
||||
"name": "total_bytes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"done_bytes": {
|
||||
"name": "done_bytes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": 0
|
||||
},
|
||||
"speed_bps": {
|
||||
"name": "speed_bps",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"eta_seconds": {
|
||||
"name": "eta_seconds",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"exit_code": {
|
||||
"name": "exit_code",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"error_code": {
|
||||
"name": "error_code",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"error_message": {
|
||||
"name": "error_message",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"cancel_requested_at": {
|
||||
"name": "cancel_requested_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"started_at": {
|
||||
"name": "started_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"finished_at": {
|
||||
"name": "finished_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"jobs_state_idx": {
|
||||
"name": "jobs_state_idx",
|
||||
"columns": [
|
||||
"state"
|
||||
],
|
||||
"isUnique": false
|
||||
},
|
||||
"jobs_model_idx": {
|
||||
"name": "jobs_model_idx",
|
||||
"columns": [
|
||||
"model_id"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"jobs_model_id_models_id_fk": {
|
||||
"name": "jobs_model_id_models_id_fk",
|
||||
"tableFrom": "jobs",
|
||||
"tableTo": "models",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"model_files": {
|
||||
"name": "model_files",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"model_id": {
|
||||
"name": "model_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"path": {
|
||||
"name": "path",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"size": {
|
||||
"name": "size",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"blob_oid": {
|
||||
"name": "blob_oid",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"lfs_sha256": {
|
||||
"name": "lfs_sha256",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"selected": {
|
||||
"name": "selected",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": false
|
||||
},
|
||||
"state": {
|
||||
"name": "state",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'pending'"
|
||||
},
|
||||
"checked_at": {
|
||||
"name": "checked_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"model_files_model_path_uq": {
|
||||
"name": "model_files_model_path_uq",
|
||||
"columns": [
|
||||
"model_id",
|
||||
"path"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"model_files_model_id_models_id_fk": {
|
||||
"name": "model_files_model_id_models_id_fk",
|
||||
"tableFrom": "model_files",
|
||||
"tableTo": "models",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"model_revisions": {
|
||||
"name": "model_revisions",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"model_id": {
|
||||
"name": "model_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"sha": {
|
||||
"name": "sha",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"pinned_at": {
|
||||
"name": "pinned_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"superseded_at": {
|
||||
"name": "superseded_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"model_revisions_model_idx": {
|
||||
"name": "model_revisions_model_idx",
|
||||
"columns": [
|
||||
"model_id"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"model_revisions_model_id_models_id_fk": {
|
||||
"name": "model_revisions_model_id_models_id_fk",
|
||||
"tableFrom": "model_revisions",
|
||||
"tableTo": "models",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"model_tags": {
|
||||
"name": "model_tags",
|
||||
"columns": {
|
||||
"model_id": {
|
||||
"name": "model_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"tag_id": {
|
||||
"name": "tag_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"model_tags_tag_idx": {
|
||||
"name": "model_tags_tag_idx",
|
||||
"columns": [
|
||||
"tag_id"
|
||||
],
|
||||
"isUnique": false
|
||||
}
|
||||
},
|
||||
"foreignKeys": {
|
||||
"model_tags_model_id_models_id_fk": {
|
||||
"name": "model_tags_model_id_models_id_fk",
|
||||
"tableFrom": "model_tags",
|
||||
"tableTo": "models",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"model_tags_tag_id_tags_id_fk": {
|
||||
"name": "model_tags_tag_id_tags_id_fk",
|
||||
"tableFrom": "model_tags",
|
||||
"tableTo": "tags",
|
||||
"columnsFrom": [
|
||||
"tag_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {
|
||||
"model_tags_model_id_tag_id_pk": {
|
||||
"columns": [
|
||||
"model_id",
|
||||
"tag_id"
|
||||
],
|
||||
"name": "model_tags_model_id_tag_id_pk"
|
||||
}
|
||||
},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"models": {
|
||||
"name": "models",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"repo_type": {
|
||||
"name": "repo_type",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'model'"
|
||||
},
|
||||
"repo_id": {
|
||||
"name": "repo_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"tracked_revision": {
|
||||
"name": "tracked_revision",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'main'"
|
||||
},
|
||||
"pinned_sha": {
|
||||
"name": "pinned_sha",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"local_path": {
|
||||
"name": "local_path",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"include_patterns": {
|
||||
"name": "include_patterns",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"exclude_patterns": {
|
||||
"name": "exclude_patterns",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'[]'"
|
||||
},
|
||||
"status": {
|
||||
"name": "status",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "'pending'"
|
||||
},
|
||||
"remote_sha": {
|
||||
"name": "remote_sha",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_checked_at": {
|
||||
"name": "last_checked_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_check_error": {
|
||||
"name": "last_check_error",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"hub_state": {
|
||||
"name": "hub_state",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"hub_missing_since": {
|
||||
"name": "hub_missing_since",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"last_verified_at": {
|
||||
"name": "last_verified_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"downloaded_at": {
|
||||
"name": "downloaded_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"base_models": {
|
||||
"name": "base_models",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"base_relation": {
|
||||
"name": "base_relation",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"author_avatar_url": {
|
||||
"name": "author_avatar_url",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"architecture": {
|
||||
"name": "architecture",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"pipeline_tag": {
|
||||
"name": "pipeline_tag",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"license": {
|
||||
"name": "license",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"hub_tags": {
|
||||
"name": "hub_tags",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"metadata_fetched_at": {
|
||||
"name": "metadata_fetched_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"models_repo_uq": {
|
||||
"name": "models_repo_uq",
|
||||
"columns": [
|
||||
"repo_type",
|
||||
"repo_id"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"settings": {
|
||||
"name": "settings",
|
||||
"columns": {
|
||||
"key": {
|
||||
"name": "key",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"value": {
|
||||
"name": "value",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"tags": {
|
||||
"name": "tags",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"slug": {
|
||||
"name": "slug",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"color": {
|
||||
"name": "color",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"tags_slug_uq": {
|
||||
"name": "tags_slug_uq",
|
||||
"columns": [
|
||||
"slug"
|
||||
],
|
||||
"isUnique": true
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
},
|
||||
"worker_state": {
|
||||
"name": "worker_state",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"instance_id": {
|
||||
"name": "instance_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"pid": {
|
||||
"name": "pid",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"hf_version": {
|
||||
"name": "hf_version",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"models_dir_free_bytes": {
|
||||
"name": "models_dir_free_bytes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"models_dir_total_bytes": {
|
||||
"name": "models_dir_total_bytes",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"autoincrement": false
|
||||
},
|
||||
"started_at": {
|
||||
"name": "started_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
},
|
||||
"heartbeat_at": {
|
||||
"name": "heartbeat_at",
|
||||
"type": "integer",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"checkConstraints": {}
|
||||
}
|
||||
},
|
||||
"views": {},
|
||||
"enums": {},
|
||||
"_meta": {
|
||||
"schemas": {},
|
||||
"tables": {},
|
||||
"columns": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,13 @@
|
||||
"when": 1791224932279,
|
||||
"tag": "0006_settings_and_tag_color",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "6",
|
||||
"when": 1791233230682,
|
||||
"tag": "0007_hub_state",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -15,7 +15,16 @@ import { formatBytes, percent } from "@/lib/format";
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
/** Sidebar card: current download state, actions and (while running) per-file progress. */
|
||||
export function DownloadCard({ modelId, status }: { modelId: string; status: ModelStatus }) {
|
||||
export function DownloadCard({
|
||||
modelId,
|
||||
status,
|
||||
hubMissing,
|
||||
}: {
|
||||
modelId: string;
|
||||
status: ModelStatus;
|
||||
/** The repo or pinned commit is gone from the Hub; no new downloads. */
|
||||
hubMissing: boolean;
|
||||
}) {
|
||||
const { snapshot } = useLive({ model: modelId });
|
||||
const [busy, setBusy] = useState(false);
|
||||
const latest = snapshot?.jobs[0];
|
||||
@@ -35,6 +44,7 @@ export function DownloadCard({ modelId, status }: { modelId: string; status: Mod
|
||||
if (open?.state === "queued") hint = snapshot?.worker.online ? "Waiting for a free download slot." : "Queued, but the worker is offline.";
|
||||
else if (open) hint = "Runs in the background; you can close this page.";
|
||||
else if (status === "ready") hint = "All selected files are present.";
|
||||
else if (hubMissing) hint = "Can't download: no longer available on Hugging Face. Local files are kept.";
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
@@ -84,6 +94,7 @@ export function DownloadCard({ modelId, status }: { modelId: string; status: Mod
|
||||
</Button>
|
||||
) : (
|
||||
status !== "ready" &&
|
||||
!hubMissing &&
|
||||
snapshot && (
|
||||
<Button size="sm" disabled={busy} onClick={() => run(() => startDownload(modelId))}>
|
||||
{latest ? "Download again" : "Download"}
|
||||
|
||||
@@ -28,6 +28,7 @@ export function FilesHeader({
|
||||
candidates,
|
||||
freeBytes,
|
||||
busy,
|
||||
hubMissing,
|
||||
}: {
|
||||
modelId: string;
|
||||
sha: string;
|
||||
@@ -39,6 +40,8 @@ export function FilesHeader({
|
||||
freeBytes: number | null;
|
||||
/** A download is queued/running; adding files has to wait. */
|
||||
busy: boolean;
|
||||
/** The repo or pinned commit is gone from the Hub; nothing more can be downloaded. */
|
||||
hubMissing: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -114,7 +117,7 @@ export function FilesHeader({
|
||||
<span className="text-muted-foreground">
|
||||
{localCount} of {selectedCount} on disk · {formatBytes(localBytes)}
|
||||
</span>
|
||||
{candidates.length > 0 && (
|
||||
{candidates.length > 0 && !hubMissing && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant={open ? "outline" : "default"}
|
||||
|
||||
@@ -122,6 +122,7 @@ export function FilesTab({
|
||||
others,
|
||||
freeBytes,
|
||||
busy,
|
||||
hubMissing,
|
||||
}: {
|
||||
modelId: string;
|
||||
repoId: string;
|
||||
@@ -130,6 +131,7 @@ export function FilesTab({
|
||||
others: FileRow[];
|
||||
freeBytes: number | null;
|
||||
busy: boolean;
|
||||
hubMissing: boolean;
|
||||
}) {
|
||||
const hub = `https://huggingface.co/${repoId}`;
|
||||
// Split files link to their folder (all parts), single files to the file itself.
|
||||
@@ -155,6 +157,7 @@ export function FilesTab({
|
||||
candidates={others.map((f) => ({ path: f.path, size: f.size }))}
|
||||
freeBytes={freeBytes}
|
||||
busy={busy}
|
||||
hubMissing={hubMissing}
|
||||
/>
|
||||
|
||||
<ul className="divide-y">
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { RefreshCwIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** Re-check right now whether the repo and pinned commit are still on the Hub. */
|
||||
export function HubCheckButton({ modelId, label = "Check now" }: { modelId: string; label?: string }) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function check() {
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await fetch(`/api/models/${modelId}/hub-check`, { method: "POST" });
|
||||
const json = await res.json().catch(() => ({}));
|
||||
if (!res.ok) toast.error(json.error?.message ?? `Check failed (${res.status})`);
|
||||
else if (json.state === "available") toast.success("Still available on Hugging Face");
|
||||
else if (json.state === "repo_missing") toast.warning("The repo is no longer on Hugging Face");
|
||||
else if (json.state === "commit_missing") toast.warning("The pinned commit is no longer on Hugging Face");
|
||||
else toast.error(`Could not check: ${json.error ?? "unknown error"}`);
|
||||
router.refresh();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Button variant="ghost" size="xs" onClick={check} disabled={busy}>
|
||||
<RefreshCwIcon className={cn(busy && "animate-spin")} />
|
||||
{label}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -11,11 +11,13 @@ import {
|
||||
MessagesSquareIcon,
|
||||
ScaleIcon,
|
||||
SparklesIcon,
|
||||
TriangleAlertIcon,
|
||||
} from "lucide-react";
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { CopyButton } from "@/components/copy-button";
|
||||
import { HubStateBadge } from "@/components/hub-state-badge";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { ModelStatusBadge } from "@/components/model-status-badge";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
@@ -30,6 +32,7 @@ import { modelTagList } from "@/lib/tags";
|
||||
import { getWorkerStatus } from "@/lib/worker-status";
|
||||
import { DownloadCard } from "./download-card";
|
||||
import { FilesTab } from "./files-tab";
|
||||
import { HubCheckButton } from "./hub-check";
|
||||
import { JobsTab } from "./jobs-tab";
|
||||
import { ModelCard } from "./model-card";
|
||||
import { RemoveModelButton } from "./remove-model-button";
|
||||
@@ -90,6 +93,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
|
||||
const hub = `https://huggingface.co/${model.repoId}`;
|
||||
const baseModels = model.baseModels ?? [];
|
||||
const hubTags = model.hubTags ?? [];
|
||||
const hubMissing = model.hubState === "repo_missing" || model.hubState === "commit_missing";
|
||||
|
||||
const [tags, related, card, worker] = await Promise.all([
|
||||
modelTagList(model.id),
|
||||
@@ -125,6 +129,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
|
||||
<h1 className="text-xl font-semibold break-all">{name}</h1>
|
||||
<CopyButton value={model.repoId} label="Copy repo ID" />
|
||||
<ModelStatusBadge status={model.status} />
|
||||
<HubStateBadge state={model.hubState} />
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
{model.status === "pending" && <RemoveModelButton id={model.id} />}
|
||||
<ExternalButton href={hub}>🤗 Hugging Face</ExternalButton>
|
||||
@@ -159,6 +164,32 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
|
||||
|
||||
</Panel>
|
||||
|
||||
{hubMissing && (
|
||||
<div className="flex flex-wrap items-start gap-3 rounded-xl border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm">
|
||||
<TriangleAlertIcon className="mt-0.5 size-4 shrink-0 text-amber-600 dark:text-amber-400" />
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
|
||||
<p className="font-medium text-amber-800 dark:text-amber-200">
|
||||
{model.hubState === "repo_missing"
|
||||
? "This repo is no longer on Hugging Face"
|
||||
: "The pinned commit is no longer on Hugging Face"}
|
||||
</p>
|
||||
<p className="text-muted-foreground">
|
||||
{model.hubState === "repo_missing"
|
||||
? "It was deleted, renamed or made private. "
|
||||
: "The repo's history was rewritten. "}
|
||||
Your local copy is kept and stays usable; downloading more files or repairing isn't possible.
|
||||
{model.hubMissingSince && (
|
||||
<>
|
||||
{" "}
|
||||
Missing since <LocalTime value={model.hubMissingSince} />.
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<HubCheckButton modelId={model.id} label="Check again" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid items-start gap-4 lg:grid-cols-[minmax(0,1fr)_320px]">
|
||||
{/* Content card with the tabs as a segmented control in its header */}
|
||||
<Panel className="min-w-0 overflow-hidden">
|
||||
@@ -220,6 +251,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
|
||||
others={others}
|
||||
freeBytes={worker.online ? worker.modelsDirFreeBytes : null}
|
||||
busy={model.status === "downloading"}
|
||||
hubMissing={hubMissing}
|
||||
/>
|
||||
)}
|
||||
{tab === "jobs" && (
|
||||
@@ -231,7 +263,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
|
||||
|
||||
<aside className="flex flex-col gap-4">
|
||||
<SideCard>
|
||||
<DownloadCard modelId={model.id} status={model.status} />
|
||||
<DownloadCard modelId={model.id} status={model.status} hubMissing={hubMissing} />
|
||||
</SideCard>
|
||||
|
||||
<SideCard title="Local copy" icon={ListChecksIcon}>
|
||||
@@ -271,6 +303,24 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
|
||||
<dd className="flex flex-col font-mono text-xs">{model.excludePatterns.map((p) => <span key={p} className="break-all">{p}</span>)}</dd>
|
||||
</>
|
||||
)}
|
||||
<dt className="text-muted-foreground">On the Hub</dt>
|
||||
<dd className="flex flex-col items-start gap-0.5">
|
||||
<span className={cn(hubMissing && "text-amber-700 dark:text-amber-300")}>
|
||||
{model.hubState === "available"
|
||||
? "Available"
|
||||
: model.hubState === "repo_missing"
|
||||
? "Repo deleted"
|
||||
: model.hubState === "commit_missing"
|
||||
? "Commit deleted"
|
||||
: "Not checked yet"}
|
||||
</span>
|
||||
{model.lastCheckedAt && (
|
||||
<span className="text-xs text-muted-foreground" title={model.lastCheckError ?? undefined}>
|
||||
{model.lastCheckError ? "check failed" : "checked"} <LocalTime value={model.lastCheckedAt} />
|
||||
</span>
|
||||
)}
|
||||
<HubCheckButton modelId={model.id} />
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Added</dt>
|
||||
<dd>
|
||||
<LocalTime value={model.createdAt} />
|
||||
|
||||
@@ -2,29 +2,18 @@
|
||||
|
||||
import { XIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useId, useState } from "react";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { TagBadge } from "@/components/tag-badge";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { TagPicker } from "@/components/tag-picker";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
|
||||
/** Add/remove user tags on a model; suggests existing tags. */
|
||||
/** Add/remove user tags on a model. */
|
||||
export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) {
|
||||
const router = useRouter();
|
||||
const listId = useId();
|
||||
const [value, setValue] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [suggestions, setSuggestions] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/tags")
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((all: Tag[]) => setSuggestions(all.map((t) => t.name)))
|
||||
.catch(() => {});
|
||||
}, [tags]);
|
||||
|
||||
async function add(name: string) {
|
||||
if (!name.trim()) return;
|
||||
setBusy(true);
|
||||
const res = await fetch(`/api/models/${modelId}/tags`, {
|
||||
method: "POST",
|
||||
@@ -37,7 +26,6 @@ export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) {
|
||||
toast.error(body.error?.message ?? `Could not add tag (${res.status})`);
|
||||
return;
|
||||
}
|
||||
setValue("");
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
@@ -47,7 +35,6 @@ export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) {
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
const current = new Set(tags.map((t) => t.name.toLowerCase()));
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{tags.map((t) => (
|
||||
@@ -57,30 +44,7 @@ export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) {
|
||||
</button>
|
||||
</TagBadge>
|
||||
))}
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void add(value);
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
list={listId}
|
||||
placeholder="Add tag…"
|
||||
disabled={busy}
|
||||
maxLength={40}
|
||||
className="h-6 w-36 text-xs"
|
||||
aria-label="Add tag"
|
||||
/>
|
||||
<datalist id={listId}>
|
||||
{suggestions
|
||||
.filter((s) => !current.has(s.toLowerCase()))
|
||||
.map((s) => (
|
||||
<option key={s} value={s} />
|
||||
))}
|
||||
</datalist>
|
||||
</form>
|
||||
<TagPicker exclude={tags.map((t) => t.name)} onPick={add} disabled={busy} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { XIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { FileRoleBadge } from "@/components/labels";
|
||||
import { TagBadge } from "@/components/tag-badge";
|
||||
import { TagPicker } from "@/components/tag-picker";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
@@ -46,15 +49,7 @@ export function AddModelForm({
|
||||
const [includeText, setIncludeText] = useState("");
|
||||
const [excludeText, setExcludeText] = useState("");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [tagsText, setTagsText] = useState("");
|
||||
const [knownTags, setKnownTags] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch("/api/tags")
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((all: { name: string }[]) => setKnownTags(all.map((t) => t.name)))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
const [tags, setTags] = useState<{ name: string; color?: string | null }[]>([]);
|
||||
|
||||
async function lookup(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
@@ -67,7 +62,7 @@ export function AddModelForm({
|
||||
setChecked(new Set());
|
||||
setIncludeText("");
|
||||
setExcludeText("");
|
||||
setTagsText("");
|
||||
setTags([]);
|
||||
} catch (err) {
|
||||
setResult(null);
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
@@ -146,7 +141,7 @@ export function AddModelForm({
|
||||
sha: result.sha,
|
||||
include: [...includePatterns, ...[...checked].sort().map(escapeGlob)],
|
||||
exclude: excludePatterns,
|
||||
tags: parsePatternList(tagsText),
|
||||
tags: tags.map((t) => t.name),
|
||||
});
|
||||
toast.success(`${result.repoId} added, download queued`);
|
||||
onAdded(id);
|
||||
@@ -289,20 +284,32 @@ export function AddModelForm({
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="tags">Tags</Label>
|
||||
<Input
|
||||
id="tags"
|
||||
value={tagsText}
|
||||
onChange={(e) => setTagsText(e.target.value)}
|
||||
placeholder="roleplay, security"
|
||||
list="known-tags"
|
||||
/>
|
||||
<datalist id="known-tags">
|
||||
{knownTags.map((t) => (
|
||||
<option key={t} value={t} />
|
||||
<Label>Tags</Label>
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{tags.map((t) => (
|
||||
<TagBadge key={t.name.toLowerCase()} name={t.name} color={t.color}>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Remove tag ${t.name}`}
|
||||
onClick={() => setTags((prev) => prev.filter((x) => x !== t))}
|
||||
className="opacity-60 hover:opacity-100"
|
||||
>
|
||||
<XIcon className="size-3" />
|
||||
</button>
|
||||
</TagBadge>
|
||||
))}
|
||||
</datalist>
|
||||
<p className="text-xs text-muted-foreground">Optional, comma-separated. Editable later on the model page.</p>
|
||||
<TagPicker
|
||||
exclude={tags.map((t) => t.name)}
|
||||
onPick={(name, tag) =>
|
||||
setTags((prev) =>
|
||||
prev.some((x) => x.name.toLowerCase() === name.toLowerCase())
|
||||
? prev
|
||||
: [...prev, { name, color: tag?.color }],
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">Optional. Editable later on the model page.</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
+12
-22
@@ -1,8 +1,9 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { auth, signOut } from "@/auth";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { AppNav } from "@/components/app-nav";
|
||||
import { LabelSettingsProvider } from "@/components/labels";
|
||||
import { UserMenu } from "@/components/user-menu";
|
||||
import { WorkerIndicator } from "@/components/worker-indicator";
|
||||
import { getFileRoleStyles } from "@/lib/settings";
|
||||
import { getWorkerStatus } from "@/lib/worker-status";
|
||||
@@ -16,34 +17,23 @@ export default async function AppLayout({ children }: LayoutProps<"/">) {
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col overflow-x-clip">
|
||||
<header className="border-b">
|
||||
<div className="mx-auto flex h-14 max-w-7xl items-center gap-6 px-4">
|
||||
<Link href="/" className="flex items-baseline gap-1.5 font-semibold">
|
||||
<div className="mx-auto flex h-14 max-w-7xl items-center gap-3 px-4 sm:gap-6">
|
||||
<Link href="/" className="flex items-center gap-2 font-semibold">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src="/icon.svg" alt="" className="size-6" />
|
||||
Kaname
|
||||
<span className="text-xs font-normal text-muted-foreground">{process.env.APP_VERSION ?? "dev"}</span>
|
||||
<span className="hidden text-xs font-normal text-muted-foreground sm:inline">{process.env.APP_VERSION ?? "dev"}</span>
|
||||
</Link>
|
||||
<nav className="flex items-center gap-4 text-sm text-muted-foreground">
|
||||
<Link href="/" className="hover:text-foreground">
|
||||
Library
|
||||
</Link>
|
||||
<Link href="/settings" className="hover:text-foreground">
|
||||
Settings
|
||||
</Link>
|
||||
</nav>
|
||||
<AppNav />
|
||||
<div className="ml-auto flex items-center gap-3">
|
||||
<WorkerIndicator initial={worker} />
|
||||
<span className="hidden text-sm text-muted-foreground sm:inline">
|
||||
{session.user.name ?? session.user.email}
|
||||
</span>
|
||||
<form
|
||||
action={async () => {
|
||||
<UserMenu
|
||||
user={{ name: session.user.name ?? null, email: session.user.email ?? null, image: session.user.image ?? null }}
|
||||
signOutAction={async () => {
|
||||
"use server";
|
||||
await signOut({ redirectTo: "/login" });
|
||||
}}
|
||||
>
|
||||
<Button type="submit" variant="ghost" size="sm">
|
||||
Sign out
|
||||
</Button>
|
||||
</form>
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useMemo, useState } from "react";
|
||||
import { JobProgress, JobStateBadge } from "@/components/job-progress";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { HUB_STATE_LABEL, HubStateBadge } from "@/components/hub-state-badge";
|
||||
import { MODEL_STATUS, ModelStatusBadge } from "@/components/model-status-badge";
|
||||
import { TagBadge, TagDot } from "@/components/tag-badge";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -55,6 +56,7 @@ function toSearchable(r: LibraryRow): SearchableModel {
|
||||
pipelineTag: r.pipelineTag,
|
||||
license: r.license,
|
||||
status: r.status,
|
||||
hubStatus: r.hubState && r.hubState !== "available" ? HUB_STATE_LABEL[r.hubState].label : null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -218,7 +220,10 @@ export function LibraryView({ rows }: { rows: LibraryRow[] }) {
|
||||
{job.state !== "queued" && <JobProgress job={job} compact />}
|
||||
</Link>
|
||||
) : (
|
||||
<ModelStatusBadge status={r.status} />
|
||||
<span className="flex flex-wrap gap-1">
|
||||
<ModelStatusBadge status={r.status} />
|
||||
<HubStateBadge state={r.hubState} />
|
||||
</span>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getFileRoleStyles } from "@/lib/settings";
|
||||
import { listTags } from "@/lib/tags";
|
||||
import { FileLabelSettings } from "./file-label-settings";
|
||||
import { TagSettings } from "./tag-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const metadata: Metadata = { title: "Labels · Settings" };
|
||||
export const metadata: Metadata = { title: "File labels · Settings" };
|
||||
|
||||
export default async function LabelSettingsPage() {
|
||||
const [fileRoles, tags] = await Promise.all([getFileRoleStyles(), listTags()]);
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<FileLabelSettings initial={fileRoles} />
|
||||
<TagSettings tags={tags} />
|
||||
</div>
|
||||
);
|
||||
return <FileLabelSettings initial={await getFileRoleStyles()} />;
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import { TagsIcon } from "lucide-react";
|
||||
import { TagIcon, TagsIcon } from "lucide-react";
|
||||
import { SettingsNav } from "./settings-nav";
|
||||
|
||||
const SECTIONS = [{ href: "/settings/labels", label: "Labels", icon: <TagsIcon className="size-4" /> }];
|
||||
const SECTIONS = [
|
||||
{ href: "/settings/labels", label: "File labels", icon: <TagIcon className="size-4" /> },
|
||||
{ href: "/settings/tags", label: "Tags", icon: <TagsIcon className="size-4" /> },
|
||||
];
|
||||
|
||||
export default function SettingsLayout({ children }: LayoutProps<"/settings">) {
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { Metadata } from "next";
|
||||
import { listTags } from "@/lib/tags";
|
||||
import { TagSettings } from "./tag-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const metadata: Metadata = { title: "Tags · Settings" };
|
||||
|
||||
export default async function TagSettingsPage() {
|
||||
return <TagSettings tags={await listTags()} />;
|
||||
}
|
||||
+65
-6
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { Trash2Icon } from "lucide-react";
|
||||
import { PlusIcon, Trash2Icon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
@@ -19,21 +19,22 @@ import {
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { autoTagColor, isLabelColor } from "@/lib/colors";
|
||||
import { autoTagColor, isLabelColor, type LabelColor } from "@/lib/colors";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
import { ColorPicker } from "./color-picker";
|
||||
import { ColorPicker } from "../labels/color-picker";
|
||||
|
||||
/** Rename, recolor or delete user tags. Changes save immediately. */
|
||||
/** Create, rename, recolor or delete user tags. Changes save immediately. */
|
||||
export function TagSettings({ tags }: { tags: (Tag & { count: number })[] }) {
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Tags</CardTitle>
|
||||
<CardDescription>
|
||||
Your own tags (added on a model page or when adding a model). Tags without a color get an automatic one.
|
||||
Your own tags, to attach on a model page or when adding a model. Tags without a color get an automatic one.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
<NewTagRow />
|
||||
{tags.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No tags yet.</p>
|
||||
) : (
|
||||
@@ -48,6 +49,64 @@ export function TagSettings({ tags }: { tags: (Tag & { count: number })[] }) {
|
||||
);
|
||||
}
|
||||
|
||||
function NewTagRow() {
|
||||
const router = useRouter();
|
||||
const [name, setName] = useState("");
|
||||
const [color, setColor] = useState<LabelColor | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function create(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!name.trim()) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await fetch("/api/tags", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name, color }),
|
||||
});
|
||||
const json = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast.error(json.error?.message ?? `Could not create tag (${res.status})`);
|
||||
return;
|
||||
}
|
||||
toast.success(`Tag "${json.name}" created`);
|
||||
setName("");
|
||||
setColor(null);
|
||||
router.refresh();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
onSubmit={create}
|
||||
className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-2 rounded-lg border border-dashed px-4 py-3 sm:grid-cols-[8rem_minmax(0,1fr)_8rem_6rem_2rem]"
|
||||
>
|
||||
{name.trim() ? (
|
||||
<TagBadge name={name.trim()} color={color} className="justify-self-start" />
|
||||
) : (
|
||||
<span className="text-xs text-muted-foreground">New tag</span>
|
||||
)}
|
||||
<Input
|
||||
value={name}
|
||||
maxLength={40}
|
||||
disabled={busy}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="e.g. roleplay"
|
||||
aria-label="New tag name"
|
||||
className="h-8"
|
||||
/>
|
||||
<ColorPicker value={color} onChange={setColor} allowAuto autoColor={autoTagColor(name.trim())} />
|
||||
<Button type="submit" size="sm" disabled={busy || !name.trim()} className="sm:col-span-2">
|
||||
<PlusIcon />
|
||||
Add
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function TagRow({ tag }: { tag: Tag & { count: number } }) {
|
||||
const router = useRouter();
|
||||
const [name, setName] = useState(tag.name);
|
||||
@@ -0,0 +1,12 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { apiError } from "@/lib/api-errors";
|
||||
import { checkHubAvailability, getCheckedModel } from "@/lib/hub/availability";
|
||||
|
||||
/** Check right now whether the repo and pinned commit are still on the Hub. */
|
||||
export const POST = withAuth<RouteContext<"/api/models/[id]/hub-check">>(async (_req, { params }) => {
|
||||
const { id } = await params;
|
||||
const model = await getCheckedModel(id);
|
||||
if (!model) return apiError(404, "not_found", "Model not found.");
|
||||
return NextResponse.json(await checkHubAvailability(model));
|
||||
});
|
||||
@@ -1,8 +1,22 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { listTags } from "@/lib/tags";
|
||||
import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { createTag, listTags, TagError } from "@/lib/tags";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/** All user tags with usage counts. */
|
||||
export const GET = withAuth(async () => NextResponse.json(await listTags()));
|
||||
|
||||
const Body = z.object({ name: z.string(), color: z.string().nullable().optional() });
|
||||
|
||||
/** Create a tag that isn't on any model yet. */
|
||||
export const POST = withAuth(async (req) => {
|
||||
try {
|
||||
return NextResponse.json(await createTag(Body.parse(await req.json())), { status: 201 });
|
||||
} catch (err) {
|
||||
if (err instanceof TagError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { LibraryIcon, SettingsIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const LINKS = [
|
||||
{ href: "/", label: "Library", icon: LibraryIcon, active: (p: string) => !p.startsWith("/settings") && !p.startsWith("/jobs/") },
|
||||
{ href: "/settings", label: "Settings", icon: SettingsIcon, active: (p: string) => p.startsWith("/settings") },
|
||||
];
|
||||
|
||||
/** Main navigation; model and job pages count as part of the library. */
|
||||
export function AppNav() {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<nav className="flex items-center gap-1 text-sm">
|
||||
{LINKS.map((l) => {
|
||||
const active = l.active(pathname) || (l.href === "/" && pathname.startsWith("/jobs/"));
|
||||
return (
|
||||
<Link
|
||||
key={l.href}
|
||||
href={l.href}
|
||||
aria-current={active ? "page" : undefined}
|
||||
className={cn(
|
||||
"flex items-center gap-1.5 rounded-md px-2.5 py-1.5 transition-colors",
|
||||
active ? "bg-muted font-medium text-foreground" : "text-muted-foreground hover:bg-muted/60 hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<l.icon className="size-4" />
|
||||
<span className="hidden sm:inline">{l.label}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { TriangleAlertIcon } from "lucide-react";
|
||||
import type { HubState } from "@/lib/db/schema";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export const HUB_STATE_LABEL: Record<Exclude<HubState, "available">, { label: string; title: string }> = {
|
||||
repo_missing: {
|
||||
label: "deleted on Hub",
|
||||
title: "The repo is no longer on Hugging Face (deleted, or made private). Your local files are kept.",
|
||||
},
|
||||
commit_missing: {
|
||||
label: "commit deleted on Hub",
|
||||
title: "The pinned commit is no longer on Hugging Face (history rewritten). Your local files are kept.",
|
||||
},
|
||||
};
|
||||
|
||||
/** Warning badge when a model's repo or pinned commit disappeared from the Hub; nothing otherwise. */
|
||||
export function HubStateBadge({ state, className }: { state: HubState | null; className?: string }) {
|
||||
if (!state || state === "available") return null;
|
||||
const { label, title } = HUB_STATE_LABEL[state];
|
||||
return (
|
||||
<span
|
||||
title={title}
|
||||
className={cn(
|
||||
"inline-flex h-5 shrink-0 items-center gap-1 rounded-4xl border border-amber-500/30 bg-amber-500/10 px-2 text-xs font-medium whitespace-nowrap text-amber-700 dark:text-amber-300",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<TriangleAlertIcon className="size-3" />
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronDownIcon, PlusIcon, SettingsIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { TagDot } from "@/components/tag-badge";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/**
|
||||
* "Add tag" dropdown: the first entry creates a new tag (inline name field), below it the existing
|
||||
* tags that aren't picked yet. Calls `onPick` with the tag name.
|
||||
*/
|
||||
export function TagPicker({
|
||||
exclude,
|
||||
onPick,
|
||||
disabled,
|
||||
className,
|
||||
}: {
|
||||
/** Tag names already applied (case-insensitive), hidden from the list. */
|
||||
exclude: string[];
|
||||
/** Picked tag name; `tag` is set when an existing tag was chosen. */
|
||||
onPick: (name: string, tag?: Tag) => void | Promise<void>;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}) {
|
||||
const [known, setKnown] = useState<Tag[]>([]);
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const cancelled = useRef(false);
|
||||
|
||||
function load() {
|
||||
fetch("/api/tags")
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((all: Tag[]) => setKnown(all))
|
||||
.catch(() => {});
|
||||
}
|
||||
useEffect(load, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!creating) return;
|
||||
cancelled.current = false;
|
||||
inputRef.current?.focus();
|
||||
}, [creating]);
|
||||
|
||||
function finishCreating() {
|
||||
setCreating(false);
|
||||
setName("");
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
const value = name.trim();
|
||||
const existing = known.find((t) => t.name.toLowerCase() === value.toLowerCase());
|
||||
if (value) await onPick(existing?.name ?? value, existing);
|
||||
finishCreating();
|
||||
}
|
||||
|
||||
if (creating) {
|
||||
return (
|
||||
<form
|
||||
className={className}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
inputRef.current?.blur(); // blur submits, so Enter and click-away can't add twice
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
ref={inputRef}
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
onBlur={() => (name.trim() && !cancelled.current ? void submit() : finishCreating())}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key !== "Escape") return;
|
||||
cancelled.current = true;
|
||||
inputRef.current?.blur();
|
||||
}}
|
||||
placeholder="New tag name…"
|
||||
disabled={disabled}
|
||||
maxLength={40}
|
||||
className="h-6 w-40 text-xs"
|
||||
aria-label="New tag name"
|
||||
/>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
const hidden = new Set(exclude.map((n) => n.toLowerCase()));
|
||||
const available = known.filter((t) => !hidden.has(t.name.toLowerCase()));
|
||||
return (
|
||||
<DropdownMenu onOpenChange={(open) => open && load()}>
|
||||
<DropdownMenuTrigger
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
"inline-flex h-6 items-center gap-1 rounded-full border border-dashed px-2 text-xs text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-50",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<PlusIcon className="size-3" />
|
||||
Add tag
|
||||
<ChevronDownIcon className="size-3 opacity-60" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="max-h-72 w-auto min-w-44">
|
||||
<DropdownMenuItem onClick={() => setCreating(true)}>
|
||||
<PlusIcon />
|
||||
Create new tag…
|
||||
</DropdownMenuItem>
|
||||
{available.length > 0 && <DropdownMenuSeparator />}
|
||||
{available.map((t) => (
|
||||
<DropdownMenuItem key={t.id} onClick={() => void onPick(t.name, t)}>
|
||||
<TagDot name={t.name} color={t.color} />
|
||||
{t.name}
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem render={<Link href="/settings/tags" />} className="text-muted-foreground">
|
||||
<SettingsIcon />
|
||||
Manage tags…
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
"use client";
|
||||
|
||||
import { LogOutIcon, MonitorIcon, MoonIcon, SunIcon, TagIcon, TagsIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useTheme } from "next-themes";
|
||||
import { useTransition } from "react";
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
|
||||
export type MenuUser = { name: string | null; email: string | null; image: string | null };
|
||||
|
||||
function initials(user: MenuUser): string {
|
||||
const source = user.name || user.email || "?";
|
||||
const parts = source.split(/[\s@._-]+/).filter(Boolean);
|
||||
return ((parts[0]?.[0] ?? "?") + (parts.length > 1 ? parts[1][0] : "")).toUpperCase();
|
||||
}
|
||||
|
||||
function UserAvatar({ user, size }: { user: MenuUser; size?: "sm" | "default" | "lg" }) {
|
||||
return (
|
||||
<Avatar size={size}>
|
||||
{user.image && <AvatarImage src={user.image} alt="" referrerPolicy="no-referrer" />}
|
||||
<AvatarFallback className="text-xs font-medium">{initials(user)}</AvatarFallback>
|
||||
</Avatar>
|
||||
);
|
||||
}
|
||||
|
||||
/** Avatar from the OIDC profile; opens a menu with account info, settings, theme and sign out. */
|
||||
export function UserMenu({ user, signOutAction }: { user: MenuUser; signOutAction: () => Promise<void> }) {
|
||||
const { theme, setTheme } = useTheme();
|
||||
const [signingOut, startSignOut] = useTransition();
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
aria-label="Account menu"
|
||||
className="flex items-center gap-2 rounded-full p-0.5 outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 sm:pr-3"
|
||||
>
|
||||
<UserAvatar user={user} />
|
||||
<span className="hidden max-w-40 truncate text-sm sm:inline">{user.name ?? user.email}</span>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-64">
|
||||
<div className="flex items-center gap-3 px-1.5 py-2">
|
||||
<UserAvatar user={user} size="lg" />
|
||||
<div className="flex min-w-0 flex-col">
|
||||
<span className="truncate text-sm font-medium">{user.name ?? "Signed in"}</span>
|
||||
{user.email && <span className="truncate text-xs text-muted-foreground">{user.email}</span>}
|
||||
</div>
|
||||
</div>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuLabel>Settings</DropdownMenuLabel>
|
||||
<DropdownMenuItem render={<Link href="/settings/labels" />}>
|
||||
<TagIcon />
|
||||
File labels
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem render={<Link href="/settings/tags" />}>
|
||||
<TagsIcon />
|
||||
Tags
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuLabel>Theme</DropdownMenuLabel>
|
||||
<DropdownMenuRadioGroup value={theme ?? "system"} onValueChange={(v) => setTheme(v as string)}>
|
||||
<DropdownMenuRadioItem value="system" closeOnClick={false}>
|
||||
<MonitorIcon />
|
||||
System
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="light" closeOnClick={false}>
|
||||
<SunIcon />
|
||||
Light
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value="dark" closeOnClick={false}>
|
||||
<MoonIcon />
|
||||
Dark
|
||||
</DropdownMenuRadioItem>
|
||||
</DropdownMenuRadioGroup>
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive" disabled={signingOut} onClick={() => startSignOut(() => signOutAction())}>
|
||||
<LogOutIcon />
|
||||
{signingOut ? "Signing out…" : "Sign out"}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -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
@@ -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 },
|
||||
|
||||
@@ -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
@@ -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 },
|
||||
|
||||
@@ -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
@@ -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
@@ -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). */
|
||||
|
||||
@@ -9,6 +9,7 @@ import { db } from "@/lib/db/client";
|
||||
import { runMigrations } from "@/lib/db/migrate";
|
||||
import { ACTIVE_JOB_STATES, jobFiles, jobLogs, jobs, modelFiles, models, workerState } from "@/lib/db/schema";
|
||||
import { coreEnv } from "@/lib/env";
|
||||
import { checkHubAvailability, modelsDueForHubCheck } from "@/lib/hub/availability";
|
||||
import { backfillMetadata } from "@/lib/hub/refresh";
|
||||
import { DownloadRunner } from "./download";
|
||||
import { log } from "./log";
|
||||
@@ -19,6 +20,8 @@ const TICK_MS = 1_000;
|
||||
/** A lease older than this is considered abandoned (worker crashed without releasing it). */
|
||||
const LEASE_STALE_MS = 20_000;
|
||||
const SHUTDOWN_GRACE_MS = 8_000;
|
||||
/** How often to look for models whose Hub check is due (the check interval itself is configurable). */
|
||||
const HUB_CHECK_SCAN_MS = 10 * 60_000;
|
||||
/** Touched on every heartbeat; the Docker healthcheck checks its age. */
|
||||
const HEALTH_FILE = join(tmpdir(), "kaname-worker-alive");
|
||||
|
||||
@@ -208,10 +211,42 @@ async function startJob(job: typeof jobs.$inferSelect) {
|
||||
log.info(`job ${job.id}: downloading ${model.repoId} (${files.length} files, attempt ${job.attempt})`);
|
||||
runner
|
||||
.run()
|
||||
.then(async () => {
|
||||
// A failed download may mean the repo or commit is gone from the Hub; find out right away.
|
||||
const done = await db().query.jobs.findFirst({ columns: { state: true }, where: eq(jobs.id, job.id) });
|
||||
if (done?.state === "failed") await reportHubCheck(model, await checkHubAvailability(model));
|
||||
})
|
||||
.catch((err) => log.error(`job ${job.id} crashed`, err))
|
||||
.finally(() => runners.delete(job.id));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Hub availability: flags models whose repo or pinned commit disappeared from the Hub
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function reportHubCheck(model: { repoId: string }, result: Awaited<ReturnType<typeof checkHubAvailability>>) {
|
||||
if (result.state === null) log.warn(`Hub check for ${model.repoId} failed: ${result.error}`);
|
||||
else if (result.state !== "available") log.warn(`${model.repoId}: ${result.state.replace("_", " ")} on the Hub (local files kept)`);
|
||||
}
|
||||
|
||||
let checkingHub = false;
|
||||
async function checkHubDue() {
|
||||
const hours = coreEnv().UPDATE_CHECK_INTERVAL_HOURS;
|
||||
if (checkingHub || stopping || hours <= 0) return;
|
||||
checkingHub = true;
|
||||
try {
|
||||
for (const model of await modelsDueForHubCheck(hours * 3_600_000)) {
|
||||
if (stopping) break;
|
||||
reportHubCheck(model, await checkHubAvailability(model));
|
||||
await sleep(1_000); // be gentle with the Hub API
|
||||
}
|
||||
} catch (err) {
|
||||
log.error("Hub check failed", err);
|
||||
} finally {
|
||||
checkingHub = false;
|
||||
}
|
||||
}
|
||||
|
||||
let ticking = false;
|
||||
async function tick() {
|
||||
if (ticking || stopping) return;
|
||||
@@ -278,7 +313,9 @@ async function main() {
|
||||
await heartbeat();
|
||||
timers.push(setInterval(() => heartbeat().catch((err) => log.error("heartbeat failed", err)), HEARTBEAT_MS));
|
||||
timers.push(setInterval(() => void tick(), TICK_MS));
|
||||
timers.push(setInterval(() => void checkHubDue(), HUB_CHECK_SCAN_MS));
|
||||
void tick();
|
||||
setTimeout(() => void checkHubDue(), 15_000);
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
|
||||
Reference in new issue
Block a user