diff --git a/src/app/api/dashboard/sessions/[sessionId]/route.ts b/src/app/api/dashboard/sessions/[sessionId]/route.ts new file mode 100644 index 0000000..3a10ab7 --- /dev/null +++ b/src/app/api/dashboard/sessions/[sessionId]/route.ts @@ -0,0 +1,20 @@ +import { getSession } from "@/lib/auth-helpers"; +import { getMongoDb } from "@/lib/mongo"; +import { NextResponse } from "next/server"; + +export async function GET(request: Request, { params }: { params: Promise<{ sessionId: string }> }) { + const { sessionId } = await params; + const session = await getSession(); + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + + const db = getMongoDb(); + + const logs = await db.collection("debug_logs") + .find({ userId: session.user.id, sessionId }) + .sort({ timestamp: 1 }) + .toArray(); + + return NextResponse.json({ data: logs }); +} diff --git a/src/app/api/dashboard/sessions/route.ts b/src/app/api/dashboard/sessions/route.ts new file mode 100644 index 0000000..11460bd --- /dev/null +++ b/src/app/api/dashboard/sessions/route.ts @@ -0,0 +1,31 @@ +import { getSession } from "@/lib/auth-helpers"; +import { getMongoDb } from "@/lib/mongo"; +import { NextResponse } from "next/server"; + +export async function GET() { + const session = await getSession(); + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + + const db = getMongoDb(); + + // Group by sessionId and get session summaries + const sessions = await db.collection("debug_logs").aggregate([ + { $match: { userId: session.user.id, sessionId: { $exists: true, $ne: null } } }, + { $sort: { timestamp: -1 } }, + { + $group: { + _id: "$sessionId", + firstRequest: { $first: "$timestamp" }, + lastRequest: { $last: "$timestamp" }, + requestCount: { $sum: 1 }, + model: { $first: "$originalModel" }, + } + }, + { $sort: { lastRequest: -1 } }, + { $limit: 50 } + ]).toArray(); + + return NextResponse.json({ data: sessions }); +}