diff --git a/ui/homepage/app/api/rag/query/route.ts b/ui/homepage/app/api/rag/query/route.ts new file mode 100644 index 0000000..3274d87 --- /dev/null +++ b/ui/homepage/app/api/rag/query/route.ts @@ -0,0 +1,21 @@ +import { getServerServiceBaseUrl } from '@lib/serviceConfig' + +export async function POST(req: Request) { + try { + const { question, history } = await req.json() + const apiBase = getServerServiceBaseUrl() + const response = await fetch(`${apiBase}/api/rag/query`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ question, history }) + }) + + const data = await response.json().catch(() => null) + return Response.json(data ?? { error: 'Invalid response from server' }, { + status: response.status + }) + } catch (error) { + const message = error instanceof Error ? error.message : 'Unknown error' + return Response.json({ error: message }, { status: 500 }) + } +} diff --git a/ui/homepage/components/AskAIButton.tsx b/ui/homepage/components/AskAIButton.tsx index eae48db..860adc8 100644 --- a/ui/homepage/components/AskAIButton.tsx +++ b/ui/homepage/components/AskAIButton.tsx @@ -4,12 +4,10 @@ import { useState } from 'react' import { Bot } from 'lucide-react' import { AskAIDialog } from './AskAIDialog' import { useAccess } from '@lib/accessControl' -import { getServerServiceBaseUrl } from '@lib/serviceConfig' export function AskAIButton() { const [open, setOpen] = useState(false) const [minimized, setMinimized] = useState(false) - const apiBase = getServerServiceBaseUrl() const { allowed, isLoading } = useAccess({ allowGuests: true }) if (!allowed && !isLoading) { @@ -32,7 +30,6 @@ export function AskAIButton() { { setOpen(false) setMinimized(true) diff --git a/ui/homepage/components/AskAIDialog.tsx b/ui/homepage/components/AskAIDialog.tsx index 7b0e29a..4f48661 100644 --- a/ui/homepage/components/AskAIDialog.tsx +++ b/ui/homepage/components/AskAIDialog.tsx @@ -11,12 +11,10 @@ const MAX_CACHE_SIZE = 50 export function AskAIDialog({ open, - apiBase, onMinimize, onEnd }: { open: boolean - apiBase: string onMinimize: () => void onEnd: () => void }) { @@ -171,7 +169,7 @@ export function AskAIDialog({ try { let { answer, retrieved } = await streamChat( - `${apiBase}/api/rag/query`, + '/api/rag/query', { question: normalized, history }, updateAI ) @@ -184,7 +182,7 @@ export function AskAIDialog({ ) try { const result = await streamChat( - `${apiBase}/api/askai`, + '/api/askai', { question: normalized, history }, updateAI )