Updated Ai to pull from facebook, added a loading SVG to make user wait for server too boot up, and added commands that can be used to start off the AI exstraction

This commit is contained in:
Ace
2026-06-24 17:17:38 +02:00
parent 8a6ad5c6c6
commit b245b352e7
7 changed files with 307 additions and 88 deletions
+25 -4
View File
@@ -1,8 +1,29 @@
import { NextRequest, NextResponse } from "next/server"
import { chatWithAI } from "@/lib/ai"
import { getSessionUser } from "@/lib/auth"
// This route handler has a known issue with Next.js 15 fetch augmentation
// on this platform. The client-side code calls the AI server directly
// via browser fetch (CORS is open). This handler returns a fallback.
export async function POST(request: NextRequest) {
return NextResponse.json({ error: "AI service unavailable on server. Use client-side mode." }, { status: 503 })
try {
const user = await getSessionUser()
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
const { message } = await request.json()
if (!message || typeof message !== "string") {
return NextResponse.json({ error: "Message is required" }, { status: 400 })
}
const sessionCookie = request.cookies.get("session")
const jwtToken = sessionCookie?.value
if (!jwtToken) {
return NextResponse.json({ error: "No session token" }, { status: 401 })
}
const response = await chatWithAI(message, jwtToken)
return NextResponse.json({ response })
} catch (error: any) {
console.error("AI chat error:", error)
return NextResponse.json({ error: error.message || "AI service error" }, { status: 500 })
}
}