/** * Route resolution * * Combines binding rules, identity links, and config to pick an agent and session keys. */ import type { BindingRule, RouteInput, RouteResult } from './bindings.js'; /** * Route context type (alias for RouteInput) */ export type RouteContext = RouteInput; /** * Identity link map: canonical peer id -> aliases across channels. * * Shape: `{ canonicalName: [alias1, alias2, ...] }` */ export type IdentityLinks = Record; /** * Session-related routing options. */ export interface SessionConfig { scope?: 'per-sender' | 'global'; mainKey?: string; /** How DM sessions are scoped / merged */ dmScope?: 'main' | 'per-peer' | 'per-channel-peer' | 'per-account-channel-peer'; /** Cross-channel identity aliases */ identityLinks?: IdentityLinks; resetTriggers?: string[]; idleMinutes?: number; reset?: { mode?: 'daily' | 'idle'; atHour?: number; idleMinutes?: number; }; resetByType?: { direct?: SessionConfig['reset']; group?: SessionConfig['reset']; thread?: SessionConfig['reset']; }; resetByChannel?: Record>; /** Optional session store tuning */ storage?: { pruneAfterMs?: number; maxEntries?: number; }; } /** * Agent list and default id from config. */ export interface AgentConfig { /** Default agent id */ default?: string; /** Registered agents */ list?: Array<{ id: string; enabled?: boolean; [key: string]: unknown; }>; } /** * Subset of app config used for routing. */ export interface RoutingConfig { agents?: AgentConfig; bindings?: BindingRule[] | any[]; session?: SessionConfig; } /** * Input to `resolveRoute`. */ export interface ResolveRouteInput extends RouteInput { /** Routing config snapshot */ config: RoutingConfig; /** Optional thread id for threaded channels */ threadId?: string | null; } /** * Resolved route including session keys. */ export interface ResolveRouteResult extends RouteResult { /** Active session key for this turn */ sessionKey: string; /** Main session key (DM merge target) */ mainSessionKey: string; /** Whether routing used the main or a per-session key */ lastRoutePolicy: 'main' | 'session'; } /** * Apply identity links and return a canonical lowercased peer id. */ export declare function applyIdentityLinks(peerId: string, channel: string, identityLinks?: IdentityLinks): string; /** * Default agent id from config (`agents.default`, `list[].default`, or `main`). */ export declare function getDefaultAgentId(config: RoutingConfig): string; /** * Whether `agentId` appears in the enabled agent list (or list is absent). */ export declare function agentExists(agentId: string, config: RoutingConfig): boolean; /** * Return `agentId` if listed, otherwise the default agent id. */ export declare function pickFirstExistingAgentId(agentId: string, config: RoutingConfig): string; /** * Thin wrapper around `buildSessionKey` for route inputs. */ export declare function buildRouteSessionKey(agentId: string, channel: string, accountId: string, peerKind: string, peerId: string, threadId?: string | null, scopeId?: string | null): string; /** * Map session vs main key to policy label. */ export declare function deriveLastRoutePolicy(sessionKey: string, mainSessionKey: string): 'main' | 'session'; /** * Resolve agent and session keys from channel context and config. */ export declare function resolveRoute(input: ResolveRouteInput): ResolveRouteResult; /** * Parse basic routing fields from a session key string. */ export declare function resolveRouteFromSessionKey(sessionKey: string, _config: RoutingConfig): { agentId: string; source: string; accountId: string; peerKind: string; peerId: string; } | null;