Intelligence
Artifacts
Browse the repository, read documents, and manage the governance folders. Source, runtime, and infrastructure are read-only.
Repository
repositories/aaf-holdings/hq01/app/api/sessions/route.ts
1.4 KB
import { NextResponse } from "next/server";
import {
listSessions,
startSession,
SessionError,
} from "@/lib/sessions/manager";
import type { StartSessionInput } from "@/lib/sessions/types";
/**
* Collection endpoint for sessions.
*
* GET /api/sessions → list all sessions (reconciled against live processes)
* POST /api/sessions → start a new session, returning immediately
*
* The session manager spawns a detached process and returns at once, so POST
* never blocks HQ01 — the CEO can lock the phone the moment the response lands.
*/
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET() {
const sessions = listSessions();
return NextResponse.json({ sessions });
}
export async function POST(request: Request) {
let body: StartSessionInput;
try {
body = (await request.json()) as StartSessionInput;
} catch {
return NextResponse.json(
{ error: "Request body must be valid JSON." },
{ status: 400 },
);
}
try {
const session = startSession(body);
return NextResponse.json({ session }, { status: 201 });
} catch (err) {
if (err instanceof SessionError) {
return NextResponse.json({ error: err.message }, { status: err.status });
}
const message = err instanceof Error ? err.message : "Unknown error";
return NextResponse.json({ error: message }, { status: 500 });
}
}
root · /srv/aaf