Skip to content
  1. Home
  2. workspace
Checking…
Demo view — sanitized data only. Sign in over HTTPS to create projects and manage the workspace.

AI Engineering Workspace

Partial

Chat, 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

app/src/app/api/central/route.ts

1import { asSystem, db, now, setSetting, uid } from "@/lib/db";
2import { platform, auditT } from "@/lib/tenant";
3import { contract, integrationStatus } from "@/lib/central";
4import { ADAPTERS, ORG_CLASSES } from "@/lib/central-core.mjs";
5export const dynamic = "force-dynamic";
6export async function GET() {
7 const g = await platform(); if (g.res) return g.res;
8 return Response.json({ integrations: await integrationStatus(), contract: await contract(), outbox: await db().prepare("SELECT status, COUNT(*) n FROM central_outbox GROUP BY status").all().catch(() => []) });
9}
10// Platform administration of mappings / classes / entitlements / endpoints. Every change is audited; nothing contacts Zoo Central.
11export async function POST(req: Request) {
12 const g = await platform({ write: true }); if (g.res) return g.res; const ctx = g.ctx; const b = await req.json().catch(() => ({})); const d = db();
13 switch (b.action) {
14 case "setOrgClass": {
15 if (!ORG_CLASSES.includes(b.class)) return Response.json({ error: "invalid class" }, { status: 422 });
16 const o = await d.prepare("SELECT id,protected FROM organizations WHERE id=?").get(String(b.orgId)) as any; if (!o) return Response.json({ error: "not found" }, { status: 404 });
17 if (o.protected && b.class !== "internal") return Response.json({ error: "the protected Zoo organization stays internal" }, { status: 409 });
18 if (b.class === "internal" && b.confirm !== "MARK INTERNAL") return Response.json({ error: 'type "MARK INTERNAL" — internal organizations may receive internal-application entitlements' }, { status: 422 });
19 if (b.class === "customer") await d.prepare("DELETE FROM app_entitlements WHERE org_id=?").run(o.id);
20 await d.prepare("UPDATE organizations SET org_class=? WHERE id=?").run(b.class, o.id); await auditT(ctx, "central.org_class", o.id, { class: b.class }); return Response.json({ ok: true });
21 }
22 case "mapOrg": {
23 const ref = String(b.centralRef ?? ""); if (!/^[A-Za-z0-9_.:-]{3,80}$/.test(ref)) return Response.json({ error: "invalid reference" }, { status: 422 });
24 if (!(await d.prepare("SELECT 1 FROM organizations WHERE id=?").get(String(b.orgId)))) return Response.json({ error: "not found" }, { status: 404 });
25 try { await d.prepare("DELETE FROM org_mappings WHERE org_id=?").run(String(b.orgId)); await d.prepare("INSERT INTO org_mappings(id,org_id,central_ref,created_by,created_at) VALUES(?,?,?,?,?)").run(uid("map_"), String(b.orgId), ref, ctx.email, now()); } catch { return Response.json({ error: "that reference is already mapped" }, { status: 409 }); }
26 await auditT(ctx, "central.map_org", String(b.orgId), { ref }); return Response.json({ ok: true });
27 }
28 case "grant": {
29 const key = String(b.appKey ?? ""); if (!/^[a-z0-9-]{2,40}$/.test(key)) return Response.json({ error: "invalid application key" }, { status: 422 });
30 try { await d.prepare("INSERT INTO app_entitlements(id,org_id,user_id,app_key,granted_by,created_at) VALUES(?,?,?,?,?,?) ON CONFLICT(org_id,user_id,app_key) DO NOTHING").run(uid("ent_"), String(b.orgId), String(b.userId), key, ctx.email, now()); }
31 catch (e) { return Response.json({ error: String((e as Error).message).slice(0, 140) }, { status: 409 }); }
32 await auditT(ctx, "central.grant", String(b.userId), { app: key, target_org: String(b.orgId) }); return Response.json({ ok: true });
33 }
34 case "revoke": { await d.prepare("DELETE FROM app_entitlements WHERE org_id=? AND user_id=? AND app_key=?").run(String(b.orgId), String(b.userId), String(b.appKey)); await auditT(ctx, "central.revoke", String(b.userId), { app: String(b.appKey) }); return Response.json({ ok: true }); }
35 case "endpoint": { // operator-configured Central endpoint for one adapter. Stored only; the probe/delivery worker is not built, so the state becomes at most "ready-untested".
36 if (!ADAPTERS.some(a => a.id === b.adapter)) return Response.json({ error: "unknown adapter" }, { status: 422 });
37 const u = String(b.url ?? ""); if (u && !/^https:\/\/[a-z0-9.-]+(:\d+)?(\/[\w./-]*)?$/i.test(u)) return Response.json({ error: "https URL required" }, { status: 422 });
38 await setSetting(`central.endpoint.${b.adapter}`, u); await auditT(ctx, "central.endpoint", String(b.adapter), { set: !!u }); return Response.json({ ok: true });
39 }
40 default: return Response.json({ error: "unknown action" }, { status: 422 });
41 }
42}
43

Conversation

Partial
Sign in to start AI sessions.

Task checklist

  • Application shell deployed
  • Persistent projects
  • Agent runtime
  • Sandboxed terminal

Execution activity

No agent sessions. Git HEAD fb22adb on master.

Approval requests

None pending.