import { NextRequest, NextResponse } from "next/server" import { createVoiceAssistantTokenResponse } from "@/lib/voice-assistant/server" import { isVoiceAssistantSuppressedRoute } from "@/lib/voice-assistant/shared" export const runtime = "nodejs" type TokenRequestBody = { pathname?: string } export async function POST(request: NextRequest) { try { const body = (await request.json().catch(() => ({}))) as TokenRequestBody const pathname = typeof body.pathname === "string" && body.pathname.trim() ? body.pathname.trim() : "/" if (isVoiceAssistantSuppressedRoute(pathname)) { console.info("[voice-assistant/token] blocked on suppressed route", { pathname, }) return NextResponse.json( { error: "Voice assistant is not available on this route." }, { status: 403 } ) } const tokenResponse = await createVoiceAssistantTokenResponse(pathname) console.info("[voice-assistant/token] issued token", { pathname, roomName: tokenResponse.roomName, participantIdentity: tokenResponse.participantIdentity, }) return NextResponse.json(tokenResponse) } catch (error) { console.error("Failed to create LiveKit voice assistant token:", error) return NextResponse.json( { error: error instanceof Error ? error.message : "Failed to create voice assistant token", }, { status: 500 } ) } }