Skip to content

Commit ce749a1

Browse files
authored
Merge pull request microsoft#258334 from mjbvz/proud-mockingbird
Small cleanup/tweaks to chat session API
2 parents 34b764d + f42c875 commit ce749a1

File tree

6 files changed

+52
-38
lines changed

6 files changed

+52
-38
lines changed

src/vs/workbench/contrib/chat/browser/actions/chatActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ export function registerChatActions() {
571571
const providerNSessions: { providerType: string; session: IChatSessionItem }[] = [];
572572

573573
for (const provider of providers) {
574-
const sessions = await chatSessionsService.provideChatSessionItems(provider.id, cancellationToken.token);
575-
providerNSessions.push(...sessions.map(session => ({ providerType: provider.id, session })));
574+
const sessions = await chatSessionsService.provideChatSessionItems(provider.type, cancellationToken.token);
575+
providerNSessions.push(...sessions.map(session => ({ providerType: provider.type, session })));
576576
}
577577

578578
for (const session of providerNSessions) {

src/vs/workbench/contrib/chat/browser/chatEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class ChatEditor extends EditorPane {
139139
const identifier = ChatSessionUri.parse(input.resource);
140140
if (identifier) {
141141
const contributions = this.chatSessionsService.getChatSessionContributions();
142-
const contribution = contributions.find(c => c.id === identifier.chatSessionType);
142+
const contribution = contributions.find(c => c.type === identifier.chatSessionType);
143143
if (contribution) {
144144
this.widget.lockToCodingAgent(contribution.name);
145145
}

src/vs/workbench/contrib/chat/browser/chatSessions.contribution.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const extensionPoint = ExtensionsRegistry.registerExtensionPoint<IChatSessionsEx
3434
items: {
3535
type: 'object',
3636
properties: {
37-
id: {
38-
description: localize('chatSessionsExtPoint.id', 'A unique identifier for this item.'),
37+
type: {
38+
description: localize('chatSessionsExtPoint.chatSessionType', 'Unique identifier for the type of chat session.'),
3939
type: 'string',
4040
},
4141
name: {
@@ -60,7 +60,7 @@ const extensionPoint = ExtensionsRegistry.registerExtensionPoint<IChatSessionsEx
6060
},
6161
activationEventsGenerator: (contribs, results) => {
6262
for (const contrib of contribs) {
63-
results.push(`onChatSession:${contrib.id}`);
63+
results.push(`onChatSession:${contrib.type}`);
6464
}
6565
}
6666
});
@@ -82,14 +82,14 @@ export class ChatSessionsContribution extends Disposable implements IWorkbenchCo
8282
}
8383
for (const contribution of ext.value) {
8484
const c: IChatSessionsExtensionPoint = {
85-
id: contribution.id,
85+
type: contribution.type,
8686
name: contribution.name,
8787
displayName: contribution.displayName,
8888
description: contribution.description,
8989
when: contribution.when,
9090
extensionDescription: ext.description,
9191
};
92-
this.logService.info(`Registering chat session from extension contribution: ${c.displayName} (id='${c.id}' name='${c.name}')`);
92+
this.logService.info(`Registering chat session from extension contribution: ${c.displayName} (id='${c.type}' name='${c.name}')`);
9393
this._register(this.chatSessionsService.registerContribution(c)); // TODO: Is it for contribution to own this? I think not
9494
}
9595
}
@@ -146,8 +146,8 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
146146
}));
147147
}
148148
public registerContribution(contribution: IChatSessionsExtensionPoint): IDisposable {
149-
if (this._contributions.has(contribution.id)) {
150-
this._logService.warn(`Chat session contribution with id '${contribution.id}' is already registered.`);
149+
if (this._contributions.has(contribution.type)) {
150+
this._logService.warn(`Chat session contribution with id '${contribution.type}' is already registered.`);
151151
return { dispose: () => { } };
152152
}
153153

@@ -161,15 +161,15 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
161161
}
162162
}
163163

164-
this._contributions.set(contribution.id, contribution);
164+
this._contributions.set(contribution.type, contribution);
165165

166166
// Register dynamic agent if the when condition is satisfied
167167
this._registerDynamicAgentIfAvailable(contribution);
168168

169169
return {
170170
dispose: () => {
171-
this._contributions.delete(contribution.id);
172-
this._disposeDynamicAgent(contribution.id);
171+
this._contributions.delete(contribution.type);
172+
this._disposeDynamicAgent(contribution.type);
173173
}
174174
};
175175
}
@@ -186,7 +186,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
186186
private _registerDynamicAgentIfAvailable(contribution: IChatSessionsExtensionPoint): void {
187187
if (this._isContributionAvailable(contribution)) {
188188
const disposable = this._registerDynamicAgent(contribution);
189-
this._dynamicAgentDisposables.set(contribution.id, disposable);
189+
this._dynamicAgentDisposables.set(contribution.type, disposable);
190190
}
191191
}
192192

@@ -202,14 +202,14 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
202202
let hasChanges = false;
203203

204204
for (const contribution of this._contributions.values()) {
205-
const isCurrentlyRegistered = this._dynamicAgentDisposables.has(contribution.id);
205+
const isCurrentlyRegistered = this._dynamicAgentDisposables.has(contribution.type);
206206
const shouldBeRegistered = this._isContributionAvailable(contribution);
207207

208208
if (isCurrentlyRegistered && !shouldBeRegistered) {
209209
// Should be unregistered
210-
this._disposeDynamicAgent(contribution.id);
210+
this._disposeDynamicAgent(contribution.type);
211211
// Also dispose any cached sessions for this contribution
212-
this._disposeSessionsForContribution(contribution.id);
212+
this._disposeSessionsForContribution(contribution.type);
213213
hasChanges = true;
214214
} else if (!isCurrentlyRegistered && shouldBeRegistered) {
215215
// Should be registered
@@ -230,7 +230,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
230230

231231
// Notify about session items changes for all chat session types
232232
for (const contribution of this._contributions.values()) {
233-
this._onDidChangeSessionItems.fire(contribution.id);
233+
this._onDidChangeSessionItems.fire(contribution.type);
234234
}
235235
}
236236
}
@@ -257,7 +257,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
257257
}
258258

259259
private _registerDynamicAgent(contribution: IChatSessionsExtensionPoint): IDisposable {
260-
const { id, name, displayName, description, extensionDescription } = contribution;
260+
const { type: id, name, displayName, description, extensionDescription } = contribution;
261261
const { identifier: extensionId, name: extensionName, displayName: extensionDisplayName, publisher: extensionPublisherId } = extensionDescription;
262262
const agentData: IChatAgentData = {
263263
id,
@@ -461,7 +461,7 @@ class CodingAgentChatImplementation extends Disposable implements IChatAgentImpl
461461
const identifier = ChatSessionUri.parse(editor.resource);
462462

463463
if (identifier) {
464-
chatSession = await this.chatSessionService.provideChatSessionContent(this.chatSession.id, identifier.sessionId, token);
464+
chatSession = await this.chatSessionService.provideChatSessionContent(this.chatSession.type, identifier.sessionId, token);
465465
}
466466
break;
467467
}

src/vs/workbench/contrib/chat/browser/chatSessions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class ChatSessionsViewPaneContainer extends ViewPaneContainer {
417417
private async updateViewRegistration(): Promise<void> {
418418
// prepare all chat session providers
419419
const contributions = await this.chatSessionsService.getChatSessionContributions();
420-
await Promise.all(contributions.map(contrib => this.chatSessionsService.canResolveItemProvider(contrib.id)));
420+
await Promise.all(contributions.map(contrib => this.chatSessionsService.canResolveItemProvider(contrib.type)));
421421
const currentProviders = this.getAllChatSessionProviders();
422422
const currentProviderIds = new Set(currentProviders.map(p => p.chatSessionType));
423423

src/vs/workbench/contrib/chat/common/chatSessionsService.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import { IChatAgentRequest } from './chatAgents.js';
1414
import { IRelaxedExtensionDescription } from '../../../../platform/extensions/common/extensions.js';
1515

1616
export interface IChatSessionsExtensionPoint {
17-
id: string;
18-
name: string;
19-
displayName: string;
20-
description: string;
21-
extensionDescription: IRelaxedExtensionDescription;
22-
when?: string;
17+
readonly type: string;
18+
readonly name: string;
19+
readonly displayName: string;
20+
readonly description: string;
21+
readonly extensionDescription: IRelaxedExtensionDescription;
22+
readonly when?: string;
2323
}
2424
export interface IChatSessionItem {
2525

src/vscode-dts/vscode.proposed.chatSessionsProvider.d.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ declare module 'vscode' {
3131

3232
/**
3333
* Provides a list of chat sessions.
34-
*
35-
* TODO: Do we need a flag to try auth if needed?
3634
*/
35+
// TODO: Do we need a flag to try auth if needed?
3736
provideChatSessionItems(token: CancellationToken): ProviderResult<ChatSessionItem[]>;
3837
}
3938

@@ -60,10 +59,9 @@ declare module 'vscode' {
6059
* The full history of the session
6160
*
6261
* This should not include any currently active responses
63-
*
64-
* TODO: Are these the right types to use?
65-
* TODO: link request + response to encourage correct usage?
6662
*/
63+
// TODO: Are these the right types to use?
64+
// TODO: link request + response to encourage correct usage?
6765
readonly history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn2>;
6866

6967
/**
@@ -79,27 +77,41 @@ declare module 'vscode' {
7977
* Handles new request for the session.
8078
*
8179
* If not set, then the session will be considered read-only and no requests can be made.
82-
*
83-
* TODO: Should we introduce our own type for `ChatRequestHandler` since not all field apply to chat sessions?
8480
*/
81+
// TODO: Should we introduce our own type for `ChatRequestHandler` since not all field apply to chat sessions?
8582
readonly requestHandler: ChatRequestHandler | undefined;
8683
}
8784

8885
export interface ChatSessionContentProvider {
8986
/**
9087
* Resolves a chat session into a full `ChatSession` object.
9188
*
92-
* @param uri The URI of the chat session to open. Uris as structured as `vscode-chat-session:<chatSessionType>/id`
89+
* @param sessionId The id of the chat session to open.
9390
* @param token A cancellation token that can be used to cancel the operation.
9491
*/
95-
provideChatSessionContent(id: string, token: CancellationToken): Thenable<ChatSession>;
92+
provideChatSessionContent(sessionId: string, token: CancellationToken): Thenable<ChatSession> | ChatSession;
9693
}
9794

9895
export namespace chat {
96+
/**
97+
* Registers a new {@link ChatSessionItemProvider chat session item provider}.
98+
*
99+
* To use this, also make sure to also add `chatSessions` contribution in the `package.json`.
100+
*
101+
* @param chatSessionType The type of chat session the provider is for.
102+
* @param provider The provider to register.
103+
*
104+
* @returns A disposable that unregisters the provider when disposed.
105+
*/
99106
export function registerChatSessionItemProvider(chatSessionType: string, provider: ChatSessionItemProvider): Disposable;
100107

101108
/**
109+
* Registers a new {@link ChatSessionContentProvider chat session content provider}.
110+
*
102111
* @param chatSessionType A unique identifier for the chat session type. This is used to differentiate between different chat session providers.
112+
* @param provider The provider to register.
113+
*
114+
* @returns A disposable that unregisters the provider when disposed.
103115
*/
104116
export function registerChatSessionContentProvider(chatSessionType: string, provider: ChatSessionContentProvider): Disposable;
105117
}
@@ -114,7 +126,9 @@ declare module 'vscode' {
114126
}
115127

116128
export namespace window {
117-
118-
export function showChatSession(chatSessionType: string, id: string, options: ChatSessionShowOptions): Thenable<void>;
129+
/**
130+
* Shows a chat session in the panel or editor.
131+
*/
132+
export function showChatSession(chatSessionType: string, sessionId: string, options: ChatSessionShowOptions): Thenable<void>;
119133
}
120134
}

0 commit comments

Comments
 (0)