import { createHermesJob, listHermesJobs, startHermesJobWorker } from '@/lib/hermes-jobs.js';

export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';

export async function GET() {
  return Response.json({ jobs: listHermesJobs(50) });
}

export async function POST(req) {
  try {
    const body = await req.json();
    const job = createHermesJob(body);
    if (process.env.HERMES_JOB_DISABLE_SPAWN !== '1') {
      startHermesJobWorker(job.id);
    }
    return Response.json({ job }, { status: 201 });
  } catch (error) {
    return Response.json({ error: error.message }, { status: 400 });
  }
}
