@codingame/monaco-vscode-chat-service-override 5.3.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chat.js +5 -7
- package/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +160 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +17 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +15 -13
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +215 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +1 -9
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +6 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +15 -93
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +27 -106
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +5 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +6 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipantContributions.js +95 -51
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.js +94 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +64 -8
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +2 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatContextAttachments.js +50 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputCompletions.js +370 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +19 -366
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +122 -63
- package/vscode/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.js +12 -5
- package/vscode/src/vs/workbench/contrib/chat/common/languageModelStats.js +6 -5
- package/vscode/src/vs/workbench/contrib/chat/common/{voiceChat.js → voiceChatService.js} +58 -21
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +15 -14
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +33 -32
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +6 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables.js +0 -26
- package/vscode/src/vs/workbench/contrib/chat/common/languageModels.js +0 -50
- package/vscode/src/vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl.js +0 -33
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
-
import {
|
|
2
|
+
import { coalesce } from 'vscode/vscode/vs/base/common/arrays';
|
|
3
|
+
import { DeferredPromise } from 'vscode/vscode/vs/base/common/async';
|
|
3
4
|
import { CancellationToken, CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
|
|
5
|
+
import { toErrorMessage } from 'vscode/vscode/vs/base/common/errorMessage';
|
|
4
6
|
import { ErrorNoTelemetry } from 'vscode/vscode/vs/base/common/errors';
|
|
5
7
|
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
6
8
|
import { MarkdownString } from 'vscode/vscode/vs/base/common/htmlContent';
|
|
@@ -11,25 +13,23 @@ import { StopWatch } from 'vscode/vscode/vs/base/common/stopwatch';
|
|
|
11
13
|
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
12
14
|
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
13
15
|
import { CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
|
|
14
|
-
import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands.service';
|
|
15
16
|
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
16
17
|
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
|
|
17
|
-
import 'vscode/vscode/vs/platform/notification/common/notification';
|
|
18
|
-
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification.service';
|
|
19
18
|
import { Progress } from 'vscode/vscode/vs/platform/progress/common/progress';
|
|
19
|
+
import { StorageScope, StorageTarget } from 'vscode/vscode/vs/platform/storage/common/storage';
|
|
20
20
|
import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
|
|
21
21
|
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
|
|
22
22
|
import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace.service';
|
|
23
23
|
import { ChatAgentLocation } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
24
24
|
import { IChatAgentService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents.service';
|
|
25
|
-
import { ChatModel, ChatWelcomeMessageModel, getHistoryEntriesFromModel, updateRanges } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatModel';
|
|
26
|
-
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, getPromptText } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParserTypes';
|
|
25
|
+
import { ChatModel, ChatWelcomeMessageModel, ChatRequestRemovalReason, getHistoryEntriesFromModel, updateRanges, ChatRequestModel } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatModel';
|
|
26
|
+
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, chatSubcommandLeader, chatAgentLeader, ChatRequestSlashCommandPart, getPromptText } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParserTypes';
|
|
27
27
|
import { ChatRequestParser } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatRequestParser';
|
|
28
|
-
import {
|
|
28
|
+
import { ChatAgentVoteDirection, ChatCopyKind } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService';
|
|
29
29
|
import { IChatSlashCommandService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatSlashCommands.service';
|
|
30
30
|
import { IChatVariablesService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatVariables.service';
|
|
31
|
+
import { ChatMessageRole } from 'vscode/vscode/vs/workbench/contrib/chat/common/languageModels';
|
|
31
32
|
import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions.service';
|
|
32
|
-
import Severity$1 from 'vscode/vscode/vs/base/common/severity';
|
|
33
33
|
|
|
34
34
|
const _moduleId = "vs/workbench/contrib/chat/common/chatServiceImpl";
|
|
35
35
|
const serializedChatKey = 'interactive.sessions';
|
|
@@ -40,7 +40,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
40
40
|
get transferredSessionData() {
|
|
41
41
|
return this._transferredSessionData;
|
|
42
42
|
}
|
|
43
|
-
constructor(storageService, logService, extensionService, instantiationService, telemetryService, workspaceContextService, chatSlashCommandService, chatVariablesService, chatAgentService
|
|
43
|
+
constructor(storageService, logService, extensionService, instantiationService, telemetryService, workspaceContextService, chatSlashCommandService, chatVariablesService, chatAgentService) {
|
|
44
44
|
super();
|
|
45
45
|
this.storageService = storageService;
|
|
46
46
|
this.logService = logService;
|
|
@@ -51,8 +51,6 @@ let ChatService = class ChatService extends Disposable {
|
|
|
51
51
|
this.chatSlashCommandService = chatSlashCommandService;
|
|
52
52
|
this.chatVariablesService = chatVariablesService;
|
|
53
53
|
this.chatAgentService = chatAgentService;
|
|
54
|
-
this.notificationService = notificationService;
|
|
55
|
-
this.commandService = commandService;
|
|
56
54
|
this._sessionModels = this._register(( (new DisposableMap())));
|
|
57
55
|
this._pendingRequests = this._register(( (new DisposableMap())));
|
|
58
56
|
this._onDidPerformUserAction = this._register(( (new Emitter())));
|
|
@@ -60,7 +58,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
60
58
|
this._onDidDisposeSession = this._register(( (new Emitter())));
|
|
61
59
|
this.onDidDisposeSession = this._onDidDisposeSession.event;
|
|
62
60
|
this._sessionFollowupCancelTokens = this._register(( (new DisposableMap())));
|
|
63
|
-
const sessionData = storageService.get(serializedChatKey,
|
|
61
|
+
const sessionData = storageService.get(serializedChatKey, StorageScope.WORKSPACE, '');
|
|
64
62
|
if (sessionData) {
|
|
65
63
|
this._persistedSessions = this.deserializeChats(sessionData);
|
|
66
64
|
const countsForLog = ( (Object.keys(this._persistedSessions))).length;
|
|
@@ -99,29 +97,33 @@ let ChatService = class ChatService extends Disposable {
|
|
|
99
97
|
if (allSessions.length) {
|
|
100
98
|
this.trace('onWillSaveState', `Persisting ${serialized.length} chars`);
|
|
101
99
|
}
|
|
102
|
-
this.storageService.store(serializedChatKey, serialized,
|
|
100
|
+
this.storageService.store(serializedChatKey, serialized, StorageScope.WORKSPACE, StorageTarget.MACHINE);
|
|
103
101
|
}
|
|
104
102
|
notifyUserAction(action) {
|
|
105
103
|
if (action.action.kind === 'vote') {
|
|
106
104
|
this.telemetryService.publicLog2('interactiveSessionVote', {
|
|
107
|
-
direction: action.action.direction ===
|
|
105
|
+
direction: action.action.direction === ChatAgentVoteDirection.Up ? 'up' : 'down',
|
|
106
|
+
agentId: action.agentId ?? ''
|
|
108
107
|
});
|
|
109
108
|
}
|
|
110
109
|
else if (action.action.kind === 'copy') {
|
|
111
110
|
this.telemetryService.publicLog2('interactiveSessionCopy', {
|
|
112
|
-
copyKind: action.action.copyKind === ChatCopyKind.Action ? 'action' : 'toolbar'
|
|
111
|
+
copyKind: action.action.copyKind === ChatCopyKind.Action ? 'action' : 'toolbar',
|
|
112
|
+
agentId: action.agentId ?? ''
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
else if (action.action.kind === 'insert') {
|
|
116
116
|
this.telemetryService.publicLog2('interactiveSessionInsert', {
|
|
117
|
-
newFile: !!action.action.newFile
|
|
117
|
+
newFile: !!action.action.newFile,
|
|
118
|
+
agentId: action.agentId ?? ''
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
121
|
else if (action.action.kind === 'command') {
|
|
121
122
|
const command = CommandsRegistry.getCommand(action.action.commandButton.command.id);
|
|
122
123
|
const commandId = command ? action.action.commandButton.command.id : 'INVALID';
|
|
123
124
|
this.telemetryService.publicLog2('interactiveSessionCommand', {
|
|
124
|
-
commandId
|
|
125
|
+
commandId,
|
|
126
|
+
agentId: action.agentId ?? ''
|
|
125
127
|
});
|
|
126
128
|
}
|
|
127
129
|
else if (action.action.kind === 'runInTerminal') {
|
|
@@ -175,7 +177,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
179
|
getTransferredSessionData() {
|
|
178
|
-
const data = this.storageService.getObject(globalChatKey,
|
|
180
|
+
const data = this.storageService.getObject(globalChatKey, StorageScope.PROFILE, []);
|
|
179
181
|
const workspaceUri = this.workspaceContextService.getWorkspace().folders[0]?.uri;
|
|
180
182
|
if (!workspaceUri) {
|
|
181
183
|
return;
|
|
@@ -184,7 +186,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
184
186
|
const currentTime = Date.now();
|
|
185
187
|
const transferred = data.find(item => ( (URI.revive(item.toWorkspace).toString())) === thisWorkspace && (currentTime - item.timestampInMilliseconds < SESSION_TRANSFER_EXPIRATION_IN_MILLISECONDS));
|
|
186
188
|
const filtered = data.filter(item => ( (URI.revive(item.toWorkspace).toString())) !== thisWorkspace && (currentTime - item.timestampInMilliseconds < SESSION_TRANSFER_EXPIRATION_IN_MILLISECONDS));
|
|
187
|
-
this.storageService.store(globalChatKey, JSON.stringify(filtered),
|
|
189
|
+
this.storageService.store(globalChatKey, JSON.stringify(filtered), StorageScope.PROFILE, StorageTarget.MACHINE);
|
|
188
190
|
return transferred;
|
|
189
191
|
}
|
|
190
192
|
getHistory() {
|
|
@@ -234,21 +236,6 @@ let ChatService = class ChatService extends Disposable {
|
|
|
234
236
|
await this.extensionService.activateByEvent(`onChatParticipant:${defaultAgentData.id}`);
|
|
235
237
|
const defaultAgent = this.chatAgentService.getActivatedAgents().find(agent => agent.id === defaultAgentData.id);
|
|
236
238
|
if (!defaultAgent) {
|
|
237
|
-
this.notificationService.notify({
|
|
238
|
-
severity: Severity$1.Error,
|
|
239
|
-
message: ( localizeWithPath(
|
|
240
|
-
_moduleId,
|
|
241
|
-
0,
|
|
242
|
-
"Chat failed to load. Please ensure that the GitHub Copilot Chat extension is up to date."
|
|
243
|
-
)),
|
|
244
|
-
actions: {
|
|
245
|
-
primary: [
|
|
246
|
-
( (new Action('showExtension', ( localizeWithPath(_moduleId, 1, "Show Extension")), undefined, true, () => {
|
|
247
|
-
return this.commandService.executeCommand('workbench.extensions.action.showExtensionsWithIds', ['GitHub.copilot-chat']);
|
|
248
|
-
})))
|
|
249
|
-
]
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
239
|
throw ( (new ErrorNoTelemetry('No default agent registered')));
|
|
253
240
|
}
|
|
254
241
|
const welcomeMessage = model.welcomeMessage ? undefined : (await defaultAgent.provideWelcomeMessage?.(model.initialLocation, token)) ?? undefined;
|
|
@@ -273,7 +260,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
273
260
|
if (model) {
|
|
274
261
|
return model;
|
|
275
262
|
}
|
|
276
|
-
const sessionData = this._persistedSessions[sessionId];
|
|
263
|
+
const sessionData = revive(this._persistedSessions[sessionId]);
|
|
277
264
|
if (!sessionData) {
|
|
278
265
|
return undefined;
|
|
279
266
|
}
|
|
@@ -291,17 +278,17 @@ let ChatService = class ChatService extends Disposable {
|
|
|
291
278
|
throw ( (new Error(`Unknown session: ${request.session.sessionId}`)));
|
|
292
279
|
}
|
|
293
280
|
await model.waitForInitialization();
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
281
|
+
const cts = this._pendingRequests.get(request.session.sessionId);
|
|
282
|
+
if (cts) {
|
|
283
|
+
this.trace('resendRequest', `Session ${request.session.sessionId} already has a pending request, cancelling...`);
|
|
284
|
+
cts.cancel();
|
|
297
285
|
}
|
|
298
286
|
const location = options?.location ?? model.initialLocation;
|
|
299
287
|
const attempt = options?.attempt ?? 0;
|
|
300
288
|
const enableCommandDetection = !options?.noCommandDetection;
|
|
301
|
-
const implicitVariablesEnabled = options?.implicitVariablesEnabled ?? false;
|
|
302
289
|
const defaultAgent = this.chatAgentService.getDefaultAgent(location);
|
|
303
|
-
|
|
304
|
-
await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection,
|
|
290
|
+
model.removeRequest(request.id, ChatRequestRemovalReason.Resend);
|
|
291
|
+
await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, defaultAgent, location, options).responseCompletePromise;
|
|
305
292
|
}
|
|
306
293
|
async sendRequest(sessionId, request, options) {
|
|
307
294
|
this.trace('sendRequest', `sessionId: ${sessionId}, message: ${request.substring(0, 20)}${request.length > 20 ? '[...]' : ''}}`);
|
|
@@ -320,24 +307,37 @@ let ChatService = class ChatService extends Disposable {
|
|
|
320
307
|
}
|
|
321
308
|
const location = options?.location ?? model.initialLocation;
|
|
322
309
|
const attempt = options?.attempt ?? 0;
|
|
323
|
-
const implicitVariablesEnabled = options?.implicitVariablesEnabled ?? false;
|
|
324
310
|
const defaultAgent = this.chatAgentService.getDefaultAgent(location);
|
|
325
|
-
const parsedRequest = this.
|
|
311
|
+
const parsedRequest = this.parseChatRequest(sessionId, request, location, options);
|
|
326
312
|
const agent = parsedRequest.parts.find((r) => r instanceof ChatRequestAgentPart)?.agent ?? defaultAgent;
|
|
327
313
|
const agentSlashCommandPart = parsedRequest.parts.find((r) => r instanceof ChatRequestAgentSubcommandPart);
|
|
328
314
|
return {
|
|
329
|
-
|
|
315
|
+
...this._sendRequestAsync(model, sessionId, parsedRequest, attempt, !options?.noCommandDetection, defaultAgent, location, options),
|
|
330
316
|
agent,
|
|
331
317
|
slashCommand: agentSlashCommandPart?.command,
|
|
332
318
|
};
|
|
333
319
|
}
|
|
320
|
+
parseChatRequest(sessionId, request, location, options) {
|
|
321
|
+
let parserContext = options?.parserContext;
|
|
322
|
+
if (options?.agentId) {
|
|
323
|
+
const agent = this.chatAgentService.getAgent(options.agentId);
|
|
324
|
+
if (!agent) {
|
|
325
|
+
throw ( (new Error(`Unknown agent: ${options.agentId}`)));
|
|
326
|
+
}
|
|
327
|
+
parserContext = { selectedAgent: agent };
|
|
328
|
+
const commandPart = options.slashCommand ? ` ${chatSubcommandLeader}${options.slashCommand}` : '';
|
|
329
|
+
request = `${chatAgentLeader}${agent.name}${commandPart} ${request}`;
|
|
330
|
+
}
|
|
331
|
+
const parsedRequest = this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, request, location, parserContext);
|
|
332
|
+
return parsedRequest;
|
|
333
|
+
}
|
|
334
334
|
refreshFollowupsCancellationToken(sessionId) {
|
|
335
335
|
this._sessionFollowupCancelTokens.get(sessionId)?.cancel();
|
|
336
336
|
const newTokenSource = ( (new CancellationTokenSource()));
|
|
337
337
|
this._sessionFollowupCancelTokens.set(sessionId, newTokenSource);
|
|
338
338
|
return newTokenSource.token;
|
|
339
339
|
}
|
|
340
|
-
|
|
340
|
+
_sendRequestAsync(model, sessionId, parsedRequest, attempt, enableCommandDetection, defaultAgent, location, options) {
|
|
341
341
|
const followupsCancelToken = this.refreshFollowupsCancellationToken(sessionId);
|
|
342
342
|
let request;
|
|
343
343
|
const agentPart = 'kind' in parsedRequest ? undefined : parsedRequest.parts.find((r) => r instanceof ChatRequestAgentPart);
|
|
@@ -345,6 +345,14 @@ let ChatService = class ChatService extends Disposable {
|
|
|
345
345
|
const commandPart = 'kind' in parsedRequest ? undefined : parsedRequest.parts.find((r) => r instanceof ChatRequestSlashCommandPart);
|
|
346
346
|
let gotProgress = false;
|
|
347
347
|
const requestType = commandPart ? 'slashCommand' : 'string';
|
|
348
|
+
const responseCreated = ( (new DeferredPromise()));
|
|
349
|
+
let responseCreatedComplete = false;
|
|
350
|
+
function completeResponseCreated() {
|
|
351
|
+
if (!responseCreatedComplete && request?.response) {
|
|
352
|
+
responseCreated.complete(request.response);
|
|
353
|
+
responseCreatedComplete = true;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
348
356
|
const source = ( (new CancellationTokenSource()));
|
|
349
357
|
const token = source.token;
|
|
350
358
|
const sendRequestInternal = async () => {
|
|
@@ -360,6 +368,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
360
368
|
this.trace('sendRequest', `Provider returned progress: ${JSON.stringify(progress)}`);
|
|
361
369
|
}
|
|
362
370
|
model.acceptResponseProgress(request, progress);
|
|
371
|
+
completeResponseCreated();
|
|
363
372
|
};
|
|
364
373
|
const stopWatch = ( (new StopWatch(false)));
|
|
365
374
|
const listener = token.onCancellationRequested(() => {
|
|
@@ -371,7 +380,8 @@ let ChatService = class ChatService extends Disposable {
|
|
|
371
380
|
requestType,
|
|
372
381
|
agent: agentPart?.agent.id ?? '',
|
|
373
382
|
slashCommand: agentSlashCommandPart ? agentSlashCommandPart.command.name : commandPart?.slashCommand.command,
|
|
374
|
-
chatSessionId: model.sessionId
|
|
383
|
+
chatSessionId: model.sessionId,
|
|
384
|
+
location,
|
|
375
385
|
});
|
|
376
386
|
model.cancelRequest(request);
|
|
377
387
|
});
|
|
@@ -384,17 +394,22 @@ let ChatService = class ChatService extends Disposable {
|
|
|
384
394
|
const history = getHistoryEntriesFromModel(model, agentPart?.agent.id);
|
|
385
395
|
const initVariableData = { variables: [] };
|
|
386
396
|
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command);
|
|
387
|
-
|
|
397
|
+
completeResponseCreated();
|
|
398
|
+
const variableData = await this.chatVariablesService.resolveVariables(parsedRequest, options?.attachedContext, model, progressCallback, token);
|
|
388
399
|
request.variableData = variableData;
|
|
389
400
|
const promptTextResult = getPromptText(request.message);
|
|
390
401
|
const updatedVariableData = updateRanges(variableData, promptTextResult.diff);
|
|
402
|
+
const implicitVariablesEnabled = (location === ChatAgentLocation.Editor || location === ChatAgentLocation.Notebook);
|
|
391
403
|
if (implicitVariablesEnabled) {
|
|
392
404
|
const implicitVariables = agent.defaultImplicitVariables;
|
|
393
405
|
if (implicitVariables) {
|
|
394
|
-
const resolvedImplicitVariables = await Promise.all(( (implicitVariables.map(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
406
|
+
const resolvedImplicitVariables = await Promise.all(( (implicitVariables.map(async (v) => {
|
|
407
|
+
const id = this.chatVariablesService.getVariable(v)?.id ?? '';
|
|
408
|
+
const value = await this.chatVariablesService.resolveVariable(v, parsedRequest.text, model, progressCallback, token);
|
|
409
|
+
return value ? { id, name: v, value } :
|
|
410
|
+
undefined;
|
|
411
|
+
}))));
|
|
412
|
+
updatedVariableData.variables.push(...coalesce(resolvedImplicitVariables));
|
|
398
413
|
}
|
|
399
414
|
}
|
|
400
415
|
const requestProps = {
|
|
@@ -406,7 +421,9 @@ let ChatService = class ChatService extends Disposable {
|
|
|
406
421
|
variables: updatedVariableData,
|
|
407
422
|
enableCommandDetection,
|
|
408
423
|
attempt,
|
|
409
|
-
location
|
|
424
|
+
location,
|
|
425
|
+
acceptedConfirmationData: options?.acceptedConfirmationData,
|
|
426
|
+
rejectedConfirmationData: options?.rejectedConfirmationData,
|
|
410
427
|
};
|
|
411
428
|
const agentResult = await this.chatAgentService.invokeAgent(agent.id, requestProps, progressCallback, history, token);
|
|
412
429
|
rawResult = agentResult;
|
|
@@ -414,13 +431,14 @@ let ChatService = class ChatService extends Disposable {
|
|
|
414
431
|
}
|
|
415
432
|
else if (commandPart && this.chatSlashCommandService.hasCommand(commandPart.slashCommand.command)) {
|
|
416
433
|
request = model.addRequest(parsedRequest, { variables: [] }, attempt);
|
|
434
|
+
completeResponseCreated();
|
|
417
435
|
const history = [];
|
|
418
436
|
for (const request of model.getRequests()) {
|
|
419
437
|
if (!request.response) {
|
|
420
438
|
continue;
|
|
421
439
|
}
|
|
422
|
-
history.push({ role:
|
|
423
|
-
history.push({ role:
|
|
440
|
+
history.push({ role: ChatMessageRole.User, content: request.message.text });
|
|
441
|
+
history.push({ role: ChatMessageRole.Assistant, content: request.response.response.asString() });
|
|
424
442
|
}
|
|
425
443
|
const message = parsedRequest.text;
|
|
426
444
|
const commandResult = await this.chatSlashCommandService.executeCommand(commandPart.slashCommand.command, message.substring(commandPart.slashCommand.command.length + 1).trimStart(), ( (new Progress(p => {
|
|
@@ -438,7 +456,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
438
456
|
else {
|
|
439
457
|
if (!rawResult) {
|
|
440
458
|
this.trace('sendRequest', `Provider returned no response for session ${model.sessionId}`);
|
|
441
|
-
rawResult = { errorDetails: { message: ( localizeWithPath(_moduleId,
|
|
459
|
+
rawResult = { errorDetails: { message: ( localizeWithPath(_moduleId, 0, "Provider returned null response")) } };
|
|
442
460
|
}
|
|
443
461
|
const result = rawResult.errorDetails?.responseIsFiltered ? 'filtered' :
|
|
444
462
|
rawResult.errorDetails && gotProgress ? 'errorWithOutput' :
|
|
@@ -451,9 +469,11 @@ let ChatService = class ChatService extends Disposable {
|
|
|
451
469
|
requestType,
|
|
452
470
|
agent: agentPart?.agent.id ?? '',
|
|
453
471
|
slashCommand: agentSlashCommandPart ? agentSlashCommandPart.command.name : commandPart?.slashCommand.command,
|
|
454
|
-
chatSessionId: model.sessionId
|
|
472
|
+
chatSessionId: model.sessionId,
|
|
473
|
+
location
|
|
455
474
|
});
|
|
456
475
|
model.setResponse(request, rawResult);
|
|
476
|
+
completeResponseCreated();
|
|
457
477
|
this.trace('sendRequest', `Provider returned response for session ${model.sessionId}`);
|
|
458
478
|
model.completeResponse(request);
|
|
459
479
|
if (agentOrCommandFollowups) {
|
|
@@ -463,6 +483,26 @@ let ChatService = class ChatService extends Disposable {
|
|
|
463
483
|
}
|
|
464
484
|
}
|
|
465
485
|
}
|
|
486
|
+
catch (err) {
|
|
487
|
+
const result = 'error';
|
|
488
|
+
this.telemetryService.publicLog2('interactiveSessionProviderInvoked', {
|
|
489
|
+
timeToFirstProgress: undefined,
|
|
490
|
+
totalTime: undefined,
|
|
491
|
+
result,
|
|
492
|
+
requestType,
|
|
493
|
+
agent: agentPart?.agent.id ?? '',
|
|
494
|
+
slashCommand: agentSlashCommandPart ? agentSlashCommandPart.command.name : commandPart?.slashCommand.command,
|
|
495
|
+
chatSessionId: model.sessionId,
|
|
496
|
+
location
|
|
497
|
+
});
|
|
498
|
+
const rawResult = { errorDetails: { message: err.message } };
|
|
499
|
+
if (request) {
|
|
500
|
+
model.setResponse(request, rawResult);
|
|
501
|
+
}
|
|
502
|
+
completeResponseCreated();
|
|
503
|
+
this.logService.error(`Error while handling chat request: ${toErrorMessage(err)}`);
|
|
504
|
+
model.completeResponse(request);
|
|
505
|
+
}
|
|
466
506
|
finally {
|
|
467
507
|
listener.dispose();
|
|
468
508
|
}
|
|
@@ -472,7 +512,10 @@ let ChatService = class ChatService extends Disposable {
|
|
|
472
512
|
rawResponsePromise.finally(() => {
|
|
473
513
|
this._pendingRequests.deleteAndDispose(model.sessionId);
|
|
474
514
|
});
|
|
475
|
-
return
|
|
515
|
+
return {
|
|
516
|
+
responseCreatedPromise: responseCreated.p,
|
|
517
|
+
responseCompletePromise: rawResponsePromise,
|
|
518
|
+
};
|
|
476
519
|
}
|
|
477
520
|
async removeRequest(sessionId, requestId) {
|
|
478
521
|
const model = this._sessionModels.get(sessionId);
|
|
@@ -482,6 +525,24 @@ let ChatService = class ChatService extends Disposable {
|
|
|
482
525
|
await model.waitForInitialization();
|
|
483
526
|
model.removeRequest(requestId);
|
|
484
527
|
}
|
|
528
|
+
async adoptRequest(sessionId, request) {
|
|
529
|
+
if (!(request instanceof ChatRequestModel)) {
|
|
530
|
+
throw ( (new TypeError('Can only adopt requests of type ChatRequestModel')));
|
|
531
|
+
}
|
|
532
|
+
const target = this._sessionModels.get(sessionId);
|
|
533
|
+
if (!target) {
|
|
534
|
+
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
535
|
+
}
|
|
536
|
+
await target.waitForInitialization();
|
|
537
|
+
const oldOwner = request.session;
|
|
538
|
+
target.adoptRequest(request);
|
|
539
|
+
if (request.response && !request.response.isComplete) {
|
|
540
|
+
const cts = this._pendingRequests.deleteAndLeak(oldOwner.sessionId);
|
|
541
|
+
if (cts) {
|
|
542
|
+
this._pendingRequests.set(target.sessionId, cts);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
485
546
|
async addCompleteRequest(sessionId, message, variableData, attempt, response) {
|
|
486
547
|
this.trace('addCompleteRequest', `message: ${message}`);
|
|
487
548
|
const model = this._sessionModels.get(sessionId);
|
|
@@ -519,7 +580,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
519
580
|
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
520
581
|
}
|
|
521
582
|
if (model.initialLocation === ChatAgentLocation.Panel) {
|
|
522
|
-
this._persistedSessions[sessionId] =
|
|
583
|
+
this._persistedSessions[sessionId] = JSON.parse(JSON.stringify(model));
|
|
523
584
|
}
|
|
524
585
|
this._sessionModels.deleteAndDispose(sessionId);
|
|
525
586
|
this._pendingRequests.get(sessionId)?.cancel();
|
|
@@ -536,14 +597,14 @@ let ChatService = class ChatService extends Disposable {
|
|
|
536
597
|
`Failed to transfer session. Unknown session ID: ${transferredSessionData.sessionId}`
|
|
537
598
|
)));
|
|
538
599
|
}
|
|
539
|
-
const existingRaw = this.storageService.getObject(globalChatKey,
|
|
600
|
+
const existingRaw = this.storageService.getObject(globalChatKey, StorageScope.PROFILE, []);
|
|
540
601
|
existingRaw.push({
|
|
541
602
|
chat: model.toJSON(),
|
|
542
603
|
timestampInMilliseconds: Date.now(),
|
|
543
604
|
toWorkspace: toWorkspace,
|
|
544
605
|
inputValue: transferredSessionData.inputValue,
|
|
545
606
|
});
|
|
546
|
-
this.storageService.store(globalChatKey, JSON.stringify(existingRaw),
|
|
607
|
+
this.storageService.store(globalChatKey, JSON.stringify(existingRaw), StorageScope.PROFILE, StorageTarget.MACHINE);
|
|
547
608
|
this.trace('transferChatSession', `Transferred session ${model.sessionId} to workspace ${( (toWorkspace.toString()))}`);
|
|
548
609
|
}
|
|
549
610
|
};
|
|
@@ -556,9 +617,7 @@ ChatService = ( (__decorate([
|
|
|
556
617
|
( (__param(5, IWorkspaceContextService))),
|
|
557
618
|
( (__param(6, IChatSlashCommandService))),
|
|
558
619
|
( (__param(7, IChatVariablesService))),
|
|
559
|
-
( (__param(8, IChatAgentService)))
|
|
560
|
-
( (__param(9, INotificationService))),
|
|
561
|
-
( (__param(10, ICommandService)))
|
|
620
|
+
( (__param(8, IChatAgentService)))
|
|
562
621
|
], ChatService)));
|
|
563
622
|
|
|
564
623
|
export { ChatService };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
2
|
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
3
|
+
import { StorageScope, StorageTarget } from 'vscode/vscode/vs/platform/storage/common/storage';
|
|
3
4
|
import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
|
|
4
5
|
import { Memento } from 'vscode/vscode/vs/workbench/common/memento';
|
|
6
|
+
import { ChatAgentLocation } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
5
7
|
import { CHAT_PROVIDER_ID } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParticipantContribTypes';
|
|
6
8
|
|
|
7
9
|
let ChatWidgetHistoryService = class ChatWidgetHistoryService {
|
|
@@ -9,20 +11,25 @@ let ChatWidgetHistoryService = class ChatWidgetHistoryService {
|
|
|
9
11
|
this._onDidClearHistory = ( new Emitter());
|
|
10
12
|
this.onDidClearHistory = this._onDidClearHistory.event;
|
|
11
13
|
this.memento = ( new Memento('interactive-session', storageService));
|
|
12
|
-
const loadedState = this.memento.getMemento(
|
|
14
|
+
const loadedState = this.memento.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE);
|
|
13
15
|
for (const provider in loadedState.history) {
|
|
14
16
|
loadedState.history[provider] = ( loadedState.history[provider].map(entry => typeof entry === 'string' ? { text: entry } : entry));
|
|
15
17
|
}
|
|
16
18
|
this.viewState = loadedState;
|
|
17
19
|
}
|
|
18
|
-
getHistory() {
|
|
19
|
-
|
|
20
|
+
getHistory(location) {
|
|
21
|
+
const key = this.getKey(location);
|
|
22
|
+
return this.viewState.history?.[key] ?? [];
|
|
20
23
|
}
|
|
21
|
-
|
|
24
|
+
getKey(location) {
|
|
25
|
+
return location === ChatAgentLocation.Panel ? CHAT_PROVIDER_ID : location;
|
|
26
|
+
}
|
|
27
|
+
saveHistory(location, history) {
|
|
22
28
|
if (!this.viewState.history) {
|
|
23
29
|
this.viewState.history = {};
|
|
24
30
|
}
|
|
25
|
-
|
|
31
|
+
const key = this.getKey(location);
|
|
32
|
+
this.viewState.history[key] = history;
|
|
26
33
|
this.memento.saveMemento();
|
|
27
34
|
}
|
|
28
35
|
clearHistory() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
2
|
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
3
3
|
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import { StorageScope, StorageTarget } from 'vscode/vscode/vs/platform/storage/common/storage';
|
|
4
5
|
import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage.service';
|
|
5
6
|
import { ExtensionIdentifier } from 'vscode/vscode/vs/platform/extensions/common/extensions';
|
|
6
7
|
import { Extensions } from 'vscode/vscode/vs/workbench/services/extensionManagement/common/extensionFeatures';
|
|
@@ -21,7 +22,7 @@ let LanguageModelStatsService = class LanguageModelStatsService extends Disposab
|
|
|
21
22
|
this._onDidChangeStats = this._register(( (new Emitter())));
|
|
22
23
|
this.onDidChangeLanguageMoelStats = this._onDidChangeStats.event;
|
|
23
24
|
this.sessionStats = ( (new Map()));
|
|
24
|
-
this._register(_storageService.onDidChangeValue(
|
|
25
|
+
this._register(_storageService.onDidChangeValue(StorageScope.APPLICATION, undefined, this._store)(e => {
|
|
25
26
|
const model = this.getModel(e.key);
|
|
26
27
|
if (model) {
|
|
27
28
|
this._onDidChangeStats.fire(model);
|
|
@@ -48,12 +49,12 @@ let LanguageModelStatsService = class LanguageModelStatsService extends Disposab
|
|
|
48
49
|
const extensions = this.getAccessExtensions(model);
|
|
49
50
|
if (!extensions.includes(extensionId)) {
|
|
50
51
|
extensions.push(extensionId);
|
|
51
|
-
this._storageService.store(this.getAccessKey(model), JSON.stringify(extensions),
|
|
52
|
+
this._storageService.store(this.getAccessKey(model), JSON.stringify(extensions), StorageScope.APPLICATION, StorageTarget.USER);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
getAccessExtensions(model) {
|
|
55
56
|
const key = this.getAccessKey(model);
|
|
56
|
-
const data = this._storageService.get(key,
|
|
57
|
+
const data = this._storageService.get(key, StorageScope.APPLICATION);
|
|
57
58
|
try {
|
|
58
59
|
if (data) {
|
|
59
60
|
const parsed = JSON.parse(data);
|
|
@@ -69,7 +70,7 @@ let LanguageModelStatsService = class LanguageModelStatsService extends Disposab
|
|
|
69
70
|
async write(model, extensionId, participant, tokenCount) {
|
|
70
71
|
const modelStats = await this.read(model);
|
|
71
72
|
this.add(modelStats, extensionId, participant, tokenCount);
|
|
72
|
-
this._storageService.store(this.getKey(model), JSON.stringify(modelStats),
|
|
73
|
+
this._storageService.store(this.getKey(model), JSON.stringify(modelStats), StorageScope.APPLICATION, StorageTarget.USER);
|
|
73
74
|
}
|
|
74
75
|
add(modelStats, extensionId, participant, tokenCount) {
|
|
75
76
|
let extensionStats = modelStats.extensions.find(e => ExtensionIdentifier.equals(e.extensionId, extensionId));
|
|
@@ -93,7 +94,7 @@ let LanguageModelStatsService = class LanguageModelStatsService extends Disposab
|
|
|
93
94
|
}
|
|
94
95
|
async read(model) {
|
|
95
96
|
try {
|
|
96
|
-
const value = this._storageService.get(this.getKey(model),
|
|
97
|
+
const value = this._storageService.get(this.getKey(model), StorageScope.APPLICATION);
|
|
97
98
|
if (value) {
|
|
98
99
|
return JSON.parse(value);
|
|
99
100
|
}
|