/** * Typed API client for the SupportRAG FastAPI backend. * All requests go through Next.js /api/* rewrite → localhost:8000 */ export interface Citation { rank: number content: string similarity: number source: string category: string resolution_status?: string | null } export interface QueryResponse { answer: string source: string confidence: number citations: Citation[] latency_ms: number query: string timestamp: string } export interface HealthResponse { status: string faq_store_loaded: boolean ticket_store_loaded: boolean faq_threshold: number } export interface StatsResponse { total_queries: number avg_latency_ms: number avg_confidence: number source_breakdown: Record } const BASE = "/api" async function request(path: string, init?: RequestInit): Promise { const res = await fetch(`${BASE}${path}`, { headers: { "Content-Type": "application/json" }, ...init, }) if (!res.ok) { const err = await res.text() throw new Error(err || `HTTP ${res.status}`) } return res.json() as Promise } export async function queryRAG(question: string, top_k = 3): Promise { return request("/query", { method: "POST", body: JSON.stringify({ question, top_k }), }) } export async function getHealth(): Promise { return request("/health") } export async function getStats(): Promise { return request("/stats") }