mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-04-20 03:02:51 -04:00
Integrated undici ProxyAgent for native fetch and HttpsProxyAgent for axios/openai/anthropic. Upgraded @google/generative-ai to fix #536. Added OCO_PROXY config. Co-authored-by: uni <uni@hanwei.ink>
22 lines
794 B
TypeScript
22 lines
794 B
TypeScript
import { setGlobalDispatcher, ProxyAgent } from 'undici';
|
|
import axios from 'axios';
|
|
import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
|
|
export function setupProxy(proxyUrl?: string) {
|
|
const proxy = proxyUrl || process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
|
|
if (proxy) {
|
|
try {
|
|
// Set global dispatcher for undici (affects globalThis.fetch used by Gemini and others)
|
|
const dispatcher = new ProxyAgent(proxy);
|
|
setGlobalDispatcher(dispatcher);
|
|
|
|
// Set axios global agent
|
|
const agent = new HttpsProxyAgent(proxy);
|
|
axios.defaults.httpsAgent = agent;
|
|
axios.defaults.proxy = false; // Disable axios built-in proxy handling to use agent
|
|
} catch (error) {
|
|
console.warn(`[Proxy Error] Failed to set proxy: ${error.message}`);
|
|
}
|
|
}
|
|
}
|