(path, options = {})
| 28 | |
| 29 | // ===== API HELPERS ===== |
| 30 | async function apiRequest(path, options = {}) { |
| 31 | const endpoint = path.startsWith("/") ? path : `/${path}`; |
| 32 | |
| 33 | async function request(baseUrl) { |
| 34 | const response = await fetch(`${baseUrl}${endpoint}`, options); |
| 35 | const data = await response.json(); |
| 36 | if (!response.ok) { |
| 37 | throw new Error(data.message || `Request failed with status ${response.status}`); |
| 38 | } |
| 39 | return data; |
| 40 | } |
| 41 | |
| 42 | try { |
| 43 | return await request(API_BASE_URL); |
| 44 | } catch (firstError) { |
| 45 | if (API_BASE_URL !== API_FALLBACK_URL) { |
| 46 | return request(API_FALLBACK_URL); |
| 47 | } |
| 48 | throw firstError; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | function setModelOptions(models, preferredModel) { |
| 53 | aiModel.innerHTML = ""; |
no test coverage detected