/**
 * FederationPeer - Unified cross-root bridge
 *
 * Replaces both EdgeGateway (daemon) and CrossRealmRouter (browser) with a
 * single shared implementation. Configuration-only differences, identical code.
 *
 * PRINCIPLE: "Symmetric peer-to-peer - should work no matter how many brokers
 * we put in between."
 *
 * Features from EdgeGateway:
 * - Security: policy, rate limiter, replay cache, anti-relay
 * - Legacy Matrix3 format support (optional)
 * - Metrics tracking
 * - includeInternalMeta/includeInboundEnvelope options
 *
 * Features from CrossRealmRouter:
 * - invoke() RPC with local/cross-root routing
 * - Tab isolation via InstanceResolver
 * - Group channel subscription (broadcast discovery)
 * - Lazy backbone initialization
 * - PATH_NOT_FOUND check (optional)
 */
import type { Transport } from './transport/base';
import type { CrossRealmEnvelopeLegacy, MxEnvelopeV1, ReplyEnvelopeLegacy, TaggedEnvelope } from './envelope';
import type { WireProfile } from './wire_profile';
import type { Clock } from './runtime/clock';
import type { Policy } from './security/policy';
import type { TokenBucketRateLimiter } from './security/ratelimit';
import type { ReplayCache } from './security/replay';
/**
 * @deprecated TS-8 DORMANT: ingress/shard envelope path is dormant until Phase 2
 * cross-account auth metadata is finalized.
 */
export type DormantMxEnvV1 = MxEnvelopeV1;
/** Reason for security block. */
export type SecurityBlockReason = 'anti_relay' | 'replay' | 'rate_limit' | 'policy';
/**
 * Determines if a target root is "local" and rewrites topics as needed.
 * Different implementations for daemon (exact match) and browser (tab isolation).
 */
export interface InstanceResolver {
    /** Base routing root for a tab or shard-local resolver. */
    readonly routingBaseRoot?: string;
    /** Check if target root routes locally */
    isLocal(targetRoot: string): boolean;
    /** Rewrite topic for local routing (e.g., add tab suffix) */
    rewriteForLocal(topic: string): string;
}
/**
 * Simple exact-match resolver for daemon.
 * Only the exact local root is considered local.
 */
export declare class ExactInstanceResolver implements InstanceResolver {
    private readonly localRoot;
    readonly routingBaseRoot: string;
    constructor(localRoot: string);
    isLocal(targetRoot: string): boolean;
    rewriteForLocal(topic: string): string;
}
/**
 * Tab-aware resolver for browser.
 * Handles: flowpad -> flowpad.tab-abc, flowpad.tab-abc -> flowpad.tab-abc
 */
export declare class TabInstanceResolver implements InstanceResolver {
    private readonly localRoot;
    private readonly baseRoot;
    readonly routingBaseRoot: string;
    constructor(localRoot: string);
    isLocal(targetRoot: string): boolean;
    rewriteForLocal(topic: string): string;
    /**
     * Rewrite URI for tab isolation.
     *
     * Examples (localRoot = 'flowpad.tab-abc', baseRoot = 'flowpad'):
     *   flowpad.db.accepts.Query -> flowpad.tab-abc.db.accepts.Query
     *   flowpad.tab-abc.db.accepts.Query -> flowpad.tab-abc.db.accepts.Query (no change)
     *   flowpad/db.accepts.Query -> flowpad.tab-abc.db.accepts.Query
     *   other.db.accepts.Query -> other.db.accepts.Query (no change)
     */
    private rewriteMatrixUri;
}
export interface FederationPeerMetrics {
    inboundRequests: number;
    inboundReplies: number;
    outboundReplies: number;
    timeouts: number;
    securityBlocks: {
        antiRelay: number;
        replay: number;
        rateLimit: number;
        policy: number;
    };
    pendingRequests: number;
}
export interface FederationPeerOptions {
    localRoot: string;
    /** @deprecated Use localRoot */
    localRealm?: string;
    shard?: string;
    localBus: Transport;
    backbone?: Transport;
    profile?: WireProfile;
    internalTimeoutMs?: number;
    /** Subscribe to group channel for broadcast discovery (Phase 1B) */
    subscribeToGroupChannel?: boolean;
    /** Check if local handler exists before routing (PATH_NOT_FOUND) */
    checkLocalSubscriber?: boolean;
    /** Instance resolver for tab/shard isolation */
    instanceResolver?: InstanceResolver;
    /** Include _mx meta in internal requests (default: true) */
    includeInternalMeta?: boolean;
    /** Include inbound envelope in internal request payload */
    includeInboundEnvelope?: boolean;
    securityPolicy?: Policy;
    rateLimiter?: TokenBucketRateLimiter;
    replayCache?: ReplayCache;
    enforceAntiRelay?: boolean;
    clock?: Clock;
    onInboundRequest?: (envelope: TaggedEnvelope, internalTopic: string) => void;
    onInboundReply?: (envelope: TaggedEnvelope) => void;
    onOutboundReply?: (replyEnvelope: ReplyEnvelopeLegacy | MxEnvelopeV1, ingressTopic: string) => void;
    onTimeout?: (correlationId: string, toPath: string) => void;
    onDrop?: (reason: string, topic: string, rawPayload: string) => void;
    onSecurityBlock?: (reason: SecurityBlockReason, envelope: TaggedEnvelope) => void;
    /** Enable verbose logging. Defaults to false. */
    logging?: boolean;
}
/**
 * FederationPeer is the unified bridge between:
 *   - the backbone transport (NATS leaf-node, cloud, etc.)
 *   - the local root bus (in-memory or NATS)
 *
 * Same class for daemon and browser. Configuration-only differences.
 */
export declare class FederationPeer {
    readonly localRoot: string;
    /** @deprecated Use localRoot */
    get localRealm(): string;
    private readonly localBus;
    private backbone;
    private readonly profile;
    private readonly shard;
    private readonly internalTimeoutMs;
    private readonly subscribeToGroupChannel;
    private readonly checkLocalSubscriber;
    private readonly instanceResolver;
    private readonly includeInternalMeta;
    private readonly includeInboundEnvelope;
    private readonly policy;
    private readonly rateLimiter?;
    private readonly replayCache?;
    private readonly enforceAntiRelay;
    private readonly clock;
    private readonly onInboundRequest?;
    private readonly onInboundReply?;
    private readonly onOutboundReply?;
    private readonly onTimeout?;
    private readonly onDrop?;
    private readonly onSecurityBlock?;
    private readonly _verbose;
    private started;
    private unsubBackbone;
    private crossRealmClient;
    private metrics;
    static validateOptions(opts: FederationPeerOptions): {
        valid: boolean;
        errors: string[];
    };
    constructor(opts: FederationPeerOptions);
    /**
     * Start the FederationPeer.
     * Subscribes to backbone ingress topics and optionally waits for SUBACK.
     */
    start(): Promise<void>;
    /**
     * Stop the FederationPeer.
     */
    stop(): void;
    /**
     * Set the backbone transport (lazy initialization).
     * Restarts ingress subscriptions if already started.
     */
    setBackbone(transport: Transport): void;
    /**
     * Check if backbone is connected.
     */
    get hasBackbone(): boolean;
    /**
     * Get the backbone transport (for SubscriptionForwarder coordination).
     */
    getBackbone(): Transport | null;
    /**
     * Get the local bus transport (for SubscriptionForwarder coordination).
     */
    getLocalBus(): Transport;
    private isFlushable;
    getMetrics(): FederationPeerMetrics;
    resetMetrics(): void;
    sendMx(env: MxEnvelopeV1): void;
    sendLegacy(env: CrossRealmEnvelopeLegacy | ReplyEnvelopeLegacy): void;
    private onBackbone;
    private handleLegacy;
    private handleLegacyCmd;
    private handleMx;
    private handleMxReply;
    private handleMxCmd;
    private hasLocalSubscriber;
    private deliverInternalEvent;
    private sendNack;
    /**
     * Invoke RPC on target root with request/reply semantics.
     *
     * Accepts two calling conventions:
     *   invoke(targetRoot, toPath, body, timeoutMs)  -- explicit root + path
     *   invoke(uri, body, timeoutMs)                 -- root/path URI
     *
     * - Local root: use local request/reply via correlation ID
     * - Foreign root: delegate to CrossRealmClient (mailbox pattern)
     */
    invoke<T = unknown>(targetRootOrUri: string, toPathOrBody: unknown, bodyOrTimeout?: unknown, timeoutMs?: number): Promise<T>;
    /**
     * Parse a Matrix URI for invoke: root/path or root.path
     */
    private parseInvokeUri;
    private invokeLocal;
    private getOrCreateCrossRealmClient;
    /**
     * Rewrite topic for tab isolation.
     * Delegates to the instance resolver.
     * PUBLIC API: Single source of truth for topic rewriting.
     */
    rewriteLocalTopic(topic: string): string;
    /**
     * Convert a local bus topic back to canonical URI format.
     *
     * Local bus format:  FLOWPAD-ROOT.tab-abc.db.accepts.Query  (dots)
     * Canonical URI:     FLOWPAD-ROOT.tab-abc/db.accepts.Query  (slash after root)
     *
     * This is the inverse of rewriteForLocal() for topics.
     * Use this for display, clipboard copy, and mx-call targeting.
     */
    toCanonicalUri(localBusTopic: string): string;
    /**
     * Route a message to the appropriate destination.
     *
     * For local root: rewrites topic and publishes to local bus.
     * For cross-root: wraps in envelope and publishes to backbone ingress.
     *
     * Works with semantic topic format (DNS hierarchical addressing).
     */
    route(topic: string, payload: unknown): Promise<void>;
    /**
     * Extract root from a topic string.
     * With DNS addressing, topics are semantic -- match known local root prefix.
     */
    private extractRoot;
}
//# sourceMappingURL=federation_peer.d.ts.map
