sharedProviderHttpClient function

Client sharedProviderHttpClient()

The shared keep-alive HTTP client for provider streams.

Streaming adapters use it when the caller injects no client: a fresh http.Client per request churns a new TCP+TLS connection every turn, which on tool-heavy runs piles up TIME_WAIT sockets until connect() stalls into the watchdog (kimi-cli/pi reuse one client for exactly this reason). The shared client is never closed per call — an aborted stream closes only its own response subscription.

If providerHttpClientFactory is set, its product is used and cached instead of the default http.Client.

Implementation

http.Client sharedProviderHttpClient() => _sharedProviderClient ??=
    (providerHttpClientFactory?.call() ?? http.Client());