Deployments: API keys, deploy from the library, reorganized form

- Settings → API keys (generate or paste, show again, delete). Deployments with
  "Require an API key" get them via LLAMA_API_KEY / VLLM_API_KEY (--api-key for
  several vLLM keys); values are masked in the stored/shown command and in logs.
  The chat proxy sends a key.
- "Deploy" in the library and on the model page preselects the model and a
  runtime that can serve it; library rows and the model page link to the
  model's deployments.
- Deployment form: grouped launch options with flags next to labels, command in
  its own step, extra arguments as flag/value rows (runtime form too).
- Native selects follow the dark theme (color-scheme), fixing unreadable options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-06 12:28:25 +02:00
1 parent 66e6a8c4f7
commit ea1f18cc74
32 files changed
+2478 -183

No files matched your search

+21 -7
View File
@@ -4,10 +4,10 @@
import { stat } from "node:fs/promises";
import { join } from "node:path";
import { and, desc, eq, inArray, lt } from "drizzle-orm";
import { and, asc, desc, eq, inArray, lt } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { deploymentLogs, deployments, type LogStream, models, runtimes, workerState } from "@/lib/db/schema";
import { buildCommand, CONTAINER_MODELS_DIR, ENGINE_PORT, renderCommand } from "@/lib/deploy-command";
import { apiKeys, deploymentLogs, deployments, type LogStream, models, runtimes, workerState } from "@/lib/db/schema";
import { buildCommand, CONTAINER_MODELS_DIR, ENGINE_PORT, redactCommand, renderCommand } from "@/lib/deploy-command";
import { coreEnv } from "@/lib/env";
import { formatBytes } from "@/lib/format";
import { sanitizeLine } from "./job-log";
@@ -40,8 +40,17 @@ const slug = (s: string) =>
const followers = new Map<string, AbortController>();
const pending: { deploymentId: string; stream: LogStream; line: string; ts: Date }[] = [];
// API key values, refreshed every reconcile pass: hidden in every log line (vLLM prints its
// arguments, including --api-key, at startup).
let apiKeySecrets: string[] = [];
async function loadApiKeys(): Promise<string[]> {
apiKeySecrets = (await db().select({ key: apiKeys.key }).from(apiKeys).orderBy(asc(apiKeys.createdAt))).map((r) => r.key);
return apiKeySecrets;
}
function addLog(deploymentId: string, stream: LogStream, line: string) {
pending.push({ deploymentId, stream, line: sanitizeLine(line, [coreEnv().HF_TOKEN ?? ""]).slice(0, 4000), ts: new Date() });
pending.push({ deploymentId, stream, line: sanitizeLine(line, [coreEnv().HF_TOKEN ?? "", ...apiKeySecrets]).slice(0, 4000), ts: new Date() });
}
export async function flushDeploymentLogs(): Promise<void> {
@@ -127,7 +136,11 @@ async function start(c: DockerClient, d: Deployment) {
}
}
const cmd = buildCommand({ engine: runtime.engine, options: d.options, model, runtime });
const keys = d.options.requireApiKey ? await loadApiKeys() : [];
if (d.options.requireApiKey && keys.length === 0) return fail(d, "This deployment requires an API key, but there are none. Add one under Settings → API keys.");
const cmd = buildCommand({ engine: runtime.engine, options: d.options, model, runtime, apiKeys: keys });
// What Kaname shows and stores: never the key values.
const shown = redactCommand(cmd, keys);
const name = `kaname-${slug(d.name)}-${d.id.slice(-6).toLowerCase()}`;
const portKey = `${cmd.port}/tcp`;
const spec = {
@@ -153,7 +166,7 @@ async function start(c: DockerClient, d: Deployment) {
};
addLog(d.id, "system", `Starting ${runtime.name} (${runtime.image})`);
addLog(d.id, "system", `$ ${renderCommand(runtime.image, cmd)}`);
addLog(d.id, "system", `$ ${renderCommand(runtime.image, shown)}`);
try {
await c.removeContainer(name); // leftover from a crash
const created = await c.createContainer(name, spec);
@@ -162,7 +175,7 @@ async function start(c: DockerClient, d: Deployment) {
state: "starting",
containerId: created.Id,
containerName: name,
command: cmd.args,
command: shown.args,
imageId: image.Id,
startedAt: new Date(),
readyAt: null,
@@ -278,6 +291,7 @@ export async function reconcileDeployments(): Promise<void> {
if (!c || reconciling) return;
reconciling = true;
try {
await loadApiKeys();
for (const d of await db().select().from(deployments)) {
await reconcileOne(c, d).catch((err) => log.error(`deployment ${d.name}`, err));
}