Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vscode-dts/vscode.proposed.chatContextProvider.d.ts
5220 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
7
declare module 'vscode' {
8
9
// https://github.com/microsoft/vscode/issues/271104 @alexr00
10
11
export namespace chat {
12
13
/**
14
* Register a chat workspace context provider. Workspace context is automatically included in all chat requests.
15
*
16
* To ensure your extension is activated when chat context is requested, make sure to include the following activations events:
17
* - If your extension implements `provideWorkspaceChatContext` or `provideChatContextForResource`, find an activation event which is a good signal to activate.
18
* Ex: `onLanguage:<languageId>`, `onWebviewPanel:<viewType>`, etc.`
19
* - If your extension implements `provideChatContextExplicit`, your extension will be automatically activated when the user requests explicit context.
20
*
21
* @param id Unique identifier for the provider.
22
* @param provider The chat workspace context provider.
23
*/
24
export function registerChatWorkspaceContextProvider(id: string, provider: ChatWorkspaceContextProvider): Disposable;
25
26
/**
27
* Register a chat explicit context provider. Explicit context items are shown as options when the user explicitly attaches context.
28
*
29
* To ensure your extension is activated when chat context is requested, make sure to include the `onChatContextProvider:<id>` activation event in your `package.json`.
30
*
31
* @param id Unique identifier for the provider.
32
* @param provider The chat explicit context provider.
33
*/
34
export function registerChatExplicitContextProvider(id: string, provider: ChatExplicitContextProvider): Disposable;
35
36
/**
37
* Register a chat resource context provider. Resource context is provided for a specific resource.
38
* Make sure to pass a selector that matches the resource you want to provide context for.
39
*
40
* To ensure your extension is activated when chat context is requested, make sure to include the `onChatContextProvider:<id>` activation event in your `package.json`.
41
*
42
* @param selector Document selector to filter which resources the provider is called for.
43
* @param id Unique identifier for the provider.
44
* @param provider The chat resource context provider.
45
*/
46
export function registerChatResourceContextProvider(selector: DocumentSelector, id: string, provider: ChatResourceContextProvider): Disposable;
47
48
/**
49
* Register a chat context provider.
50
*
51
* @deprecated Use {@link registerChatWorkspaceContextProvider}, {@link registerChatExplicitContextProvider}, or {@link registerChatResourceContextProvider} instead.
52
*
53
* @param selector Optional document selector to filter which resources the provider is called for. If omitted, the provider will only be called for explicit context requests.
54
* @param id Unique identifier for the provider.
55
* @param provider The chat context provider.
56
*/
57
export function registerChatContextProvider(selector: DocumentSelector | undefined, id: string, provider: ChatContextProvider): Disposable;
58
59
}
60
61
export interface ChatContextItem {
62
/**
63
* Icon for the context item.
64
* - If `icon` is not defined, no icon is shown.
65
* - If `icon` is defined and is a file or folder icon, the icon is derived from {@link resourceUri} if `resourceUri` is defined.
66
* - Otherwise, `icon` is used.
67
*/
68
icon?: ThemeIcon;
69
/**
70
* Human readable label for the context item.
71
* If not set, the label is derived from {@link resourceUri}.
72
*/
73
label?: string;
74
/**
75
* A resource URI for the context item.
76
* Used to derive the {@link label} and {@link icon} if they are not set.
77
*/
78
resourceUri?: Uri;
79
/**
80
* An optional description of the context item, e.g. to describe the item to the language model.
81
*/
82
modelDescription?: string;
83
/**
84
* An optional tooltip to show when hovering over the context item in the UI.
85
*/
86
tooltip?: MarkdownString;
87
/**
88
* The value of the context item. Can be omitted when returned from one of the `provide` methods if the provider supports `resolveChatContext`.
89
*/
90
value?: string;
91
/**
92
* An optional command that is executed when the context item is clicked.
93
* The original context item will be passed as the first argument to the command.
94
*/
95
command?: Command;
96
}
97
98
export interface ChatWorkspaceContextProvider<T extends ChatContextItem = ChatContextItem> {
99
100
/**
101
* An optional event that should be fired when the workspace chat context has changed.
102
*/
103
onDidChangeWorkspaceChatContext?: Event<void>;
104
105
/**
106
* Provide a list of chat context items to be included as workspace context for all chat requests.
107
* This should be used very sparingly to avoid providing useless context and to avoid using up the context window.
108
* A good example use case is to provide information about which branch the user is working on in a source control context.
109
*
110
* @param token A cancellation token.
111
*/
112
provideChatContext(token: CancellationToken): ProviderResult<T[]>;
113
}
114
115
export interface ChatExplicitContextProvider<T extends ChatContextItem = ChatContextItem> {
116
117
/**
118
* Provide a list of chat context items that a user can choose from. These context items are shown as options when the user explicitly attaches context.
119
* Chat context items can be provided without a `value`, as the `value` can be resolved later using `resolveChatContext`.
120
* `resolveChatContext` is only called for items that do not have a `value`.
121
*
122
* @param token A cancellation token.
123
*/
124
provideChatContext(token: CancellationToken): ProviderResult<T[]>;
125
126
/**
127
* If a chat context item is provided without a `value`, this method is called to resolve the `value` for the item.
128
*
129
* @param context The context item to resolve.
130
* @param token A cancellation token.
131
*/
132
resolveChatContext(context: T, token: CancellationToken): ProviderResult<ChatContextItem>;
133
}
134
135
export interface ChatResourceContextProvider<T extends ChatContextItem = ChatContextItem> {
136
137
/**
138
* Given a particular resource, provide a chat context item for it. This is used for implicit context (see the settings `chat.implicitContext.enabled` and `chat.implicitContext.suggestedContext`).
139
* Chat context items can be provided without a `value`, as the `value` can be resolved later using `resolveChatContext`.
140
* `resolveChatContext` is only called for items that do not have a `value`.
141
*
142
* Called when the resource is a webview or a text editor.
143
*
144
* @param options Options include the resource for which to provide context.
145
* @param token A cancellation token.
146
*/
147
provideChatContext(options: { resource: Uri }, token: CancellationToken): ProviderResult<T | undefined>;
148
149
/**
150
* If a chat context item is provided without a `value`, this method is called to resolve the `value` for the item.
151
*
152
* @param context The context item to resolve.
153
* @param token A cancellation token.
154
*/
155
resolveChatContext(context: T, token: CancellationToken): ProviderResult<ChatContextItem>;
156
}
157
158
/**
159
* @deprecated Use {@link ChatWorkspaceContextProvider}, {@link ChatExplicitContextProvider}, or {@link ChatResourceContextProvider} instead.
160
*/
161
export interface ChatContextProvider<T extends ChatContextItem = ChatContextItem> {
162
163
/**
164
* An optional event that should be fired when the workspace chat context has changed.
165
* @deprecated Use {@link ChatWorkspaceContextProvider.onDidChangeWorkspaceChatContext} instead.
166
*/
167
onDidChangeWorkspaceChatContext?: Event<void>;
168
169
/**
170
* Provide a list of chat context items to be included as workspace context for all chat requests.
171
* @deprecated Use {@link ChatWorkspaceContextProvider.provideChatContext} instead.
172
*/
173
provideWorkspaceChatContext?(token: CancellationToken): ProviderResult<T[]>;
174
175
/**
176
* Provide a list of chat context items that a user can choose from.
177
* @deprecated Use {@link ChatExplicitContextProvider.provideChatContext} instead.
178
*/
179
provideChatContextExplicit?(token: CancellationToken): ProviderResult<T[]>;
180
181
/**
182
* Given a particular resource, provide a chat context item for it.
183
* @deprecated Use {@link ChatResourceContextProvider.provideChatContext} instead.
184
*/
185
provideChatContextForResource?(options: { resource: Uri }, token: CancellationToken): ProviderResult<T | undefined>;
186
187
/**
188
* If a chat context item is provided without a `value`, this method is called to resolve the `value` for the item.
189
* @deprecated Use the `resolveChatContext` method on the specific provider type instead.
190
*/
191
resolveChatContext?(context: T, token: CancellationToken): ProviderResult<ChatContextItem>;
192
}
193
194
}
195
196