Initial commit

This commit is contained in:
Haitham Khalifa
2026-02-16 12:02:45 +01:00
commit 11252e6520
37 changed files with 8118 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
import { NextResponse } from "next/server";
import { runSiteMenteText } from "../../../../lib/ai/siteMenteAgent";
type MessagePayload = {
role: "user" | "assistant" | "system";
content: string;
};
const isValidMessage = (message: MessagePayload) => {
return (
message &&
typeof message.content === "string" &&
["user", "assistant", "system"].includes(message.role)
);
};
export const runtime = "nodejs";
export async function POST(request: Request) {
try {
const body = (await request.json()) as { messages?: MessagePayload[] };
if (!Array.isArray(body.messages) || body.messages.length === 0) {
return NextResponse.json(
{ error: "messages array is required." },
{ status: 400 }
);
}
if (!body.messages.every(isValidMessage)) {
return NextResponse.json(
{ error: "messages must include role and content." },
{ status: 400 }
);
}
const { reply } = await runSiteMenteText({ messages: body.messages });
return NextResponse.json({ reply });
} catch (error) {
console.error("[SiteMente][API] Text route failed", error);
return NextResponse.json(
{ error: "Failed to generate response." },
{ status: 500 }
);
}
}