src/vs/platform/agentHost/common/state/protocolUpgrade.ts
108 LOC · 94 covered · 14 uncovered · 1 ranges · 171 concepts · 1 introducers · 77 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
protocolServerHandler.ts ×78
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { UnsupportedProtocolVersionErrorData } from './protocol/errors.js';
import type { Mutable } from '../../../../base/common/types.js';
/**
* Name of the JSON-RPC method that, when invoked on an agent host spawned
* by the VS Code CLI, asks the CLI to check for a server upgrade and
* restart the running server if a newer build is available.
*
* Servers advertise this method through {@link UnsupportedProtocolVersionErrorMeta.vscodeUpgradeMethod}
* in the `_meta` payload of an `UnsupportedProtocolVersion` error so the
* client can offer an "Update server" action without hard-coding the method
* name on the renderer side.
*/
export const VSCODE_UPGRADE_METHOD = '_vscodeUpgrade' as const;
/**
* Status payload returned by the {@link VSCODE_UPGRADE_METHOD} RPC. The
* agent host server forwards the CLI's `POST /upgrade` response back to
* the client unchanged, so the UI can describe what happened (e.g.
* "already on the latest version" vs "upgrade scheduled, please reconnect").
*/
export interface IVscodeUpgradeResult {
/** Whether the CLI accepted the request without an internal error. */
readonly ok: boolean;
/** Whether the running server is older than the latest known release. */
readonly upgradeNeeded?: boolean;
/**
* Whether the CLI committed to actually performing the upgrade. When
* `true`, the client SHOULD reconnect after at least
* {@link restartDelayMs} milliseconds; the existing transport will be
* torn down by the CLI.
*/
readonly upgradeStarted?: boolean;
/** Commit of the currently running server, or `null` if no server is running. */
readonly runningCommit?: string | null;
/** Latest known release commit at the time of the call. */
readonly latestCommit?: string;
/**
* Milliseconds the client should wait before attempting to reconnect.
* The CLI deliberately delays the kill+restart so this HTTP response
* can drain back through the proxy first; reconnecting immediately
* would land on the still-running pre-upgrade server. Populated only
* when {@link upgradeStarted} is `true`.
*/
readonly restartDelayMs?: number;
/** Human-readable error when {@link ok} is `false`. */
readonly error?: string;
}
/**
* Optional `_meta` side-channel on the `UnsupportedProtocolVersion` error
* data payload. Servers that are spawned by the VS Code CLI populate this
* to let the renderer offer a one-click upgrade flow; servers without a
* managing CLI omit it.
*
* The MCP `_meta` convention is followed: this is an open-ended record so
* future versions can carry additional fields without bumping the wire
* shape of the error.
*/
export interface UnsupportedProtocolVersionErrorMeta {
/**
* JSON-RPC method name the client MAY invoke on the same transport to
* ask the server to upgrade itself. Currently always {@link VSCODE_UPGRADE_METHOD}.
*/
readonly vscodeUpgradeMethod?: string;
}
/**
* `UnsupportedProtocolVersionErrorData` augmented with the local `_meta`
* extension used by VS Code-hosted agent hosts.
*
* Kept out of the auto-generated `errors.ts` so the synced types stay
* untouched. Read at runtime as a best-effort field — older servers
* simply won't set it.
*/
export interface UnsupportedProtocolVersionErrorDataEx extends UnsupportedProtocolVersionErrorData {
readonly _meta?: UnsupportedProtocolVersionErrorMeta;
}
/**
* Reads the well-known {@link UnsupportedProtocolVersionErrorMeta} from the open
* `_meta` bag on an `UnsupportedProtocolVersion` error's data payload. `data` is
* the raw, untrusted `ProtocolError.data` (typed `unknown`); this validates that
* it carries a `_meta` object with a string {@link
* UnsupportedProtocolVersionErrorMeta.vscodeUpgradeMethod} and returns
* `undefined` otherwise. Always read the upgrade `_meta` through this helper
* rather than casting the error data to a shape that includes `_meta`.
*/
export function readUnsupportedProtocolVersionErrorMeta(data: unknown): UnsupportedProtocolVersionErrorMeta | undefined {
if (!data || typeof data !== 'object') {
return undefined;
}
const meta = (data as Record<string, unknown>)['_meta'];
if (!meta || typeof meta !== 'object' || Array.isArray(meta)) {
return undefined;
}
const raw = meta as Record<string, unknown>;
const result: Mutable<UnsupportedProtocolVersionErrorMeta> = {};
if (typeof raw['vscodeUpgradeMethod'] === 'string') {
result.vscodeUpgradeMethod = raw['vscodeUpgradeMethod'];
}
return Object.keys(result).length > 0 ? result : undefined;
}