Skip to content

Commit 6724a5f

Browse files
authored
Set title for contributed chat session (microsoft#259108)
* setCustomTitle for contributedChatSession * Add preferredTitle to allow setting * tidy up * extract out to get types happy
1 parent f58a56e commit 6724a5f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { ChatWidget, IChatViewState } from './chatWidget.js';
3131

3232
export interface IChatEditorOptions extends IEditorOptions {
3333
target?: { sessionId: string } | { data: IExportableChatData | ISerializableChatData };
34+
preferredTitle?: string;
3435
}
3536

3637
export class ChatEditor extends EditorPane {
@@ -125,13 +126,15 @@ export class ChatEditor extends EditorPane {
125126
throw new Error('ChatEditor lifecycle issue: no editor widget');
126127
}
127128

129+
let isContributedChatSession = false;
128130
if (input.resource.scheme === Schemas.vscodeChatSession) {
129131
const identifier = ChatSessionUri.parse(input.resource);
130132
if (identifier) {
131133
const contributions = this.chatSessionsService.getChatSessionContributions();
132134
const contribution = contributions.find(c => c.type === identifier.chatSessionType);
133135
if (contribution) {
134136
this.widget.lockToCodingAgent(contribution.name, contribution.displayName);
137+
isContributedChatSession = true;
135138
} else {
136139
this.widget.unlockFromCodingAgent();
137140
}
@@ -148,6 +151,10 @@ export class ChatEditor extends EditorPane {
148151
}
149152
const viewState = options?.viewState ?? input.options.viewState;
150153
this.updateModel(editorModel.model, viewState);
154+
155+
if (isContributedChatSession && options?.preferredTitle) {
156+
editorModel.model.setCustomTitle(options?.preferredTitle);
157+
}
151158
}
152159

153160
private updateModel(model: IChatModel, viewState?: IChatViewState): void {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,14 @@ class SessionsViewPane extends ViewPane {
909909
const ckey = this.contextKeyService.createKey('chatSessionType', element.provider.chatSessionType);
910910
ckey.reset();
911911

912+
const options: IChatEditorOptions = {
913+
pinned: true,
914+
preferredTitle: element.label
915+
};
916+
912917
await this.editorService.openEditor({
913918
resource: ChatSessionUri.forSession(element.provider.chatSessionType, element.id),
914-
options: { pinned: true } satisfies IChatEditorOptions
919+
options,
915920
});
916921
}
917922
}));

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ export interface IChatModel extends IDisposable {
936936
acceptResponseProgress(request: IChatRequestModel, progress: IChatProgress, quiet?: boolean): void;
937937
setResponse(request: IChatRequestModel, result: IChatAgentResult): void;
938938
completeResponse(request: IChatRequestModel): void;
939+
setCustomTitle(title: string): void;
939940
toExport(): IExportableChatData;
940941
toJSON(): ISerializableChatData;
941942
}
@@ -1105,6 +1106,7 @@ export type IChatChangeEvent =
11051106
| IChatSetHiddenEvent
11061107
| IChatCompletedRequestEvent
11071108
| IChatSetCheckpointEvent
1109+
| IChatSetCustomTitleEvent
11081110
;
11091111

11101112
export interface IChatAddRequestEvent {
@@ -1174,6 +1176,11 @@ export interface IChatSetAgentEvent {
11741176
command?: IChatAgentCommand;
11751177
}
11761178

1179+
export interface IChatSetCustomTitleEvent {
1180+
kind: 'setCustomTitle';
1181+
title: string;
1182+
}
1183+
11771184
export interface IChatInitEvent {
11781185
kind: 'initialize';
11791186
}
@@ -1556,8 +1563,9 @@ export class ChatModel extends Disposable implements IChatModel {
15561563
return request;
15571564
}
15581565

1559-
setCustomTitle(title: string): void {
1566+
public setCustomTitle(title: string): void {
15601567
this._customTitle = title;
1568+
this._onDidChange.fire({ kind: 'setCustomTitle', title });
15611569
}
15621570

15631571
updateRequest(request: ChatRequestModel, variableData: IChatRequestVariableData) {

0 commit comments

Comments
 (0)