/** * AgentServer - Hosts multiple AgentBase instances under a single HTTP server. * * Each agent is mounted at its own route prefix. The root `/` lists all * registered agents, and `/health` + `/ready` are global health checks. */ import { Hono } from 'hono'; import { AgentBase, type RoutingCallback } from './AgentBase.js'; /** * Multi-agent HTTP server that hosts multiple AgentBase instances on distinct route prefixes. * * Use `AgentServer` when one process should serve more than one agent — each with its own * prompt, tools, and route. Internally, each agent's Hono router is mounted under its own * path. Static assets can also be served from a configured directory. * * @example Host two agents on one port * ```ts * import { AgentServer, AgentBase } from '@signalwire/sdk'; * * const salesAgent = new AgentBase({ name: 'sales', route: '/sales' }); * const supportAgent = new AgentBase({ name: 'support', route: '/support' }); * * const server = new AgentServer({ host: '0.0.0.0', port: 3000 }); * server.register(salesAgent); * server.register(supportAgent); * * await server.run(); * ``` * * @see {@link AgentBase} */ export declare class AgentServer { /** Hostname the server binds to. */ host: string; /** Port the server listens on. */ port: number; /** Logging level (debug, info, warn, error). */ readonly logLevel: string; /** Public logger for this server instance. */ readonly log: import("./Logger.js").Logger; private agents; private _app; private _sipRoutingEnabled; private _sipRoute; private _sipAutoMap; private _sipUsernameMapping; private _sipRoutingCallback; private _globalRoutingCallbacks; /** * Create an AgentServer. * @param opts - Optional host, port, and logLevel overrides; defaults to 0.0.0.0:3000, logLevel 'info'. */ constructor(opts?: { host?: string; port?: number; logLevel?: string; }); /** * Register an agent at the given route prefix. * @param agent - The AgentBase instance to mount. * @param route - Route prefix; defaults to the agent's own route or '/'. * @throws If the route is already occupied by another agent. */ register(agent: AgentBase, route?: string): void; /** * Remove an agent registration by route. * @param route - The route prefix to unregister. * @returns True if the agent was found and removed, false if not found. */ unregister(route: string): boolean; /** * Get all registered agents keyed by their route prefix. * @returns A map of route prefixes to AgentBase instances. */ getAgents(): Map; /** * Look up a registered agent by its route prefix. * @param route - The route prefix to look up. * @returns The agent at that route, or undefined if none is registered. */ getAgent(route: string): AgentBase | undefined; /** * Serve static files from a local directory under a given route prefix. * Includes path traversal protection (rejects `..`), MIME type detection, * and security headers (Cache-Control, X-Content-Type-Options). * @param directory - Absolute or relative path to the directory to serve. * @param route - Route prefix for static files (defaults to '/'). */ serveStaticFiles(directory: string, route?: string): void; /** * Set up central SIP-based routing for the server. * * This configures all agents to handle SIP requests at the specified path, * using a coordinated routing system where each agent checks if it can * handle SIP requests for specific usernames. * * @param route - The path for SIP routing (default: '/sip'). * @param autoMap - Whether to automatically map SIP usernames to agent routes (default: true). */ setupSipRouting(route?: string, autoMap?: boolean): void; /** * Register a mapping from a SIP username to an agent route at the server level. * * Allows callers to manually route an arbitrary SIP username to any already-registered * agent route, independent of the automatic mapping performed by `setupSipRouting`. * * @param username - The SIP username to map (stored lowercase). * @param route - The agent route to map the username to (leading `/` added if missing; trailing slashes stripped). */ registerSipUsername(username: string, route: string): void; /** * Register a routing callback across all agents at the given path. * * This allows unified routing logic to be applied to all agents from * a central server-level coordinator. * * @param callbackFn - The callback function that receives a request and body, returning a route string or undefined. * @param path - The path to register the callback at. */ registerGlobalRoutingCallback(callbackFn: RoutingCallback, path: string): void; /** * Auto-map SIP usernames for an agent based on name and route. */ private _autoMapAgentSipUsernames; /** * Build and return the Hono application with all registered agents and a root listing endpoint. * @returns The fully configured Hono app. */ getApp(): Hono; /** * Start the HTTP server and begin listening for requests. * * This method handles server mode only. For serverless deployments * (AWS Lambda, Google Cloud Functions, Azure Functions), use * {@link ServerlessAdapter} instead. When `SWAIG_CLI_MODE=true` is set in * the environment, the call is a no-op so agent config can be inspected * without starting a server. * * @param host - Override the configured hostname. Defaults to the * constructor value. * @param port - Override the configured port. Defaults to the constructor * value. * @returns Resolves once the underlying Hono server has begun listening. */ run(host?: string, port?: number): Promise; }