@codingame/monaco-vscode-chat-service-override 4.1.0 → 4.1.2
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 +9 -9
- package/external/tslib/tslib.es6.js +11 -0
- package/external/vscode-marked/lib/marked.esm.js +2200 -0
- package/override/vs/platform/dialogs/common/dialogs.js +10 -0
- package/package.json +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClear.js +17 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatClearActions.js +115 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +503 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +82 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +77 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +110 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +171 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatTitleActions.js +271 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +317 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.js +60 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatContributionServiceImpl.js +423 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +98 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +285 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +90 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +185 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables.js +26 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +618 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +600 -0
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChat.js +141 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +40 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +41 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.js +72 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatSavingServiceImpl.js +236 -0
- package/vscode/src/vs/workbench/contrib/inlineChat/common/inlineChatServiceImpl.js +33 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { isAncestorOfActiveElement, $ } from 'vscode/vscode/vs/base/browser/dom';
|
|
3
|
+
import { Sash } from 'vscode/vscode/vs/base/browser/ui/sash/sash';
|
|
4
|
+
import { disposableTimeout } from 'vscode/vscode/vs/base/common/async';
|
|
5
|
+
import { CancellationToken } from 'vscode/vscode/vs/base/common/cancellation';
|
|
6
|
+
import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
|
|
7
|
+
import { Disposable, MutableDisposable, DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
8
|
+
import { MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
9
|
+
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
10
|
+
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
11
|
+
import { ServiceCollection } from 'vscode/vscode/vs/platform/instantiation/common/serviceCollection';
|
|
12
|
+
import { ILayoutService } from 'vscode/vscode/vs/platform/layout/browser/layoutService';
|
|
13
|
+
import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput';
|
|
14
|
+
import 'vscode/vscode/vs/platform/theme/common/colorUtils';
|
|
15
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/baseColors';
|
|
16
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/chartsColors';
|
|
17
|
+
import { editorBackground } from 'vscode/vscode/vs/platform/theme/common/colors/editorColors';
|
|
18
|
+
import { inputBackground } from 'vscode/vscode/vs/platform/theme/common/colors/inputColors';
|
|
19
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/listColors';
|
|
20
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/menuColors';
|
|
21
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/minimapColors';
|
|
22
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/miscColors';
|
|
23
|
+
import { quickInputForeground, quickInputBackground } from 'vscode/vscode/vs/platform/theme/common/colors/quickpickColors';
|
|
24
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/searchColors';
|
|
25
|
+
import { IChatWidgetService } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chat';
|
|
26
|
+
import { ChatWidget } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chatWidget';
|
|
27
|
+
import { ChatAgentLocation } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
28
|
+
import { IChatService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService';
|
|
29
|
+
|
|
30
|
+
var QuickChat_1;
|
|
31
|
+
let QuickChatService = class QuickChatService extends Disposable {
|
|
32
|
+
constructor(quickInputService, chatService, instantiationService) {
|
|
33
|
+
super();
|
|
34
|
+
this.quickInputService = quickInputService;
|
|
35
|
+
this.chatService = chatService;
|
|
36
|
+
this.instantiationService = instantiationService;
|
|
37
|
+
this._onDidClose = this._register(( new Emitter()));
|
|
38
|
+
this.onDidClose = this._onDidClose.event;
|
|
39
|
+
}
|
|
40
|
+
get enabled() {
|
|
41
|
+
return this.chatService.getProviderInfos().length > 0;
|
|
42
|
+
}
|
|
43
|
+
get focused() {
|
|
44
|
+
const widget = this._input?.widget;
|
|
45
|
+
if (!widget) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return isAncestorOfActiveElement(widget);
|
|
49
|
+
}
|
|
50
|
+
toggle(providerId, options) {
|
|
51
|
+
if (this.focused && !options?.query) {
|
|
52
|
+
this.close();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.open(providerId, options);
|
|
56
|
+
if (options?.isPartialQuery) {
|
|
57
|
+
const disposable = this._store.add(Event.once(this.onDidClose)(() => {
|
|
58
|
+
this._currentChat?.clearValue();
|
|
59
|
+
this._store.delete(disposable);
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
open(providerId, options) {
|
|
65
|
+
if (this._input) {
|
|
66
|
+
if (this._currentChat && options?.query) {
|
|
67
|
+
this._currentChat.focus();
|
|
68
|
+
this._currentChat.setValue(options.query, options.selection);
|
|
69
|
+
if (!options.isPartialQuery) {
|
|
70
|
+
this._currentChat.acceptInput();
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
return this.focus();
|
|
75
|
+
}
|
|
76
|
+
const providerInfo = providerId
|
|
77
|
+
? this.chatService.getProviderInfos().find(info => info.id === providerId)
|
|
78
|
+
: this.chatService.getProviderInfos()[0];
|
|
79
|
+
if (!providerInfo) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const disposableStore = ( new DisposableStore());
|
|
83
|
+
this._input = this.quickInputService.createQuickWidget();
|
|
84
|
+
this._input.contextKey = 'chatInputVisible';
|
|
85
|
+
this._input.ignoreFocusOut = true;
|
|
86
|
+
disposableStore.add(this._input);
|
|
87
|
+
this._container ??= $('.interactive-session');
|
|
88
|
+
this._input.widget = this._container;
|
|
89
|
+
this._input.show();
|
|
90
|
+
if (!this._currentChat) {
|
|
91
|
+
this._currentChat = this.instantiationService.createInstance(QuickChat, {
|
|
92
|
+
providerId: providerInfo.id,
|
|
93
|
+
});
|
|
94
|
+
this._currentChat.render(this._container);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this._currentChat.show();
|
|
98
|
+
}
|
|
99
|
+
disposableStore.add(this._input.onDidHide(() => {
|
|
100
|
+
disposableStore.dispose();
|
|
101
|
+
this._currentChat.hide();
|
|
102
|
+
this._input = undefined;
|
|
103
|
+
this._onDidClose.fire();
|
|
104
|
+
}));
|
|
105
|
+
this._currentChat.focus();
|
|
106
|
+
if (options?.query) {
|
|
107
|
+
this._currentChat.setValue(options.query, options.selection);
|
|
108
|
+
if (!options.isPartialQuery) {
|
|
109
|
+
this._currentChat.acceptInput();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
focus() {
|
|
114
|
+
this._currentChat?.focus();
|
|
115
|
+
}
|
|
116
|
+
close() {
|
|
117
|
+
this._input?.dispose();
|
|
118
|
+
this._input = undefined;
|
|
119
|
+
}
|
|
120
|
+
async openInChatView() {
|
|
121
|
+
await this._currentChat?.openChatView();
|
|
122
|
+
this.close();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
QuickChatService = ( __decorate([
|
|
126
|
+
( __param(0, IQuickInputService)),
|
|
127
|
+
( __param(1, IChatService)),
|
|
128
|
+
( __param(2, IInstantiationService))
|
|
129
|
+
], QuickChatService));
|
|
130
|
+
let QuickChat = class QuickChat extends Disposable {
|
|
131
|
+
static { QuickChat_1 = this; }
|
|
132
|
+
static { this.DEFAULT_MIN_HEIGHT = 200; }
|
|
133
|
+
static { this.DEFAULT_HEIGHT_OFFSET = 100; }
|
|
134
|
+
constructor(_options, instantiationService, contextKeyService, chatService, _chatWidgetService, layoutService) {
|
|
135
|
+
super();
|
|
136
|
+
this._options = _options;
|
|
137
|
+
this.instantiationService = instantiationService;
|
|
138
|
+
this.contextKeyService = contextKeyService;
|
|
139
|
+
this.chatService = chatService;
|
|
140
|
+
this._chatWidgetService = _chatWidgetService;
|
|
141
|
+
this.layoutService = layoutService;
|
|
142
|
+
this.maintainScrollTimer = this._register(( new MutableDisposable()));
|
|
143
|
+
this._deferUpdatingDynamicLayout = false;
|
|
144
|
+
}
|
|
145
|
+
clear() {
|
|
146
|
+
this.model?.dispose();
|
|
147
|
+
this.model = undefined;
|
|
148
|
+
this.updateModel();
|
|
149
|
+
this.widget.inputEditor.setValue('');
|
|
150
|
+
}
|
|
151
|
+
focus(selection) {
|
|
152
|
+
if (this.widget) {
|
|
153
|
+
this.widget.focusInput();
|
|
154
|
+
const value = this.widget.inputEditor.getValue();
|
|
155
|
+
if (value) {
|
|
156
|
+
this.widget.inputEditor.setSelection(selection ?? {
|
|
157
|
+
startLineNumber: 1,
|
|
158
|
+
startColumn: 1,
|
|
159
|
+
endLineNumber: 1,
|
|
160
|
+
endColumn: value.length + 1
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
hide() {
|
|
166
|
+
this.widget.setVisible(false);
|
|
167
|
+
this.maintainScrollTimer.value = disposableTimeout(() => {
|
|
168
|
+
this.maintainScrollTimer.clear();
|
|
169
|
+
}, 30 * 1000);
|
|
170
|
+
}
|
|
171
|
+
show() {
|
|
172
|
+
this.widget.setVisible(true);
|
|
173
|
+
if (this._deferUpdatingDynamicLayout) {
|
|
174
|
+
this._deferUpdatingDynamicLayout = false;
|
|
175
|
+
this.widget.updateDynamicChatTreeItemLayout(2, this.maxHeight);
|
|
176
|
+
}
|
|
177
|
+
if (!this.maintainScrollTimer.value) {
|
|
178
|
+
this.widget.layoutDynamicChatTreeItemMode();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
render(parent) {
|
|
182
|
+
if (this.widget) {
|
|
183
|
+
throw new Error('Cannot render quick chat twice');
|
|
184
|
+
}
|
|
185
|
+
const scopedInstantiationService = this.instantiationService.createChild(( new ServiceCollection([
|
|
186
|
+
IContextKeyService,
|
|
187
|
+
this._register(this.contextKeyService.createScoped(parent))
|
|
188
|
+
])));
|
|
189
|
+
this.widget = this._register(scopedInstantiationService.createInstance(ChatWidget, ChatAgentLocation.Panel, { resource: true }, { renderInputOnTop: true, renderStyle: 'compact', menus: { inputSideToolbar: MenuId.ChatInputSide } }, {
|
|
190
|
+
listForeground: quickInputForeground,
|
|
191
|
+
listBackground: quickInputBackground,
|
|
192
|
+
inputEditorBackground: inputBackground,
|
|
193
|
+
resultEditorBackground: editorBackground
|
|
194
|
+
}));
|
|
195
|
+
this.widget.render(parent);
|
|
196
|
+
this.widget.setVisible(true);
|
|
197
|
+
this.widget.setDynamicChatTreeItemLayout(2, this.maxHeight);
|
|
198
|
+
this.updateModel();
|
|
199
|
+
this.sash = this._register(( new Sash(
|
|
200
|
+
parent,
|
|
201
|
+
{ getHorizontalSashTop: () => parent.offsetHeight },
|
|
202
|
+
{ orientation: 1 }
|
|
203
|
+
)));
|
|
204
|
+
this.registerListeners(parent);
|
|
205
|
+
}
|
|
206
|
+
get maxHeight() {
|
|
207
|
+
return this.layoutService.mainContainerDimension.height - QuickChat_1.DEFAULT_HEIGHT_OFFSET;
|
|
208
|
+
}
|
|
209
|
+
registerListeners(parent) {
|
|
210
|
+
this._register(this.layoutService.onDidLayoutMainContainer(() => {
|
|
211
|
+
if (this.widget.visible) {
|
|
212
|
+
this.widget.updateDynamicChatTreeItemLayout(2, this.maxHeight);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
this._deferUpdatingDynamicLayout = true;
|
|
216
|
+
}
|
|
217
|
+
}));
|
|
218
|
+
this._register(this.widget.inputEditor.onDidChangeModelContent((e) => {
|
|
219
|
+
this._currentQuery = this.widget.inputEditor.getValue();
|
|
220
|
+
}));
|
|
221
|
+
this._register(this.widget.onDidClear(() => this.clear()));
|
|
222
|
+
this._register(this.widget.onDidChangeHeight((e) => this.sash.layout()));
|
|
223
|
+
const width = parent.offsetWidth;
|
|
224
|
+
this._register(this.sash.onDidStart(() => {
|
|
225
|
+
this.widget.isDynamicChatTreeItemLayoutEnabled = false;
|
|
226
|
+
}));
|
|
227
|
+
this._register(this.sash.onDidChange((e) => {
|
|
228
|
+
if (e.currentY < QuickChat_1.DEFAULT_MIN_HEIGHT || e.currentY > this.maxHeight) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
this.widget.layout(e.currentY, width);
|
|
232
|
+
this.sash.layout();
|
|
233
|
+
}));
|
|
234
|
+
this._register(this.sash.onDidReset(() => {
|
|
235
|
+
this.widget.isDynamicChatTreeItemLayoutEnabled = true;
|
|
236
|
+
this.widget.layoutDynamicChatTreeItemMode();
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
async acceptInput() {
|
|
240
|
+
return this.widget.acceptInput();
|
|
241
|
+
}
|
|
242
|
+
async openChatView() {
|
|
243
|
+
const widget = await this._chatWidgetService.revealViewForProvider(this._options.providerId);
|
|
244
|
+
if (!widget?.viewModel || !this.model) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
for (const request of this.model.getRequests()) {
|
|
248
|
+
if (request.response?.response.value || request.response?.result) {
|
|
249
|
+
this.chatService.addCompleteRequest(widget.viewModel.sessionId, request.message, request.variableData, {
|
|
250
|
+
message: request.response.response.value,
|
|
251
|
+
result: request.response.result,
|
|
252
|
+
followups: request.response.followups
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const value = this.widget.inputEditor.getValue();
|
|
257
|
+
if (value) {
|
|
258
|
+
widget.inputEditor.setValue(value);
|
|
259
|
+
}
|
|
260
|
+
widget.focusInput();
|
|
261
|
+
}
|
|
262
|
+
setValue(value, selection) {
|
|
263
|
+
this.widget.inputEditor.setValue(value);
|
|
264
|
+
this.focus(selection);
|
|
265
|
+
}
|
|
266
|
+
clearValue() {
|
|
267
|
+
this.widget.inputEditor.setValue('');
|
|
268
|
+
}
|
|
269
|
+
updateModel() {
|
|
270
|
+
this.model ??= this.chatService.startSession(this._options.providerId, CancellationToken.None);
|
|
271
|
+
if (!this.model) {
|
|
272
|
+
throw new Error('Could not start chat session');
|
|
273
|
+
}
|
|
274
|
+
this.widget.setModel(this.model, { inputValue: this._currentQuery });
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
QuickChat = QuickChat_1 = ( __decorate([
|
|
278
|
+
( __param(1, IInstantiationService)),
|
|
279
|
+
( __param(2, IContextKeyService)),
|
|
280
|
+
( __param(3, IChatService)),
|
|
281
|
+
( __param(4, IChatWidgetService)),
|
|
282
|
+
( __param(5, ILayoutService))
|
|
283
|
+
], QuickChat));
|
|
284
|
+
|
|
285
|
+
export { QuickChatService };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { coalesce } from 'vscode/vscode/vs/base/common/arrays';
|
|
3
|
+
import { onUnexpectedExternalError } from 'vscode/vscode/vs/base/common/errors';
|
|
4
|
+
import { Iterable } from 'vscode/vscode/vs/base/common/iterator';
|
|
5
|
+
import { toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
6
|
+
import { IChatWidgetService } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chat';
|
|
7
|
+
import { ChatDynamicVariableModel } from 'vscode/vscode/vs/workbench/contrib/chat/browser/contrib/chatDynamicVariables';
|
|
8
|
+
import { ChatRequestVariablePart, ChatRequestDynamicVariablePart } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatParserTypes';
|
|
9
|
+
|
|
10
|
+
let ChatVariablesService = class ChatVariablesService {
|
|
11
|
+
constructor(chatWidgetService) {
|
|
12
|
+
this.chatWidgetService = chatWidgetService;
|
|
13
|
+
this._resolver = ( new Map());
|
|
14
|
+
}
|
|
15
|
+
async resolveVariables(prompt, model, progress, token) {
|
|
16
|
+
let resolvedVariables = [];
|
|
17
|
+
const jobs = [];
|
|
18
|
+
prompt.parts
|
|
19
|
+
.forEach((part, i) => {
|
|
20
|
+
if (part instanceof ChatRequestVariablePart) {
|
|
21
|
+
const data = this._resolver.get(part.variableName.toLowerCase());
|
|
22
|
+
if (data) {
|
|
23
|
+
const references = [];
|
|
24
|
+
const variableProgressCallback = (item) => {
|
|
25
|
+
if (item.kind === 'reference') {
|
|
26
|
+
references.push(item);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
progress(item);
|
|
30
|
+
};
|
|
31
|
+
jobs.push(data.resolver(prompt.text, part.variableArg, model, variableProgressCallback, token).then(values => {
|
|
32
|
+
resolvedVariables[i] = { name: part.variableName, range: part.range, values: values ?? [], references };
|
|
33
|
+
}).catch(onUnexpectedExternalError));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (part instanceof ChatRequestDynamicVariablePart) {
|
|
37
|
+
resolvedVariables[i] = { name: part.referenceText, range: part.range, values: part.data };
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
await Promise.allSettled(jobs);
|
|
41
|
+
resolvedVariables = coalesce(resolvedVariables);
|
|
42
|
+
resolvedVariables.sort((a, b) => b.range.start - a.range.start);
|
|
43
|
+
return {
|
|
44
|
+
variables: resolvedVariables,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async resolveVariable(variableName, promptText, model, progress, token) {
|
|
48
|
+
const data = this._resolver.get(variableName.toLowerCase());
|
|
49
|
+
if (!data) {
|
|
50
|
+
return Promise.resolve([]);
|
|
51
|
+
}
|
|
52
|
+
return (await data.resolver(promptText, undefined, model, progress, token)) ?? [];
|
|
53
|
+
}
|
|
54
|
+
hasVariable(name) {
|
|
55
|
+
return ( this._resolver.has(name.toLowerCase()));
|
|
56
|
+
}
|
|
57
|
+
getVariable(name) {
|
|
58
|
+
return this._resolver.get(name.toLowerCase())?.data;
|
|
59
|
+
}
|
|
60
|
+
getVariables() {
|
|
61
|
+
const all = ( Iterable.map(( this._resolver.values()), data => data.data));
|
|
62
|
+
return Iterable.filter(all, data => !data.hidden);
|
|
63
|
+
}
|
|
64
|
+
getDynamicVariables(sessionId) {
|
|
65
|
+
const widget = this.chatWidgetService.getWidgetBySessionId(sessionId);
|
|
66
|
+
if (!widget || !widget.viewModel || !widget.supportsFileReferences) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const model = widget.getContrib(ChatDynamicVariableModel.ID);
|
|
70
|
+
if (!model) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
return model.variables;
|
|
74
|
+
}
|
|
75
|
+
registerVariable(data, resolver) {
|
|
76
|
+
const key = data.name.toLowerCase();
|
|
77
|
+
if (( this._resolver.has(key))) {
|
|
78
|
+
throw new Error(`A chat variable with the name '${data.name}' already exists.`);
|
|
79
|
+
}
|
|
80
|
+
this._resolver.set(key, { data, resolver });
|
|
81
|
+
return toDisposable(() => {
|
|
82
|
+
this._resolver.delete(key);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
ChatVariablesService = ( __decorate([
|
|
87
|
+
( __param(0, IChatWidgetService))
|
|
88
|
+
], ChatVariablesService));
|
|
89
|
+
|
|
90
|
+
export { ChatVariablesService };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { CancellationToken } from 'vscode/vscode/vs/base/common/cancellation';
|
|
3
|
+
import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
5
|
+
import { IContextKeyService } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
6
|
+
import { IContextMenuService } from 'vscode/vscode/vs/platform/contextview/browser/contextView';
|
|
7
|
+
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
8
|
+
import { ServiceCollection } from 'vscode/vscode/vs/platform/instantiation/common/serviceCollection';
|
|
9
|
+
import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
|
|
10
|
+
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
11
|
+
import { IOpenerService } from 'vscode/vscode/vs/platform/opener/common/opener';
|
|
12
|
+
import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
|
|
13
|
+
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
|
|
14
|
+
import 'vscode/vscode/vs/platform/theme/common/colorUtils';
|
|
15
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/baseColors';
|
|
16
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/chartsColors';
|
|
17
|
+
import { editorBackground } from 'vscode/vscode/vs/platform/theme/common/colors/editorColors';
|
|
18
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/inputColors';
|
|
19
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/listColors';
|
|
20
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/menuColors';
|
|
21
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/minimapColors';
|
|
22
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/miscColors';
|
|
23
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/quickpickColors';
|
|
24
|
+
import 'vscode/vscode/vs/platform/theme/common/colors/searchColors';
|
|
25
|
+
import { IThemeService } from 'vscode/vscode/vs/platform/theme/common/themeService';
|
|
26
|
+
import { ViewPane } from 'vscode/vscode/vs/workbench/browser/parts/views/viewPane';
|
|
27
|
+
import { Memento } from 'vscode/vscode/vs/workbench/common/memento';
|
|
28
|
+
import { SIDE_BAR_FOREGROUND } from 'vscode/vscode/vs/workbench/common/theme';
|
|
29
|
+
import { IViewDescriptorService } from 'vscode/vscode/vs/workbench/common/views';
|
|
30
|
+
import { ChatWidget } from 'vscode/vscode/vs/workbench/contrib/chat/browser/chatWidget';
|
|
31
|
+
import { ChatAgentLocation } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatAgents';
|
|
32
|
+
import { IChatService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatService';
|
|
33
|
+
|
|
34
|
+
const CHAT_SIDEBAR_PANEL_ID = 'workbench.panel.chatSidebar';
|
|
35
|
+
let ChatViewPane = class ChatViewPane extends ViewPane {
|
|
36
|
+
static { this.ID = 'workbench.panel.chat.view'; }
|
|
37
|
+
get widget() { return this._widget; }
|
|
38
|
+
constructor(chatViewOptions, options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, storageService, chatService, logService) {
|
|
39
|
+
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
|
|
40
|
+
this.chatViewOptions = chatViewOptions;
|
|
41
|
+
this.storageService = storageService;
|
|
42
|
+
this.chatService = chatService;
|
|
43
|
+
this.logService = logService;
|
|
44
|
+
this.modelDisposables = this._register(( new DisposableStore()));
|
|
45
|
+
this.didProviderRegistrationFail = false;
|
|
46
|
+
this.didUnregisterProvider = false;
|
|
47
|
+
this.memento = ( new Memento(
|
|
48
|
+
'interactive-session-view-' + this.chatViewOptions.providerId,
|
|
49
|
+
this.storageService
|
|
50
|
+
));
|
|
51
|
+
this.viewState = this.memento.getMemento(1 , 1 );
|
|
52
|
+
this._register(this.chatService.onDidRegisterProvider(({ providerId }) => {
|
|
53
|
+
if (providerId === this.chatViewOptions.providerId && !this._widget?.viewModel) {
|
|
54
|
+
const sessionId = this.getSessionId();
|
|
55
|
+
const model = sessionId ? this.chatService.getOrRestoreSession(sessionId) : undefined;
|
|
56
|
+
try {
|
|
57
|
+
this._widget.setVisible(false);
|
|
58
|
+
this.updateModel(model);
|
|
59
|
+
this.didProviderRegistrationFail = false;
|
|
60
|
+
this.didUnregisterProvider = false;
|
|
61
|
+
this._onDidChangeViewWelcomeState.fire();
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
this.widget.setVisible(true);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
this._register(this.chatService.onDidUnregisterProvider(({ providerId }) => {
|
|
69
|
+
if (providerId === this.chatViewOptions.providerId) {
|
|
70
|
+
this.didUnregisterProvider = true;
|
|
71
|
+
this._onDidChangeViewWelcomeState.fire();
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
updateModel(model, viewState) {
|
|
76
|
+
this.modelDisposables.clear();
|
|
77
|
+
model = model ?? (this.chatService.transferredSessionData?.sessionId
|
|
78
|
+
? this.chatService.getOrRestoreSession(this.chatService.transferredSessionData.sessionId)
|
|
79
|
+
: this.chatService.startSession(this.chatViewOptions.providerId, CancellationToken.None));
|
|
80
|
+
if (!model) {
|
|
81
|
+
throw new Error('Could not start chat session');
|
|
82
|
+
}
|
|
83
|
+
this._widget.setModel(model, { ...(viewState ?? this.viewState) });
|
|
84
|
+
this.viewState.sessionId = model.sessionId;
|
|
85
|
+
}
|
|
86
|
+
shouldShowWelcome() {
|
|
87
|
+
const noPersistedSessions = !this.chatService.hasSessions(this.chatViewOptions.providerId);
|
|
88
|
+
return this.didUnregisterProvider || !this._widget?.viewModel && (noPersistedSessions || this.didProviderRegistrationFail);
|
|
89
|
+
}
|
|
90
|
+
getSessionId() {
|
|
91
|
+
let sessionId;
|
|
92
|
+
if (this.chatService.transferredSessionData) {
|
|
93
|
+
sessionId = this.chatService.transferredSessionData.sessionId;
|
|
94
|
+
this.viewState.inputValue = this.chatService.transferredSessionData.inputValue;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
sessionId = this.viewState.sessionId;
|
|
98
|
+
}
|
|
99
|
+
return sessionId;
|
|
100
|
+
}
|
|
101
|
+
renderBody(parent) {
|
|
102
|
+
try {
|
|
103
|
+
super.renderBody(parent);
|
|
104
|
+
const scopedInstantiationService = this.instantiationService.createChild(( new ServiceCollection([IContextKeyService, this.scopedContextKeyService])));
|
|
105
|
+
this._widget = this._register(scopedInstantiationService.createInstance(ChatWidget, ChatAgentLocation.Panel, { viewId: this.id }, { supportsFileReferences: true }, {
|
|
106
|
+
listForeground: SIDE_BAR_FOREGROUND,
|
|
107
|
+
listBackground: this.getBackgroundColor(),
|
|
108
|
+
inputEditorBackground: this.getBackgroundColor(),
|
|
109
|
+
resultEditorBackground: editorBackground
|
|
110
|
+
}));
|
|
111
|
+
this._register(this.onDidChangeBodyVisibility(visible => {
|
|
112
|
+
this._widget.setVisible(visible);
|
|
113
|
+
}));
|
|
114
|
+
this._register(this._widget.onDidClear(() => this.clear()));
|
|
115
|
+
this._widget.render(parent);
|
|
116
|
+
const sessionId = this.getSessionId();
|
|
117
|
+
const disposeListener = sessionId ? this._register(this.chatService.onDidDisposeSession((e) => {
|
|
118
|
+
if (e.reason === 'initializationFailed' && e.providerId === this.chatViewOptions.providerId) {
|
|
119
|
+
this.didProviderRegistrationFail = true;
|
|
120
|
+
disposeListener?.dispose();
|
|
121
|
+
this._onDidChangeViewWelcomeState.fire();
|
|
122
|
+
}
|
|
123
|
+
})) : undefined;
|
|
124
|
+
const model = sessionId ? this.chatService.getOrRestoreSession(sessionId) : undefined;
|
|
125
|
+
this.updateModel(model);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
this.logService.error(e);
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
acceptInput(query) {
|
|
133
|
+
this._widget.acceptInput(query);
|
|
134
|
+
}
|
|
135
|
+
async clear() {
|
|
136
|
+
if (this.widget.viewModel) {
|
|
137
|
+
this.chatService.clearSession(this.widget.viewModel.sessionId);
|
|
138
|
+
}
|
|
139
|
+
this.updateModel(undefined, { ...this.viewState, inputValue: undefined });
|
|
140
|
+
}
|
|
141
|
+
loadSession(sessionId) {
|
|
142
|
+
if (this.widget.viewModel) {
|
|
143
|
+
this.chatService.clearSession(this.widget.viewModel.sessionId);
|
|
144
|
+
}
|
|
145
|
+
const newModel = this.chatService.getOrRestoreSession(sessionId);
|
|
146
|
+
this.updateModel(newModel);
|
|
147
|
+
}
|
|
148
|
+
focusInput() {
|
|
149
|
+
this._widget.focusInput();
|
|
150
|
+
}
|
|
151
|
+
focus() {
|
|
152
|
+
super.focus();
|
|
153
|
+
this._widget.focusInput();
|
|
154
|
+
}
|
|
155
|
+
layoutBody(height, width) {
|
|
156
|
+
super.layoutBody(height, width);
|
|
157
|
+
this._widget.layout(height, width);
|
|
158
|
+
}
|
|
159
|
+
saveState() {
|
|
160
|
+
if (this._widget) {
|
|
161
|
+
this._widget.saveState();
|
|
162
|
+
const widgetViewState = this._widget.getViewState();
|
|
163
|
+
this.viewState.inputValue = widgetViewState.inputValue;
|
|
164
|
+
this.viewState.inputState = widgetViewState.inputState;
|
|
165
|
+
this.memento.saveMemento();
|
|
166
|
+
}
|
|
167
|
+
super.saveState();
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
ChatViewPane = ( __decorate([
|
|
171
|
+
( __param(2, IKeybindingService)),
|
|
172
|
+
( __param(3, IContextMenuService)),
|
|
173
|
+
( __param(4, IConfigurationService)),
|
|
174
|
+
( __param(5, IContextKeyService)),
|
|
175
|
+
( __param(6, IViewDescriptorService)),
|
|
176
|
+
( __param(7, IInstantiationService)),
|
|
177
|
+
( __param(8, IOpenerService)),
|
|
178
|
+
( __param(9, IThemeService)),
|
|
179
|
+
( __param(10, ITelemetryService)),
|
|
180
|
+
( __param(11, IStorageService)),
|
|
181
|
+
( __param(12, IChatService)),
|
|
182
|
+
( __param(13, ILogService))
|
|
183
|
+
], ChatViewPane));
|
|
184
|
+
|
|
185
|
+
export { CHAT_SIDEBAR_PANEL_ID, ChatViewPane };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
3
|
+
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
|
|
4
|
+
import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
|
|
5
|
+
import { IChatVariablesService } from 'vscode/vscode/vs/workbench/contrib/chat/common/chatVariables';
|
|
6
|
+
|
|
7
|
+
let ChatHistoryVariables = class ChatHistoryVariables extends Disposable {
|
|
8
|
+
constructor(chatVariablesService) {
|
|
9
|
+
super();
|
|
10
|
+
this._register(chatVariablesService.registerVariable({ name: 'response', description: '', canTakeArgument: true, hidden: true }, async (message, arg, model, progress, token) => {
|
|
11
|
+
if (!arg) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const responseNum = parseInt(arg, 10);
|
|
15
|
+
const response = model.getRequests()[responseNum - 1].response;
|
|
16
|
+
if (!response) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
return [{ level: 'full', value: response.response.asString() }];
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
ChatHistoryVariables = ( __decorate([
|
|
24
|
+
( __param(0, IChatVariablesService))
|
|
25
|
+
], ChatHistoryVariables));
|
|
26
|
+
( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(ChatHistoryVariables, 4 );
|