@botpress/sdk 4.9.0 → 4.11.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 +4 -4
- package/dist/bot/definition.d.ts +19 -7
- package/dist/bot/server/types.d.ts +2 -2
- package/dist/index.cjs +11 -11
- package/dist/index.cjs.map +3 -3
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +3 -3
- package/dist/integration/implementation.d.ts +5 -1
- package/dist/integration/server/types.d.ts +4 -0
- package/dist/plugin/definition.d.ts +90 -23
- package/dist/schema.d.ts +2 -2
- package/dist/zui.d.ts +1 -0
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
2
|
import { BaseIntegration } from './common';
|
|
3
|
-
import { RegisterHandler as RegisterFunction, UnregisterHandler as UnregisterFunction, WebhookHandler as WebhookFunction, CreateUserHandler as CreateUserFunction, CreateConversationHandler as CreateConversationFunction, ActionHandlers as ActionFunctions, ChannelHandlers as ChannelFunctions } from './server';
|
|
3
|
+
import { RegisterHandler as RegisterFunction, UnregisterHandler as UnregisterFunction, WebhookHandler as WebhookFunction, CreateUserHandler as CreateUserFunction, CreateConversationHandler as CreateConversationFunction, ActionHandlers as ActionFunctions, ChannelHandlers as ChannelFunctions, IntegrationOperationHandler as IntegrationOperationFunction } from './server';
|
|
4
4
|
export type IntegrationImplementationProps<TIntegration extends BaseIntegration = BaseIntegration> = {
|
|
5
5
|
register: RegisterFunction<TIntegration>;
|
|
6
6
|
unregister: UnregisterFunction<TIntegration>;
|
|
@@ -15,6 +15,9 @@ export type IntegrationImplementationProps<TIntegration extends BaseIntegration
|
|
|
15
15
|
createConversation?: CreateConversationFunction<TIntegration>;
|
|
16
16
|
actions: ActionFunctions<TIntegration>;
|
|
17
17
|
channels: ChannelFunctions<TIntegration>;
|
|
18
|
+
__advanced?: {
|
|
19
|
+
integrationOperationHandler?: IntegrationOperationFunction<TIntegration>;
|
|
20
|
+
};
|
|
18
21
|
};
|
|
19
22
|
export declare class IntegrationImplementation<TIntegration extends BaseIntegration = BaseIntegration> {
|
|
20
23
|
readonly props: IntegrationImplementationProps<TIntegration>;
|
|
@@ -25,6 +28,7 @@ export declare class IntegrationImplementation<TIntegration extends BaseIntegrat
|
|
|
25
28
|
readonly createUser: IntegrationImplementationProps<TIntegration>['createUser'];
|
|
26
29
|
readonly createConversation: IntegrationImplementationProps<TIntegration>['createConversation'];
|
|
27
30
|
readonly webhook: IntegrationImplementationProps<TIntegration>['handler'];
|
|
31
|
+
readonly integrationOperationHandler: NonNullable<IntegrationImplementationProps<TIntegration>['__advanced']>['integrationOperationHandler'];
|
|
28
32
|
constructor(props: IntegrationImplementationProps<TIntegration>);
|
|
29
33
|
readonly handler: (req: import("../serve").Request) => Promise<import("../serve").Response | void>;
|
|
30
34
|
readonly start: (port?: number) => Promise<Server>;
|
|
@@ -90,6 +90,9 @@ export type ChannelHandlers<TIntegration extends BaseIntegration> = {
|
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
92
|
};
|
|
93
|
+
export type IntegrationOperationHandler<TIntegration extends BaseIntegration> = (props: CommonHandlerProps<TIntegration> & {
|
|
94
|
+
req: Request;
|
|
95
|
+
}) => Promise<Response | void>;
|
|
93
96
|
export type IntegrationHandlers<TIntegration extends BaseIntegration> = {
|
|
94
97
|
register: RegisterHandler<TIntegration>;
|
|
95
98
|
unregister: UnregisterHandler<TIntegration>;
|
|
@@ -98,5 +101,6 @@ export type IntegrationHandlers<TIntegration extends BaseIntegration> = {
|
|
|
98
101
|
createConversation?: CreateConversationHandler<TIntegration>;
|
|
99
102
|
actions: ActionHandlers<TIntegration>;
|
|
100
103
|
channels: ChannelHandlers<TIntegration>;
|
|
104
|
+
integrationOperationHandler?: IntegrationOperationHandler<TIntegration>;
|
|
101
105
|
};
|
|
102
106
|
export {};
|
|
@@ -1,15 +1,61 @@
|
|
|
1
|
-
import { StateDefinition
|
|
1
|
+
import { StateDefinition as BotStateDefinition, EventDefinition as BotEventDefinition, ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, ActionDefinition as BotActionDefinition, TableDefinition as BotTableDefinition, WorkflowDefinition } from '../bot/definition';
|
|
2
2
|
import { IntegrationPackage, InterfacePackage } from '../package';
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import * as typeUtils from '../utils/type-utils';
|
|
4
|
+
import { ZuiObjectSchema, ZuiObjectOrRefSchema, z } from '../zui';
|
|
5
|
+
export { ConfigurationDefinition, UserDefinition, ConversationDefinition, MessageDefinition, IntegrationConfigInstance, WorkflowDefinition, } from '../bot/definition';
|
|
5
6
|
type BaseConfig = ZuiObjectSchema;
|
|
6
|
-
type BaseStates = Record<string,
|
|
7
|
-
type BaseEvents = Record<string,
|
|
8
|
-
type BaseActions = Record<string,
|
|
9
|
-
type BaseInterfaces = Record<string,
|
|
10
|
-
type BaseIntegrations = Record<string,
|
|
11
|
-
type BaseTables = Record<string,
|
|
7
|
+
type BaseStates = Record<string, ZuiObjectOrRefSchema>;
|
|
8
|
+
type BaseEvents = Record<string, ZuiObjectOrRefSchema>;
|
|
9
|
+
type BaseActions = Record<string, ZuiObjectOrRefSchema>;
|
|
10
|
+
type BaseInterfaces = Record<string, InterfacePackage>;
|
|
11
|
+
type BaseIntegrations = Record<string, IntegrationPackage>;
|
|
12
|
+
type BaseTables = Record<string, ZuiObjectOrRefSchema>;
|
|
12
13
|
type BaseWorkflows = Record<string, ZuiObjectSchema>;
|
|
14
|
+
export type TableDefinition<TTable extends BaseTables[string] = BaseTables[string]> = typeUtils.Merge<BotTableDefinition, {
|
|
15
|
+
schema: TTable;
|
|
16
|
+
}>;
|
|
17
|
+
export type StateDefinition<TState extends BaseStates[string] = BaseStates[string]> = typeUtils.Merge<BotStateDefinition, {
|
|
18
|
+
schema: TState;
|
|
19
|
+
}>;
|
|
20
|
+
export type EventDefinition<TEvent extends BaseEvents[string] = BaseEvents[string]> = typeUtils.Merge<BotEventDefinition, {
|
|
21
|
+
schema: TEvent;
|
|
22
|
+
}>;
|
|
23
|
+
export type ActionDefinition<TAction extends BaseActions[string] = BaseActions[string]> = typeUtils.Merge<BotActionDefinition, {
|
|
24
|
+
input: {
|
|
25
|
+
schema: TAction;
|
|
26
|
+
};
|
|
27
|
+
output: {
|
|
28
|
+
schema: ZuiObjectOrRefSchema;
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
export type RecurringEventDefinition<TEvents extends BaseEvents = BaseEvents> = {
|
|
32
|
+
[K in keyof TEvents]: TEvents[K] extends ZuiObjectSchema ? {
|
|
33
|
+
type: K;
|
|
34
|
+
payload: z.infer<TEvents[K]>;
|
|
35
|
+
schedule: {
|
|
36
|
+
cron: string;
|
|
37
|
+
};
|
|
38
|
+
} : never;
|
|
39
|
+
}[keyof TEvents];
|
|
40
|
+
export type ZuiSchemaWithEntityReferences<TInterfaces extends BaseInterfaces, TReturnType extends ZuiObjectOrRefSchema> = ((props: {
|
|
41
|
+
entities: {
|
|
42
|
+
[TInterfaceAlias in keyof TInterfaces]: {
|
|
43
|
+
[TEntityName in keyof TInterfaces[TInterfaceAlias]['definition']['entities']]: z.ZodRef;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}) => TReturnType) | TReturnType;
|
|
47
|
+
type GenericDefinition<TInterfaces extends BaseInterfaces, TDefinition extends {
|
|
48
|
+
schema: ZuiObjectOrRefSchema;
|
|
49
|
+
}> = typeUtils.Merge<TDefinition, {
|
|
50
|
+
schema: ZuiSchemaWithEntityReferences<TInterfaces, TDefinition['schema']>;
|
|
51
|
+
}>;
|
|
52
|
+
type GenericNestedDefinition<TInterfaces extends BaseInterfaces, TDefinition extends {
|
|
53
|
+
[k: string]: any;
|
|
54
|
+
}, TKeys extends string> = Omit<TDefinition, TKeys> & {
|
|
55
|
+
[TKey in TKeys]: Omit<TDefinition[TKey], 'schema'> & {
|
|
56
|
+
schema: ZuiSchemaWithEntityReferences<TInterfaces, TDefinition[TKey]['schema']>;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
13
59
|
export type PluginDefinitionProps<TName extends string = string, TVersion extends string = string, TConfig extends BaseConfig = BaseConfig, TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TInterfaces extends BaseInterfaces = BaseInterfaces, TIntegrations extends BaseIntegrations = BaseIntegrations, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> = {
|
|
14
60
|
name: TName;
|
|
15
61
|
version: TVersion;
|
|
@@ -18,28 +64,24 @@ export type PluginDefinitionProps<TName extends string = string, TVersion extend
|
|
|
18
64
|
icon?: string;
|
|
19
65
|
readme?: string;
|
|
20
66
|
attributes?: Record<string, string>;
|
|
21
|
-
integrations?:
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
interfaces?: {
|
|
25
|
-
[K in keyof TInterfaces]: InterfacePackage;
|
|
26
|
-
};
|
|
67
|
+
integrations?: TIntegrations;
|
|
68
|
+
interfaces?: TInterfaces;
|
|
27
69
|
user?: UserDefinition;
|
|
28
70
|
conversation?: ConversationDefinition;
|
|
29
71
|
message?: MessageDefinition;
|
|
30
72
|
states?: {
|
|
31
|
-
[K in keyof TStates]: StateDefinition<TStates[K]
|
|
73
|
+
[K in keyof TStates]: GenericDefinition<TInterfaces, StateDefinition<TStates[K]>>;
|
|
32
74
|
};
|
|
33
75
|
configuration?: ConfigurationDefinition<TConfig>;
|
|
34
76
|
events?: {
|
|
35
|
-
[K in keyof TEvents]: EventDefinition<TEvents[K]
|
|
77
|
+
[K in keyof TEvents]: GenericDefinition<TInterfaces, EventDefinition<TEvents[K]>>;
|
|
36
78
|
};
|
|
37
79
|
recurringEvents?: Record<string, RecurringEventDefinition<TEvents>>;
|
|
38
80
|
actions?: {
|
|
39
|
-
[K in keyof TActions]: ActionDefinition<TActions[K]>;
|
|
81
|
+
[K in keyof TActions]: GenericNestedDefinition<TInterfaces, ActionDefinition<TActions[K]>, 'input' | 'output'>;
|
|
40
82
|
};
|
|
41
83
|
tables?: {
|
|
42
|
-
[K in keyof TTables]: TableDefinition<TTables[K]
|
|
84
|
+
[K in keyof TTables]: GenericDefinition<TInterfaces, TableDefinition<TTables[K]>>;
|
|
43
85
|
};
|
|
44
86
|
/**
|
|
45
87
|
* # EXPERIMENTAL
|
|
@@ -63,12 +105,37 @@ export declare class PluginDefinition<TName extends string = string, TVersion ex
|
|
|
63
105
|
readonly user: this['props']['user'];
|
|
64
106
|
readonly conversation: this['props']['conversation'];
|
|
65
107
|
readonly message: this['props']['message'];
|
|
66
|
-
readonly states:
|
|
108
|
+
readonly states: {
|
|
109
|
+
[K in keyof TStates]: StateDefinition<TStates[K]>;
|
|
110
|
+
};
|
|
67
111
|
readonly configuration: this['props']['configuration'];
|
|
68
|
-
readonly events:
|
|
112
|
+
readonly events: {
|
|
113
|
+
[K in keyof TEvents]: EventDefinition<TEvents[K]>;
|
|
114
|
+
};
|
|
69
115
|
readonly recurringEvents: this['props']['recurringEvents'];
|
|
70
|
-
readonly actions:
|
|
71
|
-
|
|
116
|
+
readonly actions: {
|
|
117
|
+
[K in keyof TActions]: ActionDefinition<TActions[K]>;
|
|
118
|
+
};
|
|
119
|
+
readonly tables: {
|
|
120
|
+
[K in keyof TTables]: TableDefinition<TTables[K]>;
|
|
121
|
+
};
|
|
72
122
|
readonly workflows: this['props']['workflows'];
|
|
73
123
|
constructor(props: PluginDefinitionProps<TName, TVersion, TConfig, TStates, TEvents, TActions, TInterfaces, TIntegrations, TTables, TWorkflows>);
|
|
124
|
+
/**
|
|
125
|
+
* Returns a copy of the plugin definition where all entity references are
|
|
126
|
+
* resolved to the base entity schema defined by the interface. This does not
|
|
127
|
+
* include any additional properties that may be added to the entity by the
|
|
128
|
+
* backing integration.
|
|
129
|
+
*
|
|
130
|
+
* If `intersectWithUnknownRecord` is `true` (default), the entity schemas
|
|
131
|
+
* will be intersected with `z.record(z.string(), z.unknown())` to make it
|
|
132
|
+
* explicit that the backing integration may have added additional properties.
|
|
133
|
+
*/
|
|
134
|
+
dereferenceEntities({ intersectWithUnknownRecord }?: {
|
|
135
|
+
intersectWithUnknownRecord?: boolean;
|
|
136
|
+
}): this;
|
|
137
|
+
private _buildZuiReferenceMap;
|
|
138
|
+
private _dereferenceZuiSchema;
|
|
139
|
+
private _dereferenceDefinitionSchemas;
|
|
140
|
+
private _dereferenceActionDefinitionSchemas;
|
|
74
141
|
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ type SchemaOptions<T> = {
|
|
|
4
4
|
examples: T[];
|
|
5
5
|
};
|
|
6
6
|
type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
7
|
-
type UiDefinition<TSchema extends z.
|
|
7
|
+
type UiDefinition<TSchema extends z.ZuiObjectOrRefSchema = z.ZuiObjectOrRefSchema> = IsEmptyObject<z.infer<TSchema>> extends true ? Record<string, never> : {
|
|
8
8
|
[K in keyof z.infer<TSchema>]: Partial<SchemaOptions<z.infer<TSchema>[K]>>;
|
|
9
9
|
};
|
|
10
|
-
export type SchemaDefinition<TSchema extends z.
|
|
10
|
+
export type SchemaDefinition<TSchema extends z.ZuiObjectOrRefSchema = z.ZuiObjectOrRefSchema> = {
|
|
11
11
|
schema: TSchema;
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated
|
package/dist/zui.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { z } from '@bpinternal/zui';
|
|
|
2
2
|
export * from '@bpinternal/zui';
|
|
3
3
|
export type GenericZuiSchema<A extends Record<string, z.ZodTypeAny> = Record<string, z.ZodTypeAny>, R extends z.ZodTypeAny = z.ZodTypeAny> = (typeArguments: A) => R;
|
|
4
4
|
export type ZuiObjectSchema = z.ZodObject | z.ZodRecord;
|
|
5
|
+
export type ZuiObjectOrRefSchema = ZuiObjectSchema | z.ZodRef;
|
|
5
6
|
export declare const mergeObjectSchemas: (a: ZuiObjectSchema, b: ZuiObjectSchema) => ZuiObjectSchema;
|
|
6
7
|
export default z;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.11.0",
|
|
4
4
|
"description": "Botpress SDK",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@botpress/client": "1.15.
|
|
19
|
+
"@botpress/client": "1.15.3",
|
|
20
20
|
"browser-or-node": "^2.1.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|