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- ..
- apple-touch-icon.png
- brand-guidelines-v2.md
- brand-manifest-v2.json
- favicon-16.png
- favicon-32.png
- favicon-48.png
- favicon.ico
- icon-192.png
- icon-512.png
- maskable-192.png
- maskable-512.png
- source-brand-board.png
- source-crop-icon-fullcolor.png
- source-crop-lockup-dark.png
- source-crop-wordmark-light.png
- zloud-app-icon-1024.png
- zloud-app-icon.svg
- zloud-favicon.svg
- zloud-mark-1024.png
- zloud-mark-512.png
- zloud-mark-mono-512.png
- zloud-mark-mono.svg
- zloud-mark-reversed.svg
- zloud-mark-white-512.png
- zloud-mark-white.svg
- zloud-mark.svg
- zloud-maskable.svg
- zloud-wordmark-dark.svg
- zloud-wordmark-light.svg
- zloud-wordmark-mono.svg
app/src/app/api/ai/sessions/[id]/stream/route.ts
1import { sessionOf, tenant, notFound } from "@/lib/tenant";2import { db } from "@/lib/db";3export const dynamic = "force-dynamic";4// SSE: the browser only observes durable DB state, so a dropped connection loses nothing (client reconnects and gets the snapshot again).5export async function GET(req: Request, { params }: { params: Promise<{ id: string }> }) {6 const g = await tenant("viewer"); if (g.res) return g.res;7 const { id } = await params; if (!(await sessionOf(g.ctx, id))) return notFound(); let t: NodeJS.Timeout, last = "";8 const stream = new ReadableStream({9 start(c) {10 const enc = new TextEncoder(); let busy = false;11 const tick = async () => { if (busy) return; busy = true; try {12 const run = await db().prepare("SELECT id,status,attempts,max_attempts,error,partial,tokens_in,tokens_out,cost_usd,updated_at FROM ai_runs WHERE session_id=? ORDER BY created_at DESC LIMIT 1").get(id);13 const count = await db().prepare("SELECT COUNT(*) n, COALESCE(MAX(id),0) m FROM ai_messages WHERE session_id=?").get(id) as any;14 const s = JSON.stringify({ run: run ?? null, messages: count.n, lastMessage: count.m }); if (s !== last) { last = s; c.enqueue(enc.encode(`data: ${s}\n\n`)); } else c.enqueue(enc.encode(": ping\n\n"));15 } catch { clearInterval(t); try { c.close(); } catch {} } finally { busy = false; } };16 void tick(); t = setInterval(tick, 700); req.signal.addEventListener("abort", () => { clearInterval(t); try { c.close(); } catch {} });17 }, cancel() { clearInterval(t); } });18 return new Response(stream, { headers: { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" } });19}20
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.