44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
// RAG never goes through api-gateway. The gateway proxies `/auth/*` only --
|
|
// apps/api-gateway/src/proxy/ holds a single AuthProxyController -- so
|
|
// preferring AI_SERVICE_URL here pointed every RAG call at a service with no
|
|
// such route the moment apiGateway was enabled, breaking chat, suggest,
|
|
// history, sections, section-text and feedback at once. Resolve ai-service
|
|
// directly and let AI_SERVICE_URL mean what its name says: auth only.
|
|
const AI_SERVICE_URL = process.env.AI_SERVICE_URL ?? "http://localhost:8000";
|
|
|
|
export async function GET(request: Request) {
|
|
const { searchParams } = new URL(request.url);
|
|
const conversationId = searchParams.get("conversation_id")?.trim() || "";
|
|
|
|
if (!conversationId) {
|
|
return NextResponse.json({ items: [] });
|
|
}
|
|
|
|
try {
|
|
const base = AI_SERVICE_URL.replace(/\/v1\/rag(?:\/query)?\/?$/, "");
|
|
const targetUrl = `${base}/v1/rag/history?conversation_id=${encodeURIComponent(conversationId)}`;
|
|
|
|
const upstream = await fetch(targetUrl, {
|
|
method: "GET",
|
|
headers: {
|
|
"X-Client-Version": "1.0.0",
|
|
},
|
|
cache: "no-store",
|
|
signal: AbortSignal.timeout(8_000),
|
|
});
|
|
|
|
if (!upstream.ok) {
|
|
return NextResponse.json({ items: [] });
|
|
}
|
|
|
|
const data = await upstream.json();
|
|
return NextResponse.json(data);
|
|
} catch {
|
|
return NextResponse.json({ items: [] });
|
|
}
|
|
}
|