Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompts/node/base/capabilities.tsx
13405 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 { BasePromptElementProps, PromptElement } from '@vscode/prompt-tsx';
7
import { ChatLocation } from '../../../../platform/chat/common/commonTypes';
8
import { ICommandService } from '../../../commands/node/commandService';
9
import { agentsToCommands } from '../../../common/constants';
10
import { IPromptEndpoint } from './promptRenderer';
11
12
export interface CapabilitiesProps extends BasePromptElementProps {
13
location: ChatLocation;
14
}
15
16
export interface CapabilitiesState {
17
commandDescriptions: string;
18
modelName: string;
19
}
20
21
export class Capabilities extends PromptElement<CapabilitiesProps, CapabilitiesState> {
22
23
constructor(
24
props: CapabilitiesProps,
25
@ICommandService private readonly commandService: ICommandService,
26
@IPromptEndpoint private readonly promptEndpoint: IPromptEndpoint
27
) {
28
super(props);
29
}
30
31
private getIntentDescription(id: string) {
32
const intent = this.commandService.getCommand(id, this.props.location)?.intent;
33
return !intent || intent.isListedCapability === false ? undefined : intent.description;
34
}
35
36
override async prepare() {
37
38
const seen = new Set<string>();
39
40
const commandDescriptions = Object.entries(agentsToCommands).reduce((prev, [agent, commands]) => {
41
const intent = this.getIntentDescription(agent);
42
if (intent && seen.has(intent)) {
43
return prev;
44
}
45
if (intent) {
46
seen.has(intent);
47
prev += `\n* ${intent}`;
48
}
49
for (const command of Object.values(commands)) {
50
const commandDescription = this.getIntentDescription(command);
51
if (commandDescription) {
52
prev += `\n* ${commandDescription}`;
53
}
54
}
55
return prev;
56
}, '');
57
58
return {
59
modelName: this.promptEndpoint.name,
60
commandDescriptions,
61
};
62
}
63
64
render(state: CapabilitiesState) {
65
return (
66
<>
67
You can answer general programming questions and perform the following tasks: {state.commandDescriptions}
68
<br />
69
You use the {state.modelName} large language model.
70
</>
71
);
72
}
73
}
74
75