Path: blob/main/src/vs/platform/agentHost/common/state/sessionProtocol.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45// Protocol messages using JSON-RPC 2.0 framing for the sessions process.6// See protocol.md for the full design.7//8// Most types are re-exported from the auto-generated protocol layer.9// This file adds VS Code-specific additions (ISetAuthTokenParams, ProtocolError)10// and backward-compatible aliases.1112// ---- Re-exports from protocol -----------------------------------------------1314// JSON-RPC base types15export type {16JsonRpcErrorResponse,17JsonRpcNotification,18JsonRpcRequest,19JsonRpcResponse,20JsonRpcSuccessResponse,21} from './protocol/messages.js';2223// Typed message unions24export type {25AhpClientNotification,26AhpNotification,27AhpRequest,28AhpResponse,29AhpServerNotification,30AhpSuccessResponse,31CommandMap,32ClientNotificationMap,33NotificationMap,34NotificationMethodParams,35ProtocolMessage,36ServerNotificationMap,37} from './protocol/messages.js';3839// Command params and results40export type {41CreateSessionParams,42DirectoryEntry,43DispatchActionParams,44DisposeSessionParams,45FetchTurnsParams,46FetchTurnsResult,47InitializeParams,48InitializeResult,49ListSessionsParams,50ListSessionsResult,51ReconnectParams,52ReconnectReplayResult,53ReconnectResult,54ReconnectSnapshotResult,55ResourceCopyParams,56ResourceCopyResult,57ResourceDeleteParams,58ResourceDeleteResult,59ResourceListParams,60ResourceListResult,61ResourceMoveParams,62ResourceMoveResult,63ResourceReadParams,64ResourceReadResult,65ResourceWriteParams,66ResourceWriteResult,67SubscribeParams,68UnsubscribeParams,69} from './protocol/commands.js';7071export { ContentEncoding, ReconnectResultType } from './protocol/commands.js';7273// Error codes74export { AhpErrorCodes, JsonRpcErrorCodes } from './protocol/errors.js';75export type { AhpErrorCode, JsonRpcErrorCode } from './protocol/errors.js';7677// Snapshot type (re-exported from state)78export type { Snapshot as IStateSnapshot } from './protocol/state.js';7980// ---- Backward-compatible error code aliases ---------------------------------8182export const JSON_RPC_PARSE_ERROR = -32700 as const;83export const JSON_RPC_INTERNAL_ERROR = -32603 as const;84export const AHP_SESSION_NOT_FOUND = -32001 as const;85export const AHP_PROVIDER_NOT_FOUND = -32002 as const;86export const AHP_SESSION_ALREADY_EXISTS = -32003 as const;87export const AHP_TURN_IN_PROGRESS = -32004 as const;88export const AHP_UNSUPPORTED_PROTOCOL_VERSION = -32005 as const;89export const AHP_CONTENT_NOT_FOUND = -32006 as const;90export const AHP_AUTH_REQUIRED = -32007 as const;9192// ---- Type guards -----------------------------------------------------------9394import type { AhpRequest, AhpNotification, AhpSuccessResponse, ProtocolMessage, JsonRpcErrorResponse } from './protocol/messages.js';9596export function isJsonRpcRequest(msg: ProtocolMessage): msg is AhpRequest {97return 'method' in msg && 'id' in msg;98}99100export function isJsonRpcNotification(msg: ProtocolMessage): msg is AhpNotification {101return 'method' in msg && !('id' in msg);102}103104export function isJsonRpcResponse(msg: ProtocolMessage): msg is AhpSuccessResponse | JsonRpcErrorResponse {105return 'id' in msg && !('method' in msg);106}107108// ---- VS Code-specific types ------------------------------------------------109110/**111* Error with a JSON-RPC error code for protocol-level failures.112* Optionally carries a `data` payload for structured error details.113*/114export class ProtocolError extends Error {115constructor(readonly code: number, message: string, readonly data?: unknown) {116super(message);117}118}119120/**121* VS Code-specific extension: set the auth token on the server.122* Not yet part of the official protocol.123*/124export interface ISetAuthTokenParams {125readonly token: string;126}127128// ---- Server → Client notification param aliases (backward compat) -----------129130import type { INotification } from './sessionActions.js';131132export interface INotificationBroadcastParams {133readonly notification: INotification;134}135136137