| 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<string, unknown> |
| output_schema?: Record<string, unknown> |
| 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<string, unknown> | 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<string, unknown> | 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<T>(path: string, opts: RequestInit = {}): Promise<T> { |
| const token = typeof window !== 'undefined' ? localStorage.getItem('token') : null |
| const headers: Record<string, string> = { '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: <T>(path: string) => request<T>(path), |
| post: <T>(path: string, body?: unknown) => |
| request<T>(path, { method: 'POST', body: body ? JSON.stringify(body) : undefined }), |
| put: <T>(path: string, body?: unknown) => |
| request<T>(path, { method: 'PUT', body: body ? JSON.stringify(body) : undefined }), |
| delete: <T>(path: string) => request<T>(path, { method: 'DELETE' }), |
| } |
|
|