#!/usr/bin/env node /** * Web Server - Express.js HTTP Server with REST API and SSE * * Features: * - Express server with CORS, static files, and modular API routing * - Environment-based LLM provider configuration * - Category-based logging with configurable levels * - Health check endpoint and proper error handling * - Environment Variables: Automatically loads .env file for API keys and configuration * - Controlled startup behavior for direct execution vs imported usage * - Optional browser auto-open and process signal handler registration * * Configuration: AGENT_WORLD_DATA_PATH, LOG_LEVEL, LLM provider keys * Endpoints: /health + API routes from ./api.ts * * Recent Changes: * - 2026-02-26: Added specific global API error mapping for oversized JSON payloads, invalid JSON bodies, and readonly database errors to avoid generic INTERNAL_ERROR responses. * - 2026-02-08: Fixed auto-run detection to only trigger on direct execution * - 2026-02-08: Made browser auto-open configurable via AGENT_WORLD_AUTO_OPEN env var * - 2026-02-08: Prevented duplicate process signal handler registration using WeakSet * - 2026-02-08: Added shutdown guard to prevent race conditions during graceful shutdown */ import { Server } from 'http'; export { getErrorResponse } from './error-response.js'; type StartWebServerOptions = { openBrowser?: boolean; registerProcessHandlers?: boolean; }; export declare function startWebServer(port?: number, host?: string, options?: StartWebServerOptions): Promise;