import { NextRequest } from 'next/server' import { getCurrentUser } from '@/lib/session' import { listRunLogs } from '@/lib/worker-logs' export const dynamic = 'force-dynamic' // GET /api/worker-logs?limit=10 — newest-first run-log summaries for the table. export async function GET(request: NextRequest) { const user = await getCurrentUser() if (!user) { return Response.json({ error: 'unauthorized' }, { status: 401 }) } const limitParam = request.nextUrl.searchParams.get('limit') const limit = limitParam ? Number(limitParam) : 10 try { const logs = await listRunLogs(limit) return Response.json({ logs }) } catch (err) { // Surfaces a missing bind mount legibly (e.g. WORKER_LOGS_DIR not mounted). const message = err instanceof Error ? err.message : 'failed to list worker logs' return Response.json({ error: message }, { status: 500 }) } }