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-onlyapp/src/lib/central.ts
1import crypto from "node:crypto";2import { asSystem, db, getSetting, now, uid } from "./db";3import { resolveConfig } from "./config";4import { oidcConfig } from "./oidc";5import { ADAPTERS, adapterState, buildContract, orgRef, sanitizeEvent } from "./central-core.mjs";67/** Stable application identity: random, generated once, independent of any hostname. */8export async function appId(): Promise<string> {9 const cur = await getSetting("central.app_id", ""); if (cur) return cur;10 const id = "zca_" + crypto.randomBytes(12).toString("hex");11 await asSystem(() => db().prepare("INSERT INTO settings(key,value) VALUES('central.app_id',?) ON CONFLICT(key) DO NOTHING").run(id));12 return getSetting("central.app_id", id);13}14/** History is persisted ONLY when the public URL is explicitly configured (env/settings). A URL derived from the request Host header is attacker-controlled and must never be written. */15async function history(base: string, persist: boolean): Promise<string[]> {16 let h: string[] = []; try { h = JSON.parse(await getSetting("central.endpoint_history", "[]")); } catch {}17 if (!persist) return h;18 const last = await getSetting("central.last_base", "");19 if (last && last !== base && !h.includes(last)) { h = [last, ...h].slice(0, 5); await asSystem(async () => { await db().prepare("INSERT INTO settings(key,value) VALUES('central.endpoint_history',?) ON CONFLICT(key) DO UPDATE SET value=excluded.value").run(JSON.stringify(h)); }); }20 if (last !== base) await asSystem(() => db().prepare("INSERT INTO settings(key,value) VALUES('central.last_base',?) ON CONFLICT(key) DO UPDATE SET value=excluded.value").run(base));21 return h;22}23export async function contract() {24 const c = await resolveConfig(); const o = await oidcConfig(); const base = c.PUBLIC_BASE_URL.value;25 const cfg = Object.fromEntries(Object.entries(c).map(([k, v]) => [k, v.value])) as Record<string, string>; cfg.OIDC_ISSUER = o.issuer;26 return buildContract(await appId(), cfg, await history(base, c.PUBLIC_BASE_URL.source !== "derived"));27}28export async function integrationStatus() {29 const o = await oidcConfig(); const out = [];30 for (const a of ADAPTERS) {31 const endpoint = await getSetting(`central.endpoint.${a.id}`, ""); const probeOk = (await getSetting(`central.probe.${a.id}`, "")) === "ok";32 out.push({ ...a, endpoint: endpoint || null, state: adapterState(a, { endpoint, probeOk, secretPresent: o.configured }) as string });33 }34 return out;35}36/** Queues a metadata-only event. Rejects (throws) anything outside the allowlist. Nothing is delivered until an operator-configured, probed endpoint exists. */37export async function enqueue(kind: string, orgId: string | null, data: Record<string, unknown>) {38 const id = await appId(); const m = orgId ? await asSystem(() => db().prepare("SELECT central_ref FROM org_mappings WHERE org_id=?").get(orgId)) as { central_ref: string } | undefined : undefined;39 const clean = sanitizeEvent(kind, { ...data, ...(orgId ? { orgRef: orgRef(id, orgId, m?.central_ref) } : {}) });40 await asSystem(() => db().prepare("INSERT INTO central_outbox(kind,org_id,payload,created_at) VALUES(?,?,?,?)").run(kind, orgId, JSON.stringify(clean), now()));41 return clean;42}43export { orgRef, uid };44
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 0eebc42 on master.
Approval requests
None pending.