Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/endpoint/common/capiClient.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
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 { CAPIClient, MakeRequestOptions, RequestMetadata, RequestType } from '@vscode/copilot-api';
7
import { createServiceIdentifier } from '../../../util/common/services';
8
import { IEnvService } from '../../env/common/envService';
9
import { IFetcherService, NO_FETCH_TELEMETRY } from '../../networking/common/fetcherService';
10
import { LICENSE_AGREEMENT } from './licenseAgreement';
11
12
/**
13
* Interface for CAPI client service
14
*/
15
export interface ICAPIClientService extends CAPIClient {
16
readonly _serviceBrand: undefined;
17
abExpContext: string | undefined;
18
}
19
20
export abstract class BaseCAPIClientService extends CAPIClient implements ICAPIClientService {
21
readonly _serviceBrand: undefined;
22
public abExpContext: string | undefined;
23
24
constructor(
25
hmac: string | undefined,
26
integrationId: string | undefined,
27
fetcherService: IFetcherService,
28
envService: IEnvService
29
) {
30
super({
31
machineId: envService.machineId,
32
deviceId: envService.devDeviceId,
33
sessionId: envService.sessionId,
34
vscodeVersion: envService.vscodeVersion,
35
buildType: envService.getBuildType(),
36
name: envService.getName(),
37
version: envService.getVersion(),
38
}, LICENSE_AGREEMENT, fetcherService, hmac, integrationId);
39
}
40
41
override makeRequest<T>(request: MakeRequestOptions, requestMetadata: RequestMetadata): Promise<T> {
42
// Inject AB Exp Context headers (legacy VScode-ABExpContext and new standardized X-Copilot-Client-Exp-Assignment-Context) if available
43
if (this.abExpContext) {
44
if (!request.headers) {
45
request.headers = {};
46
}
47
request.headers['VScode-ABExpContext'] = this.abExpContext;
48
request.headers['X-Copilot-Client-Exp-Assignment-Context'] = this.abExpContext;
49
}
50
// Expected high request volume events that we don't need to collect fetch telemetry for
51
if (
52
requestMetadata.type === RequestType.Telemetry ||
53
requestMetadata.type === RequestType.ChatCompletions ||
54
requestMetadata.type === RequestType.ChatMessages ||
55
requestMetadata.type === RequestType.ChatResponses
56
) {
57
request.callSite = NO_FETCH_TELEMETRY;
58
}
59
return super.makeRequest<T>(request, requestMetadata);
60
}
61
}
62
export const ICAPIClientService = createServiceIdentifier<ICAPIClientService>('ICAPIClientService');
63