@codingame/monaco-vscode-chat-service-override 14.0.6 → 15.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/index.js +14 -8
- package/package.json +20 -20
- package/vscode/src/vs/base/common/objectCache.d.ts +1 -1
- package/vscode/src/vs/base/common/objectCache.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAccessibilityHelp.js +43 -42
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/chatAttachPromptAction.d.ts +10 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/chatAttachPromptAction.js +40 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt.d.ts +17 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatAttachPromptAction/dialogs/askToSelectPrompt.js +142 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.d.ts +2 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCodeblockActions.js +25 -25
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.d.ts +2 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatContextActions.js +252 -260
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatCopyActions.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatDeveloperActions.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatFileTreeActions.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.d.ts +3 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatGettingStarted.js +8 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.js +6 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatMoveActions.js +6 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/chatQuickInputActions.js +12 -41
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.d.ts +7 -5
- package/vscode/src/vs/workbench/contrib/chat/browser/actions/codeBlockOperations.js +31 -29
- package/vscode/src/vs/workbench/contrib/chat/browser/chat.contribution.js +151 -69
- package/vscode/src/vs/workbench/contrib/chat/browser/chatAccessibilityService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatContentParts/chatMarkdownAnchorService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEdinputInputContentProvider.d.ts +4 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEdinputInputContentProvider.js +4 -4
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorAccessibility.d.ts +10 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorAccessibility.js +38 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorOverlay.d.ts +9 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingEditorOverlay.js +379 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/{chatEditingService.d.ts → chatEditingServiceImpl.d.ts} +12 -28
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingServiceImpl.js +423 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.d.ts +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditor.js +6 -7
- package/vscode/src/vs/workbench/contrib/chat/browser/chatParticipant.contribution.js +38 -38
- package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.d.ts +16 -6
- package/vscode/src/vs/workbench/contrib/chat/browser/chatPasteProviders.js +93 -24
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatQuick.js +21 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatResponseAccessibleView.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.d.ts +101 -2
- package/vscode/src/vs/workbench/contrib/chat/browser/chatSetup.js +146 -126
- package/vscode/src/vs/workbench/contrib/chat/browser/chatStatus.d.ts +39 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatStatus.js +386 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.d.ts +4 -12
- package/vscode/src/vs/workbench/contrib/chat/browser/chatVariables.js +8 -91
- package/vscode/src/vs/workbench/contrib/chat/browser/codeBlockContextProviderService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.js +7 -11
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorHover.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/chatInputRelatedFilesContrib.js +45 -45
- package/vscode/src/vs/workbench/contrib/chat/browser/contrib/editorHoverWrapper.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/browser/languageModelToolsService.js +11 -19
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatEditingEditorOverlay.css.js +6 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/media/chatStatus.css.js +6 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/createPromptCommand.d.ts +1 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/createPromptCommand.js +82 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/dialogs/askForPromptName.d.ts +2 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/dialogs/askForPromptName.js +22 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/dialogs/askForPromptSourceFolder.d.ts +16 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/dialogs/askForPromptSourceFolder.js +67 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/errors.d.ts +9 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/errors.js +17 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/utils/createPromptFile.d.ts +12 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/createPromptCommand/utils/createPromptFile.js +24 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/usePromptCommand.d.ts +6 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/promptSyntax/contributions/usePromptCommand.js +78 -0
- package/vscode/src/vs/workbench/contrib/chat/browser/viewsWelcome/chatViewsWelcomeHandler.js +6 -6
- package/vscode/src/vs/workbench/contrib/chat/common/chatCodeMapperService.d.ts +2 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatEntitlementsService.d.ts +19 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatEntitlementsService.js +13 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.d.ts +12 -10
- package/vscode/src/vs/workbench/contrib/chat/common/chatProgressTypes/chatToolInvocation.js +26 -13
- package/vscode/src/vs/workbench/contrib/chat/common/chatQuotasService.d.ts +31 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatQuotasService.js +85 -0
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.d.ts +6 -2
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceImpl.js +33 -27
- package/vscode/src/vs/workbench/contrib/chat/common/chatServiceTelemetry.js +0 -10
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/constants.d.ts +4 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/constants.js +9 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/textModelContentsProvider.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/contentProviders/textModelContentsProvider.js +1 -1
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkProvider.d.ts +4 -6
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptLinkProvider.js +15 -23
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptPathAutocompletion.d.ts +22 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptPathAutocompletion.js +175 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/textModelPromptParser.d.ts +2 -3
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/parsers/textModelPromptParser.js +6 -7
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsService.d.ts +20 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/service/promptsService.js +62 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.d.ts +14 -0
- package/vscode/src/vs/workbench/contrib/chat/common/promptSyntax/utils/promptFilesLocator.js +101 -0
- package/vscode/src/vs/workbench/contrib/chat/common/tools/languageModelToolsContribution.js +17 -17
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/chat/common/voiceChatService.js +2 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChat.contribution.js +12 -12
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibilityHelp.js +2 -2
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatAccessibleView.js +4 -4
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.d.ts +1 -1
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatCurrentLine.js +31 -36
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatNotebook.js +3 -3
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingService.js +0 -505
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.d.ts +0 -104
- package/vscode/src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingSession.js +0 -871
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.d.ts +0 -54
- package/vscode/src/vs/workbench/contrib/chat/browser/chatViewPane.js +0 -245
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.d.ts +0 -39
- package/vscode/src/vs/workbench/contrib/inlineChat/browser/inlineChatController2.js +0 -314
|
@@ -1,871 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
-
import { Sequencer, timeout } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
|
4
|
-
import { VSBuffer } from '@codingame/monaco-vscode-api/vscode/vs/base/common/buffer';
|
|
5
|
-
import { BugIndicatingError } from '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
|
|
6
|
-
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
7
|
-
import { StringSHA1 } from '@codingame/monaco-vscode-api/vscode/vs/base/common/hash';
|
|
8
|
-
import { Disposable, DisposableMap, dispose, DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
9
|
-
import { ResourceMap, ResourceSet } from '@codingame/monaco-vscode-api/vscode/vs/base/common/map';
|
|
10
|
-
import { Schemas } from '@codingame/monaco-vscode-api/vscode/vs/base/common/network';
|
|
11
|
-
import { observableValue, transaction, asyncTransaction } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/base';
|
|
12
|
-
import '@codingame/monaco-vscode-api/vscode/vs/base/common/arrays';
|
|
13
|
-
import { autorun, autorunDelta, autorunIterableDelta } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/autorun';
|
|
14
|
-
import { derived } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/derived';
|
|
15
|
-
import '@codingame/monaco-vscode-api/vscode/vs/base/common/cancellation';
|
|
16
|
-
import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/utils';
|
|
17
|
-
import { isEqual, joinPath } from '@codingame/monaco-vscode-api/vscode/vs/base/common/resources';
|
|
18
|
-
import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
|
|
19
|
-
import { isDiffEditor, isCodeEditor } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/editorBrowser';
|
|
20
|
-
import { IBulkEditService } from '@codingame/monaco-vscode-api/vscode/vs/editor/browser/services/bulkEditService';
|
|
21
|
-
import { OffsetEdit } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/core/offsetEdit';
|
|
22
|
-
import { ILanguageService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language';
|
|
23
|
-
import { IModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/model';
|
|
24
|
-
import { ITextModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/resolverService';
|
|
25
|
-
import { localize } from '@codingame/monaco-vscode-api/vscode/vs/nls';
|
|
26
|
-
import { EditorActivation } from '@codingame/monaco-vscode-api/vscode/vs/platform/editor/common/editor';
|
|
27
|
-
import { IEnvironmentService } from '@codingame/monaco-vscode-api/vscode/vs/platform/environment/common/environment.service';
|
|
28
|
-
import { IFileService } from '@codingame/monaco-vscode-api/vscode/vs/platform/files/common/files.service';
|
|
29
|
-
import { IInstantiationService } from '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
|
|
30
|
-
import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
|
|
31
|
-
import { IWorkspaceContextService } from '@codingame/monaco-vscode-api/vscode/vs/platform/workspace/common/workspace.service';
|
|
32
|
-
import { SaveReason } from '@codingame/monaco-vscode-api/vscode/vs/workbench/common/editor';
|
|
33
|
-
import { DiffEditorInput } from '@codingame/monaco-vscode-4a28f637-7c3c-5e48-a77c-1b7538b38850-common/vscode/vs/workbench/common/editor/diffEditorInput';
|
|
34
|
-
import { IEditorGroupsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService.service';
|
|
35
|
-
import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
|
|
36
|
-
import { ITextFileService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/textfile/common/textfiles.service';
|
|
37
|
-
import { MultiDiffEditorInput } from '@codingame/monaco-vscode-168b98e5-dc20-5807-b1f9-798f1f92b37f-common/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditorInput';
|
|
38
|
-
import { isNotebookEditorInput } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookEditorInput';
|
|
39
|
-
import { INotebookService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/notebook/common/notebookService.service';
|
|
40
|
-
import { IChatAgentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatAgents.service';
|
|
41
|
-
import { ChatEditingSessionState, ChatEditingSessionChangeType, WorkingSetEntryState, WorkingSetEntryRemovalReason, getMultiDiffSourceUri, ChatEditKind } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatEditingService';
|
|
42
|
-
import { IChatService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/chat/common/chatService.service';
|
|
43
|
-
import { ChatEditingModifiedFileEntry } from '@codingame/monaco-vscode-e4d0fd26-1b26-5583-b3f7-582e08d7b389-common/vscode/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedFileEntry';
|
|
44
|
-
import { ChatEditingModifiedNotebookEntry } from '@codingame/monaco-vscode-e4d0fd26-1b26-5583-b3f7-582e08d7b389-common/vscode/vs/workbench/contrib/chat/browser/chatEditing/chatEditingModifiedNotebookEntry';
|
|
45
|
-
import { ChatEditingTextModelContentProvider } from '@codingame/monaco-vscode-e4d0fd26-1b26-5583-b3f7-582e08d7b389-common/vscode/vs/workbench/contrib/chat/browser/chatEditing/chatEditingTextModelContentProviders';
|
|
46
|
-
|
|
47
|
-
const STORAGE_CONTENTS_FOLDER = 'contents';
|
|
48
|
-
const STORAGE_STATE_FILE = 'state.json';
|
|
49
|
-
class ThrottledSequencer extends Sequencer {
|
|
50
|
-
constructor(_minDuration, _maxOverallDelay) {
|
|
51
|
-
super();
|
|
52
|
-
this._minDuration = _minDuration;
|
|
53
|
-
this._maxOverallDelay = _maxOverallDelay;
|
|
54
|
-
this._size = 0;
|
|
55
|
-
}
|
|
56
|
-
queue(promiseTask) {
|
|
57
|
-
this._size += 1;
|
|
58
|
-
const noDelay = this._size * this._minDuration > this._maxOverallDelay;
|
|
59
|
-
return super.queue(async () => {
|
|
60
|
-
try {
|
|
61
|
-
const p1 = promiseTask();
|
|
62
|
-
const p2 = noDelay
|
|
63
|
-
? Promise.resolve(undefined)
|
|
64
|
-
: timeout(this._minDuration);
|
|
65
|
-
const [result] = await Promise.all([p1, p2]);
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
this._size -= 1;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
let ChatEditingSession = class ChatEditingSession extends Disposable {
|
|
75
|
-
get entries() {
|
|
76
|
-
this._assertNotDisposed();
|
|
77
|
-
return this._entriesObs;
|
|
78
|
-
}
|
|
79
|
-
get workingSet() {
|
|
80
|
-
this._assertNotDisposed();
|
|
81
|
-
const result = ( new ResourceMap(this._workingSet));
|
|
82
|
-
for (const entry of this._entriesObs.get()) {
|
|
83
|
-
result.set(entry.modifiedURI, { state: entry.state.get() });
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
get state() {
|
|
88
|
-
return this._state;
|
|
89
|
-
}
|
|
90
|
-
get onDidChange() {
|
|
91
|
-
this._assertNotDisposed();
|
|
92
|
-
return this._onDidChange.event;
|
|
93
|
-
}
|
|
94
|
-
get onDidDispose() {
|
|
95
|
-
this._assertNotDisposed();
|
|
96
|
-
return this._onDidDispose.event;
|
|
97
|
-
}
|
|
98
|
-
get isToolsAgentSession() {
|
|
99
|
-
return this._isToolsAgentSession;
|
|
100
|
-
}
|
|
101
|
-
constructor(chatSessionId, isGlobalEditingSession, editingSessionFileLimitPromise, _lookupExternalEntry, _instantiationService, _modelService, _languageService, _textModelService, _bulkEditService, _editorGroupsService, _editorService, _chatService, _notebookService, _textFileService, _chatAgentService) {
|
|
102
|
-
super();
|
|
103
|
-
this.chatSessionId = chatSessionId;
|
|
104
|
-
this.isGlobalEditingSession = isGlobalEditingSession;
|
|
105
|
-
this.editingSessionFileLimitPromise = editingSessionFileLimitPromise;
|
|
106
|
-
this._lookupExternalEntry = _lookupExternalEntry;
|
|
107
|
-
this._instantiationService = _instantiationService;
|
|
108
|
-
this._modelService = _modelService;
|
|
109
|
-
this._languageService = _languageService;
|
|
110
|
-
this._textModelService = _textModelService;
|
|
111
|
-
this._bulkEditService = _bulkEditService;
|
|
112
|
-
this._editorGroupsService = _editorGroupsService;
|
|
113
|
-
this._editorService = _editorService;
|
|
114
|
-
this._chatService = _chatService;
|
|
115
|
-
this._notebookService = _notebookService;
|
|
116
|
-
this._textFileService = _textFileService;
|
|
117
|
-
this._chatAgentService = _chatAgentService;
|
|
118
|
-
this._state = observableValue(this, ChatEditingSessionState.Initial);
|
|
119
|
-
this._linearHistory = observableValue(this, []);
|
|
120
|
-
this._linearHistoryIndex = observableValue(this, 0);
|
|
121
|
-
this._initialFileContents = ( new ResourceMap());
|
|
122
|
-
this._entriesObs = observableValue(this, []);
|
|
123
|
-
this._sequencer = ( new ThrottledSequencer(15, 1000));
|
|
124
|
-
this._workingSet = ( new ResourceMap());
|
|
125
|
-
this._removedTransientEntries = ( new ResourceSet());
|
|
126
|
-
this.canUndo = derived((r) => {
|
|
127
|
-
if (this.state.read(r) !== ChatEditingSessionState.Idle) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
const linearHistoryIndex = this._linearHistoryIndex.read(r);
|
|
131
|
-
return linearHistoryIndex > 0;
|
|
132
|
-
});
|
|
133
|
-
this.canRedo = derived((r) => {
|
|
134
|
-
if (this.state.read(r) !== ChatEditingSessionState.Idle) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
const linearHistory = this._linearHistory.read(r);
|
|
138
|
-
const linearHistoryIndex = this._linearHistoryIndex.read(r);
|
|
139
|
-
return linearHistoryIndex < linearHistory.length;
|
|
140
|
-
});
|
|
141
|
-
this.hiddenRequestIds = derived((r) => {
|
|
142
|
-
const linearHistory = this._linearHistory.read(r);
|
|
143
|
-
const linearHistoryIndex = this._linearHistoryIndex.read(r);
|
|
144
|
-
return ( linearHistory.slice(linearHistoryIndex).map(s => s.requestId)).filter((r) => !!r);
|
|
145
|
-
});
|
|
146
|
-
this._onDidChange = this._register(( new Emitter()));
|
|
147
|
-
this._onDidDispose = ( new Emitter());
|
|
148
|
-
this._isToolsAgentSession = false;
|
|
149
|
-
}
|
|
150
|
-
async init() {
|
|
151
|
-
const restoredSessionState = await this._instantiationService.createInstance(ChatEditingSessionStorage, this.chatSessionId).restoreState();
|
|
152
|
-
if (restoredSessionState) {
|
|
153
|
-
for (const [uri, content] of restoredSessionState.initialFileContents) {
|
|
154
|
-
this._initialFileContents.set(uri, content);
|
|
155
|
-
}
|
|
156
|
-
this._pendingSnapshot = restoredSessionState.pendingSnapshot;
|
|
157
|
-
await this._restoreSnapshot(restoredSessionState.recentSnapshot);
|
|
158
|
-
this._linearHistoryIndex.set(restoredSessionState.linearHistoryIndex, undefined);
|
|
159
|
-
this._linearHistory.set(restoredSessionState.linearHistory, undefined);
|
|
160
|
-
this._state.set(ChatEditingSessionState.Idle, undefined);
|
|
161
|
-
}
|
|
162
|
-
this._trackCurrentEditorsInWorkingSet();
|
|
163
|
-
this._triggerSaveParticipantsOnAccept();
|
|
164
|
-
this._register(this._editorService.onDidVisibleEditorsChange(() => {
|
|
165
|
-
this._trackCurrentEditorsInWorkingSet();
|
|
166
|
-
}));
|
|
167
|
-
this._register(autorun(reader => {
|
|
168
|
-
const entries = this.entries.read(reader);
|
|
169
|
-
entries.forEach(entry => {
|
|
170
|
-
entry.state.read(reader);
|
|
171
|
-
});
|
|
172
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
173
|
-
}));
|
|
174
|
-
}
|
|
175
|
-
getEntry(uri) {
|
|
176
|
-
return this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
177
|
-
}
|
|
178
|
-
readEntry(uri, reader) {
|
|
179
|
-
return this._entriesObs.read(reader).find(e => isEqual(e.modifiedURI, uri));
|
|
180
|
-
}
|
|
181
|
-
storeState() {
|
|
182
|
-
const storage = this._instantiationService.createInstance(ChatEditingSessionStorage, this.chatSessionId);
|
|
183
|
-
const state = {
|
|
184
|
-
initialFileContents: this._initialFileContents,
|
|
185
|
-
pendingSnapshot: this._pendingSnapshot,
|
|
186
|
-
recentSnapshot: this._createSnapshot(undefined),
|
|
187
|
-
linearHistoryIndex: this._linearHistoryIndex.get(),
|
|
188
|
-
linearHistory: this._linearHistory.get(),
|
|
189
|
-
};
|
|
190
|
-
return storage.storeState(state);
|
|
191
|
-
}
|
|
192
|
-
_triggerSaveParticipantsOnAccept() {
|
|
193
|
-
const im = this._register(( new DisposableMap()));
|
|
194
|
-
const attachToEntry = (entry) => {
|
|
195
|
-
return autorunDelta(entry.state, ({ lastValue, newValue }) => {
|
|
196
|
-
if (newValue === WorkingSetEntryState.Accepted && lastValue === WorkingSetEntryState.Modified) {
|
|
197
|
-
if (!this._textFileService.isDirty(entry.modifiedURI)) {
|
|
198
|
-
this._textFileService.save(entry.modifiedURI, {
|
|
199
|
-
reason: SaveReason.EXPLICIT,
|
|
200
|
-
force: true,
|
|
201
|
-
ignoreErrorHandler: true,
|
|
202
|
-
}).catch(() => {
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
this._register(autorunIterableDelta(reader => this._entriesObs.read(reader), ({ addedValues, removedValues }) => {
|
|
209
|
-
for (const entry of addedValues) {
|
|
210
|
-
im.set(entry, attachToEntry(entry));
|
|
211
|
-
}
|
|
212
|
-
for (const entry of removedValues) {
|
|
213
|
-
im.deleteAndDispose(entry);
|
|
214
|
-
}
|
|
215
|
-
}));
|
|
216
|
-
}
|
|
217
|
-
_trackCurrentEditorsInWorkingSet(e) {
|
|
218
|
-
const existingTransientEntries = ( new ResourceSet());
|
|
219
|
-
for (const file of ( this._workingSet.keys())) {
|
|
220
|
-
if (this._workingSet.get(file)?.state === WorkingSetEntryState.Transient) {
|
|
221
|
-
existingTransientEntries.add(file);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const activeEditors = ( new ResourceSet());
|
|
225
|
-
this._editorGroupsService.groups.forEach((group) => {
|
|
226
|
-
if (!group.activeEditorPane) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
let uri;
|
|
230
|
-
if (isNotebookEditorInput(group.activeEditorPane.input)) {
|
|
231
|
-
uri = group.activeEditorPane.input.resource;
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
let activeEditorControl = group.activeEditorPane.getControl();
|
|
235
|
-
if (isDiffEditor(activeEditorControl)) {
|
|
236
|
-
activeEditorControl = activeEditorControl.getOriginalEditor().hasTextFocus() ? activeEditorControl.getOriginalEditor() : activeEditorControl.getModifiedEditor();
|
|
237
|
-
}
|
|
238
|
-
if ((isCodeEditor(activeEditorControl)) && activeEditorControl.hasModel()) {
|
|
239
|
-
uri = activeEditorControl.getModel().uri;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (!uri) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (( existingTransientEntries.has(uri))) {
|
|
246
|
-
existingTransientEntries.delete(uri);
|
|
247
|
-
}
|
|
248
|
-
else if ((!( this._workingSet.has(uri)) || this._workingSet.get(uri)?.state === WorkingSetEntryState.Suggested) && !( this._removedTransientEntries.has(uri))) {
|
|
249
|
-
activeEditors.add(uri);
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
let didChange = false;
|
|
253
|
-
for (const entry of existingTransientEntries) {
|
|
254
|
-
didChange = this._workingSet.delete(entry) || didChange;
|
|
255
|
-
}
|
|
256
|
-
for (const entry of activeEditors) {
|
|
257
|
-
this._workingSet.set(entry, { state: WorkingSetEntryState.Transient, description: ( localize(4504, "Open Editor")) });
|
|
258
|
-
didChange = true;
|
|
259
|
-
}
|
|
260
|
-
if (didChange) {
|
|
261
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
_findSnapshot(requestId) {
|
|
265
|
-
return this._linearHistory.get().find(s => s.requestId === requestId);
|
|
266
|
-
}
|
|
267
|
-
createSnapshot(requestId) {
|
|
268
|
-
const snapshot = this._createSnapshot(requestId);
|
|
269
|
-
if (requestId) {
|
|
270
|
-
for (const [uri, data] of this._workingSet) {
|
|
271
|
-
if (data.state !== WorkingSetEntryState.Suggested) {
|
|
272
|
-
this._workingSet.set(uri, { state: WorkingSetEntryState.Sent, isMarkedReadonly: data.isMarkedReadonly });
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const linearHistory = this._linearHistory.get();
|
|
276
|
-
const linearHistoryIndex = this._linearHistoryIndex.get();
|
|
277
|
-
const newLinearHistory = linearHistory.slice(0, linearHistoryIndex);
|
|
278
|
-
newLinearHistory.push(snapshot);
|
|
279
|
-
transaction((tx) => {
|
|
280
|
-
this._linearHistory.set(newLinearHistory, tx);
|
|
281
|
-
this._linearHistoryIndex.set(newLinearHistory.length, tx);
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
this._pendingSnapshot = snapshot;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
_createSnapshot(requestId) {
|
|
289
|
-
const workingSet = ( new ResourceMap());
|
|
290
|
-
for (const [file, state] of this._workingSet) {
|
|
291
|
-
workingSet.set(file, state);
|
|
292
|
-
}
|
|
293
|
-
const entries = ( new ResourceMap());
|
|
294
|
-
for (const entry of this._entriesObs.get()) {
|
|
295
|
-
entries.set(entry.modifiedURI, entry.createSnapshot(requestId));
|
|
296
|
-
}
|
|
297
|
-
return {
|
|
298
|
-
requestId,
|
|
299
|
-
workingSet,
|
|
300
|
-
entries
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
async getSnapshotModel(requestId, snapshotUri) {
|
|
304
|
-
const entries = this._findSnapshot(requestId)?.entries;
|
|
305
|
-
if (!entries) {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
const snapshotEntry = [...( entries.values())].find((e) => isEqual(e.snapshotUri, snapshotUri));
|
|
309
|
-
if (!snapshotEntry) {
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
return this._modelService.createModel(snapshotEntry.current, this._languageService.createById(snapshotEntry.languageId), snapshotUri, false);
|
|
313
|
-
}
|
|
314
|
-
getSnapshot(requestId, uri) {
|
|
315
|
-
const snapshot = this._findSnapshot(requestId);
|
|
316
|
-
const snapshotEntries = snapshot?.entries;
|
|
317
|
-
return snapshotEntries?.get(uri);
|
|
318
|
-
}
|
|
319
|
-
getSnapshotUri(requestId, uri) {
|
|
320
|
-
return this.getSnapshot(requestId, uri)?.snapshotUri;
|
|
321
|
-
}
|
|
322
|
-
async restoreSnapshot(requestId) {
|
|
323
|
-
if (requestId !== undefined) {
|
|
324
|
-
const snapshot = this._findSnapshot(requestId);
|
|
325
|
-
if (snapshot) {
|
|
326
|
-
if (!this._pendingSnapshot) {
|
|
327
|
-
this.createSnapshot(undefined);
|
|
328
|
-
}
|
|
329
|
-
await this._restoreSnapshot(snapshot);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
if (!this._pendingSnapshot) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const snapshot = this._pendingSnapshot;
|
|
337
|
-
this._pendingSnapshot = undefined;
|
|
338
|
-
await this._restoreSnapshot(snapshot);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
async _restoreSnapshot(snapshot) {
|
|
342
|
-
this._workingSet = ( new ResourceMap());
|
|
343
|
-
snapshot.workingSet.forEach((state, uri) => this._workingSet.set(uri, state));
|
|
344
|
-
for (const entry of this._entriesObs.get()) {
|
|
345
|
-
const snapshotEntry = snapshot.entries.get(entry.modifiedURI);
|
|
346
|
-
if (!snapshotEntry) {
|
|
347
|
-
entry.resetToInitialValue();
|
|
348
|
-
entry.dispose();
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
const entriesArr = [];
|
|
352
|
-
for (const snapshotEntry of ( snapshot.entries.values())) {
|
|
353
|
-
const entry = await this._getOrCreateModifiedFileEntry(snapshotEntry.resource, snapshotEntry.telemetryInfo);
|
|
354
|
-
entry.restoreFromSnapshot(snapshotEntry);
|
|
355
|
-
entriesArr.push(entry);
|
|
356
|
-
}
|
|
357
|
-
this._entriesObs.set(entriesArr, undefined);
|
|
358
|
-
}
|
|
359
|
-
remove(reason, ...uris) {
|
|
360
|
-
this._assertNotDisposed();
|
|
361
|
-
let didRemoveUris = false;
|
|
362
|
-
for (const uri of uris) {
|
|
363
|
-
const entry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
364
|
-
if (entry) {
|
|
365
|
-
entry.dispose();
|
|
366
|
-
const newEntries = this._entriesObs.get().filter(e => !isEqual(e.modifiedURI, uri));
|
|
367
|
-
this._entriesObs.set(newEntries, undefined);
|
|
368
|
-
didRemoveUris = true;
|
|
369
|
-
}
|
|
370
|
-
const state = this._workingSet.get(uri);
|
|
371
|
-
if (state !== undefined) {
|
|
372
|
-
didRemoveUris = this._workingSet.delete(uri) || didRemoveUris;
|
|
373
|
-
if (reason === WorkingSetEntryRemovalReason.User && (state.state === WorkingSetEntryState.Transient || state.state === WorkingSetEntryState.Suggested)) {
|
|
374
|
-
this._removedTransientEntries.add(uri);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
if (!didRemoveUris) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
382
|
-
}
|
|
383
|
-
markIsReadonly(resource, isReadonly) {
|
|
384
|
-
const entry = this._workingSet.get(resource);
|
|
385
|
-
if (entry) {
|
|
386
|
-
if (entry.state === WorkingSetEntryState.Transient || entry.state === WorkingSetEntryState.Suggested) {
|
|
387
|
-
entry.state = WorkingSetEntryState.Attached;
|
|
388
|
-
}
|
|
389
|
-
entry.isMarkedReadonly = isReadonly ?? !entry.isMarkedReadonly;
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
392
|
-
this._workingSet.set(resource, {
|
|
393
|
-
state: WorkingSetEntryState.Attached,
|
|
394
|
-
isMarkedReadonly: isReadonly ?? true
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
398
|
-
}
|
|
399
|
-
_assertNotDisposed() {
|
|
400
|
-
if (this._state.get() === ChatEditingSessionState.Disposed) {
|
|
401
|
-
throw ( new BugIndicatingError(`Cannot access a disposed editing session`));
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
async accept(...uris) {
|
|
405
|
-
this._assertNotDisposed();
|
|
406
|
-
if (uris.length === 0) {
|
|
407
|
-
await Promise.all(( this._entriesObs.get().map(entry => entry.accept(undefined))));
|
|
408
|
-
}
|
|
409
|
-
for (const uri of uris) {
|
|
410
|
-
const entry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
411
|
-
if (entry) {
|
|
412
|
-
await entry.accept(undefined);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.Other);
|
|
416
|
-
}
|
|
417
|
-
async reject(...uris) {
|
|
418
|
-
this._assertNotDisposed();
|
|
419
|
-
if (uris.length === 0) {
|
|
420
|
-
await Promise.all(( this._entriesObs.get().map(entry => entry.reject(undefined))));
|
|
421
|
-
}
|
|
422
|
-
for (const uri of uris) {
|
|
423
|
-
const entry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, uri));
|
|
424
|
-
if (entry) {
|
|
425
|
-
await entry.reject(undefined);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.Other);
|
|
429
|
-
}
|
|
430
|
-
async show() {
|
|
431
|
-
this._assertNotDisposed();
|
|
432
|
-
if (this._editorPane) {
|
|
433
|
-
if (this._editorPane.isVisible()) {
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
else if (this._editorPane.input) {
|
|
437
|
-
await this._editorGroupsService.activeGroup.openEditor(this._editorPane.input, { pinned: true, activation: EditorActivation.ACTIVATE });
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
const input = MultiDiffEditorInput.fromResourceMultiDiffEditorInput({
|
|
442
|
-
multiDiffSource: getMultiDiffSourceUri(),
|
|
443
|
-
label: ( localize(4505, "Suggested Edits"))
|
|
444
|
-
}, this._instantiationService);
|
|
445
|
-
this._editorPane = await this._editorGroupsService.activeGroup.openEditor(input, { pinned: true, activation: EditorActivation.ACTIVATE });
|
|
446
|
-
}
|
|
447
|
-
async stop(clearState = false) {
|
|
448
|
-
if (!this.stopPromise) {
|
|
449
|
-
this.stopPromise = this._performStop();
|
|
450
|
-
}
|
|
451
|
-
await this.stopPromise;
|
|
452
|
-
if (clearState) {
|
|
453
|
-
await this._instantiationService.createInstance(ChatEditingSessionStorage, this.chatSessionId).clearState();
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
async _performStop() {
|
|
457
|
-
const schemes = [ChatEditingModifiedFileEntry.scheme, ChatEditingTextModelContentProvider.scheme];
|
|
458
|
-
await Promise.allSettled(this._editorGroupsService.groups.flatMap(async (g) => {
|
|
459
|
-
return ( g.editors.map(async (e) => {
|
|
460
|
-
if ((e instanceof MultiDiffEditorInput && e.initialResources?.some(r => r.originalUri && schemes.indexOf(r.originalUri.scheme) !== -1))
|
|
461
|
-
|| (e instanceof DiffEditorInput && e.original.resource && schemes.indexOf(e.original.resource.scheme) !== -1)) {
|
|
462
|
-
await g.closeEditor(e);
|
|
463
|
-
}
|
|
464
|
-
}));
|
|
465
|
-
}));
|
|
466
|
-
if (this._state.get() !== ChatEditingSessionState.Disposed) {
|
|
467
|
-
this.dispose();
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
dispose() {
|
|
471
|
-
this._assertNotDisposed();
|
|
472
|
-
this._chatService.cancelCurrentRequestForSession(this.chatSessionId);
|
|
473
|
-
dispose(this._entriesObs.get());
|
|
474
|
-
super.dispose();
|
|
475
|
-
this._state.set(ChatEditingSessionState.Disposed, undefined);
|
|
476
|
-
this._onDidDispose.fire();
|
|
477
|
-
this._onDidDispose.dispose();
|
|
478
|
-
}
|
|
479
|
-
getVirtualModel(documentId) {
|
|
480
|
-
this._assertNotDisposed();
|
|
481
|
-
const entry = this._entriesObs.get().find(e => e.entryId === documentId);
|
|
482
|
-
return entry?.originalModel ?? null;
|
|
483
|
-
}
|
|
484
|
-
acceptStreamingEditsStart() {
|
|
485
|
-
if (this._state.get() === ChatEditingSessionState.Disposed) {
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
this._sequencer.queue(() => this._acceptStreamingEditsStart());
|
|
489
|
-
}
|
|
490
|
-
acceptTextEdits(resource, textEdits, isLastEdits, responseModel) {
|
|
491
|
-
if (this._state.get() === ChatEditingSessionState.Disposed) {
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
this._isToolsAgentSession = !!responseModel.agent?.isToolsAgent;
|
|
495
|
-
this._sequencer.queue(() => this._acceptTextEdits(resource, textEdits, isLastEdits, responseModel));
|
|
496
|
-
}
|
|
497
|
-
resolve() {
|
|
498
|
-
if (this._state.get() === ChatEditingSessionState.Disposed) {
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
this._sequencer.queue(() => this._resolve());
|
|
502
|
-
}
|
|
503
|
-
_trackUntitledWorkingSetEntry(resource) {
|
|
504
|
-
if (resource.scheme !== Schemas.untitled) {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
const untitled = this._textFileService.untitled.get(resource);
|
|
508
|
-
if (!untitled) {
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
const store = ( new DisposableStore());
|
|
512
|
-
store.add(this.onDidChange(e => {
|
|
513
|
-
if (e === ChatEditingSessionChangeType.WorkingSet && !this._workingSet.get(resource)) {
|
|
514
|
-
store.dispose();
|
|
515
|
-
}
|
|
516
|
-
}));
|
|
517
|
-
store.add(this._textFileService.untitled.onDidSave(e => {
|
|
518
|
-
const existing = this._workingSet.get(resource);
|
|
519
|
-
if (isEqual(e.source, resource) && existing) {
|
|
520
|
-
this._workingSet.delete(resource);
|
|
521
|
-
this._workingSet.set(e.target, existing);
|
|
522
|
-
store.dispose();
|
|
523
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
524
|
-
}
|
|
525
|
-
}));
|
|
526
|
-
store.add(this._editorService.onDidCloseEditor((e) => {
|
|
527
|
-
if (isEqual(e.editor.resource, resource)) {
|
|
528
|
-
this._workingSet.delete(resource);
|
|
529
|
-
store.dispose();
|
|
530
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
531
|
-
}
|
|
532
|
-
}));
|
|
533
|
-
this._store.add(store);
|
|
534
|
-
}
|
|
535
|
-
addFileToWorkingSet(resource, description, proposedState) {
|
|
536
|
-
const state = this._workingSet.get(resource);
|
|
537
|
-
if (proposedState === WorkingSetEntryState.Suggested) {
|
|
538
|
-
if (state !== undefined || ( this._removedTransientEntries.has(resource))) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
this._workingSet.set(resource, { description, state: WorkingSetEntryState.Suggested });
|
|
542
|
-
this._trackUntitledWorkingSetEntry(resource);
|
|
543
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
544
|
-
}
|
|
545
|
-
else if (state === undefined || state.state === WorkingSetEntryState.Transient || state.state === WorkingSetEntryState.Suggested) {
|
|
546
|
-
this._workingSet.set(resource, { description, state: WorkingSetEntryState.Attached });
|
|
547
|
-
this._trackUntitledWorkingSetEntry(resource);
|
|
548
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
async undoInteraction() {
|
|
552
|
-
const linearHistory = this._linearHistory.get();
|
|
553
|
-
const newIndex = this._linearHistoryIndex.get() - 1;
|
|
554
|
-
if (newIndex < 0) {
|
|
555
|
-
return;
|
|
556
|
-
}
|
|
557
|
-
const previousSnapshot = linearHistory[newIndex];
|
|
558
|
-
await this.restoreSnapshot(previousSnapshot.requestId);
|
|
559
|
-
this._linearHistoryIndex.set(newIndex, undefined);
|
|
560
|
-
this._updateRequestHiddenState();
|
|
561
|
-
}
|
|
562
|
-
async redoInteraction() {
|
|
563
|
-
const linearHistory = this._linearHistory.get();
|
|
564
|
-
const newIndex = this._linearHistoryIndex.get() + 1;
|
|
565
|
-
if (newIndex > linearHistory.length) {
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
const nextSnapshot = newIndex < linearHistory.length ? linearHistory[newIndex] : this._pendingSnapshot;
|
|
569
|
-
if (!nextSnapshot) {
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
await this.restoreSnapshot(nextSnapshot.requestId);
|
|
573
|
-
this._linearHistoryIndex.set(newIndex, undefined);
|
|
574
|
-
this._updateRequestHiddenState();
|
|
575
|
-
}
|
|
576
|
-
_updateRequestHiddenState() {
|
|
577
|
-
const hiddenRequestIds = ( this._linearHistory.get().slice(this._linearHistoryIndex.get()).map(s => s.requestId)).filter((r) => !!r);
|
|
578
|
-
this._chatService.getSession(this.chatSessionId)?.disableRequests(hiddenRequestIds);
|
|
579
|
-
}
|
|
580
|
-
async _acceptStreamingEditsStart() {
|
|
581
|
-
transaction((tx) => {
|
|
582
|
-
this._state.set(ChatEditingSessionState.StreamingEdits, tx);
|
|
583
|
-
for (const entry of this._entriesObs.get()) {
|
|
584
|
-
entry.acceptStreamingEditsStart(tx);
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
async _acceptTextEdits(resource, textEdits, isLastEdits, responseModel) {
|
|
589
|
-
if (!this._chatAgentService.toolsAgentModeEnabled && !this._entriesObs.get().find(e => isEqual(e.modifiedURI, resource)) && this._entriesObs.get().length >= (await this.editingSessionFileLimitPromise)) {
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
const telemetryInfo = new class {
|
|
593
|
-
get agentId() { return responseModel.agent?.id; }
|
|
594
|
-
get command() { return responseModel.slashCommand?.name; }
|
|
595
|
-
get sessionId() { return responseModel.session.sessionId; }
|
|
596
|
-
get requestId() { return responseModel.requestId; }
|
|
597
|
-
get result() { return responseModel.result; }
|
|
598
|
-
};
|
|
599
|
-
const entry = await this._getOrCreateModifiedFileEntry(resource, telemetryInfo);
|
|
600
|
-
entry.acceptAgentEdits(textEdits, isLastEdits);
|
|
601
|
-
}
|
|
602
|
-
async _resolve() {
|
|
603
|
-
await asyncTransaction(async (tx) => {
|
|
604
|
-
const entriesWithoutChange = ( new ResourceMap());
|
|
605
|
-
for (const entry of this._entriesObs.get()) {
|
|
606
|
-
await entry.acceptStreamingEditsEnd(tx);
|
|
607
|
-
if (entry.diffInfo.get().identical) {
|
|
608
|
-
entriesWithoutChange.set(entry.modifiedURI, entry);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
if (entriesWithoutChange.size > 0) {
|
|
612
|
-
const newEntries = this._entriesObs.get().filter(e => !( entriesWithoutChange.has(e.modifiedURI)));
|
|
613
|
-
this._entriesObs.set(newEntries, tx);
|
|
614
|
-
dispose(( entriesWithoutChange.values()));
|
|
615
|
-
}
|
|
616
|
-
this._state.set(ChatEditingSessionState.Idle, tx);
|
|
617
|
-
});
|
|
618
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.Other);
|
|
619
|
-
}
|
|
620
|
-
async _getOrCreateModifiedFileEntry(resource, responseModel) {
|
|
621
|
-
const existingEntry = this._entriesObs.get().find(e => isEqual(e.modifiedURI, resource));
|
|
622
|
-
if (existingEntry) {
|
|
623
|
-
if (responseModel.requestId !== existingEntry.telemetryInfo.requestId) {
|
|
624
|
-
existingEntry.updateTelemetryInfo(responseModel);
|
|
625
|
-
}
|
|
626
|
-
return existingEntry;
|
|
627
|
-
}
|
|
628
|
-
let entry;
|
|
629
|
-
const existingExternalEntry = this._lookupExternalEntry(resource);
|
|
630
|
-
if (existingExternalEntry) {
|
|
631
|
-
entry = existingExternalEntry;
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
const initialContent = this._initialFileContents.get(resource);
|
|
635
|
-
entry = await this._createModifiedFileEntry(resource, responseModel, false, initialContent);
|
|
636
|
-
if (!initialContent) {
|
|
637
|
-
this._initialFileContents.set(resource, entry.initialContent);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
const listener = entry.onDidDelete(() => {
|
|
641
|
-
const newEntries = this._entriesObs.get().filter(e => !isEqual(e.modifiedURI, entry.modifiedURI));
|
|
642
|
-
this._entriesObs.set(newEntries, undefined);
|
|
643
|
-
this._workingSet.delete(entry.modifiedURI);
|
|
644
|
-
this._editorService.closeEditors(this._editorService.findEditors(entry.modifiedURI));
|
|
645
|
-
if (!existingExternalEntry) {
|
|
646
|
-
entry.dispose();
|
|
647
|
-
}
|
|
648
|
-
this._store.delete(listener);
|
|
649
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
650
|
-
});
|
|
651
|
-
this._store.add(listener);
|
|
652
|
-
const entriesArr = [...this._entriesObs.get(), entry];
|
|
653
|
-
this._entriesObs.set(entriesArr, undefined);
|
|
654
|
-
this._onDidChange.fire(ChatEditingSessionChangeType.WorkingSet);
|
|
655
|
-
return entry;
|
|
656
|
-
}
|
|
657
|
-
async _createModifiedFileEntry(resource, responseModel, mustExist = false, initialContent) {
|
|
658
|
-
try {
|
|
659
|
-
const ref = await this._textModelService.createModelReference(resource);
|
|
660
|
-
if (this._notebookService.hasSupportedNotebooks(resource)) {
|
|
661
|
-
return this._instantiationService.createInstance(ChatEditingModifiedNotebookEntry, ref, { collapse: (transaction) => this._collapse(resource, transaction) }, responseModel, mustExist ? ChatEditKind.Created : ChatEditKind.Modified, initialContent);
|
|
662
|
-
}
|
|
663
|
-
return this._instantiationService.createInstance(ChatEditingModifiedFileEntry, ref, { collapse: (transaction) => this._collapse(resource, transaction) }, responseModel, mustExist ? ChatEditKind.Created : ChatEditKind.Modified, initialContent);
|
|
664
|
-
}
|
|
665
|
-
catch (err) {
|
|
666
|
-
if (mustExist) {
|
|
667
|
-
throw err;
|
|
668
|
-
}
|
|
669
|
-
await this._bulkEditService.apply({ edits: [{ newResource: resource }] });
|
|
670
|
-
this._editorService.openEditor({ resource, options: { inactive: true, preserveFocus: true, pinned: true } });
|
|
671
|
-
return this._createModifiedFileEntry(resource, responseModel, true, initialContent);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
_collapse(resource, transaction) {
|
|
675
|
-
const multiDiffItem = this._editorPane?.findDocumentDiffItem(resource);
|
|
676
|
-
if (multiDiffItem) {
|
|
677
|
-
this._editorPane?.viewModel?.items.get().find((documentDiffItem) => isEqual(documentDiffItem.originalUri, multiDiffItem.originalUri) &&
|
|
678
|
-
isEqual(documentDiffItem.modifiedUri, multiDiffItem.modifiedUri))
|
|
679
|
-
?.collapsed.set(true, transaction);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
ChatEditingSession = ( __decorate([
|
|
684
|
-
( __param(4, IInstantiationService)),
|
|
685
|
-
( __param(5, IModelService)),
|
|
686
|
-
( __param(6, ILanguageService)),
|
|
687
|
-
( __param(7, ITextModelService)),
|
|
688
|
-
( __param(8, IBulkEditService)),
|
|
689
|
-
( __param(9, IEditorGroupsService)),
|
|
690
|
-
( __param(10, IEditorService)),
|
|
691
|
-
( __param(11, IChatService)),
|
|
692
|
-
( __param(12, INotebookService)),
|
|
693
|
-
( __param(13, ITextFileService)),
|
|
694
|
-
( __param(14, IChatAgentService))
|
|
695
|
-
], ChatEditingSession));
|
|
696
|
-
let ChatEditingSessionStorage = class ChatEditingSessionStorage {
|
|
697
|
-
constructor(chatSessionId, _fileService, _environmentService, _logService, _workspaceContextService) {
|
|
698
|
-
this.chatSessionId = chatSessionId;
|
|
699
|
-
this._fileService = _fileService;
|
|
700
|
-
this._environmentService = _environmentService;
|
|
701
|
-
this._logService = _logService;
|
|
702
|
-
this._workspaceContextService = _workspaceContextService;
|
|
703
|
-
}
|
|
704
|
-
_getStorageLocation() {
|
|
705
|
-
const workspaceId = this._workspaceContextService.getWorkspace().id;
|
|
706
|
-
return joinPath(this._environmentService.workspaceStorageHome, workspaceId, 'chatEditingSessions', this.chatSessionId);
|
|
707
|
-
}
|
|
708
|
-
async restoreState() {
|
|
709
|
-
const storageLocation = this._getStorageLocation();
|
|
710
|
-
const getFileContent = (hash) => {
|
|
711
|
-
return this._fileService.readFile(joinPath(storageLocation, STORAGE_CONTENTS_FOLDER, hash)).then(content => ( content.value.toString()));
|
|
712
|
-
};
|
|
713
|
-
const deserializeResourceMap = (resourceMap, deserialize, result) => {
|
|
714
|
-
resourceMap.forEach(([resourceURI, value]) => {
|
|
715
|
-
result.set(( URI.parse(resourceURI)), deserialize(value));
|
|
716
|
-
});
|
|
717
|
-
return result;
|
|
718
|
-
};
|
|
719
|
-
const deserializeChatEditingSessionSnapshot = async (snapshot) => {
|
|
720
|
-
const entriesMap = ( new ResourceMap());
|
|
721
|
-
for (const entryDTO of snapshot.entries) {
|
|
722
|
-
const entry = await deserializeSnapshotEntry(entryDTO);
|
|
723
|
-
entriesMap.set(entry.resource, entry);
|
|
724
|
-
}
|
|
725
|
-
return {
|
|
726
|
-
requestId: snapshot.requestId,
|
|
727
|
-
workingSet: deserializeResourceMap(snapshot.workingSet, (value) => value, ( new ResourceMap())),
|
|
728
|
-
entries: entriesMap
|
|
729
|
-
};
|
|
730
|
-
};
|
|
731
|
-
const deserializeSnapshotEntry = async (entry) => {
|
|
732
|
-
return {
|
|
733
|
-
resource: ( URI.parse(entry.resource)),
|
|
734
|
-
languageId: entry.languageId,
|
|
735
|
-
original: await getFileContent(entry.originalHash),
|
|
736
|
-
current: await getFileContent(entry.currentHash),
|
|
737
|
-
originalToCurrentEdit: OffsetEdit.fromJson(entry.originalToCurrentEdit),
|
|
738
|
-
state: entry.state,
|
|
739
|
-
snapshotUri: ( URI.parse(entry.snapshotUri)),
|
|
740
|
-
telemetryInfo: { requestId: entry.telemetryInfo.requestId, agentId: entry.telemetryInfo.agentId, command: entry.telemetryInfo.command, sessionId: this.chatSessionId, result: undefined }
|
|
741
|
-
};
|
|
742
|
-
};
|
|
743
|
-
try {
|
|
744
|
-
const stateFilePath = joinPath(storageLocation, STORAGE_STATE_FILE);
|
|
745
|
-
if (!(await this._fileService.exists(stateFilePath))) {
|
|
746
|
-
this._logService.debug(`chatEditingSession: No editing session state found at ${( stateFilePath.toString())}`);
|
|
747
|
-
return undefined;
|
|
748
|
-
}
|
|
749
|
-
this._logService.debug(`chatEditingSession: Restoring editing session at ${( stateFilePath.toString())}`);
|
|
750
|
-
const stateFileContent = await this._fileService.readFile(stateFilePath);
|
|
751
|
-
const data = JSON.parse(( stateFileContent.value.toString()));
|
|
752
|
-
if (data.version !== STORAGE_VERSION) {
|
|
753
|
-
return undefined;
|
|
754
|
-
}
|
|
755
|
-
const linearHistory = await Promise.all(( data.linearHistory.map(deserializeChatEditingSessionSnapshot)));
|
|
756
|
-
const initialFileContents = ( new ResourceMap());
|
|
757
|
-
for (const fileContentDTO of data.initialFileContents) {
|
|
758
|
-
initialFileContents.set(( URI.parse(fileContentDTO[0])), await getFileContent(fileContentDTO[1]));
|
|
759
|
-
}
|
|
760
|
-
const pendingSnapshot = data.pendingSnapshot ? await deserializeChatEditingSessionSnapshot(data.pendingSnapshot) : undefined;
|
|
761
|
-
const recentSnapshot = await deserializeChatEditingSessionSnapshot(data.recentSnapshot);
|
|
762
|
-
return {
|
|
763
|
-
initialFileContents,
|
|
764
|
-
pendingSnapshot,
|
|
765
|
-
recentSnapshot,
|
|
766
|
-
linearHistoryIndex: data.linearHistoryIndex,
|
|
767
|
-
linearHistory
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
catch (e) {
|
|
771
|
-
this._logService.error(`Error restoring chat editing session from ${( storageLocation.toString())}`, e);
|
|
772
|
-
}
|
|
773
|
-
return undefined;
|
|
774
|
-
}
|
|
775
|
-
async storeState(state) {
|
|
776
|
-
const storageFolder = this._getStorageLocation();
|
|
777
|
-
const contentsFolder = URI.joinPath(storageFolder, STORAGE_CONTENTS_FOLDER);
|
|
778
|
-
const existingContents = ( new Set());
|
|
779
|
-
try {
|
|
780
|
-
const stat = await this._fileService.resolve(contentsFolder);
|
|
781
|
-
stat.children?.forEach(child => {
|
|
782
|
-
if (child.isDirectory) {
|
|
783
|
-
existingContents.add(child.name);
|
|
784
|
-
}
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
catch (e) {
|
|
788
|
-
try {
|
|
789
|
-
await this._fileService.createFolder(contentsFolder);
|
|
790
|
-
}
|
|
791
|
-
catch (e) {
|
|
792
|
-
this._logService.error(`Error creating chat editing session content folder ${( contentsFolder.toString())}`, e);
|
|
793
|
-
return;
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
const fileContents = ( new Map());
|
|
797
|
-
const addFileContent = (content) => {
|
|
798
|
-
const shaComputer = ( new StringSHA1());
|
|
799
|
-
shaComputer.update(content);
|
|
800
|
-
const sha = shaComputer.digest().substring(0, 7);
|
|
801
|
-
if (!( existingContents.has(sha))) {
|
|
802
|
-
fileContents.set(sha, content);
|
|
803
|
-
}
|
|
804
|
-
return sha;
|
|
805
|
-
};
|
|
806
|
-
const serializeResourceMap = (resourceMap, serialize) => {
|
|
807
|
-
return ( Array.from(resourceMap.entries()).map(([resourceURI, value]) => [( resourceURI.toString()), serialize(value)]));
|
|
808
|
-
};
|
|
809
|
-
const serializeChatEditingSessionSnapshot = (snapshot) => {
|
|
810
|
-
return {
|
|
811
|
-
requestId: snapshot.requestId,
|
|
812
|
-
workingSet: serializeResourceMap(snapshot.workingSet, value => value),
|
|
813
|
-
entries: ( Array.from(( snapshot.entries.values())).map(serializeSnapshotEntry))
|
|
814
|
-
};
|
|
815
|
-
};
|
|
816
|
-
const serializeSnapshotEntry = (entry) => {
|
|
817
|
-
return {
|
|
818
|
-
resource: ( entry.resource.toString()),
|
|
819
|
-
languageId: entry.languageId,
|
|
820
|
-
originalHash: addFileContent(entry.original),
|
|
821
|
-
currentHash: addFileContent(entry.current),
|
|
822
|
-
originalToCurrentEdit: ( entry.originalToCurrentEdit.edits.map(
|
|
823
|
-
edit => ({ pos: edit.replaceRange.start, len: edit.replaceRange.length, txt: edit.newText })
|
|
824
|
-
)),
|
|
825
|
-
state: entry.state,
|
|
826
|
-
snapshotUri: ( entry.snapshotUri.toString()),
|
|
827
|
-
telemetryInfo: { requestId: entry.telemetryInfo.requestId, agentId: entry.telemetryInfo.agentId, command: entry.telemetryInfo.command }
|
|
828
|
-
};
|
|
829
|
-
};
|
|
830
|
-
try {
|
|
831
|
-
const data = {
|
|
832
|
-
version: STORAGE_VERSION,
|
|
833
|
-
sessionId: this.chatSessionId,
|
|
834
|
-
linearHistory: ( state.linearHistory.map(serializeChatEditingSessionSnapshot)),
|
|
835
|
-
linearHistoryIndex: state.linearHistoryIndex,
|
|
836
|
-
initialFileContents: serializeResourceMap(state.initialFileContents, value => addFileContent(value)),
|
|
837
|
-
pendingSnapshot: state.pendingSnapshot ? serializeChatEditingSessionSnapshot(state.pendingSnapshot) : undefined,
|
|
838
|
-
recentSnapshot: serializeChatEditingSessionSnapshot(state.recentSnapshot),
|
|
839
|
-
};
|
|
840
|
-
this._logService.debug(`chatEditingSession: Storing editing session at ${( storageFolder.toString())}: ${fileContents.size} files`);
|
|
841
|
-
for (const [hash, content] of fileContents) {
|
|
842
|
-
await this._fileService.writeFile(joinPath(contentsFolder, hash), VSBuffer.fromString(content));
|
|
843
|
-
}
|
|
844
|
-
await this._fileService.writeFile(joinPath(storageFolder, STORAGE_STATE_FILE), VSBuffer.fromString(JSON.stringify(data, undefined, 2)));
|
|
845
|
-
}
|
|
846
|
-
catch (e) {
|
|
847
|
-
this._logService.debug(`Error storing chat editing session to ${( storageFolder.toString())}`, e);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
async clearState() {
|
|
851
|
-
const storageFolder = this._getStorageLocation();
|
|
852
|
-
if (await this._fileService.exists(storageFolder)) {
|
|
853
|
-
this._logService.debug(`chatEditingSession: Clearing editing session at ${( storageFolder.toString())}`);
|
|
854
|
-
try {
|
|
855
|
-
await this._fileService.del(storageFolder, { recursive: true });
|
|
856
|
-
}
|
|
857
|
-
catch (e) {
|
|
858
|
-
this._logService.debug(`Error clearing chat editing session from ${( storageFolder.toString())}`, e);
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
};
|
|
863
|
-
ChatEditingSessionStorage = ( __decorate([
|
|
864
|
-
( __param(1, IFileService)),
|
|
865
|
-
( __param(2, IEnvironmentService)),
|
|
866
|
-
( __param(3, ILogService)),
|
|
867
|
-
( __param(4, IWorkspaceContextService))
|
|
868
|
-
], ChatEditingSessionStorage));
|
|
869
|
-
const STORAGE_VERSION = 1;
|
|
870
|
-
|
|
871
|
-
export { ChatEditingSession };
|