mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
Some chat service cleanup (#280105)
* Clean up unused cancel token * Simplify shouldBeInHistory * Use real DisposableResourceMap
This commit is contained in:
@@ -269,10 +269,10 @@ export class ChatEditorInput extends EditorInput implements IEditorCloseHandler
|
||||
|
||||
// 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, CancellationToken.None, { canUseTools: true });
|
||||
this.modelRef.value = this.chatService.startSession(ChatAgentLocation.Chat, { canUseTools: true });
|
||||
}
|
||||
} else if (!this.options.target) {
|
||||
this.modelRef.value = this.chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None, { canUseTools: !inputType });
|
||||
this.modelRef.value = this.chatService.startSession(ChatAgentLocation.Chat, { canUseTools: !inputType });
|
||||
} else if (this.options.target.data) {
|
||||
this.modelRef.value = this.chatService.loadSessionFromContent(this.options.target.data);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
import * as dom from '../../../../base/browser/dom.js';
|
||||
import { Orientation, Sash } from '../../../../base/browser/ui/sash/sash.js';
|
||||
import { disposableTimeout } from '../../../../base/common/async.js';
|
||||
import { CancellationToken } from '../../../../base/common/cancellation.js';
|
||||
import { Emitter, Event } from '../../../../base/common/event.js';
|
||||
import { MarkdownString } from '../../../../base/common/htmlContent.js';
|
||||
import { Disposable, DisposableStore, IDisposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
|
||||
@@ -395,7 +394,7 @@ class QuickChat extends Disposable {
|
||||
}
|
||||
|
||||
private updateModel(): void {
|
||||
this.modelRef ??= this.chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None, { disableBackgroundKeepAlive: true });
|
||||
this.modelRef ??= this.chatService.startSession(ChatAgentLocation.Chat, { disableBackgroundKeepAlive: true });
|
||||
const model = this.modelRef?.object;
|
||||
if (!model) {
|
||||
throw new Error('Could not start chat session');
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import './media/chatViewPane.css';
|
||||
import { $, append, getWindow, setVisibility } from '../../../../base/browser/dom.js';
|
||||
import { MenuWorkbenchToolBar } from '../../../../platform/actions/browser/toolbar.js';
|
||||
import { MenuId } from '../../../../platform/actions/common/actions.js';
|
||||
import { CancellationToken } from '../../../../base/common/cancellation.js';
|
||||
import { Event } from '../../../../base/common/event.js';
|
||||
import { MutableDisposable, toDisposable } from '../../../../base/common/lifecycle.js';
|
||||
import { MarshalledId } from '../../../../base/common/marshallingIds.js';
|
||||
import { autorun, IReader } from '../../../../base/common/observable.js';
|
||||
import { URI } from '../../../../base/common/uri.js';
|
||||
import { localize } from '../../../../nls.js';
|
||||
import { MenuWorkbenchToolBar } from '../../../../platform/actions/browser/toolbar.js';
|
||||
import { MenuId } from '../../../../platform/actions/common/actions.js';
|
||||
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
|
||||
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
|
||||
@@ -42,10 +42,10 @@ import { LocalChatSessionUri } from '../common/chatUri.js';
|
||||
import { ChatAgentLocation, ChatConfiguration, ChatModeKind } from '../common/constants.js';
|
||||
import { showCloseActiveChatNotification } from './actions/chatCloseNotification.js';
|
||||
import { AgentSessionsControl } from './agentSessions/agentSessionsControl.js';
|
||||
import { ChatWidget } from './chatWidget.js';
|
||||
import { ChatViewWelcomeController, IViewWelcomeDelegate } from './viewsWelcome/chatViewWelcomeController.js';
|
||||
import { AgentSessionsListDelegate } from './agentSessions/agentSessionsViewer.js';
|
||||
import { Event } from '../../../../base/common/event.js';
|
||||
import { ChatWidget } from './chatWidget.js';
|
||||
import './media/chatViewPane.css';
|
||||
import { ChatViewWelcomeController, IViewWelcomeDelegate } from './viewsWelcome/chatViewWelcomeController.js';
|
||||
|
||||
interface IChatViewPaneState extends Partial<IChatModelInputState> {
|
||||
sessionId?: string;
|
||||
@@ -179,7 +179,7 @@ export class ChatViewPane extends ViewPane implements IViewWelcomeDelegate {
|
||||
|
||||
const ref = modelRef ?? (this.chatService.transferredSessionData?.sessionId && this.chatService.transferredSessionData?.location === this.chatOptions.location
|
||||
? await this.chatService.getOrRestoreSession(LocalChatSessionUri.forSession(this.chatService.transferredSessionData.sessionId))
|
||||
: this.chatService.startSession(this.chatOptions.location, CancellationToken.None));
|
||||
: this.chatService.startSession(this.chatOptions.location));
|
||||
if (!ref) {
|
||||
throw new Error('Could not start chat session');
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CancellationToken } from '../../../../base/common/cancellation.js';
|
||||
import { Emitter } from '../../../../base/common/event.js';
|
||||
import { DisposableStore, IDisposable, IReference, ReferenceCollection } from '../../../../base/common/lifecycle.js';
|
||||
import { ObservableMap } from '../../../../base/common/observable.js';
|
||||
@@ -16,7 +15,6 @@ import { ChatAgentLocation } from './constants.js';
|
||||
export interface IStartSessionProps {
|
||||
readonly initialData?: IExportableChatData | ISerializableChatData;
|
||||
readonly location: ChatAgentLocation;
|
||||
readonly token: CancellationToken;
|
||||
readonly sessionResource: URI;
|
||||
readonly sessionId?: string;
|
||||
readonly canUseTools: boolean;
|
||||
|
||||
@@ -953,7 +953,7 @@ export interface IChatService {
|
||||
|
||||
isEnabled(location: ChatAgentLocation): boolean;
|
||||
hasSessions(): boolean;
|
||||
startSession(location: ChatAgentLocation, token: CancellationToken, options?: IChatSessionStartOptions): IChatModelReference;
|
||||
startSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference;
|
||||
|
||||
/**
|
||||
* Get an active session without holding a reference to it.
|
||||
|
||||
@@ -10,7 +10,7 @@ import { BugIndicatingError, ErrorNoTelemetry } from '../../../../base/common/er
|
||||
import { Emitter, Event } from '../../../../base/common/event.js';
|
||||
import { MarkdownString } from '../../../../base/common/htmlContent.js';
|
||||
import { Iterable } from '../../../../base/common/iterator.js';
|
||||
import { Disposable, DisposableMap, DisposableStore, IDisposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
|
||||
import { Disposable, DisposableResourceMap, DisposableStore, IDisposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
|
||||
import { revive } from '../../../../base/common/marshalling.js';
|
||||
import { Schemas } from '../../../../base/common/network.js';
|
||||
import { autorun, derived, IObservable } from '../../../../base/common/observable.js';
|
||||
@@ -72,38 +72,6 @@ class CancellableRequest implements IDisposable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class DisposableResourceMap<T extends IDisposable> extends Disposable {
|
||||
|
||||
private readonly _map = this._register(new DisposableMap<string, T>());
|
||||
|
||||
get(sessionResource: URI) {
|
||||
return this._map.get(this.toKey(sessionResource));
|
||||
}
|
||||
|
||||
set(sessionResource: URI, value: T) {
|
||||
this._map.set(this.toKey(sessionResource), value);
|
||||
}
|
||||
|
||||
has(sessionResource: URI) {
|
||||
return this._map.has(this.toKey(sessionResource));
|
||||
}
|
||||
|
||||
deleteAndLeak(sessionResource: URI) {
|
||||
return this._map.deleteAndLeak(this.toKey(sessionResource));
|
||||
}
|
||||
|
||||
deleteAndDispose(sessionResource: URI) {
|
||||
this._map.deleteAndDispose(this.toKey(sessionResource));
|
||||
}
|
||||
|
||||
private toKey(uri: URI): string {
|
||||
return uri.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ChatService extends Disposable implements IChatService {
|
||||
declare _serviceBrand: undefined;
|
||||
|
||||
@@ -396,7 +364,7 @@ export class ChatService extends Disposable implements IChatService {
|
||||
async getHistorySessionItems(): Promise<IChatDetail[]> {
|
||||
const index = await this._chatSessionStore.getIndex();
|
||||
return Object.values(index)
|
||||
.filter(entry => !this._sessionModels.has(LocalChatSessionUri.forSession(entry.sessionId)) && this.shouldBeInHistory(entry) && !entry.isEmpty)
|
||||
.filter(entry => !this._sessionModels.has(LocalChatSessionUri.forSession(entry.sessionId)) && entry.initialLocation === ChatAgentLocation.Chat && !entry.isEmpty)
|
||||
.map((entry): IChatDetail => {
|
||||
const sessionResource = LocalChatSessionUri.forSession(entry.sessionId);
|
||||
return ({
|
||||
@@ -407,11 +375,8 @@ export class ChatService extends Disposable implements IChatService {
|
||||
});
|
||||
}
|
||||
|
||||
private shouldBeInHistory(entry: Partial<ChatModel>) {
|
||||
if (entry.sessionResource) {
|
||||
return !entry.isImported && LocalChatSessionUri.parseLocalSessionId(entry.sessionResource) && entry.initialLocation === ChatAgentLocation.Chat;
|
||||
}
|
||||
return !entry.isImported && entry.initialLocation === ChatAgentLocation.Chat;
|
||||
private shouldBeInHistory(entry: ChatModel): boolean {
|
||||
return !entry.isImported && !!LocalChatSessionUri.parseLocalSessionId(entry.sessionResource) && entry.initialLocation === ChatAgentLocation.Chat;
|
||||
}
|
||||
|
||||
async removeHistoryEntry(sessionResource: URI): Promise<void> {
|
||||
@@ -422,14 +387,13 @@ export class ChatService extends Disposable implements IChatService {
|
||||
await this._chatSessionStore.clearAllSessions();
|
||||
}
|
||||
|
||||
startSession(location: ChatAgentLocation, token: CancellationToken, options?: IChatSessionStartOptions): IChatModelReference {
|
||||
startSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference {
|
||||
this.trace('startSession');
|
||||
const sessionId = generateUuid();
|
||||
const sessionResource = LocalChatSessionUri.forSession(sessionId);
|
||||
return this._sessionModels.acquireOrCreate({
|
||||
initialData: undefined,
|
||||
location,
|
||||
token,
|
||||
sessionResource,
|
||||
sessionId,
|
||||
canUseTools: options?.canUseTools ?? true,
|
||||
@@ -438,17 +402,17 @@ export class ChatService extends Disposable implements IChatService {
|
||||
}
|
||||
|
||||
private _startSession(props: IStartSessionProps): ChatModel {
|
||||
const { initialData, location, token, sessionResource, sessionId, canUseTools, transferEditingSession, disableBackgroundKeepAlive } = props;
|
||||
const { initialData, location, sessionResource, sessionId, canUseTools, transferEditingSession, disableBackgroundKeepAlive } = props;
|
||||
const model = this.instantiationService.createInstance(ChatModel, initialData, { initialLocation: location, canUseTools, resource: sessionResource, sessionId, disableBackgroundKeepAlive });
|
||||
if (location === ChatAgentLocation.Chat) {
|
||||
model.startEditingSession(true, transferEditingSession);
|
||||
}
|
||||
|
||||
this.initializeSession(model, token);
|
||||
this.initializeSession(model);
|
||||
return model;
|
||||
}
|
||||
|
||||
private initializeSession(model: ChatModel, token: CancellationToken): void {
|
||||
private initializeSession(model: ChatModel): void {
|
||||
this.trace('initializeSession', `Initialize session ${model.sessionResource}`);
|
||||
|
||||
// Activate the default extension provided agent but do not wait
|
||||
@@ -516,7 +480,6 @@ export class ChatService extends Disposable implements IChatService {
|
||||
const sessionRef = this._sessionModels.acquireOrCreate({
|
||||
initialData: sessionData,
|
||||
location: sessionData.initialLocation ?? ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
sessionResource,
|
||||
sessionId,
|
||||
canUseTools: true,
|
||||
@@ -583,7 +546,6 @@ export class ChatService extends Disposable implements IChatService {
|
||||
return this._sessionModels.acquireOrCreate({
|
||||
initialData: data,
|
||||
location: data.initialLocation ?? ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
sessionResource,
|
||||
sessionId,
|
||||
canUseTools: true,
|
||||
@@ -609,7 +571,6 @@ export class ChatService extends Disposable implements IChatService {
|
||||
const modelRef = this._sessionModels.acquireOrCreate({
|
||||
initialData: undefined,
|
||||
location,
|
||||
token: CancellationToken.None,
|
||||
sessionResource: chatSessionResource,
|
||||
canUseTools: false,
|
||||
transferEditingSession: providedSession.initialEditingSession,
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { CancellationToken } from '../../../../../base/common/cancellation.js';
|
||||
import { Disposable, DisposableStore, IDisposable } from '../../../../../base/common/lifecycle.js';
|
||||
import { waitForState } from '../../../../../base/common/observable.js';
|
||||
import { isEqual } from '../../../../../base/common/resources.js';
|
||||
@@ -140,7 +139,7 @@ suite('ChatEditingService', function () {
|
||||
test('create session', async function () {
|
||||
assert.ok(editingService);
|
||||
|
||||
const modelRef = chatService.startSession(ChatAgentLocation.EditorInline, CancellationToken.None);
|
||||
const modelRef = chatService.startSession(ChatAgentLocation.EditorInline);
|
||||
const model = modelRef.object as ChatModel;
|
||||
const session = editingService.createEditingSession(model, true);
|
||||
|
||||
@@ -161,7 +160,7 @@ suite('ChatEditingService', function () {
|
||||
|
||||
const uri = URI.from({ scheme: 'test', path: 'HelloWorld' });
|
||||
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None));
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat));
|
||||
const model = modelRef.object as ChatModel;
|
||||
const session = model.editingSession;
|
||||
if (!session) {
|
||||
@@ -218,7 +217,7 @@ suite('ChatEditingService', function () {
|
||||
|
||||
const uri = URI.from({ scheme: 'test', path: 'abc\n' });
|
||||
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None));
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat));
|
||||
const model = modelRef.object as ChatModel;
|
||||
const session = model.editingSession;
|
||||
assertType(session, 'session not created');
|
||||
@@ -252,7 +251,7 @@ suite('ChatEditingService', function () {
|
||||
|
||||
const uri = URI.from({ scheme: 'test', path: 'abc\n' });
|
||||
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None));
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat));
|
||||
const model = modelRef.object as ChatModel;
|
||||
const session = model.editingSession;
|
||||
assertType(session, 'session not created');
|
||||
@@ -286,7 +285,7 @@ suite('ChatEditingService', function () {
|
||||
|
||||
const uri = URI.from({ scheme: 'test', path: 'abc\n' });
|
||||
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None));
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat));
|
||||
const model = modelRef.object as ChatModel;
|
||||
const session = model.editingSession;
|
||||
assertType(session, 'session not created');
|
||||
@@ -322,7 +321,7 @@ suite('ChatEditingService', function () {
|
||||
|
||||
const modified = store.add(await textModelService.createModelReference(uri)).object.textEditorModel;
|
||||
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat, CancellationToken.None));
|
||||
const modelRef = store.add(chatService.startSession(ChatAgentLocation.Chat));
|
||||
const model = modelRef.object as ChatModel;
|
||||
const session = model.editingSession;
|
||||
assertType(session, 'session not created');
|
||||
|
||||
@@ -17,7 +17,7 @@ import { workbenchInstantiationService } from '../../../../test/browser/workbenc
|
||||
import { LocalAgentsSessionsProvider } from '../../browser/agentSessions/localAgentSessionsProvider.js';
|
||||
import { ModifiedFileEntryState } from '../../common/chatEditingService.js';
|
||||
import { IChatModel, IChatRequestModel, IChatResponseModel } from '../../common/chatModel.js';
|
||||
import { IChatDetail, IChatService } from '../../common/chatService.js';
|
||||
import { IChatDetail, IChatService, IChatSessionStartOptions } from '../../common/chatService.js';
|
||||
import { ChatSessionStatus, IChatSessionsService, localChatSessionType } from '../../common/chatSessionsService.js';
|
||||
import { LocalChatSessionUri } from '../../common/chatUri.js';
|
||||
import { ChatAgentLocation } from '../../common/constants.js';
|
||||
@@ -76,7 +76,7 @@ class MockChatService implements IChatService {
|
||||
return [];
|
||||
}
|
||||
|
||||
startSession(_location: ChatAgentLocation, _token: CancellationToken): any {
|
||||
startSession(_location: ChatAgentLocation, _options?: IChatSessionStartOptions): any {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import assert from 'assert';
|
||||
import { DeferredPromise } from '../../../../../base/common/async.js';
|
||||
import { CancellationToken } from '../../../../../base/common/cancellation.js';
|
||||
import { URI } from '../../../../../base/common/uri.js';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
|
||||
import { NullLogService } from '../../../../../platform/log/common/log.js';
|
||||
@@ -43,7 +42,6 @@ suite('ChatModelStore', () => {
|
||||
const props: IStartSessionProps = {
|
||||
sessionResource: uri,
|
||||
location: ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
canUseTools: true
|
||||
};
|
||||
|
||||
@@ -64,7 +62,6 @@ suite('ChatModelStore', () => {
|
||||
const props: IStartSessionProps = {
|
||||
sessionResource: uri,
|
||||
location: ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
canUseTools: true
|
||||
};
|
||||
|
||||
@@ -96,7 +93,6 @@ suite('ChatModelStore', () => {
|
||||
const props: IStartSessionProps = {
|
||||
sessionResource: uri,
|
||||
location: ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
canUseTools: true
|
||||
};
|
||||
|
||||
@@ -117,7 +113,6 @@ suite('ChatModelStore', () => {
|
||||
const props: IStartSessionProps = {
|
||||
sessionResource: uri,
|
||||
location: ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
canUseTools: true
|
||||
};
|
||||
|
||||
@@ -140,13 +135,11 @@ suite('ChatModelStore', () => {
|
||||
const props1: IStartSessionProps = {
|
||||
sessionResource: uri1,
|
||||
location: ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
canUseTools: true
|
||||
};
|
||||
const props2: IStartSessionProps = {
|
||||
sessionResource: uri2,
|
||||
location: ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
canUseTools: true
|
||||
};
|
||||
|
||||
@@ -170,7 +163,6 @@ suite('ChatModelStore', () => {
|
||||
const props: IStartSessionProps = {
|
||||
sessionResource: uri,
|
||||
location: ChatAgentLocation.Chat,
|
||||
token: CancellationToken.None,
|
||||
canUseTools: true
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { CancellationToken } from '../../../../../base/common/cancellation.js';
|
||||
import { Event } from '../../../../../base/common/event.js';
|
||||
import { MarkdownString } from '../../../../../base/common/htmlContent.js';
|
||||
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
|
||||
@@ -139,7 +138,7 @@ suite('ChatService', () => {
|
||||
}
|
||||
|
||||
function startSessionModel(service: IChatService, location: ChatAgentLocation = ChatAgentLocation.Chat): IChatModelReference {
|
||||
const ref = testDisposables.add(service.startSession(location, CancellationToken.None));
|
||||
const ref = testDisposables.add(service.startSession(location));
|
||||
return ref;
|
||||
}
|
||||
|
||||
@@ -207,11 +206,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, CancellationToken.None);
|
||||
const session1Ref = testService.startSession(ChatAgentLocation.Chat);
|
||||
const session1 = session1Ref.object as ChatModel;
|
||||
session1.addRequest({ parts: [], text: 'request 1' }, { variables: [] }, 0);
|
||||
|
||||
const session2Ref = testService.startSession(ChatAgentLocation.Chat, CancellationToken.None);
|
||||
const session2Ref = testService.startSession(ChatAgentLocation.Chat);
|
||||
const session2 = session2Ref.object as ChatModel;
|
||||
session2.addRequest({ parts: [], text: 'request 2' }, { variables: [] }, 0);
|
||||
|
||||
@@ -400,7 +399,7 @@ suite('ChatService', () => {
|
||||
|
||||
test('onDidDisposeSession', async () => {
|
||||
const testService = createChatService();
|
||||
const modelRef = testService.startSession(ChatAgentLocation.Chat, CancellationToken.None);
|
||||
const modelRef = testService.startSession(ChatAgentLocation.Chat);
|
||||
const model = modelRef.object;
|
||||
|
||||
let disposed = false;
|
||||
|
||||
@@ -10,7 +10,7 @@ import { IObservable, observableValue } from '../../../../../base/common/observa
|
||||
import { URI } from '../../../../../base/common/uri.js';
|
||||
import { IChatModel, IChatRequestModel, IChatRequestVariableData, ISerializableChatData } from '../../common/chatModel.js';
|
||||
import { IParsedChatRequest } from '../../common/chatParserTypes.js';
|
||||
import { IChatCompleteResponse, IChatDetail, IChatModelReference, IChatProgress, IChatProviderInfo, IChatSendRequestData, IChatSendRequestOptions, IChatService, IChatSessionContext, IChatTransferredSessionData, IChatUserActionEvent } from '../../common/chatService.js';
|
||||
import { IChatCompleteResponse, IChatDetail, IChatModelReference, IChatProgress, IChatProviderInfo, IChatSendRequestData, IChatSendRequestOptions, IChatService, IChatSessionContext, IChatSessionStartOptions, IChatTransferredSessionData, IChatUserActionEvent } from '../../common/chatService.js';
|
||||
import { ChatAgentLocation } from '../../common/constants.js';
|
||||
|
||||
export class MockChatService implements IChatService {
|
||||
@@ -33,7 +33,7 @@ export class MockChatService implements IChatService {
|
||||
getProviderInfos(): IChatProviderInfo[] {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
startSession(location: ChatAgentLocation, token: CancellationToken): IChatModelReference {
|
||||
startSession(location: ChatAgentLocation, options?: IChatSessionStartOptions): IChatModelReference {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
addSession(session: IChatModel): void {
|
||||
|
||||
@@ -1662,7 +1662,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, token);
|
||||
const chatModelRef = chatService.startSession(ChatAgentLocation.EditorInline);
|
||||
const chatModel = chatModelRef.object as ChatModel;
|
||||
|
||||
chatModel.startEditingSession(true);
|
||||
@@ -1714,7 +1714,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, token);
|
||||
const chatModelRef = chatService.startSession(ChatAgentLocation.EditorInline);
|
||||
const chatModel = chatModelRef.object as ChatModel;
|
||||
|
||||
chatModel.startEditingSession(true);
|
||||
|
||||
@@ -122,7 +122,7 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
|
||||
const store = new DisposableStore();
|
||||
this._logService.trace(`[IE] creating NEW session for ${editor.getId()}, ${agent.extensionId}`);
|
||||
|
||||
const chatModelRef = options.session ? undefined : this._chatService.startSession(ChatAgentLocation.EditorInline, token);
|
||||
const chatModelRef = options.session ? undefined : this._chatService.startSession(ChatAgentLocation.EditorInline);
|
||||
const chatModel = options.session?.chatModel ?? chatModelRef?.object;
|
||||
if (!chatModel) {
|
||||
this._logService.trace('[IE] NO chatModel found');
|
||||
@@ -343,7 +343,7 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
|
||||
|
||||
this._onWillStartSession.fire(editor as IActiveCodeEditor);
|
||||
|
||||
const chatModelRef = this._chatService.startSession(ChatAgentLocation.EditorInline, token, { canUseTools: false /* SEE https://github.com/microsoft/vscode/issues/279946 */ });
|
||||
const chatModelRef = this._chatService.startSession(ChatAgentLocation.EditorInline, { canUseTools: false /* SEE https://github.com/microsoft/vscode/issues/279946 */ });
|
||||
const chatModel = chatModelRef.object;
|
||||
chatModel.startEditingSession(false);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import { Emitter, Event } from '../../../../../base/common/event.js';
|
||||
import { DisposableStore } from '../../../../../base/common/lifecycle.js';
|
||||
import { constObservable, IObservable } from '../../../../../base/common/observable.js';
|
||||
import { assertType } from '../../../../../base/common/types.js';
|
||||
import { URI } from '../../../../../base/common/uri.js';
|
||||
import { mock } from '../../../../../base/test/common/mock.js';
|
||||
import { runWithFakedTimers } from '../../../../../base/test/common/timeTravelScheduler.js';
|
||||
import { IActiveCodeEditor, ICodeEditor } from '../../../../../editor/browser/editorBrowser.js';
|
||||
@@ -43,6 +44,7 @@ import { IWorkspaceContextService } from '../../../../../platform/workspace/comm
|
||||
import { IView, IViewDescriptorService } from '../../../../common/views.js';
|
||||
import { IWorkbenchAssignmentService } from '../../../../services/assignment/common/assignmentService.js';
|
||||
import { NullWorkbenchAssignmentService } from '../../../../services/assignment/test/common/nullAssignmentService.js';
|
||||
import { IChatEntitlementService } from '../../../../services/chat/common/chatEntitlementService.js';
|
||||
import { IExtensionService, nullExtensionDescription } from '../../../../services/extensions/common/extensions.js';
|
||||
import { TextModelResolverService } from '../../../../services/textmodelResolver/common/textModelResolverService.js';
|
||||
import { IViewsService } from '../../../../services/views/common/viewsService.js';
|
||||
@@ -50,19 +52,20 @@ import { TestViewsService, workbenchInstantiationService } from '../../../../tes
|
||||
import { TestChatEntitlementService, TestContextService, TestExtensionService } from '../../../../test/common/workbenchTestServices.js';
|
||||
import { AccessibilityVerbositySettingId } from '../../../accessibility/browser/accessibilityConfiguration.js';
|
||||
import { IChatAccessibilityService, IChatWidget, IChatWidgetService, IQuickChatService } from '../../../chat/browser/chat.js';
|
||||
import { ChatContextService, IChatContextService } from '../../../chat/browser/chatContextService.js';
|
||||
import { ChatInputBoxContentProvider } from '../../../chat/browser/chatEdinputInputContentProvider.js';
|
||||
import { ChatLayoutService } from '../../../chat/browser/chatLayoutService.js';
|
||||
import { ChatVariablesService } from '../../../chat/browser/chatVariables.js';
|
||||
import { ChatWidget } from '../../../chat/browser/chatWidget.js';
|
||||
import { ChatWidgetService } from '../../../chat/browser/chatWidgetService.js';
|
||||
import { ChatAgentService, IChatAgentData, IChatAgentNameService, IChatAgentService } from '../../../chat/common/chatAgents.js';
|
||||
import { IChatEditingService, IChatEditingSession } from '../../../chat/common/chatEditingService.js';
|
||||
import { IChatEntitlementService } from '../../../../services/chat/common/chatEntitlementService.js';
|
||||
import { IChatLayoutService } from '../../../chat/common/chatLayoutService.js';
|
||||
import { IChatModeService } from '../../../chat/common/chatModes.js';
|
||||
import { IChatTodo, IChatTodoListService } from '../../../chat/common/chatTodoListService.js';
|
||||
import { IChatProgress, IChatService } from '../../../chat/common/chatService.js';
|
||||
import { ChatService } from '../../../chat/common/chatServiceImpl.js';
|
||||
import { ChatSlashCommandService, IChatSlashCommandService } from '../../../chat/common/chatSlashCommands.js';
|
||||
import { IChatTodo, IChatTodoListService } from '../../../chat/common/chatTodoListService.js';
|
||||
import { ChatTransferService, IChatTransferService } from '../../../chat/common/chatTransferService.js';
|
||||
import { IChatVariablesService } from '../../../chat/common/chatVariables.js';
|
||||
import { IChatResponseViewModel } from '../../../chat/common/chatViewModel.js';
|
||||
@@ -83,9 +86,6 @@ import { IInlineChatSessionService } from '../../browser/inlineChatSessionServic
|
||||
import { InlineChatSessionServiceImpl } from '../../browser/inlineChatSessionServiceImpl.js';
|
||||
import { CTX_INLINE_CHAT_RESPONSE_TYPE, InlineChatConfigKeys, InlineChatResponseType } from '../../common/inlineChat.js';
|
||||
import { TestWorkerService } from './testWorkerService.js';
|
||||
import { URI } from '../../../../../base/common/uri.js';
|
||||
import { ChatWidgetService } from '../../../chat/browser/chatWidgetService.js';
|
||||
import { ChatContextService, IChatContextService } from '../../../chat/browser/chatContextService.js';
|
||||
|
||||
suite('InlineChatController', function () {
|
||||
|
||||
@@ -666,7 +666,7 @@ suite('InlineChatController', function () {
|
||||
|
||||
assert.strictEqual(model.getValue(), 'eins\nHello\nWorld\nHello Again\nHello World\n');
|
||||
|
||||
const targetModel = chatService.startSession(ChatAgentLocation.EditorInline, CancellationToken.None)!;
|
||||
const targetModel = chatService.startSession(ChatAgentLocation.EditorInline)!;
|
||||
store.add(targetModel);
|
||||
chatWidget = new class extends mock<IChatWidget>() {
|
||||
override get viewModel() {
|
||||
@@ -715,7 +715,7 @@ suite('InlineChatController', function () {
|
||||
|
||||
assert.strictEqual(model.getValue(), 'zwei\neins\nHello\nWorld\nHello Again\nHello World\n');
|
||||
|
||||
const targetModel = chatService.startSession(ChatAgentLocation.EditorInline, CancellationToken.None)!;
|
||||
const targetModel = chatService.startSession(ChatAgentLocation.EditorInline)!;
|
||||
store.add(targetModel);
|
||||
chatWidget = new class extends mock<IChatWidget>() {
|
||||
override get viewModel() {
|
||||
|
||||
@@ -327,7 +327,7 @@ export class TerminalChatWidget extends Disposable {
|
||||
private async _createSession(): Promise<void> {
|
||||
this._sessionCtor = createCancelablePromise<void>(async token => {
|
||||
if (!this._model.value) {
|
||||
const modelRef = this._chatService.startSession(ChatAgentLocation.Terminal, token);
|
||||
const modelRef = this._chatService.startSession(ChatAgentLocation.Terminal);
|
||||
this._model.value = modelRef;
|
||||
const model = modelRef.object;
|
||||
this._inlineChatWidget.setChatModel(model);
|
||||
|
||||
Reference in New Issue
Block a user