import { Event } from "../../../base/common/event.js"; import { Disposable, IDisposable } from "../../../base/common/lifecycle.js"; import { type ConnectionDiagnosticObserver } from "./connectionDiagnostics.js"; import { type ITunnelConnectResult, type ITunnelGatewaySelection, type ITunnelGatewaySelectionSession, type ITunnelInfo, type ITunnelRelayMessage } from "./tunnelAgentHost.js"; import type { ITunnelDuplexStream, ITunnelMessageSocket } from "./tunnelMessageSocket.js"; /** * Per-step timeout for dev-tunnel relay and socket operations. */ export declare const TUNNEL_STEP_TIMEOUT_MS = 30000; /** * A minimal tunnel descriptor that is independent of the dev-tunnels SDK. */ export interface ITunnelDescriptor { readonly tunnelId?: string; readonly clusterId?: string; readonly name?: string; readonly labels?: readonly string[]; readonly status?: { readonly hostConnectionCount?: number | { readonly current?: number; }; }; } /** * The relay client used to connect a resolved dev tunnel to its agent-host port. */ export interface ITunnelRelayClient extends IDisposable { connect(): Promise; waitForForwardedPort(port: number): Promise; connectToForwardedPort(port: number): Promise; } /** * A resolved tunnel and its configured relay client. */ export interface ITunnelRelayClientSession { readonly tunnel: ITunnelDescriptor; createRelayClient(): Promise; } /** * Resolves a dev tunnel before its relay client is created. */ export interface ITunnelRelayClientFactory { getTunnel(tunnelId: string, clusterId: string, authProvider: "github" | "microsoft", token: string): Promise; } /** * Opens a message socket over a tunnel relay stream. */ export interface ITunnelSocketFactory { open(stream: ITunnelDuplexStream, path: string): Promise; } /** * Logging methods required by the connector. */ export interface ITunnelAgentHostConnectorLogService { info(message: string): void; warn(message: string): void; } /** * Runs an operation with a named deadline. */ export declare function withTimeout(op: () => Promise, timeoutMs: number, stepName: string): Promise; /** * Derives the tunnel connection token used by the CLI and desktop clients. */ export declare function deriveConnectionToken(tunnelId: string): Promise; /** * Maps a dev-tunnels descriptor to the tunnel information shared with clients. */ export declare function parseTunnelInfo(tunnel: ITunnelDescriptor): ITunnelInfo | undefined; /** * A gateway selection that owns its socket and relay until completed or cancelled. */ export declare class PendingGatewaySelection implements IDisposable { readonly address: string; readonly name: string; readonly connectionToken: string; readonly socket: ITunnelMessageSocket; readonly relayClient: ITunnelRelayClient; private readonly _onUnexpectedClose; readonly onDiagnostic?: ConnectionDiagnosticObserver | undefined; private _disposed; private readonly _onSocketClosedListener; constructor(address: string, name: string, connectionToken: string, socket: ITunnelMessageSocket, relayClient: ITunnelRelayClient, _onUnexpectedClose: () => void, onDiagnostic?: ConnectionDiagnosticObserver | undefined); /** Transfers socket ownership to an active connection. */ detach(): void; dispose(): void; } /** * Coordinates dev-tunnel relay connection and gateway selection over injected transports. */ export declare class TunnelAgentHostConnector extends Disposable { private readonly _relayClientFactory; private readonly _socketFactory; private readonly _logService; private readonly _onDidRelayMessage; readonly onDidRelayMessage: Event; private readonly _onDidRelayActivity; /** Fires with a connection ID while that relay receives part of a message. */ readonly onDidRelayActivity: Event; private readonly _onDidRelayClose; readonly onDidRelayClose: Event; private readonly _connections; private readonly _pendingSelections; constructor(_relayClientFactory: ITunnelRelayClientFactory, _socketFactory: ITunnelSocketFactory, _logService: ITunnelAgentHostConnectorLogService); connect(token: string, authProvider: "github" | "microsoft", tunnelId: string, clusterId: string, onDiagnostic?: ConnectionDiagnosticObserver): Promise; prepareSelection(token: string, authProvider: "github" | "microsoft", tunnelId: string, clusterId: string, onDiagnostic?: ConnectionDiagnosticObserver): Promise; completeSelection(selectionId: string, selection: ITunnelGatewaySelection): Promise; cancelSelection(selectionId: string): Promise; relaySend(connectionId: string, message: string): Promise; disconnect(connectionId: string): Promise; closeTunnelConnections(tunnelId: string, operation: "deleting" | "reconnecting"): void; /** Registers a pending selection without creating a relay for unit tests. */ setPendingGatewaySelectionForTests(selectionId: string, pending: PendingGatewaySelection): void; /** Removes and disposes a pending selection for unit tests. */ deletePendingGatewaySelectionForTests(selectionId: string): void; private _createConnection; private _readNextGatewayMessage; private _disposeSocket; private _disposeRelayClient; }