Path: blob/main/src/vscode-dts/vscode.proposed.chatSessionsProvider.d.ts
5270 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45// version: 367declare module 'vscode' {8/**9* Represents the status of a chat session.10*/11export enum ChatSessionStatus {12/**13* The chat session failed to complete.14*/15Failed = 0,1617/**18* The chat session completed successfully.19*/20Completed = 1,2122/**23* The chat session is currently in progress.24*/25InProgress = 2,2627/**28* The chat session needs user input (e.g. an unresolved confirmation).29*/30NeedsInput = 331}3233export namespace chat {34/**35* Registers a new {@link ChatSessionItemProvider chat session item provider}.36*37* To use this, also make sure to also add `chatSessions` contribution in the `package.json`.38*39* @param chatSessionType The type of chat session the provider is for.40* @param provider The provider to register.41*42* @returns A disposable that unregisters the provider when disposed.43*/44export function registerChatSessionItemProvider(chatSessionType: string, provider: ChatSessionItemProvider): Disposable;4546/**47* Creates a new {@link ChatSessionItemController chat session item controller} with the given unique identifier.48*/49export function createChatSessionItemController(id: string, refreshHandler: (token: CancellationToken) => Thenable<void>): ChatSessionItemController;50}5152/**53* Provides a list of information about chat sessions.54*/55export interface ChatSessionItemProvider {56/**57* Event that the provider can fire to signal that chat sessions have changed.58*/59readonly onDidChangeChatSessionItems: Event<void>;6061/**62* Provides a list of chat sessions.63*/64// TODO: Do we need a flag to try auth if needed?65provideChatSessionItems(token: CancellationToken): ProviderResult<ChatSessionItem[]>;6667// #region Unstable parts of API6869/**70* Event that the provider can fire to signal that the current (original) chat session should be replaced with a new (modified) chat session.71* The UI can use this information to gracefully migrate the user to the new session.72*/73readonly onDidCommitChatSessionItem: Event<{ original: ChatSessionItem /** untitled */; modified: ChatSessionItem /** newly created */ }>;7475// #endregion76}7778/**79* Provides a list of information about chat sessions.80*/81export interface ChatSessionItemController {82readonly id: string;8384/**85* Unregisters the controller, disposing of its associated chat session items.86*/87dispose(): void;8889/**90* Managed collection of chat session items91*/92readonly items: ChatSessionItemCollection;9394/**95* Creates a new managed chat session item that be added to the collection.96*/97createChatSessionItem(resource: Uri, label: string): ChatSessionItem;9899/**100* Handler called to refresh the collection of chat session items.101*102* This is also called on first load to get the initial set of items.103*/104refreshHandler: (token: CancellationToken) => Thenable<void>;105106/**107* Fired when an item's archived state changes.108*/109readonly onDidChangeChatSessionItemState: Event<ChatSessionItem>;110}111112/**113* A collection of chat session items. It provides operations for managing and iterating over the items.114*/115export interface ChatSessionItemCollection extends Iterable<readonly [id: Uri, chatSessionItem: ChatSessionItem]> {116/**117* Gets the number of items in the collection.118*/119readonly size: number;120121/**122* Replaces the items stored by the collection.123* @param items Items to store.124*/125replace(items: readonly ChatSessionItem[]): void;126127/**128* Iterate over each entry in this collection.129*130* @param callback Function to execute for each entry.131* @param thisArg The `this` context used when invoking the handler function.132*/133forEach(callback: (item: ChatSessionItem, collection: ChatSessionItemCollection) => unknown, thisArg?: any): void;134135/**136* Adds the chat session item to the collection. If an item with the same resource URI already137* exists, it'll be replaced.138* @param item Item to add.139*/140add(item: ChatSessionItem): void;141142/**143* Removes a single chat session item from the collection.144* @param resource Item resource to delete.145*/146delete(resource: Uri): void;147148/**149* Efficiently gets a chat session item by resource, if it exists, in the collection.150* @param resource Item resource to get.151* @returns The found item or undefined if it does not exist.152*/153get(resource: Uri): ChatSessionItem | undefined;154}155156export interface ChatSessionItem {157/**158* The resource associated with the chat session.159*160* This is uniquely identifies the chat session and is used to open the chat session.161*/162resource: Uri;163164/**165* Human readable name of the session shown in the UI166*/167label: string;168169/**170* An icon for the participant shown in UI.171*/172iconPath?: IconPath;173174/**175* An optional description that provides additional context about the chat session.176*/177description?: string | MarkdownString;178179/**180* An optional badge that provides additional context about the chat session.181*/182badge?: string | MarkdownString;183184/**185* An optional status indicating the current state of the session.186*/187status?: ChatSessionStatus;188189/**190* The tooltip text when you hover over this item.191*/192tooltip?: string | MarkdownString;193194/**195* Whether the chat session has been archived.196*/197archived?: boolean;198199/**200* Timing information for the chat session201*/202timing?: {203/**204* Timestamp when the session was created in milliseconds elapsed since January 1, 1970 00:00:00 UTC.205*/206created: number;207208/**209* Timestamp when the most recent request started in milliseconds elapsed since January 1, 1970 00:00:00 UTC.210*211* Should be undefined if no requests have been made yet.212*/213lastRequestStarted?: number;214215/**216* Timestamp when the most recent request completed in milliseconds elapsed since January 1, 1970 00:00:00 UTC.217*218* Should be undefined if the most recent request is still in progress or if no requests have been made yet.219*/220lastRequestEnded?: number;221222/**223* Session start timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.224* @deprecated Use `created` and `lastRequestStarted` instead.225*/226startTime?: number;227228/**229* Session end timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.230* @deprecated Use `lastRequestEnded` instead.231*/232endTime?: number;233};234235/**236* Statistics about the chat session.237*/238changes?: readonly ChatSessionChangedFile[] | readonly ChatSessionChangedFile2[];239240/**241* Arbitrary metadata for the chat session. Can be anything, but must be JSON-stringifyable.242*243* To update the metadata you must re-set this property.244*/245metadata?: { readonly [key: string]: any };246}247248export class ChatSessionChangedFile {249/**250* URI of the file.251*/252modifiedUri: Uri;253254/**255* File opened when the user takes the 'compare' action.256*/257originalUri?: Uri;258259/**260* Number of insertions made during the session.261*/262insertions: number;263264/**265* Number of deletions made during the session.266*/267deletions: number;268269constructor(modifiedUri: Uri, insertions: number, deletions: number, originalUri?: Uri);270}271272export class ChatSessionChangedFile2 {273/**274* URI of the file.275*/276readonly uri: Uri;277278/**279* URI of the original file. Undefined if the file was created.280*/281readonly originalUri: Uri | undefined;282283/**284* URI of the modified file. Undefined if the file was deleted.285*/286readonly modifiedUri: Uri | undefined;287288/**289* Number of insertions made during the session.290*/291insertions: number;292293/**294* Number of deletions made during the session.295*/296deletions: number;297298constructor(uri: Uri, originalUri: Uri | undefined, modifiedUri: Uri | undefined, insertions: number, deletions: number);299}300301export interface ChatSession {302/**303* The full history of the session304*305* This should not include any currently active responses306*/307// TODO: Are these the right types to use?308// TODO: link request + response to encourage correct usage?309readonly history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn2>;310311/**312* Options configured for this session as key-value pairs.313* Keys correspond to option group IDs (e.g., 'models', 'subagents').314* Values can be either:315* - A string (the option item ID) for backwards compatibility316* - A ChatSessionProviderOptionItem object to include metadata like locked state317* TODO: Strongly type the keys318*/319readonly options?: Record<string, string | ChatSessionProviderOptionItem>;320321/**322* Callback invoked by the editor for a currently running response. This allows the session to push items for the323* current response and stream these in as them come in. The current response will be considered complete once the324* callback resolved.325*326* If not provided, the chat session is assumed to not currently be running.327*/328readonly activeResponseCallback?: (stream: ChatResponseStream, token: CancellationToken) => Thenable<void>;329330/**331* Handles new request for the session.332*333* If not set, then the session will be considered read-only and no requests can be made.334*/335// TODO: Should we introduce our own type for `ChatRequestHandler` since not all field apply to chat sessions?336// TODO: Revisit this to align with code.337readonly requestHandler: ChatRequestHandler | undefined;338}339340/**341* Event fired when chat session options change.342*/343export interface ChatSessionOptionChangeEvent {344/**345* Identifier of the chat session being updated.346*/347readonly resource: Uri;348/**349* Collection of option identifiers and their new values. Only the options that changed are included.350*/351readonly updates: ReadonlyArray<{352/**353* Identifier of the option that changed (for example `model`).354*/355readonly optionId: string;356357/**358* The new value assigned to the option. When `undefined`, the option is cleared.359*/360readonly value: string | ChatSessionProviderOptionItem;361}>;362}363364/**365* Provides the content for a chat session rendered using the native chat UI.366*/367export interface ChatSessionContentProvider {368/**369* Event that the provider can fire to signal that the options for a chat session have changed.370*/371readonly onDidChangeChatSessionOptions?: Event<ChatSessionOptionChangeEvent>;372373/**374* Event that the provider can fire to signal that the available provider options have changed.375*376* When fired, the editor will re-query {@link ChatSessionContentProvider.provideChatSessionProviderOptions}377* and update the UI to reflect the new option groups.378*/379readonly onDidChangeChatSessionProviderOptions?: Event<void>;380381/**382* Provides the chat session content for a given uri.383*384* The returned {@linkcode ChatSession} is used to populate the history of the chat UI.385*386* @param resource The URI of the chat session to resolve.387* @param token A cancellation token that can be used to cancel the operation.388*389* @return The {@link ChatSession chat session} associated with the given URI.390*/391provideChatSessionContent(resource: Uri, token: CancellationToken): Thenable<ChatSession> | ChatSession;392393/**394* @param resource Identifier of the chat session being updated.395* @param updates Collection of option identifiers and their new values. Only the options that changed are included.396* @param token A cancellation token that can be used to cancel the notification if the session is disposed.397*/398provideHandleOptionsChange?(resource: Uri, updates: ReadonlyArray<ChatSessionOptionUpdate>, token: CancellationToken): void;399400/**401* Called as soon as you register (call me once)402* @param token403*/404provideChatSessionProviderOptions?(token: CancellationToken): Thenable<ChatSessionProviderOptions | ChatSessionProviderOptions>;405}406407export interface ChatSessionOptionUpdate {408/**409* Identifier of the option that changed (for example `model`).410*/411readonly optionId: string;412413/**414* The new value assigned to the option. When `undefined`, the option is cleared.415*/416readonly value: string | undefined;417}418419export namespace chat {420/**421* Registers a new {@link ChatSessionContentProvider chat session content provider}.422*423* @param scheme The uri-scheme to register for. This must be unique.424* @param provider The provider to register.425*426* @returns A disposable that unregisters the provider when disposed.427*/428export function registerChatSessionContentProvider(scheme: string, provider: ChatSessionContentProvider, chatParticipant: ChatParticipant, capabilities?: ChatSessionCapabilities): Disposable;429}430431export interface ChatContext {432readonly chatSessionContext?: ChatSessionContext;433}434435export interface ChatSessionContext {436readonly chatSessionItem: ChatSessionItem; // Maps to URI of chat session editor (could be 'untitled-1', etc..)437readonly isUntitled: boolean;438}439440export interface ChatSessionCapabilities {441/**442* Whether sessions can be interrupted and resumed without side-effects.443*/444supportsInterruptions?: boolean;445}446447/**448* Represents a single selectable item within a provider option group.449*/450export interface ChatSessionProviderOptionItem {451/**452* Unique identifier for the option item.453*/454readonly id: string;455456/**457* Human-readable name displayed in the UI.458*/459readonly name: string;460461/**462* Optional description shown in tooltips.463*/464readonly description?: string;465466/**467* When true, this option is locked and cannot be changed by the user.468* The option will still be visible in the UI but will be disabled.469* Use this when an option is set but cannot be hot-swapped (e.g., model already initialized).470*/471readonly locked?: boolean;472473/**474* An icon for the option item shown in UI.475*/476readonly icon?: ThemeIcon;477478/**479* Indicates if this option should be selected by default.480* Only one item per option group should be marked as default.481*/482readonly default?: boolean;483}484485/**486* Represents a group of related provider options (e.g., models, sub-agents).487*/488export interface ChatSessionProviderOptionGroup {489/**490* Unique identifier for the option group (e.g., "models", "subagents").491*/492readonly id: string;493494/**495* Human-readable name for the option group.496*/497readonly name: string;498499/**500* Optional description providing context about this option group.501*/502readonly description?: string;503504/**505* The selectable items within this option group.506*/507readonly items: ChatSessionProviderOptionItem[];508509/**510* A context key expression that controls when this option group picker is visible.511* When specified, the picker is only shown when the expression evaluates to true.512* The expression can reference other option group values via `chatSessionOption.<groupId>`.513*514* Example: `"chatSessionOption.models == 'gpt-4'"` - only show this picker when515* the 'models' option group has 'gpt-4' selected.516*/517readonly when?: string;518519/**520* When true, displays a searchable QuickPick with a "See more..." option.521* Recommended for option groups with additional async items (e.g., repositories).522*/523readonly searchable?: boolean;524525/**526* An icon for the option group shown in UI.527*/528readonly icon?: ThemeIcon;529530/**531* Handler for dynamic search when `searchable` is true.532* Called when the user types in the searchable QuickPick or clicks "See more..." to load additional items.533*534* @param query The search query entered by the user. Empty string for initial load.535* @param token A cancellation token.536* @returns Additional items to display in the searchable QuickPick.537*/538readonly onSearch?: (query: string, token: CancellationToken) => Thenable<ChatSessionProviderOptionItem[]>;539540/**541* Optional commands.542*543* These commands will be displayed at the bottom of the group.544*/545readonly commands?: Command[];546}547548export interface ChatSessionProviderOptions {549/**550* Provider-defined option groups (0-2 groups supported).551* Examples: models picker, sub-agents picker, etc.552*/553optionGroups?: ChatSessionProviderOptionGroup[];554}555}556557558