mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 16:07:35 +01:00
* feat(settings): your own key builds, when you say so — a key marked for building reaches your private builder
Track 1, PR 6 of docs/architecture/private-builders.md.
- user_model_keys.for_building (migration 0123), off by default; one
switch per key in Settings → AI, offered only on keys that can drive an
agent CLI (config/build-engines.ts: Anthropic → ANTHROPIC_API_KEY for
Claude Code, OpenAI → Codex, xAI → Grok, Google → Gemini CLI) and only
to an account with a builder on the cloud.
- scripts/write-tenant-engines.ts (root on the box, from the reconcile
timer) opens the marked keys with the app's sealing secret and writes
them to /etc/loki/runners/<short>.env; a unit whose file changed is
drain-restarted, so the key reaches its next agent without ending a
session mid-task. No route ever returns an opened key.
- Records: changelog {#your-engine}; roadmap milestones ticked.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* fix(settings): the building switch sits in one row with its sentence
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* feat(engines): welcome builds, then the plan's, then your own — and capacity you can read
Track 2 (2.1, 2.2, 2.5) and Track 4.1 of docs/master-plan-2026-10.md.
- users.build_engine (migration 0124): "own" by default — the person's
sign-in or a key marked for building, never counted — or "loki": Loki's
key within WELCOME_BUILDS (3, config/welcome-changes.ts) and the plan's
PLAN_LIMITS.buildsMonthly (10 / 40 / 100). Every run records which
engine paid for it (payload.engine); welcome and plan builds are counted
from that marker. A dispatch past the last build is refused with the way
forward (code engine-exhausted), and the kickoff screen shows it with
one tap to Settings. Loki's welcome spending stops for everyone at
WELCOME_MONTHLY_CAP_CHF (20), at CHF_PER_USD, a hand-set rate.
- The box writes Loki's key (LOKI_BUILD_ENGINE_ANTHROPIC_KEY from the
app's env) into a tenant's unit only while they chose Loki's engine and
have builds left; otherwise their own marked keys.
- Settings → AI: "Your engine for building", one Segmented choice with the
numbers; /api/settings/build-engine. The kickoff's no-builder copy says
the operator switches a private builder on per account.
- System → Capacity: how long work waited for a builder in the last day
per channel (median, worst), this month's builds, tokens and cost per
account, and welcome spend against its cap.
- /pricing and the whitepaper (0.3.3) state the builds a month on Loki's
engine and the rule. Records: changelog {#welcome-changes}
{#capacity-card}; roadmap milestones ticked.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
* style(engines): format resolve.ts the way prettier wants it
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NZqZujmXpupVDC1Hi5Jbsx
---------
Co-authored-by: Claude <noreply@anthropic.com>
61 lines
2.6 KiB
TypeScript
61 lines
2.6 KiB
TypeScript
/**
|
|
* A person's own key builds only when they say so, and only through the
|
|
* variable the agent CLI reads. Run: npx tsx scripts/test/build-engines.ts
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { BUILD_ENGINES, buildEngineFor } from "../../src/config/build-engines";
|
|
import { VENDOR_IDS } from "../../src/config/model-vendors";
|
|
import { ENGINE_KEY_NAMES } from "../../src/lib/agent-execution/agent-env";
|
|
import { renderEnvFile } from "../../src/lib/tenant-engines-env";
|
|
|
|
const read = (p: string) => readFileSync(p, "utf8");
|
|
|
|
// Every build engine is a real vendor, and its variable passes the allowlist.
|
|
for (const e of BUILD_ENGINES) {
|
|
assert.ok((VENDOR_IDS as readonly string[]).includes(e.vendor), `${e.vendor} is a vendor`);
|
|
assert.ok(
|
|
(ENGINE_KEY_NAMES as readonly string[]).includes(e.env),
|
|
`${e.env} reaches an agent (agent-env.ts)`,
|
|
);
|
|
}
|
|
assert.equal(buildEngineFor("anthropic")?.env, "ANTHROPIC_API_KEY");
|
|
assert.equal(buildEngineFor("openrouter"), null, "a router key powers chat only");
|
|
assert.equal(buildEngineFor("custom"), null);
|
|
|
|
// Off by default; a key never leaves through a route.
|
|
assert.match(
|
|
read("src/db/schema/user-model-keys.ts"),
|
|
/forBuilding: boolean\("for_building"\)\.notNull\(\)\.default\(false\)/,
|
|
);
|
|
const route = read("src/app/api/settings/model/route.ts");
|
|
assert.match(route, /z\.object\(\{ vendor: Vendor, forBuilding: z\.boolean\(\) \}\)/, "one switch");
|
|
assert.doesNotMatch(route, /listBuildEngineKeys/, "no route opens the keys");
|
|
const queries = read("src/db/queries/user-model-keys.ts");
|
|
assert.match(
|
|
queries,
|
|
/if \(!buildEngineFor\(vendor\)\) return null;/,
|
|
"a chat-only vendor cannot be marked",
|
|
);
|
|
assert.match(queries, /const engine = row\.forBuilding \? buildEngineFor\(row\.vendor\) : null;/);
|
|
|
|
// The unit env file: the CLI's variable, quoted, nothing else.
|
|
assert.equal(renderEnvFile([]), "", "no keys, an empty file");
|
|
assert.equal(
|
|
renderEnvFile([
|
|
{ env: "OPENAI_API_KEY", value: "sk-o" },
|
|
{ env: "ANTHROPIC_API_KEY", value: 'a"b\\c' },
|
|
]),
|
|
'ANTHROPIC_API_KEY="a\\"b\\\\c"\nOPENAI_API_KEY="sk-o"\n',
|
|
);
|
|
// The box writes it as root and drain-restarts only the units that changed.
|
|
const reconcile = read("scripts/hetzner/reconcile-tenants.sh");
|
|
assert.match(reconcile, /write-tenant-engines\.ts/);
|
|
assert.match(reconcile, /drain-and-restart-runner\.sh" "loki-box-runner@\$\{short\}"/);
|
|
assert.match(
|
|
read("scripts/hetzner/loki-box-runner@.service"),
|
|
/^EnvironmentFile=-\/etc\/loki\/runners\/%i\.env$/m,
|
|
);
|
|
|
|
console.log("✓ build engines: your key, your switch, the CLI's own variable");
|