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/components/console-client.tsx

1"use client";
2import { useRouter } from "next/navigation";
3import { useState, type ReactNode } from "react";
4
5export async function api(url: string, method: string, body?: unknown) { const r = await fetch(url, { method, headers: { "content-type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body) }); const j = await r.json().catch(() => ({})); return { ok: r.ok, status: r.status, j }; }
6function useAct() { const r = useRouter(); const [msg, setMsg] = useState(""); const [err, setErr] = useState(""); const [busy, setBusy] = useState(false);
7 const run = async (fn: () => Promise<{ ok: boolean; j: any }>, okMsg = "Done") => { setBusy(true); setErr(""); setMsg(""); const x = await fn(); setBusy(false); if (x.ok) { setMsg(okMsg); r.refresh(); } else setErr(x.j?.error ?? "Failed"); return x; };
8 return { run, msg, err, busy }; }
9const Msg = ({ msg, err }: { msg: string; err: string }) => <>{err && <div role="alert" className="mt-2 rounded bg-[var(--err-bg)] px-3 py-2 text-sm text-[var(--err)]">{err}</div>}{msg && <div role="status" className="mt-2 text-sm text-muted">{msg}</div>}</>;
10export const STATE_TONE: Record<string, string> = { online: "bg-[var(--ok-bg)] text-[var(--ok)]", active: "bg-[var(--ok-bg)] text-[var(--ok)]", fulfilled: "bg-[var(--ok-bg)] text-[var(--ok)]", offline: "bg-[var(--warn-bg)] text-[var(--warn)]", pending: "bg-[var(--warn-bg)] text-[var(--warn)]", pending_provisioning: "bg-[var(--warn-bg)] text-[var(--warn)]", "awaiting-agent": "bg-[var(--warn-bg)] text-[var(--warn)]", created: "bg-[var(--neutral-bg)] text-muted", suspended: "bg-[var(--neutral-bg)] text-muted", revoked: "bg-[var(--err-bg)] text-[var(--err)]", terminated: "bg-[var(--err-bg)] text-[var(--err)]", rejected: "bg-[var(--err-bg)] text-[var(--err)]" };
11export const Pill = ({ s }: { s: string }) => <span className={`inline-flex rounded-full px-2 py-0.5 text-xs font-medium whitespace-nowrap ${STATE_TONE[s] ?? "bg-[var(--neutral-bg)] text-muted"}`}>{s.replace(/_/g, " ")}</span>;
12const Field = ({ l, children }: { l: string; children: ReactNode }) => <label className="block text-xs text-muted">{l}<div className="mt-1">{children}</div></label>;
13
14type Inst = { id: string; name: string; target: string; status: string; nodes: { id: string; label: string; state: string }[] };
15const NEXT: Record<string, string[]> = { created: ["active", "terminated"], pending_provisioning: ["terminated"], active: ["suspended", "terminated"], suspended: ["active", "terminated"], terminated: [] };
16export function InstancesPanel({ instances, canManage }: { instances: Inst[]; canManage: boolean }) {
17 const { run, msg, err, busy } = useAct(); const [name, setName] = useState(""); const [target, setTarget] = useState("external");
18 return <div className="space-y-4">
19 {canManage && <form className="grid gap-2 sm:grid-cols-[1fr_16rem_auto]" onSubmit={e => { e.preventDefault(); void run(() => api("/api/cloud/instances", "POST", { name, target }), "Instance created").then(x => x.ok && setName("")); }}>
20 <input className="input" aria-label="Instance name" placeholder="e.g. production" value={name} onChange={e => setName(e.target.value)} maxLength={80} />
21 <select className="input" aria-label="Target infrastructure" value={target} onChange={e => setTarget(e.target.value)}><option value="external">External VPS (customer-owned)</option><option value="managed">Zloud Compute (managed) (request)</option></select>
22 <button className="btn btn-primary" disabled={busy || name.trim().length < 2}>Create instance</button></form>}
23 <Msg msg={msg} err={err} />
24 {instances.length === 0 ? <p className="text-sm text-muted">No cloud instances yet. An instance is a logical environment; choose where it runs.</p> : <ul className="divide-y divide-line rounded-xl border border-line" data-testid="instance-list">{instances.map(i => <li key={i.id} className="flex flex-wrap items-center justify-between gap-3 p-3 text-sm">
25 <div className="min-w-0"><div className="font-medium">{i.name} <span className="mono text-xs text-muted">{i.id}</span></div><div className="text-xs text-muted">{i.target === "managed" ? "Zloud Compute (managed)" : "External VPS (customer-owned)"} · {i.nodes.length} server(s)</div></div>
26 <div className="flex flex-wrap items-center gap-2"><Pill s={i.status} />{canManage && (NEXT[i.status] ?? []).map(t => <button key={t} className="btn btn-sm" disabled={busy} onClick={() => run(() => api(`/api/cloud/instances/${i.id}`, "PATCH", { status: t }), `Instance ${t}`)}>{t === "terminated" ? "Terminate" : t === "active" ? "Activate" : "Suspend"}</button>)}</div></li>)}</ul>}</div>;
27}
28
29type Node = { id: string; instance_id: string; label: string; state: string; hostname?: string; os?: string; agent_version?: string; metrics?: { load1: number; memFreeMb: number; memTotalMb: number } | null };
30export function ServersPanel({ instances, nodes, jobs, canManage, canJob, origin, pkg }: { instances: { id: string; name: string }[]; nodes: Node[]; jobs: { id: string; node_id: string; kind: string; status: string; result: string | null }[]; canManage: boolean; canJob: boolean; origin: string; pkg: { file: string; version: string } | null }) {
31 const { run, msg, err, busy } = useAct(); const [inst, setInst] = useState(instances[0]?.id ?? ""); const [label, setLabel] = useState(""); const [tok, setTok] = useState<{ id: string; token: string; expires: string } | null>(null);
32 return <div className="space-y-4">
33 {canManage && <div className="rounded-xl border border-line p-4"><div className="font-medium">Add an external VPS</div><p className="mt-1 text-xs text-muted">Create instance → add server → generate a <b>single-use, 15-minute</b> enrollment token → install the agent on your server. The agent connects outbound over verified TLS; you open no inbound ports.</p>
34 {instances.length === 0 ? <p className="mt-2 text-sm text-muted">Create an External-VPS cloud instance first.</p> : <form className="mt-3 grid gap-2 sm:grid-cols-[14rem_1fr_auto]" onSubmit={e => { e.preventDefault(); void run(() => api("/api/cloud/servers", "POST", { action: "enroll", instanceId: inst, label }), "Token generated").then(x => { if (x.ok) { setTok(x.j); setLabel(""); } }); }}>
35 <select className="input" aria-label="Instance" value={inst} onChange={e => setInst(e.target.value)}>{instances.map(i => <option key={i.id} value={i.id}>{i.name}</option>)}</select>
36 <input className="input" aria-label="Server label" placeholder="my-vps-01" value={label} onChange={e => setLabel(e.target.value)} maxLength={80} /><button className="btn btn-primary" disabled={busy || label.trim().length < 2}>Generate enrollment token</button></form>}
37 {tok && <div role="status" className="mt-3 space-y-2 rounded-lg bg-surface2 p-3 text-xs"><div>Token (shown once; expires {tok.expires.slice(11, 19)} UTC):</div><code className="mono block break-all" data-testid="enroll-token">{tok.token}</code>
38 <div className="text-muted">On your server (Node 18+):</div><pre className="mono overflow-auto whitespace-pre-wrap rounded bg-surface p-2">{pkg ? `curl -fsSO ${origin}/packages/${pkg.file} -O ${origin}/packages/${pkg.file}.sig\nnode ${pkg.file} verify --file ${pkg.file} --sig ${pkg.file}.sig --pubkey <public key from /packages>\nnode ${pkg.file} enroll --url ${origin} --token ${tok.token} --pin <this server's TLS fingerprint>\nnode ${pkg.file} run` : "Agent package not built."}</pre>
39 <div className="text-muted">The preview certificate is self-signed, so enrollment needs <code>--pin</code> with its SHA-256 fingerprint (shown on /packages). Verified-CA TLS needs no pin.</div></div>}</div>}
40 <Msg msg={msg} err={err} />
41 {nodes.length === 0 ? <p className="text-sm text-muted">No servers connected yet.</p> : <ul className="divide-y divide-line rounded-xl border border-line" data-testid="node-list">{nodes.map(n => <li key={n.id} className="space-y-1 p-3 text-sm"><div className="flex flex-wrap items-center justify-between gap-2"><div className="min-w-0"><span className="font-medium">{n.label}</span> <span className="mono text-xs text-muted">{n.id}</span></div><div className="flex flex-wrap items-center gap-2"><Pill s={n.state} />
42 {canJob && n.state === "online" && <button className="btn btn-sm" disabled={busy} onClick={() => run(() => api("/api/cloud/servers", "POST", { action: "job", nodeId: n.id, kind: "collect-info" }), "Job queued")}>Collect info</button>}
43 {canManage && n.state !== "revoked" && <button className="btn btn-sm" disabled={busy} onClick={() => run(() => api("/api/cloud/servers", "POST", { action: "revoke", nodeId: n.id }), "Node revoked")}>Revoke</button>}</div></div>
44 <div className="text-xs text-muted">{n.hostname ? `${n.hostname} · ${n.os} · agent ${n.agent_version}` : "Agent not connected"}{n.metrics ? ` · load ${n.metrics.load1.toFixed(2)} · mem ${n.metrics.memFreeMb}/${n.metrics.memTotalMb} MB free` : ""}</div></li>)}</ul>}
45 {jobs.length > 0 && <div className="text-xs text-muted">Recent jobs: {jobs.slice(0, 5).map(j => `${j.kind}:${j.status}`).join(" · ")}</div>}</div>;
46}
47
48export function TeamPanel({ members, canManage, role, me }: { members: { id: string; email: string; name: string; role: string }[]; canManage: boolean; role: string; me: string }) {
49 const { run, msg, err, busy } = useAct(); const [f, setF] = useState({ email: "", name: "", role: "developer" }); const [tok, setTok] = useState("");
50 const roles = ["viewer", "developer", "admin", "owner"].filter(r => ["viewer", "developer", "admin", "owner"].indexOf(r) <= ["viewer", "developer", "admin", "owner"].indexOf(role));
51 return <div className="space-y-4">
52 {canManage && <form className="grid gap-2 sm:grid-cols-[1fr_1fr_10rem_auto]" onSubmit={e => { e.preventDefault(); void run(() => api("/api/cloud/team", "POST", f), "Member added").then(x => { if (x.ok) { setTok(x.j.token ?? ""); setF({ email: "", name: "", role: "developer" }); } }); }}>
53 <input className="input" type="email" aria-label="Member email" placeholder="email@company.com" value={f.email} onChange={e => setF({ ...f, email: e.target.value })} /><input className="input" aria-label="Member name" placeholder="Name" value={f.name} onChange={e => setF({ ...f, name: e.target.value })} />
54 <select className="input" aria-label="Role" value={f.role} onChange={e => setF({ ...f, role: e.target.value })}>{roles.map(r => <option key={r}>{r}</option>)}</select><button className="btn btn-primary" disabled={busy}>Add member</button></form>}
55 {tok && <div role="status" className="rounded-lg bg-surface2 p-3 text-xs"><div className="text-muted">Personal access token (shown once; dev-only sign-in until Zoo IAM):</div><code className="mono break-all" data-testid="member-token">{tok}</code></div>}
56 <Msg msg={msg} err={err} />
57 <ul className="divide-y divide-line rounded-xl border border-line" data-testid="member-list">{members.map(m => <li key={m.id} className="flex flex-wrap items-center justify-between gap-2 p-3 text-sm"><div><div className="font-medium">{m.name}{m.id === me ? " (you)" : ""}</div><div className="text-xs text-muted">{m.email}</div></div>
58 <div className="flex items-center gap-2">{canManage && m.id !== me ? <select className="input !w-auto" aria-label={`Role for ${m.email}`} value={m.role} onChange={e => run(() => api("/api/cloud/team", "PATCH", { userId: m.id, role: e.target.value }), "Role updated")}>{["viewer", "developer", "admin", "owner"].map(r => <option key={r}>{r}</option>)}</select> : <Pill s={m.role} />}
59 {canManage && m.id !== me && <button className="btn btn-sm" disabled={busy} onClick={() => run(() => api("/api/cloud/team", "PATCH", { userId: m.id, remove: true }), "Member removed")}>Remove</button>}</div></li>)}</ul></div>;
60}
61
62export function ManagedPanel({ instances, plans, requests, canManage }: { instances: { id: string; name: string; status: string }[]; plans: { id: string; name: string; cpu: number; ram_gb: number; disk_gb: number }[]; requests: { id: string; instance_id: string; plan: string; status: string; note: string | null }[]; canManage: boolean }) {
63 const { run, msg, err, busy } = useAct(); const [inst, setInst] = useState(instances[0]?.id ?? ""); const [plan, setPlan] = useState(plans[0]?.id ?? "");
64 return <div className="space-y-4">
65 {canManage && (instances.length === 0 || plans.length === 0 ? <p className="text-sm text-muted">{plans.length === 0 ? "No resource plans are defined yet (the platform administrator configures them)." : "Create a Zloud Compute (managed) cloud instance first."}</p> : <form className="grid gap-2 sm:grid-cols-[1fr_1fr_auto]" onSubmit={e => { e.preventDefault(); void run(() => api("/api/cloud/provision", "POST", { instanceId: inst, planId: plan }), "Provisioning requested"); }}>
66 <select className="input" aria-label="Managed instance" value={inst} onChange={e => setInst(e.target.value)}>{instances.map(i => <option key={i.id} value={i.id}>{i.name} ({i.status.replace(/_/g, " ")})</option>)}</select>
67 <select className="input" aria-label="Resource plan" value={plan} onChange={e => setPlan(e.target.value)}>{plans.map(p => <option key={p.id} value={p.id}>{p.name} · {p.cpu} vCPU · {p.ram_gb} GB · {p.disk_gb} GB</option>)}</select><button className="btn btn-primary" disabled={busy}>Request provisioning</button></form>)}
68 <Msg msg={msg} err={err} />
69 {requests.length > 0 && <ul className="divide-y divide-line rounded-xl border border-line text-sm" data-testid="prov-list">{requests.map(r => <li key={r.id} className="flex items-center justify-between gap-2 p-3"><span>{r.plan} · <span className="mono text-xs text-muted">{r.id}</span></span><Pill s={r.status} /></li>)}</ul>}</div>;
70}
71
72export function SuperPanel({ data }: { data: any }) {
73 const { run, msg, err, busy } = useAct(); const [o, setO] = useState({ name: "", ownerEmail: "", ownerName: "" }); const [tok, setTok] = useState(""); const [inv, setInv] = useState({ label: "", region: "", cpu: "2", ramGb: "4", diskGb: "80" }); const [pl, setPl] = useState({ name: "", cpu: "1", ramGb: "2", diskGb: "40" }); const [phrase, setPhrase] = useState("");
74 const post = (b: object, m: string) => run(() => api("/api/super", "POST", b), m);
75 return <div className="space-y-6 text-sm">
76 <section><h3 className="mb-2 font-semibold">Customer security gate</h3><p className="mb-2 text-xs text-muted">Customer sign-in and customer operations stay disabled until trusted HTTPS exists. Current mode: <b data-testid="gate-mode">{data.security.mode}</b>.</p>
77 <div className="flex flex-wrap items-center gap-2"><input className="input !w-72" aria-label="Attestation phrase" placeholder='type the phrase to enable' value={phrase} onChange={e => setPhrase(e.target.value)} />
78 <button className="btn btn-sm" disabled={phrase !== "I ATTEST TRUSTED TLS"} onClick={() => post({ action: "security", trustedTls: true, confirm: phrase }, "Trusted TLS attested")}>Attest trusted TLS (I ATTEST TRUSTED TLS)</button>
79 <button className="btn btn-sm" disabled={phrase !== "ENABLE DEV CUSTOMER OPS"} onClick={() => post({ action: "security", devCustomerOps: true, confirm: phrase }, "Dev override on")}>Enable dev override (ENABLE DEV CUSTOMER OPS)</button>
80 <button className="btn btn-sm" onClick={() => post({ action: "security", trustedTls: false, devCustomerOps: false }, "Customer ops disabled")}>Disable customer operations</button></div></section>
81 <Msg msg={msg} err={err} />
82 <section><h3 className="mb-2 font-semibold">Organizations</h3>
83 <form className="mb-3 grid gap-2 sm:grid-cols-[1fr_1fr_1fr_auto]" onSubmit={e => { e.preventDefault(); void post({ action: "createOrg", ...o }, "Organization created").then((x: any) => { if (x.ok) { setTok(x.j.token ?? ""); setO({ name: "", ownerEmail: "", ownerName: "" }); } }); }}>
84 <input className="input" aria-label="Organization name" placeholder="Organization" value={o.name} onChange={e => setO({ ...o, name: e.target.value })} /><input className="input" aria-label="Owner email" placeholder="owner@company.com" value={o.ownerEmail} onChange={e => setO({ ...o, ownerEmail: e.target.value })} /><input className="input" aria-label="Owner name" placeholder="Owner name" value={o.ownerName} onChange={e => setO({ ...o, ownerName: e.target.value })} /><button className="btn btn-primary" disabled={busy}>Create</button></form>
85 {tok && <div role="status" className="mb-3 rounded-lg bg-surface2 p-3 text-xs"><div className="text-muted">Owner access token (shown once):</div><code className="mono break-all" data-testid="owner-token">{tok}</code></div>}
86 <div className="overflow-x-auto"><table className="w-full min-w-[40rem] text-left"><thead className="text-xs text-muted"><tr><th className="p-2">Organization</th><th>Members</th><th>Instances</th><th>Servers</th><th>Projects</th><th>Status</th><th></th></tr></thead><tbody>{data.orgs.map((x: any) => <tr key={x.id} className="border-t border-line"><td className="p-2"><div className="font-medium">{x.name}{x.protected ? " (protected)" : ""}</div><div className="mono text-xs text-muted">{x.id}</div></td><td>{x.members}</td><td>{x.instances}/{x.max_instances}</td><td>{x.nodes}/{x.max_nodes}</td><td>{x.projects}/{x.max_projects}</td><td><Pill s={x.status} /></td>
87 <td>{!x.protected && <button className="btn btn-sm" disabled={busy} onClick={() => post({ action: "updateOrg", orgId: x.id, status: x.status === "active" ? "suspended" : "active" }, "Updated")}>{x.status === "active" ? "Suspend" : "Reactivate"}</button>}</td></tr>)}</tbody></table></div></section>
88 <section><h3 className="mb-2 font-semibold">Resource plans & managed inventory</h3><p className="mb-2 text-xs text-muted">Inventory entries are <b>declared records</b> of servers you already own. Nothing is purchased or billed.</p>
89 <div className="grid gap-4 lg:grid-cols-2"><div><form className="grid grid-cols-2 gap-2 sm:grid-cols-6" onSubmit={e => { e.preventDefault(); void post({ action: "addPlan", ...pl }, "Plan added"); }}><input className="input col-span-2 sm:col-span-2" aria-label="Plan name" placeholder="Plan name" value={pl.name} onChange={e => setPl({ ...pl, name: e.target.value })} /><input className="input" aria-label="Plan vCPU" placeholder="vCPU" value={pl.cpu} onChange={e => setPl({ ...pl, cpu: e.target.value })} /><input className="input" aria-label="Plan RAM GB" placeholder="RAM GB" value={pl.ramGb} onChange={e => setPl({ ...pl, ramGb: e.target.value })} /><input className="input" aria-label="Plan disk GB" placeholder="Disk GB" value={pl.diskGb} onChange={e => setPl({ ...pl, diskGb: e.target.value })} /><button className="btn btn-sm" disabled={busy}>Add plan</button></form>
90 <ul className="mt-2 text-xs text-muted">{data.plans.map((p: any) => <li key={p.id}>{p.name}: {p.cpu} vCPU · {p.ram_gb} GB · {p.disk_gb} GB</li>)}{data.plans.length === 0 && <li>No plans.</li>}</ul></div>
91 <div><form className="grid grid-cols-2 gap-2 sm:grid-cols-7" onSubmit={e => { e.preventDefault(); void post({ action: "addInventory", ...inv }, "Inventory added"); }}><input className="input sm:col-span-2" aria-label="Server label" placeholder="Server label" value={inv.label} onChange={e => setInv({ ...inv, label: e.target.value })} /><input className="input" aria-label="Region" placeholder="region" value={inv.region} onChange={e => setInv({ ...inv, region: e.target.value })} /><input className="input" aria-label="Server vCPU" placeholder="vCPU" value={inv.cpu} onChange={e => setInv({ ...inv, cpu: e.target.value })} /><input className="input" aria-label="Server RAM GB" placeholder="RAM GB" value={inv.ramGb} onChange={e => setInv({ ...inv, ramGb: e.target.value })} /><input className="input" aria-label="Server disk GB" placeholder="Disk GB" value={inv.diskGb} onChange={e => setInv({ ...inv, diskGb: e.target.value })} /><button className="btn btn-sm" disabled={busy}>Add server</button></form>
92 <ul className="mt-2 text-xs text-muted">{data.inventory.map((i: any) => <li key={i.id}>{i.label} ({i.region}) {i.cpu} vCPU · {i.ram_gb} GB — {i.status}</li>)}{data.inventory.length === 0 && <li>No managed servers declared.</li>}</ul></div></div></section>
93 <section><h3 className="mb-2 font-semibold">Provisioning requests</h3>{data.requests.length === 0 ? <p className="text-xs text-muted">None.</p> : <ul className="divide-y divide-line rounded-xl border border-line">{data.requests.map((r: any) => <li key={r.id} className="flex flex-wrap items-center justify-between gap-2 p-3"><div>{r.org} · {r.instance} · {r.plan}<div className="mono text-xs text-muted">{r.id}</div></div><div className="flex items-center gap-2"><Pill s={r.status} />{r.status === "pending" && <>
94 <select className="input !w-auto" aria-label={`Inventory for ${r.id}`} id={`inv-${r.id}`}>{data.inventory.filter((i: any) => i.status === "available").map((i: any) => <option key={i.id} value={i.id}>{i.label}</option>)}</select>
95 <button className="btn btn-sm" disabled={busy} onClick={() => post({ action: "decide", id: r.id, decision: "approve", inventoryId: (document.getElementById(`inv-${r.id}`) as HTMLSelectElement)?.value }, "Approved")}>Approve & assign</button><button className="btn btn-sm" disabled={busy} onClick={() => post({ action: "decide", id: r.id, decision: "reject" }, "Rejected")}>Reject</button></>}</div></li>)}</ul>}</section></div>;
96}
97

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.