/** * Dispatcher factory: proxyUrl -> undici Dispatcher. * One instance per proxyUrl (connection pooling), lazy-created. * * http(s) proxies use undici's native ProxyAgent. * socks5/socks5h proxies need a bespoke undici Dispatcher: undici's fetch * "dispatcher" option requires an undici Dispatcher (it only accepts * http:// and https:// URLs in ProxyAgent), but a Node http.Agent such as * socks-proxy-agent's SocksProxyAgent is NOT a valid undici Dispatcher * ("agent.dispatch is not a function" -> Connection error). We therefore * build an undici Agent whose `connect` tunnels the TCP socket through the * socks server and returns the final socket (TLS-wrapped for https). */ /** * Raised pool defaults for proxied LLM traffic, applied to both the native * `ProxyAgent` and the bespoke socks `Agent` below. * * undici ships `keepAliveTimeout: 4s` / `connections: 10` per origin. LLM * calls arrive in sparse bursts (chat turns minutes apart, subagents fanning * out), so the stock 4s idle timeout leaves the pool cold almost every time * and the first token of each burst pays a full socks-CONNECT + TLS * handshake through the proxy. 30s idle retention keeps the previous turn's * sockets warm for the next one at the cost of a few idle fds; 20 * connections per origin absorbs parallel streaming fans without queueing. * `pipelining` stays at undici's default 1 — SSE streams must not pipeline. */ export declare const PROXY_POOL_DEFAULTS: { keepAliveTimeout: number; connections: number; }; /** * Cheap availability probe for the optional `socks` dependency, memoized. * Lets the host warn at configuration time instead of failing at first request. */ export declare function socksDependencyAvailable(): boolean; /** A proxy URL may be reused by many rules; cache one Dispatcher per URL. */ export declare function getOrCreateDispatcher(proxyUrl: string): unknown; /** * Retire dispatchers: remove them from the cache and close their pooled * sockets. `close()` is graceful — undici finishes in-flight requests before * tearing down, so evicting a URL mid-config-change never kills an active * stream. Best-effort: dispatcher instances without `close` are just dropped. * * Returns how many entries were removed (test seam). */ export declare function clearDispatcherCache(proxyUrl?: string): number; //# sourceMappingURL=dispatcher.d.ts.map