"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPluginIdFromEvalRow = getPluginIdFromEvalRow;
const metadata_1 = require("../../../redteam/constants/metadata");
/** Resolves red-team plugin id from eval row metadata / test_case / component metrics. */
function getPluginIdFromEvalRow(row) {
    const metadata = row.metadata ??
        row.testCase?.metadata ??
        row.test_case?.metadata;
    if (metadata?.pluginId) {
        return String(metadata.pluginId);
    }
    if (metadata?.plugin_id) {
        return String(metadata.plugin_id);
    }
    const testCase = row.testCase ?? row.test_case;
    const vars = testCase?.vars;
    const harmCategory = vars?.harmCategory ?? metadata?.harmCategory;
    if (harmCategory) {
        const rev = metadata_1.categoryAliasesReverse[harmCategory];
        if (rev) {
            return rev;
        }
    }
    const gradingResult = row.gradingResult ?? row.grading_result;
    const componentResults = Array.isArray(gradingResult?.componentResults)
        ? gradingResult.componentResults
        : [];
    for (const cr of componentResults) {
        const metric = cr.assertion?.metric;
        if (!metric) {
            continue;
        }
        const baseName = String(metric).split('/')[0];
        const fromMetric = metadata_1.categoryAliasesReverse[baseName];
        if (fromMetric) {
            return fromMetric;
        }
    }
    return null;
}
//# sourceMappingURL=getPluginId.js.map