import { Event } from "../../../../base/common/event.js"; import { IDisposable } from "../../../../base/common/lifecycle.js"; import type { AgentHostClientConnectionKind, AgentHostTransportKind } from "../agentHostTelemetry.js"; import type { ProtocolMessage, AhpServerNotification, JsonRpcNotification, JsonRpcParseErrorResponse, JsonRpcResponse, JsonRpcRequest } from "./sessionProtocol.js"; import type { AuthenticateParams } from "../agent.js"; /** Preserve the original JSON size; reserialization can change escaping and whitespace. */ export declare function parseProtocolMessage(text: string): ProtocolMessage; export declare function getProtocolMessageSize(message: object): number; /** Machine-readable reasons a transport cannot be reconnected. */ export declare enum AgentHostTransportFailureReason { Unknown = "unknown", HostNotRunning = "hostNotRunning" } /** Signals that reconnecting the transport cannot recover the connection. */ export declare class NonReconnectableTransportError extends Error { readonly reason: AgentHostTransportFailureReason; constructor(message: string, reason?: AgentHostTransportFailureReason); } export interface ITransportCloseDetails { readonly code?: number; readonly reason?: string; readonly wasClean?: boolean; } /** * A bidirectional transport for protocol messages. Implementations handle * serialization, framing, and connection management. */ export interface IProtocolTransport extends IDisposable { /** Bytes queued in the underlying transport, when available. */ readonly bufferedAmount?: number; /** Trusted lane identity assigned by a relay server, never supplied by AHP. */ readonly relayClientId?: string; /** Trusted read-only designation assigned by a relay server. */ readonly relayPassive?: boolean; readonly relayHandshakeMeta?: Record; /** Owner-validated identity for the current relay handshake, independent of transport access. */ readonly relayAuthentication?: { readonly authenticated: boolean; readonly resource: string; readonly owner?: string; }; /** Captures the current credential lifetime for checks after awaited work. */ relayCaptureAuthorization?(): () => void; readonly onDidRelayAuthenticationExpire?: Event; relayAuthenticate?(params: AuthenticateParams): Promise; /** Diagnostic metadata can arrive after onClose has already reported a transport failure. */ readonly onDidCloseDetails?: Event; /** Physical transport accepted by the agent host. */ readonly transportKind?: AgentHostTransportKind; /** Route used by a VS Code client to reach the agent host. */ readonly clientConnectionKind?: AgentHostClientConnectionKind; /** Fires when a message is received from the remote end. */ readonly onMessage: Event; /** * Fires, possibly throttled, while part of a message is still arriving, so * liveness checks don't mistake a slow download for silence. Omitted by * transports that only see whole messages. */ readonly onDidReceiveData?: Event; /** Fires when the transport connection closes. */ readonly onClose: Event; /** * Send a message to the remote end. * * Accepts: * - `ProtocolMessage` — fully-typed client↔server messages. * - `AhpServerNotification` — server→client notifications. * - `JsonRpcResponse` — dynamically-constructed success/error responses. */ send(message: ProtocolMessage | AhpServerNotification | JsonRpcNotification | JsonRpcParseErrorResponse | JsonRpcResponse | JsonRpcRequest): void; } /** * A client-side transport that requires an explicit connection step * before messages can be exchanged. */ export interface IClientTransport extends IProtocolTransport { /** Establish the underlying connection (e.g. open a WebSocket). */ connect(): Promise; } /** Type guard for transports that require an explicit connection step. */ export declare function isClientTransport(transport: IProtocolTransport): transport is IClientTransport; /** * Server-side transport that accepts multiple client connections. * Each connected client gets its own {@link IProtocolTransport}. */ export interface IProtocolServer extends IDisposable { /** Fires when a new client connects. */ readonly onConnection: Event; /** The port or address the server is listening on. */ readonly address: string | undefined; }