"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildStoredEnvelope = buildStoredEnvelope;
exports.extractEnvelope = extractEnvelope;
/**
 * Build the stored envelope that preserves routing and task identity
 * across escalation re-runs.
 *
 * When a human (or AI) resolves an escalation, a new workflow is
 * started with this envelope — it carries the taskId and parent
 * routing so the interceptor can reconnect the dots.
 */
function buildStoredEnvelope(state) {
    return {
        ...(state.envelope || {}),
        lt: {
            ...(state.envelope?.lt || {}),
            taskId: state.taskId,
            ...(state.routing?.parentWorkflowId
                ? {
                    signalId: state.routing.signalId,
                    parentWorkflowId: state.routing.parentWorkflowId,
                    parentTaskQueue: state.routing.parentTaskQueue,
                    parentWorkflowType: state.routing.parentWorkflowType,
                }
                : {}),
        },
    };
}
/**
 * Extract the LTEnvelope from the raw HotMesh workflow context.
 */
function extractEnvelope(ctx) {
    const rawArgs = ctx.get('raw');
    return rawArgs?.data?.arguments?.[0];
}
