import * as tls from "node:tls"; import type { FetchImpl } from "../types.js"; /** * Checks if a host is local or cloud metadata, which should always bypass the proxy * (e.g. localhost, 127/8, ::1, 169.254.169.254, metadata.google.internal). */ export declare function isLocalOrMetadataHost(host: string): boolean; /** * Check if the url should bypass the proxy due to hard-coded localhost/metadata checks * or custom NO_PROXY/no_proxy environment variables rules. */ export declare function shouldBypassProxy(urlObj: URL): boolean; /** Test seam: clears the provider proxy cache. */ export declare function __resetProxyCache(): void; /** * Normalizes provider id (e.g. github-copilot -> PI_PROXY_GITHUB_COPILOT) and looks it up. * If not found, falls back to PI_PROXY. Results are memoized because env values are static * for the lifetime of the process and this function is called for every outgoing request. */ export declare function getProxyForProvider(provider: string): string | undefined; /** Resolves provider-specific and standard proxy variables for a target URL, honoring NO_PROXY. */ export declare function getProxyForUrl(provider: string, url: URL): string | undefined; /** * Return `init` with `proxy: proxyUrl` set when the request should tunnel. * A caller-supplied `init.proxy` always wins (the innermost, most specific * decision); Unix sockets, local/metadata hosts, NO_PROXY matches, and * unparseable URLs pass through unchanged. */ export declare function withProxyInit(input: string | URL | Request, init: RequestInit | undefined, proxyUrl: string): RequestInit | undefined; /** * Wraps a fetch implementation to inject proxy options for non-local hosts. */ export declare function wrapFetchForProxy(fetchImpl: FetchImpl, provider: string): FetchImpl; /** Test seam: re-arms {@link installGlobalProxyFetch}. */ export declare function __resetGlobalProxyFetch(): void; /** * Routes the process-wide `globalThis.fetch` through `PI_PROXY`. * * Bun's native fetch resolves `HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY` by * itself but knows nothing about `PI_PROXY`. Provider *streams* get their proxy * from {@link wrapFetchForProxy}; every other provider-bound request — OAuth * token refresh and login, usage probes, model discovery — goes out through the * bare global `fetch` and would silently ignore `PI_PROXY`. That asymmetry is * fatal wherever a provider geo-blocks its token endpoint: the stream is * proxied, the refresh is not, and the credential dies with a 403. * * A per-request `proxy` (including `PI_PROXY_` injected by * {@link wrapFetchForProxy}) still wins, and loopback / private-range / * `NO_PROXY` targets bypass, so local model servers and MCP hosts are * untouched. Idempotent; a no-op when `PI_PROXY` is unset. */ export declare function installGlobalProxyFetch(): void; export interface ConnectProxiedSocketOptions { /** Caller cancellation for the proxy TCP/TLS handshake and CONNECT tunnel. */ signal?: AbortSignal; /** Maximum wall-clock time to establish the final TLS tunnel. Disabled when absent or non-positive. */ timeoutMs?: number; /** Target TLS profile. Cursor defaults to HTTP/2 when this is absent. */ tls?: tls.ConnectionOptions; } /** * Tunnel a socket connection through an HTTP CONNECT proxy. * This is used specifically to wrap Node's `http2.connect(baseUrl, { createConnection })` for Cursor. */ export declare function connectProxiedSocket(proxyUrlStr: string, targetUrlStr: string, options?: ConnectProxiedSocketOptions): Promise;