"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildApprovePlanSpec = buildApprovePlanSpec;
exports.buildStartPlanSpec = buildStartPlanSpec;
exports.buildInvalidWorkflowCommandPlanSpec = buildInvalidWorkflowCommandPlanSpec;
exports.buildAcceptedWorkflowCommandPlanSpec = buildAcceptedWorkflowCommandPlanSpec;
exports.buildAcceptedWorkflowUpdatePlanSpec = buildAcceptedWorkflowUpdatePlanSpec;
const control_plane_config_1 = require("../../config/control-plane-config");
const types_1 = require("../../platform/workflow-state/types");
const workflow_surface_1 = require("../../run/run-once-cycle/workflow-surface");
const command_apply_1 = require("../../workflows/command-apply");
const config_override_validation_1 = require("../../workflows/config-override-validation");
const foreign_input_approval_1 = require("../../workflows/foreign-input-approval");
const plan_progress_1 = require("../../workflows/plan-progress");
const publisher_1 = require("../../workflows/publisher");
const publisher_events_1 = require("../../workflows/publisher-events");
const start_approval_support_1 = require("../../workflows/start-approval-support");
const visible_update_builders_1 = require("../../workflows/visible-update-builders");
const workflow_projection_support_1 = require("../../workflows/workflow-projection-support");
const workflow_timeline_scan_1 = require("../../workflows/workflow-timeline-scan");
const config_accepted_workflow_command_support_1 = require("./config-accepted-workflow-command-support");
const config_accepted_command_snapshot_support_1 = require("./config-accepted-command-snapshot-support");
const config_accepted_update_publish_support_1 = require("./config-accepted-update-publish-support");
const config_approval_helpers_1 = require("./config-approval-helpers");
const config_decision_approval_support_1 = require("./config-decision-approval-support");
const config_decision_support_1 = require("./config-decision-support");
const config_publish_spec_support_1 = require("./config-publish-spec-support");
const config_followup_label_support_1 = require("./config-followup-label-support");
async function buildApprovePlanSpec(input) {
    const { context, comment } = input;
    const { effectiveConfig, normalizedStickyState } = (0, config_decision_approval_support_1.resolveServiceRuntimeStartApprovalNormalization)({
        config: context.config,
        issue: context.issue,
        stickyState: context.stickyState,
    });
    const assigneeGate = (0, config_approval_helpers_1.resolveServiceRuntimeApprovalAssigneeGate)({
        issue: context.issue,
        comment,
    });
    if (assigneeGate === "single-assignee-required") {
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "approve",
            issue: context.issue,
            stickyState: context.stickyState,
            comment,
            message: (0, config_decision_support_1.buildApproveFeedbackMessage)(context.responseLanguage, "single-assignee-required"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    if (assigneeGate === "assignee-only") {
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "approve",
            issue: context.issue,
            stickyState: context.stickyState,
            comment,
            message: (0, config_decision_support_1.buildApproveFeedbackMessage)(context.responseLanguage, "assignee-only"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    if (context.issue.workflowState.status === types_1.WORKFLOW_STATUSES.aiNeedsHuman &&
        (0, start_approval_support_1.isWorkflowAwaitingActiveStartApproval)({
            config: effectiveConfig,
            issue: context.issue,
            workflowState: context.stickyState,
        })) {
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "approve",
            issue: context.issue,
            stickyState: context.stickyState,
            comment,
            message: (0, config_decision_support_1.buildApproveFeedbackMessage)(context.responseLanguage, "start-approval-context"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    const linkedIssueContext = await (0, config_decision_support_1.resolveLinkedIssueApprovalContext)({
        ticketTracker: context.ticketTracker,
        issue: context.issue,
    });
    const approvalInput = {
        ticketTracker: context.ticketTracker,
        config: effectiveConfig,
        issue: context.issue,
        comments: context.comments,
        scanStartCursor: context.stickyState?.lastScannedCommentCursor ?? null,
        throughCursor: (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(comment),
        includeThroughCursor: false,
        currentAssignee: comment.author,
    };
    if (linkedIssueContext !== null) {
        approvalInput.linkedIssue = linkedIssueContext.issue;
        approvalInput.linkedIssueComments = linkedIssueContext.comments;
    }
    if (context.stickyState?.foreignInputApproval !== undefined) {
        approvalInput.approvalState = context.stickyState.foreignInputApproval;
    }
    const approvalRequirement = await (0, foreign_input_approval_1.resolveForeignApprovalRequirement)(approvalInput);
    if (!approvalRequirement.required) {
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "approve",
            issue: context.issue,
            stickyState: context.stickyState,
            comment,
            message: (0, config_decision_support_1.buildApproveFeedbackMessage)(context.responseLanguage, "not-foreign-approval"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    const approvedWorkflowState = (0, config_decision_approval_support_1.materializeServiceRuntimeWorkflowState)({
        config: effectiveConfig,
        previousState: normalizedStickyState,
        workflowSurface: (0, workflow_surface_1.resolveWorkflowSurface)(context.issue),
        foreignInputApproval: {
            approvedBy: comment.author,
            approvedAssignee: comment.author,
            approvedAt: comment.createdAt,
            approvedDigest: approvalRequirement.digest,
            approvedThroughCursor: (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(comment),
        },
        needsHumanReason: null,
    });
    return buildAcceptedApprovePlanSpec({
        issue: context.issue,
        comment,
        effectiveConfig,
        responseLanguage: context.responseLanguage,
        scannedInputCursor: context.scannedInputCursor,
        workflowState: approvedWorkflowState,
    });
}
function buildAcceptedApprovePlanSpec(input) {
    if (input.issue.workflowState.status !== types_1.WORKFLOW_STATUSES.aiNeedsHuman) {
        return (0, config_publish_spec_support_1.buildServiceRuntimePublishSpec)({
            decisionKind: "approve",
            issue: input.issue,
            responseLanguage: input.responseLanguage,
            workflowState: input.workflowState,
            scannedInputCursor: input.scannedInputCursor,
            visibleUpdate: (0, config_decision_approval_support_1.buildApproveAcceptedVisibleUpdate)({
                language: input.responseLanguage,
                reason: "accepted-noop",
            }),
            visibleUpdateDedupeCursor: (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(input.comment),
        });
    }
    if ((0, start_approval_support_1.hasActiveWorkflowStartApproval)({
        config: input.effectiveConfig,
        issue: input.issue,
        workflowState: input.workflowState,
    })) {
        const nextWorkflowState = (0, config_decision_approval_support_1.materializeServiceRuntimeWorkflowState)({
            config: input.effectiveConfig,
            previousState: input.workflowState,
            needsHumanReason: publisher_events_1.WORKFLOW_NEEDS_HUMAN_REASONS.startApproval,
        });
        const nextSnapshot = (0, workflow_projection_support_1.withWorkflowStatus)(input.issue.workflowState, types_1.WORKFLOW_STATUSES.aiNeedsHuman);
        return (0, config_publish_spec_support_1.buildServiceRuntimePublishSpec)({
            decisionKind: "approve",
            issue: input.issue,
            responseLanguage: input.responseLanguage,
            workflowState: nextWorkflowState,
            scannedInputCursor: input.scannedInputCursor,
            workflowProjection: {
                previous: input.issue.workflowState,
                next: nextSnapshot,
            },
            visibleUpdate: (0, config_decision_approval_support_1.buildApproveAcceptedVisibleUpdate)({
                language: input.responseLanguage,
                reason: "accepted-start-approval",
                issueId: input.issue.id,
            }),
            visibleUpdateDedupeCursor: (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(input.comment),
        });
    }
    const nextSnapshot = (0, workflow_projection_support_1.withWorkflowStatus)(input.issue.workflowState, types_1.WORKFLOW_STATUSES.aiRunning);
    return (0, config_publish_spec_support_1.buildServiceRuntimePublishSpec)({
        decisionKind: "approve",
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: input.workflowState,
        scannedInputCursor: input.scannedInputCursor,
        workflowProjection: {
            previous: input.issue.workflowState,
            next: nextSnapshot,
        },
        visibleUpdate: (0, config_decision_approval_support_1.buildApproveAcceptedVisibleUpdate)({
            language: input.responseLanguage,
            reason: "accepted-ready",
        }),
        visibleUpdateDedupeCursor: (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(input.comment),
    });
}
function buildStartPlanSpec(input) {
    const { context, comment } = input;
    const { effectiveConfig, normalizedStickyState } = (0, config_decision_approval_support_1.resolveServiceRuntimeStartApprovalNormalization)({
        config: context.config,
        issue: context.issue,
        stickyState: context.stickyState,
    });
    const isStartApprovalContext = context.issue.workflowState.status === types_1.WORKFLOW_STATUSES.aiNeedsHuman &&
        (0, start_approval_support_1.isWorkflowAwaitingActiveStartApproval)({
            config: effectiveConfig,
            issue: context.issue,
            workflowState: context.stickyState,
        });
    const assigneeGate = (0, config_approval_helpers_1.resolveServiceRuntimeApprovalAssigneeGate)({
        issue: context.issue,
        comment,
    });
    if (assigneeGate === "single-assignee-required") {
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "start",
            issue: context.issue,
            stickyState: context.stickyState,
            comment,
            message: (0, config_decision_support_1.buildStartFeedbackMessage)(context.responseLanguage, "single-assignee-required"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    if (assigneeGate === "assignee-only") {
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "start",
            issue: context.issue,
            stickyState: context.stickyState,
            comment,
            message: (0, config_decision_support_1.buildStartFeedbackMessage)(context.responseLanguage, "assignee-only"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    if (!isStartApprovalContext ||
        context.issue.workflowState.status !== types_1.WORKFLOW_STATUSES.aiNeedsHuman) {
        const normalizedStartApprovalStateChanged = normalizedStickyState !== context.stickyState;
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "start",
            issue: context.issue,
            stickyState: context.stickyState,
            ...(normalizedStartApprovalStateChanged
                ? { workflowState: normalizedStickyState }
                : {}),
            ...(normalizedStartApprovalStateChanged
                ? {
                    workflowProjection: {
                        previous: context.issue.workflowState,
                        next: (0, workflow_projection_support_1.withWorkflowStatus)(context.issue.workflowState, types_1.WORKFLOW_STATUSES.aiReady),
                    },
                }
                : {}),
            comment,
            message: (0, config_decision_support_1.buildStartFeedbackMessage)(context.responseLanguage, "not-start-approval"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    if (!(0, plan_progress_1.hasStartableWorkflowPlan)(normalizedStickyState)) {
        return buildApprovalFeedbackPlanSpec({
            decisionKind: "start",
            issue: context.issue,
            stickyState: context.stickyState,
            comment,
            message: (0, config_decision_support_1.buildStartFeedbackMessage)(context.responseLanguage, "invalid-workflow-state"),
            responseLanguage: context.responseLanguage,
            scannedInputCursor: context.scannedInputCursor,
        });
    }
    const nextSnapshot = (0, workflow_projection_support_1.withWorkflowStatus)(context.issue.workflowState, types_1.WORKFLOW_STATUSES.aiRunning);
    return (0, config_publish_spec_support_1.buildServiceRuntimePublishSpec)({
        decisionKind: "start",
        issue: context.issue,
        responseLanguage: context.responseLanguage,
        workflowState: (() => {
            const { pendingWorkflowStartApprovalIntent: _pendingWorkflowStartApprovalIntent, ...nextWorkflowState } = normalizedStickyState;
            return {
                ...nextWorkflowState,
                needsHumanReason: null,
            };
        })(),
        scannedInputCursor: context.scannedInputCursor,
        workflowProjection: {
            previous: context.issue.workflowState,
            next: nextSnapshot,
        },
        visibleUpdate: (0, visible_update_builders_1.buildWorkflowStartedVisibleUpdate)({
            language: context.responseLanguage,
        }),
        visibleUpdateDedupeCursor: (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(comment),
    });
}
function buildInvalidWorkflowCommandPlanSpec(context) {
    const parsed = context.commandDecision.command.command;
    const commandCursor = context.commandDecision.command.source === "comment"
        ? (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(context.commandDecision.command.comment)
        : null;
    const scannedInputCursor = context.commandDecision.command.source === "comment" ? commandCursor : null;
    const workflowProjection = (0, config_decision_support_1.buildInvalidWorkflowCommandProjection)({
        issue: context.issue,
        stickyState: context.stickyState,
        workflowLabels: context.workflowLabels,
        currentNeedsHumanReason: context.currentNeedsHumanReason,
    });
    const commentCursorPolicyMode = context.commandDecision.command.source === "body"
        ? publisher_1.WORKFLOW_COMMENT_CURSOR_POLICY_MODES.preserve
        : undefined;
    return (0, config_publish_spec_support_1.buildServiceRuntimeFeedbackPublishSpec)({
        decisionKind: "workflow_command",
        issue: context.issue,
        responseLanguage: context.responseLanguage,
        workflowState: context.stickyState,
        scannedInputCursor,
        summary: (0, config_decision_support_1.buildInvalidCommandMessage)(context.responseLanguage, parsed.reason),
        visibleUpdateDedupeCursor: commandCursor,
        commentCursorPolicyMode,
        workflowProjection,
    });
}
async function buildAcceptedWorkflowCommandPlanSpec(context) {
    const acceptedAt = context.commandDecision.command.source === "comment"
        ? context.commandDecision.command.comment.createdAt
        : context.issue.updatedAt;
    const parsed = context.commandDecision.command.command;
    const commandCursor = context.commandDecision.command.source === "comment"
        ? (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(context.commandDecision.command.comment)
        : null;
    const scannedInputCursor = context.commandDecision.command.source === "comment" ? commandCursor : null;
    return buildAcceptedWorkflowUpdatePlanSpec({
        repoRoot: context.repoRoot,
        config: context.config,
        ticketTracker: context.ticketTracker,
        issue: context.issue,
        comments: context.comments,
        stickyState: context.stickyState,
        currentNeedsHumanReason: context.currentNeedsHumanReason,
        responseLanguage: context.responseLanguage,
        workflowLabels: context.workflowLabels,
        command: parsed,
        acceptedAt,
        scannedInputCursor,
        currentWorkflowStateCommentId: context.currentWorkflowStateCommentId,
        handoffVisibleUpdateDedupeCursor: commandCursor,
    });
}
async function buildAcceptedWorkflowUpdatePlanSpec(input) {
    const parsed = input.command;
    if (hasUnavailableWorkerConfigOverrideAfterCommand(input)) {
        return buildInvalidWorkflowOptionPlanSpec(input);
    }
    const nextWorkflowStateResolution = await (0, config_decision_support_1.resolveAcceptedWorkflowStateForCommand)({
        repoRoot: input.repoRoot,
        locale: input.responseLanguage,
        config: input.config,
        issue: input.issue,
        stickyState: input.stickyState,
        comments: input.comments,
        scannedInputCursor: input.scannedInputCursor,
        acceptedAt: input.acceptedAt,
        command: parsed,
        maxNestedWorkflowDepth: input.config.maxNestedWorkflowDepth,
        issueBody: input.issue.body,
    });
    if (nextWorkflowStateResolution.kind === "handoff") {
        return (0, config_publish_spec_support_1.buildServiceRuntimeFeedbackPublishSpec)({
            decisionKind: "workflow_command",
            issue: input.issue,
            responseLanguage: input.responseLanguage,
            workflowState: input.stickyState,
            scannedInputCursor: input.scannedInputCursor,
            summary: nextWorkflowStateResolution.summary,
            visibleUpdateDedupeCursor: input.handoffVisibleUpdateDedupeCursor,
            commentCursorPolicyMode: input.commentCursorPolicyMode,
        });
    }
    let nextWorkflowState = nextWorkflowStateResolution.workflowState;
    const commandOptionsResolution = (0, config_accepted_workflow_command_support_1.applyAcceptedWorkflowCommandOptions)({
        workflowState: nextWorkflowState,
        command: parsed,
        acceptedAt: input.acceptedAt,
        displayTimeZone: input.config.i18n.displayTimeZone,
    });
    if (commandOptionsResolution.kind === "invalid") {
        return buildInvalidWorkflowOptionPlanSpec(input);
    }
    nextWorkflowState = commandOptionsResolution.workflowState;
    if (hasUnavailableWorkerOverride(input.config, nextWorkflowState.configOverrides)) {
        return buildInvalidWorkflowOptionPlanSpec(input);
    }
    const followupLabelRequest = applyExplicitFollowupLabelRequestAfterCommand({
        issue: input.issue,
        workflowLabels: input.workflowLabels,
        command: parsed,
        workflowState: nextWorkflowState,
    });
    nextWorkflowState = followupLabelRequest.workflowState;
    const previousEffectiveConfig = resolvePreviousEffectiveConfigForCommand({
        config: input.config,
        stickyState: input.stickyState,
    });
    const effectiveConfig = (0, control_plane_config_1.resolveIssueEffectiveConfigForWorkflowState)(input.config, nextWorkflowState);
    nextWorkflowState = (0, start_approval_support_1.normalizeWorkflowStartApprovalState)({
        config: effectiveConfig,
        issue: input.issue,
        workflowState: nextWorkflowState,
    });
    const snapshotResolution = await (0, config_accepted_command_snapshot_support_1.resolveAcceptedCommandSnapshotAndWorkflowState)({
        ticketTracker: input.ticketTracker,
        issue: input.issue,
        comments: input.comments,
        currentNeedsHumanReason: input.currentNeedsHumanReason,
        command: parsed,
        previousEffectiveConfig,
        effectiveConfig,
        previousConsecutiveAiRuns: input.stickyState?.consecutiveAiRuns ?? 0,
        workflowState: nextWorkflowState,
    });
    const nextSnapshot = snapshotResolution.nextSnapshot;
    nextWorkflowState = snapshotResolution.workflowState;
    const workflowProjection = (0, config_publish_spec_support_1.buildServiceRuntimeWorkflowProjection)({
        issue: input.issue,
        workflowLabels: input.workflowLabels,
        next: nextSnapshot,
        previousWorkflowState: input.stickyState,
        nextWorkflowState,
        previousNeedsHumanReason: input.currentNeedsHumanReason,
        nextNeedsHumanReason: nextSnapshot.status === types_1.WORKFLOW_STATUSES.aiNeedsHuman
            ? (nextWorkflowState.needsHumanReason ?? input.currentNeedsHumanReason)
            : null,
    });
    (0, config_accepted_update_publish_support_1.applyAcceptedWorkflowUpdateProjectionLabels)({
        workflowProjection,
        workflowLabels: input.workflowLabels,
        followupLabel: followupLabelRequest.followupLabel,
    });
    const shouldAppendCanonicalState = (0, config_accepted_workflow_command_support_1.shouldAppendAcceptedWorkflowCommandState)({
        comments: input.comments,
        currentWorkflowStateCommentId: input.currentWorkflowStateCommentId,
        scannedInputCursor: input.scannedInputCursor,
        workflowState: nextWorkflowState,
    });
    if (input.feedbackMode === "silent") {
        return (0, config_accepted_update_publish_support_1.buildSilentAcceptedWorkflowUpdatePublishSpec)({
            issue: input.issue,
            responseLanguage: input.responseLanguage,
            workflowState: nextWorkflowState,
            scannedInputCursor: input.scannedInputCursor,
            commentCursorPolicyMode: input.commentCursorPolicyMode,
            workflowProjection,
            shouldAppendCanonicalState,
        });
    }
    const acceptedSummary = await (0, config_accepted_update_publish_support_1.buildAcceptedWorkflowUpdateSummary)({
        repoRoot: input.repoRoot,
        responseLanguage: input.responseLanguage,
        displayTimeZone: input.config.i18n.displayTimeZone,
        workflowState: nextWorkflowState,
    });
    return (0, config_publish_spec_support_1.buildServiceRuntimeFeedbackPublishSpec)({
        decisionKind: "workflow_command",
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: nextWorkflowState,
        ...(shouldAppendCanonicalState
            ? { appendCanonicalWorkflowStateComment: true }
            : {}),
        scannedInputCursor: input.scannedInputCursor,
        commentCursorPolicyMode: input.commentCursorPolicyMode,
        workflowProjection,
        summary: acceptedSummary,
        visibleUpdateDedupeCursor: input.visibleUpdateDedupeCursor,
    });
}
function applyExplicitFollowupLabelRequestAfterCommand(input) {
    const followupLabel = (0, config_followup_label_support_1.resolveIssueFollowupRequestLabel)({
        issue: input.issue,
        workflowLabels: input.workflowLabels,
    });
    if (followupLabel === null) {
        return { workflowState: input.workflowState, followupLabel: null };
    }
    if (hasExplicitFollowupProposalOff(input.command)) {
        return { workflowState: input.workflowState, followupLabel };
    }
    if (input.workflowState.followup?.proposalPolicy === "always") {
        return { workflowState: input.workflowState, followupLabel };
    }
    return {
        workflowState: {
            ...input.workflowState,
            followup: {
                ...(input.workflowState.followup ?? {
                    proposalPolicy: "always",
                    proposalApproval: "auto",
                }),
                proposalPolicy: "always",
                proposalApproval: "auto",
            },
        },
        followupLabel,
    };
}
function hasExplicitFollowupProposalOff(command) {
    return (command.configOverridePatch?.entries.some((entry) => entry.path === "followup.proposalPolicy" &&
        entry.op === "set" &&
        entry.value === "off") ?? false);
}
function hasUnavailableWorkerConfigOverrideAfterCommand(input) {
    return hasUnavailableWorkerOverride(input.config, (0, command_apply_1.mergeConfigOverridePatch)(input.stickyState?.configOverrides, input.command.configOverridePatch));
}
function hasUnavailableWorkerOverride(config, patch) {
    return (0, config_override_validation_1.hasUnavailableWorkerConfigOverride)({
        configWorkers: (0, control_plane_config_1.getConfiguredWorkerProviders)(config),
        patch,
    });
}
function resolvePreviousEffectiveConfigForCommand(input) {
    if (hasUnavailableWorkerOverride(input.config, input.stickyState?.configOverrides)) {
        return input.config;
    }
    return (0, control_plane_config_1.resolveIssueEffectiveConfigForWorkflowState)(input.config, input.stickyState);
}
function buildInvalidWorkflowOptionPlanSpec(input) {
    return (0, config_publish_spec_support_1.buildServiceRuntimeFeedbackPublishSpec)({
        decisionKind: "workflow_command",
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: input.stickyState,
        scannedInputCursor: input.scannedInputCursor,
        summary: (0, config_decision_support_1.buildInvalidCommandMessage)(input.responseLanguage, "invalid-option-value"),
        visibleUpdateDedupeCursor: input.handoffVisibleUpdateDedupeCursor,
        commentCursorPolicyMode: input.commentCursorPolicyMode,
    });
}
function buildApprovalFeedbackPlanSpec(input) {
    return (0, config_publish_spec_support_1.buildServiceRuntimeFeedbackPublishSpec)({
        decisionKind: input.decisionKind,
        issue: input.issue,
        responseLanguage: input.responseLanguage,
        workflowState: input.workflowState ?? input.stickyState ?? null,
        scannedInputCursor: input.scannedInputCursor,
        summary: input.message,
        visibleUpdateDedupeCursor: (0, workflow_timeline_scan_1.toWorkflowCommentCursor)(input.comment),
        workflowProjection: input.workflowProjection,
    });
}
