"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PortkeyChatCompletionProvider = void 0;
const openai_1 = require("./openai");
class PortkeyChatCompletionProvider extends openai_1.OpenAiChatCompletionProvider {
    constructor(modelName, providerOptions) {
        const headers = Object.entries(providerOptions.config || {}).reduce((acc, [key, value]) => {
            if (value) {
                const headerKey = key.startsWith('portkey')
                    ? `x-${key.replace(/^portkey/, 'portkey-').toLowerCase()}`
                    : key;
                acc[headerKey] = typeof value === 'object' ? JSON.stringify(value) : value;
            }
            return acc;
        }, {});
        super(modelName, {
            ...providerOptions,
            config: {
                ...providerOptions.config,
                apiBaseUrl: process.env.PORTKEY_API_BASE_URL ||
                    providerOptions.config?.portkeyApiBaseUrl ||
                    'https://api.portkey.ai/v1',
                headers,
            },
        });
    }
}
exports.PortkeyChatCompletionProvider = PortkeyChatCompletionProvider;
//# sourceMappingURL=portkey.js.map