8000 fix: honor `isSticky` for autodetected chat participants (#221747) · githubnext/vscode@716fbeb · GitHub
[go: up one dir, main page]

Skip to content

Commit 716fbeb

Browse files
authored
fix: honor isSticky for autodetected chat participants (microsoft#221747)
1 parent 02e7848 commit 716fbeb

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export interface IChatWidget {
139139
readonly onDidAcceptInput: Event<void>;
140140
readonly onDidHide: Event<void>;
141141
readonly onDidSubmitAgent: Event<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>;
142+
readonly onDidChangeAgent: Event<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>;
142143
readonly onDidChangeParsedInput: Event<void>;
143144
readonly onDidChangeContext: Event<{ removed?: IChatRequestVariableEntry[]; added?: IChatRequestVariableEntry[] }>;
144145
readonly location: ChatAgentLocation;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
8888
private readonly _onDidSubmitAgent = this._register(new Emitter<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>());
8989
public readonly onDidSubmitAgent = this._onDidSubmitAgent.event;
9090

91+
private _onDidChangeAgent = this._register(new Emitter<{ agent: IChatAgentData; slashCommand?: IChatAgentCommand }>());
92+
readonly onDidChangeAgent = this._onDidChangeAgent.event;
93+
9194
private _onDidFocus = this._register(new Emitter<void>());
9295
readonly onDidFocus = this._onDidFocus.event;
9396

@@ -688,6 +691,11 @@ export class ChatWidget extends Disposable implements IChatWidget {
688691
c.setInputState(viewState.inputState?.[c.id]);
689692
}
690693
});
694+
this.viewModelDisposables.add(model.onDidChange((e) => {
695+
if (e.kind === 'setAgent') {
696+
this._onDidChangeAgent.fire({ agent: e.agent, slashCommand: e.command });
697+
}
698+
}));
691699

692700
if (this.tree) {
693701
this.onDidChangeItems();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,22 @@ class InputEditorSlashCommandMode extends Disposable {
242242
private readonly widget: IChatWidget
243243
) {
244244
super();
245+
this._register(this.widget.onDidChangeAgent(e => {
246+
if (e.slashCommand && e.slashCommand.isSticky || !e.slashCommand && e.agent.metadata.isSticky) {
247+
this.repopulateAgentCommand(e.agent, e.slashCommand);
248+
}
249+
}));
245250
this._register(this.widget.onDidSubmitAgent(e => {
246251
this.repopulateAgentCommand(e.agent, e.slashCommand);
247252
}));
248253
}
249254

250255
private async repopulateAgentCommand(agent: IChatAgentData, slashCommand: IChatAgentCommand | undefined) {
256+
// Make sure we don't repopulate if the user already has something in the input
257+
if (this.widget.inputEditor.getValue().trim()) {
258+
return;
259+
}
260+
251261
let value: string | undefined;
252262
if (slashCommand && slashCommand.isSticky) {
253263
value = `${chatAgentLeader}${agent.name} ${chatSubcommandLeader}${slashCommand.name} `;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ export function isSerializableSessionData(obj: unknown): obj is ISerializableCha
545545
export type IChatChangeEvent =
546546
| IChatInitEvent
547547
| IChatAddRequestEvent | IChatChangedRequestEvent | IChatRemoveRequestEvent
548-
| IChatAddResponseEvent;
548+
| IChatAddResponseEvent
549+
| IChatSetAgentEvent;
549550

550551
export interface IChatAddRequestEvent {
551552
kind: 'addRequest';
@@ -586,6 +587,12 @@ export interface IChatRemoveRequestEvent {
586587
reason: ChatRequestRemovalReason;
587588
}
588589

590+
export interface IChatSetAgentEvent {
591+
kind: 'setAgent';
592+
agent: IChatAgentData;
593+
command?: IChatAgentCommand;
594+
}
595+
589596
export interface IChatInitEvent {
590597
kind: 'initialize';
591598
}
@@ -892,6 +899,7 @@ export class ChatModel extends Disposable implements IChatModel {
892899
const agent = this.chatAgentService.getAgent(progress.agentId);
893900
if (agent) {
894901
request.response.setAgent(agent, progress.command);
902+
this._onDidChange.fire({ kind: 'setAgent', agent, command: progress.command });
895903
}
896904
} else {
897905
this.logService.error(`Couldn't handle progress: ${JSON.stringify(progress)}`);

0 commit comments

Comments
 (0)
0