@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.
@@ -1,18 +1,18 @@
1
1
 
2
- > @botpress/sdk@3.4.0 build /home/runner/work/botpress/botpress/packages/sdk
2
+ > @botpress/sdk@3.5.1 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@3.4.0 build:type /home/runner/work/botpress/botpress/packages/sdk
6
+ > @botpress/sdk@3.5.1 build:type /home/runner/work/botpress/botpress/packages/sdk
7
7
  > tsc --emitDeclarationOnly --declaration
8
8
 
9
9
 
10
- > @botpress/sdk@3.4.0 build:node /home/runner/work/botpress/botpress/packages/sdk
10
+ > @botpress/sdk@3.5.1 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@3.4.0 build:browser /home/runner/work/botpress/botpress/packages/sdk
15
+ > @botpress/sdk@3.5.1 build:browser /home/runner/work/botpress/botpress/packages/sdk
16
16
  > ts-node -T ./build.ts --browser
17
17
 
18
18
  Done
@@ -49,6 +49,11 @@ export declare class BotSpecificClient<TBot extends common.BaseBot> implements t
49
49
  deleteTableRows: types.DeleteTableRows<TBot>;
50
50
  updateTableRows: types.UpdateTableRows<TBot>;
51
51
  upsertTableRows: types.UpsertTableRows<TBot>;
52
+ createWorkflow: types.CreateWorkflow<TBot>;
53
+ getWorkflow: types.GetWorkflow<TBot>;
54
+ updateWorkflow: types.UpdateWorkflow<TBot>;
55
+ deleteWorkflow: types.DeleteWorkflow<TBot>;
56
+ listWorkflows: types.ListWorkflows<TBot>;
52
57
  /**
53
58
  * @deprecated Use `callAction` to delegate the conversation creation to an integration.
54
59
  */
@@ -90,6 +90,22 @@ export type ListFiles<_TBot extends common.BaseBot> = client.Client['listFiles']
90
90
  export type GetFile<_TBot extends common.BaseBot> = client.Client['getFile'];
91
91
  export type UpdateFileMetadata<_TBot extends common.BaseBot> = client.Client['updateFileMetadata'];
92
92
  export type SearchFiles<_TBot extends common.BaseBot> = client.Client['searchFiles'];
93
+ export type CreateWorkflow<TBot extends common.BaseBot> = <TWorkflowName extends utils.StringKeys<TBot['workflows']>>(x: utils.Merge<Arg<client.Client['createWorkflow']>, {
94
+ name: utils.Cast<TWorkflowName, string>;
95
+ input: utils.Cast<TBot['workflows'][TWorkflowName], common.IntegrationInstanceActionDefinition>['input'];
96
+ tags?: utils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
97
+ }>) => Promise<Readonly<{
98
+ workflow: utils.Merge<Awaited<Res<client.Client['createWorkflow']>>['workflow'], {
99
+ name: NoInfer<TWorkflowName>;
100
+ }>;
101
+ }>>;
102
+ export type GetWorkflow<_TBot extends common.BaseBot> = client.Client['getWorkflow'];
103
+ export type UpdateWorkflow<_TBot extends common.BaseBot> = client.Client['updateWorkflow'];
104
+ export type DeleteWorkflow<_TBot extends common.BaseBot> = client.Client['deleteWorkflow'];
105
+ export type ListWorkflows<TBot extends common.BaseBot> = <TWorkflowName extends utils.StringKeys<TBot['workflows']>>(x: utils.Merge<Arg<client.Client['listWorkflows']>, {
106
+ name?: utils.Cast<TWorkflowName, string>;
107
+ tags?: utils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
108
+ }>) => Promise<Readonly<Awaited<Res<client.Client['listWorkflows']>>>>;
93
109
  export type GetTableRow<TBot extends common.BaseBot> = <TableName extends keyof common.EnumerateTables<TBot>, Columns = utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>>>(x: utils.Merge<Arg<client.Client['getTableRow']>, {
94
110
  table: utils.Cast<TableName, string>;
95
111
  id: client.Row['id'];
@@ -8,12 +8,20 @@ export type BaseAction = {
8
8
  export type BaseTable = {
9
9
  [k: string]: any;
10
10
  };
11
+ export type BaseWorkflow = {
12
+ input: any;
13
+ output: any;
14
+ tags?: {
15
+ [k: string]: string;
16
+ };
17
+ };
11
18
  export type BaseBot = {
12
19
  integrations: Record<string, BaseIntegration>;
13
20
  events: Record<string, any>;
14
21
  states: Record<string, any>;
15
22
  actions: Record<string, BaseAction>;
16
23
  tables: Record<string, BaseTable>;
24
+ workflows: Record<string, BaseWorkflow>;
17
25
  };
18
26
  export type InputBaseBot = utils.DeepPartial<BaseBot>;
19
27
  export type DefaultBot<B extends InputBaseBot> = {
@@ -24,4 +32,5 @@ export type DefaultBot<B extends InputBaseBot> = {
24
32
  [K in keyof B['integrations']]: DefaultIntegration<utils.Cast<B['integrations'][K], InputBaseIntegration>>;
25
33
  };
26
34
  tables: utils.Default<B['tables'], BaseBot['tables']>;
35
+ workflows: utils.Default<B['workflows'], BaseBot['workflows']>;
27
36
  };
@@ -9,6 +9,7 @@ type BaseStates = Record<string, ZuiObjectSchema>;
9
9
  type BaseEvents = Record<string, ZuiObjectSchema>;
10
10
  type BaseActions = Record<string, ZuiObjectSchema>;
11
11
  type BaseTables = Record<string, ZuiObjectSchema>;
12
+ type BaseWorkflows = Record<string, ZuiObjectSchema>;
12
13
  export type TagDefinition = {
13
14
  title?: string;
14
15
  description?: string;
@@ -44,6 +45,13 @@ export type ActionDefinition<TAction extends BaseActions[string] = BaseActions[s
44
45
  input: SchemaDefinition<TAction>;
45
46
  output: SchemaDefinition<ZuiObjectSchema>;
46
47
  };
48
+ export type WorkflowDefinition<TWorkflow extends BaseWorkflows[string] = BaseWorkflows[string]> = {
49
+ title?: string;
50
+ description?: string;
51
+ input: SchemaDefinition<TWorkflow>;
52
+ output: SchemaDefinition<ZuiObjectSchema>;
53
+ tags?: Record<string, TagDefinition>;
54
+ };
47
55
  export type TableDefinition<TTable extends BaseTables[string] = BaseTables[string]> = Merge<Omit<Table, 'id' | 'createdAt' | 'updatedAt' | 'name'>, {
48
56
  schema: TTable;
49
57
  }>;
@@ -59,6 +67,7 @@ export type IntegrationConfigInstance<I extends IntegrationPackage = Integration
59
67
  };
60
68
  }>);
61
69
  export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
70
+ alias?: string;
62
71
  configuration: z.infer<NonNullable<P['definition']['configuration']>['schema']>;
63
72
  interfaces: {
64
73
  [I in keyof NonNullable<P['definition']['interfaces']>]: PluginInterfaceExtension;
@@ -66,7 +75,7 @@ export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
66
75
  };
67
76
  export type IntegrationInstance = IntegrationPackage & IntegrationConfigInstance;
68
77
  export type PluginInstance = PluginPackage & PluginConfigInstance;
69
- export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables> = {
78
+ export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> = {
70
79
  integrations?: {
71
80
  [K: string]: IntegrationInstance;
72
81
  };
@@ -90,9 +99,16 @@ export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents
90
99
  tables?: {
91
100
  [K in keyof TTables]: TableDefinition<TTables[K]>;
92
101
  };
102
+ /**
103
+ * # EXPERIMENTAL
104
+ * This API is experimental and may change in the future.
105
+ */
106
+ workflows?: {
107
+ [K in keyof TWorkflows]: WorkflowDefinition<TWorkflows[K]>;
108
+ };
93
109
  };
94
- export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables> {
95
- readonly props: BotDefinitionProps<TStates, TEvents, TActions, TTables>;
110
+ export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> {
111
+ readonly props: BotDefinitionProps<TStates, TEvents, TActions, TTables, TWorkflows>;
96
112
  readonly integrations: this['props']['integrations'];
97
113
  readonly plugins: this['props']['plugins'];
98
114
  readonly user: this['props']['user'];
@@ -104,7 +120,8 @@ export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEve
104
120
  readonly recurringEvents: this['props']['recurringEvents'];
105
121
  readonly actions: this['props']['actions'];
106
122
  readonly tables: this['props']['tables'];
107
- constructor(props: BotDefinitionProps<TStates, TEvents, TActions, TTables>);
123
+ readonly workflows: this['props']['workflows'];
124
+ constructor(props: BotDefinitionProps<TStates, TEvents, TActions, TTables, TWorkflows>);
108
125
  addIntegration<I extends IntegrationPackage>(integrationPkg: I, config: IntegrationConfigInstance<I>): this;
109
126
  addPlugin<P extends PluginPackage>(pluginPkg: P, config: PluginConfigInstance<P>): this;
110
127
  private _mergeUser;
@@ -115,5 +132,7 @@ export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEve
115
132
  private _mergeRecurringEvents;
116
133
  private _mergeActions;
117
134
  private _mergeTables;
135
+ private _mergeWorkflows;
136
+ private _prefixKeys;
118
137
  }
119
138
  export {};
@@ -1,11 +1,12 @@
1
1
  import type { Server } from 'node:http';
2
2
  import { BasePlugin, PluginImplementation } from '../plugin';
3
+ import * as utils from '../utils';
3
4
  import { BaseBot } from './common';
4
- import { MessageHandlersMap, MessageHandlers, EventHandlersMap, EventHandlers, StateExpiredHandlersMap, StateExpiredHandlers, HookHandlersMap, HookData, HookHandlers, ActionHandlers, BotHandlers, UnimplementedActionHandlers } from './server';
5
+ import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap, BotHandlers, UnimplementedActionHandlers } from './server';
5
6
  export type BotImplementationProps<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> = {
6
7
  actions: UnimplementedActionHandlers<TBot, TPlugins>;
7
8
  plugins: {
8
- [K in keyof TPlugins]: PluginImplementation<TPlugins[K]>;
9
+ [K in utils.types.StringKeys<TPlugins>]: PluginImplementation<TPlugins[K]>;
9
10
  };
10
11
  };
11
12
  export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> implements BotHandlers<TBot> {
@@ -15,25 +16,43 @@ export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins
15
16
  private _eventHandlers;
16
17
  private _stateExpiredHandlers;
17
18
  private _hookHandlers;
19
+ private _workflowHandlers;
18
20
  private _plugins;
21
+ private _registerOrder;
19
22
  constructor(props: BotImplementationProps<TBot, TPlugins>);
20
23
  get actionHandlers(): ActionHandlers<TBot>;
21
24
  get messageHandlers(): MessageHandlersMap<TBot>;
22
25
  get eventHandlers(): EventHandlersMap<TBot>;
23
26
  get stateExpiredHandlers(): StateExpiredHandlersMap<TBot>;
24
27
  get hookHandlers(): HookHandlersMap<TBot>;
28
+ get workflowHandlers(): WorkflowHandlersMap<TBot>;
25
29
  readonly on: {
26
- message: <T extends keyof MessageHandlersMap<TBot>>(type: T, handler: MessageHandlers<TBot>[T]) => void;
27
- event: <T extends keyof EventHandlersMap<TBot>>(type: T, handler: EventHandlers<TBot>[T]) => void;
28
- stateExpired: <T extends keyof StateExpiredHandlersMap<TBot>>(type: T, handler: StateExpiredHandlers<TBot>[T]) => void;
29
- beforeIncomingEvent: <T extends keyof HookData<TBot>["before_incoming_event"]>(type: T, handler: HookHandlers<TBot>["before_incoming_event"][T]) => void;
30
- beforeIncomingMessage: <T extends keyof HookData<TBot>["before_incoming_message"]>(type: T, handler: HookHandlers<TBot>["before_incoming_message"][T]) => void;
31
- beforeOutgoingMessage: <T extends keyof HookData<TBot>["before_outgoing_message"]>(type: T, handler: HookHandlers<TBot>["before_outgoing_message"][T]) => void;
32
- beforeOutgoingCallAction: <T extends keyof HookData<TBot>["before_outgoing_call_action"]>(type: T, handler: HookHandlers<TBot>["before_outgoing_call_action"][T]) => void;
33
- afterIncomingEvent: <T extends keyof HookData<TBot>["after_incoming_event"]>(type: T, handler: HookHandlers<TBot>["after_incoming_event"][T]) => void;
34
- afterIncomingMessage: <T extends keyof HookData<TBot>["after_incoming_message"]>(type: T, handler: HookHandlers<TBot>["after_incoming_message"][T]) => void;
35
- afterOutgoingMessage: <T extends keyof HookData<TBot>["after_outgoing_message"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_message"][T]) => void;
36
- afterOutgoingCallAction: <T extends keyof HookData<TBot>["after_outgoing_call_action"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_call_action"][T]) => void;
30
+ message: <T extends utils.types.StringKeys<MessageHandlersMap<TBot>>>(type: T, handler: MessageHandlers<TBot>[T]) => void;
31
+ event: <T extends utils.types.StringKeys<EventHandlersMap<TBot>>>(type: T, handler: EventHandlers<TBot>[T]) => void;
32
+ stateExpired: <T extends utils.types.StringKeys<StateExpiredHandlersMap<TBot>>>(type: T, handler: StateExpiredHandlers<TBot>[T]) => void;
33
+ beforeIncomingEvent: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["before_incoming_event"]>>(type: T, handler: HookHandlers<TBot>["before_incoming_event"][T]) => void;
34
+ beforeIncomingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["before_incoming_message"]>>(type: T, handler: HookHandlers<TBot>["before_incoming_message"][T]) => void;
35
+ beforeOutgoingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["before_outgoing_message"]>>(type: T, handler: HookHandlers<TBot>["before_outgoing_message"][T]) => void;
36
+ beforeOutgoingCallAction: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["before_outgoing_call_action"]>>(type: T, handler: HookHandlers<TBot>["before_outgoing_call_action"][T]) => void;
37
+ afterIncomingEvent: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["after_incoming_event"]>>(type: T, handler: HookHandlers<TBot>["after_incoming_event"][T]) => void;
38
+ afterIncomingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["after_incoming_message"]>>(type: T, handler: HookHandlers<TBot>["after_incoming_message"][T]) => void;
39
+ afterOutgoingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["after_outgoing_message"]>>(type: T, handler: HookHandlers<TBot>["after_outgoing_message"][T]) => void;
40
+ afterOutgoingCallAction: <T extends utils.types.StringKeys<HookHandlersMap<TBot>["after_outgoing_call_action"]>>(type: T, handler: HookHandlers<TBot>["after_outgoing_call_action"][T]) => void;
41
+ /**
42
+ * # EXPERIMENTAL
43
+ * This API is experimental and may change in the future.
44
+ */
45
+ workflowStart: <T extends utils.types.StringKeys<WorkflowHandlersMap<TBot>["started"]>>(type: T, handler: WorkflowHandlers<TBot>[T]) => void;
46
+ /**
47
+ * # EXPERIMENTAL
48
+ * This API is experimental and may change in the future.
49
+ */
50
+ workflowContinue: <T extends utils.types.StringKeys<WorkflowHandlersMap<TBot>["continued"]>>(type: T, handler: WorkflowHandlers<TBot>[T]) => void;
51
+ /**
52
+ * # EXPERIMENTAL
53
+ * This API is experimental and may change in the future.
54
+ */
55
+ workflowTimeout: <T extends utils.types.StringKeys<WorkflowHandlersMap<TBot>["timed_out"]>>(type: T, handler: WorkflowHandlers<TBot>[T]) => void;
37
56
  };
38
57
  readonly handler: (req: import("../serve").Request) => Promise<import("../serve").Response | void>;
39
58
  readonly start: (port?: number) => Promise<Server>;
@@ -0,0 +1,3 @@
1
+ export declare const SUCCESS_RESPONSE: {
2
+ readonly status: 200;
3
+ };
@@ -1,9 +1,11 @@
1
1
  import * as client from '@botpress/client';
2
2
  import * as plugin from '../../plugin';
3
+ import type { Request } from '../../serve';
3
4
  import * as utils from '../../utils/type-utils';
4
5
  import { type BotLogger } from '../bot-logger';
5
6
  import { BotSpecificClient } from '../client';
6
7
  import * as common from '../common';
8
+ import type * as workflowProxy from '../workflow-proxy/types';
7
9
  export type BotOperation = 'event_received' | 'register' | 'unregister' | 'ping' | 'action_triggered';
8
10
  export type BotContext = {
9
11
  botId: string;
@@ -14,31 +16,31 @@ export type BotContext = {
14
16
  };
15
17
  };
16
18
  type _IncomingEvents<TBot extends common.BaseBot> = {
17
- [K in keyof common.EnumerateEvents<TBot>]: utils.Merge<client.Event, {
19
+ [K in utils.StringKeys<common.EnumerateEvents<TBot>>]: utils.Merge<client.Event, {
18
20
  type: K;
19
21
  payload: common.EnumerateEvents<TBot>[K];
20
22
  }>;
21
23
  };
22
24
  type _IncomingMessages<TBot extends common.BaseBot> = {
23
- [K in keyof common.GetMessages<TBot>]: utils.Merge<client.Message, {
25
+ [K in utils.StringKeys<common.GetMessages<TBot>>]: utils.Merge<client.Message, {
24
26
  type: K;
25
27
  payload: common.GetMessages<TBot>[K];
26
28
  }>;
27
29
  };
28
30
  type _IncomingStates<TBot extends common.BaseBot> = {
29
- [K in keyof common.EnumerateStates<TBot>]: utils.Merge<client.State, {
31
+ [K in utils.StringKeys<common.EnumerateStates<TBot>>]: utils.Merge<client.State, {
30
32
  name: K;
31
33
  payload: common.EnumerateStates<TBot>[K];
32
34
  }>;
33
35
  };
34
36
  type _OutgoingMessageRequests<TBot extends common.BaseBot> = {
35
- [K in keyof common.GetMessages<TBot>]: utils.Merge<client.ClientInputs['createMessage'], {
37
+ [K in utils.StringKeys<common.GetMessages<TBot>>]: utils.Merge<client.ClientInputs['createMessage'], {
36
38
  type: K;
37
39
  payload: common.GetMessages<TBot>[K];
38
40
  }>;
39
41
  };
40
42
  type _OutgoingMessageResponses<TBot extends common.BaseBot> = {
41
- [K in keyof common.GetMessages<TBot>]: utils.Merge<client.ClientOutputs['createMessage'], {
43
+ [K in utils.StringKeys<common.GetMessages<TBot>>]: utils.Merge<client.ClientOutputs['createMessage'], {
42
44
  message: utils.Merge<client.Message, {
43
45
  type: K;
44
46
  payload: common.GetMessages<TBot>[K];
@@ -46,13 +48,13 @@ type _OutgoingMessageResponses<TBot extends common.BaseBot> = {
46
48
  }>;
47
49
  };
48
50
  type _OutgoingCallActionRequests<TBot extends common.BaseBot> = {
49
- [K in keyof common.EnumerateActionInputs<TBot>]: utils.Merge<client.ClientInputs['callAction'], {
51
+ [K in utils.StringKeys<common.EnumerateActionInputs<TBot>>]: utils.Merge<client.ClientInputs['callAction'], {
50
52
  type: K;
51
53
  input: common.EnumerateActionInputs<TBot>[K];
52
54
  }>;
53
55
  };
54
56
  type _OutgoingCallActionResponses<TBot extends common.BaseBot> = {
55
- [K in keyof common.EnumerateActionOutputs<TBot>]: utils.Merge<client.ClientOutputs['callAction'], {
57
+ [K in utils.StringKeys<common.EnumerateActionOutputs<TBot>>]: utils.Merge<client.ClientOutputs['callAction'], {
56
58
  output: common.EnumerateActionOutputs<TBot>[K];
57
59
  }>;
58
60
  };
@@ -88,15 +90,20 @@ export type CommonHandlerProps<TBot extends common.BaseBot> = {
88
90
  ctx: BotContext;
89
91
  logger: BotLogger;
90
92
  client: BotClient<TBot>;
93
+ /**
94
+ * # EXPERIMENTAL
95
+ * This API is experimental and may change in the future.
96
+ */
97
+ workflows: workflowProxy.WorkflowProxy<TBot>;
91
98
  };
92
99
  export type MessagePayloads<TBot extends common.BaseBot> = {
93
- [K in keyof IncomingMessages<TBot>]: CommonHandlerProps<TBot> & {
94
- message: IncomingMessages<TBot>[K];
100
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]: CommonHandlerProps<TBot> & {
101
+ message: IncomingMessages<TBot>[TMessageName];
95
102
  user: client.User;
96
103
  conversation: client.Conversation;
97
104
  event: client.Event;
98
105
  states: {
99
- [TState in keyof TBot['states']]: {
106
+ [TState in utils.StringKeys<TBot['states']>]: {
100
107
  type: 'user' | 'conversation' | 'bot';
101
108
  payload: TBot['states'][TState];
102
109
  };
@@ -104,32 +111,58 @@ export type MessagePayloads<TBot extends common.BaseBot> = {
104
111
  };
105
112
  };
106
113
  export type MessageHandlers<TBot extends common.BaseBot> = {
107
- [K in keyof IncomingMessages<TBot>]: (args: MessagePayloads<TBot>[K]) => Promise<void>;
114
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]: (args: MessagePayloads<TBot>[TMessageName]) => Promise<void>;
108
115
  };
109
116
  export type EventPayloads<TBot extends common.BaseBot> = {
110
- [K in keyof IncomingEvents<TBot>]: CommonHandlerProps<TBot> & {
111
- event: IncomingEvents<TBot>[K];
117
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]: CommonHandlerProps<TBot> & {
118
+ event: IncomingEvents<TBot>[TEventName];
112
119
  };
113
120
  };
114
121
  export type EventHandlers<TBot extends common.BaseBot> = {
115
- [K in keyof IncomingEvents<TBot>]: (args: EventPayloads<TBot>[K]) => Promise<void>;
122
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]: (args: EventPayloads<TBot>[TEventName]) => Promise<void>;
116
123
  };
117
124
  export type StateExpiredPayloads<TBot extends common.BaseBot> = {
118
- [K in keyof IncomingStates<TBot>]: CommonHandlerProps<TBot> & {
119
- state: IncomingStates<TBot>[K];
125
+ [TSateName in utils.StringKeys<IncomingStates<TBot>>]: CommonHandlerProps<TBot> & {
126
+ state: IncomingStates<TBot>[TSateName];
120
127
  };
121
128
  };
122
129
  export type StateExpiredHandlers<TBot extends common.BaseBot> = {
123
- [K in keyof IncomingStates<TBot>]: (args: StateExpiredPayloads<TBot>[K]) => Promise<void>;
130
+ [TSateName in utils.StringKeys<IncomingStates<TBot>>]: (args: StateExpiredPayloads<TBot>[TSateName]) => Promise<void>;
124
131
  };
125
132
  export type ActionHandlerPayloads<TBot extends common.BaseBot> = {
126
- [K in keyof TBot['actions']]: CommonHandlerProps<TBot> & {
127
- type?: K;
128
- input: TBot['actions'][K]['input'];
133
+ [TActionName in utils.StringKeys<TBot['actions']>]: CommonHandlerProps<TBot> & {
134
+ type?: TActionName;
135
+ input: TBot['actions'][TActionName]['input'];
129
136
  };
130
137
  };
131
138
  export type ActionHandlers<TBot extends common.BaseBot> = {
132
- [K in keyof TBot['actions']]: (props: ActionHandlerPayloads<TBot>[K]) => Promise<TBot['actions'][K]['output']>;
139
+ [TActionName in utils.StringKeys<TBot['actions']>]: (props: ActionHandlerPayloads<TBot>[TActionName]) => Promise<TBot['actions'][TActionName]['output']>;
140
+ };
141
+ export type BridgeWorkflowUpdateType = 'child_workflow_deleted' | 'child_workflow_finished' | 'workflow_timedout' | 'workflow_started' | 'workflow_continued';
142
+ export type WorkflowUpdateEventPayload = {
143
+ type: BridgeWorkflowUpdateType;
144
+ childWorkflow?: client.Workflow;
145
+ workflow: client.Workflow;
146
+ conversation?: client.Conversation;
147
+ user?: client.User;
148
+ };
149
+ export type WorkflowUpdateEvent = utils.Merge<client.Event, {
150
+ type: 'workflow_update';
151
+ payload: WorkflowUpdateEventPayload;
152
+ }>;
153
+ export type WorkflowPayloads<TBot extends common.BaseBot> = {
154
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]: CommonHandlerProps<TBot> & {
155
+ conversation?: client.Conversation;
156
+ user?: client.User;
157
+ /**
158
+ * # EXPERIMENTAL
159
+ * This API is experimental and may change in the future.
160
+ */
161
+ workflow: workflowProxy.WorkflowWithUtilities<TBot, TWorkflowName>;
162
+ };
163
+ };
164
+ export type WorkflowHandlers<TBot extends common.BaseBot> = {
165
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]: (props: WorkflowPayloads<TBot>[TWorkflowName]) => Promise<void>;
133
166
  };
134
167
  type BaseHookDefinition = {
135
168
  stoppable?: boolean;
@@ -196,43 +229,83 @@ export type HookDefinitions<TBot extends common.BaseBot> = {
196
229
  }>;
197
230
  };
198
231
  export type HookData<TBot extends common.BaseBot> = {
199
- [H in keyof HookDefinitions<TBot>]: {
200
- [T in keyof HookDefinitions<TBot>[H]['data']]: HookDefinitions<TBot>[H]['data'][T];
232
+ [THookType in utils.StringKeys<HookDefinitions<TBot>>]: {
233
+ [THookDataName in utils.StringKeys<HookDefinitions<TBot>[THookType]['data']>]: HookDefinitions<TBot>[THookType]['data'][THookDataName];
201
234
  };
202
235
  };
203
236
  export type HookInputs<TBot extends common.BaseBot> = {
204
- [H in keyof HookData<TBot>]: {
205
- [T in keyof HookData<TBot>[H]]: CommonHandlerProps<TBot> & {
206
- data: HookData<TBot>[H][T];
237
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
238
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: CommonHandlerProps<TBot> & {
239
+ data: HookData<TBot>[THookType][THookDataName];
207
240
  };
208
241
  };
209
242
  };
210
243
  export type HookOutputs<TBot extends common.BaseBot> = {
211
- [H in keyof HookData<TBot>]: {
212
- [T in keyof HookData<TBot>[H]]: {
213
- data?: HookData<TBot>[H][T];
214
- } & (HookDefinitions<TBot>[H]['stoppable'] extends true ? {
244
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
245
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: {
246
+ data?: HookData<TBot>[THookType][THookDataName];
247
+ } & (HookDefinitions<TBot>[THookType]['stoppable'] extends true ? {
215
248
  stop?: boolean;
216
249
  } : {});
217
250
  };
218
251
  };
219
252
  export type HookHandlers<TBot extends common.BaseBot> = {
220
- [H in keyof HookData<TBot>]: {
221
- [T in keyof HookData<TBot>[H]]: (input: HookInputs<TBot>[H][T]) => Promise<HookOutputs<TBot>[H][T] | undefined>;
253
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
254
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: (input: HookInputs<TBot>[THookType][THookDataName]) => Promise<HookOutputs<TBot>[THookType][THookDataName] | undefined>;
222
255
  };
223
256
  };
224
257
  export type MessageHandlersMap<TBot extends common.BaseBot> = {
225
- [T in keyof IncomingMessages<TBot>]?: MessageHandlers<TBot>[T][];
258
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: MessageHandlers<TBot>[TMessageName][];
226
259
  };
227
260
  export type EventHandlersMap<TBot extends common.BaseBot> = {
228
- [T in keyof IncomingEvents<TBot>]?: EventHandlers<TBot>[T][];
261
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: EventHandlers<TBot>[TEventName][];
229
262
  };
230
263
  export type StateExpiredHandlersMap<TBot extends common.BaseBot> = {
231
- [T in keyof IncomingStates<TBot>]?: StateExpiredHandlers<TBot>[T][];
264
+ [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: StateExpiredHandlers<TBot>[TStateName][];
232
265
  };
233
266
  export type HookHandlersMap<TBot extends common.BaseBot> = {
234
- [H in keyof HookData<TBot>]: {
235
- [T in keyof HookData<TBot>[H]]?: HookHandlers<TBot>[H][T][];
267
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
268
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: HookHandlers<TBot>[THookType][THookDataName][];
269
+ };
270
+ };
271
+ export type WorkflowUpdateType = 'started' | 'continued' | 'timed_out';
272
+ export type WorkflowHandlersMap<TBot extends common.BaseBot> = {
273
+ [TWorkflowUpdateType in WorkflowUpdateType]: {
274
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: WorkflowHandlers<TBot>[TWorkflowName][];
275
+ };
276
+ };
277
+ export type OrderedMessageHandlersMap<TBot extends common.BaseBot> = {
278
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: {
279
+ handler: MessageHandlers<TBot>[TMessageName];
280
+ order: number;
281
+ }[];
282
+ };
283
+ export type OrderedEventHandlersMap<TBot extends common.BaseBot> = {
284
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: {
285
+ handler: EventHandlers<TBot>[TEventName];
286
+ order: number;
287
+ }[];
288
+ };
289
+ export type OrderedStateExpiredHandlersMap<TBot extends common.BaseBot> = {
290
+ [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: {
291
+ handler: StateExpiredHandlers<TBot>[TStateName];
292
+ order: number;
293
+ }[];
294
+ };
295
+ export type OrderedHookHandlersMap<TBot extends common.BaseBot> = {
296
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
297
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: {
298
+ handler: HookHandlers<TBot>[THookType][THookDataName];
299
+ order: number;
300
+ }[];
301
+ };
302
+ };
303
+ export type OrderedWorkflowHandlersMap<TBot extends common.BaseBot> = {
304
+ [TWorkflowUpdateType in WorkflowUpdateType]: {
305
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: {
306
+ handler: WorkflowHandlers<TBot>[TWorkflowName];
307
+ order: number;
308
+ }[];
236
309
  };
237
310
  };
238
311
  /**
@@ -246,15 +319,23 @@ export type BotHandlers<TBot extends common.BaseBot> = {
246
319
  eventHandlers: EventHandlersMap<TBot>;
247
320
  stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
248
321
  hookHandlers: HookHandlersMap<TBot>;
322
+ workflowHandlers: WorkflowHandlersMap<TBot>;
249
323
  };
324
+ type _GetPluginPrefix<TKey extends string, TPlugin extends plugin.BasePlugin> = TKey extends TPlugin['name'] ? '' : `${TKey}#`;
250
325
  type ImplementedActions<_TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = utils.UnionToIntersection<utils.ValueOf<{
251
- [K in keyof TPlugins]: TPlugins[K]['actions'];
326
+ [TPlugin in utils.StringKeys<TPlugins>]: {
327
+ [TAction in utils.StringKeys<TPlugins[TPlugin]['actions']> as `${_GetPluginPrefix<utils.Cast<TPlugin, string>, TPlugins[TPlugin]>}${utils.Cast<TAction, string>}`]: TPlugins[TPlugin]['actions'][TAction];
328
+ };
252
329
  }>>;
253
- type UnimplementedActions<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = Omit<TBot['actions'], keyof ImplementedActions<TBot, TPlugins>>;
330
+ type UnimplementedActions<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = Omit<TBot['actions'], utils.StringKeys<ImplementedActions<TBot, TPlugins>>>;
254
331
  export type ImplementedActionHandlers<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
255
- [K in keyof ImplementedActions<TBot, TPlugins>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
332
+ [K in utils.StringKeys<ImplementedActions<TBot, TPlugins>>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
256
333
  };
257
334
  export type UnimplementedActionHandlers<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
258
- [K in keyof UnimplementedActions<TBot, TPlugins>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
335
+ [K in utils.StringKeys<UnimplementedActions<TBot, TPlugins>>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
336
+ };
337
+ export type ServerProps = Omit<CommonHandlerProps<common.BaseBot>, 'workflows'> & {
338
+ req: Request;
339
+ self: BotHandlers<common.BaseBot>;
259
340
  };
260
341
  export {};
@@ -0,0 +1,3 @@
1
+ import { Response } from '../../../serve';
2
+ import * as types from '../types';
3
+ export declare const handleWorkflowUpdateEvent: (props: types.ServerProps, event: types.WorkflowUpdateEvent) => Promise<Response>;
@@ -0,0 +1,2 @@
1
+ import * as types from '../types';
2
+ export declare const bridgeUpdateTypeToSnakeCase: (updateType: types.BridgeWorkflowUpdateType) => types.WorkflowUpdateType;
@@ -0,0 +1,2 @@
1
+ export * from './proxy';
2
+ export * from './types';
@@ -0,0 +1,10 @@
1
+ import type * as client from '@botpress/client';
2
+ import type { BotSpecificClient } from '../../bot';
3
+ import type * as typeUtils from '../../utils/type-utils';
4
+ import type { BaseBot } from '../common';
5
+ import type { WorkflowProxy, WorkflowWithUtilities } from './types';
6
+ export declare const proxyWorkflows: <TBot extends BaseBot>(client: BotSpecificClient<TBot> | client.Client) => WorkflowProxy<TBot>;
7
+ export declare const wrapWorkflowInstance: <TBot extends BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot["workflows"]>>(props: {
8
+ client: BotSpecificClient<TBot> | client.Client;
9
+ workflow: client.Workflow;
10
+ }) => WorkflowWithUtilities<TBot, TWorkflowName>;
@@ -0,0 +1,64 @@
1
+ import type * as client from '@botpress/client';
2
+ import type * as typeUtils from '../../utils/type-utils';
3
+ import type * as commonTypes from '../common';
4
+ export type WorkflowProxy<TBot extends commonTypes.BaseBot = commonTypes.BaseBot> = Readonly<{
5
+ [TWorkflowName in typeUtils.StringKeys<TBot['workflows']>]: Readonly<{
6
+ startNewInstance: (x: Pick<client.ClientInputs['createWorkflow'], 'conversationId' | 'userId' | 'timeoutAt'> & {
7
+ tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
8
+ input: TBot['workflows'][TWorkflowName]['input'];
9
+ }) => Promise<Readonly<Omit<client.ClientOutputs['createWorkflow'], 'workflow'> & {
10
+ workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
11
+ }>>;
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
+ }>;
22
+ }>;
23
+ }>;
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 & {
30
+ name: TWorkflowName;
31
+ input: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['input'];
32
+ output: Partial<typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output']>;
33
+ tags: Partial<TBot['workflows'][TWorkflowName]['tags']>;
34
+ /**
35
+ * Updates the current workflow instance
36
+ */
37
+ update(x: typeUtils.AtLeastOneProperty<Pick<client.ClientInputs['updateWorkflow'], 'userId' | 'timeoutAt'> & {
38
+ tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
39
+ output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
40
+ }>): Promise<{
41
+ workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
42
+ }>;
43
+ /**
44
+ * Marks the current workflow instance as failed and stops execution
45
+ */
46
+ setFailed(x: Required<Pick<client.ClientInputs['updateWorkflow'], 'failureReason'>>): Promise<{
47
+ workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
48
+ }>;
49
+ /**
50
+ * Marks the current workflow instance as completed and stops execution
51
+ */
52
+ setCompleted(x?: {
53
+ output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
54
+ }): Promise<{
55
+ workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
56
+ }>;
57
+ /**
58
+ * Discards all output data and cancels the current workflow instance
59
+ */
60
+ cancel(): Promise<{
61
+ workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
62
+ }>;
63
+ }>;
64
+ export {};
@@ -0,0 +1 @@
1
+ export {};