import type { MemeshDatabase } from '../storage/sqlite.js'; import { type AgentJsonObject, type AgentMessagePayload, type AgentMessagePostCommitNotifier } from './agent-messaging.js'; export declare const AGENT_ROUTER_PROTOCOL_VERSION = 2; export declare const AGENT_ROUTER_MAX_FRAME_BYTES: number; export declare const AGENT_ROUTER_MAX_HOPS = 4; export declare const AGENT_ROUTER_SOCKET_PATH_MAX_BYTES = 103; export interface AgentHostRegistration { project: string; principal_id: string; session_instance_id: string; adapter_kind: string; work_summary?: string; auth_token?: string; } export interface AgentHostDispatchInput { dispatch_id: string; attempt_id: string; project: string; principal_id: string; session_instance_id: string; connection_id: string; generation: number; hops: number; untrusted_payload: true; envelope: AgentMessagePayload; } export interface AgentHostDispatchResult { accepted: boolean; receipt?: AgentJsonObject; } export interface AgentHostAdapter { readonly kind: string; authenticate(registration: AgentHostRegistration): boolean | Promise; dispatch?(input: AgentHostDispatchInput): AgentHostDispatchResult | Promise; } export interface AgentRouterLimits { max_frame_bytes?: number; max_hops?: number; max_frames_per_window?: number; rate_window_ms?: number; lease_ms?: number; drain_limit?: number; delivery_timeout_ms?: number; } export interface AgentRouterOptions { db: MemeshDatabase; socket_path: string; adapters: readonly AgentHostAdapter[]; memesh_version: string; on_superseded?: () => void; router_instance_id?: string; limits?: AgentRouterLimits; } export interface AgentRouterRegisterRequest { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; type: 'register'; request_id: string; project: string; principal_id: string; session_instance_id: string; adapter_kind: string; work_summary?: string; auth_token?: string; memesh_version?: string; hops: number; } export interface AgentRouterDiscoverRequest { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; type: 'discover'; request_id: string; project: string; limit: number; hops: number; } export interface AgentRouterNotifyRequest { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; type: 'notify'; request_id: string; project: string; delivery_id: string; hops: number; } export interface AgentRouterHeartbeatRequest { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; type: 'heartbeat'; request_id: string; project: string; session_instance_id: string; connection_id: string; generation: number; hops: number; } export interface AgentRouterDisconnectRequest { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; type: 'disconnect'; request_id: string; project: string; session_instance_id: string; connection_id: string; generation: number; hops: number; } export interface AgentRouterHostAcceptRequest { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; type: 'host_accept'; request_id: string; attempt_id: string; delivery_id: string; connection_id: string; generation: number; receipt: AgentJsonObject; hops: number; } export interface AgentRouterHostRejectRequest { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; type: 'host_reject'; request_id: string; attempt_id: string; delivery_id: string; connection_id: string; generation: number; failure_code: string; hops: number; } export type AgentRouterRequest = AgentRouterRegisterRequest | AgentRouterDiscoverRequest | AgentRouterNotifyRequest | AgentRouterHeartbeatRequest | AgentRouterDisconnectRequest | AgentRouterHostAcceptRequest | AgentRouterHostRejectRequest; export type AgentRouterSuccessResponse = { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; request_id: string; ok: true; result: AgentJsonObject; }; export type AgentRouterErrorResponse = { version: typeof AGENT_ROUTER_PROTOCOL_VERSION; request_id: string; ok: false; error: { code: string; message: string; }; }; export type AgentRouterResponse = AgentRouterSuccessResponse | AgentRouterErrorResponse; export declare function isLegacyAgentRouterVersionMismatchResponse(value: unknown): boolean; export interface AgentSelectionCard { session_id: string; principal_id: string; host_kind: 'codex' | 'claude' | 'gemini' | 'other'; project: string; model: null; work_summary: string | null; active: true; generation: number; lease_expires_at_ms: number; } export declare class AgentRouterError extends Error { readonly code: string; constructor(code: string, message: string); } export declare class AgentRouterStaleGenerationError extends AgentRouterError { constructor(); } export declare class AgentRouterProtocolError extends AgentRouterError { } export declare class AgentRouter { readonly router_instance_id: string; readonly socket_path: string; readonly memesh_version: string; private readonly db; private readonly onSuperseded; private readonly adapters; private readonly limits; private server; private socketIdentity; private readonly sockets; private readonly externalConnections; private readonly selectionCards; private readonly inFlightDeliveries; private readonly pendingExternal; constructor(options: AgentRouterOptions); start(): Promise; stop(): Promise; private acceptSocket; private handleFrame; private handleRequest; private register; private recordSuperseded; private refuseIfSuperseded; private bindExternalConnection; private disconnectSocket; private handleHostOutcome; private recordLateHostAccept; private insertHostAccept; private registerConnection; private discover; private requireCurrentConnection; private insertPresenceFact; private drainConnection; private dispatchDelivery; private dispatchDeliveryOnce; private dispatchExternal; private loadDelivery; private resolveConnection; private connectionMatchesDelivery; private beginDispatchAttempt; private finishAttempt; private writeError; private writeResponse; } export declare function createAgentRouterNotifier(socketPath: string): AgentMessagePostCommitNotifier; export declare function sendAgentRouterRequest(socketPath: string, request: AgentRouterRequest, timeoutMs?: number): Promise; export declare function isNewerVersion(candidate: string, current: string): boolean; //# sourceMappingURL=agent-router.d.ts.map