import { NextResponse } from "next/server"; import { listFleetAgents } from "@/lib/agents"; import { findTask, updateTask } from "@/lib/tasks"; export async function POST( request: Request, { params }: { params: Promise<{ slug: string }> }, ) { const { slug } = await params; const payload = (await request.json()) as { taskId?: number }; if (!payload.taskId) { return NextResponse.json({ error: "taskId_is_required" }, { status: 400 }); } const agents = await listFleetAgents(); const agent = agents.find((entry) => entry.slug === slug); if (!agent) { return NextResponse.json({ error: "agent_not_found" }, { status: 404 }); } const existing = await findTask(payload.taskId); if (!existing) { return NextResponse.json({ error: "task_not_found" }, { status: 404 }); } const updated = await updateTask(existing.id, { assignee: agent.assignmentKey }); return NextResponse.json({ success: true, task: updated }); }