diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts index 4fb6b4fbf5f..a025465c695 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts @@ -603,10 +603,15 @@ export class InlineChatController implements IEditorContribution { assertType(newEditor.hasModel()); - const newSession = await this._inlineChatSessionService.createSession(newEditor, { - editMode: this._getMode(), - chatModel: this._session.chatModel, - }, CancellationToken.None); // FIXME@ulugbekna: add cancellation + const newSession = await this._inlineChatSessionService.createSession( + newEditor, + { + editMode: this._getMode(), + chatModel: this._session.chatModel, + exchanges: this._session.exchanges, // @ulugbekna: very hacky: we pass exchanges by reference because an exchange is added only on `addRequest` event from chat model which the migrated inline chat misses + lastInput: this._session.lastInput + }, + CancellationToken.None); // TODO@ulugbekna: add proper cancellation? InlineChatController.get(newEditor)?.run({ existingSession: newSession }); diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSession.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSession.ts index 4d18fe88fce..bafa69df542 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSession.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSession.ts @@ -130,7 +130,7 @@ export class Session { private _lastInput: SessionPrompt | undefined; private _isUnstashed: boolean = false; - private readonly _exchanges: SessionExchange[] = []; + private readonly _exchanges: SessionExchange[]; private readonly _startTime = new Date(); private readonly _teldata: TelemetryData; @@ -154,6 +154,8 @@ export class Session { readonly wholeRange: SessionWholeRange, readonly hunkData: HunkData, readonly chatModel: ChatModel, + exchanges?: SessionExchange[], + lastInput?: SessionPrompt, ) { this.textModelNAltVersion = textModelN.getAlternativeVersionId(); this._teldata = { @@ -170,6 +172,8 @@ export class Session { discardedHunks: 0, responseTypes: '' }; + this._exchanges = exchanges ?? []; + this._lastInput = lastInput; } addInput(input: SessionPrompt): void { @@ -196,6 +200,10 @@ export class Session { // this._teldata.responseTypes += `${exchange.response instanceof ReplyResponse ? exchange.response.responseType : InlineChatResponseTypes.Empty}|`; } + get exchanges(): SessionExchange[] { + return this._exchanges; + } + get lastExchange(): SessionExchange | undefined { return this._exchanges[this._exchanges.length - 1]; } diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts index 1e54dcb995d..40495ad4f3d 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionService.ts @@ -12,7 +12,7 @@ import { IValidEditOperation } from 'vs/editor/common/model'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { ChatModel, IChatResponseModel } from 'vs/workbench/contrib/chat/common/chatModel'; import { EditMode } from 'vs/workbench/contrib/inlineChat/common/inlineChat'; -import { Session, StashedSession } from './inlineChatSession'; +import { Session, SessionExchange, SessionPrompt, StashedSession } from './inlineChatSession'; export type Recording = { @@ -44,7 +44,7 @@ export interface IInlineChatSessionService { onDidStashSession: Event; onDidEndSession: Event; - createSession(editor: IActiveCodeEditor, options: { editMode: EditMode; wholeRange?: IRange; chatModel?: ChatModel }, token: CancellationToken): Promise; + createSession(editor: IActiveCodeEditor, options: { editMode: EditMode; wholeRange?: IRange; chatModel?: ChatModel; exchanges?: SessionExchange[]; lastInput?: SessionPrompt }, token: CancellationToken): Promise; moveSession(session: Session, newEditor: ICodeEditor): void; diff --git a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts index 1d04ac12aa6..b29049044df 100644 --- a/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts +++ b/src/vs/workbench/contrib/inlineChat/browser/inlineChatSessionServiceImpl.ts @@ -27,7 +27,7 @@ import { IChatService } from 'vs/workbench/contrib/chat/common/chatService'; import { CTX_INLINE_CHAT_HAS_AGENT, EditMode } from 'vs/workbench/contrib/inlineChat/common/inlineChat'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; -import { EmptyResponse, ErrorResponse, HunkData, ReplyResponse, Session, SessionExchange, SessionWholeRange, StashedSession, TelemetryData, TelemetryDataClassification } from './inlineChatSession'; +import { EmptyResponse, ErrorResponse, HunkData, ReplyResponse, Session, SessionExchange, SessionPrompt, SessionWholeRange, StashedSession, TelemetryData, TelemetryDataClassification } from './inlineChatSession'; import { IInlineChatSessionEndEvent, IInlineChatSessionEvent, IInlineChatSessionService, ISessionKeyComputer, Recording } from './inlineChatSessionService'; @@ -87,7 +87,7 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService { this._sessions.clear(); } - async createSession(editor: IActiveCodeEditor, options: { editMode: EditMode; wholeRange?: Range; chatModel?: ChatModel }, token: CancellationToken): Promise { + async createSession(editor: IActiveCodeEditor, options: { editMode: EditMode; wholeRange?: Range; chatModel?: ChatModel; exchanges?: SessionExchange[]; lastInput?: SessionPrompt }, token: CancellationToken): Promise { const agent = this._chatAgentService.getDefaultAgent(ChatAgentLocation.Editor); @@ -96,7 +96,6 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService { return undefined; } - this._onWillStartSession.fire(editor); const textModel = editor.getModel(); @@ -215,7 +214,9 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService { agent, store.add(new SessionWholeRange(textModelN, wholeRange)), store.add(new HunkData(this._editorWorkerService, textModel0, textModelN)), - chatModel + chatModel, + options.exchanges, + options.lastInput ); // store: key -> session