"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleReasoningCoherence = handleReasoningCoherence;
const matchers_1 = require("../../matchers");
const invariant_1 = __importDefault(require("../../util/invariant"));
const logger_1 = __importDefault(require("../../logger"));
const util_1 = require("./util");
async function handleReasoningCoherence({ assertion, test, output, prompt, }) {
    const vars = { ...(test?.vars ?? {}) };
    const { task, plan, trace, agentOutput } = (0, util_1.getResolvedTrace)(output, vars, prompt);
    logger_1.default.debug(`reasoning-coherence: task length=${task.length}, plan length=${plan.length}, trace count=${Array.isArray(trace) ? trace.length : 'n/a'}, agentOutput length=${agentOutput.length}`);
    (0, invariant_1.default)(typeof task === 'string', 'reasoning-coherence requires a task (prompt) in test.vars or output.trusys');
    (0, invariant_1.default)(trace !== undefined && Array.isArray(trace), 'reasoning-coherence requires tool_calls or agent_calls in test.vars or output.trusys');
    (0, invariant_1.default)(typeof agentOutput === 'string' && agentOutput.length > 0, 'reasoning-coherence requires agent output in test.vars, output.trusys.output, or the output object');
    return {
        assertion,
        ...(await (0, matchers_1.matchesReasoningCoherence)(task, plan, trace, agentOutput, test.options)),
    };
}
//# sourceMappingURL=reasoningCoherence.js.map