import { NextResponse } from "next/server" import { requirePhoneAgentInternalAuth } from "@/app/api/internal/phone-calls/shared" import { searchServiceKnowledge } from "@/lib/service-knowledge" export async function POST(request: Request) { const authError = await requirePhoneAgentInternalAuth(request) if (authError) { return authError } try { const body = await request.json() const query = String(body.query || "").trim() if (!query) { return NextResponse.json({ error: "query is required" }, { status: 400 }) } const results = await searchServiceKnowledge({ query, limit: typeof body.limit === "number" && body.limit > 0 ? Math.min(body.limit, 6) : 4, }) return NextResponse.json({ success: true, results, }) } catch (error) { console.error("Failed to search phone agent service knowledge:", error) return NextResponse.json( { error: "Failed to search phone agent service knowledge" }, { status: 500 } ) } }