@botpress/cli 1.7.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +11 -9
- package/dist/api/bot-body.js +20 -6
- package/dist/api/bot-body.js.map +2 -2
- package/dist/api/client.js +18 -0
- package/dist/api/client.js.map +2 -2
- package/dist/api/interface-body.js.map +2 -2
- package/dist/api/plugin-body.js +79 -0
- package/dist/api/plugin-body.js.map +7 -0
- package/dist/api/types.js.map +1 -1
- package/dist/code-generation/bot-implementation/bot-implementation.js +40 -21
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-plugins/index.js +76 -0
- package/dist/code-generation/bot-implementation/bot-plugins/index.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js +125 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/index.js +27 -22
- package/dist/code-generation/bot-implementation/index.js.map +2 -2
- package/dist/code-generation/consts.js +3 -0
- package/dist/code-generation/consts.js.map +2 -2
- package/dist/code-generation/generators.js +8 -0
- package/dist/code-generation/generators.js.map +2 -2
- package/dist/code-generation/index.js +6 -0
- package/dist/code-generation/index.js.map +2 -2
- package/dist/code-generation/integration-package/index.js +11 -2
- package/dist/code-generation/integration-package/index.js.map +2 -2
- package/dist/code-generation/interface-implementation/index.js +29 -0
- package/dist/code-generation/interface-implementation/index.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/actions-module.js +84 -0
- package/dist/code-generation/interface-implementation/integration-typings/actions-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/channels-module.js +103 -0
- package/dist/code-generation/interface-implementation/integration-typings/channels-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/entities-module.js +59 -0
- package/dist/code-generation/interface-implementation/integration-typings/entities-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/events-module.js +59 -0
- package/dist/code-generation/interface-implementation/integration-typings/events-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/index.js +117 -0
- package/dist/code-generation/interface-implementation/integration-typings/index.js.map +7 -0
- package/dist/code-generation/interface-package/index.js +11 -2
- package/dist/code-generation/interface-package/index.js.map +2 -2
- package/dist/code-generation/module.js +17 -4
- package/dist/code-generation/module.js.map +2 -2
- package/dist/code-generation/plugin-implementation/index.js +56 -0
- package/dist/code-generation/plugin-implementation/index.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.js +86 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/actions-module.js +84 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/actions-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/configuration-module.js +57 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/configuration-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/events-module.js +59 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/events-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js +146 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/states-module.js +60 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/states-module.js.map +7 -0
- package/dist/code-generation/plugin-package/index.js +146 -0
- package/dist/code-generation/plugin-package/index.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js +84 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js +52 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js +62 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js +103 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js +62 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.js +17 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.js.map +7 -0
- package/dist/code-generation/typings.js.map +1 -1
- package/dist/command-definitions.js +8 -0
- package/dist/command-definitions.js.map +2 -2
- package/dist/command-implementations/add-command.js +47 -10
- package/dist/command-implementations/add-command.js.map +2 -2
- package/dist/command-implementations/bundle-command.js +7 -2
- package/dist/command-implementations/bundle-command.js.map +2 -2
- package/dist/command-implementations/deploy-command.js +51 -0
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/gen-command.js +11 -0
- package/dist/command-implementations/gen-command.js.map +2 -2
- package/dist/command-implementations/index.js +8 -0
- package/dist/command-implementations/index.js.map +2 -2
- package/dist/command-implementations/init-command.js +36 -8
- package/dist/command-implementations/init-command.js.map +2 -2
- package/dist/command-implementations/lint-command.js +1 -1
- package/dist/command-implementations/lint-command.js.map +2 -2
- package/dist/command-implementations/plugin-commands.js +107 -0
- package/dist/command-implementations/plugin-commands.js.map +7 -0
- package/dist/command-implementations/project-command.js +30 -3
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/command-implementations/read-command.js +13 -1
- package/dist/command-implementations/read-command.js.map +2 -2
- package/dist/config.js +23 -2
- package/dist/config.js.map +2 -2
- package/dist/consts.js +7 -0
- package/dist/consts.js.map +2 -2
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/index.js.map +2 -2
- package/dist/sdk/resolve-bot-interfaces.js +6 -1
- package/dist/sdk/resolve-bot-interfaces.js.map +2 -2
- package/dist/sdk/resolve-integration-interfaces.js +16 -8
- package/dist/sdk/resolve-integration-interfaces.js.map +2 -2
- package/dist/sdk/validate-bot.js +84 -0
- package/dist/sdk/validate-bot.js.map +7 -0
- package/dist/utils/esbuild-utils.js +3 -2
- package/dist/utils/esbuild-utils.js.map +2 -2
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/object-utils.js +32 -0
- package/dist/utils/object-utils.js.map +7 -0
- package/dist/utils/schema-utils.js.map +2 -2
- package/dist/utils/type-utils.js.map +1 -1
- package/e2e/tests/install-package.ts +1 -1
- package/package.json +3 -3
- package/templates/empty-bot/.botpress/implementation/index.ts +27 -18
- package/templates/empty-bot/.botpress/implementation/plugins/index.ts +11 -0
- package/templates/empty-bot/.botpress/index.ts +5 -1
- package/templates/empty-bot/package.json +2 -2
- package/templates/empty-integration/package.json +2 -2
- package/templates/empty-plugin/.botpress/implementation/index.ts +35 -0
- package/templates/empty-plugin/.botpress/implementation/typings/actions/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/empty-plugin/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/index.ts +26 -0
- package/templates/empty-plugin/.botpress/implementation/typings/integrations/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/interfaces/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/empty-plugin/.botpress/index.ts +1 -0
- package/templates/empty-plugin/package.json +16 -0
- package/templates/empty-plugin/plugin.definition.ts +7 -0
- package/templates/empty-plugin/src/index.ts +7 -0
- package/templates/empty-plugin/tsconfig.json +28 -0
- package/templates/hello-world/package.json +2 -2
- package/templates/webhook-message/package.json +2 -2
|
@@ -34,12 +34,13 @@ var consts = __toESM(require("../consts"));
|
|
|
34
34
|
var errors = __toESM(require("../errors"));
|
|
35
35
|
var utils = __toESM(require("../utils"));
|
|
36
36
|
var import_global_command = require("./global-command");
|
|
37
|
+
const projectTypes = ["bot", "integration", "plugin"];
|
|
37
38
|
class InitCommand extends import_global_command.GlobalCommand {
|
|
38
39
|
async run() {
|
|
39
40
|
let { type: projectType } = this.argv;
|
|
40
41
|
if (!projectType) {
|
|
41
42
|
const promptedType = await this.prompt.select("What type of project do you wish to initialize?", {
|
|
42
|
-
choices:
|
|
43
|
+
choices: projectTypes.map((t) => ({ title: t, value: t }))
|
|
43
44
|
});
|
|
44
45
|
if (!promptedType) {
|
|
45
46
|
throw new errors.ParamRequiredError("Project Type");
|
|
@@ -51,13 +52,33 @@ class InitCommand extends import_global_command.GlobalCommand {
|
|
|
51
52
|
await this._initBot({ workDir });
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
if (projectType === "integration") {
|
|
56
|
+
await this._initIntegration({ workDir });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (projectType === "plugin") {
|
|
60
|
+
await this._initPlugin({ workDir });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
throw new errors.BotpressCLIError(`Unknown project type: ${projectType}`);
|
|
56
64
|
}
|
|
65
|
+
_initPlugin = async (args) => {
|
|
66
|
+
const { workDir } = args;
|
|
67
|
+
const name = await this._getName("plugin", consts.emptyPluginDirName);
|
|
68
|
+
await this._copy({
|
|
69
|
+
srcDir: this.globalPaths.abs.emptyPluginTemplate,
|
|
70
|
+
destDir: workDir,
|
|
71
|
+
name,
|
|
72
|
+
pkgJson: {
|
|
73
|
+
pluginName: name
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
this.logger.success(`Plugin project initialized in ${import_chalk.default.bold(workDir)}`);
|
|
77
|
+
};
|
|
57
78
|
_initBot = async (args) => {
|
|
58
79
|
const { workDir } = args;
|
|
59
80
|
const name = await this._getName("bot", consts.emptyBotDirName);
|
|
60
|
-
await this._copy({ srcDir: this.globalPaths.abs.emptyBotTemplate, destDir: workDir, name });
|
|
81
|
+
await this._copy({ srcDir: this.globalPaths.abs.emptyBotTemplate, destDir: workDir, name, pkgJson: {} });
|
|
61
82
|
this.logger.success(`Bot project initialized in ${import_chalk.default.bold(workDir)}`);
|
|
62
83
|
};
|
|
63
84
|
_initIntegration = async (args) => {
|
|
@@ -79,7 +100,14 @@ class InitCommand extends import_global_command.GlobalCommand {
|
|
|
79
100
|
srcDirPath = this.globalPaths.abs.emptyIntegrationTemplate;
|
|
80
101
|
}
|
|
81
102
|
const name = await this._getName("integration", template ?? consts.emptyIntegrationDirName);
|
|
82
|
-
await this._copy({
|
|
103
|
+
await this._copy({
|
|
104
|
+
srcDir: srcDirPath,
|
|
105
|
+
destDir: workDir,
|
|
106
|
+
name,
|
|
107
|
+
pkgJson: {
|
|
108
|
+
integrationName: name
|
|
109
|
+
}
|
|
110
|
+
});
|
|
83
111
|
this.logger.success(`Integration project initialized in ${import_chalk.default.bold(this.argv.workDir)}`);
|
|
84
112
|
return;
|
|
85
113
|
};
|
|
@@ -95,7 +123,7 @@ class InitCommand extends import_global_command.GlobalCommand {
|
|
|
95
123
|
return promptedName;
|
|
96
124
|
};
|
|
97
125
|
_copy = async (props) => {
|
|
98
|
-
const { srcDir, destDir, name } = props;
|
|
126
|
+
const { srcDir, destDir, name, pkgJson } = props;
|
|
99
127
|
const dirName = utils.casing.to.kebabCase(name);
|
|
100
128
|
const destination = pathlib.join(destDir, dirName);
|
|
101
129
|
const exist = await this._checkIfDestinationExists(destination);
|
|
@@ -105,9 +133,9 @@ class InitCommand extends import_global_command.GlobalCommand {
|
|
|
105
133
|
await fs.promises.cp(srcDir, destination, { recursive: true });
|
|
106
134
|
const pkgJsonPath = pathlib.join(destination, "package.json");
|
|
107
135
|
const strContent = await fs.promises.readFile(pkgJsonPath, "utf-8");
|
|
108
|
-
const
|
|
136
|
+
const json = JSON.parse(strContent);
|
|
109
137
|
const pkgJsonName = utils.casing.to.snakeCase(name);
|
|
110
|
-
const updatedJson = { name: pkgJsonName,
|
|
138
|
+
const updatedJson = { name: pkgJsonName, ...json, ...pkgJson };
|
|
111
139
|
await fs.promises.writeFile(pkgJsonPath, JSON.stringify(updatedJson, null, 2));
|
|
112
140
|
};
|
|
113
141
|
_checkIfDestinationExists = async (destination) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/init-command.ts"],
|
|
4
|
-
"sourcesContent": ["import chalk from 'chalk'\nimport * as fs from 'fs'\nimport * as pathlib from 'path'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,SAAoB;AACpB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;
|
|
4
|
+
"sourcesContent": ["import chalk from 'chalk'\nimport * as fs from 'fs'\nimport * as pathlib from 'path'\nimport type commandDefinitions from '../command-definitions'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nconst projectTypes = ['bot', 'integration', 'plugin'] as const\ntype ProjectType = (typeof projectTypes)[number]\n\ntype CopyProps = { srcDir: string; destDir: string; name: string; pkgJson: Record<string, unknown> }\n\nexport type InitCommandDefinition = typeof commandDefinitions.init\nexport class InitCommand extends GlobalCommand<InitCommandDefinition> {\n public async run(): Promise<void> {\n let { type: projectType } = this.argv\n\n if (!projectType) {\n const promptedType = await this.prompt.select('What type of project do you wish to initialize?', {\n choices: projectTypes.map((t) => ({ title: t, value: t })),\n })\n\n if (!promptedType) {\n throw new errors.ParamRequiredError('Project Type')\n }\n\n projectType = promptedType\n }\n\n const workDir = utils.path.absoluteFrom(utils.path.cwd(), this.argv.workDir)\n\n if (projectType === 'bot') {\n await this._initBot({ workDir })\n return\n }\n\n if (projectType === 'integration') {\n await this._initIntegration({ workDir })\n return\n }\n\n if (projectType === 'plugin') {\n await this._initPlugin({ workDir })\n return\n }\n\n type _assertion = utils.types.AssertNever<typeof projectType>\n throw new errors.BotpressCLIError(`Unknown project type: ${projectType}`)\n }\n\n private _initPlugin = async (args: { workDir: string }) => {\n const { workDir } = args\n const name = await this._getName('plugin', consts.emptyPluginDirName)\n await this._copy({\n srcDir: this.globalPaths.abs.emptyPluginTemplate,\n destDir: workDir,\n name,\n pkgJson: {\n pluginName: name,\n },\n })\n this.logger.success(`Plugin project initialized in ${chalk.bold(workDir)}`)\n }\n\n private _initBot = async (args: { workDir: string }) => {\n const { workDir } = args\n const name = await this._getName('bot', consts.emptyBotDirName)\n await this._copy({ srcDir: this.globalPaths.abs.emptyBotTemplate, destDir: workDir, name, pkgJson: {} })\n this.logger.success(`Bot project initialized in ${chalk.bold(workDir)}`)\n }\n\n private _initIntegration = async (args: { workDir: string }) => {\n const { workDir } = args\n\n const template = await this.prompt.select('Which template do you want to use?', {\n choices: [\n { title: 'Empty Integration', value: consts.emptyIntegrationDirName },\n { title: 'Hello World', value: consts.helloWorldIntegrationDirName },\n { title: 'Webhook Message', value: consts.webhookMessageIntegrationDirName },\n ],\n default: consts.emptyIntegrationDirName,\n })\n\n let srcDirPath: string\n if (template === consts.helloWorldIntegrationDirName) {\n srcDirPath = this.globalPaths.abs.helloWorldIntegrationTemplate\n } else if (template === consts.webhookMessageIntegrationDirName) {\n srcDirPath = this.globalPaths.abs.webhookMessageIntegrationTemplate\n } else {\n srcDirPath = this.globalPaths.abs.emptyIntegrationTemplate\n }\n\n const name = await this._getName('integration', template ?? consts.emptyIntegrationDirName)\n\n await this._copy({\n srcDir: srcDirPath,\n destDir: workDir,\n name,\n pkgJson: {\n integrationName: name,\n },\n })\n this.logger.success(`Integration project initialized in ${chalk.bold(this.argv.workDir)}`)\n return\n }\n\n private _getName = async (projectType: ProjectType, defaultName: string): Promise<string> => {\n if (this.argv.name) {\n return this.argv.name\n }\n const promptMessage = `What is the name of your ${projectType}?`\n const promptedName = await this.prompt.text(promptMessage, { initial: defaultName })\n if (!promptedName) {\n throw new errors.ParamRequiredError('Project Name')\n }\n return promptedName\n }\n\n private _copy = async (props: CopyProps) => {\n const { srcDir, destDir, name, pkgJson } = props\n\n const dirName = utils.casing.to.kebabCase(name)\n const destination = pathlib.join(destDir, dirName)\n\n const exist = await this._checkIfDestinationExists(destination)\n if (exist) {\n return\n }\n\n await fs.promises.cp(srcDir, destination, { recursive: true })\n\n const pkgJsonPath = pathlib.join(destination, 'package.json')\n const strContent = await fs.promises.readFile(pkgJsonPath, 'utf-8')\n const json = JSON.parse(strContent)\n\n const pkgJsonName = utils.casing.to.snakeCase(name)\n const updatedJson = { name: pkgJsonName, ...json, ...pkgJson }\n await fs.promises.writeFile(pkgJsonPath, JSON.stringify(updatedJson, null, 2))\n }\n\n private _checkIfDestinationExists = async (destination: string) => {\n if (fs.existsSync(destination)) {\n const override = await this.prompt.confirm(\n `Directory ${chalk.bold(destination)} already exists. Do you want to overwrite it?`\n )\n if (!override) {\n this.logger.log('Aborting')\n return true\n }\n }\n return false\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,SAAoB;AACpB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,4BAA8B;AAE9B,MAAM,eAAe,CAAC,OAAO,eAAe,QAAQ;AAM7C,MAAM,oBAAoB,oCAAqC;AAAA,EACpE,MAAa,MAAqB;AAChC,QAAI,EAAE,MAAM,YAAY,IAAI,KAAK;AAEjC,QAAI,CAAC,aAAa;AAChB,YAAM,eAAe,MAAM,KAAK,OAAO,OAAO,mDAAmD;AAAA,QAC/F,SAAS,aAAa,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,EAAE,EAAE;AAAA,MAC3D,CAAC;AAED,UAAI,CAAC,cAAc;AACjB,cAAM,IAAI,OAAO,mBAAmB,cAAc;AAAA,MACpD;AAEA,oBAAc;AAAA,IAChB;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;AAEA,UAAM,GAAG,SAAS,GAAG,QAAQ,aAAa,EAAE,WAAW,KAAK,CAAC;AAE7D,UAAM,cAAc,QAAQ,KAAK,aAAa,cAAc;AAC5D,UAAM,aAAa,MAAM,GAAG,SAAS,SAAS,aAAa,OAAO;AAClE,UAAM,OAAO,KAAK,MAAM,UAAU;AAElC,UAAM,cAAc,MAAM,OAAO,GAAG,UAAU,IAAI;AAClD,UAAM,cAAc,EAAE,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ;AAC7D,UAAM,GAAG,SAAS,UAAU,aAAa,KAAK,UAAU,aAAa,MAAM,CAAC,CAAC;AAAA,EAC/E;AAAA,EAEQ,4BAA4B,OAAO,gBAAwB;AACjE,QAAI,GAAG,WAAW,WAAW,GAAG;AAC9B,YAAM,WAAW,MAAM,KAAK,OAAO;AAAA,QACjC,aAAa,aAAAA,QAAM,KAAK,WAAW;AAAA,MACrC;AACA,UAAI,CAAC,UAAU;AACb,aAAK,OAAO,IAAI,UAAU;AAC1B,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["chalk"]
|
|
7
7
|
}
|
|
@@ -53,7 +53,7 @@ class LintCommand extends import_project_command.ProjectCommand {
|
|
|
53
53
|
case "interface":
|
|
54
54
|
return this._runLintForInterface(projectDef.definition);
|
|
55
55
|
default:
|
|
56
|
-
throw new errors.
|
|
56
|
+
throw new errors.UnsupportedProjectType();
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
async _runLintForInterface(definition) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/lint-command.ts"],
|
|
4
|
-
"sourcesContent": ["import { type IntegrationDefinition, type BotDefinition, type
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqC;AACrC,8BAA6C;AAC7C,4BAA2C;AAE3C,aAAwB;AACxB,wBAA0B;AAC1B,gCAAkC;AAClC,8BAAgC;AAChC,IAAAA,cAA4C;AAC5C,6BAA+B;AAGxB,MAAM,oBAAoB,sCAAsC;AAAA,EACrE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAC1D,QAAI,WAAW,gBAAgB;AAC7B,WAAK,OAAO;AAAA,QACV;AAAA,MACF;AACA;AAAA,IACF;AAEA,YAAQ,WAAW,MAAM;AAAA,MACvB,KAAK;AACH,eAAO,KAAK,uBAAuB,WAAW,UAAU;AAAA,MAC1D,KAAK;AACH,eAAO,KAAK,eAAe,WAAW,UAAU;AAAA,MAClD,KAAK;AACH,eAAO,KAAK,qBAAqB,WAAW,UAAU;AAAA,MACxD;AACE,cAAM,IAAI,OAAO,
|
|
4
|
+
"sourcesContent": ["import { type IntegrationDefinition, type BotDefinition, type InterfaceDefinition } from '@botpress/sdk'\nimport { prepareCreateBotBody } from '../api/bot-body'\nimport { prepareCreateIntegrationBody } from '../api/integration-body'\nimport { prepareCreateInterfaceBody } from '../api/interface-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { BotLinter } from '../linter/bot-linter'\nimport { IntegrationLinter } from '../linter/integration-linter'\nimport { InterfaceLinter } from '../linter/interface-linter'\nimport { getImplementationStatements } from '../sdk'\nimport { ProjectCommand } from './project-command'\n\nexport type LintCommandDefinition = typeof commandDefinitions.lint\nexport class LintCommand extends ProjectCommand<LintCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.bpLintDisabled) {\n this.logger.warn(\n 'Linting is disabled for this project because of a bplint directive. To enable linting, remove the \"bplint-disable\" directive from the project definition file'\n )\n return\n }\n\n switch (projectDef.type) {\n case 'integration':\n return this._runLintForIntegration(projectDef.definition)\n case 'bot':\n return this._runLintForBot(projectDef.definition)\n case 'interface':\n return this._runLintForInterface(projectDef.definition)\n default:\n throw new errors.UnsupportedProjectType()\n }\n }\n\n private async _runLintForInterface(definition: InterfaceDefinition): Promise<void> {\n const parsedInterfaceDefinition = await prepareCreateInterfaceBody(definition)\n const linter = new InterfaceLinter(parsedInterfaceDefinition)\n\n await linter.lint()\n linter.logResults(this.logger)\n\n if (linter.hasErrors()) {\n throw new errors.BotpressCLIError('Interface definition contains linting errors')\n }\n\n this.logger.success('Interface definition is valid')\n }\n\n private async _runLintForBot(definition: BotDefinition): Promise<void> {\n const strippedDefinition = this._stripAutoGeneratedContentFromBot(definition)\n const parsedBotDefinition = await prepareCreateBotBody(strippedDefinition)\n const linter = new BotLinter(parsedBotDefinition)\n\n await linter.lint()\n linter.logResults(this.logger)\n\n if (linter.hasErrors()) {\n throw new errors.BotpressCLIError('Bot definition contains linting errors')\n }\n\n this.logger.success('Bot definition is valid')\n }\n\n private _stripAutoGeneratedContentFromBot(definition: BotDefinition) {\n return {\n ...definition,\n integrations: {},\n } as BotDefinition\n }\n\n private async _runLintForIntegration(definition: IntegrationDefinition): Promise<void> {\n const strippedDefinition = this._stripAutoGeneratedContentFromIntegration(definition)\n const parsedIntegrationDefinition = await prepareCreateIntegrationBody(strippedDefinition)\n const linter = new IntegrationLinter({ ...parsedIntegrationDefinition, secrets: strippedDefinition.secrets })\n\n await linter.lint()\n linter.logResults(this.logger)\n\n if (linter.hasErrors()) {\n throw new errors.BotpressCLIError('Integration definition contains linting errors')\n }\n\n this.logger.success('Integration definition is valid')\n }\n\n private _stripAutoGeneratedContentFromIntegration(definition: IntegrationDefinition) {\n const { actionNames, eventNames } = this._getAutoGeneratedContentOfIntegration(definition)\n\n return {\n ...definition,\n actions: Object.fromEntries(Object.entries(definition.actions ?? {}).filter(([key]) => !actionNames.has(key))),\n events: Object.fromEntries(Object.entries(definition.events ?? {}).filter(([key]) => !eventNames.has(key))),\n } as IntegrationDefinition\n }\n\n private _getAutoGeneratedContentOfIntegration(definition: IntegrationDefinition) {\n const actionNames = new Set<string>()\n const eventNames = new Set<string>()\n\n const interfacesStatements = getImplementationStatements(definition)\n for (const iface of Object.values(interfacesStatements)) {\n for (const actionDefinition of Object.values(iface.actions)) {\n actionNames.add(actionDefinition.name)\n }\n for (const eventDefinition of Object.values(iface.events)) {\n eventNames.add(eventDefinition.name)\n }\n }\n\n return { actionNames, eventNames } as const\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAqC;AACrC,8BAA6C;AAC7C,4BAA2C;AAE3C,aAAwB;AACxB,wBAA0B;AAC1B,gCAAkC;AAClC,8BAAgC;AAChC,IAAAA,cAA4C;AAC5C,6BAA+B;AAGxB,MAAM,oBAAoB,sCAAsC;AAAA,EACrE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAC1D,QAAI,WAAW,gBAAgB;AAC7B,WAAK,OAAO;AAAA,QACV;AAAA,MACF;AACA;AAAA,IACF;AAEA,YAAQ,WAAW,MAAM;AAAA,MACvB,KAAK;AACH,eAAO,KAAK,uBAAuB,WAAW,UAAU;AAAA,MAC1D,KAAK;AACH,eAAO,KAAK,eAAe,WAAW,UAAU;AAAA,MAClD,KAAK;AACH,eAAO,KAAK,qBAAqB,WAAW,UAAU;AAAA,MACxD;AACE,cAAM,IAAI,OAAO,uBAAuB;AAAA,IAC5C;AAAA,EACF;AAAA,EAEA,MAAc,qBAAqB,YAAgD;AACjF,UAAM,4BAA4B,UAAM,kDAA2B,UAAU;AAC7E,UAAM,SAAS,IAAI,wCAAgB,yBAAyB;AAE5D,UAAM,OAAO,KAAK;AAClB,WAAO,WAAW,KAAK,MAAM;AAE7B,QAAI,OAAO,UAAU,GAAG;AACtB,YAAM,IAAI,OAAO,iBAAiB,8CAA8C;AAAA,IAClF;AAEA,SAAK,OAAO,QAAQ,+BAA+B;AAAA,EACrD;AAAA,EAEA,MAAc,eAAe,YAA0C;AACrE,UAAM,qBAAqB,KAAK,kCAAkC,UAAU;AAC5E,U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AACpC,UAAM,aAAa,oBAAI,IAAY;AAEnC,UAAM,2BAAuB,yCAA4B,UAAU;AACnE,eAAW,SAAS,OAAO,OAAO,oBAAoB,GAAG;AACvD,iBAAW,oBAAoB,OAAO,OAAO,MAAM,OAAO,GAAG;AAC3D,oBAAY,IAAI,iBAAiB,IAAI;AAAA,MACvC;AACA,iBAAW,mBAAmB,OAAO,OAAO,MAAM,MAAM,GAAG;AACzD,mBAAW,IAAI,gBAAgB,IAAI;AAAA,MACrC;AAAA,IACF;AAEA,WAAO,EAAE,aAAa,WAAW;AAAA,EACnC;AACF;",
|
|
6
6
|
"names": ["import_sdk"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var plugin_commands_exports = {};
|
|
26
|
+
__export(plugin_commands_exports, {
|
|
27
|
+
DeletePluginCommand: () => DeletePluginCommand,
|
|
28
|
+
GetPluginCommand: () => GetPluginCommand,
|
|
29
|
+
ListPluginsCommand: () => ListPluginsCommand
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(plugin_commands_exports);
|
|
32
|
+
var import_chalk = __toESM(require("chalk"));
|
|
33
|
+
var errors = __toESM(require("../errors"));
|
|
34
|
+
var import_package_ref = require("../package-ref");
|
|
35
|
+
var utils = __toESM(require("../utils"));
|
|
36
|
+
var import_global_command = require("./global-command");
|
|
37
|
+
class GetPluginCommand extends import_global_command.GlobalCommand {
|
|
38
|
+
async run() {
|
|
39
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
40
|
+
const parsedRef = (0, import_package_ref.parsePackageRef)(this.argv.pluginRef);
|
|
41
|
+
if (!parsedRef) {
|
|
42
|
+
throw new errors.InvalidPackageReferenceError(this.argv.pluginRef);
|
|
43
|
+
}
|
|
44
|
+
if (parsedRef.type === "path") {
|
|
45
|
+
throw new errors.BotpressCLIError("Cannot get local plugin");
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const plugin = await api.findPublicPlugin(parsedRef);
|
|
49
|
+
if (plugin) {
|
|
50
|
+
this.logger.success(`Plugin ${import_chalk.default.bold(this.argv.pluginRef)}:`);
|
|
51
|
+
this.logger.json(utils.object.omit(plugin, "code"));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
} catch (thrown) {
|
|
55
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not get plugin ${this.argv.pluginRef}`);
|
|
56
|
+
}
|
|
57
|
+
throw new errors.BotpressCLIError(`Plugin ${this.argv.pluginRef} not found`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class ListPluginsCommand extends import_global_command.GlobalCommand {
|
|
61
|
+
async run() {
|
|
62
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
63
|
+
const lister = (req) => api.client.listPlugins({ nextToken: req.nextToken });
|
|
64
|
+
try {
|
|
65
|
+
const plugins = await api.listAllPages(lister, (r) => r.plugins);
|
|
66
|
+
this.logger.success("Plugins:");
|
|
67
|
+
this.logger.json(plugins);
|
|
68
|
+
} catch (thrown) {
|
|
69
|
+
throw errors.BotpressCLIError.wrap(thrown, "Could not list plugins");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
class DeletePluginCommand extends import_global_command.GlobalCommand {
|
|
74
|
+
async run() {
|
|
75
|
+
const api = await this.ensureLoginAndCreateClient(this.argv);
|
|
76
|
+
const parsedRef = (0, import_package_ref.parsePackageRef)(this.argv.pluginRef);
|
|
77
|
+
if (!parsedRef) {
|
|
78
|
+
throw new errors.InvalidPackageReferenceError(this.argv.pluginRef);
|
|
79
|
+
}
|
|
80
|
+
if (parsedRef.type === "path") {
|
|
81
|
+
throw new errors.BotpressCLIError("Cannot delete local plugin");
|
|
82
|
+
}
|
|
83
|
+
let plugin;
|
|
84
|
+
try {
|
|
85
|
+
plugin = await api.findPublicPlugin(parsedRef);
|
|
86
|
+
} catch (thrown) {
|
|
87
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not get plugin ${this.argv.pluginRef}`);
|
|
88
|
+
}
|
|
89
|
+
if (!plugin) {
|
|
90
|
+
throw new errors.BotpressCLIError(`Plugin ${this.argv.pluginRef} not found`);
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
await api.client.deletePlugin({ id: plugin.id });
|
|
94
|
+
} catch (thrown) {
|
|
95
|
+
throw errors.BotpressCLIError.wrap(thrown, `Could not delete plugin ${this.argv.pluginRef}`);
|
|
96
|
+
}
|
|
97
|
+
this.logger.success(`Plugin ${import_chalk.default.bold(this.argv.pluginRef)} deleted`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
DeletePluginCommand,
|
|
104
|
+
GetPluginCommand,
|
|
105
|
+
ListPluginsCommand
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=plugin-commands.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/command-implementations/plugin-commands.ts"],
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport chalk from 'chalk'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { parsePackageRef } from '../package-ref'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type GetPluginCommandDefinition = typeof commandDefinitions.plugins.subcommands.get\nexport class GetPluginCommand extends GlobalCommand<GetPluginCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parsePackageRef(this.argv.pluginRef)\n if (!parsedRef) {\n throw new errors.InvalidPackageReferenceError(this.argv.pluginRef)\n }\n if (parsedRef.type === 'path') {\n throw new errors.BotpressCLIError('Cannot get local plugin')\n }\n\n try {\n const plugin = await api.findPublicPlugin(parsedRef)\n if (plugin) {\n this.logger.success(`Plugin ${chalk.bold(this.argv.pluginRef)}:`)\n this.logger.json(utils.object.omit(plugin, 'code'))\n return\n }\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get plugin ${this.argv.pluginRef}`)\n }\n\n throw new errors.BotpressCLIError(`Plugin ${this.argv.pluginRef} not found`)\n }\n}\n\nexport type ListPluginsCommandDefinition = typeof commandDefinitions.plugins.subcommands.list\nexport class ListPluginsCommand extends GlobalCommand<ListPluginsCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const lister = (req: { nextToken?: string }) => api.client.listPlugins({ nextToken: req.nextToken })\n\n try {\n const plugins = await api.listAllPages(lister, (r) => r.plugins)\n\n this.logger.success('Plugins:')\n this.logger.json(plugins)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list plugins')\n }\n }\n}\n\nexport type DeletePluginCommandDefinition = typeof commandDefinitions.plugins.subcommands.delete\nexport class DeletePluginCommand extends GlobalCommand<DeletePluginCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n const parsedRef = parsePackageRef(this.argv.pluginRef)\n if (!parsedRef) {\n throw new errors.InvalidPackageReferenceError(this.argv.pluginRef)\n }\n if (parsedRef.type === 'path') {\n throw new errors.BotpressCLIError('Cannot delete local plugin')\n }\n\n let plugin: client.Plugin | undefined\n try {\n plugin = await api.findPublicPlugin(parsedRef)\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not get plugin ${this.argv.pluginRef}`)\n }\n\n if (!plugin) {\n throw new errors.BotpressCLIError(`Plugin ${this.argv.pluginRef} not found`)\n }\n\n try {\n await api.client.deletePlugin({ id: plugin.id })\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, `Could not delete plugin ${this.argv.pluginRef}`)\n }\n\n this.logger.success(`Plugin ${chalk.bold(this.argv.pluginRef)} deleted`)\n return\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAkB;AAElB,aAAwB;AACxB,yBAAgC;AAChC,YAAuB;AACvB,4BAA8B;AAGvB,MAAM,yBAAyB,oCAA0C;AAAA,EAC9E,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAC3D,UAAM,gBAAY,oCAAgB,KAAK,KAAK,SAAS;AACrD,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,OAAO,6BAA6B,KAAK,KAAK,SAAS;AAAA,IACnE;AACA,QAAI,UAAU,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I;AACJ,QAAI;AACF,eAAS,MAAM,IAAI,iBAAiB,SAAS;AAAA,IAC/C,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,wBAAwB,KAAK,KAAK,WAAW;AAAA,IAC1F;AAEA,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,OAAO,iBAAiB,UAAU,KAAK,KAAK,qBAAqB;AAAA,IAC7E;AAEA,QAAI;AACF,YAAM,IAAI,OAAO,aAAa,EAAE,IAAI,OAAO,GAAG,CAAC;AAAA,IACjD,SAAS,QAAP;AACA,YAAM,OAAO,iBAAiB,KAAK,QAAQ,2BAA2B,KAAK,KAAK,WAAW;AAAA,IAC7F;AAEA,SAAK,OAAO,QAAQ,UAAU,aAAAA,QAAM,KAAK,KAAK,KAAK,SAAS,WAAW;AACvE;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["chalk"]
|
|
7
|
+
}
|
|
@@ -63,7 +63,7 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
63
63
|
const integrationList = (0, import_lodash.default)(botDefinition.integrations).values().filter(utils.guards.is.defined).value();
|
|
64
64
|
const { remoteInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList);
|
|
65
65
|
const fetchedInstances = await import_bluebird.default.map(localInstances, async (instance) => {
|
|
66
|
-
const ref = { type: "name", name: instance.
|
|
66
|
+
const ref = { type: "name", name: instance.name, version: instance.version };
|
|
67
67
|
const integration = await api.findIntegration(ref);
|
|
68
68
|
if (!integration) {
|
|
69
69
|
const formattedRef = (0, import_package_ref.formatPackageRef)(ref);
|
|
@@ -81,8 +81,9 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
81
81
|
const remoteInstances = [];
|
|
82
82
|
const localInstances = [];
|
|
83
83
|
for (const instance of instances) {
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const { id } = instance;
|
|
85
|
+
if (id) {
|
|
86
|
+
remoteInstances.push({ ...instance, id });
|
|
86
87
|
} else {
|
|
87
88
|
localInstances.push(instance);
|
|
88
89
|
}
|
|
@@ -104,6 +105,10 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
104
105
|
if (botDefinition) {
|
|
105
106
|
return { type: "bot", ...botDefinition };
|
|
106
107
|
}
|
|
108
|
+
const pluginDefinition = await this._readPluginDefinitionFromFS(projectPaths);
|
|
109
|
+
if (pluginDefinition) {
|
|
110
|
+
return { type: "plugin", ...pluginDefinition };
|
|
111
|
+
}
|
|
107
112
|
} catch (thrown) {
|
|
108
113
|
throw errors.BotpressCLIError.wrap(thrown, "Error while reading project definition");
|
|
109
114
|
}
|
|
@@ -173,6 +178,28 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
173
178
|
}
|
|
174
179
|
let { default: definition } = utils.require.requireJsCode(artifact.text);
|
|
175
180
|
definition = (0, import_sdk.resolveBotInterfaces)(definition);
|
|
181
|
+
(0, import_sdk.validateBotDefinition)(definition);
|
|
182
|
+
return { definition, bpLintDisabled };
|
|
183
|
+
}
|
|
184
|
+
async _readPluginDefinitionFromFS(projectPaths) {
|
|
185
|
+
const abs = projectPaths.abs;
|
|
186
|
+
const rel = projectPaths.rel("workDir");
|
|
187
|
+
if (!import_fs.default.existsSync(abs.pluginDefinition)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const bpLintDisabled = await this._isBpLintDisabled(abs.pluginDefinition);
|
|
191
|
+
const { outputFiles } = await utils.esbuild.buildEntrypoint({
|
|
192
|
+
cwd: abs.workDir,
|
|
193
|
+
outfile: "",
|
|
194
|
+
entrypoint: rel.pluginDefinition,
|
|
195
|
+
write: false,
|
|
196
|
+
minify: false
|
|
197
|
+
});
|
|
198
|
+
const artifact = outputFiles[0];
|
|
199
|
+
if (!artifact) {
|
|
200
|
+
throw new errors.BotpressCLIError("Could not read plugin definition");
|
|
201
|
+
}
|
|
202
|
+
const { default: definition } = utils.require.requireJsCode(artifact.text);
|
|
176
203
|
return { definition, bpLintDisabled };
|
|
177
204
|
}
|
|
178
205
|
async _isBpLintDisabled(definitionPath) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/project-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport { ApiClient } from '../api/client'\nimport * as codegen from '../code-generation'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { formatPackageRef, PackageRef } from '../package-ref'\nimport { validateIntegrationDefinition, resolveInterfaces, resolveBotInterfaces } from '../sdk'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { workDir: string }\ntype ConstantProjectPaths = typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\ntype IntegrationInstance = NonNullable<sdk.BotDefinition['integrations']>[string]\ntype RemoteIntegrationInstance = utils.types.Merge<IntegrationInstance, { id: string }>\ntype LocalIntegrationInstance = utils.types.Merge<IntegrationInstance, { uri?: string }>\ntype BotIntegrationRequest = NonNullable<NonNullable<client.ClientInputs['updateBot']['integrations']>[string]>\n\ntype LintIgnoredConfig = { bpLintDisabled?: boolean }\n\nexport type ProjectType = ProjectDefinition['type']\nexport type ProjectDefinition = LintIgnoredConfig &\n (\n | { type: 'integration'; definition: sdk.IntegrationDefinition }\n | { type: 'interface'; definition: sdk.InterfaceDeclaration }\n | { type: 'bot'; definition: sdk.BotDefinition }\n )\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n super({\n workDir: absWorkDir,\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected override async bootstrap() {\n await super.bootstrap()\n await this._notifyUpdateSdk()\n }\n\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected async fetchBotIntegrationInstances(\n botDefinition: sdk.BotDefinition,\n api: ApiClient\n ): Promise<Record<string, BotIntegrationRequest>> {\n const integrationList = _(botDefinition.integrations).values().filter(utils.guards.is.defined).value()\n\n const { remoteInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList)\n\n const fetchedInstances: RemoteIntegrationInstance[] = await bluebird.map(localInstances, async (instance) => {\n const ref: PackageRef = { type: 'name', name: instance.definition.name, version: instance.definition.version }\n const integration = await api.findIntegration(ref)\n if (!integration) {\n const formattedRef = formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Integration \"${formattedRef}\" not found`)\n }\n return { ...instance, id: integration.id }\n })\n\n return _([...fetchedInstances, ...remoteInstances])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configurationType, configuration }) => ({\n enabled,\n configurationType: configurationType ?? null,\n configuration,\n }))\n .value()\n }\n\n private _splitApiAndLocalIntegrationInstances(instances: IntegrationInstance[]): {\n remoteInstances: RemoteIntegrationInstance[]\n localInstances: LocalIntegrationInstance[]\n } {\n const remoteInstances: RemoteIntegrationInstance[] = []\n const localInstances: LocalIntegrationInstance[] = []\n for (const instance of instances) {\n if ('id' in instance) {\n remoteInstances.push(instance)\n } else {\n localInstances.push(instance)\n }\n }\n\n return { remoteInstances, localInstances }\n }\n\n protected async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n const projectPaths = this.projectPaths\n try {\n const integrationDefinition = await this._readIntegrationDefinitionFromFS(projectPaths)\n if (integrationDefinition) {\n return { type: 'integration', ...integrationDefinition }\n }\n const interfaceDefinition = await this._readInterfaceDefinitionFromFS(projectPaths)\n if (interfaceDefinition) {\n return { type: 'interface', ...interfaceDefinition }\n }\n const botDefinition = await this._readBotDefinitionFromFS(projectPaths)\n if (botDefinition) {\n return { type: 'bot', ...botDefinition }\n }\n } catch (thrown: unknown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Error while reading project definition')\n }\n\n throw new errors.ProjectDefinitionNotFoundError(this.projectPaths.abs.workDir)\n }\n\n private async _readIntegrationDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'integrationDefinition'>\n ): Promise<({ definition: sdk.IntegrationDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.integrationDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.integrationDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.integrationDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n let { default: definition } = utils.require.requireJsCode<{ default: sdk.IntegrationDefinition }>(artifact.text)\n definition = resolveInterfaces(definition)\n validateIntegrationDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readInterfaceDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'interfaceDefinition'>\n ): Promise<({ definition: sdk.InterfaceDeclaration } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.interfaceDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.interfaceDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.interfaceDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.InterfaceDeclaration }>(artifact.text)\n\n return { definition, bpLintDisabled }\n }\n\n private async _readBotDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'botDefinition'>\n ): Promise<({ definition: sdk.BotDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.botDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.botDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.botDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n let { default: definition } = utils.require.requireJsCode<{ default: sdk.BotDefinition }>(artifact.text)\n // TODO: validate bot definition\n\n definition = resolveBotInterfaces(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _isBpLintDisabled(definitionPath: string): Promise<boolean> {\n const tsContent = await fs.promises.readFile(definitionPath, 'utf-8')\n const regex = /\\/\\* bplint-disable \\*\\//\n return regex.test(tsContent)\n }\n\n protected displayWebhookUrls(bot: client.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n this.logger.log('Integrations:')\n for (const integration of Object.values(bot.integrations).filter(utils.guards.is.defined)) {\n if (!integration.enabled) {\n this.logger.log(`${chalk.grey(integration.name)} ${chalk.italic('(disabled)')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 2 },\n })\n } else {\n this.logger.log(`${chalk.bold(integration.name)} : ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 2 },\n })\n }\n }\n }\n\n protected async promptSecrets(\n integrationDef: sdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>,\n opts: { formatEnv?: boolean; knownSecrets?: string[] } = {}\n ): Promise<Record<string, string | null>> {\n const formatEnv = opts.formatEnv ?? false\n const knownSecrets = opts.knownSecrets ?? []\n\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string | null> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const alreadyKnown = knownSecrets.includes(secretName)\n let mode: string\n if (alreadyKnown) {\n mode = 'already set'\n } else if (optional) {\n mode = 'optional'\n } else {\n mode = 'required'\n }\n\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (alreadyKnown) {\n this.logger.log(`Secret \"${secretName}\" is unchanged`)\n } else if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n } else {\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n }\n\n for (const secretName of knownSecrets) {\n const isDefined = secretName in secretDefinitions\n if (isDefined) {\n continue\n }\n const prompted = await this.prompt.confirm(`Secret \"${secretName}\" was removed. Do you wish to delete it?`)\n if (prompted) {\n this.logger.log(`Deleting secret \"${secretName}\"`, { prefix: { symbol: '\u00D7', fg: 'red' } })\n values[secretName] = null\n }\n }\n\n if (!formatEnv) {\n return values\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n protected async readIntegrationConfigDefinition<C extends client.ClientInputs['createIntegration']['configuration']>(\n config: C\n ): Promise<C> {\n if (!config?.identifier) {\n return config\n }\n return {\n ...config,\n identifier: {\n ...config.identifier,\n linkTemplateScript: await this.readProjectFile(config.identifier.linkTemplateScript),\n },\n }\n }\n\n protected readProjectFile = async (filePath: string | undefined): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'utf-8').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read file \"${absoluteFilePath}\"`)\n })\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = utils.string.splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _notifyUpdateSdk = async (): Promise<void> => {\n try {\n this.logger.debug('Checking if sdk is up to date')\n\n const { workDir } = this.projectPaths.abs\n const projectPkgJson = await utils.pkgJson.readPackageJson(workDir)\n if (!projectPkgJson) {\n this.logger.debug(`Could not find package.json at \"${workDir}\"`)\n return\n }\n\n const sdkPackageName = '@botpress/sdk'\n const actualSdkVersion = utils.pkgJson.findDependency(projectPkgJson, sdkPackageName)\n if (!actualSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in project package.json`)\n return\n }\n\n if (actualSdkVersion.startsWith('workspace:')) {\n return\n }\n\n const actualCleanedSdkVersion = semver.valid(semver.coerce(actualSdkVersion))\n if (!actualCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${actualSdkVersion}\" in project package.json`)\n return\n }\n\n const cliPkgJson = await this.readPkgJson()\n const expectedSdkVersion = utils.pkgJson.findDependency(cliPkgJson, sdkPackageName)\n if (!expectedSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in cli package.json`)\n return\n }\n\n const expectedCleanedSdkVersion = semver.valid(semver.coerce(expectedSdkVersion))\n if (!expectedCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${expectedSdkVersion}\" in cli package.json`)\n return\n }\n\n if (semver.eq(actualCleanedSdkVersion, expectedCleanedSdkVersion)) {\n return\n }\n\n const diff = semver.diff(actualCleanedSdkVersion, expectedCleanedSdkVersion)\n if (!diff) {\n this.logger.debug(`Could not compare versions \"${actualCleanedSdkVersion}\" and \"${expectedCleanedSdkVersion}\"`)\n return\n }\n\n const errorMsg = `Project SDK version is \"${actualCleanedSdkVersion}\", but expected \"${expectedCleanedSdkVersion}\"`\n if (utils.semver.releases.lt(diff, 'minor')) {\n this.logger.debug(`${errorMsg}. This may cause compatibility issues.`)\n return\n }\n\n this.logger.warn(chalk.bold(`${errorMsg}. This will cause compatibility issues.`))\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check if sdk is up to date: ${err.message}`)\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAqB;AACrB,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;AAEnB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,yBAA6C;AAC7C,
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport bluebird from 'bluebird'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport { ApiClient } from '../api/client'\nimport * as codegen from '../code-generation'\nimport type * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { formatPackageRef, PackageRef } from '../package-ref'\nimport { validateIntegrationDefinition, resolveInterfaces, resolveBotInterfaces, validateBotDefinition } from '../sdk'\nimport type { CommandArgv, CommandDefinition } from '../typings'\nimport * as utils from '../utils'\nimport { GlobalCommand } from './global-command'\n\nexport type ProjectCommandDefinition = CommandDefinition<typeof config.schemas.project>\nexport type ProjectCache = { botId: string; devId: string }\n\ntype ConfigurableProjectPaths = { workDir: string }\ntype ConstantProjectPaths = typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\n\ntype IntegrationInstance = NonNullable<sdk.BotDefinition['integrations']>[string]\ntype RemoteIntegrationInstance = utils.types.Merge<IntegrationInstance, { id: string }>\ntype LocalIntegrationInstance = utils.types.Merge<IntegrationInstance, { uri?: string }>\ntype BotIntegrationRequest = NonNullable<NonNullable<client.ClientInputs['updateBot']['integrations']>[string]>\n\ntype LintIgnoredConfig = { bpLintDisabled?: boolean }\n\nexport type ProjectType = ProjectDefinition['type']\nexport type ProjectDefinition = LintIgnoredConfig &\n (\n | { type: 'integration'; definition: sdk.IntegrationDefinition }\n | { type: 'interface'; definition: sdk.InterfaceDefinition }\n | { type: 'bot'; definition: sdk.BotDefinition }\n | { type: 'plugin'; definition: sdk.PluginDefinition }\n )\n\nclass ProjectPaths extends utils.path.PathStore<keyof AllProjectPaths> {\n public constructor(argv: CommandArgv<ProjectCommandDefinition>) {\n const absWorkDir = utils.path.absoluteFrom(utils.path.cwd(), argv.workDir)\n super({\n workDir: absWorkDir,\n ..._.mapValues(consts.fromWorkDir, (p) => utils.path.absoluteFrom(absWorkDir, p)),\n })\n }\n}\n\nexport abstract class ProjectCommand<C extends ProjectCommandDefinition> extends GlobalCommand<C> {\n protected override async bootstrap() {\n await super.bootstrap()\n await this._notifyUpdateSdk()\n }\n\n protected get projectPaths() {\n return new ProjectPaths(this.argv)\n }\n\n protected get projectCache() {\n return new utils.cache.FSKeyValueCache<ProjectCache>(this.projectPaths.abs.projectCacheFile)\n }\n\n protected async fetchBotIntegrationInstances(\n botDefinition: sdk.BotDefinition,\n api: ApiClient\n ): Promise<Record<string, BotIntegrationRequest>> {\n const integrationList = _(botDefinition.integrations).values().filter(utils.guards.is.defined).value()\n\n const { remoteInstances, localInstances } = this._splitApiAndLocalIntegrationInstances(integrationList)\n\n const fetchedInstances: RemoteIntegrationInstance[] = await bluebird.map(localInstances, async (instance) => {\n const ref: PackageRef = { type: 'name', name: instance.name, version: instance.version }\n const integration = await api.findIntegration(ref)\n if (!integration) {\n const formattedRef = formatPackageRef(ref)\n throw new errors.BotpressCLIError(`Integration \"${formattedRef}\" not found`)\n }\n return { ...instance, id: integration.id }\n })\n\n return _([...fetchedInstances, ...remoteInstances])\n .keyBy((i) => i.id)\n .mapValues(({ enabled, configurationType, configuration }) => ({\n enabled,\n configurationType: configurationType ?? null,\n configuration,\n }))\n .value()\n }\n\n private _splitApiAndLocalIntegrationInstances(instances: IntegrationInstance[]): {\n remoteInstances: RemoteIntegrationInstance[]\n localInstances: LocalIntegrationInstance[]\n } {\n const remoteInstances: RemoteIntegrationInstance[] = []\n const localInstances: LocalIntegrationInstance[] = []\n for (const instance of instances) {\n const { id } = instance\n if (id) {\n remoteInstances.push({ ...instance, id })\n } else {\n localInstances.push(instance)\n }\n }\n\n return { remoteInstances, localInstances }\n }\n\n protected async readProjectDefinitionFromFS(): Promise<ProjectDefinition> {\n const projectPaths = this.projectPaths\n try {\n const integrationDefinition = await this._readIntegrationDefinitionFromFS(projectPaths)\n if (integrationDefinition) {\n return { type: 'integration', ...integrationDefinition }\n }\n const interfaceDefinition = await this._readInterfaceDefinitionFromFS(projectPaths)\n if (interfaceDefinition) {\n return { type: 'interface', ...interfaceDefinition }\n }\n const botDefinition = await this._readBotDefinitionFromFS(projectPaths)\n if (botDefinition) {\n return { type: 'bot', ...botDefinition }\n }\n const pluginDefinition = await this._readPluginDefinitionFromFS(projectPaths)\n if (pluginDefinition) {\n return { type: 'plugin', ...pluginDefinition }\n }\n } catch (thrown: unknown) {\n throw errors.BotpressCLIError.wrap(thrown, 'Error while reading project definition')\n }\n\n throw new errors.ProjectDefinitionNotFoundError(this.projectPaths.abs.workDir)\n }\n\n private async _readIntegrationDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'integrationDefinition'>\n ): Promise<({ definition: sdk.IntegrationDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.integrationDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.integrationDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.integrationDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n let { default: definition } = utils.require.requireJsCode<{ default: sdk.IntegrationDefinition }>(artifact.text)\n definition = resolveInterfaces(definition)\n validateIntegrationDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readInterfaceDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'interfaceDefinition'>\n ): Promise<({ definition: sdk.InterfaceDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.interfaceDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.interfaceDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.interfaceDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read interface definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.InterfaceDefinition }>(artifact.text)\n\n return { definition, bpLintDisabled }\n }\n\n private async _readBotDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'botDefinition'>\n ): Promise<({ definition: sdk.BotDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.botDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.botDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.botDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n let { default: definition } = utils.require.requireJsCode<{ default: sdk.BotDefinition }>(artifact.text)\n definition = resolveBotInterfaces(definition)\n validateBotDefinition(definition)\n return { definition, bpLintDisabled }\n }\n\n private async _readPluginDefinitionFromFS(\n projectPaths: utils.path.PathStore<'workDir' | 'pluginDefinition'>\n ): Promise<({ definition: sdk.PluginDefinition } & LintIgnoredConfig) | undefined> {\n const abs = projectPaths.abs\n const rel = projectPaths.rel('workDir')\n\n if (!fs.existsSync(abs.pluginDefinition)) {\n return\n }\n\n const bpLintDisabled = await this._isBpLintDisabled(abs.pluginDefinition)\n\n const { outputFiles } = await utils.esbuild.buildEntrypoint({\n cwd: abs.workDir,\n outfile: '',\n entrypoint: rel.pluginDefinition,\n write: false,\n minify: false,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read plugin definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.PluginDefinition }>(artifact.text)\n // TODO: validate plugin definition\n return { definition, bpLintDisabled }\n }\n\n private async _isBpLintDisabled(definitionPath: string): Promise<boolean> {\n const tsContent = await fs.promises.readFile(definitionPath, 'utf-8')\n const regex = /\\/\\* bplint-disable \\*\\//\n return regex.test(tsContent)\n }\n\n protected displayWebhookUrls(bot: client.Bot) {\n if (!_.keys(bot.integrations).length) {\n this.logger.debug('No integrations in bot')\n return\n }\n\n this.logger.log('Integrations:')\n for (const integration of Object.values(bot.integrations).filter(utils.guards.is.defined)) {\n if (!integration.enabled) {\n this.logger.log(`${chalk.grey(integration.name)} ${chalk.italic('(disabled)')}: ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CB', indent: 2 },\n })\n } else {\n this.logger.log(`${chalk.bold(integration.name)} : ${integration.webhookUrl}`, {\n prefix: { symbol: '\u25CF', indent: 2 },\n })\n }\n }\n }\n\n protected async promptSecrets(\n integrationDef: sdk.IntegrationDefinition,\n argv: YargsConfig<typeof config.schemas.secrets>,\n opts: { formatEnv?: boolean; knownSecrets?: string[] } = {}\n ): Promise<Record<string, string | null>> {\n const formatEnv = opts.formatEnv ?? false\n const knownSecrets = opts.knownSecrets ?? []\n\n const { secrets: secretDefinitions } = integrationDef\n if (!secretDefinitions) {\n return {}\n }\n\n const secretArgv = this._parseArgvSecrets(argv.secrets)\n const invalidSecret = Object.keys(secretArgv).find((s) => !secretDefinitions[s])\n if (invalidSecret) {\n throw new errors.BotpressCLIError(`Secret ${invalidSecret} is not defined in integration definition`)\n }\n\n const values: Record<string, string | null> = {}\n for (const [secretName, { optional }] of Object.entries(secretDefinitions)) {\n const argvSecret = secretArgv[secretName]\n if (argvSecret) {\n this.logger.debug(`Using secret \"${secretName}\" from argv`)\n values[secretName] = argvSecret\n continue\n }\n\n const alreadyKnown = knownSecrets.includes(secretName)\n let mode: string\n if (alreadyKnown) {\n mode = 'already set'\n } else if (optional) {\n mode = 'optional'\n } else {\n mode = 'required'\n }\n\n const prompted = await this.prompt.text(`Enter value for secret \"${secretName}\" (${mode})`)\n if (prompted) {\n values[secretName] = prompted\n continue\n }\n\n if (alreadyKnown) {\n this.logger.log(`Secret \"${secretName}\" is unchanged`)\n } else if (optional) {\n this.logger.warn(`Secret \"${secretName}\" is unassigned`)\n } else {\n throw new errors.BotpressCLIError(`Secret \"${secretName}\" is required`)\n }\n }\n\n for (const secretName of knownSecrets) {\n const isDefined = secretName in secretDefinitions\n if (isDefined) {\n continue\n }\n const prompted = await this.prompt.confirm(`Secret \"${secretName}\" was removed. Do you wish to delete it?`)\n if (prompted) {\n this.logger.log(`Deleting secret \"${secretName}\"`, { prefix: { symbol: '\u00D7', fg: 'red' } })\n values[secretName] = null\n }\n }\n\n if (!formatEnv) {\n return values\n }\n\n const envVariables = _.mapKeys(values, (_v, k) => codegen.secretEnvVariableName(k))\n return envVariables\n }\n\n protected async readIntegrationConfigDefinition<C extends client.ClientInputs['createIntegration']['configuration']>(\n config: C\n ): Promise<C> {\n if (!config?.identifier) {\n return config\n }\n return {\n ...config,\n identifier: {\n ...config.identifier,\n linkTemplateScript: await this.readProjectFile(config.identifier.linkTemplateScript),\n },\n }\n }\n\n protected readProjectFile = async (filePath: string | undefined): Promise<string | undefined> => {\n if (!filePath) {\n return undefined\n }\n const absoluteFilePath = utils.path.absoluteFrom(this.projectPaths.abs.workDir, filePath)\n return fs.promises.readFile(absoluteFilePath, 'utf-8').catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not read file \"${absoluteFilePath}\"`)\n })\n }\n\n private _parseArgvSecrets(argvSecrets: string[]): Record<string, string> {\n const parsed: Record<string, string> = {}\n for (const secret of argvSecrets) {\n const [key, value] = utils.string.splitOnce(secret, '=')\n if (!value) {\n throw new errors.BotpressCLIError(\n `Secret \"${key}\" is missing a value. Expected format: \"SECRET_NAME=secretValue\"`\n )\n }\n parsed[key!] = value\n }\n\n return parsed\n }\n\n private _notifyUpdateSdk = async (): Promise<void> => {\n try {\n this.logger.debug('Checking if sdk is up to date')\n\n const { workDir } = this.projectPaths.abs\n const projectPkgJson = await utils.pkgJson.readPackageJson(workDir)\n if (!projectPkgJson) {\n this.logger.debug(`Could not find package.json at \"${workDir}\"`)\n return\n }\n\n const sdkPackageName = '@botpress/sdk'\n const actualSdkVersion = utils.pkgJson.findDependency(projectPkgJson, sdkPackageName)\n if (!actualSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in project package.json`)\n return\n }\n\n if (actualSdkVersion.startsWith('workspace:')) {\n return\n }\n\n const actualCleanedSdkVersion = semver.valid(semver.coerce(actualSdkVersion))\n if (!actualCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${actualSdkVersion}\" in project package.json`)\n return\n }\n\n const cliPkgJson = await this.readPkgJson()\n const expectedSdkVersion = utils.pkgJson.findDependency(cliPkgJson, sdkPackageName)\n if (!expectedSdkVersion) {\n this.logger.debug(`Could not find dependency \"${sdkPackageName}\" in cli package.json`)\n return\n }\n\n const expectedCleanedSdkVersion = semver.valid(semver.coerce(expectedSdkVersion))\n if (!expectedCleanedSdkVersion) {\n this.logger.debug(`Invalid sdk version \"${expectedSdkVersion}\" in cli package.json`)\n return\n }\n\n if (semver.eq(actualCleanedSdkVersion, expectedCleanedSdkVersion)) {\n return\n }\n\n const diff = semver.diff(actualCleanedSdkVersion, expectedCleanedSdkVersion)\n if (!diff) {\n this.logger.debug(`Could not compare versions \"${actualCleanedSdkVersion}\" and \"${expectedCleanedSdkVersion}\"`)\n return\n }\n\n const errorMsg = `Project SDK version is \"${actualCleanedSdkVersion}\", but expected \"${expectedCleanedSdkVersion}\"`\n if (utils.semver.releases.lt(diff, 'minor')) {\n this.logger.debug(`${errorMsg}. This may cause compatibility issues.`)\n return\n }\n\n this.logger.warn(chalk.bold(`${errorMsg}. This will cause compatibility issues.`))\n } catch (thrown) {\n const err = errors.BotpressCLIError.map(thrown)\n this.logger.debug(`Failed to check if sdk is up to date: ${err.message}`)\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAqB;AACrB,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;AAEnB,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,yBAA6C;AAC7C,iBAA8G;AAE9G,YAAuB;AACvB,4BAA8B;AAyB9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,K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,CAAC;AAC5E,UAAI,CAAC,yBAAyB;AAC5B,aAAK,OAAO,MAAM,wBAAwB,2CAA2C;AACrF;AAAA,MACF;AAEA,YAAM,aAAa,MAAM,KAAK,YAAY;AAC1C,YAAM,qBAAqB,MAAM,QAAQ,eAAe,YAAY,cAAc;AAClF,UAAI,CAAC,oBAAoB;AACvB,aAAK,OAAO,MAAM,8BAA8B,qCAAqC;AACrF;AAAA,MACF;AAEA,YAAM,4BAA4B,cAAAA,QAAO,MAAM,cAAAA,QAAO,OAAO,kBAAkB,CAAC;AAChF,UAAI,CAAC,2BAA2B;AAC9B,aAAK,OAAO,MAAM,wBAAwB,yCAAyC;AACnF;AAAA,MACF;AAEA,UAAI,cAAAA,QAAO,GAAG,yBAAyB,yBAAyB,GAAG;AACjE;AAAA,MACF;AAEA,YAAM,OAAO,cAAAA,QAAO,KAAK,yBAAyB,yBAAyB;AAC3E,UAAI,CAAC,MAAM;AACT,aAAK,OAAO,MAAM,+BAA+B,iCAAiC,4BAA4B;AAC9G;AAAA,MACF;AAEA,YAAM,WAAW,2BAA2B,2CAA2C;AACvF,UAAI,MAAM,OAAO,SAAS,GAAG,MAAM,OAAO,GAAG;AAC3C,aAAK,OAAO,MAAM,GAAG,gDAAgD;AACrE;AAAA,MACF;AAEA,WAAK,OAAO,KAAK,aAAAD,QAAM,KAAK,GAAG,iDAAiD,CAAC;AAAA,IACnF,SAAS,QAAP;AACA,YAAM,MAAM,OAAO,iBAAiB,IAAI,MAAM;AAC9C,WAAK,OAAO,MAAM,yCAAyC,IAAI,SAAS;AAAA,IAC1E;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["_", "bluebird", "fs", "chalk", "semver"]
|
|
7
7
|
}
|
|
@@ -27,8 +27,10 @@ __export(read_command_exports, {
|
|
|
27
27
|
ReadCommand: () => ReadCommand
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(read_command_exports);
|
|
30
|
+
var import_bot_body = require("../api/bot-body");
|
|
30
31
|
var import_integration_body = require("../api/integration-body");
|
|
31
32
|
var import_interface_body = require("../api/interface-body");
|
|
33
|
+
var import_plugin_body = require("../api/plugin-body");
|
|
32
34
|
var errors = __toESM(require("../errors"));
|
|
33
35
|
var import_project_command = require("./project-command");
|
|
34
36
|
class ReadCommand extends import_project_command.ProjectCommand {
|
|
@@ -44,7 +46,17 @@ class ReadCommand extends import_project_command.ProjectCommand {
|
|
|
44
46
|
this.logger.json(parsed);
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
if (projectDef.type === "bot") {
|
|
50
|
+
const parsed = await (0, import_bot_body.prepareCreateBotBody)(projectDef.definition);
|
|
51
|
+
this.logger.json(parsed);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (projectDef.type === "plugin") {
|
|
55
|
+
const parsed = await (0, import_plugin_body.prepareCreatePluginBody)(projectDef.definition);
|
|
56
|
+
this.logger.json(parsed);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
throw new errors.BotpressCLIError("Unsupported project type");
|
|
48
60
|
}
|
|
49
61
|
}
|
|
50
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/read-command.ts"],
|
|
4
|
-
"sourcesContent": ["import { prepareCreateIntegrationBody } from '../api/integration-body'\nimport { prepareCreateInterfaceBody } from '../api/interface-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport { ProjectCommand } from './project-command'\n\nexport type ReadCommandDefinition = typeof commandDefinitions.read\nexport class ReadCommand extends ProjectCommand<ReadCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.type === 'integration') {\n const parsed = await prepareCreateIntegrationBody(projectDef.definition)\n // TODO: maybe display interface implementation statements here\n this.logger.json(parsed)\n return\n }\n if (projectDef.type === 'interface') {\n const parsed = await prepareCreateInterfaceBody(projectDef.definition)\n this.logger.json(parsed)\n return\n }\n\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAA6C;AAC7C,4BAA2C;
|
|
4
|
+
"sourcesContent": ["import { prepareCreateBotBody } from '../api/bot-body'\nimport { prepareCreateIntegrationBody } from '../api/integration-body'\nimport { prepareCreateInterfaceBody } from '../api/interface-body'\nimport { prepareCreatePluginBody } from '../api/plugin-body'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as utils from '../utils'\nimport { ProjectCommand } from './project-command'\n\nexport type ReadCommandDefinition = typeof commandDefinitions.read\nexport class ReadCommand extends ProjectCommand<ReadCommandDefinition> {\n public async run(): Promise<void> {\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.type === 'integration') {\n const parsed = await prepareCreateIntegrationBody(projectDef.definition)\n // TODO: maybe display interface implementation statements here\n this.logger.json(parsed)\n return\n }\n if (projectDef.type === 'interface') {\n const parsed = await prepareCreateInterfaceBody(projectDef.definition)\n this.logger.json(parsed)\n return\n }\n if (projectDef.type === 'bot') {\n const parsed = await prepareCreateBotBody(projectDef.definition)\n this.logger.json(parsed)\n return\n }\n if (projectDef.type === 'plugin') {\n const parsed = await prepareCreatePluginBody(projectDef.definition)\n this.logger.json(parsed)\n return\n }\n\n type _assertion = utils.types.AssertNever<typeof projectDef>\n throw new errors.BotpressCLIError('Unsupported project type')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAqC;AACrC,8BAA6C;AAC7C,4BAA2C;AAC3C,yBAAwC;AAExC,aAAwB;AAExB,6BAA+B;AAGxB,MAAM,oBAAoB,sCAAsC;AAAA,EACrE,MAAa,MAAqB;AAChC,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAC1D,QAAI,WAAW,SAAS,eAAe;AACrC,YAAM,SAAS,UAAM,sDAA6B,WAAW,UAAU;AAEvE,WAAK,OAAO,KAAK,MAAM;AACvB;AAAA,IACF;AACA,QAAI,WAAW,SAAS,aAAa;AACnC,YAAM,SAAS,UAAM,kDAA2B,WAAW,UAAU;AACrE,WAAK,OAAO,KAAK,MAAM;AACvB;AAAA,IACF;AACA,QAAI,WAAW,SAAS,OAAO;AAC7B,YAAM,SAAS,UAAM,sCAAqB,WAAW,UAAU;AAC/D,WAAK,OAAO,KAAK,MAAM;AACvB;AAAA,IACF;AACA,QAAI,WAAW,SAAS,UAAU;AAChC,YAAM,SAAS,UAAM,4CAAwB,WAAW,UAAU;AAClE,WAAK,OAAO,KAAK,MAAM;AACvB;AAAA,IACF;AAGA,UAAM,IAAI,OAAO,iBAAiB,0BAA0B;AAAA,EAC9D;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/config.js
CHANGED
|
@@ -70,7 +70,7 @@ const botRef = {
|
|
|
70
70
|
const packageType = {
|
|
71
71
|
type: "string",
|
|
72
72
|
description: "Either an integration or an interface; helps disambiguate the package type in case both an integration and an interface have the same reference.",
|
|
73
|
-
choices: ["integration", "interface"]
|
|
73
|
+
choices: ["integration", "interface", "plugin"]
|
|
74
74
|
};
|
|
75
75
|
const packageRef = {
|
|
76
76
|
type: "string",
|
|
@@ -87,6 +87,10 @@ const interfaceRef = {
|
|
|
87
87
|
...packageRef,
|
|
88
88
|
description: "The interface ID or name and version. Ex: llm@5.1.0"
|
|
89
89
|
};
|
|
90
|
+
const pluginRef = {
|
|
91
|
+
...packageRef,
|
|
92
|
+
description: "The plugin ID or name and version. Ex: knowledge@0.0.1"
|
|
93
|
+
};
|
|
90
94
|
const sourceMap = { type: "boolean", description: "Generate sourcemaps", default: false };
|
|
91
95
|
const minify = { type: "boolean", description: "Minify the bundled code", default: true };
|
|
92
96
|
const dev = {
|
|
@@ -261,10 +265,24 @@ const deleteInterfaceSchema = {
|
|
|
261
265
|
...credentialsSchema,
|
|
262
266
|
interfaceRef
|
|
263
267
|
};
|
|
268
|
+
const getPluginSchema = {
|
|
269
|
+
...globalSchema,
|
|
270
|
+
...credentialsSchema,
|
|
271
|
+
pluginRef
|
|
272
|
+
};
|
|
273
|
+
const listPluginsSchema = {
|
|
274
|
+
...globalSchema,
|
|
275
|
+
...credentialsSchema
|
|
276
|
+
};
|
|
277
|
+
const deletePluginSchema = {
|
|
278
|
+
...globalSchema,
|
|
279
|
+
...credentialsSchema,
|
|
280
|
+
pluginRef
|
|
281
|
+
};
|
|
264
282
|
const initSchema = {
|
|
265
283
|
...globalSchema,
|
|
266
284
|
workDir,
|
|
267
|
-
type: { type: "string", choices: ["bot", "integration"] },
|
|
285
|
+
type: { type: "string", choices: ["bot", "integration", "plugin"] },
|
|
268
286
|
name: { type: "string", description: "The name of the project" }
|
|
269
287
|
};
|
|
270
288
|
const lintSchema = {
|
|
@@ -287,6 +305,9 @@ const schemas = {
|
|
|
287
305
|
getInterface: getInterfaceSchema,
|
|
288
306
|
listInterfaces: listInterfacesSchema,
|
|
289
307
|
deleteInterface: deleteInterfaceSchema,
|
|
308
|
+
getPlugin: getPluginSchema,
|
|
309
|
+
listPlugins: listPluginsSchema,
|
|
310
|
+
deletePlugin: deletePluginSchema,
|
|
290
311
|
init: initSchema,
|
|
291
312
|
generate: generateSchema,
|
|
292
313
|
bundle: bundleSchema,
|