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/proxy-core.mjs
1// Customer hosting: domain validation, DNS instructions, and the Caddyfile renderer (mirrors agent/zoo-cloud-agent.mjs; QA compares both outputs byte-for-byte).2// Proxy choice: Caddy — single static binary, automatic HTTPS (ACME HTTP-01/TLS-ALPN) with renewal built in, validate-then-reload via admin API, tiny config.3// Nginx would need certbot + cron; Traefik needs a provider/dynamic config layer. Caddy is the smallest managed surface for an unprivileged agent.4export const HOST_OK = /^(?=.{4,253}$)([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;5export const PLATFORM_SUFFIXES = ["zoobd.com", "zloud.io", "gpt.com"]; // never customer-mappable (platform / third-party domains)6export function checkHostname(h) {7 const x = String(h ?? "").trim().toLowerCase().replace(/\.$/, ""); if (!HOST_OK.test(x)) return { ok: false, error: "enter a valid domain name such as app.example.com (no scheme, port, path or wildcard)" };8 if (/^\d+(\.\d+){3}$/.test(x) || x.endsWith(".local") || x.endsWith(".internal") || x.endsWith(".localhost")) return { ok: false, error: "IP addresses and internal names are not allowed" };9 if (PLATFORM_SUFFIXES.some(s => x === s || x.endsWith("." + s))) return { ok: false, error: "this domain belongs to the platform operator or a third party and cannot be connected" };10 return { ok: true, hostname: x };11}12export const isApex = h => h.split(".").length <= 2 || /\.(co|com|org|net|gov|ac)\.[a-z]{2}$/.test(h) && h.split(".").length <= 3;13export const verifyName = h => `_zloud-verify.${h}`;14/** DNS records the customer must create, derived from the real target node (public IP or hostname). */15export function dnsInstructions(hostname, token, target) {16 const rec = []; const isIp = /^(\d{1,3}\.){3}\d{1,3}$/.test(target ?? ""); const isV6 = /:/.test(target ?? "");17 if (!target) return { records: [], note: "The server has no public address recorded. Re-enroll the agent with --public-host <public IP or hostname>." };18 if (isIp) rec.push({ type: "A", name: hostname, value: target, purpose: "routes the domain to your server" }); else if (isV6) rec.push({ type: "AAAA", name: hostname, value: target, purpose: "routes the domain to your server" });19 else rec.push(isApex(hostname) ? { type: "A", name: hostname, value: `(the IP address of ${target})`, purpose: "an apex domain cannot be a CNAME; use the server's IP" } : { type: "CNAME", name: hostname, value: target, purpose: "routes the domain to your server" });20 rec.push({ type: "TXT", name: verifyName(hostname), value: token, purpose: "proves you control the domain" }); return { records: rec, note: "DNS changes can take minutes to hours. Ports 80 and 443 must be reachable on the server for certificate issuance." };21}22export function renderCaddyfile(sites, admin = "127.0.0.1:2019") {23 const out = [`{\n\tadmin ${admin}\n}\n`]; for (const s of sites) {24 if (!HOST_OK.test(s.hostname)) throw new Error(`invalid hostname ${String(s.hostname).slice(0, 60)}`);25 if (s.redirectTo) { if (!HOST_OK.test(s.redirectTo)) throw new Error("invalid redirect target"); out.push(`${s.hostname} {\n\tredir https://${s.redirectTo}{uri} permanent\n}\n`); continue; }26 if (!Number.isInteger(s.port) || s.port < 20000 || s.port > 29999) throw new Error("upstream port must be a managed application port (20000-29999)");27 out.push(`${s.hostname} {\n\tencode gzip\n\theader X-Content-Type-Options nosniff\n\treverse_proxy 127.0.0.1:${s.port}\n}\n`);28 } return out.join("\n");29}30/** Pure DNS evaluation: txt = TXT strings at _zloud-verify.<host>; a = A/AAAA answers for <host>; cname = CNAME answers. Ownership needs the TXT token; routing needs the target address. */31export function evaluateDns({ txt = [], a = [], cname = [] }, token, target, resolvedTarget = []) {32 const owned = txt.map(s => String(s).trim()).includes(token); const want = new Set([target, ...resolvedTarget].filter(Boolean));33 const routed = a.some(x => want.has(x)) || cname.map(c => String(c).replace(/\.$/, "").toLowerCase()).includes(String(target).toLowerCase());34 return { owned, routed, dns: owned ? (routed ? "ok" : a.length || cname.length ? "wrong-target" : "no-route-record") : "ownership-not-proven" };35}36
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.