Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/agentHost/common/state/sessionTransport.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
// Transport abstraction for the sessions process protocol.
7
// See protocol.md -> Client-server protocol for the full design.
8
//
9
// The transport is pluggable — the same protocol runs over MessagePort
10
// (ProxyChannel), WebSocket, or stdio. This module defines the contract;
11
// concrete implementations live in platform-specific folders.
12
13
import { Event } from '../../../../base/common/event.js';
14
import { IDisposable } from '../../../../base/common/lifecycle.js';
15
import type { ProtocolMessage, AhpServerNotification, JsonRpcNotification, JsonRpcResponse, JsonRpcRequest } from './sessionProtocol.js';
16
17
/**
18
* A bidirectional transport for protocol messages. Implementations handle
19
* serialization, framing, and connection management.
20
*/
21
export interface IProtocolTransport extends IDisposable {
22
/** Fires when a message is received from the remote end. */
23
readonly onMessage: Event<ProtocolMessage>;
24
25
/** Fires when the transport connection closes. */
26
readonly onClose: Event<void>;
27
28
/**
29
* Send a message to the remote end.
30
*
31
* Accepts:
32
* - `ProtocolMessage` — fully-typed client↔server messages.
33
* - `AhpServerNotification` — server→client notifications.
34
* - `JsonRpcResponse` — dynamically-constructed success/error responses.
35
*/
36
send(message: ProtocolMessage | AhpServerNotification | JsonRpcNotification | JsonRpcResponse | JsonRpcRequest): void;
37
}
38
39
/**
40
* A client-side transport that requires an explicit connection step
41
* before messages can be exchanged.
42
*/
43
export interface IClientTransport extends IProtocolTransport {
44
/** Establish the underlying connection (e.g. open a WebSocket). */
45
connect(): Promise<void>;
46
}
47
48
/** Type guard for transports that require an explicit connection step. */
49
export function isClientTransport(transport: IProtocolTransport): transport is IClientTransport {
50
return typeof (transport as IClientTransport).connect === 'function';
51
}
52
53
/**
54
* Server-side transport that accepts multiple client connections.
55
* Each connected client gets its own {@link IProtocolTransport}.
56
*/
57
export interface IProtocolServer extends IDisposable {
58
/** Fires when a new client connects. */
59
readonly onConnection: Event<IProtocolTransport>;
60
61
/** The port or address the server is listening on. */
62
readonly address: string | undefined;
63
}
64
65