@botpress/cli 4.17.9 → 4.17.10
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 -11
- package/dist/command-implementations/deploy-command.js +7 -0
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/dev-command.js +18 -5
- package/dist/command-implementations/dev-command.js.map +2 -2
- package/dist/command-implementations/project-command.js +11 -0
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/config.js +4 -0
- package/dist/config.js.map +2 -2
- package/dist/errors.js +7 -1
- package/dist/errors.js.map +2 -2
- package/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/cli@4.17.
|
|
2
|
+
> @botpress/cli@4.17.10 build /home/runner/work/botpress/botpress/packages/cli
|
|
3
3
|
> pnpm run bundle && pnpm run template:gen
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @botpress/cli@4.17.
|
|
6
|
+
> @botpress/cli@4.17.10 bundle /home/runner/work/botpress/botpress/packages/cli
|
|
7
7
|
> ts-node -T build.ts
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
> @botpress/cli@4.17.
|
|
10
|
+
> @botpress/cli@4.17.10 template:gen /home/runner/work/botpress/botpress/packages/cli
|
|
11
11
|
> pnpm -r --stream -F @bp-templates/* exec bp gen
|
|
12
12
|
|
|
13
|
-
🤖 Botpress CLI v4.17.
|
|
14
|
-
🤖 Botpress CLI v4.17.
|
|
15
|
-
🤖 Botpress CLI v4.17.
|
|
16
|
-
🤖 Botpress CLI v4.17.
|
|
13
|
+
🤖 Botpress CLI v4.17.10
|
|
14
|
+
🤖 Botpress CLI v4.17.10
|
|
15
|
+
🤖 Botpress CLI v4.17.10
|
|
16
|
+
🤖 Botpress CLI v4.17.10
|
|
17
17
|
○ Generating typings for integration hello-world...
|
|
18
|
+
○ Generating typings for integration empty-integration...
|
|
18
19
|
✓ Typings available at .botpress
|
|
19
20
|
|
|
20
|
-
○ Generating typings for plugin empty-plugin...
|
|
21
|
-
○ Generating typings for bot...
|
|
22
21
|
✓ Typings available at .botpress
|
|
23
22
|
|
|
23
|
+
○ Generating typings for plugin empty-plugin...
|
|
24
|
+
○ Generating typings for bot...
|
|
24
25
|
✓ Typings available at .botpress
|
|
25
26
|
|
|
26
|
-
○ Generating typings for integration empty-integration...
|
|
27
27
|
✓ Typings available at .botpress
|
|
28
28
|
|
|
29
|
-
🤖 Botpress CLI v4.17.
|
|
29
|
+
🤖 Botpress CLI v4.17.10
|
|
30
30
|
○ Generating typings for integration webhook-message...
|
|
31
31
|
✓ Typings available at .botpress
|
|
32
32
|
|
|
@@ -391,6 +391,13 @@ class DeployCommand extends import_project_command.ProjectCommand {
|
|
|
391
391
|
const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {
|
|
392
392
|
throw errors.BotpressCLIError.wrap(thrown, `Could not update bot "${bot.name}"`);
|
|
393
393
|
});
|
|
394
|
+
this.validateIntegrationRegistration(
|
|
395
|
+
updatedBot,
|
|
396
|
+
(failedIntegrations) => this.logger.warn(
|
|
397
|
+
`Some integrations failed to register:
|
|
398
|
+
${Object.entries(failedIntegrations).map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`).join("\n")}`
|
|
399
|
+
)
|
|
400
|
+
);
|
|
394
401
|
const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt });
|
|
395
402
|
await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition });
|
|
396
403
|
line.success("Bot deployed");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/deploy-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\nimport * as utils from '../utils'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\nexport type DeployCommandDefinition = typeof commandDefinitions.deploy\nexport class DeployCommand extends ProjectCommand<DeployCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const projectDef = await this.readProjectDefinitionFromFS()\n\n if (projectDef.type === 'integration') {\n return this._deployIntegration(api, projectDef.definition)\n }\n if (projectDef.type === 'interface') {\n return this._deployInterface(api, projectDef.definition)\n }\n if (projectDef.type === 'plugin') {\n return this._deployPlugin(api, projectDef.definition)\n }\n if (projectDef.type === 'bot') {\n return this._deployBot(api, projectDef.definition, this.argv.botId, this.argv.createNewBot)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private get _visibility(): 'public' | 'private' | 'unlisted' {\n if (this.argv.public && this.argv.visibility === 'private') {\n this.logger.warn('The --public flag is deprecated. Please use \"--visibility public\" instead.')\n return 'public'\n }\n\n if (this.argv.public && this.argv.visibility !== 'private') {\n this.logger.warn('The --public flag and --visibility option are both present. Ignoring the --public flag...')\n }\n\n return this.argv.visibility\n }\n\n private async _deployIntegration(api: apiUtils.ApiClient, integrationDef: sdk.IntegrationDefinition) {\n const res = await this._manageWorkspaceHandle(api, integrationDef)\n if (!res) return\n const { integration: updatedIntegrationDef, workspaceId } = res\n integrationDef = updatedIntegrationDef\n if (workspaceId) {\n api = api.switchWorkspace(workspaceId)\n }\n\n const { name, version } = integrationDef\n\n if (integrationDef.icon && !integrationDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (integrationDef.readme && !integrationDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const integration = await api.findPublicOrPrivateIntegration({ type: 'name', name, version })\n if (integration && integration.workspaceId !== api.workspaceId) {\n throw new errors.BotpressCLIError(\n `Public integration ${name} v${version} is already deployed in another workspace.`\n )\n }\n\n if (integration && integration.visibility !== 'private' && !api.isBotpressWorkspace) {\n throw new errors.BotpressCLIError(\n `Integration ${name} v${version} is already deployed publicly and cannot be updated. Please bump the version.`\n )\n }\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override integration ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy integration ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing integration request body...')\n\n const createBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n visibility: this._visibility,\n }\n\n const startedMessage = `Deploying integration ${chalk.bold(name)} v${version}...`\n const successMessage = 'Integration deployed'\n if (integration) {\n const updateBody = apiUtils.prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n const { secrets: knownSecrets } = integration\n updateBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, { allowDeprecated: true })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration update...')\n\n await api.client.validateIntegrationUpdate(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n } else {\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n this.logger.debug(`looking for previous version of integration \"${name}\"`)\n const previousVersion = await api.findPreviousIntegrationVersion({ type: 'name', name, version })\n\n if (previousVersion) {\n this.logger.debug(`previous version found: ${previousVersion.version}`)\n } else {\n this.logger.debug('no previous version found')\n }\n\n const knownSecrets = previousVersion?.secrets\n\n createBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, {\n allowDeprecated: this._allowDeprecatedFeatures(integrationDef, previousVersion),\n })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration creation...')\n\n await api.client.validateIntegrationCreation(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployInterface(api: apiUtils.ApiClient, interfaceDeclaration: sdk.InterfaceDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for interfaces. Please use \"public\" or \"private\".'\n )\n }\n\n if (interfaceDeclaration.icon && !interfaceDeclaration.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (interfaceDeclaration.readme && !interfaceDeclaration.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const { name, version } = interfaceDeclaration\n const intrface = await api.findPublicOrPrivateInterface({ type: 'name', name, version })\n\n let message: string\n if (intrface) {\n this.logger.warn('Interface already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override interface ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy interface ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n const icon = await this.readProjectFile(interfaceDeclaration.icon, 'base64')\n const readme = await this.readProjectFile(interfaceDeclaration.readme, 'base64')\n\n const createBody = {\n ...(await apiUtils.prepareCreateInterfaceBody(interfaceDeclaration)),\n public: this._visibility === 'public',\n icon,\n readme,\n }\n\n const startedMessage = `Deploying interface ${chalk.bold(name)} v${version}...`\n const successMessage = 'Interface deployed'\n if (intrface) {\n const updateBody = apiUtils.prepareUpdateInterfaceBody(\n {\n id: intrface.id,\n ...createBody,\n },\n intrface\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface updates. Skipping deployment...')\n } else {\n await api.client.updateInterface(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface creation. Skipping deployment...')\n } else {\n await api.client.createInterface(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployPlugin(api: apiUtils.ApiClient, pluginDef: sdk.PluginDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for plugins. Please use \"public\" or \"private\".'\n )\n }\n\n const codeCJS = await fs.promises.readFile(this.projectPaths.abs.outFileCJS, 'utf-8')\n const codeESM = await fs.promises.readFile(this.projectPaths.abs.outFileESM, 'utf-8')\n\n const { name, version } = pluginDef\n\n if (pluginDef.icon && !pluginDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (pluginDef.readme && !pluginDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const plugin = await api.findPublicOrPrivatePlugin({ type: 'name', name, version })\n\n let message: string\n if (plugin) {\n this.logger.warn('Plugin already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override plugin ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy plugin ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing plugin request body...')\n\n const icon = await this.readProjectFile(pluginDef.icon, 'base64')\n const readme = await this.readProjectFile(pluginDef.readme, 'base64')\n\n const createBody = {\n ...(await apiUtils.prepareCreatePluginBody(pluginDef)),\n ...(await this.preparePluginDependencies(pluginDef, api)),\n public: this._visibility === 'public',\n icon,\n readme,\n code: {\n node: codeCJS,\n browser: codeESM,\n },\n }\n\n const startedMessage = `Deploying plugin ${chalk.bold(name)} v${version}...`\n const successMessage = 'Plugin deployed'\n if (plugin) {\n const updateBody = apiUtils.prepareUpdatePluginBody(\n {\n id: plugin.id,\n ...createBody,\n },\n plugin\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin updates. Skipping deployment...')\n } else {\n await api.client.updatePlugin(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin creation. Skipping deployment...')\n } else {\n await api.client.createPlugin(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private _allowDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n previousVersion: client.Integration | undefined\n ): boolean {\n if (this.argv.allowDeprecated) {\n return true\n }\n\n if (!previousVersion) {\n return false\n }\n\n const versionDiff = semver.diff(integrationDef.version, previousVersion.version)\n if (!versionDiff) {\n return false\n }\n\n return utils.semver.releases.lt(versionDiff, 'major')\n }\n\n private _detectDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n opts: { allowDeprecated?: boolean } = {}\n ) {\n const deprecatedFields: string[] = []\n const { user, channels } = integrationDef\n if (user?.creation?.enabled) {\n deprecatedFields.push('user.creation')\n }\n\n for (const [channelName, channel] of Object.entries(channels ?? {})) {\n if (channel?.conversation?.creation?.enabled) {\n deprecatedFields.push(`channels.${channelName}.creation`)\n }\n }\n\n if (!deprecatedFields.length) {\n return\n }\n\n const errorMessage = `The following fields of the integration's definition are deprecated: ${deprecatedFields.join(\n ', '\n )}`\n\n if (opts.allowDeprecated) {\n this.logger.warn(errorMessage)\n } else {\n throw new errors.BotpressCLIError(errorMessage)\n }\n }\n\n private async _deployBot(\n api: apiUtils.ApiClient,\n botDefinition: sdk.BotDefinition,\n argvBotId: string | undefined,\n argvCreateNew: boolean | undefined\n ) {\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for bot deployments. Skipping deployment...')\n return\n }\n\n const outfile = this.projectPaths.abs.outFileCJS\n const code = await fs.promises.readFile(outfile, 'utf-8')\n\n let bot: client.Bot\n if (argvBotId && argvCreateNew) {\n throw new errors.BotpressCLIError('Cannot specify both --botId and --createNew')\n } else if (argvCreateNew) {\n const confirm = await this.prompt.confirm('Are you sure you want to create a new bot ?')\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n bot = await this._createNewBot(api)\n } else {\n bot = await this._getExistingBot(api, argvBotId)\n\n const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot \"${bot.name}\"?`)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDefinition)),\n ...(await this.prepareBotDependencies(botDefinition, api)),\n id: bot.id,\n code,\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update bot \"${bot.name}\"`)\n })\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition })\n\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _createNewBot(api: apiUtils.ApiClient): Promise<client.Bot> {\n const line = this.logger.line()\n const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n })\n line.success(`Bot created with ID \"${createdBot.id}\" and name \"${createdBot.name}\"`)\n await this.projectCache.set('botId', createdBot.id)\n return createdBot\n }\n\n private async _getExistingBot(api: apiUtils.ApiClient, botId: string | undefined): Promise<client.Bot> {\n const promptedBotId = await this.projectCache.sync('botId', botId, async (defaultId) => {\n const userBots = await api\n .listAllPages(api.client.listBots, (r) => r.bots)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch existing bots')\n })\n\n if (!userBots.length) {\n throw new errors.NoBotsFoundError()\n }\n\n const initial = userBots.find((bot) => bot.id === defaultId)\n\n const prompted = await this.prompt.select('Which bot do you want to deploy?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userBots.map((bot) => ({ title: bot.name, value: bot.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Bot Id')\n }\n\n return prompted\n })\n\n const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not get bot info')\n })\n\n return fetchedBot\n }\n\n private async _manageWorkspaceHandle(\n api: apiUtils.ApiClient,\n integration: sdk.IntegrationDefinition\n ): Promise<\n | {\n integration: sdk.IntegrationDefinition\n workspaceId?: string // Set if user opted to deploy on another available workspace\n }\n | undefined\n > {\n const { name: localName, workspaceHandle: localHandle } = this._parseIntegrationName(integration.name)\n if (!localHandle && api.isBotpressWorkspace) {\n this.logger.debug('Botpress workspace detected; workspace handle omitted')\n return { integration } // botpress has the right to omit workspace handle\n }\n\n const { handle: remoteHandle, name: workspaceName } = await api.getWorkspace().catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch workspace')\n })\n\n if (localHandle && remoteHandle) {\n let workspaceId: string | undefined = undefined\n if (localHandle !== remoteHandle) {\n const remoteWorkspace = await api.findWorkspaceByHandle(localHandle).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list workspaces')\n })\n if (!remoteWorkspace) {\n throw new errors.BotpressCLIError(\n `The integration handle \"${localHandle}\" is not associated with any of your workspaces.`\n )\n }\n this.logger.warn(\n `Your are logged in to workspace \"${workspaceName}\" but integration handle \"${localHandle}\" belongs to \"${remoteWorkspace.name}\".`\n )\n const confirmUseAlternateWorkspace = await this.prompt.confirm(\n 'Do you want to deploy integration on this workspace instead?'\n )\n if (!confirmUseAlternateWorkspace) {\n throw new errors.BotpressCLIError(\n `Cannot deploy integration with handle \"${localHandle}\" on workspace \"${workspaceName}\"`\n )\n }\n\n workspaceId = remoteWorkspace.id\n }\n return { integration, workspaceId }\n }\n\n const workspaceHandleIsMandatoryMsg = 'Cannot deploy integration without workspace handle'\n\n if (!localHandle && remoteHandle) {\n const confirmAddHandle = await this.prompt.confirm(\n `Your current workspace handle is \"${remoteHandle}\". Do you want to use the name \"${remoteHandle}/${localName}\"?`\n )\n if (!confirmAddHandle) {\n this.logger.log('Aborted')\n return\n }\n const newName = `${remoteHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n if (localHandle && !remoteHandle) {\n const { available } = await api.client.checkHandleAvailability({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not check handle availability')\n })\n\n if (!available) {\n throw new errors.BotpressCLIError(`Handle \"${localHandle}\" is not yours and is not available`)\n }\n\n const confirmClaimHandle = await this.prompt.confirm(\n `Handle \"${localHandle}\" is available. Do you want to claim it for your workspace ${workspaceName}?`\n )\n if (!confirmClaimHandle) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n await api.updateWorkspace({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${localHandle}\"`)\n })\n\n this.logger.success(`Handle \"${localHandle}\" is now yours!`)\n return { integration }\n }\n\n this.logger.warn(\"It seems you don't have a workspace handle yet.\")\n let claimedHandle: string | undefined = undefined\n do {\n const prompted = await this.prompt.text('Please enter a workspace handle')\n if (!prompted) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n const { available, suggestions } = await api.client.checkHandleAvailability({ handle: prompted })\n if (!available) {\n this.logger.warn(`Handle \"${prompted}\" is not available. Suggestions: ${suggestions.join(', ')}`)\n continue\n }\n\n claimedHandle = prompted\n await api.updateWorkspace({ handle: claimedHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${claimedHandle}\"`)\n })\n } while (!claimedHandle)\n\n this.logger.success(`Handle \"${claimedHandle}\" is yours!`)\n const newName = `${claimedHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n private _parseIntegrationName = (integrationName: string): { name: string; workspaceHandle?: string } => {\n const parts = integrationName.split('/')\n if (parts.length > 2) {\n throw new errors.BotpressCLIError(\n `Invalid integration name \"${integrationName}\": a single forward slash is allowed`\n )\n }\n if (parts.length === 2) {\n const [workspaceHandle, name] = parts as [string, string]\n return { name, workspaceHandle }\n }\n const [name] = parts as [string]\n return { name }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,UAAqB;AACrB,mBAAkB;AAClB,SAAoB;AACpB,oBAAmB;AACnB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACz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AAAA,OAAM,gBAAgB;AAAA,IACjC;AACA,UAAM,CAAC,IAAI,IAAI;AACf,WAAO,EAAE,KAAK;AAAA,EAChB;AACF;",
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport * as sdk from '@botpress/sdk'\nimport chalk from 'chalk'\nimport * as fs from 'fs'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\nimport * as utils from '../utils'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand } from './project-command'\n\nexport type DeployCommandDefinition = typeof commandDefinitions.deploy\nexport class DeployCommand extends ProjectCommand<DeployCommandDefinition> {\n public async run(): Promise<void> {\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n if (!this.argv.noBuild) {\n await this._runBuild() // This ensures the bundle is always synced with source code\n }\n\n const projectDef = await this.readProjectDefinitionFromFS()\n\n if (projectDef.type === 'integration') {\n return this._deployIntegration(api, projectDef.definition)\n }\n if (projectDef.type === 'interface') {\n return this._deployInterface(api, projectDef.definition)\n }\n if (projectDef.type === 'plugin') {\n return this._deployPlugin(api, projectDef.definition)\n }\n if (projectDef.type === 'bot') {\n return this._deployBot(api, projectDef.definition, this.argv.botId, this.argv.createNewBot)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private async _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private get _visibility(): 'public' | 'private' | 'unlisted' {\n if (this.argv.public && this.argv.visibility === 'private') {\n this.logger.warn('The --public flag is deprecated. Please use \"--visibility public\" instead.')\n return 'public'\n }\n\n if (this.argv.public && this.argv.visibility !== 'private') {\n this.logger.warn('The --public flag and --visibility option are both present. Ignoring the --public flag...')\n }\n\n return this.argv.visibility\n }\n\n private async _deployIntegration(api: apiUtils.ApiClient, integrationDef: sdk.IntegrationDefinition) {\n const res = await this._manageWorkspaceHandle(api, integrationDef)\n if (!res) return\n const { integration: updatedIntegrationDef, workspaceId } = res\n integrationDef = updatedIntegrationDef\n if (workspaceId) {\n api = api.switchWorkspace(workspaceId)\n }\n\n const { name, version } = integrationDef\n\n if (integrationDef.icon && !integrationDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (integrationDef.readme && !integrationDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const integration = await api.findPublicOrPrivateIntegration({ type: 'name', name, version })\n if (integration && integration.workspaceId !== api.workspaceId) {\n throw new errors.BotpressCLIError(\n `Public integration ${name} v${version} is already deployed in another workspace.`\n )\n }\n\n if (integration && integration.visibility !== 'private' && !api.isBotpressWorkspace) {\n throw new errors.BotpressCLIError(\n `Integration ${name} v${version} is already deployed publicly and cannot be updated. Please bump the version.`\n )\n }\n\n let message: string\n if (integration) {\n this.logger.warn('Integration already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override integration ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy integration ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing integration request body...')\n\n const createBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n visibility: this._visibility,\n }\n\n const startedMessage = `Deploying integration ${chalk.bold(name)} v${version}...`\n const successMessage = 'Integration deployed'\n if (integration) {\n const updateBody = apiUtils.prepareUpdateIntegrationBody(\n {\n id: integration.id,\n ...createBody,\n },\n integration\n )\n\n const { secrets: knownSecrets } = integration\n updateBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, { allowDeprecated: true })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration update...')\n\n await api.client.validateIntegrationUpdate(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n } else {\n await api.client.updateIntegration(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n this.logger.debug(`looking for previous version of integration \"${name}\"`)\n const previousVersion = await api.findPreviousIntegrationVersion({ type: 'name', name, version })\n\n if (previousVersion) {\n this.logger.debug(`previous version found: ${previousVersion.version}`)\n } else {\n this.logger.debug('no previous version found')\n }\n\n const knownSecrets = previousVersion?.secrets\n\n createBody.secrets = await this.promptSecrets(integrationDef, this.argv, { knownSecrets })\n this._detectDeprecatedFeatures(integrationDef, {\n allowDeprecated: this._allowDeprecatedFeatures(integrationDef, previousVersion),\n })\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.log('Dry-run mode is active. Simulating integration creation...')\n\n await api.client.validateIntegrationCreation(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n } else {\n await api.client.createIntegration(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create integration \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployInterface(api: apiUtils.ApiClient, interfaceDeclaration: sdk.InterfaceDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for interfaces. Please use \"public\" or \"private\".'\n )\n }\n\n if (interfaceDeclaration.icon && !interfaceDeclaration.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (interfaceDeclaration.readme && !interfaceDeclaration.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const { name, version } = interfaceDeclaration\n const intrface = await api.findPublicOrPrivateInterface({ type: 'name', name, version })\n\n let message: string\n if (intrface) {\n this.logger.warn('Interface already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override interface ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy interface ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n const icon = await this.readProjectFile(interfaceDeclaration.icon, 'base64')\n const readme = await this.readProjectFile(interfaceDeclaration.readme, 'base64')\n\n const createBody = {\n ...(await apiUtils.prepareCreateInterfaceBody(interfaceDeclaration)),\n public: this._visibility === 'public',\n icon,\n readme,\n }\n\n const startedMessage = `Deploying interface ${chalk.bold(name)} v${version}...`\n const successMessage = 'Interface deployed'\n if (intrface) {\n const updateBody = apiUtils.prepareUpdateInterfaceBody(\n {\n id: intrface.id,\n ...createBody,\n },\n intrface\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface updates. Skipping deployment...')\n } else {\n await api.client.updateInterface(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for interface creation. Skipping deployment...')\n } else {\n await api.client.createInterface(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create interface \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private async _deployPlugin(api: apiUtils.ApiClient, pluginDef: sdk.PluginDefinition) {\n if (this._visibility === 'unlisted') {\n throw new errors.BotpressCLIError(\n 'Unlisted visibility is not supported for plugins. Please use \"public\" or \"private\".'\n )\n }\n\n const codeCJS = await fs.promises.readFile(this.projectPaths.abs.outFileCJS, 'utf-8')\n const codeESM = await fs.promises.readFile(this.projectPaths.abs.outFileESM, 'utf-8')\n\n const { name, version } = pluginDef\n\n if (pluginDef.icon && !pluginDef.icon.toLowerCase().endsWith('.svg')) {\n throw new errors.BotpressCLIError('Icon must be an SVG file')\n }\n\n if (pluginDef.readme && !pluginDef.readme.toLowerCase().endsWith('.md')) {\n throw new errors.BotpressCLIError('Readme must be a Markdown file')\n }\n\n const plugin = await api.findPublicOrPrivatePlugin({ type: 'name', name, version })\n\n let message: string\n if (plugin) {\n this.logger.warn('Plugin already exists. If you decide to deploy, it will override the existing one.')\n message = `Are you sure you want to override plugin ${name} v${version}?`\n } else {\n message = `Are you sure you want to deploy plugin ${name} v${version}?`\n }\n\n const confirm = await this.prompt.confirm(message)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n this.logger.debug('Preparing plugin request body...')\n\n const icon = await this.readProjectFile(pluginDef.icon, 'base64')\n const readme = await this.readProjectFile(pluginDef.readme, 'base64')\n\n const createBody = {\n ...(await apiUtils.prepareCreatePluginBody(pluginDef)),\n ...(await this.preparePluginDependencies(pluginDef, api)),\n public: this._visibility === 'public',\n icon,\n readme,\n code: {\n node: codeCJS,\n browser: codeESM,\n },\n }\n\n const startedMessage = `Deploying plugin ${chalk.bold(name)} v${version}...`\n const successMessage = 'Plugin deployed'\n if (plugin) {\n const updateBody = apiUtils.prepareUpdatePluginBody(\n {\n id: plugin.id,\n ...createBody,\n },\n plugin\n )\n\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin updates. Skipping deployment...')\n } else {\n await api.client.updatePlugin(updateBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n } else {\n const line = this.logger.line()\n line.started(startedMessage)\n\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for plugin creation. Skipping deployment...')\n } else {\n await api.client.createPlugin(createBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not create plugin \"${name}\"`)\n })\n }\n\n line.success(successMessage)\n }\n }\n\n private _allowDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n previousVersion: client.Integration | undefined\n ): boolean {\n if (this.argv.allowDeprecated) {\n return true\n }\n\n if (!previousVersion) {\n return false\n }\n\n const versionDiff = semver.diff(integrationDef.version, previousVersion.version)\n if (!versionDiff) {\n return false\n }\n\n return utils.semver.releases.lt(versionDiff, 'major')\n }\n\n private _detectDeprecatedFeatures(\n integrationDef: sdk.IntegrationDefinition,\n opts: { allowDeprecated?: boolean } = {}\n ) {\n const deprecatedFields: string[] = []\n const { user, channels } = integrationDef\n if (user?.creation?.enabled) {\n deprecatedFields.push('user.creation')\n }\n\n for (const [channelName, channel] of Object.entries(channels ?? {})) {\n if (channel?.conversation?.creation?.enabled) {\n deprecatedFields.push(`channels.${channelName}.creation`)\n }\n }\n\n if (!deprecatedFields.length) {\n return\n }\n\n const errorMessage = `The following fields of the integration's definition are deprecated: ${deprecatedFields.join(\n ', '\n )}`\n\n if (opts.allowDeprecated) {\n this.logger.warn(errorMessage)\n } else {\n throw new errors.BotpressCLIError(errorMessage)\n }\n }\n\n private async _deployBot(\n api: apiUtils.ApiClient,\n botDefinition: sdk.BotDefinition,\n argvBotId: string | undefined,\n argvCreateNew: boolean | undefined\n ) {\n if (this.argv.dryRun) {\n this.logger.warn('Dry-run mode is not supported for bot deployments. Skipping deployment...')\n return\n }\n\n const outfile = this.projectPaths.abs.outFileCJS\n const code = await fs.promises.readFile(outfile, 'utf-8')\n\n let bot: client.Bot\n if (argvBotId && argvCreateNew) {\n throw new errors.BotpressCLIError('Cannot specify both --botId and --createNew')\n } else if (argvCreateNew) {\n const confirm = await this.prompt.confirm('Are you sure you want to create a new bot ?')\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n\n bot = await this._createNewBot(api)\n } else {\n bot = await this._getExistingBot(api, argvBotId)\n\n const confirm = await this.prompt.confirm(`Are you sure you want to deploy the bot \"${bot.name}\"?`)\n if (!confirm) {\n this.logger.log('Aborted')\n return\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying bot ${chalk.bold(bot.name)}...`)\n\n const updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDefinition)),\n ...(await this.prepareBotDependencies(botDefinition, api)),\n id: bot.id,\n code,\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update bot \"${bot.name}\"`)\n })\n\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) =>\n this.logger.warn(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n )\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition })\n\n line.success('Bot deployed')\n this.displayWebhookUrls(updatedBot)\n }\n\n private async _createNewBot(api: apiUtils.ApiClient): Promise<client.Bot> {\n const line = this.logger.line()\n const { bot: createdBot } = await api.client.createBot({}).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not create bot')\n })\n line.success(`Bot created with ID \"${createdBot.id}\" and name \"${createdBot.name}\"`)\n await this.projectCache.set('botId', createdBot.id)\n return createdBot\n }\n\n private async _getExistingBot(api: apiUtils.ApiClient, botId: string | undefined): Promise<client.Bot> {\n const promptedBotId = await this.projectCache.sync('botId', botId, async (defaultId) => {\n const userBots = await api\n .listAllPages(api.client.listBots, (r) => r.bots)\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch existing bots')\n })\n\n if (!userBots.length) {\n throw new errors.NoBotsFoundError()\n }\n\n const initial = userBots.find((bot) => bot.id === defaultId)\n\n const prompted = await this.prompt.select('Which bot do you want to deploy?', {\n initial: initial && { title: initial.name, value: initial.id },\n choices: userBots.map((bot) => ({ title: bot.name, value: bot.id })),\n })\n\n if (!prompted) {\n throw new errors.ParamRequiredError('Bot Id')\n }\n\n return prompted\n })\n\n const { bot: fetchedBot } = await api.client.getBot({ id: promptedBotId }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not get bot info')\n })\n\n return fetchedBot\n }\n\n private async _manageWorkspaceHandle(\n api: apiUtils.ApiClient,\n integration: sdk.IntegrationDefinition\n ): Promise<\n | {\n integration: sdk.IntegrationDefinition\n workspaceId?: string // Set if user opted to deploy on another available workspace\n }\n | undefined\n > {\n const { name: localName, workspaceHandle: localHandle } = this._parseIntegrationName(integration.name)\n if (!localHandle && api.isBotpressWorkspace) {\n this.logger.debug('Botpress workspace detected; workspace handle omitted')\n return { integration } // botpress has the right to omit workspace handle\n }\n\n const { handle: remoteHandle, name: workspaceName } = await api.getWorkspace().catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not fetch workspace')\n })\n\n if (localHandle && remoteHandle) {\n let workspaceId: string | undefined = undefined\n if (localHandle !== remoteHandle) {\n const remoteWorkspace = await api.findWorkspaceByHandle(localHandle).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not list workspaces')\n })\n if (!remoteWorkspace) {\n throw new errors.BotpressCLIError(\n `The integration handle \"${localHandle}\" is not associated with any of your workspaces.`\n )\n }\n this.logger.warn(\n `Your are logged in to workspace \"${workspaceName}\" but integration handle \"${localHandle}\" belongs to \"${remoteWorkspace.name}\".`\n )\n const confirmUseAlternateWorkspace = await this.prompt.confirm(\n 'Do you want to deploy integration on this workspace instead?'\n )\n if (!confirmUseAlternateWorkspace) {\n throw new errors.BotpressCLIError(\n `Cannot deploy integration with handle \"${localHandle}\" on workspace \"${workspaceName}\"`\n )\n }\n\n workspaceId = remoteWorkspace.id\n }\n return { integration, workspaceId }\n }\n\n const workspaceHandleIsMandatoryMsg = 'Cannot deploy integration without workspace handle'\n\n if (!localHandle && remoteHandle) {\n const confirmAddHandle = await this.prompt.confirm(\n `Your current workspace handle is \"${remoteHandle}\". Do you want to use the name \"${remoteHandle}/${localName}\"?`\n )\n if (!confirmAddHandle) {\n this.logger.log('Aborted')\n return\n }\n const newName = `${remoteHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n if (localHandle && !remoteHandle) {\n const { available } = await api.client.checkHandleAvailability({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not check handle availability')\n })\n\n if (!available) {\n throw new errors.BotpressCLIError(`Handle \"${localHandle}\" is not yours and is not available`)\n }\n\n const confirmClaimHandle = await this.prompt.confirm(\n `Handle \"${localHandle}\" is available. Do you want to claim it for your workspace ${workspaceName}?`\n )\n if (!confirmClaimHandle) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n await api.updateWorkspace({ handle: localHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${localHandle}\"`)\n })\n\n this.logger.success(`Handle \"${localHandle}\" is now yours!`)\n return { integration }\n }\n\n this.logger.warn(\"It seems you don't have a workspace handle yet.\")\n let claimedHandle: string | undefined = undefined\n do {\n const prompted = await this.prompt.text('Please enter a workspace handle')\n if (!prompted) {\n throw new errors.BotpressCLIError(workspaceHandleIsMandatoryMsg)\n }\n\n const { available, suggestions } = await api.client.checkHandleAvailability({ handle: prompted })\n if (!available) {\n this.logger.warn(`Handle \"${prompted}\" is not available. Suggestions: ${suggestions.join(', ')}`)\n continue\n }\n\n claimedHandle = prompted\n await api.updateWorkspace({ handle: claimedHandle }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not claim handle \"${claimedHandle}\"`)\n })\n } while (!claimedHandle)\n\n this.logger.success(`Handle \"${claimedHandle}\" is yours!`)\n const newName = `${claimedHandle}/${localName}`\n return { integration: new sdk.IntegrationDefinition({ ...integration, name: newName }) }\n }\n\n private _parseIntegrationName = (integrationName: string): { name: string; workspaceHandle?: string } => {\n const parts = integrationName.split('/')\n if (parts.length > 2) {\n throw new errors.BotpressCLIError(\n `Invalid integration name \"${integrationName}\": a single forward slash is allowed`\n )\n }\n if (parts.length === 2) {\n const [workspaceHandle, name] = parts as [string, string]\n return { name, workspaceHandle }\n }\n const [name] = parts as [string]\n return { name }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,UAAqB;AACrB,mBAAkB;AAClB,SAAoB;AACpB,oBAAmB;AACnB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,2BAA6B;AAC7B,6BAA+B;AAGxB,MAAM,sBAAsB,sCAAwC;AAAA,EACzE,MAAa,MAAqB;AAChC,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,QAAI,CAAC,KAAK,KAAK,SAAS;AACtB,YAAM,KAAK,UAAU;AAAA,IACvB;AAEA,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAE1D,QAAI,WAAW,SAAS,eAAe;AACrC,aAAO,KAAK,mBAAmB,KAAK,WAAW,UAAU;AAAA,IAC3D;AACA,QAAI,WAAW,SAAS,aAAa;AACnC,aAAO,KAAK,iBAAiB,KAAK,WAAW,UAAU;AAAA,IACzD;AACA,QAAI,WAAW,SAAS,UAAU;AAChC,aAAO,KAAK,cAAc,KAAK,WAAW,UAAU;AAAA,IACtD;AACA,QAAI,WAAW,SAAS,OAAO;AAC7B,aAAO,KAAK,WAAW,KAAK,WAAW,YAAY,KAAK,KAAK,OAAO,KAAK,KAAK,YAAY;AAAA,IAC5F;AACA,UAAM,IAAI,OAAO,uBAAuB;AAAA,EAC1C;AAAA,EAEA,MAAc,YAAY;AACxB,WAAO,IAAI,kCAAa,KAAK,KAAK,KAAK,QAAQ,KAAK,QAAQ,KAAK,IAAI,EAAE,IAAI;AAAA,EAC7E;AAAA,EAEA,IAAY,cAAiD;AAC3D,QAAI,KAAK,KAAK,UAAU,KAAK,KAAK,eAAe,WAAW;AAC1D,WAAK,OAAO,KAAK,4EAA4E;AAC7F,aA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M,IAAI,gBAAgB,EAAE,QAAQ,cAAc,CAAC,EAAE,MAAM,CAAC,WAAW;AACrE,cAAM,OAAO,iBAAiB,KAAK,QAAQ,2BAA2B,gBAAgB;AAAA,MACxF,CAAC;AAAA,IACH,SAAS,CAAC;AAEV,SAAK,OAAO,QAAQ,WAAW,0BAA0B;AACzD,UAAM,UAAU,GAAG,iBAAiB;AACpC,WAAO,EAAE,aAAa,IAAI,IAAI,sBAAsB,EAAE,GAAG,aAAa,MAAM,QAAQ,CAAC,EAAE;AAAA,EACzF;AAAA,EAEQ,wBAAwB,CAAC,oBAAwE;AACvG,UAAM,QAAQ,gBAAgB,MAAM,GAAG;AACvC,QAAI,MAAM,SAAS,GAAG;AACpB,YAAM,IAAI,OAAO;AAAA,QACf,6BAA6B;AAAA,MAC/B;AAAA,IACF;AACA,QAAI,MAAM,WAAW,GAAG;AACtB,YAAM,CAAC,iBAAiBC,KAAI,IAAI;AAChC,aAAO,EAAE,MAAAA,OAAM,gBAAgB;AAAA,IACjC;AACA,UAAM,CAAC,IAAI,IAAI;AACf,WAAO,EAAE,KAAK;AAAA,EAChB;AACF;",
|
|
6
6
|
"names": ["chalk", "semver", "newName", "name"]
|
|
7
7
|
}
|
|
@@ -73,7 +73,18 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
73
73
|
if (urlParseResult.status === "error") {
|
|
74
74
|
throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`);
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const cachedTunnelId = await this.projectCache.get("tunnelId");
|
|
77
|
+
let tunnelId;
|
|
78
|
+
if (this.argv.tunnelId) {
|
|
79
|
+
tunnelId = this.argv.tunnelId;
|
|
80
|
+
} else if (cachedTunnelId) {
|
|
81
|
+
tunnelId = cachedTunnelId;
|
|
82
|
+
} else {
|
|
83
|
+
tunnelId = uuid.v4();
|
|
84
|
+
}
|
|
85
|
+
if (cachedTunnelId !== tunnelId) {
|
|
86
|
+
await this.projectCache.set("tunnelId", tunnelId);
|
|
87
|
+
}
|
|
77
88
|
const { url: parsedTunnelUrl } = urlParseResult;
|
|
78
89
|
const isSecured = parsedTunnelUrl.protocol === "https" || parsedTunnelUrl.protocol === "wss";
|
|
79
90
|
const wsTunnelUrl = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? "wss" : "ws" });
|
|
@@ -292,10 +303,12 @@ class DevCommand extends import_project_command.ProjectCommand {
|
|
|
292
303
|
const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {
|
|
293
304
|
throw errors.BotpressCLIError.wrap(thrown, "Could not deploy dev bot");
|
|
294
305
|
});
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
306
|
+
this.validateIntegrationRegistration(updatedBot, (failedIntegrations) => {
|
|
307
|
+
throw new errors.BotpressCLIError(
|
|
308
|
+
`Some integrations failed to register:
|
|
309
|
+
${Object.entries(failedIntegrations).map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`).join("\n")}`
|
|
310
|
+
);
|
|
311
|
+
});
|
|
299
312
|
updateLine.success(`Dev Bot deployed with id "${updatedBot.id}" at "${externalUrl}"`);
|
|
300
313
|
updateLine.commit();
|
|
301
314
|
const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/command-implementations/dev-command.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport { TunnelRequest, TunnelResponse } from '@bpinternal/tunnel'\nimport axios, { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport chalk from 'chalk'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand, ProjectDefinition } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\nconst TUNNEL_HELLO_INTERVAL = 5000\nconst FILEWATCHER_DEBOUNCE_MS = 2000\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: ProjectDefinition | undefined = undefined\n\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.type === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n this._initialDef = projectDef\n\n let env: Record<string, string> = {\n ...process.env,\n BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n let defaultPort = DEFAULT_BOT_PORT\n if (this._initialDef.type === 'integration') {\n defaultPort = DEFAULT_INTEGRATION_PORT\n // TODO: store secrets in local cache to avoid prompting every time\n const secretEnvVariables = await this.promptSecrets(this._initialDef.definition, this.argv, { formatEnv: true })\n const nonNullSecretEnvVariables = utils.records.filterValues(secretEnvVariables, utils.guards.is.notNull)\n env = { ...env, ...nonNullSecretEnvVariables }\n }\n\n const port = this.argv.port ?? defaultPort\n\n const urlParseResult = utils.url.parse(this.argv.tunnelUrl)\n if (urlParseResult.status === 'error') {\n throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`)\n }\n\n const tunnelId = uuid.v4()\n\n const { url: parsedTunnelUrl } = urlParseResult\n const isSecured = parsedTunnelUrl.protocol === 'https' || parsedTunnelUrl.protocol === 'wss'\n\n const wsTunnelUrl: string = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? 'wss' : 'ws' })\n const httpTunnelUrl: string = utils.url.format({\n ...parsedTunnelUrl,\n protocol: isSecured ? 'https' : 'http',\n path: `/${tunnelId}`,\n })\n\n let worker: Worker | undefined = undefined\n\n const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger)\n supervisor.events.on('connected', ({ tunnel }) => {\n // prevents the tunnel from closing due to inactivity\n const timer = setInterval(() => {\n if (tunnel.closed) {\n return handleClose()\n }\n tunnel.hello()\n }, TUNNEL_HELLO_INTERVAL)\n const handleClose = (): void => clearInterval(timer)\n tunnel.events.on('close', handleClose)\n\n tunnel.events.on('request', (req) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring request')\n tunnel.send({ requestId: req.id, status: 503, body: 'Worker not ready yet' })\n return\n }\n\n void this._forwardTunnelRequest(`http://localhost:${port}`, req)\n .then((res) => {\n tunnel.send(res)\n })\n .catch((thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, 'An error occurred while handling request')\n this.logger.error(err.message)\n tunnel.send({\n requestId: req.id,\n status: 500,\n body: err.message,\n })\n })\n })\n })\n\n supervisor.events.on('manuallyClosed', () => {\n this.logger.debug('Tunnel manually closed')\n })\n\n await supervisor.start()\n\n await this._runBuild()\n await this._deploy(api, httpTunnelUrl)\n worker = await this._spawnWorker(env, port)\n\n try {\n const watcher = await utils.filewatcher.FileWatcher.watch(\n this.argv.workDir,\n async (events) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring file change event')\n return\n }\n\n const typescriptEvents = events.filter((e) => pathlib.extname(e.path) === '.ts')\n if (typescriptEvents.length === 0) {\n return\n }\n\n this.logger.log('Changes detected, rebuilding')\n await this._restart(api, worker, httpTunnelUrl)\n },\n {\n ignore: [this.projectPaths.abs.outDir],\n debounceMs: FILEWATCHER_DEBOUNCE_MS,\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()])\n\n if (worker.running) {\n await worker.kill()\n }\n await watcher.close()\n supervisor.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev server')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: apiUtils.ApiClient, worker: Worker, tunnelUrl: string) => {\n try {\n await this._runBuild()\n } catch (thrown) {\n const error = errors.BotpressCLIError.wrap(thrown, 'Build failed')\n this.logger.error(error.message)\n return\n }\n\n await this._deploy(api, tunnelUrl)\n await worker.reload()\n }\n\n private _deploy = async (api: apiUtils.ApiClient, tunnelUrl: string) => {\n const projectDef = await this.readProjectDefinitionFromFS()\n\n if (projectDef.type === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n if (projectDef.type === 'integration') {\n this._checkSecrets(projectDef.definition)\n return await this._deployDevIntegration(api, tunnelUrl, projectDef.definition)\n }\n if (projectDef.type === 'bot') {\n return await this._deployDevBot(api, tunnelUrl, projectDef.definition)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private _checkSecrets(integrationDef: sdk.IntegrationDefinition) {\n if (this._initialDef?.type !== 'integration') {\n return\n }\n const initialSecrets = this._initialDef?.definition.secrets ?? {}\n const currentSecrets = integrationDef.secrets ?? {}\n const newSecrets = Object.keys(currentSecrets).filter((s) => !initialSecrets[s])\n if (newSecrets.length > 0) {\n throw new errors.BotpressCLIError('Secrets were added while the server was running. A restart is required.')\n }\n }\n\n private _spawnWorker = async (env: Record<string, string>, port: number) => {\n const outfile = this.projectPaths.abs.outFileCJS\n const importPath = utils.path.toUnix(outfile)\n const code = `require('${importPath}').default.start(${port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n return worker\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployDevIntegration(\n api: apiUtils.ApiClient,\n externalUrl: string,\n integrationDef: sdk.IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: client.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n\n const createIntegrationBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = apiUtils.prepareUpdateIntegrationBody(\n { ...createIntegrationBody, id: integration.id },\n integration\n )\n\n const resp = await api.client.updateIntegration(updateIntegrationBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n } else {\n const resp = await api.client.createIntegration({ ...createIntegrationBody, dev: true }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n }\n\n line.success(`Dev Integration deployed with id \"${integration.id}\" at \"${externalUrl}\"`)\n line.commit()\n\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: apiUtils.ApiClient, externalUrl: string, botDef: sdk.BotDefinition): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: client.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.log('Dev Bot created')\n createLine.commit()\n await this.projectCache.set('devId', bot.id)\n }\n\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDef)),\n ...(await this.prepareBotDependencies(botDef, api)),\n id: bot.id,\n url: externalUrl,\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n const failedIntegrationNames = Object.values(updatedBot.integrations)\n .filter((integration) => integration.enabled && integration.status === 'registration_failed')\n .map(({ name }) => name)\n\n if (failedIntegrationNames.length > 0) {\n throw new errors.BotpressCLIError(`${failedIntegrationNames.join(', ')} integrations failed to register`)\n }\n\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\" at \"${externalUrl}\"`)\n updateLine.commit()\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition: botDef })\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private _forwardTunnelRequest = async (baseUrl: string, request: TunnelRequest): Promise<TunnelResponse> => {\n const axiosConfig = {\n method: request.method,\n url: this._formatLocalUrl(baseUrl, request),\n headers: request.headers,\n data: request.body,\n responseType: 'text',\n validateStatus: () => true,\n } satisfies AxiosRequestConfig\n\n this.logger.debug(`Forwarding request to ${axiosConfig.url}`)\n const response = await axios(axiosConfig)\n this.logger.debug('Sending back response up the tunnel')\n\n return {\n requestId: request.id,\n status: response.status,\n headers: this._getHeaders(response.headers),\n body: response.data,\n }\n }\n\n private _formatLocalUrl = (baseUrl: string, req: TunnelRequest): string => {\n if (req.query) {\n return `${baseUrl}${req.path}?${req.query}`\n }\n return `${baseUrl}${req.path}`\n }\n\n private _getHeaders = (res: AxiosResponse['headers']): TunnelResponse['headers'] => {\n const headers: TunnelResponse['headers'] = {}\n for (const key in res) {\n if (typeof res[key] === 'string' || typeof res[key] === 'number') {\n headers[key] = String(res[key])\n }\n }\n return headers\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAyD;AACzD,mBAAkB;AAClB,cAAyB;AACzB,WAAsB;AACtB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAAkD;AAElD,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAGzB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAA6C;AAAA,EAErD,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,UAAM,aAAa,MAAM,KAAK,4BAA4B;AAC1D,QAAI,WAAW,SAAS,aAAa;AACnC,YAAM,IAAI,OAAO,iBAAiB,+CAA+C;AAAA,IACnF;AACA,SAAK,cAAc;AAEnB,QAAI,MAA8B;AAAA,MAChC,GAAG,QAAQ;AAAA,MACX,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB;AAEA,QAAI,cAAc;AAClB,QAAI,KAAK,YAAY,SAAS,eAAe;AAC3C,oBAAc;AAEd,YAAM,qBAAqB,MAAM,KAAK,cAAc,KAAK,YAAY,YAAY,KAAK,MAAM,EAAE,WAAW,KAAK,CAAC;AAC/G,YAAM,4BAA4B,MAAM,QAAQ,aAAa,oBAAoB,MAAM,OAAO,GAAG,OAAO;AACxG,YAAM,EAAE,GAAG,KAAK,GAAG,0BAA0B;AAAA,IAC/C;AAEA,UAAM,OAAO,KAAK,KAAK,QAAQ;AAE/B,UAAM,iBAAiB,MAAM,IAAI,MAAM,KAAK,KAAK,SAAS;AAC1D,QAAI,eAAe,WAAW,SAAS;AACrC,YAAM,IAAI,OAAO,iBAAiB,uBAAuB,eAAe,OAAO;AAAA,IACjF;AAEA,UAAM,WAAW,KAAK,GAAG;
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport { TunnelRequest, TunnelResponse } from '@bpinternal/tunnel'\nimport axios, { AxiosRequestConfig, AxiosResponse } from 'axios'\nimport chalk from 'chalk'\nimport * as pathlib from 'path'\nimport * as uuid from 'uuid'\nimport * as apiUtils from '../api'\nimport type commandDefinitions from '../command-definitions'\nimport * as errors from '../errors'\nimport * as tables from '../tables'\nimport * as utils from '../utils'\nimport { Worker } from '../worker'\nimport { BuildCommand } from './build-command'\nimport { ProjectCommand, ProjectDefinition } from './project-command'\n\nconst DEFAULT_BOT_PORT = 8075\nconst DEFAULT_INTEGRATION_PORT = 8076\nconst TUNNEL_HELLO_INTERVAL = 5000\nconst FILEWATCHER_DEBOUNCE_MS = 2000\n\nexport type DevCommandDefinition = typeof commandDefinitions.dev\nexport class DevCommand extends ProjectCommand<DevCommandDefinition> {\n private _initialDef: ProjectDefinition | undefined = undefined\n\n public async run(): Promise<void> {\n this.logger.warn('This command is experimental and subject to breaking changes without notice.')\n\n const api = await this.ensureLoginAndCreateClient(this.argv)\n\n const projectDef = await this.readProjectDefinitionFromFS()\n if (projectDef.type === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n this._initialDef = projectDef\n\n let env: Record<string, string> = {\n ...process.env,\n BP_API_URL: api.url,\n BP_TOKEN: api.token,\n }\n\n let defaultPort = DEFAULT_BOT_PORT\n if (this._initialDef.type === 'integration') {\n defaultPort = DEFAULT_INTEGRATION_PORT\n // TODO: store secrets in local cache to avoid prompting every time\n const secretEnvVariables = await this.promptSecrets(this._initialDef.definition, this.argv, { formatEnv: true })\n const nonNullSecretEnvVariables = utils.records.filterValues(secretEnvVariables, utils.guards.is.notNull)\n env = { ...env, ...nonNullSecretEnvVariables }\n }\n\n const port = this.argv.port ?? defaultPort\n\n const urlParseResult = utils.url.parse(this.argv.tunnelUrl)\n if (urlParseResult.status === 'error') {\n throw new errors.BotpressCLIError(`Invalid tunnel URL: ${urlParseResult.error}`)\n }\n\n const cachedTunnelId = await this.projectCache.get('tunnelId')\n\n let tunnelId: string\n if (this.argv.tunnelId) {\n tunnelId = this.argv.tunnelId\n } else if (cachedTunnelId) {\n tunnelId = cachedTunnelId\n } else {\n tunnelId = uuid.v4()\n }\n\n if (cachedTunnelId !== tunnelId) {\n await this.projectCache.set('tunnelId', tunnelId)\n }\n\n const { url: parsedTunnelUrl } = urlParseResult\n const isSecured = parsedTunnelUrl.protocol === 'https' || parsedTunnelUrl.protocol === 'wss'\n\n const wsTunnelUrl: string = utils.url.format({ ...parsedTunnelUrl, protocol: isSecured ? 'wss' : 'ws' })\n const httpTunnelUrl: string = utils.url.format({\n ...parsedTunnelUrl,\n protocol: isSecured ? 'https' : 'http',\n path: `/${tunnelId}`,\n })\n\n let worker: Worker | undefined = undefined\n\n const supervisor = new utils.tunnel.TunnelSupervisor(wsTunnelUrl, tunnelId, this.logger)\n supervisor.events.on('connected', ({ tunnel }) => {\n // prevents the tunnel from closing due to inactivity\n const timer = setInterval(() => {\n if (tunnel.closed) {\n return handleClose()\n }\n tunnel.hello()\n }, TUNNEL_HELLO_INTERVAL)\n const handleClose = (): void => clearInterval(timer)\n tunnel.events.on('close', handleClose)\n\n tunnel.events.on('request', (req) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring request')\n tunnel.send({ requestId: req.id, status: 503, body: 'Worker not ready yet' })\n return\n }\n\n void this._forwardTunnelRequest(`http://localhost:${port}`, req)\n .then((res) => {\n tunnel.send(res)\n })\n .catch((thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, 'An error occurred while handling request')\n this.logger.error(err.message)\n tunnel.send({\n requestId: req.id,\n status: 500,\n body: err.message,\n })\n })\n })\n })\n\n supervisor.events.on('manuallyClosed', () => {\n this.logger.debug('Tunnel manually closed')\n })\n\n await supervisor.start()\n\n await this._runBuild()\n await this._deploy(api, httpTunnelUrl)\n worker = await this._spawnWorker(env, port)\n\n try {\n const watcher = await utils.filewatcher.FileWatcher.watch(\n this.argv.workDir,\n async (events) => {\n if (!worker) {\n this.logger.debug('Worker not ready yet, ignoring file change event')\n return\n }\n\n const typescriptEvents = events.filter((e) => pathlib.extname(e.path) === '.ts')\n if (typescriptEvents.length === 0) {\n return\n }\n\n this.logger.log('Changes detected, rebuilding')\n await this._restart(api, worker, httpTunnelUrl)\n },\n {\n ignore: [this.projectPaths.abs.outDir],\n debounceMs: FILEWATCHER_DEBOUNCE_MS,\n }\n )\n\n await Promise.race([worker.wait(), watcher.wait(), supervisor.wait()])\n\n if (worker.running) {\n await worker.kill()\n }\n await watcher.close()\n supervisor.close()\n } catch (thrown) {\n throw errors.BotpressCLIError.wrap(thrown, 'An error occurred while running the dev server')\n } finally {\n if (worker.running) {\n await worker.kill()\n }\n }\n }\n\n private _restart = async (api: apiUtils.ApiClient, worker: Worker, tunnelUrl: string) => {\n try {\n await this._runBuild()\n } catch (thrown) {\n const error = errors.BotpressCLIError.wrap(thrown, 'Build failed')\n this.logger.error(error.message)\n return\n }\n\n await this._deploy(api, tunnelUrl)\n await worker.reload()\n }\n\n private _deploy = async (api: apiUtils.ApiClient, tunnelUrl: string) => {\n const projectDef = await this.readProjectDefinitionFromFS()\n\n if (projectDef.type === 'interface') {\n throw new errors.BotpressCLIError('This feature is not available for interfaces.')\n }\n if (projectDef.type === 'integration') {\n this._checkSecrets(projectDef.definition)\n return await this._deployDevIntegration(api, tunnelUrl, projectDef.definition)\n }\n if (projectDef.type === 'bot') {\n return await this._deployDevBot(api, tunnelUrl, projectDef.definition)\n }\n throw new errors.UnsupportedProjectType()\n }\n\n private _checkSecrets(integrationDef: sdk.IntegrationDefinition) {\n if (this._initialDef?.type !== 'integration') {\n return\n }\n const initialSecrets = this._initialDef?.definition.secrets ?? {}\n const currentSecrets = integrationDef.secrets ?? {}\n const newSecrets = Object.keys(currentSecrets).filter((s) => !initialSecrets[s])\n if (newSecrets.length > 0) {\n throw new errors.BotpressCLIError('Secrets were added while the server was running. A restart is required.')\n }\n }\n\n private _spawnWorker = async (env: Record<string, string>, port: number) => {\n const outfile = this.projectPaths.abs.outFileCJS\n const importPath = utils.path.toUnix(outfile)\n const code = `require('${importPath}').default.start(${port})`\n const worker = await Worker.spawn(\n {\n type: 'code',\n code,\n env,\n },\n this.logger\n ).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not start dev worker')\n })\n\n return worker\n }\n\n private _runBuild() {\n return new BuildCommand(this.api, this.prompt, this.logger, this.argv).run()\n }\n\n private async _deployDevIntegration(\n api: apiUtils.ApiClient,\n externalUrl: string,\n integrationDef: sdk.IntegrationDefinition\n ): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let integration: client.Integration | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getIntegration({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev integration with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { integration: undefined }\n })\n\n if (resp.integration?.dev) {\n integration = resp.integration\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n const line = this.logger.line()\n line.started(`Deploying dev integration ${chalk.bold(integrationDef.name)}...`)\n\n const createIntegrationBody = {\n ...(await this.prepareCreateIntegrationBody(integrationDef)),\n ...(await this.prepareIntegrationDependencies(integrationDef, api)),\n url: externalUrl,\n }\n\n if (integration) {\n const updateIntegrationBody = apiUtils.prepareUpdateIntegrationBody(\n { ...createIntegrationBody, id: integration.id },\n integration\n )\n\n const resp = await api.client.updateIntegration(updateIntegrationBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not update dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n } else {\n const resp = await api.client.createIntegration({ ...createIntegrationBody, dev: true }).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, `Could not deploy dev integration \"${integrationDef.name}\"`)\n })\n integration = resp.integration\n }\n\n line.success(`Dev Integration deployed with id \"${integration.id}\" at \"${externalUrl}\"`)\n line.commit()\n\n await this.projectCache.set('devId', integration.id)\n }\n\n private async _deployDevBot(api: apiUtils.ApiClient, externalUrl: string, botDef: sdk.BotDefinition): Promise<void> {\n const devId = await this.projectCache.get('devId')\n\n let bot: client.Bot | undefined = undefined\n\n if (devId) {\n const resp = await api.client.getBot({ id: devId }).catch(async (thrown) => {\n const err = errors.BotpressCLIError.wrap(thrown, `Could not find existing dev bot with id \"${devId}\"`)\n this.logger.warn(err.message)\n return { bot: undefined }\n })\n\n if (resp.bot?.dev) {\n bot = resp.bot\n } else {\n await this.projectCache.rm('devId')\n }\n }\n\n if (!bot) {\n const createLine = this.logger.line()\n createLine.started('Creating dev bot...')\n const resp = await api.client\n .createBot({\n dev: true,\n url: externalUrl,\n })\n .catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n bot = resp.bot\n createLine.log('Dev Bot created')\n createLine.commit()\n await this.projectCache.set('devId', bot.id)\n }\n\n const updateLine = this.logger.line()\n updateLine.started('Deploying dev bot...')\n\n const updateBotBody = apiUtils.prepareUpdateBotBody(\n {\n ...(await apiUtils.prepareCreateBotBody(botDef)),\n ...(await this.prepareBotDependencies(botDef, api)),\n id: bot.id,\n url: externalUrl,\n },\n bot\n )\n\n const { bot: updatedBot } = await api.client.updateBot(updateBotBody).catch((thrown) => {\n throw errors.BotpressCLIError.wrap(thrown, 'Could not deploy dev bot')\n })\n\n this.validateIntegrationRegistration(updatedBot, (failedIntegrations) => {\n throw new errors.BotpressCLIError(\n `Some integrations failed to register:\\n${Object.entries(failedIntegrations)\n .map(([key, int]) => `\u2022 ${key}: ${int.statusReason}`)\n .join('\\n')}`\n )\n })\n\n updateLine.success(`Dev Bot deployed with id \"${updatedBot.id}\" at \"${externalUrl}\"`)\n updateLine.commit()\n\n const tablesPublisher = new tables.TablesPublisher({ api, logger: this.logger, prompt: this.prompt })\n await tablesPublisher.deployTables({ botId: updatedBot.id, botDefinition: botDef })\n\n this.displayWebhookUrls(updatedBot)\n }\n\n private _forwardTunnelRequest = async (baseUrl: string, request: TunnelRequest): Promise<TunnelResponse> => {\n const axiosConfig = {\n method: request.method,\n url: this._formatLocalUrl(baseUrl, request),\n headers: request.headers,\n data: request.body,\n responseType: 'text',\n validateStatus: () => true,\n } satisfies AxiosRequestConfig\n\n this.logger.debug(`Forwarding request to ${axiosConfig.url}`)\n const response = await axios(axiosConfig)\n this.logger.debug('Sending back response up the tunnel')\n\n return {\n requestId: request.id,\n status: response.status,\n headers: this._getHeaders(response.headers),\n body: response.data,\n }\n }\n\n private _formatLocalUrl = (baseUrl: string, req: TunnelRequest): string => {\n if (req.query) {\n return `${baseUrl}${req.path}?${req.query}`\n }\n return `${baseUrl}${req.path}`\n }\n\n private _getHeaders = (res: AxiosResponse['headers']): TunnelResponse['headers'] => {\n const headers: TunnelResponse['headers'] = {}\n for (const key in res) {\n if (typeof res[key] === 'string' || typeof res[key] === 'number') {\n headers[key] = String(res[key])\n }\n }\n return headers\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAyD;AACzD,mBAAkB;AAClB,cAAyB;AACzB,WAAsB;AACtB,eAA0B;AAE1B,aAAwB;AACxB,aAAwB;AACxB,YAAuB;AACvB,oBAAuB;AACvB,2BAA6B;AAC7B,6BAAkD;AAElD,MAAM,mBAAmB;AACzB,MAAM,2BAA2B;AACjC,MAAM,wBAAwB;AAC9B,MAAM,0BAA0B;AAGzB,MAAM,mBAAmB,sCAAqC;AAAA,EAC3D,cAA6C;AAAA,EAErD,MAAa,MAAqB;AAChC,SAAK,OAAO,KAAK,8EAA8E;AAE/F,UAAM,MAAM,MAAM,KAAK,2BAA2B,KAAK,IAAI;AAE3D,UAAM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A,EAEQ,kBAAkB,CAAC,SAAiB,QAA+B;AACzE,QAAI,IAAI,OAAO;AACb,aAAO,GAAG,UAAU,IAAI,QAAQ,IAAI;AAAA,IACtC;AACA,WAAO,GAAG,UAAU,IAAI;AAAA,EAC1B;AAAA,EAEQ,cAAc,CAAC,QAA6D;AAClF,UAAM,UAAqC,CAAC;AAC5C,eAAW,OAAO,KAAK;AACrB,UAAI,OAAO,IAAI,GAAG,MAAM,YAAY,OAAO,IAAI,GAAG,MAAM,UAAU;AAChE,gBAAQ,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC;AAAA,MAChC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["chalk", "axios"]
|
|
7
7
|
}
|
|
@@ -423,6 +423,17 @@ class ProjectCommand extends import_global_command.GlobalCommand {
|
|
|
423
423
|
this.logger.debug(`Failed to check if sdk is up to date: ${err.message}`);
|
|
424
424
|
}
|
|
425
425
|
};
|
|
426
|
+
validateIntegrationRegistration(updatedBot, onFailCallback) {
|
|
427
|
+
let failedIntegrations = {};
|
|
428
|
+
for (const [integrationName, integration] of Object.entries(updatedBot.integrations)) {
|
|
429
|
+
if (integration.status === "registration_failed") {
|
|
430
|
+
failedIntegrations = { ...failedIntegrations, [integrationName]: integration };
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (Object.keys(failedIntegrations).length > 0) {
|
|
434
|
+
onFailCallback(failedIntegrations);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
426
437
|
}
|
|
427
438
|
// Annotate the CommonJS export names for ESM import in node:
|
|
428
439
|
0 && (module.exports = {
|
|
@@ -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 chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { validateIntegrationDefinition, 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 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 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 absWorkingDir: abs.workDir,\n entrypoint: rel.integrationDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.IntegrationDefinition }>(artifact.text)\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 absWorkingDir: abs.workDir,\n entrypoint: rel.interfaceDefinition,\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 absWorkingDir: abs.workDir,\n entrypoint: rel.botDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.BotDefinition }>(artifact.text)\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 absWorkingDir: abs.workDir,\n entrypoint: rel.pluginDefinition,\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 prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n const partialBody = await apiUtils.prepareCreateIntegrationBody(integrationDef)\n\n let code: string | undefined = undefined\n if (fs.existsSync(this.projectPaths.abs.outFileCJS)) {\n code = await this.readProjectFile(this.projectPaths.abs.outFileCJS)\n }\n\n const icon = await this.readProjectFile(integrationDef.icon, 'base64')\n const readme = await this.readProjectFile(integrationDef.readme, 'base64')\n const extractScript = await this.readProjectFile(integrationDef.identifier?.extractScript)\n const fallbackHandlerScript = await this.readProjectFile(integrationDef.identifier?.fallbackHandlerScript)\n return {\n ...partialBody,\n code,\n icon,\n readme,\n identifier: {\n extractScript,\n fallbackHandlerScript,\n },\n configuration: integrationDef.configuration\n ? {\n schema: await utils.schema.mapZodToJsonSchema(integrationDef.configuration),\n identifier: {\n required: integrationDef.configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(\n integrationDef.configuration.identifier?.linkTemplateScript\n ),\n },\n }\n : undefined,\n configurations: integrationDef.configurations\n ? await utils.records.mapValuesAsync(integrationDef.configurations, async (configuration) => ({\n title: configuration.title,\n description: configuration.description,\n schema: await utils.schema.mapZodToJsonSchema(configuration),\n identifier: {\n required: configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(configuration.identifier?.linkTemplateScript),\n },\n }))\n : undefined,\n }\n }\n\n protected async prepareBotDependencies(\n botDef: sdk.BotDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.UpdateBotRequestBody>> {\n const integrations = await this._fetchDependencies(botDef.integrations ?? {}, ({ name, version }) =>\n api.getPublicOrPrivateIntegration({ type: 'name', name, version })\n )\n\n const plugins = await this._fetchDependencies(\n botDef.plugins ?? {},\n async ({ name, version }) => await api.getPublicOrPrivatePlugin({ type: 'name', name, version })\n )\n\n const pluginsWithBackingIntegrations = await utils.records.mapValuesAsync(plugins, async (plugin) => ({\n ...plugin,\n interfaces: await this._fetchDependencies(\n plugin.interfaces ?? {},\n async (interfaceExtension) => await api.getPublicOrPrivateIntegration({ ...interfaceExtension, type: 'name' })\n ),\n }))\n\n return {\n integrations: _(integrations)\n .keyBy((i) => i.id)\n .mapValues(\n ({ enabled, configurationType, configuration, disabledChannels }) =>\n ({\n enabled,\n configurationType,\n configuration,\n disabledChannels,\n }) satisfies NonNullable<apiUtils.UpdateBotRequestBody['integrations']>[string]\n )\n .value(),\n plugins: utils.records.mapValues(pluginsWithBackingIntegrations, (plugin) => ({\n ...plugin,\n interfaces: utils.records.mapValues(plugin.interfaces ?? {}, (iface) => ({\n ...iface,\n integrationId: iface.id,\n })),\n })),\n }\n }\n\n protected async prepareIntegrationDependencies(\n integrationDef: sdk.IntegrationDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreateIntegrationRequestBody>> {\n const interfaces = await this._fetchDependencies(integrationDef.interfaces ?? {}, ({ name, version }) =>\n api.getPublicInterface({ type: 'name', name, version })\n )\n return { interfaces }\n }\n\n protected async preparePluginDependencies(\n pluginDef: sdk.PluginDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreatePluginRequestBody>> {\n const integrations = await this._fetchDependencies(pluginDef.integrations ?? {}, ({ name, version }) =>\n api.getPublicOrPrivateIntegration({ type: 'name', name, version })\n )\n const interfaces = await this._fetchDependencies(pluginDef.interfaces ?? {}, ({ name, version }) =>\n api.getPublicInterface({ type: 'name', name, version })\n )\n return {\n dependencies: {\n integrations,\n interfaces,\n },\n }\n }\n\n private _fetchDependencies = async <T extends { id?: string; name: string; version: string }>(\n deps: Record<string, T>,\n fetcher: (dep: T) => Promise<{ id: string }>\n ): Promise<Record<string, T & { id: string }>> => {\n const isRemote = (dep: T): dep is T & { id: string } => dep.id !== undefined\n return utils.records.mapValuesAsync(deps, async (dep): Promise<T & { id: string }> => {\n if (isRemote(dep)) {\n return dep\n }\n const { id } = await fetcher(dep)\n return { ...dep, id }\n })\n }\n\n protected readProjectFile = async (\n filePath: string | undefined,\n encoding: BufferEncoding = 'utf-8'\n ): 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, encoding).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,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;AACnB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,iBAAqE;AAErE,YAAuB;AACvB,4BAA8B;AAoB9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM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,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;",
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport type { YargsConfig } from '@bpinternal/yargs-extra'\nimport chalk from 'chalk'\nimport fs from 'fs'\nimport _ from 'lodash'\nimport semver from 'semver'\nimport * as apiUtils from '../api'\nimport * as codegen from '../code-generation'\nimport * as config from '../config'\nimport * as consts from '../consts'\nimport * as errors from '../errors'\nimport { validateIntegrationDefinition, 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; tunnelId: string }\n\ntype ConfigurableProjectPaths = { workDir: string }\ntype ConstantProjectPaths = typeof consts.fromWorkDir\ntype AllProjectPaths = ConfigurableProjectPaths & ConstantProjectPaths\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\ntype UpdatedBot = client.Bot\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 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 absWorkingDir: abs.workDir,\n entrypoint: rel.integrationDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read integration definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.IntegrationDefinition }>(artifact.text)\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 absWorkingDir: abs.workDir,\n entrypoint: rel.interfaceDefinition,\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 absWorkingDir: abs.workDir,\n entrypoint: rel.botDefinition,\n })\n\n const artifact = outputFiles[0]\n if (!artifact) {\n throw new errors.BotpressCLIError('Could not read bot definition')\n }\n\n const { default: definition } = utils.require.requireJsCode<{ default: sdk.BotDefinition }>(artifact.text)\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 absWorkingDir: abs.workDir,\n entrypoint: rel.pluginDefinition,\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 prepareCreateIntegrationBody(\n integrationDef: sdk.IntegrationDefinition\n ): Promise<apiUtils.CreateIntegrationRequestBody> {\n const partialBody = await apiUtils.prepareCreateIntegrationBody(integrationDef)\n\n let code: string | undefined = undefined\n if (fs.existsSync(this.projectPaths.abs.outFileCJS)) {\n code = await this.readProjectFile(this.projectPaths.abs.outFileCJS)\n }\n\n const icon = await this.readProjectFile(integrationDef.icon, 'base64')\n const readme = await this.readProjectFile(integrationDef.readme, 'base64')\n const extractScript = await this.readProjectFile(integrationDef.identifier?.extractScript)\n const fallbackHandlerScript = await this.readProjectFile(integrationDef.identifier?.fallbackHandlerScript)\n return {\n ...partialBody,\n code,\n icon,\n readme,\n identifier: {\n extractScript,\n fallbackHandlerScript,\n },\n configuration: integrationDef.configuration\n ? {\n schema: await utils.schema.mapZodToJsonSchema(integrationDef.configuration),\n identifier: {\n required: integrationDef.configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(\n integrationDef.configuration.identifier?.linkTemplateScript\n ),\n },\n }\n : undefined,\n configurations: integrationDef.configurations\n ? await utils.records.mapValuesAsync(integrationDef.configurations, async (configuration) => ({\n title: configuration.title,\n description: configuration.description,\n schema: await utils.schema.mapZodToJsonSchema(configuration),\n identifier: {\n required: configuration.identifier?.required,\n linkTemplateScript: await this.readProjectFile(configuration.identifier?.linkTemplateScript),\n },\n }))\n : undefined,\n }\n }\n\n protected async prepareBotDependencies(\n botDef: sdk.BotDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.UpdateBotRequestBody>> {\n const integrations = await this._fetchDependencies(botDef.integrations ?? {}, ({ name, version }) =>\n api.getPublicOrPrivateIntegration({ type: 'name', name, version })\n )\n\n const plugins = await this._fetchDependencies(\n botDef.plugins ?? {},\n async ({ name, version }) => await api.getPublicOrPrivatePlugin({ type: 'name', name, version })\n )\n\n const pluginsWithBackingIntegrations = await utils.records.mapValuesAsync(plugins, async (plugin) => ({\n ...plugin,\n interfaces: await this._fetchDependencies(\n plugin.interfaces ?? {},\n async (interfaceExtension) => await api.getPublicOrPrivateIntegration({ ...interfaceExtension, type: 'name' })\n ),\n }))\n\n return {\n integrations: _(integrations)\n .keyBy((i) => i.id)\n .mapValues(\n ({ enabled, configurationType, configuration, disabledChannels }) =>\n ({\n enabled,\n configurationType,\n configuration,\n disabledChannels,\n }) satisfies NonNullable<apiUtils.UpdateBotRequestBody['integrations']>[string]\n )\n .value(),\n plugins: utils.records.mapValues(pluginsWithBackingIntegrations, (plugin) => ({\n ...plugin,\n interfaces: utils.records.mapValues(plugin.interfaces ?? {}, (iface) => ({\n ...iface,\n integrationId: iface.id,\n })),\n })),\n }\n }\n\n protected async prepareIntegrationDependencies(\n integrationDef: sdk.IntegrationDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreateIntegrationRequestBody>> {\n const interfaces = await this._fetchDependencies(integrationDef.interfaces ?? {}, ({ name, version }) =>\n api.getPublicInterface({ type: 'name', name, version })\n )\n return { interfaces }\n }\n\n protected async preparePluginDependencies(\n pluginDef: sdk.PluginDefinition,\n api: apiUtils.ApiClient\n ): Promise<Partial<apiUtils.CreatePluginRequestBody>> {\n const integrations = await this._fetchDependencies(pluginDef.integrations ?? {}, ({ name, version }) =>\n api.getPublicOrPrivateIntegration({ type: 'name', name, version })\n )\n const interfaces = await this._fetchDependencies(pluginDef.interfaces ?? {}, ({ name, version }) =>\n api.getPublicInterface({ type: 'name', name, version })\n )\n return {\n dependencies: {\n integrations,\n interfaces,\n },\n }\n }\n\n private _fetchDependencies = async <T extends { id?: string; name: string; version: string }>(\n deps: Record<string, T>,\n fetcher: (dep: T) => Promise<{ id: string }>\n ): Promise<Record<string, T & { id: string }>> => {\n const isRemote = (dep: T): dep is T & { id: string } => dep.id !== undefined\n return utils.records.mapValuesAsync(deps, async (dep): Promise<T & { id: string }> => {\n if (isRemote(dep)) {\n return dep\n }\n const { id } = await fetcher(dep)\n return { ...dep, id }\n })\n }\n\n protected readProjectFile = async (\n filePath: string | undefined,\n encoding: BufferEncoding = 'utf-8'\n ): 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, encoding).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 protected validateIntegrationRegistration(\n updatedBot: UpdatedBot,\n onFailCallback: (failedIntegrations: UpdatedBot['integrations']) => void\n ) {\n let failedIntegrations: UpdatedBot['integrations'] = {}\n for (const [integrationName, integration] of Object.entries(updatedBot.integrations)) {\n if (integration.status === 'registration_failed') {\n failedIntegrations = { ...failedIntegrations, [integrationName]: integration }\n }\n }\n if (Object.keys(failedIntegrations).length > 0) {\n onFailCallback(failedIntegrations)\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAkB;AAClB,gBAAe;AACf,oBAAc;AACd,oBAAmB;AACnB,eAA0B;AAC1B,cAAyB;AAEzB,aAAwB;AACxB,aAAwB;AACxB,iBAAqE;AAErE,YAAuB;AACvB,4BAA8B;AAsB9B,MAAM,qBAAqB,MAAM,KAAK,UAAiC;AAAA,EAC9D,YAAY,MAA6C;AAC9D,UAAM,aAAa,MAAM,KAAK,aAAa,MAAM,KAAK,IAAI,GAAG,KAAK,OAAO;AACzE,UAAM;AAAA,MACJ,SAAS;AAAA,MACT,GAAG,cAAAA,QAAE,UAAU,OAAO,aAAa,CAAC,MAAM,MAAM,KAAK,aAAa,YAAY,CAAC,CAAC;AAAA,IAClF,CAAC;AAAA,EACH;AACF;AAEO,MAAe,uBAA2D,oCAAiB;AAAA,EAChG,MAAyB,YAAY;AACnC,UAAM,MAAM,UAAU;AACtB,UAAM,KAAK,iBAAiB;AAAA,EAC9B;AAAA,EAEA,IAAc,eAAe;AAC3B,WAAO,IAAI,aAAa,KAAK,IAAI;AAAA,EACnC;AAAA,EAEA,IAAc,eAAe;AAC3B,WAAO,IAAI,MAAM,MAAM,gBAA8B,KAAK,aAAa,IAAI,gBAAgB;AAAA,EAC7F;AAAA,EAEA,MAAgB,8BAA0D;AACxE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,OAAO,KAAK,kBAAkB,EAAE,SAAS,GAAG;AAC9C,qBAAe,kBAAkB;AAAA,IACnC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["_", "fs", "chalk", "semver"]
|
|
7
7
|
}
|
package/dist/config.js
CHANGED
|
@@ -211,6 +211,10 @@ const devSchema = {
|
|
|
211
211
|
type: "string",
|
|
212
212
|
description: "The tunnel HTTP URL to use",
|
|
213
213
|
default: consts.defaultTunnelUrl
|
|
214
|
+
},
|
|
215
|
+
tunnelId: {
|
|
216
|
+
type: "string",
|
|
217
|
+
description: "The tunnel ID to use. The ID will be generated if not specified"
|
|
214
218
|
}
|
|
215
219
|
};
|
|
216
220
|
const addSchema = {
|
package/dist/config.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/config.ts"],
|
|
4
|
-
"sourcesContent": ["import * as consts from './consts'\nimport { ProjectTemplates } from './project-templates'\nimport type { CommandOption, CommandSchema } from './typings'\n\n// command options\n\nconst port = {\n type: 'number',\n description: 'The port to use',\n} satisfies CommandOption\n\nconst workDir = {\n type: 'string',\n description: 'The path to the project',\n default: consts.defaultWorkDir,\n} satisfies CommandOption\n\nconst noBuild = {\n type: 'boolean',\n description: 'Skip the build step',\n default: false,\n} satisfies CommandOption\n\nconst dryRun = {\n type: 'boolean',\n description: 'Ask the API not to perform the actual operation',\n default: false,\n} as const satisfies CommandOption\n\nconst apiUrl = {\n type: 'string',\n description: 'The URL of the Botpress server',\n} satisfies CommandOption\n\nconst token = {\n type: 'string',\n description: 'You Personal Access Token ',\n} satisfies CommandOption\n\nconst workspaceId = {\n type: 'string',\n description: 'The Workspace Id to deploy to',\n} satisfies CommandOption\n\nconst secrets = {\n type: 'string',\n description: 'Values for the integration secrets',\n array: true,\n default: [],\n} satisfies CommandOption\n\nconst botRef = {\n type: 'string',\n description: 'The bot ID. Bot Name is not supported.',\n demandOption: true,\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst packageType = {\n type: 'string',\n description:\n 'Either an integration or an interface; helps disambiguate the package type in case both an integration and an interface have the same reference.',\n choices: ['integration', 'interface', 'plugin'] as const,\n} satisfies CommandOption\n\nconst packageRef = {\n type: 'string',\n description:\n 'The package ID or name with optional version. The package can be either an integration or an interface. Ex: teams, teams@0.2.0, llm@5.1.0',\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst integrationRef = {\n ...packageRef,\n demandOption: true,\n description: 'The integration ID or name with optional version. Ex: teams or teams@0.2.0',\n} satisfies CommandOption\n\nconst interfaceRef = {\n ...packageRef,\n demandOption: true,\n description: 'The interface ID or name and version. Ex: llm@5.1.0',\n} satisfies CommandOption\n\nconst pluginRef = {\n ...packageRef,\n demandOption: true,\n description: 'The plugin ID or name and version. Ex: knowledge@0.0.1',\n} satisfies CommandOption\n\nconst sourceMap = { type: 'boolean', description: 'Generate sourcemaps', default: false } satisfies CommandOption\n\nconst minify = { type: 'boolean', description: 'Minify the bundled code', default: true } satisfies CommandOption\n\nconst dev = {\n type: 'boolean',\n description: 'List only dev bots / dev integrations',\n default: false,\n} satisfies CommandOption\n\n// base schemas\n\nconst globalSchema = {\n verbose: {\n type: 'boolean',\n description: 'Enable verbose logging',\n alias: 'v',\n default: false,\n },\n confirm: {\n type: 'boolean',\n description: 'Confirm all prompts',\n alias: 'y',\n default: false,\n },\n json: {\n type: 'boolean',\n description: 'Prevent logging anything else than raw json in stdout. Useful for piping output to other tools',\n default: false,\n },\n botpressHome: {\n type: 'string',\n description: 'The path to the Botpress home directory',\n default: consts.defaultBotpressHome,\n },\n profile: {\n type: 'string',\n description: 'The CLI profile defined in the $BP_BOTPRESS_HOME/profiles.json',\n alias: 'p',\n },\n} satisfies CommandSchema\n\nconst projectSchema = {\n ...globalSchema,\n workDir,\n} satisfies CommandSchema\n\nconst credentialsSchema = {\n apiUrl,\n workspaceId,\n token,\n} satisfies CommandSchema\n\nconst secretsSchema = {\n secrets,\n} satisfies CommandSchema\n\n// command schemas\n\nconst generateSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst bundleSchema = {\n ...projectSchema,\n sourceMap,\n minify,\n} satisfies CommandSchema\n\nconst buildSchema = {\n ...projectSchema,\n sourceMap,\n minify,\n} satisfies CommandSchema\n\nconst readSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst serveSchema = {\n ...projectSchema,\n ...secretsSchema,\n port,\n} satisfies CommandSchema\n\nconst deploySchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n botId: { type: 'string', description: 'The bot ID to deploy. Only used when deploying a bot' },\n noBuild,\n dryRun,\n createNewBot: { type: 'boolean', description: 'Create a new bot when deploying. Only used when deploying a bot' },\n sourceMap,\n minify,\n visibility: {\n type: 'string',\n choices: ['public', 'private', 'unlisted'] as const,\n description:\n 'The visibility of the project. By default, projects are always private. Unlisted visibility is only supported for integrations.',\n default: 'private',\n },\n public: {\n type: 'boolean',\n description: 'DEPRECATED: Please use \"--visibility public\" instead.',\n default: false,\n deprecated: true,\n } satisfies CommandOption,\n allowDeprecated: {\n type: 'boolean',\n description: 'Allow deprecated features in the project',\n default: false,\n },\n} as const satisfies CommandSchema\n\nconst devSchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n sourceMap,\n minify,\n port,\n tunnelUrl: {\n type: 'string',\n description: 'The tunnel HTTP URL to use',\n default: consts.defaultTunnelUrl,\n },\n} satisfies CommandSchema\n\nconst addSchema = {\n ...globalSchema,\n ...credentialsSchema,\n packageRef,\n packageType,\n installPath: {\n type: 'string',\n description: 'The path where to install the package',\n default: consts.defaultInstallPath,\n },\n useDev: {\n type: 'boolean',\n description: 'If a dev version of the package is found, use it',\n default: false,\n },\n} satisfies CommandSchema\n\nconst loginSchema = {\n ...globalSchema,\n token,\n workspaceId,\n apiUrl: { ...apiUrl, default: consts.defaultBotpressApiUrl },\n} satisfies CommandSchema\n\nconst logoutSchema = {\n ...globalSchema,\n} satisfies CommandSchema\n\nconst createBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name of the bot to create' },\n ifNotExists: {\n type: 'boolean',\n description: 'Do not create if a bot with the same name already exists',\n default: false,\n },\n} satisfies CommandSchema\n\nconst getBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n botRef,\n} satisfies CommandSchema\n\nconst deleteBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n botRef,\n} satisfies CommandSchema\n\nconst listBotsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n dev,\n} satisfies CommandSchema\n\nconst getIntegrationSchema = {\n ...globalSchema,\n ...credentialsSchema,\n integrationRef,\n} satisfies CommandSchema\n\nconst listIntegrationsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name filter when listing integrations' },\n versionNumber: { type: 'string', description: 'The version filter when listing integrations' },\n dev,\n} satisfies CommandSchema\n\nconst deleteIntegrationSchema = {\n ...globalSchema,\n ...credentialsSchema,\n integrationRef,\n} satisfies CommandSchema\n\nconst getInterfaceSchema = {\n ...globalSchema,\n ...credentialsSchema,\n interfaceRef,\n} satisfies CommandSchema\n\nconst listInterfacesSchema = {\n ...globalSchema,\n ...credentialsSchema,\n} satisfies CommandSchema\n\nconst deleteInterfaceSchema = {\n ...globalSchema,\n ...credentialsSchema,\n interfaceRef,\n} satisfies CommandSchema\n\nconst getPluginSchema = {\n ...globalSchema,\n ...credentialsSchema,\n pluginRef,\n} satisfies CommandSchema\n\nconst listPluginsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name filter when listing plugins' },\n versionNumber: { type: 'string', description: 'The version filter when listing plugins' },\n} satisfies CommandSchema\n\nconst deletePluginSchema = {\n ...globalSchema,\n ...credentialsSchema,\n pluginRef,\n} satisfies CommandSchema\n\nconst initSchema = {\n ...globalSchema,\n workDir,\n type: { type: 'string', choices: ['bot', 'integration', 'plugin'] as const },\n template: {\n type: 'string',\n choices: ProjectTemplates.getAllChoices(),\n description: 'The template to use',\n },\n name: { type: 'string', description: 'The name of the project' },\n} satisfies CommandSchema\n\nconst lintSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst chatSchema = {\n ...globalSchema,\n ...credentialsSchema,\n chatApiUrl: {\n type: 'string',\n description: 'The URL of the chat server',\n },\n botId: {\n type: 'string',\n positional: true,\n idx: 0,\n description: 'The bot ID to chat with',\n },\n} satisfies CommandSchema\n\nconst listProfilesSchema = {\n ...globalSchema,\n} satisfies CommandSchema\n\nconst activeProfileSchema = {\n ...globalSchema,\n} satisfies CommandSchema\n\nconst useProfileSchema = {\n ...globalSchema,\n profileToUse: {\n type: 'string',\n description: 'The CLI profile defined in the $BP_BOTPRESS_HOME/profiles.json',\n positional: true,\n idx: 0,\n },\n} satisfies CommandSchema\n\n// exports\n\nexport const schemas = {\n global: globalSchema,\n project: projectSchema,\n credentials: credentialsSchema,\n secrets: secretsSchema,\n login: loginSchema,\n logout: logoutSchema,\n createBot: createBotSchema,\n getBot: getBotSchema,\n deleteBot: deleteBotSchema,\n listBots: listBotsSchema,\n getIntegration: getIntegrationSchema,\n listIntegrations: listIntegrationsSchema,\n deleteIntegration: deleteIntegrationSchema,\n getInterface: getInterfaceSchema,\n listInterfaces: listInterfacesSchema,\n deleteInterface: deleteInterfaceSchema,\n getPlugin: getPluginSchema,\n listPlugins: listPluginsSchema,\n deletePlugin: deletePluginSchema,\n init: initSchema,\n generate: generateSchema,\n bundle: bundleSchema,\n build: buildSchema,\n read: readSchema,\n serve: serveSchema,\n deploy: deploySchema,\n add: addSchema,\n dev: devSchema,\n lint: lintSchema,\n chat: chatSchema,\n listProfiles: listProfilesSchema,\n activeProfile: activeProfileSchema,\n useProfile: useProfileSchema,\n} as const\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,+BAAiC;AAKjC,MAAM,OAAO;AAAA,EACX,MAAM;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,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,aAAa;AAAA,EACf;AACF;AAEA,MAAM,qBAAqB;AAAA,EACzB,GAAG;AACL;AAEA,MAAM,sBAAsB;AAAA,EAC1B,GAAG;AACL;AAEA,MAAM,mBAAmB;AAAA,EACvB,GAAG;AAAA,EACH,cAAc;AAAA,IACZ,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,KAAK;AAAA,EACP;AACF;AAIO,MAAM,UAAU;AAAA,EACrB,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,aAAa;AAAA,EACb,SAAS;AAAA,EACT,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,kBAAkB;AAAA,EAClB,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,cAAc;AAAA,EACd,eAAe;AAAA,EACf,YAAY;AACd;",
|
|
4
|
+
"sourcesContent": ["import * as consts from './consts'\nimport { ProjectTemplates } from './project-templates'\nimport type { CommandOption, CommandSchema } from './typings'\n\n// command options\n\nconst port = {\n type: 'number',\n description: 'The port to use',\n} satisfies CommandOption\n\nconst workDir = {\n type: 'string',\n description: 'The path to the project',\n default: consts.defaultWorkDir,\n} satisfies CommandOption\n\nconst noBuild = {\n type: 'boolean',\n description: 'Skip the build step',\n default: false,\n} satisfies CommandOption\n\nconst dryRun = {\n type: 'boolean',\n description: 'Ask the API not to perform the actual operation',\n default: false,\n} as const satisfies CommandOption\n\nconst apiUrl = {\n type: 'string',\n description: 'The URL of the Botpress server',\n} satisfies CommandOption\n\nconst token = {\n type: 'string',\n description: 'You Personal Access Token ',\n} satisfies CommandOption\n\nconst workspaceId = {\n type: 'string',\n description: 'The Workspace Id to deploy to',\n} satisfies CommandOption\n\nconst secrets = {\n type: 'string',\n description: 'Values for the integration secrets',\n array: true,\n default: [],\n} satisfies CommandOption\n\nconst botRef = {\n type: 'string',\n description: 'The bot ID. Bot Name is not supported.',\n demandOption: true,\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst packageType = {\n type: 'string',\n description:\n 'Either an integration or an interface; helps disambiguate the package type in case both an integration and an interface have the same reference.',\n choices: ['integration', 'interface', 'plugin'] as const,\n} satisfies CommandOption\n\nconst packageRef = {\n type: 'string',\n description:\n 'The package ID or name with optional version. The package can be either an integration or an interface. Ex: teams, teams@0.2.0, llm@5.1.0',\n positional: true,\n idx: 0,\n} satisfies CommandOption\n\nconst integrationRef = {\n ...packageRef,\n demandOption: true,\n description: 'The integration ID or name with optional version. Ex: teams or teams@0.2.0',\n} satisfies CommandOption\n\nconst interfaceRef = {\n ...packageRef,\n demandOption: true,\n description: 'The interface ID or name and version. Ex: llm@5.1.0',\n} satisfies CommandOption\n\nconst pluginRef = {\n ...packageRef,\n demandOption: true,\n description: 'The plugin ID or name and version. Ex: knowledge@0.0.1',\n} satisfies CommandOption\n\nconst sourceMap = { type: 'boolean', description: 'Generate sourcemaps', default: false } satisfies CommandOption\n\nconst minify = { type: 'boolean', description: 'Minify the bundled code', default: true } satisfies CommandOption\n\nconst dev = {\n type: 'boolean',\n description: 'List only dev bots / dev integrations',\n default: false,\n} satisfies CommandOption\n\n// base schemas\n\nconst globalSchema = {\n verbose: {\n type: 'boolean',\n description: 'Enable verbose logging',\n alias: 'v',\n default: false,\n },\n confirm: {\n type: 'boolean',\n description: 'Confirm all prompts',\n alias: 'y',\n default: false,\n },\n json: {\n type: 'boolean',\n description: 'Prevent logging anything else than raw json in stdout. Useful for piping output to other tools',\n default: false,\n },\n botpressHome: {\n type: 'string',\n description: 'The path to the Botpress home directory',\n default: consts.defaultBotpressHome,\n },\n profile: {\n type: 'string',\n description: 'The CLI profile defined in the $BP_BOTPRESS_HOME/profiles.json',\n alias: 'p',\n },\n} satisfies CommandSchema\n\nconst projectSchema = {\n ...globalSchema,\n workDir,\n} satisfies CommandSchema\n\nconst credentialsSchema = {\n apiUrl,\n workspaceId,\n token,\n} satisfies CommandSchema\n\nconst secretsSchema = {\n secrets,\n} satisfies CommandSchema\n\n// command schemas\n\nconst generateSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst bundleSchema = {\n ...projectSchema,\n sourceMap,\n minify,\n} satisfies CommandSchema\n\nconst buildSchema = {\n ...projectSchema,\n sourceMap,\n minify,\n} satisfies CommandSchema\n\nconst readSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst serveSchema = {\n ...projectSchema,\n ...secretsSchema,\n port,\n} satisfies CommandSchema\n\nconst deploySchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n botId: { type: 'string', description: 'The bot ID to deploy. Only used when deploying a bot' },\n noBuild,\n dryRun,\n createNewBot: { type: 'boolean', description: 'Create a new bot when deploying. Only used when deploying a bot' },\n sourceMap,\n minify,\n visibility: {\n type: 'string',\n choices: ['public', 'private', 'unlisted'] as const,\n description:\n 'The visibility of the project. By default, projects are always private. Unlisted visibility is only supported for integrations.',\n default: 'private',\n },\n public: {\n type: 'boolean',\n description: 'DEPRECATED: Please use \"--visibility public\" instead.',\n default: false,\n deprecated: true,\n } satisfies CommandOption,\n allowDeprecated: {\n type: 'boolean',\n description: 'Allow deprecated features in the project',\n default: false,\n },\n} as const satisfies CommandSchema\n\nconst devSchema = {\n ...projectSchema,\n ...credentialsSchema,\n ...secretsSchema,\n sourceMap,\n minify,\n port,\n tunnelUrl: {\n type: 'string',\n description: 'The tunnel HTTP URL to use',\n default: consts.defaultTunnelUrl,\n },\n tunnelId: {\n type: 'string',\n description: 'The tunnel ID to use. The ID will be generated if not specified',\n },\n} satisfies CommandSchema\n\nconst addSchema = {\n ...globalSchema,\n ...credentialsSchema,\n packageRef,\n packageType,\n installPath: {\n type: 'string',\n description: 'The path where to install the package',\n default: consts.defaultInstallPath,\n },\n useDev: {\n type: 'boolean',\n description: 'If a dev version of the package is found, use it',\n default: false,\n },\n} satisfies CommandSchema\n\nconst loginSchema = {\n ...globalSchema,\n token,\n workspaceId,\n apiUrl: { ...apiUrl, default: consts.defaultBotpressApiUrl },\n} satisfies CommandSchema\n\nconst logoutSchema = {\n ...globalSchema,\n} satisfies CommandSchema\n\nconst createBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name of the bot to create' },\n ifNotExists: {\n type: 'boolean',\n description: 'Do not create if a bot with the same name already exists',\n default: false,\n },\n} satisfies CommandSchema\n\nconst getBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n botRef,\n} satisfies CommandSchema\n\nconst deleteBotSchema = {\n ...globalSchema,\n ...credentialsSchema,\n botRef,\n} satisfies CommandSchema\n\nconst listBotsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n dev,\n} satisfies CommandSchema\n\nconst getIntegrationSchema = {\n ...globalSchema,\n ...credentialsSchema,\n integrationRef,\n} satisfies CommandSchema\n\nconst listIntegrationsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name filter when listing integrations' },\n versionNumber: { type: 'string', description: 'The version filter when listing integrations' },\n dev,\n} satisfies CommandSchema\n\nconst deleteIntegrationSchema = {\n ...globalSchema,\n ...credentialsSchema,\n integrationRef,\n} satisfies CommandSchema\n\nconst getInterfaceSchema = {\n ...globalSchema,\n ...credentialsSchema,\n interfaceRef,\n} satisfies CommandSchema\n\nconst listInterfacesSchema = {\n ...globalSchema,\n ...credentialsSchema,\n} satisfies CommandSchema\n\nconst deleteInterfaceSchema = {\n ...globalSchema,\n ...credentialsSchema,\n interfaceRef,\n} satisfies CommandSchema\n\nconst getPluginSchema = {\n ...globalSchema,\n ...credentialsSchema,\n pluginRef,\n} satisfies CommandSchema\n\nconst listPluginsSchema = {\n ...globalSchema,\n ...credentialsSchema,\n name: { type: 'string', description: 'The name filter when listing plugins' },\n versionNumber: { type: 'string', description: 'The version filter when listing plugins' },\n} satisfies CommandSchema\n\nconst deletePluginSchema = {\n ...globalSchema,\n ...credentialsSchema,\n pluginRef,\n} satisfies CommandSchema\n\nconst initSchema = {\n ...globalSchema,\n workDir,\n type: { type: 'string', choices: ['bot', 'integration', 'plugin'] as const },\n template: {\n type: 'string',\n choices: ProjectTemplates.getAllChoices(),\n description: 'The template to use',\n },\n name: { type: 'string', description: 'The name of the project' },\n} satisfies CommandSchema\n\nconst lintSchema = {\n ...projectSchema,\n} satisfies CommandSchema\n\nconst chatSchema = {\n ...globalSchema,\n ...credentialsSchema,\n chatApiUrl: {\n type: 'string',\n description: 'The URL of the chat server',\n },\n botId: {\n type: 'string',\n positional: true,\n idx: 0,\n description: 'The bot ID to chat with',\n },\n} satisfies CommandSchema\n\nconst listProfilesSchema = {\n ...globalSchema,\n} satisfies CommandSchema\n\nconst activeProfileSchema = {\n ...globalSchema,\n} satisfies CommandSchema\n\nconst useProfileSchema = {\n ...globalSchema,\n profileToUse: {\n type: 'string',\n description: 'The CLI profile defined in the $BP_BOTPRESS_HOME/profiles.json',\n positional: true,\n idx: 0,\n },\n} satisfies CommandSchema\n\n// exports\n\nexport const schemas = {\n global: globalSchema,\n project: projectSchema,\n credentials: credentialsSchema,\n secrets: secretsSchema,\n login: loginSchema,\n logout: logoutSchema,\n createBot: createBotSchema,\n getBot: getBotSchema,\n deleteBot: deleteBotSchema,\n listBots: listBotsSchema,\n getIntegration: getIntegrationSchema,\n listIntegrations: listIntegrationsSchema,\n deleteIntegration: deleteIntegrationSchema,\n getInterface: getInterfaceSchema,\n listInterfaces: listInterfacesSchema,\n deleteInterface: deleteInterfaceSchema,\n getPlugin: getPluginSchema,\n listPlugins: listPluginsSchema,\n deletePlugin: deletePluginSchema,\n init: initSchema,\n generate: generateSchema,\n bundle: bundleSchema,\n build: buildSchema,\n read: readSchema,\n serve: serveSchema,\n deploy: deploySchema,\n add: addSchema,\n dev: devSchema,\n lint: lintSchema,\n chat: chatSchema,\n listProfiles: listProfilesSchema,\n activeProfile: activeProfileSchema,\n useProfile: useProfileSchema,\n} as const\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,+BAAiC;AAKjC,MAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,UAAU;AAAA,EACd,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS,OAAO;AAClB;AAEA,MAAM,UAAU;AAAA,EACd,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS;AACX;AAEA,MAAM,SAAS;AAAA,EACb,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS;AACX;AAEA,MAAM,SAAS;AAAA,EACb,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,QAAQ;AAAA,EACZ,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,aAAa;AACf;AAEA,MAAM,UAAU;AAAA,EACd,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,EACP,SAAS,CAAC;AACZ;AAEA,MAAM,SAAS;AAAA,EACb,MAAM;AAAA,EACN,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,KAAK;AACP;AAEA,MAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,aACE;AAAA,EACF,SAAS,CAAC,eAAe,aAAa,QAAQ;AAChD;AAEA,MAAM,aAAa;AAAA,EACjB,MAAM;AAAA,EACN,aACE;AAAA,EACF,YAAY;AAAA,EACZ,KA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AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,cAAc;AAAA,EACd,eAAe;AAAA,EACf,YAAY;AACd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/errors.js
CHANGED
|
@@ -58,7 +58,13 @@ class BotpressCLIError extends import_verror.VError {
|
|
|
58
58
|
return thrown;
|
|
59
59
|
}
|
|
60
60
|
if (thrown instanceof client.UnknownError) {
|
|
61
|
-
|
|
61
|
+
let inst;
|
|
62
|
+
const cause = thrown.error?.cause;
|
|
63
|
+
if (cause && typeof cause === "object" && "code" in cause && cause.code === "ECONNREFUSED") {
|
|
64
|
+
inst = new HTTPError(500, "The connection was refused by the server");
|
|
65
|
+
} else {
|
|
66
|
+
inst = new HTTPError(500, "An unknown error has occurred.");
|
|
67
|
+
}
|
|
62
68
|
inst.debug = thrown.message;
|
|
63
69
|
return inst;
|
|
64
70
|
}
|
package/dist/errors.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors.ts"],
|
|
4
|
-
"sourcesContent": ["import * as client from '@botpress/client'\nimport axios, { AxiosError } from 'axios'\nimport { VError } from 'verror'\nimport * as consts from './consts'\n\ntype KnownApiError = Exclude<client.ApiError, client.UnknownError>\nconst isKnownApiError = (e: unknown): e is KnownApiError => client.isApiError(e) && !(e instanceof client.UnknownError)\n\nexport class BotpressCLIError extends VError {\n public static wrap(thrown: unknown, message: string): BotpressCLIError {\n const err = BotpressCLIError.map(thrown)\n return new BotpressCLIError(err, message ?? '')\n }\n\n public static map(thrown: unknown): BotpressCLIError {\n if (thrown instanceof BotpressCLIError) {\n return thrown\n }\n if (thrown instanceof client.UnknownError) {\n const inst = new HTTPError(500, 'An unknown error has occurred.')\n inst.debug = thrown.message\n return inst\n }\n if (isKnownApiError(thrown)) {\n return HTTPError.fromApi(thrown)\n }\n if (axios.isAxiosError(thrown)) {\n return HTTPError.fromAxios(thrown)\n }\n if (thrown instanceof Error) {\n const { message } = thrown\n return new BotpressCLIError(message)\n }\n return new BotpressCLIError(`${thrown}`)\n }\n\n private readonly _debug: string[]\n\n public constructor(error: BotpressCLIError, message: string)\n public constructor(message: string)\n public constructor(first: BotpressCLIError | string, second?: string) {\n if (typeof first === 'string') {\n super(first)\n this._debug = []\n return\n }\n super(first, second!)\n this._debug = [...first._debug]\n }\n\n public set debug(msg: string) {\n this._debug.push(msg)\n }\n\n public get debug(): string {\n const dbgMsgs = this._debug.filter((s) => s.length)\n if (!dbgMsgs.length) {\n return ''\n }\n return 'Error: \\n' + dbgMsgs.map((s) => ` ${s}`).join('\\n')\n }\n}\n\nexport class ExclusiveBotFeatureError extends BotpressCLIError {\n public constructor() {\n const message = 'This feature is only available for bots. This project is an integration or interface.'\n super(message)\n }\n}\n\nexport class ExclusiveIntegrationFeatureError extends BotpressCLIError {\n public constructor() {\n const message = 'This feature is only available for integration. This project is a bot or interface.'\n super(message)\n }\n}\n\nexport class HTTPError extends BotpressCLIError {\n public constructor(\n public readonly status: number | undefined,\n message: string\n ) {\n super(message)\n }\n\n public static fromAxios(e: AxiosError<{ message?: string }>): HTTPError {\n const message = this._axiosMsg(e)\n return new HTTPError(e.response?.status, message)\n }\n\n public static fromApi(e: KnownApiError): HTTPError {\n const { message, code } = e\n return new HTTPError(code, message)\n }\n\n private static _axiosMsg(e: AxiosError<{ message?: string }>): string {\n let message = e.message\n if (e.response?.statusText) {\n message += `\\n ${e.response?.statusText}`\n }\n if (e.response?.status && e.request?.method && e.request?.path) {\n message += `\\n (${e.response?.status}) ${e.request.method} ${e.request.path}`\n }\n if (e.response?.data?.message) {\n message += `\\n ${e.response?.data?.message}`\n }\n return message\n }\n}\n\nexport class NoBundleFoundError extends BotpressCLIError {\n public constructor() {\n const message = 'No bundle found. Please run `bp bundle` first.'\n super(message)\n }\n}\n\nexport class NoBotsFoundError extends BotpressCLIError {\n public constructor() {\n const message = `No Bot found in your Workspace. Please create one first at ${consts.defaultBotpressAppUrl}.`\n super(message)\n }\n}\n\nexport class NoWorkspacesFoundError extends BotpressCLIError {\n public constructor() {\n const message = 'No Workspace found. Please create one first.'\n super(message)\n }\n}\n\nexport class NotLoggedInError extends BotpressCLIError {\n public constructor() {\n const message = 'Not logged in. Please run `bp login` first.'\n super(message)\n }\n}\n\nexport class ParamRequiredError extends BotpressCLIError {\n public constructor(param: string) {\n const message = `${param} is required.`\n super(message)\n }\n}\n\nexport class InvalidPackageReferenceError extends BotpressCLIError {\n public constructor(ref: string) {\n const message = `Invalid package reference \"${ref}\".`\n super(message)\n }\n}\n\nexport class UnsupportedProjectType extends BotpressCLIError {\n public constructor() {\n const message = 'Unsupported project type.'\n super(message)\n }\n}\n\nexport class ProjectDefinitionNotFoundError extends BotpressCLIError {\n public constructor(workdir: string) {\n const message = `No project definition found at \"${workdir}\".`\n super(message)\n }\n}\n\nexport class AbortedOperationError extends BotpressCLIError {\n public constructor() {\n super('Aborted')\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,mBAAkC;AAClC,oBAAuB;AACvB,aAAwB;AAGxB,MAAM,kBAAkB,CAAC,MAAmC,OAAO,WAAW,CAAC,KAAK,EAAE,aAAa,OAAO;AAEnG,MAAM,yBAAyB,qBAAO;AAAA,EAC3C,OAAc,KAAK,QAAiB,SAAmC;AACrE,UAAM,MAAM,iBAAiB,IAAI,MAAM;AACvC,WAAO,IAAI,iBAAiB,KAAK,WAAW,EAAE;AAAA,EAChD;AAAA,EAEA,OAAc,IAAI,QAAmC;AACnD,QAAI,kBAAkB,kBAAkB;AACtC,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,OAAO,cAAc;AACzC,YAAM,OAAO,IAAI,UAAU,KAAK,gCAAgC;
|
|
4
|
+
"sourcesContent": ["import * as client from '@botpress/client'\nimport axios, { AxiosError } from 'axios'\nimport { VError } from 'verror'\nimport * as consts from './consts'\n\ntype KnownApiError = Exclude<client.ApiError, client.UnknownError>\nconst isKnownApiError = (e: unknown): e is KnownApiError => client.isApiError(e) && !(e instanceof client.UnknownError)\n\nexport class BotpressCLIError extends VError {\n public static wrap(thrown: unknown, message: string): BotpressCLIError {\n const err = BotpressCLIError.map(thrown)\n return new BotpressCLIError(err, message ?? '')\n }\n\n public static map(thrown: unknown): BotpressCLIError {\n if (thrown instanceof BotpressCLIError) {\n return thrown\n }\n if (thrown instanceof client.UnknownError) {\n let inst: HTTPError\n const cause = thrown.error?.cause\n if (cause && typeof cause === 'object' && 'code' in cause && (cause as any).code === 'ECONNREFUSED') {\n inst = new HTTPError(500, 'The connection was refused by the server')\n } else {\n inst = new HTTPError(500, 'An unknown error has occurred.')\n }\n inst.debug = thrown.message\n return inst\n }\n if (isKnownApiError(thrown)) {\n return HTTPError.fromApi(thrown)\n }\n if (axios.isAxiosError(thrown)) {\n return HTTPError.fromAxios(thrown)\n }\n if (thrown instanceof Error) {\n const { message } = thrown\n return new BotpressCLIError(message)\n }\n return new BotpressCLIError(`${thrown}`)\n }\n\n private readonly _debug: string[]\n\n public constructor(error: BotpressCLIError, message: string)\n public constructor(message: string)\n public constructor(first: BotpressCLIError | string, second?: string) {\n if (typeof first === 'string') {\n super(first)\n this._debug = []\n return\n }\n super(first, second!)\n this._debug = [...first._debug]\n }\n\n public set debug(msg: string) {\n this._debug.push(msg)\n }\n\n public get debug(): string {\n const dbgMsgs = this._debug.filter((s) => s.length)\n if (!dbgMsgs.length) {\n return ''\n }\n return 'Error: \\n' + dbgMsgs.map((s) => ` ${s}`).join('\\n')\n }\n}\n\nexport class ExclusiveBotFeatureError extends BotpressCLIError {\n public constructor() {\n const message = 'This feature is only available for bots. This project is an integration or interface.'\n super(message)\n }\n}\n\nexport class ExclusiveIntegrationFeatureError extends BotpressCLIError {\n public constructor() {\n const message = 'This feature is only available for integration. This project is a bot or interface.'\n super(message)\n }\n}\n\nexport class HTTPError extends BotpressCLIError {\n public constructor(\n public readonly status: number | undefined,\n message: string\n ) {\n super(message)\n }\n\n public static fromAxios(e: AxiosError<{ message?: string }>): HTTPError {\n const message = this._axiosMsg(e)\n return new HTTPError(e.response?.status, message)\n }\n\n public static fromApi(e: KnownApiError): HTTPError {\n const { message, code } = e\n return new HTTPError(code, message)\n }\n\n private static _axiosMsg(e: AxiosError<{ message?: string }>): string {\n let message = e.message\n if (e.response?.statusText) {\n message += `\\n ${e.response?.statusText}`\n }\n if (e.response?.status && e.request?.method && e.request?.path) {\n message += `\\n (${e.response?.status}) ${e.request.method} ${e.request.path}`\n }\n if (e.response?.data?.message) {\n message += `\\n ${e.response?.data?.message}`\n }\n return message\n }\n}\n\nexport class NoBundleFoundError extends BotpressCLIError {\n public constructor() {\n const message = 'No bundle found. Please run `bp bundle` first.'\n super(message)\n }\n}\n\nexport class NoBotsFoundError extends BotpressCLIError {\n public constructor() {\n const message = `No Bot found in your Workspace. Please create one first at ${consts.defaultBotpressAppUrl}.`\n super(message)\n }\n}\n\nexport class NoWorkspacesFoundError extends BotpressCLIError {\n public constructor() {\n const message = 'No Workspace found. Please create one first.'\n super(message)\n }\n}\n\nexport class NotLoggedInError extends BotpressCLIError {\n public constructor() {\n const message = 'Not logged in. Please run `bp login` first.'\n super(message)\n }\n}\n\nexport class ParamRequiredError extends BotpressCLIError {\n public constructor(param: string) {\n const message = `${param} is required.`\n super(message)\n }\n}\n\nexport class InvalidPackageReferenceError extends BotpressCLIError {\n public constructor(ref: string) {\n const message = `Invalid package reference \"${ref}\".`\n super(message)\n }\n}\n\nexport class UnsupportedProjectType extends BotpressCLIError {\n public constructor() {\n const message = 'Unsupported project type.'\n super(message)\n }\n}\n\nexport class ProjectDefinitionNotFoundError extends BotpressCLIError {\n public constructor(workdir: string) {\n const message = `No project definition found at \"${workdir}\".`\n super(message)\n }\n}\n\nexport class AbortedOperationError extends BotpressCLIError {\n public constructor() {\n super('Aborted')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,mBAAkC;AAClC,oBAAuB;AACvB,aAAwB;AAGxB,MAAM,kBAAkB,CAAC,MAAmC,OAAO,WAAW,CAAC,KAAK,EAAE,aAAa,OAAO;AAEnG,MAAM,yBAAyB,qBAAO;AAAA,EAC3C,OAAc,KAAK,QAAiB,SAAmC;AACrE,UAAM,MAAM,iBAAiB,IAAI,MAAM;AACvC,WAAO,IAAI,iBAAiB,KAAK,WAAW,EAAE;AAAA,EAChD;AAAA,EAEA,OAAc,IAAI,QAAmC;AACnD,QAAI,kBAAkB,kBAAkB;AACtC,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,OAAO,cAAc;AACzC,UAAI;AACJ,YAAM,QAAQ,OAAO,OAAO;AAC5B,UAAI,SAAS,OAAO,UAAU,YAAY,UAAU,SAAU,MAAc,SAAS,gBAAgB;AACnG,eAAO,IAAI,UAAU,KAAK,0CAA0C;AAAA,MACtE,OAAO;AACL,eAAO,IAAI,UAAU,KAAK,gCAAgC;AAAA,MAC5D;AACA,WAAK,QAAQ,OAAO;AACpB,aAAO;AAAA,IACT;AACA,QAAI,gBAAgB,MAAM,GAAG;AAC3B,aAAO,UAAU,QAAQ,MAAM;AAAA,IACjC;AACA,QAAI,aAAAA,QAAM,aAAa,MAAM,GAAG;AAC9B,aAAO,UAAU,UAAU,MAAM;AAAA,IACnC;AACA,QAAI,kBAAkB,OAAO;AAC3B,YAAM,EAAE,QAAQ,IAAI;AACpB,aAAO,IAAI,iBAAiB,OAAO;AAAA,IACrC;AACA,WAAO,IAAI,iBAAiB,GA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