Skip to content
  1. Home
  2. workspace
Checking…
Public 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/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";
9
10export 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

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 0eebc42 on master.

Approval requests

None pending.