Skip to content

Commit

Permalink
debt - remove defaultImplicitVariables from agents and remove varia…
Browse files Browse the repository at this point in the history
…ble resolvers for inline chat (editor, notebook) (microsoft#219659)
  • Loading branch information
jrieken authored and aaronchucarroll committed Jul 10, 2024
1 parent f2c9ded commit a4e6c65
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ export class ChatExtensionPointHandler implements IWorkbenchContribution {
name: providerDescriptor.name,
fullName: providerDescriptor.fullName,
isDefault: providerDescriptor.isDefault,
defaultImplicitVariables: providerDescriptor.defaultImplicitVariables,
locations: isNonEmptyArray(providerDescriptor.locations) ?
providerDescriptor.locations.map(ChatAgentLocation.fromRaw) :
[ChatAgentLocation.Panel],
Expand Down
2 changes: 0 additions & 2 deletions src/vs/workbench/contrib/chat/common/chatAgents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export interface IChatAgentData {
isDynamic?: boolean;
metadata: IChatAgentMetadata;
slashCommands: IChatAgentCommand[];
defaultImplicitVariables?: string[];
locations: ChatAgentLocation[];
}

Expand Down Expand Up @@ -397,7 +396,6 @@ export class MergedChatAgent implements IChatAgent {
get isDefault(): boolean | undefined { return this.data.isDefault; }
get metadata(): IChatAgentMetadata { return this.data.metadata; }
get slashCommands(): IChatAgentCommand[] { return this.data.slashCommands; }
get defaultImplicitVariables(): string[] | undefined { return this.data.defaultImplicitVariables; }
get locations(): ChatAgentLocation[] { return this.data.locations; }

async invoke(request: IChatAgentRequest, progress: (part: IChatProgress) => void, history: IChatAgentHistoryEntry[], token: CancellationToken): Promise<IChatAgentResult> {
Expand Down
18 changes: 1 addition & 17 deletions src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { coalesce } from 'vs/base/common/arrays';
import { DeferredPromise } from 'vs/base/common/async';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { toErrorMessage } from 'vs/base/common/errorMessage';
Expand All @@ -23,7 +22,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { ChatAgentLocation, IChatAgent, IChatAgentRequest, IChatAgentResult, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
import { ChatModel, ChatRequestModel, ChatRequestRemovalReason, ChatWelcomeMessageModel, IChatModel, IChatRequestModel, IChatRequestVariableData, IChatRequestVariableEntry, IChatResponseModel, IExportableChatData, ISerializableChatData, ISerializableChatsData, getHistoryEntriesFromModel, updateRanges } from 'vs/workbench/contrib/chat/common/chatModel';
import { ChatModel, ChatRequestModel, ChatRequestRemovalReason, ChatWelcomeMessageModel, IChatModel, IChatRequestModel, IChatRequestVariableData, IChatResponseModel, IExportableChatData, ISerializableChatData, ISerializableChatsData, getHistoryEntriesFromModel, updateRanges } from 'vs/workbench/contrib/chat/common/chatModel';
import { ChatRequestAgentPart, ChatRequestAgentSubcommandPart, ChatRequestSlashCommandPart, IParsedChatRequest, chatAgentLeader, chatSubcommandLeader, getPromptText } from 'vs/workbench/contrib/chat/common/chatParserTypes';
import { ChatRequestParser } from 'vs/workbench/contrib/chat/common/chatRequestParser';
import { IChatCompleteResponse, IChatDetail, IChatFollowup, IChatProgress, IChatSendRequestData, IChatSendRequestOptions, IChatSendRequestResponseState, IChatService, IChatTransferredSessionData, IChatUserActionEvent } from 'vs/workbench/contrib/chat/common/chatService';
Expand Down Expand Up @@ -485,21 +484,6 @@ export class ChatService extends Disposable implements IChatService {
const promptTextResult = getPromptText(request.message);
const updatedVariableData = updateRanges(variableData, promptTextResult.diff); // TODO bit of a hack

// TODO- should figure out how to get rid of implicit variables for inline chat
const implicitVariablesEnabled = (location === ChatAgentLocation.Editor || location === ChatAgentLocation.Notebook);
if (implicitVariablesEnabled) {
const implicitVariables = agent.defaultImplicitVariables;
if (implicitVariables) {
const resolvedImplicitVariables = await Promise.all(implicitVariables.map(async v => {
const id = this.chatVariablesService.getVariable(v)?.id ?? '';
const value = await this.chatVariablesService.resolveVariable(v, parsedRequest.text, model, progressCallback, token);
return value ? { id, name: v, value } satisfies IChatRequestVariableEntry :
undefined;
}));
updatedVariableData.variables.push(...coalesce(resolvedImplicitVariables));
}
}

const requestProps: IChatAgentRequest = {
sessionId,
requestId: request.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
import { IActiveCodeEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IRange, Range } from 'vs/editor/common/core/range';
import { Range } from 'vs/editor/common/core/range';
import { IValidEditOperation } from 'vs/editor/common/model';
import { createTextBufferFactoryFromSnapshot } from 'vs/editor/common/model/textModel';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker';
Expand All @@ -27,8 +27,6 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput';
import { EmptyResponse, ErrorResponse, HunkData, ReplyResponse, Session, SessionExchange, SessionWholeRange, StashedSession, TelemetryData, TelemetryDataClassification } from './inlineChatSession';
import { IInlineChatSessionEndEvent, IInlineChatSessionEvent, IInlineChatSessionService, ISessionKeyComputer, Recording } from './inlineChatSessionService';
import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVariables';
import { ISelection } from 'vs/editor/common/core/selection';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';


Expand All @@ -46,19 +44,6 @@ export class InlineChatError extends Error {
}
}

const _inlineChatContext = '_inlineChatContext';
const _inlineChatDocument = '_inlineChatDocument';

class InlineChatContext {

static readonly variableName = '_inlineChatContext';

constructor(
readonly uri: URI,
readonly selection: ISelection,
readonly wholeRange: IRange,
) { }
}

export class InlineChatSessionServiceImpl implements IInlineChatSessionService {

Expand Down Expand Up @@ -92,37 +77,8 @@ export class InlineChatSessionServiceImpl implements IInlineChatSessionService {
@IInstantiationService private readonly _instaService: IInstantiationService,
@IEditorService private readonly _editorService: IEditorService,
@IChatService private readonly _chatService: IChatService,
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
@IChatVariablesService chatVariableService: IChatVariablesService,
) {


// MARK: implicit variable for editor selection and (tracked) whole range

this._store.add(chatVariableService.registerVariable(
{ id: _inlineChatContext, name: _inlineChatContext, description: '', hidden: true },
async (_message, _arg, model) => {
for (const [, data] of this._sessions) {
if (data.session.chatModel === model) {
return JSON.stringify(new InlineChatContext(data.session.textModelN.uri, data.editor.getSelection()!, data.session.wholeRange.trackedInitialRange));
}
}
return undefined;
}
));
this._store.add(chatVariableService.registerVariable(
{ id: _inlineChatDocument, name: _inlineChatDocument, description: '', hidden: true },
async (_message, _arg, model) => {
for (const [, data] of this._sessions) {
if (data.session.chatModel === model) {
return data.session.textModelN.uri;
}
}
return undefined;
}
));

}
@IChatAgentService private readonly _chatAgentService: IChatAgentService
) { }

dispose() {
this._store.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from 'vs/workbench/common/contributions';
import { ChatAgentLocation, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
import { IChatVariablesService } from 'vs/workbench/contrib/chat/common/chatVariables';
import 'vs/workbench/contrib/notebook/browser/controller/chat/cellChatActions';
import { CTX_NOTEBOOK_CHAT_HAS_AGENT } from 'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatContext';
import { NotebookChatController } from 'vs/workbench/contrib/notebook/browser/controller/chat/notebookChatController';
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/services/notebookEditorService';

class NotebookChatContribution extends Disposable implements IWorkbenchContribution {

Expand All @@ -20,28 +17,11 @@ class NotebookChatContribution extends Disposable implements IWorkbenchContribut
private readonly _ctxHasProvider: IContextKey<boolean>;

constructor(
@IChatVariablesService private readonly _chatVariableService: IChatVariablesService,
@INotebookEditorService private readonly _notebookEditorService: INotebookEditorService,
@IContextKeyService contextKeyService: IContextKeyService,
@IChatAgentService chatAgentService: IChatAgentService
) {
super();

this._register(this._chatVariableService.registerVariable(
{ id: '_notebookChatInput', name: '_notebookChatInput', description: '', hidden: true },
async (_message, _arg, model) => {
const editors = this._notebookEditorService.listNotebookEditors();
for (const editor of editors) {
const chatController = editor.getContribution(NotebookChatController.id) as NotebookChatController | undefined;
if (chatController?.hasSession(model)) {
return chatController.getSessionInputUri();
}
}

return undefined;
}
));

this._ctxHasProvider = CTX_NOTEBOOK_CHAT_HAS_AGENT.bindTo(contextKeyService);

const updateNotebookAgentStatus = () => {
Expand Down

0 comments on commit a4e6c65

Please sign in to comment.