"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ControllerChildDecisionReviewError = void 0;
exports.reconcileControllerChildIssues = reconcileControllerChildIssues;
exports.buildControllerChildParentDependencyChanges = buildControllerChildParentDependencyChanges;
exports.buildControllerChildDependencyChanges = buildControllerChildDependencyChanges;
const workflow_labels_1 = require("../../../platform/ticket-tracker/workflow-labels");
const types_1 = require("../../../platform/workflow-state/types");
const plan_progress_1 = require("../../../workflows/plan-progress");
const publish_request_builders_1 = require("../../../workflows/publish-request-builders");
const publisher_shared_1 = require("../../../workflows/publisher-shared");
const publisher_state_support_1 = require("../../../workflows/publisher-state-support");
const issue_creation_publication_1 = require("../issue-creation-publication");
const execution_ownership_1 = require("../../execution-ownership");
const issue_branch_remote_1 = require("../issue-branch-remote");
const issue_branch_target_1 = require("../issue-branch-target");
const publisher_factory_1 = require("../publisher-factory");
const same_issue_replan_state_support_1 = require("../same-issue-replan-state-support");
const match_1 = require("./match");
const shared_1 = require("./shared");
class ControllerChildDecisionReviewError extends Error {
    constructor(message) {
        super(message);
        this.name = "ControllerChildDecisionReviewError";
    }
}
exports.ControllerChildDecisionReviewError = ControllerChildDecisionReviewError;
async function reconcileControllerChildIssues(input) {
    const plan = await buildControllerChildPublicationPlan(input);
    const publication = plan.actions.length === 0
        ? {
            executions: [],
            issueByKey: new Map(),
            activeIssueByKey: new Map(),
            createdIssues: [],
            updatedIssues: [],
        }
        : await (0, issue_creation_publication_1.executeIssuePublicationPlans)({
            ...(plan.actions.some((action) => action.kind !== "reuse")
                ? {
                    publisher: (0, publisher_factory_1.createRunWorkflowPublisher)(input.context),
                }
                : {}),
            plans: plan.actions,
            eventHooks: {
                repoRoot: input.context.workflowTemplateRepoRoot ?? input.context.cwd,
                config: input.context.config,
                worker: input.context.worker,
                ...(input.context.logHomeDirectory !== undefined
                    ? { homeDirectory: input.context.logHomeDirectory }
                    : {}),
            },
        });
    return {
        childIssueByKey: new Map([...plan.issueByKey, ...publication.issueByKey]),
        activeChildIssueByKey: publication.activeIssueByKey,
        createdChildren: publication.createdIssues,
        reflectedCompletedChildren: plan.reflectedCompletedChildren,
        updatedChildren: publication.updatedIssues,
        workflowState: (0, shared_1.attachControllerChildIssueRefsToWorkflowState)({
            workflowState: plan.workflowState,
            childIssueByKey: new Map([...plan.issueByKey, ...publication.issueByKey]),
            startedChildWorkflowStateByKey: plan.startedChildWorkflowStateByKey,
        }),
    };
}
// biome-ignore lint/complexity/noExcessiveLinesPerFunction: Child reconciliation is intentionally ordered around tracker side-effect planning.
async function buildControllerChildPublicationPlan(input) {
    const existingOpenChildLookup = await (0, shared_1.loadControllerChildIssueLookup)({
        ticketTracker: input.context.ticketTracker,
        issues: input.existingOpenChildren,
    });
    const pendingDecisionByKey = new Map((input.pendingChildIssueDecisions ?? []).map((decision) => [decision.childKey, decision]));
    const allChildIssueSteps = (0, shared_1.resolveControllerChildIssueSteps)(input.workerExecution.workflowState);
    const actions = [];
    const issueByKey = new Map();
    const reflectedCompletedChildren = [];
    const startedChildWorkflowStateByKey = new Map();
    const parentWorkflowState = input.workerExecution.workflowState;
    if (parentWorkflowState === null) {
        throw new Error("Controller child issue publication requires parent workflow state.");
    }
    let workflowState = parentWorkflowState;
    const desiredChildFollowup = (0, shared_1.resolveControllerChildFollowupState)({
        childIssuePolicy: input.context.config.followup.childIssuePolicy,
        parentWorkflowState,
    });
    const childBaseBranch = (0, issue_branch_target_1.resolveIssueCreationBaseBranch)({
        branchTarget: "parent_issue_branch",
        config: input.context.config,
        parentIssue: input.workerExecution.issue,
        effectiveWorkflowState: input.workerExecution.workflowState,
    });
    let parentBranchRemoteEnsured = false;
    const ensureParentBranchRemote = async () => {
        if (parentBranchRemoteEnsured) {
            return;
        }
        await (0, issue_branch_remote_1.ensureParentIssueBranchRemoteRef)({
            context: input.context,
            parentIssue: input.workerExecution.issue,
            workflowState: input.workerExecution.workflowState,
        });
        parentBranchRemoteEnsured = true;
    };
    for (const childIssueStep of input.childIssueSteps) {
        if (pendingDecisionByKey.has(childIssueStep.childKey)) {
            continue;
        }
        const existingChild = await resolveControllerChildForStep({
            ticketTracker: input.context.ticketTracker,
            parentIssue: input.workerExecution.issue,
            childIssueStep,
            openChildIssueByKey: existingOpenChildLookup.issueByChildKey,
            openChildWorkflowStateByKey: existingOpenChildLookup.workflowStateByChildKey,
        });
        if (existingChild === undefined) {
            await ensureParentBranchRemote();
            const desiredSpec = (0, shared_1.buildControllerChildDesiredSpecForStep)({
                responseLanguage: input.workerExecution.responseLanguage,
                parentIssue: input.workerExecution.issue,
                parentWorkflowState: input.workerExecution.workflowState,
                followup: desiredChildFollowup,
                baseBranch: childBaseBranch,
                childIssueStep,
                childIssueSteps: input.childIssueSteps,
                catalog: input.catalog,
                workflowLabels: input.workflowLabels,
                assignee: input.assignee,
            });
            actions.push(buildCreateControllerChildIssuePlan({
                childKey: childIssueStep.childKey,
                parentIssueId: input.workerExecution.issue.id,
                childWorkflowState: (0, shared_1.buildControllerChildWorkflowState)({
                    desiredSpec,
                }),
                desiredSpec,
                runLimitPolicy: {
                    config: input.context.config,
                    workflowLabels: input.workflowLabels,
                },
                responseLanguage: input.workerExecution.responseLanguage,
            }));
            continue;
        }
        issueByKey.set(childIssueStep.childKey, existingChild.issue);
        if (existingChild.kind === "completed") {
            assertCompletedChildStillMatchesParentStep({
                childIssueStep,
                childIssue: existingChild.issue,
                childWorkflowState: existingChild.workflowState,
            });
            reflectedCompletedChildren.push(existingChild.issue);
            if (workflowState !== null && workflowState.plan !== null) {
                workflowState = {
                    ...workflowState,
                    plan: (0, plan_progress_1.withWorkflowPlanStepResultById)(workflowState.plan, childIssueStep.id, (0, plan_progress_1.buildCompletedControllerChildIssueResult)({
                        issue: existingChild.issue,
                        workflowState: existingChild.workflowState,
                    })),
                };
            }
            continue;
        }
        if (!(0, shared_1.isStartedControllerChildIssue)(existingChild.issue, existingChild.workflowState)) {
            await ensureParentBranchRemote();
            const desiredSpec = (0, shared_1.buildControllerChildDesiredSpecForStep)({
                responseLanguage: input.workerExecution.responseLanguage,
                parentIssue: input.workerExecution.issue,
                parentWorkflowState: input.workerExecution.workflowState,
                followup: desiredChildFollowup,
                baseBranch: childBaseBranch,
                childIssueStep,
                childIssueSteps: input.childIssueSteps,
                catalog: input.catalog,
                workflowLabels: input.workflowLabels,
                assignee: input.assignee,
            });
            actions.push(buildPatchControllerChildIssuePlan({
                childKey: childIssueStep.childKey,
                existingChild: existingChild.issue,
                childWorkflowState: preserveExistingControllerChildPatchState({
                    nextWorkflowState: (0, shared_1.buildControllerChildWorkflowState)({
                        desiredSpec,
                    }),
                    existingWorkflowState: existingChild.workflowState,
                }),
                desiredSpec,
                workflowLabels: input.workflowLabels,
                runLimitPolicy: {
                    config: input.context.config,
                    workflowLabels: input.workflowLabels,
                },
                responseLanguage: input.workerExecution.responseLanguage,
            }));
        }
        else {
            if ((0, shared_1.hasControllerChildParentStepContractSnapshotDrift)({
                childIssueStep,
                childWorkflowState: existingChild.workflowState,
            })) {
                throw new ControllerChildDecisionReviewError(`Started child issue ${existingChild.issue.displayId} no longer matches the current parent child step, so this now needs human review.`);
            }
            startedChildWorkflowStateByKey.set(childIssueStep.childKey, existingChild.workflowState);
            actions.push((0, issue_creation_publication_1.buildReuseIssuePublicationPlan)({
                issueKey: childIssueStep.childKey,
                issue: existingChild.issue,
            }));
        }
    }
    const decisionActions = await buildPendingChildIssueDecisionPlans({
        workflowLabels: input.workflowLabels,
        pendingChildIssueDecisions: input.pendingChildIssueDecisions ?? [],
        parentIssue: input.workerExecution.issue,
        parentWorkflowState: workflowState,
        existingOpenChildren: input.existingOpenChildren,
        existingOpenChildLookup,
        childIssueSteps: allChildIssueSteps,
        catalog: input.catalog,
        assignee: input.assignee,
        childBaseBranch,
        childFollowup: desiredChildFollowup,
        responseLanguage: input.workerExecution.responseLanguage,
    });
    actions.push(...decisionActions.actions);
    for (const [childKey, issue] of decisionActions.issueByKey) {
        issueByKey.set(childKey, issue);
    }
    if (workflowState !== null &&
        (input.pendingChildIssueDecisions ?? []).length > 0) {
        const { pendingChildIssueDecisions: _pendingChildIssueDecisions, ...stateWithoutCommittedChildDecisions } = workflowState;
        workflowState = stateWithoutCommittedChildDecisions;
    }
    return {
        actions,
        issueByKey,
        reflectedCompletedChildren,
        startedChildWorkflowStateByKey,
        workflowState,
    };
}
async function buildPendingChildIssueDecisionPlans(input) {
    const actions = [];
    const issueByKey = new Map();
    const childStepByKey = new Map(input.childIssueSteps.map((step) => [step.childKey, step]));
    for (const decision of input.pendingChildIssueDecisions) {
        const resolvedChild = resolveOpenChildForDecision({
            decision,
            existingOpenChildren: input.existingOpenChildren,
            existingOpenChildLookup: input.existingOpenChildLookup,
        });
        if (resolvedChild === null) {
            if (decision.action === "detach_child_issue" ||
                decision.action === "cancel_child_issue") {
                continue;
            }
            throw new ControllerChildDecisionReviewError(`Child issue decision ${decision.action} for ${decision.childKey} could not find an open child issue.`);
        }
        if (decision.action === "detach_child_issue" &&
            resolvedChild.workflowState.detachedFromParentReason != null) {
            continue;
        }
        if (!(0, shared_1.isControllerChildForParent)({
            workflowState: resolvedChild.workflowState,
            parentDisplayId: input.parentIssue.displayId,
            childKey: decision.childKey,
        })) {
            throw new ControllerChildDecisionReviewError(`Child issue ${resolvedChild.issue.displayId} no longer matches parent ${input.parentIssue.displayId}.`);
        }
        const childHasActiveOwnership = (0, execution_ownership_1.isExecutionOwnershipActive)(resolvedChild.workflowState.executionOwnership);
        if (childHasActiveOwnership) {
            throw new ControllerChildDecisionReviewError(`Child issue ${resolvedChild.issue.displayId} is currently running and cannot be changed safely.`);
        }
        switch (decision.action) {
            case "queue_child_issue_replan": {
                const childIssueStep = childStepByKey.get(decision.childKey);
                if (childIssueStep === undefined) {
                    throw new ControllerChildDecisionReviewError(`Child issue decision ${decision.action} for ${decision.childKey} has no current parent child step.`);
                }
                const desiredSpec = (0, shared_1.buildControllerChildDesiredSpecForStep)({
                    responseLanguage: input.responseLanguage,
                    parentIssue: input.parentIssue,
                    parentWorkflowState: input.parentWorkflowState,
                    followup: input.childFollowup,
                    baseBranch: input.childBaseBranch,
                    childIssueStep,
                    childIssueSteps: input.childIssueSteps,
                    catalog: input.catalog,
                    workflowLabels: input.workflowLabels,
                    assignee: input.assignee,
                });
                issueByKey.set(decision.childKey, resolvedChild.issue);
                actions.push(buildChildIssueDecisionPatchPlan({
                    issueKey: decision.childKey,
                    issue: resolvedChild.issue,
                    previousWorkflowState: resolvedChild.workflowState,
                    workflowState: (0, same_issue_replan_state_support_1.applySameIssueReplanPlanningState)({
                        workflowState: withQueuedChildReplanContract({
                            workflowState: resolvedChild.workflowState,
                            desiredSpec,
                        }),
                        reason: decision.reason,
                    }),
                    nextProjectionStatus: types_1.WORKFLOW_STATUSES.aiReady,
                    responseLanguage: input.responseLanguage,
                }));
                break;
            }
            case "detach_child_issue":
                actions.push(buildChildIssueDecisionPatchPlan({
                    issueKey: null,
                    issue: resolvedChild.issue,
                    previousWorkflowState: resolvedChild.workflowState,
                    workflowState: {
                        ...(0, execution_ownership_1.stripExecutionOwnership)(resolvedChild.workflowState),
                        detachedFromParentReason: decision.reason,
                    },
                    nextProjectionStatus: resolvedChild.issue.workflowState.status,
                    responseLanguage: input.responseLanguage,
                }));
                break;
            case "cancel_child_issue":
                actions.push(buildChildIssueDecisionPatchPlan({
                    issueKey: decision.childKey,
                    issue: resolvedChild.issue,
                    previousWorkflowState: resolvedChild.workflowState,
                    workflowState: {
                        ...(0, execution_ownership_1.stripExecutionOwnership)(resolvedChild.workflowState),
                        cancelledChildReason: decision.reason,
                    },
                    nextProjectionStatus: resolvedChild.issue.workflowState.status,
                    terminalAction: { kind: "close" },
                    responseLanguage: input.responseLanguage,
                }));
                break;
        }
    }
    return { actions, issueByKey };
}
function assertCompletedChildStillMatchesParentStep(input) {
    if (!(0, shared_1.hasControllerChildParentStepContractSnapshotDrift)({
        childIssueStep: input.childIssueStep,
        childWorkflowState: input.childWorkflowState,
    })) {
        return;
    }
    throw new ControllerChildDecisionReviewError(`Completed child issue ${input.childIssue.displayId} is missing a current parent contract snapshot or no longer matches the current parent child step, so this now needs human review.`);
}
function resolveOpenChildForDecision(input) {
    const byKey = input.existingOpenChildLookup.issueByChildKey.get(input.decision.childKey);
    if (byKey !== undefined) {
        const workflowState = input.existingOpenChildLookup.workflowStateByIssueId.get(byKey.id) ??
            null;
        if (workflowState !== null) {
            return { issue: byKey, workflowState };
        }
    }
    const childIssueRef = (0, shared_1.normalizeControllerChildIssueRef)(input.decision.childIssueRef);
    if (childIssueRef === null) {
        return null;
    }
    const byRef = input.existingOpenChildren.find((issue) => issue.id === childIssueRef ||
        (0, shared_1.normalizeControllerChildIssueRef)(issue.displayId) === childIssueRef);
    if (byRef === undefined) {
        return null;
    }
    const workflowState = input.existingOpenChildLookup.workflowStateByIssueId.get(byRef.id) ?? null;
    if (workflowState === null) {
        return null;
    }
    return { issue: byRef, workflowState };
}
function withQueuedChildReplanContract(input) {
    const { needsHumanReason: _needsHumanReason, pendingWorkflowStartApprovalIntent: _pendingWorkflowStartApprovalIntent, ...workflowState } = (0, execution_ownership_1.stripExecutionOwnership)(input.workflowState);
    return {
        ...workflowState,
        executionContract: cloneControllerChildContract(input.desiredSpec.contract),
        parentContractRevision: input.desiredSpec.parentContractRevision,
        parentStepContractSnapshot: cloneControllerChildContract(input.desiredSpec.parentStepContractSnapshot),
        finalResult: null,
    };
}
function cloneControllerChildContract(contract) {
    return {
        objective: contract.objective,
        doneWhen: [...contract.doneWhen],
        inputs: [...contract.inputs],
        outputs: [...contract.outputs],
        ...(contract.instructions !== undefined
            ? { instructions: [...contract.instructions] }
            : {}),
    };
}
function buildChildIssueDecisionPatchPlan(input) {
    return {
        kind: "patch",
        issueKey: input.issueKey,
        request: (0, publish_request_builders_1.buildExistingIssueWorkflowPublishRequest)({
            issueId: input.issue.id,
            preloadedIssue: input.issue,
            workflowState: input.workflowState,
            workflowProjection: (0, publisher_state_support_1.buildWorkflowProjectionChange)({
                previous: input.issue.workflowState,
                next: {
                    status: input.nextProjectionStatus,
                    rules: [...input.issue.workflowState.rules],
                },
            }),
            commentCursorPolicy: {
                mode: publisher_shared_1.WORKFLOW_COMMENT_CURSOR_POLICY_MODES.preserve,
            },
            ...(input.terminalAction !== undefined
                ? { terminalAction: input.terminalAction }
                : {}),
            publishPrecondition: {
                expectedPlanRevision: input.previousWorkflowState.planRevision,
            },
            responseLanguage: input.responseLanguage,
        }),
    };
}
async function buildControllerChildParentDependencyChanges(input) {
    const liveBlockerIds = new Set(input.existingBlockers
        .filter((blocker) => blocker.isOpen)
        .map((blocker) => blocker.id));
    const changes = [];
    for (const childIssue of input.childIssues) {
        if (liveBlockerIds.has(childIssue.id)) {
            continue;
        }
        changes.push({
            kind: "add_blocking_dependency",
            issue: { kind: "issue", issueId: input.parentIssue.id },
            blockedBy: { kind: "issue", issueId: childIssue.id },
        });
        liveBlockerIds.add(childIssue.id);
    }
    return changes;
}
async function buildControllerChildDependencyChanges(input) {
    const managedChildIssueIds = new Set([...input.childIssueByKey.values()].map((childIssue) => childIssue.id));
    for (const childIssueStep of input.childIssueSteps) {
        const referencedChildIssueId = (0, shared_1.normalizeControllerChildIssueRef)(childIssueStep.childIssueRef);
        if (referencedChildIssueId !== null) {
            managedChildIssueIds.add(referencedChildIssueId);
        }
    }
    const resolveDependencySteps = (0, shared_1.createControllerChildDependencyStepResolver)({
        childIssueSteps: input.childIssueSteps,
        allWorkflowSteps: input.allWorkflowSteps ?? input.childIssueSteps,
    });
    const changes = [];
    for (const childIssueStep of input.childIssueSteps) {
        const childIssue = input.activeChildIssueByKey.get(childIssueStep.childKey);
        if (childIssue === undefined) {
            continue;
        }
        const desiredDependencyIds = resolveDesiredControllerChildDependencyIds({
            childIssueStep,
            resolveDependencySteps,
            childIssueByKey: input.childIssueByKey,
        });
        const currentBlockers = await input.ticketTracker.listBlockingDependencies(childIssue.id);
        const currentManagedBlockerIds = new Set(currentBlockers
            .filter((blocker) => managedChildIssueIds.has(blocker.id))
            .map((blocker) => blocker.id));
        for (const blockerId of currentManagedBlockerIds) {
            if (desiredDependencyIds.has(blockerId)) {
                continue;
            }
            changes.push({
                kind: "remove_blocking_dependency",
                issue: { kind: "issue", issueId: childIssue.id },
                blockedBy: { kind: "issue", issueId: blockerId },
            });
        }
        for (const blockerId of desiredDependencyIds) {
            if (currentManagedBlockerIds.has(blockerId)) {
                continue;
            }
            changes.push({
                kind: "add_blocking_dependency",
                issue: { kind: "issue", issueId: childIssue.id },
                blockedBy: { kind: "issue", issueId: blockerId },
            });
        }
    }
    return changes;
}
function resolveDesiredControllerChildDependencyIds(input) {
    const desiredDependencyIds = new Set();
    for (const dependencyStep of input.resolveDependencySteps(input.childIssueStep)) {
        const dependencyIssue = input.childIssueByKey.get(dependencyStep.childKey);
        if (dependencyIssue === undefined || !dependencyIssue.isOpen) {
            continue;
        }
        desiredDependencyIds.add(dependencyIssue.id);
    }
    return desiredDependencyIds;
}
async function resolveControllerChildForStep(input) {
    const openChild = input.openChildIssueByKey.get(input.childIssueStep.childKey);
    if (openChild !== undefined) {
        const workflowState = input.openChildWorkflowStateByKey.get(input.childIssueStep.childKey) ??
            null;
        if (workflowState !== null &&
            (0, shared_1.isControllerChildForParent)({
                workflowState,
                parentDisplayId: input.parentIssue.displayId,
                childKey: input.childIssueStep.childKey,
            })) {
            return {
                kind: "open",
                issue: openChild,
                workflowState,
            };
        }
    }
    const completedChild = await (0, match_1.resolveCompletedControllerChildIssueByRef)({
        ticketTracker: input.ticketTracker,
        parentIssue: input.parentIssue,
        childIssueStep: input.childIssueStep,
    });
    if (completedChild !== null) {
        return {
            kind: "completed",
            issue: completedChild.issue,
            workflowState: completedChild.workflowState,
        };
    }
    return undefined;
}
function preserveExistingControllerChildPatchState(input) {
    if (input.existingWorkflowState === null) {
        return input.nextWorkflowState;
    }
    return {
        ...input.nextWorkflowState,
        consecutiveAiRuns: input.existingWorkflowState.consecutiveAiRuns,
        totalAiRunHours: input.existingWorkflowState.totalAiRunHours,
        lastScannedCommentCursor: input.existingWorkflowState.lastScannedCommentCursor,
        followup: (0, shared_1.resolveStoredControllerChildFollowupState)(input.existingWorkflowState.followup),
    };
}
function buildCreateControllerChildIssuePlan(input) {
    return (0, issue_creation_publication_1.buildCreateIssuePublicationPlan)({
        issueKey: input.childKey,
        source: "controller",
        branchTarget: "parent_issue_branch",
        relationship: {
            kind: "blocking_parent",
            parentIssueId: input.parentIssueId,
        },
        title: input.desiredSpec.title,
        body: input.desiredSpec.issueBody,
        trackerFields: {
            assignees: input.desiredSpec.assignees,
            labelNames: input.desiredSpec.labelNames,
            ...(input.desiredSpec.milestoneRef !== undefined
                ? { milestoneRef: input.desiredSpec.milestoneRef }
                : {}),
            ...(input.desiredSpec.projectRef !== undefined
                ? { projectRef: input.desiredSpec.projectRef }
                : {}),
        },
        workflowState: input.childWorkflowState,
        dependencyChanges: [
            {
                kind: "add_blocking_dependency",
                issue: { kind: "issue", issueId: input.parentIssueId },
                blockedBy: { kind: "target" },
            },
        ],
        runLimitPolicy: input.runLimitPolicy,
        newIssueFailurePolicy: "close_created_internal_issue",
        responseLanguage: input.responseLanguage,
    });
}
function buildPatchControllerChildIssuePlan(input) {
    const nextWorkflowProjection = (0, workflow_labels_1.parseWorkflowStateFromLabelNames)(input.workflowLabels, input.desiredSpec.labelNames);
    if (nextWorkflowProjection === null) {
        throw new Error(`Controller child patch requires a managed workflow state label for ${input.existingChild.displayId}.`);
    }
    return (0, issue_creation_publication_1.buildPatchIssuePublicationPlan)({
        issueKey: input.childKey,
        issue: input.existingChild,
        title: input.desiredSpec.title,
        body: input.desiredSpec.issueBody,
        trackerFields: {
            assignees: input.desiredSpec.assignees,
            labelNames: input.desiredSpec.labelNames,
            ...(input.desiredSpec.milestoneRef !== undefined
                ? { milestoneRef: input.desiredSpec.milestoneRef }
                : {}),
            ...(input.desiredSpec.projectRef !== undefined
                ? { projectRef: input.desiredSpec.projectRef }
                : {}),
        },
        workflowState: input.childWorkflowState,
        workflowProjection: {
            previous: input.existingChild.workflowState,
            next: nextWorkflowProjection,
        },
        runLimitPolicy: input.runLimitPolicy,
        responseLanguage: input.responseLanguage,
    });
}
