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/api/cloud/team/route.ts
1import { db, asSystem } from "@/lib/db";2import { auditT, hashToken, ROLES, ROLE_LEVEL, tenant, type Role } from "@/lib/tenant";3import { newToken, uid, now } from "@/lib/cloud";4export const dynamic = "force-dynamic";5export async function GET() {6 const g = await tenant("viewer"); if (g.res) return g.res;7 return Response.json({ members: await db().prepare("SELECT u.id,u.email,u.name,u.status,m.role FROM memberships m JOIN users u ON u.id=m.user_id WHERE m.org_id=? ORDER BY m.created_at").all(g.ctx.orgId) });8}9// Add a member (creates the account if the email is new). The personal access token is returned ONCE; only its hash is stored (dev-only until Zoo IAM).10export async function POST(req: Request) {11 const g = await tenant("admin", { write: true }); if (g.res) return g.res; const ctx = g.ctx; const b = await req.json().catch(() => ({}));12 const email = String(b.email ?? "").trim().toLowerCase(), name = String(b.name ?? "").trim() || email.split("@")[0], role = String(b.role ?? "") as Role;13 if (!/^[^\s@]{1,64}@[^\s@]{1,190}\.[^\s@]{2,}$/.test(email)) return Response.json({ error: "valid email required" }, { status: 422 });14 if (!ROLES.includes(role)) return Response.json({ error: "invalid role" }, { status: 422 });15 if (b.mode === "invite") { // Zoo IAM invitation: bound to the invited VERIFIED e-mail, 7 days, grants only this role in THIS organization16 if (ROLE_LEVEL[role] > ROLE_LEVEL[ctx.role]) return Response.json({ error: "cannot grant a role above your own" }, { status: 403 });17 const iid = uid("inv_"); await db().prepare("INSERT INTO invitations(id,org_id,email,role,created_by,created_at,expires_at) VALUES(?,?,?,?,?,?,?)").run(iid, ctx.orgId, email, role, ctx.email, now(), Date.now() + 7 * 86400_000);18 await auditT(ctx, "team.invite", iid, { role }); return Response.json({ id: iid, note: "Accepted automatically when this person signs in through Zoo IAM with this verified e-mail." }, { status: 201 });19 }20 if (ROLE_LEVEL[role] > ROLE_LEVEL[ctx.role]) return Response.json({ error: "cannot grant a role above your own" }, { status: 403 });21 let token: string | undefined; // account lookup/creation is an explicit identity operation (users are global; tenants cannot read non-members)22 let u = await asSystem(() => db().prepare("SELECT id,platform_admin FROM users WHERE email=?").get(email)) as any;23 if (u?.platform_admin) return Response.json({ error: "that account is a platform administrator" }, { status: 409 });24 if (!u) { token = newToken("zcu"); const id = uid("usr_"); const tk = token; await asSystem(() => db().prepare("INSERT INTO users(id,email,name,token_hash,created_at) VALUES(?,?,?,?,?)").run(id, email, name.slice(0, 80), hashToken(tk), now())); u = { id }; }25 await db().prepare("INSERT INTO memberships(org_id,user_id,role,created_at) VALUES(?,?,?,?) ON CONFLICT(org_id,user_id) DO UPDATE SET role=excluded.role").run(ctx.orgId, u.id, role, now());26 await auditT(ctx, "team.add", u.id, { role }); return Response.json({ id: u.id, token, note: token ? "Shown once. Share securely." : "Existing account added; they sign in with their own token." }, { status: 201 });27}28export async function PATCH(req: Request) { // change role / remove member29 const g = await tenant("admin", { write: true }); if (g.res) return g.res; const ctx = g.ctx; const b = await req.json().catch(() => ({})); const uidv = String(b.userId ?? "");30 const m = await db().prepare("SELECT role FROM memberships WHERE org_id=? AND user_id=?").get(ctx.orgId, uidv) as any; if (!m) return Response.json({ error: "not found" }, { status: 404 });31 const owners = Number((await db().prepare("SELECT COUNT(*) n FROM memberships WHERE org_id=? AND role='owner'").get(ctx.orgId) as any).n);32 if (ROLE_LEVEL[m.role as Role] > ROLE_LEVEL[ctx.role]) return Response.json({ error: "cannot modify a higher role" }, { status: 403 });33 if (b.remove) { if (m.role === "owner" && owners <= 1) return Response.json({ error: "cannot remove the last owner" }, { status: 409 }); await db().prepare("DELETE FROM memberships WHERE org_id=? AND user_id=?").run(ctx.orgId, uidv); await asSystem(() => db().prepare("DELETE FROM sessions WHERE user_id=? AND org_id=?").run(uidv, ctx.orgId)); await auditT(ctx, "team.remove", uidv); return Response.json({ ok: true }); }34 const role = String(b.role) as Role; if (!ROLES.includes(role) || ROLE_LEVEL[role] > ROLE_LEVEL[ctx.role]) return Response.json({ error: "invalid role" }, { status: 422 });35 if (m.role === "owner" && role !== "owner" && owners <= 1) return Response.json({ error: "cannot demote the last owner" }, { status: 409 });36 await db().prepare("UPDATE memberships SET role=? WHERE org_id=? AND user_id=?").run(role, ctx.orgId, uidv); await auditT(ctx, "team.role", uidv, { role }); return Response.json({ ok: true });37}38
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.