"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Portkey = void 0;
const Types = __importStar(require("./_types/portkeyConstructs"));
const API = __importStar(require("./apis"));
const baseClient_1 = require("./baseClient");
const constants_1 = require("./constants");
const utils_1 = require("./utils");
class Portkey extends baseClient_1.ApiClient {
    constructor(_a) {
        var _b, _c;
        var { apiKey = (_b = (0, utils_1.readEnv)('PORTKEY_API_KEY')) !== null && _b !== void 0 ? _b : null, baseURL = (_c = (0, utils_1.readEnv)('PORTKEY_BASE_URL')) !== null && _c !== void 0 ? _c : null, mode, llms, config } = _a;
        super({
            apiKey,
            baseURL
        });
        this.completions = new API.Completions(this);
        this.chatCompletions = new API.ChatCompletions(this);
        this.generations = new API.Generations(this);
        this.apiKey = apiKey;
        if (!this.apiKey) {
            throw (0, utils_1.castToError)(constants_1.MISSING_API_KEY_ERROR_MESSAGE);
        }
        this.config = config || null;
        this.baseURL = baseURL || constants_1.PORTKEY_BASE_URL;
        this.mode = mode || null;
        this.llms = this.constructLlms(llms || null);
    }
    constructLlms(llms) {
        if (!llms) {
            return llms || null;
        }
        llms.forEach(llm => {
            for (const key in llm) {
                if (Types.ModelParamsList.includes(key)) {
                    if (!llm.override_params) {
                        llm.override_params = {};
                    }
                    llm.override_params[key] = llm[key];
                    delete llm[key];
                }
            }
        });
        return llms;
    }
}
exports.Portkey = Portkey;
//# sourceMappingURL=index.js.map