/** * 统一代理 Agent 工厂 * 消除各适配器中重复的代理 URL 构建和 Agent 创建逻辑 */ /** * 代理配置 */ export interface ProxyConfig { /** 代理服务器地址,如 http://127.0.0.1:7890 或 socks5://127.0.0.1:1080 */ url: string; /** 代理用户名(可选) */ username?: string; /** 代理密码(可选) */ password?: string; } /** * 构建包含认证信息的代理 URL * 使用 URL 对象确保正确编码用户名和密码中的特殊字符 */ export declare function buildProxyUrl(proxy: ProxyConfig): string; /** * 脱敏代理 URL(用于日志输出) * 将密码部分替换为 *** */ export declare function maskProxyUrl(url: string): string; /** * 创建 HTTPS 代理 Agent * @param proxy 代理配置 * @returns HttpsProxyAgent 实例,如果 https-proxy-agent 未安装则返回 null */ export declare function createHttpsProxyAgent(proxy: ProxyConfig): Promise; /** * 创建 SOCKS5 代理 Agent * @param proxy 代理配置 * @returns SocksProxyAgent 实例,如果 socks-proxy-agent 未安装则返回 null */ export declare function createSocksProxyAgent(proxy: ProxyConfig): Promise; /** * 创建代理 Agent(自动选择最佳可用代理类型) * * 策略: * 1. 如果 URL 以 socks 开头,优先使用 SocksProxyAgent * 2. 否则优先使用 HttpsProxyAgent * 3. 如果首选代理类型不可用,尝试回退 * 4. 如果都不可用,返回 null(直连) * * @param proxy 代理配置 * @param preferSocks 是否优先使用 SOCKS5(默认 false) * @returns 代理 Agent 实例,如果无可用代理则返回 null */ export declare function createProxyAgent(proxy: ProxyConfig | undefined, preferSocks?: boolean): Promise;