mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -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 { PolicyEngine } from '../policy/policy-engine.js';
|
||||||
import type { PolicyEngineConfig } from '../policy/types.js';
|
import type { PolicyEngineConfig } from '../policy/types.js';
|
||||||
import type { UserTierId } from '../code_assist/types.js';
|
import type { UserTierId } from '../code_assist/types.js';
|
||||||
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
|
||||||
|
|
||||||
import { AgentRegistry } from '../agents/registry.js';
|
import { AgentRegistry } from '../agents/registry.js';
|
||||||
|
import { setGlobalProxy } from '../utils/fetch.js';
|
||||||
import { SubagentToolWrapper } from '../agents/subagent-tool-wrapper.js';
|
import { SubagentToolWrapper } from '../agents/subagent-tool-wrapper.js';
|
||||||
|
|
||||||
export enum ApprovalMode {
|
export enum ApprovalMode {
|
||||||
@@ -506,7 +505,7 @@ export class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.getProxy()) {
|
if (this.getProxy()) {
|
||||||
setGlobalDispatcher(new ProxyAgent(this.getProxy() as string));
|
setGlobalProxy(this.getProxy() as string);
|
||||||
}
|
}
|
||||||
this.geminiClient = new GeminiClient(this);
|
this.geminiClient = new GeminiClient(this);
|
||||||
this.modelRouterService = new ModelRouterService(this);
|
this.modelRouterService = new ModelRouterService(this);
|
||||||
|
|||||||
@@ -21,9 +21,12 @@ import { getErrorMessage } from '../utils/errors.js';
|
|||||||
import type { Config } from '../config/config.js';
|
import type { Config } from '../config/config.js';
|
||||||
import { ApprovalMode, DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js';
|
import { ApprovalMode, DEFAULT_GEMINI_FLASH_MODEL } from '../config/config.js';
|
||||||
import { getResponseText } from '../utils/partUtils.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 { convert } from 'html-to-text';
|
||||||
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
|
||||||
import {
|
import {
|
||||||
logWebFetchFallbackAttempt,
|
logWebFetchFallbackAttempt,
|
||||||
WebFetchFallbackAttemptEvent,
|
WebFetchFallbackAttemptEvent,
|
||||||
@@ -425,7 +428,7 @@ export class WebFetchTool extends BaseDeclarativeTool<
|
|||||||
);
|
);
|
||||||
const proxy = config.getProxy();
|
const proxy = config.getProxy();
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
setGlobalDispatcher(new ProxyAgent(proxy as string));
|
setGlobalProxy(proxy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import { getErrorMessage, isNodeError } from './errors.js';
|
import { getErrorMessage, isNodeError } from './errors.js';
|
||||||
import { URL } from 'node:url';
|
import { URL } from 'node:url';
|
||||||
|
import { ProxyAgent, setGlobalDispatcher } from 'undici';
|
||||||
|
|
||||||
const PRIVATE_IP_RANGES = [
|
const PRIVATE_IP_RANGES = [
|
||||||
/^10\./,
|
/^10\./,
|
||||||
@@ -55,3 +56,11 @@ export async function fetchWithTimeout(
|
|||||||
clearTimeout(timeoutId);
|
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