Skip to content

Commit 3ab4e99

Browse files
committed
- getDefaultAgent takes chat agent location
- forward agent location to more places - updated snapshots
1 parent 09990db commit 3ab4e99

22 files changed

+64
-55
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { ChatVariablesService } from 'vs/workbench/contrib/chat/browser/chatVari
4242
import { ChatWidgetService } from 'vs/workbench/contrib/chat/browser/chatWidget';
4343
import 'vs/workbench/contrib/chat/browser/contrib/chatHistoryVariables';
4444
import 'vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib';
45-
import { ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
45+
import { ChatAgentLocation, ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
4646
import { CONTEXT_IN_CHAT_SESSION } from 'vs/workbench/contrib/chat/common/chatContextKeys';
4747
import { IChatContributionService } from 'vs/workbench/contrib/chat/common/chatContributionService';
4848
import { ChatWelcomeMessageModel } from 'vs/workbench/contrib/chat/common/chatModel';
@@ -250,7 +250,7 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
250250
sortText: 'z1_help',
251251
executeImmediately: true
252252
}, async (prompt, progress) => {
253-
const defaultAgent = chatAgentService.getDefaultAgent();
253+
const defaultAgent = chatAgentService.getDefaultAgent(ChatAgentLocation.Panel);
254254
const agents = chatAgentService.getAgents();
255255

256256
// Report prefix

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MarkdownString } from 'vs/base/common/htmlContent';
99
import { Disposable } from 'vs/base/common/lifecycle';
1010
import { localize } from 'vs/nls';
1111
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
12-
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
12+
import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
1313
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
1414
import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService';
1515
import { IInlineChatFollowup } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
@@ -20,6 +20,7 @@ export class ChatFollowups<T extends IChatFollowup | IInlineChatFollowup> extend
2020
constructor(
2121
container: HTMLElement,
2222
followups: T[],
23+
private readonly location: ChatAgentLocation,
2324
private readonly options: IButtonStyles | undefined,
2425
private readonly clickHandler: (followup: T) => void,
2526
@IContextKeyService private readonly contextService: IContextKeyService,
@@ -37,13 +38,13 @@ export class ChatFollowups<T extends IChatFollowup | IInlineChatFollowup> extend
3738
return;
3839
}
3940

40-
if (!this.chatAgentService.getDefaultAgent()) {
41+
if (!this.chatAgentService.getDefaultAgent(this.location)) {
4142
// No default agent yet, which affects how followups are rendered, so can't render this yet
4243
return;
4344
}
4445

4546
let tooltipPrefix = '';
46-
if ('agentId' in followup && followup.agentId && followup.agentId !== this.chatAgentService.getDefaultAgent()?.id) {
47+
if ('agentId' in followup && followup.agentId && followup.agentId !== this.chatAgentService.getDefaultAgent(this.location)?.id) {
4748
tooltipPrefix += `${chatAgentLeader}${followup.agentId} `;
4849
if ('subCommand' in followup && followup.subCommand) {
4950
tooltipPrefix += `${chatSubcommandLeader}${followup.subCommand} `;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { ChatSubmitEditorAction, ChatSubmitSecondaryAgentEditorAction } from 'vs
4040
import { IChatExecuteActionContext, SubmitAction } from 'vs/workbench/contrib/chat/browser/actions/chatExecuteActions';
4141
import { IChatWidget } from 'vs/workbench/contrib/chat/browser/chat';
4242
import { ChatFollowups } from 'vs/workbench/contrib/chat/browser/chatFollowups';
43-
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
43+
import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
4444
import { CONTEXT_CHAT_INPUT_CURSOR_AT_TOP, CONTEXT_CHAT_INPUT_HAS_FOCUS, CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_IN_CHAT_INPUT } from 'vs/workbench/contrib/chat/common/chatContextKeys';
4545
import { chatAgentLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
4646
import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService';
@@ -119,6 +119,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
119119

120120
constructor(
121121
// private readonly editorOptions: ChatEditorOptions, // TODO this should be used
122+
private readonly location: ChatAgentLocation,
122123
private readonly options: {
123124
renderFollowups: boolean;
124125
renderStyle?: 'default' | 'compact';
@@ -415,7 +416,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
415416
dom.clearNode(this.followupsContainer);
416417

417418
if (items && items.length > 0) {
418-
this.followupsDisposables.add(this.instantiationService.createInstance<typeof ChatFollowups<IChatFollowup>, ChatFollowups<IChatFollowup>>(ChatFollowups, this.followupsContainer, items, undefined, followup => this._onDidAcceptFollowup.fire({ followup, response })));
419+
this.followupsDisposables.add(this.instantiationService.createInstance<typeof ChatFollowups<IChatFollowup>, ChatFollowups<IChatFollowup>>(ChatFollowups, this.followupsContainer, items, this.location, undefined, followup => this._onDidAcceptFollowup.fire({ followup, response })));
419420
}
420421
}
421422

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { ChatFollowups } from 'vs/workbench/contrib/chat/browser/chatFollowups';
5353
import { ChatMarkdownDecorationsRenderer } from 'vs/workbench/contrib/chat/browser/chatMarkdownDecorationsRenderer';
5454
import { ChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatOptions';
5555
import { ChatCodeBlockContentProvider, CodeBlockPart, ICodeBlockData, localFileLanguageId, parseLocalFileData } from 'vs/workbench/contrib/chat/browser/codeBlockPart';
56-
import { IChatAgentMetadata } from 'vs/workbench/contrib/chat/common/chatAgents';
56+
import { ChatAgentLocation, IChatAgentMetadata } from 'vs/workbench/contrib/chat/common/chatAgents';
5757
import { CONTEXT_CHAT_RESPONSE_SUPPORT_ISSUE_REPORTING, CONTEXT_REQUEST, CONTEXT_RESPONSE, CONTEXT_RESPONSE_DETECTED_AGENT_COMMAND, CONTEXT_RESPONSE_FILTERED, CONTEXT_RESPONSE_VOTE } from 'vs/workbench/contrib/chat/common/chatContextKeys';
5858
import { IChatProgressRenderableResponseContent } from 'vs/workbench/contrib/chat/common/chatModel';
5959
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
@@ -131,6 +131,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
131131

132132
constructor(
133133
editorOptions: ChatEditorOptions,
134+
private readonly location: ChatAgentLocation,
134135
private readonly rendererOptions: IChatListItemRendererOptions,
135136
private readonly delegate: IChatRendererDelegate,
136137
private readonly codeBlockModelCollection: CodeBlockModelCollection,
@@ -373,7 +374,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
373374
} else if (element.agentOrSlashCommandDetected) {
374375
const usingMsg: string[] = [];
375376
if (element.agent && !element.agent.isDefault) {
376-
usingMsg.push(chatAgentLeader + element.agent.id);
377+
usingMsg.push(chatAgentLeader + element.agent.name);
377378
}
378379
if (element.slashCommand) {
379380
usingMsg.push(chatSubcommandLeader + element.slashCommand.name);
@@ -518,6 +519,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
518519
ChatFollowups,
519520
templateData.value,
520521
item,
522+
this.location,
521523
undefined,
522524
followup => this._onDidClickFollowup.fire(followup)));
523525
} else {

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
404404
this.renderer = this._register(scopedInstantiationService.createInstance(
405405
ChatListItemRenderer,
406406
this.editorOptions,
407+
this.location,
407408
options,
408409
rendererDelegate,
409410
this._codeBlockModelCollection,
@@ -495,11 +496,14 @@ export class ChatWidget extends Disposable implements IChatWidget {
495496
}
496497

497498
private createInput(container: HTMLElement, options?: { renderFollowups: boolean; renderStyle?: 'default' | 'compact' }): void {
498-
this.inputPart = this._register(this.instantiationService.createInstance(ChatInputPart, {
499-
renderFollowups: options?.renderFollowups ?? true,
500-
renderStyle: options?.renderStyle,
501-
menus: { executeToolbar: MenuId.ChatExecute, ...this.viewOptions.menus }
502-
}));
499+
this.inputPart = this._register(this.instantiationService.createInstance(ChatInputPart,
500+
this.location,
501+
{
502+
renderFollowups: options?.renderFollowups ?? true,
503+
renderStyle: options?.renderStyle,
504+
menus: { executeToolbar: MenuId.ChatExecute, ...this.viewOptions.menus }
505+
}
506+
));
503507
this.inputPart.render(container, '', this);
504508

505509
this._register(this.inputPart.onDidLoadInputState(state => {
@@ -516,7 +520,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
516520
}
517521

518522
let msg = '';
519-
if (e.followup.agentId !== this.chatAgentService.getDefaultAgent()?.id) {
523+
if (e.followup.agentId !== this.chatAgentService.getDefaultAgent(this.location)?.id) {
520524
msg = `${chatAgentLeader}${e.followup.agentId} `;
521525
if (e.followup.subCommand) {
522526
msg += `${chatSubcommandLeader}${e.followup.subCommand} `;
@@ -564,7 +568,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
564568
}
565569
this.parsedChatRequest = undefined;
566570
const agentAndSubcommand = extractAgentAndCommand(this.parsedInput);
567-
const currentAgent = agentAndSubcommand.agentPart?.agent ?? this.chatAgentService.getDefaultAgent();
571+
const currentAgent = agentAndSubcommand.agentPart?.agent ?? this.chatAgentService.getDefaultAgent(this.location);
568572
const implicitVariables = agentAndSubcommand.commandPart ?
569573
agentAndSubcommand.commandPart.command.defaultImplicitVariables :
570574
currentAgent?.defaultImplicitVariables;
@@ -734,7 +738,6 @@ export class ChatWidget extends Disposable implements IChatWidget {
734738

735739
this.inputPart.layout(height, width);
736740
const inputPartHeight = this.inputPart.inputPartHeight;
737-
// const inputPartHeight = dom.getTotalHeight(this.inputPart.element);
738741
const lastElementVisible = this.tree.scrollTop + this.tree.renderHeight >= this.tree.scrollHeight;
739742

740743
const listHeight = height - inputPartHeight;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class InputEditorDecorations extends Disposable {
126126
}
127127

128128
if (!inputValue) {
129-
const defaultAgent = this.chatAgentService.getDefaultAgent();
129+
const defaultAgent = this.chatAgentService.getDefaultAgent(this.widget.location);
130130
const decoration: IDecorationOptions[] = [
131131
{
132132
range: {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export interface IChatAgentService {
138138
getAgents(): IChatAgentData[];
139139
getActivatedAgents(): Array<IChatAgent>;
140140
getAgentsByName(name: string): IChatAgentData[];
141-
getDefaultAgent(): IChatAgent | undefined;
141+
getDefaultAgent(location: ChatAgentLocation): IChatAgent | undefined;
142142
getSecondaryAgent(): IChatAgentData | undefined;
143143
updateAgent(id: string, updateMetadata: IChatAgentMetadata): void;
144144
}
@@ -219,9 +219,8 @@ export class ChatAgentService implements IChatAgentService {
219219
this._onDidChangeAgents.fire(new MergedChatAgent(agent.data, agent.impl));
220220
}
221221

222-
getDefaultAgent(): IChatAgent | undefined {
223-
// TODO@jrieken pass location!
224-
return this.getActivatedAgents().find(a => !!a.isDefault && a.locations.includes(ChatAgentLocation.Panel));
222+
getDefaultAgent(location: ChatAgentLocation): IChatAgent | undefined {
223+
return this.getActivatedAgents().find(a => !!a.isDefault && a.locations.includes(location));
225224
}
226225

227226
getSecondaryAgent(): IChatAgentData | undefined {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
347347
}
348348
}
349349

350-
setAgent(agent: IChatAgentData, slashCommand?: IChatAgentCommand, detected?: boolean) {
350+
setAgent(agent: IChatAgentData, slashCommand?: IChatAgentCommand) {
351351
this._agent = agent;
352352
this._slashCommand = slashCommand;
353-
this._agentOrSlashCommandDetected = detected;
353+
this._agentOrSlashCommandDetected = true;
354354
this._onDidChange.fire();
355355
}
356356

@@ -531,7 +531,7 @@ export class ChatModel extends Disposable implements IChatModel {
531531
}
532532

533533
private get _defaultAgent() {
534-
return this.chatAgentService.getDefaultAgent();
534+
return this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel);
535535
}
536536

537537
get requesterUsername(): string {
@@ -741,7 +741,7 @@ export class ChatModel extends Disposable implements IChatModel {
741741
} else if (progress.kind === 'agentDetection') {
742742
const agent = this.chatAgentService.getAgent(progress.agentId);
743743
if (agent) {
744-
request.response.setAgent(agent, progress.command, progress.detected);
744+
request.response.setAgent(agent, progress.command);
745745
}
746746
} else if (progress.kind === 'textEdit') {
747747
request.response.updateTextEdits(progress.uri, progress.edits);
@@ -897,11 +897,11 @@ export class ChatWelcomeMessageModel implements IChatWelcomeMessageModel {
897897
}
898898

899899
public get username(): string {
900-
return this.chatAgentService.getDefaultAgent()?.metadata.fullName ?? '';
900+
return this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel)?.metadata.fullName ?? '';
901901
}
902902

903903
public get avatarIcon(): ThemeIcon | undefined {
904-
return this.chatAgentService.getDefaultAgent()?.metadata.themeIcon;
904+
return this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel)?.metadata.themeIcon;
905905
}
906906
}
907907

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export interface IChatContentInlineReference {
8888
export interface IChatAgentDetection {
8989
agentId: string;
9090
command?: IChatAgentCommand;
91-
detected?: boolean;
9291
kind: 'agentDetection';
9392
}
9493

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export class ChatService extends Disposable implements IChatService {
383383

384384
this.trace('startSession', `Provider returned session`);
385385

386-
const defaultAgent = this.chatAgentService.getDefaultAgent();
386+
const defaultAgent = this.chatAgentService.getDefaultAgent(ChatAgentLocation.Panel);
387387
if (!defaultAgent) {
388388
throw new ErrorNoTelemetry('No default agent');
389389
}
@@ -458,10 +458,7 @@ export class ChatService extends Disposable implements IChatService {
458458
return;
459459
}
460460

461-
let defaultAgent = this.chatAgentService.getDefaultAgent()!;
462-
if (location && !defaultAgent?.locations.includes(location)) {
463-
defaultAgent = this.chatAgentService.getActivatedAgents().find(a => a.locations.includes(location)) ?? defaultAgent;
464-
}
461+
const defaultAgent = this.chatAgentService.getDefaultAgent(location)!;
465462

466463
const parsedRequest = this.instantiationService.createInstance(ChatRequestParser).parseChatRequest(sessionId, request, location, parserContext);
467464
const agent = parsedRequest.parts.find((r): r is ChatRequestAgentPart => r instanceof ChatRequestAgentPart)?.agent ?? defaultAgent;
@@ -534,7 +531,6 @@ export class ChatService extends Disposable implements IChatService {
534531
let rawResult: IChatAgentResult | null | undefined;
535532
let agentOrCommandFollowups: Promise<IChatFollowup[] | undefined> | undefined = undefined;
536533

537-
// const defaultAgent = this.chatAgentService.getDefaultAgent();
538534
if (agentPart || (defaultAgent && !commandPart)) {
539535
const agent = (agentPart?.agent ?? defaultAgent)!;
540536
await this.extensionService.activateByEvent(`onChatParticipant:${agent.id}`);

0 commit comments

Comments
 (0)