@botpress/sdk 2.5.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +11 -5
- package/dist/bot/client/index.d.ts +6 -0
- package/dist/bot/client/types.d.ts +87 -0
- package/dist/bot/definition.d.ts +17 -9
- package/dist/bot/implementation.d.ts +11 -10
- package/dist/bot/index.d.ts +1 -1
- package/dist/bot/server/types.d.ts +32 -26
- package/dist/bot/types/common.d.ts +6 -2
- package/dist/bot/types/generic.d.ts +110 -9
- package/dist/fixtures.d.ts +49 -0
- package/dist/index.cjs +129 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +123 -0
- package/dist/index.mjs.map +7 -0
- package/dist/integration/client/types.d.ts +2 -1
- package/dist/integration/definition/index.d.ts +48 -12
- package/dist/integration/definition/types.d.ts +6 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/integration/types/common.d.ts +0 -7
- package/dist/interface/definition.d.ts +0 -2
- package/dist/interface/index.d.ts +1 -0
- package/dist/interface/resolve.d.ts +18 -0
- package/dist/interface/types/index.d.ts +1 -0
- package/dist/package.d.ts +4 -2
- package/dist/plugin/action-proxy/index.d.ts +2 -0
- package/dist/plugin/action-proxy/proxy.d.ts +5 -0
- package/dist/plugin/action-proxy/types.d.ts +14 -0
- package/dist/plugin/action-proxy/types.test.d.ts +1 -0
- package/dist/plugin/definition.d.ts +11 -6
- package/dist/plugin/implementation.d.ts +21 -15
- package/dist/plugin/index.d.ts +2 -1
- package/dist/plugin/interface-resolution.d.ts +15 -0
- package/dist/plugin/server/index.d.ts +1 -0
- package/dist/plugin/server/types.d.ts +241 -1
- package/dist/plugin/types/common.d.ts +41 -0
- package/dist/plugin/types/generic.d.ts +110 -2
- package/dist/plugin/types/index.d.ts +2 -0
- package/dist/serve.d.ts +2 -2
- package/dist/utils/record-utils.d.ts +2 -0
- package/dist/utils/record-utils.test.d.ts +1 -0
- package/dist/utils/type-utils.d.ts +15 -0
- package/dist/zui.d.ts +1 -0
- package/package.json +9 -5
- package/dist/bot/merge-bots.d.ts +0 -2
- package/dist/index.js +0 -129
- package/dist/index.js.map +0 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as client from '@botpress/client';
|
|
2
2
|
import * as utils from '../../utils/type-utils';
|
|
3
3
|
import * as common from '../types';
|
|
4
|
-
type
|
|
4
|
+
type BaseChannelDefinition = common.BaseIntegration['channels'][string];
|
|
5
|
+
type GetChannelByName<TIntegration extends common.BaseIntegration, TChannelName extends keyof TIntegration['channels']> = utils.Cast<TIntegration['channels'][TChannelName], BaseChannelDefinition>;
|
|
5
6
|
/**
|
|
6
7
|
* @deprecated Integration's should no longer use their name as prefix for event types or tags.
|
|
7
8
|
*/
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import type * as esbuild from 'esbuild';
|
|
2
2
|
import { InterfacePackage } from '../../package';
|
|
3
|
+
import * as utils from '../../utils';
|
|
3
4
|
import { z } from '../../zui';
|
|
4
5
|
import { SchemaStore, BrandedSchema } from './branded-schema';
|
|
5
6
|
import { BaseConfig, BaseEvents, BaseActions, BaseChannels, BaseStates, BaseEntities, BaseConfigs } from './generic';
|
|
6
|
-
import { ConfigurationDefinition, EventDefinition, ChannelDefinition, ActionDefinition, StateDefinition, UserDefinition, SecretDefinition, EntityDefinition, AdditionalConfigurationDefinition } from './types';
|
|
7
|
+
import { ConfigurationDefinition, EventDefinition, ChannelDefinition, ActionDefinition, StateDefinition, UserDefinition, SecretDefinition, EntityDefinition, AdditionalConfigurationDefinition, InterfaceExtension } from './types';
|
|
7
8
|
export * from './types';
|
|
8
|
-
export type InterfaceExtension = InterfacePackage & {
|
|
9
|
-
entities: Record<string, {
|
|
10
|
-
name: string;
|
|
11
|
-
schema: z.AnyZodObject;
|
|
12
|
-
}>;
|
|
13
|
-
};
|
|
14
9
|
export type IntegrationDefinitionProps<TName extends string = string, TVersion extends string = string, TConfig extends BaseConfig = BaseConfig, TConfigs extends BaseConfigs = BaseConfigs, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TChannels extends BaseChannels = BaseChannels, TStates extends BaseStates = BaseStates, TEntities extends BaseEntities = BaseEntities> = {
|
|
15
10
|
name: TName;
|
|
16
11
|
version: TVersion;
|
|
@@ -51,11 +46,47 @@ export type IntegrationDefinitionProps<TName extends string = string, TVersion e
|
|
|
51
46
|
type EntitiesOfPackage<TPackage extends InterfacePackage> = {
|
|
52
47
|
[K in keyof TPackage['definition']['entities']]: NonNullable<TPackage['definition']['entities']>[K]['schema'];
|
|
53
48
|
};
|
|
54
|
-
type
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
type ActionsOfPackage<TPackage extends InterfacePackage> = {
|
|
50
|
+
[K in keyof TPackage['definition']['actions']]: NonNullable<TPackage['definition']['actions']>[K]['input']['schema'];
|
|
51
|
+
};
|
|
52
|
+
type EventsOfPackage<TPackage extends InterfacePackage> = {
|
|
53
|
+
[K in keyof TPackage['definition']['events']]: NonNullable<TPackage['definition']['events']>[K]['schema'];
|
|
54
|
+
};
|
|
55
|
+
type ChannelsOfPackage<TPackage extends InterfacePackage> = {
|
|
56
|
+
[K in keyof TPackage['definition']['channels']]: {
|
|
57
|
+
[M in keyof NonNullable<TPackage['definition']['channels']>[K]['messages']]: NonNullable<NonNullable<TPackage['definition']['channels']>[K]['messages']>[M]['schema'];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export type ActionOverrideProps = utils.types.AtLeastOneProperty<Pick<Required<ActionDefinition>, 'title' | 'description' | 'billable' | 'cacheable'> & {
|
|
61
|
+
name: string;
|
|
62
|
+
}>;
|
|
63
|
+
export type EventOverrideProps = utils.types.AtLeastOneProperty<Pick<Required<EventDefinition>, 'title' | 'description'> & {
|
|
64
|
+
name: string;
|
|
65
|
+
}>;
|
|
66
|
+
export type ChannelOverrideProps = utils.types.AtLeastOneProperty<Pick<Required<ChannelDefinition>, 'title' | 'description'> & {
|
|
67
|
+
name: string;
|
|
68
|
+
message: {
|
|
69
|
+
tags: Required<Required<ChannelDefinition>['message']>['tags'];
|
|
70
|
+
};
|
|
71
|
+
conversation: {
|
|
72
|
+
tags: Required<Required<ChannelDefinition>['conversation']>['tags'];
|
|
73
|
+
};
|
|
74
|
+
}>;
|
|
75
|
+
type ActionOverrides<TInterfaceActionNames extends string = string> = utils.types.AtLeastOneProperty<Record<TInterfaceActionNames, ActionOverrideProps>>;
|
|
76
|
+
type EventOverrides<TInterfaceEventNames extends string = string> = utils.types.AtLeastOneProperty<Record<TInterfaceEventNames, EventOverrideProps>>;
|
|
77
|
+
type ChannelOverrides<TInterfaceChannelNames extends string = string> = utils.types.AtLeastOneProperty<Record<TInterfaceChannelNames, ChannelOverrideProps>>;
|
|
78
|
+
type ExtensionBuilderInput<TIntegrationEntities extends BaseEntities, _TIntegrationActions extends BaseActions, _TIntegrationEvents extends BaseEvents, _TIntegrationChannels extends BaseChannels> = {
|
|
79
|
+
entities: SchemaStore<TIntegrationEntities>;
|
|
80
|
+
};
|
|
81
|
+
type ExtensionBuilderOutput<TInterfaceEntities extends BaseEntities, TInterfaceActions extends BaseActions, TInterfaceEvents extends BaseEvents, TInterfaceChannels extends BaseChannels> = {
|
|
82
|
+
entities: {
|
|
83
|
+
[K in keyof TInterfaceEntities]: BrandedSchema<z.ZodSchema<z.infer<TInterfaceEntities[K]>>>;
|
|
84
|
+
};
|
|
85
|
+
actions?: ActionOverrides<Extract<keyof TInterfaceActions, string>>;
|
|
86
|
+
events?: EventOverrides<Extract<keyof TInterfaceEvents, string>>;
|
|
87
|
+
channels?: ChannelOverrides<Extract<keyof TInterfaceChannels, string>>;
|
|
57
88
|
};
|
|
58
|
-
type ExtensionBuilder<TIntegrationEntities extends BaseEntities, TInterfaceEntities extends BaseEntities> = (input: ExtensionBuilderInput<TIntegrationEntities>) => ExtensionBuilderOutput<TInterfaceEntities>;
|
|
89
|
+
type ExtensionBuilder<TIntegrationEntities extends BaseEntities, TIntegrationActions extends BaseActions, TIntegrationEvents extends BaseEvents, TIntegrationChannels extends BaseChannels, TInterfaceEntities extends BaseEntities, TInterfaceActions extends BaseActions, TInterfaceEvents extends BaseEvents, TInterfaceChannels extends BaseChannels> = (input: ExtensionBuilderInput<TIntegrationEntities, TIntegrationActions, TIntegrationEvents, TIntegrationChannels>) => ExtensionBuilderOutput<TInterfaceEntities, TInterfaceActions, TInterfaceEvents, TInterfaceChannels>;
|
|
59
90
|
export declare class IntegrationDefinition<TName extends string = string, TVersion extends string = string, TConfig extends BaseConfig = BaseConfig, TConfigs extends BaseConfigs = BaseConfigs, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TChannels extends BaseChannels = BaseChannels, TStates extends BaseStates = BaseStates, TEntities extends BaseEntities = BaseEntities> {
|
|
60
91
|
readonly props: IntegrationDefinitionProps<TName, TVersion, TConfig, TConfigs, TEvents, TActions, TChannels, TStates, TEntities>;
|
|
61
92
|
readonly name: this['props']['name'];
|
|
@@ -77,5 +108,10 @@ export declare class IntegrationDefinition<TName extends string = string, TVersi
|
|
|
77
108
|
readonly interfaces: this['props']['interfaces'];
|
|
78
109
|
readonly __advanced: this['props']['__advanced'];
|
|
79
110
|
constructor(props: IntegrationDefinitionProps<TName, TVersion, TConfig, TConfigs, TEvents, TActions, TChannels, TStates, TEntities>);
|
|
80
|
-
extend<P extends InterfacePackage>(interfacePkg: P, builder: ExtensionBuilder<TEntities, EntitiesOfPackage<P>>): this;
|
|
111
|
+
extend<P extends InterfacePackage>(interfacePkg: P, builder: ExtensionBuilder<TEntities, TActions, TEvents, TChannels, EntitiesOfPackage<P>, ActionsOfPackage<P>, EventsOfPackage<P>, ChannelsOfPackage<P>>): this;
|
|
112
|
+
private _callBuilder;
|
|
113
|
+
private _mergeActions;
|
|
114
|
+
private _mergeEvents;
|
|
115
|
+
private _mergeChannels;
|
|
116
|
+
private _mergeMessage;
|
|
81
117
|
}
|
|
@@ -80,7 +80,12 @@ export type ResolvedInterface<TEvents extends BaseEvents = BaseEvents, TActions
|
|
|
80
80
|
[K in keyof TChannels]: ChannelDefinition<TChannels[K]>;
|
|
81
81
|
};
|
|
82
82
|
};
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* A.K.A. Interface Implementation Statetement
|
|
85
|
+
* Used by an integration to explicitly declare that it implements an interface
|
|
86
|
+
*/
|
|
87
|
+
export type InterfaceExtension<TEntities extends BaseEntities = BaseEntities, TActions extends BaseActions = BaseActions, TEvents extends BaseEvents = BaseEvents, TChannels extends BaseChannels = BaseChannels> = {
|
|
88
|
+
id?: string;
|
|
84
89
|
name: string;
|
|
85
90
|
version: string;
|
|
86
91
|
entities: {
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import * as utils from '../../utils/type-utils';
|
|
2
|
-
import { BaseIntegration } from './generic';
|
|
3
|
-
export type ConfigurationDefinition = BaseIntegration['configuration'];
|
|
4
|
-
export type ActionDefinition = BaseIntegration['actions'][string];
|
|
5
|
-
export type ChannelDefinition = BaseIntegration['channels'][string];
|
|
6
|
-
export type EventDefinition = BaseIntegration['events'][string];
|
|
7
|
-
export type StateDefinition = BaseIntegration['states'][string];
|
|
8
|
-
export type UserDefinition = BaseIntegration['user'];
|
|
9
2
|
type AsTags<T extends Record<string, string | undefined>> = utils.Cast<T, Record<string, string>>;
|
|
10
3
|
export type ToTags<TTags extends string | number | symbol> = AsTags<Partial<Record<utils.Cast<TTags, string>, string>>>;
|
|
11
4
|
export {};
|
|
@@ -45,7 +45,6 @@ export type InterfaceDefinitionProps<TName extends string = string, TVersion ext
|
|
|
45
45
|
channels?: {
|
|
46
46
|
[K in keyof TChannels]: GenericChannelDefinition<TEntities, TChannels[K]>;
|
|
47
47
|
};
|
|
48
|
-
templateName?: string;
|
|
49
48
|
};
|
|
50
49
|
export declare class InterfaceDefinition<TName extends string = string, TVersion extends string = string, TEntities extends BaseEntities = BaseEntities, TActions extends BaseActions = BaseActions, TEvents extends BaseEvents = BaseEvents, TChannels extends BaseChannels = BaseChannels> {
|
|
51
50
|
readonly props: InterfaceDefinitionProps<TName, TVersion, TEntities, TActions, TEvents, TChannels>;
|
|
@@ -63,7 +62,6 @@ export declare class InterfaceDefinition<TName extends string = string, TVersion
|
|
|
63
62
|
readonly channels: {
|
|
64
63
|
[K in keyof TChannels]: ChannelDefinition<TChannels[K]>;
|
|
65
64
|
};
|
|
66
|
-
readonly templateName: this['props']['templateName'];
|
|
67
65
|
constructor(props: InterfaceDefinitionProps<TName, TVersion, TEntities, TActions, TEvents, TChannels>);
|
|
68
66
|
private _getEntityReference;
|
|
69
67
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ActionOverrideProps, ChannelOverrideProps, EventOverrideProps, InterfaceExtension, ResolvedInterface } from '../integration';
|
|
2
|
+
import { InterfacePackage } from '../package';
|
|
3
|
+
import { ZuiObjectSchema } from '../zui';
|
|
4
|
+
type ResolveInterfaceInput = InterfacePackage & {
|
|
5
|
+
entities: Record<string, {
|
|
6
|
+
name: string;
|
|
7
|
+
schema: ZuiObjectSchema;
|
|
8
|
+
}>;
|
|
9
|
+
actions: Record<string, ActionOverrideProps>;
|
|
10
|
+
events: Record<string, EventOverrideProps>;
|
|
11
|
+
channels: Record<string, ChannelOverrideProps>;
|
|
12
|
+
};
|
|
13
|
+
type ResolveInterfaceOutput = {
|
|
14
|
+
resolved: ResolvedInterface;
|
|
15
|
+
statement: InterfaceExtension;
|
|
16
|
+
};
|
|
17
|
+
export declare const resolveInterface: (intrface: ResolveInterfaceInput) => ResolveInterfaceOutput;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './generic';
|
package/dist/package.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as integration from './integration';
|
|
2
2
|
import * as plugin from './plugin';
|
|
3
|
+
import * as utils from './utils/type-utils';
|
|
3
4
|
type NameVersion = {
|
|
4
5
|
name: string;
|
|
5
6
|
version: string;
|
|
@@ -8,6 +9,7 @@ type PackageReference = NameVersion & {
|
|
|
8
9
|
id?: string;
|
|
9
10
|
uri?: string;
|
|
10
11
|
};
|
|
12
|
+
type IntegrationPackageDefinitionInterface = utils.Merge<PackageReference, integration.InterfaceExtension>;
|
|
11
13
|
type IntegrationPackageDefinition = NameVersion & {
|
|
12
14
|
configuration?: integration.ConfigurationDefinition;
|
|
13
15
|
configurations?: Record<string, integration.AdditionalConfigurationDefinition>;
|
|
@@ -18,10 +20,9 @@ type IntegrationPackageDefinition = NameVersion & {
|
|
|
18
20
|
user?: integration.UserDefinition;
|
|
19
21
|
secrets?: Record<string, integration.SecretDefinition>;
|
|
20
22
|
entities?: Record<string, integration.EntityDefinition>;
|
|
21
|
-
interfaces?: Record<string,
|
|
23
|
+
interfaces?: Record<string, IntegrationPackageDefinitionInterface>;
|
|
22
24
|
};
|
|
23
25
|
type InterfacePackageDefinition = NameVersion & {
|
|
24
|
-
templateName?: string;
|
|
25
26
|
entities?: Record<string, integration.EntityDefinition>;
|
|
26
27
|
events?: Record<string, integration.EventDefinition>;
|
|
27
28
|
actions?: Record<string, integration.ActionDefinition>;
|
|
@@ -38,6 +39,7 @@ type PluginPackageDefinition = NameVersion & {
|
|
|
38
39
|
events?: Record<string, plugin.EventDefinition>;
|
|
39
40
|
recurringEvents?: Record<string, plugin.RecurringEventDefinition>;
|
|
40
41
|
actions?: Record<string, plugin.ActionDefinition>;
|
|
42
|
+
tables?: Record<string, plugin.TableDefinition>;
|
|
41
43
|
};
|
|
42
44
|
export type IntegrationPackage = PackageReference & {
|
|
43
45
|
type: 'integration';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Client } from '@botpress/client';
|
|
2
|
+
import { BotSpecificClient } from '../../bot';
|
|
3
|
+
import { BasePlugin, PluginInterfaceExtensions } from '../types';
|
|
4
|
+
import { ActionProxy } from './types';
|
|
5
|
+
export declare const proxyActions: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client, interfaces: PluginInterfaceExtensions<TPlugin>) => ActionProxy<TPlugin>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as utils from '../../utils/type-utils';
|
|
2
|
+
import { BasePlugin } from '../types';
|
|
3
|
+
type IntegrationActionProxy<TPlugin extends BasePlugin> = {
|
|
4
|
+
[TIntegrationName in keyof TPlugin['integrations']]: {
|
|
5
|
+
[TActionName in keyof TPlugin['integrations'][TIntegrationName]['actions']]: (input: TPlugin['integrations'][TIntegrationName]['actions'][TActionName]['input']) => Promise<TPlugin['integrations'][TIntegrationName]['actions'][TActionName]['output']>;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
type InterfacesActionProxy<TPlugin extends BasePlugin> = {
|
|
9
|
+
[TInterfaceName in keyof TPlugin['interfaces']]: {
|
|
10
|
+
[TActionName in keyof TPlugin['interfaces'][TInterfaceName]['actions']]: (input: TPlugin['interfaces'][TInterfaceName]['actions'][TActionName]['input']) => Promise<TPlugin['interfaces'][TInterfaceName]['actions'][TActionName]['output']>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type ActionProxy<TPlugin extends BasePlugin> = utils.Normalize<IntegrationActionProxy<TPlugin> & InterfacesActionProxy<TPlugin>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { StateDefinition, RecurringEventDefinition, EventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition } from '../bot/definition';
|
|
1
|
+
import { StateDefinition, RecurringEventDefinition, EventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition, TableDefinition } 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, IntegrationConfigInstance, } from '../bot/definition';
|
|
4
|
+
export { StateDefinition, RecurringEventDefinition, EventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition, TableDefinition, IntegrationConfigInstance, } from '../bot/definition';
|
|
5
5
|
type BaseConfig = ZuiObjectSchema;
|
|
6
6
|
type BaseStates = Record<string, ZuiObjectSchema>;
|
|
7
7
|
type BaseEvents = Record<string, ZuiObjectSchema>;
|
|
8
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
13
|
name: TName;
|
|
13
14
|
version: TVersion;
|
|
14
15
|
integrations?: {
|
|
@@ -31,9 +32,12 @@ export type PluginDefinitionProps<TName extends string = string, TVersion extend
|
|
|
31
32
|
actions?: {
|
|
32
33
|
[K in keyof TActions]: ActionDefinition<TActions[K]>;
|
|
33
34
|
};
|
|
35
|
+
tables?: {
|
|
36
|
+
[K in keyof TTables]: TableDefinition<TTables[K]>;
|
|
37
|
+
};
|
|
34
38
|
};
|
|
35
|
-
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> {
|
|
36
|
-
readonly props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations>;
|
|
39
|
+
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> {
|
|
40
|
+
readonly props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations, TTables>;
|
|
37
41
|
readonly name: this['props']['name'];
|
|
38
42
|
readonly version: this['props']['version'];
|
|
39
43
|
readonly integrations: this['props']['integrations'];
|
|
@@ -46,5 +50,6 @@ export declare class PluginDefinition<TName extends string = string, TVersion ex
|
|
|
46
50
|
readonly events: this['props']['events'];
|
|
47
51
|
readonly recurringEvents: this['props']['recurringEvents'];
|
|
48
52
|
readonly actions: this['props']['actions'];
|
|
49
|
-
|
|
53
|
+
readonly tables: this['props']['tables'];
|
|
54
|
+
constructor(props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations, TTables>);
|
|
50
55
|
}
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { MessageHandlersMap
|
|
2
|
-
import {
|
|
1
|
+
import { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, ActionHandlers as BotActionHandlers, BotHandlers } from '../bot';
|
|
2
|
+
import { MessageHandlersMap, MessageHandlers, EventHandlersMap, EventHandlers, StateExpiredHandlersMap, StateExpiredHandlers, HookData, HookHandlers, ActionHandlers, PluginConfiguration } from './server/types';
|
|
3
|
+
import { BasePlugin, PluginInterfaceExtensions } from './types';
|
|
3
4
|
export type PluginImplementationProps<TPlugin extends BasePlugin = BasePlugin> = {
|
|
4
5
|
actions: ActionHandlers<TPlugin>;
|
|
5
6
|
};
|
|
6
7
|
export type PluginRuntimeProps<TPlugin extends BasePlugin = BasePlugin> = {
|
|
7
|
-
configuration: TPlugin
|
|
8
|
-
interfaces:
|
|
9
|
-
[K in keyof TPlugin['interfaces']]: {
|
|
10
|
-
name: string;
|
|
11
|
-
version: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
8
|
+
configuration: PluginConfiguration<TPlugin>;
|
|
9
|
+
interfaces: PluginInterfaceExtensions<TPlugin>;
|
|
14
10
|
};
|
|
15
11
|
export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugin> implements BotHandlers<TPlugin> {
|
|
16
12
|
readonly props: PluginImplementationProps<TPlugin>;
|
|
17
13
|
private _runtimeProps;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
private _actionHandlers;
|
|
15
|
+
private _messageHandlers;
|
|
16
|
+
private _eventHandlers;
|
|
17
|
+
private _stateExpiredHandlers;
|
|
18
|
+
private _hookHandlers;
|
|
23
19
|
constructor(props: PluginImplementationProps<TPlugin>);
|
|
24
20
|
initialize(config: PluginRuntimeProps<TPlugin>): this;
|
|
25
|
-
get
|
|
21
|
+
private get _runtime();
|
|
22
|
+
private _getTools;
|
|
23
|
+
get actionHandlers(): BotActionHandlers<TPlugin>;
|
|
24
|
+
get messageHandlers(): BotMessageHandlersMap<TPlugin>;
|
|
25
|
+
get eventHandlers(): BotEventHandlersMap<TPlugin>;
|
|
26
|
+
get stateExpiredHandlers(): BotStateExpiredHandlersMap<TPlugin>;
|
|
27
|
+
get hookHandlers(): BotHookHandlersMap<TPlugin>;
|
|
26
28
|
readonly on: {
|
|
27
29
|
message: <T extends keyof MessageHandlersMap<TPlugin>>(type: T, handler: MessageHandlers<TPlugin>[T]) => void;
|
|
28
30
|
event: <T extends keyof EventHandlersMap<TPlugin>>(type: T, handler: EventHandlers<TPlugin>[T]) => void;
|
|
@@ -36,4 +38,8 @@ export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugi
|
|
|
36
38
|
afterOutgoingMessage: <T extends keyof HookData<TPlugin>["after_outgoing_message"]>(type: T, handler: HookHandlers<TPlugin>["after_outgoing_message"][T]) => void;
|
|
37
39
|
afterOutgoingCallAction: <T extends keyof HookData<TPlugin>["after_outgoing_call_action"]>(type: T, handler: HookHandlers<TPlugin>["after_outgoing_call_action"][T]) => void;
|
|
38
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* checks if the actual event resolves to the target event
|
|
43
|
+
*/
|
|
44
|
+
private _eventResolvesTo;
|
|
39
45
|
}
|
package/dist/plugin/index.d.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PluginInterfaceExtensions } from './types';
|
|
2
|
+
export type ParsedActionRef = {
|
|
3
|
+
namespace: string;
|
|
4
|
+
actionName: string;
|
|
5
|
+
};
|
|
6
|
+
export type ParsedEventRef = {
|
|
7
|
+
namespace: string;
|
|
8
|
+
eventName: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const parseActionRef: (actionRef: string) => ParsedActionRef | null;
|
|
11
|
+
export declare const parseEventRef: (eventRef: string) => ParsedEventRef | null;
|
|
12
|
+
export declare const formatActionRef: (actionRef: ParsedActionRef) => string;
|
|
13
|
+
export declare const formatEventRef: (eventRef: ParsedEventRef) => string;
|
|
14
|
+
export declare const resolveAction: (actionRef: ParsedActionRef, interfaces: PluginInterfaceExtensions<any>) => ParsedActionRef;
|
|
15
|
+
export declare const resolveEvent: (eventRef: ParsedEventRef, interfaces: PluginInterfaceExtensions<any>) => ParsedEventRef;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
|
@@ -1 +1,241 @@
|
|
|
1
|
-
|
|
1
|
+
import * as client from '@botpress/client';
|
|
2
|
+
import * as bot from '../../bot';
|
|
3
|
+
import * as utils from '../../utils/type-utils';
|
|
4
|
+
import * as proxy from '../action-proxy';
|
|
5
|
+
import * as types from '../types';
|
|
6
|
+
type EnumeratePluginEvents<TPlugin extends types.BasePlugin> = bot.EnumerateEvents<TPlugin> & types.EnumerateInterfaceEvents<TPlugin>;
|
|
7
|
+
type _IncomingEvents<TPlugin extends types.BasePlugin> = {
|
|
8
|
+
[K in keyof EnumeratePluginEvents<TPlugin>]: utils.Merge<client.Event, {
|
|
9
|
+
type: K;
|
|
10
|
+
payload: EnumeratePluginEvents<TPlugin>[K];
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
type _IncomingMessages<TPlugin extends types.BasePlugin> = {
|
|
14
|
+
[K in keyof bot.GetMessages<TPlugin>]: utils.Merge<client.Message, {
|
|
15
|
+
type: K;
|
|
16
|
+
payload: bot.GetMessages<TPlugin>[K];
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
type _IncomingStates<TPlugin extends types.BasePlugin> = {
|
|
20
|
+
[K in keyof bot.EnumerateStates<TPlugin>]: utils.Merge<client.State, {
|
|
21
|
+
name: K;
|
|
22
|
+
payload: bot.EnumerateStates<TPlugin>[K];
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
type _OutgoingMessageRequests<TPlugin extends types.BasePlugin> = {
|
|
26
|
+
[K in keyof bot.GetMessages<TPlugin>]: utils.Merge<client.ClientInputs['createMessage'], {
|
|
27
|
+
type: K;
|
|
28
|
+
payload: bot.GetMessages<TPlugin>[K];
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
type _OutgoingMessageResponses<TPlugin extends types.BasePlugin> = {
|
|
32
|
+
[K in keyof bot.GetMessages<TPlugin>]: utils.Merge<client.ClientOutputs['createMessage'], {
|
|
33
|
+
message: utils.Merge<client.Message, {
|
|
34
|
+
type: K;
|
|
35
|
+
payload: bot.GetMessages<TPlugin>[K];
|
|
36
|
+
}>;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
type _OutgoingCallActionRequests<TPlugin extends types.BasePlugin> = {
|
|
40
|
+
[K in keyof bot.EnumerateActionInputs<TPlugin>]: utils.Merge<client.ClientInputs['callAction'], {
|
|
41
|
+
type: K;
|
|
42
|
+
input: bot.EnumerateActionInputs<TPlugin>[K];
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
type _OutgoingCallActionResponses<TPlugin extends types.BasePlugin> = {
|
|
46
|
+
[K in keyof bot.EnumerateActionOutputs<TPlugin>]: utils.Merge<client.ClientOutputs['callAction'], {
|
|
47
|
+
output: bot.EnumerateActionOutputs<TPlugin>[K];
|
|
48
|
+
}>;
|
|
49
|
+
};
|
|
50
|
+
export type AnyIncomingEvent<_TPlugin extends types.BasePlugin> = client.Event;
|
|
51
|
+
export type AnyIncomingMessage<_TPlugin extends types.BasePlugin> = client.Message;
|
|
52
|
+
export type AnyOutgoingMessageRequest<_TPlugin extends types.BasePlugin> = client.ClientInputs['createMessage'];
|
|
53
|
+
export type AnyOutgoingMessageResponse<_TPlugin extends types.BasePlugin> = client.ClientOutputs['createMessage'];
|
|
54
|
+
export type AnyOutgoingCallActionRequest<_TPlugin extends types.BasePlugin> = client.ClientInputs['callAction'];
|
|
55
|
+
export type AnyOutgoingCallActionResponse<_TPlugin extends types.BasePlugin> = client.ClientOutputs['callAction'];
|
|
56
|
+
export type IncomingEvents<TPlugin extends types.BasePlugin> = _IncomingEvents<TPlugin> & {
|
|
57
|
+
'*': AnyIncomingEvent<TPlugin>;
|
|
58
|
+
};
|
|
59
|
+
export type IncomingMessages<TPlugin extends types.BasePlugin> = _IncomingMessages<TPlugin> & {
|
|
60
|
+
'*': AnyIncomingMessage<TPlugin>;
|
|
61
|
+
};
|
|
62
|
+
export type IncomingStates<_TPlugin extends types.BasePlugin> = _IncomingStates<_TPlugin> & {
|
|
63
|
+
'*': client.State;
|
|
64
|
+
};
|
|
65
|
+
export type OutgoingMessageRequests<TPlugin extends types.BasePlugin> = _OutgoingMessageRequests<TPlugin> & {
|
|
66
|
+
'*': AnyOutgoingMessageRequest<TPlugin>;
|
|
67
|
+
};
|
|
68
|
+
export type OutgoingMessageResponses<TPlugin extends types.BasePlugin> = _OutgoingMessageResponses<TPlugin> & {
|
|
69
|
+
'*': AnyOutgoingMessageResponse<TPlugin>;
|
|
70
|
+
};
|
|
71
|
+
export type OutgoingCallActionRequests<TPlugin extends types.BasePlugin> = _OutgoingCallActionRequests<TPlugin> & {
|
|
72
|
+
'*': AnyOutgoingCallActionRequest<TPlugin>;
|
|
73
|
+
};
|
|
74
|
+
export type OutgoingCallActionResponses<TPlugin extends types.BasePlugin> = _OutgoingCallActionResponses<TPlugin> & {
|
|
75
|
+
'*': AnyOutgoingCallActionResponse<TPlugin>;
|
|
76
|
+
};
|
|
77
|
+
export type PluginClient<_TPlugin extends types.BasePlugin> = bot.BotSpecificClient<types.BasePlugin>;
|
|
78
|
+
export type PluginConfiguration<TPlugin extends types.BasePlugin> = TPlugin['configuration'];
|
|
79
|
+
export type CommonHandlerProps<TPlugin extends types.BasePlugin> = {
|
|
80
|
+
ctx: bot.BotContext;
|
|
81
|
+
logger: bot.BotLogger;
|
|
82
|
+
client: PluginClient<TPlugin>;
|
|
83
|
+
configuration: PluginConfiguration<TPlugin>;
|
|
84
|
+
interfaces: types.PluginInterfaceExtensions<TPlugin>;
|
|
85
|
+
actions: proxy.ActionProxy<TPlugin>;
|
|
86
|
+
};
|
|
87
|
+
export type MessagePayloads<TPlugin extends types.BasePlugin> = {
|
|
88
|
+
[K in keyof IncomingMessages<TPlugin>]: CommonHandlerProps<TPlugin> & {
|
|
89
|
+
message: IncomingMessages<TPlugin>[K];
|
|
90
|
+
user: client.User;
|
|
91
|
+
conversation: client.Conversation;
|
|
92
|
+
event: client.Event;
|
|
93
|
+
states: {
|
|
94
|
+
[TState in keyof TPlugin['states']]: {
|
|
95
|
+
type: 'user' | 'conversation' | 'bot';
|
|
96
|
+
payload: TPlugin['states'][TState];
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export type MessageHandlers<TPlugin extends types.BasePlugin> = {
|
|
102
|
+
[K in keyof IncomingMessages<TPlugin>]: (args: MessagePayloads<TPlugin>[K]) => Promise<void>;
|
|
103
|
+
};
|
|
104
|
+
export type EventPayloads<TPlugin extends types.BasePlugin> = {
|
|
105
|
+
[K in keyof IncomingEvents<TPlugin>]: CommonHandlerProps<TPlugin> & {
|
|
106
|
+
event: IncomingEvents<TPlugin>[K];
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
export type EventHandlers<TPlugin extends types.BasePlugin> = {
|
|
110
|
+
[K in keyof IncomingEvents<TPlugin>]: (args: EventPayloads<TPlugin>[K]) => Promise<void>;
|
|
111
|
+
};
|
|
112
|
+
export type StateExpiredPayloads<TPlugin extends types.BasePlugin> = {
|
|
113
|
+
[K in keyof IncomingStates<TPlugin>]: CommonHandlerProps<TPlugin> & {
|
|
114
|
+
state: IncomingStates<TPlugin>[K];
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
export type StateExpiredHandlers<TPlugin extends types.BasePlugin> = {
|
|
118
|
+
[K in keyof IncomingStates<TPlugin>]: (args: StateExpiredPayloads<TPlugin>[K]) => Promise<void>;
|
|
119
|
+
};
|
|
120
|
+
export type ActionHandlerPayloads<TPlugin extends types.BasePlugin> = {
|
|
121
|
+
[K in keyof TPlugin['actions']]: CommonHandlerProps<TPlugin> & {
|
|
122
|
+
type?: K;
|
|
123
|
+
input: TPlugin['actions'][K]['input'];
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
export type ActionHandlers<TPlugin extends types.BasePlugin> = {
|
|
127
|
+
[K in keyof TPlugin['actions']]: (props: ActionHandlerPayloads<TPlugin>[K]) => Promise<TPlugin['actions'][K]['output']>;
|
|
128
|
+
};
|
|
129
|
+
type BaseHookDefinition = {
|
|
130
|
+
stoppable?: boolean;
|
|
131
|
+
data: any;
|
|
132
|
+
};
|
|
133
|
+
type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> = THookDef;
|
|
134
|
+
/**
|
|
135
|
+
* TODO: add hooks for:
|
|
136
|
+
* - before_register
|
|
137
|
+
* - after_register
|
|
138
|
+
* - before_state_expired
|
|
139
|
+
* - after_state_expired
|
|
140
|
+
* - before_incoming_call_action
|
|
141
|
+
* - after_incoming_call_action
|
|
142
|
+
*/
|
|
143
|
+
export type HookDefinitionType = keyof HookDefinitions<types.BasePlugin>;
|
|
144
|
+
export type HookDefinitions<TPlugin extends types.BasePlugin> = {
|
|
145
|
+
before_incoming_event: HookDefinition<{
|
|
146
|
+
stoppable: true;
|
|
147
|
+
data: _IncomingEvents<TPlugin> & {
|
|
148
|
+
'*': AnyIncomingEvent<TPlugin>;
|
|
149
|
+
};
|
|
150
|
+
}>;
|
|
151
|
+
before_incoming_message: HookDefinition<{
|
|
152
|
+
stoppable: true;
|
|
153
|
+
data: _IncomingMessages<TPlugin> & {
|
|
154
|
+
'*': AnyIncomingMessage<TPlugin>;
|
|
155
|
+
};
|
|
156
|
+
}>;
|
|
157
|
+
before_outgoing_message: HookDefinition<{
|
|
158
|
+
stoppable: false;
|
|
159
|
+
data: _OutgoingMessageRequests<TPlugin> & {
|
|
160
|
+
'*': AnyOutgoingMessageRequest<TPlugin>;
|
|
161
|
+
};
|
|
162
|
+
}>;
|
|
163
|
+
before_outgoing_call_action: HookDefinition<{
|
|
164
|
+
stoppable: false;
|
|
165
|
+
data: _OutgoingCallActionRequests<TPlugin> & {
|
|
166
|
+
'*': AnyOutgoingCallActionRequest<TPlugin>;
|
|
167
|
+
};
|
|
168
|
+
}>;
|
|
169
|
+
after_incoming_event: HookDefinition<{
|
|
170
|
+
stoppable: true;
|
|
171
|
+
data: _IncomingEvents<TPlugin> & {
|
|
172
|
+
'*': AnyIncomingEvent<TPlugin>;
|
|
173
|
+
};
|
|
174
|
+
}>;
|
|
175
|
+
after_incoming_message: HookDefinition<{
|
|
176
|
+
stoppable: true;
|
|
177
|
+
data: _IncomingMessages<TPlugin> & {
|
|
178
|
+
'*': AnyIncomingMessage<TPlugin>;
|
|
179
|
+
};
|
|
180
|
+
}>;
|
|
181
|
+
after_outgoing_message: HookDefinition<{
|
|
182
|
+
stoppable: false;
|
|
183
|
+
data: _OutgoingMessageResponses<TPlugin> & {
|
|
184
|
+
'*': AnyOutgoingMessageResponse<TPlugin>;
|
|
185
|
+
};
|
|
186
|
+
}>;
|
|
187
|
+
after_outgoing_call_action: HookDefinition<{
|
|
188
|
+
stoppable: false;
|
|
189
|
+
data: _OutgoingCallActionResponses<TPlugin> & {
|
|
190
|
+
'*': AnyOutgoingCallActionResponse<TPlugin>;
|
|
191
|
+
};
|
|
192
|
+
}>;
|
|
193
|
+
};
|
|
194
|
+
export type HookData<TPlugin extends types.BasePlugin> = {
|
|
195
|
+
[H in keyof HookDefinitions<TPlugin>]: {
|
|
196
|
+
[T in keyof HookDefinitions<TPlugin>[H]['data']]: HookDefinitions<TPlugin>[H]['data'][T];
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
export type HookInputs<TPlugin extends types.BasePlugin> = {
|
|
200
|
+
[H in keyof HookData<TPlugin>]: {
|
|
201
|
+
[T in keyof HookData<TPlugin>[H]]: CommonHandlerProps<TPlugin> & {
|
|
202
|
+
data: HookData<TPlugin>[H][T];
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
export type HookOutputs<TPlugin extends types.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 ? {
|
|
211
|
+
stop?: boolean;
|
|
212
|
+
} : {});
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
export type HookHandlers<TPlugin extends types.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>;
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
export type MessageHandlersMap<TPlugin extends types.BasePlugin> = {
|
|
221
|
+
[T in keyof IncomingMessages<TPlugin>]?: MessageHandlers<TPlugin>[T][];
|
|
222
|
+
};
|
|
223
|
+
export type EventHandlersMap<TPlugin extends types.BasePlugin> = {
|
|
224
|
+
[T in keyof IncomingEvents<TPlugin>]?: EventHandlers<TPlugin>[T][];
|
|
225
|
+
};
|
|
226
|
+
export type StateExpiredHandlersMap<TPlugin extends types.BasePlugin> = {
|
|
227
|
+
[T in keyof IncomingStates<TPlugin>]?: StateExpiredHandlers<TPlugin>[T][];
|
|
228
|
+
};
|
|
229
|
+
export type HookHandlersMap<TPlugin extends types.BasePlugin> = {
|
|
230
|
+
[H in keyof HookData<TPlugin>]: {
|
|
231
|
+
[T in keyof HookData<TPlugin>[H]]?: HookHandlers<TPlugin>[H][T][];
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
export type PluginHandlers<TPlugin extends types.BasePlugin> = {
|
|
235
|
+
actionHandlers: ActionHandlers<TPlugin>;
|
|
236
|
+
messageHandlers: MessageHandlersMap<TPlugin>;
|
|
237
|
+
eventHandlers: EventHandlersMap<TPlugin>;
|
|
238
|
+
stateExpiredHandlers: StateExpiredHandlersMap<TPlugin>;
|
|
239
|
+
hookHandlers: HookHandlersMap<TPlugin>;
|
|
240
|
+
};
|
|
241
|
+
export {};
|