"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveTraceIds = resolveTraceIds;
function pick(row, camel, snake) {
    const c = row[camel];
    if (c !== undefined && c !== null) {
        return c;
    }
    const s = row[snake];
    if (s !== undefined && s !== null) {
        return s;
    }
    return undefined;
}
function isUsableTraceId(id) {
    const t = id.trim();
    return t.length > 0 && t !== 'null';
}
/**
 * Session eval: all trace IDs in the session (from eval_results.trace_ids).
 * Trace eval: single-element array [trace_id].
 */
function resolveTraceIds(row) {
    const sessionId = pick(row, 'sessionId', 'session_id');
    const traceId = pick(row, 'traceId', 'trace_id');
    const raw = pick(row, 'traceIds', 'trace_ids');
    let fromArray = [];
    if (Array.isArray(raw)) {
        fromArray = raw.map((v) => String(v)).filter(isUsableTraceId);
    }
    else if (typeof raw === 'string' && raw.trim().startsWith('[')) {
        try {
            const parsed = JSON.parse(raw);
            if (Array.isArray(parsed)) {
                fromArray = parsed.map((v) => String(v)).filter(isUsableTraceId);
            }
        }
        catch {
            fromArray = [];
        }
    }
    const hasSession = typeof sessionId === 'string' && isUsableTraceId(sessionId);
    if (hasSession) {
        const merged = [...fromArray];
        if (typeof traceId === 'string' && isUsableTraceId(traceId) && !merged.includes(traceId)) {
            merged.push(traceId);
        }
        return [...new Set(merged)];
    }
    if (typeof traceId === 'string' && isUsableTraceId(traceId)) {
        return [traceId];
    }
    return [...new Set(fromArray)];
}
//# sourceMappingURL=resolveTraceIds.js.map