import { NextResponse } from "next/server"; import { z } from "zod"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { createRuntime, getDockerInfo, listRuntimes, RuntimeBody, RuntimeError } from "@/lib/runtimes"; export const dynamic = "force-dynamic"; /** Runtimes plus the Docker facts the worker reported. */ export const GET = withAuth(async () => NextResponse.json({ runtimes: await listRuntimes(), docker: await getDockerInfo() })); export const POST = withAuth(async (req) => { try { const body = RuntimeBody.extend({ preset: z.string().optional() }).parse(await req.json()); return NextResponse.json(await createRuntime(body), { status: 201 }); } catch (err) { if (err instanceof RuntimeError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });