feat: 设置面板添加代理配置 — web_search/web_fetch走HTTP代理(Clash等)

This commit is contained in:
thzxx
2026-06-10 15:38:56 +08:00
parent 3c54f15218
commit 3f11e7c3cd
6 changed files with 50 additions and 1 deletions
+15
View File
@@ -231,6 +231,21 @@ export async function setupIPC(): Promise<void> {
return { success: true };
});
// ── 代理设置(web_search/web_fetch 走代理)──
ipcMain.handle('proxy:set', (_, url: string) => {
if (url) {
process.env.HTTP_PROXY = url;
process.env.HTTPS_PROXY = url;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
sendLog('info', `🌐 代理已设置`, url);
} else {
delete process.env.HTTP_PROXY;
delete process.env.HTTPS_PROXY;
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
sendLog('info', `🌐 代理已禁用`);
}
});
// ── Workspace IPC ──
// 获取工作空间目录
+2 -1
View File
@@ -20,7 +20,8 @@ contextBridge.exposeInMainWorld('metonaDesktop', {
execute: (toolName: string, args: Record<string, unknown>) => ipcRenderer.invoke('tool:execute', toolName, args),
getConfig: () => ipcRenderer.invoke('tool:getConfig'),
setAllowedDirs: (dirs: string[]) => ipcRenderer.invoke('tool:setAllowedDirs', dirs),
setTimeouts: (timeouts: { http?: number; mcp?: number }) => ipcRenderer.invoke('tool:setTimeouts', timeouts)
setTimeouts: (timeouts: { http?: number; mcp?: number }) => ipcRenderer.invoke('tool:setTimeouts', timeouts),
setProxy: (url: string) => ipcRenderer.invoke('proxy:set', url)
},
notify: (title: string, body: string) => ipcRenderer.invoke('notify', title, body),
window: {
+12
View File
@@ -39,6 +39,18 @@ export function initSettingsModal(): void {
}, 500);
document.querySelector('#inputServerUrl')!.addEventListener('input', saveServerUrl);
// 代理设置
const inputProxyUrl = document.querySelector('#inputProxyUrl') as HTMLInputElement;
if (inputProxyUrl) {
const saveProxyUrl = debounce(async () => {
const db = state.get<ChatDB | null>(KEYS.DB);
const url = inputProxyUrl.value.trim();
if (db) await db.saveSetting('proxyUrl', url);
logSetting('代理', url || '已禁用');
}, 500);
inputProxyUrl.addEventListener('input', saveProxyUrl);
}
const tempSlider = document.querySelector('#inputTemperature') as HTMLInputElement;
const tempDisplay = document.querySelector('#tempValue')!;
tempSlider.addEventListener('input', () => {
+5
View File
@@ -271,6 +271,11 @@
<code>OLLAMA_ORIGINS="*" ollama serve</code>
</div>
</div>
<div class="setting-group">
<label class="setting-label">🌐 代理设置(用于 web_search / web_fetch</label>
<input class="setting-input" id="inputProxyUrl" type="text" placeholder="http://127.0.0.1:7890">
<p class="text-muted" style="font-size:11px;">留空则不使用代理。支持 HTTP 代理,例如 Clash(http://127.0.0.1:7890)。修改后需重启应用生效。</p>
</div>
<div class="setting-group">
<label class="setting-label">上下文长度(自动检测)</label>
<div style="display:flex;gap:8px;align-items:center;">
+15
View File
@@ -394,6 +394,21 @@ async function init(): Promise<void> {
(document.querySelector('#inputMCPTimeout') as HTMLInputElement).value = mcpTimeout >= 0 ? String(mcpTimeout) : '';
logInit(`超时设置: HTTP=${httpTimeout>=0?httpTimeout:30}s 流式=${streamTimeout>=0?streamTimeout:300}s MCP=${mcpTimeout>=0?mcpTimeout:60}s`);
// ── 代理设置 ──
const proxyUrl = await db.getSetting('proxyUrl', '');
if (proxyUrl) {
try {
await fetch(proxyUrl, { method: 'HEAD', signal: AbortSignal.timeout(2000) });
logInit(`代理: ${proxyUrl}`);
} catch { logInit(`代理: ${proxyUrl} (无法连接,但已设置)`); }
state.set('proxyUrl', proxyUrl);
// 通知主进程设置环境变量
if (bridge?.tool?.setProxy) {
await bridge.tool.setProxy(proxyUrl);
}
}
(document.querySelector('#inputProxyUrl') as HTMLInputElement).value = proxyUrl;
// ── Tool Calling 设置(永久开启,不可关闭)──
state.set('toolCallingEnabled', true);
const runCommandMode = await db.getSetting('runCommandMode', 'confirm') as 'auto' | 'confirm' | 'disabled';
+1
View File
@@ -221,6 +221,7 @@ export interface MetonaDesktopAPI {
getConfig: () => Promise<{ allowedDirs: string[]; blockedDirs: string[] }>;
setAllowedDirs: (dirs: string[]) => Promise<void>;
setTimeouts: (timeouts: { http?: number; mcp?: number }) => Promise<{ success: boolean }>;
setProxy: (url: string) => Promise<void>;
};
notify: (title: string, body: string) => void;
window: {