@botpress/sdk 4.15.11 → 4.15.12

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,20 +1,20 @@
1
1
 
2
- > @botpress/sdk@4.15.11 build /home/runner/work/botpress/botpress/packages/sdk
2
+ > @botpress/sdk@4.15.12 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.15.11 build:type /home/runner/work/botpress/botpress/packages/sdk
6
+ > @botpress/sdk@4.15.12 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.15.11 build:node /home/runner/work/botpress/botpress/packages/sdk
10
+ > @botpress/sdk@4.15.12 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.15.11 build:browser /home/runner/work/botpress/botpress/packages/sdk
15
+ > @botpress/sdk@4.15.12 build:browser /home/runner/work/botpress/botpress/packages/sdk
16
16
  > ts-node -T ./build.ts --browser
17
17
 
18
- (node:3706) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
18
+ (node:3727) [DEP0180] DeprecationWarning: fs.Stats constructor is deprecated.
19
19
  (Use `node --trace-deprecation ...` to show where the warning was created)
20
20
  Done
@@ -2,14 +2,14 @@ import type { Server } from 'node:http';
2
2
  import { BasePlugin, PluginImplementation } from '../plugin';
3
3
  import * as utils from '../utils';
4
4
  import { BaseBot } from './common';
5
- import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap, BotHandlers, UnimplementedActionHandlers } from './server';
5
+ import { MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap, UnimplementedActionHandlers, InjectedBotHandlers } from './server';
6
6
  export type BotImplementationProps<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> = {
7
7
  actions: UnimplementedActionHandlers<TBot, TPlugins>;
8
8
  plugins: {
9
9
  [K in utils.types.StringKeys<TPlugins>]: PluginImplementation<TPlugins[K]>;
10
10
  };
11
11
  };
12
- export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> implements BotHandlers<TBot> {
12
+ export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> implements InjectedBotHandlers<TBot> {
13
13
  readonly props: BotImplementationProps<TBot, TPlugins>;
14
14
  private _actionHandlers;
15
15
  private _messageHandlers;
@@ -20,12 +20,12 @@ export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins
20
20
  private _plugins;
21
21
  private _registerOrder;
22
22
  constructor(props: BotImplementationProps<TBot, TPlugins>);
23
- get actionHandlers(): ActionHandlers<TBot>;
24
- get messageHandlers(): MessageHandlersMap<TBot>;
25
- get eventHandlers(): EventHandlersMap<TBot>;
26
- get stateExpiredHandlers(): StateExpiredHandlersMap<TBot>;
27
- get hookHandlers(): HookHandlersMap<TBot>;
28
- get workflowHandlers(): WorkflowHandlersMap<TBot>;
23
+ get actionHandlers(): InjectedBotHandlers<TBot>['actionHandlers'];
24
+ get messageHandlers(): InjectedBotHandlers<TBot>['messageHandlers'];
25
+ get eventHandlers(): InjectedBotHandlers<TBot>['eventHandlers'];
26
+ get stateExpiredHandlers(): InjectedBotHandlers<TBot>['stateExpiredHandlers'];
27
+ get hookHandlers(): InjectedBotHandlers<TBot>['hookHandlers'];
28
+ get workflowHandlers(): InjectedBotHandlers<TBot>['workflowHandlers'];
29
29
  readonly on: {
30
30
  message: <T extends utils.types.StringKeys<MessageHandlersMap<TBot>>>(type: T, handler: MessageHandlers<TBot>[T]) => void;
31
31
  event: <T extends utils.types.StringKeys<EventHandlersMap<TBot>>>(type: T, handler: EventHandlers<TBot>[T]) => void;
@@ -112,14 +112,17 @@ export type CommonHandlerProps<TBot extends common.BaseBot> = {
112
112
  ctx: BotContext;
113
113
  logger: BotLogger;
114
114
  client: BotClient<TBot>;
115
+ };
116
+ export type InjectedHandlerProps<TBot extends common.BaseBot> = {
115
117
  /**
116
118
  * # EXPERIMENTAL
117
119
  * This API is experimental and may change in the future.
118
120
  */
119
121
  workflows: workflowProxy.WorkflowProxy<TBot>;
120
122
  };
123
+ export type ExtendedHandlerProps<TBot extends common.BaseBot> = CommonHandlerProps<TBot> & InjectedHandlerProps<TBot>;
121
124
  export type MessagePayloads<TBot extends common.BaseBot> = {
122
- [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]: CommonHandlerProps<TBot> & {
125
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]: ExtendedHandlerProps<TBot> & {
123
126
  message: IncomingMessages<TBot>[TMessageName];
124
127
  user: client.User;
125
128
  conversation: client.Conversation;
@@ -130,7 +133,7 @@ export type MessageHandlers<TBot extends common.BaseBot> = {
130
133
  [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]: (args: MessagePayloads<TBot>[TMessageName]) => Promise<void>;
131
134
  };
132
135
  export type EventPayloads<TBot extends common.BaseBot> = {
133
- [TEventName in utils.StringKeys<IncomingEvents<TBot>>]: CommonHandlerProps<TBot> & {
136
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]: ExtendedHandlerProps<TBot> & {
134
137
  event: IncomingEvents<TBot>[TEventName];
135
138
  };
136
139
  };
@@ -138,7 +141,7 @@ export type EventHandlers<TBot extends common.BaseBot> = {
138
141
  [TEventName in utils.StringKeys<IncomingEvents<TBot>>]: (args: EventPayloads<TBot>[TEventName]) => Promise<void>;
139
142
  };
140
143
  export type StateExpiredPayloads<TBot extends common.BaseBot> = {
141
- [TSateName in utils.StringKeys<IncomingStates<TBot>>]: CommonHandlerProps<TBot> & {
144
+ [TSateName in utils.StringKeys<IncomingStates<TBot>>]: ExtendedHandlerProps<TBot> & {
142
145
  state: IncomingStates<TBot>[TSateName];
143
146
  };
144
147
  };
@@ -146,7 +149,7 @@ export type StateExpiredHandlers<TBot extends common.BaseBot> = {
146
149
  [TSateName in utils.StringKeys<IncomingStates<TBot>>]: (args: StateExpiredPayloads<TBot>[TSateName]) => Promise<void>;
147
150
  };
148
151
  export type ActionHandlerPayloads<TBot extends common.BaseBot> = {
149
- [TActionName in utils.StringKeys<TBot['actions']>]: CommonHandlerProps<TBot> & {
152
+ [TActionName in utils.StringKeys<TBot['actions']>]: ExtendedHandlerProps<TBot> & {
150
153
  type?: TActionName;
151
154
  input: TBot['actions'][TActionName]['input'];
152
155
  };
@@ -154,6 +157,9 @@ export type ActionHandlerPayloads<TBot extends common.BaseBot> = {
154
157
  export type ActionHandlers<TBot extends common.BaseBot> = {
155
158
  [TActionName in utils.StringKeys<TBot['actions']>]: (props: ActionHandlerPayloads<TBot>[TActionName]) => Promise<TBot['actions'][TActionName]['output']>;
156
159
  };
160
+ export type ActionHandlersMap<TBot extends common.BaseBot> = {
161
+ [TActionName in utils.StringKeys<TBot['actions']>]?: (props: Omit<Parameters<ActionHandlers<TBot>[TActionName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<Awaited<ReturnType<ActionHandlers<TBot>[TActionName]>>>;
162
+ };
157
163
  export type BridgeWorkflowUpdateType = 'child_workflow_deleted' | 'child_workflow_finished' | 'workflow_timedout' | 'workflow_started' | 'workflow_continued';
158
164
  export type WorkflowUpdateEventPayload = {
159
165
  type: BridgeWorkflowUpdateType;
@@ -167,7 +173,7 @@ export type WorkflowUpdateEvent = utils.Merge<client.Event, {
167
173
  payload: WorkflowUpdateEventPayload;
168
174
  }>;
169
175
  export type WorkflowPayloads<TBot extends common.BaseBot> = {
170
- [TWorkflowName in utils.StringKeys<TBot['workflows']>]: CommonHandlerProps<TBot> & {
176
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]: ExtendedHandlerProps<TBot> & {
171
177
  conversation?: client.Conversation;
172
178
  user?: client.User;
173
179
  event: WorkflowUpdateEvent;
@@ -262,7 +268,7 @@ export type HookData<TBot extends common.BaseBot> = {
262
268
  };
263
269
  export type HookInputs<TBot extends common.BaseBot> = {
264
270
  [THookType in utils.StringKeys<HookData<TBot>>]: {
265
- [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: CommonHandlerProps<TBot> & {
271
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: ExtendedHandlerProps<TBot> & {
266
272
  data: HookData<TBot>[THookType][THookDataName];
267
273
  };
268
274
  };
@@ -282,23 +288,25 @@ export type HookHandlers<TBot extends common.BaseBot> = {
282
288
  };
283
289
  };
284
290
  export type MessageHandlersMap<TBot extends common.BaseBot> = {
285
- [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: MessageHandlers<TBot>[TMessageName][];
291
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: ((props: Omit<Parameters<MessageHandlers<TBot>[TMessageName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<void>)[];
286
292
  };
287
293
  export type EventHandlersMap<TBot extends common.BaseBot> = {
288
- [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: EventHandlers<TBot>[TEventName][];
294
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: ((props: Omit<Parameters<EventHandlers<TBot>[TEventName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<void>)[];
289
295
  };
290
296
  export type StateExpiredHandlersMap<TBot extends common.BaseBot> = {
291
- [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: StateExpiredHandlers<TBot>[TStateName][];
297
+ [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: ((props: Omit<Parameters<StateExpiredHandlers<TBot>[TStateName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<void>)[];
292
298
  };
293
299
  export type HookHandlersMap<TBot extends common.BaseBot> = {
294
300
  [THookType in utils.StringKeys<HookData<TBot>>]: {
295
- [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: HookHandlers<TBot>[THookType][THookDataName][];
301
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: ((props: Omit<Parameters<HookHandlers<TBot>[THookType][THookDataName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<Awaited<ReturnType<HookHandlers<TBot>[THookType][THookDataName]>>>)[];
296
302
  };
297
303
  };
298
304
  export type WorkflowUpdateType = 'started' | 'continued' | 'timed_out';
299
305
  export type WorkflowHandlersMap<TBot extends common.BaseBot> = {
300
306
  [TWorkflowUpdateType in WorkflowUpdateType]: {
301
- [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: WorkflowHandlers<TBot>[TWorkflowName][];
307
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: ((props: Omit<Parameters<WorkflowHandlers<TBot>[TWorkflowName]>[0], keyof InjectedHandlerProps<TBot> | 'workflow'> & {
308
+ workflow: client.Workflow;
309
+ }) => Promise<client.Workflow>)[];
302
310
  };
303
311
  };
304
312
  export type OrderedMessageHandlersMap<TBot extends common.BaseBot> = {
@@ -336,18 +344,46 @@ export type OrderedWorkflowHandlersMap<TBot extends common.BaseBot> = {
336
344
  };
337
345
  };
338
346
  /**
347
+ * Bot handlers without InjectedHandlerProps
348
+ *
339
349
  * TODO:
340
350
  * the consumer of this type shouldnt be able to access "*" directly;
341
351
  * "*" is meant the user who registers an handler, not for the user who calls the handler
342
352
  */
343
353
  export type BotHandlers<TBot extends common.BaseBot> = {
344
- actionHandlers: ActionHandlers<TBot>;
354
+ actionHandlers: ActionHandlersMap<TBot>;
345
355
  messageHandlers: MessageHandlersMap<TBot>;
346
356
  eventHandlers: EventHandlersMap<TBot>;
347
357
  stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
348
358
  hookHandlers: HookHandlersMap<TBot>;
349
359
  workflowHandlers: WorkflowHandlersMap<TBot>;
350
360
  };
361
+ /** identical to BotHandlers, but contains the injected properties */
362
+ export type InjectedBotHandlers<TBot extends common.BaseBot> = {
363
+ actionHandlers: ActionHandlers<TBot>;
364
+ messageHandlers: {
365
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: MessageHandlers<TBot>[TMessageName][];
366
+ };
367
+ eventHandlers: {
368
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: EventHandlers<TBot>[TEventName][];
369
+ };
370
+ stateExpiredHandlers: {
371
+ [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: StateExpiredHandlers<TBot>[TStateName][];
372
+ };
373
+ hookHandlers: {
374
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
375
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: HookHandlers<TBot>[THookType][THookDataName][];
376
+ };
377
+ };
378
+ workflowHandlers: {
379
+ [TWorkflowUpdateType in WorkflowUpdateType]: {
380
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: {
381
+ handler: WorkflowHandlers<TBot>[TWorkflowName];
382
+ order: number;
383
+ }[];
384
+ };
385
+ };
386
+ };
351
387
  type _GetPluginPrefix<TKey extends string> = `${TKey}#`;
352
388
  type ImplementedActions<_TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = utils.UnionToIntersection<utils.ValueOf<{
353
389
  [TPlugin in utils.StringKeys<TPlugins>]: {
@@ -361,7 +397,7 @@ export type ImplementedActionHandlers<TBot extends common.BaseBot, TPlugins exte
361
397
  export type UnimplementedActionHandlers<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
362
398
  [K in utils.StringKeys<UnimplementedActions<TBot, TPlugins>>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
363
399
  };
364
- export type ServerProps = Omit<CommonHandlerProps<common.BaseBot>, 'workflows'> & {
400
+ export type ServerProps = CommonHandlerProps<common.BaseBot> & {
365
401
  req: Request;
366
402
  self: BotHandlers<common.BaseBot>;
367
403
  };