import { Event } from "../../../base/common/event.js"; import { IDisposable } from "../../../base/common/lifecycle.js"; import type { IObservable } from "../../../base/common/observable.js"; import type { OperatingSystem } from "../../../base/common/platform.js"; import { ConfigurationTarget } from "../../configuration/common/configuration.js"; import { type IConfigurationService } from "../../configuration/common/configuration.service.js"; import { type IStorageService } from "../../storage/common/storage.service.js"; import type { IAgentConnection } from "./agentService.js"; import { AgentHostTransportFailureReason } from "./state/sessionTransport.js"; import { type IVscodeUpgradeResult } from "./state/protocolUpgrade.js"; import { type IRemoteAgentHostReconnectPolicy } from "./reconnectPolicy.js"; import type { SSHAgentHostLifecycle } from "./sshRemoteAgentHost.js"; import type { AgentHostServerType } from "./agentHostEndpointRegistry.js"; import type { IDevContainerRepository } from "./devContainerSamples.js"; import type { ConnectionDiagnosticObserver, IConnectionDiagnosticEvent, IRemoteConnectionDiagnosticEvent } from "./connectionDiagnostics.js"; import { IRemoteAgentHostService } from "./remoteAgentHostService.service.js"; /** * Connection status for a remote agent host. * * Discriminated by `kind`. The `incompatible` variant carries the rejection * message returned by the host (typically when its protocol version is not * compatible with anything the client offered) so the UI can surface it. */ export type RemoteAgentHostConnectionStatus = { readonly kind: "connected"; } | { readonly kind: "connecting"; } /** * The transport dropped and the protocol client is re-establishing it itself, * preserving session state. Distinct from `connecting` (initial dial) and * `disconnected` (no connection, nothing in flight). */ | { readonly kind: "reconnecting"; /** When the next automatic attempt fires, if one is scheduled. Absent while an attempt is in flight. */ readonly nextAttemptAt?: number; } | { readonly kind: "disconnected"; readonly reason: AgentHostTransportFailureReason; } | { readonly kind: "incompatible"; /** Human-readable reason from the host (or a synthesised one when the host did not send one). */ readonly message: string; /** Protocol versions the client offered. */ readonly supportedByClient: readonly string[]; /** Protocol versions the server reported it can speak, if available. */ readonly offeredByServer?: readonly string[]; /** * JSON-RPC method the server has advertised via `_meta` that the * client may invoke to ask the hosting CLI to upgrade the server. * Set only when the server was spawned by a VS Code CLI willing * to receive upgrade signals. */ readonly vscodeUpgradeMethod?: string; }; export declare namespace RemoteAgentHostConnectionStatus { /** Singleton "connected" status. */ const connected: RemoteAgentHostConnectionStatus; /** Singleton "connecting" status. */ const connecting: RemoteAgentHostConnectionStatus; /** Singleton "reconnecting" status. */ const reconnecting: RemoteAgentHostConnectionStatus; /** Build a reconnecting status carrying its backoff deadline. */ function reconnectingUntil(nextAttemptAt: number | undefined): RemoteAgentHostConnectionStatus; /** Singleton "disconnected" status. */ const disconnected: RemoteAgentHostConnectionStatus; /** Build a disconnected status with a machine-readable reason. */ function disconnectedBecause(reason: AgentHostTransportFailureReason): RemoteAgentHostConnectionStatus; /** Build an "incompatible" status from a host-supplied message and the versions involved. */ function incompatible(message: string, supportedByClient: readonly string[], offeredByServer?: readonly string[], vscodeUpgradeMethod?: string): RemoteAgentHostConnectionStatus; /** Whether the connection is fully established and ready for traffic. */ function isConnected(status: RemoteAgentHostConnectionStatus | undefined): boolean; /** Whether the connection is mid-handshake. */ function isConnecting(status: RemoteAgentHostConnectionStatus | undefined): boolean; /** Whether the protocol client is restoring a dropped transport. */ function isReconnecting(status: RemoteAgentHostConnectionStatus | undefined): boolean; /** Whether the connection is in the plain disconnected state. */ function isDisconnected(status: RemoteAgentHostConnectionStatus | undefined): boolean; /** Whether the connection rejected our protocol version. */ function isIncompatible(status: RemoteAgentHostConnectionStatus | undefined): status is RemoteAgentHostConnectionStatus & { kind: "incompatible"; }; /** Whether the connection is anything except `connected`. */ function isUnavailable(status: RemoteAgentHostConnectionStatus | undefined): boolean; /** * If `err` is a protocol-version mismatch reported by an agent host * during the `initialize` handshake, returns an `incompatible` status * carrying the host's message. Returns `undefined` otherwise so callers * can fall back to their existing failure handling. */ function fromConnectError(err: unknown, supportedByClient: readonly string[]): RemoteAgentHostConnectionStatus | undefined; } /** Configuration key for the list of WebSocket remote agent host addresses. */ export declare const RemoteAgentHostsSettingId = "chat.remoteAgentHosts"; /** * Configuration key for the WebSocket remote agent hosts an editor window connects to * while its workspace is open. Editor windows use it instead of {@link RemoteAgentHostsSettingId}, * which belongs to the Agents window. Only honored in trusted workspaces. */ export declare const WorkspaceRemoteAgentHostsSettingId = "chat.workspaceRemoteAgentHosts"; /** Configuration key to enable remote agent host connections. */ export declare const RemoteAgentHostsEnabledSettingId = "chat.remoteAgentHostsEnabled"; /** Configuration key that controls whether online dev tunnels, configured SSH remote agent hosts, and WSL remote agent hosts are auto-connected at startup. */ export declare const RemoteAgentHostAutoConnectSettingId = "chat.remoteAgentHostsAutoConnect"; export declare enum RemoteAgentHostEntryType { WebSocket = "websocket", SSH = "ssh", WSL = "wsl", Tunnel = "tunnel", CloudSandbox = "cloudSandbox", DevContainer = "devContainer" } export interface IRemoteAgentHostWebSocketConnection { readonly type: RemoteAgentHostEntryType.WebSocket; readonly address: string; } export interface IRemoteAgentHostSSHConnection { readonly type: RemoteAgentHostEntryType.SSH; /** * The WebSocket address used by the agent host protocol client to * communicate with the remote agent host process. This is typically a * forwarded local port (e.g. `localhost:4321`) established by the SSH * tunnel — it is NOT the SSH hostname itself. */ readonly address: string; /** * SSH config host alias (e.g. `myserver`). When set, the SSH tunnel is * automatically re-established on startup using the user's SSH config. * This takes precedence over {@link hostName} when constructing the * VS Code Remote SSH authority. */ readonly sshConfigHost?: string; /** * The actual SSH hostname or IP address of the remote machine * (e.g. `myserver.example.com`). This is the host that the SSH * client connects to, and is used to construct the VS Code Remote * SSH authority when {@link sshConfigHost} is not available. */ readonly hostName: string; /** SSH username for the remote machine. */ readonly user?: string; /** SSH port on the remote machine (default 22). */ readonly port?: number; /** Server type selected for the most recent SSH connection. */ readonly serverType?: AgentHostServerType; /** Registry instance id selected for the most recent SSH connection. */ readonly instanceId?: string; /** Whether the most recently selected SSH connection was primary. */ readonly primary?: boolean; /** Ownership of the remote agent host selected for the most recent SSH connection. */ readonly lifecycle?: SSHAgentHostLifecycle; } export interface IRemoteAgentHostTunnelConnection { readonly type: RemoteAgentHostEntryType.Tunnel; /** Dev tunnel ID. */ readonly tunnelId: string; /** Dev tunnel cluster region. */ readonly clusterId: string; /** * User-defined display name for this tunnel (derived from tunnel tags). * Used as the tunnel name in the VS Code Remote Tunnels authority * (e.g. `tunnel+