|
| 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 context provider. Chat context can be provided: |
| 15 | + * - For a resource. Make sure to pass a selector that matches the resource you want to provide context for. |
| 16 | + * Providers registered without a selector will not be called for resource-based context. |
| 17 | + * - Explicitly. These context items are shown as options when the user explicitly attaches context. |
| 18 | + * |
| 19 | + * To ensure your extension is activated when chat context is requested, make sure to include the `onChatContextProvider:<id>` activation event in your `package.json`. |
| 20 | + * |
| 21 | + * @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. |
| 22 | + * @param id Unique identifier for the provider. |
| 23 | + * @param provider The chat context provider. |
| 24 | + */ |
| 25 | + export function registerChatContextProvider(selector: DocumentSelector | undefined, id: string, provider: ChatContextProvider): Disposable; |
| 26 | + |
| 27 | + } |
| 28 | + |
| 29 | + export interface ChatContextItem { |
| 30 | + /** |
| 31 | + * Icon for the context item. |
| 32 | + */ |
| 33 | + icon: ThemeIcon; |
| 34 | + /** |
| 35 | + * Human readable label for the context item. |
| 36 | + */ |
| 37 | + label: string; |
| 38 | + /** |
| 39 | + * An optional description of the context item, e.g. to describe the item to the language model. |
| 40 | + */ |
| 41 | + modelDescription?: string; |
| 42 | + /** |
| 43 | + * The value of the context item. Can be omitted when returned from one of the `provide` methods if the provider supports `resolveChatContext`. |
| 44 | + */ |
| 45 | + value?: string; |
| 46 | + } |
| 47 | + |
| 48 | + export interface ChatContextProvider<T extends ChatContextItem = ChatContextItem> { |
| 49 | + |
| 50 | + /** |
| 51 | + * An optional event that should be fired when the workspace chat context has changed. |
| 52 | + */ |
| 53 | + onDidChangeWorkspaceChatContext?: Event<void>; |
| 54 | + |
| 55 | + /** |
| 56 | + * Provide a list of chat context items to be included as workspace context for all chat sessions. |
| 57 | + * |
| 58 | + * @param token A cancellation token. |
| 59 | + */ |
| 60 | + provideWorkspaceChatContext?(token: CancellationToken): ProviderResult<T[]>; |
| 61 | + |
| 62 | + /** |
| 63 | + * 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. |
| 64 | + * Chat context items can be provided without a `value`, as the `value` can be resolved later using `resolveChatContext`. |
| 65 | + * `resolveChatContext` is only called for items that do not have a `value`. |
| 66 | + * |
| 67 | + * @param token A cancellation token. |
| 68 | + */ |
| 69 | + provideChatContextExplicit?(token: CancellationToken): ProviderResult<T[]>; |
| 70 | + |
| 71 | + /** |
| 72 | + * 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`). |
| 73 | + * Chat context items can be provided without a `value`, as the `value` can be resolved later using `resolveChatContext`. |
| 74 | + * `resolveChatContext` is only called for items that do not have a `value`. |
| 75 | + * |
| 76 | + * @param options Options include the resource for which to provide context. |
| 77 | + * @param token A cancellation token. |
| 78 | + */ |
| 79 | + provideChatContextForResource?(options: { resource: Uri }, token: CancellationToken): ProviderResult<T | undefined>; |
| 80 | + |
| 81 | + /** |
| 82 | + * If a chat context item is provided without a `value`, from either of the `provide` methods, this method is called to resolve the `value` for the item. |
| 83 | + * |
| 84 | + * @param context The context item to resolve. |
| 85 | + * @param token A cancellation token. |
| 86 | + */ |
| 87 | + resolveChatContext(context: T, token: CancellationToken): ProviderResult<ChatContextItem>; |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments