"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleCallOutcome = void 0;
const invariant_1 = __importDefault(require("../../util/invariant"));
const handleCallOutcome = async ({ assertion, renderedValue, prompt, output, test, evaluateResult, }) => {
    (0, invariant_1.default)(typeof renderedValue === 'string' || Array.isArray(renderedValue), 'Call outcome assertion values must have a string or array of strings value');
    let input = [];
    if (Array.isArray(renderedValue)) {
        input = renderedValue;
    }
    else {
        input = [renderedValue];
    }
    if (evaluateResult) {
        const result = typeof output === 'string' ? output.toLowerCase() : '';
        const pass = input.includes(result);
        return {
            pass: true,
            score: pass ? 1 : 0,
            reason: result,
            assertion,
        };
    }
    else {
        return {
            pass: true,
            score: 1,
            reason: '',
            metadata: {
                prompt: `The audio call that you are analyzing has the following stages: ${JSON.stringify(renderedValue)}. Each entry in the array has a stage and expected outcomes. Each outcome has a name and condition field which specifies the condition to be satisfied for you to infer that this particular outcome was achieved. The call progresses to these stages in the same order as in the array. Analyze the transcript that you have generated to identify the outcome of the call. The outcome of the call is the outcome in the last stage to which the call progressed and this should be a single string value. Provide the result in a metric called 'call-outcome'.`,
                metric: '"call-outcome": "Sale succeeded",',
            },
        };
    }
};
exports.handleCallOutcome = handleCallOutcome;
//# sourceMappingURL=callOutcome.js.map