1
>
/*---------------------------------------------------------------------------------------------
agentHostProxyResolver.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { LogLevel as ProxyLogLevel, ProxyAgentParams, ProxySupportSetting, createFetchPatch, createProxyAuthorizationLookup, createProxyResolver, loadSystemCertificates } from '@vscode/proxy-agent';
7
>
import { IDisposable, toDisposable } from '../../../base/common/lifecycle.js';
8
>
import { IConfigurationService } from '../../configuration/common/configuration.js';
9
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
10
>
import { ILogService, LogLevel } from '../../log/common/log.js';
11
>
import { AuthInfo, Credentials, systemCertificatesNodeDefault } from '../../request/common/request.js';
12
>
import { IAgentHostClientProxyConnection } from '../common/agentHostClientProxyChannel.js';
13
>
14
>
export const IAgentHostProxyResolver = createDecorator<IAgentHostProxyResolver>('agentHostProxyResolver');
15
>
16
>
/**
17
>
* Node-side registry of renderer {@link IAgentHostClientProxyConnection}s keyed
18
>
* by client id. Populated by the agent host's connection lifecycle (one entry
19
>
* per connected renderer) and consumed by {@link CopilotAgent} to resolve the
20
>
* CAPI proxy through VS Code's Electron session before spawning the Copilot SDK.
21
>
*
22
>
* Proxy configuration is a property of the machine, not of a particular window,
23
>
* so any connected renderer can serve the lookup; the resolver calls the first
24
>
* available connection and falls through to the next on failure.
25
>
*/
26
>
export interface IAgentHostProxyResolver {
27
>
readonly _serviceBrand: undefined;
28
>
29
>
/** Register a renderer connection. Disposing the result removes it. */
30
>
register(clientId: string, connection: IAgentHostClientProxyConnection): IDisposable;
31
>
32
>
/**
33
>
* Resolve the proxy URL for `url` (e.g. `http://host:port`), or `undefined`
34
>
* for a direct connection. Reuses `@vscode/proxy-agent`'s `resolveProxyURL`
35
>
* so the same precedence as the rest of VS Code applies: `http.noProxy` →
36
>
* `http.proxy` setting → `HTTP(S)_PROXY` env vars → the host proxy resolution
37
>
* that runs in VS Code (Electron session) via the reverse channel.
38
>
*/
39
>
resolveProxy(url: string): Promise<string | undefined>;
40
>
41
>
/** Fetch using the same proxy, certificate, and host/PAC resolution as {@link resolveProxy}. */
42
>
fetch(input: string | URL | Request, init?: RequestInit): Promise<Response>;
43
>
}
44
>
45
>
export class AgentHostProxyResolver implements IAgentHostProxyResolver {
46
>
47
>
declare readonly _serviceBrand: undefined;
48
>
49
>
private readonly _connections = new Map<string, IAgentHostClientProxyConnection>();
50
>
private _proxyResolver: ReturnType<typeof createProxyResolver> | undefined;
51
>
private _proxyAgentParams: ProxyAgentParams | undefined;
52
>
private _fetch: typeof globalThis.fetch | undefined;
53
>
54
>
constructor(
55
@IConfigurationService private readonly _configurationService: IConfigurationService,
56
@ILogService private readonly _logService: ILogService,
57
) { }
59
>
register(clientId: string, connection: IAgentHostClientProxyConnection): IDisposable {
60
this._connections.set(clientId, connection);
61
return toDisposable(() => {