Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2c239bf16 | ||
|
|
0247f257fb | ||
|
|
145818f149 | ||
|
|
3603742637 | ||
|
|
df18415e02 | ||
|
|
5211ec9064 | ||
|
|
6dc9527682 | ||
|
|
5fadd64367 | ||
|
|
1527fcd830 | ||
|
|
d16bd6dfee | ||
|
|
67191b3e16 |
No files matched your search
+38
-26
@@ -1,32 +1,44 @@
|
||||
# Hugging Face token (server-side only; passed to the hf CLI via environment)
|
||||
# ---------------------------------------------------------------------------
|
||||
# Required
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# URL you open Kaname at in the browser. Your OIDC redirect URI is
|
||||
# <AUTH_URL>/api/auth/callback/pocket-id
|
||||
AUTH_URL=http://localhost:3000
|
||||
# Random secret for session cookies: `openssl rand -base64 33`
|
||||
AUTH_SECRET=
|
||||
|
||||
# OIDC provider (e.g. Pocket ID): authorization code flow with PKCE
|
||||
OIDC_ISSUER=https://auth.example.com
|
||||
OIDC_CLIENT_ID=
|
||||
OIDC_CLIENT_SECRET=
|
||||
# Optional, comma-separated: only members of these groups (`groups` claim) can log in.
|
||||
OIDC_ALLOWED_GROUPS=
|
||||
|
||||
# Hugging Face token: read-only is enough. Needed for gated/private repos, recommended anyway
|
||||
# (higher rate limits). Stays on the server; never sent to the browser or written to logs.
|
||||
HF_TOKEN=
|
||||
# Where models are stored: <MODELS_DIR>/<org>/<repo>
|
||||
MODELS_DIR=/models
|
||||
# SQLite database (keep on a local volume, not NFS)
|
||||
DATABASE_URL=file:/data/app.db
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Folders on the Docker host (deploy/compose.yaml); both must be owned by uid 1000
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# SQLite database, shared by web and worker. Must be on local disk, not NFS.
|
||||
KANAME_DATA_DIR=./data
|
||||
# Downloaded models. Can be a NAS share mounted on the host, e.g. /mnt/nas/models.
|
||||
KANAME_MODELS_DIR=./models
|
||||
# Host port of the web UI
|
||||
WEB_PORT=3000
|
||||
# Image tag to run, e.g. 0.4.0 (default: latest)
|
||||
KANAME_VERSION=
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Optional tuning
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
MAX_CONCURRENT_DOWNLOADS=1
|
||||
# 0 disables the periodic update check
|
||||
# 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.
|
||||
HF_HUB_DISABLE_XET=1
|
||||
|
||||
# Auth.js: generate with `npx auth secret` or `openssl rand -base64 33`
|
||||
AUTH_SECRET=
|
||||
# Public URL of this app; OIDC redirect URI is <AUTH_URL>/api/auth/callback/pocket-id
|
||||
AUTH_URL=https://models.example.com
|
||||
OIDC_ISSUER=https://auth.example.com
|
||||
OIDC_CLIENT_ID=
|
||||
OIDC_CLIENT_SECRET=
|
||||
# Optional, comma-separated. If set, only members of these groups (from the `groups` claim) can log in.
|
||||
OIDC_ALLOWED_GROUPS=
|
||||
|
||||
# --- deploy/compose.yaml only -------------------------------------------------
|
||||
# Image tag to run (default: latest)
|
||||
KANAME_VERSION=
|
||||
# Host folder for the SQLite DB, shared by web and worker. Local disk, not NFS. Owner uid 1000.
|
||||
KANAME_DATA_DIR=./data
|
||||
WEB_PORT=3000
|
||||
# NFS export for the models (NFSv4, writable by uid 1000)
|
||||
NFS_SERVER=truenas.lan
|
||||
NFS_EXPORT=/mnt/tank/models
|
||||
+101
@@ -6,6 +6,107 @@ step 1 (Hugging Face downloader) is released as a minor version.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.5.0] - 2026-10-06
|
||||
|
||||
Hugging Face style model pages, file labels, recommended files, importing models already on disk,
|
||||
and flagging models deleted from the Hub. Database migrations run automatically on start.
|
||||
|
||||
### Added
|
||||
|
||||
- Model pages modeled on Hugging Face, built from cards: a header with org avatar, `org / name`
|
||||
with copy button, pills for task, format, architecture, language and license, your tags and a
|
||||
Hugging Face link; a content card with tabs:
|
||||
- **Files** (default): selected files with type icon, size, LFS marker and local state
|
||||
(downloaded, missing, size mismatch, …), a "on disk" progress summary, and the unselected repo
|
||||
files collapsed below; each file links to the Hub at the pinned commit
|
||||
- **Model card**: the repo's README at the pinned commit, rendered (sanitized HTML, relative
|
||||
links/images resolved to the Hub)
|
||||
- **Jobs**: download history
|
||||
- Custom tags are color-coded: automatic color from the name, or one you pick in Settings.
|
||||
- File labels in front of every file name: Model, MTP, Vision (mmproj), Draft, Adapter, imatrix,
|
||||
Config, Tokenizer, Template, Docs, Image, Git (detected from the file name).
|
||||
- Split files (`…-00001-of-00003.gguf`) are shown and selected as one entry with "N parts", the
|
||||
combined size and a combined status, in the Files tab, Add model, Download more and progress lists.
|
||||
- **Download more** in the Files tab: pick additional files (quick-select chips, checkboxes) and
|
||||
download them; they're added to the model's selection. Files already on disk are skipped.
|
||||
- **Settings** page (`/settings`), first section **Labels**: name and color per file label (with
|
||||
reset), and rename, recolor or delete your tags. Stored in a new `settings` table.
|
||||
- App icon (要).
|
||||
- Sidebar with download status/actions, local copy details (commit, path, patterns) and a model
|
||||
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".
|
||||
- **Import models already on disk:** the worker scans the models folder (at startup, every
|
||||
2 minutes and on "Rescan") for `<org>/<name>` folders that aren't in the library. They're listed
|
||||
under "Found in the models folder"; **Import** opens Add model for that folder with the repo, the
|
||||
commit hf recorded (if any) and the files already there preselected, marked "on disk". The import
|
||||
job runs `hf download` into the existing folder: hf 2.1.1 hashes files it didn't download itself,
|
||||
keeps those that match and downloads only missing or different ones. Other files in the folder
|
||||
are left alone. Jobs show the purpose "import".
|
||||
- **Recommended files:** picking a quant (chip or checkbox) in Add model or Download more also
|
||||
selects the files that usually go with it, shown in a "Recommended with your quant" strip where
|
||||
each can be unchecked. They drop out again when you deselect the quant. Variants are matched:
|
||||
the MTP head or mmproj with the same quant if there is one, otherwise the best single one (mmproj:
|
||||
F16, BF16, Q8_0, F32); nothing is added if the model already has one of that kind. Which kinds
|
||||
(default: chat template, MTP, vision) is set in the new **Settings → Downloads**.
|
||||
- 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
|
||||
|
||||
- Model URLs are the repo path, like on Hugging Face: `/unsloth/Qwen3-8B-GGUF` (case-insensitive,
|
||||
redirects to the canonical spelling). Old `/models/<id>` links redirect.
|
||||
- The auth gate excludes only exact paths (`/login`, `/api/auth/…`), so org names like `loginx`
|
||||
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**, **Tags** and **Downloads**.
|
||||
- The selection bar at the bottom of Add model is a floating card like the rest of the page.
|
||||
- Header: app icon, navigation with icons and the current page highlighted.
|
||||
- Docs: full configuration reference and the NAS guide moved to the
|
||||
[wiki](https://git.linxweiler.xyz/pascallinxweiler/Kaname/wiki); the README keeps the quick install.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Hydration error in progress bars on non-English browsers (locale-dependent `aria-valuetext`).
|
||||
|
||||
## [0.4.0] - 2026-10-05
|
||||
|
||||
The app is now called **Kaname**; search, filters and tags.
|
||||
|
||||
### Added
|
||||
|
||||
- Library search: every word must match the repo, author, model family, base model, architecture,
|
||||
quant, tags, Hub tags or status (e.g. `unsloth qwen`, `q4_k_m`, `roleplay`).
|
||||
- Library filters for Author, Family, Quant, Tag and Status (multi-select with counts, combinable,
|
||||
kept in the URL), removable filter chips and "N of M models".
|
||||
- Hub metadata per model: base model(s), architecture, license, pipeline tag and Hub tags. The
|
||||
"family" is the base model's org (an unsloth quant of Qwen3 → `Qwen`). Stored when a model is
|
||||
added; the worker fetches it for existing models on startup.
|
||||
- Custom tags: add/remove on the model page (with suggestions), set them when adding a model,
|
||||
click a tag in the library to filter. Tags are case-insensitive and deleted when unused.
|
||||
- Model page shows author, family, base model links, architecture, license and Hub tags.
|
||||
- README rewritten around a four-step install, with a banner and screenshots.
|
||||
|
||||
### Changed
|
||||
|
||||
- Renamed the app from "Model Manager" to "Kaname".
|
||||
- `deploy/compose.yaml`: models go to a host folder (`KANAME_MODELS_DIR`, default `./models`;
|
||||
a NAS share mounted on the host works) instead of a Docker NFS volume, so the default setup
|
||||
needs no NAS. `NFS_SERVER`/`NFS_EXPORT` are gone.
|
||||
- `.env.example` is ordered by what you need to fill in; container-internal paths
|
||||
(`DATABASE_URL`, `MODELS_DIR`) are no longer in it because the image defaults are correct.
|
||||
|
||||
## [0.3.1] - 2026-10-05
|
||||
|
||||
Release pipeline, server deployment and a simpler library page.
|
||||
|
||||
@@ -1,94 +1,126 @@
|
||||
# Model Manager
|
||||
<p align="center">
|
||||
<img src="docs/banner.png" alt="Kaname: self-hosted model manager for Hugging Face" width="100%" />
|
||||
</p>
|
||||
|
||||
Self-hosted web UI for downloading and managing local LLMs from Hugging Face.
|
||||
Downloads are done by the official `hf` CLI; the Hub API is used for metadata.
|
||||
**Kaname** (要, "the pivot") is a self-hosted web app for downloading and managing local LLMs from
|
||||
Hugging Face. Look up a repo, pick the quant you want, and Kaname downloads exactly those files with
|
||||
the official `hf` CLI, pinned to a specific commit so every download is reproducible.
|
||||
|
||||
## Architecture
|
||||
- **Pick files, not whole repos:** one-click quant selection for GGUF repos, or include/exclude globs.
|
||||
- **Pinned and reproducible:** every model is pinned to the exact commit SHA you reviewed.
|
||||
- **Downloads in the background:** live progress, speed and ETA per file; keeps going when you close
|
||||
the browser; cancel any time.
|
||||
- **Find things again:** search and filter by author, model family (e.g. Qwen, Gemma), quant, status
|
||||
and your own tags like `roleplay` or `security`.
|
||||
- **Homelab-friendly:** two containers, SQLite, OIDC single sign-on (e.g. Pocket ID), models on any
|
||||
folder or NAS share.
|
||||
|
||||
- **web** (`next start`): Next.js App Router UI + API routes, OIDC login via Auth.js.
|
||||
- **worker** (`src/worker`): owns the job queue, spawns `hf download`, tracks progress from bytes on
|
||||
disk, applies DB migrations at startup. Only one worker runs at a time (DB lease).
|
||||
- They talk only through the SQLite database (`DATABASE_URL`); the UI gets live updates via SSE
|
||||
(`/api/stream`).
|
||||
## Install
|
||||
|
||||
## Run with Docker (recommended)
|
||||
You need Docker with Compose and an OIDC provider (e.g. [Pocket ID](https://pocket-id.org)).
|
||||
|
||||
**1. Get the compose file and the config template**
|
||||
|
||||
```bash
|
||||
cp .env.example .env # fill in HF_TOKEN, AUTH_SECRET, OIDC_*; AUTH_URL = URL you open in the browser
|
||||
docker compose up --build
|
||||
mkdir kaname && cd kaname
|
||||
curl -fsSLo compose.yaml https://git.linxweiler.xyz/pascallinxweiler/Kaname/raw/branch/main/deploy/compose.yaml
|
||||
curl -fsSLo .env https://git.linxweiler.xyz/pascallinxweiler/Kaname/raw/branch/main/.env.example
|
||||
```
|
||||
|
||||
Open `AUTH_URL` (e.g. http://localhost:3000). `WEB_PORT=3100 docker compose up` changes the host port.
|
||||
Volumes: `data` (SQLite + hf home, keep on local disk) and `models` (downloaded models).
|
||||
**2. Create an OIDC client** in your identity provider with the redirect URI
|
||||
`<AUTH_URL>/api/auth/callback/pocket-id`, e.g. `http://192.168.1.10:3000/api/auth/callback/pocket-id`.
|
||||
Request the `groups` scope if you want to restrict access by group.
|
||||
|
||||
OIDC redirect URI for the client in Pocket ID: `<AUTH_URL>/api/auth/callback/pocket-id`.
|
||||
**3. Fill in `.env`.** At minimum: `AUTH_URL` (the address you open in the browser), `AUTH_SECRET`
|
||||
(`openssl rand -base64 33`), `OIDC_ISSUER`, `OIDC_CLIENT_ID`, `OIDC_CLIENT_SECRET`, and ideally a
|
||||
read-only `HF_TOKEN`.
|
||||
|
||||
## Releases and deployment
|
||||
|
||||
Pushing a tag `vX.Y.Z` (must equal `version` in `package.json` and have a `## [X.Y.Z]` section in
|
||||
`CHANGELOG.md`) runs `.gitea/workflows/release.yaml` on Gitea Actions:
|
||||
|
||||
1. lint, typecheck, unit tests
|
||||
2. builds the image and pushes `git.linxweiler.xyz/pascallinxweiler/kaname:X.Y.Z`, `:X.Y` and `:latest`
|
||||
3. creates a Gitea release with the CHANGELOG section as notes
|
||||
|
||||
Requirements: an `act_runner` registered for the repo/user with Docker access, and a repo secret
|
||||
`REGISTRY_TOKEN` (personal access token with *package: read and write*).
|
||||
|
||||
On the server you only need `deploy/compose.yaml` and a filled-in `.env` (from `.env.example`) in
|
||||
one folder; no source code, no Dockerfile:
|
||||
**4. Create the folders and start**
|
||||
|
||||
```bash
|
||||
mkdir -p data && sudo chown 1000:1000 data # SQLite DB, shared by web and worker (local disk!)
|
||||
docker compose pull && docker compose up -d
|
||||
mkdir -p data models && sudo chown 1000:1000 data models
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
Storage layout on the server:
|
||||
Open your `AUTH_URL`, sign in, click **Add model**. That's it.
|
||||
|
||||
- `KANAME_DATA_DIR` (default `./data`): bind mount for the SQLite DB, mounted by both services.
|
||||
Must be on local disk (SQLite breaks on NFS) and owned by uid 1000.
|
||||
- `models`: NFS volume from `NFS_SERVER`/`NFS_EXPORT`, mounted only by the worker. Use NFSv4
|
||||
(hf needs file locks) and make the dataset writable for uid 1000 (owner 1000, or TrueNAS
|
||||
*Mapall User/Group*). After changing NFS settings: `docker compose down && docker volume rm kaname_models`.
|
||||
**Updating:** `docker compose pull && docker compose up -d`. To stay on a version, set e.g.
|
||||
`KANAME_VERSION=0.4.0` in `.env`. The running version is shown next to the app name.
|
||||
|
||||
Pin a version with `KANAME_VERSION=0.4.0` in `.env`; the running version is shown next to the app
|
||||
name in the header.
|
||||
## Configuration
|
||||
|
||||
The image picks its role from the first argument: `web` (default) or `worker`. Both run pending
|
||||
DB migrations at startup (serialized with a file lock on `/data`), and the image has a built-in
|
||||
healthcheck for both roles.
|
||||
All settings live in `.env`. The four steps above cover the required ones; the **[configuration
|
||||
reference in the wiki](https://git.linxweiler.xyz/pascallinxweiler/Kaname/wiki/Configuration)**
|
||||
lists every option with defaults and examples (folders, ports, download tuning, OIDC groups, which
|
||||
Hugging Face token to use).
|
||||
|
||||
## Local development
|
||||
Models end up in `<models folder>/<org>/<repo>/`, e.g. `models/unsloth/Qwen3-8B-GGUF/`.
|
||||
More guides are in the [wiki](https://git.linxweiler.xyz/pascallinxweiler/Kaname/wiki).
|
||||
|
||||
## Using it
|
||||
|
||||
<p align="center">
|
||||
<img src="docs/screenshots/add-model.png" alt="Adding a model: quant quick-select" width="100%" />
|
||||
</p>
|
||||
|
||||
- **Add model:** enter a repo ID like `unsloth/Qwen3-8B-GGUF` (or paste the URL), click a quant, and
|
||||
**Add & download**. Files that belong with the quant (chat template, MTP head, vision projector)
|
||||
are selected along with it; choose which kinds in Settings → Downloads. You can add tags right there.
|
||||
- **Search:** type anything: `unsloth qwen`, `q4_k_m`, `gemma`, `roleplay`. Every word has to match
|
||||
somewhere (repo, author, base model family, architecture, quant, tags).
|
||||
- **Filter:** combine Author, Family, Quant, Tag and Status filters. The URL keeps the filters, so
|
||||
you can bookmark a view.
|
||||
- **Tags:** add or remove your own tags on a model's page; click a tag in the list to filter by it.
|
||||
Create, rename and color them in Settings.
|
||||
- **Import:** models you already have in the models folder (as `<org>/<name>`) show up under
|
||||
"Found in the models folder"; **Import** matches them with the Hub repo and verifies the files
|
||||
instead of downloading them again. See the
|
||||
[wiki](https://git.linxweiler.xyz/pascallinxweiler/Kaname/wiki/Importing-existing-models).
|
||||
- **Deleted on the Hub:** if a repo (or its pinned commit) disappears from Hugging Face, the model
|
||||
is flagged and your local copy is kept.
|
||||
- **Jobs:** each download has a page with per-file progress and the full `hf` log.
|
||||
|
||||
## How it works
|
||||
|
||||
Two containers from the same image share one SQLite database:
|
||||
|
||||
- **web:** Next.js UI and API, OIDC login (Auth.js); live updates via Server-Sent Events.
|
||||
- **worker:** runs the download queue, spawns `hf download --revision <sha> --include <files>`, and
|
||||
measures progress from bytes on disk. Only one worker runs at a time.
|
||||
|
||||
Notes on the `hf` CLI (huggingface_hub 2.1.1, pinned in the image):
|
||||
|
||||
- Interrupted files are **not resumed**: a re-run skips finished files and restarts unfinished ones.
|
||||
Kaname cleans up the leftover partial files.
|
||||
- With Xet transfers the partial file only grows in large bursts, so Kaname disables Xet by default
|
||||
to show accurate progress.
|
||||
- `hf` exits successfully even if nothing matched, so Kaname checks every file's size and hash
|
||||
metadata after each download.
|
||||
- Files that already exist in the target folder without hf's metadata (copied in by hand) are
|
||||
hashed and kept if they match, and downloaded again if not. Imports rely on this.
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm run dev # web (http://localhost:3000) + worker
|
||||
cp .env.example .env # plus DATABASE_URL=file:./data/app.db and MODELS_DIR=./data/models
|
||||
npm run dev # web on http://localhost:3000 + worker
|
||||
```
|
||||
|
||||
Use local paths in `.env` (`DATABASE_URL=file:./data/app.db`, `MODELS_DIR=./data/models`).
|
||||
The worker needs the `hf` CLI on `PATH` (`pip install "huggingface_hub[hf_xet]==2.1.1"`); without it
|
||||
everything but downloading works. Don't point a Windows-native web app and a containerized worker at
|
||||
the same SQLite file: SQLite locking doesn't work across that boundary.
|
||||
The worker needs `hf` on `PATH` (`pip install "huggingface_hub[hf_xet]==2.1.1"`). Without it,
|
||||
everything but downloading works. `docker compose up --build` (root `compose.yaml`) builds and runs
|
||||
the image locally.
|
||||
|
||||
| Script | What it does |
|
||||
| --- | --- |
|
||||
| `npm run dev:web` / `npm run dev:worker` | run one side only |
|
||||
| `npm run db:generate` | create a migration after changing `src/lib/db/schema.ts` |
|
||||
| `npm run db:migrate` | apply migrations without starting the worker |
|
||||
| `npm run build:worker` | bundle the worker to `dist/worker.mjs` (used in the image) |
|
||||
| `npm test` | unit tests (Node test runner via tsx) |
|
||||
| `npm test` | unit tests |
|
||||
| `npm run typecheck`, `npm run lint` | checks |
|
||||
| `npm run db:generate` | new migration after changing `src/lib/db/schema.ts` |
|
||||
| `npm run build:worker` | bundle worker + migrate script into `dist/` (used by the image) |
|
||||
|
||||
## How `hf download` behaves (huggingface_hub 2.1.1)
|
||||
|
||||
Verified in a container; the image pins this version. Re-check before bumping it.
|
||||
|
||||
- With `--local-dir`, partial files live in `<dir>/.cache/huggingface/download/` as
|
||||
`<hash>.<etag>.<random>.incomplete` and are moved into place when complete.
|
||||
- **Partial files are not resumed.** A re-run skips completed files but restarts unfinished ones
|
||||
from zero (new random name). The worker deletes leftover partials.
|
||||
- With Xet enabled the partial file only grows in large bursts, so the worker sets
|
||||
`HF_HUB_DISABLE_XET=1` by default for accurate progress (configurable in `.env`).
|
||||
- SIGTERM stops a download (exit 143); SIGINT does not stop a Xet download.
|
||||
- Exit code 0 doesn't guarantee the files are there (e.g. a pattern that matched nothing), so the
|
||||
worker checks every expected file's size and metadata afterwards.
|
||||
**Releases:** bump `version` in `package.json`, add a `## [X.Y.Z]` section to
|
||||
[`CHANGELOG.md`](CHANGELOG.md), commit and push a `vX.Y.Z` tag. Gitea Actions
|
||||
([`.gitea/workflows/release.yaml`](.gitea/workflows/release.yaml)) runs the checks, pushes
|
||||
`git.linxweiler.xyz/pascallinxweiler/kaname:X.Y.Z` (+ `X.Y`, `latest`) and creates the release.
|
||||
It needs an `act_runner` with Docker access and a `REGISTRY_TOKEN` repo secret (package read/write).
|
||||
+5
-17
@@ -1,6 +1,6 @@
|
||||
# Server setup: put this file and a filled-in .env (from .env.example) in a folder, then
|
||||
# mkdir -p data && sudo chown 1000:1000 data
|
||||
# docker compose pull && docker compose up -d
|
||||
# Kaname: put this file and a filled-in .env (from .env.example) in one folder, then
|
||||
# mkdir -p data models && sudo chown 1000:1000 data models
|
||||
# docker compose up -d
|
||||
name: kaname
|
||||
|
||||
services:
|
||||
@@ -9,8 +9,8 @@ services:
|
||||
command: worker
|
||||
env_file: .env
|
||||
volumes:
|
||||
- ${KANAME_DATA_DIR:-./data}:/data
|
||||
- models:/models
|
||||
- ${KANAME_DATA_DIR:-./data}:/data # SQLite DB, shared with web (local disk, not NFS)
|
||||
- ${KANAME_MODELS_DIR:-./models}:/models # downloaded models (a host-mounted NAS share works)
|
||||
restart: unless-stopped
|
||||
|
||||
web:
|
||||
@@ -20,15 +20,3 @@ services:
|
||||
volumes:
|
||||
- ${KANAME_DATA_DIR:-./data}:/data
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
# Downloaded models on the NAS (only the worker mounts it). NFSv4 because hf uses file locks;
|
||||
# "hard" makes writes wait while the NAS is unreachable instead of failing half-written.
|
||||
# Docker keeps these options once the volume exists: after changing them, run
|
||||
# `docker compose down && docker volume rm kaname_models` (files on the NAS are not touched).
|
||||
models:
|
||||
driver: local
|
||||
driver_opts:
|
||||
type: nfs
|
||||
o: "addr=${NFS_SERVER:?set NFS_SERVER in .env},nfsvers=4.1,rw,hard,noatime"
|
||||
device: ":${NFS_EXPORT:?set NFS_EXPORT in .env}"
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 705 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 219 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 233 KiB |
@@ -0,0 +1,24 @@
|
||||
CREATE TABLE `model_tags` (
|
||||
`model_id` text NOT NULL,
|
||||
`tag_id` text NOT NULL,
|
||||
`created_at` integer NOT NULL,
|
||||
PRIMARY KEY(`model_id`, `tag_id`),
|
||||
FOREIGN KEY (`model_id`) REFERENCES `models`(`id`) ON UPDATE no action ON DELETE no action,
|
||||
FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE no action
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `model_tags_tag_idx` ON `model_tags` (`tag_id`);--> statement-breakpoint
|
||||
CREATE TABLE `tags` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`slug` text NOT NULL,
|
||||
`created_at` integer NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `tags_slug_uq` ON `tags` (`slug`);--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `base_models` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `architecture` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `pipeline_tag` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `license` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `hub_tags` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `metadata_fetched_at` integer;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `models` ADD `base_relation` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `author_avatar_url` text;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Refetch Hub metadata once so existing models get author avatar and base relation.
|
||||
UPDATE `models` SET `metadata_fetched_at` = NULL;
|
||||
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE `settings` (
|
||||
`key` text PRIMARY KEY NOT NULL,
|
||||
`value` text NOT NULL,
|
||||
`updated_at` integer NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `tags` ADD `color` text;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE `models` ADD `hub_state` text;--> statement-breakpoint
|
||||
ALTER TABLE `models` ADD `hub_missing_since` integer;
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE `local_folders` (
|
||||
`path` text PRIMARY KEY NOT NULL,
|
||||
`files` text NOT NULL,
|
||||
`file_count` integer NOT NULL,
|
||||
`total_bytes` integer NOT NULL,
|
||||
`commit` text,
|
||||
`scanned_at` integer NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE `worker_state` ADD `scan_requested_at` integer;
|
||||
@@ -0,0 +1,894 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "9c67e3d1-730e-4c71-ac1e-2ec7d0d37dea",
|
||||
"prevId": "ccc02033-9cf0-4202-af94-36f060837602",
|
||||
"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
|
||||
},
|
||||
"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
|
||||
},
|
||||
"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": {}
|
||||
},
|
||||
"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
|
||||
},
|
||||
"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": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,908 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "024725ee-3ede-4d7d-85b0-52dfd38971f8",
|
||||
"prevId": "9c67e3d1-730e-4c71-ac1e-2ec7d0d37dea",
|
||||
"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
|
||||
},
|
||||
"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": {}
|
||||
},
|
||||
"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
|
||||
},
|
||||
"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": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,908 @@
|
||||
{
|
||||
"id": "0388c49a-d01a-4c5a-9694-0d844297213f",
|
||||
"prevId": "024725ee-3ede-4d7d-85b0-52dfd38971f8",
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"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",
|
||||
"columnsFrom": [
|
||||
"job_id"
|
||||
],
|
||||
"tableTo": "jobs",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "no action"
|
||||
},
|
||||
"job_files_model_file_id_model_files_id_fk": {
|
||||
"name": "job_files_model_file_id_model_files_id_fk",
|
||||
"tableFrom": "job_files",
|
||||
"columnsFrom": [
|
||||
"model_file_id"
|
||||
],
|
||||
"tableTo": "model_files",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "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",
|
||||
"columnsFrom": [
|
||||
"job_id"
|
||||
],
|
||||
"tableTo": "jobs",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "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",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"tableTo": "models",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "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",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"tableTo": "models",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "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",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"tableTo": "models",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "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",
|
||||
"columnsFrom": [
|
||||
"model_id"
|
||||
],
|
||||
"tableTo": "models",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "no action"
|
||||
},
|
||||
"model_tags_tag_id_tags_id_fk": {
|
||||
"name": "model_tags_tag_id_tags_id_fk",
|
||||
"tableFrom": "model_tags",
|
||||
"columnsFrom": [
|
||||
"tag_id"
|
||||
],
|
||||
"tableTo": "tags",
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onUpdate": "no action",
|
||||
"onDelete": "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
|
||||
},
|
||||
"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": {}
|
||||
},
|
||||
"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
|
||||
},
|
||||
"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": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
},
|
||||
"internal": {
|
||||
"indexes": {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,946 @@
|
||||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "84e7c88b-53c4-4eba-8f2f-7de08b494316",
|
||||
"prevId": "0388c49a-d01a-4c5a-9694-0d844297213f",
|
||||
"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
|
||||
},
|
||||
"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": {}
|
||||
}
|
||||
}
|
||||
@@ -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": {}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -22,6 +22,48 @@
|
||||
"when": 1791210991713,
|
||||
"tag": "0002_worker_lease",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "6",
|
||||
"when": 1791221700558,
|
||||
"tag": "0003_model_metadata_and_tags",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "6",
|
||||
"when": 1791223472733,
|
||||
"tag": "0004_model_avatar_relation",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"version": "6",
|
||||
"when": 1791223474007,
|
||||
"tag": "0005_refetch_metadata",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"version": "6",
|
||||
"when": 1791224932279,
|
||||
"tag": "0006_settings_and_tag_color",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "6",
|
||||
"when": 1791233230682,
|
||||
"tag": "0007_hub_state",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"version": "6",
|
||||
"when": 1791233749207,
|
||||
"tag": "0008_local_folders",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Generated
+1708
-5
File diff suppressed because it is too large.
Load diff
+6
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "kaname",
|
||||
"version": "0.3.1",
|
||||
"version": "0.5.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "concurrently -k -n web,worker -c blue,magenta \"npm:dev:web\" \"npm:dev:worker\"",
|
||||
@@ -28,6 +28,10 @@
|
||||
"next-themes": "^0.4.6",
|
||||
"react": "19.2.8",
|
||||
"react-dom": "19.2.8",
|
||||
"react-markdown": "^10.1.0",
|
||||
"rehype-raw": "^7.0.0",
|
||||
"rehype-sanitize": "^6.0.0",
|
||||
"remark-gfm": "^4.0.1",
|
||||
"server-only": "^0.0.1",
|
||||
"shadcn": "^4.21.1",
|
||||
"sonner": "^2.0.8",
|
||||
@@ -37,6 +41,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
"@tailwindcss/typography": "^0.5.20",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
"use client";
|
||||
|
||||
import { DownloadIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { cancelJob, startDownload } from "@/components/job-actions";
|
||||
import { JobProgress, JobStateBadge } from "@/components/job-progress";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import type { ModelStatus } from "@/lib/db/schema";
|
||||
import { groupJobFiles } from "@/lib/file-groups";
|
||||
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,
|
||||
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];
|
||||
const open = latest && OPEN.includes(latest.state) ? latest : undefined;
|
||||
const files = open ? groupJobFiles(snapshot?.files ?? []) : [];
|
||||
|
||||
async function run(fn: () => Promise<void>) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await fn();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
let hint = "Downloads the selected files at the pinned commit.";
|
||||
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">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<h3 className="flex items-center gap-1.5 text-sm font-semibold">
|
||||
<DownloadIcon className="size-4 text-muted-foreground" />
|
||||
Download
|
||||
</h3>
|
||||
{latest && <JobStateBadge job={latest} />}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">{hint}</p>
|
||||
|
||||
{latest && !(latest.state === "completed" && status === "ready") && <JobProgress job={latest} compact />}
|
||||
|
||||
{latest?.state === "failed" && latest.errorMessage && (
|
||||
<pre className="max-h-40 overflow-auto rounded-md bg-destructive/10 px-2.5 py-2 text-xs whitespace-pre-wrap text-destructive">
|
||||
{latest.errorMessage}
|
||||
</pre>
|
||||
)}
|
||||
|
||||
{files.length > 0 && (
|
||||
<ul className="flex flex-col gap-1.5">
|
||||
{files.map((f) => (
|
||||
<li key={f.path} className="flex flex-col gap-1">
|
||||
<div className="flex justify-between gap-2 text-xs">
|
||||
<span className="truncate font-mono" title={f.path}>
|
||||
{f.path}
|
||||
{f.parts > 1 && <span className="text-muted-foreground"> · {f.parts} parts</span>}
|
||||
</span>
|
||||
<span className="shrink-0 text-muted-foreground tabular-nums">{formatBytes(f.expectedBytes)}</span>
|
||||
</div>
|
||||
<Progress value={percent(f.doneBytes, f.expectedBytes)} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{open ? (
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={busy || open.cancelRequested}
|
||||
onClick={() => run(() => cancelJob(open.id))}
|
||||
>
|
||||
{open.cancelRequested ? "Cancelling…" : "Cancel"}
|
||||
</Button>
|
||||
) : (
|
||||
status !== "ready" &&
|
||||
!hubMissing &&
|
||||
snapshot && (
|
||||
<Button size="sm" disabled={busy} onClick={() => run(() => startDownload(modelId))}>
|
||||
{latest ? "Download again" : "Download"}
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
{latest && (
|
||||
<Link
|
||||
href={`/jobs/${latest.id}`}
|
||||
className="inline-flex h-7 items-center rounded-md px-2.5 text-[0.8rem] hover:bg-muted"
|
||||
>
|
||||
View log
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
"use client";
|
||||
|
||||
import { PlusIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMemo, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { FileRoleBadge } from "@/components/labels";
|
||||
import { RecommendedStrip } from "@/components/recommended-strip";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { useRecommended } from "@/hooks/use-recommended";
|
||||
import { groupSplitFiles } from "@/lib/file-groups";
|
||||
import { formatBytes, percent, shortSha } from "@/lib/format";
|
||||
import { quantGroup } from "@/lib/selection";
|
||||
|
||||
type Candidate = { path: string; size: number };
|
||||
|
||||
/**
|
||||
* Files tab header: selection summary + on-disk progress, and a "Download more" panel to add
|
||||
* files that aren't selected yet.
|
||||
*/
|
||||
export function FilesHeader({
|
||||
modelId,
|
||||
sha,
|
||||
selectedCount,
|
||||
totalBytes,
|
||||
localCount,
|
||||
localBytes,
|
||||
candidates,
|
||||
selectedPaths,
|
||||
freeBytes,
|
||||
busy,
|
||||
hubMissing,
|
||||
}: {
|
||||
modelId: string;
|
||||
sha: string;
|
||||
selectedCount: number;
|
||||
totalBytes: number;
|
||||
localCount: number;
|
||||
localBytes: number;
|
||||
candidates: Candidate[];
|
||||
/** Files the model already has selected (no second mmproj/MTP is recommended). */
|
||||
selectedPaths: string[];
|
||||
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);
|
||||
const [picked, setPicked] = useState<Set<string>>(new Set());
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const groups = useMemo(() => {
|
||||
const m = new Map<string, { paths: string[]; size: number }>();
|
||||
for (const c of candidates) {
|
||||
const g = quantGroup(c.path);
|
||||
if (!g) continue;
|
||||
const entry = m.get(g) ?? { paths: [], size: 0 };
|
||||
entry.paths.push(c.path);
|
||||
entry.size += c.size;
|
||||
m.set(g, entry);
|
||||
}
|
||||
return [...m.entries()].sort(([a], [b]) => a.localeCompare(b, undefined, { numeric: true }));
|
||||
}, [candidates]);
|
||||
|
||||
// Companions (template, MTP, mmproj, …) of newly picked model files come along.
|
||||
const { all: recAll, active: recActive, setOn: setRecommendedOn, reset: resetRecommended } = useRecommended(candidates, picked, { have: selectedPaths });
|
||||
const chosen = useMemo(() => new Set([...picked, ...recActive]), [picked, recActive]);
|
||||
|
||||
// Split files are one entry; its checkbox selects all parts.
|
||||
const entries = useMemo(() => groupSplitFiles(candidates), [candidates]);
|
||||
const pickedEntries = entries.filter((e) => e.parts.every((p) => chosen.has(p.path))).length;
|
||||
const pickedBytes = candidates.filter((c) => chosen.has(c.path)).reduce((s, c) => s + c.size, 0);
|
||||
const tooBig = freeBytes != null && pickedBytes > freeBytes;
|
||||
|
||||
function toggle(paths: string[], on: boolean) {
|
||||
setRecommendedOn(paths, on);
|
||||
setPicked((prev) => {
|
||||
const next = new Set(prev);
|
||||
for (const p of paths) {
|
||||
if (on) next.add(p);
|
||||
else next.delete(p);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const res = await fetch(`/api/models/${modelId}/files`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ add: [...chosen] }),
|
||||
});
|
||||
const body = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast.error(body.error?.message ?? `Could not add files (${res.status})`);
|
||||
return;
|
||||
}
|
||||
toast.success(`${body.added} file${body.added === 1 ? "" : "s"} added, download queued`);
|
||||
setOpen(false);
|
||||
setPicked(new Set());
|
||||
resetRecommended();
|
||||
router.refresh();
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border-b">
|
||||
<div className="flex flex-col gap-2 px-5 py-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-2 text-sm">
|
||||
<span>
|
||||
<span className="font-medium">
|
||||
{selectedCount} selected file{selectedCount === 1 ? "" : "s"}
|
||||
</span>
|
||||
<span className="text-muted-foreground">
|
||||
{" "}
|
||||
· {formatBytes(totalBytes)} · commit {shortSha(sha)}
|
||||
</span>
|
||||
</span>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-muted-foreground">
|
||||
{localCount} of {selectedCount} on disk · {formatBytes(localBytes)}
|
||||
</span>
|
||||
{candidates.length > 0 && !hubMissing && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant={open ? "outline" : "default"}
|
||||
onClick={() => setOpen((o) => !o)}
|
||||
disabled={busy && !open}
|
||||
title={busy ? "Wait until the current download has finished" : undefined}
|
||||
>
|
||||
{open ? (
|
||||
"Close"
|
||||
) : (
|
||||
<>
|
||||
<PlusIcon /> Download more
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Progress value={percent(localBytes, totalBytes)} />
|
||||
</div>
|
||||
|
||||
{open && (
|
||||
<div className="border-t bg-muted/30">
|
||||
{groups.length > 0 && (
|
||||
<div className="flex flex-col gap-1.5 px-5 pt-4">
|
||||
<span className="text-xs text-muted-foreground">Quick select</span>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{groups.map(([name, g]) => {
|
||||
const on = g.paths.every((p) => picked.has(p));
|
||||
return (
|
||||
<Button
|
||||
key={name}
|
||||
type="button"
|
||||
size="xs"
|
||||
variant={on ? "default" : "outline"}
|
||||
onClick={() => toggle(g.paths, !on)}
|
||||
title={g.paths.join("\n")}
|
||||
>
|
||||
{name}
|
||||
<span className="opacity-70">{formatBytes(g.size)}</span>
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<RecommendedStrip files={candidates} paths={recAll} active={recActive} onToggle={toggle} className="mx-5 mt-3" />
|
||||
|
||||
<ul className="mt-3 max-h-96 divide-y overflow-y-auto border-y bg-card">
|
||||
{entries.map((e) => {
|
||||
const paths = e.parts.map((p) => p.path);
|
||||
const on = paths.every((p) => chosen.has(p));
|
||||
const isRecommended = paths.every((p) => recAll.includes(p));
|
||||
return (
|
||||
<li key={e.path}>
|
||||
<label className="grid cursor-pointer grid-cols-[1rem_auto_minmax(0,1fr)_auto] items-center gap-x-3 px-5 py-2 hover:bg-muted/50">
|
||||
<Checkbox checked={on} onCheckedChange={(v) => toggle(paths, v === true)} />
|
||||
<FileRoleBadge path={e.path} />
|
||||
<span className="flex min-w-0 items-center gap-2" title={paths.join("\n")}>
|
||||
<span className="truncate font-mono text-[13px]">{e.path}</span>
|
||||
{e.totalParts > 1 && (
|
||||
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">
|
||||
{e.totalParts} parts
|
||||
</span>
|
||||
)}
|
||||
{isRecommended && (
|
||||
<span className="shrink-0 rounded border border-amber-500/30 bg-amber-500/10 px-1 text-[10px] leading-4 text-amber-700 dark:text-amber-300">
|
||||
recommended
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="text-right text-sm text-muted-foreground tabular-nums">{formatBytes(e.size)}</span>
|
||||
</label>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 px-5 py-3 text-sm">
|
||||
<span>
|
||||
<span className="font-medium">
|
||||
{pickedEntries} file{pickedEntries === 1 ? "" : "s"} · {formatBytes(pickedBytes)}
|
||||
</span>
|
||||
{freeBytes != null && (
|
||||
<span className={tooBig ? "text-destructive" : "text-muted-foreground"}>
|
||||
{" "}
|
||||
({formatBytes(freeBytes)} free)
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<div className="ml-auto flex gap-2">
|
||||
<Button variant="ghost" size="sm" onClick={() => {
|
||||
setPicked(new Set());
|
||||
resetRecommended();
|
||||
}}
|
||||
disabled={chosen.size === 0}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
<Button size="sm" onClick={submit} disabled={chosen.size === 0 || submitting || busy}>
|
||||
{submitting ? "Adding…" : pickedEntries === 0 ? "Download" : `Download ${pickedEntries} file${pickedEntries === 1 ? "" : "s"}`}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import {
|
||||
AlertTriangleIcon,
|
||||
BoxIcon,
|
||||
CheckCircle2Icon,
|
||||
ChevronRightIcon,
|
||||
CircleDashedIcon,
|
||||
FileIcon,
|
||||
FileImageIcon,
|
||||
FileJsonIcon,
|
||||
FileTextIcon,
|
||||
ShieldCheckIcon,
|
||||
XCircleIcon,
|
||||
} from "lucide-react";
|
||||
import { FileRoleBadge } from "@/components/labels";
|
||||
import type { ModelFileState } from "@/lib/db/schema";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import { type FileGroup, groupSplitFiles } from "@/lib/file-groups";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { FilesHeader } from "./download-more";
|
||||
|
||||
type FileRow = { id: string; path: string; size: number; lfsSha256: string | null; state: ModelFileState };
|
||||
|
||||
const STATE: Record<ModelFileState, { label: string; icon: React.ReactNode; className: string }> = {
|
||||
pending: { label: "Not downloaded", icon: <CircleDashedIcon className="size-3.5" />, className: "text-muted-foreground" },
|
||||
present: { label: "Downloaded", icon: <CheckCircle2Icon className="size-3.5" />, className: "text-emerald-600 dark:text-emerald-400" },
|
||||
verified: { label: "Verified", icon: <ShieldCheckIcon className="size-3.5" />, className: "text-emerald-600 dark:text-emerald-400" },
|
||||
missing: { label: "Missing", icon: <XCircleIcon className="size-3.5" />, className: "text-destructive" },
|
||||
size_mismatch: { label: "Size mismatch", icon: <AlertTriangleIcon className="size-3.5" />, className: "text-amber-600 dark:text-amber-400" },
|
||||
hash_mismatch: { label: "Hash mismatch", icon: <AlertTriangleIcon className="size-3.5" />, className: "text-amber-600 dark:text-amber-400" },
|
||||
};
|
||||
|
||||
function FileTypeIcon({ path }: { path: string }) {
|
||||
const ext = path.toLowerCase().split(".").pop() ?? "";
|
||||
const cls = "size-4 text-muted-foreground";
|
||||
if (["gguf", "safetensors", "bin", "pt", "onnx"].includes(ext)) return <BoxIcon className={cls} />;
|
||||
if (ext === "json") return <FileJsonIcon className={cls} />;
|
||||
if (["md", "txt"].includes(ext)) return <FileTextIcon className={cls} />;
|
||||
if (["png", "jpg", "jpeg", "gif", "webp", "svg"].includes(ext)) return <FileImageIcon className={cls} />;
|
||||
return <FileIcon className={cls} />;
|
||||
}
|
||||
|
||||
function FileName({ path }: { path: string }) {
|
||||
const slash = path.lastIndexOf("/");
|
||||
return (
|
||||
<span className="min-w-0 truncate font-mono text-[13px]" title={path}>
|
||||
{slash >= 0 && <span className="text-muted-foreground">{path.slice(0, slash + 1)}</span>}
|
||||
{path.slice(slash + 1)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
type Entry = FileGroup<FileRow>;
|
||||
|
||||
/** One status for a whole entry (all parts of a split file). */
|
||||
function entryState(e: Entry): { state: ModelFileState; label: string } {
|
||||
const states = e.parts.map((p) => p.state);
|
||||
const done = states.filter((st) => st === "present" || st === "verified").length;
|
||||
const worst = (["missing", "hash_mismatch", "size_mismatch"] as const).find((st) => states.includes(st));
|
||||
if (worst) return { state: worst, label: STATE[worst].label };
|
||||
if (done === states.length) {
|
||||
const state = states.every((st) => st === "verified") ? "verified" : "present";
|
||||
return { state, label: STATE[state].label };
|
||||
}
|
||||
if (done > 0) return { state: "pending", label: `${done} of ${states.length} parts` };
|
||||
return { state: "pending", label: STATE.pending.label };
|
||||
}
|
||||
|
||||
const isLocal = (e: Entry) => e.parts.every((p) => p.state === "present" || p.state === "verified");
|
||||
|
||||
function Row({ entry, href, muted, showState }: { entry: Entry; href: string; muted?: boolean; showState: boolean }) {
|
||||
const { state: stateKey, label } = entryState(entry);
|
||||
const state = STATE[stateKey];
|
||||
const split = entry.totalParts > 1;
|
||||
return (
|
||||
<li>
|
||||
<a
|
||||
href={href}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
title={split ? entry.parts.map((p) => p.path).join("\n") : undefined}
|
||||
className={cn(
|
||||
// Fixed status column so sizes line up between selected and unselected rows.
|
||||
"grid grid-cols-[1rem_auto_minmax(0,1fr)_auto] items-center gap-x-3 px-5 py-2.5 transition-colors hover:bg-muted/50 sm:grid-cols-[1rem_auto_minmax(0,1fr)_5rem_1rem] md:grid-cols-[1rem_auto_minmax(0,1fr)_5rem_7.5rem]",
|
||||
muted && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
<FileTypeIcon path={entry.path} />
|
||||
<FileRoleBadge path={entry.path} className={muted ? "opacity-70" : undefined} />
|
||||
<span className="flex min-w-0 items-center gap-2">
|
||||
<FileName path={entry.path} />
|
||||
{split && (
|
||||
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">
|
||||
{entry.parts.length === entry.totalParts
|
||||
? `${entry.totalParts} parts`
|
||||
: `${entry.parts.length} of ${entry.totalParts} parts`}
|
||||
</span>
|
||||
)}
|
||||
{entry.parts[0].lfsSha256 && (
|
||||
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">LFS</span>
|
||||
)}
|
||||
</span>
|
||||
<span className="hidden text-right text-sm tabular-nums sm:block">{formatBytes(entry.size)}</span>
|
||||
{showState ? (
|
||||
<span className={cn("flex items-center justify-end gap-1.5 text-xs whitespace-nowrap", state.className)}>
|
||||
{state.icon}
|
||||
<span className="hidden md:inline">{label}</span>
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-right text-sm tabular-nums sm:hidden">{formatBytes(entry.size)}</span>
|
||||
)}
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
/** "Files and versions"-style list: selected files with their local state, the rest collapsed. */
|
||||
export function FilesTab({
|
||||
modelId,
|
||||
repoId,
|
||||
sha,
|
||||
selected,
|
||||
others,
|
||||
freeBytes,
|
||||
busy,
|
||||
hubMissing,
|
||||
}: {
|
||||
modelId: string;
|
||||
repoId: string;
|
||||
sha: string;
|
||||
selected: FileRow[];
|
||||
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.
|
||||
const href = (e: Entry) => {
|
||||
const dir = e.path.includes("/") ? e.path.slice(0, e.path.lastIndexOf("/")) : null;
|
||||
return e.totalParts > 1 && dir ? `${hub}/tree/${sha}/${dir}` : `${hub}/blob/${sha}/${e.parts[0].path}`;
|
||||
};
|
||||
const selectedEntries = groupSplitFiles(selected);
|
||||
const otherEntries = groupSplitFiles(others);
|
||||
const totalBytes = selected.reduce((s, f) => s + f.size, 0);
|
||||
const localEntries = selectedEntries.filter(isLocal);
|
||||
const localBytes = selected.filter((f) => f.state === "present" || f.state === "verified").reduce((s, f) => s + f.size, 0);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<FilesHeader
|
||||
modelId={modelId}
|
||||
sha={sha}
|
||||
selectedCount={selectedEntries.length}
|
||||
totalBytes={totalBytes}
|
||||
localCount={localEntries.length}
|
||||
localBytes={localBytes}
|
||||
candidates={others.map((f) => ({ path: f.path, size: f.size }))}
|
||||
selectedPaths={selected.map((f) => f.path)}
|
||||
freeBytes={freeBytes}
|
||||
busy={busy}
|
||||
hubMissing={hubMissing}
|
||||
/>
|
||||
|
||||
<ul className="divide-y">
|
||||
{selectedEntries.map((e) => (
|
||||
<Row key={e.path} entry={e} href={href(e)} showState />
|
||||
))}
|
||||
</ul>
|
||||
|
||||
{otherEntries.length > 0 && (
|
||||
<details className="group border-t">
|
||||
<summary className="flex cursor-pointer list-none items-center gap-2 px-5 py-3 text-sm hover:bg-muted/50">
|
||||
<ChevronRightIcon className="size-4 text-muted-foreground transition-transform group-open:rotate-90" />
|
||||
<span className="font-medium">Not selected</span>
|
||||
<span className="text-muted-foreground">
|
||||
{otherEntries.length} file{otherEntries.length === 1 ? "" : "s"} ·{" "}
|
||||
{formatBytes(others.reduce((s, f) => s + f.size, 0))}
|
||||
</span>
|
||||
</summary>
|
||||
<ul className="divide-y border-t">
|
||||
{otherEntries.map((e) => (
|
||||
<Row key={e.path} entry={e} href={href(e)} muted showState={false} />
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { JobStateBadge } from "@/components/job-progress";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
|
||||
/** Job history of one model (live). */
|
||||
export function JobsTab({ modelId }: { modelId: string }) {
|
||||
const { snapshot } = useLive({ model: modelId });
|
||||
const jobs = snapshot?.jobs ?? [];
|
||||
|
||||
if (snapshot && jobs.length === 0) {
|
||||
return <p className="py-6 text-sm text-muted-foreground">No jobs yet.</p>;
|
||||
}
|
||||
return (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Started</TableHead>
|
||||
<TableHead>Kind</TableHead>
|
||||
<TableHead>State</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead className="hidden sm:table-cell">Finished</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{jobs.map((j) => (
|
||||
<TableRow key={j.id}>
|
||||
<TableCell>
|
||||
<Link href={`/jobs/${j.id}`} className="hover:underline">
|
||||
<LocalTime value={j.startedAt ?? j.createdAt} />
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{j.kind}
|
||||
{j.purpose && j.purpose !== "initial" ? ` (${j.purpose})` : ""}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<JobStateBadge job={j} />
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">{formatBytes(j.totalBytes)}</TableCell>
|
||||
<TableCell className="hidden text-sm text-muted-foreground sm:table-cell">
|
||||
<LocalTime value={j.finishedAt} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import ReactMarkdown, { defaultUrlTransform } from "react-markdown";
|
||||
import rehypeRaw from "rehype-raw";
|
||||
import rehypeSanitize, { defaultSchema } from "rehype-sanitize";
|
||||
import remarkGfm from "remark-gfm";
|
||||
|
||||
// Model cards mix Markdown and raw HTML. Parse the HTML (rehype-raw), then sanitize it: no scripts,
|
||||
// styles or event handlers, only the tags/attributes GitHub-style READMEs normally use.
|
||||
const schema = {
|
||||
...defaultSchema,
|
||||
attributes: {
|
||||
...defaultSchema.attributes,
|
||||
img: [...(defaultSchema.attributes?.img ?? []), "width", "height", "align", "loading"],
|
||||
div: [...(defaultSchema.attributes?.div ?? []), "align"],
|
||||
p: [...(defaultSchema.attributes?.p ?? []), "align"],
|
||||
td: [...(defaultSchema.attributes?.td ?? []), "align"],
|
||||
th: [...(defaultSchema.attributes?.th ?? []), "align"],
|
||||
},
|
||||
};
|
||||
|
||||
/** Renders a repo's README like the Hub: relative links/images point at the pinned commit. */
|
||||
export function ModelCard({ markdown, repoId, sha }: { markdown: string; repoId: string; sha: string }) {
|
||||
const base = `https://huggingface.co/${repoId}`;
|
||||
return (
|
||||
<article className="prose prose-sm max-w-none dark:prose-invert prose-headings:scroll-mt-20 prose-img:inline-block prose-img:my-1 prose-pre:bg-muted prose-pre:text-foreground prose-table:text-xs">
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm]}
|
||||
rehypePlugins={[rehypeRaw, [rehypeSanitize, schema]]}
|
||||
urlTransform={(url, key) => {
|
||||
const safe = defaultUrlTransform(url);
|
||||
if (!safe || safe.startsWith("#") || /^[a-z][a-z0-9+.-]*:|^\/\//i.test(safe)) return safe;
|
||||
// Relative path inside the repo: images from /resolve, links to /blob, both at the pinned SHA.
|
||||
const path = safe.replace(/^\.?\//, "");
|
||||
return key === "src" ? `${base}/resolve/${sha}/${path}` : `${base}/blob/${sha}/${path}`;
|
||||
}}
|
||||
components={{
|
||||
a: ({ href, children, ...props }) => (
|
||||
<a href={href} {...props} target={href?.startsWith("#") ? undefined : "_blank"} rel="noreferrer">
|
||||
{children}
|
||||
</a>
|
||||
),
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
img: ({ alt, ...props }) => <img alt={alt ?? ""} loading="lazy" referrerPolicy="no-referrer" {...props} />,
|
||||
}}
|
||||
>
|
||||
{markdown}
|
||||
</ReactMarkdown>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,459 @@
|
||||
import {
|
||||
ArrowDownIcon,
|
||||
BoxIcon,
|
||||
CpuIcon,
|
||||
ExternalLinkIcon,
|
||||
FileTextIcon,
|
||||
FolderIcon,
|
||||
HistoryIcon,
|
||||
LanguagesIcon,
|
||||
ListChecksIcon,
|
||||
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";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import { fetchModelCard } from "@/lib/hub/client";
|
||||
import { modelFamilies } from "@/lib/hub/metadata";
|
||||
import { getModelByRepo, relatedModels } from "@/lib/library";
|
||||
import { fileRole } from "@/lib/file-roles";
|
||||
import { quantGroup } from "@/lib/selection";
|
||||
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";
|
||||
import { TagEditor } from "./tag-editor";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const TABS = [
|
||||
{ id: "files", label: "Files", icon: FolderIcon },
|
||||
{ id: "card", label: "Model card", icon: FileTextIcon },
|
||||
{ id: "jobs", label: "Jobs", icon: HistoryIcon },
|
||||
] as const;
|
||||
type TabId = (typeof TABS)[number]["id"];
|
||||
|
||||
const FORMATS: Record<string, string> = {
|
||||
gguf: "GGUF",
|
||||
safetensors: "Safetensors",
|
||||
transformers: "Transformers",
|
||||
pytorch: "PyTorch",
|
||||
onnx: "ONNX",
|
||||
mlx: "MLX",
|
||||
};
|
||||
|
||||
const RELATION_LABEL: Record<string, string> = {
|
||||
quantized: "Quantized",
|
||||
finetune: "Finetuned",
|
||||
adapter: "Adapter",
|
||||
merge: "Merged",
|
||||
};
|
||||
|
||||
const titleCase = (s: string) => s.replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
|
||||
function languageName(code: string): string | null {
|
||||
if (!/^[a-z]{2,3}$/.test(code)) return null;
|
||||
try {
|
||||
const name = new Intl.DisplayNames(["en"], { type: "language" }).of(code);
|
||||
return name && name !== code ? name : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: PageProps<"/[org]/[repo]">): Promise<Metadata> {
|
||||
const { org, repo } = await params;
|
||||
return { title: `${org}/${repo}` };
|
||||
}
|
||||
|
||||
export default async function ModelPage({ params, searchParams }: PageProps<"/[org]/[repo]">) {
|
||||
const { org, repo } = await params;
|
||||
const sp = await searchParams;
|
||||
const data = await getModelByRepo(`${org}/${repo}`);
|
||||
if (!data) notFound();
|
||||
const { model, files } = data;
|
||||
if (model.repoId !== `${org}/${repo}`) redirect(`/${model.repoId}`); // canonical spelling
|
||||
|
||||
const tab: TabId = TABS.some((t) => t.id === sp.tab) ? (sp.tab as TabId) : "files";
|
||||
const [author, name] = model.repoId.split("/");
|
||||
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),
|
||||
relatedModels(model.id, baseModels),
|
||||
tab === "card" ? fetchModelCard(model.repoId, model.pinnedSha).catch(() => undefined) : Promise.resolve(undefined),
|
||||
getWorkerStatus(),
|
||||
]);
|
||||
|
||||
const selected = files.filter((f) => f.selected);
|
||||
const others = files.filter((f) => !f.selected);
|
||||
const selectedBytes = selected.reduce((s, f) => s + f.size, 0);
|
||||
const quants = [
|
||||
...new Set(selected.filter((f) => fileRole(f.path) === "model").map((f) => quantGroup(f.path)).filter(Boolean)),
|
||||
] as string[];
|
||||
|
||||
const formats = hubTags.filter((t) => FORMATS[t]).map((t) => FORMATS[t]);
|
||||
const languages = hubTags.map(languageName).filter(Boolean) as string[];
|
||||
const shown = new Set([...Object.keys(FORMATS), model.architecture, author.toLowerCase(), model.pipelineTag]);
|
||||
const extraTags = hubTags.filter((t) => !shown.has(t) && !languageName(t)).slice(0, 8);
|
||||
|
||||
const tabHref = (id: TabId) => (id === "files" ? `/${model.repoId}` : `/${model.repoId}?tab=${id}`);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Header card, styled after the Hugging Face model page */}
|
||||
<Panel className="flex flex-col gap-4 p-5">
|
||||
<div className="flex flex-wrap items-center gap-x-2 gap-y-2">
|
||||
<Avatar url={model.authorAvatarUrl} name={author} />
|
||||
<Link href={`/?author=${encodeURIComponent(author)}`} className="text-muted-foreground hover:text-foreground hover:underline">
|
||||
{author}
|
||||
</Link>
|
||||
<span className="text-muted-foreground">/</span>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{model.pipelineTag && (
|
||||
<Pill icon={MessagesSquareIcon} accent>
|
||||
{titleCase(model.pipelineTag)}
|
||||
</Pill>
|
||||
)}
|
||||
{formats.map((f) => (
|
||||
<Pill key={f} icon={BoxIcon}>
|
||||
{f}
|
||||
</Pill>
|
||||
))}
|
||||
{model.architecture && <Pill icon={CpuIcon}>{model.architecture}</Pill>}
|
||||
{languages.length > 0 && <Pill icon={LanguagesIcon}>{languages.join(", ")}</Pill>}
|
||||
{model.license && <Pill icon={ScaleIcon}>License: {model.license}</Pill>}
|
||||
{extraTags.map((t) => (
|
||||
<Pill key={t} muted>
|
||||
{t}
|
||||
</Pill>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-xs text-muted-foreground">Your tags</span>
|
||||
<TagEditor modelId={model.id} tags={tags} />
|
||||
</div>
|
||||
|
||||
</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">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 border-b px-4 py-3">
|
||||
<nav className="inline-flex rounded-lg bg-muted p-1">
|
||||
{TABS.map((t) => (
|
||||
<Link
|
||||
key={t.id}
|
||||
href={tabHref(t.id)}
|
||||
scroll={false}
|
||||
className={cn(
|
||||
"flex items-center gap-1.5 rounded-md px-3 py-1 text-sm transition-colors",
|
||||
tab === t.id
|
||||
? "bg-background font-medium text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<t.icon className="size-4" />
|
||||
{t.label}
|
||||
{t.id === "files" && <span className="text-xs text-muted-foreground tabular-nums">{selected.length}</span>}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{tab === "card" && (
|
||||
<div className="p-5 sm:p-6">
|
||||
{card ? (
|
||||
<>
|
||||
<ModelCard markdown={card} repoId={model.repoId} sha={model.pinnedSha} />
|
||||
<div className="mt-6 flex justify-end">
|
||||
<a
|
||||
href={`${hub}/blob/${model.pinnedSha}/README.md`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
README.md @ {shortSha(model.pinnedSha)}
|
||||
<ExternalLinkIcon className="size-3" />
|
||||
</a>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{card === null ? "This repository has no model card." : "The model card could not be loaded."}{" "}
|
||||
<a href={hub} target="_blank" rel="noreferrer" className="underline">
|
||||
Open on Hugging Face
|
||||
</a>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{tab === "files" && (
|
||||
<FilesTab
|
||||
modelId={model.id}
|
||||
repoId={model.repoId}
|
||||
sha={model.pinnedSha}
|
||||
selected={selected}
|
||||
others={others}
|
||||
freeBytes={worker.online ? worker.modelsDirFreeBytes : null}
|
||||
busy={model.status === "downloading"}
|
||||
hubMissing={hubMissing}
|
||||
/>
|
||||
)}
|
||||
{tab === "jobs" && (
|
||||
<div className="px-2 pb-2">
|
||||
<JobsTab modelId={model.id} />
|
||||
</div>
|
||||
)}
|
||||
</Panel>
|
||||
|
||||
<aside className="flex flex-col gap-4">
|
||||
<SideCard>
|
||||
<DownloadCard modelId={model.id} status={model.status} hubMissing={hubMissing} />
|
||||
</SideCard>
|
||||
|
||||
<SideCard title="Local copy" icon={ListChecksIcon}>
|
||||
<dl className="grid grid-cols-[max-content_1fr] gap-x-4 gap-y-1.5 text-sm">
|
||||
<dt className="text-muted-foreground">Selection</dt>
|
||||
<dd>{quants.length > 0 ? quants.join(", ") : `${selected.length} file${selected.length === 1 ? "" : "s"}`}</dd>
|
||||
<dt className="text-muted-foreground">Size</dt>
|
||||
<dd className="tabular-nums">{formatBytes(selectedBytes)}</dd>
|
||||
<dt className="text-muted-foreground">Commit</dt>
|
||||
<dd className="flex items-center gap-1">
|
||||
<a href={`${hub}/commit/${model.pinnedSha}`} target="_blank" rel="noreferrer" className="font-mono hover:underline" title={model.pinnedSha}>
|
||||
{shortSha(model.pinnedSha)}
|
||||
</a>
|
||||
<span className="text-muted-foreground">on {model.trackedRevision}</span>
|
||||
<CopyButton value={model.pinnedSha} label="Copy commit SHA" />
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Downloaded</dt>
|
||||
<dd>
|
||||
<LocalTime value={model.downloadedAt} />
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Path</dt>
|
||||
<dd className="flex min-w-0 items-center gap-1">
|
||||
<span className="truncate font-mono text-xs" title={`$MODELS_DIR/${model.localPath}`}>
|
||||
{model.localPath}
|
||||
</span>
|
||||
<CopyButton value={model.localPath} label="Copy path" />
|
||||
</dd>
|
||||
{model.includePatterns.length > 0 && (
|
||||
<>
|
||||
<dt className="text-muted-foreground">Include</dt>
|
||||
<dd className="flex flex-col font-mono text-xs">{model.includePatterns.map((p) => <span key={p} className="break-all">{p}</span>)}</dd>
|
||||
</>
|
||||
)}
|
||||
{model.excludePatterns.length > 0 && (
|
||||
<>
|
||||
<dt className="text-muted-foreground">Exclude</dt>
|
||||
<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} />
|
||||
</dd>
|
||||
</dl>
|
||||
</SideCard>
|
||||
|
||||
<SideCard title="Model tree" icon={SparklesIcon}>
|
||||
<ModelTree
|
||||
repoId={model.repoId}
|
||||
baseModels={baseModels}
|
||||
relation={model.baseRelation}
|
||||
families={modelFamilies(model.repoId, baseModels)}
|
||||
/>
|
||||
{related.length > 0 && (
|
||||
<div className="mt-4 flex flex-col gap-1.5 border-t pt-3">
|
||||
<span className="text-xs text-muted-foreground">Also in your library</span>
|
||||
{related.map((r) => (
|
||||
<Link key={r.repoId} href={`/${r.repoId}`} className="flex items-center justify-between gap-2 text-sm hover:underline">
|
||||
<span className="truncate">{r.repoId}</span>
|
||||
<span className="shrink-0 text-xs text-muted-foreground">{r.quants.join(", ")}</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</SideCard>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Avatar({ url, name }: { url: string | null; name: string }) {
|
||||
if (url) {
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
return <img src={url} alt="" className="size-6 rounded-md object-cover" referrerPolicy="no-referrer" />;
|
||||
}
|
||||
return (
|
||||
<span className="grid size-6 place-items-center rounded-md bg-muted text-xs font-semibold uppercase">
|
||||
{name.slice(0, 1)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function Pill({
|
||||
icon: Icon,
|
||||
accent,
|
||||
muted,
|
||||
children,
|
||||
}: {
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
accent?: boolean;
|
||||
muted?: boolean;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-xs",
|
||||
accent && "border-indigo-500/30 bg-indigo-500/10 text-indigo-700 dark:text-indigo-300",
|
||||
muted && "text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
{Icon && <Icon className="size-3.5" />}
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function ExternalButton({ href, children }: { href: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<a href={href} target="_blank" rel="noreferrer" className={cn(buttonVariants({ variant: "outline", size: "sm" }), "border-foreground/15 bg-background shadow-xs")}>
|
||||
{children}
|
||||
<ExternalLinkIcon className="opacity-60" />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
/** Card surface shared by header, content and sidebar. */
|
||||
function Panel({ className, children }: { className?: string; children: React.ReactNode }) {
|
||||
return <div className={cn("rounded-xl bg-card text-card-foreground ring-1 ring-foreground/10", className)}>{children}</div>;
|
||||
}
|
||||
|
||||
function SideCard({
|
||||
title,
|
||||
icon: Icon,
|
||||
children,
|
||||
}: {
|
||||
title?: string;
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Panel className="p-4">
|
||||
{title && (
|
||||
<h3 className="mb-3 flex items-center gap-1.5 text-sm font-semibold">
|
||||
{Icon && <Icon className="size-4 text-muted-foreground" />}
|
||||
{title}
|
||||
</h3>
|
||||
)}
|
||||
{children}
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
|
||||
function ModelTree({
|
||||
repoId,
|
||||
baseModels,
|
||||
relation,
|
||||
families,
|
||||
}: {
|
||||
repoId: string;
|
||||
baseModels: string[];
|
||||
relation: string | null;
|
||||
families: string[];
|
||||
}) {
|
||||
if (baseModels.length === 0) {
|
||||
return <p className="text-sm text-muted-foreground">Original model, family {families.join(", ")}.</p>;
|
||||
}
|
||||
return (
|
||||
<ol className="flex flex-col items-start gap-1 text-sm">
|
||||
{baseModels.map((b) => (
|
||||
<li key={b}>
|
||||
<a href={`https://huggingface.co/${b}`} target="_blank" rel="noreferrer" className="hover:underline">
|
||||
{b}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
<li className="flex items-center gap-1 pl-2 text-xs text-muted-foreground">
|
||||
<ArrowDownIcon className="size-3.5" />
|
||||
{relation ? (RELATION_LABEL[relation] ?? titleCase(relation)) : "Derived"}
|
||||
</li>
|
||||
<li className="font-medium">{repoId}</li>
|
||||
</ol>
|
||||
);
|
||||
}
|
||||
File renamed without changes.
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import { XIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { TagBadge } from "@/components/tag-badge";
|
||||
import { TagPicker } from "@/components/tag-picker";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
|
||||
/** Add/remove user tags on a model. */
|
||||
export function TagEditor({ modelId, tags }: { modelId: string; tags: Tag[] }) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function add(name: string) {
|
||||
setBusy(true);
|
||||
const res = await fetch(`/api/models/${modelId}/tags`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
setBusy(false);
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
toast.error(body.error?.message ?? `Could not add tag (${res.status})`);
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
async function remove(tag: Tag) {
|
||||
const res = await fetch(`/api/models/${modelId}/tags/${tag.id}`, { method: "DELETE" });
|
||||
if (!res.ok) toast.error(`Could not remove tag (${res.status})`);
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{tags.map((t) => (
|
||||
<TagBadge key={t.id} name={t.name} color={t.color}>
|
||||
<button type="button" aria-label={`Remove tag ${t.name}`} onClick={() => remove(t)} className="opacity-60 hover:opacity-100">
|
||||
<XIcon className="size-3" />
|
||||
</button>
|
||||
</TagBadge>
|
||||
))}
|
||||
<TagPicker exclude={tags.map((t) => t.name)} onPick={add} disabled={busy} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { XIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { FileRoleBadge } from "@/components/labels";
|
||||
import { RecommendedStrip } from "@/components/recommended-strip";
|
||||
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";
|
||||
@@ -10,6 +15,8 @@ import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useRecommended } from "@/hooks/use-recommended";
|
||||
import { groupSplitFiles } from "@/lib/file-groups";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import type { LookupResult } from "@/lib/hub/lookup";
|
||||
import { escapeGlob, matchesAny, parsePatternList, quantGroup } from "@/lib/selection";
|
||||
@@ -27,15 +34,21 @@ async function postJson<T>(url: string, body: unknown): Promise<T> {
|
||||
return json;
|
||||
}
|
||||
|
||||
/** A folder from the models folder to import (found by the worker's scan). */
|
||||
export type ImportFolder = { path: string; commit: string | null; files: { path: string; size: number }[]; fileCount: number };
|
||||
|
||||
export function AddModelForm({
|
||||
freeBytes,
|
||||
onAdded,
|
||||
importFolder,
|
||||
}: {
|
||||
freeBytes: number | null;
|
||||
onAdded: (modelId: string) => void;
|
||||
/** Import mode: look up this folder's repo and preselect the files that are already there. */
|
||||
importFolder?: ImportFolder;
|
||||
}) {
|
||||
const [repo, setRepo] = useState("");
|
||||
const [revision, setRevision] = useState("main");
|
||||
const [repo, setRepo] = useState(importFolder?.path ?? "");
|
||||
const [revision, setRevision] = useState(importFolder?.commit ?? "main");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [result, setResult] = useState<LookupResult | null>(null);
|
||||
@@ -44,18 +57,41 @@ export function AddModelForm({
|
||||
const [includeText, setIncludeText] = useState("");
|
||||
const [excludeText, setExcludeText] = useState("");
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [tags, setTags] = useState<{ name: string; color?: string | null }[]>([]);
|
||||
|
||||
async function lookup(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
const includePatterns = useMemo(() => parsePatternList(includeText), [includeText]);
|
||||
const excludePatterns = useMemo(() => parsePatternList(excludeText), [excludeText]);
|
||||
|
||||
const repoFiles = useMemo(() => result?.files ?? [], [result]);
|
||||
const isExcluded = useCallback((path: string) => matchesAny(path, excludePatterns), [excludePatterns]);
|
||||
// Picked by checkbox or include pattern; recommended companions come on top.
|
||||
const picked = useMemo(
|
||||
() => repoFiles.filter((f) => (checked.has(f.path) || matchesAny(f.path, includePatterns)) && !isExcluded(f.path)).map((f) => f.path),
|
||||
[repoFiles, checked, includePatterns, isExcluded],
|
||||
);
|
||||
const { all: recAll, active: recActive, setOn: setRecommendedOn, reset: resetRecommended } = useRecommended(
|
||||
repoFiles,
|
||||
picked,
|
||||
{ isExcluded },
|
||||
);
|
||||
|
||||
// Local files of the imported folder by path.
|
||||
const onDisk = useMemo(() => new Map((importFolder?.files ?? []).map((f) => [f.path, f.size])), [importFolder]);
|
||||
|
||||
async function lookup(e?: React.FormEvent) {
|
||||
e?.preventDefault();
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const r = await postJson<LookupResult>("/api/hub/lookup", { repo, revision });
|
||||
setResult(r);
|
||||
setRevision(r.revision);
|
||||
setChecked(new Set());
|
||||
// Import: preselect every repo file that's already in the folder.
|
||||
setChecked(new Set(r.files.filter((f) => onDisk.has(f.path)).map((f) => f.path)));
|
||||
resetRecommended();
|
||||
setIncludeText("");
|
||||
setExcludeText("");
|
||||
setTags([]);
|
||||
} catch (err) {
|
||||
setResult(null);
|
||||
setError(err instanceof Error ? err.message : String(err));
|
||||
@@ -64,23 +100,31 @@ export function AddModelForm({
|
||||
}
|
||||
}
|
||||
|
||||
const includePatterns = useMemo(() => parsePatternList(includeText), [includeText]);
|
||||
const excludePatterns = useMemo(() => parsePatternList(excludeText), [excludeText]);
|
||||
const autoLookup = useRef(false);
|
||||
useEffect(() => {
|
||||
if (importFolder && !autoLookup.current) {
|
||||
autoLookup.current = true;
|
||||
void lookup();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- run once for the folder being imported
|
||||
}, [importFolder]);
|
||||
|
||||
|
||||
const files = useMemo(() => {
|
||||
if (!result) return [];
|
||||
return result.files.map((f) => {
|
||||
const pickedSet = new Set(picked);
|
||||
return repoFiles.map((f) => {
|
||||
const byPattern = matchesAny(f.path, includePatterns);
|
||||
const excluded = matchesAny(f.path, excludePatterns);
|
||||
const excluded = isExcluded(f.path);
|
||||
return {
|
||||
...f,
|
||||
group: quantGroup(f.path),
|
||||
byPattern,
|
||||
excluded,
|
||||
selected: (checked.has(f.path) || byPattern) && !excluded,
|
||||
recommended: recAll.includes(f.path),
|
||||
selected: pickedSet.has(f.path) || recActive.has(f.path),
|
||||
};
|
||||
});
|
||||
}, [result, checked, includePatterns, excludePatterns]);
|
||||
}, [repoFiles, picked, includePatterns, isExcluded, recAll, recActive]);
|
||||
|
||||
const groups = useMemo(() => {
|
||||
const m = new Map<string, { paths: string[]; size: number }>();
|
||||
@@ -95,14 +139,26 @@ export function AddModelForm({
|
||||
}, [files]);
|
||||
|
||||
const selected = files.filter((f) => f.selected);
|
||||
// Split files are one row; its checkbox covers all parts.
|
||||
const entries = useMemo(() => groupSplitFiles(files), [files]);
|
||||
const selectedEntries = entries.filter((e) => e.parts.every((f) => f.selected)).length;
|
||||
const totalBytes = selected.reduce((s, f) => s + f.size, 0);
|
||||
const notEnoughSpace = freeBytes != null && totalBytes > freeBytes;
|
||||
// Files already on disk with the right size are verified by hf, not downloaded again.
|
||||
const present = selected.filter((f) => onDisk.get(f.path) === f.size);
|
||||
const toDownload = totalBytes - present.reduce((s, f) => s + f.size, 0);
|
||||
const notEnoughSpace = freeBytes != null && toDownload > freeBytes;
|
||||
const repoPaths = useMemo(() => new Set(result?.files.map((f) => f.path)), [result]);
|
||||
const sizeDiffers = selected.filter((f) => onDisk.has(f.path) && onDisk.get(f.path) !== f.size).length;
|
||||
const notInRepo = importFolder ? importFolder.files.filter((f) => !repoPaths.has(f.path)).length : 0;
|
||||
|
||||
function toggle(path: string, on: boolean) {
|
||||
function toggle(paths: string[], on: boolean) {
|
||||
setRecommendedOn(paths, on);
|
||||
setChecked((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (on) next.add(path);
|
||||
else next.delete(path);
|
||||
for (const path of paths) {
|
||||
if (on) next.add(path);
|
||||
else next.delete(path);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
@@ -127,10 +183,12 @@ export function AddModelForm({
|
||||
repoId: result.repoId,
|
||||
revision: result.revision,
|
||||
sha: result.sha,
|
||||
include: [...includePatterns, ...[...checked].sort().map(escapeGlob)],
|
||||
include: [...includePatterns, ...[...new Set([...checked, ...recActive])].sort().map(escapeGlob)],
|
||||
exclude: excludePatterns,
|
||||
tags: tags.map((t) => t.name),
|
||||
localPath: importFolder?.path,
|
||||
});
|
||||
toast.success(`${result.repoId} added, download queued`);
|
||||
toast.success(importFolder ? `${result.repoId} imported, verifying files` : `${result.repoId} added, download queued`);
|
||||
onAdded(id);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
@@ -143,8 +201,12 @@ export function AddModelForm({
|
||||
<div className="flex flex-col gap-4">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Hugging Face repository</CardTitle>
|
||||
<CardDescription>Repo ID like unsloth/Qwen3-8B-GGUF, or paste the repo URL.</CardDescription>
|
||||
<CardTitle>{importFolder ? `Import ${importFolder.path}` : "Hugging Face repository"}</CardTitle>
|
||||
<CardDescription>
|
||||
{importFolder
|
||||
? `The folder's files are matched against this Hub repo${importFolder.commit ? " at the commit hf recorded when it downloaded them" : ""}. Change the repo or revision if they don't fit.`
|
||||
: "Repo ID like unsloth/Qwen3-8B-GGUF, or paste the repo URL."}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={lookup} className="flex flex-col gap-3 sm:flex-row sm:items-end">
|
||||
@@ -207,10 +269,27 @@ export function AddModelForm({
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{importFolder && !result.existingModelId && (
|
||||
<div className="rounded-md bg-muted px-3 py-2 text-sm">
|
||||
<p>
|
||||
<span className="font-medium">
|
||||
{present.length} of {selected.length} selected files are already on disk
|
||||
</span>{" "}
|
||||
and are verified by hash (hf only downloads files that are missing or different).
|
||||
{sizeDiffers > 0 && ` ${sizeDiffers} differ in size and will be downloaded again.`}
|
||||
</p>
|
||||
{notInRepo > 0 && (
|
||||
<p className="mt-1 text-muted-foreground">
|
||||
{notInRepo} file{notInRepo === 1 ? " in the folder isn't" : "s in the folder aren't"} part of the repo at this
|
||||
commit; {notInRepo === 1 ? "it stays" : "they stay"} untouched.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{result.existingModelId && (
|
||||
<p className="rounded-md bg-muted px-3 py-2 text-sm">
|
||||
This repo is already in the library.{" "}
|
||||
<Link href={`/models/${result.existingModelId}`} className="underline">
|
||||
<Link href={`/${result.repoId}`} className="underline">
|
||||
Open it
|
||||
</Link>
|
||||
</p>
|
||||
@@ -240,6 +319,8 @@ export function AddModelForm({
|
||||
</div>
|
||||
)}
|
||||
|
||||
<RecommendedStrip files={repoFiles} paths={recAll} active={recActive} onToggle={toggle} />
|
||||
|
||||
<div className="grid gap-3 sm:grid-cols-2">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="include">Include patterns</Label>
|
||||
@@ -269,6 +350,35 @@ export function AddModelForm({
|
||||
folder. Selected = checked or matching an include pattern, minus excludes.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<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>
|
||||
))}
|
||||
<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>
|
||||
|
||||
@@ -283,44 +393,62 @@ export function AddModelForm({
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{files.map((f) => (
|
||||
<TableRow key={f.path} data-state={f.selected ? "selected" : undefined}>
|
||||
<TableCell>
|
||||
<Checkbox
|
||||
checked={f.selected}
|
||||
disabled={f.byPattern || f.excluded}
|
||||
onCheckedChange={(v) => toggle(f.path, v === true)}
|
||||
aria-label={`Select ${f.path}`}
|
||||
title={
|
||||
f.excluded
|
||||
? "Excluded by a pattern"
|
||||
: f.byPattern
|
||||
? "Selected by an include pattern"
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-xs break-all whitespace-normal">
|
||||
{f.path}
|
||||
{f.excluded && <span className="ml-2 text-muted-foreground">(excluded)</span>}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(f.size)}</TableCell>
|
||||
<TableCell className="hidden text-xs text-muted-foreground sm:table-cell">
|
||||
{f.lfsSha256 ? "LFS" : "git"}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{entries.map((e) => {
|
||||
const parts = e.parts;
|
||||
const all = parts.every((f) => f.selected);
|
||||
const some = !all && parts.some((f) => f.selected);
|
||||
const byPattern = parts.every((f) => f.byPattern);
|
||||
const excluded = parts.every((f) => f.excluded);
|
||||
const isRecommended = parts.every((f) => f.recommended);
|
||||
return (
|
||||
<TableRow key={e.path} data-state={all ? "selected" : undefined}>
|
||||
<TableCell>
|
||||
<Checkbox
|
||||
checked={all}
|
||||
indeterminate={some}
|
||||
disabled={byPattern || excluded}
|
||||
onCheckedChange={(v) => toggle(parts.map((f) => f.path), v === true)}
|
||||
aria-label={`Select ${e.path}`}
|
||||
title={excluded ? "Excluded by a pattern" : byPattern ? "Selected by an include pattern" : undefined}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell className="whitespace-normal">
|
||||
<span className="flex items-center gap-2" title={e.totalParts > 1 ? parts.map((f) => f.path).join("\n") : undefined}>
|
||||
<FileRoleBadge path={e.path} />
|
||||
<span className="font-mono text-xs break-all">{e.path}</span>
|
||||
{e.totalParts > 1 && (
|
||||
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">
|
||||
{e.totalParts} parts
|
||||
</span>
|
||||
)}
|
||||
{excluded && <span className="text-xs text-muted-foreground">(excluded)</span>}
|
||||
{isRecommended && (
|
||||
<span className="shrink-0 rounded border border-amber-500/30 bg-amber-500/10 px-1 text-[10px] leading-4 text-amber-700 dark:text-amber-300">
|
||||
recommended
|
||||
</span>
|
||||
)}
|
||||
{importFolder && <DiskState parts={parts} onDisk={onDisk} />}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(e.size)}</TableCell>
|
||||
<TableCell className="hidden text-xs text-muted-foreground sm:table-cell">
|
||||
{parts[0].lfsSha256 ? "LFS" : "git"}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
|
||||
<div className="sticky bottom-0 -mx-4 border-t bg-background/95 px-4 py-3 backdrop-blur">
|
||||
<div className="sticky bottom-3 z-10 rounded-xl bg-card/95 px-4 py-3 text-card-foreground shadow-lg ring-1 ring-foreground/10 backdrop-blur">
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2">
|
||||
<div className="text-sm">
|
||||
<span className="font-medium">
|
||||
{selected.length} file{selected.length === 1 ? "" : "s"} · {formatBytes(totalBytes)}
|
||||
{selectedEntries} file{selectedEntries === 1 ? "" : "s"} · {formatBytes(totalBytes)}
|
||||
</span>{" "}
|
||||
selected
|
||||
{importFolder && <span className="text-muted-foreground"> · {formatBytes(toDownload)} to download</span>}
|
||||
{freeBytes != null && (
|
||||
<span className={notEnoughSpace ? "ml-2 text-destructive" : "ml-2 text-muted-foreground"}>
|
||||
({formatBytes(freeBytes)} free on the models volume)
|
||||
@@ -328,7 +456,10 @@ export function AddModelForm({
|
||||
)}
|
||||
</div>
|
||||
<div className="ml-auto flex gap-2">
|
||||
<Button type="button" variant="ghost" onClick={() => setChecked(new Set())}>
|
||||
<Button type="button" variant="ghost" onClick={() => {
|
||||
setChecked(new Set());
|
||||
resetRecommended();
|
||||
}}>
|
||||
Clear
|
||||
</Button>
|
||||
<Button
|
||||
@@ -336,7 +467,7 @@ export function AddModelForm({
|
||||
onClick={addToLibrary}
|
||||
disabled={selected.length === 0 || submitting || !!result.existingModelId}
|
||||
>
|
||||
{submitting ? "Adding…" : "Add & download"}
|
||||
{submitting ? "Adding…" : importFolder ? "Import & verify" : "Add & download"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -346,3 +477,21 @@ export function AddModelForm({
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Import mode: is this entry already in the folder (and the right size)? */
|
||||
function DiskState({ parts, onDisk }: { parts: { path: string; size: number }[]; onDisk: Map<string, number> }) {
|
||||
const here = parts.filter((f) => onDisk.has(f.path));
|
||||
if (here.length === 0) return null;
|
||||
const ok = here.every((f) => onDisk.get(f.path) === f.size) && here.length === parts.length;
|
||||
return (
|
||||
<span
|
||||
className={
|
||||
ok
|
||||
? "shrink-0 rounded border border-emerald-500/30 bg-emerald-500/10 px-1 text-[10px] leading-4 text-emerald-700 dark:text-emerald-300"
|
||||
: "shrink-0 rounded border border-amber-500/30 bg-amber-500/10 px-1 text-[10px] leading-4 text-amber-700 dark:text-amber-300"
|
||||
}
|
||||
>
|
||||
{ok ? "on disk" : here.length < parts.length ? `${here.length} of ${parts.length} parts on disk` : "on disk, size differs"}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,32 +1,120 @@
|
||||
"use client";
|
||||
|
||||
import { FolderInputIcon, RefreshCwIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { AddModelForm } from "./add-model-form";
|
||||
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { AddModelForm, type ImportFolder } from "./add-model-form";
|
||||
|
||||
/** Library header with an "Add model" toggle that opens the lookup/selection form inline. */
|
||||
export function AddModelPanel({ freeBytes, defaultOpen }: { freeBytes: number | null; defaultOpen: boolean }) {
|
||||
type Folder = ImportFolder & { totalBytes: number };
|
||||
|
||||
/**
|
||||
* Library header with an "Add model" toggle that opens the lookup/selection form inline, and the
|
||||
* folders in the models folder that aren't in the library yet, each with "Import".
|
||||
*/
|
||||
export function AddModelPanel({
|
||||
freeBytes,
|
||||
defaultOpen,
|
||||
folders,
|
||||
}: {
|
||||
freeBytes: number | null;
|
||||
defaultOpen: boolean;
|
||||
folders: Folder[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(defaultOpen);
|
||||
const [importing, setImporting] = useState<Folder | null>(null);
|
||||
const [scanning, setScanning] = useState(false);
|
||||
|
||||
function close() {
|
||||
setOpen(false);
|
||||
setImporting(null);
|
||||
}
|
||||
|
||||
async function rescan() {
|
||||
setScanning(true);
|
||||
try {
|
||||
const res = await fetch("/api/local-folders/scan", { method: "POST" });
|
||||
if (!res.ok) {
|
||||
toast.error(`Could not start a scan (${res.status})`);
|
||||
return;
|
||||
}
|
||||
// The worker picks the request up with its next heartbeat (every 5 s).
|
||||
await new Promise((r) => setTimeout(r, 7_000));
|
||||
router.refresh();
|
||||
} finally {
|
||||
setScanning(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold">Library</h1>
|
||||
<Button variant={open ? "outline" : "default"} onClick={() => setOpen((o) => !o)}>
|
||||
<Button variant={open ? "outline" : "default"} onClick={() => (open ? close() : setOpen(true))}>
|
||||
{open ? "Close" : "Add model"}
|
||||
</Button>
|
||||
</div>
|
||||
{open && (
|
||||
<AddModelForm
|
||||
key={importing?.path ?? "new"}
|
||||
freeBytes={freeBytes}
|
||||
importFolder={importing ?? undefined}
|
||||
onAdded={() => {
|
||||
setOpen(false);
|
||||
close();
|
||||
router.refresh();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{!open && folders.length > 0 && (
|
||||
<Card size="sm">
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<FolderInputIcon className="size-4 text-muted-foreground" />
|
||||
Found in the models folder
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{folders.length} folder{folders.length === 1 ? " isn't" : "s aren't"} in the library yet. Import matches
|
||||
{folders.length === 1 ? " it" : " them"} with the Hub repo and verifies the files instead of downloading them again.
|
||||
</CardDescription>
|
||||
<CardAction>
|
||||
<Button variant="ghost" size="sm" onClick={rescan} disabled={scanning}>
|
||||
<RefreshCwIcon className={cn(scanning && "animate-spin")} />
|
||||
{scanning ? "Scanning…" : "Rescan"}
|
||||
</Button>
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<ul className="divide-y rounded-lg ring-1 ring-foreground/10">
|
||||
{folders.map((f) => (
|
||||
<li key={f.path} className="flex flex-wrap items-center gap-x-4 gap-y-1 px-3 py-2">
|
||||
<span className="min-w-0 flex-1 truncate font-mono text-sm" title={f.path}>
|
||||
{f.path}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground tabular-nums">
|
||||
{f.fileCount} file{f.fileCount === 1 ? "" : "s"} · {formatBytes(f.totalBytes)}
|
||||
{f.commit && <> · hf commit {shortSha(f.commit)}</>}
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
setImporting(f);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
Import
|
||||
</Button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronDownIcon } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
|
||||
/** Multi-select dropdown for one facet, with per-value counts. */
|
||||
export function FacetFilter({
|
||||
label,
|
||||
values,
|
||||
selected,
|
||||
onChange,
|
||||
format = (v) => v,
|
||||
marker,
|
||||
}: {
|
||||
label: string;
|
||||
values: [string, number][];
|
||||
selected: string[];
|
||||
onChange: (next: string[]) => void;
|
||||
format?: (value: string) => string;
|
||||
/** Optional element before each value, e.g. a tag's color dot. */
|
||||
marker?: (value: string) => React.ReactNode;
|
||||
}) {
|
||||
const active = selected.length > 0;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
render={<Button variant={active ? "secondary" : "outline"} size="sm" disabled={values.length === 0} />}
|
||||
>
|
||||
{label}
|
||||
{active && <span className="rounded bg-background/60 px-1 text-xs tabular-nums">{selected.length}</span>}
|
||||
<ChevronDownIcon className="opacity-60" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-auto min-w-48">
|
||||
{values.map(([value, count]) => (
|
||||
<DropdownMenuCheckboxItem
|
||||
key={value}
|
||||
checked={selected.includes(value)}
|
||||
closeOnClick={false}
|
||||
onCheckedChange={(on) => onChange(on ? [...selected, value] : selected.filter((v) => v !== value))}
|
||||
>
|
||||
{marker?.(value)}
|
||||
<span className="flex-1">{format(value)}</span>
|
||||
<span className="ml-4 text-xs text-muted-foreground tabular-nums">{count}</span>
|
||||
</DropdownMenuCheckboxItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ export function JobLive({ initial }: { initial: JobSnapshot }) {
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<h1 className="text-xl font-semibold">
|
||||
{job.kind === "download" ? "Download" : job.kind} ·{" "}
|
||||
<Link href={`/models/${job.modelId}`} className="hover:underline">
|
||||
<Link href={`/${job.repoId}`} className="hover:underline">
|
||||
{job.repoId}
|
||||
</Link>
|
||||
</h1>
|
||||
|
||||
+24
-23
@@ -1,48 +1,49 @@
|
||||
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, getRecommendedRoles } from "@/lib/settings";
|
||||
import { getWorkerStatus } from "@/lib/worker-status";
|
||||
|
||||
export default async function AppLayout({ children }: LayoutProps<"/">) {
|
||||
const session = await auth();
|
||||
if (!session?.user) redirect("/login");
|
||||
|
||||
const worker = await getWorkerStatus();
|
||||
const [worker, fileRoles, recommendedRoles] = await Promise.all([
|
||||
getWorkerStatus(),
|
||||
getFileRoleStyles(),
|
||||
getRecommendedRoles(),
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col">
|
||||
<div className="flex min-h-screen flex-col overflow-x-clip">
|
||||
<header className="border-b">
|
||||
<div className="mx-auto flex h-14 max-w-6xl items-center gap-6 px-4">
|
||||
<Link href="/" className="flex items-baseline gap-1.5 font-semibold">
|
||||
Model Manager
|
||||
<span className="text-xs font-normal text-muted-foreground">{process.env.APP_VERSION ?? "dev"}</span>
|
||||
<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="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>
|
||||
</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>
|
||||
<main className="mx-auto w-full max-w-6xl flex-1 px-4 py-6">{children}</main>
|
||||
<main className="mx-auto w-full max-w-7xl flex-1 px-4 py-6">
|
||||
<LabelSettingsProvider fileRoles={fileRoles} recommendedRoles={recommendedRoles}>{children}</LabelSettingsProvider>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { JobProgress, JobStateBadge } from "@/components/job-progress";
|
||||
import { ModelStatusBadge } from "@/components/model-status-badge";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import type { JobSnapshot } from "@/lib/jobs";
|
||||
import type { LibraryRow } from "@/lib/library";
|
||||
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
export function LibraryTable({ rows }: { rows: LibraryRow[] }) {
|
||||
const { snapshot } = useLive();
|
||||
const openJobs = new Map<string, JobSnapshot>();
|
||||
for (const j of snapshot?.jobs ?? []) {
|
||||
if (OPEN.includes(j.state) && !openJobs.has(j.modelId)) openJobs.set(j.modelId, j);
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="py-0">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Repository</TableHead>
|
||||
<TableHead>Selection</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead>Pinned</TableHead>
|
||||
<TableHead className="hidden md:table-cell">Downloaded</TableHead>
|
||||
<TableHead className="w-56">Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{rows.map((r) => {
|
||||
const job = openJobs.get(r.id);
|
||||
return (
|
||||
<TableRow key={r.id}>
|
||||
<TableCell className="font-medium">
|
||||
<Link href={`/models/${r.id}`} className="hover:underline">
|
||||
{r.repoId}
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{r.quants.length > 0 ? r.quants.join(", ") : `${r.fileCount} files`}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(r.totalBytes)}</TableCell>
|
||||
<TableCell>
|
||||
<code className="font-mono text-xs" title={r.pinnedSha}>
|
||||
{r.trackedRevision}@{shortSha(r.pinnedSha)}
|
||||
</code>
|
||||
</TableCell>
|
||||
<TableCell className="hidden text-sm text-muted-foreground md:table-cell">
|
||||
<LocalTime value={r.downloadedAt} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{job ? (
|
||||
<Link href={`/jobs/${job.id}`} className="flex flex-col gap-1">
|
||||
<JobStateBadge job={job} />
|
||||
{job.state !== "queued" && <JobProgress job={job} compact />}
|
||||
</Link>
|
||||
) : (
|
||||
<ModelStatusBadge status={r.status} />
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
"use client";
|
||||
|
||||
import { SearchIcon, XIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
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";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import type { ModelStatus } from "@/lib/db/schema";
|
||||
import { formatBytes, shortSha } from "@/lib/format";
|
||||
import type { JobSnapshot } from "@/lib/jobs";
|
||||
import type { LibraryRow } from "@/lib/library";
|
||||
import {
|
||||
EMPTY_FILTERS,
|
||||
type Facet,
|
||||
FACETS,
|
||||
facetCounts,
|
||||
type Filters,
|
||||
matchesFilters,
|
||||
matchesQuery,
|
||||
type SearchableModel,
|
||||
} from "@/lib/search";
|
||||
import { FacetFilter } from "./facet-filter";
|
||||
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
const FACET_LABEL: Record<Facet, string> = {
|
||||
author: "Author",
|
||||
family: "Family",
|
||||
quant: "Quant",
|
||||
tag: "Tag",
|
||||
status: "Status",
|
||||
};
|
||||
|
||||
const statusLabel = (v: string) => MODEL_STATUS[v as ModelStatus]?.label ?? v;
|
||||
|
||||
function toSearchable(r: LibraryRow): SearchableModel {
|
||||
return {
|
||||
repoId: r.repoId,
|
||||
author: r.author,
|
||||
families: r.families,
|
||||
baseModels: r.baseModels,
|
||||
architecture: r.architecture,
|
||||
quants: r.quants,
|
||||
tags: r.tags.map((t) => t.name),
|
||||
hubTags: r.hubTags,
|
||||
pipelineTag: r.pipelineTag,
|
||||
license: r.license,
|
||||
status: r.status,
|
||||
hubStatus: r.hubState && r.hubState !== "available" ? HUB_STATE_LABEL[r.hubState].label : null,
|
||||
};
|
||||
}
|
||||
|
||||
/** Search + facet filters (kept in the URL) over the library table. */
|
||||
export function LibraryView({ rows }: { rows: LibraryRow[] }) {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const params = useSearchParams();
|
||||
const [query, setQuery] = useState(() => params.get("q") ?? "");
|
||||
const [filters, setFilters] = useState<Filters>(() => {
|
||||
const f = { ...EMPTY_FILTERS };
|
||||
for (const facet of FACETS) f[facet] = params.getAll(facet);
|
||||
return f;
|
||||
});
|
||||
|
||||
function sync(nextQuery: string, nextFilters: Filters) {
|
||||
const p = new URLSearchParams();
|
||||
if (nextQuery) p.set("q", nextQuery);
|
||||
for (const facet of FACETS) for (const v of nextFilters[facet]) p.append(facet, v);
|
||||
const qs = p.toString();
|
||||
router.replace(qs ? `${pathname}?${qs}` : pathname, { scroll: false });
|
||||
}
|
||||
const updateQuery = (q: string) => {
|
||||
setQuery(q);
|
||||
sync(q, filters);
|
||||
};
|
||||
const updateFilter = (facet: Facet, values: string[]) => {
|
||||
const next = { ...filters, [facet]: values };
|
||||
setFilters(next);
|
||||
sync(query, next);
|
||||
};
|
||||
const clearAll = () => {
|
||||
setQuery("");
|
||||
setFilters(EMPTY_FILTERS);
|
||||
sync("", EMPTY_FILTERS);
|
||||
};
|
||||
|
||||
const searchable = useMemo(() => rows.map(toSearchable), [rows]);
|
||||
const tagColors = useMemo(() => new Map(rows.flatMap((r) => r.tags.map((t) => [t.name, t.color] as const))), [rows]);
|
||||
const visible = rows.filter((_, i) => matchesQuery(searchable[i], query) && matchesFilters(searchable[i], filters));
|
||||
const anyActive = query.trim() !== "" || FACETS.some((f) => filters[f].length > 0);
|
||||
|
||||
const { snapshot } = useLive();
|
||||
const openJobs = new Map<string, JobSnapshot>();
|
||||
for (const j of snapshot?.jobs ?? []) {
|
||||
if (OPEN.includes(j.state) && !openJobs.has(j.modelId)) openJobs.set(j.modelId, j);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<div className="relative min-w-56 flex-1">
|
||||
<SearchIcon className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(e) => updateQuery(e.target.value)}
|
||||
placeholder="Search repo, author, family, quant, tag…"
|
||||
className="pl-8"
|
||||
aria-label="Search models"
|
||||
/>
|
||||
</div>
|
||||
{FACETS.map((facet) => (
|
||||
<FacetFilter
|
||||
key={facet}
|
||||
label={FACET_LABEL[facet]}
|
||||
values={facetCounts(searchable, facet, query, filters)}
|
||||
selected={filters[facet]}
|
||||
onChange={(v) => updateFilter(facet, v)}
|
||||
format={facet === "status" ? statusLabel : undefined}
|
||||
marker={facet === "tag" ? (v) => <TagDot name={v} color={tagColors.get(v)} /> : undefined}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{anyActive && (
|
||||
<div className="flex flex-wrap items-center gap-1.5 text-sm">
|
||||
<span className="text-muted-foreground">
|
||||
{visible.length} of {rows.length} models
|
||||
</span>
|
||||
{FACETS.flatMap((facet) =>
|
||||
filters[facet].map((v) => (
|
||||
<Badge key={`${facet}:${v}`} variant="secondary" className="gap-1">
|
||||
{facet === "tag" && <TagDot name={v} color={tagColors.get(v)} />}
|
||||
{FACET_LABEL[facet]}: {facet === "status" ? statusLabel(v) : v}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Remove filter ${v}`}
|
||||
onClick={() => updateFilter(facet, filters[facet].filter((x) => x !== v))}
|
||||
>
|
||||
<XIcon className="size-3" />
|
||||
</button>
|
||||
</Badge>
|
||||
)),
|
||||
)}
|
||||
<Button variant="ghost" size="xs" onClick={clearAll}>
|
||||
Clear all
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{visible.length === 0 ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>No matching models</CardTitle>
|
||||
<CardDescription>Try a different search or remove a filter.</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
) : (
|
||||
<Card className="py-0">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Model</TableHead>
|
||||
<TableHead>Selection</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead className="hidden lg:table-cell">Pinned</TableHead>
|
||||
<TableHead className="hidden md:table-cell">Downloaded</TableHead>
|
||||
<TableHead className="w-56">Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{visible.map((r) => {
|
||||
const job = openJobs.get(r.id);
|
||||
const base = r.baseModels[0];
|
||||
return (
|
||||
<TableRow key={r.id}>
|
||||
<TableCell className="whitespace-normal">
|
||||
<Link href={`/${r.repoId}`} className="font-medium hover:underline">
|
||||
{r.repoId}
|
||||
</Link>
|
||||
<div className="mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">
|
||||
{base && base !== r.repoId && <span>base {base}</span>}
|
||||
{r.architecture && <span>{r.architecture}</span>}
|
||||
{r.tags.map((t) => (
|
||||
<button
|
||||
key={t.id}
|
||||
type="button"
|
||||
onClick={() => !filters.tag.includes(t.name) && updateFilter("tag", [...filters.tag, t.name])}
|
||||
>
|
||||
<TagBadge name={t.name} color={t.color} />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{r.quants.length > 0 ? r.quants.join(", ") : `${r.fileCount} file${r.fileCount === 1 ? "" : "s"}`}
|
||||
</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(r.totalBytes)}</TableCell>
|
||||
<TableCell className="hidden lg:table-cell">
|
||||
<code className="font-mono text-xs" title={r.pinnedSha}>
|
||||
{r.trackedRevision}@{shortSha(r.pinnedSha)}
|
||||
</code>
|
||||
</TableCell>
|
||||
<TableCell className="hidden text-sm text-muted-foreground md:table-cell">
|
||||
<LocalTime value={r.downloadedAt} />
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{job ? (
|
||||
<Link href={`/jobs/${job.id}`} className="flex flex-col gap-1">
|
||||
<JobStateBadge job={job} />
|
||||
{job.state !== "queued" && <JobProgress job={job} compact />}
|
||||
</Link>
|
||||
) : (
|
||||
<span className="flex flex-wrap gap-1">
|
||||
<ModelStatusBadge status={r.status} />
|
||||
<HubStateBadge state={r.hubState} />
|
||||
</span>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { cancelJob, startDownload } from "@/components/job-actions";
|
||||
import { JobFilesTable } from "@/components/job-files-table";
|
||||
import { JobProgress, JobStateBadge } from "@/components/job-progress";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { useLive } from "@/hooks/use-live";
|
||||
import type { ModelStatus } from "@/lib/db/schema";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import type { JobSnapshot } from "@/lib/jobs";
|
||||
|
||||
const OPEN = ["queued", "downloading", "verifying"];
|
||||
|
||||
export function ModelLive({ modelId, status }: { modelId: string; status: ModelStatus }) {
|
||||
const { snapshot } = useLive({ model: modelId });
|
||||
const [busy, setBusy] = useState(false);
|
||||
const jobs = snapshot?.jobs ?? [];
|
||||
const latest = jobs[0] as JobSnapshot | undefined;
|
||||
const open = latest && OPEN.includes(latest.state) ? latest : undefined;
|
||||
const workerOffline = snapshot && !snapshot.worker.online;
|
||||
|
||||
async function run(fn: () => Promise<void>) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await fn();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex flex-wrap items-center gap-2">
|
||||
Download
|
||||
{latest && <JobStateBadge job={latest} />}
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{open
|
||||
? open.state === "queued"
|
||||
? workerOffline
|
||||
? "Queued, but the worker is offline."
|
||||
: "Queued, waiting for a free download slot."
|
||||
: "Running in the background; you can close this page."
|
||||
: status === "ready"
|
||||
? "All selected files are present."
|
||||
: "Downloads the selected files at the pinned SHA."}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
{latest && !(latest.state === "completed" && status === "ready") && <JobProgress job={latest} compact />}
|
||||
{latest?.errorMessage && latest.state === "failed" && (
|
||||
<pre className="rounded-md bg-destructive/10 px-3 py-2 text-xs whitespace-pre-wrap text-destructive">
|
||||
{latest.errorMessage}
|
||||
</pre>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{open ? (
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
disabled={busy || open.cancelRequested}
|
||||
onClick={() => run(() => cancelJob(open.id))}
|
||||
>
|
||||
{open.cancelRequested ? "Cancelling…" : "Cancel"}
|
||||
</Button>
|
||||
) : (
|
||||
status !== "ready" &&
|
||||
snapshot && (
|
||||
<Button size="sm" disabled={busy} onClick={() => run(() => startDownload(modelId))}>
|
||||
{latest ? "Download again" : "Download"}
|
||||
</Button>
|
||||
)
|
||||
)}
|
||||
{latest && (
|
||||
<Link
|
||||
href={`/jobs/${latest.id}`}
|
||||
className="inline-flex h-7 items-center rounded-md px-2.5 text-[0.8rem] hover:bg-muted"
|
||||
>
|
||||
View log
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
{open && snapshot && snapshot.files.length > 0 && <JobFilesTable files={snapshot.files} />}
|
||||
</Card>
|
||||
|
||||
{jobs.length > 0 && (
|
||||
<Card className="py-0">
|
||||
<CardHeader className="pt-4">
|
||||
<CardTitle>Jobs</CardTitle>
|
||||
</CardHeader>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Started</TableHead>
|
||||
<TableHead>Kind</TableHead>
|
||||
<TableHead>State</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead className="hidden sm:table-cell">Finished</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{jobs.map((j) => (
|
||||
<TableRow key={j.id}>
|
||||
<TableCell>
|
||||
<Link href={`/jobs/${j.id}`} className="hover:underline">
|
||||
<LocalTime value={j.startedAt ?? j.createdAt} />
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm">
|
||||
{j.kind}
|
||||
{j.purpose && j.purpose !== "initial" ? ` (${j.purpose})` : ""}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<JobStateBadge job={j} />
|
||||
</TableCell>
|
||||
<TableCell className="text-right text-sm tabular-nums">{formatBytes(j.totalBytes)}</TableCell>
|
||||
<TableCell className="hidden text-sm text-muted-foreground sm:table-cell">
|
||||
<LocalTime value={j.finishedAt} />
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,94 +1,14 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { ModelStatusBadge } from "@/components/model-status-badge";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import { LocalTime } from "@/components/local-time";
|
||||
import { getModel } from "@/lib/library";
|
||||
import { ModelLive } from "./model-live";
|
||||
import { RemoveModelButton } from "./remove-model-button";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { notFound, permanentRedirect } from "next/navigation";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { models } from "@/lib/db/schema";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function ModelPage({ params }: PageProps<"/models/[id]">) {
|
||||
/** Old URL scheme (/models/<id>): redirect to /<org>/<name>. */
|
||||
export default async function LegacyModelPage({ params }: PageProps<"/models/[id]">) {
|
||||
const { id } = await params;
|
||||
const data = await getModel(id);
|
||||
if (!data) notFound();
|
||||
const { model, files } = data;
|
||||
const selected = files.filter((f) => f.selected);
|
||||
const totalBytes = selected.reduce((s, f) => s + f.size, 0);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<h1 className="text-xl font-semibold break-all">{model.repoId}</h1>
|
||||
<ModelStatusBadge status={model.status} />
|
||||
<div className="ml-auto">{model.status === "pending" && <RemoveModelButton id={model.id} />}</div>
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Details</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<dl className="grid grid-cols-[max-content_1fr] gap-x-6 gap-y-2 text-sm">
|
||||
<dt className="text-muted-foreground">Hub</dt>
|
||||
<dd>
|
||||
<a
|
||||
href={`https://huggingface.co/${model.repoId}/tree/${model.pinnedSha}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="underline"
|
||||
>
|
||||
huggingface.co/{model.repoId}
|
||||
</a>
|
||||
</dd>
|
||||
<dt className="text-muted-foreground">Tracked revision</dt>
|
||||
<dd className="font-mono">{model.trackedRevision}</dd>
|
||||
<dt className="text-muted-foreground">Pinned SHA</dt>
|
||||
<dd className="font-mono break-all">{model.pinnedSha}</dd>
|
||||
<dt className="text-muted-foreground">Local path</dt>
|
||||
<dd className="font-mono break-all">$MODELS_DIR/{model.localPath}</dd>
|
||||
<dt className="text-muted-foreground">Include</dt>
|
||||
<dd className="font-mono text-xs break-all">{model.includePatterns.join(", ") || "–"}</dd>
|
||||
<dt className="text-muted-foreground">Exclude</dt>
|
||||
<dd className="font-mono text-xs break-all">{model.excludePatterns.join(", ") || "–"}</dd>
|
||||
<dt className="text-muted-foreground">Added</dt>
|
||||
<dd><LocalTime value={model.createdAt} /></dd>
|
||||
</dl>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<ModelLive modelId={model.id} status={model.status} />
|
||||
|
||||
<Card className="py-0">
|
||||
<CardHeader className="pt-4">
|
||||
<CardTitle>
|
||||
Selected files · {selected.length} · {formatBytes(totalBytes)}
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{files.length - selected.length} other files in the repo are not selected.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>File</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
<TableHead>State</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{selected.map((f) => (
|
||||
<TableRow key={f.id}>
|
||||
<TableCell className="font-mono text-xs break-all whitespace-normal">{f.path}</TableCell>
|
||||
<TableCell className="text-right tabular-nums">{formatBytes(f.size)}</TableCell>
|
||||
<TableCell className="text-sm text-muted-foreground">{f.state}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
const model = await db().query.models.findFirst({ columns: { repoId: true }, where: eq(models.id, id) });
|
||||
if (!model) notFound();
|
||||
permanentRedirect(`/${model.repoId}`);
|
||||
}
|
||||
+10
-5
@@ -1,18 +1,23 @@
|
||||
import { listLibrary } from "@/lib/library";
|
||||
import { listLocalFolders } from "@/lib/local-folders";
|
||||
import { getWorkerStatus } from "@/lib/worker-status";
|
||||
import { AddModelPanel } from "./add-model-panel";
|
||||
import { LibraryTable } from "./library-table";
|
||||
import { LibraryView } from "./library-view";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function LibraryPage() {
|
||||
const [rows, worker] = await Promise.all([listLibrary(), getWorkerStatus()]);
|
||||
const [rows, worker, folders] = await Promise.all([listLibrary(), getWorkerStatus(), listLocalFolders()]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Opens by default while the library is empty. */}
|
||||
<AddModelPanel freeBytes={worker.online ? worker.modelsDirFreeBytes : null} defaultOpen={rows.length === 0} />
|
||||
{rows.length > 0 && <LibraryTable rows={rows} />}
|
||||
{/* Opens by default while the library is empty and there's nothing on disk to import. */}
|
||||
<AddModelPanel
|
||||
freeBytes={worker.online ? worker.modelsDirFreeBytes : null}
|
||||
defaultOpen={rows.length === 0 && folders.length === 0}
|
||||
folders={folders.map((f) => ({ path: f.path, commit: f.commit, files: f.files, fileCount: f.fileCount, totalBytes: f.totalBytes }))}
|
||||
/>
|
||||
{rows.length > 0 && <LibraryView rows={rows} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getRecommendedRoles } from "@/lib/settings";
|
||||
import { RecommendedSettings } from "./recommended-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const metadata: Metadata = { title: "Downloads · Settings" };
|
||||
|
||||
export default async function DownloadSettingsPage() {
|
||||
return <RecommendedSettings initial={await getRecommendedRoles()} />;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { FileRoleBadge } from "@/components/labels";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { FILE_ROLES, type FileRole } from "@/lib/file-roles";
|
||||
import { RECOMMENDABLE_ROLES } from "@/lib/recommend";
|
||||
|
||||
/** Example file name per kind, so the badge shows the configured label and color. */
|
||||
const EXAMPLE: Partial<Record<FileRole, string>> = {
|
||||
template: "chat_template.jinja",
|
||||
mtp: "mtp-model.gguf",
|
||||
vision: "mmproj-F16.gguf",
|
||||
draft: "model-draft.gguf",
|
||||
config: "config.json",
|
||||
tokenizer: "tokenizer.json",
|
||||
imatrix: "imatrix.dat",
|
||||
adapter: "adapter_model.safetensors",
|
||||
docs: "README.md",
|
||||
};
|
||||
|
||||
const HINT: Partial<Record<FileRole, string>> = {
|
||||
mtp: "The variant with the same quant as your model file, otherwise the closest one.",
|
||||
vision: "One mmproj file: same quant if there is one, otherwise F16, BF16, Q8_0, F32.",
|
||||
draft: "One draft model, picked like MTP.",
|
||||
imatrix: "Only needed to make your own quants.",
|
||||
config: "GGUF files already contain it; useful for safetensors repos.",
|
||||
tokenizer: "GGUF files already contain it; useful for safetensors repos.",
|
||||
};
|
||||
|
||||
/** Which file kinds are selected automatically when you pick model weights. Saves on change. */
|
||||
export function RecommendedSettings({ initial }: { initial: FileRole[] }) {
|
||||
const router = useRouter();
|
||||
const [roles, setRoles] = useState(new Set(initial));
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
async function toggle(role: FileRole, on: boolean) {
|
||||
const before = roles;
|
||||
const next = new Set(roles);
|
||||
if (on) next.add(role);
|
||||
else next.delete(role);
|
||||
setRoles(next);
|
||||
setSaving(true);
|
||||
try {
|
||||
const res = await fetch("/api/settings/downloads", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ recommendedRoles: [...next] }),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
toast.error(body.error?.message ?? `Could not save (${res.status})`);
|
||||
setRoles(before);
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Recommended files</CardTitle>
|
||||
<CardDescription>
|
||||
When you pick model weights (a quant) in Add model or Download more, files of these kinds are selected along
|
||||
with them. You can still uncheck them before downloading.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="divide-y rounded-lg ring-1 ring-foreground/10">
|
||||
{RECOMMENDABLE_ROLES.map((role) => (
|
||||
<label key={role} className="flex cursor-pointer items-start gap-3 px-4 py-3 hover:bg-muted/40">
|
||||
<Checkbox
|
||||
checked={roles.has(role)}
|
||||
disabled={saving}
|
||||
onCheckedChange={(v) => void toggle(role, v === true)}
|
||||
className="mt-0.5"
|
||||
aria-label={FILE_ROLES[role].label}
|
||||
/>
|
||||
<FileRoleBadge path={EXAMPLE[role] ?? role} />
|
||||
<span className="flex min-w-0 flex-col">
|
||||
<span className="text-sm">{FILE_ROLES[role].description}</span>
|
||||
{HINT[role] && <span className="text-xs text-muted-foreground">{HINT[role]}</span>}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronDownIcon } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { DOT_CLASS, LABEL_COLORS, type LabelColor } from "@/lib/colors";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** Dropdown of the named label colors; optional "Automatic" entry (value null). */
|
||||
export function ColorPicker({
|
||||
value,
|
||||
onChange,
|
||||
allowAuto = false,
|
||||
autoColor,
|
||||
}: {
|
||||
value: LabelColor | null;
|
||||
onChange: (color: LabelColor | null) => void;
|
||||
allowAuto?: boolean;
|
||||
/** Color shown for the automatic option. */
|
||||
autoColor?: LabelColor;
|
||||
}) {
|
||||
const shown = value ?? autoColor ?? "gray";
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger render={<Button variant="outline" size="sm" className="w-32 justify-start" />}>
|
||||
<span className={cn("size-3 rounded-full", DOT_CLASS[shown])} />
|
||||
<span className="flex-1 text-left capitalize">{value ?? "Automatic"}</span>
|
||||
<ChevronDownIcon className="opacity-60" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="max-h-72 min-w-40">
|
||||
{allowAuto && (
|
||||
<DropdownMenuItem onClick={() => onChange(null)}>
|
||||
<span className={cn("size-3 rounded-full", DOT_CLASS[autoColor ?? "gray"])} />
|
||||
Automatic
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{LABEL_COLORS.map((c) => (
|
||||
<DropdownMenuItem key={c} onClick={() => onChange(c)}>
|
||||
<span className={cn("size-3 rounded-full", DOT_CLASS[c])} />
|
||||
<span className="capitalize">{c}</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
"use client";
|
||||
|
||||
import { RotateCcwIcon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { BADGE_CLASS } from "@/lib/colors";
|
||||
import { FILE_ROLE_ORDER, FILE_ROLES, type FileRoleStyles } from "@/lib/file-roles";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ColorPicker } from "./color-picker";
|
||||
|
||||
/** Edit the label text and color shown in front of file names. */
|
||||
export function FileLabelSettings({ initial }: { initial: FileRoleStyles }) {
|
||||
const router = useRouter();
|
||||
const [styles, setStyles] = useState(initial);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const dirty = JSON.stringify(styles) !== JSON.stringify(initial);
|
||||
|
||||
function update(role: keyof FileRoleStyles, patch: Partial<FileRoleStyles[keyof FileRoleStyles]>) {
|
||||
setStyles((prev) => ({ ...prev, [role]: { ...prev[role], ...patch } }));
|
||||
}
|
||||
|
||||
async function save(next = styles) {
|
||||
setSaving(true);
|
||||
try {
|
||||
const res = await fetch("/api/settings/labels", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ fileRoles: next }),
|
||||
});
|
||||
const body = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast.error(body.error?.message ?? `Could not save (${res.status})`);
|
||||
return;
|
||||
}
|
||||
setStyles(body.fileRoles);
|
||||
toast.success("File labels saved");
|
||||
router.refresh();
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
const defaults = Object.fromEntries(
|
||||
FILE_ROLE_ORDER.map((r) => [r, { label: FILE_ROLES[r].label, color: FILE_ROLES[r].color }]),
|
||||
) as FileRoleStyles;
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>File labels</CardTitle>
|
||||
<CardDescription>
|
||||
Shown in front of file names (Files tab, Add model). Kaname detects the type from the file name; here you
|
||||
choose how each type is labeled and colored.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-4">
|
||||
<div className="divide-y rounded-lg ring-1 ring-foreground/10">
|
||||
{FILE_ROLE_ORDER.map((role) => {
|
||||
const s = styles[role];
|
||||
const changed = s.label !== defaults[role].label || s.color !== defaults[role].color;
|
||||
return (
|
||||
<div key={role} className="grid grid-cols-[6rem_minmax(0,1fr)] items-center gap-x-4 gap-y-2 px-4 py-3 sm:grid-cols-[6rem_minmax(0,1fr)_10rem_8rem_2rem]">
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex h-5 justify-self-start rounded-md border px-1.5 text-[11px] leading-[18px] font-medium",
|
||||
BADGE_CLASS[s.color],
|
||||
)}
|
||||
>
|
||||
{s.label || "…"}
|
||||
</span>
|
||||
<span className="min-w-0 text-xs text-muted-foreground">{FILE_ROLES[role].description}</span>
|
||||
<Input
|
||||
value={s.label}
|
||||
maxLength={24}
|
||||
onChange={(e) => update(role, { label: e.target.value })}
|
||||
aria-label={`Label for ${FILE_ROLES[role].label}`}
|
||||
className="h-8"
|
||||
/>
|
||||
<ColorPicker value={s.color} onChange={(c) => c && update(role, { color: c })} />
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
disabled={!changed}
|
||||
title="Reset to default"
|
||||
aria-label="Reset to default"
|
||||
onClick={() => update(role, defaults[role])}
|
||||
>
|
||||
<RotateCcwIcon />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="flex flex-wrap justify-end gap-2">
|
||||
<Button variant="ghost" onClick={() => setStyles(initial)} disabled={!dirty || saving}>
|
||||
Discard changes
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => save(defaults)} disabled={saving}>
|
||||
Reset all to defaults
|
||||
</Button>
|
||||
<Button onClick={() => save()} disabled={!dirty || saving}>
|
||||
{saving ? "Saving…" : "Save"}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getFileRoleStyles } from "@/lib/settings";
|
||||
import { FileLabelSettings } from "./file-label-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const metadata: Metadata = { title: "File labels · Settings" };
|
||||
|
||||
export default async function LabelSettingsPage() {
|
||||
return <FileLabelSettings initial={await getFileRoleStyles()} />;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { DownloadIcon, TagIcon, TagsIcon } from "lucide-react";
|
||||
import { SettingsNav } from "./settings-nav";
|
||||
|
||||
const SECTIONS = [
|
||||
{ href: "/settings/labels", label: "File labels", icon: <TagIcon className="size-4" /> },
|
||||
{ href: "/settings/tags", label: "Tags", icon: <TagsIcon className="size-4" /> },
|
||||
{ href: "/settings/downloads", label: "Downloads", icon: <DownloadIcon className="size-4" /> },
|
||||
];
|
||||
|
||||
export default function SettingsLayout({ children }: LayoutProps<"/settings">) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<h1 className="text-xl font-semibold">Settings</h1>
|
||||
<div className="grid items-start gap-4 md:grid-cols-[200px_minmax(0,1fr)]">
|
||||
<SettingsNav sections={SECTIONS} />
|
||||
<div className="min-w-0">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function SettingsPage() {
|
||||
redirect("/settings/labels");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
export function SettingsNav({ sections }: { sections: { href: string; label: string; icon: React.ReactNode }[] }) {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<nav className="flex gap-1 rounded-xl bg-card p-2 ring-1 ring-foreground/10 md:flex-col">
|
||||
{sections.map((s) => (
|
||||
<Link
|
||||
key={s.href}
|
||||
href={s.href}
|
||||
className={cn(
|
||||
"flex items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors",
|
||||
pathname === s.href ? "bg-muted font-medium text-foreground" : "text-muted-foreground hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
{s.icon}
|
||||
{s.label}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -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()} />;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
"use client";
|
||||
|
||||
import { PlusIcon, Trash2Icon } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { TagBadge } from "@/components/tag-badge";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
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, type LabelColor } from "@/lib/colors";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
import { ColorPicker } from "../labels/color-picker";
|
||||
|
||||
/** 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, to attach on a model page or when adding a model. Tags without a color get an automatic one.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
<NewTagRow />
|
||||
{tags.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No tags yet.</p>
|
||||
) : (
|
||||
<div className="divide-y rounded-lg ring-1 ring-foreground/10">
|
||||
{tags.map((t) => (
|
||||
<TagRow key={t.id} tag={t} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function patch(body: { name?: string; color?: string | null }) {
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await fetch(`/api/tags/${tag.id}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const json = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast.error(json.error?.message ?? `Could not save (${res.status})`);
|
||||
setName(tag.name);
|
||||
return;
|
||||
}
|
||||
router.refresh();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
const res = await fetch(`/api/tags/${tag.id}`, { method: "DELETE" });
|
||||
if (!res.ok) toast.error(`Could not delete (${res.status})`);
|
||||
else toast.success(`Tag "${tag.name}" deleted`);
|
||||
router.refresh();
|
||||
}
|
||||
|
||||
const color = isLabelColor(tag.color) ? tag.color : null;
|
||||
return (
|
||||
<div className="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 gap-y-2 px-4 py-3 sm:grid-cols-[8rem_minmax(0,1fr)_8rem_6rem_2rem]">
|
||||
<TagBadge name={name || tag.name} color={tag.color} className="justify-self-start" />
|
||||
<Input
|
||||
value={name}
|
||||
maxLength={40}
|
||||
disabled={busy}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
onBlur={() => name.trim() && name !== tag.name && patch({ name })}
|
||||
onKeyDown={(e) => e.key === "Enter" && (e.target as HTMLInputElement).blur()}
|
||||
aria-label={`Rename tag ${tag.name}`}
|
||||
className="h-8"
|
||||
/>
|
||||
<ColorPicker value={color} onChange={(c) => patch({ color: c })} allowAuto autoColor={autoTagColor(tag.name)} />
|
||||
<span className="text-xs text-muted-foreground tabular-nums">
|
||||
{tag.count} model{tag.count === 1 ? "" : "s"}
|
||||
</span>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger render={<Button variant="ghost" size="icon-sm" aria-label={`Delete tag ${tag.name}`} />}>
|
||||
<Trash2Icon />
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete tag “{tag.name}”?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
It is removed from {tag.count} model{tag.count === 1 ? "" : "s"}. The models themselves are not touched.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" onClick={remove}>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { requestFolderScan } from "@/lib/local-folders";
|
||||
|
||||
/** Ask the worker to rescan the models folder for importable folders. */
|
||||
export const POST = withAuth(async () => {
|
||||
await requestFolderScan();
|
||||
return new NextResponse(null, { status: 202 });
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { addFilesToModel, ModelError } from "@/lib/models";
|
||||
|
||||
const Body = z.object({ add: z.array(z.string().min(1).max(1024)).min(1).max(10_000) });
|
||||
|
||||
/** Add files to a model's selection and queue their download. */
|
||||
export const POST = withAuth<RouteContext<"/api/models/[id]/files">>(async (req, { params }) => {
|
||||
const { id } = await params;
|
||||
try {
|
||||
const { add } = Body.parse(await req.json());
|
||||
return NextResponse.json(await addFilesToModel(id, add), { status: 201 });
|
||||
} catch (err) {
|
||||
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -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));
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { removeTag } from "@/lib/tags";
|
||||
|
||||
/** Detach a tag from a model. */
|
||||
export const DELETE = withAuth<RouteContext<"/api/models/[id]/tags/[tagId]">>(async (_req, { params }) => {
|
||||
const { id, tagId } = await params;
|
||||
await removeTag(id, tagId);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { addTag, TagError } from "@/lib/tags";
|
||||
|
||||
const Body = z.object({ name: z.string() });
|
||||
|
||||
/** Attach a tag to a model (creates the tag on first use). */
|
||||
export const POST = withAuth<RouteContext<"/api/models/[id]/tags">>(async (req, { params }) => {
|
||||
const { id } = await params;
|
||||
try {
|
||||
const { name } = Body.parse(await req.json());
|
||||
return NextResponse.json(await addTag(id, name), { status: 201 });
|
||||
} catch (err) {
|
||||
if (err instanceof TagError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { REPO_ID_RE, SHA_RE } from "@/lib/hub/client";
|
||||
import { queueDownload } from "@/lib/jobs";
|
||||
import { addModel, ModelError } from "@/lib/models";
|
||||
import { addTag, normalizeTagName, TagError } from "@/lib/tags";
|
||||
|
||||
const Body = z.object({
|
||||
repoId: z.string().regex(REPO_ID_RE),
|
||||
@@ -13,22 +14,28 @@ const Body = z.object({
|
||||
include: z.array(z.string().min(1).max(1024)).max(10_000),
|
||||
exclude: z.array(z.string().min(1).max(1024)).max(1_000),
|
||||
download: z.boolean().default(true),
|
||||
tags: z.array(z.string()).max(50).default([]),
|
||||
/** Import an existing folder from the models folder (as found by the worker's scan). */
|
||||
localPath: z.string().min(1).max(512).optional(),
|
||||
});
|
||||
|
||||
/** Add a model to the library, pinned to the SHA the user reviewed, and queue its download. */
|
||||
export const POST = withAuth(async (req) => {
|
||||
try {
|
||||
const body = Body.parse(await req.json());
|
||||
body.tags.forEach(normalizeTagName); // validate before anything is written
|
||||
const { id } = await addModel({
|
||||
repoId: body.repoId,
|
||||
revision: body.revision,
|
||||
sha: body.sha,
|
||||
rule: { include: body.include, exclude: body.exclude },
|
||||
localPath: body.localPath,
|
||||
});
|
||||
const job = body.download ? await queueDownload(id) : null;
|
||||
for (const tag of body.tags) await addTag(id, tag);
|
||||
const job = body.download ? await queueDownload(id, body.localPath ? "import" : "initial") : null;
|
||||
return NextResponse.json({ id, jobId: job?.jobId ?? null }, { status: 201 });
|
||||
} catch (err) {
|
||||
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
|
||||
if (err instanceof ModelError || err instanceof TagError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { getRecommendedRoles, saveRecommendedRoles, SettingsError } from "@/lib/settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/** Download settings: which file kinds are picked along with model weights. */
|
||||
export const GET = withAuth(async () => NextResponse.json({ recommendedRoles: await getRecommendedRoles() }));
|
||||
|
||||
const Body = z.object({ recommendedRoles: z.array(z.string()).max(32) });
|
||||
|
||||
export const PUT = withAuth(async (req) => {
|
||||
try {
|
||||
const { recommendedRoles } = Body.parse(await req.json());
|
||||
return NextResponse.json({ recommendedRoles: await saveRecommendedRoles(recommendedRoles) });
|
||||
} catch (err) {
|
||||
if (err instanceof SettingsError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { getFileRoleStyles, saveFileRoleStyles, SettingsError } from "@/lib/settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
/** Label text and color per file role (defaults merged with saved overrides). */
|
||||
export const GET = withAuth(async () => NextResponse.json({ fileRoles: await getFileRoleStyles() }));
|
||||
|
||||
const Body = z.object({
|
||||
fileRoles: z.record(z.string(), z.object({ label: z.string().optional(), color: z.string().optional() })),
|
||||
});
|
||||
|
||||
/** Replace the saved overrides; send the full set (values equal to the default are dropped). */
|
||||
export const PUT = withAuth(async (req) => {
|
||||
try {
|
||||
const { fileRoles } = Body.parse(await req.json());
|
||||
return NextResponse.json({ fileRoles: await saveFileRoleStyles(fileRoles) });
|
||||
} catch (err) {
|
||||
if (err instanceof SettingsError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
import { apiError, handleApiError } from "@/lib/api-errors";
|
||||
import { deleteTag, TagError, updateTag } from "@/lib/tags";
|
||||
|
||||
const Body = z.object({ name: z.string().optional(), color: z.string().nullable().optional() });
|
||||
|
||||
/** Rename a tag and/or change its color (null = automatic). */
|
||||
export const PATCH = withAuth<RouteContext<"/api/tags/[id]">>(async (req, { params }) => {
|
||||
const { id } = await params;
|
||||
try {
|
||||
return NextResponse.json(await updateTag(id, Body.parse(await req.json())));
|
||||
} catch (err) {
|
||||
if (err instanceof TagError) return apiError(err.status, err.code, err.message);
|
||||
return handleApiError(err);
|
||||
}
|
||||
});
|
||||
|
||||
/** Delete a tag everywhere. */
|
||||
export const DELETE = withAuth<RouteContext<"/api/tags/[id]">>(async (_req, { params }) => {
|
||||
const { id } = await params;
|
||||
await deleteTag(id);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { z } from "zod";
|
||||
import { withAuth } from "@/lib/api-auth";
|
||||
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);
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
@import "tailwindcss";
|
||||
@import "tw-animate-css";
|
||||
@import "shadcn/tailwind.css";
|
||||
@plugin "@tailwindcss/typography";
|
||||
|
||||
@custom-variant dark (&:is(.dark *));
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
||||
<defs>
|
||||
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#7c5cff"/>
|
||||
<stop offset="1" stop-color="#14b8a6"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="64" height="64" rx="14" fill="url(#g)"/>
|
||||
<text x="32" y="45" text-anchor="middle" font-size="38" font-weight="700" fill="#fff"
|
||||
font-family="'Yu Gothic','Meiryo','Noto Sans JP','Hiragino Sans',sans-serif">要</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 497 B |
+1
-1
@@ -9,7 +9,7 @@ const geist = Geist({ subsets: ["latin"], variable: "--font-sans" });
|
||||
const geistMono = Geist_Mono({ subsets: ["latin"], variable: "--font-mono" });
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Model Manager",
|
||||
title: { default: "Kaname", template: "%s · Kaname" },
|
||||
description: "Download and manage local LLMs from Hugging Face",
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ export default async function LoginPage({ searchParams }: PageProps<"/login">) {
|
||||
<main className="flex min-h-screen items-center justify-center p-4">
|
||||
<Card className="w-full max-w-sm">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">Model Manager</CardTitle>
|
||||
<CardTitle className="text-lg">Kaname</CardTitle>
|
||||
<CardDescription>Sign in to manage local models.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col gap-3">
|
||||
|
||||
@@ -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,24 @@
|
||||
"use client";
|
||||
|
||||
import { CheckIcon, CopyIcon } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
export function CopyButton({ value, label = "Copy" }: { value: string; label?: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-xs"
|
||||
aria-label={label}
|
||||
title={label}
|
||||
onClick={async () => {
|
||||
await navigator.clipboard.writeText(value);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 1500);
|
||||
}}
|
||||
>
|
||||
{copied ? <CheckIcon /> : <CopyIcon />}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { FileRoleBadge } from "@/components/labels";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { groupJobFiles } from "@/lib/file-groups";
|
||||
import { formatBytes, percent } from "@/lib/format";
|
||||
import type { JobFileSnapshot } from "@/lib/jobs";
|
||||
|
||||
/** Per-file progress of one job. */
|
||||
/** Per-file progress of one job (split files as one entry). */
|
||||
export function JobFilesTable({ files }: { files: JobFileSnapshot[] }) {
|
||||
return (
|
||||
<Table>
|
||||
@@ -15,16 +17,26 @@ export function JobFilesTable({ files }: { files: JobFileSnapshot[] }) {
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{files.map((f) => {
|
||||
{groupJobFiles(files).map((f) => {
|
||||
const pct = percent(f.doneBytes, f.expectedBytes);
|
||||
return (
|
||||
<TableRow key={f.modelFileId}>
|
||||
<TableCell className="font-mono text-xs break-all whitespace-normal">{f.path}</TableCell>
|
||||
<TableRow key={f.path}>
|
||||
<TableCell className="whitespace-normal">
|
||||
<span className="flex items-center gap-2">
|
||||
<FileRoleBadge path={f.path} />
|
||||
<span className="font-mono text-xs break-all">{f.path}</span>
|
||||
{f.parts > 1 && (
|
||||
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">
|
||||
{f.parts} parts
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex items-center gap-2">
|
||||
<Progress value={pct} className="flex-1" />
|
||||
<span className="w-12 text-right text-xs text-muted-foreground tabular-nums">
|
||||
{f.state === "failed" ? "missing" : `${pct.toFixed(0)}%`}
|
||||
{f.failed ? "missing" : `${pct.toFixed(0)}%`}
|
||||
</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext } from "react";
|
||||
import { BADGE_CLASS } from "@/lib/colors";
|
||||
import { FILE_ROLES, fileRole, type FileRole, type FileRoleStyles } from "@/lib/file-roles";
|
||||
import { DEFAULT_RECOMMENDED_ROLES } from "@/lib/recommend";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const defaults = Object.fromEntries(
|
||||
Object.entries(FILE_ROLES).map(([role, r]) => [role, { label: r.label, color: r.color }]),
|
||||
) as FileRoleStyles;
|
||||
|
||||
const LabelContext = createContext<FileRoleStyles>(defaults);
|
||||
const RecommendedContext = createContext<FileRole[]>(DEFAULT_RECOMMENDED_ROLES);
|
||||
|
||||
/** Provides file label and download settings (from the Settings page) to client components. */
|
||||
export function LabelSettingsProvider({
|
||||
fileRoles,
|
||||
recommendedRoles,
|
||||
children,
|
||||
}: {
|
||||
fileRoles: FileRoleStyles;
|
||||
recommendedRoles: FileRole[];
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<LabelContext.Provider value={fileRoles}>
|
||||
<RecommendedContext.Provider value={recommendedRoles}>{children}</RecommendedContext.Provider>
|
||||
</LabelContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useFileRoleStyles(): FileRoleStyles {
|
||||
return useContext(LabelContext);
|
||||
}
|
||||
|
||||
/** File kinds picked automatically along with model weights. */
|
||||
export function useRecommendedRoles(): FileRole[] {
|
||||
return useContext(RecommendedContext);
|
||||
}
|
||||
|
||||
/** Label in front of a file name telling what the file is (Model, MTP, Vision, …). */
|
||||
export function FileRoleBadge({ path, className }: { path: string; className?: string }) {
|
||||
const styles = useFileRoleStyles();
|
||||
const role = fileRole(path);
|
||||
const style = styles[role];
|
||||
return (
|
||||
<span
|
||||
title={FILE_ROLES[role].description}
|
||||
className={cn(
|
||||
"inline-flex h-5 min-w-16 shrink-0 items-center justify-center rounded-md border px-1.5 text-[11px] font-medium whitespace-nowrap",
|
||||
BADGE_CLASS[style.color],
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{style.label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { ModelStatus } from "@/lib/db/schema";
|
||||
|
||||
const LABELS: Record<ModelStatus, { label: string; variant: "default" | "secondary" | "destructive" | "outline" }> = {
|
||||
export const MODEL_STATUS: Record<ModelStatus, { label: string; variant: "default" | "secondary" | "destructive" | "outline" }> = {
|
||||
pending: { label: "not downloaded", variant: "outline" },
|
||||
downloading: { label: "downloading", variant: "secondary" },
|
||||
ready: { label: "ok", variant: "default" },
|
||||
@@ -11,6 +11,6 @@ const LABELS: Record<ModelStatus, { label: string; variant: "default" | "seconda
|
||||
};
|
||||
|
||||
export function ModelStatusBadge({ status }: { status: ModelStatus }) {
|
||||
const { label, variant } = LABELS[status];
|
||||
const { label, variant } = MODEL_STATUS[status];
|
||||
return <Badge variant={variant}>{label}</Badge>;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
"use client";
|
||||
|
||||
import { SparklesIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { FileRoleBadge } from "@/components/labels";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { groupSplitFiles } from "@/lib/file-groups";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** Companion files picked along with the chosen quant; each can be unchecked. */
|
||||
export function RecommendedStrip({
|
||||
files,
|
||||
paths,
|
||||
active,
|
||||
onToggle,
|
||||
className,
|
||||
}: {
|
||||
files: { path: string; size: number }[];
|
||||
/** All recommended paths (checked or not). */
|
||||
paths: string[];
|
||||
active: Set<string>;
|
||||
onToggle: (paths: string[], on: boolean) => void;
|
||||
className?: string;
|
||||
}) {
|
||||
if (paths.length === 0) return null;
|
||||
const wanted = new Set(paths);
|
||||
const entries = groupSplitFiles(files.filter((f) => wanted.has(f.path)));
|
||||
|
||||
return (
|
||||
<div className={cn("flex flex-col gap-2 rounded-lg bg-muted/50 px-3 py-2.5 ring-1 ring-foreground/5", className)}>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground">
|
||||
<span className="flex items-center gap-1.5 font-medium text-foreground">
|
||||
<SparklesIcon className="size-3.5 text-amber-500" />
|
||||
Recommended with your quant
|
||||
</span>
|
||||
<Link href="/settings/downloads" className="hover:text-foreground hover:underline">
|
||||
Change in Settings
|
||||
</Link>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{entries.map((e) => {
|
||||
const parts = e.parts.map((p) => p.path);
|
||||
const on = parts.every((p) => active.has(p));
|
||||
return (
|
||||
<label
|
||||
key={e.path}
|
||||
className={cn(
|
||||
"flex cursor-pointer items-center gap-2 rounded-md border bg-background px-2 py-1 text-xs transition-opacity",
|
||||
!on && "opacity-60",
|
||||
)}
|
||||
>
|
||||
<Checkbox checked={on} onCheckedChange={(v) => onToggle(parts, v === true)} aria-label={`Download ${e.path}`} />
|
||||
<FileRoleBadge path={e.path} />
|
||||
<span className="font-mono break-all">{e.path}</span>
|
||||
<span className="text-muted-foreground tabular-nums">{formatBytes(e.size)}</span>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { autoTagColor, BADGE_CLASS, DOT_CLASS, isLabelColor, type LabelColor } from "@/lib/colors";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
/** The tag's chosen color, or a stable automatic one derived from its name. */
|
||||
export function tagColor(name: string, color?: string | null): LabelColor {
|
||||
return isLabelColor(color) ? color : autoTagColor(name);
|
||||
}
|
||||
|
||||
/** Small colored dot for a tag (e.g. in filter menus). */
|
||||
export function TagDot({ name, color }: { name: string; color?: string | null }) {
|
||||
return <span className={cn("inline-block size-2 shrink-0 rounded-full", DOT_CLASS[tagColor(name, color)])} />;
|
||||
}
|
||||
|
||||
/** A user tag, in its color. */
|
||||
export function TagBadge({
|
||||
name,
|
||||
color,
|
||||
className,
|
||||
children,
|
||||
}: {
|
||||
name: string;
|
||||
color?: string | null;
|
||||
className?: string;
|
||||
children?: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex h-5 items-center gap-1 rounded-full border px-2 text-xs font-medium whitespace-nowrap",
|
||||
BADGE_CLASS[tagColor(name, color)],
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{name}
|
||||
{children}
|
||||
</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>
|
||||
);
|
||||
}
|
||||
@@ -7,11 +7,15 @@ function Progress({
|
||||
className,
|
||||
children,
|
||||
value,
|
||||
// Fixed locale: the default (runtime locale) formats aria-valuetext differently on the server
|
||||
// and in e.g. a German browser ("50%" vs "50 %"), which breaks hydration.
|
||||
locale = "en-US",
|
||||
...props
|
||||
}: ProgressPrimitive.Root.Props) {
|
||||
return (
|
||||
<ProgressPrimitive.Root
|
||||
value={value}
|
||||
locale={locale}
|
||||
data-slot="progress"
|
||||
className={cn("flex flex-wrap gap-3", className)}
|
||||
{...props}
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { useRecommendedRoles } from "@/components/labels";
|
||||
import { modelFilePaths, recommendFiles } from "@/lib/recommend";
|
||||
|
||||
/**
|
||||
* Companion files (template, MTP, mmproj, …) for the model weights in `picked`, per the
|
||||
* "Recommended files" setting. They count as selected unless the user unchecked them (`dismissed`),
|
||||
* and drop out by themselves when the model file they belong to is deselected.
|
||||
*/
|
||||
export function useRecommended(
|
||||
files: { path: string; size: number }[],
|
||||
picked: Iterable<string>,
|
||||
options: { isExcluded?: (path: string) => boolean; have?: string[] } = {},
|
||||
) {
|
||||
const { isExcluded, have } = options;
|
||||
const roles = useRecommendedRoles();
|
||||
const [dismissed, setDismissed] = useState<Set<string>>(new Set());
|
||||
const pickedList = useMemo(() => [...picked], [picked]);
|
||||
|
||||
const all = useMemo(() => {
|
||||
const already = new Set(pickedList);
|
||||
return recommendFiles(files, modelFilePaths(pickedList), roles, [...pickedList, ...(have ?? [])]).filter(
|
||||
(p) => !already.has(p) && !isExcluded?.(p),
|
||||
);
|
||||
}, [files, pickedList, roles, isExcluded, have]);
|
||||
const active = useMemo(() => new Set(all.filter((p) => !dismissed.has(p))), [all, dismissed]);
|
||||
|
||||
/** Check or uncheck recommended paths (unchecking remembers the choice). */
|
||||
function setOn(paths: string[], on: boolean) {
|
||||
setDismissed((prev) => {
|
||||
const next = new Set(prev);
|
||||
for (const p of paths) {
|
||||
if (on) next.delete(p);
|
||||
else next.add(p);
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
return { all, active, setOn, reset: () => setDismissed(new Set()) };
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Named label colors. Class strings are spelled out in full so Tailwind generates them.
|
||||
|
||||
export const LABEL_COLORS = [
|
||||
"gray",
|
||||
"red",
|
||||
"orange",
|
||||
"amber",
|
||||
"yellow",
|
||||
"lime",
|
||||
"green",
|
||||
"emerald",
|
||||
"teal",
|
||||
"cyan",
|
||||
"sky",
|
||||
"blue",
|
||||
"indigo",
|
||||
"violet",
|
||||
"purple",
|
||||
"fuchsia",
|
||||
"pink",
|
||||
"rose",
|
||||
] as const;
|
||||
export type LabelColor = (typeof LABEL_COLORS)[number];
|
||||
|
||||
export function isLabelColor(v: unknown): v is LabelColor {
|
||||
return typeof v === "string" && (LABEL_COLORS as readonly string[]).includes(v);
|
||||
}
|
||||
|
||||
/** Pill: border + tinted background + readable text in both themes. */
|
||||
export const BADGE_CLASS: Record<LabelColor, string> = {
|
||||
gray: "border-zinc-500/30 bg-zinc-500/10 text-zinc-700 dark:text-zinc-300",
|
||||
red: "border-red-500/30 bg-red-500/10 text-red-700 dark:text-red-300",
|
||||
orange: "border-orange-500/30 bg-orange-500/10 text-orange-700 dark:text-orange-300",
|
||||
amber: "border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300",
|
||||
yellow: "border-yellow-500/30 bg-yellow-500/10 text-yellow-700 dark:text-yellow-300",
|
||||
lime: "border-lime-500/30 bg-lime-500/10 text-lime-700 dark:text-lime-300",
|
||||
green: "border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300",
|
||||
emerald: "border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300",
|
||||
teal: "border-teal-500/30 bg-teal-500/10 text-teal-700 dark:text-teal-300",
|
||||
cyan: "border-cyan-500/30 bg-cyan-500/10 text-cyan-700 dark:text-cyan-300",
|
||||
sky: "border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",
|
||||
blue: "border-blue-500/30 bg-blue-500/10 text-blue-700 dark:text-blue-300",
|
||||
indigo: "border-indigo-500/30 bg-indigo-500/10 text-indigo-700 dark:text-indigo-300",
|
||||
violet: "border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",
|
||||
purple: "border-purple-500/30 bg-purple-500/10 text-purple-700 dark:text-purple-300",
|
||||
fuchsia: "border-fuchsia-500/30 bg-fuchsia-500/10 text-fuchsia-700 dark:text-fuchsia-300",
|
||||
pink: "border-pink-500/30 bg-pink-500/10 text-pink-700 dark:text-pink-300",
|
||||
rose: "border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-300",
|
||||
};
|
||||
|
||||
export const DOT_CLASS: Record<LabelColor, string> = {
|
||||
gray: "bg-zinc-500",
|
||||
red: "bg-red-500",
|
||||
orange: "bg-orange-500",
|
||||
amber: "bg-amber-500",
|
||||
yellow: "bg-yellow-500",
|
||||
lime: "bg-lime-500",
|
||||
green: "bg-green-500",
|
||||
emerald: "bg-emerald-500",
|
||||
teal: "bg-teal-500",
|
||||
cyan: "bg-cyan-500",
|
||||
sky: "bg-sky-500",
|
||||
blue: "bg-blue-500",
|
||||
indigo: "bg-indigo-500",
|
||||
violet: "bg-violet-500",
|
||||
purple: "bg-purple-500",
|
||||
fuchsia: "bg-fuchsia-500",
|
||||
pink: "bg-pink-500",
|
||||
rose: "bg-rose-500",
|
||||
};
|
||||
|
||||
/** Colors used for tags that have no color set: picked from the name so they stay stable. */
|
||||
const AUTO_TAG_COLORS: LabelColor[] = ["sky", "emerald", "amber", "rose", "violet", "cyan", "lime", "orange", "fuchsia", "teal"];
|
||||
|
||||
export function autoTagColor(name: string): LabelColor {
|
||||
let h = 0;
|
||||
for (const ch of name.trim().toLowerCase()) h = (h * 31 + ch.codePointAt(0)!) >>> 0;
|
||||
return AUTO_TAG_COLORS[h % AUTO_TAG_COLORS.length];
|
||||
}
|
||||
+84
-1
@@ -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,14 +77,65 @@ 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.
|
||||
/** e.g. ["Qwen/Qwen3-8B"] (cardData.base_model, or base_model:* tags). */
|
||||
baseModels: text("base_models", { mode: "json" }).$type<string[]>(),
|
||||
/** How this model derives from its base: "quantized", "finetune", "adapter", "merge". */
|
||||
baseRelation: text("base_relation"),
|
||||
/** Avatar of the repo's org/user on the Hub. */
|
||||
authorAvatarUrl: text("author_avatar_url"),
|
||||
/** e.g. "qwen3" (gguf.architecture or config.model_type). */
|
||||
architecture: text("architecture"),
|
||||
pipelineTag: text("pipeline_tag"),
|
||||
license: text("license"),
|
||||
/** Hub tags, minus noise like arxiv:/region:/deploy:. */
|
||||
hubTags: text("hub_tags", { mode: "json" }).$type<string[]>(),
|
||||
metadataFetchedAt: ts("metadata_fetched_at"),
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [uniqueIndex("models_repo_uq").on(t.repoType, t.repoId)],
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// User tags (e.g. "roleplay", "security")
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const tags = sqliteTable(
|
||||
"tags",
|
||||
{
|
||||
id: id(),
|
||||
/** Display name as entered. */
|
||||
name: text("name").notNull(),
|
||||
/** Lowercased, trimmed name; unique. */
|
||||
slug: text("slug").notNull(),
|
||||
/** One of LABEL_COLORS; null = automatic color derived from the name. */
|
||||
color: text("color"),
|
||||
createdAt: createdAt(),
|
||||
},
|
||||
(t) => [uniqueIndex("tags_slug_uq").on(t.slug)],
|
||||
);
|
||||
|
||||
export const modelTags = sqliteTable(
|
||||
"model_tags",
|
||||
{
|
||||
modelId: text("model_id")
|
||||
.notNull()
|
||||
.references(() => models.id),
|
||||
tagId: text("tag_id")
|
||||
.notNull()
|
||||
.references(() => tags.id),
|
||||
createdAt: createdAt(),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.modelId, t.tagId] }), index("model_tags_tag_idx").on(t.tagId)],
|
||||
);
|
||||
|
||||
/** History of SHAs a model has been pinned to. */
|
||||
export const modelRevisions = sqliteTable(
|
||||
"model_revisions",
|
||||
@@ -138,7 +193,7 @@ export const modelFiles = sqliteTable(
|
||||
export const JOB_KINDS = ["download", "verify", "deep_verify"] as const;
|
||||
export type JobKind = (typeof JOB_KINDS)[number];
|
||||
|
||||
export const JOB_PURPOSES = ["initial", "repair", "update"] as const;
|
||||
export const JOB_PURPOSES = ["initial", "add", "import", "repair", "update"] as const;
|
||||
export type JobPurpose = (typeof JOB_PURPOSES)[number];
|
||||
|
||||
export const JOB_STATES = [
|
||||
@@ -233,6 +288,16 @@ export const jobLogs = sqliteTable(
|
||||
(t) => [index("job_logs_job_idx").on(t.jobId, t.id)],
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// App settings (key/value, edited on the Settings page)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const settings = sqliteTable("settings", {
|
||||
key: text("key").primaryKey(),
|
||||
value: text("value", { mode: "json" }).notNull(),
|
||||
updatedAt: updatedAt(),
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Worker liveness
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -248,4 +313,22 @@ export const workerState = sqliteTable("worker_state", {
|
||||
modelsDirTotalBytes: integer("models_dir_total_bytes"),
|
||||
startedAt: ts("started_at").notNull(),
|
||||
heartbeatAt: ts("heartbeat_at").notNull(),
|
||||
/** Set by the web app ("Rescan"); the worker scans MODELS_DIR when this is newer than its last scan. */
|
||||
scanRequestedAt: ts("scan_requested_at"),
|
||||
});
|
||||
|
||||
/**
|
||||
* Folders in MODELS_DIR (`<org>/<name>`, like `hf download --local-dir` layouts) that no model uses,
|
||||
* found by the worker's scan. Rewritten on every scan; the web app offers them for import.
|
||||
*/
|
||||
export const localFolders = sqliteTable("local_folders", {
|
||||
/** Relative to MODELS_DIR, e.g. "unsloth/Qwen3-8B-GGUF". */
|
||||
path: text("path").primaryKey(),
|
||||
/** Files in the folder (without hf's .cache), capped. */
|
||||
files: text("files", { mode: "json" }).$type<{ path: string; size: number }[]>().notNull(),
|
||||
fileCount: integer("file_count").notNull(),
|
||||
totalBytes: integer("total_bytes").notNull(),
|
||||
/** Commit from hf's download metadata, if the folder was written by `hf download`. */
|
||||
commit: text("commit"),
|
||||
scannedAt: ts("scanned_at").notNull(),
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
// Group split files ("model-00001-of-00003.gguf", …) into one entry for display and selection.
|
||||
|
||||
const SPLIT = /^(.*)-(\d{5})-of-(\d{5})(\.[^./]+)$/;
|
||||
|
||||
export type SplitInfo = { base: string; part: number; total: number };
|
||||
|
||||
/** "BF16/X-BF16-00001-of-00002.gguf" → { base: "BF16/X-BF16.gguf", part: 1, total: 2 }. */
|
||||
export function splitInfo(path: string): SplitInfo | null {
|
||||
const m = path.match(SPLIT);
|
||||
if (!m) return null;
|
||||
return { base: `${m[1]}${m[4]}`, part: Number(m[2]), total: Number(m[3]) };
|
||||
}
|
||||
|
||||
export type FileGroup<T> = {
|
||||
/** Display path: the file itself, or the shared name of a split file without the part suffix. */
|
||||
path: string;
|
||||
/** Files in this entry, in part order. */
|
||||
parts: T[];
|
||||
size: number;
|
||||
/** Number of parts the split file has in total (1 for normal files). */
|
||||
totalParts: number;
|
||||
};
|
||||
|
||||
/** Merge split parts into one entry; other files stay as they are. Keeps first-seen order. */
|
||||
export function groupSplitFiles<T extends { path: string; size: number }>(files: T[]): FileGroup<T>[] {
|
||||
const groups: FileGroup<T>[] = [];
|
||||
const byBase = new Map<string, FileGroup<T>>();
|
||||
for (const f of files) {
|
||||
const info = splitInfo(f.path);
|
||||
if (!info) {
|
||||
groups.push({ path: f.path, parts: [f], size: f.size, totalParts: 1 });
|
||||
continue;
|
||||
}
|
||||
const key = `${info.base}#${info.total}`;
|
||||
let g = byBase.get(key);
|
||||
if (!g) {
|
||||
g = { path: info.base, parts: [], size: 0, totalParts: info.total };
|
||||
byBase.set(key, g);
|
||||
groups.push(g);
|
||||
}
|
||||
g.parts.push(f);
|
||||
g.size += f.size;
|
||||
}
|
||||
for (const g of groups) {
|
||||
if (g.parts.length > 1) g.parts.sort((a, b) => (splitInfo(a.path)?.part ?? 0) - (splitInfo(b.path)?.part ?? 0));
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
export type JobFileEntry = { path: string; expectedBytes: number; doneBytes: number; failed: boolean; parts: number };
|
||||
|
||||
/** Job progress per entry: split parts summed into one line. */
|
||||
export function groupJobFiles(files: { path: string; expectedBytes: number; doneBytes: number; state: string }[]): JobFileEntry[] {
|
||||
return groupSplitFiles(files.map((f) => ({ ...f, size: f.expectedBytes }))).map((g) => ({
|
||||
path: g.path,
|
||||
expectedBytes: g.size,
|
||||
doneBytes: g.parts.reduce((s, p) => s + p.doneBytes, 0),
|
||||
failed: g.parts.some((p) => p.state === "failed"),
|
||||
parts: g.totalParts,
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// What a file in a model repo is for, guessed from its path. Shared by UI and server.
|
||||
|
||||
import type { LabelColor } from "./colors";
|
||||
|
||||
export type FileRole =
|
||||
| "model"
|
||||
| "mtp"
|
||||
| "vision"
|
||||
| "draft"
|
||||
| "adapter"
|
||||
| "imatrix"
|
||||
| "config"
|
||||
| "tokenizer"
|
||||
| "template"
|
||||
| "docs"
|
||||
| "image"
|
||||
| "git"
|
||||
| "other";
|
||||
|
||||
/** Defaults; label and color can be changed in Settings. */
|
||||
export const FILE_ROLES: Record<FileRole, { label: string; color: LabelColor; description: string }> = {
|
||||
model: { label: "Model", color: "indigo", description: "Model weights" },
|
||||
mtp: { label: "MTP", color: "amber", description: "Multi-token prediction head (speculative decoding draft)" },
|
||||
vision: { label: "Vision", color: "fuchsia", description: "Multimodal projector (mmproj) for image input" },
|
||||
draft: { label: "Draft", color: "orange", description: "Draft model for speculative decoding" },
|
||||
adapter: { label: "Adapter", color: "violet", description: "LoRA / adapter weights" },
|
||||
imatrix: { label: "imatrix", color: "gray", description: "Importance matrix used to make the quants; not needed to run the model" },
|
||||
config: { label: "Config", color: "sky", description: "Model or generation config" },
|
||||
tokenizer: { label: "Tokenizer", color: "teal", description: "Tokenizer / vocabulary" },
|
||||
template: { label: "Template", color: "cyan", description: "Chat template" },
|
||||
docs: { label: "Docs", color: "gray", description: "Documentation or license" },
|
||||
image: { label: "Image", color: "pink", description: "Image (e.g. for the model card)" },
|
||||
git: { label: "Git", color: "gray", description: "Git metadata" },
|
||||
other: { label: "Other", color: "gray", description: "Other file" },
|
||||
};
|
||||
|
||||
export const FILE_ROLE_ORDER = Object.keys(FILE_ROLES) as FileRole[];
|
||||
|
||||
export type FileRoleStyle = { label: string; color: LabelColor };
|
||||
export type FileRoleStyles = Record<FileRole, FileRoleStyle>;
|
||||
|
||||
const WEIGHTS = /\.(gguf|safetensors|bin|pt|pth|ckpt|onnx|ggml|mlmodel|npz|h5)$/i;
|
||||
|
||||
export function fileRole(path: string): FileRole {
|
||||
const lower = path.toLowerCase();
|
||||
const name = lower.slice(lower.lastIndexOf("/") + 1);
|
||||
const dirs = lower.split("/").slice(0, -1);
|
||||
|
||||
if (name.startsWith(".git")) return "git";
|
||||
if (name.includes("imatrix")) return "imatrix";
|
||||
if (name.includes("mmproj") || dirs.includes("mmproj")) return "vision";
|
||||
if (name.startsWith("mtp-") || name.startsWith("mtp_") || dirs.includes("mtp")) return "mtp";
|
||||
if (WEIGHTS.test(name)) {
|
||||
if (name.includes("adapter")) return "adapter";
|
||||
if (/(^|[-_.])draft([-_.]|$)/.test(name)) return "draft";
|
||||
return "model";
|
||||
}
|
||||
if (/^tokenizer|^vocab|^merges\.txt$|^special_tokens_map\.json$|^added_tokens\.json$|\.tiktoken$|^tokenizer\.model$/.test(name)) {
|
||||
return "tokenizer";
|
||||
}
|
||||
if (name.endsWith(".jinja") || name.includes("chat_template") || name === "template") return "template";
|
||||
if (name.endsWith(".json") || name === "params" || name.endsWith(".yaml") || name.endsWith(".yml")) return "config";
|
||||
if (/\.(md|txt|rst)$/.test(name) || name.startsWith("license") || name.startsWith("notice")) return "docs";
|
||||
if (/\.(png|jpe?g|gif|webp|svg)$/.test(name)) return "image";
|
||||
return "other";
|
||||
}
|
||||
@@ -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),
|
||||
});
|
||||
}
|
||||
+46
-1
@@ -2,6 +2,7 @@
|
||||
// Server-side only: it reads HF_TOKEN from the environment. Never import from client components.
|
||||
|
||||
import { coreEnv } from "@/lib/env";
|
||||
import { parseRepoMetadata, type RepoMetadata } from "./metadata";
|
||||
|
||||
const HUB = "https://huggingface.co";
|
||||
const TIMEOUT_MS = 20_000;
|
||||
@@ -48,6 +49,7 @@ export type RepoInfo = {
|
||||
gated: false | "auto" | "manual";
|
||||
private: boolean;
|
||||
lastModified: string | null;
|
||||
metadata: RepoMetadata;
|
||||
};
|
||||
|
||||
function headers(): HeadersInit {
|
||||
@@ -138,13 +140,14 @@ export async function getRepoInfo(repoId: string, revision: string): Promise<Rep
|
||||
gated?: false | "auto" | "manual";
|
||||
private?: boolean;
|
||||
lastModified?: string;
|
||||
};
|
||||
} & Parameters<typeof parseRepoMetadata>[0];
|
||||
return {
|
||||
repoId: j.id ?? repoId,
|
||||
sha: j.sha,
|
||||
gated: j.gated ?? false,
|
||||
private: j.private ?? false,
|
||||
lastModified: j.lastModified ?? null,
|
||||
metadata: parseRepoMetadata(j),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -190,6 +193,21 @@ function nextLink(link: string | null): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Avatar URL of a Hub org or user, or null. Best effort: errors are swallowed. */
|
||||
export async function getAuthorAvatar(name: string): Promise<string | null> {
|
||||
for (const path of [`organizations/${enc(name)}/avatar`, `users/${enc(name)}/overview`]) {
|
||||
try {
|
||||
const res = await hubFetch(`${HUB}/api/${path}`);
|
||||
if (!res.ok) continue;
|
||||
const j = (await res.json()) as { avatarUrl?: string };
|
||||
if (j.avatarUrl?.startsWith("https://")) return j.avatarUrl;
|
||||
} catch {
|
||||
// ignore, try next
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* For gated repos the file list is public, but downloads need accepted terms.
|
||||
* Probe one file with a HEAD request (no body is downloaded) to find out early.
|
||||
@@ -200,3 +218,30 @@ export async function checkFileAccess(repoId: string, sha: string, path: string)
|
||||
if (res.ok || (res.status >= 300 && res.status < 400)) return;
|
||||
throw await toHubError(res, repoId, sha);
|
||||
}
|
||||
|
||||
const cardCache = new Map<string, string | null>();
|
||||
const CARD_CACHE_MAX = 100;
|
||||
const CARD_MAX_BYTES = 512 * 1024;
|
||||
|
||||
/**
|
||||
* The repo's README.md at a commit, without YAML front matter. Null if there is none.
|
||||
* Cached in memory: a commit's content never changes.
|
||||
*/
|
||||
export async function fetchModelCard(repoId: string, sha: string): Promise<string | null> {
|
||||
assertRepoId(repoId);
|
||||
const key = `${repoId}@${sha}`;
|
||||
if (cardCache.has(key)) return cardCache.get(key)!;
|
||||
|
||||
const res = await hubFetch(`${HUB}/${repoPath(repoId)}/raw/${enc(sha)}/README.md`);
|
||||
if (res.status === 404) {
|
||||
cardCache.set(key, null);
|
||||
return null;
|
||||
}
|
||||
if (!res.ok) throw await toHubError(res, repoId, sha);
|
||||
let text = (await res.text()).slice(0, CARD_MAX_BYTES);
|
||||
text = text.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, "").trim();
|
||||
|
||||
if (cardCache.size >= CARD_CACHE_MAX) cardCache.delete(cardCache.keys().next().value!);
|
||||
cardCache.set(key, text || null);
|
||||
return text || null;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Pure helpers that turn Hub model info into searchable metadata. Shared by web and worker.
|
||||
|
||||
export type RepoMetadata = {
|
||||
author: string | null;
|
||||
baseModels: string[];
|
||||
/** "quantized", "finetune", "adapter", "merge" (from base_model:<relation>:<id> tags). */
|
||||
baseRelation: string | null;
|
||||
architecture: string | null;
|
||||
pipelineTag: string | null;
|
||||
license: string | null;
|
||||
hubTags: string[];
|
||||
};
|
||||
|
||||
type HubModelInfo = {
|
||||
id?: string;
|
||||
author?: string;
|
||||
pipeline_tag?: string;
|
||||
tags?: string[];
|
||||
cardData?: { base_model?: string | string[]; license?: string | string[] } | null;
|
||||
gguf?: { architecture?: string } | null;
|
||||
config?: { model_type?: string } | null;
|
||||
};
|
||||
|
||||
/** Hub tags that carry no useful search signal (or are stored separately). */
|
||||
const NOISE_TAG = /^(arxiv|region|deploy|base_model|license|doi|dataset):|^(endpoints_compatible|autotrain_compatible|eval-results|text-generation-inference|conversational)$/;
|
||||
|
||||
const asArray = (v: string | string[] | undefined | null): string[] =>
|
||||
v == null ? [] : (Array.isArray(v) ? v : [v]).filter((x): x is string => typeof x === "string" && x.length > 0);
|
||||
|
||||
export function parseRepoMetadata(info: HubModelInfo): RepoMetadata {
|
||||
const tags = info.tags ?? [];
|
||||
|
||||
// Prefer the model card; fall back to "base_model:<relation>:<id>" / "base_model:<id>" tags.
|
||||
let baseModels = asArray(info.cardData?.base_model);
|
||||
if (baseModels.length === 0) {
|
||||
baseModels = tags
|
||||
.filter((t) => t.startsWith("base_model:"))
|
||||
.map((t) => t.split(":").at(-1)!)
|
||||
.filter((id) => id.includes("/"));
|
||||
}
|
||||
|
||||
const relation = tags.map((t) => t.match(/^base_model:([a-z_]+):/)?.[1]).find(Boolean) ?? null;
|
||||
|
||||
const license = asArray(info.cardData?.license)[0] ?? tags.find((t) => t.startsWith("license:"))?.slice(8) ?? null;
|
||||
|
||||
return {
|
||||
author: info.author ?? info.id?.split("/")[0] ?? null,
|
||||
baseModels: [...new Set(baseModels)],
|
||||
baseRelation: baseModels.length > 0 ? relation : null,
|
||||
architecture: info.gguf?.architecture ?? info.config?.model_type ?? null,
|
||||
pipelineTag: info.pipeline_tag ?? null,
|
||||
license,
|
||||
hubTags: [...new Set(tags.filter((t) => !NOISE_TAG.test(t)))],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The model "family" for filtering: the org of the base model(s) (unsloth/Qwen3-8B-GGUF → "Qwen"),
|
||||
* or the repo's own org for original models without a base model.
|
||||
*/
|
||||
export function modelFamilies(repoId: string, baseModels: string[] | null | undefined): string[] {
|
||||
const orgs = (baseModels ?? []).map((b) => b.split("/")[0]).filter(Boolean);
|
||||
return orgs.length > 0 ? [...new Set(orgs)] : [repoId.split("/")[0]];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { eq, isNull } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { models } from "@/lib/db/schema";
|
||||
import { getAuthorAvatar, getRepoInfo } from "./client";
|
||||
import type { RepoMetadata } from "./metadata";
|
||||
|
||||
/** Columns to write on `models` for fetched Hub metadata. */
|
||||
export function metadataColumns(meta: RepoMetadata, authorAvatarUrl: string | null) {
|
||||
return {
|
||||
baseModels: meta.baseModels,
|
||||
baseRelation: meta.baseRelation,
|
||||
authorAvatarUrl,
|
||||
architecture: meta.architecture,
|
||||
pipelineTag: meta.pipelineTag,
|
||||
license: meta.license,
|
||||
hubTags: meta.hubTags,
|
||||
metadataFetchedAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch Hub metadata for models that don't have it yet (added before metadata existed).
|
||||
* Returns how many were updated; failures are reported but don't stop the others.
|
||||
*/
|
||||
export async function backfillMetadata(onError: (repoId: string, err: unknown) => void): Promise<number> {
|
||||
const missing = await db()
|
||||
.select({ id: models.id, repoId: models.repoId, pinnedSha: models.pinnedSha })
|
||||
.from(models)
|
||||
.where(isNull(models.metadataFetchedAt));
|
||||
let updated = 0;
|
||||
for (const m of missing) {
|
||||
try {
|
||||
const info = await getRepoInfo(m.repoId, m.pinnedSha);
|
||||
const avatar = await getAuthorAvatar(m.repoId.split("/")[0]);
|
||||
await db().update(models).set(metadataColumns(info.metadata, avatar)).where(eq(models.id, m.id));
|
||||
updated++;
|
||||
} catch (err) {
|
||||
onError(m.repoId, err);
|
||||
}
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
+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 },
|
||||
|
||||
+59
-9
@@ -1,12 +1,15 @@
|
||||
import "server-only";
|
||||
import { and, asc, desc, eq, sql } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { modelFiles, models } from "@/lib/db/schema";
|
||||
import { modelFiles, models, modelTags, tags } from "@/lib/db/schema";
|
||||
import { modelFamilies } from "@/lib/hub/metadata";
|
||||
import { fileRole } from "@/lib/file-roles";
|
||||
import { quantGroup } from "@/lib/selection";
|
||||
import type { Tag } from "@/lib/tags";
|
||||
|
||||
export type LibraryRow = Awaited<ReturnType<typeof listLibrary>>[number];
|
||||
|
||||
/** Models with their selected-file totals and a short "which quant" label. */
|
||||
/** Models with selected-file totals, quant labels, Hub metadata and user tags. */
|
||||
export async function listLibrary() {
|
||||
const d = db();
|
||||
const rows = await d
|
||||
@@ -17,8 +20,14 @@ 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,
|
||||
architecture: models.architecture,
|
||||
pipelineTag: models.pipelineTag,
|
||||
license: models.license,
|
||||
hubTags: models.hubTags,
|
||||
fileCount: sql<number>`count(${modelFiles.id})`,
|
||||
totalBytes: sql<number>`coalesce(sum(${modelFiles.size}), 0)`,
|
||||
})
|
||||
@@ -31,17 +40,25 @@ export async function listLibrary() {
|
||||
.select({ modelId: modelFiles.modelId, path: modelFiles.path })
|
||||
.from(modelFiles)
|
||||
.where(eq(modelFiles.selected, true));
|
||||
const quants = new Map<string, Set<string>>();
|
||||
for (const f of selected) {
|
||||
const g = quantGroup(f.path);
|
||||
if (!g) continue;
|
||||
if (!quants.has(f.modelId)) quants.set(f.modelId, new Set());
|
||||
quants.get(f.modelId)!.add(g);
|
||||
}
|
||||
// Only model weights count as a quant (not MTP heads, mmproj or imatrix files).
|
||||
const quants = groupBy(selected, (f) => f.modelId, (f) => (fileRole(f.path) === "model" ? quantGroup(f.path) : null));
|
||||
|
||||
const tagRows = await d
|
||||
.select({ modelId: modelTags.modelId, id: tags.id, name: tags.name, color: tags.color })
|
||||
.from(modelTags)
|
||||
.innerJoin(tags, eq(tags.id, modelTags.tagId))
|
||||
.orderBy(asc(tags.slug));
|
||||
const tagsByModel = new Map<string, Tag[]>();
|
||||
for (const t of tagRows) tagsByModel.set(t.modelId, [...(tagsByModel.get(t.modelId) ?? []), { id: t.id, name: t.name, color: t.color }]);
|
||||
|
||||
return rows.map((r) => ({
|
||||
...r,
|
||||
author: r.repoId.split("/")[0],
|
||||
families: modelFamilies(r.repoId, r.baseModels),
|
||||
baseModels: r.baseModels ?? [],
|
||||
hubTags: r.hubTags ?? [],
|
||||
quants: [...(quants.get(r.id) ?? [])].sort(),
|
||||
tags: tagsByModel.get(r.id) ?? [],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -56,3 +73,36 @@ export async function getModel(id: string) {
|
||||
.orderBy(asc(modelFiles.path));
|
||||
return { model, files };
|
||||
}
|
||||
|
||||
function groupBy<T>(items: T[], key: (t: T) => string, value: (t: T) => string | null) {
|
||||
const out = new Map<string, Set<string>>();
|
||||
for (const item of items) {
|
||||
const v = value(item);
|
||||
if (v == null) continue;
|
||||
const k = key(item);
|
||||
if (!out.has(k)) out.set(k, new Set());
|
||||
out.get(k)!.add(v);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Look up a model by "org/name" (case-insensitive, like the Hub). */
|
||||
export async function getModelByRepo(repoId: string) {
|
||||
const row = await db()
|
||||
.select({ id: models.id })
|
||||
.from(models)
|
||||
.where(sql`lower(${models.repoId}) = lower(${repoId})`)
|
||||
.limit(1);
|
||||
return row[0] ? getModel(row[0].id) : null;
|
||||
}
|
||||
|
||||
export type RelatedModel = { repoId: string; quants: string[]; status: string };
|
||||
|
||||
/** Other models in the library that share a base model (e.g. another quant of the same Qwen). */
|
||||
export async function relatedModels(modelId: string, baseModels: string[]): Promise<RelatedModel[]> {
|
||||
if (baseModels.length === 0) return [];
|
||||
const all = await listLibrary();
|
||||
return all
|
||||
.filter((m) => m.id !== modelId && m.baseModels.some((b) => baseModels.includes(b)))
|
||||
.map((m) => ({ repoId: m.repoId, quants: m.quants, status: m.status }));
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import "server-only";
|
||||
import { asc, eq, notInArray } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { localFolders, models, workerState } from "@/lib/db/schema";
|
||||
|
||||
export type LocalFolder = typeof localFolders.$inferSelect;
|
||||
|
||||
/** Folders in MODELS_DIR that no model uses (from the worker's last scan). */
|
||||
export async function listLocalFolders(): Promise<LocalFolder[]> {
|
||||
const d = db();
|
||||
return d
|
||||
.select()
|
||||
.from(localFolders)
|
||||
.where(notInArray(localFolders.path, d.select({ p: models.localPath }).from(models)))
|
||||
.orderBy(asc(localFolders.path));
|
||||
}
|
||||
|
||||
export async function getLocalFolder(path: string): Promise<LocalFolder | undefined> {
|
||||
return db().query.localFolders.findFirst({ where: eq(localFolders.path, path) });
|
||||
}
|
||||
|
||||
/** Ask the worker to scan MODELS_DIR now (it picks this up with its next heartbeat). */
|
||||
export async function requestFolderScan(): Promise<void> {
|
||||
await db().update(workerState).set({ scanRequestedAt: new Date() }).where(eq(workerState.id, "worker"));
|
||||
}
|
||||
+60
-6
@@ -1,14 +1,18 @@
|
||||
import "server-only";
|
||||
import { and, eq, sql } from "drizzle-orm";
|
||||
import { and, eq, inArray, sql } from "drizzle-orm";
|
||||
import { ulid } from "ulid";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { jobs, modelFiles, modelRevisions, models } from "@/lib/db/schema";
|
||||
import { checkFileAccess, getRepoInfo, listFiles } from "@/lib/hub/client";
|
||||
import { isSelected, type SelectionRule } from "@/lib/selection";
|
||||
import { jobs, localFolders, 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 { getLocalFolder } from "@/lib/local-folders";
|
||||
import { escapeGlob, isSelected, matchesAny, type SelectionRule } from "@/lib/selection";
|
||||
|
||||
export class ModelError extends Error {
|
||||
constructor(
|
||||
public code: "already_exists" | "empty_selection" | "not_found" | "not_removable",
|
||||
public code: "already_exists" | "empty_selection" | "not_found" | "not_removable" | "busy" | "hub_missing",
|
||||
message: string,
|
||||
public status: number,
|
||||
) {
|
||||
@@ -27,9 +31,17 @@ export async function addModel(input: {
|
||||
revision: string;
|
||||
sha: string;
|
||||
rule: SelectionRule;
|
||||
/** Import: use this existing folder in MODELS_DIR (must be one the worker's scan found). */
|
||||
localPath?: string;
|
||||
}): Promise<{ id: string }> {
|
||||
const info = await getRepoInfo(input.repoId, input.sha);
|
||||
const repoId = info.repoId;
|
||||
const localPath = input.localPath ?? repoId;
|
||||
if (input.localPath && !(await getLocalFolder(input.localPath))) {
|
||||
throw new ModelError("not_found", `Folder ${input.localPath} was not found in the models folder. Rescan and try again.`, 404);
|
||||
}
|
||||
const usedBy = await db().query.models.findFirst({ columns: { repoId: true }, where: eq(models.localPath, localPath) });
|
||||
if (usedBy) throw new ModelError("already_exists", `The folder ${localPath} already belongs to ${usedBy.repoId}.`, 409);
|
||||
|
||||
const existing = await db().query.models.findFirst({
|
||||
columns: { id: true },
|
||||
@@ -64,12 +76,14 @@ export async function addModel(input: {
|
||||
repoId,
|
||||
trackedRevision: input.revision,
|
||||
pinnedSha: info.sha,
|
||||
localPath: repoId,
|
||||
localPath,
|
||||
includePatterns: input.rule.include,
|
||||
excludePatterns: input.rule.exclude,
|
||||
...metadataColumns(info.metadata, await getAuthorAvatar(repoId.split("/")[0])),
|
||||
}),
|
||||
d.insert(modelRevisions).values({ modelId, sha: info.sha }),
|
||||
...chunk(fileRows, INSERT_CHUNK).map((c) => d.insert(modelFiles).values(c)),
|
||||
d.delete(localFolders).where(eq(localFolders.path, localPath)), // no longer an import candidate
|
||||
]);
|
||||
return { id: modelId };
|
||||
}
|
||||
@@ -91,6 +105,7 @@ export async function removeModel(id: string): Promise<void> {
|
||||
);
|
||||
}
|
||||
await d.batch([
|
||||
d.delete(modelTags).where(eq(modelTags.modelId, id)),
|
||||
d.delete(modelFiles).where(eq(modelFiles.modelId, id)),
|
||||
d.delete(modelRevisions).where(eq(modelRevisions.modelId, id)),
|
||||
d.delete(models).where(eq(models.id, id)),
|
||||
@@ -102,3 +117,42 @@ function chunk<T>(items: T[], size: number): T[][] {
|
||||
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add files to a model's selection and queue a download. The paths are added to the selection
|
||||
* rule as exact includes; exclude patterns that would block one of them are dropped, then the
|
||||
* rule is re-applied to the whole file list so `selected` always matches the stored rule.
|
||||
*/
|
||||
export async function addFilesToModel(modelId: string, paths: string[]): Promise<{ jobId: string; added: number }> {
|
||||
const d = db();
|
||||
const model = await d.query.models.findFirst({ where: eq(models.id, modelId) });
|
||||
if (!model) throw new ModelError("not_found", "Model not found.", 404);
|
||||
const missing = hubMissingMessage(model);
|
||||
if (missing) throw new ModelError("hub_missing", missing, 409);
|
||||
|
||||
const open = await d.query.jobs.findFirst({
|
||||
columns: { id: true },
|
||||
where: and(eq(jobs.modelId, modelId), inArray(jobs.state, ["queued", "downloading", "verifying"])),
|
||||
});
|
||||
if (open) throw new ModelError("busy", "A download for this model is still queued or running. Add files when it has finished.", 409);
|
||||
|
||||
const files = await d.select().from(modelFiles).where(eq(modelFiles.modelId, modelId));
|
||||
const known = new Map(files.map((f) => [f.path, f]));
|
||||
const wanted = [...new Set(paths)].filter((p) => known.has(p) && !known.get(p)!.selected);
|
||||
if (wanted.length === 0) throw new ModelError("empty_selection", "No new files selected.", 400);
|
||||
|
||||
const rule: SelectionRule = {
|
||||
include: [...model.includePatterns, ...wanted.map(escapeGlob)],
|
||||
exclude: model.excludePatterns.filter((p) => !wanted.some((path) => matchesAny(path, [p]))),
|
||||
};
|
||||
const changed = files.filter((f) => f.selected !== isSelected(f.path, rule));
|
||||
|
||||
await d.batch([
|
||||
d.update(models).set({ includePatterns: rule.include, excludePatterns: rule.exclude }).where(eq(models.id, modelId)),
|
||||
...changed.map((f) =>
|
||||
d.update(modelFiles).set({ selected: !f.selected, state: "pending" }).where(eq(modelFiles.id, f.id)),
|
||||
),
|
||||
]);
|
||||
const { jobId } = await queueDownload(modelId, "add");
|
||||
return { jobId, added: changed.filter((f) => !f.selected).length };
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { DEFAULT_RECOMMENDED_ROLES, quantTag, recommendFiles } from "./recommend";
|
||||
|
||||
const f = (path: string, size = 1) => ({ path, size });
|
||||
|
||||
// Trimmed from unsloth/Qwen3.8-27B-GGUF and unsloth/Qwen3-8B-GGUF.
|
||||
const qwen38 = [
|
||||
f(".gitattributes"),
|
||||
f("MTP/mtp-Qwen3.8-27B-Q4_0.gguf", 1_369_590_656),
|
||||
f("Qwen3.8-27B-Q4_0.gguf"),
|
||||
f("Qwen3.8-27B-UD-Q4_K_XL.gguf"),
|
||||
f("README.md"),
|
||||
f("config.json"),
|
||||
f("imatrix_unsloth.gguf"),
|
||||
f("mmproj-BF16.gguf", 931_146_432),
|
||||
f("mmproj-F16.gguf", 927_607_488),
|
||||
];
|
||||
const qwen3 = [f("Qwen3-8B-Q4_K_M.gguf"), f("Qwen3-8B-Q8_0.gguf"), f("params"), f("template"), f("config.json"), f("imatrix_unsloth.dat")];
|
||||
|
||||
describe("quantTag", () => {
|
||||
it("reads quant and precision tags", () => {
|
||||
assert.equal(quantTag("MTP/mtp-Qwen3.8-27B-Q4_0.gguf"), "q4_0");
|
||||
assert.equal(quantTag("mmproj-F16.gguf"), "f16");
|
||||
assert.equal(quantTag("Qwen3.8-27B-UD-Q4_K_XL.gguf"), "ud-q4_k_xl");
|
||||
});
|
||||
});
|
||||
|
||||
describe("recommendFiles", () => {
|
||||
it("adds the only MTP head and prefers the F16 mmproj", () => {
|
||||
const rec = recommendFiles(qwen38, ["Qwen3.8-27B-UD-Q4_K_XL.gguf"], DEFAULT_RECOMMENDED_ROLES);
|
||||
assert.deepEqual(rec.sort(), ["MTP/mtp-Qwen3.8-27B-Q4_0.gguf", "mmproj-F16.gguf"]);
|
||||
});
|
||||
|
||||
it("matches the variant with the same quant", () => {
|
||||
const files = [...qwen38, f("MTP/mtp-Qwen3.8-27B-Q8_0.gguf"), f("Qwen3.8-27B-Q8_0.gguf")];
|
||||
assert.deepEqual(recommendFiles(files, ["Qwen3.8-27B-Q8_0.gguf"], ["mtp"]), ["MTP/mtp-Qwen3.8-27B-Q8_0.gguf"]);
|
||||
assert.deepEqual(recommendFiles(files, ["Qwen3.8-27B-Q4_0.gguf"], ["mtp"]), ["MTP/mtp-Qwen3.8-27B-Q4_0.gguf"]);
|
||||
});
|
||||
|
||||
it("adds the chat template, and config only when enabled", () => {
|
||||
assert.deepEqual(recommendFiles(qwen3, ["Qwen3-8B-Q4_K_M.gguf"], DEFAULT_RECOMMENDED_ROLES), ["template"]);
|
||||
assert.deepEqual(recommendFiles(qwen3, ["Qwen3-8B-Q4_K_M.gguf"], ["config"]).sort(), ["config.json", "params"]);
|
||||
});
|
||||
|
||||
it("doesn't add a second variant when one is already selected", () => {
|
||||
assert.deepEqual(recommendFiles(qwen38, ["Qwen3.8-27B-Q4_0.gguf"], ["vision"], ["mmproj-BF16.gguf"]), []);
|
||||
assert.deepEqual(recommendFiles(qwen38, ["Qwen3.8-27B-Q4_0.gguf", "mmproj-BF16.gguf"], ["vision", "mtp"]), [
|
||||
"MTP/mtp-Qwen3.8-27B-Q4_0.gguf",
|
||||
]);
|
||||
});
|
||||
|
||||
it("recommends nothing without picked model files", () => {
|
||||
assert.deepEqual(recommendFiles(qwen38, [], DEFAULT_RECOMMENDED_ROLES), []);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
// Files that usually go with the model weights you pick: chat template, MTP head, vision
|
||||
// projector (mmproj), … Which kinds is a setting. Shared by UI and server (pure functions).
|
||||
|
||||
import { groupSplitFiles } from "./file-groups";
|
||||
import { fileRole, type FileRole } from "./file-roles";
|
||||
import { quantGroup } from "./selection";
|
||||
|
||||
/** File kinds that can be recommended, in display order. */
|
||||
export const RECOMMENDABLE_ROLES: FileRole[] = ["template", "mtp", "vision", "draft", "config", "tokenizer", "imatrix", "adapter", "docs"];
|
||||
export const DEFAULT_RECOMMENDED_ROLES: FileRole[] = ["template", "mtp", "vision"];
|
||||
|
||||
/** Kinds where a repo has alternatives (one per quant or precision) and one is enough. */
|
||||
const VARIANT_ROLES = new Set<FileRole>(["mtp", "vision", "draft", "adapter", "imatrix"]);
|
||||
/** Preferred precision when no variant matches the picked quant. */
|
||||
const PRECISION_ORDER = ["f16", "bf16", "q8_0", "f32"];
|
||||
|
||||
const basename = (p: string) => p.slice(p.lastIndexOf("/") + 1);
|
||||
const dirname = (p: string) => (p.includes("/") ? p.slice(0, p.lastIndexOf("/")) : "");
|
||||
|
||||
/** Quant/precision tag from a file name: "mtp-X-Q4_0.gguf" → "q4_0", "mmproj-F16.gguf" → "f16". */
|
||||
export function quantTag(path: string): string | null {
|
||||
const g = quantGroup(basename(path));
|
||||
return g ? g.replace(/^mmproj-/i, "").toLowerCase() : null;
|
||||
}
|
||||
|
||||
const withoutUd = (q: string) => q.replace(/^ud-/, "");
|
||||
const bits = (q: string) => q.match(/^(?:ud-)?(?:i?q|tq|bf|f)(\d+)/)?.[1] ?? null;
|
||||
|
||||
/**
|
||||
* Paths to download along with `modelPaths` (model weights), for the given kinds. Variant kinds
|
||||
* (MTP, mmproj, …) get the variant matching a picked quant, else the best single one; other kinds
|
||||
* (template, config, …) get every such file at the repo root or next to a picked model file.
|
||||
* `have`: everything already selected; a variant kind that's already there isn't added again.
|
||||
*/
|
||||
export function recommendFiles(
|
||||
files: { path: string; size: number }[],
|
||||
modelPaths: string[],
|
||||
roles: FileRole[],
|
||||
have: string[] = [],
|
||||
): string[] {
|
||||
if (modelPaths.length === 0 || roles.length === 0) return [];
|
||||
const picked = new Set([...modelPaths, ...have]);
|
||||
const haveRoles = new Set([...picked].map(fileRole));
|
||||
const quants = modelPaths.map(quantTag).filter((q): q is string => !!q);
|
||||
const dirs = new Set(["", ...modelPaths.map(dirname)]);
|
||||
const out: string[] = [];
|
||||
|
||||
for (const role of roles) {
|
||||
const entries = groupSplitFiles(files.filter((f) => !picked.has(f.path) && fileRole(f.path) === role));
|
||||
if (entries.length === 0) continue;
|
||||
if (!VARIANT_ROLES.has(role)) {
|
||||
for (const e of entries) if (dirs.has(dirname(e.path))) out.push(...e.parts.map((p) => p.path));
|
||||
continue;
|
||||
}
|
||||
if (haveRoles.has(role)) continue; // e.g. an mmproj is already selected
|
||||
if (entries.length === 1) {
|
||||
out.push(...entries[0].parts.map((p) => p.path));
|
||||
continue;
|
||||
}
|
||||
const tag = (e: (typeof entries)[number]) => quantTag(e.path) ?? "";
|
||||
// Same quant as a picked model file (ignoring unsloth's "UD-" prefix): take those.
|
||||
const same = entries.filter((e) => quants.some((q) => withoutUd(q) === withoutUd(tag(e))));
|
||||
if (same.length > 0) {
|
||||
for (const e of same) out.push(...e.parts.map((p) => p.path));
|
||||
continue;
|
||||
}
|
||||
// Otherwise one variant: next to the model, then preferred precision, then same bit width, then smallest.
|
||||
const pickedBits = new Set(quants.map(bits).filter(Boolean));
|
||||
const score = (e: (typeof entries)[number]) => {
|
||||
const t = tag(e);
|
||||
const precision = PRECISION_ORDER.indexOf(t);
|
||||
return [
|
||||
dirs.has(dirname(e.path)) && dirname(e.path) !== "" ? 0 : 1,
|
||||
precision === -1 ? PRECISION_ORDER.length : precision,
|
||||
pickedBits.has(bits(t)) ? 0 : 1,
|
||||
e.size,
|
||||
];
|
||||
};
|
||||
const best = [...entries].sort((a, b) => {
|
||||
const sa = score(a);
|
||||
const sb = score(b);
|
||||
for (let i = 0; i < sa.length; i++) if (sa[i] !== sb[i]) return sa[i] - sb[i];
|
||||
return 0;
|
||||
})[0];
|
||||
out.push(...best.parts.map((p) => p.path));
|
||||
}
|
||||
return [...new Set(out)];
|
||||
}
|
||||
|
||||
/** Model-weight paths among `paths`. */
|
||||
export function modelFilePaths(paths: Iterable<string>): string[] {
|
||||
return [...paths].filter((p) => fileRole(p) === "model");
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { groupSplitFiles, splitInfo } from "./file-groups";
|
||||
import { fileRole } from "./file-roles";
|
||||
import { modelFamilies, parseRepoMetadata } from "./hub/metadata";
|
||||
import { EMPTY_FILTERS, facetCounts, matchesFilters, matchesQuery, type SearchableModel } from "./search";
|
||||
|
||||
describe("parseRepoMetadata (real Hub responses, trimmed)", () => {
|
||||
it("unsloth GGUF quant of Qwen", () => {
|
||||
const m = parseRepoMetadata({
|
||||
id: "unsloth/Qwen3-8B-GGUF",
|
||||
author: "unsloth",
|
||||
pipeline_tag: "text-generation",
|
||||
tags: ["transformers", "gguf", "qwen3", "qwen", "unsloth", "base_model:Qwen/Qwen3-8B", "base_model:quantized:Qwen/Qwen3-8B", "license:apache-2.0", "endpoints_compatible", "conversational", "arxiv:2309.00071"],
|
||||
cardData: { base_model: "Qwen/Qwen3-8B", license: "apache-2.0" },
|
||||
gguf: { architecture: "qwen3" },
|
||||
});
|
||||
assert.deepEqual(m.baseModels, ["Qwen/Qwen3-8B"]);
|
||||
assert.equal(m.architecture, "qwen3");
|
||||
assert.equal(m.license, "apache-2.0");
|
||||
assert.deepEqual(m.hubTags, ["transformers", "gguf", "qwen3", "qwen", "unsloth"]);
|
||||
assert.deepEqual(modelFamilies("unsloth/Qwen3-8B-GGUF", m.baseModels), ["Qwen"]);
|
||||
});
|
||||
|
||||
it("finetune with base_model as array and config.model_type", () => {
|
||||
const m = parseRepoMetadata({
|
||||
id: "TheDrummer/Cydonia-24B-v4.1",
|
||||
author: "TheDrummer",
|
||||
tags: ["safetensors", "mistral"],
|
||||
cardData: { base_model: ["mistralai/Mistral-Small-3.2-24B-Instruct-2507"] },
|
||||
config: { model_type: "mistral" },
|
||||
});
|
||||
assert.deepEqual(m.baseModels, ["mistralai/Mistral-Small-3.2-24B-Instruct-2507"]);
|
||||
assert.equal(m.architecture, "mistral");
|
||||
assert.deepEqual(modelFamilies("TheDrummer/Cydonia-24B-v4.1", m.baseModels), ["mistralai"]);
|
||||
});
|
||||
|
||||
it("falls back to base_model tags; original models are their own family", () => {
|
||||
const m = parseRepoMetadata({ id: "x/y", tags: ["base_model:finetune:Qwen/Qwen3-8B-Base"] });
|
||||
assert.deepEqual(m.baseModels, ["Qwen/Qwen3-8B-Base"]);
|
||||
assert.equal(m.author, "x");
|
||||
assert.deepEqual(modelFamilies("Qwen/Qwen3-8B", []), ["Qwen"]);
|
||||
});
|
||||
});
|
||||
|
||||
const model = (over: Partial<SearchableModel>): SearchableModel => ({
|
||||
repoId: "unsloth/Qwen3-8B-GGUF",
|
||||
author: "unsloth",
|
||||
families: ["Qwen"],
|
||||
baseModels: ["Qwen/Qwen3-8B"],
|
||||
architecture: "qwen3",
|
||||
quants: ["Q4_K_M"],
|
||||
tags: ["roleplay"],
|
||||
hubTags: ["gguf"],
|
||||
pipelineTag: "text-generation",
|
||||
license: "apache-2.0",
|
||||
status: "ready",
|
||||
hubStatus: null,
|
||||
...over,
|
||||
});
|
||||
|
||||
describe("matchesQuery", () => {
|
||||
it("matches author, family, quant and tags case-insensitively, all terms required", () => {
|
||||
const m = model({});
|
||||
assert.ok(matchesQuery(m, "qwen"));
|
||||
assert.ok(matchesQuery(m, "unsloth qwen"));
|
||||
assert.ok(matchesQuery(m, "q4_k_m"));
|
||||
assert.ok(matchesQuery(m, "ROLEPLAY"));
|
||||
assert.ok(matchesQuery(m, " "));
|
||||
assert.ok(!matchesQuery(m, "unsloth gemma"));
|
||||
});
|
||||
});
|
||||
|
||||
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({}),
|
||||
model({ repoId: "bartowski/Qwen_Qwen3-8B-GGUF", author: "bartowski", quants: ["Q6_K"], tags: [] }),
|
||||
model({ repoId: "unsloth/gemma-3-27b-it-GGUF", families: ["google"], quants: ["Q4_K_M"], tags: ["security"] }),
|
||||
];
|
||||
|
||||
it("ORs within a facet and ANDs across facets", () => {
|
||||
const f = { ...EMPTY_FILTERS, author: ["unsloth"], quant: ["Q4_K_M", "Q6_K"] };
|
||||
assert.deepEqual(
|
||||
models.filter((m) => matchesFilters(m, f)).map((m) => m.repoId),
|
||||
["unsloth/Qwen3-8B-GGUF", "unsloth/gemma-3-27b-it-GGUF"],
|
||||
);
|
||||
});
|
||||
|
||||
it("counts a facet without applying its own selection", () => {
|
||||
const f = { ...EMPTY_FILTERS, author: ["unsloth"] };
|
||||
assert.deepEqual(facetCounts(models, "author", "", f), [["unsloth", 2], ["bartowski", 1]]);
|
||||
assert.deepEqual(facetCounts(models, "family", "", f), [["google", 1], ["Qwen", 1]]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("fileRole", () => {
|
||||
it("classifies typical GGUF repo files", () => {
|
||||
const cases: [string, string][] = [
|
||||
["Qwen3.8-27B-UD-Q4_K_M.gguf", "model"],
|
||||
["Q4_K_M/Qwen3-235B-A22B-Q4_K_M-00001-of-00003.gguf", "model"],
|
||||
["MTP/mtp-Qwen3.8-27B-Q4_0.gguf", "mtp"],
|
||||
["mmproj-BF16.gguf", "vision"],
|
||||
["mmproj-model-f16.gguf", "vision"],
|
||||
["imatrix_unsloth.gguf", "imatrix"],
|
||||
["imatrix_unsloth.dat", "imatrix"],
|
||||
["Qwen_Qwen3-8B.imatrix", "imatrix"],
|
||||
["config.json", "config"],
|
||||
["generation_config.json", "config"],
|
||||
["params", "config"],
|
||||
["tokenizer.json", "tokenizer"],
|
||||
["tokenizer_config.json", "tokenizer"],
|
||||
["merges.txt", "tokenizer"],
|
||||
["chat_template.jinja", "template"],
|
||||
["template", "template"],
|
||||
["README.md", "docs"],
|
||||
["LICENSE", "docs"],
|
||||
[".gitattributes", "git"],
|
||||
["model-00001-of-00004.safetensors", "model"],
|
||||
["adapter_model.safetensors", "adapter"],
|
||||
["images/banner.png", "image"],
|
||||
];
|
||||
for (const [path, role] of cases) assert.equal(fileRole(path), role, path);
|
||||
});
|
||||
});
|
||||
|
||||
describe("groupSplitFiles", () => {
|
||||
it("merges split parts into one entry and leaves other files alone", () => {
|
||||
const files = [
|
||||
{ path: ".gitattributes", size: 1 },
|
||||
{ path: "BF16/Qwen3.8-27B-BF16-00002-of-00002.gguf", size: 20 },
|
||||
{ path: "BF16/Qwen3.8-27B-BF16-00001-of-00002.gguf", size: 50 },
|
||||
{ path: "Qwen3.8-27B-Q4_0.gguf", size: 16 },
|
||||
];
|
||||
const groups = groupSplitFiles(files);
|
||||
assert.deepEqual(
|
||||
groups.map((g) => [g.path, g.size, g.totalParts, g.parts.map((p) => p.path.slice(-18))]),
|
||||
[
|
||||
[".gitattributes", 1, 1, [".gitattributes"]],
|
||||
["BF16/Qwen3.8-27B-BF16.gguf", 70, 2, ["00001-of-00002.gguf", "00002-of-00002.gguf"].map((s) => s.slice(-18))],
|
||||
["Qwen3.8-27B-Q4_0.gguf", 16, 1, ["Qwen3.8-27B-Q4_0.gguf".slice(-18)]],
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
it("parses part numbers", () => {
|
||||
assert.deepEqual(splitInfo("Q4_K_M/X-Q4_K_M-00003-of-00010.gguf"), { base: "Q4_K_M/X-Q4_K_M.gguf", part: 3, total: 10 });
|
||||
assert.equal(splitInfo("model-00001-of-00004.safetensors")?.base, "model.safetensors");
|
||||
assert.equal(splitInfo("Qwen3-8B-Q4_K_M.gguf"), null);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
// Library search and facet filtering (runs in the browser; the library is small).
|
||||
|
||||
export type SearchableModel = {
|
||||
repoId: string;
|
||||
author: string;
|
||||
families: string[];
|
||||
baseModels: string[];
|
||||
architecture: string | null;
|
||||
quants: string[];
|
||||
tags: string[];
|
||||
hubTags: string[];
|
||||
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;
|
||||
export type Facet = (typeof FACETS)[number];
|
||||
export type Filters = Record<Facet, string[]>;
|
||||
|
||||
export const EMPTY_FILTERS: Filters = { author: [], family: [], quant: [], tag: [], status: [] };
|
||||
|
||||
export function facetValues(m: SearchableModel, facet: Facet): string[] {
|
||||
switch (facet) {
|
||||
case "author":
|
||||
return [m.author];
|
||||
case "family":
|
||||
return m.families;
|
||||
case "quant":
|
||||
return m.quants;
|
||||
case "tag":
|
||||
return m.tags;
|
||||
case "status":
|
||||
return m.hubStatus ? [m.status, m.hubStatus] : [m.status];
|
||||
}
|
||||
}
|
||||
|
||||
function haystack(m: SearchableModel): string {
|
||||
return [
|
||||
m.repoId,
|
||||
m.author,
|
||||
...m.families,
|
||||
...m.baseModels,
|
||||
m.architecture,
|
||||
...m.quants,
|
||||
...m.tags,
|
||||
...m.hubTags,
|
||||
m.pipelineTag,
|
||||
m.license,
|
||||
m.status,
|
||||
m.hubStatus,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" ")
|
||||
.toLowerCase();
|
||||
}
|
||||
|
||||
/** Every whitespace-separated term must appear somewhere (case-insensitive substring). */
|
||||
export function matchesQuery(m: SearchableModel, query: string): boolean {
|
||||
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
||||
if (terms.length === 0) return true;
|
||||
const text = haystack(m);
|
||||
return terms.every((t) => text.includes(t));
|
||||
}
|
||||
|
||||
/** OR within a facet, AND across facets. Values compare case-insensitively. */
|
||||
export function matchesFilters(m: SearchableModel, filters: Filters, except?: Facet): boolean {
|
||||
return FACETS.every((facet) => {
|
||||
const wanted = filters[facet];
|
||||
if (facet === except || wanted.length === 0) return true;
|
||||
const have = facetValues(m, facet).map((v) => v.toLowerCase());
|
||||
return wanted.some((w) => have.includes(w.toLowerCase()));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Value counts for one facet, computed over the models that match the query and all *other*
|
||||
* facets, so picking e.g. an author narrows the quant counts but not the author list itself.
|
||||
*/
|
||||
export function facetCounts(models: SearchableModel[], facet: Facet, query: string, filters: Filters) {
|
||||
const counts = new Map<string, number>();
|
||||
for (const m of models) {
|
||||
if (!matchesQuery(m, query) || !matchesFilters(m, filters, facet)) continue;
|
||||
for (const v of new Set(facetValues(m, facet))) counts.set(v, (counts.get(v) ?? 0) + 1);
|
||||
}
|
||||
// Keep selected values visible even if their count dropped to 0.
|
||||
for (const v of filters[facet]) if (!counts.has(v)) counts.set(v, 0);
|
||||
return [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0], undefined, { numeric: true }));
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import "server-only";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { settings } from "@/lib/db/schema";
|
||||
import { isLabelColor } from "@/lib/colors";
|
||||
import { FILE_ROLE_ORDER, FILE_ROLES, type FileRole, type FileRoleStyles } from "@/lib/file-roles";
|
||||
import { DEFAULT_RECOMMENDED_ROLES, RECOMMENDABLE_ROLES } from "@/lib/recommend";
|
||||
|
||||
const FILE_ROLES_KEY = "labels.fileRoles";
|
||||
export const FILE_ROLE_LABEL_MAX = 24;
|
||||
|
||||
type StoredRoles = Partial<Record<FileRole, { label?: string; color?: string }>>;
|
||||
|
||||
async function read<T>(key: string): Promise<T | null> {
|
||||
try {
|
||||
const row = await db().query.settings.findFirst({ where: eq(settings.key, key) });
|
||||
return (row?.value as T) ?? null;
|
||||
} catch {
|
||||
return null; // table missing before the first migration
|
||||
}
|
||||
}
|
||||
|
||||
async function write(key: string, value: unknown) {
|
||||
await db()
|
||||
.insert(settings)
|
||||
.values({ key, value })
|
||||
.onConflictDoUpdate({ target: settings.key, set: { value, updatedAt: new Date() } });
|
||||
}
|
||||
|
||||
/** Label text and color per file role: defaults merged with what was saved in Settings. */
|
||||
export async function getFileRoleStyles(): Promise<FileRoleStyles> {
|
||||
const stored = (await read<StoredRoles>(FILE_ROLES_KEY)) ?? {};
|
||||
const out = {} as FileRoleStyles;
|
||||
for (const role of FILE_ROLE_ORDER) {
|
||||
const s = stored[role] ?? {};
|
||||
out[role] = {
|
||||
label: typeof s.label === "string" && s.label.trim() ? s.label.trim() : FILE_ROLES[role].label,
|
||||
color: isLabelColor(s.color) ? s.color : FILE_ROLES[role].color,
|
||||
};
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export class SettingsError extends Error {
|
||||
status = 400;
|
||||
code = "invalid";
|
||||
}
|
||||
|
||||
/** Save label/color overrides. Values equal to the default are not stored. */
|
||||
export async function saveFileRoleStyles(input: Record<string, { label?: unknown; color?: unknown }>): Promise<FileRoleStyles> {
|
||||
const stored: StoredRoles = {};
|
||||
for (const [role, v] of Object.entries(input)) {
|
||||
if (!(role in FILE_ROLES)) throw new SettingsError(`Unknown file label "${role}".`);
|
||||
const def = FILE_ROLES[role as FileRole];
|
||||
const entry: { label?: string; color?: string } = {};
|
||||
if (v.label !== undefined) {
|
||||
if (typeof v.label !== "string" || !v.label.trim() || v.label.trim().length > FILE_ROLE_LABEL_MAX) {
|
||||
throw new SettingsError(`Label for "${role}" must be 1–${FILE_ROLE_LABEL_MAX} characters.`);
|
||||
}
|
||||
if (v.label.trim() !== def.label) entry.label = v.label.trim();
|
||||
}
|
||||
if (v.color !== undefined) {
|
||||
if (!isLabelColor(v.color)) throw new SettingsError(`Unknown color "${String(v.color)}".`);
|
||||
if (v.color !== def.color) entry.color = v.color;
|
||||
}
|
||||
if (entry.label || entry.color) stored[role as FileRole] = entry;
|
||||
}
|
||||
await write(FILE_ROLES_KEY, stored);
|
||||
return getFileRoleStyles();
|
||||
}
|
||||
|
||||
const RECOMMENDED_KEY = "downloads.recommendedRoles";
|
||||
|
||||
/** File kinds picked automatically along with model weights (Settings → Downloads). */
|
||||
export async function getRecommendedRoles(): Promise<FileRole[]> {
|
||||
const stored = await read<unknown>(RECOMMENDED_KEY);
|
||||
if (!Array.isArray(stored)) return DEFAULT_RECOMMENDED_ROLES;
|
||||
return RECOMMENDABLE_ROLES.filter((r) => stored.includes(r));
|
||||
}
|
||||
|
||||
export async function saveRecommendedRoles(roles: string[]): Promise<FileRole[]> {
|
||||
const unknown = roles.find((r) => !RECOMMENDABLE_ROLES.includes(r as FileRole));
|
||||
if (unknown) throw new SettingsError(`"${unknown}" can't be recommended.`);
|
||||
await write(RECOMMENDED_KEY, RECOMMENDABLE_ROLES.filter((r) => roles.includes(r)));
|
||||
return getRecommendedRoles();
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
import "server-only";
|
||||
import { and, asc, eq, sql } from "drizzle-orm";
|
||||
import { ulid } from "ulid";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { isLabelColor } from "@/lib/colors";
|
||||
import { modelTags, models, tags } from "@/lib/db/schema";
|
||||
|
||||
export const TAG_MAX_LENGTH = 40;
|
||||
|
||||
export class TagError extends Error {
|
||||
constructor(
|
||||
public code: "invalid" | "not_found",
|
||||
message: string,
|
||||
public status: number,
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export type Tag = { id: string; name: string; color: string | null };
|
||||
|
||||
/** Trim and collapse whitespace; the slug (lowercase) decides uniqueness. */
|
||||
export function normalizeTagName(raw: string): { name: string; slug: string } {
|
||||
const name = raw.trim().replace(/\s+/g, " ");
|
||||
if (!name) throw new TagError("invalid", "Tag name is empty.", 400);
|
||||
if (name.length > TAG_MAX_LENGTH) throw new TagError("invalid", `Tag names are at most ${TAG_MAX_LENGTH} characters.`, 400);
|
||||
return { name, slug: name.toLowerCase() };
|
||||
}
|
||||
|
||||
/** All tags with how many models use them (for autocomplete). */
|
||||
export async function listTags(): Promise<(Tag & { count: number })[]> {
|
||||
return db()
|
||||
.select({ id: tags.id, name: tags.name, color: tags.color, count: sql<number>`count(${modelTags.modelId})` })
|
||||
.from(tags)
|
||||
.leftJoin(modelTags, eq(modelTags.tagId, tags.id))
|
||||
.groupBy(tags.id)
|
||||
.orderBy(asc(tags.slug));
|
||||
}
|
||||
|
||||
export async function modelTagList(modelId: string): Promise<Tag[]> {
|
||||
return db()
|
||||
.select({ id: tags.id, name: tags.name, color: tags.color })
|
||||
.from(modelTags)
|
||||
.innerJoin(tags, eq(tags.id, modelTags.tagId))
|
||||
.where(eq(modelTags.modelId, modelId))
|
||||
.orderBy(asc(tags.slug));
|
||||
}
|
||||
|
||||
/** Attach a tag (created on first use; matched case-insensitively) to a model. */
|
||||
export async function addTag(modelId: string, rawName: string): Promise<Tag> {
|
||||
const { name, slug } = normalizeTagName(rawName);
|
||||
const d = db();
|
||||
const model = await d.query.models.findFirst({ columns: { id: true }, where: eq(models.id, modelId) });
|
||||
if (!model) throw new TagError("not_found", "Model not found.", 404);
|
||||
|
||||
await d.insert(tags).values({ id: ulid(), name, slug }).onConflictDoNothing({ target: tags.slug });
|
||||
const tag = await d.query.tags.findFirst({ columns: { id: true, name: true, color: true }, where: eq(tags.slug, slug) });
|
||||
if (!tag) throw new Error("tag vanished after insert");
|
||||
await d.insert(modelTags).values({ modelId, tagId: tag.id }).onConflictDoNothing();
|
||||
return tag;
|
||||
}
|
||||
|
||||
/** Detach a tag from a model. The tag itself stays (delete it in Settings). */
|
||||
export async function removeTag(modelId: string, tagId: string): Promise<void> {
|
||||
await db().delete(modelTags).where(and(eq(modelTags.modelId, modelId), eq(modelTags.tagId, tagId)));
|
||||
}
|
||||
|
||||
/** 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). */
|
||||
export async function updateTag(id: string, input: { name?: string; color?: string | null }): Promise<Tag> {
|
||||
const d = db();
|
||||
const tag = await d.query.tags.findFirst({ where: eq(tags.id, id) });
|
||||
if (!tag) throw new TagError("not_found", "Tag not found.", 404);
|
||||
const set: { name?: string; slug?: string; color?: string | null } = {};
|
||||
if (input.name !== undefined) {
|
||||
const { name, slug } = normalizeTagName(input.name);
|
||||
const clash = await d.query.tags.findFirst({ columns: { id: true }, where: eq(tags.slug, slug) });
|
||||
if (clash && clash.id !== id) throw new TagError("invalid", `A tag named "${name}" already exists.`, 409);
|
||||
Object.assign(set, { name, slug });
|
||||
}
|
||||
if (input.color !== undefined) {
|
||||
if (input.color !== null && !isLabelColor(input.color)) throw new TagError("invalid", "Unknown color.", 400);
|
||||
set.color = input.color;
|
||||
}
|
||||
if (Object.keys(set).length > 0) await d.update(tags).set(set).where(eq(tags.id, id));
|
||||
const updated = await d.query.tags.findFirst({ columns: { id: true, name: true, color: true }, where: eq(tags.id, id) });
|
||||
return updated!;
|
||||
}
|
||||
|
||||
/** Delete a tag and remove it from all models. */
|
||||
export async function deleteTag(id: string): Promise<void> {
|
||||
const d = db();
|
||||
await d.batch([d.delete(modelTags).where(eq(modelTags.tagId, id)), d.delete(tags).where(eq(tags.id, id))]);
|
||||
}
|
||||
+2
-1
@@ -27,5 +27,6 @@ export async function proxy(req: NextRequest, event: NextFetchEvent) {
|
||||
|
||||
export const config = {
|
||||
// Everything except the Auth.js endpoints, the login page and static assets.
|
||||
matcher: ["/((?!api/auth|login|_next/static|_next/image|favicon.ico).*)"],
|
||||
// Exact exclusions only: an org like "loginx" must still go through the gate.
|
||||
matcher: ["/((?!api/auth/|login$|_next/static/|_next/image/|favicon\\.ico$|icon\\.svg$).*)"],
|
||||
};
|
||||
@@ -147,7 +147,11 @@ export class DownloadRunner {
|
||||
const initial = await this.sample(dir, expected);
|
||||
const remaining = expected.reduce((s, f, i) => s + (initial[i].complete ? 0 : f.size), 0);
|
||||
const doneCount = initial.filter((p) => p.complete).length;
|
||||
if (doneCount > 0) this.jobLog.system(`${doneCount} file(s) already complete, hf will skip them.`);
|
||||
if (doneCount > 0) {
|
||||
this.jobLog.system(
|
||||
`${doneCount} file(s) already on disk with the right size. hf skips the ones it downloaded itself and checks the others by hash (slow for large files), downloading them again if they differ.`,
|
||||
);
|
||||
}
|
||||
|
||||
const free = await freeBytes(dir);
|
||||
if (free != null && remaining > free) {
|
||||
|
||||
+67
-1
@@ -9,8 +9,11 @@ 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";
|
||||
import { scanModelsDir } from "./scan";
|
||||
import { settleModelStatus } from "./model-status";
|
||||
|
||||
const HEARTBEAT_MS = 5_000;
|
||||
@@ -18,6 +21,10 @@ 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;
|
||||
/** How often MODELS_DIR is scanned for folders that could be imported (plus on request). */
|
||||
const FOLDER_SCAN_MS = 2 * 60_000;
|
||||
/** Touched on every heartbeat; the Docker healthcheck checks its age. */
|
||||
const HEALTH_FILE = join(tmpdir(), "kaname-worker-alive");
|
||||
|
||||
@@ -99,12 +106,14 @@ async function heartbeat() {
|
||||
.update(workerState)
|
||||
.set(values)
|
||||
.where(and(eq(workerState.id, "worker"), eq(workerState.instanceId, instanceId)))
|
||||
.returning({ id: workerState.id });
|
||||
.returning({ id: workerState.id, scanRequestedAt: workerState.scanRequestedAt });
|
||||
if (kept.length === 0) {
|
||||
log.error("lost the worker lease to another process; exiting");
|
||||
await shutdown("lease lost", 1);
|
||||
return;
|
||||
}
|
||||
const requested = kept[0].scanRequestedAt;
|
||||
if (requested && requested.getTime() > lastScanStartedAt) void scanFolders();
|
||||
await writeFile(HEALTH_FILE, String(Date.now())).catch(() => {});
|
||||
}
|
||||
|
||||
@@ -207,10 +216,58 @@ 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 scanning = false;
|
||||
let lastScanStartedAt = 0;
|
||||
async function scanFolders() {
|
||||
if (scanning || stopping) return;
|
||||
scanning = true;
|
||||
lastScanStartedAt = Date.now();
|
||||
try {
|
||||
const n = await scanModelsDir(coreEnv().MODELS_DIR);
|
||||
if (n > 0) log.info(`found ${n} folder(s) in the models dir that aren't in the library`);
|
||||
} catch (err) {
|
||||
log.error("models dir scan failed", err);
|
||||
} finally {
|
||||
scanning = false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -269,10 +326,19 @@ async function main() {
|
||||
if (hfVersion) log.info(`hf CLI: ${hfVersion}, xet ${env.HF_HUB_DISABLE_XET ? "disabled" : "enabled"}`);
|
||||
else log.warn("hf CLI not found on PATH; downloads will fail until it is installed");
|
||||
|
||||
// Models added before Hub metadata was stored (search/filters need it).
|
||||
backfillMetadata((repoId, err) => log.warn(`metadata for ${repoId} failed: ${err instanceof Error ? err.message : err}`))
|
||||
.then((n) => n > 0 && log.info(`fetched Hub metadata for ${n} model(s)`))
|
||||
.catch((err) => log.error("metadata backfill failed", err));
|
||||
|
||||
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));
|
||||
timers.push(setInterval(() => void scanFolders(), FOLDER_SCAN_MS));
|
||||
void scanFolders();
|
||||
void tick();
|
||||
setTimeout(() => void checkHubDue(), 15_000);
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// Finds model folders in MODELS_DIR that aren't in the library, so they can be imported.
|
||||
// Only the `<org>/<name>` layout is recognized (what Kaname and `hf download --local-dir` write).
|
||||
// Read-only: nothing on disk is changed.
|
||||
|
||||
import { readdir, readFile, stat } from "node:fs/promises";
|
||||
import { join, relative, sep } from "node:path";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { localFolders, models } from "@/lib/db/schema";
|
||||
import { HF_CACHE_DIR } from "./hf-layout";
|
||||
|
||||
/** Stop listing a folder's files after this many (the count stays exact). */
|
||||
const MAX_LISTED_FILES = 5_000;
|
||||
const SKIP_DIRS = new Set([".cache", ".git"]);
|
||||
|
||||
type FoundFolder = typeof localFolders.$inferInsert;
|
||||
|
||||
async function subdirs(dir: string): Promise<string[]> {
|
||||
try {
|
||||
const entries = await readdir(dir, { withFileTypes: true });
|
||||
return entries.filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function walk(root: string, dir: string, out: { path: string; size: number }[], totals: { count: number; bytes: number }) {
|
||||
let entries;
|
||||
try {
|
||||
entries = await readdir(dir, { withFileTypes: true });
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
for (const e of entries) {
|
||||
const full = join(dir, e.name);
|
||||
if (e.isDirectory()) {
|
||||
if (!SKIP_DIRS.has(e.name)) await walk(root, full, out, totals);
|
||||
} else if (e.isFile() && !e.name.endsWith(".incomplete")) {
|
||||
const size = (await stat(full).catch(() => null))?.size ?? 0;
|
||||
totals.count++;
|
||||
totals.bytes += size;
|
||||
if (out.length < MAX_LISTED_FILES) out.push({ path: relative(root, full).split(sep).join("/"), size });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The commit hf recorded for the first file it downloaded into this folder, if any. */
|
||||
async function hfCommit(folder: string): Promise<string | null> {
|
||||
const stack = [join(folder, HF_CACHE_DIR, "download")];
|
||||
while (stack.length > 0) {
|
||||
const dir = stack.pop()!;
|
||||
let entries;
|
||||
try {
|
||||
entries = await readdir(dir, { withFileTypes: true });
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
for (const e of entries) {
|
||||
if (e.isDirectory()) stack.push(join(dir, e.name));
|
||||
else if (e.name.endsWith(".metadata")) {
|
||||
const first = (await readFile(join(dir, e.name), "utf8").catch(() => "")).split("\n")[0].trim();
|
||||
if (/^[0-9a-f]{40}$/.test(first)) return first;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Scan MODELS_DIR and replace the `local_folders` table with folders no model uses. */
|
||||
export async function scanModelsDir(modelsDir: string): Promise<number> {
|
||||
const used = new Set((await db().select({ p: models.localPath }).from(models)).map((m) => m.p));
|
||||
const found: FoundFolder[] = [];
|
||||
const now = new Date();
|
||||
for (const org of await subdirs(modelsDir)) {
|
||||
for (const name of await subdirs(join(modelsDir, org))) {
|
||||
const path = `${org}/${name}`;
|
||||
if (used.has(path)) continue;
|
||||
const folder = join(modelsDir, org, name);
|
||||
const files: { path: string; size: number }[] = [];
|
||||
const totals = { count: 0, bytes: 0 };
|
||||
await walk(folder, folder, files, totals);
|
||||
if (totals.count === 0) continue;
|
||||
files.sort((a, b) => a.path.localeCompare(b.path));
|
||||
found.push({ path, files, fileCount: totals.count, totalBytes: totals.bytes, commit: await hfCommit(folder), scannedAt: now });
|
||||
}
|
||||
}
|
||||
const d = db();
|
||||
await d.batch([d.delete(localFolders), ...found.map((f) => d.insert(localFolders).values(f))]);
|
||||
return found.length;
|
||||
}
|
||||
Reference in new issue
Block a user