@codingame/monaco-vscode-chat-service-override 4.5.2 → 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 +32 -45
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +52 -12
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +6 -12
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +35 -72
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +83 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +23 -13
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +3 -23
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +2 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/{chatContributionServiceImpl.js → chatParticipantContributions.js} +43 -139
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +33 -26
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +48 -40
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +5 -5
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +76 -122
- 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 +7 -0
- 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
|
@@ -4,6 +4,7 @@ import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
|
4
4
|
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
|
|
5
5
|
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey.service';
|
|
6
6
|
import { IContextMenuService } from 'vscode/vscode/vs/platform/contextview/browser/contextView.service';
|
|
7
|
+
import { IHoverService } from 'vscode/vscode/vs/platform/hover/browser/hover.service';
|
|
7
8
|
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
8
9
|
import { ServiceCollection } from 'vscode/vscode/vs/platform/instantiation/common/serviceCollection';
|
|
9
10
|
import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding.service';
|
|
@@ -29,54 +30,58 @@ import { SIDE_BAR_FOREGROUND } from 'vscode/vscode/vs/workbench/common/theme';
|
|
|
29
30
|
import { IViewDescriptorService } from 'vscode/vscode/vs/workbench/common/views.service';
|
|
30
31
|
import { ChatWidget } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chatWidget';
|
|
31
32
|
import { ChatAgentLocation } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
33
|
+
import { IChatAgentService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents.service';
|
|
34
|
+
import { CHAT_PROVIDER_ID } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParticipantContribTypes';
|
|
35
|
+
import { ChatModelInitState } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatModel';
|
|
32
36
|
import { IChatService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService.service';
|
|
33
37
|
|
|
34
38
|
const CHAT_SIDEBAR_PANEL_ID = 'workbench.panel.chatSidebar';
|
|
35
39
|
let ChatViewPane = class ChatViewPane extends ViewPane {
|
|
36
|
-
static { this.ID = 'workbench.panel.chat.view'; }
|
|
37
40
|
get widget() { return this._widget; }
|
|
38
|
-
constructor(
|
|
39
|
-
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
|
|
40
|
-
this.chatViewOptions = chatViewOptions;
|
|
41
|
+
constructor(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService, storageService, chatService, chatAgentService, logService) {
|
|
42
|
+
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService);
|
|
41
43
|
this.storageService = storageService;
|
|
42
44
|
this.chatService = chatService;
|
|
45
|
+
this.chatAgentService = chatAgentService;
|
|
43
46
|
this.logService = logService;
|
|
44
47
|
this.modelDisposables = this._register(( new DisposableStore()));
|
|
45
48
|
this.didProviderRegistrationFail = false;
|
|
46
49
|
this.didUnregisterProvider = false;
|
|
47
|
-
this.memento = ( new Memento(
|
|
48
|
-
'interactive-session-view-' + this.chatViewOptions.providerId,
|
|
49
|
-
this.storageService
|
|
50
|
-
));
|
|
50
|
+
this.memento = ( new Memento('interactive-session-view-' + CHAT_PROVIDER_ID, this.storageService));
|
|
51
51
|
this.viewState = this.memento.getMemento(1 , 1 );
|
|
52
|
-
this._register(this.
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
this._register(this.chatAgentService.onDidChangeAgents(() => {
|
|
53
|
+
if (this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel)) {
|
|
54
|
+
if (!this._widget?.viewModel) {
|
|
55
|
+
const sessionId = this.getSessionId();
|
|
56
|
+
const model = sessionId ? this.chatService.getOrRestoreSession(sessionId) : undefined;
|
|
57
|
+
try {
|
|
58
|
+
this._widget.setVisible(false);
|
|
59
|
+
this.updateModel(model);
|
|
60
|
+
this.didProviderRegistrationFail = false;
|
|
61
|
+
this.didUnregisterProvider = false;
|
|
62
|
+
this._onDidChangeViewWelcomeState.fire();
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
this.widget.setVisible(true);
|
|
66
|
+
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
this._register(this.chatService.onDidUnregisterProvider(({ providerId }) => {
|
|
69
|
-
if (providerId === this.chatViewOptions.providerId) {
|
|
69
|
+
else if (this._widget?.viewModel?.initState === ChatModelInitState.Initialized) {
|
|
70
70
|
this.didUnregisterProvider = true;
|
|
71
71
|
this._onDidChangeViewWelcomeState.fire();
|
|
72
72
|
}
|
|
73
73
|
}));
|
|
74
74
|
}
|
|
75
|
+
getActionsContext() {
|
|
76
|
+
return {
|
|
77
|
+
chatView: this
|
|
78
|
+
};
|
|
79
|
+
}
|
|
75
80
|
updateModel(model, viewState) {
|
|
76
81
|
this.modelDisposables.clear();
|
|
77
82
|
model = model ?? (this.chatService.transferredSessionData?.sessionId
|
|
78
83
|
? this.chatService.getOrRestoreSession(this.chatService.transferredSessionData.sessionId)
|
|
79
|
-
: this.chatService.startSession(
|
|
84
|
+
: this.chatService.startSession(ChatAgentLocation.Panel, CancellationToken.None));
|
|
80
85
|
if (!model) {
|
|
81
86
|
throw ( new Error('Could not start chat session'));
|
|
82
87
|
}
|
|
@@ -84,7 +89,7 @@ let ChatViewPane = class ChatViewPane extends ViewPane {
|
|
|
84
89
|
this.viewState.sessionId = model.sessionId;
|
|
85
90
|
}
|
|
86
91
|
shouldShowWelcome() {
|
|
87
|
-
const noPersistedSessions = !this.chatService.hasSessions(
|
|
92
|
+
const noPersistedSessions = !this.chatService.hasSessions();
|
|
88
93
|
return this.didUnregisterProvider || !this._widget?.viewModel && (noPersistedSessions || this.didProviderRegistrationFail);
|
|
89
94
|
}
|
|
90
95
|
getSessionId() {
|
|
@@ -102,10 +107,11 @@ let ChatViewPane = class ChatViewPane extends ViewPane {
|
|
|
102
107
|
try {
|
|
103
108
|
super.renderBody(parent);
|
|
104
109
|
const scopedInstantiationService = this.instantiationService.createChild(( new ServiceCollection([IContextKeyService, this.scopedContextKeyService])));
|
|
110
|
+
const locationBasedColors = this.getLocationBasedColors();
|
|
105
111
|
this._widget = this._register(scopedInstantiationService.createInstance(ChatWidget, ChatAgentLocation.Panel, { viewId: this.id }, { supportsFileReferences: true }, {
|
|
106
112
|
listForeground: SIDE_BAR_FOREGROUND,
|
|
107
|
-
listBackground:
|
|
108
|
-
inputEditorBackground:
|
|
113
|
+
listBackground: locationBasedColors.background,
|
|
114
|
+
inputEditorBackground: locationBasedColors.background,
|
|
109
115
|
resultEditorBackground: editorBackground
|
|
110
116
|
}));
|
|
111
117
|
this._register(this.onDidChangeBodyVisibility(visible => {
|
|
@@ -115,7 +121,7 @@ let ChatViewPane = class ChatViewPane extends ViewPane {
|
|
|
115
121
|
this._widget.render(parent);
|
|
116
122
|
const sessionId = this.getSessionId();
|
|
117
123
|
const disposeListener = sessionId ? this._register(this.chatService.onDidDisposeSession((e) => {
|
|
118
|
-
if (e.reason === 'initializationFailed'
|
|
124
|
+
if (e.reason === 'initializationFailed') {
|
|
119
125
|
this.didProviderRegistrationFail = true;
|
|
120
126
|
disposeListener?.dispose();
|
|
121
127
|
this._onDidChangeViewWelcomeState.fire();
|
|
@@ -132,7 +138,7 @@ let ChatViewPane = class ChatViewPane extends ViewPane {
|
|
|
132
138
|
acceptInput(query) {
|
|
133
139
|
this._widget.acceptInput(query);
|
|
134
140
|
}
|
|
135
|
-
|
|
141
|
+
clear() {
|
|
136
142
|
if (this.widget.viewModel) {
|
|
137
143
|
this.chatService.clearSession(this.widget.viewModel.sessionId);
|
|
138
144
|
}
|
|
@@ -168,18 +174,20 @@ let ChatViewPane = class ChatViewPane extends ViewPane {
|
|
|
168
174
|
}
|
|
169
175
|
};
|
|
170
176
|
ChatViewPane = ( __decorate([
|
|
171
|
-
( __param(
|
|
172
|
-
( __param(
|
|
173
|
-
( __param(
|
|
174
|
-
( __param(
|
|
175
|
-
( __param(
|
|
176
|
-
( __param(
|
|
177
|
-
( __param(
|
|
178
|
-
( __param(
|
|
179
|
-
( __param(
|
|
177
|
+
( __param(1, IKeybindingService)),
|
|
178
|
+
( __param(2, IContextMenuService)),
|
|
179
|
+
( __param(3, IConfigurationService)),
|
|
180
|
+
( __param(4, IContextKeyService)),
|
|
181
|
+
( __param(5, IViewDescriptorService)),
|
|
182
|
+
( __param(6, IInstantiationService)),
|
|
183
|
+
( __param(7, IOpenerService)),
|
|
184
|
+
( __param(8, IThemeService)),
|
|
185
|
+
( __param(9, ITelemetryService)),
|
|
186
|
+
( __param(10, IHoverService)),
|
|
180
187
|
( __param(11, IStorageService)),
|
|
181
188
|
( __param(12, IChatService)),
|
|
182
|
-
( __param(13,
|
|
189
|
+
( __param(13, IChatAgentService)),
|
|
190
|
+
( __param(14, ILogService))
|
|
183
191
|
], ChatViewPane));
|
|
184
192
|
|
|
185
193
|
export { CHAT_SIDEBAR_PANEL_ID, ChatViewPane };
|
|
@@ -123,7 +123,7 @@ let InputEditorDecorations = class InputEditorDecorations extends Disposable {
|
|
|
123
123
|
},
|
|
124
124
|
renderOptions: {
|
|
125
125
|
after: {
|
|
126
|
-
contentText: viewModel.inputPlaceholder
|
|
126
|
+
contentText: viewModel.inputPlaceholder || (defaultAgent?.description ?? ''),
|
|
127
127
|
color: this.getPlaceholderColor()
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -187,8 +187,8 @@ let InputEditorDecorations = class InputEditorDecorations extends Disposable {
|
|
|
187
187
|
const textDecorations = [];
|
|
188
188
|
if (agentPart) {
|
|
189
189
|
const isDupe = !!this.chatAgentService.getAgents().find(other => other.name === agentPart.agent.name && other.id !== agentPart.agent.id);
|
|
190
|
-
const
|
|
191
|
-
const agentHover = `${
|
|
190
|
+
const publisher = isDupe ? `(${agentPart.agent.extensionPublisherDisplayName}) ` : '';
|
|
191
|
+
const agentHover = `${publisher}${agentPart.agent.description}`;
|
|
192
192
|
textDecorations.push({ range: agentPart.editorRange, hoverMessage: ( (new MarkdownString(agentHover))) });
|
|
193
193
|
if (agentSubcommandPart) {
|
|
194
194
|
textDecorations.push({ range: agentSubcommandPart.editorRange, hoverMessage: ( (new MarkdownString(agentSubcommandPart.command.description))) });
|
|
@@ -318,7 +318,7 @@ let AgentCompletions = class AgentCompletions extends Disposable {
|
|
|
318
318
|
const isDupe = !!agents.find(other => other.name === a.name && other.id !== a.id);
|
|
319
319
|
return {
|
|
320
320
|
label: isDupe ?
|
|
321
|
-
{ label: withAt, description: a.description, detail: ` (${a.
|
|
321
|
+
{ label: withAt, description: a.description, detail: ` (${a.extensionPublisherDisplayName})` } :
|
|
322
322
|
withAt,
|
|
323
323
|
insertText: `${withAt} `,
|
|
324
324
|
detail: a.description,
|
|
@@ -394,7 +394,7 @@ let AgentCompletions = class AgentCompletions extends Disposable {
|
|
|
394
394
|
const agentLabel = `${chatAgentLeader}${agent.name}`;
|
|
395
395
|
return {
|
|
396
396
|
label: isDupe ?
|
|
397
|
-
{ label: agentLabel, description: agent.description, detail: ` (${agent.
|
|
397
|
+
{ label: agentLabel, description: agent.description, detail: ` (${agent.extensionPublisherDisplayName})` } :
|
|
398
398
|
agentLabel,
|
|
399
399
|
detail,
|
|
400
400
|
filterText: `${chatSubcommandLeader}${agent.name}`,
|
|
@@ -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';
|
|
@@ -42,33 +40,26 @@ let ChatService = class ChatService extends Disposable {
|
|
|
42
40
|
get transferredSessionData() {
|
|
43
41
|
return this._transferredSessionData;
|
|
44
42
|
}
|
|
45
|
-
constructor(storageService, logService, extensionService, instantiationService, telemetryService,
|
|
43
|
+
constructor(storageService, logService, extensionService, instantiationService, telemetryService, workspaceContextService, chatSlashCommandService, chatVariablesService, chatAgentService, notificationService, commandService) {
|
|
46
44
|
super();
|
|
47
45
|
this.storageService = storageService;
|
|
48
46
|
this.logService = logService;
|
|
49
47
|
this.extensionService = extensionService;
|
|
50
48
|
this.instantiationService = instantiationService;
|
|
51
49
|
this.telemetryService = telemetryService;
|
|
52
|
-
this.contextKeyService = contextKeyService;
|
|
53
50
|
this.workspaceContextService = workspaceContextService;
|
|
54
51
|
this.chatSlashCommandService = chatSlashCommandService;
|
|
55
52
|
this.chatVariablesService = chatVariablesService;
|
|
56
53
|
this.chatAgentService = chatAgentService;
|
|
57
54
|
this.notificationService = notificationService;
|
|
58
55
|
this.commandService = commandService;
|
|
59
|
-
this._providers = ( (new Map()));
|
|
60
56
|
this._sessionModels = this._register(( (new DisposableMap())));
|
|
61
57
|
this._pendingRequests = this._register(( (new DisposableMap())));
|
|
62
58
|
this._onDidPerformUserAction = this._register(( (new Emitter())));
|
|
63
59
|
this.onDidPerformUserAction = this._onDidPerformUserAction.event;
|
|
64
60
|
this._onDidDisposeSession = this._register(( (new Emitter())));
|
|
65
61
|
this.onDidDisposeSession = this._onDidDisposeSession.event;
|
|
66
|
-
this._onDidRegisterProvider = this._register(( (new Emitter())));
|
|
67
|
-
this.onDidRegisterProvider = this._onDidRegisterProvider.event;
|
|
68
|
-
this._onDidUnregisterProvider = this._register(( (new Emitter())));
|
|
69
|
-
this.onDidUnregisterProvider = this._onDidUnregisterProvider.event;
|
|
70
62
|
this._sessionFollowupCancelTokens = this._register(( (new DisposableMap())));
|
|
71
|
-
this._hasProvider = CONTEXT_PROVIDER_EXISTS.bindTo(this.contextKeyService);
|
|
72
63
|
const sessionData = storageService.get(serializedChatKey, 1 , '');
|
|
73
64
|
if (sessionData) {
|
|
74
65
|
this._persistedSessions = this.deserializeChats(sessionData);
|
|
@@ -89,9 +80,12 @@ let ChatService = class ChatService extends Disposable {
|
|
|
89
80
|
}
|
|
90
81
|
this._register(storageService.onWillSaveState(() => this.saveState()));
|
|
91
82
|
}
|
|
83
|
+
isEnabled(location) {
|
|
84
|
+
return this.chatAgentService.getContributedDefaultAgent(location) !== undefined;
|
|
85
|
+
}
|
|
92
86
|
saveState() {
|
|
93
87
|
let allSessions = Array.from(( (this._sessionModels.values())))
|
|
94
|
-
.filter(session =>
|
|
88
|
+
.filter(session => session.initialLocation === ChatAgentLocation.Panel)
|
|
95
89
|
.filter(session => session.getRequests().length > 0);
|
|
96
90
|
allSessions = allSessions.concat(( (Object.values(this._persistedSessions)))
|
|
97
91
|
.filter(session => !( (this._sessionModels.has(session.sessionId))))
|
|
@@ -110,19 +104,16 @@ let ChatService = class ChatService extends Disposable {
|
|
|
110
104
|
notifyUserAction(action) {
|
|
111
105
|
if (action.action.kind === 'vote') {
|
|
112
106
|
this.telemetryService.publicLog2('interactiveSessionVote', {
|
|
113
|
-
providerId: action.providerId,
|
|
114
107
|
direction: action.action.direction === InteractiveSessionVoteDirection.Up ? 'up' : 'down'
|
|
115
108
|
});
|
|
116
109
|
}
|
|
117
110
|
else if (action.action.kind === 'copy') {
|
|
118
111
|
this.telemetryService.publicLog2('interactiveSessionCopy', {
|
|
119
|
-
providerId: action.providerId,
|
|
120
112
|
copyKind: action.action.copyKind === ChatCopyKind.Action ? 'action' : 'toolbar'
|
|
121
113
|
});
|
|
122
114
|
}
|
|
123
115
|
else if (action.action.kind === 'insert') {
|
|
124
116
|
this.telemetryService.publicLog2('interactiveSessionInsert', {
|
|
125
|
-
providerId: action.providerId,
|
|
126
117
|
newFile: !!action.action.newFile
|
|
127
118
|
});
|
|
128
119
|
}
|
|
@@ -130,20 +121,23 @@ let ChatService = class ChatService extends Disposable {
|
|
|
130
121
|
const command = CommandsRegistry.getCommand(action.action.commandButton.command.id);
|
|
131
122
|
const commandId = command ? action.action.commandButton.command.id : 'INVALID';
|
|
132
123
|
this.telemetryService.publicLog2('interactiveSessionCommand', {
|
|
133
|
-
providerId: action.providerId,
|
|
134
124
|
commandId
|
|
135
125
|
});
|
|
136
126
|
}
|
|
137
127
|
else if (action.action.kind === 'runInTerminal') {
|
|
138
128
|
this.telemetryService.publicLog2('interactiveSessionRunInTerminal', {
|
|
139
|
-
providerId: action.providerId,
|
|
140
129
|
languageId: action.action.languageId ?? ''
|
|
141
130
|
});
|
|
142
131
|
}
|
|
143
132
|
this._onDidPerformUserAction.fire(action);
|
|
144
133
|
}
|
|
145
134
|
trace(method, message) {
|
|
146
|
-
|
|
135
|
+
if (message) {
|
|
136
|
+
this.logService.trace(`ChatService#${method}: ${message}`);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.logService.trace(`ChatService#${method}`);
|
|
140
|
+
}
|
|
147
141
|
}
|
|
148
142
|
error(method, message) {
|
|
149
143
|
this.logService.error(`ChatService#${method} ${message}`);
|
|
@@ -218,42 +212,27 @@ let ChatService = class ChatService extends Disposable {
|
|
|
218
212
|
this._persistedSessions = {};
|
|
219
213
|
this.saveState();
|
|
220
214
|
}
|
|
221
|
-
startSession(
|
|
222
|
-
this.trace('startSession'
|
|
223
|
-
return this._startSession(
|
|
215
|
+
startSession(location, token) {
|
|
216
|
+
this.trace('startSession');
|
|
217
|
+
return this._startSession(undefined, location, token);
|
|
224
218
|
}
|
|
225
|
-
_startSession(
|
|
226
|
-
this.
|
|
227
|
-
const model = this.instantiationService.createInstance(ChatModel, providerId, someSessionHistory);
|
|
219
|
+
_startSession(someSessionHistory, location, token) {
|
|
220
|
+
const model = this.instantiationService.createInstance(ChatModel, someSessionHistory, location);
|
|
228
221
|
this._sessionModels.set(model.sessionId, model);
|
|
229
222
|
this.initializeSession(model, token);
|
|
230
223
|
return model;
|
|
231
224
|
}
|
|
232
|
-
reinitializeModel(model) {
|
|
233
|
-
this.trace('reinitializeModel', `Start reinit`);
|
|
234
|
-
this.initializeSession(model, CancellationToken.None);
|
|
235
|
-
}
|
|
236
225
|
async initializeSession(model, token) {
|
|
237
226
|
try {
|
|
238
227
|
this.trace('initializeSession', `Initialize session ${model.sessionId}`);
|
|
239
228
|
model.startInitialize();
|
|
240
|
-
await this.extensionService.
|
|
241
|
-
const
|
|
242
|
-
if (!
|
|
243
|
-
throw ( (new ErrorNoTelemetry(
|
|
244
|
-
}
|
|
245
|
-
let session;
|
|
246
|
-
try {
|
|
247
|
-
session = (await provider.prepareSession(token)) ?? undefined;
|
|
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')));
|
|
248
233
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
if (!session) {
|
|
253
|
-
throw ( (new Error('Provider returned no session')));
|
|
254
|
-
}
|
|
255
|
-
this.trace('startSession', `Provider returned session`);
|
|
256
|
-
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);
|
|
257
236
|
if (!defaultAgent) {
|
|
258
237
|
this.notificationService.notify({
|
|
259
238
|
severity: Severity$1.Error,
|
|
@@ -270,27 +249,24 @@ let ChatService = class ChatService extends Disposable {
|
|
|
270
249
|
]
|
|
271
250
|
}
|
|
272
251
|
});
|
|
273
|
-
throw ( (new ErrorNoTelemetry('No default agent')));
|
|
252
|
+
throw ( (new ErrorNoTelemetry('No default agent registered')));
|
|
274
253
|
}
|
|
275
|
-
const welcomeMessage = model.welcomeMessage ? undefined : (await defaultAgent.provideWelcomeMessage?.(token)) ?? undefined;
|
|
254
|
+
const welcomeMessage = model.welcomeMessage ? undefined : (await defaultAgent.provideWelcomeMessage?.(model.initialLocation, token)) ?? undefined;
|
|
276
255
|
const welcomeModel = welcomeMessage && this.instantiationService.createInstance(ChatWelcomeMessageModel, ( (welcomeMessage.map(
|
|
277
256
|
item => typeof item === 'string' ? ( (new MarkdownString(item))) : item
|
|
278
|
-
))), (await defaultAgent.provideSampleQuestions?.(token)) ?? []);
|
|
279
|
-
model.initialize(
|
|
257
|
+
))), (await defaultAgent.provideSampleQuestions?.(model.initialLocation, token)) ?? []);
|
|
258
|
+
model.initialize(welcomeModel);
|
|
280
259
|
}
|
|
281
260
|
catch (err) {
|
|
282
261
|
this.trace('startSession', `initializeSession failed: ${err}`);
|
|
283
262
|
model.setInitializationError(err);
|
|
284
263
|
this._sessionModels.deleteAndDispose(model.sessionId);
|
|
285
|
-
this._onDidDisposeSession.fire({ sessionId: model.sessionId,
|
|
264
|
+
this._onDidDisposeSession.fire({ sessionId: model.sessionId, reason: 'initializationFailed' });
|
|
286
265
|
}
|
|
287
266
|
}
|
|
288
267
|
getSession(sessionId) {
|
|
289
268
|
return this._sessionModels.get(sessionId);
|
|
290
269
|
}
|
|
291
|
-
getSessionId(sessionProviderId) {
|
|
292
|
-
return Iterable.find(( (this._sessionModels.values())), model => model.session?.id === sessionProviderId)?.sessionId;
|
|
293
|
-
}
|
|
294
270
|
getOrRestoreSession(sessionId) {
|
|
295
271
|
this.trace('getOrRestoreSession', `sessionId: ${sessionId}`);
|
|
296
272
|
const model = this._sessionModels.get(sessionId);
|
|
@@ -304,12 +280,30 @@ let ChatService = class ChatService extends Disposable {
|
|
|
304
280
|
if (sessionId === this.transferredSessionData?.sessionId) {
|
|
305
281
|
this._transferredSessionData = undefined;
|
|
306
282
|
}
|
|
307
|
-
return this._startSession(sessionData
|
|
283
|
+
return this._startSession(sessionData, sessionData.initialLocation ?? ChatAgentLocation.Panel, CancellationToken.None);
|
|
308
284
|
}
|
|
309
285
|
loadSessionFromContent(data) {
|
|
310
|
-
return this._startSession(data
|
|
286
|
+
return this._startSession(data, data.initialLocation ?? ChatAgentLocation.Panel, CancellationToken.None);
|
|
311
287
|
}
|
|
312
|
-
async
|
|
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);
|
|
305
|
+
}
|
|
306
|
+
async sendRequest(sessionId, request, options) {
|
|
313
307
|
this.trace('sendRequest', `sessionId: ${sessionId}, message: ${request.substring(0, 20)}${request.length > 20 ? '[...]' : ''}}`);
|
|
314
308
|
if (!request.trim()) {
|
|
315
309
|
this.trace('sendRequest', 'Rejected empty message');
|
|
@@ -320,20 +314,19 @@ let ChatService = class ChatService extends Disposable {
|
|
|
320
314
|
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
321
315
|
}
|
|
322
316
|
await model.waitForInitialization();
|
|
323
|
-
const provider = this._providers.get(model.providerId);
|
|
324
|
-
if (!provider) {
|
|
325
|
-
throw ( (new Error(`Unknown provider: ${model.providerId}`)));
|
|
326
|
-
}
|
|
327
317
|
if (( (this._pendingRequests.has(sessionId)))) {
|
|
328
318
|
this.trace('sendRequest', `Session ${sessionId} already has a pending request`);
|
|
329
319
|
return;
|
|
330
320
|
}
|
|
321
|
+
const location = options?.location ?? model.initialLocation;
|
|
322
|
+
const attempt = options?.attempt ?? 0;
|
|
323
|
+
const implicitVariablesEnabled = options?.implicitVariablesEnabled ?? false;
|
|
331
324
|
const defaultAgent = this.chatAgentService.getDefaultAgent(location);
|
|
332
|
-
const parsedRequest = this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, request, location, parserContext);
|
|
325
|
+
const parsedRequest = this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, request, location, options?.parserContext);
|
|
333
326
|
const agent = parsedRequest.parts.find((r) => r instanceof ChatRequestAgentPart)?.agent ?? defaultAgent;
|
|
334
327
|
const agentSlashCommandPart = parsedRequest.parts.find((r) => r instanceof ChatRequestAgentSubcommandPart);
|
|
335
328
|
return {
|
|
336
|
-
responseCompletePromise: this._sendRequestAsync(model, sessionId,
|
|
329
|
+
responseCompletePromise: this._sendRequestAsync(model, sessionId, parsedRequest, attempt, !options?.noCommandDetection, implicitVariablesEnabled, defaultAgent, location),
|
|
337
330
|
agent,
|
|
338
331
|
slashCommand: agentSlashCommandPart?.command,
|
|
339
332
|
};
|
|
@@ -344,7 +337,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
344
337
|
this._sessionFollowupCancelTokens.set(sessionId, newTokenSource);
|
|
345
338
|
return newTokenSource.token;
|
|
346
339
|
}
|
|
347
|
-
async _sendRequestAsync(model, sessionId,
|
|
340
|
+
async _sendRequestAsync(model, sessionId, parsedRequest, attempt, enableCommandDetection, implicitVariablesEnabled, defaultAgent, location) {
|
|
348
341
|
const followupsCancelToken = this.refreshFollowupsCancellationToken(sessionId);
|
|
349
342
|
let request;
|
|
350
343
|
const agentPart = 'kind' in parsedRequest ? undefined : parsedRequest.parts.find((r) => r instanceof ChatRequestAgentPart);
|
|
@@ -360,8 +353,8 @@ let ChatService = class ChatService extends Disposable {
|
|
|
360
353
|
return;
|
|
361
354
|
}
|
|
362
355
|
gotProgress = true;
|
|
363
|
-
if (progress.kind === '
|
|
364
|
-
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`);
|
|
365
358
|
}
|
|
366
359
|
else {
|
|
367
360
|
this.trace('sendRequest', `Provider returned progress: ${JSON.stringify(progress)}`);
|
|
@@ -372,7 +365,6 @@ let ChatService = class ChatService extends Disposable {
|
|
|
372
365
|
const listener = token.onCancellationRequested(() => {
|
|
373
366
|
this.trace('sendRequest', `Request for session ${model.sessionId} was cancelled`);
|
|
374
367
|
this.telemetryService.publicLog2('interactiveSessionProviderInvoked', {
|
|
375
|
-
providerId: provider.id,
|
|
376
368
|
timeToFirstProgress: undefined,
|
|
377
369
|
totalTime: stopWatch.elapsed(),
|
|
378
370
|
result: 'cancelled',
|
|
@@ -389,9 +381,9 @@ let ChatService = class ChatService extends Disposable {
|
|
|
389
381
|
if (agentPart || (defaultAgent && !commandPart)) {
|
|
390
382
|
const agent = (agentPart?.agent ?? defaultAgent);
|
|
391
383
|
await this.extensionService.activateByEvent(`onChatParticipant:${agent.id}`);
|
|
392
|
-
const history = getHistoryEntriesFromModel(model);
|
|
384
|
+
const history = getHistoryEntriesFromModel(model, agentPart?.agent.id);
|
|
393
385
|
const initVariableData = { variables: [] };
|
|
394
|
-
request = model.addRequest(parsedRequest, initVariableData, agent, agentSlashCommandPart?.command);
|
|
386
|
+
request = model.addRequest(parsedRequest, initVariableData, attempt, agent, agentSlashCommandPart?.command);
|
|
395
387
|
const variableData = await this.chatVariablesService.resolveVariables(parsedRequest, model, progressCallback, token);
|
|
396
388
|
request.variableData = variableData;
|
|
397
389
|
const promptTextResult = getPromptText(request.message);
|
|
@@ -412,6 +404,8 @@ let ChatService = class ChatService extends Disposable {
|
|
|
412
404
|
message: promptTextResult.message,
|
|
413
405
|
command: agentSlashCommandPart?.command.name,
|
|
414
406
|
variables: updatedVariableData,
|
|
407
|
+
enableCommandDetection,
|
|
408
|
+
attempt,
|
|
415
409
|
location
|
|
416
410
|
};
|
|
417
411
|
const agentResult = await this.chatAgentService.invokeAgent(agent.id, requestProps, progressCallback, history, token);
|
|
@@ -419,7 +413,7 @@ let ChatService = class ChatService extends Disposable {
|
|
|
419
413
|
agentOrCommandFollowups = this.chatAgentService.getFollowups(agent.id, requestProps, agentResult, history, followupsCancelToken);
|
|
420
414
|
}
|
|
421
415
|
else if (commandPart && this.chatSlashCommandService.hasCommand(commandPart.slashCommand.command)) {
|
|
422
|
-
request = model.addRequest(parsedRequest, { variables: [] });
|
|
416
|
+
request = model.addRequest(parsedRequest, { variables: [] }, attempt);
|
|
423
417
|
const history = [];
|
|
424
418
|
for (const request of model.getRequests()) {
|
|
425
419
|
if (!request.response) {
|
|
@@ -451,7 +445,6 @@ let ChatService = class ChatService extends Disposable {
|
|
|
451
445
|
rawResult.errorDetails ? 'error' :
|
|
452
446
|
'success';
|
|
453
447
|
this.telemetryService.publicLog2('interactiveSessionProviderInvoked', {
|
|
454
|
-
providerId: provider.id,
|
|
455
448
|
timeToFirstProgress: rawResult.timings?.firstProgress,
|
|
456
449
|
totalTime: rawResult.timings?.totalElapsed,
|
|
457
450
|
result,
|
|
@@ -487,16 +480,9 @@ let ChatService = class ChatService extends Disposable {
|
|
|
487
480
|
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
488
481
|
}
|
|
489
482
|
await model.waitForInitialization();
|
|
490
|
-
const provider = this._providers.get(model.providerId);
|
|
491
|
-
if (!provider) {
|
|
492
|
-
throw ( (new Error(`Unknown provider: ${model.providerId}`)));
|
|
493
|
-
}
|
|
494
483
|
model.removeRequest(requestId);
|
|
495
484
|
}
|
|
496
|
-
|
|
497
|
-
return Array.from(( (this._providers.keys())));
|
|
498
|
-
}
|
|
499
|
-
async addCompleteRequest(sessionId, message, variableData, response) {
|
|
485
|
+
async addCompleteRequest(sessionId, message, variableData, attempt, response) {
|
|
500
486
|
this.trace('addCompleteRequest', `message: ${message}`);
|
|
501
487
|
const model = this._sessionModels.get(sessionId);
|
|
502
488
|
if (!model) {
|
|
@@ -506,9 +492,9 @@ let ChatService = class ChatService extends Disposable {
|
|
|
506
492
|
const parsedRequest = typeof message === 'string' ?
|
|
507
493
|
this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, message) :
|
|
508
494
|
message;
|
|
509
|
-
const request = model.addRequest(parsedRequest, variableData || { variables: [] });
|
|
495
|
+
const request = model.addRequest(parsedRequest, variableData || { variables: [] }, attempt ?? 0);
|
|
510
496
|
if (typeof response.message === 'string') {
|
|
511
|
-
model.acceptResponseProgress(request, { content: response.message, kind: '
|
|
497
|
+
model.acceptResponseProgress(request, { content: ( (new MarkdownString(response.message))), kind: 'markdownContent' });
|
|
512
498
|
}
|
|
513
499
|
else {
|
|
514
500
|
for (const part of response.message) {
|
|
@@ -532,47 +518,16 @@ let ChatService = class ChatService extends Disposable {
|
|
|
532
518
|
if (!model) {
|
|
533
519
|
throw ( (new Error(`Unknown session: ${sessionId}`)));
|
|
534
520
|
}
|
|
535
|
-
if (
|
|
521
|
+
if (model.initialLocation === ChatAgentLocation.Panel) {
|
|
536
522
|
this._persistedSessions[sessionId] = model.toJSON();
|
|
537
523
|
}
|
|
538
524
|
this._sessionModels.deleteAndDispose(sessionId);
|
|
539
525
|
this._pendingRequests.get(sessionId)?.cancel();
|
|
540
526
|
this._pendingRequests.deleteAndDispose(sessionId);
|
|
541
|
-
this._onDidDisposeSession.fire({ sessionId,
|
|
542
|
-
}
|
|
543
|
-
registerProvider(provider) {
|
|
544
|
-
this.trace('registerProvider', `Adding new chat provider`);
|
|
545
|
-
if (( (this._providers.has(provider.id)))) {
|
|
546
|
-
throw ( (new Error(`Provider ${provider.id} already registered`)));
|
|
547
|
-
}
|
|
548
|
-
this._providers.set(provider.id, provider);
|
|
549
|
-
this._hasProvider.set(true);
|
|
550
|
-
this._onDidRegisterProvider.fire({ providerId: provider.id });
|
|
551
|
-
Array.from(( (this._sessionModels.values())))
|
|
552
|
-
.filter(model => model.providerId === provider.id)
|
|
553
|
-
.filter(model => model.initState === ChatModelInitState.Created)
|
|
554
|
-
.forEach(model => this.reinitializeModel(model));
|
|
555
|
-
return toDisposable(() => {
|
|
556
|
-
this.trace('registerProvider', `Disposing chat provider`);
|
|
557
|
-
this._providers.delete(provider.id);
|
|
558
|
-
this._hasProvider.set(this._providers.size > 0);
|
|
559
|
-
Array.from(( (this._sessionModels.values())))
|
|
560
|
-
.filter(model => model.providerId === provider.id)
|
|
561
|
-
.forEach(model => model.deinitialize());
|
|
562
|
-
this._onDidUnregisterProvider.fire({ providerId: provider.id });
|
|
563
|
-
});
|
|
527
|
+
this._onDidDisposeSession.fire({ sessionId, reason: 'cleared' });
|
|
564
528
|
}
|
|
565
|
-
hasSessions(
|
|
566
|
-
return !!( (Object.values(this._persistedSessions)))
|
|
567
|
-
}
|
|
568
|
-
getProviderInfos() {
|
|
569
|
-
return (
|
|
570
|
-
(Array.from(( (this._providers.values()))).map(provider => {
|
|
571
|
-
return {
|
|
572
|
-
id: provider.id,
|
|
573
|
-
};
|
|
574
|
-
}))
|
|
575
|
-
);
|
|
529
|
+
hasSessions() {
|
|
530
|
+
return !!( (Object.values(this._persistedSessions)));
|
|
576
531
|
}
|
|
577
532
|
transferChatSession(transferredSessionData, toWorkspace) {
|
|
578
533
|
const model = Iterable.find(( (this._sessionModels.values())), model => model.sessionId === transferredSessionData.sessionId);
|
|
@@ -598,13 +553,12 @@ ChatService = ( (__decorate([
|
|
|
598
553
|
( (__param(2, IExtensionService))),
|
|
599
554
|
( (__param(3, IInstantiationService))),
|
|
600
555
|
( (__param(4, ITelemetryService))),
|
|
601
|
-
( (__param(5,
|
|
602
|
-
( (__param(6,
|
|
603
|
-
( (__param(7,
|
|
604
|
-
( (__param(8,
|
|
605
|
-
( (__param(9,
|
|
606
|
-
( (__param(10,
|
|
607
|
-
( (__param(11, ICommandService)))
|
|
556
|
+
( (__param(5, IWorkspaceContextService))),
|
|
557
|
+
( (__param(6, IChatSlashCommandService))),
|
|
558
|
+
( (__param(7, IChatVariablesService))),
|
|
559
|
+
( (__param(8, IChatAgentService))),
|
|
560
|
+
( (__param(9, INotificationService))),
|
|
561
|
+
( (__param(10, ICommandService)))
|
|
608
562
|
], ChatService)));
|
|
609
563
|
|
|
610
564
|
export { ChatService };
|