( connection: ConnectionEffectConnection, apiKey: string, options: ConnectionEffectFetchDependency, model?: string, )
| 87 | } |
| 88 | |
| 89 | export async function runConnectionTestEffect( |
| 90 | connection: ConnectionEffectConnection, |
| 91 | apiKey: string, |
| 92 | options: ConnectionEffectFetchDependency, |
| 93 | model?: string, |
| 94 | ): Promise<ConnectionTestEffectOutcome> { |
| 95 | const t0 = Date.now(); |
| 96 | try { |
| 97 | const result = await testConnectionStrict(connection, apiKey, model, options.fetch, t0); |
| 98 | if (result.ok) { |
| 99 | if (!result.modelTested || result.latencyMs === undefined) { |
| 100 | return { ok: false, error: { kind: 'invalid_response' } }; |
| 101 | } |
| 102 | return { |
| 103 | ok: true, |
| 104 | modelId: result.modelTested, |
| 105 | latencyMs: result.latencyMs, |
| 106 | }; |
| 107 | } |
| 108 | return { |
| 109 | ok: false, |
| 110 | error: classifyConnectionTestResult(result), |
| 111 | ...connectionTestMeasurements(result), |
| 112 | }; |
| 113 | } catch (error) { |
| 114 | return { |
| 115 | ok: false, |
| 116 | error: classifyConnectionTestError(error), |
| 117 | latencyMs: Date.now() - t0, |
| 118 | }; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | async function testConnectionStrict( |
| 123 | connection: ConnectionEffectConnection, |
no test coverage detected