Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chat.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { IMouseWheelEvent } from '../../../../base/browser/mouseEvent.js';
7
import { Event } from '../../../../base/common/event.js';
8
import { IDisposable } from '../../../../base/common/lifecycle.js';
9
import { URI } from '../../../../base/common/uri.js';
10
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
11
import { Selection } from '../../../../editor/common/core/selection.js';
12
import { EditDeltaInfo } from '../../../../editor/common/textModelEditSource.js';
13
import { MenuId } from '../../../../platform/actions/common/actions.js';
14
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
15
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
16
import { IWorkbenchLayoutService } from '../../../services/layout/browser/layoutService.js';
17
import { IViewsService } from '../../../services/views/common/viewsService.js';
18
import { IChatAgentCommand, IChatAgentData } from '../common/chatAgents.js';
19
import { IChatResponseModel } from '../common/chatModel.js';
20
import { IParsedChatRequest } from '../common/chatParserTypes.js';
21
import { CHAT_PROVIDER_ID } from '../common/chatParticipantContribTypes.js';
22
import { IChatElicitationRequest, IChatSendRequestOptions } from '../common/chatService.js';
23
import { IChatRequestViewModel, IChatResponseViewModel, IChatViewModel } from '../common/chatViewModel.js';
24
import { ChatAgentLocation, ChatModeKind } from '../common/constants.js';
25
import { ChatAttachmentModel } from './chatAttachmentModel.js';
26
import { ChatInputPart } from './chatInputPart.js';
27
import { ChatViewPane } from './chatViewPane.js';
28
import { IChatViewState, IChatWidgetContrib } from './chatWidget.js';
29
import { ICodeBlockActionContext } from './codeBlockPart.js';
30
31
export const IChatWidgetService = createDecorator<IChatWidgetService>('chatWidgetService');
32
33
export interface IChatWidgetService {
34
35
readonly _serviceBrand: undefined;
36
37
/**
38
* Returns the most recently focused widget if any.
39
*/
40
readonly lastFocusedWidget: IChatWidget | undefined;
41
42
readonly onDidAddWidget: Event<IChatWidget>;
43
44
getAllWidgets(): ReadonlyArray<IChatWidget>;
45
getWidgetByInputUri(uri: URI): IChatWidget | undefined;
46
getWidgetBySessionId(sessionId: string): IChatWidget | undefined;
47
getWidgetsByLocations(location: ChatAgentLocation): ReadonlyArray<IChatWidget>;
48
}
49
50
export async function showChatView(viewsService: IViewsService): Promise<IChatWidget | undefined> {
51
return (await viewsService.openView<ChatViewPane>(ChatViewId))?.widget;
52
}
53
54
export function showCopilotView(viewsService: IViewsService, layoutService: IWorkbenchLayoutService): Promise<IChatWidget | undefined> {
55
56
// Ensure main window is in front
57
if (layoutService.activeContainer !== layoutService.mainContainer) {
58
layoutService.mainContainer.focus();
59
}
60
61
return showChatView(viewsService);
62
}
63
64
export const IQuickChatService = createDecorator<IQuickChatService>('quickChatService');
65
export interface IQuickChatService {
66
readonly _serviceBrand: undefined;
67
readonly onDidClose: Event<void>;
68
readonly enabled: boolean;
69
readonly focused: boolean;
70
toggle(options?: IQuickChatOpenOptions): void;
71
focus(): void;
72
open(options?: IQuickChatOpenOptions): void;
73
close(): void;
74
openInChatView(): void;
75
}
76
77
export interface IQuickChatOpenOptions {
78
/**
79
* The query for quick chat.
80
*/
81
query: string;
82
/**
83
* Whether the query is partial and will await more input from the user.
84
*/
85
isPartialQuery?: boolean;
86
/**
87
* An optional selection range to apply to the query text box.
88
*/
89
selection?: Selection;
90
}
91
92
export const IChatAccessibilityService = createDecorator<IChatAccessibilityService>('chatAccessibilityService');
93
export interface IChatAccessibilityService {
94
readonly _serviceBrand: undefined;
95
acceptRequest(): number;
96
acceptResponse(response: IChatResponseViewModel | string | undefined, requestId: number, isVoiceInput?: boolean): void;
97
acceptElicitation(message: IChatElicitationRequest): void;
98
}
99
100
export interface IChatCodeBlockInfo {
101
readonly ownerMarkdownPartId: string;
102
readonly codeBlockIndex: number;
103
readonly elementId: string;
104
readonly uri: URI | undefined;
105
readonly uriPromise: Promise<URI | undefined>;
106
codemapperUri: URI | undefined;
107
readonly isStreaming: boolean;
108
readonly chatSessionId: string;
109
focus(): void;
110
readonly languageId?: string | undefined;
111
readonly editDeltaInfo?: EditDeltaInfo | undefined;
112
}
113
114
export interface IChatFileTreeInfo {
115
treeDataId: string;
116
treeIndex: number;
117
focus(): void;
118
}
119
120
export type ChatTreeItem = IChatRequestViewModel | IChatResponseViewModel;
121
122
export interface IChatListItemRendererOptions {
123
readonly renderStyle?: 'compact' | 'minimal';
124
readonly noHeader?: boolean;
125
readonly noFooter?: boolean;
126
readonly editableCodeBlock?: boolean;
127
readonly renderDetectedCommandsWithRequest?: boolean;
128
readonly restorable?: boolean;
129
readonly editable?: boolean;
130
readonly renderTextEditsAsSummary?: (uri: URI) => boolean;
131
readonly referencesExpandedWhenEmptyResponse?: boolean | ((mode: ChatModeKind) => boolean);
132
readonly progressMessageAtBottomOfResponse?: boolean | ((mode: ChatModeKind) => boolean);
133
}
134
135
export interface IChatWidgetViewOptions {
136
autoScroll?: boolean | ((mode: ChatModeKind) => boolean);
137
renderInputOnTop?: boolean;
138
renderFollowups?: boolean;
139
renderStyle?: 'compact' | 'minimal';
140
supportsFileReferences?: boolean;
141
filter?: (item: ChatTreeItem) => boolean;
142
rendererOptions?: IChatListItemRendererOptions;
143
menus?: {
144
/**
145
* The menu that is inside the input editor, use for send, dictation
146
*/
147
executeToolbar?: MenuId;
148
/**
149
* The menu that next to the input editor, use for close, config etc
150
*/
151
inputSideToolbar?: MenuId;
152
/**
153
* The telemetry source for all commands of this widget
154
*/
155
telemetrySource?: string;
156
};
157
defaultElementHeight?: number;
158
editorOverflowWidgetsDomNode?: HTMLElement;
159
enableImplicitContext?: boolean;
160
enableWorkingSet?: 'explicit' | 'implicit';
161
supportsChangingModes?: boolean;
162
dndContainer?: HTMLElement;
163
}
164
165
export interface IChatViewViewContext {
166
viewId: string;
167
}
168
169
export interface IChatResourceViewContext {
170
isQuickChat?: boolean;
171
isInlineChat?: boolean;
172
}
173
174
export type IChatWidgetViewContext = IChatViewViewContext | IChatResourceViewContext | {};
175
176
export interface IChatAcceptInputOptions {
177
noCommandDetection?: boolean;
178
isVoiceInput?: boolean;
179
}
180
181
export interface IChatWidget {
182
readonly domNode: HTMLElement;
183
readonly onDidChangeViewModel: Event<void>;
184
readonly onDidAcceptInput: Event<void>;
185
readonly onDidHide: Event<void>;
186
readonly onDidShow: Event<void>;
187
readonly onDidSubmitAgent: Event<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>;
188
readonly onDidChangeAgent: Event<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>;
189
readonly onDidChangeParsedInput: Event<void>;
190
readonly location: ChatAgentLocation;
191
readonly viewContext: IChatWidgetViewContext;
192
readonly viewModel: IChatViewModel | undefined;
193
readonly inputEditor: ICodeEditor;
194
readonly supportsFileReferences: boolean;
195
readonly parsedInput: IParsedChatRequest;
196
readonly lockedAgentId: string | undefined;
197
lastSelectedAgent: IChatAgentData | undefined;
198
readonly scopedContextKeyService: IContextKeyService;
199
readonly input: ChatInputPart;
200
readonly attachmentModel: ChatAttachmentModel;
201
202
readonly supportsChangingModes: boolean;
203
204
getContrib<T extends IChatWidgetContrib>(id: string): T | undefined;
205
reveal(item: ChatTreeItem): void;
206
focus(item: ChatTreeItem): void;
207
getSibling(item: ChatTreeItem, type: 'next' | 'previous'): ChatTreeItem | undefined;
208
getFocus(): ChatTreeItem | undefined;
209
setInput(query?: string): void;
210
getInput(): string;
211
refreshParsedInput(): void;
212
logInputHistory(): void;
213
acceptInput(query?: string, options?: IChatAcceptInputOptions): Promise<IChatResponseModel | undefined>;
214
startEditing(requestId: string): void;
215
finishedEditing(completedEdit?: boolean): void;
216
rerunLastRequest(): Promise<void>;
217
setInputPlaceholder(placeholder: string): void;
218
resetInputPlaceholder(): void;
219
focusLastMessage(): void;
220
focusInput(): void;
221
hasInputFocus(): boolean;
222
getModeRequestOptions(): Partial<IChatSendRequestOptions>;
223
getCodeBlockInfoForEditor(uri: URI): IChatCodeBlockInfo | undefined;
224
getCodeBlockInfosForResponse(response: IChatResponseViewModel): IChatCodeBlockInfo[];
225
getFileTreeInfosForResponse(response: IChatResponseViewModel): IChatFileTreeInfo[];
226
getLastFocusedFileTreeForResponse(response: IChatResponseViewModel): IChatFileTreeInfo | undefined;
227
clear(): void;
228
/**
229
* Wait for this widget to have a VM with a fully initialized model and editing session.
230
* Sort of a hack. See https://github.com/microsoft/vscode/issues/247484
231
*/
232
waitForReady(): Promise<void>;
233
getViewState(): IChatViewState;
234
lockToCodingAgent(name: string, displayName: string, agentId?: string): void;
235
236
delegateScrollFromMouseWheelEvent(event: IMouseWheelEvent): void;
237
}
238
239
240
export interface ICodeBlockActionContextProvider {
241
getCodeBlockContext(editor?: ICodeEditor): ICodeBlockActionContext | undefined;
242
}
243
244
export const IChatCodeBlockContextProviderService = createDecorator<IChatCodeBlockContextProviderService>('chatCodeBlockContextProviderService');
245
export interface IChatCodeBlockContextProviderService {
246
readonly _serviceBrand: undefined;
247
readonly providers: ICodeBlockActionContextProvider[];
248
registerProvider(provider: ICodeBlockActionContextProvider, id: string): IDisposable;
249
}
250
251
export const ChatViewId = `workbench.panel.chat.view.${CHAT_PROVIDER_ID}`;
252
253