Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/intents/node/editCodeIntent2.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type * as vscode from 'vscode';
7
import { ChatLocation } from '../../../platform/chat/common/commonTypes';
8
import { IConfigurationService } from '../../../platform/configuration/common/configurationService';
9
import { modelSupportsMultiReplaceString, modelSupportsReplaceString } from '../../../platform/endpoint/common/chatModelCapabilities';
10
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
11
import { IAutomodeService } from '../../../platform/endpoint/node/automodeService';
12
import { IEnvService } from '../../../platform/env/common/envService';
13
import { ILogService } from '../../../platform/log/common/logService';
14
import { IEditLogService } from '../../../platform/multiFileEdit/common/editLogService';
15
import { IChatEndpoint } from '../../../platform/networking/common/networking';
16
import { requestHasNotebookRefs } from '../../../platform/notebook/common/helpers';
17
import { INotebookService } from '../../../platform/notebook/common/notebookService';
18
import { IOTelService } from '../../../platform/otel/common/otelService';
19
import { ISessionTranscriptService } from '../../../platform/chat/common/sessionTranscriptService';
20
import { IPromptPathRepresentationService } from '../../../platform/prompts/common/promptPathRepresentationService';
21
import { IExperimentationService } from '../../../platform/telemetry/common/nullExperimentationService';
22
import { ITelemetryService } from '../../../platform/telemetry/common/telemetry';
23
import { IWorkspaceService } from '../../../platform/workspace/common/workspaceService';
24
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
25
import { ICommandService } from '../../commands/node/commandService';
26
import { IIntent, IntentLinkificationOptions } from '../../prompt/node/intents';
27
import { ICodeMapperService } from '../../prompts/node/codeMapper/codeMapperService';
28
import { EditCodePrompt2 } from '../../prompts/node/panel/editCodePrompt2';
29
import { NotebookInlinePrompt } from '../../prompts/node/panel/notebookInlinePrompt';
30
import { ToolName } from '../../tools/common/toolNames';
31
import { IToolsService } from '../../tools/common/toolsService';
32
import { AgentIntentInvocation } from './agentIntent';
33
import { EditCodeIntentOptions } from './editCodeIntent';
34
35
const getTools = (instaService: IInstantiationService, request: vscode.ChatRequest): Promise<vscode.LanguageModelToolInformation[]> =>
36
instaService.invokeFunction(async accessor => {
37
const toolsService = accessor.get<IToolsService>(IToolsService);
38
const endpointProvider = accessor.get<IEndpointProvider>(IEndpointProvider);
39
const notebookService = accessor.get<INotebookService>(INotebookService);
40
const model = await endpointProvider.getChatEndpoint(request);
41
const lookForTools = new Set<string>([ToolName.EditFile]);
42
43
44
if (requestHasNotebookRefs(request, notebookService, { checkPromptAsWell: true })) {
45
lookForTools.add(ToolName.CreateNewJupyterNotebook);
46
}
47
48
if (modelSupportsReplaceString(model)) {
49
lookForTools.add(ToolName.ReplaceString);
50
if (modelSupportsMultiReplaceString(model)) {
51
lookForTools.add(ToolName.MultiReplaceString);
52
}
53
}
54
lookForTools.add(ToolName.EditNotebook);
55
if (requestHasNotebookRefs(request, notebookService, { checkPromptAsWell: true })) {
56
lookForTools.add(ToolName.GetNotebookSummary);
57
lookForTools.add(ToolName.RunNotebookCell);
58
}
59
60
return toolsService.getEnabledTools(request, model, tool => lookForTools.has(tool.name));
61
});
62
63
export class EditCode2IntentInvocation extends AgentIntentInvocation {
64
65
public override get linkification(): IntentLinkificationOptions {
66
return { disable: false };
67
}
68
69
protected override prompt: typeof EditCodePrompt2 | typeof NotebookInlinePrompt = EditCodePrompt2;
70
71
constructor(
72
intent: IIntent,
73
location: ChatLocation,
74
endpoint: IChatEndpoint,
75
request: vscode.ChatRequest,
76
intentOptions: EditCodeIntentOptions,
77
@IInstantiationService instantiationService: IInstantiationService,
78
@ICodeMapperService codeMapperService: ICodeMapperService,
79
@IEnvService envService: IEnvService,
80
@IPromptPathRepresentationService promptPathRepresentationService: IPromptPathRepresentationService,
81
@IEndpointProvider endpointProvider: IEndpointProvider,
82
@IWorkspaceService workspaceService: IWorkspaceService,
83
@IToolsService toolsService: IToolsService,
84
@IConfigurationService configurationService: IConfigurationService,
85
@IEditLogService editLogService: IEditLogService,
86
@ICommandService commandService: ICommandService,
87
@ITelemetryService telemetryService: ITelemetryService,
88
@INotebookService notebookService: INotebookService,
89
@ILogService logService: ILogService,
90
@IExperimentationService expService: IExperimentationService,
91
@IAutomodeService automodeService: IAutomodeService,
92
@IOTelService otelService: IOTelService,
93
@ISessionTranscriptService sessionTranscriptService: ISessionTranscriptService,
94
) {
95
super(intent, location, endpoint, request, intentOptions, instantiationService, codeMapperService, envService, promptPathRepresentationService, endpointProvider, workspaceService, toolsService, configurationService, editLogService, commandService, telemetryService, notebookService, logService, expService, automodeService, otelService, sessionTranscriptService);
96
}
97
98
public override async getAvailableTools(): Promise<vscode.LanguageModelToolInformation[]> {
99
return getTools(this.instantiationService, this.request);
100
}
101
}
102
103