/**
 * Agent Peer Routing
 *
 * OpenClaw-inspired message routing system that binds inbound messages
 * to specific agent configurations by (channel, accountId, peer).
 *
 * Peer matches always take priority over channel-wide rules.
 *
 * Usage:
 * ```typescript
 * const router = getPeerRouter();
 *
 * // Route a specific user's WhatsApp messages to Claude Opus
 * router.addRoute({
 *   channelType: 'whatsapp',
 *   peerId: 'user-123',
 *   agent: { model: 'claude-3-opus', systemPrompt: 'Be helpful' }
 * });
 *
 * // Route all Discord messages to Grok
 * router.addRoute({
 *   channelType: 'discord',
 *   agent: { model: 'grok-3' }
 * });
 *
 * // Resolve route for a message
 * const route = router.resolve(message);
 * ```
 */
import { EventEmitter } from 'events';
import type { ChannelType, InboundMessage } from './index.js';
/**
 * Agent configuration for a route
 */
export interface RouteAgentConfig {
    /** Agent ID (for multi-agent setups) */
    agentId?: string;
    /** Model to use */
    model?: string;
    /** System prompt override */
    systemPrompt?: string;
    /** Max tool rounds */
    maxToolRounds?: number;
    /** Temperature */
    temperature?: number;
    /** Tools allowlist */
    allowedTools?: string[];
    /** Tools denylist */
    deniedTools?: string[];
    /** Custom agent metadata */
    metadata?: Record<string, unknown>;
}
/**
 * A routing rule
 */
export interface PeerRoute {
    /** Unique route ID */
    id: string;
    /** Route name/label */
    name: string;
    /** Route description */
    description?: string;
    /** Channel type to match (undefined = all channels) */
    channelType?: ChannelType;
    /** Account ID to match (for multi-account setups) */
    accountId?: string;
    /** Peer ID to match (undefined = all peers on channel) */
    peerId?: string;
    /** Channel ID to match (for specific groups/DMs) */
    channelId?: string;
    /** Agent configuration for this route */
    agent: RouteAgentConfig;
    /** Priority (higher = checked first) */
    priority: number;
    /** Whether this route is active */
    enabled: boolean;
    /** Conditions for matching */
    conditions?: RouteCondition[];
    /** Creation timestamp */
    createdAt: Date;
}
/**
 * Additional conditions for route matching
 */
export interface RouteCondition {
    /** Condition type */
    type: 'time-range' | 'message-pattern' | 'content-type' | 'is-dm' | 'is-group';
    /** Condition value */
    value: string | boolean;
}
/**
 * Result of route resolution
 */
export interface ResolvedRoute {
    /** Matched route */
    route: PeerRoute;
    /** Match type (how the route was matched) */
    matchType: 'peer' | 'channel-id' | 'channel-type' | 'account' | 'default';
    /** Match specificity (higher = more specific) */
    specificity: number;
    /** Agent config from the route */
    agent: RouteAgentConfig;
}
/**
 * Peer router configuration
 */
export interface PeerRouterConfig {
    /** Default agent config when no route matches */
    defaultAgent: RouteAgentConfig;
    /** Enable logging of routing decisions */
    logDecisions: boolean;
}
export declare class PeerRouter extends EventEmitter {
    private config;
    private routes;
    private routeCounter;
    private routingHistory;
    constructor(config?: Partial<PeerRouterConfig>);
    /**
     * Add a routing rule
     */
    addRoute(route: Omit<PeerRoute, 'id' | 'createdAt'> & {
        id?: string;
    }): PeerRoute;
    /**
     * Remove a routing rule
     */
    removeRoute(routeId: string): boolean;
    /**
     * Update a routing rule
     */
    updateRoute(routeId: string, updates: Partial<PeerRoute>): PeerRoute | null;
    /**
     * Enable/disable a route
     */
    toggleRoute(routeId: string, enabled: boolean): boolean;
    /**
     * Get a route by ID
     */
    getRoute(routeId: string): PeerRoute | undefined;
    /**
     * List all routes (sorted by priority descending)
     */
    listRoutes(): PeerRoute[];
    /**
     * Resolve the best route for an inbound message.
     * Peer matches take priority over channel-wide rules.
     *
     * Resolution order (highest to lowest priority):
     * 1. Exact peer match (channel + accountId + peer)
     * 2. Channel ID match (specific group/DM)
     * 3. Channel type + account match
     * 4. Channel type match (all peers on channel)
     * 5. Default agent config
     */
    resolve(message: InboundMessage, accountId?: string): ResolvedRoute | null;
    /**
     * Get effective agent config for a message (resolves route + applies defaults)
     */
    getAgentConfig(message: InboundMessage, accountId?: string): RouteAgentConfig;
    /**
     * Check if a route matches a message
     */
    private matchRoute;
    /**
     * Check a single route condition
     */
    private checkCondition;
    getStats(): {
        totalRoutes: number;
        activeRoutes: number;
        routesByChannel: Record<string, number>;
        routingDecisions: number;
        matchRate: number;
    };
    dispose(): void;
}
export declare function getPeerRouter(config?: Partial<PeerRouterConfig>): PeerRouter;
export declare function resetPeerRouter(): void;
