Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/intents/node/terminalExplainIntent.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 type * as vscode from 'vscode';
8
import { ChatLocation } from '../../../platform/chat/common/commonTypes';
9
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';
10
import { IEnvService } from '../../../platform/env/common/envService';
11
import { IChatEndpoint } from '../../../platform/networking/common/networking';
12
import { ITerminalService } from '../../../platform/terminal/common/terminalService';
13
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
14
import { Intent } from '../../common/constants';
15
import { IBuildPromptContext } from '../../prompt/common/intents';
16
import { IIntent, IIntentInvocation, IIntentInvocationContext } from '../../prompt/node/intents';
17
import { PromptRenderer } from '../../prompts/node/base/promptRenderer';
18
import { TerminalExplainPrompt } from '../../prompts/node/panel/terminalExplain';
19
20
21
export class TerminalExplainIntent implements IIntent {
22
static readonly ID = Intent.TerminalExplain;
23
static intentName = 'explain';
24
readonly id = TerminalExplainIntent.ID;
25
readonly locations = [ChatLocation.Panel, ChatLocation.Terminal];
26
readonly description = l10n.t('Explain what just happened in the terminal');
27
readonly commandInfo = {
28
allowsEmptyArgs: true,
29
defaultEnablement: true,
30
sampleRequest: l10n.t('What did the last command do?')
31
};
32
33
constructor(
34
@IInstantiationService private readonly instantiationService: IInstantiationService,
35
@IEndpointProvider private readonly endpointProvider: IEndpointProvider,
36
) { }
37
38
async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {
39
const location = invocationContext.location;
40
const endpoint = await this.endpointProvider.getChatEndpoint(invocationContext.request);
41
return this.instantiationService.createInstance(TerminalExplainIntentInvocation, this, endpoint, location);
42
}
43
}
44
45
class TerminalExplainIntentInvocation implements IIntentInvocation {
46
47
constructor(
48
readonly intent: TerminalExplainIntent,
49
readonly endpoint: IChatEndpoint,
50
readonly location: ChatLocation,
51
@IInstantiationService private readonly instantiationService: IInstantiationService,
52
@IEnvService private readonly envService: IEnvService,
53
@ITerminalService private readonly terminalService: ITerminalService,
54
) { }
55
56
async buildPrompt(promptContext: IBuildPromptContext, progress: vscode.Progress<vscode.ChatResponseProgressPart | vscode.ChatResponseReferencePart>, token: vscode.CancellationToken) {
57
const osName = this.envService.OS;
58
const shellType = this.terminalService.terminalShellType;
59
60
const renderer = PromptRenderer.create(this.instantiationService, this.endpoint, TerminalExplainPrompt, {
61
promptContext,
62
osName,
63
shellType,
64
endpoint: this.endpoint,
65
});
66
67
const result = await renderer.render(progress, token);
68
69
return result;
70
}
71
}
72
73