import type { ApprovalDecision, PendingApproval, WaitNodeConfig, WorkflowContext, WorkflowRun } from "../types.js"; import type { Schema } from "../../extensions/schema/index.js"; import { type PersistedPendingApproval, type WorkflowBackend } from "../backends/types.js"; import type { WorkflowExecutor } from "../executor/workflow-executor.js"; /** @internal Apply retained decisions after retry reactivates a failed run. */ export declare function reconcileApprovalDecisionClaimsBeforeRetry(backend: WorkflowBackend, runId: string): Promise; /** Receives detached approval and run snapshots. Mutating them does not change persisted state. */ export type ApprovalNotifier = (approval: PendingApproval, run: WorkflowRun) => Promise; export interface ApprovalResponseSchemaResolverInput { run: WorkflowRun; approval: PendingApproval; } export type ApprovalResponseSchemaResolver = (input: ApprovalResponseSchemaResolverInput) => Schema | undefined | Promise | undefined>; export interface InternalApprovalResponseSchemaResolverInput { run: WorkflowRun; approval: PersistedPendingApproval; } export type InternalApprovalResponseSchemaResolver = (input: InternalApprovalResponseSchemaResolverInput) => Schema | undefined | Promise | undefined>; export interface ApprovalManagerConfig { /** Backend for persistence */ backend: WorkflowBackend; /** Workflow executor for resuming after approval */ executor?: WorkflowExecutor; /** Notification callback. Approvals are persisted before this callback runs. */ notifier?: ApprovalNotifier; /** Resolve a wait node response schema for persisted approvals. */ responseSchemaResolver?: ApprovalResponseSchemaResolver; /** Resolve a response schema from backend-only approval metadata. */ internalResponseSchemaResolver?: InternalApprovalResponseSchemaResolver; /** Check expired approvals interval (ms) */ expirationCheckInterval?: number; /** Age after which an unfinished decision claim is recoverable after a process exit (ms). */ decisionClaimRecoveryDelay?: number; /** Interval for discovering decision claims abandoned by another process (ms). */ decisionClaimCheckInterval?: number; /** Enable debug logging */ debug?: boolean; } export interface ApprovalRequest { /** Approval ID */ approvalId: string; /** Run ID */ runId: string; /** Node ID */ nodeId: string; /** Message for approver */ message: string; /** Payload with context */ payload: unknown; /** When approval expires */ expiresAt?: Date; /** * Set when notifying approvers failed. The approval was still created and the * workflow is paused, but approvers were NOT informed. The caller should * re-notify or alert an operator rather than assume delivery. */ notificationError?: string; } /** Manages pending approvals, processing decisions, and resuming workflows */ export declare class ApprovalManager { private config; private expirationTimer?; private destroyed; private responseSchemas; private activeDecisionClaims; private decisionClaimReconciliation?; private decisionClaimRecoveryTimer?; private decisionClaimRecoveryAt?; private decisionClaimCheckTimer?; constructor(config: ApprovalManagerConfig); private findApprovalCreationCollision; private startDecisionClaimRecovery; /** Create a pending approval request */ createApproval(run: WorkflowRun, nodeId: string, waitConfig: WaitNodeConfig, context: WorkflowContext, options?: { responseSchemaId?: string; notify?: boolean; }): Promise; /** Notify after the execution lock has released for an already-persisted approval. */ notifyPendingApproval(run: WorkflowRun, nodeId: string): Promise; private notifyApproval; /** Get pending approval by ID */ getApproval(runId: string, approvalId: string): Promise; private getPersistedApproval; /** Get all pending approvals for a run */ getPendingApprovals(runId: string): Promise; private responseSchemaKey; private resolveResponseSchema; private validateDecisionData; /** Reconcile durable decisions left behind by an interrupted process. */ checkApprovalDecisionClaims(): Promise; private reconcileApprovalDecisionClaims; private reconcileApprovalDecisionClaim; private tryReconstructApprovalDecision; private reserveApprovalDecisionRecovery; private reconcileReservedApprovalDecision; /** Return true when the durable decision remains live and its reservation should be released. */ private applyReservedApprovalDecision; private finishCommittedApprovalDecision; private finalizeReservedApproval; private decisionClaimKey; private scheduleDecisionClaimRecovery; /** Process an approval decision */ processDecision(runId: string, approvalId: string, decision: ApprovalDecision): Promise; private assertDecisionCanApply; private reconcileAppliedDecision; private submitDecision; /** Approve an approval request */ approve(runId: string, approvalId: string, approver: string, comment?: string, data?: unknown): Promise; /** Reject an approval request */ reject(runId: string, approvalId: string, approver: string, comment?: string, data?: unknown): Promise; /** List all pending approvals across workflows */ listAllPending(filter?: { workflowId?: string; approver?: string; }): Promise>; /** Check and expire stale approvals */ checkExpiredApprovals(): Promise; private expireApproval; private startExpirationChecker; private startDecisionClaimChecker; private runMaintenance; /** Stop the approval manager */ stop(): void; } //# sourceMappingURL=approval-manager.d.ts.map