diff --git a/src/vs/sessions/contrib/chat/browser/branchChatSessionAction.ts b/src/vs/sessions/contrib/chat/browser/branchChatSessionAction.ts index f5575ce5a9b..6766f48b2b4 100644 --- a/src/vs/sessions/contrib/chat/browser/branchChatSessionAction.ts +++ b/src/vs/sessions/contrib/chat/browser/branchChatSessionAction.ts @@ -101,10 +101,7 @@ export class BranchChatSessionAction extends Action2 { } // Load the branched data into a new session model - const modelRef = chatService.loadSessionFromContent(serializedData); - if (!modelRef) { - return; - } + const modelRef = chatService.loadSessionFromData(serializedData); // Open the branched session in the chat view pane await widgetService.openSession(modelRef.object.sessionResource, ChatViewPaneTarget); diff --git a/src/vs/sessions/contrib/sessions/browser/sessionsManagementService.ts b/src/vs/sessions/contrib/sessions/browser/sessionsManagementService.ts index d3a7e961119..8d4124b8b94 100644 --- a/src/vs/sessions/contrib/sessions/browser/sessionsManagementService.ts +++ b/src/vs/sessions/contrib/sessions/browser/sessionsManagementService.ts @@ -307,7 +307,7 @@ export class SessionsManagementService extends Disposable implements ISessionsMa * Open a new remote session - load the model first, then show it in the ChatViewPane. */ private async openNewRemoteSession(sessionResource: URI): Promise { - const modelRef = await this.chatService.loadSessionForResource(sessionResource, ChatAgentLocation.Chat, CancellationToken.None); + const modelRef = await this.chatService.acquireOrLoadSession(sessionResource, ChatAgentLocation.Chat, CancellationToken.None); const chatWidget = await this.chatWidgetService.openSession(sessionResource, ChatViewPaneTarget); if (!chatWidget?.viewModel) { this.logService.warn(`[ActiveSessionService] Failed to open session: ${sessionResource.toString()}`); @@ -372,7 +372,7 @@ export class SessionsManagementService extends Disposable implements ISessionsMa // 2. Apply selected options (repository, branch, etc.) to the contributed session if (selectedOptions && selectedOptions.size > 0) { - const modelRef = this.chatService.getActiveSessionReference(sessionResource); + const modelRef = this.chatService.acquireExistingSession(sessionResource); if (modelRef) { const model = modelRef.object; const contributedSession = model.contributedChatSession; diff --git a/src/vs/workbench/api/browser/mainThreadChatSessions.ts b/src/vs/workbench/api/browser/mainThreadChatSessions.ts index cd45ead9ff5..a683f75dfb8 100644 --- a/src/vs/workbench/api/browser/mainThreadChatSessions.ts +++ b/src/vs/workbench/api/browser/mainThreadChatSessions.ts @@ -529,7 +529,7 @@ export class MainThreadChatSessions extends Disposable implements MainThreadChat } const originalEditor = this._editorService.editors.find(editor => editor.resource?.toString() === originalResource.toString()); - const originalModel = this._chatService.getActiveSessionReference(originalResource); + const originalModel = this._chatService.acquireExistingSession(originalResource); const contribution = this._chatSessionsService.getAllChatSessionContributions().find(c => c.type === chatSessionType); try { @@ -584,7 +584,7 @@ export class MainThreadChatSessions extends Disposable implements MainThreadChat await this._chatWidgetService.openSession(modifiedResource, undefined, { preserveFocus: true }); } else { // Loading the session to ensure the session is created and editing session is transferred. - const ref = await this._chatService.loadSessionForResource(modifiedResource, ChatAgentLocation.Chat, CancellationToken.None); + const ref = await this._chatService.acquireOrLoadSession(modifiedResource, ChatAgentLocation.Chat, CancellationToken.None); ref?.dispose(); } } finally { diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatForkActions.ts b/src/vs/workbench/contrib/chat/browser/actions/chatForkActions.ts index 1521270c59b..fd008ea10c9 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatForkActions.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatForkActions.ts @@ -78,10 +78,7 @@ export function registerChatForkActions() { } } - const modelRef = chatService.loadSessionFromContent(cleanData); - if (!modelRef) { - return; - } + const modelRef = chatService.loadSessionFromData(cleanData); // Defer navigation until after the slash command flow completes. const newSessionResource = modelRef.object.sessionResource; @@ -177,7 +174,7 @@ export function registerChatForkActions() { } } - const modelRef = chatService.loadSessionFromContent(forkedData); + const modelRef = chatService.loadSessionFromData(forkedData); if (!modelRef) { return; diff --git a/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.ts b/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.ts index 7f350b188d7..059f2febb5c 100644 --- a/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.ts +++ b/src/vs/workbench/contrib/chat/browser/actions/chatImportExport.ts @@ -123,10 +123,7 @@ export function registerChatExportActions() { let options: IChatEditorOptions; if (opts?.target === 'chatViewPane') { - const modelRef = chatService.loadSessionFromContent(data); - if (!modelRef) { - return; - } + const modelRef = chatService.loadSessionFromData(data); sessionResource = modelRef.object.sessionResource; resolvedTarget = ChatViewPaneTarget; options = { pinned: true }; diff --git a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionHoverWidget.ts b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionHoverWidget.ts index dbe4495753a..27aaaa4f88f 100644 --- a/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionHoverWidget.ts +++ b/src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionHoverWidget.ts @@ -80,7 +80,7 @@ export class AgentSessionHoverWidget extends Disposable { } private async loadModel() { - const modelRef = await this.chatService.loadSessionForResource(this.session.resource, ChatAgentLocation.Chat, this.cts.token); + const modelRef = await this.chatService.acquireOrLoadSession(this.session.resource, ChatAgentLocation.Chat, this.cts.token); if (this._store.isDisposed) { modelRef?.dispose(); return; diff --git a/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts b/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts index ada489b06ac..deff82e8693 100644 --- a/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts +++ b/src/vs/workbench/contrib/chat/browser/chatSessions/chatSessions.contribution.ts @@ -575,7 +575,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ if (chatOptions) { const resource = URI.revive(chatOptions.resource); - const ref = await chatService.loadSessionForResource(resource, ChatAgentLocation.Chat, CancellationToken.None); + const ref = await chatService.acquireOrLoadSession(resource, ChatAgentLocation.Chat, CancellationToken.None); try { const result = await chatService.sendRequest(resource, chatOptions.prompt, { agentIdSilent: type, attachedContext: chatOptions.attachedContext }); if (result.kind === 'queued') { diff --git a/src/vs/workbench/contrib/chat/browser/widgetHosts/chatQuick.ts b/src/vs/workbench/contrib/chat/browser/widgetHosts/chatQuick.ts index fda57a33cdc..c6a61b98152 100644 --- a/src/vs/workbench/contrib/chat/browser/widgetHosts/chatQuick.ts +++ b/src/vs/workbench/contrib/chat/browser/widgetHosts/chatQuick.ts @@ -394,7 +394,7 @@ class QuickChat extends Disposable { } private updateModel(): void { - this.modelRef ??= this.chatService.startSession(ChatAgentLocation.Chat, { disableBackgroundKeepAlive: true }); + this.modelRef ??= this.chatService.startNewLocalSession(ChatAgentLocation.Chat, { disableBackgroundKeepAlive: true }); const model = this.modelRef?.object; if (!model) { throw new Error('Could not start chat session'); diff --git a/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts b/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts index 9653b59d817..47214b2d68d 100644 --- a/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts +++ b/src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts @@ -211,16 +211,16 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler const inputType = chatSessionType ?? this.resource.authority; if (this._sessionResource) { - this.modelRef.value = await this.chatService.loadSessionForResource(this._sessionResource, ChatAgentLocation.Chat, CancellationToken.None); + this.modelRef.value = await this.chatService.acquireOrLoadSession(this._sessionResource, ChatAgentLocation.Chat, CancellationToken.None); // For local session only, if we find no existing session, create a new one if (!this.model && LocalChatSessionUri.parseLocalSessionId(this._sessionResource)) { - this.modelRef.value = this.chatService.startSession(ChatAgentLocation.Chat, { canUseTools: true }); + this.modelRef.value = this.chatService.startNewLocalSession(ChatAgentLocation.Chat, { canUseTools: true }); } } else if (!this.options.target) { - this.modelRef.value = this.chatService.startSession(ChatAgentLocation.Chat, { canUseTools: !inputType }); + this.modelRef.value = this.chatService.startNewLocalSession(ChatAgentLocation.Chat, { canUseTools: !inputType }); } else if (this.options.target.data) { - this.modelRef.value = this.chatService.loadSessionFromContent(this.options.target.data); + this.modelRef.value = this.chatService.loadSessionFromData(this.options.target.data); } if (!this.model || this.isDisposed()) { diff --git a/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts b/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts index 9ff8c082319..19519ce7abb 100644 --- a/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts +++ b/src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts @@ -248,7 +248,7 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate { if (!this._widget?.viewModel && !this.restoringSession) { const sessionResource = this.getTransferredOrPersistedSessionInfo(); this.restoringSession = - (sessionResource ? this.chatService.getOrRestoreSession(sessionResource) : Promise.resolve(undefined)).then(async modelRef => { + (sessionResource ? this.chatService.acquireOrLoadSession(sessionResource, ChatAgentLocation.Chat, CancellationToken.None) : Promise.resolve(undefined)).then(async modelRef => { if (!this._widget) { return; // renderBody has not been called yet } @@ -675,7 +675,7 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate { private async _applyModel(): Promise { const sessionResource = this.getTransferredOrPersistedSessionInfo(); - const modelRef = sessionResource ? await this.chatService.getOrRestoreSession(sessionResource) : undefined; + const modelRef = sessionResource ? await this.chatService.acquireOrLoadSession(sessionResource, ChatAgentLocation.Chat, CancellationToken.None) : undefined; await this.showModel(modelRef); } @@ -686,8 +686,8 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate { let ref: IChatModelReference | undefined; if (startNewSession) { ref = modelRef ?? (this.chatService.transferredSessionResource - ? await this.chatService.getOrRestoreSession(this.chatService.transferredSessionResource) - : this.chatService.startSession(ChatAgentLocation.Chat)); + ? await this.chatService.acquireOrLoadSession(this.chatService.transferredSessionResource, ChatAgentLocation.Chat, CancellationToken.None) + : this.chatService.startNewLocalSession(ChatAgentLocation.Chat)); if (!ref) { throw new Error('Could not start chat session'); } @@ -773,12 +773,7 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate { }, 100); try { - const sessionType = getChatSessionType(sessionResource); - if (sessionType !== localChatSessionType) { - await this.chatSessionsService.canResolveChatSession(sessionResource); - } - - const newModelRef = await this.chatService.loadSessionForResource(sessionResource, ChatAgentLocation.Chat, CancellationToken.None); + const newModelRef = await this.chatService.acquireOrLoadSession(sessionResource, ChatAgentLocation.Chat, CancellationToken.None); clearWidget.dispose(); await queue; diff --git a/src/vs/workbench/contrib/chat/common/chatService/chatService.ts b/src/vs/workbench/contrib/chat/common/chatService/chatService.ts index a826cd3b658..654eaa98fb4 100644 --- a/src/vs/workbench/contrib/chat/common/chatService/chatService.ts +++ b/src/vs/workbench/contrib/chat/common/chatService/chatService.ts @@ -1354,25 +1354,46 @@ export interface IChatService { */ readonly chatModels: IObservable>; + readonly editingSessions: readonly IChatEditingSession[]; + isEnabled(location: ChatAgentLocation): boolean; + hasSessions(): boolean; - startSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference; + + /** + * Starts a new chat session at the given location. + * + * @returns A reference to the session's model. + */ + startNewLocalSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference; /** * Get an active session without holding a reference to it. + * + * @returns The session's model, or undefined if no active session exists. */ getSession(sessionResource: URI): IChatModel | undefined; /** * Acquire a reference to an active session. + * + * @returns A reference to the session's model or undefined if there is no active session for the given resource. */ - getActiveSessionReference(sessionResource: URI): IChatModelReference | undefined; + acquireExistingSession(sessionResource: URI): IChatModelReference | undefined; + + /** + * Tries to acquire an existing a chat session for the resource. If no session exists, tries to load one for the given + * session resource and location. This may load the session from an external provider. + * + * @returns A reference to the session's model, or undefined if the session could not be loaded + */ + acquireOrLoadSession(sessionResource: URI, location: ChatAgentLocation, token: CancellationToken): Promise; + + /** + * Loads a session from exported chat data + */ + loadSessionFromData(data: IExportableChatData | ISerializableChatData): IChatModelReference; - getOrRestoreSession(sessionResource: URI): Promise; - getSessionTitle(sessionResource: URI): string | undefined; - loadSessionFromContent(data: IExportableChatData | ISerializableChatData | URI): IChatModelReference | undefined; - loadSessionForResource(resource: URI, location: ChatAgentLocation, token: CancellationToken): Promise; - readonly editingSessions: IChatEditingSession[]; getChatSessionFromInternalUri(sessionResource: URI): IChatSessionContext | undefined; /** @@ -1381,10 +1402,9 @@ export interface IChatService { */ sendRequest(sessionResource: URI, message: string, options?: IChatSendRequestOptions): Promise; - /** - * Sets a custom title for a chat model. - */ - setTitle(sessionResource: URI, title: string): void; + getSessionTitle(sessionResource: URI): string | undefined; + setSessionTitle(sessionResource: URI, title: string): void; + appendProgress(request: IChatRequestModel, progress: IChatProgress): void; resendRequest(request: IChatRequestModel, options?: IChatSendRequestOptions): Promise; adoptRequest(sessionResource: URI, request: IChatRequestModel): Promise; diff --git a/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts b/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts index e2b5b29c409..7b937fb65fb 100644 --- a/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts +++ b/src/vs/workbench/contrib/chat/common/chatService/chatServiceImpl.ts @@ -356,7 +356,7 @@ export class ChatService extends Disposable implements IChatService { } sessionResource ??= LocalChatSessionUri.forSession(session.sessionId); - const sessionRef = await this.getOrRestoreSession(sessionResource); + const sessionRef = await this.acquireOrLoadSession(sessionResource, ChatAgentLocation.Chat, CancellationToken.None); if (sessionRef?.object.editingSession) { await chatEditingSessionIsReady(sessionRef.object.editingSession); // the session will hold a self-reference as long as there are modified files @@ -444,10 +444,9 @@ export class ChatService extends Disposable implements IChatService { await this._chatSessionStore.clearAllSessions(); } - startSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference { + startNewLocalSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference { this.trace('startSession'); - const sessionId = generateUuid(); - const sessionResource = LocalChatSessionUri.forSession(sessionId); + const sessionResource = LocalChatSessionUri.forSession(generateUuid()); return this._sessionModels.acquireOrCreate({ initialData: undefined, location, @@ -506,13 +505,13 @@ export class ChatService extends Disposable implements IChatService { return this._sessionModels.get(sessionResource); } - getActiveSessionReference(sessionResource: URI): IChatModelReference | undefined { + acquireExistingSession(sessionResource: URI): IChatModelReference | undefined { return this._sessionModels.acquireExisting(sessionResource); } - async getOrRestoreSession(sessionResource: URI): Promise { - this.trace('getOrRestoreSession', `${sessionResource}`); - const existingRef = this._sessionModels.acquireExisting(sessionResource); + private async acquireOrRestoreLocalSession(sessionResource: URI): Promise { + this.trace('acquireOrRestoreSession', `${sessionResource}`); + const existingRef = this.acquireExistingSession(sessionResource); if (existingRef) { return existingRef; } @@ -525,8 +524,6 @@ export class ChatService extends Disposable implements IChatService { const localSessionId = LocalChatSessionUri.parseLocalSessionId(sessionResource); if (localSessionId) { sessionData = await this._chatSessionStore.readSession(localSessionId); - } else { - return this.loadSessionForResource(sessionResource, ChatAgentLocation.Chat, CancellationToken.None); } } @@ -556,7 +553,7 @@ export class ChatService extends Disposable implements IChatService { this._chatSessionStore.getMetadataForSessionSync(sessionResource)?.title; } - loadSessionFromContent(data: IExportableChatData | ISerializableChatData): IChatModelReference | undefined { + loadSessionFromData(data: IExportableChatData | ISerializableChatData): IChatModelReference { const sessionId = (data as ISerializableChatData).sessionId ?? generateUuid(); const sessionResource = LocalChatSessionUri.forSession(sessionId); return this._sessionModels.acquireOrCreate({ @@ -567,43 +564,52 @@ export class ChatService extends Disposable implements IChatService { }); } - async loadSessionForResource(chatSessionResource: URI, location: ChatAgentLocation, token: CancellationToken): Promise { - // TODO: Move this into a new ChatModelService + async acquireOrLoadSession(sessionResource: URI, location: ChatAgentLocation, token: CancellationToken): Promise { + if (sessionResource.scheme === Schemas.vscodeLocalChatSession) { + return this.acquireOrRestoreLocalSession(sessionResource); + } else { + return this.loadRemoteSession(sessionResource, location, token); + } + } - if (chatSessionResource.scheme === Schemas.vscodeLocalChatSession) { - return this.getOrRestoreSession(chatSessionResource); + private async loadRemoteSession(sessionResource: URI, location: ChatAgentLocation, token: CancellationToken): Promise { + await this.chatSessionService.canResolveChatSession(sessionResource); + + // Check if session already exists + { + const existingRef = this.acquireExistingSession(sessionResource); + if (existingRef) { + return existingRef; + } } - const existingRef = this._sessionModels.acquireExisting(chatSessionResource); - if (existingRef) { - return existingRef; - } - - const providedSession = await this.chatSessionService.getOrCreateChatSession(chatSessionResource, CancellationToken.None); + const providedSession = await this.chatSessionService.getOrCreateChatSession(sessionResource, token); // Make sure we haven't created this in the meantime - const existingRefAfterProvision = this._sessionModels.acquireExisting(chatSessionResource); - if (existingRefAfterProvision) { - providedSession.dispose(); - return existingRefAfterProvision; + { + const existingRef = this.acquireExistingSession(sessionResource); + if (existingRef) { + providedSession.dispose(); + return existingRef; + } } - const chatSessionType = chatSessionResource.scheme; + const chatSessionType = sessionResource.scheme; // Contributed sessions do not use UI tools const modelRef = this._sessionModels.acquireOrCreate({ initialData: undefined, location, - sessionResource: chatSessionResource, + sessionResource: sessionResource, canUseTools: false, transferEditingSession: providedSession.transferredState?.editingSession, inputState: providedSession.transferredState?.inputState, }); modelRef.object.setContributedChatSession({ - chatSessionResource, + chatSessionResource: sessionResource, chatSessionType, - isUntitled: chatSessionResource.path.startsWith('/untitled-') //TODO(jospicer) + isUntitled: sessionResource.path.startsWith('/untitled-') //TODO(jospicer) }); const model = modelRef.object; @@ -1489,7 +1495,7 @@ export class ChatService extends Disposable implements IChatService { this._chatSessionStore.logIndex(); } - setTitle(sessionResource: URI, title: string): void { + setSessionTitle(sessionResource: URI, title: string): void { this._sessionModels.get(sessionResource)?.setCustomTitle(title); } diff --git a/src/vs/workbench/contrib/chat/common/model/chatModel.ts b/src/vs/workbench/contrib/chat/common/model/chatModel.ts index c5d858de46c..a85a969c0b2 100644 --- a/src/vs/workbench/contrib/chat/common/model/chatModel.ts +++ b/src/vs/workbench/contrib/chat/common/model/chatModel.ts @@ -2214,7 +2214,7 @@ export class ChatModel extends Disposable implements IChatModel { const needsInput = this.requestNeedsInput.read(r); const shouldStayAlive = inProgress || !!needsInput; if (shouldStayAlive && !selfRef.value) { - selfRef.value = chatService.getActiveSessionReference(this._sessionResource); + selfRef.value = chatService.acquireExistingSession(this._sessionResource); } else if (!shouldStayAlive && selfRef.value) { selfRef.clear(); } @@ -2238,7 +2238,7 @@ export class ChatModel extends Disposable implements IChatModel { this._register(autorun(r => { const hasModified = session.entries.read(r).some(e => e.state.read(r) === ModifiedFileEntryState.Modified); if (hasModified && !selfRef.value) { - selfRef.value = this.chatService.getActiveSessionReference(this._sessionResource); + selfRef.value = this.chatService.acquireExistingSession(this._sessionResource); } else if (!hasModified && selfRef.value) { selfRef.clear(); } diff --git a/src/vs/workbench/contrib/chat/common/model/chatModelStore.ts b/src/vs/workbench/contrib/chat/common/model/chatModelStore.ts index 588be79a828..24bd5cd8263 100644 --- a/src/vs/workbench/contrib/chat/common/model/chatModelStore.ts +++ b/src/vs/workbench/contrib/chat/common/model/chatModelStore.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Emitter } from '../../../../../base/common/event.js'; -import { Disposable, IDisposable, IReference, ReferenceCollection } from '../../../../../base/common/lifecycle.js'; +import { Disposable, IReference, ReferenceCollection } from '../../../../../base/common/lifecycle.js'; import { ObservableMap } from '../../../../../base/common/observable.js'; import { URI } from '../../../../../base/common/uri.js'; import { ILogService } from '../../../../../platform/log/common/log.js'; @@ -27,7 +27,7 @@ export interface ChatModelStoreDelegate { willDisposeModel: (model: ChatModel) => Promise; } -export class ChatModelStore extends Disposable implements IDisposable { +export class ChatModelStore extends Disposable { private readonly _refCollection: ReferenceCollection; private readonly _models = new ObservableMap(); diff --git a/src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts b/src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts index 2cd794010cb..81130418144 100644 --- a/src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/agentSessions/localAgentSessionsController.test.ts @@ -98,7 +98,7 @@ class MockChatService implements IChatService { return []; } - startSession(_location: ChatAgentLocation, _options?: IChatSessionStartOptions): any { + startNewLocalSession(_location: ChatAgentLocation, _options?: IChatSessionStartOptions): any { throw new Error('Method not implemented.'); } @@ -110,7 +110,7 @@ class MockChatService implements IChatService { return undefined; } - getOrRestoreSession(_sessionResource: URI): Promise { + acquireOrRestoreSession(_sessionResource: URI): Promise { throw new Error('Method not implemented.'); } @@ -118,19 +118,19 @@ class MockChatService implements IChatService { return undefined; } - loadSessionFromContent(_data: any): any { + loadSessionFromData(_data: any): any { throw new Error('Method not implemented.'); } - loadSessionForResource(_resource: URI, _position: ChatAgentLocation, _token: CancellationToken): Promise { + acquireOrLoadSession(_resource: URI, _position: ChatAgentLocation, _token: CancellationToken): Promise { throw new Error('Method not implemented.'); } - getActiveSessionReference(_sessionResource: URI): any { + acquireExistingSession(_sessionResource: URI): any { return undefined; } - setTitle(_sessionResource: URI, _title: string): void { } + setSessionTitle(_sessionResource: URI, _title: string): void { } appendProgress(_request: IChatRequestModel, _progress: any): void { } diff --git a/src/vs/workbench/contrib/chat/test/browser/chatEditing/chatEditingService.test.ts b/src/vs/workbench/contrib/chat/test/browser/chatEditing/chatEditingService.test.ts index 0243dcfdd0d..adf87b80a57 100644 --- a/src/vs/workbench/contrib/chat/test/browser/chatEditing/chatEditingService.test.ts +++ b/src/vs/workbench/contrib/chat/test/browser/chatEditing/chatEditingService.test.ts @@ -147,7 +147,7 @@ suite('ChatEditingService', function () { test('create session', async function () { assert.ok(editingService); - const modelRef = chatService.startSession(ChatAgentLocation.EditorInline); + const modelRef = chatService.startNewLocalSession(ChatAgentLocation.EditorInline); const model = modelRef.object as ChatModel; const session = editingService.createEditingSession(model, true); @@ -168,7 +168,7 @@ suite('ChatEditingService', function () { const uri = URI.from({ scheme: 'test', path: 'HelloWorld' }); - const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat)); + const modelRef = store.add(chatService.startNewLocalSession(ChatAgentLocation.Chat)); const model = modelRef.object as ChatModel; const session = model.editingSession; if (!session) { @@ -225,7 +225,7 @@ suite('ChatEditingService', function () { const uri = URI.from({ scheme: 'test', path: 'abc\n' }); - const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat)); + const modelRef = store.add(chatService.startNewLocalSession(ChatAgentLocation.Chat)); const model = modelRef.object as ChatModel; const session = model.editingSession; assertType(session, 'session not created'); @@ -259,7 +259,7 @@ suite('ChatEditingService', function () { const uri = URI.from({ scheme: 'test', path: 'abc\n' }); - const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat)); + const modelRef = store.add(chatService.startNewLocalSession(ChatAgentLocation.Chat)); const model = modelRef.object as ChatModel; const session = model.editingSession; assertType(session, 'session not created'); @@ -293,7 +293,7 @@ suite('ChatEditingService', function () { const uri = URI.from({ scheme: 'test', path: 'abc\n' }); - const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat)); + const modelRef = store.add(chatService.startNewLocalSession(ChatAgentLocation.Chat)); const model = modelRef.object as ChatModel; const session = model.editingSession; assertType(session, 'session not created'); @@ -329,7 +329,7 @@ suite('ChatEditingService', function () { const modified = store.add(await textModelService.createModelReference(uri)).object.textEditorModel; - const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat)); + const modelRef = store.add(chatService.startNewLocalSession(ChatAgentLocation.Chat)); const model = modelRef.object as ChatModel; const session = model.editingSession; assertType(session, 'session not created'); diff --git a/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts b/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts index 15a5add3196..ca738af3fb2 100644 --- a/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts +++ b/src/vs/workbench/contrib/chat/test/common/chatService/chatService.test.ts @@ -49,6 +49,7 @@ import { MockChatService } from './mockChatService.js'; import { MockChatVariablesService } from '../mockChatVariables.js'; import { IPromptsService } from '../../../common/promptSyntax/service/promptsService.js'; import { MockPromptsService } from '../promptSyntax/service/mockPromptsService.js'; +import { CancellationToken } from '../../../../../../base/common/cancellation.js'; const chatAgentWithUsedContextId = 'ChatProviderWithUsedContext'; const chatAgentWithUsedContext: IChatAgent = { @@ -144,12 +145,12 @@ suite('ChatService', () => { } function startSessionModel(service: IChatService, location: ChatAgentLocation = ChatAgentLocation.Chat): IChatModelReference { - const ref = testDisposables.add(service.startSession(location)); + const ref = testDisposables.add(service.startNewLocalSession(location)); return ref; } async function getOrRestoreModel(service: IChatService, resource: URI): Promise { - const ref = await service.getOrRestoreSession(resource); + const ref = await service.acquireOrLoadSession(resource, ChatAgentLocation.Chat, CancellationToken.None); if (!ref) { return undefined; } @@ -218,11 +219,11 @@ suite('ChatService', () => { test('retrieveSession', async () => { const testService = createChatService(); // Don't add refs to testDisposables so we can control disposal - const session1Ref = testService.startSession(ChatAgentLocation.Chat); + const session1Ref = testService.startNewLocalSession(ChatAgentLocation.Chat); const session1 = session1Ref.object as ChatModel; session1.addRequest({ parts: [], text: 'request 1' }, { variables: [] }, 0); - const session2Ref = testService.startSession(ChatAgentLocation.Chat); + const session2Ref = testService.startNewLocalSession(ChatAgentLocation.Chat); const session2 = session2Ref.object as ChatModel; session2.addRequest({ parts: [], text: 'request 2' }, { variables: [] }, 0); @@ -370,7 +371,7 @@ suite('ChatService', () => { const testService2 = createChatService(); - const chatModel2Ref = testService2.loadSessionFromContent(serializedChatData); + const chatModel2Ref = testService2.loadSessionFromData(serializedChatData); assert(chatModel2Ref); testDisposables.add(chatModel2Ref); const chatModel2 = chatModel2Ref.object; @@ -401,7 +402,7 @@ suite('ChatService', () => { const testService2 = createChatService(); - const chatModel2Ref = testService2.loadSessionFromContent(serializedChatData); + const chatModel2Ref = testService2.loadSessionFromData(serializedChatData); assert(chatModel2Ref); testDisposables.add(chatModel2Ref); const chatModel2 = chatModel2Ref.object; @@ -411,7 +412,7 @@ suite('ChatService', () => { test('onDidDisposeSession', async () => { const testService = createChatService(); - const modelRef = testService.startSession(ChatAgentLocation.Chat); + const modelRef = testService.startNewLocalSession(ChatAgentLocation.Chat); const model = modelRef.object; let disposed = false; diff --git a/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts b/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts index 5d662e05199..8fb1d803dee 100644 --- a/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts +++ b/src/vs/workbench/contrib/chat/test/common/chatService/mockChatService.ts @@ -37,7 +37,7 @@ export class MockChatService implements IChatService { getProviderInfos(): IChatProviderInfo[] { throw new Error('Method not implemented.'); } - startSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference { + startNewLocalSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference { throw new Error('Method not implemented.'); } addSession(session: IChatModel): void { @@ -50,22 +50,22 @@ export class MockChatService implements IChatService { getLatestRequest(): IChatRequestModel | undefined { return undefined; } - async getOrRestoreSession(sessionResource: URI): Promise { + async acquireOrRestoreSession(sessionResource: URI): Promise { throw new Error('Method not implemented.'); } getSessionTitle(sessionResource: URI): string | undefined { throw new Error('Method not implemented.'); } - loadSessionFromContent(data: ISerializableChatData): IChatModelReference | undefined { + loadSessionFromData(data: ISerializableChatData): IChatModelReference { throw new Error('Method not implemented.'); } - loadSessionForResource(resource: URI, position: ChatAgentLocation, token: CancellationToken): Promise { + acquireOrLoadSession(resource: URI, position: ChatAgentLocation, token: CancellationToken): Promise { throw new Error('Method not implemented.'); } - getActiveSessionReference(sessionResource: URI): IChatModelReference | undefined { + acquireExistingSession(sessionResource: URI): IChatModelReference | undefined { return undefined; } - setTitle(sessionResource: URI, title: string): void { + setSessionTitle(sessionResource: URI, title: string): void { throw new Error('Method not implemented.'); } appendProgress(request: IChatRequestModel, progress: IChatProgress): void { diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts index 6415bfcfe49..7efaea3ee5d 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts @@ -687,7 +687,7 @@ export async function reviewEdits(accessor: ServicesAccessor, editor: ICodeEdito const chatService = accessor.get(IChatService); const uri = editor.getModel().uri; - const chatModelRef = chatService.startSession(ChatAgentLocation.EditorInline); + const chatModelRef = chatService.startNewLocalSession(ChatAgentLocation.EditorInline); const chatModel = chatModelRef.object as ChatModel; chatModel.startEditingSession(true); @@ -739,7 +739,7 @@ export async function reviewNotebookEdits(accessor: ServicesAccessor, uri: URI, const chatService = accessor.get(IChatService); const notebookService = accessor.get(INotebookService); const isNotebook = notebookService.hasSupportedNotebooks(uri); - const chatModelRef = chatService.startSession(ChatAgentLocation.EditorInline); + const chatModelRef = chatService.startNewLocalSession(ChatAgentLocation.EditorInline); const chatModel = chatModelRef.object as ChatModel; chatModel.startEditingSession(true); diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts index 4f16fdc8bbb..1e54c82cb2f 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts @@ -71,7 +71,7 @@ export async function askInPanelChat(accessor: ServicesAccessor, request: IChatR return; } - const newModelRef = chatService.startSession(ChatAgentLocation.Chat); + const newModelRef = chatService.startNewLocalSession(ChatAgentLocation.Chat); const newModel = newModelRef.object; newModel.inputModel.setState({ ...state }); diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts index 185b56de369..52ea6e46316 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts @@ -80,7 +80,7 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService { this._onWillStartSession.fire(editor); - const chatModelRef = this._chatService.startSession(ChatAgentLocation.EditorInline, { canUseTools: false /* SEE https://github.com/microsoft/vscode/issues/279946 */ }); + const chatModelRef = this._chatService.startNewLocalSession(ChatAgentLocation.EditorInline, { canUseTools: false /* SEE https://github.com/microsoft/vscode/issues/279946 */ }); const chatModel = chatModelRef.object; chatModel.startEditingSession(false); diff --git a/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts b/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts index d08f85abbe2..946f14bcbcd 100644 --- a/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts +++ b/src/vs/workbench/contrib/terminalContrib/chat/browser/terminalChatWidget.ts @@ -329,7 +329,7 @@ export class TerminalChatWidget extends Disposable { private async _createSession(): Promise { this._sessionCtor = createCancelablePromise(async token => { if (!this._model.value) { - const modelRef = this._chatService.startSession(ChatAgentLocation.Terminal); + const modelRef = this._chatService.startNewLocalSession(ChatAgentLocation.Terminal); this._model.value = modelRef; const model = modelRef.object; this._inlineChatWidget.setChatModel(model); diff --git a/src/vs/workbench/contrib/welcomeAgentSessions/browser/agentSessionsWelcome.ts b/src/vs/workbench/contrib/welcomeAgentSessions/browser/agentSessionsWelcome.ts index 34b84089d18..a46a9622da6 100644 --- a/src/vs/workbench/contrib/welcomeAgentSessions/browser/agentSessionsWelcome.ts +++ b/src/vs/workbench/contrib/welcomeAgentSessions/browser/agentSessionsWelcome.ts @@ -323,8 +323,8 @@ export class AgentSessionsWelcomePage extends EditorPane { position: ChatSessionPosition.Sidebar, displayName: '' }); - const ref = await this.chatService.loadSessionForResource(newResource, ChatAgentLocation.Chat, CancellationToken.None); - this.chatModelRef = ref ?? this.chatService.startSession(ChatAgentLocation.Chat); + const ref = await this.chatService.acquireOrLoadSession(newResource, ChatAgentLocation.Chat, CancellationToken.None); + this.chatModelRef = ref ?? this.chatService.startNewLocalSession(ChatAgentLocation.Chat); this.contentDisposables.add(this.chatModelRef); if (this.chatModelRef.object) { this.chatWidget.setModel(this.chatModelRef.object); @@ -404,7 +404,7 @@ export class AgentSessionsWelcomePage extends EditorPane { // Start a chat session so the widget has a viewModel // This is necessary for actions like mode switching to work properly - this.chatModelRef = this.chatService.startSession(ChatAgentLocation.Chat); + this.chatModelRef = this.chatService.startNewLocalSession(ChatAgentLocation.Chat); this.contentDisposables.add(this.chatModelRef); if (this.chatModelRef.object) { this.chatWidget.setModel(this.chatModelRef.object);