import { sql } from "drizzle-orm"; import { index, integer, primaryKey, sqliteTable, text, uniqueIndex, } from "drizzle-orm/sqlite-core"; import { ulid } from "ulid"; import { BENCHMARK_KINDS, type BenchmarkPhase, BENCHMARK_STATES, ENDPOINT_ENGINES, type EndpointEngine, HUB_STATES, JOB_ERROR_CODES, JOB_FILE_STATES, JOB_KINDS, JOB_PURPOSES, JOB_STATES, LOG_STREAMS, MODEL_FILE_STATES, MODEL_STATUSES, PUBLICATION_STATES, type QualitySection, } from "./enums"; // The enum arrays live in ./enums (no dependencies), so client components can use them without // pulling drizzle-orm and every table definition into the browser bundle. export * from "./enums"; // Conventions (keep these when adding tables in later steps, they keep a Postgres port simple): // - Primary keys are ULID strings, generated in the app, never reused. // - Timestamps are integer milliseconds (mode "timestamp_ms"). // - Byte counts are integers (safe up to 2^53). // - Enums are text columns with a TS-level enum, not DB enums. // - Foreign keys are declared, but deletes cascade in app code: SQLite only enforces // FKs per connection with PRAGMA foreign_keys=ON, which libsql's pool doesn't guarantee. const id = () => text("id") .primaryKey() .$defaultFn(() => ulid()); const createdAt = () => integer("created_at", { mode: "timestamp_ms" }) .notNull() .$defaultFn(() => new Date()); const updatedAt = () => integer("updated_at", { mode: "timestamp_ms" }) .notNull() .$defaultFn(() => new Date()) .$onUpdateFn(() => new Date()); const ts = (name: string) => integer(name, { mode: "timestamp_ms" }); // --------------------------------------------------------------------------- // Models // --------------------------------------------------------------------------- export type UpdateDiffFile = { path: string; size: number; oldSize?: number }; export type UpdateDiff = { /** Commit the diff was computed against (the tracked revision's head on the Hub). */ sha: string; changed: UpdateDiffFile[]; added: UpdateDiffFile[]; removed: UpdateDiffFile[]; checkedAt: string; }; /** Outcome of a verify job, or extra instructions for a job (`removePaths` after an update). */ export type JobResult = { checked?: number; missing?: string[]; sizeMismatch?: string[]; hashMismatch?: string[]; /** Files in the model folder that aren't selected repo files. */ extra?: { path: string; size: number; inRepo: boolean }[]; /** Update jobs: files of the old revision to delete once the download succeeded. Remove jobs: the files to delete. */ removePaths?: string[]; /** Remove jobs: what was actually deleted. */ removed?: string[]; /** Delete jobs: files that were kept because they don't belong to the repo. */ kept?: string[]; }; export const models = sqliteTable( "models", { id: id(), repoType: text("repo_type", { enum: ["model"] }).notNull().default("model"), repoId: text("repo_id").notNull(), // "org/name" trackedRevision: text("tracked_revision").notNull().default("main"), pinnedSha: text("pinned_sha").notNull(), /** Relative to MODELS_DIR, e.g. "unsloth/Qwen3-27B-GGUF". */ localPath: text("local_path").notNull(), /** * Selection rule, applied to the repo's file list. Checkbox picks are stored as escaped * exact-path globs, so the same rule can be re-applied to a newer revision. */ includePatterns: text("include_patterns", { mode: "json" }) .$type() .notNull() .default(sql`'[]'`), excludePatterns: text("exclude_patterns", { mode: "json" }) .$type() .notNull() .default(sql`'[]'`), status: text("status", { enum: MODEL_STATUSES }).notNull().default("pending"), /** Latest SHA of trackedRevision seen on the Hub (update check). */ remoteSha: text("remote_sha"), lastCheckedAt: ts("last_checked_at"), lastCheckError: text("last_check_error"), /** Result of the last successful Hub check; null until checked. */ hubState: text("hub_state", { enum: HUB_STATES }), /** When the repo or pinned commit was first seen missing; cleared when it's back. */ hubMissingSince: ts("hub_missing_since"), /** What updating to `remoteSha` would change in the selection; null when up to date. */ updateDiff: text("update_diff", { mode: "json" }).$type(), lastVerifiedAt: ts("last_verified_at"), downloadedAt: ts("downloaded_at"), // Hub metadata (for search/filters), refreshed by the worker. Null until fetched. /** e.g. ["Qwen/Qwen3-8B"] (cardData.base_model, or base_model:* tags). */ baseModels: text("base_models", { mode: "json" }).$type(), /** How this model derives from its base: "quantized", "finetune", "adapter", "merge". */ baseRelation: text("base_relation"), /** Avatar of the repo's org/user on the Hub. */ authorAvatarUrl: text("author_avatar_url"), /** e.g. "qwen3" (gguf.architecture or config.model_type). */ architecture: text("architecture"), pipelineTag: text("pipeline_tag"), license: text("license"), /** Hub tags, minus noise like arxiv:/region:/deploy:. */ hubTags: text("hub_tags", { mode: "json" }).$type(), metadataFetchedAt: ts("metadata_fetched_at"), createdAt: createdAt(), updatedAt: updatedAt(), }, (t) => [uniqueIndex("models_repo_uq").on(t.repoType, t.repoId)], ); // --------------------------------------------------------------------------- // User tags (e.g. "roleplay", "security") // --------------------------------------------------------------------------- export const tags = sqliteTable( "tags", { id: id(), /** Display name as entered. */ name: text("name").notNull(), /** Lowercased, trimmed name; unique. */ slug: text("slug").notNull(), /** One of LABEL_COLORS; null = automatic color derived from the name. */ color: text("color"), createdAt: createdAt(), }, (t) => [uniqueIndex("tags_slug_uq").on(t.slug)], ); export const modelTags = sqliteTable( "model_tags", { modelId: text("model_id") .notNull() .references(() => models.id), tagId: text("tag_id") .notNull() .references(() => tags.id), createdAt: createdAt(), }, (t) => [primaryKey({ columns: [t.modelId, t.tagId] }), index("model_tags_tag_idx").on(t.tagId)], ); /** History of SHAs a model has been pinned to. */ export const modelRevisions = sqliteTable( "model_revisions", { id: id(), modelId: text("model_id") .notNull() .references(() => models.id), sha: text("sha").notNull(), pinnedAt: ts("pinned_at") .notNull() .$defaultFn(() => new Date()), supersededAt: ts("superseded_at"), }, (t) => [index("model_revisions_model_idx").on(t.modelId)], ); /** All files in the repo at the pinned SHA. `selected` marks what we keep locally. */ export const modelFiles = sqliteTable( "model_files", { id: id(), modelId: text("model_id") .notNull() .references(() => models.id), path: text("path").notNull(), size: integer("size").notNull(), /** Git blob SHA-1 from the Hub tree API. */ blobOid: text("blob_oid"), /** SHA-256 for LFS/Xet files (null for small git-stored files). */ lfsSha256: text("lfs_sha256"), selected: integer("selected", { mode: "boolean" }).notNull().default(false), state: text("state", { enum: MODEL_FILE_STATES }).notNull().default("pending"), checkedAt: ts("checked_at"), createdAt: createdAt(), updatedAt: updatedAt(), }, (t) => [uniqueIndex("model_files_model_path_uq").on(t.modelId, t.path)], ); // --------------------------------------------------------------------------- // Jobs (executed by the worker) // --------------------------------------------------------------------------- export const jobs = sqliteTable( "jobs", { id: id(), modelId: text("model_id") .notNull() .references(() => models.id), kind: text("kind", { enum: JOB_KINDS }).notNull(), purpose: text("purpose", { enum: JOB_PURPOSES }), targetSha: text("target_sha").notNull(), state: text("state", { enum: JOB_STATES }).notNull().default("queued"), attempt: integer("attempt").notNull().default(0), totalBytes: integer("total_bytes").notNull().default(0), doneBytes: integer("done_bytes").notNull().default(0), speedBps: integer("speed_bps"), etaSeconds: integer("eta_seconds"), exitCode: integer("exit_code"), errorCode: text("error_code", { enum: JOB_ERROR_CODES }), errorMessage: text("error_message"), result: text("result", { mode: "json" }).$type(), /** Set by the web app; the worker picks it up and stops the job. */ cancelRequestedAt: ts("cancel_requested_at"), startedAt: ts("started_at"), finishedAt: ts("finished_at"), createdAt: createdAt(), updatedAt: updatedAt(), }, (t) => [index("jobs_state_idx").on(t.state), index("jobs_model_idx").on(t.modelId)], ); export const jobFiles = sqliteTable( "job_files", { jobId: text("job_id") .notNull() .references(() => jobs.id), modelFileId: text("model_file_id") .notNull() .references(() => modelFiles.id), path: text("path").notNull(), expectedBytes: integer("expected_bytes").notNull(), doneBytes: integer("done_bytes").notNull().default(0), state: text("state", { enum: JOB_FILE_STATES }).notNull().default("pending"), }, (t) => [primaryKey({ columns: [t.jobId, t.modelFileId] })], ); export const jobLogs = sqliteTable( "job_logs", { id: integer("id").primaryKey({ autoIncrement: true }), jobId: text("job_id") .notNull() .references(() => jobs.id), ts: ts("ts") .notNull() .$defaultFn(() => new Date()), stream: text("stream", { enum: LOG_STREAMS }).notNull(), line: text("line").notNull(), }, (t) => [index("job_logs_job_idx").on(t.jobId, t.id)], ); // --------------------------------------------------------------------------- // App settings (key/value, edited on the Settings page) // --------------------------------------------------------------------------- export const settings = sqliteTable("settings", { key: text("key").primaryKey(), value: text("value", { mode: "json" }).notNull(), updatedAt: updatedAt(), }); // --------------------------------------------------------------------------- // Worker liveness // --------------------------------------------------------------------------- export const workerState = sqliteTable("worker_state", { id: text("id").primaryKey(), // "worker" /** Random per process; the row acts as a lease so only one worker runs at a time. */ instanceId: text("instance_id"), pid: integer("pid"), hfVersion: text("hf_version"), /** Free/total bytes on the filesystem holding MODELS_DIR (the web app has no access to it). */ modelsDirFreeBytes: integer("models_dir_free_bytes"), modelsDirTotalBytes: integer("models_dir_total_bytes"), startedAt: ts("started_at").notNull(), heartbeatAt: ts("heartbeat_at").notNull(), /** Set by the web app ("Rescan"); the worker scans MODELS_DIR when this is newer than its last scan. */ scanRequestedAt: ts("scan_requested_at"), /** The last scan of MODELS_DIR (scheduled, requested or at startup) and how many importable folders it found. */ lastScanAt: ts("last_scan_at"), lastScanFound: integer("last_scan_found"), }); /** A PCIe link: generation (1 = 2.5 GT/s … 6 = 64 GT/s) and lanes. */ export type PcieLink = { gen: number | null; width: number | null }; /** * Folders in MODELS_DIR (`/`, like `hf download --local-dir` layouts) that no model uses, * found by the worker's scan. Rewritten on every scan; the web app offers them for import. */ export const localFolders = sqliteTable("local_folders", { /** Relative to MODELS_DIR, e.g. "unsloth/Qwen3-8B-GGUF". */ path: text("path").primaryKey(), /** Files in the folder (without hf's .cache), capped. */ files: text("files", { mode: "json" }).$type<{ path: string; size: number }[]>().notNull(), fileCount: integer("file_count").notNull(), totalBytes: integer("total_bytes").notNull(), /** Commit from hf's download metadata, if the folder was written by `hf download`. */ commit: text("commit"), scannedAt: ts("scanned_at").notNull(), }); // --------------------------------------------------------------------------- // Before 0.15 Kaname ran the servers itself (runtimes, deployments). Benchmark runs from then keep // a snapshot of the deployment; these types describe it. // --------------------------------------------------------------------------- export type RuntimeEngine = "llama.cpp" | "vllm"; export type RuntimeAccelerator = "cpu" | "nvidia" | "dri" | "rocm"; /** A deployment's launch options (legacy). */ export type DeploymentOptions = { /** Model file (llama.cpp: the GGUF, first part of a split) or "" for the repo folder (vLLM). */ modelFile: string; /** llama.cpp: multimodal projector. */ mmproj?: string | null; /** llama.cpp: draft model (MTP head or a small draft model) for speculative decoding. */ draftFile?: string | null; draftType?: "draft-mtp" | "draft-simple" | null; contextSize: number; threads?: number | null; batchSize?: number | null; ubatchSize?: number | null; parallel?: number | null; cacheTypeK?: string | null; cacheTypeV?: string | null; flashAttn?: "auto" | "on" | "off" | null; /** llama.cpp: serve the built-in web UI at / (llama-server's default; false passes --no-webui). */ webui?: boolean | null; /** llama.cpp -cram: prompt cache in RAM, MiB (llama-server default 8192; 0 off, -1 unlimited). */ cacheRamMb?: number | null; /** NVIDIA: GPU UUIDs to use (null: all). */ gpus?: string[] | null; /** llama.cpp -ngl: "auto" (default), "all" or a number of layers. */ gpuLayers?: string | null; /** llama.cpp -sm across several GPUs. */ splitMode?: "none" | "layer" | "row" | "tensor" | null; /** llama.cpp -ts, e.g. "3,1". */ tensorSplit?: string | null; /** llama.cpp: keep all MoE expert weights in RAM (-cmoe) or those of the first N layers (-ncmoe). */ cpuMoe?: boolean | null; nCpuMoe?: number | null; /** vLLM --tensor-parallel-size and --gpu-memory-utilization. */ tensorParallel?: number | null; gpuMemoryUtilization?: number | null; /** Only accept requests with one of the API keys from Settings → API keys. */ requireApiKey?: boolean | null; /** vLLM */ dtype?: string | null; maxNumSeqs?: number | null; kvCacheGb?: number | null; extraArgs: string[]; }; // --------------------------------------------------------------------------- // Endpoints: OpenAI-compatible servers to benchmark (llama.cpp, vLLM, SGLang, …), run elsewhere // --------------------------------------------------------------------------- /** * What runs behind an endpoint, as the user describes it (Kaname can't see that machine). Copied into * every run; goes into BetterBench notes and launch80. Nothing here may identify the host. */ export type EndpointHardware = { gpuName?: string | null; gpuCount?: number | null; /** Per GPU. */ vramGb?: number | null; /** e.g. "Gen4 x16". */ pcie?: string | null; p2p?: "on" | "off" | "partial" | null; rebar?: boolean | null; gpuDriver?: string | null; cpu?: string | null; memoryGb?: number | null; os?: string | null; /** e.g. "Proxmox VM with GPU passthrough". */ virtualization?: string | null; /** Shown instead of the detected engine, e.g. "ik_llama.cpp". */ engineName?: string | null; engineVersion?: string | null; image?: string | null; quant?: string | null; kvCache?: string | null; contextSize?: number | null; /** Parallel slots / max sequences. */ concurrency?: number | null; /** Free text: launch flags, anything else worth knowing. */ description?: string | null; }; /** The last "Test connection" (or check before a run). */ export type EndpointProbe = { ok: boolean; at: string; error: string | null; latencyMs: number | null; /** Model names from /v1/models. */ models: string[]; engine: EndpointEngine | null; engineVersion: string | null; contextSize: number | null; slots: number | null; }; export const endpoints = sqliteTable( "endpoints", { id: id(), name: text("name").notNull(), /** Server root, e.g. "http://gpu-box:8080" (Kaname appends /v1). */ baseUrl: text("base_url").notNull(), /** Sent as a bearer token; never leaves the server (not shown, logged or put into a run). */ apiKey: text("api_key"), /** Model to benchmark; null: the only one the server lists. */ model: text("model"), /** null: detect from the server. */ engine: text("engine", { enum: ENDPOINT_ENGINES }), hardware: text("hardware", { mode: "json" }).$type().notNull().default(sql`'{}'`), probe: text("probe", { mode: "json" }).$type(), createdAt: createdAt(), updatedAt: updatedAt(), }, (t) => [uniqueIndex("endpoints_name_uq").on(t.name)], ); // --------------------------------------------------------------------------- // Benchmarks (BetterBench runs against an endpoint) // --------------------------------------------------------------------------- /** What a run measures. `passes`/`warmup` null: BetterBench's defaults (20 / 3), or 5 / 1 with quick. */ export type BenchmarkSettings = { quick: boolean; passes: number | null; warmup: number | null; phases: BenchmarkPhase[]; /** A/B: target minimum detectable effect in % (BetterBench --mde, default 1) and pair ceiling. */ mdePct?: number | null; maxPairs?: number | null; /** eval: which sections (empty: all). */ evalSections?: QualitySection[]; }; /** A quality eval's result: pass rates per section and the overall score (their mean), 0–100. */ export type QualityResult = { /** The eval set's version; only results of the same version are comparable. */ evalSet: string; score: number | null; sections: { section: QualitySection; passed: number; total: number; score: number | null; /** Why the section couldn't run (e.g. the server doesn't do tool calls); then it doesn't count. */ unsupported?: string | null; seconds: number; }[]; items: { section: QualitySection; id: string; pass: boolean; detail?: string | null }[]; config: { temperature: number; seed: number; thinking: boolean; contextTokens: number | null }; }; /** One side of a paired comparison, as BetterBench's paired_compare reports it. */ export type PairedResult = { metric: string; n_pairs: number; mean_a: number; mean_b: number; mean_diff: number; pct_diff: number; ci_low_pct: number; ci_high_pct: number; conf: number; significant: boolean; verdict: string; higher_is_better: boolean; }; /** `betterbench ab` result without the endpoints (raw per-pair series kept for the chart). */ export type AbSummary = { pairs: number; decode_tps: PairedResult; gap_median: PairedResult & { batched: boolean }; paired_cv: number; pairs_needed_for_mde: number; target_mde_pct: number; conf: number; maxPairs: number | null; raw: { a_tps: number[]; b_tps: number[] }; betterbenchVersion: string; corpusVersion: string; timestamp: string | null; config: { greedy?: boolean | null; temperature?: number | null; warmup?: number | null; unique_nonce?: boolean | null; ab_min_pairs?: number | null }; }; /** The endpoint as it was when the run started, so results stay comparable after edits. */ export type EndpointSnapshot = { type: "endpoint"; endpointName: string; /** The model name sent to the server (what /v1/models lists). */ model: string; engine: EndpointEngine | null; engineVersion: string | null; contextSize: number | null; /** Parallel slots the server reported (llama.cpp). */ slots?: number | null; hardware: EndpointHardware; }; /** Runs before 0.15: the deployment Kaname ran, as it was when the run started. */ export type DeploymentSnapshot = { type?: "deployment"; deploymentName: string; repoId: string; runtimeName: string; engine: RuntimeEngine; accelerator?: RuntimeAccelerator; /** Names of the GPUs used (NVIDIA), for comparisons. */ gpuNames?: string[]; /** The Docker host when the run started. */ host?: { cpuModel: string | null; threads: number | null; memoryBytes: number | null; os: string | null }; image: string; imageId: string | null; options: DeploymentOptions; cpus: number | null; memoryMb: number | null; /** Rendered command (API keys masked). */ command: string; }; export type BenchmarkSnapshot = EndpointSnapshot | DeploymentSnapshot; /** What was measured on what, recorded when a run starts (from the endpoint's hardware notes). */ export type RunMeta = { v: 1; gpus: { pciAddress?: string; name: string | null; vramMb: number | null; linkCurrent: PcieLink | null; linkMax: PcieLink | null; rebar: boolean | null }[]; /** * GPUs lower their link speed when idle: true once linkCurrent is the fastest link seen while the run * was under load (otherwise it is what detection saw, possibly idle). */ linkUnderLoad?: boolean; /** "n/a" with fewer than two GPUs; null = unknown. */ p2p: "on" | "off" | "partial" | "n/a" | null; /** On for every GPU used; null = unknown. */ rebar: boolean | null; runtime: { image: string; tag: string | null; digest: string | null; engine: string; engineName: string; engineVersion: string | null }; model: { repoId: string; file: string | null; quant: string | null; kvCache: string | null }; contextSize: number | null; /** Parallel slots (llama.cpp) or max sequences (vLLM); reported by the server where it can. */ concurrency: number | null; /** Runs before 0.15: fields taken from Settings → Hardware instead of detection. */ overridden: string[]; }; /** The host, as published: nothing that identifies it (no hostname, IP, user or path). */ export type SystemSummary = { cpu: { model: string | null; cores: number | null; threads: number | null }; memoryBytes: number | null; storage: { model: string | null; kind: "nvme" | "ssd" | "hdd" | "virtual" | null; sizeBytes: number | null } | null; os: string | null; kernel: string | null; gpuDrivers: string[]; virtualization: { vm: boolean | null; hypervisor: string | null; gpuPassthrough: boolean | null }; kaname: string; }; /** What the server reported about itself once ready (llama.cpp /props, vLLM /version and /v1/models). */ export type EngineInfo = { version: string | null; slots: number | null; contextSize: number | null; at: string }; /** * BetterBench's own report rows for a run (betterbench.report: single_rows, prefill_rows, * concurrency_rows, combined_score, sample_gate, …), copied as computed. Nothing in Kaname derives * or fills in a number; `null` means BetterBench didn't report it. The endpoint and host are never * stored. `v` 2; older summaries (no `v`) are recomputed by the worker from results.json. */ export type BenchmarkSummary = { v?: number; combined: { decode: number | null; ttft_p50: number | null; itl_low1: number | null; update_p50: number | null; update_p99: number | null } | null; single: { category: string; runs: number; tokens?: number; ttft_n?: number; gap_n?: number; ttft_p99_ok?: boolean; tail_ok?: boolean; ttft_p50: number | null; ttft_p99: number | null; update_p50?: number | null; update_p99?: number | null; tok_per_update: number | null; batched?: boolean; batched_runs?: number; decode_med: number | null; decode_iqr?: number | null; decode_cv: number | null; itl_low1: number | null; itl_med?: number | null; itl_high99?: number | null; }[]; prefill: { target_depth: number; skipped: boolean; prompt_tokens_med?: number | null; ttft_p50?: number | null; pp_low1?: number | null; pp_med?: number | null; pp_p99?: number | null; pp_n?: number; pp_tail_ok?: boolean; }[]; concurrency: { level: number; ok: number; requests: number; aggregate_tps: number; ttft_p50: number | null; ttft_p99: number | null; decode_med: number | null; ttft_n?: number; ttft_p99_ok?: boolean; }[]; /** Thinking models: share of reasoning tokens and time to first answer token, where detectable. */ reasoning?: { category: string; runs: number; known: number; answered: number; never_answered: number; reasoning_share: number | null; ttfa_p50: number | null }[]; /** Percentiles resting on fewer samples than n · tail ≥ 5 requires (BetterBench's sample gate). */ gate?: { section: string; key: string | number; metric: string; n: number; need: number }[]; /** [runs stopped at max_tokens, ok runs] in the single-stream set. */ truncated?: [number, number]; failedSingle?: number; phases: string[]; cacheHits: number; betterbenchVersion: string; corpusVersion: string; corpusHash?: string | null; timestamp?: string | null; maxModelLen?: number | null; config?: { warmup?: number | null; runs_per_category?: number | null; temperature?: number | null; top_p?: number | null; top_k?: number | null; greedy?: boolean | null; unique_nonce?: boolean | null; weights?: Record | null; concurrency_levels?: number[] | null; concurrency_requests?: number | null; prefill_runs?: number | null; prefill_warmup?: number | null; prefill_max_tokens?: number | null; }; passes: number | null; quick: boolean; }; export const benchmarkRuns = sqliteTable( "benchmark_runs", { id: id(), /** Null once the endpoint is deleted; the snapshot keeps what was measured. */ endpointId: text("endpoint_id"), /** A/B: the second endpoint (B); `endpointId` is A. */ endpointBId: text("endpoint_b_id"), /** A downloaded model the endpoint serves (matched by repo id), if any. */ modelId: text("model_id"), tool: text("tool").notNull().default("betterbench"), settings: text("settings", { mode: "json" }).$type().notNull(), snapshot: text("snapshot", { mode: "json" }).$type().notNull(), /** Free-form label, e.g. "q8 KV cache". */ label: text("label"), state: text("state", { enum: BENCHMARK_STATES }).notNull().default("queued"), phase: text("phase"), cancelRequestedAt: ts("cancel_requested_at"), startedAt: ts("started_at"), finishedAt: ts("finished_at"), error: text("error"), summary: text("summary", { mode: "json" }).$type(), /** Files under BENCHMARKS_DIR//: results.json and results.html. */ hasReport: integer("has_report", { mode: "boolean" }).notNull().default(false), kind: text("kind", { enum: BENCHMARK_KINDS }).notNull().default("run"), snapshotB: text("snapshot_b", { mode: "json" }).$type(), ab: text("ab", { mode: "json" }).$type(), /** kind "eval": the quality eval's result. */ quality: text("quality", { mode: "json" }).$type(), /** Hardware, runtime and model facts (A, and B of an A/B), recorded at the start. */ meta: text("meta", { mode: "json" }).$type(), metaB: text("meta_b", { mode: "json" }).$type(), system: text("system", { mode: "json" }).$type(), /** Free text by the user; passed to BetterBench and launch80 with the system summary. */ description: text("description"), createdAt: createdAt(), }, (t) => [index("benchmark_runs_created_idx").on(t.createdAt)], ); export const benchmarkLogs = sqliteTable( "benchmark_logs", { id: integer("id").primaryKey({ autoIncrement: true }), runId: text("run_id").notNull(), ts: integer("ts", { mode: "timestamp_ms" }).notNull(), stream: text("stream", { enum: LOG_STREAMS }).notNull(), line: text("line").notNull(), }, (t) => [index("benchmark_logs_idx").on(t.runId, t.id)], ); // --------------------------------------------------------------------------- // launch80 publications (double opt-in: a dry-run preview, then an explicit confirmation) // --------------------------------------------------------------------------- export const benchmarkPublications = sqliteTable( "benchmark_publications", { id: id(), runId: text("run_id").notNull(), state: text("state", { enum: PUBLICATION_STATES }).notNull().default("preview"), template: text("template").notNull().default("bench.betterbench.v1"), title: text("title"), summary: text("summary"), /** Size of the exact payload from the dry run; the payload itself is a file next to the run. */ payloadBytes: integer("payload_bytes"), previewedAt: ts("previewed_at"), /** Who confirmed publishing (the second opt-in), and when. */ confirmedBy: text("confirmed_by"), confirmedAt: ts("confirmed_at"), url: text("url"), guid: text("guid"), publishedAt: ts("published_at"), error: text("error"), createdAt: createdAt(), }, (t) => [index("benchmark_publications_run_idx").on(t.runId)], );