import { getState } from '@/lib/runtime.js';
import { listHermesJobs } from '@/lib/hermes-jobs.js';
import { requireSession } from '@/lib/auth.js';
import { isDashboardLiveDeltasEnabled } from '@/lib/feature-flags.js';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
export async function GET(req) {
  try {
    await requireSession(req);
    const { searchParams } = new URL(req.url);
    const project_id = searchParams.get('project_id') || searchParams.get('project') || null;
    const state = getState({ project_id });
    return Response.json({
      ...state,
      hermes_jobs: listHermesJobs(20),
      live_deltas_enabled: isDashboardLiveDeltasEnabled(),
    });
  } catch (err) {
    if (err && typeof err === 'object' && err.status) {
      return Response.json({ error: err.error || 'unauthorized' }, { status: err.status });
    }
    throw err;
  }
}
