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