(req: NextRequest, { params }: RouteParams)
| 31 | } |
| 32 | |
| 33 | export async function GET(req: NextRequest, { params }: RouteParams) { |
| 34 | // Check admin authentication |
| 35 | const authResult = await checkAdminAuth() |
| 36 | if (authResult instanceof NextResponse) { |
| 37 | return authResult |
| 38 | } |
| 39 | |
| 40 | const { clientRequestId } = await params |
| 41 | |
| 42 | if (!clientRequestId) { |
| 43 | return NextResponse.json( |
| 44 | { error: 'Missing required parameter: clientRequestId' }, |
| 45 | { status: 400 }, |
| 46 | ) |
| 47 | } |
| 48 | |
| 49 | try { |
| 50 | // Query messages by client_request_id |
| 51 | const messages = await db |
| 52 | .select({ |
| 53 | id: schema.message.id, |
| 54 | client_request_id: schema.message.client_request_id, |
| 55 | |
| 56 | user_id: schema.message.user_id, |
| 57 | model: schema.message.model, |
| 58 | request: schema.message.request, |
| 59 | response: schema.message.response, |
| 60 | finished_at: schema.message.finished_at, |
| 61 | latency_ms: schema.message.latency_ms, |
| 62 | credits: schema.message.credits, |
| 63 | input_tokens: schema.message.input_tokens, |
| 64 | output_tokens: schema.message.output_tokens, |
| 65 | org_id: schema.message.org_id, |
| 66 | repo_url: schema.message.repo_url, |
| 67 | }) |
| 68 | .from(schema.message) |
| 69 | .where(eq(schema.message.client_request_id, clientRequestId)) |
| 70 | .orderBy(schema.message.finished_at) |
| 71 | |
| 72 | if (messages.length === 0) { |
| 73 | return NextResponse.json( |
| 74 | { error: 'No messages found for this client request ID' }, |
| 75 | { status: 404 }, |
| 76 | ) |
| 77 | } |
| 78 | |
| 79 | logger.info( |
| 80 | { |
| 81 | adminId: authResult.id, |
| 82 | clientRequestId, |
| 83 | messageCount: messages.length, |
| 84 | }, |
| 85 | 'Admin fetched trace messages', |
| 86 | ) |
| 87 | |
| 88 | return NextResponse.json({ messages }) |
| 89 | } catch (error) { |
| 90 | logger.error({ error, clientRequestId }, 'Error fetching trace messages') |
nothing calls this directly
no test coverage detected