@codingame/monaco-vscode-chat-service-override 4.5.1 → 5.0.0
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 +6 -6
- package/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClear.js +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +36 -60
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +78 -51
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +5 -12
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +6 -13
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +10 -27
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +39 -95
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +102 -40
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +57 -70
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +3 -23
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +4 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/{chatContributionServiceImpl.js → chatParticipantContributions.js} +63 -202
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +35 -28
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +49 -41
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +71 -74
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +142 -185
- package/vscode/src/vs/workbench/contrib/chat/common/chatSlashCommands.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/common/chatWidgetHistoryService.js +5 -4
- package/vscode/src/vs/workbench/contrib/chat/common/languageModelStats.js +131 -0
- package/vscode/src/vs/workbench/contrib/chat/common/languageModels.js +11 -2
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChat.js +4 -4
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +1 -4
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +35 -34
|
@@ -5,14 +5,13 @@ import { ErrorNoTelemetry } from 'vscode/vscode/vs/base/common/errors';
|
|
|
5
5
|
import { Emitter } from 'vscode/vscode/vs/base/common/event';
|
|
6
6
|
import { MarkdownString } from 'vscode/vscode/vs/base/common/htmlContent';
|
|
7
7
|
import { Iterable } from 'vscode/vscode/vs/base/common/iterator';
|
|
8
|
-
import { Disposable, DisposableMap
|
|
8
|
+
import { Disposable, DisposableMap } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
9
9
|
import { revive } from 'vscode/vscode/vs/base/common/marshalling';
|
|
10
10
|
import { StopWatch } from 'vscode/vscode/vs/base/common/stopwatch';
|
|
11
11
|
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
12
12
|
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
13
13
|
import { CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
|
|
14
14
|
import { ICommandService } from 'vscode/vscode/vs/platform/commands/common/commands.service';
|
|
15
|
-
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey.service';
|
|
16
15
|
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
17
16
|
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
|
|
18
17
|
import 'vscode/vscode/vs/platform/notification/common/notification';
|
|
@@ -23,8 +22,7 @@ import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/te
|
|
|
23
22
|
import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace.service';
|
|
24
23
|
import { ChatAgentLocation } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
25
24
|
import { IChatAgentService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents.service';
|
|
26
|
-
import {
|
|
27
|
-
import { ChatModel, ChatWelcomeMessageModel, getHistoryEntriesFromModel, updateRanges, ChatModelInitState } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatModel';
|
|
25
|
+
import { ChatModel, ChatWelcomeMessageModel, getHistoryEntriesFromModel, updateRanges } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatModel';
|
|
28
26
|
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, getPromptText } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParserTypes';
|
|
29
27
|
import { ChatRequestParser } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatRequestParser';
|
|
30
28
|
import { InteractiveSessionVoteDirection, ChatCopyKind } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService';
|
|
@@ -33,6 +31,7 @@ import { IChatVariablesService } from 'vscode/vscode/vs/workbench/contrib/chat/c
|
|
|
33
31
|
import { IExtensionService } from 'vscode/vscode/vs/workbench/services/extensions/common/extensions.service';
|
|
34
32
|
import Severity$1 from 'vscode/vscode/vs/base/common/severity';
|
|
35
33
|
|
|
34
|
+
const _moduleId = "vs/workbench/contrib/chat/common/chatServiceImpl";
|
|
36
35
|
const serializedChatKey = 'interactive.sessions';
|
|
37
36
|
const globalChatKey = 'chat.workspaceTransfer';
|
|
38
37
|
const SESSION_TRANSFER_EXPIRATION_IN_MILLISECONDS = 1000 * 60;
|
|
@@ -41,37 +40,30 @@ let ChatService = class ChatService extends Disposable {
|
|
|
41
40
|
get transferredSessionData() {
|
|
42
41
|
return this._transferredSessionData;
|
|
43
42
|
}
|
|
44
|
-
constructor(storageService, logService, extensionService, instantiationService, telemetryService,
|
|
43
|
+
constructor(storageService, logService, extensionService, instantiationService, telemetryService, workspaceContextService, chatSlashCommandService, chatVariablesService, chatAgentService, notificationService, commandService) {
|
|
45
44
|
super();
|
|
46
45
|
this.storageService = storageService;
|
|
47
46
|
this.logService = logService;
|
|
48
47
|
this.extensionService = extensionService;
|
|
49
48
|
this.instantiationService = instantiationService;
|
|
50
49
|
this.telemetryService = telemetryService;
|
|
51
|
-
this.contextKeyService = contextKeyService;
|
|
52
50
|
this.workspaceContextService = workspaceContextService;
|
|
53
51
|
this.chatSlashCommandService = chatSlashCommandService;
|
|
54
52
|
this.chatVariablesService = chatVariablesService;
|
|
55
53
|
this.chatAgentService = chatAgentService;
|
|
56
54
|
this.notificationService = notificationService;
|
|
57
55
|
this.commandService = commandService;
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this._onDidPerformUserAction = this._register(( new Emitter()));
|
|
56
|
+
this._sessionModels = this._register(( (new DisposableMap())));
|
|
57
|
+
this._pendingRequests = this._register(( (new DisposableMap())));
|
|
58
|
+
this._onDidPerformUserAction = this._register(( (new Emitter())));
|
|
62
59
|
this.onDidPerformUserAction = this._onDidPerformUserAction.event;
|
|
63
|
-
this._onDidDisposeSession = this._register(( new Emitter()));
|
|
60
|
+
this._onDidDisposeSession = this._register(( (new Emitter())));
|
|
64
61
|
this.onDidDisposeSession = this._onDidDisposeSession.event;
|
|
65
|
-
this.
|
|
66
|
-
this.onDidRegisterProvider = this._onDidRegisterProvider.event;
|
|
67
|
-
this._onDidUnregisterProvider = this._register(( new Emitter()));
|
|
68
|
-
this.onDidUnregisterProvider = this._onDidUnregisterProvider.event;
|
|
69
|
-
this._sessionFollowupCancelTokens = this._register(( new DisposableMap()));
|
|
70
|
-
this._hasProvider = CONTEXT_PROVIDER_EXISTS.bindTo(this.contextKeyService);
|
|
62
|
+
this._sessionFollowupCancelTokens = this._register(( (new DisposableMap())));
|
|
71
63
|
const sessionData = storageService.get(serializedChatKey, 1 , '');
|
|
72
64
|
if (sessionData) {
|
|
73
65
|
this._persistedSessions = this.deserializeChats(sessionData);
|
|
74
|
-
const countsForLog = ( Object.keys(this._persistedSessions)).length;
|
|
66
|
+
const countsForLog = ( (Object.keys(this._persistedSessions))).length;
|
|
75
67
|
if (countsForLog > 0) {
|
|
76
68
|
this.trace('constructor', `Restored ${countsForLog} persisted sessions`);
|
|
77
69
|
}
|
|
@@ -88,12 +80,15 @@ let ChatService = class ChatService extends Disposable {
|
|
|
88
80
|
}
|
|
89
81
|
this._register(storageService.onWillSaveState(() => this.saveState()));
|
|
90
82
|
}
|
|
83
|
+
isEnabled(location) {
|
|
84
|
+
return this.chatAgentService.getContributedDefaultAgent(location) !== undefined;
|
|
85
|
+
}
|
|
91
86
|
saveState() {
|
|
92
|
-
let allSessions = Array.from(( this._sessionModels.values()))
|
|
93
|
-
.filter(session =>
|
|
87
|
+
let allSessions = Array.from(( (this._sessionModels.values())))
|
|
88
|
+
.filter(session => session.initialLocation === ChatAgentLocation.Panel)
|
|
94
89
|
.filter(session => session.getRequests().length > 0);
|
|
95
|
-
allSessions = allSessions.concat(( Object.values(this._persistedSessions))
|
|
96
|
-
.filter(session => !( this._sessionModels.has(session.sessionId)))
|
|
90
|
+
allSessions = allSessions.concat(( (Object.values(this._persistedSessions)))
|
|
91
|
+
.filter(session => !( (this._sessionModels.has(session.sessionId))))
|
|
97
92
|
.filter(session => session.requests.length));
|
|
98
93
|
allSessions.sort((a, b) => (b.creationDate ?? 0) - (a.creationDate ?? 0));
|
|
99
94
|
allSessions = allSessions.slice(0, maxPersistedSessions);
|
|
@@ -109,19 +104,16 @@ let ChatService = class ChatService extends Disposable {
|
|
|
109
104
|
notifyUserAction(action) {
|
|
110
105
|
if (action.action.kind === 'vote') {
|
|
111
106
|
this.telemetryService.publicLog2('interactiveSessionVote', {
|
|
112
|
-
providerId: action.providerId,
|
|
113
107
|
direction: action.action.direction === InteractiveSessionVoteDirection.Up ? 'up' : 'down'
|
|
114
108
|
});
|
|
115
109
|
}
|
|
116
110
|
else if (action.action.kind === 'copy') {
|
|
117
111
|
this.telemetryService.publicLog2('interactiveSessionCopy', {
|
|
118
|
-
providerId: action.providerId,
|
|
119
112
|
copyKind: action.action.copyKind === ChatCopyKind.Action ? 'action' : 'toolbar'
|
|
120
113
|
});
|
|
121
114
|
}
|
|
122
115
|
else if (action.action.kind === 'insert') {
|
|
123
116
|
this.telemetryService.publicLog2('interactiveSessionInsert', {
|
|
124
|
-
providerId: action.providerId,
|
|
125
117
|
newFile: !!action.action.newFile
|
|
126
118
|
});
|
|
127
119
|
}
|
|
@@ -129,20 +121,23 @@ let ChatService = class ChatService extends Disposable {
|
|
|
129
121
|
const command = CommandsRegistry.getCommand(action.action.commandButton.command.id);
|
|
130
122
|
const commandId = command ? action.action.commandButton.command.id : 'INVALID';
|
|
131
123
|
this.telemetryService.publicLog2('interactiveSessionCommand', {
|
|
132
|
-
providerId: action.providerId,
|
|
133
124
|
commandId
|
|
134
125
|
});
|
|
135
126
|
}
|
|
136
127
|
else if (action.action.kind === 'runInTerminal') {
|
|
137
128
|
this.telemetryService.publicLog2('interactiveSessionRunInTerminal', {
|
|
138
|
-
providerId: action.providerId,
|
|
139
129
|
languageId: action.action.languageId ?? ''
|
|
140
130
|
});
|
|
141
131
|
}
|
|
142
132
|
this._onDidPerformUserAction.fire(action);
|
|
143
133
|
}
|
|
144
134
|
trace(method, message) {
|
|
145
|
-
|
|
135
|
+
if (message) {
|
|
136
|
+
this.logService.trace(`ChatService#${method}: ${message}`);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.logService.trace(`ChatService#${method}`);
|
|
140
|
+
}
|
|
146
141
|
}
|
|
147
142
|
error(method, message) {
|
|
148
143
|
this.logService.error(`ChatService#${method} ${message}`);
|
|
@@ -151,20 +146,22 @@ let ChatService = class ChatService extends Disposable {
|
|
|
151
146
|
try {
|
|
152
147
|
const arrayOfSessions = revive(JSON.parse(sessionData));
|
|
153
148
|
if (!Array.isArray(arrayOfSessions)) {
|
|
154
|
-
throw new Error('Expected array');
|
|
149
|
+
throw ( (new Error('Expected array')));
|
|
155
150
|
}
|
|
156
151
|
const sessions = arrayOfSessions.reduce((acc, session) => {
|
|
157
152
|
for (const request of session.requests) {
|
|
158
153
|
if (Array.isArray(request.response)) {
|
|
159
|
-
request.response = ( request.response.map((response) => {
|
|
154
|
+
request.response = ( (request.response.map((response) => {
|
|
160
155
|
if (typeof response === 'string') {
|
|
161
|
-
return (
|
|
156
|
+
return (
|
|
157
|
+
(new MarkdownString(response))
|
|
158
|
+
);
|
|
162
159
|
}
|
|
163
160
|
return response;
|
|
164
|
-
}));
|
|
161
|
+
})));
|
|
165
162
|
}
|
|
166
163
|
else if (typeof request.response === 'string') {
|
|
167
|
-
request.response = [( new MarkdownString(request.response))];
|
|
164
|
+
request.response = [( (new MarkdownString(request.response)))];
|
|
168
165
|
}
|
|
169
166
|
}
|
|
170
167
|
acc[session.sessionId] = session;
|
|
@@ -183,27 +180,29 @@ let ChatService = class ChatService extends Disposable {
|
|
|
183
180
|
if (!workspaceUri) {
|
|
184
181
|
return;
|
|
185
182
|
}
|
|
186
|
-
const thisWorkspace = ( workspaceUri.toString());
|
|
183
|
+
const thisWorkspace = ( (workspaceUri.toString()));
|
|
187
184
|
const currentTime = Date.now();
|
|
188
|
-
const transferred = data.find(item => ( URI.revive(item.toWorkspace).toString()) === thisWorkspace && (currentTime - item.timestampInMilliseconds < SESSION_TRANSFER_EXPIRATION_IN_MILLISECONDS));
|
|
189
|
-
const filtered = data.filter(item => ( URI.revive(item.toWorkspace).toString()) !== thisWorkspace && (currentTime - item.timestampInMilliseconds < SESSION_TRANSFER_EXPIRATION_IN_MILLISECONDS));
|
|
185
|
+
const transferred = data.find(item => ( (URI.revive(item.toWorkspace).toString())) === thisWorkspace && (currentTime - item.timestampInMilliseconds < SESSION_TRANSFER_EXPIRATION_IN_MILLISECONDS));
|
|
186
|
+
const filtered = data.filter(item => ( (URI.revive(item.toWorkspace).toString())) !== thisWorkspace && (currentTime - item.timestampInMilliseconds < SESSION_TRANSFER_EXPIRATION_IN_MILLISECONDS));
|
|
190
187
|
this.storageService.store(globalChatKey, JSON.stringify(filtered), 0 , 1 );
|
|
191
188
|
return transferred;
|
|
192
189
|
}
|
|
193
190
|
getHistory() {
|
|
194
|
-
const sessions = ( Object.values(this._persistedSessions))
|
|
191
|
+
const sessions = ( (Object.values(this._persistedSessions)))
|
|
195
192
|
.filter(session => session.requests.length > 0);
|
|
196
193
|
sessions.sort((a, b) => (b.creationDate ?? 0) - (a.creationDate ?? 0));
|
|
197
|
-
return (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
return (
|
|
195
|
+
(sessions
|
|
196
|
+
.filter(session => !( (this._sessionModels.has(session.sessionId))))
|
|
197
|
+
.filter(session => !session.isImported)
|
|
198
|
+
.map(item => {
|
|
199
|
+
const title = ChatModel.getDefaultTitle(item.requests);
|
|
200
|
+
return {
|
|
201
|
+
sessionId: item.sessionId,
|
|
202
|
+
title
|
|
203
|
+
};
|
|
204
|
+
}))
|
|
205
|
+
);
|
|
207
206
|
}
|
|
208
207
|
removeHistoryEntry(sessionId) {
|
|
209
208
|
delete this._persistedSessions[sessionId];
|
|
@@ -213,81 +212,61 @@ let ChatService = class ChatService extends Disposable {
|
|
|
213
212
|
this._persistedSessions = {};
|
|
214
213
|
this.saveState();
|
|
215
214
|
}
|
|
216
|
-
startSession(
|
|
217
|
-
this.trace('startSession'
|
|
218
|
-
return this._startSession(
|
|
215
|
+
startSession(location, token) {
|
|
216
|
+
this.trace('startSession');
|
|
217
|
+
return this._startSession(undefined, location, token);
|
|
219
218
|
}
|
|
220
|
-
_startSession(
|
|
221
|
-
this.
|
|
222
|
-
const model = this.instantiationService.createInstance(ChatModel, providerId, someSessionHistory);
|
|
219
|
+
_startSession(someSessionHistory, location, token) {
|
|
220
|
+
const model = this.instantiationService.createInstance(ChatModel, someSessionHistory, location);
|
|
223
221
|
this._sessionModels.set(model.sessionId, model);
|
|
224
222
|
this.initializeSession(model, token);
|
|
225
223
|
return model;
|
|
226
224
|
}
|
|
227
|
-
reinitializeModel(model) {
|
|
228
|
-
this.trace('reinitializeModel', `Start reinit`);
|
|
229
|
-
this.initializeSession(model, CancellationToken.None);
|
|
230
|
-
}
|
|
231
225
|
async initializeSession(model, token) {
|
|
232
226
|
try {
|
|
233
227
|
this.trace('initializeSession', `Initialize session ${model.sessionId}`);
|
|
234
228
|
model.startInitialize();
|
|
235
|
-
await this.extensionService.
|
|
236
|
-
const
|
|
237
|
-
if (!
|
|
238
|
-
throw new ErrorNoTelemetry(
|
|
229
|
+
await this.extensionService.whenInstalledExtensionsRegistered();
|
|
230
|
+
const defaultAgentData = this.chatAgentService.getContributedDefaultAgent(model.initialLocation) ?? this.chatAgentService.getContributedDefaultAgent(ChatAgentLocation.Panel);
|
|
231
|
+
if (!defaultAgentData) {
|
|
232
|
+
throw ( (new ErrorNoTelemetry('No default agent contributed')));
|
|
239
233
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
session = (await provider.prepareSession(token)) ?? undefined;
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
this.trace('initializeSession', `Provider initializeSession threw: ${err}`);
|
|
246
|
-
}
|
|
247
|
-
if (!session) {
|
|
248
|
-
throw new Error('Provider returned no session');
|
|
249
|
-
}
|
|
250
|
-
this.trace('startSession', `Provider returned session`);
|
|
251
|
-
const defaultAgent = this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel);
|
|
234
|
+
await this.extensionService.activateByEvent(`onChatParticipant:${defaultAgentData.id}`);
|
|
235
|
+
const defaultAgent = this.chatAgentService.getActivatedAgents().find(agent => agent.id === defaultAgentData.id);
|
|
252
236
|
if (!defaultAgent) {
|
|
253
237
|
this.notificationService.notify({
|
|
254
238
|
severity: Severity$1.Error,
|
|
255
239
|
message: ( localizeWithPath(
|
|
256
|
-
|
|
257
|
-
|
|
240
|
+
_moduleId,
|
|
241
|
+
0,
|
|
258
242
|
"Chat failed to load. Please ensure that the GitHub Copilot Chat extension is up to date."
|
|
259
243
|
)),
|
|
260
244
|
actions: {
|
|
261
245
|
primary: [
|
|
262
|
-
( new Action('showExtension', ( localizeWithPath(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
"Show Extension"
|
|
266
|
-
)), undefined, true, () => {
|
|
267
|
-
return this.commandService.executeCommand('workbench.extensions.action.showExtensionsWithIds', ['GitHub.copilot-chat']);
|
|
268
|
-
}))
|
|
246
|
+
( (new Action('showExtension', ( localizeWithPath(_moduleId, 1, "Show Extension")), undefined, true, () => {
|
|
247
|
+
return this.commandService.executeCommand('workbench.extensions.action.showExtensionsWithIds', ['GitHub.copilot-chat']);
|
|
248
|
+
})))
|
|
269
249
|
]
|
|
270
250
|
}
|
|
271
251
|
});
|
|
272
|
-
throw new ErrorNoTelemetry('No default agent');
|
|
252
|
+
throw ( (new ErrorNoTelemetry('No default agent registered')));
|
|
273
253
|
}
|
|
274
|
-
const welcomeMessage = model.welcomeMessage ? undefined : (await defaultAgent.provideWelcomeMessage?.(token)) ?? undefined;
|
|
275
|
-
const welcomeModel = welcomeMessage && this.instantiationService.createInstance(ChatWelcomeMessageModel, ( welcomeMessage.map(
|
|
276
|
-
|
|
254
|
+
const welcomeMessage = model.welcomeMessage ? undefined : (await defaultAgent.provideWelcomeMessage?.(model.initialLocation, token)) ?? undefined;
|
|
255
|
+
const welcomeModel = welcomeMessage && this.instantiationService.createInstance(ChatWelcomeMessageModel, ( (welcomeMessage.map(
|
|
256
|
+
item => typeof item === 'string' ? ( (new MarkdownString(item))) : item
|
|
257
|
+
))), (await defaultAgent.provideSampleQuestions?.(model.initialLocation, token)) ?? []);
|
|
258
|
+
model.initialize(welcomeModel);
|
|
277
259
|
}
|
|
278
260
|
catch (err) {
|
|
279
261
|
this.trace('startSession', `initializeSession failed: ${err}`);
|
|
280
262
|
model.setInitializationError(err);
|
|
281
263
|
this._sessionModels.deleteAndDispose(model.sessionId);
|
|
282
|
-
this._onDidDisposeSession.fire({ sessionId: model.sessionId,
|
|
264
|
+
this._onDidDisposeSession.fire({ sessionId: model.sessionId, reason: 'initializationFailed' });
|
|
283
265
|
}
|
|
284
266
|
}
|
|
285
267
|
getSession(sessionId) {
|
|
286
268
|
return this._sessionModels.get(sessionId);
|
|
287
269
|
}
|
|
288
|
-
getSessionId(sessionProviderId) {
|
|
289
|
-
return Iterable.find(( this._sessionModels.values()), model => model.session?.id === sessionProviderId)?.sessionId;
|
|
290
|
-
}
|
|
291
270
|
getOrRestoreSession(sessionId) {
|
|
292
271
|
this.trace('getOrRestoreSession', `sessionId: ${sessionId}`);
|
|
293
272
|
const model = this._sessionModels.get(sessionId);
|
|
@@ -301,12 +280,30 @@ let ChatService = class ChatService extends Disposable {
|
|
|
301
280
|
if (sessionId === this.transferredSessionData?.sessionId) {
|
|
302
281
|
this._transferredSessionData = undefined;
|
|
303
282
|
}
|
|
304
|
-
return this._startSession(sessionData
|
|
283
|
+
return this._startSession(sessionData, sessionData.initialLocation ?? ChatAgentLocation.Panel, CancellationToken.None);
|
|
305
284
|
}
|
|
306
285
|
loadSessionFromContent(data) {
|
|
307
|
-
return this._startSession(data
|
|
286
|
+
return this._startSession(data, data.initialLocation ?? ChatAgentLocation.Panel, CancellationToken.None);
|
|
287
|
+
}
|
|
288
|
+
async resendRequest(request, options) {
|
|
289
|
+
const model = this._sessionModels.get(request.session.sessionId);
|
|
290
|
+
if (!model && model !== request.session) {
|
|
291
|
+
throw ( (new Error(`Unknown session: ${request.session.sessionId}`)));
|
|
292
|
+
}
|
|
293
|
+
await model.waitForInitialization();
|
|
294
|
+
if (( (this._pendingRequests.has(request.session.sessionId)))) {
|
|
295
|
+
this.trace('sendRequest', `Session ${request.session.sessionId} already has a pending request`);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const location = options?.location ?? model.initialLocation;
|
|
299
|
+
const attempt = options?.attempt ?? 0;
|
|
300
|
+
const enableCommandDetection = !options?.noCommandDetection;
|
|
301
|
+
const implicitVariablesEnabled = options?.implicitVariablesEnabled ?? false;
|
|
302
|
+
const defaultAgent = this.chatAgentService.getDefaultAgent(location);
|
|
303
|
+
this.removeRequest(model.sessionId, request.id);
|
|
304
|
+
await this._sendRequestAsync(model, model.sessionId, request.message, attempt, enableCommandDetection, implicitVariablesEnabled, defaultAgent, location);
|
|
308
305
|
}
|
|
309
|
-
async sendRequest(sessionId, request,
|
|
306
|
+
async sendRequest(sessionId, request, options) {
|
|
310
307
|
this.trace('sendRequest', `sessionId: ${sessionId}, message: ${request.substring(0, 20)}${request.length > 20 ? '[...]' : ''}}`);
|
|
311
308
|
if (!request.trim()) {
|
|
312
309
|
this.trace('sendRequest', 'Rejected empty message');
|
|
@@ -314,34 +311,33 @@ let ChatService = class ChatService extends Disposable {
|
|
|
314
311
|
}
|
|
315
312
|
const model = this._sessionModels.get(sessionId);
|
|
316
313
|
if (!model) {
|
|
317
|
-
throw new Error(`Unknown session: ${sessionId}`);
|
|
314
|
+
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
318
315
|
}
|
|
319
316
|
await model.waitForInitialization();
|
|
320
|
-
|
|
321
|
-
if (!provider) {
|
|
322
|
-
throw new Error(`Unknown provider: ${model.providerId}`);
|
|
323
|
-
}
|
|
324
|
-
if (( this._pendingRequests.has(sessionId))) {
|
|
317
|
+
if (( (this._pendingRequests.has(sessionId)))) {
|
|
325
318
|
this.trace('sendRequest', `Session ${sessionId} already has a pending request`);
|
|
326
319
|
return;
|
|
327
320
|
}
|
|
321
|
+
const location = options?.location ?? model.initialLocation;
|
|
322
|
+
const attempt = options?.attempt ?? 0;
|
|
323
|
+
const implicitVariablesEnabled = options?.implicitVariablesEnabled ?? false;
|
|
328
324
|
const defaultAgent = this.chatAgentService.getDefaultAgent(location);
|
|
329
|
-
const parsedRequest = this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, request, location, parserContext);
|
|
325
|
+
const parsedRequest = this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, request, location, options?.parserContext);
|
|
330
326
|
const agent = parsedRequest.parts.find((r) => r instanceof ChatRequestAgentPart)?.agent ?? defaultAgent;
|
|
331
327
|
const agentSlashCommandPart = parsedRequest.parts.find((r) => r instanceof ChatRequestAgentSubcommandPart);
|
|
332
328
|
return {
|
|
333
|
-
responseCompletePromise: this._sendRequestAsync(model, sessionId,
|
|
329
|
+
responseCompletePromise: this._sendRequestAsync(model, sessionId, parsedRequest, attempt, !options?.noCommandDetection, implicitVariablesEnabled, defaultAgent, location),
|
|
334
330
|
agent,
|
|
335
331
|
slashCommand: agentSlashCommandPart?.command,
|
|
336
332
|
};
|
|
337
333
|
}
|
|
338
334
|
refreshFollowupsCancellationToken(sessionId) {
|
|
339
335
|
this._sessionFollowupCancelTokens.get(sessionId)?.cancel();
|
|
340
|
-
const newTokenSource = ( new CancellationTokenSource());
|
|
336
|
+
const newTokenSource = ( (new CancellationTokenSource()));
|
|
341
337
|
this._sessionFollowupCancelTokens.set(sessionId, newTokenSource);
|
|
342
338
|
return newTokenSource.token;
|
|
343
339
|
}
|
|
344
|
-
async _sendRequestAsync(model, sessionId,
|
|
340
|
+
async _sendRequestAsync(model, sessionId, parsedRequest, attempt, enableCommandDetection, implicitVariablesEnabled, defaultAgent, location) {
|
|
345
341
|
const followupsCancelToken = this.refreshFollowupsCancellationToken(sessionId);
|
|
346
342
|
let request;
|
|
347
343
|
const agentPart = 'kind' in parsedRequest ? undefined : parsedRequest.parts.find((r) => r instanceof ChatRequestAgentPart);
|
|
@@ -349,7 +345,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
349
345
|
const commandPart = 'kind' in parsedRequest ? undefined : parsedRequest.parts.find((r) => r instanceof ChatRequestSlashCommandPart);
|
|
350
346
|
let gotProgress = false;
|
|
351
347
|
const requestType = commandPart ? 'slashCommand' : 'string';
|
|
352
|
-
const source = ( new CancellationTokenSource());
|
|
348
|
+
const source = ( (new CancellationTokenSource()));
|
|
353
349
|
const token = source.token;
|
|
354
350
|
const sendRequestInternal = async () => {
|
|
355
351
|
const progressCallback = (progress) => {
|
|
@@ -357,19 +353,18 @@ let ChatService = class ChatService extends Disposable {
|
|
|
357
353
|
return;
|
|
358
354
|
}
|
|
359
355
|
gotProgress = true;
|
|
360
|
-
if (progress.kind === '
|
|
361
|
-
this.trace('sendRequest', `Provider returned progress for session ${model.sessionId}, ${
|
|
356
|
+
if (progress.kind === 'markdownContent') {
|
|
357
|
+
this.trace('sendRequest', `Provider returned progress for session ${model.sessionId}, ${progress.content.value.length} chars`);
|
|
362
358
|
}
|
|
363
359
|
else {
|
|
364
360
|
this.trace('sendRequest', `Provider returned progress: ${JSON.stringify(progress)}`);
|
|
365
361
|
}
|
|
366
362
|
model.acceptResponseProgress(request, progress);
|
|
367
363
|
};
|
|
368
|
-
const stopWatch = ( new StopWatch(false));
|
|
364
|
+
const stopWatch = ( (new StopWatch(false)));
|
|
369
365
|
const listener = token.onCancellationRequested(() => {
|
|
370
366
|
this.trace('sendRequest', `Request for session ${model.sessionId} was cancelled`);
|
|
371
367
|
this.telemetryService.publicLog2('interactiveSessionProviderInvoked', {
|
|
372
|
-
providerId: provider.id,
|
|
373
368
|
timeToFirstProgress: undefined,
|
|
374
369
|
totalTime: stopWatch.elapsed(),
|
|
375
370
|
result: 'cancelled',
|
|
@@ -386,9 +381,9 @@ let ChatService = class ChatService extends Disposable {
|
|
|
386
381
|
if (agentPart || (defaultAgent && !commandPart)) {
|
|
387
382
|
const agent = (agentPart?.agent ?? defaultAgent);
|
|
388
383
|
await this.extensionService.activateByEvent(`onChatParticipant:${agent.id}`);
|
|
389
|
-
const history = getHistoryEntriesFromModel(model);
|
|
384
|
+
const history = getHistoryEntriesFromModel(model, agentPart?.agent.id);
|
|
390
385
|
const initVariableData = { variables: [] };
|
|
391
|
-
request = model.addRequest(parsedRequest, initVariableData, agent, agentSlashCommandPart?.command);
|
|
386
|
+
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command);
|
|
392
387
|
const variableData = await this.chatVariablesService.resolveVariables(parsedRequest, model, progressCallback, token);
|
|
393
388
|
request.variableData = variableData;
|
|
394
389
|
const promptTextResult = getPromptText(request.message);
|
|
@@ -396,9 +391,9 @@ let ChatService = class ChatService extends Disposable {
|
|
|
396
391
|
if (implicitVariablesEnabled) {
|
|
397
392
|
const implicitVariables = agent.defaultImplicitVariables;
|
|
398
393
|
if (implicitVariables) {
|
|
399
|
-
const resolvedImplicitVariables = await Promise.all(( implicitVariables.map(
|
|
394
|
+
const resolvedImplicitVariables = await Promise.all(( (implicitVariables.map(
|
|
400
395
|
async (v) => ({ name: v, values: await this.chatVariablesService.resolveVariable(v, parsedRequest.text, model, progressCallback, token) })
|
|
401
|
-
)));
|
|
396
|
+
))));
|
|
402
397
|
updatedVariableData.variables.push(...resolvedImplicitVariables);
|
|
403
398
|
}
|
|
404
399
|
}
|
|
@@ -409,6 +404,8 @@ let ChatService = class ChatService extends Disposable {
|
|
|
409
404
|
message: promptTextResult.message,
|
|
410
405
|
command: agentSlashCommandPart?.command.name,
|
|
411
406
|
variables: updatedVariableData,
|
|
407
|
+
enableCommandDetection,
|
|
408
|
+
attempt,
|
|
412
409
|
location
|
|
413
410
|
};
|
|
414
411
|
const agentResult = await this.chatAgentService.invokeAgent(agent.id, requestProps, progressCallback, history, token);
|
|
@@ -416,7 +413,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
416
413
|
agentOrCommandFollowups = this.chatAgentService.getFollowups(agent.id, requestProps, agentResult, history, followupsCancelToken);
|
|
417
414
|
}
|
|
418
415
|
else if (commandPart && this.chatSlashCommandService.hasCommand(commandPart.slashCommand.command)) {
|
|
419
|
-
request = model.addRequest(parsedRequest, { variables: [] });
|
|
416
|
+
request = model.addRequest(parsedRequest, { variables: [] }, attempt);
|
|
420
417
|
const history = [];
|
|
421
418
|
for (const request of model.getRequests()) {
|
|
422
419
|
if (!request.response) {
|
|
@@ -426,14 +423,14 @@ let ChatService = class ChatService extends Disposable {
|
|
|
426
423
|
history.push({ role: 2 , content: request.response.response.asString() });
|
|
427
424
|
}
|
|
428
425
|
const message = parsedRequest.text;
|
|
429
|
-
const commandResult = await this.chatSlashCommandService.executeCommand(commandPart.slashCommand.command, message.substring(commandPart.slashCommand.command.length + 1).trimStart(), ( new Progress(p => {
|
|
426
|
+
const commandResult = await this.chatSlashCommandService.executeCommand(commandPart.slashCommand.command, message.substring(commandPart.slashCommand.command.length + 1).trimStart(), ( (new Progress(p => {
|
|
430
427
|
progressCallback(p);
|
|
431
|
-
})), history, token);
|
|
428
|
+
}))), history, token);
|
|
432
429
|
agentOrCommandFollowups = Promise.resolve(commandResult?.followUp);
|
|
433
430
|
rawResult = {};
|
|
434
431
|
}
|
|
435
432
|
else {
|
|
436
|
-
throw new Error(`Cannot handle request`);
|
|
433
|
+
throw ( (new Error(`Cannot handle request`)));
|
|
437
434
|
}
|
|
438
435
|
if (token.isCancellationRequested) {
|
|
439
436
|
return;
|
|
@@ -441,18 +438,13 @@ let ChatService = class ChatService extends Disposable {
|
|
|
441
438
|
else {
|
|
442
439
|
if (!rawResult) {
|
|
443
440
|
this.trace('sendRequest', `Provider returned no response for session ${model.sessionId}`);
|
|
444
|
-
rawResult = { errorDetails: { message: ( localizeWithPath(
|
|
445
|
-
'vs/workbench/contrib/chat/common/chatServiceImpl',
|
|
446
|
-
'emptyResponse',
|
|
447
|
-
"Provider returned null response"
|
|
448
|
-
)) } };
|
|
441
|
+
rawResult = { errorDetails: { message: ( localizeWithPath(_moduleId, 2, "Provider returned null response")) } };
|
|
449
442
|
}
|
|
450
443
|
const result = rawResult.errorDetails?.responseIsFiltered ? 'filtered' :
|
|
451
444
|
rawResult.errorDetails && gotProgress ? 'errorWithOutput' :
|
|
452
445
|
rawResult.errorDetails ? 'error' :
|
|
453
446
|
'success';
|
|
454
447
|
this.telemetryService.publicLog2('interactiveSessionProviderInvoked', {
|
|
455
|
-
providerId: provider.id,
|
|
456
448
|
timeToFirstProgress: rawResult.timings?.firstProgress,
|
|
457
449
|
totalTime: rawResult.timings?.totalElapsed,
|
|
458
450
|
result,
|
|
@@ -485,31 +477,24 @@ let ChatService = class ChatService extends Disposable {
|
|
|
485
477
|
async removeRequest(sessionId, requestId) {
|
|
486
478
|
const model = this._sessionModels.get(sessionId);
|
|
487
479
|
if (!model) {
|
|
488
|
-
throw new Error(`Unknown session: ${sessionId}`);
|
|
480
|
+
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
489
481
|
}
|
|
490
482
|
await model.waitForInitialization();
|
|
491
|
-
const provider = this._providers.get(model.providerId);
|
|
492
|
-
if (!provider) {
|
|
493
|
-
throw new Error(`Unknown provider: ${model.providerId}`);
|
|
494
|
-
}
|
|
495
483
|
model.removeRequest(requestId);
|
|
496
484
|
}
|
|
497
|
-
|
|
498
|
-
return Array.from(( this._providers.keys()));
|
|
499
|
-
}
|
|
500
|
-
async addCompleteRequest(sessionId, message, variableData, response) {
|
|
485
|
+
async addCompleteRequest(sessionId, message, variableData, attempt, response) {
|
|
501
486
|
this.trace('addCompleteRequest', `message: ${message}`);
|
|
502
487
|
const model = this._sessionModels.get(sessionId);
|
|
503
488
|
if (!model) {
|
|
504
|
-
throw new Error(`Unknown session: ${sessionId}`);
|
|
489
|
+
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
505
490
|
}
|
|
506
491
|
await model.waitForInitialization();
|
|
507
492
|
const parsedRequest = typeof message === 'string' ?
|
|
508
493
|
this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, message) :
|
|
509
494
|
message;
|
|
510
|
-
const request = model.addRequest(parsedRequest, variableData || { variables: [] });
|
|
495
|
+
const request = model.addRequest(parsedRequest, variableData || { variables: [] }, attempt ?? 0);
|
|
511
496
|
if (typeof response.message === 'string') {
|
|
512
|
-
model.acceptResponseProgress(request, { content: response.message, kind: '
|
|
497
|
+
model.acceptResponseProgress(request, { content: ( (new MarkdownString(response.message))), kind: 'markdownContent' });
|
|
513
498
|
}
|
|
514
499
|
else {
|
|
515
500
|
for (const part of response.message) {
|
|
@@ -531,52 +516,25 @@ let ChatService = class ChatService extends Disposable {
|
|
|
531
516
|
this.trace('clearSession', `sessionId: ${sessionId}`);
|
|
532
517
|
const model = this._sessionModels.get(sessionId);
|
|
533
518
|
if (!model) {
|
|
534
|
-
throw new Error(`Unknown session: ${sessionId}`);
|
|
519
|
+
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
535
520
|
}
|
|
536
|
-
if (
|
|
521
|
+
if (model.initialLocation === ChatAgentLocation.Panel) {
|
|
537
522
|
this._persistedSessions[sessionId] = model.toJSON();
|
|
538
523
|
}
|
|
539
524
|
this._sessionModels.deleteAndDispose(sessionId);
|
|
540
525
|
this._pendingRequests.get(sessionId)?.cancel();
|
|
541
526
|
this._pendingRequests.deleteAndDispose(sessionId);
|
|
542
|
-
this._onDidDisposeSession.fire({ sessionId,
|
|
543
|
-
}
|
|
544
|
-
registerProvider(provider) {
|
|
545
|
-
this.trace('registerProvider', `Adding new chat provider`);
|
|
546
|
-
if (( this._providers.has(provider.id))) {
|
|
547
|
-
throw new Error(`Provider ${provider.id} already registered`);
|
|
548
|
-
}
|
|
549
|
-
this._providers.set(provider.id, provider);
|
|
550
|
-
this._hasProvider.set(true);
|
|
551
|
-
this._onDidRegisterProvider.fire({ providerId: provider.id });
|
|
552
|
-
Array.from(( this._sessionModels.values()))
|
|
553
|
-
.filter(model => model.providerId === provider.id)
|
|
554
|
-
.filter(model => model.initState === ChatModelInitState.Created)
|
|
555
|
-
.forEach(model => this.reinitializeModel(model));
|
|
556
|
-
return toDisposable(() => {
|
|
557
|
-
this.trace('registerProvider', `Disposing chat provider`);
|
|
558
|
-
this._providers.delete(provider.id);
|
|
559
|
-
this._hasProvider.set(this._providers.size > 0);
|
|
560
|
-
Array.from(( this._sessionModels.values()))
|
|
561
|
-
.filter(model => model.providerId === provider.id)
|
|
562
|
-
.forEach(model => model.deinitialize());
|
|
563
|
-
this._onDidUnregisterProvider.fire({ providerId: provider.id });
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
hasSessions(providerId) {
|
|
567
|
-
return !!( Object.values(this._persistedSessions)).find((session) => session.providerId === providerId);
|
|
527
|
+
this._onDidDisposeSession.fire({ sessionId, reason: 'cleared' });
|
|
568
528
|
}
|
|
569
|
-
|
|
570
|
-
return (
|
|
571
|
-
return {
|
|
572
|
-
id: provider.id,
|
|
573
|
-
};
|
|
574
|
-
}));
|
|
529
|
+
hasSessions() {
|
|
530
|
+
return !!( (Object.values(this._persistedSessions)));
|
|
575
531
|
}
|
|
576
532
|
transferChatSession(transferredSessionData, toWorkspace) {
|
|
577
|
-
const model = Iterable.find(( this._sessionModels.values()), model => model.sessionId === transferredSessionData.sessionId);
|
|
533
|
+
const model = Iterable.find(( (this._sessionModels.values())), model => model.sessionId === transferredSessionData.sessionId);
|
|
578
534
|
if (!model) {
|
|
579
|
-
throw new Error(
|
|
535
|
+
throw ( (new Error(
|
|
536
|
+
`Failed to transfer session. Unknown session ID: ${transferredSessionData.sessionId}`
|
|
537
|
+
)));
|
|
580
538
|
}
|
|
581
539
|
const existingRaw = this.storageService.getObject(globalChatKey, 0 , []);
|
|
582
540
|
existingRaw.push({
|
|
@@ -586,22 +544,21 @@ let ChatService = class ChatService extends Disposable {
|
|
|
586
544
|
inputValue: transferredSessionData.inputValue,
|
|
587
545
|
});
|
|
588
546
|
this.storageService.store(globalChatKey, JSON.stringify(existingRaw), 0 , 1 );
|
|
589
|
-
this.trace('transferChatSession', `Transferred session ${model.sessionId} to workspace ${( toWorkspace.toString())}`);
|
|
547
|
+
this.trace('transferChatSession', `Transferred session ${model.sessionId} to workspace ${( (toWorkspace.toString()))}`);
|
|
590
548
|
}
|
|
591
549
|
};
|
|
592
|
-
ChatService = ( __decorate([
|
|
593
|
-
( __param(0, IStorageService)),
|
|
594
|
-
( __param(1, ILogService)),
|
|
595
|
-
( __param(2, IExtensionService)),
|
|
596
|
-
( __param(3, IInstantiationService)),
|
|
597
|
-
( __param(4, ITelemetryService)),
|
|
598
|
-
( __param(5,
|
|
599
|
-
( __param(6,
|
|
600
|
-
( __param(7,
|
|
601
|
-
( __param(8,
|
|
602
|
-
( __param(9,
|
|
603
|
-
( __param(10,
|
|
604
|
-
|
|
605
|
-
], ChatService));
|
|
550
|
+
ChatService = ( (__decorate([
|
|
551
|
+
( (__param(0, IStorageService))),
|
|
552
|
+
( (__param(1, ILogService))),
|
|
553
|
+
( (__param(2, IExtensionService))),
|
|
554
|
+
( (__param(3, IInstantiationService))),
|
|
555
|
+
( (__param(4, ITelemetryService))),
|
|
556
|
+
( (__param(5, IWorkspaceContextService))),
|
|
557
|
+
( (__param(6, IChatSlashCommandService))),
|
|
558
|
+
( (__param(7, IChatVariablesService))),
|
|
559
|
+
( (__param(8, IChatAgentService))),
|
|
560
|
+
( (__param(9, INotificationService))),
|
|
561
|
+
( (__param(10, ICommandService)))
|
|
562
|
+
], ChatService)));
|
|
606
563
|
|
|
607
564
|
export { ChatService };
|