"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyAiUserResponseTerminalState = applyAiUserResponseTerminalState;
/**
 * AI user-response ends the conversation: drop actions after the AI step on this turn
 * and remove all later turns.
 */
function applyAiUserResponseTerminalState(turns, params) {
    const turnIndex = turns.findIndex((t) => String(t.id) === String(params.turnId));
    if (turnIndex < 0) {
        return turns;
    }
    let actionsAbove = [...(params.actionsAbove ?? [])];
    let actionsBelow = [...(params.actionsBelow ?? [])];
    if (params.position === 'above') {
        actionsAbove = actionsAbove.slice(0, params.aiActionIndex + 1);
        actionsBelow = [];
    }
    else {
        actionsBelow = actionsBelow.slice(0, params.aiActionIndex + 1);
    }
    const updatedTurns = turns.map((turn, index) => {
        if (index !== turnIndex) {
            return turn;
        }
        return {
            ...turn,
            actionsAbove,
            actionsBelow,
        };
    });
    return updatedTurns.slice(0, turnIndex + 1);
}
//# sourceMappingURL=applyAiUserResponseTerminalState.js.map