import { Router } from "express"; import { requireApiKey } from "../middlewares/auth.js"; const router = Router(); const NEO_REST_URL = "http://localhost:5001"; router.post("/neo/chat", requireApiKey, async (req, res) => { const { message, history = [] } = req.body as { message?: string; history?: Array<{ role: string; content: string }>; }; if (!message || typeof message !== "string" || !message.trim()) { res.status(400).json({ error: "The 'message' field is required." }); return; } try { const response = await fetch(`${NEO_REST_URL}/chat`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message: message.trim(), history }), }); if (!response.ok) { const err = await response.text(); res.status(502).json({ error: "NEO-1 model error.", detail: err }); return; } const data = await response.json() as { response: string; model: string; status: string }; res.json({ response: data.response, model: data.model ?? "mdfjbots-neo-1", status: "ok", }); } catch (err: any) { res.status(503).json({ error: "Could not connect to the NEO-1 model. Is it running?", detail: err?.message ?? String(err), }); } }); router.get("/neo/models", requireApiKey, (_req, res) => { res.json({ models: [ { id: "mdfjbots-neo-1", name: "NEO-1", description: "Conversational assistant with Roblox support, calculator, and educational topics.", version: "1.13.1", }, ], }); }); export default router;