import type { IExitSignal, IDownSignal, IMonitorRef } from '../engine/mailbox/IMailbox';
export type { IExitSignal, IDownSignal, IMonitorRef };
/**
 * Error information passed to supervision handlers.
 */
export interface ISupervisionError {
    /** Child id that failed */
    childId: string;
    /** Error message */
    message: string;
    /** Stack trace (if available) */
    stack?: string;
    /** Original error object - use instanceof or type guards to check type */
    original?: unknown;
    /** Timestamp */
    ts: number;
    /** Number of times this child has been restarted */
    restartCount: number;
}
/**
 * Actions that can be taken in response to a child error.
 */
export type SupervisionAction = 'restart' | 'stop' | 'escalate' | 'ignore';
/**
 * Built-in supervision strategies.
 */
export type BuiltinStrategy = 'log' | 'restart' | 'restart-all' | 'stop' | 'escalate';
/**
 * Custom supervision function.
 */
export type SupervisionFn = (error: ISupervisionError) => SupervisionAction | Promise<SupervisionAction>;
/**
 * Supervision strategy - can be built-in string or custom function.
 */
export type SupervisionStrategy = BuiltinStrategy | SupervisionFn;
/**
 * Restart limits configuration.
 */
export interface IRestartLimits {
    /** Maximum restarts within time window */
    maxRestarts: number;
    /** Time window in milliseconds */
    withinMs: number;
}
/**
 * Supervision policy for a composite component.
 */
export interface ISupervisionPolicy {
    /** Strategy for handling errors */
    strategy: SupervisionStrategy;
    /** Restart limits (for 'restart' strategy) */
    restartLimits?: IRestartLimits;
    /** Delay before restart in ms */
    restartDelayMs?: number;
    /** Whether to bubble errors up via emit */
    emitErrors?: boolean;
}
/**
 * Default supervision policy.
 */
export declare const DEFAULT_SUPERVISION_POLICY: ISupervisionPolicy;
/**
 * Supervisor - manages error handling for child components.
 *
 * ## DESIGN NOTE: Exit Signals via Topics (Joe Armstrong's Concern)
 *
 * Exit signals are delivered via pub/sub topics, not actor mailboxes:
 * ```typescript
 * // In MatrixActor._monitorChild():
 * const exitTopic = `${childInfo.mount}.$exit`;
 * transport.subscribe(exitTopic, handleExitSignal);
 * ```
 *
 * **Why topics instead of mailboxes:**
 *
 * 1. **Multiple observers** - In Erlang, multiple processes can monitor
 *    the same process. Topics enable parent + siblings + external observers
 *    to all receive the exit signal.
 *
 * 2. **System-level vs application-level** - Exit signals are runtime
 *    infrastructure, not application messages. Erlang's monitors are also
 *    delivered by the runtime, not via the actor's message queue.
 *
 * 3. **Separation of concerns** - The mailbox is for business logic messages.
 *    Supervision is orthogonal infrastructure.
 *
 * **Tradeoff:**
 * - Topics: Anyone who knows the topic can listen (no exclusivity)
 * - Mailbox: Exclusive delivery, but only one supervisor per actor
 *
 * **If mailbox-based supervision is needed**, the IDownSignal could be
 * sent to the supervisor's mailbox as a message:
 * ```typescript
 * supervisorMailbox.send({
 *   command: '$down',
 *   payload: { target: 'child.$inbox', reason: 'error' },
 *   meta: { ts: Date.now() }
 * });
 * ```
 * This would require supervisors to run processMailbox() loops.
 */
export declare class Supervisor {
    private readonly _policy;
    private readonly _restartCounts;
    private readonly _restartTimestamps;
    constructor(policy?: ISupervisionPolicy);
    /**
     * Handle an error from a child.
     * Returns the action to take.
     */
    handleError(error: ISupervisionError): Promise<SupervisionAction>;
    /**
     * Check if child is over restart limit.
     */
    private _isOverRestartLimit;
    /**
     * Record a restart for tracking limits.
     */
    private _recordRestart;
    /**
     * Get restart delay in ms.
     */
    getRestartDelayMs(): number;
    /**
     * Check if errors should be emitted.
     */
    shouldEmitErrors(): boolean;
    /**
     * Check if strategy is 'restart-all'.
     */
    isRestartAllStrategy(): boolean;
    /**
     * Reset restart tracking for a child.
     */
    resetChild(childId: string): void;
    /**
     * Reset all tracking.
     */
    reset(): void;
    /**
     * Convert an actor IExitSignal to a SupervisionError.
     *
     * This bridges the actor mailbox system (IExitSignal) with the
     * supervision system (SupervisionError), enabling unified error handling.
     *
     * @param signal - Exit signal from actor termination
     * @returns SupervisionError for processing by handleError()
     */
    exitSignalToError(signal: IExitSignal): ISupervisionError;
    /**
     * Handle an actor exit signal.
     *
     * Convenience method that converts the signal and determines action.
     *
     * @param signal - Exit signal from actor termination
     * @returns Action to take
     */
    handleExitSignal(signal: IExitSignal): Promise<SupervisionAction>;
}
/**
 * Create a IDownSignal from an IExitSignal.
 *
 * Used by supervisors to notify monitors about child termination.
 *
 * @param exit - Exit signal from terminated actor
 * @param observerMount - Mount path of the observer
 * @returns IDownSignal to send to observers
 */
export declare function createDownSignal(exit: IExitSignal, observerMount: string): IDownSignal;
/**
 * Create a IMonitorRef for tracking monitors.
 *
 * @param target - Mount path being monitored
 * @param observer - Mount path of observer
 * @returns IMonitorRef for tracking
 */
export declare function createMonitorRef(target: string, observer: string): IMonitorRef;
//# sourceMappingURL=Supervision.d.ts.map