(path: string, options: RequestInit = {})
| 100 | |
| 101 | // API helpers |
| 102 | async function apiRequest<T>(path: string, options: RequestInit = {}): Promise<T> { |
| 103 | const headers = await getApiAuthHeaders(); |
| 104 | const { signal, ...restOptions } = options; |
| 105 | const response = await fetch(`${API_BASE_URL}${path}`, { |
| 106 | ...restOptions, |
| 107 | signal, |
| 108 | headers: { |
| 109 | ...headers, |
| 110 | 'Content-Type': 'application/json', |
| 111 | ...options.headers, |
| 112 | }, |
| 113 | }); |
| 114 | |
| 115 | if (!response.ok) { |
| 116 | const error = await response.json().catch(() => ({ message: 'Request failed' })); |
| 117 | throw new Error(error.message || `Request failed: ${response.status}`); |
| 118 | } |
| 119 | |
| 120 | // Handle 204 No Content |
| 121 | if (response.status === 204) { |
| 122 | return undefined as T; |
| 123 | } |
| 124 | |
| 125 | return response.json(); |
| 126 | } |
| 127 | |
| 128 | export const useMcpServerStore = create<McpServerStore>((set, get) => ({ |
| 129 | ...createInitialState(), |
no test coverage detected