"use client"; import { CheckCircle2Icon, Loader2Icon, PlugZapIcon, SaveIcon, XCircleIcon } 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 { NativeSelect } from "@/components/ui/native-select"; import { ENGINE_LABEL } from "@/lib/benchmark-meta"; import { ENDPOINT_ENGINES } from "@/lib/db/enums"; import type { EndpointHardware, EndpointProbe } from "@/lib/db/schema"; import type { EndpointView } from "@/lib/endpoints"; type Field = { key: keyof EndpointHardware; label: string; placeholder?: string; kind?: "number" | "int"; hint?: string }; const GROUPS: { title: string; hint: string; fields: Field[] }[] = [ { title: "GPU", hint: "Leave empty for a CPU-only server.", fields: [ { key: "gpuName", label: "GPU", placeholder: "NVIDIA GeForce RTX 4090" }, { key: "gpuCount", label: "Count", placeholder: "1", kind: "int" }, { key: "vramGb", label: "VRAM per GPU (GB)", placeholder: "24", kind: "number" }, { key: "pcie", label: "PCIe link", placeholder: "Gen4 x16" }, { key: "gpuDriver", label: "Driver", placeholder: "nvidia 580.82" }, ], }, { title: "Machine", hint: "Only facts like these are published, never host names or addresses.", fields: [ { key: "cpu", label: "CPU", placeholder: "AMD EPYC 7282" }, { key: "memoryGb", label: "RAM (GB)", placeholder: "128", kind: "number" }, { key: "os", label: "OS", placeholder: "Debian 13" }, { key: "virtualization", label: "Virtualization", placeholder: "Proxmox VM with GPU passthrough, or bare metal" }, ], }, { title: "Server", hint: "What the server runs. Empty fields are taken from what it reports where it can.", fields: [ { key: "engineName", label: "Engine name", placeholder: "ik_llama.cpp (default: detected)" }, { key: "engineVersion", label: "Engine version", placeholder: "default: detected" }, { key: "image", label: "Container image", placeholder: "ghcr.io/ggml-org/llama.cpp:server-cuda" }, { key: "quant", label: "Quant", placeholder: "Q4_K_M (default: from the model name)" }, { key: "kvCache", label: "KV cache type", placeholder: "q8_0" }, { key: "contextSize", label: "Context (tokens)", placeholder: "default: reported", kind: "int" }, { key: "concurrency", label: "Parallel slots", placeholder: "4", kind: "int" }, ], }, ]; const toText = (v: unknown) => (v == null ? "" : String(v)); /** Create or edit an endpoint. The API key is never sent to the browser: on edit it can be kept, replaced or removed. */ export function EndpointForm({ initial }: { initial?: EndpointView }) { const router = useRouter(); const [name, setName] = useState(initial?.name ?? ""); const [baseUrl, setBaseUrl] = useState(initial?.baseUrl ?? ""); const [apiKey, setApiKey] = useState(""); const [removeKey, setRemoveKey] = useState(false); const [model, setModel] = useState(initial?.model ?? ""); const [engine, setEngine] = useState(initial?.engine ?? ""); const [hw, setHw] = useState>(() => Object.fromEntries(Object.entries(initial?.hardware ?? {}).map(([k, v]) => [k, typeof v === "boolean" ? (v ? "on" : "off") : toText(v)])), ); const [probe, setProbe] = useState(initial?.probe ?? null); const [testing, setTesting] = useState(false); const [saving, setSaving] = useState(false); const fields = GROUPS.flatMap((g) => g.fields); function body() { const hardware: Record = {}; for (const f of fields) { const v = (hw[f.key] ?? "").trim(); if (!v) continue; hardware[f.key] = f.kind ? Number(v.replace(",", ".")) : v; } if (hw.p2p) hardware.p2p = hw.p2p; if (hw.rebar) hardware.rebar = hw.rebar === "on"; if (hw.description?.trim()) hardware.description = hw.description.trim(); return { name, baseUrl, // Left out: keep the stored key. "": remove it. ...(apiKey.trim() ? { apiKey: apiKey.trim() } : removeKey || !initial ? { apiKey: "" } : {}), model: model.trim() || null, engine: engine || null, hardware, }; } async function test() { setTesting(true); try { const res = await fetch(initial ? `/api/endpoints/${initial.id}/test` : "/api/endpoints/test", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body()), }); const json = await res.json().catch(() => ({})); if (!res.ok) return toast.error(json.error?.message ?? `Test failed (${res.status})`); setProbe(json); if (json.ok && !model && json.models.length === 1) setModel(json.models[0]); } finally { setTesting(false); } } async function save(e: React.FormEvent) { e.preventDefault(); setSaving(true); try { const res = await fetch(initial ? `/api/endpoints/${initial.id}` : "/api/endpoints", { method: initial ? "PATCH" : "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body()), }); const json = await res.json().catch(() => ({})); if (!res.ok) return toast.error(json.error?.message ?? `Could not save (${res.status})`); router.push(`/endpoints/${json.id}`); router.refresh(); } finally { setSaving(false); } } const set = (key: string) => (e: React.ChangeEvent) => setHw((cur) => ({ ...cur, [key]: e.target.value })); const models = probe?.ok ? probe.models : []; return (
Connection Any OpenAI-compatible server: llama.cpp, vLLM, SGLang, Ollama, … Kaname talks to it from its own server.
{probe && }
Hardware notes Kaname can't see the machine behind an endpoint. What you enter here goes into every run, its BetterBench notes and launch80 reports, so results stay comparable. {GROUPS.map((g) => (
{g.title}

{g.hint}

{g.fields.map((f) => ( ))} {g.title === "GPU" && ( <> )}
))}