From 716bd8f2f07e38c3384fea72df4bf981383f238c Mon Sep 17 00:00:00 2001 From: Pascal Linxweiler Date: Wed, 21 Oct 2026 15:11:06 +0200 Subject: [PATCH] Release 0.13.0: agent API for deployments and benchmarks Scopes deployments:read/write and benchmarks:read/run; /api/v1 endpoints for runtimes, deployments (create with dry run, edit, start, stop, delete own ones), benchmark runs, A/B, sweeps and comparisons; ?wait= on all status endpoints. Guardrails: approval, agent deployments at once, one GPU job at a time, time limits, sweep variants, runtime and argument allowlists, host port range, memory/CPU caps, protected deployments with a VRAM check. Requested-by filters, approval bars, per-token activity log, scope editing, docs/agent/SKILL-tuning.md. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 53 + README.md | 8 +- docs/agent/SKILL-tuning.md | 179 ++ docs/agent/SKILL.md | 17 +- docs/api.md | 174 +- drizzle/0019_agent_tuning.sql | 25 + drizzle/meta/0019_snapshot.json | 2320 +++++++++++++++++ drizzle/meta/_journal.json | 7 + package-lock.json | 4 +- package.json | 2 +- .../benchmarks/[id]/benchmark-detail.tsx | 12 +- src/app/(app)/benchmarks/benchmark-list.tsx | 171 +- .../benchmarks/sweeps/[id]/sweep-detail.tsx | 12 +- .../deployments/[id]/deployment-detail.tsx | 32 +- src/app/(app)/deployments/deployment-list.tsx | 219 +- src/app/(app)/settings/api-tokens/page.tsx | 15 +- .../settings/api-tokens/token-settings.tsx | 336 ++- .../settings/api-tokens/tuning-settings.tsx | 166 ++ src/app/api/api-tokens/[id]/route.ts | 16 +- src/app/api/benchmarks/[id]/approve/route.ts | 16 + src/app/api/benchmarks/[id]/reject/route.ts | 16 + src/app/api/deployments/[id]/approve/route.ts | 16 + src/app/api/deployments/[id]/protect/route.ts | 19 + src/app/api/deployments/[id]/reject/route.ts | 16 + src/app/api/settings/tuning/route.ts | 35 + src/app/api/sweeps/[id]/approve/route.ts | 16 + src/app/api/sweeps/[id]/reject/route.ts | 16 + .../api/v1/benchmarks/[id]/cancel/route.ts | 20 + src/app/api/v1/benchmarks/[id]/route.ts | 23 + src/app/api/v1/benchmarks/compare/route.ts | 16 + src/app/api/v1/benchmarks/route.ts | 38 + src/app/api/v1/deployments/[id]/route.ts | 59 + .../api/v1/deployments/[id]/start/route.ts | 21 + src/app/api/v1/deployments/[id]/stop/route.ts | 18 + src/app/api/v1/deployments/route.ts | 44 + src/app/api/v1/downloads/route.ts | 6 +- src/app/api/v1/jobs/[id]/route.ts | 20 +- src/app/api/v1/route.ts | 35 +- src/app/api/v1/runtimes/route.ts | 33 + src/app/api/v1/sweeps/[id]/cancel/route.ts | 20 + src/app/api/v1/sweeps/[id]/route.ts | 19 + src/app/api/v1/sweeps/route.ts | 29 + src/components/approval-bar.tsx | 44 + src/components/benchmark-state.tsx | 3 +- src/lib/agent-activity.ts | 66 + src/lib/agent-deployments.ts | 293 +++ src/lib/agent-downloads.ts | 4 +- src/lib/agent-runs.ts | 258 ++ src/lib/agent-tuning.test.ts | 155 ++ src/lib/agent-tuning.ts | 351 +++ src/lib/api-tokens.ts | 12 + src/lib/api-v1-agent.test.ts | 535 ++++ src/lib/api-v1.ts | 7 +- src/lib/benchmarks.ts | 42 +- src/lib/db/schema.ts | 44 +- src/lib/deployments.ts | 53 +- src/lib/settings.ts | 30 + src/lib/sweeps.ts | 31 +- src/lib/token-scopes.ts | 4 + src/lib/wait.ts | 34 + src/worker/benchmarks.ts | 12 +- src/worker/sweeps.ts | 13 +- 62 files changed, 6091 insertions(+), 219 deletions(-) create mode 100644 docs/agent/SKILL-tuning.md create mode 100644 drizzle/0019_agent_tuning.sql create mode 100644 drizzle/meta/0019_snapshot.json create mode 100644 src/app/(app)/settings/api-tokens/tuning-settings.tsx create mode 100644 src/app/api/benchmarks/[id]/approve/route.ts create mode 100644 src/app/api/benchmarks/[id]/reject/route.ts create mode 100644 src/app/api/deployments/[id]/approve/route.ts create mode 100644 src/app/api/deployments/[id]/protect/route.ts create mode 100644 src/app/api/deployments/[id]/reject/route.ts create mode 100644 src/app/api/settings/tuning/route.ts create mode 100644 src/app/api/sweeps/[id]/approve/route.ts create mode 100644 src/app/api/sweeps/[id]/reject/route.ts create mode 100644 src/app/api/v1/benchmarks/[id]/cancel/route.ts create mode 100644 src/app/api/v1/benchmarks/[id]/route.ts create mode 100644 src/app/api/v1/benchmarks/compare/route.ts create mode 100644 src/app/api/v1/benchmarks/route.ts create mode 100644 src/app/api/v1/deployments/[id]/route.ts create mode 100644 src/app/api/v1/deployments/[id]/start/route.ts create mode 100644 src/app/api/v1/deployments/[id]/stop/route.ts create mode 100644 src/app/api/v1/deployments/route.ts create mode 100644 src/app/api/v1/runtimes/route.ts create mode 100644 src/app/api/v1/sweeps/[id]/cancel/route.ts create mode 100644 src/app/api/v1/sweeps/[id]/route.ts create mode 100644 src/app/api/v1/sweeps/route.ts create mode 100644 src/lib/agent-activity.ts create mode 100644 src/lib/agent-deployments.ts create mode 100644 src/lib/agent-runs.ts create mode 100644 src/lib/agent-tuning.test.ts create mode 100644 src/lib/agent-tuning.ts create mode 100644 src/lib/api-v1-agent.test.ts create mode 100644 src/lib/wait.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index baa7538..b3708ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,59 @@ All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); each milestone of step 1 (Hugging Face downloader) is released as a minor version. +## [0.13.0] - 2026-10-21 + +The agent API can now deploy and benchmark models, so an AI agent can tune launch options for the +hardware: within guardrails you set, only on deployments its own token created, and by default only +after you approve each start, run and sweep. + +No changes to `compose.yaml` or `.env`. The new columns and table are added on start. Existing +tokens keep their scopes; grant the new ones with **Scopes** in Settings → API tokens. + +### Added + +- **Token scopes** `deployments:read`, `deployments:write`, `benchmarks:read`, `benchmarks:run`, and + editing an existing token's scopes. +- **`/api/v1` for deployments** ([docs/api.md](docs/api.md)): + - `GET /api/v1/runtimes`: pulled runtimes, what they serve, whether agents may use them and which + extra arguments; the host's GPUs. + - `GET /api/v1/deployments`, `GET /api/v1/deployments/{id}`: state, endpoint, options, the engine + version and slots, live CPU/RAM; the log with `?log=N`. + - `POST /api/v1/deployments` with the same validation, memory/VRAM estimate and `docker run` + command as the form (returned in the answer); `dryRun: true` only checks. Unknown fields are + refused instead of ignored. + - `PATCH`, `POST …/start`, `POST …/stop`, `DELETE` for the token's own deployments. +- **`/api/v1` for benchmarks**: `POST /api/v1/benchmarks` (run or A/B, quick or full, phases, + description), `GET /api/v1/benchmarks/{id}` with a compact result (headline numbers, the run's + hardware/runtime/model setup, GPU and RAM use; the full summary with `?full=1`), cancel, a list, + `GET /api/v1/benchmarks/compare?ids=` (what differs, what's the same), and sweeps + (`POST /api/v1/sweeps`, `GET /api/v1/sweeps/{id}`, cancel). +- **`?wait=`** (max 900) on the job, deployment, run and sweep status endpoints: the request + returns once the state settles, so agents make one call instead of polling. Things that wait for + approval answer right away. +- **Guardrails for API deployments and benchmarks** (Settings → API tokens): approval (default: ask + me), agent deployments at once (1), one agent run or sweep at a time and no agent start while one + runs, time limits per run and sweep (30 min / 3 h, enforced by the worker), max sweep variants (8), + a runtime allowlist, an allowlist of extra argument flags per engine (values can't be paths or + URLs; the error names the argument), host ports only within a range (none by default), and caps + for memory and CPUs (agent deployments always get a memory limit). +- **Protected deployments**: the Protect button on a deployment's page. Agents can't edit, stop, + delete or benchmark it, nor start anything on the same GPUs that would crowd it out of VRAM + (estimated). +- **Approval** for agent starts, runs and sweeps on the deployment, run and sweep pages; "awaiting + approval" in the lists. +- Everything an agent creates shows **requested by <token>**, with a filter in the deployment + and benchmark lists; an **activity log** per token (Settings → API tokens) lists every request, + including refusals with their error code. +- **Agent skill for tuning** ([docs/agent/SKILL-tuning.md](docs/agent/SKILL-tuning.md)): check the + limits, pick a runtime, deploy (dry run first), wait until ready, benchmark, change one variable at a + time (or sweep), compare, report a compact table, stop the deployment; no polling loops, stop when + something needs approval, never work around a guardrail. + +### Changed + +- The download skill and messages use `?wait=` instead of "check again later". + ## [0.12.0] - 2026-10-21 Intel GPU support (Arc A- and B-series, Arc Pro): telemetry during benchmarks, presets, render group diff --git a/README.md b/README.md index 133bbee..d071cc8 100644 --- a/README.md +++ b/README.md @@ -87,9 +87,11 @@ More guides are in the [wiki](https://git.linxweiler.xyz/pascallinxweiler/Kaname [wiki](https://git.linxweiler.xyz/pascallinxweiler/Kaname/wiki/Runtimes). - **Jobs:** each download has a page with per-file progress and the full `hf` log. - **API for agents:** create a token in Settings → API tokens and let a program or AI agent look up - repos, list models and request downloads at `/api/v1`, within guardrails you set (approval, max - size, free space, jobs at once, allowed authors). See [docs/api.md](docs/api.md) (also how to let - `/api/v1/` past a forward-auth proxy) and the agent skill [docs/agent/SKILL.md](docs/agent/SKILL.md). + repos, list models and request downloads at `/api/v1`, and deploy and benchmark models to tune + their launch options, within guardrails you set (approval, sizes and limits, one GPU job at a time, + allowed runtimes and arguments, protected deployments). See [docs/api.md](docs/api.md) (also how to + let `/api/v1/` past a forward-auth proxy) and the agent skills [docs/agent/SKILL.md](docs/agent/SKILL.md) + and [docs/agent/SKILL-tuning.md](docs/agent/SKILL-tuning.md). ## How it works diff --git a/docs/agent/SKILL-tuning.md b/docs/agent/SKILL-tuning.md new file mode 100644 index 0000000..62ada44 --- /dev/null +++ b/docs/agent/SKILL-tuning.md @@ -0,0 +1,179 @@ +--- +name: kaname-tuning +description: Deploy local LLMs on the user's Kaname server and benchmark them to find good launch options (context, KV cache type, batch sizes, GPU layers, runtime) for the hardware. Use when the user asks to deploy, test, benchmark, tune or compare a model's settings, or to find the fastest setup for a model. +required_environment_variables: + - name: KANAME_URL + prompt: Kaname base URL (no trailing slash) + - name: KANAME_TOKEN + prompt: Kaname API token (kn_…) with the deployments and benchmarks scopes +--- + +# Kaname: deploy and tune models + +Kaname runs models in containers (llama.cpp or vLLM) and measures them with BetterBench. With this +skill you deploy a downloaded model, benchmark it, change **one** launch option at a time and report +which setup is best. To find or download models, use the `kaname-models` skill (`SKILL.md`). + +You may only change and benchmark deployments your own token created. You **cannot** touch the +user's deployments (especially protected ones), change settings, runtimes or tokens, or delete +models. Tell the user when something needs one of those. + +Every call needs `KANAME_URL` and `KANAME_TOKEN` (never print the token or put it in a URL), and the +`kaname` helper (a `curl` wrapper that adds the token and JSON headers; see `SKILL.md` → Setup). If +`kaname` is missing, write out +`curl -sS -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: application/json" …` instead. + +Errors are `{"error": {"code", "message"}}`; the message says what to do. + +## Rules + +- **No polling loops.** Status calls take `?wait=S` (max 900): Kaname holds the request until the + state settles. Make one call, with `-m` (curl's time limit) a bit above the wait. +- **Approval:** by default every start, run and sweep waits for the user (`state: + pending_approval`). Then **stop**: tell the user what you asked for and that it awaits their + approval in Kaname. Don't retry, don't poll. Continue when the user says it's approved. +- **Never work around a guardrail** (another token, splitting a sweep, renaming things). Report the + error message and stop. +- **One GPU job at a time:** one of your deployments running at once (unless the user raised the + limit), one run or sweep at a time. Stop your deployment when you're done. +- **Change one variable at a time**, so a difference has one cause. + +## 1. Know your limits + +```bash +kaname "$KANAME_URL/api/v1" +``` + +`deploymentGuardrails`: approval mode, how many of your deployments may run, run/sweep time limits, +max sweep variants, caps, host ports. Your scopes must include `deployments:write` and +`benchmarks:run`; if not, tell the user. + +## 2. Pick a model and a runtime + +```bash +kaname "$KANAME_URL/api/v1/models?status=ready&q=qwen3" +kaname "$KANAME_URL/api/v1/models/" # its files (pick a .gguf for llama.cpp) +kaname "$KANAME_URL/api/v1/runtimes" +``` + +Runtimes say what they serve (llama.cpp: a GGUF file, vLLM: a safetensors repo), whether you may use +them (`"allowed": true`) and which extra argument flags you may pass (`allowedExtraArgs`). `gpus` +lists the host's GPUs and their VRAM. + +Previous results for this model, to start from what is known: + +```bash +kaname "$KANAME_URL/api/v1/benchmarks?limit=10" +``` + +## 3. Deploy + +Check first (nothing is created; you get the exact command and the memory/VRAM estimates): + +```bash +kaname -X POST "$KANAME_URL/api/v1/deployments" -d '{ + "runtimeId": "", "modelId": "", "dryRun": true, + "options": { "modelFile": "Qwen3-8B-Q4_K_M.gguf", "contextSize": 16384, "gpuLayers": "auto", + "cacheTypeK": "q8_0", "cacheTypeV": "q8_0", "parallel": 1, "extraArgs": [] } +}' +``` + +If `estimates.vramMb` is above `estimates.gpuVramMb`, lower the context, quantize the KV cache or +pick a smaller quant. Then the same body without `"dryRun"`: + +- `state: pending_approval` → tell the user and stop (see Rules). +- `state: starting` → wait until it is ready: + +```bash +kaname -m 660 "$KANAME_URL/api/v1/deployments/?wait=600" +``` + +`state: running` → go on. `state: failed` → read `error` (and `?log=50`), fix the options +(`PATCH`, below) and start again; don't repeat the same failing options. + +## 4. Benchmark + +```bash +kaname -X POST "$KANAME_URL/api/v1/benchmarks" -d '{ + "deploymentId": "", "quick": true, "label": "Q4_K_M ctx16k q8_0 KV", + "description": "Baseline for tuning Qwen3-8B on this GPU" +}' +kaname -m 960 "$KANAME_URL/api/v1/benchmarks/?wait=900" +``` + +- `quick: true` (5 passes) to screen options; `quick: false` (20 passes) to confirm the winner. +- `phases` (`decode`, `prefill`, `concurrency`) narrows what is measured; leave it out for all. +- The result's `headline` has `decodeTps` (generation speed), `prefillTps` (prompt processing at the + deepest prompt), `ttftMs` (time to first token) and `peakParallelTps`; `setup` lists GPU, PCIe, + engine version, model/quant/KV cache, context and concurrency; `resources` has VRAM, power and + temperature. `?full=1` only when you need the per-category details. +- If the wait times out, the run is still going: one more call with `?wait=900`, then report. + +## 5. Change one variable and compare + +Stop, change one option, start, wait, benchmark again: + +```bash +kaname -X POST "$KANAME_URL/api/v1/deployments//stop" +kaname -m 120 "$KANAME_URL/api/v1/deployments/?wait=60" +kaname -X PATCH "$KANAME_URL/api/v1/deployments/" -d '{"options": {"cacheTypeK": "f16", "cacheTypeV": "f16"}}' +kaname -X POST "$KANAME_URL/api/v1/deployments//start" +``` + +Or let Kaname do it: a **sweep** deploys each variant of one or two settings, benchmarks it and +removes it again (stop your own deployment first; it counts as one run): + +```bash +kaname -X POST "$KANAME_URL/api/v1/sweeps" -d '{ + "baseDeploymentId": "", "quick": true, + "params": [{ "key": "kvCache", "values": ["f16", "q8_0", "q4_0"] }] +}' +kaname -m 960 "$KANAME_URL/api/v1/sweeps/?wait=900" +``` + +Keys: `contextSize`, `modelFile`, `kvCache`, `threads`, `parallel`, `batchSize`, `ubatchSize`, +`flashAttn`, `cacheRamMb`, `gpuLayers` (llama.cpp); `dtype`, `maxNumSeqs`, `gpuMemoryUtilization` +(vLLM); `cpus`. A sweep can take long: after a timed-out wait, report progress instead of waiting +again and again. + +Compare runs side by side: + +```bash +kaname "$KANAME_URL/api/v1/benchmarks/compare?ids=,," +``` + +Differences under ~2 % between separate runs are noise. For a small difference that matters, run +an A/B (two deployments of the same model at once, if the user allows 2 agent deployments): +`{"kind": "ab", "deploymentId": "", "deploymentBId": ""}`. + +## 6. Report and clean up + +Report a compact table, one row per setup, the varied option first: + +| KV cache | Decode t/s | Prefill t/s | TTFT ms | VRAM peak | Notes | +| --- | --- | --- | --- | --- | --- | +| f16 | 58.1 | 1910 | 88 | 11.2 GB | baseline | +| q8_0 | 57.6 | 1880 | 90 | 9.4 GB | −1 %, 1.8 GB less VRAM | + +Name the winner and why (and what stayed the same: GPU, engine version, quant, context). Then stop +your deployment (or delete it if the user doesn't need it): + +```bash +kaname -X POST "$KANAME_URL/api/v1/deployments//stop" +``` + +## When something is refused + +| `error.code` | What to do | +| --- | --- | +| `too_many_deployments` | Stop your other deployment first, or tell the user. | +| `gpu_busy` | Another agent job is running or a deployment is loading: wait once with `?wait=`, then retry once; otherwise report and stop. | +| `vram_protected` | It would crowd the user's protected deployment out of VRAM: smaller quant, context or quantized KV cache, or tell the user. | +| `arg_not_allowed` | That flag isn't allowed; use the structured option if there is one (`contextSize`, `gpuLayers`, `cacheTypeK`, …) or drop it. | +| `limit_exceeded` | Over the memory/CPU cap: smaller model or context. | +| `port_not_allowed` | Leave out `hostPort`. | +| `runtime_not_allowed`, `runtime_not_pulled` | Pick another runtime from `GET /api/v1/runtimes`, or tell the user. | +| `protected`, `not_owner` | Not your deployment: deploy your own. | +| `too_many_variants` | Vary fewer values. | +| `busy` | Stop the deployment before changing it. | +| `unauthorized`, `forbidden` | Token wrong, revoked or missing a scope: tell the user. | diff --git a/docs/agent/SKILL.md b/docs/agent/SKILL.md index ac51753..6c22e20 100644 --- a/docs/agent/SKILL.md +++ b/docs/agent/SKILL.md @@ -12,7 +12,9 @@ required_environment_variables: Kaname manages the user's local LLM library. You can look up Hugging Face repos, see what is already downloaded, request a download and follow it. You **cannot** delete anything, change -settings, or start models: tell the user when they need one of those. +settings, or start models with this skill: tell the user when they need one of those. To deploy and +benchmark models (with a token that has the deployments and benchmarks scopes), see +`SKILL-tuning.md`. Every call needs two environment variables: @@ -94,17 +96,20 @@ Answer: ## 4. Follow it ```bash -kaname "$KANAME_URL/api/v1/jobs/" +kaname -m 660 "$KANAME_URL/api/v1/jobs/?wait=600" ``` -`state`: `pending_approval` → `queued` → `downloading` → `verifying` → `completed`. Every check -costs a full round of your context, so check rarely: +`state`: `pending_approval` → `queued` → `downloading` → `verifying` → `completed`. With `?wait=600` +Kaname holds the request until the job is finished (or 600 s have passed; then `timedOut` is +`true`), so one call replaces a polling loop. Keep `-m` (curl's time limit) a bit above the wait. +Every call costs a full round of your context, so call rarely: - **`pending_approval`:** do **not** poll. Tell the user what you requested and that it awaits their approval in Kaname, then stop. Check again only when the user says it's approved, or, if the user asks for it, schedule a single one-off check later with your cron/scheduling tool. -- **`queued` / `downloading` / `verifying`:** check at most once, around the reported - `etaSeconds`; if there is no ETA, once after about 10 minutes. Never loop in short intervals. +- **`queued` / `downloading` / `verifying`:** one call with `?wait=600`. If it comes back with + `timedOut: true` and the ETA is long, tell the user it is still downloading instead of waiting + again and again. Never loop in short intervals. - **`completed`:** tell the user it's ready. - **`cancelled`:** the user rejected or cancelled it. Don't ask again unless the user says so. - **`failed`:** report `error.message` to the user. Don't loop on retries. diff --git a/docs/api.md b/docs/api.md index a119f77..b799b09 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,16 +1,17 @@ # Kaname API (`/api/v1`) A small JSON API for programs and AI agents: look up Hugging Face repos, list the local library, -request downloads and follow them. Everything an agent can do here is bounded by -[guardrails](#guardrails); it can't delete models or files, change settings, or manage runtimes or -tokens. +request downloads, deploy models and benchmark them to tune launch options. Everything an agent can +do here is bounded by [guardrails](#guardrails); it can't delete models or files, change settings, +manage runtimes or tokens, or touch deployments it didn't create. The rest of Kaname (the web UI and its internal `/api/*` routes) stays behind your OIDC login. Only `/api/v1` accepts tokens, and it accepts *only* tokens (a browser session doesn't work there). - [Authentication](#authentication) - [Errors](#errors) -- [Endpoints](#endpoints) +- [Endpoints](#endpoints): models and downloads, [deployments](#deployments), [benchmarks](#benchmarks) +- [Waiting instead of polling](#waiting-instead-of-polling) - [Guardrails](#guardrails) - [Behind a forward-auth proxy (Traefik)](#behind-a-forward-auth-proxy-traefik) @@ -27,6 +28,13 @@ Authorization: Bearer kn_… | --- | --- | | `models:read` | Hub lookup, list models, read jobs (and their log), disk space | | `downloads:create` | `POST /api/v1/downloads`, within the guardrails | +| `deployments:read` | List runtimes and deployments, read a deployment's state and log | +| `deployments:write` | Create deployments; edit, start, stop and delete **its own** ones, within the guardrails | +| `benchmarks:read` | Read runs, sweeps and comparisons | +| `benchmarks:run` | Start runs, A/B runs and sweeps on **its own** deployments; cancel its own | + +Tokens created before 0.13 keep the scopes they had; grant new ones with **Scopes** next to the +token in Settings → API tokens. A missing, unknown or revoked token gets `401`; a token without the needed scope gets `403`. The settings page shows when each token was last used; **Revoke** stops it immediately. @@ -44,12 +52,12 @@ Errors are JSON with a message meant to be read and acted on: | Status | Codes | | --- | --- | -| 400 | `invalid_request`, `invalid_json`, `empty_selection` (quant or globs match nothing), `invalid_repo_id` | -| 401 / 403 | `unauthorized`, `forbidden` (scope), `author_not_allowed`, `gated_no_token`, `gated_no_access` | +| 400 | `invalid_request` (also unknown fields), `invalid_json`, `empty_selection` (quant or globs match nothing), `invalid_repo_id`, `invalid` | +| 401 / 403 | `unauthorized`, `forbidden` (scope), `author_not_allowed`, `gated_no_token`, `gated_no_access`, `runtime_not_allowed`, `arg_not_allowed`, `port_not_allowed`, `protected`, `not_owner` | | 404 | `not_found`, `repo_not_found`, `revision_not_found` | -| 409 | `already_exists` (repo is in the library at another commit), `busy` (the model has an open job) | -| 422 | `too_large` | -| 429 | `too_many_jobs`, `rate_limited` (Hugging Face) | +| 409 | `already_exists` (repo is in the library at another commit), `busy` (a model with an open job; a deployment that must be stopped first), `runtime_not_pulled`, `vram_protected`, `invalid` (e.g. benchmarking a stopped deployment) | +| 422 | `too_large`, `limit_exceeded`, `too_many_variants` | +| 429 | `too_many_jobs`, `too_many_deployments`, `gpu_busy`, `rate_limited` (Hugging Face) | | 503 / 507 | `disk_unknown` (worker offline), `disk_space` | Sizes appear as bytes plus a readable `"… GB"` field (decimal GB, like the Hub). @@ -136,7 +144,7 @@ curl -s -X POST -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: appli ```json { "created": true, "modelId": "01M…", "jobId": "01M…", "state": "pending_approval", "requestedBytes": 5027783488, "requestedSize": "5.0 GB", "files": ["Qwen3-8B-Q4_K_M.gguf"], - "message": "Requested; waiting for the user to approve it in Kaname. Do not retry: check GET /api/v1/jobs/01M… every few minutes." } + "message": "Requested; waiting for the user to approve it in Kaname. Do not retry or poll; tell the user and stop." } ``` - **201**: a new job, `state` `pending_approval` (approval mode `approve`) or `queued` (`auto`). @@ -149,7 +157,7 @@ curl -s -X POST -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: appli It uses the same code path as the Add model dialog (the file list is fetched again from the Hub at that commit; the client's list isn't trusted). -### `GET /api/v1/jobs/{id}[?log=N]` +### `GET /api/v1/jobs/{id}[?wait=S][&log=N]` `models:read`. Compact job state: @@ -166,7 +174,8 @@ that commit; the client's list isn't trusted). States: `pending_approval`, `queued`, `downloading`, `verifying`, `completed`, `failed`, `cancelled` (also when the user rejected the request), `interrupted`. The `hf` log is only included with -`?log=N` (the last N lines, at most 200). +`?log=N` (the last N lines, at most 200). `?wait=S` returns once the job is finished (or right away +while it waits for approval); see [Waiting instead of polling](#waiting-instead-of-polling). ### `GET /api/v1/disk` @@ -181,8 +190,117 @@ States: `pending_approval`, `queued`, `downloading`, `verifying`, `completed`, ` `reservedBytes` is what open downloads still have to fetch; `availableForRequests` is what a request may use before hitting the minimum-free guardrail. +### Deployments + +A deployment is a model served by a runtime container. Agents use the same validation, estimates and +`docker run` command as the UI; they can only edit, start, stop, delete and benchmark deployments their +own token created, and never [protected](#protected-deployments) ones. + +#### `GET /api/v1/runtimes` + +`deployments:read`. Runtimes with a pulled image: engine (`llama.cpp` or `vllm`), accelerator +(`cpu`, `nvidia`, `dri` for Intel/AMD), what they serve, whether agents may use them (`allowed`) and +the extra argument flags agents may pass (`allowedExtraArgs`); plus the host's GPUs. + +#### `GET /api/v1/deployments[?mine=1]`, `GET /api/v1/deployments/{id}[?wait=S][&log=N]` + +`deployments:read`. State (`stopped`, `pending_approval`, `starting`, `running`, `stopping`, +`failed`), `mine`, `protected`, runtime, model, options, limits, the endpoint inside the Docker +network, what the server reported once ready (version, slots, context), live CPU/RAM, error and a +`next` hint. `?wait=S` returns once it is running, stopped or failed (or right away while the start +waits for approval). `?log=N` adds the last N log lines (max 200). + +#### `POST /api/v1/deployments` + +`deployments:write`. + +| Field | | +| --- | --- | +| `runtimeId`, `modelId` | From `GET /api/v1/runtimes` and `GET /api/v1/models` | +| `options` | The deployment form's launch options: `modelFile` (llama.cpp: the `.gguf`; vLLM: `""`), `contextSize`, `parallel`, `cacheTypeK`/`cacheTypeV`, `flashAttn`, `gpuLayers`, `batchSize`/`ubatchSize`, `maxNumSeqs`, `gpuMemoryUtilization`, … and `extraArgs` (only [allowed flags](#deployments-and-benchmarks)). Unknown fields are refused. | +| `cpus`, `memoryMb` | Optional limits within the caps; without `memoryMb` the estimate is used | +| `hostPort` | Optional, only inside the configured range (none by default) | +| `name` | Optional | +| `start` | Default `true`; with approval mode `approve` the start waits for the user | +| `dryRun` | `true`: only validate; returns the command and estimates, creates nothing | + +```json +{ "created": true, "id": "01M…", "state": "pending_approval", + "command": "docker run -v :/models:ro ghcr.io/ggml-org/llama.cpp:server-intel -m /models/… -c 16384 -ctk q8_0 …", + "estimates": { "memoryMb": 9800, "vramMb": 7900, "gpuVramMb": 32768 }, "limits": { "memoryMb": 9800, "cpus": null }, + "message": "Created; the start waits for the user's approval in Kaname. Don't retry or poll; tell the user and stop." } +``` + +#### `PATCH /api/v1/deployments/{id}`, `POST …/start`, `POST …/stop`, `DELETE …` + +`deployments:write`, own deployments only. `PATCH` takes `options` (merged into the current ones), +`cpus`, `memoryMb`, `hostPort`, `name`, and only while the deployment is stopped; it returns the new +command and estimates. `start` goes through the same guardrails as creating one (and approval); +`stop` and `DELETE` never need approval. + +### Benchmarks + +#### `POST /api/v1/benchmarks` + +`benchmarks:run`. A [BetterBench](https://github.com/GGZ14/BetterBench) run against the token's own +**running** deployment. + +| Field | | +| --- | --- | +| `kind` | `run` (default) or `ab` (paired A/B with `deploymentBId`, same model; needs 2 agent deployments) | +| `deploymentId`, `deploymentBId` | Own, running deployments | +| `quick` | `true`: 5 passes, a smoke check; default `false`: 20 passes, comparable | +| `passes`, `phases` | Optional: passes per category; phases `decode`, `prefill`, `concurrency` (default all) | +| `label`, `description` | Optional; the description goes into the report and the launch80 preview | + +Answers `201` with `state` `pending_approval` (default) or `queued`, and the run's time limit. + +#### `GET /api/v1/benchmarks/{id}[?wait=S][&full=1]`, `GET /api/v1/benchmarks[?deployment=&requested_by=&limit=]` + +`benchmarks:read`. Compact result: + +```json +{ "id": "01M…", "kind": "run", "state": "completed", "label": "q8_0 KV", "mine": true, + "headline": { "decodeTps": 61.3, "prefillTps": 1840, "prefillDepth": 16000, "ttftMs": 92, "peakParallelTps": 155.2, "peakParallelLevel": 8 }, + "setup": { "gpus": "1× Intel Arc Pro B65 (32 GiB)", "pcie": "Gen5 x8 of Gen5 x16", "p2p": "n/a", "rebar": "on", + "engine": "llama.cpp b11541-f2918cabb", "image": "ghcr.io/ggml-org/llama.cpp:server-intel", "digest": "sha256:…", + "model": "Qwen3-8B-GGUF Q4_K_M with q8_0 KV cache", "ctx": "16,384", "concurrency": "4" }, + "resources": { "cpuAvgCores": 1.1, "ramPeakBytes": 2100000000, + "gpus": [{ "name": "Intel Arc Pro B65", "vramPeakMb": 9100, "vramTotalMb": 32768, "utilAvg": 88.5, "powerAvgW": 151.2, "tempPeakC": 71 }] }, + "error": null, "next": "Done. Compare runs with GET /api/v1/benchmarks/compare?ids=…" } +``` + +`?full=1` adds BetterBench's complete summary (per category, per prompt depth, per concurrency +level). A/B runs add `ab` (pairs, verdict, decode difference with its confidence interval). +`POST /api/v1/benchmarks/{id}/cancel` cancels an own run. + +#### `GET /api/v1/benchmarks/compare?ids=a,b,…` + +`benchmarks:read`. 2–16 runs: headline numbers side by side, the setup values that differ per run +(`differs`) and the ones they share (`same`). + +#### `POST /api/v1/sweeps`, `GET /api/v1/sweeps/{id}[?wait=S]`, `POST /api/v1/sweeps/{id}/cancel` + +`benchmarks:run` / `benchmarks:read`. One or two settings varied from an own base deployment, e.g. +`{"baseDeploymentId": "…", "params": [{"key": "kvCache", "values": ["f16", "q8_0"]}], "quick": true}`. +Keys: `contextSize`, `modelFile`, `kvCache`, `threads`, `parallel`, `batchSize`, `ubatchSize`, +`flashAttn`, `cacheRamMb`, `gpuLayers`, `dtype`, `maxNumSeqs`, `kvCacheGb`, `gpuMemoryUtilization`, +`cpus` (per engine, as in the UI). Each variant is deployed, benchmarked and removed again. The +answer lists every variant with its headline numbers and setup. + +## Waiting instead of polling + +Every status call costs an agent a round of its context. The status endpoints (`/jobs/{id}`, +`/deployments/{id}`, `/benchmarks/{id}`, `/sweeps/{id}`) take `?wait=S` (seconds, at most 900): the +request is held until the state is settled (finished, running, failed, cancelled) or the time is up, +then answers with the current state plus `waitedSeconds` and `timedOut`. Something that waits for the +user's approval answers right away: there is nothing to wait for. Use one waiting call instead of a +polling loop, with a wait shorter than your HTTP client's timeout (and any proxy's). + ## Guardrails +### Downloads + Settings → API tokens → **Guardrails for API downloads**. They apply to every token together; downloads started in the UI aren't affected. @@ -197,6 +315,38 @@ downloads started in the UI aren't affected. Rejecting a request cancels its job. A model that only that request added leaves the library again; for a request that added files to an existing model, the previous selection is restored. +### Deployments and benchmarks + +Settings → API tokens → **Guardrails for API deployments and benchmarks**, for every token together: + +| Setting | Default | Rejection | +| --- | --- | --- | +| Approval | **Ask me**: starts, runs and sweeps wait as *pending approval* on the deployment, run or sweep page. Creating or editing a stopped deployment, stopping and deleting own ones need none. | (not an error) | +| Agent deployments at once | 1 (running, starting or waiting to start); 2 for A/B runs | `429 too_many_deployments` | +| One GPU job at a time | No agent start while an agent run or sweep is pending or running, or another agent deployment is still loading; one agent run or sweep at a time; no sweep while an agent deployment runs (the sweep deploys its variants itself) | `429 gpu_busy` | +| Max minutes per run / sweep | 30 / 180, then the worker stops it | (`failed` with the reason) | +| Max variants per sweep | 8 | `422 too_many_variants` | +| Runtimes | Any with a pulled image, or an allowlist | `403 runtime_not_allowed`, `409 runtime_not_pulled` | +| Extra arguments | Tuning flags only, per engine (editable list); values can't be paths or URLs | `403 arg_not_allowed`, naming the argument | +| Host ports | None (Kaname reaches deployments over the Docker network), or a range | `403 port_not_allowed` | +| Memory / CPU caps | The host's size, or what you set; agent deployments always get a memory limit (the estimate if they don't give one) | `422 limit_exceeded` | +| Own deployments only | Agents change and benchmark only what their token created | `403 not_owner` | + +Docker options (devices, volumes, privileges, capabilities, network) are never arguments: they belong +to the runtime, which tokens can't change. + +### Protected deployments + +The **Protect** button on a deployment's page: agents can't edit, start, stop, delete or benchmark +it, and can't start a deployment on the same GPUs if the estimated VRAM of everything running there +plus the new one (and 1 GiB to spare) exceeds the GPUs' VRAM (`409 vram_protected`). When the need +can't be estimated (only some layers on the GPU), such a start is refused too. + +### Activity + +Settings → API tokens → **Activity** next to each token lists what it did: every request that +creates or changes something, waits for approval, or was refused (with the error code). + ## Behind a forward-auth proxy (Traefik) If Kaname sits behind forward auth (e.g. Traefik with Tinyauth or Pocket ID), the proxy would answer diff --git a/drizzle/0019_agent_tuning.sql b/drizzle/0019_agent_tuning.sql new file mode 100644 index 0000000..d201eb7 --- /dev/null +++ b/drizzle/0019_agent_tuning.sql @@ -0,0 +1,25 @@ +CREATE TABLE `agent_activity` ( + `id` text PRIMARY KEY NOT NULL, + `token_id` text NOT NULL, + `token_name` text NOT NULL, + `action` text NOT NULL, + `target_type` text, + `target_id` text, + `outcome` text NOT NULL, + `code` text, + `message` text, + `created_at` integer NOT NULL +); +--> statement-breakpoint +CREATE INDEX `agent_activity_token_idx` ON `agent_activity` (`token_id`,`created_at`);--> statement-breakpoint +ALTER TABLE `benchmark_runs` ADD `requested_by_token_id` text;--> statement-breakpoint +ALTER TABLE `benchmark_runs` ADD `requested_by` text;--> statement-breakpoint +ALTER TABLE `benchmark_runs` ADD `time_limit_s` integer;--> statement-breakpoint +ALTER TABLE `benchmark_sweeps` ADD `requested_by_token_id` text;--> statement-breakpoint +ALTER TABLE `benchmark_sweeps` ADD `requested_by` text;--> statement-breakpoint +ALTER TABLE `benchmark_sweeps` ADD `time_limit_s` integer;--> statement-breakpoint +ALTER TABLE `benchmark_sweeps` ADD `run_time_limit_s` integer;--> statement-breakpoint +ALTER TABLE `deployments` ADD `requested_by_token_id` text;--> statement-breakpoint +ALTER TABLE `deployments` ADD `requested_by` text;--> statement-breakpoint +ALTER TABLE `deployments` ADD `protected` integer DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE `deployments` ADD `start_requested_at` integer; \ No newline at end of file diff --git a/drizzle/meta/0019_snapshot.json b/drizzle/meta/0019_snapshot.json new file mode 100644 index 0000000..052b0fe --- /dev/null +++ b/drizzle/meta/0019_snapshot.json @@ -0,0 +1,2320 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "b20bb7ae-f705-4f7a-a6c4-27f2ba35918c", + "prevId": "242cc50c-62a9-4514-b1b3-cd58ae9068c6", + "tables": { + "agent_activity": { + "name": "agent_activity", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "token_id": { + "name": "token_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token_name": { + "name": "token_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "agent_activity_token_idx": { + "name": "agent_activity_token_idx", + "columns": [ + "token_id", + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "api_keys": { + "name": "api_keys", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "api_keys_key_unique": { + "name": "api_keys_key_unique", + "columns": [ + "key" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "api_tokens": { + "name": "api_tokens", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "prefix": { + "name": "prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hash": { + "name": "hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scopes": { + "name": "scopes", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "api_tokens_hash_unique": { + "name": "api_tokens_hash_unique", + "columns": [ + "hash" + ], + "isUnique": true + }, + "api_tokens_name_uq": { + "name": "api_tokens_name_uq", + "columns": [ + "name" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "benchmark_logs": { + "name": "benchmark_logs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "run_id": { + "name": "run_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": { + "benchmark_logs_idx": { + "name": "benchmark_logs_idx", + "columns": [ + "run_id", + "id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "benchmark_publications": { + "name": "benchmark_publications", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "run_id": { + "name": "run_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'preview'" + }, + "template": { + "name": "template", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'bench.betterbench.v1'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payload_bytes": { + "name": "payload_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "previewed_at": { + "name": "previewed_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "confirmed_by": { + "name": "confirmed_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "guid": { + "name": "guid", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "published_at": { + "name": "published_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "benchmark_publications_run_idx": { + "name": "benchmark_publications_run_idx", + "columns": [ + "run_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "benchmark_runs": { + "name": "benchmark_runs", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "deployment_id": { + "name": "deployment_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "model_id": { + "name": "model_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tool": { + "name": "tool", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'betterbench'" + }, + "settings": { + "name": "settings", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "snapshot": { + "name": "snapshot", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'queued'" + }, + "phase": { + "name": "phase", + "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 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "has_report": { + "name": "has_report", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'run'" + }, + "deployment_b_id": { + "name": "deployment_b_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "snapshot_b": { + "name": "snapshot_b", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ab": { + "name": "ab", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "resources": { + "name": "resources", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sweep_id": { + "name": "sweep_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by_token_id": { + "name": "requested_by_token_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_limit_s": { + "name": "time_limit_s", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "meta": { + "name": "meta", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "meta_b": { + "name": "meta_b", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "system": { + "name": "system", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "benchmark_runs_created_idx": { + "name": "benchmark_runs_created_idx", + "columns": [ + "created_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "benchmark_sweeps": { + "name": "benchmark_sweeps", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "base_deployment_id": { + "name": "base_deployment_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "base": { + "name": "base", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "params": { + "name": "params", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "settings": { + "name": "settings", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "variants": { + "name": "variants", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'queued'" + }, + "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 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by_token_id": { + "name": "requested_by_token_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_limit_s": { + "name": "time_limit_s", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "run_time_limit_s": { + "name": "run_time_limit_s", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "deployment_logs": { + "name": "deployment_logs", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "deployment_id": { + "name": "deployment_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": { + "deployment_logs_idx": { + "name": "deployment_logs_idx", + "columns": [ + "deployment_id", + "id" + ], + "isUnique": false + } + }, + "foreignKeys": { + "deployment_logs_deployment_id_deployments_id_fk": { + "name": "deployment_logs_deployment_id_deployments_id_fk", + "tableFrom": "deployment_logs", + "tableTo": "deployments", + "columnsFrom": [ + "deployment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "deployments": { + "name": "deployments", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "runtime_id": { + "name": "runtime_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "model_id": { + "name": "model_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "options": { + "name": "options", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "cpus": { + "name": "cpus", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "memory_mb": { + "name": "memory_mb", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "host_port": { + "name": "host_port", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "desired_state": { + "name": "desired_state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'stopped'" + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'stopped'" + }, + "delete_requested_at": { + "name": "delete_requested_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "container_id": { + "name": "container_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "container_name": { + "name": "container_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "command": { + "name": "command", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_id": { + "name": "image_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ready_at": { + "name": "ready_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stopped_at": { + "name": "stopped_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "exit_code": { + "name": "exit_code", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stats": { + "name": "stats", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "engine_info": { + "name": "engine_info", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sweep_id": { + "name": "sweep_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by_token_id": { + "name": "requested_by_token_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "protected": { + "name": "protected", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "start_requested_at": { + "name": "start_requested_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": {}, + "foreignKeys": { + "deployments_runtime_id_runtimes_id_fk": { + "name": "deployments_runtime_id_runtimes_id_fk", + "tableFrom": "deployments", + "tableTo": "runtimes", + "columnsFrom": [ + "runtime_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "deployments_model_id_models_id_fk": { + "name": "deployments_model_id_models_id_fk", + "tableFrom": "deployments", + "tableTo": "models", + "columnsFrom": [ + "model_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "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 + }, + "result": { + "name": "result", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cancel_requested_at": { + "name": "cancel_requested_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by_token_id": { + "name": "requested_by_token_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "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": {} + }, + "local_folders": { + "name": "local_folders", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "files": { + "name": "files", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "file_count": { + "name": "file_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "total_bytes": { + "name": "total_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "commit": { + "name": "commit", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scanned_at": { + "name": "scanned_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "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 + }, + "update_diff": { + "name": "update_diff", + "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 + }, + "requested_by_token_id": { + "name": "requested_by_token_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requested_by": { + "name": "requested_by", + "type": "text", + "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": {} + }, + "runtimes": { + "name": "runtimes", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "engine": { + "name": "engine", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "accelerator": { + "name": "accelerator", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'cpu'" + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "env": { + "name": "env", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'{}'" + }, + "extra_args": { + "name": "extra_args", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "devices": { + "name": "devices", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[]'" + }, + "shm_size_mb": { + "name": "shm_size_mb", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "numa_tuning": { + "name": "numa_tuning", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "preset": { + "name": "preset", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_state": { + "name": "image_state", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'unknown'" + }, + "image_id": { + "name": "image_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_size": { + "name": "image_size", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_created": { + "name": "image_created", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pull_requested_at": { + "name": "pull_requested_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pull_started_at": { + "name": "pull_started_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pull_progress": { + "name": "pull_progress", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pull_error": { + "name": "pull_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_checked_at": { + "name": "image_checked_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image_digest": { + "name": "image_digest", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "engine_name": { + "name": "engine_name", + "type": "text", + "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": {}, + "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 + }, + "scan_requested_at": { + "name": "scan_requested_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "docker": { + "name": "docker", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 97d23d0..a7cfad2 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -134,6 +134,13 @@ "when": 1792513935880, "tag": "0018_benchmark_metadata", "breakpoints": true + }, + { + "idx": 19, + "version": "6", + "when": 1792587768766, + "tag": "0019_agent_tuning", + "breakpoints": true } ] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 61f4c0a..08c6a94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kaname", - "version": "0.12.0", + "version": "0.13.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kaname", - "version": "0.12.0", + "version": "0.13.0", "dependencies": { "@base-ui/react": "^1.8.0", "@libsql/client": "^0.18.0", diff --git a/package.json b/package.json index a6457dc..e7ff743 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kaname", - "version": "0.12.0", + "version": "0.13.0", "private": true, "scripts": { "dev": "concurrently -k -n web,worker -c blue,magenta \"npm:dev:web\" \"npm:dev:worker\"", diff --git a/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx b/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx index 10b9f0e..34d29f4 100644 --- a/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx +++ b/src/app/(app)/benchmarks/[id]/benchmark-detail.tsx @@ -33,6 +33,8 @@ import { Input } from "@/components/ui/input"; import { reportSummary, weightsLabel } from "@/lib/benchmark-report"; import { CONFIG_ROWS, describeSettings } from "@/lib/benchmark-view"; import type { ListRow } from "../benchmark-list"; +import { AgentApprovalBar } from "@/components/approval-bar"; +import { RequestedByBadge } from "@/components/requested-by-badge"; import { RunMetaCard } from "@/components/run-meta"; import { cancelBenchmark, deleteBenchmark, describeBenchmark, renameBenchmark } from "../actions"; import { AbReport } from "./ab-report"; @@ -60,7 +62,7 @@ export function BenchmarkDetail({ initial }: { initial: ListRow }) { const [now, setNow] = useState(() => Date.now()); const [label, setLabel] = useState(initial.label ?? ""); const [description, setDescription] = useState(initial.description ?? ""); - const active = r.state === "queued" || r.state === "running"; + const active = r.state === "pending_approval" || r.state === "queued" || r.state === "running"; useEffect(() => { if (!active) return; @@ -120,6 +122,7 @@ export function BenchmarkDetail({ initial }: { initial: ListRow }) { state={r.state} cancelling={!!r.cancelRequestedAt} /> +

{r.deploymentId ? ( @@ -265,6 +268,13 @@ export function BenchmarkDetail({ initial }: { initial: ListRow }) { + {r.state === "pending_approval" && ( + + )} {r.error && (

diff --git a/src/app/(app)/benchmarks/benchmark-list.tsx b/src/app/(app)/benchmarks/benchmark-list.tsx index c26216a..e7c3b1a 100644 --- a/src/app/(app)/benchmarks/benchmark-list.tsx +++ b/src/app/(app)/benchmarks/benchmark-list.tsx @@ -4,16 +4,28 @@ import { GaugeIcon, GitCompareIcon } from "lucide-react"; import Link from "next/link"; import { useEffect, useState } from "react"; import { BenchmarkStateBadge } from "@/components/benchmark-state"; +import { RequestedByBadge } from "@/components/requested-by-badge"; +import { NativeSelect } from "@/components/ui/native-select"; import { LocalTime } from "@/components/local-time"; import { buttonVariants } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Checkbox } from "@/components/ui/checkbox"; -import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; import type { BenchmarkRow } from "@/lib/benchmarks"; import { configChips, describeSettings, headline } from "@/lib/benchmark-view"; import { cn } from "@/lib/utils"; -export type ListRow = Omit & { +export type ListRow = Omit< + BenchmarkRow, + "createdAt" | "startedAt" | "finishedAt" | "cancelRequestedAt" +> & { createdAt: string; startedAt: string | null; finishedAt: string | null; @@ -21,18 +33,35 @@ export type ListRow = Omit (v == null ? "–" : v.toFixed(digits)); +const fmt = (v: number | null | undefined, digits = 1) => + v == null ? "–" : v.toFixed(digits); /** All runs with their headline numbers; polls while something is queued or running. */ -export function BenchmarkList({ rows: initial, compact }: { rows: ListRow[]; compact?: boolean }) { +export function BenchmarkList({ + rows: initial, + compact, +}: { + rows: ListRow[]; + compact?: boolean; +}) { const [rows, setRows] = useState(initial); const [selected, setSelected] = useState([]); + // "" = everything, "-" = started in Kaname, else a token name. + const [by, setBy] = useState(""); const busy = rows.some((r) => r.state === "queued" || r.state === "running"); + const tokens = [ + ...new Set(rows.map((r) => r.requestedBy).filter((x): x is string => !!x)), + ].sort(); + const shown = rows.filter( + (r) => !by || (by === "-" ? !r.requestedBy : r.requestedBy === by), + ); useEffect(() => { if (!busy || compact) return; const t = setInterval(async () => { - const res = await fetch("/api/benchmarks", { cache: "no-store" }).catch(() => null); + const res = await fetch("/api/benchmarks", { cache: "no-store" }).catch( + () => null, + ); if (res?.ok) setRows(await res.json()); }, 3_000); return () => clearInterval(t); @@ -53,22 +82,54 @@ export function BenchmarkList({ rows: initial, compact }: { rows: ListRow[]; com ); } - const toggle = (id: string) => setSelected((s) => (s.includes(id) ? s.filter((x) => x !== id) : s.length < MAX_COMPARE ? [...s, id] : s)); + const toggle = (id: string) => + setSelected((s) => + s.includes(id) + ? s.filter((x) => x !== id) + : s.length < MAX_COMPARE + ? [...s, id] + : s, + ); const comparable = rows.filter((r) => r.state === "completed"); return (
- {!compact && comparable.length > 1 && ( -
- {selected.length === 0 ? "Select completed runs to compare them." : `${selected.length} selected (up to ${MAX_COMPARE}).`} - - - Compare - + {!compact && (comparable.length > 1 || tokens.length > 0) && ( +
+ + {selected.length === 0 + ? "Select completed runs to compare them." + : `${selected.length} selected (up to ${MAX_COMPARE}).`} + + + {tokens.length > 0 && ( + setBy(e.target.value)} + className="h-8 text-xs" + aria-label="Requested by" + > + + + {tokens.map((t) => ( + + ))} + + )} + + + Compare + +
)} @@ -78,27 +139,42 @@ export function BenchmarkList({ rows: initial, compact }: { rows: ListRow[]; com {!compact && } Run Settings - + Decode t/s - + TTFT - + Prefill t/s - + Peak t/s State - {rows.map((r) => { + {shown.map((r) => { const h = headline(r.summary); const s = r.snapshot; return ( - + {!compact && ( )} - + {r.label ?? s.deploymentName} -
+
{r.label && `${s.deploymentName} · `} {s.repoId} · +
- {s.runtimeName} + + {s.runtimeName} + {configChips(s).map((c) => ( - + {c} ))}
-
{describeSettings(r.settings)}
+
+ {describeSettings(r.settings)} +
- {fmt(h.decode)} - {h.ttftMs != null ? `${Math.round(h.ttftMs)} ms` : "–"} - + + {fmt(h.decode)} + + + {h.ttftMs != null ? `${Math.round(h.ttftMs)} ms` : "–"} + + {fmt(h.prefill?.tps, 0)} - + {fmt(h.peak?.tps)} - + ); diff --git a/src/app/(app)/benchmarks/sweeps/[id]/sweep-detail.tsx b/src/app/(app)/benchmarks/sweeps/[id]/sweep-detail.tsx index 7398321..5f95d14 100644 --- a/src/app/(app)/benchmarks/sweeps/[id]/sweep-detail.tsx +++ b/src/app/(app)/benchmarks/sweeps/[id]/sweep-detail.tsx @@ -9,6 +9,8 @@ import { BarChart } from "@/components/bar-chart"; import { BenchmarkStateBadge } from "@/components/benchmark-state"; import { Button, buttonVariants } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { AgentApprovalBar } from "@/components/approval-bar"; +import { RequestedByBadge } from "@/components/requested-by-badge"; import { metaRows } from "@/lib/benchmark-meta"; import { describeSettings, headline } from "@/lib/benchmark-view"; import type { benchmarkSweeps, BenchmarkSummary, ResourceStats, RunMeta, SweepVariant } from "@/lib/db/schema"; @@ -90,7 +92,7 @@ export function SweepDetail({ initial }: { initial: SweepData }) { const [data, setData] = useState(initial); const [busy, setBusy] = useState(false); const { sweep } = data; - const active = sweep.state === "queued" || sweep.state === "running"; + const active = sweep.state === "pending_approval" || sweep.state === "queued" || sweep.state === "running"; useEffect(() => { if (!active) return; @@ -153,6 +155,7 @@ export function SweepDetail({ initial }: { initial: SweepData }) {

+ {runIds.length >= 2 && ( @@ -179,6 +182,13 @@ export function SweepDetail({ initial }: { initial: SweepData }) { {done} of {rows.length} variants finished. Each variant is deployed, benchmarked and removed again, one after another.

)} + {sweep.state === "pending_approval" && ( + `${p.key}: ${p.values.join(", ")}`).join("; ")}${sweep.timeLimitS ? `, at most ${Math.round(sweep.timeLimitS / 60)} min` : ""}); each variant is deployed, benchmarked and removed`} + base={`/api/sweeps/${sweep.id}`} + /> + )} {sweep.error &&

{sweep.error}

} {finished.length > 0 && ( diff --git a/src/app/(app)/deployments/[id]/deployment-detail.tsx b/src/app/(app)/deployments/[id]/deployment-detail.tsx index 46cfc85..29da38a 100644 --- a/src/app/(app)/deployments/[id]/deployment-detail.tsx +++ b/src/app/(app)/deployments/[id]/deployment-detail.tsx @@ -1,6 +1,9 @@ "use client"; -import { ExternalLinkIcon, PencilIcon, PlayIcon, SendIcon, SquareIcon, Trash2Icon } from "lucide-react"; +import { ExternalLinkIcon, PencilIcon, PlayIcon, SendIcon, ShieldCheckIcon, ShieldIcon, SquareIcon, Trash2Icon } from "lucide-react"; +import { toast } from "sonner"; +import { AgentApprovalBar } from "@/components/approval-bar"; +import { RequestedByBadge } from "@/components/requested-by-badge"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; @@ -83,6 +86,13 @@ export function DeploymentDetail({ initial, benchmarks }: { initial: Deployment;

{d.name}

+ + {d.protected && ( + + + protected + + )}

@@ -118,6 +128,19 @@ export function DeploymentDetail({ initial, benchmarks }: { initial: Deployment; Start )} + + {d.startRequestedAt && ( + + )} {d.state === "failed" && d.error && (

{d.error}
diff --git a/src/app/(app)/deployments/deployment-list.tsx b/src/app/(app)/deployments/deployment-list.tsx index a185cad..6ef7b63 100644 --- a/src/app/(app)/deployments/deployment-list.tsx +++ b/src/app/(app)/deployments/deployment-list.tsx @@ -1,9 +1,16 @@ "use client"; -import { ExternalLinkIcon, PlayIcon, RocketIcon, SquareIcon } from "lucide-react"; +import { + ExternalLinkIcon, + PlayIcon, + RocketIcon, + SquareIcon, +} from "lucide-react"; import Link from "next/link"; import { useEffect, useState } from "react"; import { DeploymentStateBadge } from "@/components/deployment-state"; +import { RequestedByBadge } from "@/components/requested-by-badge"; +import { NativeSelect } from "@/components/ui/native-select"; import { Button, buttonVariants } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { useHostname, webUiUrl } from "@/hooks/use-hostname"; @@ -12,23 +19,45 @@ import { formatBytes } from "@/lib/format"; import { quantGroup } from "@/lib/selection"; import { startDeployment, stopDeployment } from "./actions"; -type Row = Omit & { +type Row = Omit< + DeploymentRow, + "startedAt" | "readyAt" | "stoppedAt" | "createdAt" +> & { startedAt: string | null; readyAt: string | null; stoppedAt: string | null; createdAt: string; }; -const isActive = (r: Row) => r.desiredState === "running" || r.state === "starting" || r.state === "running" || r.state === "stopping"; +const isActive = (r: Row) => + r.desiredState === "running" || + r.state === "starting" || + r.state === "running" || + r.state === "stopping"; /** Live list (polls every 2 s while something is starting/stopping, else every 5 s). */ export function DeploymentList({ rows: initial }: { rows: Row[] }) { const [rows, setRows] = useState(initial); + // "" = everything, "-" = created in the UI, else a token name. + const [by, setBy] = useState(""); + const tokens = [ + ...new Set(rows.map((r) => r.requestedBy).filter((x): x is string => !!x)), + ].sort(); + const shown = rows.filter( + (r) => !by || (by === "-" ? !r.requestedBy : r.requestedBy === by), + ); const hostname = useHostname(); - const busy = rows.some((r) => r.state === "starting" || r.state === "stopping" || (r.desiredState === "running") !== (r.state === "running")); + const busy = rows.some( + (r) => + r.state === "starting" || + r.state === "stopping" || + (r.desiredState === "running") !== (r.state === "running"), + ); async function reload() { - const res = await fetch("/api/deployments", { cache: "no-store" }).catch(() => null); + const res = await fetch("/api/deployments", { cache: "no-store" }).catch( + () => null, + ); if (res?.ok) setRows(await res.json()); } useEffect(() => { @@ -40,7 +69,10 @@ export function DeploymentList({ rows: initial }: { rows: Row[] }) { return ( -

No deployments yet. Pick a runtime and a downloaded model to start one.

+

+ No deployments yet. Pick a runtime and a downloaded model to start + one. +

New deployment @@ -49,59 +81,130 @@ export function DeploymentList({ rows: initial }: { rows: Row[] }) { } return ( -
- {rows.map((r) => { - const file = r.options.modelFile ? (quantGroup(r.options.modelFile) ?? r.options.modelFile) : null; - const loadSecs = r.readyAt && r.startedAt ? (new Date(r.readyAt).getTime() - new Date(r.startedAt).getTime()) / 1000 : null; - return ( - -
-
- - {r.name} - - - {r.repoId} - {file && ` · ${file}`} - {r.options.mmproj && " · vision"} - {r.options.draftFile && " · MTP/draft"} - - {r.runtimeName} +
+ {tokens.length > 0 && ( + + )} +
+ {shown.map((r) => { + const file = r.options.modelFile + ? (quantGroup(r.options.modelFile) ?? r.options.modelFile) + : null; + const loadSecs = + r.readyAt && r.startedAt + ? (new Date(r.readyAt).getTime() - + new Date(r.startedAt).getTime()) / + 1000 + : null; + return ( + +
+
+ + {r.name} + + + {r.repoId} + {file && ` · ${file}`} + {r.options.mmproj && " · vision"} + {r.options.draftFile && " · MTP/draft"} + + + {r.runtimeName} + + {r.protected && ( + + protected + + )} + {r.startRequestedAt && ( + + start awaits approval + + )} + +
+
- -
-
- - {r.state === "running" && r.stats - ? `CPU ${(r.stats.cpuPercent / 100).toFixed(1)} cores · RAM ${formatBytes(r.stats.memoryBytes)}${r.memoryMb ? ` / ${formatBytes(r.memoryMb * 2 ** 20)}` : ""}` - : r.state === "failed" - ? (r.error?.split("\n")[0] ?? "failed") - : `ctx ${r.options.contextSize}${r.memoryMb ? ` · ${formatBytes(r.memoryMb * 2 ** 20)} RAM` : ""}`} - {r.state === "running" && loadSecs != null && ` · loaded in ${loadSecs.toFixed(1)} s`} - - - {r.state === "running" && webUiUrl(r, hostname) && ( - - - Web UI - - )} - {isActive(r) ? ( - - ) : ( - - )} - -
- - ); - })} +
+ + ); + })} +
); } diff --git a/src/app/(app)/settings/api-tokens/page.tsx b/src/app/(app)/settings/api-tokens/page.tsx index 376503b..87b31e8 100644 --- a/src/app/(app)/settings/api-tokens/page.tsx +++ b/src/app/(app)/settings/api-tokens/page.tsx @@ -1,18 +1,27 @@ import type { Metadata } from "next"; +import { listActivity } from "@/lib/agent-activity"; import { listTokens } from "@/lib/api-tokens"; -import { getGuardrails } from "@/lib/settings"; +import { listRuntimes } from "@/lib/runtimes"; +import { getGuardrails, getTuning } from "@/lib/settings"; import { GuardrailSettings } from "./guardrail-settings"; import { TokenSettings } from "./token-settings"; +import { TuningSettings } from "./tuning-settings"; export const dynamic = "force-dynamic"; export const metadata: Metadata = { title: "API tokens · Settings" }; export default async function ApiTokenSettingsPage() { - const [tokens, guardrails] = await Promise.all([listTokens(), getGuardrails()]); + const [tokens, guardrails, tuning, runtimes] = await Promise.all([listTokens(), getGuardrails(), getTuning(), listRuntimes()]); + const activity = Object.fromEntries( + await Promise.all( + tokens.map(async (t) => [t.id, (await listActivity(t.id, 50)).map((a) => ({ ...a, createdAt: a.createdAt.toISOString() }))] as const), + ), + ); return (
- + + ({ id: r.id, name: r.name, pulled: r.imageState === "present" }))} />
); } diff --git a/src/app/(app)/settings/api-tokens/token-settings.tsx b/src/app/(app)/settings/api-tokens/token-settings.tsx index 80988eb..28aa5f6 100644 --- a/src/app/(app)/settings/api-tokens/token-settings.tsx +++ b/src/app/(app)/settings/api-tokens/token-settings.tsx @@ -1,6 +1,7 @@ "use client"; import { BotIcon, PlusIcon, Trash2Icon } from "lucide-react"; +import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { toast } from "sonner"; @@ -19,7 +20,13 @@ import { } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/components/ui/card"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { SCOPE_LABEL } from "@/lib/token-scopes"; @@ -27,25 +34,43 @@ import type { ApiTokenRow } from "@/lib/api-tokens"; import { TOKEN_SCOPES, type TokenScope } from "@/lib/db/schema"; /** Bearer tokens for /api/v1 (e.g. an AI agent). The token is shown once, then only its prefix. */ -export function TokenSettings({ tokens }: { tokens: ApiTokenRow[] }) { - const [created, setCreated] = useState<{ name: string; token: string } | null>(null); +export function TokenSettings({ + tokens, + activity, +}: { + tokens: ApiTokenRow[]; + activity: Record; +}) { + const [created, setCreated] = useState<{ + name: string; + token: string; + } | null>(null); return ( API tokens - For programs and agents calling Kaname's API at /api/v1 with{" "} - Authorization: Bearer <token>. No token can delete models or files, change settings, or manage runtimes and - tokens. + For programs and agents calling Kaname's API at{" "} + /api/v1 with{" "} + + Authorization: Bearer <token> + + . No token can delete models or files, change settings, or manage + runtimes and tokens. {created && (
-

Token “{created.name}” created. Copy it now: it is not shown again.

+

+ Token “{created.name}” created. Copy it now: it is not + shown again. +

- {created.token} + + {created.token} +
@@ -55,7 +80,7 @@ export function TokenSettings({ tokens }: { tokens: ApiTokenRow[] }) { ) : (
{tokens.map((t) => ( - + ))}
)} @@ -64,7 +89,11 @@ export function TokenSettings({ tokens }: { tokens: ApiTokenRow[] }) { ); } -function NewTokenForm({ onCreated }: { onCreated: (t: { name: string; token: string }) => void }) { +function NewTokenForm({ + onCreated, +}: { + onCreated: (t: { name: string; token: string }) => void; +}) { const router = useRouter(); const [name, setName] = useState(""); const [scopes, setScopes] = useState(["models:read"]); @@ -74,9 +103,16 @@ function NewTokenForm({ onCreated }: { onCreated: (t: { name: string; token: str e.preventDefault(); setBusy(true); try { - const res = await fetch("/api/api-tokens", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name, scopes }) }); + const res = await fetch("/api/api-tokens", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ name, scopes }), + }); const json = await res.json().catch(() => ({})); - if (!res.ok) return toast.error(json.error?.message ?? `Could not create the token (${res.status})`); + if (!res.ok) + return toast.error( + json.error?.message ?? `Could not create the token (${res.status})`, + ); onCreated({ name: name.trim().toLowerCase(), token: json.token }); setName(""); router.refresh(); @@ -86,93 +122,269 @@ function NewTokenForm({ onCreated }: { onCreated: (t: { name: string; token: str } return ( -
+
setName(e.target.value.toLowerCase().replace(/[^a-z0-9._-]/g, ""))} + onChange={(e) => + setName(e.target.value.toLowerCase().replace(/[^a-z0-9._-]/g, "")) + } placeholder="Name, e.g. hermes" aria-label="Token name" className="max-w-56" /> -
{TOKEN_SCOPES.map((s) => ( -
-

The name is shown as “requested by” on everything the token asks for.

+

+ The name is shown as “requested by” on everything the token + asks for. +

); } -function TokenRow({ token }: { token: ApiTokenRow }) { +function TokenRow({ + token, + activity, +}: { + token: ApiTokenRow; + activity: ActivityItem[]; +}) { const router = useRouter(); const revoked = !!token.revokedAt; + const [editing, setEditing] = useState(false); + const [scopes, setScopes] = useState(token.scopes); + const [showActivity, setShowActivity] = useState(false); + + async function saveScopes() { + const res = await fetch(`/api/api-tokens/${token.id}`, { + method: "PATCH", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ scopes }), + }); + const json = await res.json().catch(() => ({})); + if (!res.ok) + return void toast.error(json.error?.message ?? `Failed (${res.status})`); + toast.success(`Scopes of "${token.name}" changed`); + setEditing(false); + router.refresh(); + } async function act(method: "POST" | "DELETE") { const res = await fetch(`/api/api-tokens/${token.id}`, { method }); const json = await res.json().catch(() => ({})); if (!res.ok) toast.error(json.error?.message ?? `Failed (${res.status})`); - else toast.success(method === "POST" ? `Token "${token.name}" revoked` : `Token "${token.name}" deleted`); + else + toast.success( + method === "POST" + ? `Token "${token.name}" revoked` + : `Token "${token.name}" deleted`, + ); router.refresh(); } return ( -
- - {token.name} - {token.prefix}… - - {token.scopes.map((s) => ( - - {s} - - ))} - - {revoked && revoked} - - {token.lastUsedAt ? ( - <> - used - - ) : ( - "never used" +
+
+ + {token.name} + + {token.prefix}… + + + {token.scopes.map((s) => ( + + {s} + + ))} + + {revoked && revoked} + + {token.lastUsedAt ? ( + <> + used + + ) : ( + "never used" + )} + + {activity.length > 0 && ( + )} - - - }>{revoked ? : "Revoke"} - - - - {revoked ? "Delete" : "Revoke"} token “{token.name}”? - - - {revoked - ? "The entry goes away and the name can be used again. Models it requested keep their “requested by” label." - : "It stops working immediately. Downloads it already requested are not affected."} - - - - Cancel - act(revoked ? "DELETE" : "POST")}> - {revoked ? "Delete" : "Revoke"} - - - - + {!revoked && ( + + )} + + }> + {revoked ? : "Revoke"} + + + + + {revoked ? "Delete" : "Revoke"} token “{token.name} + ”? + + + {revoked + ? "The entry goes away and the name can be used again. Models it requested keep their “requested by” label." + : "It stops working immediately. Downloads it already requested are not affected."} + + + + Cancel + act(revoked ? "DELETE" : "POST")} + > + {revoked ? "Delete" : "Revoke"} + + + + +
+ {editing && ( +
+ {TOKEN_SCOPES.map((s) => ( + + ))} + +
+ )} + {showActivity && }
); } + +export type ActivityItem = { + id: string; + action: string; + targetType: string | null; + targetId: string | null; + outcome: string; + code: string | null; + message: string | null; + createdAt: string; +}; + +const TARGET_HREF: Record string> = { + deployment: (id) => `/deployments/${id}`, + benchmark: (id) => `/benchmarks/${id}`, + sweep: (id) => `/benchmarks/sweeps/${id}`, + model: (id) => `/models/${id}`, +}; + +/** What the token did, newest first: outcome, and the reason when a guardrail refused it. */ +function ActivityList({ items }: { items: ActivityItem[] }) { + return ( +
    + {items.map((a) => ( +
  • + + + + {a.action} + + {a.outcome === "refused" + ? `refused: ${a.code}` + : a.outcome === "pending_approval" + ? "awaiting approval" + : "ok"} + + {a.targetType && a.targetId && TARGET_HREF[a.targetType] && ( + + {a.targetType} + + )} + {a.message && ( + {a.message} + )} +
  • + ))} +
+ ); +} diff --git a/src/app/(app)/settings/api-tokens/tuning-settings.tsx b/src/app/(app)/settings/api-tokens/tuning-settings.tsx new file mode 100644 index 0000000..b7de594 --- /dev/null +++ b/src/app/(app)/settings/api-tokens/tuning-settings.tsx @@ -0,0 +1,166 @@ +"use client"; + +import { ShieldCheckIcon } 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 { Checkbox } from "@/components/ui/checkbox"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { NativeSelect } from "@/components/ui/native-select"; +import type { ApprovalMode } from "@/lib/agent-guardrails"; +import { DEFAULT_ALLOWED_ARGS, parseFlagList, type TuningGuardrails } from "@/lib/agent-tuning"; + +const intText = (s: string) => s.replace(/\D/g, ""); +const decText = (s: string) => s.replace(/[^\d.,]/g, ""); +const num = (s: string) => Number(s.replace(",", ".")); + +/** Limits for deployments, benchmark runs and sweeps requested through the API. */ +export function TuningSettings({ initial, runtimes }: { initial: TuningGuardrails; runtimes: { id: string; name: string; pulled: boolean }[] }) { + const router = useRouter(); + const [mode, setMode] = useState(initial.approvalMode); + const [maxDeps, setMaxDeps] = useState(String(initial.maxAgentDeployments)); + const [runMin, setRunMin] = useState(String(initial.maxRunMinutes)); + const [sweepMin, setSweepMin] = useState(String(initial.maxSweepMinutes)); + const [variants, setVariants] = useState(String(initial.maxSweepVariants)); + const [allowed, setAllowed] = useState(initial.allowedRuntimeIds); + const [llamaArgs, setLlamaArgs] = useState(initial.allowedArgs["llama.cpp"].join(" ")); + const [vllmArgs, setVllmArgs] = useState(initial.allowedArgs.vllm.join(" ")); + const [portFrom, setPortFrom] = useState(initial.hostPortRange ? String(initial.hostPortRange.from) : ""); + const [portTo, setPortTo] = useState(initial.hostPortRange ? String(initial.hostPortRange.to) : ""); + const [memGiB, setMemGiB] = useState(initial.maxMemoryMb ? String(Math.round((initial.maxMemoryMb / 1024) * 10) / 10) : ""); + const [cpus, setCpus] = useState(initial.maxCpus != null ? String(initial.maxCpus) : ""); + const [busy, setBusy] = useState(false); + + let argError: string | null = null; + let llama: string[] = []; + let vllm: string[] = []; + try { + llama = parseFlagList(llamaArgs); + vllm = parseFlagList(vllmArgs); + } catch (err) { + argError = err instanceof Error ? err.message : String(err); + } + + async function save(e: React.FormEvent) { + e.preventDefault(); + if (argError) return; + setBusy(true); + try { + const res = await fetch("/api/settings/tuning", { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + approvalMode: mode, + maxAgentDeployments: num(maxDeps), + maxRunMinutes: num(runMin), + maxSweepMinutes: num(sweepMin), + maxSweepVariants: num(variants), + allowedRuntimeIds: allowed, + allowedArgs: { "llama.cpp": llama, vllm }, + hostPortRange: portFrom && portTo ? { from: num(portFrom), to: num(portTo) } : null, + maxMemoryMb: memGiB ? Math.round(num(memGiB) * 1024) : null, + maxCpus: cpus ? num(cpus) : null, + }), + }); + const json = await res.json().catch(() => ({})); + if (!res.ok) return void toast.error(json.error?.message ?? `Could not save (${res.status})`); + toast.success("Guardrails saved"); + router.refresh(); + } finally { + setBusy(false); + } + } + + const field = (id: string, label: string, value: string, set: (v: string) => void, opts: { placeholder?: string; decimal?: boolean } = {}) => ( +
+ + set((opts.decimal ? decText : intText)(e.target.value))} inputMode={opts.decimal ? "decimal" : "numeric"} placeholder={opts.placeholder} /> +
+ ); + + return ( + + + + + Guardrails for API deployments and benchmarks + + + For tokens with the deployments and benchmarks scopes. Agents only change and benchmark deployments their own token created, never protected ones (the + shield on a deployment's page), and can't start anything that would crowd a running protected deployment out of VRAM. + + + +
+
+ + setMode(e.target.value as ApprovalMode)} className="max-w-md"> + + + +

Creating or editing a stopped deployment, stopping and deleting their own ones never needs approval.

+
+
+ {field("t-deps", "Agent deployments at once", maxDeps, setMaxDeps)} + {field("t-run", "Max minutes per run", runMin, setRunMin)} + {field("t-sweep", "Max minutes per sweep", sweepMin, setSweepMin)} + {field("t-var", "Max variants per sweep", variants, setVariants)} +
+

+ One agent run or sweep at a time, and no agent deployment starts while one is measured. Raise “deployments at once” to 2 for A/B runs. +

+
+ {field("t-mem", "Memory cap per deployment (GiB)", memGiB, setMemGiB, { placeholder: "host RAM", decimal: true })} + {field("t-cpu", "CPU cap (cores)", cpus, setCpus, { placeholder: "all cores", decimal: true })} + {field("t-pf", "Host ports from", portFrom, setPortFrom, { placeholder: "none" })} + {field("t-pt", "Host ports to", portTo, setPortTo, { placeholder: "none" })} +
+
+ +
+ {runtimes.map((r) => ( + + ))} +
+

None ticked: every runtime with a pulled image.

+
+ {( + [ + ["llama.cpp", llamaArgs, setLlamaArgs], + ["vllm", vllmArgs, setVllmArgs], + ] as const + ).map(([engine, value, set]) => ( +
+ +