320
321
registerAgent(id: string, data: IChatAgentData): IDisposable {
323
>
if (existingAgent) {
324
throw new Error(`Agent already registered: ${JSON.stringify(id)}`);
325
}
327
>
const that = this;
328
>
const commands = data.slashCommands;
329
>
data = {
330
>
...data,
331
>
get slashCommands() {
332
return commands.filter(c => !c.when || that.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(c.when)));
333
}
335
>
const entry = { data };
336
>
this._agents.set(id, entry);
337
>
this._updateAgentsContextKeys();
338
>
this._updateContextKeys();
339
>
this._onDidChangeAgents.fire(undefined);
340
>
341
>
return toDisposable(() => {
342
>
this._agents.delete(id);
343
>
this._updateAgentsContextKeys();
344
>
this._updateContextKeys();
345
>
this._onDidChangeAgents.fire(undefined);
346
>
});
347
>
}
348
349
private _updateAgentsContextKeys(): void {
350
>
// Update the set of context keys used by all agents
chatAgents.ts
351
>
this._agentsContextKeys.clear();
352
>
for (const agent of this._agents.values()) {
353
>
if (agent.data.when) {
354
const expr = ContextKeyExpr.deserialize(agent.data.when);
355
for (const key of expr?.keys() || []) {