166
167
constructor(
169
>
private readonly _options: IAgentSideEffectsOptions,
170
>
@IInstantiationService instantiationService: IInstantiationService,
171
>
@ILogService private readonly _logService: ILogService,
172
>
@IAgentHostChangesetService private readonly _changesets: IAgentHostChangesetService,
173
>
@ITelemetryService private readonly _telemetryService: ITelemetryService,
174
>
@IAgentHostCheckpointService private readonly _checkpointService: IAgentHostCheckpointService,
175
>
) {
176
>
super();
177
>
this._telemetryReporter = new AgentHostTelemetryReporter(this._telemetryService);
178
>
this._turnTracker = new AgentHostTurnTracker(this._telemetryReporter);
179
>
this._toolCallTracker = this._register(new AgentHostToolCallTracker(this._telemetryReporter));
180
>
this._permissionManager = this._register(instantiationService.createInstance(SessionPermissionManager, this._stateManager, {}));
181
>
this._localCommands = this._register(instantiationService.createInstance(
182
>
AgentHostLocalCommands,
183
>
this._stateManager,
184
>
this._options.localTurns,
185
>
// Draining the queue re-enters agent lookup / telemetry / sendMessage,
186
>
// which is this class's responsibility, so the dispatcher hands the
187
>
// turn back here once it has completed a host-handled command.
188
>
(turnChannel: ProtocolURI) => this._tryConsumeNextQueuedMessage(turnChannel),
189
>
));
190
>
this._titleController = this._register(instantiationService.createInstance(AgentHostSessionTitleController, this._stateManager, {
191
>
sessionDataService: this._options.sessionDataService,
192
>
getGitHubCopilotToken: this._options.getGitHubCopilotToken,
193
>
copilotApiService: this._options.copilotApiService,
194
>
}));
195
>
196
>
// Whenever the agents observable changes, publish to root state.
197
>
this._register(autorun(reader => {
198
>
const agents = this._options.agents.read(reader);
199
>
this._publishAgentInfos(agents, reader);
200
>
}));
201
>
202
>
// Server-dispatched ChatToolCallComplete actions (e.g. from
203
>
// the disconnect timeout in ProtocolServerHandler) bypass
204
>
// handleAction, so the agent's SDK deferred never resolves.
205
>
// Listen for these envelopes and notify the agent directly.
206
>
this._register(this._stateManager.onDidEmitEnvelope(envelope => {
207
if (isAhpChatChannel(envelope.channel) && isChatAction(envelope.action)) {
208
if (envelope.action.type === ActionType.ChatTurnCancelled) {