@botpress/cli 1.7.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +12 -10
- package/dist/api/bot-body.js +20 -6
- package/dist/api/bot-body.js.map +2 -2
- package/dist/api/client.js +18 -0
- package/dist/api/client.js.map +2 -2
- package/dist/api/interface-body.js.map +2 -2
- package/dist/api/plugin-body.js +79 -0
- package/dist/api/plugin-body.js.map +7 -0
- package/dist/api/types.js.map +1 -1
- package/dist/code-generation/bot-implementation/bot-implementation.js +40 -21
- package/dist/code-generation/bot-implementation/bot-implementation.js.map +2 -2
- package/dist/code-generation/bot-implementation/bot-plugins/index.js +76 -0
- package/dist/code-generation/bot-implementation/bot-plugins/index.js.map +7 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js +125 -0
- package/dist/code-generation/bot-implementation/bot-plugins/plugin-module.js.map +7 -0
- package/dist/code-generation/bot-implementation/index.js +27 -22
- package/dist/code-generation/bot-implementation/index.js.map +2 -2
- package/dist/code-generation/consts.js +3 -0
- package/dist/code-generation/consts.js.map +2 -2
- package/dist/code-generation/generators.js +8 -0
- package/dist/code-generation/generators.js.map +2 -2
- package/dist/code-generation/index.js +6 -0
- package/dist/code-generation/index.js.map +2 -2
- package/dist/code-generation/integration-package/index.js +11 -2
- package/dist/code-generation/integration-package/index.js.map +2 -2
- package/dist/code-generation/interface-implementation/index.js +29 -0
- package/dist/code-generation/interface-implementation/index.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/actions-module.js +84 -0
- package/dist/code-generation/interface-implementation/integration-typings/actions-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/channels-module.js +103 -0
- package/dist/code-generation/interface-implementation/integration-typings/channels-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/entities-module.js +59 -0
- package/dist/code-generation/interface-implementation/integration-typings/entities-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/events-module.js +59 -0
- package/dist/code-generation/interface-implementation/integration-typings/events-module.js.map +7 -0
- package/dist/code-generation/interface-implementation/integration-typings/index.js +117 -0
- package/dist/code-generation/interface-implementation/integration-typings/index.js.map +7 -0
- package/dist/code-generation/interface-package/index.js +11 -2
- package/dist/code-generation/interface-package/index.js.map +2 -2
- package/dist/code-generation/module.js +17 -4
- package/dist/code-generation/module.js.map +2 -2
- package/dist/code-generation/plugin-implementation/index.js +56 -0
- package/dist/code-generation/plugin-implementation/index.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.js +86 -0
- package/dist/code-generation/plugin-implementation/plugin-implementation.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/actions-module.js +84 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/actions-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/configuration-module.js +57 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/configuration-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/events-module.js +59 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/events-module.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js +146 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/index.js.map +7 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/states-module.js +60 -0
- package/dist/code-generation/plugin-implementation/plugin-typings/states-module.js.map +7 -0
- package/dist/code-generation/plugin-package/index.js +146 -0
- package/dist/code-generation/plugin-package/index.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js +84 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/actions-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js +52 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/configuration-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js +62 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/events-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js +103 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/index.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js +62 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/states-module.js.map +7 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.js +17 -0
- package/dist/code-generation/plugin-package/plugin-package-definition/typings.js.map +7 -0
- package/dist/code-generation/typings.js.map +1 -1
- package/dist/command-definitions.js +8 -0
- package/dist/command-definitions.js.map +2 -2
- package/dist/command-implementations/add-command.js +47 -10
- package/dist/command-implementations/add-command.js.map +2 -2
- package/dist/command-implementations/bundle-command.js +7 -2
- package/dist/command-implementations/bundle-command.js.map +2 -2
- package/dist/command-implementations/deploy-command.js +51 -0
- package/dist/command-implementations/deploy-command.js.map +2 -2
- package/dist/command-implementations/gen-command.js +11 -0
- package/dist/command-implementations/gen-command.js.map +2 -2
- package/dist/command-implementations/index.js +8 -0
- package/dist/command-implementations/index.js.map +2 -2
- package/dist/command-implementations/init-command.js +36 -8
- package/dist/command-implementations/init-command.js.map +2 -2
- package/dist/command-implementations/lint-command.js +1 -1
- package/dist/command-implementations/lint-command.js.map +2 -2
- package/dist/command-implementations/plugin-commands.js +107 -0
- package/dist/command-implementations/plugin-commands.js.map +7 -0
- package/dist/command-implementations/project-command.js +30 -3
- package/dist/command-implementations/project-command.js.map +2 -2
- package/dist/command-implementations/read-command.js +13 -1
- package/dist/command-implementations/read-command.js.map +2 -2
- package/dist/config.js +23 -2
- package/dist/config.js.map +2 -2
- package/dist/consts.js +7 -0
- package/dist/consts.js.map +2 -2
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/index.js.map +2 -2
- package/dist/sdk/resolve-bot-interfaces.js +6 -1
- package/dist/sdk/resolve-bot-interfaces.js.map +2 -2
- package/dist/sdk/resolve-integration-interfaces.js +16 -8
- package/dist/sdk/resolve-integration-interfaces.js.map +2 -2
- package/dist/sdk/validate-bot.js +84 -0
- package/dist/sdk/validate-bot.js.map +7 -0
- package/dist/utils/esbuild-utils.js +3 -2
- package/dist/utils/esbuild-utils.js.map +2 -2
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +2 -2
- package/dist/utils/object-utils.js +32 -0
- package/dist/utils/object-utils.js.map +7 -0
- package/dist/utils/schema-utils.js.map +2 -2
- package/dist/utils/type-utils.js.map +1 -1
- package/e2e/tests/install-package.ts +1 -1
- package/package.json +2 -2
- package/templates/empty-bot/.botpress/implementation/index.ts +27 -18
- package/templates/empty-bot/.botpress/implementation/plugins/index.ts +11 -0
- package/templates/empty-bot/.botpress/index.ts +5 -1
- package/templates/empty-bot/package.json +1 -1
- package/templates/empty-integration/package.json +1 -1
- package/templates/empty-plugin/.botpress/implementation/index.ts +35 -0
- package/templates/empty-plugin/.botpress/implementation/typings/actions/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/configuration/index.ts +2 -0
- package/templates/empty-plugin/.botpress/implementation/typings/events/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/index.ts +26 -0
- package/templates/empty-plugin/.botpress/implementation/typings/integrations/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/interfaces/index.ts +6 -0
- package/templates/empty-plugin/.botpress/implementation/typings/states/index.ts +6 -0
- package/templates/empty-plugin/.botpress/index.ts +1 -0
- package/templates/empty-plugin/package.json +16 -0
- package/templates/empty-plugin/plugin.definition.ts +7 -0
- package/templates/empty-plugin/src/index.ts +7 -0
- package/templates/empty-plugin/tsconfig.json +28 -0
- package/templates/hello-world/package.json +1 -1
- package/templates/webhook-message/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/cli@
|
|
2
|
+
> @botpress/cli@2.0.0 build /home/runner/work/botpress/botpress/packages/cli
|
|
3
3
|
> pnpm run bundle && pnpm run template:gen
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @botpress/cli@
|
|
6
|
+
> @botpress/cli@2.0.0 bundle /home/runner/work/botpress/botpress/packages/cli
|
|
7
7
|
> ts-node -T build.ts
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
> @botpress/cli@
|
|
10
|
+
> @botpress/cli@2.0.0 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
|
|
14
|
-
🤖 Botpress CLI
|
|
15
|
-
🤖 Botpress CLI
|
|
16
|
-
🤖 Botpress CLI
|
|
17
|
-
[2K[1G○ Generating typings for integration hello-world...[2K[1G○ Generating typings for integration
|
|
18
|
-
[2K[1G○ Generating typings for
|
|
19
|
-
[2K[1G✓ Typings available at .botpress
|
|
13
|
+
🤖 Botpress CLI v2.0.0
|
|
14
|
+
🤖 Botpress CLI v2.0.0
|
|
15
|
+
🤖 Botpress CLI v2.0.0
|
|
16
|
+
🤖 Botpress CLI v2.0.0
|
|
17
|
+
[2K[1G○ Generating typings for integration hello-world...[2K[1G○ Generating typings for integration empty-integration...[2K[1G✓ Typings available at .botpress
|
|
18
|
+
[2K[1G○ Generating typings for bot...[2K[1G✓ Typings available at .botpress
|
|
19
|
+
[2K[1G○ Generating typings for plugin...[2K[1G✓ Typings available at .botpress
|
|
20
20
|
[2K[1G✓ Typings available at .botpress
|
|
21
|
+
🤖 Botpress CLI v2.0.0
|
|
22
|
+
[2K[1G○ Generating typings for integration webhook-message...[2K[1G✓ Typings available at .botpress
|
package/dist/api/bot-body.js
CHANGED
|
@@ -30,16 +30,30 @@ __export(bot_body_exports, {
|
|
|
30
30
|
module.exports = __toCommonJS(bot_body_exports);
|
|
31
31
|
var utils = __toESM(require("../utils"));
|
|
32
32
|
const prepareCreateBotBody = async (bot) => ({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
user: bot.user,
|
|
34
|
+
conversation: bot.conversation,
|
|
35
|
+
message: bot.message,
|
|
36
|
+
recurringEvents: bot.recurringEvents,
|
|
37
|
+
actions: bot.actions ? await utils.records.mapValuesAsync(bot.actions, async (action) => ({
|
|
38
|
+
...action,
|
|
39
|
+
input: {
|
|
40
|
+
...action.input,
|
|
41
|
+
schema: await utils.schema.mapZodToJsonSchema(action.input)
|
|
42
|
+
},
|
|
43
|
+
output: {
|
|
44
|
+
...action.output,
|
|
45
|
+
schema: await utils.schema.mapZodToJsonSchema(action.output)
|
|
46
|
+
}
|
|
47
|
+
})) : void 0,
|
|
48
|
+
configuration: bot.configuration ? {
|
|
49
|
+
...bot.configuration,
|
|
50
|
+
schema: await utils.schema.mapZodToJsonSchema(bot.configuration)
|
|
37
51
|
} : void 0,
|
|
38
|
-
events: bot.
|
|
52
|
+
events: bot.events ? await utils.records.mapValuesAsync(bot.events, async (event) => ({
|
|
39
53
|
...event,
|
|
40
54
|
schema: await utils.schema.mapZodToJsonSchema(event)
|
|
41
55
|
})) : void 0,
|
|
42
|
-
states: bot.
|
|
56
|
+
states: bot.states ? await utils.records.mapValuesAsync(bot.states, async (state) => ({
|
|
43
57
|
...state,
|
|
44
58
|
schema: await utils.schema.mapZodToJsonSchema(state)
|
|
45
59
|
})) : void 0
|
package/dist/api/bot-body.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/api/bot-body.ts"],
|
|
4
|
-
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\n\nexport type CreateBotBody = Parameters<client.Client['createBot']>[0]\nexport type UpdateBotBody = Parameters<client.Client['updateBot']>[0]\n\nexport const prepareCreateBotBody = async (bot: sdk.BotDefinition): Promise<CreateBotBody> => ({\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAKhB,MAAM,uBAAuB,OAAO,SAAoD;AAAA,EAC7F,
|
|
4
|
+
"sourcesContent": ["import type * as client from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\n\nexport type CreateBotBody = Parameters<client.Client['createBot']>[0]\nexport type UpdateBotBody = Parameters<client.Client['updateBot']>[0]\n\nexport const prepareCreateBotBody = async (bot: sdk.BotDefinition): Promise<CreateBotBody> => ({\n user: bot.user,\n conversation: bot.conversation,\n message: bot.message,\n recurringEvents: bot.recurringEvents,\n actions: bot.actions\n ? await utils.records.mapValuesAsync(bot.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n configuration: bot.configuration\n ? {\n ...bot.configuration,\n schema: await utils.schema.mapZodToJsonSchema(bot.configuration),\n }\n : undefined,\n events: bot.events\n ? await utils.records.mapValuesAsync(bot.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n states: bot.states\n ? await utils.records.mapValuesAsync(bot.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n})\n\nexport const prepareUpdateBotBody = (localBot: UpdateBotBody, remoteBot: client.Bot): UpdateBotBody => ({\n ...localBot,\n states: utils.records.setNullOnMissingValues(localBot.states, remoteBot.states),\n recurringEvents: utils.records.setNullOnMissingValues(localBot.recurringEvents, remoteBot.recurringEvents),\n events: utils.records.setNullOnMissingValues(localBot.events, remoteBot.events),\n user: {\n ...localBot.user,\n tags: utils.records.setNullOnMissingValues(localBot.user?.tags, remoteBot.user?.tags),\n },\n conversation: {\n ...localBot.conversation,\n tags: utils.records.setNullOnMissingValues(localBot.conversation?.tags, remoteBot.conversation?.tags),\n },\n message: {\n ...localBot.message,\n tags: utils.records.setNullOnMissingValues(localBot.message?.tags, remoteBot.message?.tags),\n },\n integrations: utils.records.setNullOnMissing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QAAQ,uBAAuB,SAAS,iBAAiB,UAAU,eAAe;AAAA,EACzG,QAAQ,MAAM,QAAQ,uBAAuB,SAAS,QAAQ,UAAU,MAAM;AAAA,EAC9E,MAAM;AAAA,IACJ,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,MAAM,MAAM,UAAU,MAAM,IAAI;AAAA,EACtF;AAAA,EACA,cAAc;AAAA,IACZ,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,cAAc,MAAM,UAAU,cAAc,IAAI;AAAA,EACtG;AAAA,EACA,SAAS;AAAA,IACP,GAAG,SAAS;AAAA,IACZ,MAAM,MAAM,QAAQ,uBAAuB,SAAS,SAAS,MAAM,UAAU,SAAS,IAAI;AAAA,EAC5F;AAAA,EACA,cAAc,MAAM,QAAQ,uBAAuB,SAAS,cAAc,UAAU,YAAY;AAClG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/api/client.js
CHANGED
|
@@ -102,6 +102,15 @@ class ApiClient {
|
|
|
102
102
|
}
|
|
103
103
|
return this.client.getInterfaceByName(ref).then((r) => r.interface).catch(this._returnUndefinedOnError("ResourceNotFound"));
|
|
104
104
|
}
|
|
105
|
+
async findPublicPlugin(ref) {
|
|
106
|
+
if (ref.type === "id") {
|
|
107
|
+
return this.client.getPlugin(ref).then((r) => r.plugin).catch(this._returnUndefinedOnError("ResourceNotFound"));
|
|
108
|
+
}
|
|
109
|
+
if ((0, import_package_ref.isLatest)(ref)) {
|
|
110
|
+
return this._findLatestPluginVersion(ref);
|
|
111
|
+
}
|
|
112
|
+
return this.client.getPluginByName(ref).then((r) => r.plugin).catch(this._returnUndefinedOnError("ResourceNotFound"));
|
|
113
|
+
}
|
|
105
114
|
_findLatestInterfaceVersion = async ({ name }) => {
|
|
106
115
|
const { interfaces: allVersions } = await this.client.listInterfaces({ name });
|
|
107
116
|
const sorted = allVersions.sort((a, b) => import_semver.default.compare(b.version, a.version));
|
|
@@ -111,6 +120,15 @@ class ApiClient {
|
|
|
111
120
|
}
|
|
112
121
|
return this.client.getInterface({ id: latestVersion.id }).then((r) => r.interface);
|
|
113
122
|
};
|
|
123
|
+
_findLatestPluginVersion = async ({ name }) => {
|
|
124
|
+
const { plugins: allVersions } = await this.client.listPlugins({ name });
|
|
125
|
+
const sorted = allVersions.sort((a, b) => import_semver.default.compare(b.version, a.version));
|
|
126
|
+
const latestVersion = sorted[0];
|
|
127
|
+
if (!latestVersion) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
return this.client.getPlugin({ id: latestVersion.id }).then((r) => r.plugin);
|
|
131
|
+
};
|
|
114
132
|
async testLogin() {
|
|
115
133
|
await this.client.listBots({});
|
|
116
134
|
}
|
package/dist/api/client.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/api/client.ts"],
|
|
4
|
-
"sourcesContent": ["import * as client from '@botpress/client'\nimport semver from 'semver'\nimport yn from 'yn'\nimport type { Logger } from '../logger'\nimport { formatPackageRef, ApiPackageRef, NamePackageRef, isLatest } from '../package-ref'\nimport { findPreviousIntegrationVersion } from './find-previous-version'\nimport * as paging from './paging'\n\nimport {\n ApiClientProps,\n PublicIntegration,\n PrivateIntegration,\n Integration,\n Requests,\n Responses,\n Interface,\n BotSummary,\n} from './types'\n\nexport * from './types'\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: client.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(props: ApiClientProps, private _logger: Logger) {\n const { apiUrl, token, workspaceId } = props\n this.client = new client.Client({ apiUrl, token, workspaceId })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n }\n\n public get isBotpressWorkspace(): boolean {\n // this environment variable is undocumented and only used internally for dev purposes\n const isBotpressWorkspace = yn(process.env.BP_IS_BOTPRESS_WORKSPACE)\n if (isBotpressWorkspace !== undefined) {\n return isBotpressWorkspace\n }\n return [\n '6a76fa10-e150-4ff6-8f59-a300feec06c1',\n '95de33eb-1551-4af9-9088-e5dcb02efd09',\n '11111111-1111-1111-aaaa-111111111111',\n ].includes(this.workspaceId)\n }\n\n public async getWorkspace(): Promise<Responses['getWorkspace']> {\n return this.client.getWorkspace({ id: this.workspaceId })\n }\n\n public async updateWorkspace(props: Omit<Requests['updateWorkspace'], 'id'>): Promise<Responses['updateWorkspace']> {\n return this.client.updateWorkspace({ id: this.workspaceId, ...props })\n }\n\n public async findIntegration(ref: ApiPackageRef): Promise<Integration | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: ApiPackageRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getIntegration(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getIntegrationByName(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicIntegration(ref: ApiPackageRef): Promise<PublicIntegration | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicIntegrationById(ref)\n .then((r) => r.integration)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPublicIntegration(ref)\n .then((r) => r.integration)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicInterface(ref: ApiPackageRef): Promise<Interface | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getInterface(ref)\n .then((r) => r.interface)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n if (isLatest(ref)) {\n // TODO: handle latest keyword in backend\n return this._findLatestInterfaceVersion(ref)\n }\n\n return this.client\n .getInterfaceByName(ref)\n .then((r) => r.interface)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n private _findLatestInterfaceVersion = async ({ name }: NamePackageRef): Promise<Interface | undefined> => {\n const { interfaces: allVersions } = await this.client.listInterfaces({ name })\n const sorted = allVersions.sort((a, b) => semver.compare(b.version, a.version))\n const latestVersion = sorted[0]\n if (!latestVersion) {\n return\n }\n return this.client.getInterface({ id: latestVersion.id }).then((r) => r.interface)\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async findPreviousIntegrationVersion(ref: NamePackageRef): Promise<Integration | undefined> {\n const previous = await findPreviousIntegrationVersion(this.client, ref)\n if (!previous) {\n return\n }\n return this.findIntegration({ type: 'id', id: previous.id })\n }\n\n public async findBotByName(name: string): Promise<BotSummary | undefined> {\n // api does not allow filtering bots by name\n const allBots = await this.listAllPages(this.client.listBots, (r) => r.bots)\n return allBots.find((b) => b.name === name)\n }\n\n private _returnUndefinedOnError =\n (type: client.ApiError['type']) =>\n (thrown: any): undefined => {\n if (client.isApiError(thrown) && thrown.type === type) {\n return\n }\n throw thrown\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,oBAAmB;AACnB,gBAAe;AAEf,yBAA0E;AAC1E,mCAA+C;AAC/C,aAAwB;
|
|
4
|
+
"sourcesContent": ["import * as client from '@botpress/client'\nimport semver from 'semver'\nimport yn from 'yn'\nimport type { Logger } from '../logger'\nimport { formatPackageRef, ApiPackageRef, NamePackageRef, isLatest } from '../package-ref'\nimport { findPreviousIntegrationVersion } from './find-previous-version'\nimport * as paging from './paging'\n\nimport {\n ApiClientProps,\n PublicIntegration,\n PrivateIntegration,\n Integration,\n Requests,\n Responses,\n Interface,\n Plugin,\n BotSummary,\n} from './types'\n\nexport * from './types'\n\n/**\n * This class is used to wrap the Botpress API and provide a more convenient way to interact with it.\n */\nexport class ApiClient {\n public readonly client: client.Client\n public readonly url: string\n public readonly token: string\n public readonly workspaceId: string\n\n public static newClient = (props: ApiClientProps, logger: Logger) => new ApiClient(props, logger)\n\n public constructor(props: ApiClientProps, private _logger: Logger) {\n const { apiUrl, token, workspaceId } = props\n this.client = new client.Client({ apiUrl, token, workspaceId })\n this.url = apiUrl\n this.token = token\n this.workspaceId = workspaceId\n }\n\n public get isBotpressWorkspace(): boolean {\n // this environment variable is undocumented and only used internally for dev purposes\n const isBotpressWorkspace = yn(process.env.BP_IS_BOTPRESS_WORKSPACE)\n if (isBotpressWorkspace !== undefined) {\n return isBotpressWorkspace\n }\n return [\n '6a76fa10-e150-4ff6-8f59-a300feec06c1',\n '95de33eb-1551-4af9-9088-e5dcb02efd09',\n '11111111-1111-1111-aaaa-111111111111',\n ].includes(this.workspaceId)\n }\n\n public async getWorkspace(): Promise<Responses['getWorkspace']> {\n return this.client.getWorkspace({ id: this.workspaceId })\n }\n\n public async updateWorkspace(props: Omit<Requests['updateWorkspace'], 'id'>): Promise<Responses['updateWorkspace']> {\n return this.client.updateWorkspace({ id: this.workspaceId, ...props })\n }\n\n public async findIntegration(ref: ApiPackageRef): Promise<Integration | undefined> {\n const formatted = formatPackageRef(ref)\n\n const privateIntegration = await this.findPrivateIntegration(ref)\n if (privateIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in workspace`)\n return privateIntegration\n }\n\n const publicIntegration = await this.findPublicIntegration(ref)\n if (publicIntegration) {\n this._logger.debug(`Found integration \"${formatted}\" in hub`)\n return publicIntegration\n }\n\n return\n }\n\n public async findPrivateIntegration(ref: ApiPackageRef): Promise<PrivateIntegration | undefined> {\n const { workspaceId } = this\n if (ref.type === 'id') {\n return this.client\n .getIntegration(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getIntegrationByName(ref)\n .then((r) => ({ ...r.integration, workspaceId }))\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicIntegration(ref: ApiPackageRef): Promise<PublicIntegration | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPublicIntegrationById(ref)\n .then((r) => r.integration)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n return this.client\n .getPublicIntegration(ref)\n .then((r) => r.integration)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicInterface(ref: ApiPackageRef): Promise<Interface | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getInterface(ref)\n .then((r) => r.interface)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n if (isLatest(ref)) {\n // TODO: handle latest keyword in backend\n return this._findLatestInterfaceVersion(ref)\n }\n\n return this.client\n .getInterfaceByName(ref)\n .then((r) => r.interface)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n public async findPublicPlugin(ref: ApiPackageRef): Promise<Plugin | undefined> {\n if (ref.type === 'id') {\n return this.client\n .getPlugin(ref)\n .then((r) => r.plugin)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n if (isLatest(ref)) {\n // TODO: handle latest keyword in backend\n return this._findLatestPluginVersion(ref)\n }\n\n return this.client\n .getPluginByName(ref)\n .then((r) => r.plugin)\n .catch(this._returnUndefinedOnError('ResourceNotFound'))\n }\n\n private _findLatestInterfaceVersion = async ({ name }: NamePackageRef): Promise<Interface | undefined> => {\n const { interfaces: allVersions } = await this.client.listInterfaces({ name })\n const sorted = allVersions.sort((a, b) => semver.compare(b.version, a.version))\n const latestVersion = sorted[0]\n if (!latestVersion) {\n return\n }\n return this.client.getInterface({ id: latestVersion.id }).then((r) => r.interface)\n }\n\n private _findLatestPluginVersion = async ({ name }: NamePackageRef): Promise<Plugin | undefined> => {\n const { plugins: allVersions } = await this.client.listPlugins({ name })\n const sorted = allVersions.sort((a, b) => semver.compare(b.version, a.version))\n const latestVersion = sorted[0]\n if (!latestVersion) {\n return\n }\n return this.client.getPlugin({ id: latestVersion.id }).then((r) => r.plugin)\n }\n\n public async testLogin(): Promise<void> {\n await this.client.listBots({})\n }\n\n public listAllPages = paging.listAllPages\n\n public async findPreviousIntegrationVersion(ref: NamePackageRef): Promise<Integration | undefined> {\n const previous = await findPreviousIntegrationVersion(this.client, ref)\n if (!previous) {\n return\n }\n return this.findIntegration({ type: 'id', id: previous.id })\n }\n\n public async findBotByName(name: string): Promise<BotSummary | undefined> {\n // api does not allow filtering bots by name\n const allBots = await this.listAllPages(this.client.listBots, (r) => r.bots)\n return allBots.find((b) => b.name === name)\n }\n\n private _returnUndefinedOnError =\n (type: client.ApiError['type']) =>\n (thrown: any): undefined => {\n if (client.isApiError(thrown) && thrown.type === type) {\n return\n }\n throw thrown\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,aAAwB;AACxB,oBAAmB;AACnB,gBAAe;AAEf,yBAA0E;AAC1E,mCAA+C;AAC/C,aAAwB;AAcxB,2BAAc,oBApBd;AAyBO,MAAM,UAAU;AAAA,EAQd,YAAY,OAA+B,SAAiB;AAAjB;AAChD,UAAM,EAAE,QAAQ,OAAO,YAAY,IAAI;AACvC,SAAK,SAAS,IAAI,OAAO,OAAO,EAAE,QAAQ,OAAO,YAAY,CAAC;AAC9D,SAAK,MAAM;AACX,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAbgB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,OAAc,YAAY,CAAC,OAAuB,WAAmB,IAAI,UAAU,OAAO,MAAM;AAAA,EAUhG,IAAW,sBAA+B;AAExC,UAAM,0BAAs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
|
|
6
6
|
"names": ["yn", "semver"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/api/interface-body.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Client, Interface } from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\n\nexport type CreateInterfaceBody = Parameters<Client['createInterface']>[0]\nexport type UpdateInterfaceBody = Parameters<Client['updateInterface']>[0]\n\nexport const prepareCreateInterfaceBody = async (intrface: sdk.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAKhB,MAAM,6BAA6B,OAAO,
|
|
4
|
+
"sourcesContent": ["import type { Client, Interface } from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\n\nexport type CreateInterfaceBody = Parameters<Client['createInterface']>[0]\nexport type UpdateInterfaceBody = Parameters<Client['updateInterface']>[0]\n\nexport const prepareCreateInterfaceBody = async (intrface: sdk.InterfaceDefinition): Promise<CreateInterfaceBody> => ({\n name: intrface.name,\n version: intrface.version,\n entities: intrface.entities\n ? await utils.records.mapValuesAsync(intrface.entities, async (entity) => ({\n ...entity,\n schema: await utils.schema.mapZodToJsonSchema(entity),\n }))\n : {},\n events: intrface.events\n ? await utils.records.mapValuesAsync(intrface.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : {},\n actions: intrface.actions\n ? await utils.records.mapValuesAsync(intrface.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : {},\n channels: intrface.channels\n ? await utils.records.mapValuesAsync(intrface.channels, async (channel) => ({\n ...channel,\n messages: await utils.records.mapValuesAsync(channel.messages, async (message) => ({\n ...message,\n schema: await utils.schema.mapZodToJsonSchema(message),\n })),\n }))\n : {},\n nameTemplate: intrface.templateName\n ? {\n script: intrface.templateName,\n language: 'handlebars',\n }\n : undefined,\n})\n\nexport const prepareUpdateInterfaceBody = (\n localInterface: CreateInterfaceBody & { id: string },\n remoteInterface: Interface\n): UpdateInterfaceBody => {\n const actions = utils.records.setNullOnMissingValues(localInterface.actions, remoteInterface.actions)\n const events = utils.records.setNullOnMissingValues(localInterface.events, remoteInterface.events)\n const entities = utils.records.setNullOnMissingValues(localInterface.entities, remoteInterface.entities)\n\n const currentChannels: UpdateInterfaceBody['channels'] = localInterface.channels\n ? utils.records.mapValues(localInterface.channels, (channel, channelName) => ({\n ...channel,\n messages: utils.records.setNullOnMissingValues(\n channel?.messages,\n remoteInterface.channels[channelName]?.messages\n ),\n }))\n : undefined\n\n const channels = utils.records.setNullOnMissingValues(currentChannels, remoteInterface.channels)\n\n return {\n ...localInterface,\n entities,\n actions,\n events,\n channels,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,YAAuB;AAKhB,MAAM,6BAA6B,OAAO,cAAqE;AAAA,EACpH,MAAM,SAAS;AAAA,EACf,SAAS,SAAS;AAAA,EAClB,UAAU,SAAS,WACf,MAAM,MAAM,QAAQ,eAAe,SAAS,UAAU,OAAO,YAAY;AAAA,IACvE,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,MAAM;AAAA,EACtD,EAAE,IACF,CAAC;AAAA,EACL,QAAQ,SAAS,SACb,MAAM,MAAM,QAAQ,eAAe,SAAS,QAAQ,OAAO,WAAW;AAAA,IACpE,GAAG;AAAA,IACH,QAAQ,MAAM,MAAM,OAAO,mBAAmB,KAAK;AAAA,EACrD,EAAE,IACF,CAAC;AAAA,EACL,SAAS,SAAS,UACd,MAAM,MAAM,QAAQ,eAAe,SAAS,SAAS,OAAO,YAAY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A;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var plugin_body_exports = {};
|
|
26
|
+
__export(plugin_body_exports, {
|
|
27
|
+
prepareCreatePluginBody: () => prepareCreatePluginBody,
|
|
28
|
+
prepareUpdatePluginBody: () => prepareUpdatePluginBody
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(plugin_body_exports);
|
|
31
|
+
var utils = __toESM(require("../utils"));
|
|
32
|
+
const prepareCreatePluginBody = async (plugin) => ({
|
|
33
|
+
name: plugin.name,
|
|
34
|
+
version: plugin.version,
|
|
35
|
+
user: {
|
|
36
|
+
tags: plugin.user?.tags ?? {}
|
|
37
|
+
},
|
|
38
|
+
configuration: plugin.configuration ? {
|
|
39
|
+
...plugin.configuration,
|
|
40
|
+
schema: await utils.schema.mapZodToJsonSchema(plugin.configuration)
|
|
41
|
+
} : void 0,
|
|
42
|
+
events: plugin.events ? await utils.records.mapValuesAsync(plugin.events, async (event) => ({
|
|
43
|
+
...event,
|
|
44
|
+
schema: await utils.schema.mapZodToJsonSchema(event)
|
|
45
|
+
})) : void 0,
|
|
46
|
+
actions: plugin.actions ? await utils.records.mapValuesAsync(plugin.actions, async (action) => ({
|
|
47
|
+
...action,
|
|
48
|
+
input: {
|
|
49
|
+
...action.input,
|
|
50
|
+
schema: await utils.schema.mapZodToJsonSchema(action.input)
|
|
51
|
+
},
|
|
52
|
+
output: {
|
|
53
|
+
...action.output,
|
|
54
|
+
schema: await utils.schema.mapZodToJsonSchema(action.output)
|
|
55
|
+
}
|
|
56
|
+
})) : void 0,
|
|
57
|
+
states: plugin.states ? await utils.records.mapValuesAsync(plugin.states, async (state) => ({
|
|
58
|
+
...state,
|
|
59
|
+
schema: await utils.schema.mapZodToJsonSchema(state)
|
|
60
|
+
})) : void 0
|
|
61
|
+
});
|
|
62
|
+
const prepareUpdatePluginBody = (localPlugin, remotePlugin) => {
|
|
63
|
+
const actions = utils.records.setNullOnMissingValues(localPlugin.actions, remotePlugin.actions);
|
|
64
|
+
const events = utils.records.setNullOnMissingValues(localPlugin.events, remotePlugin.events);
|
|
65
|
+
const states = utils.records.setNullOnMissingValues(localPlugin.states, remotePlugin.states);
|
|
66
|
+
return {
|
|
67
|
+
...localPlugin,
|
|
68
|
+
actions,
|
|
69
|
+
events,
|
|
70
|
+
states,
|
|
71
|
+
user: localPlugin.user
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
prepareCreatePluginBody,
|
|
77
|
+
prepareUpdatePluginBody
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=plugin-body.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/api/plugin-body.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Client, Plugin } from '@botpress/client'\nimport type * as sdk from '@botpress/sdk'\nimport * as utils from '../utils'\n\nexport type CreatePluginBody = utils.types.Merge<\n Parameters<Client['createPlugin']>[0],\n {\n code?: string\n }\n>\nexport type UpdatePluginBody = Parameters<Client['updatePlugin']>[0]\n\nexport const prepareCreatePluginBody = async (plugin: sdk.PluginDefinition): Promise<CreatePluginBody> => ({\n name: plugin.name,\n version: plugin.version,\n user: {\n tags: plugin.user?.tags ?? {},\n },\n configuration: plugin.configuration\n ? {\n ...plugin.configuration,\n schema: await utils.schema.mapZodToJsonSchema(plugin.configuration),\n }\n : undefined,\n events: plugin.events\n ? await utils.records.mapValuesAsync(plugin.events, async (event) => ({\n ...event,\n schema: await utils.schema.mapZodToJsonSchema(event),\n }))\n : undefined,\n actions: plugin.actions\n ? await utils.records.mapValuesAsync(plugin.actions, async (action) => ({\n ...action,\n input: {\n ...action.input,\n schema: await utils.schema.mapZodToJsonSchema(action.input),\n },\n output: {\n ...action.output,\n schema: await utils.schema.mapZodToJsonSchema(action.output),\n },\n }))\n : undefined,\n states: plugin.states\n ? await utils.records.mapValuesAsync(plugin.states, async (state) => ({\n ...state,\n schema: await utils.schema.mapZodToJsonSchema(state),\n }))\n : undefined,\n})\n\nexport const prepareUpdatePluginBody = (localPlugin: UpdatePluginBody, remotePlugin: Plugin): UpdatePluginBody => {\n const actions = utils.records.setNullOnMissingValues(localPlugin.actions, remotePlugin.actions)\n const events = utils.records.setNullOnMissingValues(localPlugin.events, remotePlugin.events)\n const states = utils.records.setNullOnMissingValues(localPlugin.states, remotePlugin.states)\n\n return {\n ...localPlugin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AAO;AAC9F,QAAM,SAAS,MAAM,QAAQ,uBAAuB,YAAY,QAAQ,aAAa,MAAM;AAC3F,QAAM,SAAS,MAAM,QAAQ,uBAAuB,YAAY,QAAQ,aAAa,MAAM;AAE3F,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,YAAY;AAAA,EACpB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/api/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/api/types.ts"],
|
|
4
|
-
"sourcesContent": ["import * as client from '@botpress/client'\nimport { Logger } from 'src/logger'\nimport { ApiClient } from './client'\n\nexport type ApiClientProps = {\n apiUrl: string\n token: string\n workspaceId: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\nexport type PublicIntegration = client.Integration\nexport type PrivateIntegration = client.Integration & { workspaceId: string }\nexport type Integration = client.Integration & { workspaceId?: string }\nexport type IntegrationSummary = client.ClientOutputs['listIntegrations']['integrations'][number]\n\nexport type BotSummary = client.ClientOutputs['listBots']['bots'][number]\n\nexport type Interface = client.Interface\n\nexport type BaseOperation = (...args: any[]) => Promise<any>\nexport type Operations = {\n [K in keyof client.Client as client.Client[K] extends BaseOperation ? K : never]: client.Client[K]\n}\nexport type Requests = {\n [K in keyof Operations]: Parameters<Operations[K]>[0]\n}\nexport type Responses = {\n [K in keyof Operations]: ReturnType<Operations[K]>\n}\n"],
|
|
4
|
+
"sourcesContent": ["import * as client from '@botpress/client'\nimport { Logger } from 'src/logger'\nimport { ApiClient } from './client'\n\nexport type ApiClientProps = {\n apiUrl: string\n token: string\n workspaceId: string\n}\n\nexport type ApiClientFactory = {\n newClient: (props: ApiClientProps, logger: Logger) => ApiClient\n}\n\nexport type PublicIntegration = client.Integration\nexport type PrivateIntegration = client.Integration & { workspaceId: string }\nexport type Integration = client.Integration & { workspaceId?: string }\nexport type IntegrationSummary = client.ClientOutputs['listIntegrations']['integrations'][number]\n\nexport type BotSummary = client.ClientOutputs['listBots']['bots'][number]\n\nexport type Interface = client.Interface\nexport type Plugin = client.Plugin\n\nexport type BaseOperation = (...args: any[]) => Promise<any>\nexport type Operations = {\n [K in keyof client.Client as client.Client[K] extends BaseOperation ? K : never]: client.Client[K]\n}\nexport type Requests = {\n [K in keyof Operations]: Parameters<Operations[K]>[0]\n}\nexport type Responses = {\n [K in keyof Operations]: ReturnType<Operations[K]>\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,9 +29,11 @@ __export(bot_implementation_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(bot_implementation_exports);
|
|
30
30
|
var consts = __toESM(require("../consts"));
|
|
31
31
|
var import_module = require("../module");
|
|
32
|
+
var import_bot_plugins = require("./bot-plugins");
|
|
32
33
|
var import_bot_typings = require("./bot-typings");
|
|
33
34
|
class BotImplementationModule extends import_module.Module {
|
|
34
35
|
_typingsModule;
|
|
36
|
+
_pluginsModule;
|
|
35
37
|
constructor(bot) {
|
|
36
38
|
super({
|
|
37
39
|
exportName: "Bot",
|
|
@@ -40,27 +42,56 @@ class BotImplementationModule extends import_module.Module {
|
|
|
40
42
|
this._typingsModule = new import_bot_typings.BotTypingsModule(bot);
|
|
41
43
|
this._typingsModule.unshift("typings");
|
|
42
44
|
this.pushDep(this._typingsModule);
|
|
45
|
+
this._pluginsModule = new import_bot_plugins.BotPluginsIndexModule(bot);
|
|
46
|
+
this._pluginsModule.unshift(consts.fromOutDir.pluginsDir);
|
|
47
|
+
this.pushDep(this._pluginsModule);
|
|
43
48
|
}
|
|
44
49
|
async getContent() {
|
|
45
|
-
const
|
|
50
|
+
const {
|
|
51
|
+
_typingsModule: typingsModule,
|
|
52
|
+
_pluginsModule: pluginsModule
|
|
53
|
+
} = this;
|
|
54
|
+
const typingsImport = typingsModule.import(this);
|
|
55
|
+
const pluginsImport = pluginsModule.import(this);
|
|
46
56
|
return [
|
|
47
57
|
consts.GENERATED_HEADER,
|
|
48
58
|
'import * as sdk from "@botpress/sdk"',
|
|
49
|
-
`import * as ${
|
|
59
|
+
`import * as ${typingsModule.name} from "./${typingsImport}"`,
|
|
60
|
+
`import * as ${pluginsModule.name} from "./${pluginsImport}"`,
|
|
61
|
+
"",
|
|
50
62
|
`export * from "./${typingsImport}"`,
|
|
63
|
+
`export * from "./${pluginsImport}"`,
|
|
64
|
+
"",
|
|
65
|
+
`type TPlugins = ${pluginsModule.name}.TPlugins`,
|
|
66
|
+
`type TBot = sdk.DefaultBot<${typingsModule.name}.${typingsModule.exportName}>`,
|
|
51
67
|
"",
|
|
52
|
-
|
|
68
|
+
"export type BotProps = {",
|
|
69
|
+
' actions: sdk.BotProps<TBot, TPlugins>["actions"]',
|
|
70
|
+
"}",
|
|
53
71
|
"",
|
|
54
|
-
"export class Bot extends sdk.Bot<TBot> {
|
|
72
|
+
"export class Bot extends sdk.Bot<TBot, TPlugins> {",
|
|
73
|
+
" public constructor(props: BotProps) {",
|
|
74
|
+
" super({",
|
|
75
|
+
" actions: props.actions,",
|
|
76
|
+
` plugins: ${pluginsModule.name}.${pluginsModule.exportName}`,
|
|
77
|
+
" })",
|
|
78
|
+
" }",
|
|
79
|
+
"}",
|
|
55
80
|
"",
|
|
56
81
|
"// extra types",
|
|
57
82
|
"",
|
|
58
83
|
"type AsyncFunction = (...args: any[]) => Promise<any>",
|
|
59
|
-
"export type
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"export type
|
|
63
|
-
"
|
|
84
|
+
"export type EventHandlers = Required<{",
|
|
85
|
+
" [K in keyof Bot['eventHandlers']]: NonNullable<Bot['eventHandlers'][K]>[number]",
|
|
86
|
+
"}>",
|
|
87
|
+
"export type MessageHandlers = Required<{",
|
|
88
|
+
" [K in keyof Bot['messageHandlers']]: NonNullable<Bot['messageHandlers'][K]>[number]",
|
|
89
|
+
"}>",
|
|
90
|
+
"",
|
|
91
|
+
"export type MessageHandlerProps = Parameters<MessageHandlers['*']>[0]",
|
|
92
|
+
"export type EventHandlerProps = Parameters<EventHandlers['*']>[0]",
|
|
93
|
+
"",
|
|
94
|
+
"export type Client = (MessageHandlerProps | EventHandlerProps)['client']",
|
|
64
95
|
"export type ClientOperation = keyof {",
|
|
65
96
|
" [K in keyof Client as Client[K] extends AsyncFunction ? K : never]: null",
|
|
66
97
|
"}",
|
|
@@ -69,18 +100,6 @@ class BotImplementationModule extends import_module.Module {
|
|
|
69
100
|
"}",
|
|
70
101
|
"export type ClientOutputs = {",
|
|
71
102
|
" [K in ClientOperation]: Awaited<ReturnType<Client[K]>>",
|
|
72
|
-
"}",
|
|
73
|
-
"// @deprecated",
|
|
74
|
-
"export type BotEvent = EventHandlerProps['event']",
|
|
75
|
-
"// @deprecated",
|
|
76
|
-
"export type BotEvents = {",
|
|
77
|
-
" [K in BotEvent['type']]: Extract<BotEvent, { type: K }>",
|
|
78
|
-
"}",
|
|
79
|
-
"// @deprecated",
|
|
80
|
-
"export type BotState = ClientOutputs['getState']['state']",
|
|
81
|
-
"// @deprecated",
|
|
82
|
-
"export type BotStates = {",
|
|
83
|
-
" [K in BotState['name']]: Extract<BotState, { type: K }>['payload']",
|
|
84
103
|
"}"
|
|
85
104
|
].join("\n");
|
|
86
105
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/code-generation/bot-implementation/bot-implementation.ts"],
|
|
4
|
-
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../consts'\nimport { Module } from '../module'\nimport { BotTypingsModule } from './bot-typings'\n\nexport class BotImplementationModule extends Module {\n private _typingsModule: BotTypingsModule\n\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'Bot',\n path: consts.INDEX_FILE,\n })\n\n this._typingsModule = new BotTypingsModule(bot)\n this._typingsModule.unshift('typings')\n this.pushDep(this._typingsModule)\n }\n\n public async getContent() {\n const typingsImport = this.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,oBAAuB;AACvB,yBAAiC;AAE1B,MAAM,gCAAgC,qBAAO;AAAA,EAC1C;AAAA,EAED,YAAY,KAAwB;AACzC,UAAM;AAAA,MACJ,YAAY;AAAA,MACZ,MAAM,OAAO;AAAA,IACf,CAAC;AAED,SAAK,iBAAiB,IAAI,oCAAiB,GAAG;AAC9C,SAAK,eAAe,QAAQ,SAAS;AACrC,SAAK,QAAQ,KAAK,cAAc;AAAA,EAClC;AAAA,EAEA,MAAa,aAAa;AACxB,UAAM,gBAAgB,
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../consts'\nimport { Module } from '../module'\nimport { BotPluginsIndexModule } from './bot-plugins'\nimport { BotTypingsModule } from './bot-typings'\n\nexport class BotImplementationModule extends Module {\n private _typingsModule: BotTypingsModule\n private _pluginsModule: BotPluginsIndexModule\n\n public constructor(bot: sdk.BotDefinition) {\n super({\n exportName: 'Bot',\n path: consts.INDEX_FILE,\n })\n\n this._typingsModule = new BotTypingsModule(bot)\n this._typingsModule.unshift('typings')\n this.pushDep(this._typingsModule)\n\n this._pluginsModule = new BotPluginsIndexModule(bot)\n this._pluginsModule.unshift(consts.fromOutDir.pluginsDir)\n this.pushDep(this._pluginsModule)\n }\n\n public async getContent() {\n const {\n //\n _typingsModule: typingsModule,\n _pluginsModule: pluginsModule,\n } = this\n\n const typingsImport = typingsModule.import(this)\n const pluginsImport = pluginsModule.import(this)\n\n return [\n consts.GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n `import * as ${typingsModule.name} from \"./${typingsImport}\"`,\n `import * as ${pluginsModule.name} from \"./${pluginsImport}\"`,\n '',\n `export * from \"./${typingsImport}\"`,\n `export * from \"./${pluginsImport}\"`,\n '',\n `type TPlugins = ${pluginsModule.name}.TPlugins`,\n `type TBot = sdk.DefaultBot<${typingsModule.name}.${typingsModule.exportName}>`,\n '',\n 'export type BotProps = {',\n ' actions: sdk.BotProps<TBot, TPlugins>[\"actions\"]',\n '}',\n '',\n 'export class Bot extends sdk.Bot<TBot, TPlugins> {',\n ' public constructor(props: BotProps) {',\n ' super({',\n ' actions: props.actions,',\n ` plugins: ${pluginsModule.name}.${pluginsModule.exportName}`,\n ' })',\n ' }',\n '}',\n '',\n '// extra types',\n '',\n 'type AsyncFunction = (...args: any[]) => Promise<any>',\n 'export type EventHandlers = Required<{',\n \" [K in keyof Bot['eventHandlers']]: NonNullable<Bot['eventHandlers'][K]>[number]\",\n '}>',\n 'export type MessageHandlers = Required<{',\n \" [K in keyof Bot['messageHandlers']]: NonNullable<Bot['messageHandlers'][K]>[number]\",\n '}>',\n '',\n \"export type MessageHandlerProps = Parameters<MessageHandlers['*']>[0]\",\n \"export type EventHandlerProps = Parameters<EventHandlers['*']>[0]\",\n '',\n \"export type Client = (MessageHandlerProps | EventHandlerProps)['client']\",\n 'export type ClientOperation = keyof {',\n ' [K in keyof Client as Client[K] extends AsyncFunction ? K : never]: null',\n '}',\n 'export type ClientInputs = {',\n ' [K in ClientOperation]: Parameters<Client[K]>[0]',\n '}',\n 'export type ClientOutputs = {',\n ' [K in ClientOperation]: Awaited<ReturnType<Client[K]>>',\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,oBAAuB;AACvB,yBAAsC;AACtC,yBAAiC;AAE1B,MAAM,gCAAgC,qBAAO;AAAA,EAC1C;AAAA,EACA;AAAA,EAED,YAAY,KAAwB;AACzC,UAAM;AAAA,MACJ,YAAY;AAAA,MACZ,MAAM,OAAO;AAAA,IACf,CAAC;AAED,SAAK,iBAAiB,IAAI,oCAAiB,GAAG;AAC9C,SAAK,eAAe,QAAQ,SAAS;AACrC,SAAK,QAAQ,KAAK,cAAc;AAEhC,SAAK,iBAAiB,IAAI,yCAAsB,GAAG;AACnD,SAAK,eAAe,QAAQ,OAAO,WAAW,UAAU;AACxD,SAAK,QAAQ,KAAK,cAAc;AAAA,EAClC;AAAA,EAEA,MAAa,aAAa;AACxB,UAAM;AAAA,MAEJ,gBAAgB;AAAA,MAChB,gBAAgB;AAAA,IAClB,IAAI;AAEJ,UAAM,gBAAgB,cAAc,OAAO,IAAI;AAC/C,UAAM,gBAAgB,cAAc,OAAO,IAAI;AAE/C,WAAO;AAAA,MACL,OAAO;AAAA,MACP;AAAA,MACA,eAAe,cAAc,gBAAgB;AAAA,MAC7C,eAAe,cAAc,gBAAgB;AAAA,MAC7C;AAAA,MACA,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB;AAAA,MACA,mBAAmB,cAAc;AAAA,MACjC,8BAA8B,cAAc,QAAQ,cAAc;AAAA,MAClE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAkB,cAAc,QAAQ,cAAc;AAAA,MACtD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,EAAE,KAAK,IAAI;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
22
|
+
mod2
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
25
|
+
var bot_plugins_exports = {};
|
|
26
|
+
__export(bot_plugins_exports, {
|
|
27
|
+
BotPluginsIndexModule: () => BotPluginsIndexModule
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(bot_plugins_exports);
|
|
30
|
+
var consts = __toESM(require("../../consts"));
|
|
31
|
+
var mod = __toESM(require("../../module"));
|
|
32
|
+
var strings = __toESM(require("../../strings"));
|
|
33
|
+
var import_plugin_module = require("./plugin-module");
|
|
34
|
+
class BotPluginsIndexModule extends mod.Module {
|
|
35
|
+
_pluginModules;
|
|
36
|
+
constructor(sdkBotDefinition) {
|
|
37
|
+
super({
|
|
38
|
+
path: consts.INDEX_FILE,
|
|
39
|
+
exportName: "plugins"
|
|
40
|
+
});
|
|
41
|
+
const pluginsModules = [];
|
|
42
|
+
for (const plugin of Object.values(sdkBotDefinition.plugins ?? {})) {
|
|
43
|
+
const pluginModule = new import_plugin_module.BotPluginModule(plugin);
|
|
44
|
+
pluginModule.unshift(plugin.name);
|
|
45
|
+
this.pushDep(pluginModule);
|
|
46
|
+
pluginsModules.push(pluginModule);
|
|
47
|
+
}
|
|
48
|
+
this._pluginModules = pluginsModules;
|
|
49
|
+
}
|
|
50
|
+
async getContent() {
|
|
51
|
+
const modules = this._pluginModules.map((module2) => ({
|
|
52
|
+
importAlias: strings.importAlias(module2.name),
|
|
53
|
+
importFrom: module2.import(this),
|
|
54
|
+
module: module2
|
|
55
|
+
}));
|
|
56
|
+
return [
|
|
57
|
+
consts.GENERATED_HEADER,
|
|
58
|
+
'import * as sdk from "@botpress/sdk"',
|
|
59
|
+
...modules.map(({ importAlias, importFrom }) => `import * as ${importAlias} from "./${importFrom}";`),
|
|
60
|
+
...modules.map(({ importAlias, importFrom }) => `export * as ${importAlias} from "./${importFrom}";`),
|
|
61
|
+
"",
|
|
62
|
+
`export const ${this.exportName} = {`,
|
|
63
|
+
...modules.map(({ module: module2, importAlias }) => ` "${module2.pluginName}": ${importAlias}.${module2.exportName},`),
|
|
64
|
+
"}",
|
|
65
|
+
"",
|
|
66
|
+
"export type TPlugins = {",
|
|
67
|
+
...modules.map(({ module: module2, importAlias }) => ` "${module2.pluginName}": ${importAlias}.TPlugin;`),
|
|
68
|
+
"}"
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
BotPluginsIndexModule
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/code-generation/bot-implementation/bot-plugins/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as sdk from '@botpress/sdk'\nimport * as consts from '../../consts'\nimport * as mod from '../../module'\nimport * as strings from '../../strings'\nimport { BotPluginModule } from './plugin-module'\n\nexport class BotPluginsIndexModule extends mod.Module {\n private _pluginModules: BotPluginModule[]\n\n public constructor(sdkBotDefinition: sdk.BotDefinition) {\n super({\n path: consts.INDEX_FILE,\n exportName: 'plugins',\n })\n\n const pluginsModules: BotPluginModule[] = []\n for (const plugin of Object.values(sdkBotDefinition.plugins ?? {})) {\n const pluginModule = new BotPluginModule(plugin)\n pluginModule.unshift(plugin.name)\n this.pushDep(pluginModule)\n pluginsModules.push(pluginModule)\n }\n\n this._pluginModules = pluginsModules\n }\n\n public async getContent(): Promise<string> {\n const modules = this._pluginModules.map((module) => ({\n importAlias: strings.importAlias(module.name),\n importFrom: module.import(this),\n module,\n }))\n\n return [\n consts.GENERATED_HEADER,\n 'import * as sdk from \"@botpress/sdk\"',\n ...modules.map(({ importAlias, importFrom }) => `import * as ${importAlias} from \"./${importFrom}\";`),\n ...modules.map(({ importAlias, importFrom }) => `export * as ${importAlias} from \"./${importFrom}\";`),\n '',\n `export const ${this.exportName} = {`,\n ...modules.map(({ module, importAlias }) => ` \"${module.pluginName}\": ${importAlias}.${module.exportName},`),\n '}',\n '',\n 'export type TPlugins = {',\n ...modules.map(({ module, importAlias }) => ` \"${module.pluginName}\": ${importAlias}.TPlugin;`),\n '}',\n ].join('\\n')\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,aAAwB;AACxB,UAAqB;AACrB,cAAyB;AACzB,2BAAgC;AAEzB,MAAM,8BAA8B,IAAI,OAAO;AAAA,EAC5C;AAAA,EAED,YAAY,kBAAqC;AACtD,UAAM;AAAA,MACJ,MAAM,OAAO;AAAA,MACb,YAAY;AAAA,IACd,CAAC;AAED,UAAM,iBAAoC,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