"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleConversationCoherence = void 0;
const invariant_1 = __importDefault(require("../../util/invariant"));
const handleConversationCoherence = async ({ assertion, output, evaluateResult, }) => {
    if (evaluateResult) {
        (0, invariant_1.default)(typeof output === 'string', 'Conversation coherence output must be a string');
        const cleanedOutput = output.trim().toLowerCase();
        const validCoherenceValues = ['coherent', 'incoherent', 'slightly incoherent']; // Define valid values
        if (!validCoherenceValues.includes(cleanedOutput)) {
            return {
                pass: false,
                score: 0,
                reason: `Invalid coherence value: "${cleanedOutput}".  Expected one of: ${validCoherenceValues.join(', ')}`,
                assertion,
            };
        }
        const pass = cleanedOutput === 'coherent';
        const score = cleanedOutput === 'coherent' ? 1 : cleanedOutput === 'slightly incoherent' ? 0.5 : 0;
        return {
            pass,
            score,
            reason: cleanedOutput,
            assertion,
        };
    }
    return {
        pass: true,
        score: 1,
        reason: '',
        metadata: {
            prompt: `Analyze the conversation for coherence.  A coherent conversation is one where each turn logically follows from the previous one, and the overall discussion has a clear purpose and direction.  Classify the conversation as one of the following: 'coherent', 'slightly incoherent', or 'incoherent'.  Provide the result in a metric called 'conversation-coherence'.`,
            metric: '"conversation-coherence": "coherent"',
        },
    };
};
exports.handleConversationCoherence = handleConversationCoherence;
//# sourceMappingURL=audioConversationCoherence.js.map