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 { lookup } from 'dns';
7
>
import { streamToBuffer } from '../../../base/common/buffer.js';
8
>
import { CancellationToken } from '../../../base/common/cancellation.js';
9
>
import { IConfigurationService } from '../../configuration/common/configuration.js';
10
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
11
>
import { ILogService } from '../../log/common/log.js';
12
>
import { IProductService } from '../../product/common/productService.js';
13
>
import { IRequestService, NO_FETCH_TELEMETRY } from '../../request/common/request.js';
14
>
import { IAgentHostDnsResult, IAgentHostNetworkDiagnosticsInfo, IAgentHostNetworkEndpoint, IAgentHostNetworkFetchResult } from '../common/agentService.js';
15
>
import { IAgentHostProxyResolver } from './agentHostProxyResolver.js';
16
>
17
>
export const INetworkDiagnosticsService = createDecorator<INetworkDiagnosticsService>('networkDiagnosticsService');
18
>
19
>
/**
20
>
* Owns agent-host network connectivity diagnostics: host-level network context
21
>
* ({@link getInfo}) and the per-URL reachability probe ({@link fetch}). Split
22
>
* out from {@link IAgentService} so the network stack dependencies
23
>
* ({@link IRequestService}, {@link IAgentHostProxyResolver}) are injected here
24
>
* rather than threaded through the session orchestrator.
25
>
*/
26
>
export interface INetworkDiagnosticsService {
27
>
readonly _serviceBrand: undefined;
28
>
29
>
/** Host-level network context: version, OS/arch, account, proxy settings/env, and endpoints worth probing. */
30
>
getInfo(endpoints: readonly IAgentHostNetworkEndpoint[], account?: string): Promise<IAgentHostNetworkDiagnosticsInfo>;
31
>
32
>
/** Probe connectivity from the agent host process to a single `url`. */
33
>
fetch(url: string): Promise<IAgentHostNetworkFetchResult>;
34
>
}
35
>
36
>
/** Per-probe timeout: DNS lookup and the reachability request each get this long. */
37
>
const PROBE_TIMEOUT_MS = 10_000;
38
>
39
>
/** Cap on the response body returned to callers (for expected-content checks), to bound the IPC payload. */
40
>
const MAX_BODY_CHARS = 64 * 1024;
41
>
42
>
/**
43
>
* Proxy-related environment variables surfaced in the diagnostics report so a
44
>
* mismatch between the OS/config proxy and an explicit env override is visible.
45
>
*/
46
>
const PROXY_ENV_KEYS = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy', 'ALL_PROXY', 'all_proxy', 'NO_PROXY', 'no_proxy'] as const;
47
>
48
>
/** VS Code `http.*` proxy settings surfaced alongside the env vars. */
49
>
const PROXY_CONFIG_KEYS = ['http.proxy', 'http.proxyStrictSSL', 'http.proxySupport', 'http.noProxy'] as const;
50
>
51
>
export class NetworkDiagnosticsService implements INetworkDiagnosticsService {
52
>
53
>
declare readonly _serviceBrand: undefined;
54
>
55
>
constructor(
56
@IRequestService private readonly _requestService: IRequestService,
57
@IAgentHostProxyResolver private readonly _proxyResolver: IAgentHostProxyResolver,