@botpress/sdk 4.21.0 → 5.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.
Files changed (41) hide show
  1. package/.turbo/turbo-build.log +5 -5
  2. package/dist/bot/definition.d.ts +45 -7
  3. package/dist/bot/server/types.d.ts +2 -5
  4. package/dist/bot/workflow-proxy/proxy.d.ts +7 -3
  5. package/dist/bot/workflow-proxy/types.d.ts +24 -23
  6. package/dist/common/index.d.ts +1 -0
  7. package/dist/common/types.d.ts +2 -0
  8. package/dist/fixtures.d.ts +84 -13
  9. package/dist/index.cjs +41 -38
  10. package/dist/index.cjs.map +4 -4
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.mjs +33 -30
  13. package/dist/index.mjs.map +4 -4
  14. package/dist/integration/client/types.d.ts +15 -14
  15. package/dist/integration/common/index.d.ts +0 -1
  16. package/dist/integration/server/types.d.ts +8 -7
  17. package/dist/plugin/common/generic.d.ts +12 -0
  18. package/dist/plugin/common/types.d.ts +17 -5
  19. package/dist/plugin/conversation-proxy/index.d.ts +2 -0
  20. package/dist/plugin/conversation-proxy/proxy.d.ts +13 -0
  21. package/dist/plugin/conversation-proxy/types.d.ts +54 -0
  22. package/dist/plugin/conversation-proxy/types.test.d.ts +1 -0
  23. package/dist/plugin/definition.d.ts +1 -1
  24. package/dist/plugin/event-proxy/proxy.d.ts +2 -2
  25. package/dist/plugin/event-proxy/types.d.ts +11 -6
  26. package/dist/plugin/implementation.d.ts +4 -4
  27. package/dist/plugin/message-proxy/index.d.ts +2 -0
  28. package/dist/plugin/message-proxy/proxy.d.ts +13 -0
  29. package/dist/plugin/message-proxy/types.d.ts +22 -0
  30. package/dist/plugin/server/types.d.ts +129 -51
  31. package/dist/plugin/tag-prefixer.d.ts +10 -0
  32. package/dist/plugin/tag-prefixer.test.d.ts +1 -0
  33. package/dist/plugin/user-proxy/index.d.ts +2 -0
  34. package/dist/plugin/user-proxy/proxy.d.ts +14 -0
  35. package/dist/plugin/user-proxy/types.d.ts +30 -0
  36. package/dist/utils/api-paging-utils.d.ts +43 -0
  37. package/dist/utils/api-paging-utils.test.d.ts +1 -0
  38. package/dist/utils/type-utils.d.ts +1 -0
  39. package/package.json +1 -1
  40. package/dist/integration/common/types.d.ts +0 -2
  41. package/dist/plugin/interface-resolution.d.ts +0 -15
@@ -1,20 +1,20 @@
1
1
 
2
- > @botpress/sdk@4.21.0 build /home/runner/work/botpress/botpress/packages/sdk
2
+ > @botpress/sdk@5.0.0 build /home/runner/work/botpress/botpress/packages/sdk
3
3
  > pnpm build:type && pnpm build:node && pnpm build:browser
4
4
 
5
5
 
6
- > @botpress/sdk@4.21.0 build:type /home/runner/work/botpress/botpress/packages/sdk
6
+ > @botpress/sdk@5.0.0 build:type /home/runner/work/botpress/botpress/packages/sdk
7
7
  > tsc -p ./tsconfig.package.json --emitDeclarationOnly --declaration
8
8
 
9
9
 
10
- > @botpress/sdk@4.21.0 build:node /home/runner/work/botpress/botpress/packages/sdk
10
+ > @botpress/sdk@5.0.0 build:node /home/runner/work/botpress/botpress/packages/sdk
11
11
  > ts-node -T ./build.ts --node
12
12
 
13
13
  Done
14
14
 
15
- > @botpress/sdk@4.21.0 build:browser /home/runner/work/botpress/botpress/packages/sdk
15
+ > @botpress/sdk@5.0.0 build:browser /home/runner/work/botpress/botpress/packages/sdk
16
16
  > ts-node -T ./build.ts --browser
17
17
 
18
- (node:3050) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
18
+ (node:3093) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
19
19
  (Use `node --trace-deprecation ...` to show where the warning was created)
20
20
  Done
@@ -1,6 +1,6 @@
1
1
  import { Table } from '@botpress/client';
2
2
  import { IntegrationPackage, PluginPackage } from '../package';
3
- import { PluginInterfaceExtension } from '../plugin';
3
+ import { PluginInterfaceExtension, PluginIntegrationExtension } from '../plugin';
4
4
  import { SchemaDefinition } from '../schema';
5
5
  import { ValueOf, Merge, StringKeys } from '../utils/type-utils';
6
6
  import z, { ZuiObjectSchema, ZuiObjectOrRefSchema } from '../zui';
@@ -58,9 +58,9 @@ export type WorkflowDefinition<TWorkflow extends BaseWorkflows[string] = BaseWor
58
58
  export type TableDefinition<TTable extends BaseTables[string] = BaseTables[string]> = Merge<Omit<Table, 'id' | 'createdAt' | 'updatedAt' | 'name'>, {
59
59
  schema: TTable;
60
60
  }>;
61
- export type IntegrationConfigInstance<I extends IntegrationPackage = IntegrationPackage> = {
62
- enabled: boolean;
63
- alias?: string;
61
+ export type ResolvedIntegrationConfigInstance<I extends IntegrationPackage = IntegrationPackage> = {
62
+ enabled?: boolean;
63
+ alias: string;
64
64
  disabledChannels?: StringKeys<NonNullable<I['definition']['channels']>>[];
65
65
  } & ({
66
66
  configurationType?: null;
@@ -71,15 +71,53 @@ export type IntegrationConfigInstance<I extends IntegrationPackage = Integration
71
71
  configuration: z.infer<NonNullable<I['definition']['configurations']>[K]['schema']>;
72
72
  };
73
73
  }>);
74
- export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
74
+ type IntegrationConfigInstance<I extends IntegrationPackage = IntegrationPackage> = Omit<ResolvedIntegrationConfigInstance<I>, 'alias'> & {
75
75
  alias?: string;
76
+ };
77
+ type _ResolvedPluginConfigInstance<P extends PluginPackage = PluginPackage> = {
78
+ alias: string;
76
79
  configuration: z.infer<NonNullable<P['definition']['configuration']>['schema']>;
77
80
  interfaces: {
78
81
  [I in keyof NonNullable<P['definition']['interfaces']>]: PluginInterfaceExtension;
79
82
  };
83
+ integrations: {
84
+ [I in keyof NonNullable<P['definition']['integrations']>]: PluginIntegrationExtension;
85
+ };
86
+ };
87
+ type PluginConfigInstance<P extends PluginPackage = PluginPackage> = Omit<_ResolvedPluginConfigInstance<P>, 'alias' | 'integrations' | 'interfaces'> & {
88
+ alias?: string;
89
+ /** Backing integrations for the plugin's dependencies */
90
+ dependencies: {
91
+ [K in StringKeys<NonNullable<P['definition']['interfaces']>>]: {
92
+ /**
93
+ * Alias of the integration to use to fullfil this dependency.
94
+ *
95
+ * This is the alias given when adding the integration to the bot
96
+ * via `addIntegration()`.
97
+ */
98
+ integrationAlias: string;
99
+ /**
100
+ * Alias of the interface within the integration.
101
+ *
102
+ * This is the alias defined by the integration package for the
103
+ * interface it implements.
104
+ */
105
+ integrationInterfaceAlias: string;
106
+ };
107
+ } & {
108
+ [K in StringKeys<NonNullable<P['definition']['integrations']>>]: {
109
+ /**
110
+ * Alias of the integration to use to fullfil this dependency.
111
+ *
112
+ * This is the alias given when adding the integration to the bot
113
+ * via `addIntegration()`.
114
+ */
115
+ integrationAlias: string;
116
+ };
117
+ };
80
118
  };
81
- export type IntegrationInstance = IntegrationPackage & Partial<IntegrationConfigInstance>;
82
- export type PluginInstance = PluginPackage & PluginConfigInstance;
119
+ export type IntegrationInstance = IntegrationPackage & ResolvedIntegrationConfigInstance;
120
+ export type PluginInstance = PluginPackage & _ResolvedPluginConfigInstance;
83
121
  export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> = {
84
122
  integrations?: {
85
123
  [K: string]: IntegrationInstance;
@@ -181,7 +181,7 @@ export type WorkflowPayloads<TBot extends common.BaseBot> = {
181
181
  * # EXPERIMENTAL
182
182
  * This API is experimental and may change in the future.
183
183
  */
184
- workflow: workflowProxy.WorkflowWithUtilities<TBot, TWorkflowName>;
184
+ workflow: workflowProxy.ActionableWorkflow<TBot, TWorkflowName>;
185
185
  };
186
186
  };
187
187
  export type WorkflowHandlers<TBot extends common.BaseBot> = {
@@ -377,10 +377,7 @@ export type InjectedBotHandlers<TBot extends common.BaseBot> = {
377
377
  };
378
378
  workflowHandlers: {
379
379
  [TWorkflowUpdateType in WorkflowUpdateType]: {
380
- [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: {
381
- handler: WorkflowHandlers<TBot>[TWorkflowName];
382
- order: number;
383
- }[];
380
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: WorkflowHandlers<TBot>[TWorkflowName][];
384
381
  };
385
382
  };
386
383
  };
@@ -3,11 +3,15 @@ import type { BotSpecificClient } from '../../bot';
3
3
  import type * as typeUtils from '../../utils/type-utils';
4
4
  import type { BaseBot } from '../common';
5
5
  import * as botServerTypes from '../server/types';
6
- import type { WorkflowProxy, WorkflowWithUtilities } from './types';
7
- export declare const proxyWorkflows: <TBot extends BaseBot>(client: BotSpecificClient<TBot> | client.Client) => WorkflowProxy<TBot>;
6
+ import type { WorkflowProxy, ActionableWorkflow } from './types';
7
+ export declare const proxyWorkflows: <TBot extends BaseBot>(props: {
8
+ client: BotSpecificClient<TBot> | client.Client;
9
+ pluginAlias?: string;
10
+ }) => WorkflowProxy<TBot>;
8
11
  export declare const wrapWorkflowInstance: <TBot extends BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot["workflows"]>>(props: {
9
12
  client: BotSpecificClient<TBot> | client.Client;
10
13
  workflow: client.Workflow;
11
14
  event?: botServerTypes.WorkflowUpdateEvent;
12
15
  onWorkflowUpdate?: (newState: client.Workflow) => Promise<void> | void;
13
- }) => WorkflowWithUtilities<TBot, TWorkflowName>;
16
+ pluginAlias?: string;
17
+ }) => ActionableWorkflow<TBot, TWorkflowName>;
@@ -1,4 +1,5 @@
1
1
  import type * as client from '@botpress/client';
2
+ import { AsyncCollection } from '../../utils/api-paging-utils';
2
3
  import type * as typeUtils from '../../utils/type-utils';
3
4
  import type * as commonTypes from '../common';
4
5
  export type WorkflowProxy<TBot extends commonTypes.BaseBot = commonTypes.BaseBot> = Readonly<{
@@ -7,26 +8,27 @@ export type WorkflowProxy<TBot extends commonTypes.BaseBot = commonTypes.BaseBot
7
8
  tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
8
9
  input: TBot['workflows'][TWorkflowName]['input'];
9
10
  }) => Promise<Readonly<Omit<client.ClientOutputs['createWorkflow'], 'workflow'> & {
10
- workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
11
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
11
12
  }>>;
12
- listInstances: Readonly<{
13
- all: _ListInstances<TBot, TWorkflowName>;
14
- running: _ListInstances<TBot, TWorkflowName>;
15
- scheduled: _ListInstances<TBot, TWorkflowName>;
16
- allFinished: _ListInstances<TBot, TWorkflowName>;
17
- succeeded: _ListInstances<TBot, TWorkflowName>;
18
- cancelled: _ListInstances<TBot, TWorkflowName>;
19
- timedOut: _ListInstances<TBot, TWorkflowName>;
20
- failed: _ListInstances<TBot, TWorkflowName>;
21
- }>;
13
+ listInstances: (x?: Pick<client.ClientInputs['listWorkflows'], 'conversationId' | 'userId'> & {
14
+ tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
15
+ /**
16
+ * Filter by statuses:
17
+ *
18
+ * - `pending` - Workflow is created but not started yet
19
+ * - `in_progress` - Workflow is currently running
20
+ * - `failed` - Workflow finished with errors
21
+ * - `completed` - Workflow finished successfully
22
+ * - `cancelled` - Workflow finished due to cancellation through the API
23
+ * - `timedout` - Workflow finished due to timeout
24
+ * - `listening` - Workflow is waiting for an event to continue
25
+ * - `paused` - Workflow was paused through the API
26
+ */
27
+ statuses?: client.Workflow['status'][];
28
+ }) => AsyncCollection<ActionableWorkflow<TBot, TWorkflowName>>;
22
29
  }>;
23
30
  }>;
24
- type _ListInstances<TBot extends commonTypes.BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot['workflows']>> = (x?: Pick<client.ClientInputs['listWorkflows'], 'nextToken' | 'conversationId' | 'userId'> & {
25
- tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
26
- }) => Promise<Readonly<Omit<client.ClientOutputs['listWorkflows'], 'workflows'> & {
27
- workflows: WorkflowWithUtilities<TBot, TWorkflowName>[];
28
- }>>;
29
- export type WorkflowWithUtilities<TBot extends commonTypes.BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot['workflows']>> = Readonly<client.Workflow & {
31
+ export type ActionableWorkflow<TBot extends commonTypes.BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot['workflows']>> = Readonly<client.Workflow & {
30
32
  name: TWorkflowName;
31
33
  input: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['input'];
32
34
  output: Partial<typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output']>;
@@ -38,7 +40,7 @@ export type WorkflowWithUtilities<TBot extends commonTypes.BaseBot, TWorkflowNam
38
40
  tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
39
41
  output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
40
42
  }>): Promise<{
41
- workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
43
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
42
44
  }>;
43
45
  /**
44
46
  * Acknowledges the start of processing for a pending workflow instance.
@@ -53,13 +55,13 @@ export type WorkflowWithUtilities<TBot extends commonTypes.BaseBot, TWorkflowNam
53
55
  * retriggered 3 times before being marked as failed.
54
56
  */
55
57
  acknowledgeStartOfProcessing(): Promise<{
56
- workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
58
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
57
59
  }>;
58
60
  /**
59
61
  * Marks the current workflow instance as failed and stops execution
60
62
  */
61
63
  setFailed(x: Required<Pick<client.ClientInputs['updateWorkflow'], 'failureReason'>>): Promise<{
62
- workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
64
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
63
65
  }>;
64
66
  /**
65
67
  * Marks the current workflow instance as completed and stops execution
@@ -67,13 +69,12 @@ export type WorkflowWithUtilities<TBot extends commonTypes.BaseBot, TWorkflowNam
67
69
  setCompleted(x?: {
68
70
  output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
69
71
  }): Promise<{
70
- workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
72
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
71
73
  }>;
72
74
  /**
73
75
  * Discards all output data and cancels the current workflow instance
74
76
  */
75
77
  cancel(): Promise<{
76
- workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
78
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
77
79
  }>;
78
80
  }>;
79
- export {};
@@ -0,0 +1 @@
1
+ export type * as commonTypes from './types';
@@ -0,0 +1,2 @@
1
+ import * as typeUtils from '../utils/type-utils';
2
+ export type ToTags<TTags extends string | number | symbol> = typeUtils.Cast<Partial<Record<TTags, string>>, Record<string, string>>;
@@ -1,7 +1,8 @@
1
- import { DefaultBot } from './bot/common/generic';
2
- import { DefaultChannel, DefaultIntegration } from './integration/common/generic';
3
- import { DefaultPlugin } from './plugin/common/generic';
4
- type _FooBarBazIntegration = {
1
+ import type { DefaultBot } from './bot/common/generic';
2
+ import type { DefaultChannel, DefaultIntegration } from './integration/common/generic';
3
+ import type { DefaultInterface } from './interface/common/generic';
4
+ import type { DefaultPlugin } from './plugin/common/generic';
5
+ export type FooBarBazIntegration = DefaultIntegration<{
5
6
  actions: {
6
7
  doFoo: {
7
8
  input: {
@@ -111,8 +112,8 @@ type _FooBarBazIntegration = {
111
112
  fooUserTag3: '';
112
113
  };
113
114
  };
114
- };
115
- type _TotoTutuTataInterface = {
115
+ }>;
116
+ export type TotoTutuTataInterface = DefaultInterface<{
116
117
  actions: {
117
118
  doToto: {
118
119
  input: {
@@ -150,12 +151,75 @@ type _TotoTutuTataInterface = {
150
151
  eventTata: boolean;
151
152
  };
152
153
  };
153
- };
154
- export type FooBarBazIntegration = DefaultIntegration<_FooBarBazIntegration>;
155
- export type TotoTutuTataIntegration = DefaultIntegration<_TotoTutuTataInterface>;
154
+ channels: {
155
+ channelFoo: DefaultChannel<{
156
+ messages: {
157
+ messageFoo: {
158
+ foo: string;
159
+ };
160
+ };
161
+ message: {
162
+ tags: {
163
+ fooMessageTag1: '';
164
+ fooMessageTag2: '';
165
+ fooMessageTag3: '';
166
+ };
167
+ };
168
+ conversation: {
169
+ tags: {
170
+ fooConversationTag1: '';
171
+ fooConversationTag2: '';
172
+ fooConversationTag3: '';
173
+ };
174
+ };
175
+ }>;
176
+ channelBar: DefaultChannel<{
177
+ messages: {
178
+ messageBar: {
179
+ bar: number;
180
+ };
181
+ };
182
+ message: {
183
+ tags: {
184
+ barMessageTag1: '';
185
+ barMessageTag2: '';
186
+ barMessageTag3: '';
187
+ };
188
+ };
189
+ conversation: {
190
+ tags: {
191
+ barConversationTag1: '';
192
+ barConversationTag2: '';
193
+ barConversationTag3: '';
194
+ };
195
+ };
196
+ }>;
197
+ channelBaz: DefaultChannel<{
198
+ messages: {
199
+ messageBaz: {
200
+ baz: boolean;
201
+ };
202
+ };
203
+ message: {
204
+ tags: {
205
+ bazMessageTag1: '';
206
+ bazMessageTag2: '';
207
+ bazMessageTag3: '';
208
+ };
209
+ };
210
+ conversation: {
211
+ tags: {
212
+ bazConversationTag1: '';
213
+ bazConversationTag2: '';
214
+ bazConversationTag3: '';
215
+ };
216
+ };
217
+ }>;
218
+ };
219
+ }>;
156
220
  export type FooBarBazBot = DefaultBot<{
157
221
  integrations: {
158
- fooBarBaz: _FooBarBazIntegration;
222
+ fooBarBaz: FooBarBazIntegration;
159
223
  };
160
224
  actions: {
161
225
  act: {
@@ -202,10 +266,17 @@ export type FooBarBazBot = DefaultBot<{
202
266
  }>;
203
267
  export type FooBarBazPlugin = DefaultPlugin<{
204
268
  integrations: {
205
- fooBarBaz: _FooBarBazIntegration;
269
+ fooBarBaz: FooBarBazIntegration;
206
270
  };
207
271
  interfaces: {
208
- totoTutuTata: _TotoTutuTataInterface;
272
+ totoTutuTata: TotoTutuTataInterface;
273
+ };
274
+ message: {
275
+ tags: {
276
+ pluginMessageTag1: '';
277
+ pluginMessageTag2: '';
278
+ pluginMessageTag3: '';
279
+ };
209
280
  };
210
281
  actions: {
211
282
  act: {
@@ -280,7 +351,7 @@ export type EmptyBot = DefaultBot<{
280
351
  }>;
281
352
  export type EmptyPlugin = DefaultPlugin<{
282
353
  integrations: {};
354
+ interfaces: {};
283
355
  actions: {};
284
356
  events: {};
285
357
  }>;
286
- export {};