From 8b74fa69dbe33873c64abccc6bf17ea2ec08b82f Mon Sep 17 00:00:00 2001 From: Pascal Linxweiler Date: Tue, 6 Oct 2026 11:31:04 +0200 Subject: [PATCH] Deployments: serve a model with a runtime container - deployments + deployment_logs tables; desired/actual state reconciled by the worker (create/start/stop/remove via the socket proxy, /health wait, log follower, stats, memory guard, adopt/remove containers on restart). - Pure command builder for llama-server and vllm serve (mmproj, MTP draft, KV cache types, dtype, KV cache size) with tests; file candidates per engine with tests. - New main menu entry Deployments: list, new/edit form (runtime -> model and files -> launch options, live command preview), detail page with stats, log, endpoint and a streaming chat smoke test. Not yet tested end-to-end against real containers. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 18 + drizzle/0011_deployments.sql | 37 + drizzle/meta/0011_snapshot.json | 1477 +++++++++++++++++ drizzle/meta/_journal.json | 7 + .../deployments/[id]/deployment-detail.tsx | 402 +++++ src/app/(app)/deployments/[id]/edit/page.tsx | 26 + src/app/(app)/deployments/[id]/page.tsx | 17 + src/app/(app)/deployments/actions.ts | 15 + src/app/(app)/deployments/deployment-form.tsx | 520 ++++++ src/app/(app)/deployments/deployment-list.tsx | 97 ++ src/app/(app)/deployments/form-data.ts | 14 + src/app/(app)/deployments/new/page.tsx | 16 + src/app/(app)/deployments/page.tsx | 33 + src/app/api/deployments/[id]/chat/route.ts | 41 + src/app/api/deployments/[id]/logs/route.ts | 11 + src/app/api/deployments/[id]/route.ts | 32 + src/app/api/deployments/[id]/start/route.ts | 14 + src/app/api/deployments/[id]/stop/route.ts | 14 + src/app/api/deployments/route.ts | 20 + src/components/app-nav.tsx | 12 +- src/components/deployment-state.tsx | 23 + src/lib/db/schema.ts | 86 + src/lib/deploy-candidates.test.ts | 36 + src/lib/deploy-candidates.ts | 41 + src/lib/deploy-command.test.ts | 49 + src/lib/deploy-command.ts | 93 ++ src/lib/deployments.ts | 237 +++ src/lib/models.ts | 5 + src/lib/runtimes.ts | 5 + src/worker/deployments.ts | 313 ++++ src/worker/docker/client.ts | 106 ++ src/worker/index.ts | 10 + 32 files changed, 3824 insertions(+), 3 deletions(-) create mode 100644 drizzle/0011_deployments.sql create mode 100644 drizzle/meta/0011_snapshot.json create mode 100644 src/app/(app)/deployments/[id]/deployment-detail.tsx create mode 100644 src/app/(app)/deployments/[id]/edit/page.tsx create mode 100644 src/app/(app)/deployments/[id]/page.tsx create mode 100644 src/app/(app)/deployments/actions.ts create mode 100644 src/app/(app)/deployments/deployment-form.tsx create mode 100644 src/app/(app)/deployments/deployment-list.tsx create mode 100644 src/app/(app)/deployments/form-data.ts create mode 100644 src/app/(app)/deployments/new/page.tsx create mode 100644 src/app/(app)/deployments/page.tsx create mode 100644 src/app/api/deployments/[id]/chat/route.ts create mode 100644 src/app/api/deployments/[id]/logs/route.ts create mode 100644 src/app/api/deployments/[id]/route.ts create mode 100644 src/app/api/deployments/[id]/start/route.ts create mode 100644 src/app/api/deployments/[id]/stop/route.ts create mode 100644 src/app/api/deployments/route.ts create mode 100644 src/components/deployment-state.tsx create mode 100644 src/lib/deploy-candidates.test.ts create mode 100644 src/lib/deploy-candidates.ts create mode 100644 src/lib/deploy-command.test.ts create mode 100644 src/lib/deploy-command.ts create mode 100644 src/lib/deployments.ts create mode 100644 src/worker/deployments.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index acb5aa1..520d983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,24 @@ step 1 (Hugging Face downloader) is released as a minor version. ## [Unreleased] +### Added + +- **Deployments** (new main menu entry): serve a downloaded model with a runtime container. + - **New deployment:** pick a runtime (only pulled images), then a model it can serve (llama.cpp: + downloaded GGUF files with the quant, optional mmproj for vision and MTP head / draft model for + speculative decoding; vLLM: safetensors repos with a config.json), then launch options: context + size, threads, parallel slots, KV cache types, flash attention, batch sizes (llama.cpp) or data + type, max sequences, KV cache GiB (vLLM), CPU and memory limits (with an estimate), an optional + published host port and extra arguments. A live preview shows the exact `docker run` command. + - The worker starts the container on Kaname's Docker network with the models mounted read-only, + waits for `/health`, follows the log, samples CPU/RAM every 5 s and refuses to start when the + memory limits of running deployments wouldn't fit. Containers keep running across worker + restarts; orphaned ones are removed. + - Deployment page: state, load time, live CPU/RAM, endpoint URLs (Docker network and published + port), live log, start/stop/edit/delete, and a "Try it" chat that streams the answer and shows + time to first token and tokens/s. +- Models and runtimes used by a deployment can't be deleted until the deployment is. + ### Fixed - Image pulls showed "Starting · 0 B" until they finished: the worker's progress updates were never diff --git a/drizzle/0011_deployments.sql b/drizzle/0011_deployments.sql new file mode 100644 index 0000000..97ed499 --- /dev/null +++ b/drizzle/0011_deployments.sql @@ -0,0 +1,37 @@ +CREATE TABLE `deployment_logs` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `deployment_id` text NOT NULL, + `ts` integer NOT NULL, + `stream` text NOT NULL, + `line` text NOT NULL, + FOREIGN KEY (`deployment_id`) REFERENCES `deployments`(`id`) ON UPDATE no action ON DELETE no action +); +--> statement-breakpoint +CREATE INDEX `deployment_logs_idx` ON `deployment_logs` (`deployment_id`,`id`);--> statement-breakpoint +CREATE TABLE `deployments` ( + `id` text PRIMARY KEY NOT NULL, + `name` text NOT NULL, + `runtime_id` text NOT NULL, + `model_id` text NOT NULL, + `options` text NOT NULL, + `cpus` real, + `memory_mb` integer, + `host_port` integer, + `desired_state` text DEFAULT 'stopped' NOT NULL, + `state` text DEFAULT 'stopped' NOT NULL, + `delete_requested_at` integer, + `container_id` text, + `container_name` text, + `command` text, + `image_id` text, + `started_at` integer, + `ready_at` integer, + `stopped_at` integer, + `exit_code` integer, + `error` text, + `stats` text, + `created_at` integer NOT NULL, + `updated_at` integer NOT NULL, + FOREIGN KEY (`runtime_id`) REFERENCES `runtimes`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`model_id`) REFERENCES `models`(`id`) ON UPDATE no action ON DELETE no action +); diff --git a/drizzle/meta/0011_snapshot.json b/drizzle/meta/0011_snapshot.json new file mode 100644 index 0000000..6f46418 --- /dev/null +++ b/drizzle/meta/0011_snapshot.json @@ -0,0 +1,1477 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "4d24a2c4-682c-4a99-946f-ceb7fd1d1bae", + "prevId": "e8b2de90-0b1c-4264-93cd-886b041d5660", + "tables": { + "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 + }, + "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 + }, + "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 + }, + "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 + }, + "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 + }, + "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 a6143cb..d902789 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -78,6 +78,13 @@ "when": 1791242201063, "tag": "0010_runtimes", "breakpoints": true + }, + { + "idx": 11, + "version": "6", + "when": 1791278463453, + "tag": "0011_deployments", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/app/(app)/deployments/[id]/deployment-detail.tsx b/src/app/(app)/deployments/[id]/deployment-detail.tsx new file mode 100644 index 0000000..46ac574 --- /dev/null +++ b/src/app/(app)/deployments/[id]/deployment-detail.tsx @@ -0,0 +1,402 @@ +"use client"; + +import { PencilIcon, PlayIcon, SendIcon, SquareIcon, Trash2Icon } from "lucide-react"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { useEffect, useRef, useState, useSyncExternalStore } from "react"; +import { CopyButton } from "@/components/copy-button"; +import { DeploymentStateBadge } from "@/components/deployment-state"; +import { LocalTime } from "@/components/local-time"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@/components/ui/alert-dialog"; +import { Button, buttonVariants } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { Progress } from "@/components/ui/progress"; +import { ENGINE_PORT } from "@/lib/deploy-command"; +import type { DeploymentRow } from "@/lib/deployments"; +import { formatBytes, percent } from "@/lib/format"; +import { quantGroup } from "@/lib/selection"; +import { cn } from "@/lib/utils"; +import { deleteDeployment, startDeployment, stopDeployment } from "../actions"; + +type Deployment = Omit & { + startedAt: string | null; + readyAt: string | null; + stoppedAt: string | null; + createdAt: string; +}; +type LogLine = { id: number; ts: number; stream: string; line: string }; + +function Stat({ label, value, children }: { label: string; value: React.ReactNode; children?: React.ReactNode }) { + return ( +
+ {label} + {value} + {children} +
+ ); +} + +export function DeploymentDetail({ initial }: { initial: Deployment }) { + const router = useRouter(); + const [d, setD] = useState(initial); + const [now, setNow] = useState(() => Date.now()); + const active = d.desiredState === "running" || d.state === "starting" || d.state === "running" || d.state === "stopping"; + + useEffect(() => { + const t = setInterval(async () => { + setNow(Date.now()); + const res = await fetch(`/api/deployments/${d.id}`, { cache: "no-store" }).catch(() => null); + if (res?.status === 404) router.push("/deployments"); + else if (res?.ok) setD(await res.json()); + }, 2_000); + return () => clearInterval(t); + }, [d.id, router]); + + const file = d.options.modelFile ? (quantGroup(d.options.modelFile) ?? d.options.modelFile) : null; + const loadSecs = d.readyAt && d.startedAt ? (new Date(d.readyAt).getTime() - new Date(d.startedAt).getTime()) / 1000 : null; + const startingSecs = d.state === "starting" && d.startedAt ? Math.max(0, (now - new Date(d.startedAt).getTime()) / 1000) : null; + const port = ENGINE_PORT[d.engine]; + const internal = d.containerName ? `http://${d.containerName}:${port}/v1` : null; + // The browser's host name (null while rendering on the server, so hydration matches). + const hostname = useSyncExternalStore( + () => () => {}, + () => window.location.hostname, + () => null, + ); + const published = d.hostPort && hostname ? `http://${hostname}:${d.hostPort}/v1` : null; + + return ( +
+ + +
+
+

{d.name}

+ +
+

+ + {d.repoId} + + {file && ` · ${file}`} + {d.options.mmproj && " · vision"} + {d.options.draftFile && ` · ${d.options.draftType === "draft-mtp" ? "MTP" : "draft"}`} · {d.runtimeName} +

+ {d.runtimeImage} +
+
+ {active ? ( + + ) : ( + + )} + + + Edit + + + }> + + Delete + + + + Delete {d.name}? + The container is stopped and removed. The model files stay in the library. + + + Cancel + { + if (await deleteDeployment(d.id)) router.push("/deployments"); + }} + > + Delete + + + + +
+
+
+ + {d.state === "failed" && d.error && ( +
{d.error}
+ )} + +
+
+ + + + {d.cpus ? `limit ${d.cpus}` : "no limit"} + + + {d.stats && d.state === "running" && d.memoryMb ? ( + + ) : ( + {d.memoryMb ? `limit ${formatBytes(d.memoryMb * 2 ** 20)}` : "no limit"} + )} + + + until /health answered + + + + {d.engine === "vllm" ? `seqs ${d.options.maxNumSeqs ?? "default"}` : `slots ${d.options.parallel ?? "auto"}`} + + + + + + +
+ +
+ + + + Endpoint + + + {internal ? ( +
+ {internal} + +
+ ) : ( + Not started yet. + )} + On the Docker network, for Kaname and other containers. + {published && ( +
+ {published} + +
+ )} + + OpenAI-compatible; model name {d.repoId}. + +
+
+ + + Details + + +
+
Container
+
{d.containerName ?? "–"}
+
Started
+
+ +
+
Stopped
+
+ +
+ {d.command && ( + <> +
Arguments
+
+ {d.command.join(" ")} + +
+ + )} +
+
+
+
+
+
+ ); +} + +/** Live container log (polls new lines every 1.5 s). */ +function Logs({ id }: { id: string }) { + const [lines, setLines] = useState([]); + const box = useRef(null); + const stick = useRef(true); + + useEffect(() => { + let last = 0; + let stopped = false; + const load = async () => { + const res = await fetch(`/api/deployments/${id}/logs?after=${last}`, { cache: "no-store" }).catch(() => null); + if (!res?.ok || stopped) return; + const next: LogLine[] = await res.json(); + if (next.length === 0) return; + last = next[next.length - 1].id; + setLines((prev) => [...prev, ...next].slice(-2000)); + }; + void load(); + const t = setInterval(load, 1_500); + return () => { + stopped = true; + clearInterval(t); + }; + }, [id]); + + useEffect(() => { + if (stick.current && box.current) box.current.scrollTop = box.current.scrollHeight; + }, [lines]); + + return ( + + + Log + + +
{ + const el = e.currentTarget; + stick.current = el.scrollHeight - el.scrollTop - el.clientHeight < 40; + }} + className="h-96 overflow-auto rounded-lg bg-muted/50 px-3 py-2 font-mono text-[11px] leading-relaxed" + > + {lines.length === 0 ? ( + No output yet. + ) : ( + lines.map((l) => ( +
+ {l.line} +
+ )) + )} +
+
+
+ ); +} + +/** Smoke test over the OpenAI API: streams the answer and measures time to first token and speed. */ +function Chat({ id, running }: { id: string; running: boolean }) { + const [prompt, setPrompt] = useState("Write one sentence about the sea."); + const [answer, setAnswer] = useState(""); + const [busy, setBusy] = useState(false); + const [stats, setStats] = useState<{ ttft: number | null; total: number; tokens: number | null; promptTokens: number | null } | null>(null); + const [error, setError] = useState(null); + + async function send() { + setBusy(true); + setAnswer(""); + setError(null); + setStats(null); + const t0 = performance.now(); + let first: number | null = null; + let usage: { completion_tokens?: number; prompt_tokens?: number } | null = null; + let chunks = 0; + try { + const res = await fetch(`/api/deployments/${id}/chat`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ messages: [{ role: "user", content: prompt }], maxTokens: 256 }), + }); + if (!res.ok || !res.body) { + const body = await res.json().catch(() => ({})); + throw new Error(body.error?.message ?? `HTTP ${res.status}`); + } + const reader = res.body.pipeThrough(new TextDecoderStream()).getReader(); + let buf = ""; + for (;;) { + const { value, done } = await reader.read(); + if (done) break; + buf += value; + let nl: number; + while ((nl = buf.indexOf("\n")) >= 0) { + const line = buf.slice(0, nl).trim(); + buf = buf.slice(nl + 1); + if (!line.startsWith("data:")) continue; + const data = line.slice(5).trim(); + if (data === "[DONE]") continue; + const j = JSON.parse(data); + if (j.usage) usage = j.usage; + const delta: string = j.choices?.[0]?.delta?.content ?? j.choices?.[0]?.delta?.reasoning_content ?? ""; + if (delta) { + first ??= performance.now(); + chunks++; + setAnswer((a) => a + delta); + } + } + } + const total = (performance.now() - t0) / 1000; + setStats({ ttft: first ? (first - t0) / 1000 : null, total, tokens: usage?.completion_tokens ?? chunks, promptTokens: usage?.prompt_tokens ?? null }); + } catch (err) { + setError(err instanceof Error ? err.message : String(err)); + } finally { + setBusy(false); + } + } + + const genSecs = stats && stats.ttft != null ? stats.total - stats.ttft : null; + return ( + + + Try it + + +