mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(proxy): Add error handling to proxy agent creation (#11538)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -76,9 +76,8 @@ import { MessageBus } from '../confirmation-bus/message-bus.js';
|
||||
import { PolicyEngine } from '../policy/policy-engine.js';
|
||||
import type { PolicyEngineConfig } from '../policy/types.js';
|
||||
import type { UserTierId } from '../code_assist/types.js';
|
||||
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
||||
|
||||
import { AgentRegistry } from '../agents/registry.js';
|
||||
import { setGlobalProxy } from '../utils/fetch.js';
|
||||
import { SubagentToolWrapper } from '../agents/subagent-tool-wrapper.js';
|
||||
|
||||
export enum ApprovalMode {
|
||||
@@ -506,7 +505,7 @@ export class Config {
|
||||
}
|
||||
|
||||
if (this.getProxy()) {
|
||||
setGlobalDispatcher(new ProxyAgent(this.getProxy() as string));
|
||||
setGlobalProxy(this.getProxy() as string);
|
||||
}
|
||||
this.geminiClient = new GeminiClient(this);
|
||||
this.modelRouterService = new ModelRouterService(this);
|
||||
|
||||
@@ -21,9 +21,12 @@ import { getErrorMessage } from '../utils/errors.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import { ApprovalMode, DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js';
|
||||
import { getResponseText } from '../utils/partUtils.js';
|
||||
import { fetchWithTimeout, isPrivateIp } from '../utils/fetch.js';
|
||||
import {
|
||||
fetchWithTimeout,
|
||||
isPrivateIp,
|
||||
setGlobalProxy,
|
||||
} from '../utils/fetch.js';
|
||||
import { convert } from 'html-to-text';
|
||||
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
||||
import {
|
||||
logWebFetchFallbackAttempt,
|
||||
WebFetchFallbackAttemptEvent,
|
||||
@@ -425,7 +428,7 @@ export class WebFetchTool extends BaseDeclarativeTool<
|
||||
);
|
||||
const proxy = config.getProxy();
|
||||
if (proxy) {
|
||||
setGlobalDispatcher(new ProxyAgent(proxy as string));
|
||||
setGlobalProxy(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import { getErrorMessage, isNodeError } from './errors.js';
|
||||
import { URL } from 'node:url';
|
||||
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
||||
|
||||
const PRIVATE_IP_RANGES = [
|
||||
/^10\./,
|
||||
@@ -55,3 +56,11 @@ export async function fetchWithTimeout(
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
|
||||
export function setGlobalProxy(proxy: string) {
|
||||
try {
|
||||
setGlobalDispatcher(new ProxyAgent(proxy));
|
||||
} catch (e) {
|
||||
console.error(`Failed to set proxy: ${getErrorMessage(e)}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user