From 25809c1532524d35563ad2f84f4212a1fa62d964 Mon Sep 17 00:00:00 2001 From: thzxx Date: Wed, 10 Jun 2026 16:00:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=20https-proxy-agent?= =?UTF-8?q?=20=E4=BE=9D=E8=B5=96=EF=BC=8C=E8=A7=A3=E5=86=B3=E4=BB=A3?= =?UTF-8?q?=E7=90=86DNS=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- src/main/tool-handlers-system.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 60a48e3..7b87a91 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "vite": "^5.4.0" }, "dependencies": { - "sql.js": "^1.11.0" + "sql.js": "^1.11.0", + "https-proxy-agent": "^7.0.0" } } diff --git a/src/main/tool-handlers-system.ts b/src/main/tool-handlers-system.ts index c5b6553..a935099 100644 --- a/src/main/tool-handlers-system.ts +++ b/src/main/tool-handlers-system.ts @@ -12,24 +12,27 @@ import { getWorkspaceDir } from './workspace.js'; // ── 代理支持 ── let _proxyUrl = ''; -let _proxyAgent: any = null; function getProxyAgent(): any { if (!_proxyUrl) return null; - if (_proxyAgent) return _proxyAgent; try { - const { ProxyAgent } = require('undici'); - _proxyAgent = new ProxyAgent(_proxyUrl); - return _proxyAgent; + const url = new URL(_proxyUrl); + const { HttpsProxyAgent } = require('https-proxy-agent'); + return new HttpsProxyAgent(url); } catch { - return null; + // https-proxy-agent 不可用,尝试 undici + try { + const { ProxyAgent } = require('undici'); + return new ProxyAgent(_proxyUrl); + } catch { + return null; + } } } /** 设置 HTTP 代理(供 IPC 调用) */ export function setProxyUrl(url: string): void { _proxyUrl = url; - _proxyAgent = null; // 重建 agent } /** 当前工具命令进程(用于用户手动终止) */