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- ..
- ai.ts
- apps.ts
- audit.ts
- auth.ts
- central-core.d.mts
- central-core.mjs
- central.ts
- cloud.ts
- config.ts
- crypto.ts
- db.ts
- design.ts
- engines.ts
- files.ts
- gates.ts
- gateway.ts
- marketplace-core.d.mts
- marketplace-core.mjs
- metrics.ts
- modules.ts
- motion.ts
- nexus-core.d.mts
- nexus-core.mjs
- oidc-core.d.mts
- oidc-core.mjs
- oidc.ts
- providers.ts
- proxy-core.d.mts
- proxy-core.mjs
- pwauth-core.d.mts
- pwauth-core.mjs
- requirements.ts
- rls.sql.d.mts
- rls.sql.mjs
- ssrf.ts
- status.ts
- tenant.ts
- tlsgate.ts
- workspace.ts
app/src/lib/gateway.ts
1// Agent <-> platform authentication. Nodes authenticate with "<nodeId>.<secret>"; the server stores only sha256(secret).2import crypto from "node:crypto";3import { db, asSystem, enterScope } from "./db";4import { isSecure } from "./auth";5import { GATE_MSG } from "./tenant";6import { orgAdmitted } from "./gates";7import { resolveConfig } from "./config";8import { sha } from "./cloud";910export const jerr = (status: number, error: string) => Response.json({ error }, { status });11/** Gateway traffic must be TLS-terminated by the edge; customer tenants additionally need the trusted-HTTPS gate. */12export async function gatewayGate(orgId?: string): Promise<Response | null> {13 if (!(await isSecure())) return jerr(403, "HTTPS required");14 if (orgId) { const o = await db().prepare("SELECT protected,status FROM organizations WHERE id=?").get(orgId) as any; if (!o || o.status !== "active") return jerr(403, "organization inactive"); if (!o.protected && !(await orgAdmitted(orgId))) return jerr(403, GATE_MSG); }15 return null;16}17/** Authenticates a node and binds the request's row-level-security scope to the NODE'S tenant (no other tenant's rows are reachable afterwards). */18export function nodeAuth(req: Request): Promise<{ node: any } | { res: Response }> {19 const scope = enterScope();20 return nodeAuthInner(req).then(r => { if ("node" in r) { scope.org = r.node.org_id; scope.mode = "tenant"; } return r; });21}22async function nodeAuthInner(req: Request): Promise<{ node: any } | { res: Response }> {23 const h = req.headers.get("authorization") ?? ""; const m = /^Bearer (node_[0-9a-f]{16})\.([0-9a-f]{64})$/.exec(h); if (!m) return { res: jerr(401, "node credential required") };24 const node = await asSystem(() => db().prepare("SELECT * FROM nodes WHERE id=?").get(m[1])) as any;25 if (node?.revoked_at) return { res: jerr(403, "node revoked") };26 const ok = node?.secret_hash && crypto.timingSafeEqual(Buffer.from(sha(m[2])), Buffer.from(node.secret_hash));27 if (!node || !ok) return { res: jerr(401, "invalid node credential") };28 const gate = await asSystem(() => gatewayGate(node.org_id)); if (gate) return { res: gate };29 return { node };30}31export async function gatewayUrl() { return (await resolveConfig()).GATEWAY_BASE_URL.value; }32
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 1c27633 on master.
Approval requests
None pending.