Set title for contributed chat session (#259108)

* setCustomTitle for contributedChatSession

* Add preferredTitle to allow setting

* tidy up

* extract out to get types happy
This commit is contained in:
Josh Spicer 2025-07-31 17:08:55 -07:00 committed by GitHub
parent f58a56ea03
commit 6724a5fb36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View File

@ -31,6 +31,7 @@ import { ChatWidget, IChatViewState } from './chatWidget.js';
export interface IChatEditorOptions extends IEditorOptions {
target?: { sessionId: string } | { data: IExportableChatData | ISerializableChatData };
preferredTitle?: string;
}
export class ChatEditor extends EditorPane {
@ -125,6 +126,7 @@ export class ChatEditor extends EditorPane {
throw new Error('ChatEditor lifecycle issue: no editor widget');
}
let isContributedChatSession = false;
if (input.resource.scheme === Schemas.vscodeChatSession) {
const identifier = ChatSessionUri.parse(input.resource);
if (identifier) {
@ -132,6 +134,7 @@ export class ChatEditor extends EditorPane {
const contribution = contributions.find(c => c.type === identifier.chatSessionType);
if (contribution) {
this.widget.lockToCodingAgent(contribution.name, contribution.displayName);
isContributedChatSession = true;
} else {
this.widget.unlockFromCodingAgent();
}
@ -148,6 +151,10 @@ export class ChatEditor extends EditorPane {
}
const viewState = options?.viewState ?? input.options.viewState;
this.updateModel(editorModel.model, viewState);
if (isContributedChatSession && options?.preferredTitle) {
editorModel.model.setCustomTitle(options?.preferredTitle);
}
}
private updateModel(model: IChatModel, viewState?: IChatViewState): void {

View File

@ -909,9 +909,14 @@ class SessionsViewPane extends ViewPane {
const ckey = this.contextKeyService.createKey('chatSessionType', element.provider.chatSessionType);
ckey.reset();
const options: IChatEditorOptions = {
pinned: true,
preferredTitle: element.label
};
await this.editorService.openEditor({
resource: ChatSessionUri.forSession(element.provider.chatSessionType, element.id),
options: { pinned: true } satisfies IChatEditorOptions
options,
});
}
}));

View File

@ -936,6 +936,7 @@ export interface IChatModel extends IDisposable {
acceptResponseProgress(request: IChatRequestModel, progress: IChatProgress, quiet?: boolean): void;
setResponse(request: IChatRequestModel, result: IChatAgentResult): void;
completeResponse(request: IChatRequestModel): void;
setCustomTitle(title: string): void;
toExport(): IExportableChatData;
toJSON(): ISerializableChatData;
}
@ -1105,6 +1106,7 @@ export type IChatChangeEvent =
| IChatSetHiddenEvent
| IChatCompletedRequestEvent
| IChatSetCheckpointEvent
| IChatSetCustomTitleEvent
;
export interface IChatAddRequestEvent {
@ -1174,6 +1176,11 @@ export interface IChatSetAgentEvent {
command?: IChatAgentCommand;
}
export interface IChatSetCustomTitleEvent {
kind: 'setCustomTitle';
title: string;
}
export interface IChatInitEvent {
kind: 'initialize';
}
@ -1556,8 +1563,9 @@ export class ChatModel extends Disposable implements IChatModel {
return request;
}
setCustomTitle(title: string): void {
public setCustomTitle(title: string): void {
this._customTitle = title;
this._onDidChange.fire({ kind: 'setCustomTitle', title });
}
updateRequest(request: ChatRequestModel, variableData: IChatRequestVariableData) {