"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ICAPIClientService = exports.BaseCAPIClientService = void 0;
const copilot_api_1 = require("@vscode/copilot-api");
const services_1 = require("../../../util/common/services");
const fetcherService_1 = require("../../networking/common/fetcherService");
const licenseAgreement_1 = require("./licenseAgreement");
class BaseCAPIClientService extends copilot_api_1.CAPIClient {
    constructor(hmac, integrationId, fetcherService, envService) {
        super({
            machineId: envService.machineId,
            deviceId: envService.devDeviceId,
            sessionId: envService.sessionId,
            vscodeVersion: envService.vscodeVersion,
            buildType: envService.getBuildType(),
            name: envService.getName(),
            version: envService.getVersion(),
        }, licenseAgreement_1.LICENSE_AGREEMENT, fetcherService, hmac, integrationId);
    }
    makeRequest(request, requestMetadata) {
        // Inject AB Exp Context headers (legacy VScode-ABExpContext and new standardized X-Copilot-Client-Exp-Assignment-Context) if available
        if (this.abExpContext) {
            if (!request.headers) {
                request.headers = {};
            }
            request.headers['VScode-ABExpContext'] = this.abExpContext;
            request.headers['X-Copilot-Client-Exp-Assignment-Context'] = this.abExpContext;
        }
        // Expected high request volume events that we don't need to collect fetch telemetry for
        if (requestMetadata.type === copilot_api_1.RequestType.Telemetry ||
            requestMetadata.type === copilot_api_1.RequestType.ChatCompletions ||
            requestMetadata.type === copilot_api_1.RequestType.ChatMessages ||
            requestMetadata.type === copilot_api_1.RequestType.ChatResponses) {
            request.callSite = fetcherService_1.NO_FETCH_TELEMETRY;
        }
        return super.makeRequest(request, requestMetadata);
    }
}
exports.BaseCAPIClientService = BaseCAPIClientService;
exports.ICAPIClientService = (0, services_1.createServiceIdentifier)('ICAPIClientService');
//# sourceMappingURL=capiClient.js.map