import { NextResponse } from "next/server"; import { prisma } from "@/lib/prisma"; // GET /api/traces/[id] — Get single trace with all relations export async function GET( _request: Request, { params }: { params: Promise<{ id: string }> } ) { try { const { id } = await params; if (!id || typeof id !== "string") { return NextResponse.json({ error: "Invalid trace ID" }, { status: 400 }); } const trace = await prisma.trace.findUnique({ where: { id }, include: { decisionPoints: { orderBy: { timestamp: "asc", }, }, spans: { orderBy: { startedAt: "asc", }, }, events: { orderBy: { timestamp: "asc", }, }, }, }); if (!trace) { return NextResponse.json({ error: "Trace not found" }, { status: 404 }); } return NextResponse.json({ trace }, { status: 200 }); } catch (error) { console.error("Error retrieving trace:", error); return NextResponse.json({ error: "Internal server error" }, { status: 500 }); } }