| 117 | >; |
| 118 | |
| 119 | export async function fetchProviderModels( |
| 120 | connection: LlmConnection, |
| 121 | apiKey: string, |
| 122 | options: ConnectionEffectFetchOptions = {}, |
| 123 | ): Promise<ModelInfo[]> { |
| 124 | try { |
| 125 | return normalizeDiscoveredModels( |
| 126 | await fetchProviderModelsStrict(connection, apiKey, options.fetch), |
| 127 | ); |
| 128 | } catch (error) { |
| 129 | // Preserve status-bearing discovery errors so the sync layer can classify |
| 130 | // auth/protocol/network failures; only wrap unknown errors for display. |
| 131 | if ( |
| 132 | error instanceof OpenAiCodexDiscoveryError || |
| 133 | error instanceof ProviderModelDiscoveryHttpError |
| 134 | ) { |
| 135 | throw error; |
| 136 | } |
| 137 | throw new Error(generalizedErrorMessage(error, 'Failed to fetch provider models')); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | export async function runConnectionModelDiscoveryEffect( |
| 142 | connection: ConnectionEffectConnection, |