export interface Integration { id: string name: string description: string logo_url: string category: string auth_type: string tool_count: number trigger_count: number is_active: boolean } export interface Tool { id: string integration_id: string name: string description: string input_schema: Record output_schema?: Record category: string is_active: boolean } export interface Stats { total_executions: number successful: number failed: number success_rate: number avg_latency_ms: number } const API_BASE = typeof window !== 'undefined' ? '' : process.env.NEXT_PUBLIC_API_URL || '' async function fetchApi(path: string, opts: RequestInit = {}) { const token = typeof window !== 'undefined' ? localStorage.getItem('token') : null const headers: Record = { 'Content-Type': 'application/json' } if (token) headers['Authorization'] = `Bearer ${token}` const res = await fetch(`${API_BASE}${path}`, { ...opts, headers }) if (res.status === 401) { if (typeof window !== 'undefined') { localStorage.removeItem('token') window.location.href = '/login' } throw new Error('Unauthorized') } return res.json() } export const api = { get: (path: string) => fetchApi(path) as Promise, post: (path: string, body?: unknown) => fetchApi(path, { method: 'POST', body: body ? JSON.stringify(body) : undefined }) as Promise, delete: (path: string) => fetchApi(path, { method: 'DELETE' }) as Promise, }