/**
 * SubscriptionForwarder - Lease-based event egress for federation
 *
 * Solves the "unsolicited event" problem: local emits have no destination.
 * Unlike Cmd/Result (which use correlationId for routing), Evt messages
 * need explicit subscription leases to know where to forward.
 *
 * MXSUB Protocol:
 * 1. Client sends Cmd to _federation.accepts.subscribe with sourceFilter
 * 2. Forwarder creates lease, subscribes to local bus, returns subId
 * 3. Matching local events are wrapped as Evt and published to client's mailbox
 * 4. Client can refresh lease or unsubscribe when done
 *
 * Security invariants:
 * - Anti-relay: events only forwarded to requesting root (no third-party relay)
 * - Lease expiry: subscriptions automatically cleaned up
 * - Rate limiting: max subscriptions per root
 *
 * @module packages/federation/src/runtime/subscription_forwarder
 */
import type { Transport } from '../transport/base';
import type { WireProfile } from '../wire_profile';
/**
 * Subscription request from remote client.
 */
export interface SubscribeRequest {
    /** Local topic filter to watch (e.g., "daemon.*.emits.scanComplete") */
    sourceFilter: string;
    /** Client's sink path where events will be delivered */
    sinkPath: string;
    /** Lease duration in seconds */
    leaseSeconds: number;
}
/**
 * Subscription response.
 */
export interface SubscribeResponse {
    /** Subscription ID for refresh/unsubscribe */
    subId: string;
    /** Expiration timestamp (Unix ms) */
    expiresAt: number;
}
/**
 * Refresh request.
 */
export interface RefreshRequest {
    /** Subscription ID to refresh */
    subId: string;
    /** New lease duration in seconds */
    leaseSeconds: number;
}
/**
 * Unsubscribe request.
 */
export interface UnsubscribeRequest {
    /** Subscription ID to cancel */
    subId: string;
}
/**
 * Metrics for subscription forwarder.
 */
export interface SubscriptionMetrics {
    activeSubscriptions: number;
    forwardedEvents: number;
    expiredLeases: number;
    rejectedRequests: number;
    subscribeRequests: number;
    refreshRequests: number;
    unsubscribeRequests: number;
}
/**
 * Options for SubscriptionForwarder.
 */
export interface SubscriptionForwarderOptions {
    /** Local root identifier */
    localRoot: string;
    /** @deprecated Use localRoot */
    localRealm?: string;
    /** Backbone transport for publishing events to remote mailboxes */
    backbone: Transport;
    /** Local bus transport for subscribing to local events */
    localBus: Transport;
    /** Wire profile for envelope formatting */
    profile: WireProfile;
    /** Maximum lease duration in seconds (default: 3600 = 1 hour) */
    maxLeaseSeconds?: number;
    /** Maximum subscriptions per root (default: 100) */
    maxSubscriptionsPerRoot?: number;
    /** @deprecated Use maxSubscriptionsPerRoot */
    maxSubscriptionsPerRealm?: number;
    /** Shard identifier for backbone mailbox (default: '00') */
    shard?: string;
    /** Lease expiry check interval in ms (default: 1000) */
    expiryCheckIntervalMs?: number;
}
/**
 * SubscriptionForwarder implements lease-based event egress.
 *
 * Clients request event forwarding via Cmd/Result to _federation.accepts.*
 * endpoints. Matching local events are wrapped as Evt and published to
 * the client's backbone mailbox.
 */
export declare class SubscriptionForwarder {
    private readonly localRoot;
    private readonly backbone;
    private readonly localBus;
    private readonly profile;
    private readonly shard;
    private readonly maxLeaseSeconds;
    private readonly maxSubscriptionsPerRoot;
    private readonly expiryCheckIntervalMs;
    private readonly leases;
    private readonly unsubscribers;
    private readonly rootSubscriptionCounts;
    private expiryTimer;
    private localUnsubscribers;
    private started;
    private metrics;
    constructor(options: SubscriptionForwarderOptions);
    /**
     * Start the forwarder.
     * Subscribes to _federation.accepts.* on local bus for subscription management.
     */
    start(): void;
    /**
     * Stop the forwarder.
     * Cleans up all leases and subscriptions.
     */
    stop(): void;
    /**
     * Get current metrics.
     */
    getMetrics(): SubscriptionMetrics;
    /**
     * Reset metrics (for testing).
     */
    resetMetrics(): void;
    private handleSubscribe;
    private handleRefresh;
    private handleUnsubscribe;
    private forwardEvent;
    private cleanupExpiredLeases;
    private removeLease;
    private generateSubId;
    private sendReply;
    private sendError;
}
//# sourceMappingURL=subscription_forwarder.d.ts.map