import { EventEmitter } from 'events'; import { GatewayMode } from './gateway-mode'; export declare class Type3GatewayServer extends EventEmitter { private wss; private registryWs; private serverConnections; private nodeId; private instanceId; private gatewayId; private configManager; private vault; private activeRequests; private healthCheckInterval; private currentVersion; private updateAvailable; private isUpdating; private port; private registryUrl; private registryApiUrl; private managementApp; private managementServer; private metrics; private apiKey; private isAuthenticated; private currentUser; private reconnectInterval; private reconnectAttempts; private maxReconnectAttempts; private reconnectDelay; private isShuttingDown; private headlessSessionManager; private apiKeyExpiresAt; private keyRenewalCheckInterval; private readonly KEY_RENEWAL_CHECK_INTERVAL; private readonly KEY_RENEWAL_THRESHOLD; private isRenewingKey; private readonly gatewayMode; private readonly enableRemoteLLMSession; private readonly enableLLMRouting; constructor(config: { port: number; registryUrl?: string; instanceId?: string; apiKey?: string; vaultPath?: string; vaultPassword?: string; configPath?: string; mode?: GatewayMode; enableRemoteLLMSession?: boolean; enableLLMRouting?: boolean; }); /** * Start the Type 3 gateway server */ start(): Promise; /** * Discover all available inference servers from the registry * This enables Type 3 Multi-Connect architecture */ private discoverInferenceServers; /** * Connect to all discovered inference servers (Multi-Connect) */ private connectToAllServers; /** * Connect to a specific inference server */ private connectToServer; /** * Handle disconnection from a specific server and schedule reconnection */ private handleServerDisconnection; /** * Register gateway with a specific server */ private registerWithServer; /** * Register gateway with all connected servers */ private registerWithAllServers; /** * Build registration message (extracted for reuse) */ private buildRegistrationMessage; /** * Initialize the headless session manager for remote automation */ private initializeHeadlessSessionManager; /** * Setup management REST API endpoints for CLI */ private setupManagementEndpoints; /** * Start management REST API server */ private startManagementServer; /** * Format uptime in human-readable format */ private formatUptime; /** * Connect to registry control plane */ private connectToRegistry; /** * Load API credentials from local vault * KEY DIFFERENCE from Type 2: Reads from local vault instead of receiving from Type 1 * * 🔒 SECURITY: Type 3 gateways should NEVER have direct database access. * Credentials must be added via: * 1. Local vault (persistent storage) * 2. Management API endpoints (POST /providers, POST /providers/:id/update-key) * 3. CLI tools that interact with the management API */ private loadCredentials; /** * Register gateway with registry * Includes tool discovery for remote automation sessions (if enabled) */ private registerGateway; /** * Handle messages from registry control plane * @param data - Message data as string * @param serverId - Optional server ID for multi-connect tracking */ private handleRegistryMessage; /** * Handle inference request forwarded from Gateway Type 1 */ private handleForwardedInferenceRequest; /** * Forward request to provider API (non-streaming) */ private forwardToProvider; /** * Forward streaming request to provider */ private forwardToProviderStreaming; /** * Get provider-specific headers */ private getProviderHeaders; /** * Generic HTTP request forwarder * Type 3 is ONLY a forwarder - it makes HTTP calls and returns RAW responses * Type 1 does all business logic, translation, and storage * * Message format: * { * event: 'http_request', * requestId: 'uuid', * connection_id: 'uuid', * method: 'GET' | 'POST' | etc, * url: 'http://localhost:11434/api/tags', * headers: { ... }, * body: { ... } (optional) * } */ private handleHttpRequest; /** * Send message to a specific server connection * Falls back to registryWs if serverId not found or not connected * @param serverId - The server ID to send to * @param message - The message object to send * @returns true if message was sent, false otherwise */ private sendToServer; /** * Send health status to all connected servers (multi-connect) */ private sendHealthStatus; /** * Determine health status */ private determineHealthStatus; /** * Report rate limits */ private reportRateLimits; /** * Start health monitoring * Checks connection every 30s and triggers proper reconnection if disconnected */ private startHealthMonitoring; /** * Start API key renewal monitoring * Checks every 30 minutes if the API key is expiring within 1 hour * and automatically renews it */ private startKeyRenewalMonitoring; /** * Check if API key needs renewal and renew if necessary */ private checkAndRenewApiKey; /** * Fetch API key info from Type 1 gateway * This gets the current expiration time for the API key */ private fetchApiKeyInfo; /** * Renew the API key by calling the renew-key endpoint * This extends the expiration time without reissuing a new key */ private renewApiKey; /** * Handle registry disconnection with robust retry logic * This method schedules reconnection attempts with exponential backoff * and ensures registerGateway() is always called after successful reconnection */ private handleRegistryDisconnection; /** * Get CPU usage */ private getCpuUsage; /** * Detect if running inside a container (Docker, Podman, Kubernetes, etc.) * Container-based gateways cannot auto-update via npm - they require image updates */ private detectContainerEnvironment; /** * Detect how the gateway is running * Returns: 'docker', 'systemd', 'service', or 'standalone' */ private detectRunMode; /** * Detect Docker image name if running in container * Returns image name or null if not in container/can't detect */ private detectDockerImage; /** * Get test URL for provider * Uses /v1/models endpoint for OpenAI-compatible providers */ private getTestUrl; /** * Handle session start request from Type 1 */ private handleSessionStart; /** * Handle session message from Type 1 * Auto-restores sessions that are no longer in memory */ private handleSessionMessage; /** * Internal method to process session messages with streaming * @param modelId - Optional model ID to use for this specific message (overrides session default) */ private processSessionMessageInternal; /** * Handle session cancel request from Type 1 */ private handleSessionCancel; /** * Handle tool discovery request from Type 1 */ private handleGetTools; /** * Send session error to Type 1 */ private sendSessionError; /** * Send inference error response to Type 1 */ private sendErrorResponse; /** * Handle execute_script request from Type 1 * Executes a remote server script via SSH * * SECURITY: This handler includes fixes for: * - #1: No hardcoded encryption key fallback * - #2/#3: Parameter name/value validation and shell escaping * - #4: Working directory path validation */ private handleExecuteScript; /** * Send script execution error to Type 1 */ private sendScriptError; /** * Handle update_available notification from Type 1 * Stores update info and optionally triggers automatic update * Auto-updates if either: * 1. mandatory=true (forced update by admin) * 2. autoUpdate=true (user preference from database) */ private handleUpdateAvailable; /** * Handle update_now command from Type 1 * Forces immediate update regardless of current version */ private handleUpdateNow; /** * Perform self-update by installing the new package and restarting * Cross-platform support for Windows and Linux */ private performSelfUpdate; /** * Compare semantic versions * Returns true if newVersion is newer than currentVersion */ private isNewerVersion; /** * Graceful shutdown */ gracefulShutdown(): Promise; } //# sourceMappingURL=gateway-server.d.ts.map