/** * Vibe MCP Server - Relay Connection * * Connects to the relay server as a WebSocket client. * Supports two modes: * - Local: connects to local relay daemon at ws://127.0.0.1:19888 * - Remote: connects to public relay at wss://relay.api.vibebrowser.app/ */ import { EventEmitter } from 'events'; import { ConnectionStatus, RelaySessionSummary, ToolDefinition, ToolResult } from './types.js'; export declare const DEFAULT_RELAY_HANDSHAKE_TIMEOUT_MS = 10000; export declare const REDACTED_REMOTE_ID = "[redacted]"; /** * Remote relay configuration. * * The routing UUID (in the wss URL path) is the sole bearer capability for * relay access. Treat it like a password: if it leaks, regenerate it in the * Vibe extension Settings. There is no second-factor secret/attach token. */ export interface RemoteConfig { uuid: string; relayUrl?: string; } export interface ParsedRemoteRelayUrl { relayUrl: string; uuid: string; } export interface RelayCloseInfo { code: number; reason: string; permanent: boolean; } export declare function isPermanentRelayCloseCode(code: number): boolean; export declare function isPermanentRelayHttpStatus(statusCode: number): boolean; export declare function redactRemoteTarget(message: string, target?: string): string; export declare function parseRemoteRelayUrl(value: string): ParsedRemoteRelayUrl; /** * Parse the canonical HTTPS MCP connector URL exposed in the extension UI: * https://host[/prefix]/mcp/ -> relayUrl wss://host[/prefix] * http://[/prefix]/mcp/ -> relayUrl ws://[/prefix] * * Error messages intentionally never echo the input value or the UUID, since * this value is a bearer credential. */ export declare function parseHttpMcpConnectorUrl(value: string): ParsedRemoteRelayUrl; export declare function parseRemoteTarget(value: string, currentRelayUrl?: string): ParsedRemoteRelayUrl; export declare function normalizeRemoteConfig(remote?: RemoteConfig): RemoteConfig | undefined; export interface LocalSessionConfig { sessionId?: string; } /** * Relay connection manager * * Connects to a relay server (local or remote) to reach the extension. */ export declare class ExtensionConnection extends EventEmitter { private readonly reconnectDelayMs; private ws; private status; private pendingRequests; private requestIdCounter; private port; private debug; private tools; private sessions; private reconnectTimer; private extensionConnected; private remoteConfig; private localSessionConfig; private stopping; private connectionGeneration; private lifecycleEpoch; private shutdownEpoch; private startPromise; private remoteUpdate; private reconnectSuppressed; private lastClose; private readonly handshakeTimeoutMs; constructor(port?: number, debug?: boolean, remote?: RemoteConfig, localSessionConfig?: LocalSessionConfig, handshakeTimeoutMs?: number, reconnectDelayMs?: number); /** * Start connection to relay server. * In local mode: spawns relay daemon if needed, then connects. * In remote mode: connects directly to public relay. */ start(): Promise; setRemoteUrl(url: string): Promise; /** * Spawn relay daemon as detached process (local mode only) */ private spawnRelay; /** * Wait for local relay to become available */ private waitForRelay; /** * Get the WebSocket URL for connection. * Local mode: ws://127.0.0.1: * Remote mode: wss://relay.api.vibebrowser.app/ */ private getRelayUrl; getRemoteConfig(): RemoteConfig | null; getLastClose(): RelayCloseInfo | null; /** * Connect to the relay server (local or remote) */ private connectToRelay; /** * Schedule reconnection attempt */ private scheduleReconnect; /** * Stop the connection */ stop(): Promise; private clearReconnectTimer; private rejectPendingRequests; private closeSocket; private clearExtensionState; /** * Handle message from relay */ private handleMessage; /** * Send a message to the extension via relay and wait for response */ private sendRequest; private withSessionSelection; private resolveRequestedSessionId; private getRequestedSessionConnectionError; getConnectionErrorMessage(): string; /** * Refresh available tools from extension */ refreshTools(timeoutMs?: number): Promise; listSessions(timeoutMs?: number): Promise; /** * Wait briefly for a tools update event without forcing a request. * This keeps MCP startup responsive when extension announces tools asynchronously. */ waitForToolsUpdate(timeoutMs?: number): Promise; /** * Get cached list of available tools */ getTools(): ToolDefinition[]; getSessions(): RelaySessionSummary[]; /** * Call a tool on the extension */ callTool(name: string, args: Record, timeoutMs?: number): Promise; /** * Check if extension is connected (via relay) */ isConnected(): boolean; /** * Get connection status */ getStatus(): ConnectionStatus; /** * Check if extension is connected to relay */ isExtensionConnected(): boolean; /** * Log message if debug is enabled */ private log; private redactRemoteCredential; private redactErrorToolResult; private redactUnknownStrings; redactErrorMessage(message: string): string; private formatCloseMessage; } //# sourceMappingURL=connection.d.ts.map