"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoChatEndpoint = void 0;
exports.isAutoModel = isAutoModel;
const instantiation_1 = require("../../../util/vs/platform/instantiation/common/instantiation");
const authentication_1 = require("../../authentication/common/authentication");
const chatMLFetcher_1 = require("../../chat/common/chatMLFetcher");
const configurationService_1 = require("../../configuration/common/configurationService");
const envService_1 = require("../../env/common/envService");
const logService_1 = require("../../log/common/logService");
const fetcherService_1 = require("../../networking/common/fetcherService");
const chatWebSocketManager_1 = require("../../networking/node/chatWebSocketManager");
const nullExperimentationService_1 = require("../../telemetry/common/nullExperimentationService");
const telemetry_1 = require("../../telemetry/common/telemetry");
const tokenizer_1 = require("../../tokenizer/node/tokenizer");
const capiClient_1 = require("../common/capiClient");
const domainService_1 = require("../common/domainService");
const chatEndpoint_1 = require("./chatEndpoint");
const copilotChatEndpoint_1 = require("./copilotChatEndpoint");
/**
 * This endpoint represents the "Auto" model in the model picker.
 * It just effectively wraps a different endpoint and adds the auto stuff on top
 */
let AutoChatEndpoint = class AutoChatEndpoint extends copilotChatEndpoint_1.CopilotChatEndpoint {
    static { this.pseudoModelId = 'auto'; }
    constructor(_wrappedEndpoint, _sessionToken, _discountPercent, discountRange, _domainService, _capiClientService, _fetcherService, _envService, _telemetryService, _authService, _chatMLFetcher, _tokenizerProvider, _instantiationService, _configurationService, _expService, _chatWebSocketService, _logService) {
        super(calculateAutoModelInfo(_wrappedEndpoint, _sessionToken, _discountPercent), _domainService, _capiClientService, _fetcherService, _envService, _telemetryService, _authService, _chatMLFetcher, _tokenizerProvider, _instantiationService, _configurationService, _expService, _chatWebSocketService, _logService);
        this.discountRange = discountRange;
    }
};
exports.AutoChatEndpoint = AutoChatEndpoint;
exports.AutoChatEndpoint = AutoChatEndpoint = __decorate([
    __param(4, domainService_1.IDomainService),
    __param(5, capiClient_1.ICAPIClientService),
    __param(6, fetcherService_1.IFetcherService),
    __param(7, envService_1.IEnvService),
    __param(8, telemetry_1.ITelemetryService),
    __param(9, authentication_1.IAuthenticationService),
    __param(10, chatMLFetcher_1.IChatMLFetcher),
    __param(11, tokenizer_1.ITokenizerProvider),
    __param(12, instantiation_1.IInstantiationService),
    __param(13, configurationService_1.IConfigurationService),
    __param(14, nullExperimentationService_1.IExperimentationService),
    __param(15, chatWebSocketManager_1.IChatWebSocketManager),
    __param(16, logService_1.ILogService)
], AutoChatEndpoint);
function calculateAutoModelInfo(endpoint, sessionToken, discountPercent) {
    let originalModelInfo;
    if (endpoint instanceof chatEndpoint_1.ChatEndpoint) {
        originalModelInfo = endpoint.modelMetadata;
    }
    else {
        originalModelInfo = {
            id: endpoint.model,
            vendor: endpoint.modelProvider,
            name: endpoint.name,
            version: endpoint.version,
            model_picker_enabled: endpoint.showInModelPicker,
            is_chat_default: true,
            is_chat_fallback: endpoint.isFallback,
            capabilities: {
                type: 'chat',
                family: endpoint.family,
                tokenizer: endpoint.tokenizer,
                limits: {
                    max_prompt_tokens: endpoint.modelMaxPromptTokens,
                    max_output_tokens: endpoint.maxOutputTokens,
                },
                supports: {
                    tool_calls: endpoint.supportsToolCalls,
                    vision: endpoint.supportsVision,
                    prediction: endpoint.supportsPrediction,
                    streaming: true, // Assume streaming support for non-ChatEndpoint instances
                },
            },
            billing: endpoint.isPremium !== undefined || endpoint.multiplier !== undefined || endpoint.restrictedToSkus !== undefined
                ? {
                    is_premium: endpoint.isPremium ?? false,
                    multiplier: endpoint.multiplier ?? 0,
                    restricted_to: endpoint.restrictedToSkus,
                }
                : undefined,
            custom_model: endpoint.customModel,
        };
    }
    // Calculate the multiplier including the discount percent, rounding to two decimal places
    const newMultiplier = endpoint.multiplier !== undefined
        ? Math.round(endpoint.multiplier * (1 - discountPercent) * 100) / 100
        : undefined;
    const newModelInfo = {
        ...originalModelInfo,
        warning_messages: undefined,
        model_picker_enabled: true,
        info_messages: undefined,
        billing: {
            is_premium: originalModelInfo.billing?.is_premium,
            multiplier: newMultiplier,
            restricted_to: originalModelInfo.billing?.restricted_to
        },
        requestHeaders: {
            ...(originalModelInfo.requestHeaders || {}),
            'Copilot-Session-Token': sessionToken
        }
    };
    return newModelInfo;
}
function isAutoModel(endpoint) {
    if (!endpoint) {
        return -1;
    }
    return (endpoint.model === AutoChatEndpoint.pseudoModelId || endpoint instanceof AutoChatEndpoint) ? 1 : -1;
}
//# sourceMappingURL=autoChatEndpoint.js.map