@botpress/sdk 6.8.0 → 6.9.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/.turbo/turbo-build.log +5 -5
- package/dist/bot/server/types.d.ts +20 -1
- package/dist/common/types.d.ts +1 -0
- package/dist/index.cjs +18 -18
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +3 -3
- package/dist/integration/client/sub-types.d.ts +1 -2
- package/dist/integration/client/types.d.ts +11 -11
- package/dist/plugin/conversation-proxy/types.d.ts +1 -1
- package/dist/plugin/server/types.d.ts +76 -28
- package/package.json +2 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { commonTypes } from '../../common';
|
|
2
1
|
import * as utils from '../../utils/type-utils';
|
|
3
2
|
import * as common from '../common';
|
|
4
3
|
export type EnumerateMessages<TIntegration extends common.BaseIntegration> = utils.UnionToIntersection<utils.ValueOf<{
|
|
@@ -24,5 +23,5 @@ export type ConversationTags<TIntegration extends common.BaseIntegration> = keyo
|
|
|
24
23
|
export type MessageTags<TIntegration extends common.BaseIntegration> = keyof utils.UnionToIntersection<utils.ValueOf<{
|
|
25
24
|
[TChannelName in keyof TIntegration['channels']]: TIntegration['channels'][TChannelName]['message']['tags'];
|
|
26
25
|
}>>;
|
|
27
|
-
export type UserTags<TIntegration extends common.BaseIntegration> =
|
|
26
|
+
export type UserTags<TIntegration extends common.BaseIntegration> = keyof TIntegration['user']['tags'];
|
|
28
27
|
export type TagsOfMessage<TIntegration extends common.BaseIntegration, TMessageName extends keyof EnumerateMessages<TIntegration>> = keyof utils.UnionToIntersection<GetMessageByName<TIntegration, TMessageName>['tags']>;
|
|
@@ -32,11 +32,11 @@ export type ListConversations<TIntegration extends common.BaseIntegration> = <Ch
|
|
|
32
32
|
}>) => Res<client.Client['listConversations']>;
|
|
33
33
|
export type GetOrCreateConversation<TIntegration extends common.BaseIntegration> = <ChannelName extends keyof TIntegration['channels'], TTags extends keyof GetChannelByName<TIntegration, ChannelName>['conversation']['tags']>(x: utils.Merge<Arg<client.Client['getOrCreateConversation']>, {
|
|
34
34
|
channel: utils.Cast<ChannelName, string>;
|
|
35
|
-
tags: commonTypes.
|
|
35
|
+
tags: commonTypes.ToNullableTags<TTags>;
|
|
36
36
|
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>;
|
|
37
37
|
}>) => Promise<GetOrCreateConversationResponse<TIntegration, ChannelName>>;
|
|
38
38
|
export type UpdateConversation<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateConversation']>, {
|
|
39
|
-
tags?: commonTypes.
|
|
39
|
+
tags?: commonTypes.ToNullableTags<ConversationTags<TIntegration>>;
|
|
40
40
|
}>) => Promise<ConversationResponse<TIntegration>>;
|
|
41
41
|
export type DeleteConversation<_TIntegration extends common.BaseIntegration> = client.Client['deleteConversation'];
|
|
42
42
|
export type ListParticipants<_TIntegration extends common.BaseIntegration> = client.Client['listParticipants'];
|
|
@@ -73,12 +73,12 @@ type GetOrCreateMessageResponse<TIntegration extends common.BaseIntegration, TMe
|
|
|
73
73
|
export type GetOrCreateMessage<TIntegration extends common.BaseIntegration> = <TMessage extends keyof EnumerateMessages<TIntegration>, TTags extends keyof GetMessageByName<TIntegration, TMessage>['tags']>(x: utils.Merge<Arg<client.Client['getOrCreateMessage']>, {
|
|
74
74
|
type: utils.Cast<TMessage, string>;
|
|
75
75
|
payload?: GetMessageByName<TIntegration, TMessage>['payload'];
|
|
76
|
-
tags: commonTypes.
|
|
76
|
+
tags: commonTypes.ToNullableTags<TTags>;
|
|
77
77
|
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>;
|
|
78
78
|
}>) => Promise<GetOrCreateMessageResponse<TIntegration, TMessage>>;
|
|
79
79
|
export type GetMessage<TIntegration extends common.BaseIntegration> = (x: Arg<client.Client['getMessage']>) => Promise<MessageResponse<TIntegration>>;
|
|
80
80
|
export type UpdateMessage<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateMessage']>, {
|
|
81
|
-
tags
|
|
81
|
+
tags?: commonTypes.ToNullableTags<MessageTags<TIntegration>>;
|
|
82
82
|
}>) => Promise<MessageResponse<TIntegration>>;
|
|
83
83
|
export type ListMessages<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listMessages']>, {
|
|
84
84
|
tags?: commonTypes.ToTags<MessageTags<TIntegration>>;
|
|
@@ -86,32 +86,32 @@ export type ListMessages<TIntegration extends common.BaseIntegration> = (x: util
|
|
|
86
86
|
export type DeleteMessage<_TIntegration extends common.BaseIntegration> = client.Client['deleteMessage'];
|
|
87
87
|
type UserResponse<TIntegration extends common.BaseIntegration> = {
|
|
88
88
|
user: utils.Merge<Awaited<Res<client.Client['getUser']>>['user'], {
|
|
89
|
-
tags: UserTags<TIntegration
|
|
89
|
+
tags: commonTypes.ToTags<UserTags<TIntegration>>;
|
|
90
90
|
}>;
|
|
91
91
|
};
|
|
92
92
|
export type CreateUser<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['createUser']>, {
|
|
93
|
-
tags: UserTags<TIntegration
|
|
93
|
+
tags: commonTypes.ToTags<UserTags<TIntegration>>;
|
|
94
94
|
}>) => Promise<UserResponse<TIntegration>>;
|
|
95
95
|
export type GetUser<TIntegration extends common.BaseIntegration> = (x: Arg<client.Client['getUser']>) => Promise<UserResponse<TIntegration>>;
|
|
96
96
|
export type ListUsers<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listUsers']>, {
|
|
97
|
-
tags?: UserTags<TIntegration
|
|
97
|
+
tags?: commonTypes.ToTags<UserTags<TIntegration>>;
|
|
98
98
|
}>) => Res<client.Client['listUsers']>;
|
|
99
99
|
type GetOrCreateUserResponse<TIntegration extends common.BaseIntegration> = utils.Merge<Awaited<Res<client.Client['getOrCreateUser']>>, {
|
|
100
100
|
user: utils.Merge<Awaited<Res<client.Client['getOrCreateUser']>>['user'], {
|
|
101
|
-
tags: UserTags<TIntegration
|
|
101
|
+
tags: commonTypes.ToTags<UserTags<TIntegration>>;
|
|
102
102
|
}>;
|
|
103
103
|
}>;
|
|
104
104
|
export type GetOrCreateUser<TIntegration extends common.BaseIntegration> = <TTags extends keyof TIntegration['user']['tags']>(x: utils.Merge<Arg<client.Client['getOrCreateUser']>, {
|
|
105
|
-
tags: commonTypes.
|
|
105
|
+
tags: commonTypes.ToNullableTags<TTags>;
|
|
106
106
|
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>;
|
|
107
107
|
}>) => Promise<GetOrCreateUserResponse<TIntegration>>;
|
|
108
108
|
export type UpdateUser<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateUser']>, {
|
|
109
|
-
tags?: UserTags<TIntegration
|
|
109
|
+
tags?: commonTypes.ToNullableTags<UserTags<TIntegration>>;
|
|
110
110
|
}>) => Promise<UserResponse<TIntegration>>;
|
|
111
111
|
export type DeleteUser<_TIntegration extends common.BaseIntegration> = client.Client['deleteUser'];
|
|
112
112
|
export type InitializeIncomingMessage<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['initializeIncomingMessage']>, {
|
|
113
113
|
user?: utils.Merge<NonNullable<Arg<client.Client['initializeIncomingMessage']>['user']>, {
|
|
114
|
-
tags: UserTags<TIntegration
|
|
114
|
+
tags: commonTypes.ToTags<UserTags<TIntegration>>;
|
|
115
115
|
}>;
|
|
116
116
|
conversation?: utils.Merge<NonNullable<Arg<client.Client['initializeIncomingMessage']>['conversation']>, {
|
|
117
117
|
tags: commonTypes.ToTags<ConversationTags<TIntegration>>;
|
|
@@ -36,7 +36,7 @@ export type ActionableConversation<TPlugin extends BasePlugin, TChannelName exte
|
|
|
36
36
|
delete: () => Promise<void>;
|
|
37
37
|
update: (props: typeUtils.Merge<Omit<client.ClientInputs['updateConversation'], 'id'>, {
|
|
38
38
|
tags?: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['conversation']['tags']>>;
|
|
39
|
-
}>) => Promise<ActionableConversation<TPlugin>>;
|
|
39
|
+
}>) => Promise<ActionableConversation<TPlugin, TChannelName, TMessage>>;
|
|
40
40
|
getMessage: (props: {
|
|
41
41
|
id: string;
|
|
42
42
|
}) => Promise<messageProxy.ActionableMessage<TPlugin, TMessage>>;
|
|
@@ -253,6 +253,16 @@ export type WorkflowHandlers<TPlugin extends common.BasePlugin> = {
|
|
|
253
253
|
type BaseHookDefinition = {
|
|
254
254
|
stoppable?: boolean;
|
|
255
255
|
data: any;
|
|
256
|
+
/**
|
|
257
|
+
* Per-hook-type extra props injected into the hook handler input. Only set
|
|
258
|
+
* for hooks where the bot runtime already has the relevant context (e.g.
|
|
259
|
+
* incoming message hooks). The `raw` shape uses `client.User`/
|
|
260
|
+
* `client.Conversation`; the `injected` shape replaces them with proxies.
|
|
261
|
+
*/
|
|
262
|
+
extraInputs?: {
|
|
263
|
+
raw: object;
|
|
264
|
+
injected: object;
|
|
265
|
+
};
|
|
256
266
|
};
|
|
257
267
|
type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> = THookDef;
|
|
258
268
|
/**
|
|
@@ -261,8 +271,6 @@ type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> =
|
|
|
261
271
|
* - after_register
|
|
262
272
|
* - before_state_expired
|
|
263
273
|
* - after_state_expired
|
|
264
|
-
* - before_incoming_call_action
|
|
265
|
-
* - after_incoming_call_action
|
|
266
274
|
*/
|
|
267
275
|
export type HookDefinitionType = keyof HookDefinitions<common.BasePlugin>;
|
|
268
276
|
export type HookDefinitions<TPlugin extends common.BasePlugin> = {
|
|
@@ -277,6 +285,16 @@ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
|
|
|
277
285
|
data: _IncomingMessages<TPlugin> & {
|
|
278
286
|
'*': AnyIncomingMessage<TPlugin>;
|
|
279
287
|
};
|
|
288
|
+
extraInputs: {
|
|
289
|
+
raw: {
|
|
290
|
+
user?: client.User;
|
|
291
|
+
conversation?: client.Conversation;
|
|
292
|
+
};
|
|
293
|
+
injected: {
|
|
294
|
+
user?: userProxy.ActionableUser<TPlugin, string>;
|
|
295
|
+
conversation?: conversationProxy.ActionableConversation<TPlugin>;
|
|
296
|
+
};
|
|
297
|
+
};
|
|
280
298
|
}>;
|
|
281
299
|
before_outgoing_message: HookDefinition<{
|
|
282
300
|
stoppable: false;
|
|
@@ -307,6 +325,16 @@ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
|
|
|
307
325
|
data: _IncomingMessages<TPlugin> & {
|
|
308
326
|
'*': AnyIncomingMessage<TPlugin>;
|
|
309
327
|
};
|
|
328
|
+
extraInputs: {
|
|
329
|
+
raw: {
|
|
330
|
+
user?: client.User;
|
|
331
|
+
conversation?: client.Conversation;
|
|
332
|
+
};
|
|
333
|
+
injected: {
|
|
334
|
+
user?: userProxy.ActionableUser<TPlugin, string>;
|
|
335
|
+
conversation?: conversationProxy.ActionableConversation<TPlugin>;
|
|
336
|
+
};
|
|
337
|
+
};
|
|
310
338
|
}>;
|
|
311
339
|
after_outgoing_message: HookDefinition<{
|
|
312
340
|
stoppable: false;
|
|
@@ -328,22 +356,36 @@ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
|
|
|
328
356
|
}>;
|
|
329
357
|
};
|
|
330
358
|
export type HookData<TPlugin extends common.BasePlugin> = {
|
|
331
|
-
[THookType in
|
|
359
|
+
[THookType in HookDefinitionType]: {
|
|
332
360
|
[THookDataName in utils.StringKeys<HookDefinitions<TPlugin>[THookType]['data']>]: HookDefinitions<TPlugin>[THookType]['data'][THookDataName];
|
|
333
361
|
};
|
|
334
362
|
};
|
|
363
|
+
type _HookExtraInputsRaw<TPlugin extends common.BasePlugin> = {
|
|
364
|
+
[THookType in HookDefinitionType]: HookDefinitions<TPlugin>[THookType] extends {
|
|
365
|
+
extraInputs: {
|
|
366
|
+
raw: infer T;
|
|
367
|
+
};
|
|
368
|
+
} ? T : {};
|
|
369
|
+
};
|
|
370
|
+
type _HookExtraInputsInjected<TPlugin extends common.BasePlugin> = {
|
|
371
|
+
[THookType in HookDefinitionType]: HookDefinitions<TPlugin>[THookType] extends {
|
|
372
|
+
extraInputs: {
|
|
373
|
+
injected: infer T;
|
|
374
|
+
};
|
|
375
|
+
} ? T : {};
|
|
376
|
+
};
|
|
335
377
|
export type HookInputsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
336
|
-
[THookType in
|
|
337
|
-
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & {
|
|
378
|
+
[THookType in HookDefinitionType]: {
|
|
379
|
+
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & _HookExtraInputsRaw<TPlugin>[THookType] & {
|
|
338
380
|
data: HookData<TPlugin>[THookType][THookDataName];
|
|
339
381
|
};
|
|
340
382
|
};
|
|
341
383
|
};
|
|
342
384
|
export type HookInputs<TPlugin extends common.BasePlugin> = {
|
|
343
|
-
[THookType in
|
|
385
|
+
[THookType in HookDefinitionType]: _WithInjectedProps<HookInputsWithoutInjectedProps<TPlugin>[THookType], TPlugin, _HookExtraInputsInjected<TPlugin>[THookType]>;
|
|
344
386
|
};
|
|
345
387
|
export type HookOutputs<TPlugin extends common.BasePlugin> = {
|
|
346
|
-
[THookType in
|
|
388
|
+
[THookType in HookDefinitionType]: {
|
|
347
389
|
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: {
|
|
348
390
|
data?: HookData<TPlugin>[THookType][THookDataName];
|
|
349
391
|
} & (HookDefinitions<TPlugin>[THookType]['stoppable'] extends true ? {
|
|
@@ -352,15 +394,21 @@ export type HookOutputs<TPlugin extends common.BasePlugin> = {
|
|
|
352
394
|
};
|
|
353
395
|
};
|
|
354
396
|
export type HookHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
355
|
-
[THookType in
|
|
397
|
+
[THookType in HookDefinitionType]: {
|
|
356
398
|
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: (input: HookInputsWithoutInjectedProps<TPlugin>[THookType][THookDataName]) => Promise<HookOutputs<TPlugin>[THookType][THookDataName] | undefined>;
|
|
357
399
|
};
|
|
358
400
|
};
|
|
359
401
|
export type HookHandlers<TPlugin extends common.BasePlugin> = {
|
|
360
|
-
[THookType in
|
|
402
|
+
[THookType in HookDefinitionType]: _WithInjectedPropsFn<HookHandlersWithoutInjectedProps<TPlugin>[THookType], TPlugin, _HookExtraInputsInjected<TPlugin>[THookType]>;
|
|
361
403
|
};
|
|
404
|
+
export type AnyHookHandler<TPlugin extends common.BasePlugin> = (input: CommonHandlerProps<TPlugin> & {
|
|
405
|
+
data: any;
|
|
406
|
+
} & InjectedHandlerProps<TPlugin>) => Promise<{
|
|
407
|
+
data?: any;
|
|
408
|
+
stop?: boolean;
|
|
409
|
+
} | undefined>;
|
|
362
410
|
export type HookHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
363
|
-
[THookType in
|
|
411
|
+
[THookType in HookDefinitionType]: {
|
|
364
412
|
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
|
|
365
413
|
};
|
|
366
414
|
};
|
|
@@ -374,36 +422,36 @@ export type WorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
|
374
422
|
}[];
|
|
375
423
|
};
|
|
376
424
|
};
|
|
377
|
-
export type OrderedMessageHandlersMap
|
|
378
|
-
[TMessageName in
|
|
379
|
-
handler: MessageHandlers<
|
|
425
|
+
export type OrderedMessageHandlersMap = {
|
|
426
|
+
[TMessageName in string]?: {
|
|
427
|
+
handler: MessageHandlers<common.BasePlugin>[TMessageName];
|
|
380
428
|
order: number;
|
|
381
429
|
}[];
|
|
382
430
|
};
|
|
383
|
-
export type OrderedEventHandlersMap
|
|
384
|
-
[TEventName in
|
|
385
|
-
handler: EventHandlers<
|
|
431
|
+
export type OrderedEventHandlersMap = {
|
|
432
|
+
[TEventName in string]?: {
|
|
433
|
+
handler: EventHandlers<common.BasePlugin>['*'];
|
|
386
434
|
order: number;
|
|
387
435
|
}[];
|
|
388
436
|
};
|
|
389
|
-
export type OrderedStateExpiredHandlersMap
|
|
390
|
-
[TStateName in
|
|
391
|
-
handler: StateExpiredHandlers<
|
|
437
|
+
export type OrderedStateExpiredHandlersMap = {
|
|
438
|
+
[TStateName in string]?: {
|
|
439
|
+
handler: StateExpiredHandlers<common.BasePlugin>['*'];
|
|
392
440
|
order: number;
|
|
393
441
|
}[];
|
|
394
442
|
};
|
|
395
|
-
export type OrderedHookHandlersMap
|
|
396
|
-
[THookType in
|
|
397
|
-
[THookDataName in
|
|
398
|
-
handler:
|
|
443
|
+
export type OrderedHookHandlersMap = {
|
|
444
|
+
[THookType in HookDefinitionType]: {
|
|
445
|
+
[THookDataName in string]?: {
|
|
446
|
+
handler: AnyHookHandler<common.BasePlugin>;
|
|
399
447
|
order: number;
|
|
400
448
|
}[];
|
|
401
449
|
};
|
|
402
450
|
};
|
|
403
|
-
export type OrderedWorkflowHandlersMap
|
|
451
|
+
export type OrderedWorkflowHandlersMap = {
|
|
404
452
|
[TWorkflowUpdateType in bot.WorkflowUpdateType]: {
|
|
405
|
-
[TWorkflowName in
|
|
406
|
-
handler: WorkflowHandlers<
|
|
453
|
+
[TWorkflowName in string]?: {
|
|
454
|
+
handler: WorkflowHandlers<common.BasePlugin>['*'];
|
|
407
455
|
order: number;
|
|
408
456
|
}[];
|
|
409
457
|
};
|
|
@@ -421,7 +469,7 @@ export type PluginHandlers<TPlugin extends common.BasePlugin> = {
|
|
|
421
469
|
[TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlersWithoutInjectedProps<TPlugin>[TStateName][];
|
|
422
470
|
};
|
|
423
471
|
hookHandlers: {
|
|
424
|
-
[THookType in
|
|
472
|
+
[THookType in HookDefinitionType]: {
|
|
425
473
|
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
|
|
426
474
|
};
|
|
427
475
|
};
|
|
@@ -444,7 +492,7 @@ export type InjectedPluginHandlers<TPlugin extends common.BasePlugin> = {
|
|
|
444
492
|
[TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlers<TPlugin>[TStateName][];
|
|
445
493
|
};
|
|
446
494
|
hookHandlers: {
|
|
447
|
-
[THookType in
|
|
495
|
+
[THookType in HookDefinitionType]: {
|
|
448
496
|
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlers<TPlugin>[THookType][THookDataName][];
|
|
449
497
|
};
|
|
450
498
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/sdk",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.9.1",
|
|
4
4
|
"description": "Botpress SDK",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"author": "",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@botpress/client": "1.
|
|
23
|
+
"@botpress/client": "1.44.0",
|
|
24
24
|
"browser-or-node": "^2.1.1",
|
|
25
25
|
"semver": "^7.3.8"
|
|
26
26
|
},
|