Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/intents/node/unknownIntent.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 * as l10n from '@vscode/l10n';
7
import { ChatLocation } from '../../../platform/chat/common/commonTypes';
8
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
9
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
10
import { Intent } from '../../common/constants';
11
import { GenericInlineIntentInvocation } from '../../context/node/resolvers/genericInlineIntentInvocation';
12
import { GenericPanelIntentInvocation } from '../../context/node/resolvers/genericPanelIntentInvocation';
13
import { EditStrategy } from '../../prompt/node/editGeneration';
14
import { IIntent, IIntentInvocation, IIntentInvocationContext, IIntentSlashCommandInfo } from '../../prompt/node/intents';
15
16
17
export class UnknownIntent implements IIntent {
18
19
static readonly ID = Intent.Unknown;
20
21
readonly id = UnknownIntent.ID;
22
readonly locations = [ChatLocation.Editor, ChatLocation.Panel];
23
readonly description = l10n.t('Intent of this command is unclear or is not related to information technologies');
24
readonly commandInfo: IIntentSlashCommandInfo = { hiddenFromUser: true };
25
26
constructor(
27
@IInstantiationService private readonly instantiationService: IInstantiationService,
28
@IEndpointProvider private readonly endpointProvider: IEndpointProvider,
29
) { }
30
31
async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {
32
const { location, documentContext, request } = invocationContext;
33
const endpoint = await this.endpointProvider.getChatEndpoint(request);
34
if (location === ChatLocation.Editor) {
35
if (!documentContext) {
36
throw new Error('Open a file to add code.');
37
}
38
return this.instantiationService.createInstance(GenericInlineIntentInvocation, this, location, endpoint, documentContext, EditStrategy.FallbackToReplaceRange);
39
}
40
return this.instantiationService.createInstance(GenericPanelIntentInvocation, this, location, endpoint, undefined, documentContext);
41
}
42
}
43
44