@botpress/sdk 3.4.0 → 3.5.1

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/dist/package.d.ts CHANGED
@@ -40,6 +40,7 @@ type PluginPackageDefinition = NameVersion & {
40
40
  recurringEvents?: Record<string, plugin.RecurringEventDefinition>;
41
41
  actions?: Record<string, plugin.ActionDefinition>;
42
42
  tables?: Record<string, plugin.TableDefinition>;
43
+ workflows?: Record<string, plugin.WorkflowDefinition>;
43
44
  };
44
45
  export type IntegrationPackage = PackageReference & {
45
46
  type: 'integration';
@@ -6,114 +6,18 @@ export type BaseAction = {
6
6
  output: any;
7
7
  };
8
8
  export type BaseTable = {
9
- /**
10
- * Required. This name is used to identify your table.
11
- */
12
- name: string;
13
- /**
14
- * The 'factor' multiplies the row's data storage limit by 4KB and its quota count, but can only be set at table creation and not modified later. For instance, a factor of 2 increases storage to 8KB but counts as 2 rows in your quota. The default factor is 1.
15
- */
16
- factor?: number;
17
- /**
18
- * A table designated as "frozen" is immutable in terms of its name and schema structure; modifications to its schema or a renaming operation are not permitted. The only action that can be taken on such a table is deletion. The schema established at the time of creation is locked in as the final structure. To implement any changes, the table must be duplicated with the desired alterations.
19
- */
20
- frozen?: boolean;
21
- schema: {
22
- $schema?: string;
23
- /**
24
- * List of keys/columns in the table.
25
- */
26
- properties: {
27
- [k: string]: {
28
- type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null';
29
- format?: 'date-time';
30
- description?: string;
31
- /**
32
- * String properties must match this pattern
33
- */
34
- pattern?: string;
35
- /**
36
- * String properties must be one of these values
37
- */
38
- enum?: string[];
39
- /**
40
- * Defines the shape of items in an array
41
- */
42
- items?: {
43
- type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null';
44
- [k: string]: any;
45
- };
46
- nullable?: boolean;
47
- properties?: {
48
- [k: string]: {
49
- type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null';
50
- [k: string]: any;
51
- };
52
- };
53
- 'x-zui': {
54
- index: number;
55
- /**
56
- * Indicates if the column is vectorized and searchable.
57
- */
58
- searchable?: boolean;
59
- /**
60
- * Indicates if the field is hidden in the UI
61
- */
62
- hidden?: boolean;
63
- /**
64
- * Order of the column in the UI
65
- */
66
- order?: number;
67
- /**
68
- * Width of the column in the UI
69
- */
70
- width?: number;
71
- computed?: {
72
- action: 'ai' | 'code' | 'workflow';
73
- dependencies?: string[];
74
- /**
75
- * Prompt when action is "ai"
76
- */
77
- prompt?: string;
78
- /**
79
- * Code to execute when action is "code"
80
- */
81
- code?: string;
82
- /**
83
- * Model to use when action is "ai"
84
- */
85
- model?: string;
86
- /**
87
- * ID of Workflow to execute when action is "workflow"
88
- */
89
- workflowId?: string;
90
- enabled?: boolean;
91
- };
92
- };
93
- };
94
- };
95
- /**
96
- * Additional properties can be provided, but they will be ignored if no column matches.
97
- */
98
- additionalProperties: true;
99
- /**
100
- * Array of required properties.
101
- */
102
- required?: string[];
103
- type: 'object';
104
- };
105
- /**
106
- * Optional tags to help organize your tables. These should be passed here as an object representing key/value pairs.
107
- */
9
+ [k: string]: any;
10
+ };
11
+ export type BaseWorkflow = {
12
+ input: any;
13
+ output: any;
108
14
  tags?: {
109
15
  [k: string]: string;
110
16
  };
111
- /**
112
- * Indicates if the table is enabled for computation.
113
- */
114
- isComputeEnabled?: boolean;
115
17
  };
116
18
  export type BasePlugin = {
19
+ name: string;
20
+ version: string;
117
21
  configuration: any;
118
22
  integrations: Record<string, BaseIntegration>;
119
23
  interfaces: Record<string, BaseInterface>;
@@ -121,14 +25,18 @@ export type BasePlugin = {
121
25
  states: Record<string, any>;
122
26
  actions: Record<string, BaseAction>;
123
27
  tables: Record<string, BaseTable>;
28
+ workflows: Record<string, BaseWorkflow>;
124
29
  };
125
30
  export type InputBasePlugin = utils.DeepPartial<BasePlugin>;
126
31
  export type DefaultPlugin<B extends utils.DeepPartial<BasePlugin>> = {
32
+ name: utils.Default<B['name'], BasePlugin['name']>;
33
+ version: utils.Default<B['version'], BasePlugin['version']>;
127
34
  configuration: utils.Default<B['configuration'], BasePlugin['configuration']>;
128
35
  events: utils.Default<B['events'], BasePlugin['events']>;
129
36
  states: utils.Default<B['states'], BasePlugin['states']>;
130
37
  actions: utils.Default<B['actions'], BasePlugin['actions']>;
131
38
  tables: utils.Default<B['tables'], BasePlugin['tables']>;
39
+ workflows: utils.Default<B['workflows'], BasePlugin['workflows']>;
132
40
  integrations: undefined extends B['integrations'] ? BasePlugin['integrations'] : {
133
41
  [K in keyof B['integrations']]: DefaultIntegration<utils.Cast<B['integrations'][K], InputBaseIntegration>>;
134
42
  };
@@ -1,7 +1,7 @@
1
- import { StateDefinition, RecurringEventDefinition, EventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition, TableDefinition } from '../bot/definition';
1
+ import { StateDefinition, RecurringEventDefinition, EventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition, TableDefinition, WorkflowDefinition } from '../bot/definition';
2
2
  import { IntegrationPackage, InterfacePackage } from '../package';
3
3
  import { ZuiObjectSchema } from '../zui';
4
- export { StateDefinition, RecurringEventDefinition, EventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition, TableDefinition, IntegrationConfigInstance, } from '../bot/definition';
4
+ export { StateDefinition, RecurringEventDefinition, EventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition, TableDefinition, IntegrationConfigInstance, WorkflowDefinition, } from '../bot/definition';
5
5
  type BaseConfig = ZuiObjectSchema;
6
6
  type BaseStates = Record<string, ZuiObjectSchema>;
7
7
  type BaseEvents = Record<string, ZuiObjectSchema>;
@@ -9,7 +9,8 @@ type BaseActions = Record<string, ZuiObjectSchema>;
9
9
  type BaseInterfaces = Record<string, any>;
10
10
  type BaseIntegrations = Record<string, any>;
11
11
  type BaseTables = Record<string, ZuiObjectSchema>;
12
- export type PluginDefinitionProps<TName extends string = string, TVersion extends string = string, TConfig extends BaseConfig = BaseConfig, TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TInterfaces extends BaseInterfaces = BaseInterfaces, TIntegrations extends BaseIntegrations = BaseIntegrations, TTables extends BaseTables = BaseTables> = {
12
+ type BaseWorkflows = Record<string, ZuiObjectSchema>;
13
+ export type PluginDefinitionProps<TName extends string = string, TVersion extends string = string, TConfig extends BaseConfig = BaseConfig, TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TInterfaces extends BaseInterfaces = BaseInterfaces, TIntegrations extends BaseIntegrations = BaseIntegrations, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> = {
13
14
  name: TName;
14
15
  version: TVersion;
15
16
  title?: string;
@@ -39,9 +40,16 @@ export type PluginDefinitionProps<TName extends string = string, TVersion extend
39
40
  tables?: {
40
41
  [K in keyof TTables]: TableDefinition<TTables[K]>;
41
42
  };
43
+ /**
44
+ * # EXPERIMENTAL
45
+ * This API is experimental and may change in the future.
46
+ */
47
+ workflows?: {
48
+ [K in keyof TWorkflows]: WorkflowDefinition<TWorkflows[K]>;
49
+ };
42
50
  };
43
- export declare class PluginDefinition<TName extends string = string, TVersion extends string = string, TConfig extends BaseConfig = BaseConfig, TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TInterfaces extends BaseInterfaces = BaseInterfaces, TIntegrations extends BaseIntegrations = BaseIntegrations, TTables extends BaseTables = BaseTables> {
44
- readonly props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations, TTables>;
51
+ export declare class PluginDefinition<TName extends string = string, TVersion extends string = string, TConfig extends BaseConfig = BaseConfig, TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TInterfaces extends BaseInterfaces = BaseInterfaces, TIntegrations extends BaseIntegrations = BaseIntegrations, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> {
52
+ readonly props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations, TTables, TWorkflows>;
45
53
  readonly name: this['props']['name'];
46
54
  readonly version: this['props']['version'];
47
55
  readonly title: this['props']['title'];
@@ -59,5 +67,6 @@ export declare class PluginDefinition<TName extends string = string, TVersion ex
59
67
  readonly recurringEvents: this['props']['recurringEvents'];
60
68
  readonly actions: this['props']['actions'];
61
69
  readonly tables: this['props']['tables'];
62
- constructor(props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations, TTables>);
70
+ readonly workflows: this['props']['workflows'];
71
+ constructor(props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations, TTables, TWorkflows>);
63
72
  }
@@ -1,10 +1,12 @@
1
- import { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, ActionHandlers as BotActionHandlers, BotHandlers } from '../bot';
1
+ import type { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, WorkflowHandlersMap as BotWorkflowHandlersMap, ActionHandlers as BotActionHandlers, BotHandlers } from '../bot';
2
+ import * as utils from '../utils';
2
3
  import { BasePlugin, PluginInterfaceExtensions } from './common';
3
- import { MessageHandlersMap, MessageHandlers, EventHandlersMap, EventHandlers, StateExpiredHandlersMap, StateExpiredHandlers, HookData, HookHandlers, ActionHandlers, PluginConfiguration } from './server/types';
4
+ import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap, PluginConfiguration } from './server/types';
4
5
  export type PluginImplementationProps<TPlugin extends BasePlugin = BasePlugin> = {
5
6
  actions: ActionHandlers<TPlugin>;
6
7
  };
7
8
  export type PluginRuntimeProps<TPlugin extends BasePlugin = BasePlugin> = {
9
+ alias?: string;
8
10
  configuration: PluginConfiguration<TPlugin>;
9
11
  interfaces: PluginInterfaceExtensions<TPlugin>;
10
12
  };
@@ -16,8 +18,10 @@ export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugi
16
18
  private _eventHandlers;
17
19
  private _stateExpiredHandlers;
18
20
  private _hookHandlers;
21
+ private _workflowHandlers;
22
+ private _registerOrder;
19
23
  constructor(props: PluginImplementationProps<TPlugin>);
20
- initialize(config: PluginRuntimeProps<TPlugin>): this;
24
+ initialize(props: PluginRuntimeProps<TPlugin>): this;
21
25
  private get _runtime();
22
26
  private _getTools;
23
27
  get actionHandlers(): BotActionHandlers<TPlugin>;
@@ -25,21 +29,38 @@ export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugi
25
29
  get eventHandlers(): BotEventHandlersMap<TPlugin>;
26
30
  get stateExpiredHandlers(): BotStateExpiredHandlersMap<TPlugin>;
27
31
  get hookHandlers(): BotHookHandlersMap<TPlugin>;
32
+ get workflowHandlers(): BotWorkflowHandlersMap<TPlugin>;
28
33
  readonly on: {
29
- message: <T extends keyof MessageHandlersMap<TPlugin>>(type: T, handler: MessageHandlers<TPlugin>[T]) => void;
30
- event: <T extends keyof EventHandlersMap<TPlugin>>(type: T, handler: EventHandlers<TPlugin>[T]) => void;
31
- stateExpired: <T extends keyof StateExpiredHandlersMap<TPlugin>>(type: T, handler: StateExpiredHandlers<TPlugin>[T]) => void;
32
- beforeIncomingEvent: <T extends keyof HookData<TPlugin>["before_incoming_event"]>(type: T, handler: HookHandlers<TPlugin>["before_incoming_event"][T]) => void;
33
- beforeIncomingMessage: <T extends keyof HookData<TPlugin>["before_incoming_message"]>(type: T, handler: HookHandlers<TPlugin>["before_incoming_message"][T]) => void;
34
- beforeOutgoingMessage: <T extends keyof HookData<TPlugin>["before_outgoing_message"]>(type: T, handler: HookHandlers<TPlugin>["before_outgoing_message"][T]) => void;
35
- beforeOutgoingCallAction: <T extends keyof HookData<TPlugin>["before_outgoing_call_action"]>(type: T, handler: HookHandlers<TPlugin>["before_outgoing_call_action"][T]) => void;
36
- afterIncomingEvent: <T extends keyof HookData<TPlugin>["after_incoming_event"]>(type: T, handler: HookHandlers<TPlugin>["after_incoming_event"][T]) => void;
37
- afterIncomingMessage: <T extends keyof HookData<TPlugin>["after_incoming_message"]>(type: T, handler: HookHandlers<TPlugin>["after_incoming_message"][T]) => void;
38
- afterOutgoingMessage: <T extends keyof HookData<TPlugin>["after_outgoing_message"]>(type: T, handler: HookHandlers<TPlugin>["after_outgoing_message"][T]) => void;
39
- afterOutgoingCallAction: <T extends keyof HookData<TPlugin>["after_outgoing_call_action"]>(type: T, handler: HookHandlers<TPlugin>["after_outgoing_call_action"][T]) => void;
34
+ message: <T extends utils.types.StringKeys<MessageHandlersMap<TPlugin>>>(type: T, handler: MessageHandlers<TPlugin>[T]) => void;
35
+ event: <T extends utils.types.StringKeys<EventHandlersMap<TPlugin>>>(type: T, handler: EventHandlers<TPlugin>[T]) => void;
36
+ stateExpired: <T extends utils.types.StringKeys<StateExpiredHandlersMap<TPlugin>>>(type: T, handler: StateExpiredHandlers<TPlugin>[T]) => void;
37
+ beforeIncomingEvent: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["before_incoming_event"]>>(type: T, handler: HookHandlers<TPlugin>["before_incoming_event"][T]) => void;
38
+ beforeIncomingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["before_incoming_message"]>>(type: T, handler: HookHandlers<TPlugin>["before_incoming_message"][T]) => void;
39
+ beforeOutgoingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["before_outgoing_message"]>>(type: T, handler: HookHandlers<TPlugin>["before_outgoing_message"][T]) => void;
40
+ beforeOutgoingCallAction: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["before_outgoing_call_action"]>>(type: T, handler: HookHandlers<TPlugin>["before_outgoing_call_action"][T]) => void;
41
+ afterIncomingEvent: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["after_incoming_event"]>>(type: T, handler: HookHandlers<TPlugin>["after_incoming_event"][T]) => void;
42
+ afterIncomingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["after_incoming_message"]>>(type: T, handler: HookHandlers<TPlugin>["after_incoming_message"][T]) => void;
43
+ afterOutgoingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["after_outgoing_message"]>>(type: T, handler: HookHandlers<TPlugin>["after_outgoing_message"][T]) => void;
44
+ afterOutgoingCallAction: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["after_outgoing_call_action"]>>(type: T, handler: HookHandlers<TPlugin>["after_outgoing_call_action"][T]) => void;
45
+ /**
46
+ * # EXPERIMENTAL
47
+ * This API is experimental and may change in the future.
48
+ */
49
+ workflowStart: <T extends utils.types.StringKeys<WorkflowHandlersMap<TPlugin>["started"]>>(type: T, handler: WorkflowHandlers<TPlugin>[T]) => void;
50
+ /**
51
+ * # EXPERIMENTAL
52
+ * This API is experimental and may change in the future.
53
+ */
54
+ workflowContinue: <T extends utils.types.StringKeys<WorkflowHandlersMap<TPlugin>["continued"]>>(type: T, handler: WorkflowHandlers<TPlugin>[T]) => void;
55
+ /**
56
+ * # EXPERIMENTAL
57
+ * This API is experimental and may change in the future.
58
+ */
59
+ workflowTimeout: <T extends utils.types.StringKeys<WorkflowHandlersMap<TPlugin>["timed_out"]>>(type: T, handler: WorkflowHandlers<TPlugin>[T]) => void;
40
60
  };
41
61
  /**
42
62
  * checks if the actual event resolves to the target event
43
63
  */
44
64
  private _eventResolvesTo;
65
+ private _stripAliasPrefix;
45
66
  }
@@ -1,35 +1,36 @@
1
1
  import * as client from '@botpress/client';
2
2
  import * as bot from '../../bot';
3
+ import * as workflowProxy from '../../bot/workflow-proxy';
3
4
  import * as utils from '../../utils/type-utils';
4
- import * as proxy from '../action-proxy';
5
+ import * as actionProxy from '../action-proxy';
5
6
  import * as common from '../common';
6
7
  type EnumeratePluginEvents<TPlugin extends common.BasePlugin> = bot.EnumerateEvents<TPlugin> & common.EnumerateInterfaceEvents<TPlugin>;
7
8
  type _IncomingEvents<TPlugin extends common.BasePlugin> = {
8
- [K in keyof EnumeratePluginEvents<TPlugin>]: utils.Merge<client.Event, {
9
+ [K in utils.StringKeys<EnumeratePluginEvents<TPlugin>>]: utils.Merge<client.Event, {
9
10
  type: K;
10
11
  payload: EnumeratePluginEvents<TPlugin>[K];
11
12
  }>;
12
13
  };
13
14
  type _IncomingMessages<TPlugin extends common.BasePlugin> = {
14
- [K in keyof bot.GetMessages<TPlugin>]: utils.Merge<client.Message, {
15
+ [K in utils.StringKeys<bot.GetMessages<TPlugin>>]: utils.Merge<client.Message, {
15
16
  type: K;
16
17
  payload: bot.GetMessages<TPlugin>[K];
17
18
  }>;
18
19
  };
19
20
  type _IncomingStates<TPlugin extends common.BasePlugin> = {
20
- [K in keyof bot.EnumerateStates<TPlugin>]: utils.Merge<client.State, {
21
+ [K in utils.StringKeys<bot.EnumerateStates<TPlugin>>]: utils.Merge<client.State, {
21
22
  name: K;
22
23
  payload: bot.EnumerateStates<TPlugin>[K];
23
24
  }>;
24
25
  };
25
26
  type _OutgoingMessageRequests<TPlugin extends common.BasePlugin> = {
26
- [K in keyof bot.GetMessages<TPlugin>]: utils.Merge<client.ClientInputs['createMessage'], {
27
+ [K in utils.StringKeys<bot.GetMessages<TPlugin>>]: utils.Merge<client.ClientInputs['createMessage'], {
27
28
  type: K;
28
29
  payload: bot.GetMessages<TPlugin>[K];
29
30
  }>;
30
31
  };
31
32
  type _OutgoingMessageResponses<TPlugin extends common.BasePlugin> = {
32
- [K in keyof bot.GetMessages<TPlugin>]: utils.Merge<client.ClientOutputs['createMessage'], {
33
+ [K in utils.StringKeys<bot.GetMessages<TPlugin>>]: utils.Merge<client.ClientOutputs['createMessage'], {
33
34
  message: utils.Merge<client.Message, {
34
35
  type: K;
35
36
  payload: bot.GetMessages<TPlugin>[K];
@@ -37,13 +38,13 @@ type _OutgoingMessageResponses<TPlugin extends common.BasePlugin> = {
37
38
  }>;
38
39
  };
39
40
  type _OutgoingCallActionRequests<TPlugin extends common.BasePlugin> = {
40
- [K in keyof bot.EnumerateActionInputs<TPlugin>]: utils.Merge<client.ClientInputs['callAction'], {
41
+ [K in utils.StringKeys<bot.EnumerateActionInputs<TPlugin>>]: utils.Merge<client.ClientInputs['callAction'], {
41
42
  type: K;
42
43
  input: bot.EnumerateActionInputs<TPlugin>[K];
43
44
  }>;
44
45
  };
45
46
  type _OutgoingCallActionResponses<TPlugin extends common.BasePlugin> = {
46
- [K in keyof bot.EnumerateActionOutputs<TPlugin>]: utils.Merge<client.ClientOutputs['callAction'], {
47
+ [K in utils.StringKeys<bot.EnumerateActionOutputs<TPlugin>>]: utils.Merge<client.ClientOutputs['callAction'], {
47
48
  output: bot.EnumerateActionOutputs<TPlugin>[K];
48
49
  }>;
49
50
  };
@@ -82,16 +83,21 @@ export type CommonHandlerProps<TPlugin extends common.BasePlugin> = {
82
83
  client: PluginClient<TPlugin>;
83
84
  configuration: PluginConfiguration<TPlugin>;
84
85
  interfaces: common.PluginInterfaceExtensions<TPlugin>;
85
- actions: proxy.ActionProxy<TPlugin>;
86
+ actions: actionProxy.ActionProxy<TPlugin>;
87
+ /**
88
+ * # EXPERIMENTAL
89
+ * This API is experimental and may change in the future.
90
+ */
91
+ workflows: workflowProxy.WorkflowProxy<TPlugin>;
86
92
  };
87
93
  export type MessagePayloads<TPlugin extends common.BasePlugin> = {
88
- [K in keyof IncomingMessages<TPlugin>]: CommonHandlerProps<TPlugin> & {
89
- message: IncomingMessages<TPlugin>[K];
94
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: CommonHandlerProps<TPlugin> & {
95
+ message: IncomingMessages<TPlugin>[TMessageName];
90
96
  user: client.User;
91
97
  conversation: client.Conversation;
92
98
  event: client.Event;
93
99
  states: {
94
- [TState in keyof TPlugin['states']]: {
100
+ [TState in utils.StringKeys<TPlugin['states']>]: {
95
101
  type: 'user' | 'conversation' | 'bot';
96
102
  payload: TPlugin['states'][TState];
97
103
  };
@@ -99,32 +105,46 @@ export type MessagePayloads<TPlugin extends common.BasePlugin> = {
99
105
  };
100
106
  };
101
107
  export type MessageHandlers<TPlugin extends common.BasePlugin> = {
102
- [K in keyof IncomingMessages<TPlugin>]: (args: MessagePayloads<TPlugin>[K]) => Promise<void>;
108
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: (args: MessagePayloads<TPlugin>[TMessageName]) => Promise<void>;
103
109
  };
104
110
  export type EventPayloads<TPlugin extends common.BasePlugin> = {
105
- [K in keyof IncomingEvents<TPlugin>]: CommonHandlerProps<TPlugin> & {
106
- event: IncomingEvents<TPlugin>[K];
111
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: CommonHandlerProps<TPlugin> & {
112
+ event: IncomingEvents<TPlugin>[TEventName];
107
113
  };
108
114
  };
109
115
  export type EventHandlers<TPlugin extends common.BasePlugin> = {
110
- [K in keyof IncomingEvents<TPlugin>]: (args: EventPayloads<TPlugin>[K]) => Promise<void>;
116
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: (args: EventPayloads<TPlugin>[TEventName]) => Promise<void>;
111
117
  };
112
118
  export type StateExpiredPayloads<TPlugin extends common.BasePlugin> = {
113
- [K in keyof IncomingStates<TPlugin>]: CommonHandlerProps<TPlugin> & {
114
- state: IncomingStates<TPlugin>[K];
119
+ [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: CommonHandlerProps<TPlugin> & {
120
+ state: IncomingStates<TPlugin>[TSateName];
115
121
  };
116
122
  };
117
123
  export type StateExpiredHandlers<TPlugin extends common.BasePlugin> = {
118
- [K in keyof IncomingStates<TPlugin>]: (args: StateExpiredPayloads<TPlugin>[K]) => Promise<void>;
124
+ [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: (args: StateExpiredPayloads<TPlugin>[TSateName]) => Promise<void>;
119
125
  };
120
126
  export type ActionHandlerPayloads<TPlugin extends common.BasePlugin> = {
121
- [K in keyof TPlugin['actions']]: CommonHandlerProps<TPlugin> & {
122
- type?: K;
123
- input: TPlugin['actions'][K]['input'];
127
+ [TActionName in utils.StringKeys<TPlugin['actions']>]: CommonHandlerProps<TPlugin> & {
128
+ type?: TActionName;
129
+ input: TPlugin['actions'][TActionName]['input'];
124
130
  };
125
131
  };
126
132
  export type ActionHandlers<TPlugin extends common.BasePlugin> = {
127
- [K in keyof TPlugin['actions']]: (props: ActionHandlerPayloads<TPlugin>[K]) => Promise<TPlugin['actions'][K]['output']>;
133
+ [TActionName in utils.StringKeys<TPlugin['actions']>]: (props: ActionHandlerPayloads<TPlugin>[TActionName]) => Promise<TPlugin['actions'][TActionName]['output']>;
134
+ };
135
+ export type WorkflowPayloads<TPlugin extends common.BasePlugin> = {
136
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: CommonHandlerProps<TPlugin> & {
137
+ conversation?: client.Conversation;
138
+ user?: client.User;
139
+ /**
140
+ * # EXPERIMENTAL
141
+ * This API is experimental and may change in the future.
142
+ */
143
+ workflow: workflowProxy.WorkflowWithUtilities<TPlugin, TWorkflowName>;
144
+ };
145
+ };
146
+ export type WorkflowHandlers<TPlugin extends common.BasePlugin> = {
147
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: (props: WorkflowPayloads<TPlugin>[TWorkflowName]) => Promise<void>;
128
148
  };
129
149
  type BaseHookDefinition = {
130
150
  stoppable?: boolean;
@@ -192,43 +212,85 @@ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
192
212
  }>;
193
213
  };
194
214
  export type HookData<TPlugin extends common.BasePlugin> = {
195
- [H in keyof HookDefinitions<TPlugin>]: {
196
- [T in keyof HookDefinitions<TPlugin>[H]['data']]: HookDefinitions<TPlugin>[H]['data'][T];
215
+ [THookType in utils.StringKeys<HookDefinitions<TPlugin>>]: {
216
+ [THookDataName in utils.StringKeys<HookDefinitions<TPlugin>[THookType]['data']>]: HookDefinitions<TPlugin>[THookType]['data'][THookDataName];
197
217
  };
198
218
  };
199
219
  export type HookInputs<TPlugin extends common.BasePlugin> = {
200
- [H in keyof HookData<TPlugin>]: {
201
- [T in keyof HookData<TPlugin>[H]]: CommonHandlerProps<TPlugin> & {
202
- data: HookData<TPlugin>[H][T];
220
+ [THookType in utils.StringKeys<HookData<TPlugin>>]: {
221
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & {
222
+ data: HookData<TPlugin>[THookType][THookDataName];
203
223
  };
204
224
  };
205
225
  };
206
226
  export type HookOutputs<TPlugin extends common.BasePlugin> = {
207
- [H in keyof HookData<TPlugin>]: {
208
- [T in keyof HookData<TPlugin>[H]]: {
209
- data?: HookData<TPlugin>[H][T];
210
- } & (HookDefinitions<TPlugin>[H]['stoppable'] extends true ? {
227
+ [THookType in utils.StringKeys<HookData<TPlugin>>]: {
228
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: {
229
+ data?: HookData<TPlugin>[THookType][THookDataName];
230
+ } & (HookDefinitions<TPlugin>[THookType]['stoppable'] extends true ? {
211
231
  stop?: boolean;
212
232
  } : {});
213
233
  };
214
234
  };
215
235
  export type HookHandlers<TPlugin extends common.BasePlugin> = {
216
- [H in keyof HookData<TPlugin>]: {
217
- [T in keyof HookData<TPlugin>[H]]: (input: HookInputs<TPlugin>[H][T]) => Promise<HookOutputs<TPlugin>[H][T] | undefined>;
236
+ [THookType in utils.StringKeys<HookData<TPlugin>>]: {
237
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: (input: HookInputs<TPlugin>[THookType][THookDataName]) => Promise<HookOutputs<TPlugin>[THookType][THookDataName] | undefined>;
218
238
  };
219
239
  };
220
240
  export type MessageHandlersMap<TPlugin extends common.BasePlugin> = {
221
- [T in keyof IncomingMessages<TPlugin>]?: MessageHandlers<TPlugin>[T][];
241
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: MessageHandlers<TPlugin>[TMessageName][];
222
242
  };
223
243
  export type EventHandlersMap<TPlugin extends common.BasePlugin> = {
224
- [T in keyof IncomingEvents<TPlugin>]?: EventHandlers<TPlugin>[T][];
244
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: EventHandlers<TPlugin>[TEventName][];
225
245
  };
226
246
  export type StateExpiredHandlersMap<TPlugin extends common.BasePlugin> = {
227
- [T in keyof IncomingStates<TPlugin>]?: StateExpiredHandlers<TPlugin>[T][];
247
+ [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlers<TPlugin>[TStateName][];
228
248
  };
229
249
  export type HookHandlersMap<TPlugin extends common.BasePlugin> = {
230
- [H in keyof HookData<TPlugin>]: {
231
- [T in keyof HookData<TPlugin>[H]]?: HookHandlers<TPlugin>[H][T][];
250
+ [THookType in utils.StringKeys<HookData<TPlugin>>]: {
251
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlers<TPlugin>[THookType][THookDataName][];
252
+ };
253
+ };
254
+ export type WorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
255
+ [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
256
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: {
257
+ handler: WorkflowHandlers<TPlugin>[TWorkflowName];
258
+ order: number;
259
+ }[];
260
+ };
261
+ };
262
+ export type OrderedMessageHandlersMap<TPlugin extends common.BasePlugin> = {
263
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: {
264
+ handler: MessageHandlers<TPlugin>[TMessageName];
265
+ order: number;
266
+ }[];
267
+ };
268
+ export type OrderedEventHandlersMap<TPlugin extends common.BasePlugin> = {
269
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: {
270
+ handler: EventHandlers<TPlugin>[TEventName];
271
+ order: number;
272
+ }[];
273
+ };
274
+ export type OrderedStateExpiredHandlersMap<TPlugin extends common.BasePlugin> = {
275
+ [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: {
276
+ handler: StateExpiredHandlers<TPlugin>[TStateName];
277
+ order: number;
278
+ }[];
279
+ };
280
+ export type OrderedHookHandlersMap<TPlugin extends common.BasePlugin> = {
281
+ [THookType in utils.StringKeys<HookData<TPlugin>>]: {
282
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: {
283
+ handler: HookHandlers<TPlugin>[THookType][THookDataName];
284
+ order: number;
285
+ }[];
286
+ };
287
+ };
288
+ export type OrderedWorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
289
+ [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
290
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: {
291
+ handler: WorkflowHandlers<TPlugin>[TWorkflowName];
292
+ order: number;
293
+ }[];
232
294
  };
233
295
  };
234
296
  export type PluginHandlers<TPlugin extends common.BasePlugin> = {
@@ -237,5 +299,6 @@ export type PluginHandlers<TPlugin extends common.BasePlugin> = {
237
299
  eventHandlers: EventHandlersMap<TPlugin>;
238
300
  stateExpiredHandlers: StateExpiredHandlersMap<TPlugin>;
239
301
  hookHandlers: HookHandlersMap<TPlugin>;
302
+ workflowHandlers: WorkflowHandlersMap<TPlugin>;
240
303
  };
241
304
  export {};
@@ -1,5 +1,6 @@
1
1
  export declare const pairs: <K extends string, V>(obj: Record<K, V>) => [K, V][];
2
2
  export declare const values: <K extends string, V>(obj: Record<K, V>) => V[];
3
3
  export declare const mapValues: <K extends string, V, R>(obj: Record<K, V>, fn: (value: V, key: K) => R) => Record<K, R>;
4
+ export declare const mapKeys: <K1 extends string, K2 extends string, V>(obj: Record<K1, V>, fn: (key: K1) => K2) => Record<K2, V>;
4
5
  export declare const stripUndefinedProps: <K extends string, V>(obj: Record<K, V | undefined>) => Record<K, V>;
5
6
  export declare const mergeRecords: <K extends string, V>(a: Record<K, V>, b: Record<K, V>, merge: (v1: V, v2: V) => V) => Record<K, V>;
@@ -7,12 +7,12 @@ export type Writable<T> = {
7
7
  };
8
8
  export type Default<T, U> = undefined extends T ? U : T;
9
9
  export type AtLeastOne<T> = [T, ...T[]];
10
- export type AtLeastOneProperty<T> = {
10
+ export type AtLeastOneProperty<T> = T extends undefined ? {} : {
11
11
  [K in keyof T]?: T[K];
12
12
  } & {
13
13
  [K in keyof T]: Pick<T, K>;
14
14
  }[keyof T];
15
- export type ExactlyOneProperty<T> = {
15
+ export type ExactlyOneProperty<T> = T extends undefined ? {} : {
16
16
  [K in keyof T]: {
17
17
  [P in K]: T[P];
18
18
  } & {
@@ -45,4 +45,5 @@ type DeepPartialObject<T extends object> = T extends infer O ? {
45
45
  } : never;
46
46
  export type DeepPartial<T> = T extends (...args: infer A) => infer R ? (...args: DeepPartial<A>) => DeepPartial<R> : T extends Array<infer E> ? Array<DeepPartial<E>> : T extends ReadonlyArray<infer E> ? ReadonlyArray<DeepPartial<E>> : T extends Promise<infer R> ? Promise<DeepPartial<R>> : T extends Buffer ? Buffer : T extends object ? DeepPartialObject<T> : T;
47
47
  export type SafeOmit<T, K extends keyof T> = Omit<T, K>;
48
+ export type StringKeys<T> = Extract<keyof T, string>;
48
49
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/sdk",
3
- "version": "3.4.0",
3
+ "version": "3.5.1",
4
4
  "description": "Botpress SDK",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -16,7 +16,7 @@
16
16
  "author": "",
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@botpress/client": "0.47.0",
19
+ "@botpress/client": "0.48.0",
20
20
  "browser-or-node": "^2.1.1"
21
21
  },
22
22
  "devDependencies": {