import { NextRequest, NextResponse } from "next/server"; import { getAllTasks, createTask } from "@/lib/store"; import { getAgentConfig } from "@/lib/agents"; import { Task, TaskSpec } from "@/lib/types"; export async function GET() { return NextResponse.json(getAllTasks()); } export async function POST(request: NextRequest) { const spec: TaskSpec = await request.json(); if (!spec.slug || !spec.goal) { return NextResponse.json({ error: "slug and goal are required" }, { status: 400 }); } if (!spec.agentId) { return NextResponse.json({ error: "agentId is required" }, { status: 400 }); } const agentConfig = getAgentConfig(spec.agentId); if (!agentConfig) { return NextResponse.json( { error: `Agent config not found: ${spec.agentId}` }, { status: 400 }, ); } const task: Task = { id: `task-${Date.now()}`, slug: spec.slug, goal: spec.goal, project: spec.project || "—", status: "pending", iteration: 0, maxIterations: spec.maxIterations || 6, startedAt: null, evals: {}, iterations: [], spec, }; const created = createTask(task); return NextResponse.json(created, { status: 201 }); }