Skip to content

Commit a88f68b

Browse files
authored
Merge pull request #256647 from microsoft/osortega/agents-show-chat-menu
Coding agents to show in "Show chats" menu
2 parents 3b2551c + 714d1f5 commit a88f68b

File tree

12 files changed

+528
-112
lines changed

12 files changed

+528
-112
lines changed

src/vs/base/common/marshallingIds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ export const enum MarshalledId {
2727
LanguageModelTextPart,
2828
LanguageModelPromptTsxPart,
2929
LanguageModelDataPart,
30+
ChatSessionContext,
3031
}

src/vs/platform/actions/common/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export class MenuId {
256256
static readonly ChatTextEditorMenu = new MenuId('ChatTextEditorMenu');
257257
static readonly ChatTerminalMenu = new MenuId('ChatTerminalMenu');
258258
static readonly ChatToolOutputResourceContext = new MenuId('ChatToolOutputResourceContext');
259+
static readonly ChatSessionsMenu = new MenuId('ChatSessionsMenu');
259260
static readonly AccessibleView = new MenuId('AccessibleView');
260261
static readonly MultiDiffEditorFileToolbar = new MenuId('MultiDiffEditorFileToolbar');
261262
static readonly DiffEditorHunkToolbar = new MenuId('DiffEditorHunkToolbar');

src/vs/workbench/api/browser/mainThreadChatSessions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ export class MainThreadChatSessions extends Disposable implements MainThreadChat
2323
super();
2424
}
2525

26-
$registerChatSessionsProvider(handle: number): void {
26+
$registerChatSessionsProvider(handle: number, chatSessionType: string): void {
2727
// Register the provider handle - this tracks that a provider exists
2828
const provider: IChatSessionsProvider = {
29+
chatSessionType,
2930
provideChatSessions: (token) => this._provideChatSessionsInformation(handle, token)
3031
};
3132
this._registrations.set(handle, this._chatSessionsService.registerChatSessionsProvider(handle, provider));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ import { ExtHostWebviewViews } from './extHostWebviewView.js';
112112
import { IExtHostWindow } from './extHostWindow.js';
113113
import { IExtHostWorkspace } from './extHostWorkspace.js';
114114
import { ExtHostAiSettingsSearch } from './extHostAiSettingsSearch.js';
115-
import { IExtHostChatSessions } from './extHostChatSessions.js';
115+
import { ExtHostChatSessions } from './extHostChatSessions.js';
116116

117117
export interface IExtensionRegistries {
118118
mine: ExtensionDescriptionRegistry;
@@ -154,7 +154,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
154154
const extHostLanguageModels = accessor.get(IExtHostLanguageModels);
155155
const extHostMcp = accessor.get(IExtHostMpcService);
156156
const extHostDataChannels = accessor.get(IExtHostDataChannels);
157-
const extHostChatSessions = accessor.get(IExtHostChatSessions);
158157

159158
// register addressable instances
160159
rpcProtocol.set(ExtHostContext.ExtHostFileSystemInfo, extHostFileSystemInfo);
@@ -174,7 +173,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
174173
rpcProtocol.set(ExtHostContext.ExtHostAuthentication, extHostAuthentication);
175174
rpcProtocol.set(ExtHostContext.ExtHostChatProvider, extHostLanguageModels);
176175
rpcProtocol.set(ExtHostContext.ExtHostDataChannels, extHostDataChannels);
177-
rpcProtocol.set(ExtHostContext.ExtHostChatSessions, extHostChatSessions);
178176

179177
// automatically create and register addressable instances
180178
const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, accessor.get(IExtHostDecorations));
@@ -231,6 +229,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
231229
const extHostStatusBar = rpcProtocol.set(ExtHostContext.ExtHostStatusBar, new ExtHostStatusBar(rpcProtocol, extHostCommands.converter));
232230
const extHostSpeech = rpcProtocol.set(ExtHostContext.ExtHostSpeech, new ExtHostSpeech(rpcProtocol));
233231
const extHostEmbeddings = rpcProtocol.set(ExtHostContext.ExtHostEmbeddings, new ExtHostEmbeddings(rpcProtocol));
232+
const extHostChatSessions = rpcProtocol.set(ExtHostContext.ExtHostChatSessions, new ExtHostChatSessions(extHostCommands, rpcProtocol, extHostLogService));
233+
234234
rpcProtocol.set(ExtHostContext.ExtHostMcp, accessor.get(IExtHostMpcService));
235235

236236
// Check that no named customers are missing

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { ExtHostMcpService, IExtHostMpcService } from './extHostMcp.js';
3434
import { ExtHostUrls, IExtHostUrlsService } from './extHostUrls.js';
3535
import { ExtHostProgress, IExtHostProgress } from './extHostProgress.js';
3636
import { ExtHostDataChannels, IExtHostDataChannels } from './extHostDataChannels.js';
37-
import { ExtHostChatSessions, IExtHostChatSessions } from './extHostChatSessions.js';
3837

3938
registerSingleton(IExtHostLocalizationService, ExtHostLocalizationService, InstantiationType.Delayed);
4039
registerSingleton(ILoggerService, ExtHostLoggerService, InstantiationType.Delayed);
@@ -65,4 +64,3 @@ registerSingleton(IExtHostEditorTabs, ExtHostEditorTabs, InstantiationType.Eager
6564
registerSingleton(IExtHostVariableResolverProvider, ExtHostVariableResolverProviderService, InstantiationType.Eager);
6665
registerSingleton(IExtHostMpcService, ExtHostMcpService, InstantiationType.Eager);
6766
registerSingleton(IExtHostDataChannels, ExtHostDataChannels, InstantiationType.Eager);
68-
registerSingleton(IExtHostChatSessions, ExtHostChatSessions, InstantiationType.Eager);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3102,7 +3102,7 @@ export interface MainThreadChatStatusShape {
31023102
}
31033103

31043104
export interface MainThreadChatSessionsShape extends IDisposable {
3105-
$registerChatSessionsProvider(handle: number): void;
3105+
$registerChatSessionsProvider(handle: number, chatSessionType: string): void;
31063106
$unregisterChatSessionsProvider(handle: number): void;
31073107
}
31083108

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { ExtHostChatSessionsShape, MainContext, MainThreadChatSessionsShape } fr
1010
import type * as vscode from 'vscode';
1111
import { ILogService } from '../../../platform/log/common/log.js';
1212
import { Proxied } from '../../services/extensions/common/proxyIdentifier.js';
13+
import { ExtHostCommands } from './extHostCommands.js';
14+
import { MarshalledId } from '../../../base/common/marshallingIds.js';
15+
import { URI } from '../../../base/common/uri.js';
1316

1417
export interface IExtHostChatSessions extends ExtHostChatSessionsShape {
1518
registerChatSessionsProvider(provider: vscode.ChatSessionsProvider): vscode.Disposable;
@@ -23,21 +26,40 @@ export class ExtHostChatSessions extends Disposable implements IExtHostChatSessi
2326
private readonly _proxy: Proxied<MainThreadChatSessionsShape>;
2427
private readonly _statusProviders = new Map<number, { provider: vscode.ChatSessionsProvider; disposable: DisposableStore }>();
2528
private _nextHandle = 0;
29+
private _sessionMap: Map<string, vscode.ChatSessionContent & Record<string, unknown>> = new Map();
2630

2731
constructor(
32+
commands: ExtHostCommands,
2833
@IExtHostRpcService private readonly _extHostRpc: IExtHostRpcService,
2934
@ILogService private readonly _logService: ILogService,
3035
) {
3136
super();
3237
this._proxy = this._extHostRpc.getProxy(MainContext.MainThreadChatSessions);
38+
39+
commands.registerArgumentProcessor({
40+
processArgument: (arg) => {
41+
if (arg && arg.$mid === MarshalledId.ChatSessionContext) {
42+
const id = this.uriToId(arg.uri);
43+
const sessionContent = this._sessionMap.get(id);
44+
if (sessionContent) {
45+
return sessionContent;
46+
} else {
47+
this._logService.warn(`No chat session found for URI: ${id}`);
48+
return arg;
49+
}
50+
}
51+
52+
return arg;
53+
}
54+
});
3355
}
3456

3557
registerChatSessionsProvider(provider: vscode.ChatSessionsProvider): vscode.Disposable {
3658
const handle = this._nextHandle++;
3759
const disposables = new DisposableStore();
3860

3961
this._statusProviders.set(handle, { provider, disposable: disposables });
40-
this._proxy.$registerChatSessionsProvider(handle);
62+
this._proxy.$registerChatSessionsProvider(handle, provider.chatSessionType);
4163

4264
return {
4365
dispose: () => {
@@ -56,6 +78,20 @@ export class ExtHostChatSessions extends Disposable implements IExtHostChatSessi
5678
return [];
5779
}
5880

59-
return await entry.provider.provideChatSessions(token);
81+
const session = await entry.provider.provideChatSessions(token);
82+
for (const sessionContent of session) {
83+
if (sessionContent.uri) {
84+
this._sessionMap.set(
85+
this.uriToId(sessionContent.uri),
86+
sessionContent as vscode.ChatSessionContent & Record<string, unknown>
87+
);
88+
}
89+
}
90+
91+
return session;
92+
}
93+
94+
private uriToId(uri: URI): string {
95+
return `${uri.scheme}+${uri.authority}+${uri.path}`;
6096
}
6197
}

0 commit comments

Comments
 (0)