(timeoutMs = DEFAULT_TIMEOUT_MS)
| 138 | * Result is returned as a structured diagnostic; never throws. |
| 139 | */ |
| 140 | export async function checkPublicConnectivity(timeoutMs = DEFAULT_TIMEOUT_MS): Promise<NetworkDiagnostic> { |
| 141 | const probes = await Promise.all( |
| 142 | PUBLIC_ENDPOINTS.map(e => probeEndpoint(e.url, e.label, timeoutMs)), |
| 143 | ); |
| 144 | // "Internet" = can we reach Cloudflare 1.1.1.1? Other probes can be blocked |
| 145 | // by ISP without that meaning the machine is offline. |
| 146 | const cf = probes.find(p => p.endpoint === 'https://1.1.1.1'); |
| 147 | let internet: 'ok' | 'blocked' | 'unknown' = 'unknown'; |
| 148 | if (cf?.status === 'ok') internet = 'ok'; |
| 149 | else if (cf?.status === 'dns_failed' || cf?.status === 'connection_refused') internet = 'blocked'; |
| 150 | else if (probes.some(p => p.status === 'ok')) internet = 'ok'; // CF blocked but something works |
| 151 | return { internet, probes, timestamp: Date.now() }; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Quick probe of local model backends. Used by startup banner so we can tell |
no test coverage detected