"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertApplicationToProviderFormat = void 0;
const handleHttpApiStructure_1 = require("../handleHttpApiStructure");
const buildProviderForEval_1 = require("../customAIApplication/buildProviderForEval");
const convertApplicationToProviderFormat = (application) => {
    let provider;
    const providerConfig = application?.provider_config?.config?.provider;
    if (application?.provider_config?.provider_type === 'agentic' && providerConfig?.platform) {
        provider = {
            id: `agentic:${providerConfig?.platform}`,
            label: application?.name,
            config: {
                ...providerConfig,
            },
        };
    }
    else if (application?.provider_config?.config?.custom_provider_type === 'HTTP API') {
        provider = (0, handleHttpApiStructure_1.handleHTTPAPIStructure)(providerConfig, application?.name);
    }
    else if (application?.provider_config?.config?.custom_provider_type === 'Websocket') {
        provider = {
            id: providerConfig?.url,
            label: application?.name,
            config: {
                messageTemplate: providerConfig?.messageTemplate,
                transform: providerConfig?.transformResponse,
                timeout: providerConfig?.timeoutMs || 10000,
            },
        };
    }
    else if (application?.provider_config?.config?.custom_provider_type === 'Custom AI Application' ||
        (application?.provider_config?.provider_type === 'custom' &&
            application?.provider_config?.config?.provider?.language)) {
        const built = (0, buildProviderForEval_1.buildCustomAIProviderForEval)(application);
        if (!built) {
            throw new Error('Custom AI Application is missing provider configuration. Complete upload setup or select another application.');
        }
        provider = built;
    }
    else {
        provider = {
            ...application?.provider_config?.config?.provider,
            label: application?.name,
        };
    }
    return provider;
};
exports.convertApplicationToProviderFormat = convertApplicationToProviderFormat;
//# sourceMappingURL=index.js.map