/**
 * A2A Message Router
 *
 * Routes messages between agents, handling discovery, load balancing,
 * and message delivery with retry logic.
 *
 * @packageDocumentation
 */
import { type A2AMessage, type A2APayload, type TrustContext, type AgentEndpoint, type ChainContext } from './types.js';
import { TrustNegotiationService } from './trust-negotiation.js';
/**
 * Router configuration
 */
export interface RouterConfig {
    /** Default timeout for A2A calls */
    defaultTimeoutMs: number;
    /** Maximum retries */
    maxRetries: number;
    /** Retry delay base in ms */
    retryDelayMs: number;
    /** Enable circuit breaker */
    circuitBreakerEnabled: boolean;
    /** Circuit breaker failure threshold */
    circuitBreakerThreshold: number;
    /** Circuit breaker reset time in ms */
    circuitBreakerResetMs: number;
}
/**
 * Circuit breaker state
 */
interface CircuitBreakerState {
    failures: number;
    lastFailure: Date | null;
    state: 'closed' | 'open' | 'half-open';
    nextAttempt: Date | null;
}
/**
 * Message handler callback
 */
export type MessageHandler = (message: A2AMessage, context: MessageContext) => Promise<A2APayload | null>;
/**
 * Message context passed to handlers
 */
export interface MessageContext {
    /** Verified trust context */
    trustContext: TrustContext;
    /** Effective caller tier (after verification) */
    effectiveTier: number;
    /** Effective caller score (after verification) */
    effectiveScore: number;
    /** Chain context for nested calls */
    chainContext?: ChainContext;
    /** Request metadata */
    metadata: Record<string, unknown>;
}
export declare class A2ARouter {
    private config;
    private endpoints;
    private pendingRequests;
    private circuitBreakers;
    private handlers;
    private trustService;
    constructor(config?: Partial<RouterConfig>);
    /**
     * Set trust service (lazy initialization)
     */
    setTrustService(service: TrustNegotiationService): void;
    /**
     * Register an agent endpoint
     */
    registerEndpoint(endpoint: AgentEndpoint): void;
    /**
     * Unregister an agent endpoint
     */
    unregisterEndpoint(carId: string): void;
    /**
     * Get endpoint for a CAR ID
     */
    getEndpoint(carId: string): AgentEndpoint | undefined;
    /**
     * Discover endpoints matching criteria
     */
    discoverEndpoints(criteria: {
        capabilities?: string[];
        minTier?: number;
        action?: string;
    }): AgentEndpoint[];
    /**
     * Send an A2A message and wait for response
     */
    send(from: string, to: string, payload: A2APayload, trustContext: TrustContext, options?: {
        timeoutMs?: number;
        correlationId?: string;
    }): Promise<A2AMessage>;
    /**
     * Send fire-and-forget message (no response expected)
     */
    sendAsync(from: string, to: string, payload: A2APayload, trustContext: TrustContext): Promise<string>;
    /**
     * Deliver message to endpoint
     */
    private deliverMessage;
    /**
     * Handle message locally
     */
    private handleLocally;
    /**
     * Send response to a message
     */
    private sendResponse;
    /**
     * Send error response
     */
    private sendErrorResponse;
    /**
     * Register a message handler for a CAR ID
     */
    registerHandler(carId: string, handler: MessageHandler): void;
    /**
     * Unregister a message handler
     */
    unregisterHandler(carId: string): void;
    /**
     * Initialize circuit breaker for endpoint
     */
    private initCircuitBreaker;
    /**
     * Check if we can send to endpoint
     */
    private canSend;
    /**
     * Record successful call
     */
    private recordSuccess;
    /**
     * Record failed call
     */
    private recordFailure;
    /**
     * Handle timeout
     */
    private handleTimeout;
    /**
     * Handle delivery error
     */
    private handleDeliveryError;
    /**
     * Get message type from payload
     */
    private getMessageType;
    /**
     * Create A2A error
     */
    private createError;
    /**
     * Get router statistics
     */
    getStats(): {
        endpoints: number;
        pendingRequests: number;
        circuitBreakers: Record<string, CircuitBreakerState>;
    };
}
export declare function createA2ARouter(config?: Partial<RouterConfig>): A2ARouter;
export declare function getA2ARouter(): A2ARouter;
export {};
//# sourceMappingURL=router.d.ts.map