MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / createProxyDispatcher

Function createProxyDispatcher

packages/agent-core/src/utils/proxy.ts:263–292  ·  view source on GitHub ↗
(
  env: Env = process.env,
  factories: Partial<ProxyAgentFactories> = {},
)

Source from the content-addressed store, hash-verified

261 * dispatcher untouched.
262 */
263export function createProxyDispatcher(
264 env: Env = process.env,
265 factories: Partial<ProxyAgentFactories> = {},
266): Dispatcher | undefined {
267 const { makeHttpAgent = defaultMakeHttpAgent, makeSocksAgent = defaultMakeSocksAgent } = factories;
268 try {
269 if (hasHttpProxy(env)) {
270 // Coerce a missing value to '' (falsy to undici) so EnvHttpProxyAgent
271 // neither builds a broken agent from a socks: URI nor re-reads a
272 // blank-masked value from env.
273 const { httpProxy, httpsProxy } = resolveHttpProxyUrls(env);
274 return makeHttpAgent({
275 httpProxy: httpProxy ?? '',
276 httpsProxy: httpsProxy ?? '',
277 noProxy: resolveNoProxy(env),
278 });
279 }
280 const socks = resolveSocksProxy(env);
281 if (socks !== undefined) {
282 return makeSocksAgent({ proxy: socks, noProxy: resolveNoProxy(env) });
283 }
284 return undefined;
285 } catch (error) {
286 // A malformed proxy URL makes agent construction throw synchronously. Don't
287 // abort startup with a raw stack trace — report it and fall back to direct.
288 const reason = error instanceof Error ? error.message : String(error);
289 process.stderr.write(`kimi: ignoring invalid proxy configuration (${reason}); connecting directly\n`);
290 return undefined;
291 }
292}
293
294export interface InstallProxyDeps {
295 readonly setGlobalDispatcher: (dispatcher: Dispatcher) => void;

Callers 1

proxy.test.tsFile · 0.90

Calls 5

hasHttpProxyFunction · 0.85
resolveHttpProxyUrlsFunction · 0.85
resolveNoProxyFunction · 0.85
resolveSocksProxyFunction · 0.85
writeMethod · 0.65

Tested by

no test coverage detected