(apiKey, proxy = null)
| 253 | * @returns {Promise<{configs: object[], sorts: object[], defaultOverride: object|null}>} |
| 254 | */ |
| 255 | export async function getCascadeModelConfigs(apiKey, proxy = null) { |
| 256 | const body = { metadata: buildMetadata(apiKey) }; |
| 257 | |
| 258 | const proxyModes = proxy ? [proxy, null] : [null]; |
| 259 | let lastErr = null; |
| 260 | for (const px of proxyModes) { |
| 261 | for (const host of SERVER_HOSTS) { |
| 262 | try { |
| 263 | const res = await postJson(host, MODEL_CONFIGS_PATH, body, px); |
| 264 | if (res.status >= 400) { |
| 265 | lastErr = new Error(`GetCascadeModelConfigs ${host} → ${res.status}: ${res.raw.slice(0, 160)}`); |
| 266 | continue; |
| 267 | } |
| 268 | return { |
| 269 | configs: res.data.clientModelConfigs || [], |
| 270 | sorts: res.data.clientModelSorts || [], |
| 271 | defaultOverride: res.data.defaultOverrideModelConfig || null, |
| 272 | }; |
| 273 | } catch (e) { |
| 274 | lastErr = e; |
| 275 | log.debug(`GetCascadeModelConfigs host ${host} failed: ${e.message}`); |
| 276 | if (px && isProxyError(e)) break; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | throw lastErr || new Error('GetCascadeModelConfigs: all hosts failed'); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Direct Windsurf web search API. |
no test coverage detected