@@ -35,6 +35,8 @@ declare module 'vscode' {
3535 /**
3636 * Registers a new {@link ChatSessionItemProvider chat session item provider}.
3737 *
38+ * @deprecated Use {@linkcode createChatSessionItemController} instead.
39+ *
3840 * To use this, also make sure to also add `chatSessions` contribution in the `package.json`.
3941 *
4042 * @param chatSessionType The type of chat session the provider is for.
@@ -46,12 +48,21 @@ declare module 'vscode' {
4648
4749 /**
4850 * Creates a new {@link ChatSessionItemController chat session item controller} with the given unique identifier.
51+ *
52+ * To use this, also make sure to also add `chatSessions` contribution in the `package.json`.
53+ *
54+ * @param chatSessionType The type of chat session the provider is for.
55+ * @param refreshHandler The controller's {@link ChatSessionItemController.refreshHandler refresh handler}.
56+ *
57+ * @returns A new controller instance that can be used to manage chat session items for the given chat session type.
4958 */
50- export function createChatSessionItemController ( id : string , refreshHandler : ( token : CancellationToken ) => Thenable < void > ) : ChatSessionItemController ;
59+ export function createChatSessionItemController ( chatSessionType : string , refreshHandler : ChatSessionItemControllerRefreshHandler ) : ChatSessionItemController ;
5160 }
5261
5362 /**
5463 * Provides a list of information about chat sessions.
64+ *
65+ * @deprecated Use {@linkcode ChatSessionItemController} instead.
5566 */
5667 export interface ChatSessionItemProvider {
5768 /**
@@ -77,7 +88,21 @@ declare module 'vscode' {
7788 }
7889
7990 /**
80- * Provides a list of information about chat sessions.
91+ * Extension callback invoked to refresh the collection of chat session items for a {@linkcode ChatSessionItemController}.
92+ */
93+ export type ChatSessionItemControllerRefreshHandler = ( token : CancellationToken ) => Thenable < void > ;
94+
95+ export interface ChatSessionItemControllerNewItemHandlerContext {
96+ readonly request : ChatRequest ;
97+ }
98+
99+ /**
100+ * Extension callback invoked when a new chat session is started.
101+ */
102+ export type ChatSessionItemControllerNewItemHandler = ( context : ChatSessionItemControllerNewItemHandlerContext , token : CancellationToken ) => Thenable < ChatSessionItem > ;
103+
104+ /**
105+ * Manages chat sessions for a specific chat session type
81106 */
82107 export interface ChatSessionItemController {
83108 readonly id : string ;
@@ -93,7 +118,7 @@ declare module 'vscode' {
93118 readonly items : ChatSessionItemCollection ;
94119
95120 /**
96- * Creates a new managed chat session item that be added to the collection.
121+ * Creates a new managed chat session item that can be added to the collection.
97122 */
98123 createChatSessionItem ( resource : Uri , label : string ) : ChatSessionItem ;
99124
@@ -102,7 +127,16 @@ declare module 'vscode' {
102127 *
103128 * This is also called on first load to get the initial set of items.
104129 */
105- readonly refreshHandler : ( token : CancellationToken ) => Thenable < void > ;
130+ readonly refreshHandler : ChatSessionItemControllerRefreshHandler ;
131+
132+ /**
133+ * Invoked when a new chat session is started.
134+ *
135+ * This allows the controller to initialize the chat session item with information from the initial request.
136+ *
137+ * The returned chat session is added to the collection and shown in the UI.
138+ */
139+ newChatSessionItemHandler ?: ChatSessionItemControllerNewItemHandler ;
106140
107141 /**
108142 * Fired when an item's archived state changes.
@@ -121,7 +155,8 @@ declare module 'vscode' {
121155
122156 /**
123157 * Replaces the items stored by the collection.
124- * @param items Items to store.
158+ *
159+ * @param items Items to store. If two items have the same resource URI, the last one will be used.
125160 */
126161 replace ( items : readonly ChatSessionItem [ ] ) : void ;
127162
@@ -136,31 +171,42 @@ declare module 'vscode' {
136171 /**
137172 * Adds the chat session item to the collection. If an item with the same resource URI already
138173 * exists, it'll be replaced.
174+ *
139175 * @param item Item to add.
140176 */
141177 add ( item : ChatSessionItem ) : void ;
142178
143179 /**
144180 * Removes a single chat session item from the collection.
181+ *
145182 * @param resource Item resource to delete.
146183 */
147184 delete ( resource : Uri ) : void ;
148185
149186 /**
150187 * Efficiently gets a chat session item by resource, if it exists, in the collection.
188+ *
151189 * @param resource Item resource to get.
190+ *
152191 * @returns The found item or undefined if it does not exist.
153192 */
154193 get ( resource : Uri ) : ChatSessionItem | undefined ;
155194 }
156195
196+ /**
197+ * A chat session show in the UI.
198+ *
199+ * This should be created by calling a {@link ChatSessionItemController.createChatSessionItem createChatSessionItem}
200+ * method on the controller. The item can then be added to the controller's {@link ChatSessionItemController.items items collection}
201+ * to show it in the UI.
202+ */
157203 export interface ChatSessionItem {
158204 /**
159205 * The resource associated with the chat session.
160206 *
161207 * This is uniquely identifies the chat session and is used to open the chat session.
162208 */
163- resource : Uri ;
209+ readonly resource : Uri ;
164210
165211 /**
166212 * Human readable name of the session shown in the UI
@@ -300,6 +346,15 @@ declare module 'vscode' {
300346 }
301347
302348 export interface ChatSession {
349+ /**
350+ * An optional title for the chat session.
351+ *
352+ * When provided, this title is used as the display name for the session
353+ * (e.g. in the editor tab). When not provided, the title defaults to
354+ * the first user message in the session history.
355+ */
356+ readonly title ?: string ;
357+
303358 /**
304359 * The full history of the session
305360 *
@@ -335,6 +390,7 @@ declare module 'vscode' {
335390 */
336391 // TODO: Should we introduce our own type for `ChatRequestHandler` since not all field apply to chat sessions?
337392 // TODO: Revisit this to align with code.
393+ // TODO: pass in options?
338394 readonly requestHandler : ChatRequestHandler | undefined ;
339395 }
340396
@@ -400,9 +456,8 @@ declare module 'vscode' {
400456
401457 /**
402458 * Called as soon as you register (call me once)
403- * @param token
404459 */
405- provideChatSessionProviderOptions ?( token : CancellationToken ) : Thenable < ChatSessionProviderOptions | ChatSessionProviderOptions > ;
460+ provideChatSessionProviderOptions ?( token : CancellationToken ) : Thenable < ChatSessionProviderOptions > ;
406461 }
407462
408463 export interface ChatSessionOptionUpdate {
@@ -435,7 +490,15 @@ declare module 'vscode' {
435490
436491 export interface ChatSessionContext {
437492 readonly chatSessionItem : ChatSessionItem ; // Maps to URI of chat session editor (could be 'untitled-1', etc..)
493+
494+ /** @deprecated This will be removed along with the concept of `untitled-` sessions. */
438495 readonly isUntitled : boolean ;
496+
497+ /**
498+ * The initial option selections for the session, provided with the first request.
499+ * Contains the options the user selected (or defaults) before the session was created.
500+ */
501+ readonly initialSessionOptions ?: ReadonlyArray < { optionId : string ; value : string | ChatSessionProviderOptionItem } > ;
439502 }
440503
441504 export interface ChatSessionCapabilities {
@@ -551,6 +614,13 @@ declare module 'vscode' {
551614 * Provider-defined option groups (0-2 groups supported).
552615 * Examples: models picker, sub-agents picker, etc.
553616 */
554- optionGroups ?: ChatSessionProviderOptionGroup [ ] ;
617+ readonly optionGroups ?: readonly ChatSessionProviderOptionGroup [ ] ;
618+
619+ /**
620+ * The set of default options used for new chat sessions, provided as key-value pairs.
621+ *
622+ * Keys correspond to option group IDs (e.g., 'models', 'subagents').
623+ */
624+ readonly newSessionOptions ?: Record < string , string | ChatSessionProviderOptionItem > ;
555625 }
556626}
0 commit comments