Skip to content

Commit 9bd6ee4

Browse files
authored
Warm up slash command cache (microsoft#206290)
Fix microsoft#206050
1 parent 927ae34 commit 9bd6ee4

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ export const IChatAgentService = createDecorator<IChatAgentService>('chatAgentSe
107107

108108
export interface IChatAgentService {
109109
_serviceBrand: undefined;
110-
readonly onDidChangeAgents: Event<void>;
110+
/**
111+
* undefined when an agent was removed
112+
*/
113+
readonly onDidChangeAgents: Event<IChatAgent | undefined>;
111114
registerAgent(agent: IChatAgent): IDisposable;
112115
invokeAgent(id: string, request: IChatAgentRequest, progress: (part: IChatProgress) => void, history: IChatAgentHistoryEntry[], token: CancellationToken): Promise<IChatAgentResult>;
113116
getFollowups(id: string, request: IChatAgentRequest, result: IChatAgentResult, token: CancellationToken): Promise<IChatFollowup[]>;
@@ -127,8 +130,8 @@ export class ChatAgentService extends Disposable implements IChatAgentService {
127130

128131
private readonly _agents = new Map<string, { agent: IChatAgent }>();
129132

130-
private readonly _onDidChangeAgents = this._register(new Emitter<void>());
131-
readonly onDidChangeAgents: Event<void> = this._onDidChangeAgents.event;
133+
private readonly _onDidChangeAgents = this._register(new Emitter<IChatAgent | undefined>());
134+
readonly onDidChangeAgents: Event<IChatAgent | undefined> = this._onDidChangeAgents.event;
132135

133136
override dispose(): void {
134137
super.dispose();
@@ -140,11 +143,11 @@ export class ChatAgentService extends Disposable implements IChatAgentService {
140143
throw new Error(`Already registered an agent with id ${agent.id}`);
141144
}
142145
this._agents.set(agent.id, { agent });
143-
this._onDidChangeAgents.fire();
146+
this._onDidChangeAgents.fire(agent);
144147

145148
return toDisposable(() => {
146149
if (this._agents.delete(agent.id)) {
147-
this._onDidChangeAgents.fire();
150+
this._onDidChangeAgents.fire(undefined);
148151
}
149152
});
150153
}
@@ -155,7 +158,7 @@ export class ChatAgentService extends Disposable implements IChatAgentService {
155158
throw new Error(`No agent with id ${id} registered`);
156159
}
157160
data.agent.metadata = { ...data.agent.metadata, ...updateMetadata };
158-
this._onDidChangeAgents.fire();
161+
this._onDidChangeAgents.fire(data.agent);
159162
}
160163

161164
getDefaultAgent(): IChatAgent | undefined {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { Progress } from 'vs/platform/progress/common/progress';
2020
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
2121
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2222
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
23-
import { IChatAgentRequest, IChatAgentResult, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
23+
import { IChatAgent, IChatAgentRequest, IChatAgentResult, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
2424
import { CONTEXT_PROVIDER_EXISTS } from 'vs/workbench/contrib/chat/common/chatContextKeys';
2525
import { ChatModel, ChatModelInitState, ChatRequestModel, ChatWelcomeMessageModel, IChatModel, IChatRequestVariableData, ISerializableChatData, ISerializableChatsData, getHistoryEntriesFromModel, updateRanges } from 'vs/workbench/contrib/chat/common/chatModel';
2626
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, IParsedChatRequest, getPromptText } from 'vs/workbench/contrib/chat/common/chatParserTypes';
@@ -193,6 +193,12 @@ export class ChatService extends Disposable implements IChatService {
193193
}
194194

195195
this._register(storageService.onWillSaveState(() => this.saveState()));
196+
197+
this._register(Event.debounce(this.chatAgentService.onDidChangeAgents, () => { }, 500)(() => {
198+
for (const model of this._sessionModels.values()) {
199+
this.warmSlashCommandCache(model);
200+
}
201+
}));
196202
}
197203

198204
private saveState(): void {
@@ -358,9 +364,15 @@ export class ChatService extends Disposable implements IChatService {
358364
this.initializeSession(model, CancellationToken.None);
359365
}
360366

367+
private warmSlashCommandCache(model: IChatModel, agent?: IChatAgent) {
368+
const agents = agent ? [agent] : this.chatAgentService.getAgents();
369+
agents.forEach(agent => agent.provideSlashCommands(model, [], CancellationToken.None));
370+
}
371+
361372
private async initializeSession(model: ChatModel, token: CancellationToken): Promise<void> {
362373
try {
363374
this.trace('initializeSession', `Initialize session ${model.sessionId}`);
375+
this.warmSlashCommandCache(model);
364376
model.startInitialize();
365377
await this.extensionService.activateByEvent(`onInteractiveSession:${model.providerId}`);
366378

0 commit comments

Comments
 (0)