@botpress/sdk 2.0.4 → 2.1.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 +12 -0
- package/dist/base-logger.d.ts +13 -0
- package/dist/bot/bot-logger.d.ts +14 -0
- package/dist/bot/client/index.d.ts +62 -0
- package/dist/bot/client/types.d.ts +141 -0
- package/dist/bot/client/types.test.d.ts +1 -0
- package/dist/bot/definition.d.ts +111 -0
- package/dist/bot/implementation.d.ts +39 -0
- package/dist/bot/index.d.ts +6 -0
- package/dist/bot/merge-bots.d.ts +2 -0
- package/dist/bot/server/context.d.ts +2 -0
- package/dist/bot/server/index.d.ts +5 -0
- package/dist/bot/server/types.d.ts +254 -0
- package/dist/bot/server/types.test.d.ts +1 -0
- package/dist/bot/types/common.d.ts +50 -0
- package/dist/bot/types/common.test.d.ts +1 -0
- package/dist/bot/types/generic.d.ts +31 -0
- package/dist/bot/types/generic.test.d.ts +1 -0
- package/dist/bot/types/index.d.ts +2 -0
- package/dist/const.d.ts +8 -0
- package/dist/fixtures.d.ts +108 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/dist/integration/client/index.d.ts +47 -0
- package/dist/integration/client/types.d.ts +177 -0
- package/dist/integration/client/types.test.d.ts +1 -0
- package/dist/integration/definition/branded-schema.d.ts +21 -0
- package/dist/integration/definition/generic.d.ts +9 -0
- package/dist/integration/definition/index.d.ts +76 -0
- package/dist/integration/definition/types.d.ts +106 -0
- package/dist/integration/implementation.d.ts +31 -0
- package/dist/integration/index.d.ts +5 -0
- package/dist/integration/server/action-metadata.d.ts +9 -0
- package/dist/integration/server/context.d.ts +3 -0
- package/dist/integration/server/index.d.ts +6 -0
- package/dist/integration/server/integration-logger.d.ts +16 -0
- package/dist/integration/server/types.d.ts +102 -0
- package/dist/integration/types/common.d.ts +11 -0
- package/dist/integration/types/generic.d.ts +52 -0
- package/dist/integration/types/generic.test.d.ts +1 -0
- package/dist/integration/types/index.d.ts +2 -0
- package/dist/interface/definition.d.ts +70 -0
- package/dist/interface/index.d.ts +1 -0
- package/dist/interface/types/generic.d.ts +34 -0
- package/dist/interface/types/generic.test.d.ts +1 -0
- package/dist/log.d.ts +7 -0
- package/dist/message.d.ts +474 -0
- package/dist/package.d.ts +58 -0
- package/dist/plugin/definition.d.ts +50 -0
- package/dist/plugin/implementation.d.ts +39 -0
- package/dist/plugin/index.d.ts +3 -0
- package/dist/plugin/server/types.d.ts +1 -0
- package/dist/plugin/server/types.test.d.ts +1 -0
- package/dist/plugin/types/generic.d.ts +30 -0
- package/dist/plugin/types/generic.test.d.ts +1 -0
- package/dist/retry.d.ts +2 -0
- package/dist/schema.d.ts +18 -0
- package/dist/serve.d.ts +20 -0
- package/dist/utils/array-utils.d.ts +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/record-utils.d.ts +3 -0
- package/dist/utils/type-utils.d.ts +33 -0
- package/dist/utils/type-utils.test.d.ts +1 -0
- package/dist/zui.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
> @botpress/sdk@2.1.0 build /home/runner/work/botpress/botpress/packages/sdk
|
|
3
|
+
> pnpm build:type && pnpm build:node
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> @botpress/sdk@2.1.0 build:type /home/runner/work/botpress/botpress/packages/sdk
|
|
7
|
+
> tsc --emitDeclarationOnly --declaration
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
> @botpress/sdk@2.1.0 build:node /home/runner/work/botpress/botpress/packages/sdk
|
|
11
|
+
> ts-node -T build.ts
|
|
12
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare abstract class BaseLogger<TOptions extends object> {
|
|
2
|
+
protected defaultOptions: TOptions;
|
|
3
|
+
protected constructor(defaultOptions: TOptions);
|
|
4
|
+
abstract with(options: TOptions): BaseLogger<TOptions>;
|
|
5
|
+
info(...args: Parameters<typeof console.info>): void;
|
|
6
|
+
debug(...args: Parameters<typeof console.debug>): void;
|
|
7
|
+
warn(...args: Parameters<typeof console.warn>): void;
|
|
8
|
+
error(...args: Parameters<typeof console.error>): void;
|
|
9
|
+
private _log;
|
|
10
|
+
private _serializeMessage;
|
|
11
|
+
protected getJsonMessage(msg: string): string;
|
|
12
|
+
private _getConsoleMethod;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseLogger } from '../base-logger';
|
|
2
|
+
type BotLogOptions = {
|
|
3
|
+
userID?: string;
|
|
4
|
+
conversationID?: string;
|
|
5
|
+
workflowID?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class BotLogger extends BaseLogger<BotLogOptions> {
|
|
8
|
+
constructor(options?: BotLogOptions);
|
|
9
|
+
with(options: BotLogOptions): BotLogger;
|
|
10
|
+
withUserID(userID: string): BotLogger;
|
|
11
|
+
withConversationID(conversationID: string): BotLogger;
|
|
12
|
+
withWorkflowID(workflowID: string): BotLogger;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as client from '@botpress/client';
|
|
2
|
+
import * as common from '../types';
|
|
3
|
+
import * as types from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Just like the regular botpress client, but typed with the bot's properties.
|
|
7
|
+
*/
|
|
8
|
+
export declare class BotSpecificClient<TBot extends common.BaseBot> implements types.ClientOperations<TBot> {
|
|
9
|
+
private _client;
|
|
10
|
+
private _hooks;
|
|
11
|
+
constructor(_client: client.Client, _hooks?: types.ClientHooks);
|
|
12
|
+
getConversation: types.GetConversation<TBot>;
|
|
13
|
+
listConversations: types.ListConversations<TBot>;
|
|
14
|
+
updateConversation: types.UpdateConversation<TBot>;
|
|
15
|
+
deleteConversation: types.DeleteConversation<TBot>;
|
|
16
|
+
listParticipants: types.ListParticipants<TBot>;
|
|
17
|
+
addParticipant: types.AddParticipant<TBot>;
|
|
18
|
+
getParticipant: types.GetParticipant<TBot>;
|
|
19
|
+
removeParticipant: types.RemoveParticipant<TBot>;
|
|
20
|
+
getEvent: types.GetEvent<TBot>;
|
|
21
|
+
listEvents: types.ListEvents<TBot>;
|
|
22
|
+
createMessage: types.CreateMessage<TBot>;
|
|
23
|
+
getOrCreateMessage: types.GetOrCreateMessage<TBot>;
|
|
24
|
+
getMessage: types.GetMessage<TBot>;
|
|
25
|
+
updateMessage: types.UpdateMessage<TBot>;
|
|
26
|
+
listMessages: types.ListMessages<TBot>;
|
|
27
|
+
deleteMessage: types.DeleteMessage<TBot>;
|
|
28
|
+
getUser: types.GetUser<TBot>;
|
|
29
|
+
listUsers: types.ListUsers<TBot>;
|
|
30
|
+
updateUser: types.UpdateUser<TBot>;
|
|
31
|
+
deleteUser: types.DeleteUser<TBot>;
|
|
32
|
+
getState: types.GetState<TBot>;
|
|
33
|
+
setState: types.SetState<TBot>;
|
|
34
|
+
getOrSetState: types.GetOrSetState<TBot>;
|
|
35
|
+
patchState: types.PatchState<TBot>;
|
|
36
|
+
callAction: types.CallAction<TBot>;
|
|
37
|
+
uploadFile: types.UploadFile<TBot>;
|
|
38
|
+
upsertFile: types.UpsertFile<TBot>;
|
|
39
|
+
deleteFile: types.DeleteFile<TBot>;
|
|
40
|
+
listFiles: types.ListFiles<TBot>;
|
|
41
|
+
getFile: types.GetFile<TBot>;
|
|
42
|
+
updateFileMetadata: types.UpdateFileMetadata<TBot>;
|
|
43
|
+
searchFiles: types.SearchFiles<TBot>;
|
|
44
|
+
trackAnalytics: types.TrackAnalytics<TBot>;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use `callAction` to delegate the conversation creation to an integration.
|
|
47
|
+
*/
|
|
48
|
+
createConversation: types.CreateConversation<TBot>;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use `callAction` to delegate the conversation creation to an integration.
|
|
51
|
+
*/
|
|
52
|
+
getOrCreateConversation: types.GetOrCreateConversation<TBot>;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use `callAction` to delegate the user creation to an integration.
|
|
55
|
+
*/
|
|
56
|
+
createUser: types.CreateUser<TBot>;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use `callAction` to delegate the user creation to an integration.
|
|
59
|
+
*/
|
|
60
|
+
getOrCreateUser: types.GetOrCreateUser<TBot>;
|
|
61
|
+
private _run;
|
|
62
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import * as client from '@botpress/client';
|
|
2
|
+
import * as utils from '../../utils/type-utils';
|
|
3
|
+
import * as common from '../types';
|
|
4
|
+
type Arg<F extends (...args: any[]) => any> = Parameters<F>[number];
|
|
5
|
+
type Res<F extends (...args: any[]) => any> = ReturnType<F>;
|
|
6
|
+
type EventResponse<TBot extends common.BaseBot> = {
|
|
7
|
+
event: {
|
|
8
|
+
[K in keyof common.EnumerateEvents<TBot>]: utils.Merge<client.Event, {
|
|
9
|
+
type: K;
|
|
10
|
+
payload: common.EnumerateEvents<TBot>[K];
|
|
11
|
+
}>;
|
|
12
|
+
}[keyof common.EnumerateEvents<TBot>];
|
|
13
|
+
};
|
|
14
|
+
type MessageResponse<TBot extends common.BaseBot, TMessage extends keyof common.GetMessages<TBot> = keyof common.GetMessages<TBot>> = {
|
|
15
|
+
message: utils.ValueOf<{
|
|
16
|
+
[K in keyof common.GetMessages<TBot> as K extends TMessage ? K : never]: utils.Merge<client.Message, {
|
|
17
|
+
type: K;
|
|
18
|
+
payload: common.GetMessages<TBot>[K];
|
|
19
|
+
}>;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
type StateResponse<TBot extends common.BaseBot, TState extends keyof TBot['states'] = keyof TBot['states']> = utils.Merge<Awaited<Res<client.Client['getState']>>, {
|
|
23
|
+
state: utils.Merge<Awaited<Res<client.Client['getState']>>['state'], {
|
|
24
|
+
payload: TBot['states'][TState];
|
|
25
|
+
}>;
|
|
26
|
+
}>;
|
|
27
|
+
export type CreateConversation<_TBot extends common.BaseBot> = client.Client['createConversation'];
|
|
28
|
+
export type GetConversation<_TBot extends common.BaseBot> = client.Client['getConversation'];
|
|
29
|
+
export type ListConversations<_TBot extends common.BaseBot> = client.Client['listConversations'];
|
|
30
|
+
export type GetOrCreateConversation<_TBot extends common.BaseBot> = client.Client['getOrCreateConversation'];
|
|
31
|
+
export type UpdateConversation<_TBot extends common.BaseBot> = client.Client['updateConversation'];
|
|
32
|
+
export type DeleteConversation<_TBot extends common.BaseBot> = client.Client['deleteConversation'];
|
|
33
|
+
export type ListParticipants<_TBot extends common.BaseBot> = client.Client['listParticipants'];
|
|
34
|
+
export type AddParticipant<_TBot extends common.BaseBot> = client.Client['addParticipant'];
|
|
35
|
+
export type GetParticipant<_TBot extends common.BaseBot> = client.Client['getParticipant'];
|
|
36
|
+
export type RemoveParticipant<_TBot extends common.BaseBot> = client.Client['removeParticipant'];
|
|
37
|
+
export type GetEvent<TBot extends common.BaseBot> = (x: Arg<client.Client['getEvent']>) => Promise<EventResponse<TBot>>;
|
|
38
|
+
export type ListEvents<_TBot extends common.BaseBot> = client.Client['listEvents'];
|
|
39
|
+
export type CreateMessage<TBot extends common.BaseBot> = <TMessage extends keyof common.GetMessages<TBot>>(x: utils.Merge<Arg<client.Client['createMessage']>, {
|
|
40
|
+
type: utils.Cast<TMessage, string>;
|
|
41
|
+
payload: utils.Cast<common.GetMessages<TBot>[TMessage], Record<string, any>>;
|
|
42
|
+
}>) => Promise<MessageResponse<TBot, TMessage>>;
|
|
43
|
+
export type GetOrCreateMessage<TBot extends common.BaseBot> = <TMessage extends keyof common.GetMessages<TBot>>(x: utils.Merge<Arg<client.Client['getOrCreateMessage']>, {
|
|
44
|
+
type: utils.Cast<TMessage, string>;
|
|
45
|
+
payload: utils.Cast<common.GetMessages<TBot>[TMessage], Record<string, any>>;
|
|
46
|
+
}>) => Promise<MessageResponse<TBot, TMessage>>;
|
|
47
|
+
export type GetMessage<TBot extends common.BaseBot> = (x: Arg<client.Client['getMessage']>) => Promise<MessageResponse<TBot>>;
|
|
48
|
+
export type UpdateMessage<TBot extends common.BaseBot> = (x: Arg<client.Client['updateMessage']>) => Promise<MessageResponse<TBot>>;
|
|
49
|
+
export type ListMessages<_TBot extends common.BaseBot> = client.Client['listMessages'];
|
|
50
|
+
export type DeleteMessage<_TBot extends common.BaseBot> = client.Client['deleteMessage'];
|
|
51
|
+
export type CreateUser<_TBot extends common.BaseBot> = client.Client['createUser'];
|
|
52
|
+
export type GetUser<_TBot extends common.BaseBot> = client.Client['getUser'];
|
|
53
|
+
export type ListUsers<_TBot extends common.BaseBot> = client.Client['listUsers'];
|
|
54
|
+
export type GetOrCreateUser<_TBot extends common.BaseBot> = client.Client['getOrCreateUser'];
|
|
55
|
+
export type UpdateUser<_TBot extends common.BaseBot> = client.Client['updateUser'];
|
|
56
|
+
export type DeleteUser<_TBot extends common.BaseBot> = client.Client['deleteUser'];
|
|
57
|
+
export type GetState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['getState']>, {
|
|
58
|
+
name: utils.Cast<TState, string>;
|
|
59
|
+
}>) => Promise<StateResponse<TBot, TState>>;
|
|
60
|
+
export type SetState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['setState']>, {
|
|
61
|
+
name: utils.Cast<TState, string>;
|
|
62
|
+
payload: TBot['states'][TState] | null;
|
|
63
|
+
}>) => Promise<StateResponse<TBot, TState>>;
|
|
64
|
+
export type GetOrSetState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['getOrSetState']>, {
|
|
65
|
+
name: utils.Cast<TState, string>;
|
|
66
|
+
payload: TBot['states'][TState];
|
|
67
|
+
}>) => Promise<StateResponse<TBot, TState>>;
|
|
68
|
+
export type PatchState<TBot extends common.BaseBot> = <TState extends keyof TBot['states']>(x: utils.Merge<Arg<client.Client['patchState']>, {
|
|
69
|
+
name: utils.Cast<TState, string>;
|
|
70
|
+
payload: Partial<TBot['states'][TState]>;
|
|
71
|
+
}>) => Promise<{
|
|
72
|
+
state: utils.Merge<Awaited<Res<client.Client['patchState']>>['state'], {
|
|
73
|
+
payload: TBot['states'][TState];
|
|
74
|
+
}>;
|
|
75
|
+
}>;
|
|
76
|
+
export type CallAction<TBot extends common.BaseBot> = <ActionType extends keyof common.EnumerateActions<TBot>>(x: utils.Merge<Arg<client.Client['callAction']>, {
|
|
77
|
+
type: utils.Cast<ActionType, string>;
|
|
78
|
+
input: utils.Cast<common.EnumerateActions<TBot>[ActionType], common.IntegrationInstanceActionDefinition>['input'];
|
|
79
|
+
}>) => Promise<utils.Merge<Awaited<Res<client.Client['callAction']>>, {
|
|
80
|
+
output: utils.Cast<common.EnumerateActions<TBot>[ActionType], common.IntegrationInstanceActionDefinition>['output'];
|
|
81
|
+
}>>;
|
|
82
|
+
export type UploadFile<_TBot extends common.BaseBot> = client.Client['uploadFile'];
|
|
83
|
+
export type UpsertFile<_TBot extends common.BaseBot> = client.Client['upsertFile'];
|
|
84
|
+
export type DeleteFile<_TBot extends common.BaseBot> = client.Client['deleteFile'];
|
|
85
|
+
export type ListFiles<_TBot extends common.BaseBot> = client.Client['listFiles'];
|
|
86
|
+
export type GetFile<_TBot extends common.BaseBot> = client.Client['getFile'];
|
|
87
|
+
export type UpdateFileMetadata<_TBot extends common.BaseBot> = client.Client['updateFileMetadata'];
|
|
88
|
+
export type SearchFiles<_TBot extends common.BaseBot> = client.Client['searchFiles'];
|
|
89
|
+
export type TrackAnalytics<_TBot extends common.BaseBot> = client.Client['trackAnalytics'];
|
|
90
|
+
export type ClientOperations<TBot extends common.BaseBot> = {
|
|
91
|
+
getConversation: GetConversation<TBot>;
|
|
92
|
+
listConversations: ListConversations<TBot>;
|
|
93
|
+
updateConversation: UpdateConversation<TBot>;
|
|
94
|
+
deleteConversation: DeleteConversation<TBot>;
|
|
95
|
+
listParticipants: ListParticipants<TBot>;
|
|
96
|
+
addParticipant: AddParticipant<TBot>;
|
|
97
|
+
getParticipant: GetParticipant<TBot>;
|
|
98
|
+
removeParticipant: RemoveParticipant<TBot>;
|
|
99
|
+
getEvent: GetEvent<TBot>;
|
|
100
|
+
listEvents: ListEvents<TBot>;
|
|
101
|
+
createMessage: CreateMessage<TBot>;
|
|
102
|
+
getOrCreateMessage: GetOrCreateMessage<TBot>;
|
|
103
|
+
getMessage: GetMessage<TBot>;
|
|
104
|
+
updateMessage: UpdateMessage<TBot>;
|
|
105
|
+
listMessages: ListMessages<TBot>;
|
|
106
|
+
deleteMessage: DeleteMessage<TBot>;
|
|
107
|
+
getUser: GetUser<TBot>;
|
|
108
|
+
listUsers: ListUsers<TBot>;
|
|
109
|
+
updateUser: UpdateUser<TBot>;
|
|
110
|
+
deleteUser: DeleteUser<TBot>;
|
|
111
|
+
getState: GetState<TBot>;
|
|
112
|
+
setState: SetState<TBot>;
|
|
113
|
+
getOrSetState: GetOrSetState<TBot>;
|
|
114
|
+
patchState: PatchState<TBot>;
|
|
115
|
+
callAction: CallAction<TBot>;
|
|
116
|
+
uploadFile: UploadFile<TBot>;
|
|
117
|
+
upsertFile: UpsertFile<TBot>;
|
|
118
|
+
deleteFile: DeleteFile<TBot>;
|
|
119
|
+
listFiles: ListFiles<TBot>;
|
|
120
|
+
getFile: GetFile<TBot>;
|
|
121
|
+
updateFileMetadata: UpdateFileMetadata<TBot>;
|
|
122
|
+
searchFiles: SearchFiles<TBot>;
|
|
123
|
+
trackAnalytics: TrackAnalytics<TBot>;
|
|
124
|
+
};
|
|
125
|
+
export type ClientInputs<TBot extends common.BaseBot> = {
|
|
126
|
+
[K in keyof ClientOperations<TBot>]: Arg<ClientOperations<TBot>[K]>;
|
|
127
|
+
};
|
|
128
|
+
export type ClientOutputs<TBot extends common.BaseBot> = {
|
|
129
|
+
[K in keyof ClientOperations<TBot>]: Awaited<Res<ClientOperations<TBot>[K]>>;
|
|
130
|
+
};
|
|
131
|
+
type ClientHooksBefore = {
|
|
132
|
+
[K in client.Operation]?: (x: client.ClientInputs[K]) => Promise<client.ClientInputs[K]>;
|
|
133
|
+
};
|
|
134
|
+
type ClientHooksAfter = {
|
|
135
|
+
[K in client.Operation]?: (x: client.ClientOutputs[K]) => Promise<client.ClientOutputs[K]>;
|
|
136
|
+
};
|
|
137
|
+
export type ClientHooks = {
|
|
138
|
+
before: ClientHooksBefore;
|
|
139
|
+
after: ClientHooksAfter;
|
|
140
|
+
};
|
|
141
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { IntegrationPackage, PluginPackage } from '../package';
|
|
2
|
+
import { SchemaDefinition } from '../schema';
|
|
3
|
+
import { ValueOf } from '../utils/type-utils';
|
|
4
|
+
import z, { ZuiObjectSchema } from '../zui';
|
|
5
|
+
type BaseConfig = ZuiObjectSchema;
|
|
6
|
+
type BaseStates = Record<string, ZuiObjectSchema>;
|
|
7
|
+
type BaseEvents = Record<string, ZuiObjectSchema>;
|
|
8
|
+
type BaseActions = Record<string, ZuiObjectSchema>;
|
|
9
|
+
export type TagDefinition = {
|
|
10
|
+
title?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
};
|
|
13
|
+
export type StateType = 'conversation' | 'user' | 'bot';
|
|
14
|
+
export type StateDefinition<TState extends BaseStates[string] = BaseStates[string]> = SchemaDefinition<TState> & {
|
|
15
|
+
type: StateType;
|
|
16
|
+
expiry?: number;
|
|
17
|
+
};
|
|
18
|
+
export type RecurringEventDefinition<TEvents extends BaseEvents = BaseEvents> = {
|
|
19
|
+
[K in keyof TEvents]: {
|
|
20
|
+
type: K;
|
|
21
|
+
payload: z.infer<TEvents[K]>;
|
|
22
|
+
schedule: {
|
|
23
|
+
cron: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}[keyof TEvents];
|
|
27
|
+
export type EventDefinition<TEvent extends BaseEvents[string] = BaseEvents[string]> = SchemaDefinition<TEvent>;
|
|
28
|
+
export type ConfigurationDefinition<TConfig extends BaseConfig = BaseConfig> = SchemaDefinition<TConfig>;
|
|
29
|
+
export type UserDefinition = {
|
|
30
|
+
tags?: Record<string, TagDefinition>;
|
|
31
|
+
};
|
|
32
|
+
export type ConversationDefinition = {
|
|
33
|
+
tags?: Record<string, TagDefinition>;
|
|
34
|
+
};
|
|
35
|
+
export type MessageDefinition = {
|
|
36
|
+
tags?: Record<string, TagDefinition>;
|
|
37
|
+
};
|
|
38
|
+
export type ActionDefinition<TAction extends BaseActions[string] = BaseActions[string]> = {
|
|
39
|
+
title?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
input: SchemaDefinition<TAction>;
|
|
42
|
+
output: SchemaDefinition<ZuiObjectSchema>;
|
|
43
|
+
};
|
|
44
|
+
export type IntegrationConfigInstance<I extends IntegrationPackage = IntegrationPackage> = {
|
|
45
|
+
enabled: boolean;
|
|
46
|
+
} & ({
|
|
47
|
+
configurationType?: null;
|
|
48
|
+
configuration: z.infer<NonNullable<I['definition']['configuration']>['schema']>;
|
|
49
|
+
} | ValueOf<{
|
|
50
|
+
[K in keyof NonNullable<I['definition']['configurations']>]: {
|
|
51
|
+
configurationType: K;
|
|
52
|
+
configuration: z.infer<NonNullable<I['definition']['configurations']>[K]['schema']>;
|
|
53
|
+
};
|
|
54
|
+
}>);
|
|
55
|
+
export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
|
|
56
|
+
configuration: z.infer<NonNullable<P['definition']['configuration']>['schema']>;
|
|
57
|
+
interfaces: {
|
|
58
|
+
[I in keyof NonNullable<P['definition']['interfaces']>]: {
|
|
59
|
+
name: string;
|
|
60
|
+
version: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export type IntegrationInstance = IntegrationPackage & IntegrationConfigInstance;
|
|
65
|
+
export type PluginInstance = PluginPackage & PluginConfigInstance;
|
|
66
|
+
export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions> = {
|
|
67
|
+
integrations?: {
|
|
68
|
+
[K: string]: IntegrationInstance;
|
|
69
|
+
};
|
|
70
|
+
plugins?: {
|
|
71
|
+
[K: string]: PluginInstance;
|
|
72
|
+
};
|
|
73
|
+
user?: UserDefinition;
|
|
74
|
+
conversation?: ConversationDefinition;
|
|
75
|
+
message?: MessageDefinition;
|
|
76
|
+
states?: {
|
|
77
|
+
[K in keyof TStates]: StateDefinition<TStates[K]>;
|
|
78
|
+
};
|
|
79
|
+
configuration?: ConfigurationDefinition;
|
|
80
|
+
events?: {
|
|
81
|
+
[K in keyof TEvents]: EventDefinition<TEvents[K]>;
|
|
82
|
+
};
|
|
83
|
+
recurringEvents?: Record<string, RecurringEventDefinition<TEvents>>;
|
|
84
|
+
actions?: {
|
|
85
|
+
[K in keyof TActions]: ActionDefinition<TActions[K]>;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions> {
|
|
89
|
+
readonly props: BotDefinitionProps<TStates, TEvents, TActions>;
|
|
90
|
+
readonly integrations: this['props']['integrations'];
|
|
91
|
+
readonly plugins: this['props']['plugins'];
|
|
92
|
+
readonly user: this['props']['user'];
|
|
93
|
+
readonly conversation: this['props']['conversation'];
|
|
94
|
+
readonly message: this['props']['message'];
|
|
95
|
+
readonly states: this['props']['states'];
|
|
96
|
+
readonly configuration: this['props']['configuration'];
|
|
97
|
+
readonly events: this['props']['events'];
|
|
98
|
+
readonly recurringEvents: this['props']['recurringEvents'];
|
|
99
|
+
readonly actions: this['props']['actions'];
|
|
100
|
+
constructor(props: BotDefinitionProps<TStates, TEvents, TActions>);
|
|
101
|
+
addIntegration<I extends IntegrationPackage>(integrationPkg: I, config: IntegrationConfigInstance<I>): this;
|
|
102
|
+
addPlugin<P extends PluginPackage>(pluginPkg: P, config: PluginConfigInstance<P>): this;
|
|
103
|
+
private _mergeUser;
|
|
104
|
+
private _mergeConversation;
|
|
105
|
+
private _mergeMessage;
|
|
106
|
+
private _mergeStates;
|
|
107
|
+
private _mergeEvents;
|
|
108
|
+
private _mergeRecurringEvents;
|
|
109
|
+
private _mergeActions;
|
|
110
|
+
}
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Server } from 'node:http';
|
|
2
|
+
import { BasePlugin, PluginImplementation } from '../plugin';
|
|
3
|
+
import { MessageHandlersMap, MessageHandlers, EventHandlersMap, EventHandlers, StateExpiredHandlersMap, StateExpiredHandlers, HookHandlersMap, HookData, HookHandlers, ActionHandlers, BotHandlers, UnimplementedActionHandlers } from './server';
|
|
4
|
+
import { BaseBot } from './types';
|
|
5
|
+
export type BotImplementationProps<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> = {
|
|
6
|
+
actions: UnimplementedActionHandlers<TBot, TPlugins>;
|
|
7
|
+
plugins: {
|
|
8
|
+
[K in keyof TPlugins]: PluginImplementation<TPlugins[K]>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> implements BotHandlers<TBot> {
|
|
12
|
+
readonly props: BotImplementationProps<TBot, TPlugins>;
|
|
13
|
+
readonly actionHandlers: ActionHandlers<TBot>;
|
|
14
|
+
readonly messageHandlers: MessageHandlersMap<TBot>;
|
|
15
|
+
readonly eventHandlers: EventHandlersMap<TBot>;
|
|
16
|
+
readonly stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
|
|
17
|
+
readonly hookHandlers: HookHandlersMap<TBot>;
|
|
18
|
+
/**
|
|
19
|
+
* alias for actionHandlers
|
|
20
|
+
*/
|
|
21
|
+
get actions(): ActionHandlers<TBot>;
|
|
22
|
+
constructor(props: BotImplementationProps<TBot, TPlugins>);
|
|
23
|
+
readonly on: {
|
|
24
|
+
message: <T extends keyof MessageHandlersMap<TBot>>(type: T, handler: MessageHandlers<TBot>[T]) => void;
|
|
25
|
+
event: <T extends keyof EventHandlersMap<TBot>>(type: T, handler: EventHandlers<TBot>[T]) => void;
|
|
26
|
+
stateExpired: <T extends keyof StateExpiredHandlersMap<TBot>>(type: T, handler: StateExpiredHandlers<TBot>[T]) => void;
|
|
27
|
+
beforeIncomingEvent: <T extends keyof HookData<TBot>["before_incoming_event"]>(type: T, handler: HookHandlers<TBot>["before_incoming_event"][T]) => void;
|
|
28
|
+
beforeIncomingMessage: <T extends keyof HookData<TBot>["before_incoming_message"]>(type: T, handler: HookHandlers<TBot>["before_incoming_message"][T]) => void;
|
|
29
|
+
beforeOutgoingMessage: <T extends keyof HookData<TBot>["before_outgoing_message"]>(type: T, handler: HookHandlers<TBot>["before_outgoing_message"][T]) => void;
|
|
30
|
+
beforeOutgoingCallAction: <T extends keyof HookData<TBot>["before_outgoing_call_action"]>(type: T, handler: HookHandlers<TBot>["before_outgoing_call_action"][T]) => void;
|
|
31
|
+
afterIncomingEvent: <T extends keyof HookData<TBot>["after_incoming_event"]>(type: T, handler: HookHandlers<TBot>["after_incoming_event"][T]) => void;
|
|
32
|
+
afterIncomingMessage: <T extends keyof HookData<TBot>["after_incoming_message"]>(type: T, handler: HookHandlers<TBot>["after_incoming_message"][T]) => void;
|
|
33
|
+
afterOutgoingMessage: <T extends keyof HookData<TBot>["after_outgoing_message"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_message"][T]) => void;
|
|
34
|
+
afterOutgoingCallAction: <T extends keyof HookData<TBot>["after_outgoing_call_action"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_call_action"][T]) => void;
|
|
35
|
+
};
|
|
36
|
+
private readonly _use;
|
|
37
|
+
readonly handler: (req: import("../serve").Request) => Promise<import("../serve").Response | void>;
|
|
38
|
+
readonly start: (port?: number) => Promise<Server>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Request, Response } from '../../serve';
|
|
2
|
+
import * as common from '../types';
|
|
3
|
+
import * as types from './types';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export declare const botHandler: (bot: types.BotHandlers<common.BaseBot>) => (req: Request) => Promise<Response | void>;
|