"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleDropOutRates = void 0;
const invariant_1 = __importDefault(require("../../util/invariant"));
const handleDropOutRates = async ({ assertion, output, evaluateResult, }) => {
    if (evaluateResult) {
        (0, invariant_1.default)(typeof output === 'string', 'Audio drop-out rates output must be a string');
        const cleanedOutput = output.trim().toLowerCase();
        const match = cleanedOutput.match(/([\d.]+)\s*%?/);
        if (!match || !match[1]) {
            return {
                pass: false,
                score: 0,
                reason: 'Could not extract drop-out rate percentage.',
                assertion,
            };
        }
        const dropOutRate = Number.parseFloat(match[1]);
        if (Number.isNaN(dropOutRate) || dropOutRate < 0 || dropOutRate > 100) {
            return {
                pass: false,
                score: 0,
                reason: 'Invalid drop-out rate percentage.',
                assertion,
            };
        }
        return {
            pass: true,
            score: 1 - dropOutRate / 100,
            reason: `${dropOutRate}%`,
            assertion,
        };
    }
    return {
        pass: true,
        score: 1,
        reason: '',
        metadata: {
            prompt: `Measure the audio drop-out rate as a percentage in the provided transcript. Return the result in a metric called 'drop-out-rates'.`,
            metric: '"drop-out-rates": "5%",',
        },
    };
};
exports.handleDropOutRates = handleDropOutRates;
//# sourceMappingURL=audioDropOutRates.js.map