Skip to content

Commit eb082b9

Browse files
committed
Reshape chat session api
Name and shape cleanup
1 parent 3547642 commit eb082b9

File tree

3 files changed

+31
-40
lines changed

3 files changed

+31
-40
lines changed

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,9 +1505,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
15051505
checkProposedApiEnabled(extension, 'chatParticipantPrivate');
15061506
return _asExtensionEvent(extHostChatAgents2.onDidDisposeChatSession)(listeners, thisArgs, disposables);
15071507
},
1508-
registerChatSessionsProvider(provider: vscode.ChatSessionsProvider) {
1508+
registerChatSessionItemProvider(chatSessionType: string, provider: vscode.ChatSessionItemProvider) {
15091509
checkProposedApiEnabled(extension, 'chatSessionsProvider');
1510-
return extHostChatSessions.registerChatSessionsProvider(provider);
1510+
return extHostChatSessions.registerChatSessionItemProvider(chatSessionType, provider);
15111511
},
15121512
};
15131513

src/vs/workbench/api/common/extHostChatSessions.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,23 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Disposable, DisposableStore } from '../../../base/common/lifecycle.js';
7-
import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
8-
import { IExtHostRpcService } from './extHostRpcService.js';
9-
import { ExtHostChatSessionsShape, MainContext, MainThreadChatSessionsShape } from './extHost.protocol.js';
106
import type * as vscode from 'vscode';
7+
import { Disposable, DisposableStore } from '../../../base/common/lifecycle.js';
8+
import { MarshalledId } from '../../../base/common/marshallingIds.js';
9+
import { URI } from '../../../base/common/uri.js';
1110
import { ILogService } from '../../../platform/log/common/log.js';
1211
import { Proxied } from '../../services/extensions/common/proxyIdentifier.js';
12+
import { ExtHostChatSessionsShape, MainContext, MainThreadChatSessionsShape } from './extHost.protocol.js';
1313
import { ExtHostCommands } from './extHostCommands.js';
14-
import { MarshalledId } from '../../../base/common/marshallingIds.js';
15-
import { URI } from '../../../base/common/uri.js';
16-
17-
export interface IExtHostChatSessions extends ExtHostChatSessionsShape {
18-
registerChatSessionsProvider(provider: vscode.ChatSessionsProvider): vscode.Disposable;
19-
$provideChatSessions(handle: number, token: vscode.CancellationToken): Promise<vscode.ChatSessionContent[]>;
20-
}
21-
export const IExtHostChatSessions = createDecorator<IExtHostChatSessions>('IExtHostChatSessions');
14+
import { IExtHostRpcService } from './extHostRpcService.js';
15+
import { IChatSessionContent } from '../../contrib/chat/common/chatSessionsService.js';
2216

23-
export class ExtHostChatSessions extends Disposable implements IExtHostChatSessions {
24-
declare _serviceBrand: undefined;
17+
export class ExtHostChatSessions extends Disposable implements ExtHostChatSessionsShape {
2518

2619
private readonly _proxy: Proxied<MainThreadChatSessionsShape>;
27-
private readonly _statusProviders = new Map<number, { provider: vscode.ChatSessionsProvider; disposable: DisposableStore }>();
20+
private readonly _statusProviders = new Map<number, { provider: vscode.ChatSessionItemProvider; disposable: DisposableStore }>();
2821
private _nextHandle = 0;
29-
private _sessionMap: Map<string, vscode.ChatSessionContent> = new Map();
22+
private _sessionMap: Map<string, vscode.ChatSessionItem> = new Map();
3023

3124
constructor(
3225
commands: ExtHostCommands,
@@ -54,32 +47,35 @@ export class ExtHostChatSessions extends Disposable implements IExtHostChatSessi
5447
});
5548
}
5649

57-
registerChatSessionsProvider(provider: vscode.ChatSessionsProvider): vscode.Disposable {
50+
registerChatSessionItemProvider(chatSessionType: string, provider: vscode.ChatSessionItemProvider): vscode.Disposable {
5851
const handle = this._nextHandle++;
5952
const disposables = new DisposableStore();
6053

6154
this._statusProviders.set(handle, { provider, disposable: disposables });
62-
this._proxy.$registerChatSessionsProvider(handle, provider.chatSessionType);
55+
this._proxy.$registerChatSessionsProvider(handle, chatSessionType);
6356

6457
return {
6558
dispose: () => {
6659
this._statusProviders.delete(handle);
6760
disposables.dispose();
68-
provider.dispose();
6961
this._proxy.$unregisterChatSessionsProvider(handle);
7062
}
7163
};
7264
}
7365

74-
async $provideChatSessions(handle: number, token: vscode.CancellationToken): Promise<vscode.ChatSessionContent[]> {
66+
async $provideChatSessions(handle: number, token: vscode.CancellationToken): Promise<IChatSessionContent[]> {
7567
const entry = this._statusProviders.get(handle);
7668
if (!entry) {
7769
this._logService.error(`No provider registered for handle ${handle}`);
7870
return [];
7971
}
8072

81-
const sessions = await entry.provider.provideChatSessions(token);
82-
const response: vscode.ChatSessionContent[] = [];
73+
const sessions = await entry.provider.provideChatSessionItems(token);
74+
if (!sessions) {
75+
return [];
76+
}
77+
78+
const response: IChatSessionContent[] = [];
8379
for (const sessionContent of sessions) {
8480
if (sessionContent.uri) {
8581
this._sessionMap.set(

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,25 @@
55

66
declare module 'vscode' {
77
/**
8-
* Provides a list of chat sessions
8+
* Provides a list of information about chat sessions.
99
*/
10-
export interface ChatSessionsProvider extends Disposable {
10+
export interface ChatSessionItemProvider {
1111
/**
12-
* Type to identify providers.
12+
* Event that the provider can fire to signal that chat sessions have changed.
1313
*/
14-
readonly chatSessionType: string;
14+
readonly onDidChangeChatSessionItems: Event<void>;
1515

1616
/**
17-
* Fired when chat sessions change.
17+
* Provides a list of chat sessions.
1818
*/
19-
readonly onDidChangeChatSessionContent: Event<void>;
20-
21-
/**
22-
* Provide a list of chat sessions.
23-
* */
24-
provideChatSessions(token: CancellationToken): Thenable<ChatSessionContent[]>;
19+
provideChatSessionItems(token: CancellationToken): ProviderResult<ChatSessionItem[]>;
2520
}
2621

27-
export interface ChatSessionContent {
22+
export interface ChatSessionItem {
2823
/**
29-
* Identifies the session
30-
* */
31-
uri: Uri;
24+
* Unique identifier for the chat session.
25+
*/
26+
id: string;
3227

3328
/**
3429
* Human readable name of the session shown in the UI
@@ -42,6 +37,6 @@ declare module 'vscode' {
4237
}
4338

4439
export namespace chat {
45-
export function registerChatSessionsProvider(provider: ChatSessionsProvider): Disposable;
40+
export function registerChatSessionItemProvider(chatSessionType: string, provider: ChatSessionItemProvider): Disposable;
4641
}
4742
}

0 commit comments

Comments
 (0)