mirror of
https://github.com/better-auth/better-auth.git
synced 2026-06-02 12:26:43 -05:00
36 lines
871 B
TypeScript
36 lines
871 B
TypeScript
import type { NextRequest } from "next/server";
|
|
import { NextResponse } from "next/server";
|
|
import type { InkeepMessage } from "@/lib/inkeep-analytics";
|
|
import { logConversationToAnalytics } from "@/lib/inkeep-analytics";
|
|
|
|
export const runtime = "edge";
|
|
|
|
export async function POST(req: NextRequest) {
|
|
try {
|
|
const { messages }: { messages: InkeepMessage[] } = await req.json();
|
|
|
|
if (!messages || !Array.isArray(messages)) {
|
|
return NextResponse.json(
|
|
{ error: "Messages array is required" },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const result = await logConversationToAnalytics({
|
|
type: "openai",
|
|
messages,
|
|
properties: {
|
|
source: "better-auth-docs",
|
|
timestamp: new Date().toISOString(),
|
|
},
|
|
});
|
|
|
|
return NextResponse.json(result);
|
|
} catch {
|
|
return NextResponse.json(
|
|
{ error: "Failed to log conversation" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|