"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handlePiiCheck = void 0;
const invariant_1 = __importDefault(require("../../util/invariant"));
const handlePiiCheck = async ({ assertion, renderedValue, prompt, output, test, evaluateResult, }) => {
    if (evaluateResult) {
        // Ensure that 'renderedValue' is a string
        (0, invariant_1.default)(typeof renderedValue === 'string', 'PII Check assertion type must have a string value');
        // Ensure that 'output' is a string, convert it if necessary
        if (typeof output !== 'string') {
            output = JSON.stringify(output); // Convert 'output' to a string if it is not already
        }
        (0, invariant_1.default)(typeof output === 'string', 'PII Check output must be a string');
        // Normalize and parse output to determine pii-check status
        const outputLower = output.toLowerCase();
        let formattedOutput;
        // Specifically handling audio-pii-check case:
        if (outputLower === 'no') {
            formattedOutput = JSON.stringify({ 'pii-check': 'No' });
        }
        else if (outputLower === 'yes' && outputLower.includes('customer')) {
            formattedOutput = JSON.stringify({ 'pii-check': 'Yes', speaker: 'customer' });
        }
        else if (outputLower === 'yes' && outputLower.includes('agent')) {
            formattedOutput = JSON.stringify({ 'pii-check': 'Yes', speaker: 'agent' });
        }
        else {
            formattedOutput = JSON.stringify({ 'pii-check': 'No' });
        }
        const pass = renderedValue.toLowerCase() === formattedOutput.toLowerCase();
        return {
            pass,
            score: pass ? 1 : 0,
            reason: formattedOutput,
            assertion,
        };
    }
    else {
        return {
            pass: true,
            score: 1,
            reason: '',
            metadata: {
                prompt: `Check if any personal identifiable information (PII) is mentioned during the conversation. If PII is detected in the conversation, mention which participant (AI Bot agent or customer) mentioned it. Output should be: {"pii-check": "Yes", "speaker": "customer"} or {"pii-check": "No"}.`,
                metric: '"pii-check": "No"',
            },
        };
    }
};
exports.handlePiiCheck = handlePiiCheck;
//# sourceMappingURL=audioPiiCheck.js.map