/** * WebService - Static file serving service with HTTP API. * * Provides configurable static file serving with security features including * basic auth, extension filtering, directory browsing, file size limits, * CORS, and SSL support. Equivalent to the Python SDK's WebService class. */ import { Hono } from 'hono'; import { SslConfig } from './SslConfig.js'; import type { SslOptions } from './SslConfig.js'; /** Configuration options for WebService. */ export interface WebServiceOptions { /** Port to bind to. Default: 8002. */ port?: number; /** Map of URL route prefixes to local directory paths. Default: {}. */ directories?: Record; /** Basic auth credentials as [username, password]. Default: none. */ basicAuth?: [string, string]; /** Path to a JSON config file. Default: none. */ configFile?: string; /** Serve directory listings and fall back to index.html. Default: false. */ enableDirectoryBrowsing?: boolean; /** Allowlist of file extensions (e.g. ['.html', '.css']). Default: all allowed. */ allowedExtensions?: string[]; /** * Blocklist of file extensions or names. * Default: ['.env', '.git', '.gitignore', '.key', '.pem', '.crt', '.pyc', '__pycache__', '.DS_Store', '.swp'] */ blockedExtensions?: string[]; /** Maximum file size in bytes. Default: 104857600 (100 MB). */ maxFileSize?: number; /** Enable CORS. Default: true. */ enableCors?: boolean; /** SSL/TLS configuration options. */ ssl?: SslOptions; } /** * Static file serving service with HTTP API. * * Provides configurable static file hosting with per-route directory mounting, * extension filtering, file size limits, HTTP Basic Auth, CORS, directory * browsing, and optional SSL/TLS. Mirrors the Python SDK's `WebService` class. * * Useful when an agent or prefab needs to serve supporting assets — prompts, audio * files, images — from the same process without running a separate nginx / CDN. * * @example Serve a directory of audio files * ```ts * import { WebService } from '@signalwire/sdk'; * * const web = new WebService({ * port: 8080, * directories: { '/audio': './public/audio' }, * allowedExtensions: ['.mp3', '.wav'], * }); * * await web.serve(); * // GET http://host:8080/audio/greeting.mp3 * ``` */ export declare class WebService { /** Port the service binds to. */ readonly port: number; /** Whether directory listings are enabled. */ readonly enableDirectoryBrowsing: boolean; /** Maximum file size in bytes that will be served. */ readonly maxFileSize: number; /** Whether CORS is enabled. */ readonly enableCors: boolean; /** Allowlist of file extensions, or null to allow all (subject to blocklist). */ readonly allowedExtensions: string[] | null; /** Blocklist of file extensions and file names. */ readonly blockedExtensions: string[]; /** Map of URL route prefixes to local directory paths. */ readonly directories: Record; private _app; private _basicAuth; private _ssl; private _server; private readonly log; /** Default blocked extensions and file names (security-sensitive files). */ private static readonly DEFAULT_BLOCKED; /** * Create a WebService. * @param options - Configuration options for the service. */ constructor(options?: WebServiceOptions); /** * Add a new directory to serve at a URL route prefix. * @param route - URL prefix (e.g. '/docs'). * @param directory - Local directory path to serve. * @throws If the directory does not exist or is not a directory. */ addDirectory(route: string, directory: string): void; /** * Remove a previously added directory route from the bookkeeping map. * * Note: Hono does not support dynamic route removal; a server restart * is required for the route to fully stop responding. * @param route - The URL route prefix to remove. */ removeDirectory(route: string): void; /** * Get the Hono application for mounting or testing. * @returns The configured Hono app. */ getApp(): Hono; /** * The SSL/TLS configuration for this service. * * Mirrors the Python SDK's `security` attribute (`SecurityConfig`), which * exposes SSL settings for post-construction inspection. In the Python SDK * `SecurityConfig` also covers CORS origins, HSTS, allowed hosts, and rate * limiting; in this SDK those concerns are configured via their own * constructor options (`enableCors`, `ssl`, etc.) and Hono middleware rather * than a single combined object. * * @returns The `SslConfig` instance used by this service. */ get sslConfig(): SslConfig; /** * Start the HTTP(S) service. * * When `SWAIG_CLI_MODE=true` is set in the environment, the call is a * no-op so config can be inspected without binding a port. * * @param host - Bind address. Defaults to `'0.0.0.0'`. * @param port - Port override. Defaults to `this.port`. * @param sslCert - Path to SSL certificate file (overrides `SslConfig`). * @param sslKey - Path to SSL key file (overrides `SslConfig`). * @returns Resolves once the server has begun listening. */ start(host?: string, port?: number, sslCert?: string, sslKey?: string): Promise; /** * Stop the service and release resources. */ stop(): void; /** Intermediate config shape returned by the file loader. */ private _loadConfig; private _extractServiceConfig; private _setupMiddleware; private _setupRoutes; private _mountDirectories; private _mountSingleDirectory; private _isFileAllowed; private _serveFile; private _serveDirectoryListing; }