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/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

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.