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.

1 > /*--------------------------------------------------------------------------------------------- protocolServerHandler.ts ×78
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 > import type { UnsupportedProtocolVersionErrorData } from './protocol/errors.js';
7 > import type { Mutable } from '../../../../base/common/types.js';
8 >
9 > /**
10 > * Name of the JSON-RPC method that, when invoked on an agent host spawned
11 > * by the VS Code CLI, asks the CLI to check for a server upgrade and
12 > * restart the running server if a newer build is available.
13 > *
14 > * Servers advertise this method through {@link UnsupportedProtocolVersionErrorMeta.vscodeUpgradeMethod}
15 > * in the `_meta` payload of an `UnsupportedProtocolVersion` error so the
16 > * client can offer an "Update server" action without hard-coding the method
17 > * name on the renderer side.
18 > */
19 > export const VSCODE_UPGRADE_METHOD = '_vscodeUpgrade' as const;
20 >
21 > /**
22 > * Status payload returned by the {@link VSCODE_UPGRADE_METHOD} RPC. The
23 > * agent host server forwards the CLI's `POST /upgrade` response back to
24 > * the client unchanged, so the UI can describe what happened (e.g.
25 > * "already on the latest version" vs "upgrade scheduled, please reconnect").
26 > */
27 > export interface IVscodeUpgradeResult {
28 > /** Whether the CLI accepted the request without an internal error. */
29 > readonly ok: boolean;
30 > /** Whether the running server is older than the latest known release. */
31 > readonly upgradeNeeded?: boolean;
32 > /**
33 > * Whether the CLI committed to actually performing the upgrade. When
34 > * `true`, the client SHOULD reconnect after at least
35 > * {@link restartDelayMs} milliseconds; the existing transport will be
36 > * torn down by the CLI.
37 > */
38 > readonly upgradeStarted?: boolean;
39 > /** Commit of the currently running server, or `null` if no server is running. */
40 > readonly runningCommit?: string | null;
41 > /** Latest known release commit at the time of the call. */
42 > readonly latestCommit?: string;
43 > /**
44 > * Milliseconds the client should wait before attempting to reconnect.
45 > * The CLI deliberately delays the kill+restart so this HTTP response
46 > * can drain back through the proxy first; reconnecting immediately
47 > * would land on the still-running pre-upgrade server. Populated only
48 > * when {@link upgradeStarted} is `true`.
49 > */
50 > readonly restartDelayMs?: number;
51 > /** Human-readable error when {@link ok} is `false`. */
52 > readonly error?: string;
53 > }
54 >
55 > /**
56 > * Optional `_meta` side-channel on the `UnsupportedProtocolVersion` error
57 > * data payload. Servers that are spawned by the VS Code CLI populate this
58 > * to let the renderer offer a one-click upgrade flow; servers without a
59 > * managing CLI omit it.
60 > *
61 > * The MCP `_meta` convention is followed: this is an open-ended record so
62 > * future versions can carry additional fields without bumping the wire
63 > * shape of the error.
64 > */
65 > export interface UnsupportedProtocolVersionErrorMeta {
66 > /**
67 > * JSON-RPC method name the client MAY invoke on the same transport to
68 > * ask the server to upgrade itself. Currently always {@link VSCODE_UPGRADE_METHOD}.
69 > */
70 > readonly vscodeUpgradeMethod?: string;
71 > }
72 >
73 > /**
74 > * `UnsupportedProtocolVersionErrorData` augmented with the local `_meta`
75 > * extension used by VS Code-hosted agent hosts.
76 > *
77 > * Kept out of the auto-generated `errors.ts` so the synced types stay
78 > * untouched. Read at runtime as a best-effort field — older servers
79 > * simply won't set it.
80 > */
81 > export interface UnsupportedProtocolVersionErrorDataEx extends UnsupportedProtocolVersionErrorData {
82 > readonly _meta?: UnsupportedProtocolVersionErrorMeta;
83 > }
84 >
85 > /**
86 > * Reads the well-known {@link UnsupportedProtocolVersionErrorMeta} from the open
87 > * `_meta` bag on an `UnsupportedProtocolVersion` error's data payload. `data` is
88 > * the raw, untrusted `ProtocolError.data` (typed `unknown`); this validates that
89 > * it carries a `_meta` object with a string {@link
90 > * UnsupportedProtocolVersionErrorMeta.vscodeUpgradeMethod} and returns
91 > * `undefined` otherwise. Always read the upgrade `_meta` through this helper
92 > * rather than casting the error data to a shape that includes `_meta`.
93 > */
94 > export function readUnsupportedProtocolVersionErrorMeta(data: unknown): UnsupportedProtocolVersionErrorMeta | undefined {
95 if (!data || typeof data !== 'object') {
96 return undefined;
97 }
98 const meta = (data as Record<string, unknown>)['_meta'];
99 if (!meta || typeof meta !== 'object' || Array.isArray(meta)) {
100 return undefined;
101 }
102 const raw = meta as Record<string, unknown>;
103 const result: Mutable<UnsupportedProtocolVersionErrorMeta> = {};
104 if (typeof raw['vscodeUpgradeMethod'] === 'string') {
105 result.vscodeUpgradeMethod = raw['vscodeUpgradeMethod'];
106 }
107 return Object.keys(result).length > 0 ? result : undefined;
108 }