AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-only- ..
- _clean.mjs
- acceptance.mjs
- ai-adapters.mjs
- ai-enqueue.mjs
- central.mjs
- deploy-flow.mjs
- external-vps.mjs
- fake-opencode.mjs
- gates.mjs
- immersive.mjs
- lower.mjs
- nexus.mjs
- oidc-core.mjs
- oidc-flow.mjs
- opencode-engine.mjs
- owner-auth.mjs
- proxy.mjs
- retake-landing.mjs
- rls.mjs
- run.mjs
- services.mjs
- shot-central.mjs
- tenant-isolation.mjs
- trusted-https.mjs
- web-shots.mjs
- with-derived.mjs
app/src/app/gateway/api/enroll/route.ts
1import crypto from "node:crypto";2import { asSystem, db, now } from "@/lib/db";3import { audit } from "@/lib/audit";4import { gatewayGate, gatewayUrl, jerr } from "@/lib/gateway";5import { sha } from "@/lib/cloud";6export const dynamic = "force-dynamic";7// Exchange a one-time enrollment token for a node credential. The UPDATE is atomic: a token can succeed exactly once, only before expiry, never for a revoked node.8export const POST = (req: Request) => asSystem(() => handle(req)); // identity is not known yet: explicit system scope for this bootstrap exchange9async function handle(req: Request) {10 const pre = await gatewayGate(); if (pre) return pre;11 const b = await req.json().catch(() => ({})); const token = String(b.token ?? ""); if (!/^zce_[0-9a-f]{48}$/.test(token)) return jerr(400, "malformed token");12 const secret = crypto.randomBytes(32).toString("hex");13 const hostname = String(b.hostname ?? "").slice(0, 80), os = String(b.os ?? "").slice(0, 80), ver = String(b.agentVersion ?? "").slice(0, 20); const ph = /^[A-Za-z0-9.-]{1,120}$|^[0-9a-fA-F:]{2,45}$/.test(String(b.publicHost ?? "")) ? String(b.publicHost) : null;14 const r = await db().prepare("UPDATE nodes SET enroll_used_at=?, enrolled_at=?, secret_hash=?, enroll_hash=NULL, hostname=?, os=?, agent_version=?, last_seen=?, public_host=? WHERE id=(SELECT id FROM nodes WHERE enroll_hash=? AND enroll_used_at IS NULL AND revoked_at IS NULL AND enroll_expires>?) RETURNING id,org_id").get(now(), now(), sha(secret), hostname, os, ver, Date.now(), ph, sha(token), Date.now()) as any;15 if (!r) { await audit("anonymous", "node.enroll.failed"); return jerr(401, "token invalid, expired or already used"); }16 const gate = await gatewayGate(r.org_id); if (gate) { await db().prepare("UPDATE nodes SET revoked_at=? WHERE id=?").run(now(), r.id); return gate; }17 await audit("node:" + r.id, "node.enrolled", r.id, { org: r.org_id, agent: ver });18 return Response.json({ nodeId: r.id, credential: `${r.id}.${secret}`, gatewayUrl: await gatewayUrl(), heartbeatSeconds: 15 });19}20
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 692573d on master.
Approval requests
None pending.