// API client configuration // Base URL configuration - works in both dev and production const API_BASE_URL = import.meta.env.DEV ? '/api' // Proxy to backend in development : 'http://localhost:8000/api'; // Direct backend in production // Generic API request function async function apiRequest( endpoint: string, options: RequestInit = {} ): Promise { const url = `${API_BASE_URL}${endpoint}`; try { const response = await fetch(url, { ...options, headers: { ...options.headers, } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error('API request failed:', error); throw error; } } // API methods export const api = { // Upload file async uploadFile(file: File): Promise { const formData = new FormData(); formData.append('file', file); return apiRequest('/upload', { method: 'POST', body: formData }); }, // Process query async processQuery(request: QueryRequest): Promise { return apiRequest('/query', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(request) }); }, // Get database schema async getSchema(): Promise { return apiRequest('/schema'); }, // Generate insights async generateInsights(request: InsightsRequest): Promise { return apiRequest('/insights', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(request) }); }, // Health check async healthCheck(): Promise { return apiRequest('/health'); } };