src/vs/platform/agentHost/node/copilot/copilotSessionWrapper.ts

285 LOC · 285 covered · 0 uncovered · 104 ranges · 903 concepts · 6 introducers · 421 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 > /*--------------------------------------------------------------------------------------------- copilotSessionWrapper.ts ×51
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 { CopilotSession, SessionEvent, SessionEventPayload, SessionEventType } from '@github/copilot-sdk';
7 > import { Emitter, Event } from '../../../../base/common/event.js';
8 > import { Disposable, toDisposable } from '../../../../base/common/lifecycle.js';
9 >
10 > /**
11 > * Thin wrapper around {@link CopilotSession} that exposes each SDK event as a
12 > * proper VS Code `Event<T>`. All subscriptions and the underlying SDK session
13 > * are cleaned up on dispose.
14 > */
15 > export class CopilotSessionWrapper extends Disposable {
16 >
17 > private readonly _handledEventTypes = new Set<SessionEventType>();
18 > private readonly _onUnhandledEvent = this._register(new Emitter<SessionEvent>());
19 > readonly onUnhandledEvent = this._onUnhandledEvent.event;
20 >
21 > constructor(readonly session: CopilotSession) {
23 > const unsubscribeAll = session.on(event => {
24 > if (!this._handledEventTypes.has(event.type)) { copilotSessionWrapper.ts ×1
25 > this._onUnhandledEvent.fire(event); copilotSessionWrapper.ts ×1
26 > }
28 > this._register(toDisposable(unsubscribeAll));
29 > this._register(toDisposable(() => {
30 > session.disconnect().catch(() => { /* best-effort */ });
31 > }));
32 > }
34 > get sessionId(): string { return this.session.sessionId; }
35 >
36 > private _onMessageDelta: Event<SessionEventPayload<'assistant.message_delta'>> | undefined;
37 > get onMessageDelta(): Event<SessionEventPayload<'assistant.message_delta'>> {
38 > return this._onMessageDelta ??= this._sdkEvent('assistant.message_delta'); copilotAgentSession.ts ×67
39 > }
41 > private _onMessage: Event<SessionEventPayload<'assistant.message'>> | undefined;
42 > get onMessage(): Event<SessionEventPayload<'assistant.message'>> {
43 > return this._onMessage ??= this._sdkEvent('assistant.message'); copilotAgentSession.ts ×67
44 > }
46 > private _onToolStart: Event<SessionEventPayload<'tool.execution_start'>> | undefined;
47 > get onToolStart(): Event<SessionEventPayload<'tool.execution_start'>> {
48 > return this._onToolStart ??= this._sdkEvent('tool.execution_start'); copilotAgentSession.ts ×67
49 > }
51 > private _onToolComplete: Event<SessionEventPayload<'tool.execution_complete'>> | undefined;
52 > get onToolComplete(): Event<SessionEventPayload<'tool.execution_complete'>> {
53 > return this._onToolComplete ??= this._sdkEvent('tool.execution_complete'); copilotAgentSession.ts ×67
54 > }
56 > private _onPermissionRequested: Event<SessionEventPayload<'permission.requested'>> | undefined;
57 > get onPermissionRequested(): Event<SessionEventPayload<'permission.requested'>> {
58 > return this._onPermissionRequested ??= this._sdkEvent('permission.requested'); copilotAgentSession.ts ×67
59 > }
61 > private _onIdle: Event<SessionEventPayload<'session.idle'>> | undefined;
62 > get onIdle(): Event<SessionEventPayload<'session.idle'>> {
63 > return this._onIdle ??= this._sdkEvent('session.idle'); copilotAgentSession.ts ×67
64 > }
66 > private _onSessionStart: Event<SessionEventPayload<'session.start'>> | undefined;
67 > get onSessionStart(): Event<SessionEventPayload<'session.start'>> {
68 > return this._onSessionStart ??= this._sdkEvent('session.start'); copilotAgentSession.ts ×67
69 > }
71 > private _onSessionResume: Event<SessionEventPayload<'session.resume'>> | undefined;
72 > get onSessionResume(): Event<SessionEventPayload<'session.resume'>> {
73 > return this._onSessionResume ??= this._sdkEvent('session.resume'); copilotAgentSession.ts ×67
74 > }
76 > private _onSessionError: Event<SessionEventPayload<'session.error'>> | undefined;
77 > get onSessionError(): Event<SessionEventPayload<'session.error'>> {
78 > return this._onSessionError ??= this._sdkEvent('session.error'); copilotAgentSession.ts ×67
79 > }
81 > private _onSessionInfo: Event<SessionEventPayload<'session.info'>> | undefined;
82 > get onSessionInfo(): Event<SessionEventPayload<'session.info'>> {
83 > return this._onSessionInfo ??= this._sdkEvent('session.info'); copilotAgentSession.ts ×67
84 > }
86 > private _onSessionWarning: Event<SessionEventPayload<'session.warning'>> | undefined;
87 > get onSessionWarning(): Event<SessionEventPayload<'session.warning'>> {
88 > return this._onSessionWarning ??= this._sdkEvent('session.warning'); copilotAgentSession.ts ×67
89 > }
91 > private _onSessionModelChange: Event<SessionEventPayload<'session.model_change'>> | undefined;
92 > get onSessionModelChange(): Event<SessionEventPayload<'session.model_change'>> {
93 > return this._onSessionModelChange ??= this._sdkEvent('session.model_change'); copilotAgentSession.ts ×67
94 > }
96 > private _onAutoModeResolved: Event<SessionEventPayload<'session.auto_mode_resolved'>> | undefined;
97 > get onAutoModeResolved(): Event<SessionEventPayload<'session.auto_mode_resolved'>> {
98 > return this._onAutoModeResolved ??= this._sdkEvent('session.auto_mode_resolved'); copilotAgentSession.ts ×67
99 > }
101 > private _onManagedSettingsResolved: Event<SessionEventPayload<'session.managed_settings_resolved'>> | undefined;
102 > get onManagedSettingsResolved(): Event<SessionEventPayload<'session.managed_settings_resolved'>> {
103 > return this._onManagedSettingsResolved ??= this._sdkEvent('session.managed_settings_resolved'); copilotAgentSession.ts ×67
104 > }
106 > private _onManagedSettingsEnforced: Event<SessionEventPayload<'session.managed_settings_enforced'>> | undefined;
107 > get onManagedSettingsEnforced(): Event<SessionEventPayload<'session.managed_settings_enforced'>> {
108 > return this._onManagedSettingsEnforced ??= this._sdkEvent('session.managed_settings_enforced'); copilotAgentSession.ts ×67
109 > }
111 > private _onSessionHandoff: Event<SessionEventPayload<'session.handoff'>> | undefined;
112 > get onSessionHandoff(): Event<SessionEventPayload<'session.handoff'>> {
113 > return this._onSessionHandoff ??= this._sdkEvent('session.handoff'); copilotAgentSession.ts ×67
114 > }
116 > private _onSessionTruncation: Event<SessionEventPayload<'session.truncation'>> | undefined;
117 > get onSessionTruncation(): Event<SessionEventPayload<'session.truncation'>> {
118 > return this._onSessionTruncation ??= this._sdkEvent('session.truncation'); copilotAgentSession.ts ×67
119 > }
121 > private _onSessionSnapshotRewind: Event<SessionEventPayload<'session.snapshot_rewind'>> | undefined;
122 > get onSessionSnapshotRewind(): Event<SessionEventPayload<'session.snapshot_rewind'>> {
123 > return this._onSessionSnapshotRewind ??= this._sdkEvent('session.snapshot_rewind'); copilotAgentSession.ts ×67
124 > }
126 > private _onSessionShutdown: Event<SessionEventPayload<'session.shutdown'>> | undefined;
127 > get onSessionShutdown(): Event<SessionEventPayload<'session.shutdown'>> {
128 > return this._onSessionShutdown ??= this._sdkEvent('session.shutdown'); copilotAgentSession.ts ×67
129 > }
131 > private _onSessionUsageInfo: Event<SessionEventPayload<'session.usage_info'>> | undefined;
132 > get onSessionUsageInfo(): Event<SessionEventPayload<'session.usage_info'>> {
133 > return this._onSessionUsageInfo ??= this._sdkEvent('session.usage_info'); copilotAgentSession.ts ×67
134 > }
136 > private _onSessionCompactionStart: Event<SessionEventPayload<'session.compaction_start'>> | undefined;
137 > get onSessionCompactionStart(): Event<SessionEventPayload<'session.compaction_start'>> {
138 > return this._onSessionCompactionStart ??= this._sdkEvent('session.compaction_start'); copilotSessionWrapper.ts ×2
139 > }
141 > private _onSessionCompactionComplete: Event<SessionEventPayload<'session.compaction_complete'>> | undefined;
142 > get onSessionCompactionComplete(): Event<SessionEventPayload<'session.compaction_complete'>> {
143 > return this._onSessionCompactionComplete ??= this._sdkEvent('session.compaction_complete'); copilotAgentSession.ts ×67
144 > }
146 > private _onUserMessage: Event<SessionEventPayload<'user.message'>> | undefined;
147 > get onUserMessage(): Event<SessionEventPayload<'user.message'>> {
148 > return this._onUserMessage ??= this._sdkEvent('user.message'); copilotAgentSession.ts ×67
149 > }
151 > private _onPendingMessagesModified: Event<SessionEventPayload<'pending_messages.modified'>> | undefined;
152 > get onPendingMessagesModified(): Event<SessionEventPayload<'pending_messages.modified'>> {
153 > return this._onPendingMessagesModified ??= this._sdkEvent('pending_messages.modified'); copilotAgentSession.ts ×67
154 > }
156 > private _onTurnStart: Event<SessionEventPayload<'assistant.turn_start'>> | undefined;
157 > get onTurnStart(): Event<SessionEventPayload<'assistant.turn_start'>> {
158 > return this._onTurnStart ??= this._sdkEvent('assistant.turn_start'); copilotAgentSession.ts ×67
159 > }
161 > private _onIntent: Event<SessionEventPayload<'assistant.intent'>> | undefined;
162 > get onIntent(): Event<SessionEventPayload<'assistant.intent'>> {
163 > return this._onIntent ??= this._sdkEvent('assistant.intent'); copilotAgentSession.ts ×67
164 > }
166 > private _onReasoning: Event<SessionEventPayload<'assistant.reasoning'>> | undefined;
167 > get onReasoning(): Event<SessionEventPayload<'assistant.reasoning'>> {
168 > return this._onReasoning ??= this._sdkEvent('assistant.reasoning'); copilotAgentSession.ts ×67
169 > }
171 > private _onReasoningDelta: Event<SessionEventPayload<'assistant.reasoning_delta'>> | undefined;
172 > get onReasoningDelta(): Event<SessionEventPayload<'assistant.reasoning_delta'>> {
173 > return this._onReasoningDelta ??= this._sdkEvent('assistant.reasoning_delta'); copilotAgentSession.ts ×67
174 > }
176 > private _onTurnEnd: Event<SessionEventPayload<'assistant.turn_end'>> | undefined;
177 > get onTurnEnd(): Event<SessionEventPayload<'assistant.turn_end'>> {
178 > return this._onTurnEnd ??= this._sdkEvent('assistant.turn_end'); copilotAgentSession.ts ×67
179 > }
181 > private _onUsage: Event<SessionEventPayload<'assistant.usage'>> | undefined;
182 > get onUsage(): Event<SessionEventPayload<'assistant.usage'>> {
183 > return this._onUsage ??= this._sdkEvent('assistant.usage'); copilotAgentSession.ts ×67
184 > }
186 > private _onAbort: Event<SessionEventPayload<'abort'>> | undefined;
187 > get onAbort(): Event<SessionEventPayload<'abort'>> {
188 > return this._onAbort ??= this._sdkEvent('abort'); copilotAgentSession.ts ×67
189 > }
191 > private _onToolUserRequested: Event<SessionEventPayload<'tool.user_requested'>> | undefined;
192 > get onToolUserRequested(): Event<SessionEventPayload<'tool.user_requested'>> {
193 > return this._onToolUserRequested ??= this._sdkEvent('tool.user_requested'); copilotAgentSession.ts ×67
194 > }
196 > private _onToolPartialResult: Event<SessionEventPayload<'tool.execution_partial_result'>> | undefined;
197 > get onToolPartialResult(): Event<SessionEventPayload<'tool.execution_partial_result'>> {
198 > return this._onToolPartialResult ??= this._sdkEvent('tool.execution_partial_result'); copilotAgentSession.ts ×67
199 > }
201 > private _onToolProgress: Event<SessionEventPayload<'tool.execution_progress'>> | undefined;
202 > get onToolProgress(): Event<SessionEventPayload<'tool.execution_progress'>> {
203 > return this._onToolProgress ??= this._sdkEvent('tool.execution_progress'); copilotAgentSession.ts ×67
204 > }
206 > private _onSkillInvoked: Event<SessionEventPayload<'skill.invoked'>> | undefined;
207 > get onSkillInvoked(): Event<SessionEventPayload<'skill.invoked'>> {
208 > return this._onSkillInvoked ??= this._sdkEvent('skill.invoked'); copilotAgentSession.ts ×67
209 > }
211 > private _onSubagentStarted: Event<SessionEventPayload<'subagent.started'>> | undefined;
212 > get onSubagentStarted(): Event<SessionEventPayload<'subagent.started'>> {
213 > return this._onSubagentStarted ??= this._sdkEvent('subagent.started'); copilotAgentSession.ts ×67
214 > }
216 > private _onSubagentCompleted: Event<SessionEventPayload<'subagent.completed'>> | undefined;
217 > get onSubagentCompleted(): Event<SessionEventPayload<'subagent.completed'>> {
218 > return this._onSubagentCompleted ??= this._sdkEvent('subagent.completed'); copilotAgentSession.ts ×67
219 > }
221 > private _onSubagentFailed: Event<SessionEventPayload<'subagent.failed'>> | undefined;
222 > get onSubagentFailed(): Event<SessionEventPayload<'subagent.failed'>> {
223 > return this._onSubagentFailed ??= this._sdkEvent('subagent.failed'); copilotAgentSession.ts ×67
224 > }
226 > private _onSubagentSelected: Event<SessionEventPayload<'subagent.selected'>> | undefined;
227 > get onSubagentSelected(): Event<SessionEventPayload<'subagent.selected'>> {
228 > return this._onSubagentSelected ??= this._sdkEvent('subagent.selected'); copilotAgentSession.ts ×67
229 > }
231 > private _onHookStart: Event<SessionEventPayload<'hook.start'>> | undefined;
232 > get onHookStart(): Event<SessionEventPayload<'hook.start'>> {
233 > return this._onHookStart ??= this._sdkEvent('hook.start'); copilotAgentSession.ts ×67
234 > }
236 > private _onHookEnd: Event<SessionEventPayload<'hook.end'>> | undefined;
237 > get onHookEnd(): Event<SessionEventPayload<'hook.end'>> {
238 > return this._onHookEnd ??= this._sdkEvent('hook.end'); copilotAgentSession.ts ×67
239 > }
241 > private _onSystemMessage: Event<SessionEventPayload<'system.message'>> | undefined;
242 > get onSystemMessage(): Event<SessionEventPayload<'system.message'>> {
243 > return this._onSystemMessage ??= this._sdkEvent('system.message'); copilotAgentSession.ts ×67
244 > }
246 > private _onSystemNotification: Event<SessionEventPayload<'system.notification'>> | undefined;
247 > get onSystemNotification(): Event<SessionEventPayload<'system.notification'>> {
248 > return this._onSystemNotification ??= this._sdkEvent('system.notification'); copilotAgentSession.ts ×67
249 > }
251 > private _onSessionModeChanged: Event<SessionEventPayload<'session.mode_changed'>> | undefined;
252 > get onSessionModeChanged(): Event<SessionEventPayload<'session.mode_changed'>> {
253 > return this._onSessionModeChanged ??= this._sdkEvent('session.mode_changed'); copilotAgentSession.ts ×67
254 > }
256 > private _onMcpServersLoaded: Event<SessionEventPayload<'session.mcp_servers_loaded'>> | undefined;
257 > get onMcpServersLoaded(): Event<SessionEventPayload<'session.mcp_servers_loaded'>> {
258 > return this._onMcpServersLoaded ??= this._sdkEvent('session.mcp_servers_loaded'); copilotAgentSession.ts ×67
259 > }
261 > private _onMcpServerStatusChanged: Event<SessionEventPayload<'session.mcp_server_status_changed'>> | undefined;
262 > get onMcpServerStatusChanged(): Event<SessionEventPayload<'session.mcp_server_status_changed'>> {
263 > return this._onMcpServerStatusChanged ??= this._sdkEvent('session.mcp_server_status_changed'); copilotAgentSession.ts ×67
264 > }
266 > private _onToolsUpdated: Event<SessionEventPayload<'session.tools_updated'>> | undefined;
267 > get onToolsUpdated(): Event<SessionEventPayload<'session.tools_updated'>> {
268 > return this._onToolsUpdated ??= this._sdkEvent('session.tools_updated'); copilotAgentSession.ts ×67
269 > }
271 > private _onCommandsChanged: Event<SessionEventPayload<'commands.changed'>> | undefined;
272 > get onCommandsChanged(): Event<SessionEventPayload<'commands.changed'>> {
273 > return this._onCommandsChanged ??= this._sdkEvent('commands.changed'); copilotAgentSession.ts ×67
274 > }
276 > private _sdkEvent<K extends SessionEventType>(eventType: K): Event<SessionEventPayload<K>> {
277 > const emitter = this._register(new Emitter<SessionEventPayload<K>>({ copilotSessionWrapper.ts ×2
278 > onDidAddFirstListener: () => this._handledEventTypes.add(eventType),
279 > onDidRemoveLastListener: () => this._handledEventTypes.delete(eventType),
280 > }));
281 > const unsubscribe = this.session.on(eventType, (data: SessionEventPayload<K>) => emitter.fire(data));
282 > this._register(toDisposable(unsubscribe));
283 > return emitter.event;
284 > }