export interface Integration { id: string name: string description: string logo_url: string category: string auth_type: string oauth_scopes?: string[] | null 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 | null is_active: boolean } export interface Connection { id: string integration_id: string integration_name: string account_label: string | null status: string connected_at: string last_used: string | null metadata: Record | null } export interface Stats { total_executions: number successful: number failed: number success_rate: number avg_latency_ms: number } export interface AuthField { name: string label: string type: string required: boolean description: string default: string } export interface AuthConfig { integration_id: string auth_type: string fields: AuthField[] oauth_authorize_url: string | null oauth_token_url: string | null } export interface ToolExecution { execution_id: string status: string result: Record | null latency_ms: number executed_at: string error: string | null } export interface APIKey { id: string name: string key_preview: string created_at: string last_used: string | null is_active: boolean } const API_BASE = '' async function request(path: string, opts: RequestInit = {}): Promise { 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') localStorage.removeItem('email') window.location.href = '/login' } throw new Error('Unauthorized') } if (!res.ok) { const data = await res.json().catch(() => ({ detail: 'Request failed' })) throw new Error(data.detail || `HTTP ${res.status}`) } return res.json() } export const api = { get: (path: string) => request(path), post: (path: string, body?: unknown) => request(path, { method: 'POST', body: body ? JSON.stringify(body) : undefined }), put: (path: string, body?: unknown) => request(path, { method: 'PUT', body: body ? JSON.stringify(body) : undefined }), delete: (path: string) => request(path, { method: 'DELETE' }), }