import { parseLenientJsonishWithNative } from '../../../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
function normalizeRecordPayload(payload) {
    if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
        return payload;
    }
    try {
        const nativeParsed = parseLenientJsonishWithNative(payload);
        if (nativeParsed && typeof nativeParsed === 'object' && !Array.isArray(nativeParsed)) {
            return nativeParsed;
        }
    }
    catch {
        // native normalization is best-effort
    }
    return {};
}
export function recordStage(recorder, stageId, payload) {
    if (!recorder) {
        return;
    }
    try {
        recorder.record(stageId, normalizeRecordPayload(payload));
    }
    catch {
        // Snapshot failures should not block the pipeline.
    }
}
