/**
 * Approval Queue Service
 *
 * Manages pending tool approval requests for the Crewly Agent runtime.
 * When a tool requires approval (based on SecurityPolicy.requireApproval),
 * execution is blocked and a PendingApproval entry is created. External
 * callers (API, auditor) can then approve or reject the request.
 *
 * @module services/agent/crewly-agent/approval-queue.service
 */
import type { ToolSensitivity } from './types.js';
/**
 * Status of an approval request.
 */
export type ApprovalStatus = 'pending' | 'approved' | 'rejected' | 'expired';
/**
 * A single pending approval entry.
 */
export interface PendingApproval {
    /** Unique approval ID */
    id: string;
    /** Agent session that requested the tool call */
    sessionName: string;
    /** Name of the tool awaiting approval */
    toolName: string;
    /** Sensitivity classification of the tool */
    sensitivity: ToolSensitivity;
    /** Sanitized arguments passed to the tool */
    args: Record<string, unknown>;
    /** Current status */
    status: ApprovalStatus;
    /** ISO timestamp when the approval was requested */
    requestedAt: string;
    /** ISO timestamp when the approval was resolved (approved/rejected/expired) */
    resolvedAt?: string;
    /** Who resolved the approval (e.g. 'api', 'auditor', 'auto-expire') */
    resolvedBy?: string;
    /** Reason for rejection (if rejected) */
    reason?: string;
}
/**
 * Result of resolving (approve/reject) an approval request.
 */
export interface ApprovalResolution {
    /** Whether the resolution was successful */
    success: boolean;
    /** The resolved approval entry */
    approval?: PendingApproval;
    /** Error message if resolution failed */
    error?: string;
}
/**
 * In-memory approval queue for tool execution requests.
 *
 * Stores pending approvals and provides approve/reject operations.
 * Approvals that exceed the TTL are automatically marked as expired
 * when queried.
 *
 * @example
 * ```typescript
 * const queue = new ApprovalQueueService();
 * const approval = queue.enqueue('session-1', 'edit_file', 'destructive', { path: '/foo' });
 * // Later, approve it:
 * const result = queue.approve(approval.id, 'api');
 * ```
 */
export declare class ApprovalQueueService {
    private static instance;
    private approvals;
    private idCounter;
    private ttlMs;
    /**
     * Get the shared singleton instance.
     * All agent-runners and API controllers share the same queue.
     *
     * @returns The shared ApprovalQueueService instance
     */
    static getInstance(): ApprovalQueueService;
    /**
     * Reset the singleton instance (for testing only).
     */
    static resetInstance(): void;
    /**
     * Create a new ApprovalQueueService.
     *
     * @param ttlMs - Time-to-live for pending approvals in milliseconds
     */
    constructor(ttlMs?: number);
    /**
     * Add a new approval request to the queue.
     *
     * @param sessionName - Agent session requesting approval
     * @param toolName - Name of the tool
     * @param sensitivity - Sensitivity classification
     * @param args - Sanitized tool arguments
     * @returns The created PendingApproval entry
     */
    enqueue(sessionName: string, toolName: string, sensitivity: ToolSensitivity, args: Record<string, unknown>): PendingApproval;
    /**
     * Approve a pending approval request.
     *
     * @param id - Approval ID to approve
     * @param resolvedBy - Who is approving (e.g. 'api', 'auditor')
     * @returns Resolution result
     */
    approve(id: string, resolvedBy?: string): ApprovalResolution;
    /**
     * Reject a pending approval request.
     *
     * @param id - Approval ID to reject
     * @param resolvedBy - Who is rejecting
     * @param reason - Reason for rejection
     * @returns Resolution result
     */
    reject(id: string, resolvedBy?: string, reason?: string): ApprovalResolution;
    /**
     * Get all pending approval requests.
     *
     * @param sessionName - Optional filter by session name
     * @returns Array of pending approvals
     */
    getPending(sessionName?: string): PendingApproval[];
    /**
     * Get a specific approval by ID.
     *
     * @param id - Approval ID
     * @returns The approval entry or undefined
     */
    getById(id: string): PendingApproval | undefined;
    /**
     * Get the count of currently pending approvals.
     *
     * @returns Number of pending approvals
     */
    getPendingCount(): number;
    /**
     * Clear all approvals (for testing or reset).
     */
    clear(): void;
    /**
     * Resolve a pending approval with the given status.
     *
     * @param id - Approval ID
     * @param status - New status
     * @param resolvedBy - Who resolved it
     * @param reason - Optional reason (for rejections)
     * @returns Resolution result
     */
    private resolve;
    /**
     * Expire stale pending approvals that have exceeded the TTL.
     */
    private expireStale;
    /**
     * Get the oldest pending approval.
     *
     * @returns Oldest pending approval or undefined
     */
    private getOldestPending;
}
//# sourceMappingURL=approval-queue.service.d.ts.map