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/[id]/logs/route.ts
1.2 KB
import { NextResponse } from "next/server";
import { readLogs, SessionError } from "@/lib/sessions/manager";
import { LOG_TAIL_BYTES } from "@/lib/sessions/config";
/**
* Log tail endpoint — polled by the read-only log viewer.
*
* GET /api/sessions/:id/logs?bytes=N → the trailing N bytes of stdout/stderr,
* plus the current status and last-activity timestamp.
*
* No websocket: the viewer simply re-requests every few seconds.
*/
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET(
request: Request,
{ params }: { params: { id: string } },
) {
const url = new URL(request.url);
const bytesParam = Number(url.searchParams.get("bytes"));
const maxBytes =
Number.isFinite(bytesParam) && bytesParam > 0
? Math.min(bytesParam, 1024 * 1024)
: LOG_TAIL_BYTES;
try {
const logs = readLogs(params.id, maxBytes);
return NextResponse.json(logs);
} 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