Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/agentHost/common/state/sessionProtocol.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
// Protocol messages using JSON-RPC 2.0 framing for the sessions process.
7
// See protocol.md for the full design.
8
//
9
// Most types are re-exported from the auto-generated protocol layer.
10
// This file adds VS Code-specific additions (ISetAuthTokenParams, ProtocolError)
11
// and backward-compatible aliases.
12
13
// ---- Re-exports from protocol -----------------------------------------------
14
15
// JSON-RPC base types
16
export type {
17
JsonRpcErrorResponse,
18
JsonRpcNotification,
19
JsonRpcRequest,
20
JsonRpcResponse,
21
JsonRpcSuccessResponse,
22
} from './protocol/messages.js';
23
24
// Typed message unions
25
export type {
26
AhpClientNotification,
27
AhpNotification,
28
AhpRequest,
29
AhpResponse,
30
AhpServerNotification,
31
AhpSuccessResponse,
32
CommandMap,
33
ClientNotificationMap,
34
NotificationMap,
35
NotificationMethodParams,
36
ProtocolMessage,
37
ServerNotificationMap,
38
} from './protocol/messages.js';
39
40
// Command params and results
41
export type {
42
CreateSessionParams,
43
DirectoryEntry,
44
DispatchActionParams,
45
DisposeSessionParams,
46
FetchTurnsParams,
47
FetchTurnsResult,
48
InitializeParams,
49
InitializeResult,
50
ListSessionsParams,
51
ListSessionsResult,
52
ReconnectParams,
53
ReconnectReplayResult,
54
ReconnectResult,
55
ReconnectSnapshotResult,
56
ResourceCopyParams,
57
ResourceCopyResult,
58
ResourceDeleteParams,
59
ResourceDeleteResult,
60
ResourceListParams,
61
ResourceListResult,
62
ResourceMoveParams,
63
ResourceMoveResult,
64
ResourceReadParams,
65
ResourceReadResult,
66
ResourceWriteParams,
67
ResourceWriteResult,
68
SubscribeParams,
69
UnsubscribeParams,
70
} from './protocol/commands.js';
71
72
export { ContentEncoding, ReconnectResultType } from './protocol/commands.js';
73
74
// Error codes
75
export { AhpErrorCodes, JsonRpcErrorCodes } from './protocol/errors.js';
76
export type { AhpErrorCode, JsonRpcErrorCode } from './protocol/errors.js';
77
78
// Snapshot type (re-exported from state)
79
export type { Snapshot as IStateSnapshot } from './protocol/state.js';
80
81
// ---- Backward-compatible error code aliases ---------------------------------
82
83
export const JSON_RPC_PARSE_ERROR = -32700 as const;
84
export const JSON_RPC_INTERNAL_ERROR = -32603 as const;
85
export const AHP_SESSION_NOT_FOUND = -32001 as const;
86
export const AHP_PROVIDER_NOT_FOUND = -32002 as const;
87
export const AHP_SESSION_ALREADY_EXISTS = -32003 as const;
88
export const AHP_TURN_IN_PROGRESS = -32004 as const;
89
export const AHP_UNSUPPORTED_PROTOCOL_VERSION = -32005 as const;
90
export const AHP_CONTENT_NOT_FOUND = -32006 as const;
91
export const AHP_AUTH_REQUIRED = -32007 as const;
92
93
// ---- Type guards -----------------------------------------------------------
94
95
import type { AhpRequest, AhpNotification, AhpSuccessResponse, ProtocolMessage, JsonRpcErrorResponse } from './protocol/messages.js';
96
97
export function isJsonRpcRequest(msg: ProtocolMessage): msg is AhpRequest {
98
return 'method' in msg && 'id' in msg;
99
}
100
101
export function isJsonRpcNotification(msg: ProtocolMessage): msg is AhpNotification {
102
return 'method' in msg && !('id' in msg);
103
}
104
105
export function isJsonRpcResponse(msg: ProtocolMessage): msg is AhpSuccessResponse | JsonRpcErrorResponse {
106
return 'id' in msg && !('method' in msg);
107
}
108
109
// ---- VS Code-specific types ------------------------------------------------
110
111
/**
112
* Error with a JSON-RPC error code for protocol-level failures.
113
* Optionally carries a `data` payload for structured error details.
114
*/
115
export class ProtocolError extends Error {
116
constructor(readonly code: number, message: string, readonly data?: unknown) {
117
super(message);
118
}
119
}
120
121
/**
122
* VS Code-specific extension: set the auth token on the server.
123
* Not yet part of the official protocol.
124
*/
125
export interface ISetAuthTokenParams {
126
readonly token: string;
127
}
128
129
// ---- Server → Client notification param aliases (backward compat) -----------
130
131
import type { INotification } from './sessionActions.js';
132
133
export interface INotificationBroadcastParams {
134
readonly notification: INotification;
135
}
136
137