-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcopilot.ts
More file actions
67 lines (53 loc) · 1.85 KB
/
copilot.ts
File metadata and controls
67 lines (53 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { select, cancel, isCancel, outro, confirm, log, text, } from "@clack/prompts";
import { CopilotConfig } from "../../types/build/build.js";
import { getMessageInCyanColor } from "../../utils/utils.js";
export class PortalCopilotPrompts {
public async selectCopilotKey(keys: string[]): Promise<string> {
const selectedKey = await select({
message: "Select the ID for the API Copilot you would like to add to this API Portal:",
maxItems: 10,
options: keys.map((key) => ({
value: key,
label: key
}))
});
if (isCancel(selectedKey)) {
cancel("Operation cancelled.");
return process.exit(0);
}
return selectedKey;
}
public copilotConfigured(apiCopilotConfig: CopilotConfig) {
outro(
`API Copilot configured successfully!
Copilot ID: ${getMessageInCyanColor(apiCopilotConfig.key)}
Welcome Message: ${getMessageInCyanColor(apiCopilotConfig.welcomeMessage)}
Status: ${getMessageInCyanColor(apiCopilotConfig.isEnabled ? "Enabled" : "Disabled")}
Configuration saved to: APIMATIC-BUILD.json
Run 'apimatic portal:serve' to preview your API Portal and try out the API Copilot.`
);
}
public async confirmOverwrite(): Promise<boolean> {
const shouldOverwrite = await confirm({
message: "API Copilot configuration already exists. Do you want to overwrite?",
initialValue: false
});
if (isCancel(shouldOverwrite)) {
return false;
}
return shouldOverwrite;
}
logError(error: string): void {
log.error(error);
}
async getWelcomeMessage(): Promise<string | undefined> {
const welcomeMessage = await text({
message: "Enter a welcome message for your API Copilot:",
placeholder: "Enter your welcome message here..."
});
if (isCancel(welcomeMessage)) {
return undefined;
}
return welcomeMessage;
}
}