Path: blob/main/extensions/copilot/src/extension/intents/node/terminalIntent.ts
13399 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/456import * as l10n from '@vscode/l10n';7import type * as vscode from 'vscode';8import { ChatLocation } from '../../../platform/chat/common/commonTypes';9import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider';10import { IEnvService } from '../../../platform/env/common/envService';11import { IChatEndpoint } from '../../../platform/networking/common/networking';12import { ITerminalService } from '../../../platform/terminal/common/terminalService';13import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';14import { Intent } from '../../common/constants';15import { IBuildPromptContext } from '../../prompt/common/intents';16import { IIntent, IIntentInvocation, IIntentInvocationContext, IIntentSlashCommandInfo } from '../../prompt/node/intents';17import { PromptRenderer } from '../../prompts/node/base/promptRenderer';18import { TerminalPrompt } from '../../prompts/node/panel/terminal';192021export class TerminalIntent implements IIntent {22static readonly ID = Intent.Terminal;23readonly locations = [ChatLocation.Panel, ChatLocation.Terminal];24readonly id = TerminalIntent.ID;25readonly description = l10n.t('Ask how to do something in the terminal');26readonly commandInfo: IIntentSlashCommandInfo = {27allowsEmptyArgs: false28};2930constructor(31@IInstantiationService private readonly instantiationService: IInstantiationService,32@IEndpointProvider private readonly endpointProvider: IEndpointProvider,33) { }3435async invoke(invocationContext: IIntentInvocationContext): Promise<IIntentInvocation> {36const location = invocationContext.location;37const endpoint = await this.endpointProvider.getChatEndpoint(invocationContext.request);38return this.instantiationService.createInstance(TerminalIntentInvocation, this, endpoint, location);39}40}4142class TerminalIntentInvocation implements IIntentInvocation {4344constructor(45readonly intent: TerminalIntent,46readonly endpoint: IChatEndpoint,47readonly location: ChatLocation,48@IInstantiationService private readonly instantiationService: IInstantiationService,49@IEnvService private readonly envService: IEnvService,50@ITerminalService private readonly terminalService: ITerminalService,51) { }5253async buildPrompt(promptContext: IBuildPromptContext, progress: vscode.Progress<vscode.ChatResponseProgressPart | vscode.ChatResponseReferencePart>, token: vscode.CancellationToken) {54const osName = this.envService.OS;55const shellType = this.terminalService.terminalShellType;5657const renderer = PromptRenderer.create(this.instantiationService, this.endpoint, TerminalPrompt, {58promptContext,59osName,60shellType,61endpoint: this.endpoint62});6364const result = await renderer.render(progress, token);6566return result;67}68}697071