Skip to content

Commit fc3def6

Browse files
[Cherry-pick] Remove last-used session type and agent logic (#323484) (#324826)
* cherry-pick b802a62 * signing commit * Fix test * Revert PR #324669 * Revert "Revert PR #324669" This reverts commit d97c4e5. * Preserve explicit local chat session branch * Remove IStorageService --------- Co-authored-by: Don Jayamanne <don.jayamanne@outlook.com>
1 parent 2eb7053 commit fc3def6

5 files changed

Lines changed: 3 additions & 104 deletions

File tree

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ import { isEqual } from '../../../../../base/common/resources.js';
1111
import { URI } from '../../../../../base/common/uri.js';
1212
import { ILayoutService } from '../../../../../platform/layout/browser/layoutService.js';
1313
import { ILogService } from '../../../../../platform/log/common/log.js';
14-
import { IStorageService, StorageScope, StorageTarget } from '../../../../../platform/storage/common/storage.js';
1514
import { ACTIVE_GROUP, IEditorService, type PreferredGroup } from '../../../../services/editor/common/editorService.js';
1615
import { IEditorGroup, IEditorGroupsService, isEditorGroup } from '../../../../services/editor/common/editorGroupsService.js';
1716
import { IViewsService } from '../../../../services/views/common/viewsService.js';
1817
import { IChatService } from '../../common/chatService/chatService.js';
19-
import { localChatSessionType } from '../../common/chatSessionsService.js';
20-
import { ChatAgentLocation, ChatLastUsedEditorSessionTypeStorageKey } from '../../common/constants.js';
21-
import { getChatSessionType } from '../../common/model/chatUri.js';
18+
import { ChatAgentLocation } from '../../common/constants.js';
2219
import { ChatViewId, ChatViewPaneTarget, IChatWidget, IChatWidgetService, IQuickChatService, isIChatViewViewContext } from '../chat.js';
2320
import { ChatEditor, IChatEditorOptions } from '../widgetHosts/editor/chatEditor.js';
2421
import { ChatEditorInput } from '../widgetHosts/editor/chatEditorInput.js';
@@ -51,7 +48,6 @@ export class ChatWidgetService extends Disposable implements IChatWidgetService
5148
@IEditorService private readonly editorService: IEditorService,
5249
@IChatService private readonly chatService: IChatService,
5350
@ILogService private readonly logService: ILogService,
54-
@IStorageService private readonly storageService: IStorageService,
5551
) {
5652
super();
5753
}
@@ -237,30 +233,10 @@ export class ChatWidgetService extends Disposable implements IChatWidgetService
237233
}
238234

239235
this._lastFocusedWidget = widget;
240-
this.recordLastUsedSessionType(widget);
241236
this._onDidChangeFocusedWidget.fire(widget);
242237
this._onDidChangeFocusedSession.fire();
243238
}
244239

245-
/**
246-
* Stores the session type (agent) of the last-focused user-facing chat so new chat editors can reuse it (excluding Quick Chat).
247-
*/
248-
private recordLastUsedSessionType(widget: IChatWidget | undefined): void {
249-
const sessionResource = widget?.viewModel?.sessionResource;
250-
if (!sessionResource) {
251-
return;
252-
}
253-
if (this.quickChatService.sessionResource && isEqual(sessionResource, this.quickChatService.sessionResource)) {
254-
return;
255-
}
256-
const sessionType = getChatSessionType(sessionResource);
257-
// Only remember non-local agents to avoid clobbering the user's last-used agent.
258-
if (sessionType === localChatSessionType) {
259-
return;
260-
}
261-
this.storageService.store(ChatLastUsedEditorSessionTypeStorageKey, sessionType, StorageScope.PROFILE, StorageTarget.USER);
262-
}
263-
264240
register(newWidget: IChatWidget): IDisposable {
265241
if (this._widgets.some(widget => widget === newWidget)) {
266242
throw new Error('Cannot register the same widget multiple times');
@@ -277,7 +253,6 @@ export class ChatWidgetService extends Disposable implements IChatWidgetService
277253
newWidget.onDidFocus(() => this.setLastFocusedWidget(newWidget)),
278254
newWidget.onDidChangeViewModel(({ previousSessionResource, currentSessionResource }) => {
279255
if (this._lastFocusedWidget === newWidget && !isEqual(previousSessionResource, currentSessionResource)) {
280-
this.recordLastUsedSessionType(newWidget);
281256
this._onDidChangeFocusedSession.fire();
282257
}
283258

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -999,21 +999,6 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
999999
|| hasModelsTargetingSession(this.getAllMergedModels(), sessionType);
10001000
}
10011001

1002-
/**
1003-
* Returns the persisted model for the current session type, if it exists in the current model pool.
1004-
*/
1005-
private _getRememberedSessionTypeModel(): ILanguageModelChatMetadataAndIdentifier | undefined {
1006-
const sessionType = this._currentSessionType;
1007-
if (!sessionType || !this.sessionTypeHasOwnModelPool(sessionType)) {
1008-
return undefined;
1009-
}
1010-
const persisted = this.storageService.get(this.getSelectedModelStorageKey(), StorageScope.APPLICATION);
1011-
if (!persisted) {
1012-
return undefined;
1013-
}
1014-
return this.getModels().find(m => m.identifier === persisted);
1015-
}
1016-
10171002
private initSelectedModel() {
10181003
// initSelectedModel is scoped to the current storage key/session type.
10191004
// Do not let a delayed restore from a previous session type apply later.
@@ -1475,13 +1460,6 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
14751460
if (!state && this._chatSessionIsEmpty) {
14761461
state = this._getPersistedEmptyInputState();
14771462
message = `syncing from empty input state for ${forSessionResource.toString()}`;
1478-
// Seed model/config from the last-used selection for this session type (configured default still wins).
1479-
const rememberedSessionTypeModel = this._getRememberedSessionTypeModel();
1480-
if (rememberedSessionTypeModel) {
1481-
const base = state ?? this.getCurrentInputState();
1482-
const rememberedModelConfiguration = this._modelConfigStore.getModelConfiguration(rememberedSessionTypeModel.identifier);
1483-
state = { ...base, selectedModel: rememberedSessionTypeModel, modelConfiguration: rememberedModelConfiguration };
1484-
}
14851463
// A configured default model (e.g. set by enterprise policy via
14861464
// `chat.defaultModel`) starts every NEW conversation and
14871465
// must win over the remembered empty-input draft model. `initSelectedModel`

src/vs/workbench/contrib/chat/browser/widgetHosts/editor/chatEditorInput.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ import * as nls from '../../../../../../nls.js';
1616
import { ConfirmResult, IDialogService } from '../../../../../../platform/dialogs/common/dialogs.js';
1717
import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js';
1818
import { IInstantiationService } from '../../../../../../platform/instantiation/common/instantiation.js';
19-
import { IStorageService, StorageScope } from '../../../../../../platform/storage/common/storage.js';
2019
import { registerIcon } from '../../../../../../platform/theme/common/iconRegistry.js';
2120
import { EditorInputCapabilities, IEditorIdentifier, IEditorSerializer, IUntypedEditorInput, Verbosity } from '../../../../../common/editor.js';
2221
import { EditorInput, IEditorCloseHandler } from '../../../../../common/editor/editorInput.js';
2322
import { IChatModelReference, IChatService } from '../../../common/chatService/chatService.js';
2423
import { IChatSessionsService, localChatSessionType } from '../../../common/chatSessionsService.js';
25-
import { ChatAgentLocation, ChatEditorTitleMaxLength, ChatLastUsedEditorSessionTypeStorageKey, getDefaultNewChatSessionResource, getDefaultNewChatSessionType, getNewChatEditorSessionResource } from '../../../common/constants.js';
24+
import { ChatAgentLocation, ChatEditorTitleMaxLength, getDefaultNewChatSessionResource, getDefaultNewChatSessionType } from '../../../common/constants.js';
2625
import { IChatEditingSession, ModifiedFileEntryState } from '../../../common/editing/chatEditingService.js';
2726
import { IChatModel } from '../../../common/model/chatModel.js';
2827
import { LocalChatSessionUri, getChatSessionType } from '../../../common/model/chatUri.js';
@@ -66,7 +65,6 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler
6665
@IConfigurationService private readonly configurationService: IConfigurationService,
6766
@IChatSessionsService private readonly chatSessionsService: IChatSessionsService,
6867
@IInstantiationService private readonly instantiationService: IInstantiationService,
69-
@IStorageService private readonly storageService: IStorageService,
7068
) {
7169
super();
7270

@@ -236,8 +234,7 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler
236234
if (this.options.explicitSessionType === localChatSessionType) {
237235
this.modelRef.value = this.chatService.startNewLocalSession(ChatAgentLocation.Chat, { canUseTools: !inputType, debugOwner: 'ChatEditorInput#resolveExplicitLocal' });
238236
} else {
239-
const lastUsedSessionType = this.storageService.get(ChatLastUsedEditorSessionTypeStorageKey, StorageScope.PROFILE);
240-
const defaultResource = getNewChatEditorSessionResource(this.configurationService, this.chatSessionsService, lastUsedSessionType);
237+
const defaultResource = getDefaultNewChatSessionResource(this.configurationService, this.chatSessionsService);
241238
if (getChatSessionType(defaultResource) === localChatSessionType) {
242239
this.modelRef.value = this.chatService.startNewLocalSession(ChatAgentLocation.Chat, { canUseTools: !inputType, debugOwner: 'ChatEditorInput#resolveUntitled' });
243240
} else {

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

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -293,54 +293,6 @@ export function getDefaultNewChatSessionResource(
293293
: URI.from({ scheme: defaultType, path: `/untitled-${generateUuid()}` });
294294
}
295295

296-
/**
297-
* Storage key for the last-used non-local editor chat session type (agent), persisted at profile scope.
298-
*/
299-
export const ChatLastUsedEditorSessionTypeStorageKey = 'chat.lastUsedEditorSessionType';
300-
301-
/**
302-
* Resolves the session type (agent) for a new chat editor, preferring the last-used visible non-local agent when `chat.editor.defaultProvider` isn't explicitly configured.
303-
*/
304-
export function getNewChatEditorSessionType(
305-
configurationService: IConfigurationService,
306-
chatSessionsService: Pick<IChatSessionsService, 'getChatSessionContribution' | 'getAllChatSessionContributions'>,
307-
lastUsedSessionType: string | undefined,
308-
): string {
309-
const inspected = configurationService.inspect<string>(ChatConfiguration.EditorDefaultProvider);
310-
const explicitlyConfigured = inspected.applicationValue !== undefined
311-
|| inspected.userValue !== undefined
312-
|| inspected.userLocalValue !== undefined
313-
|| inspected.userRemoteValue !== undefined
314-
|| inspected.workspaceValue !== undefined
315-
|| inspected.workspaceFolderValue !== undefined
316-
|| inspected.memoryValue !== undefined
317-
|| inspected.policyValue !== undefined;
318-
319-
if (!explicitlyConfigured
320-
&& lastUsedSessionType
321-
&& lastUsedSessionType !== localChatSessionType
322-
&& isVisibleEditorChatSessionType(lastUsedSessionType, configurationService, chatSessionsService)) {
323-
return lastUsedSessionType;
324-
}
325-
326-
return getDefaultNewChatSessionType(configurationService, chatSessionsService);
327-
}
328-
329-
/**
330-
* Like {@link getDefaultNewChatSessionResource}, but prefers the user's
331-
* last-used session type via {@link getNewChatEditorSessionType}.
332-
*/
333-
export function getNewChatEditorSessionResource(
334-
configurationService: IConfigurationService,
335-
chatSessionsService: Pick<IChatSessionsService, 'getChatSessionContribution' | 'getAllChatSessionContributions'>,
336-
lastUsedSessionType: string | undefined,
337-
): URI {
338-
const sessionType = getNewChatEditorSessionType(configurationService, chatSessionsService, lastUsedSessionType);
339-
return sessionType === localChatSessionType
340-
? LocalChatSessionUri.getNewSessionUri()
341-
: URI.from({ scheme: sessionType, path: `/untitled-${generateUuid()}` });
342-
}
343-
344296
export function isEditorLocalAgentEnabled(configurationService: IConfigurationService): boolean {
345297
return configurationService.getValue<boolean>(ChatConfiguration.EditorLocalAgentEnabled) ?? true;
346298
}

src/vs/workbench/contrib/chat/test/browser/widgetHosts/editor/chatEditorInput.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../../ba
1010
import { IConfigurationService } from '../../../../../../../platform/configuration/common/configuration.js';
1111
import { IDialogService } from '../../../../../../../platform/dialogs/common/dialogs.js';
1212
import { IInstantiationService } from '../../../../../../../platform/instantiation/common/instantiation.js';
13-
import { IStorageService } from '../../../../../../../platform/storage/common/storage.js';
1413
import { ChatEditorInput } from '../../../../browser/widgetHosts/editor/chatEditorInput.js';
1514
import { IChatService, IChatSessionStartOptions } from '../../../../common/chatService/chatService.js';
1615
import { IChatSessionsService, localChatSessionType } from '../../../../common/chatSessionsService.js';
@@ -51,7 +50,6 @@ suite('ChatEditorInput', () => {
5150
{} as IConfigurationService,
5251
{} as IChatSessionsService,
5352
{} as IInstantiationService,
54-
{} as IStorageService,
5553
);
5654

5755
try {
@@ -103,7 +101,6 @@ suite('ChatEditorInput', () => {
103101
{} as IConfigurationService,
104102
{} as IChatSessionsService,
105103
{} as IInstantiationService,
106-
{} as IStorageService,
107104
);
108105

109106
try {

0 commit comments

Comments
 (0)