@holocronlab/botruntime-sdk 6.13.3

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.
Files changed (126) hide show
  1. package/LICENSE +8 -0
  2. package/dist/base-logger.d.ts +34 -0
  3. package/dist/base-logger.test.d.ts +1 -0
  4. package/dist/bot/bot-logger.d.ts +18 -0
  5. package/dist/bot/client/index.d.ts +80 -0
  6. package/dist/bot/client/types.d.ts +254 -0
  7. package/dist/bot/client/types.test.d.ts +1 -0
  8. package/dist/bot/common/generic.d.ts +41 -0
  9. package/dist/bot/common/generic.test.d.ts +1 -0
  10. package/dist/bot/common/index.d.ts +2 -0
  11. package/dist/bot/common/types.d.ts +54 -0
  12. package/dist/bot/common/types.test.d.ts +1 -0
  13. package/dist/bot/definition.d.ts +214 -0
  14. package/dist/bot/definition.test.d.ts +1 -0
  15. package/dist/bot/implementation.d.ts +72 -0
  16. package/dist/bot/implementation.test.d.ts +1 -0
  17. package/dist/bot/index.d.ts +6 -0
  18. package/dist/bot/server/context.d.ts +2 -0
  19. package/dist/bot/server/index.d.ts +5 -0
  20. package/dist/bot/server/responses.d.ts +3 -0
  21. package/dist/bot/server/types.d.ts +423 -0
  22. package/dist/bot/server/types.test.d.ts +1 -0
  23. package/dist/bot/server/workflows/update-handler.d.ts +3 -0
  24. package/dist/bot/server/workflows/update-type-conv.d.ts +2 -0
  25. package/dist/bot/workflow-proxy/index.d.ts +2 -0
  26. package/dist/bot/workflow-proxy/proxy.d.ts +17 -0
  27. package/dist/bot/workflow-proxy/types.d.ts +80 -0
  28. package/dist/bot/workflow-proxy/types.test.d.ts +1 -0
  29. package/dist/common/index.d.ts +1 -0
  30. package/dist/common/recurring-events.d.ts +9 -0
  31. package/dist/common/recurring-events.test.d.ts +1 -0
  32. package/dist/common/types.d.ts +8 -0
  33. package/dist/consts.d.ts +11 -0
  34. package/dist/errors.d.ts +19 -0
  35. package/dist/fixtures.d.ts +357 -0
  36. package/dist/index.cjs +5 -0
  37. package/dist/index.cjs.map +7 -0
  38. package/dist/index.d.ts +17 -0
  39. package/dist/index.mjs +34 -0
  40. package/dist/index.mjs.map +7 -0
  41. package/dist/integration/client/index.d.ts +55 -0
  42. package/dist/integration/client/sub-types.d.ts +27 -0
  43. package/dist/integration/client/sub-types.test.d.ts +1 -0
  44. package/dist/integration/client/types.d.ts +209 -0
  45. package/dist/integration/client/types.test.d.ts +1 -0
  46. package/dist/integration/common/generic.d.ts +57 -0
  47. package/dist/integration/common/generic.test.d.ts +1 -0
  48. package/dist/integration/common/index.d.ts +1 -0
  49. package/dist/integration/definition/branded-schema.d.ts +21 -0
  50. package/dist/integration/definition/definition.test.d.ts +1 -0
  51. package/dist/integration/definition/generic.d.ts +9 -0
  52. package/dist/integration/definition/index.d.ts +130 -0
  53. package/dist/integration/definition/types.d.ts +119 -0
  54. package/dist/integration/implementation.d.ts +37 -0
  55. package/dist/integration/index.d.ts +5 -0
  56. package/dist/integration/server/action-metadata.d.ts +9 -0
  57. package/dist/integration/server/context.d.ts +4 -0
  58. package/dist/integration/server/index.d.ts +6 -0
  59. package/dist/integration/server/integration-logger.d.ts +36 -0
  60. package/dist/integration/server/types.d.ts +108 -0
  61. package/dist/interface/common/generic.d.ts +34 -0
  62. package/dist/interface/common/generic.test.d.ts +1 -0
  63. package/dist/interface/common/index.d.ts +1 -0
  64. package/dist/interface/definition.d.ts +87 -0
  65. package/dist/interface/index.d.ts +2 -0
  66. package/dist/interface/resolve.d.ts +18 -0
  67. package/dist/log.d.ts +7 -0
  68. package/dist/message.d.ts +742 -0
  69. package/dist/package.d.ts +64 -0
  70. package/dist/plugin/action-proxy/index.d.ts +2 -0
  71. package/dist/plugin/action-proxy/proxy.d.ts +5 -0
  72. package/dist/plugin/action-proxy/types.d.ts +14 -0
  73. package/dist/plugin/action-proxy/types.test.d.ts +1 -0
  74. package/dist/plugin/common/generic.d.ts +63 -0
  75. package/dist/plugin/common/generic.test.d.ts +1 -0
  76. package/dist/plugin/common/index.d.ts +2 -0
  77. package/dist/plugin/common/types.d.ts +59 -0
  78. package/dist/plugin/conversation-proxy/index.d.ts +2 -0
  79. package/dist/plugin/conversation-proxy/proxy.d.ts +13 -0
  80. package/dist/plugin/conversation-proxy/types.d.ts +54 -0
  81. package/dist/plugin/conversation-proxy/types.test.d.ts +1 -0
  82. package/dist/plugin/definition.d.ts +152 -0
  83. package/dist/plugin/definition.test.d.ts +1 -0
  84. package/dist/plugin/event-proxy/index.d.ts +2 -0
  85. package/dist/plugin/event-proxy/proxy.d.ts +5 -0
  86. package/dist/plugin/event-proxy/types.d.ts +19 -0
  87. package/dist/plugin/event-proxy/types.test.d.ts +1 -0
  88. package/dist/plugin/implementation.d.ts +71 -0
  89. package/dist/plugin/implementation.test.d.ts +1 -0
  90. package/dist/plugin/index.d.ts +4 -0
  91. package/dist/plugin/message-proxy/index.d.ts +2 -0
  92. package/dist/plugin/message-proxy/proxy.d.ts +13 -0
  93. package/dist/plugin/message-proxy/types.d.ts +22 -0
  94. package/dist/plugin/server/index.d.ts +1 -0
  95. package/dist/plugin/server/types.d.ts +505 -0
  96. package/dist/plugin/server/types.test.d.ts +1 -0
  97. package/dist/plugin/state-proxy/index.d.ts +2 -0
  98. package/dist/plugin/state-proxy/proxy.d.ts +5 -0
  99. package/dist/plugin/state-proxy/types.d.ts +29 -0
  100. package/dist/plugin/state-proxy/types.test.d.ts +1 -0
  101. package/dist/plugin/tag-prefixer.d.ts +10 -0
  102. package/dist/plugin/tag-prefixer.test.d.ts +1 -0
  103. package/dist/plugin/user-proxy/index.d.ts +2 -0
  104. package/dist/plugin/user-proxy/proxy.d.ts +14 -0
  105. package/dist/plugin/user-proxy/types.d.ts +30 -0
  106. package/dist/public-consts.d.ts +9 -0
  107. package/dist/retry.d.ts +2 -0
  108. package/dist/retry.test.d.ts +1 -0
  109. package/dist/schema.d.ts +18 -0
  110. package/dist/serve.d.ts +38 -0
  111. package/dist/utils/api-paging-utils.d.ts +43 -0
  112. package/dist/utils/api-paging-utils.test.d.ts +1 -0
  113. package/dist/utils/array-utils.d.ts +2 -0
  114. package/dist/utils/error-utils.d.ts +4 -0
  115. package/dist/utils/function-utils.d.ts +2 -0
  116. package/dist/utils/function-utils.test.d.ts +1 -0
  117. package/dist/utils/index.d.ts +4 -0
  118. package/dist/utils/record-utils.d.ts +6 -0
  119. package/dist/utils/record-utils.test.d.ts +1 -0
  120. package/dist/utils/type-utils.d.ts +63 -0
  121. package/dist/utils/type-utils.test.d.ts +1 -0
  122. package/dist/version-utils.d.ts +18 -0
  123. package/dist/version.d.ts +1 -0
  124. package/dist/zui.d.ts +9 -0
  125. package/package.json +59 -0
  126. package/readme.md +11 -0
@@ -0,0 +1,505 @@
1
+ import * as client from '@holocronlab/botruntime-client';
2
+ import * as bot from '../../bot';
3
+ import * as workflowProxy from '../../bot/workflow-proxy';
4
+ import * as utils from '../../utils/type-utils';
5
+ import * as actionProxy from '../action-proxy';
6
+ import * as common from '../common';
7
+ import * as conversationProxy from '../conversation-proxy';
8
+ import * as eventProxy from '../event-proxy';
9
+ import * as messageProxy from '../message-proxy';
10
+ import * as stateProxy from '../state-proxy';
11
+ import * as userProxy from '../user-proxy';
12
+ type EnumeratePluginEvents<TPlugin extends common.BasePlugin> = bot.EnumerateEvents<TPlugin> & common.EnumerateInterfaceEvents<TPlugin>;
13
+ type _IncomingEvents<TPlugin extends common.BasePlugin> = {
14
+ [K in utils.StringKeys<EnumeratePluginEvents<TPlugin>>]: utils.Merge<client.Event, {
15
+ type: K;
16
+ payload: EnumeratePluginEvents<TPlugin>[K];
17
+ }>;
18
+ };
19
+ type _IncomingMessages<TPlugin extends common.BasePlugin> = {
20
+ [K in utils.StringKeys<bot.GetMessages<TPlugin>>]: utils.Merge<client.Message, {
21
+ type: Extract<K, string>;
22
+ payload: bot.GetMessages<TPlugin>[K];
23
+ }>;
24
+ };
25
+ type _IncomingStates<TPlugin extends common.BasePlugin> = {
26
+ [K in utils.StringKeys<bot.EnumerateStates<TPlugin>>]: utils.Merge<client.State, {
27
+ name: K;
28
+ payload: bot.EnumerateStates<TPlugin>[K];
29
+ }>;
30
+ };
31
+ type _OutgoingMessageRequests<TPlugin extends common.BasePlugin> = {
32
+ [K in utils.StringKeys<bot.GetMessages<TPlugin>>]: utils.Merge<client.ClientInputs['createMessage'], {
33
+ type: K;
34
+ payload: bot.GetMessages<TPlugin>[K];
35
+ }>;
36
+ };
37
+ type _OutgoingMessageResponses<TPlugin extends common.BasePlugin> = {
38
+ [K in utils.StringKeys<bot.GetMessages<TPlugin>>]: utils.Merge<client.ClientOutputs['createMessage'], {
39
+ message: utils.Merge<client.Message, {
40
+ type: K;
41
+ payload: bot.GetMessages<TPlugin>[K];
42
+ }>;
43
+ }>;
44
+ };
45
+ type _OutgoingCallActionRequests<TPlugin extends common.BasePlugin> = {
46
+ [K in utils.StringKeys<bot.EnumerateActionInputs<TPlugin>>]: utils.Merge<client.ClientInputs['callAction'], {
47
+ type: K;
48
+ input: bot.EnumerateActionInputs<TPlugin>[K];
49
+ }>;
50
+ };
51
+ type _OutgoingCallActionResponses<TPlugin extends common.BasePlugin> = {
52
+ [K in utils.StringKeys<bot.EnumerateActionOutputs<TPlugin>>]: utils.Merge<client.ClientOutputs['callAction'], {
53
+ type: K;
54
+ output: bot.EnumerateActionOutputs<TPlugin>[K];
55
+ }>;
56
+ };
57
+ type _IncomingCallActionRequests<TPlugin extends common.BasePlugin> = {
58
+ [K in utils.StringKeys<TPlugin['actions']>]: {
59
+ type: K;
60
+ input: TPlugin['actions'][K]['input'];
61
+ };
62
+ };
63
+ type _IncomingCallActionResponses<TPlugin extends common.BasePlugin> = {
64
+ [K in utils.StringKeys<TPlugin['actions']>]: {
65
+ type: K;
66
+ output: TPlugin['actions'][K]['output'];
67
+ };
68
+ };
69
+ export type AnyIncomingEvent<_TPlugin extends common.BasePlugin> = client.Event;
70
+ export type AnyIncomingMessage<_TPlugin extends common.BasePlugin> = client.Message;
71
+ export type AnyOutgoingMessageRequest<_TPlugin extends common.BasePlugin> = client.ClientInputs['createMessage'];
72
+ export type AnyOutgoingMessageResponse<_TPlugin extends common.BasePlugin> = client.ClientOutputs['createMessage'];
73
+ export type AnyOutgoingCallActionRequest<_TPlugin extends common.BasePlugin> = client.ClientInputs['callAction'];
74
+ export type AnyOutgoingCallActionResponse<_TPlugin extends common.BasePlugin> = client.ClientOutputs['callAction'] & {
75
+ type: string;
76
+ };
77
+ export type AnyIncomingCallActionRequest<_TPlugin extends common.BasePlugin> = {
78
+ type: string;
79
+ input: Record<string, unknown>;
80
+ };
81
+ export type AnyIncomingCallActionResponse<_TPlugin extends common.BasePlugin> = {
82
+ type: string;
83
+ output: Record<string, unknown>;
84
+ };
85
+ export type IncomingEvents<TPlugin extends common.BasePlugin> = _IncomingEvents<TPlugin> & {
86
+ '*': AnyIncomingEvent<TPlugin>;
87
+ };
88
+ export type IncomingMessages<TPlugin extends common.BasePlugin> = _IncomingMessages<TPlugin> & {
89
+ '*': AnyIncomingMessage<TPlugin>;
90
+ };
91
+ export type IncomingStates<_TPlugin extends common.BasePlugin> = _IncomingStates<_TPlugin> & {
92
+ '*': client.State;
93
+ };
94
+ export type OutgoingMessageRequests<TPlugin extends common.BasePlugin> = _OutgoingMessageRequests<TPlugin> & {
95
+ '*': AnyOutgoingMessageRequest<TPlugin>;
96
+ };
97
+ export type OutgoingMessageResponses<TPlugin extends common.BasePlugin> = _OutgoingMessageResponses<TPlugin> & {
98
+ '*': AnyOutgoingMessageResponse<TPlugin>;
99
+ };
100
+ export type OutgoingCallActionRequests<TPlugin extends common.BasePlugin> = _OutgoingCallActionRequests<TPlugin> & {
101
+ '*': AnyOutgoingCallActionRequest<TPlugin>;
102
+ };
103
+ export type OutgoingCallActionResponses<TPlugin extends common.BasePlugin> = _OutgoingCallActionResponses<TPlugin> & {
104
+ '*': AnyOutgoingCallActionResponse<TPlugin>;
105
+ };
106
+ export type IncomingCallActionRequest<TPlugin extends common.BasePlugin> = _IncomingCallActionRequests<TPlugin> & {
107
+ '*': AnyIncomingCallActionRequest<TPlugin>;
108
+ };
109
+ export type IncomingCallActionResponse<TPlugin extends common.BasePlugin> = _IncomingCallActionResponses<TPlugin> & {
110
+ '*': AnyIncomingCallActionResponse<TPlugin>;
111
+ };
112
+ export type PluginClient<_TPlugin extends common.BasePlugin> = bot.BotSpecificClient<common.BasePlugin>;
113
+ export type CommonHandlerProps<TPlugin extends common.BasePlugin> = {
114
+ ctx: bot.BotContext;
115
+ logger: bot.BotLogger;
116
+ /**
117
+ * Please use the `users`, `conversations`, `actions`, `messages`, `states`,
118
+ * `events`, `workflows` utilities instead of accessing the client directly.
119
+ *
120
+ * For example, you can replace `props.client.listUsers(...)` with
121
+ * `props.users.list(...).take(n)`
122
+ */
123
+ client: PluginClient<TPlugin>;
124
+ };
125
+ export type InjectedHandlerProps<TPlugin extends common.BasePlugin> = {
126
+ configuration: common.PluginConfiguration<TPlugin>;
127
+ /**
128
+ * Mapping of plugin interface dependencies to the integrations that
129
+ * implement them.
130
+ */
131
+ interfaces: common.PluginInterfaceExtensions<TPlugin>;
132
+ /**
133
+ * Mapping of plugin integration dependencies to the integrations that
134
+ * implement them.
135
+ */
136
+ integrations: common.PluginIntegrationExtensions<TPlugin>;
137
+ /**
138
+ * Alias of the plugin within the bot. This is usually equal to the plugin's
139
+ * name, but may be different if the bot has multiple instances of the same
140
+ * plugin installed.
141
+ */
142
+ alias: string;
143
+ /**
144
+ * Allows calling actions defined by the plugins's integration and interface
145
+ * dependencies.
146
+ */
147
+ actions: actionProxy.ActionProxy<TPlugin>;
148
+ /**
149
+ * Allows querying and mutating states defined by the plugin.
150
+ */
151
+ states: stateProxy.StateProxy<TPlugin>;
152
+ /**
153
+ * Allows emitting events defined by the plugin.
154
+ */
155
+ events: eventProxy.EventProxy<TPlugin>;
156
+ /**
157
+ * Allows querying and mutating users.
158
+ */
159
+ users: userProxy.UserFinder<TPlugin>;
160
+ /**
161
+ * Allows querying and mutating conversations on channels defined by the
162
+ * plugin's integration and interface dependencies.
163
+ */
164
+ conversations: conversationProxy.ConversationFinder<TPlugin>;
165
+ /**
166
+ * Allows querying and mutating individual messages.
167
+ */
168
+ messages: messageProxy.MessageFinder<TPlugin>;
169
+ /**
170
+ * # EXPERIMENTAL
171
+ * This API is experimental and may change in the future.
172
+ */
173
+ workflows: workflowProxy.WorkflowProxy<TPlugin>;
174
+ };
175
+ type _WithInjectedProps<T extends Record<string, Record<string, any>>, TPlugin extends common.BasePlugin, TMerge extends object = {}> = {
176
+ [K in keyof T]: utils.Merge<T[K], TMerge> & InjectedHandlerProps<TPlugin>;
177
+ };
178
+ type _WithInjectedPropsFn<T extends Record<string, (args: any) => any>, TPlugin extends common.BasePlugin, TMerge extends object = {}> = {
179
+ [K in keyof T]: (args: utils.Merge<Parameters<T[K]>[0], TMerge> & InjectedHandlerProps<TPlugin>) => ReturnType<T[K]>;
180
+ };
181
+ export type MessagePayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
182
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: CommonHandlerProps<TPlugin> & {
183
+ message: IncomingMessages<TPlugin>[TMessageName];
184
+ user: client.User;
185
+ conversation: client.Conversation;
186
+ event: client.Event;
187
+ };
188
+ };
189
+ export type MessageHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
190
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: (args: MessagePayloadsWithoutInjectedProps<TPlugin>[TMessageName]) => Promise<void>;
191
+ };
192
+ export type MessageHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<MessageHandlersWithoutInjectedProps<TPlugin>, TPlugin, {
193
+ user: userProxy.ActionableUser<TPlugin, string>;
194
+ conversation: conversationProxy.ActionableConversation<TPlugin>;
195
+ message: messageProxy.ActionableMessage<TPlugin>;
196
+ }>;
197
+ export type EventPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
198
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: CommonHandlerProps<TPlugin> & {
199
+ event: IncomingEvents<TPlugin>[TEventName];
200
+ };
201
+ };
202
+ export type EventPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<EventPayloadsWithoutInjectedProps<TPlugin>, TPlugin>;
203
+ export type EventHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
204
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: (args: EventPayloadsWithoutInjectedProps<TPlugin>[TEventName]) => Promise<void>;
205
+ };
206
+ export type EventHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<EventHandlersWithoutInjectedProps<TPlugin>, TPlugin>;
207
+ export type StateExpiredPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
208
+ [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: CommonHandlerProps<TPlugin> & {
209
+ state: IncomingStates<TPlugin>[TSateName];
210
+ };
211
+ };
212
+ export type StateExpiredPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<StateExpiredPayloadsWithoutInjectedProps<TPlugin>, TPlugin>;
213
+ export type StateExpiredHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
214
+ [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: (args: StateExpiredPayloadsWithoutInjectedProps<TPlugin>[TSateName]) => Promise<void>;
215
+ };
216
+ export type StateExpiredHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<StateExpiredHandlersWithoutInjectedProps<TPlugin>, TPlugin>;
217
+ export type ActionHandlerPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
218
+ [TActionName in utils.StringKeys<TPlugin['actions']>]: CommonHandlerProps<TPlugin> & {
219
+ type?: TActionName;
220
+ input: TPlugin['actions'][TActionName]['input'];
221
+ };
222
+ };
223
+ export type ActionHandlerPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<ActionHandlerPayloadsWithoutInjectedProps<TPlugin>, TPlugin>;
224
+ export type ActionHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
225
+ [TActionName in utils.StringKeys<TPlugin['actions']>]: (props: ActionHandlerPayloadsWithoutInjectedProps<TPlugin>[TActionName]) => Promise<TPlugin['actions'][TActionName]['output']>;
226
+ };
227
+ export type ActionHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<ActionHandlersWithoutInjectedProps<TPlugin>, TPlugin>;
228
+ export type WorkflowPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
229
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: CommonHandlerProps<TPlugin> & {
230
+ conversation?: client.Conversation;
231
+ user?: client.User;
232
+ event: bot.WorkflowUpdateEvent;
233
+ workflow: client.Workflow;
234
+ };
235
+ };
236
+ export type WorkflowPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<{
237
+ [TWorkflowName in keyof WorkflowPayloadsWithoutInjectedProps<TPlugin>]: utils.Merge<WorkflowPayloadsWithoutInjectedProps<TPlugin>[TWorkflowName], {
238
+ /**
239
+ * # EXPERIMENTAL
240
+ * This API is experimental and may change in the future.
241
+ */
242
+ workflow: workflowProxy.ActionableWorkflow<TPlugin, TWorkflowName>;
243
+ }>;
244
+ }, TPlugin>;
245
+ export type WorkflowHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
246
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: (props: WorkflowPayloadsWithoutInjectedProps<TPlugin>[TWorkflowName]) => Promise<void>;
247
+ };
248
+ export type WorkflowHandlers<TPlugin extends common.BasePlugin> = {
249
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: (props: utils.Merge<WorkflowPayloads<TPlugin>[TWorkflowName], {
250
+ workflow: workflowProxy.ActionableWorkflow<TPlugin, TWorkflowName>;
251
+ }>) => Promise<void>;
252
+ };
253
+ type BaseHookDefinition = {
254
+ stoppable?: boolean;
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
+ };
266
+ };
267
+ type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> = THookDef;
268
+ /**
269
+ * TODO: add hooks for:
270
+ * - before_register
271
+ * - after_register
272
+ * - before_state_expired
273
+ * - after_state_expired
274
+ */
275
+ export type HookDefinitionType = keyof HookDefinitions<common.BasePlugin>;
276
+ export type HookDefinitions<TPlugin extends common.BasePlugin> = {
277
+ before_incoming_event: HookDefinition<{
278
+ stoppable: true;
279
+ data: _IncomingEvents<TPlugin> & {
280
+ '*': AnyIncomingEvent<TPlugin>;
281
+ };
282
+ }>;
283
+ before_incoming_message: HookDefinition<{
284
+ stoppable: true;
285
+ data: _IncomingMessages<TPlugin> & {
286
+ '*': AnyIncomingMessage<TPlugin>;
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
+ };
298
+ }>;
299
+ before_outgoing_message: HookDefinition<{
300
+ stoppable: false;
301
+ data: _OutgoingMessageRequests<TPlugin> & {
302
+ '*': AnyOutgoingMessageRequest<TPlugin>;
303
+ };
304
+ }>;
305
+ before_outgoing_call_action: HookDefinition<{
306
+ stoppable: false;
307
+ data: _OutgoingCallActionRequests<TPlugin> & {
308
+ '*': AnyOutgoingCallActionRequest<TPlugin>;
309
+ };
310
+ }>;
311
+ before_incoming_call_action: HookDefinition<{
312
+ stoppable: true;
313
+ data: _IncomingCallActionRequests<TPlugin> & {
314
+ '*': AnyIncomingCallActionRequest<TPlugin>;
315
+ };
316
+ }>;
317
+ after_incoming_event: HookDefinition<{
318
+ stoppable: true;
319
+ data: _IncomingEvents<TPlugin> & {
320
+ '*': AnyIncomingEvent<TPlugin>;
321
+ };
322
+ }>;
323
+ after_incoming_message: HookDefinition<{
324
+ stoppable: true;
325
+ data: _IncomingMessages<TPlugin> & {
326
+ '*': AnyIncomingMessage<TPlugin>;
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
+ };
338
+ }>;
339
+ after_outgoing_message: HookDefinition<{
340
+ stoppable: false;
341
+ data: _OutgoingMessageResponses<TPlugin> & {
342
+ '*': AnyOutgoingMessageResponse<TPlugin>;
343
+ };
344
+ }>;
345
+ after_outgoing_call_action: HookDefinition<{
346
+ stoppable: false;
347
+ data: _OutgoingCallActionResponses<TPlugin> & {
348
+ '*': AnyOutgoingCallActionResponse<TPlugin>;
349
+ };
350
+ }>;
351
+ after_incoming_call_action: HookDefinition<{
352
+ stoppable: true;
353
+ data: _IncomingCallActionResponses<TPlugin> & {
354
+ '*': AnyIncomingCallActionResponse<TPlugin>;
355
+ };
356
+ }>;
357
+ };
358
+ export type HookData<TPlugin extends common.BasePlugin> = {
359
+ [THookType in HookDefinitionType]: {
360
+ [THookDataName in utils.StringKeys<HookDefinitions<TPlugin>[THookType]['data']>]: HookDefinitions<TPlugin>[THookType]['data'][THookDataName];
361
+ };
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
+ };
377
+ export type HookInputsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
378
+ [THookType in HookDefinitionType]: {
379
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & _HookExtraInputsRaw<TPlugin>[THookType] & {
380
+ data: HookData<TPlugin>[THookType][THookDataName];
381
+ };
382
+ };
383
+ };
384
+ export type HookInputs<TPlugin extends common.BasePlugin> = {
385
+ [THookType in HookDefinitionType]: _WithInjectedProps<HookInputsWithoutInjectedProps<TPlugin>[THookType], TPlugin, _HookExtraInputsInjected<TPlugin>[THookType]>;
386
+ };
387
+ export type HookOutputs<TPlugin extends common.BasePlugin> = {
388
+ [THookType in HookDefinitionType]: {
389
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: {
390
+ data?: HookData<TPlugin>[THookType][THookDataName];
391
+ } & (HookDefinitions<TPlugin>[THookType]['stoppable'] extends true ? {
392
+ stop?: boolean;
393
+ } : {});
394
+ };
395
+ };
396
+ export type HookHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
397
+ [THookType in HookDefinitionType]: {
398
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: (input: HookInputsWithoutInjectedProps<TPlugin>[THookType][THookDataName]) => Promise<HookOutputs<TPlugin>[THookType][THookDataName] | undefined>;
399
+ };
400
+ };
401
+ export type HookHandlers<TPlugin extends common.BasePlugin> = {
402
+ [THookType in HookDefinitionType]: _WithInjectedPropsFn<HookHandlersWithoutInjectedProps<TPlugin>[THookType], TPlugin, _HookExtraInputsInjected<TPlugin>[THookType]>;
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>;
410
+ export type HookHandlersMap<TPlugin extends common.BasePlugin> = {
411
+ [THookType in HookDefinitionType]: {
412
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
413
+ };
414
+ };
415
+ export type WorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
416
+ [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
417
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: {
418
+ handler: (props: Omit<Parameters<WorkflowHandlersWithoutInjectedProps<TPlugin>[TWorkflowName]>[0], 'workflow'> & {
419
+ workflow: client.Workflow;
420
+ }) => Promise<client.Workflow>;
421
+ order: number;
422
+ }[];
423
+ };
424
+ };
425
+ export type OrderedMessageHandlersMap = {
426
+ [TMessageName in string]?: {
427
+ handler: MessageHandlers<common.BasePlugin>[TMessageName];
428
+ order: number;
429
+ }[];
430
+ };
431
+ export type OrderedEventHandlersMap = {
432
+ [TEventName in string]?: {
433
+ handler: EventHandlers<common.BasePlugin>['*'];
434
+ order: number;
435
+ }[];
436
+ };
437
+ export type OrderedStateExpiredHandlersMap = {
438
+ [TStateName in string]?: {
439
+ handler: StateExpiredHandlers<common.BasePlugin>['*'];
440
+ order: number;
441
+ }[];
442
+ };
443
+ export type OrderedHookHandlersMap = {
444
+ [THookType in HookDefinitionType]: {
445
+ [THookDataName in string]?: {
446
+ handler: AnyHookHandler<common.BasePlugin>;
447
+ order: number;
448
+ }[];
449
+ };
450
+ };
451
+ export type OrderedWorkflowHandlersMap = {
452
+ [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
453
+ [TWorkflowName in string]?: {
454
+ handler: WorkflowHandlers<common.BasePlugin>['*'];
455
+ order: number;
456
+ }[];
457
+ };
458
+ };
459
+ /** Plugin handlers without InjectedHandlerProps */
460
+ export type PluginHandlers<TPlugin extends common.BasePlugin> = {
461
+ actionHandlers: ActionHandlersWithoutInjectedProps<TPlugin>;
462
+ messageHandlers: {
463
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: MessageHandlersWithoutInjectedProps<TPlugin>[TMessageName][];
464
+ };
465
+ eventHandlers: {
466
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: EventHandlersWithoutInjectedProps<TPlugin>[TEventName][];
467
+ };
468
+ stateExpiredHandlers: {
469
+ [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlersWithoutInjectedProps<TPlugin>[TStateName][];
470
+ };
471
+ hookHandlers: {
472
+ [THookType in HookDefinitionType]: {
473
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
474
+ };
475
+ };
476
+ workflowHandlers: {
477
+ [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
478
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: WorkflowHandlersWithoutInjectedProps<TPlugin>[TWorkflowName][];
479
+ };
480
+ };
481
+ };
482
+ /** identical to PluginHandlers, but contains the injected properties */
483
+ export type InjectedPluginHandlers<TPlugin extends common.BasePlugin> = {
484
+ actionHandlers: ActionHandlers<TPlugin>;
485
+ messageHandlers: {
486
+ [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: MessageHandlers<TPlugin>[TMessageName][];
487
+ };
488
+ eventHandlers: {
489
+ [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: EventHandlers<TPlugin>[TEventName][];
490
+ };
491
+ stateExpiredHandlers: {
492
+ [TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlers<TPlugin>[TStateName][];
493
+ };
494
+ hookHandlers: {
495
+ [THookType in HookDefinitionType]: {
496
+ [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlers<TPlugin>[THookType][THookDataName][];
497
+ };
498
+ };
499
+ workflowHandlers: {
500
+ [TWorkflowUpdateType in bot.WorkflowUpdateType]: {
501
+ [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: WorkflowHandlers<TPlugin>[TWorkflowName][];
502
+ };
503
+ };
504
+ };
505
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './proxy';
2
+ export * from './types';
@@ -0,0 +1,5 @@
1
+ import { Client } from '@holocronlab/botruntime-client';
2
+ import { BotSpecificClient } from '../../bot';
3
+ import { BasePlugin, PluginRuntimeProps } from '../common';
4
+ import { StateProxy } from './types';
5
+ export declare const proxyStates: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client, props: PluginRuntimeProps<TPlugin>) => StateProxy<TPlugin>;
@@ -0,0 +1,29 @@
1
+ import * as bot from '../../bot';
2
+ import * as utils from '../../utils/type-utils';
3
+ import { BasePlugin } from '../common';
4
+ type _EnumerateStates<TPlugin extends BasePlugin> = {
5
+ [TStateName in keyof TPlugin['states']]: TPlugin['states'][TStateName] & {
6
+ name: TStateName;
7
+ };
8
+ };
9
+ type _FilterStates<TPlugin extends BasePlugin, TStateType extends bot.StateType> = Extract<utils.ValueOf<_EnumerateStates<TPlugin>>, {
10
+ type: TStateType;
11
+ }>['name'];
12
+ type _GetStatePayload<TPlugin extends BasePlugin, TStateName extends string | number | symbol> = TPlugin['states'][utils.Cast<TStateName, keyof TPlugin['states']>]['payload'];
13
+ export type StateRepo<TPayload> = {
14
+ get: (id: string) => Promise<TPayload>;
15
+ set: (id: string, payload: TPayload, options?: {
16
+ expiryMs: number;
17
+ }) => Promise<void>;
18
+ getOrSet: (id: string, payload: TPayload, options?: {
19
+ expiryMs: number;
20
+ }) => Promise<TPayload>;
21
+ delete: (id: string) => Promise<void>;
22
+ patch: (id: string, payload: Partial<TPayload>) => Promise<void>;
23
+ };
24
+ export type StateProxy<TPlugin extends BasePlugin> = utils.Normalize<{
25
+ [TStateType in bot.StateType]: {
26
+ [TStateName in _FilterStates<TPlugin, TStateType>]: StateRepo<_GetStatePayload<TPlugin, TStateName>>;
27
+ };
28
+ }>;
29
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export declare const unprefixTagsOwnedByPlugin: <T extends {} | {
2
+ tags?: Record<string, string>;
3
+ }>(obj: T, { alias }: {
4
+ alias?: string;
5
+ }) => T;
6
+ export declare const prefixTagsIfNeeded: <T extends {} | {
7
+ tags?: Record<string, string>;
8
+ }>(obj: T, { alias }: {
9
+ alias?: string;
10
+ }) => T;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { proxyUsers, proxyUser } from './proxy';
2
+ export { UserFinder, ActionableUser } from './types';
@@ -0,0 +1,14 @@
1
+ import type * as client from '@holocronlab/botruntime-client';
2
+ import type { BotSpecificClient } from '../../bot';
3
+ import type { BasePlugin } from '../common';
4
+ import type { UserFinder, ActionableUser } from './types';
5
+ export declare const proxyUsers: <TPlugin extends BasePlugin>(props: {
6
+ client: BotSpecificClient<TPlugin> | client.Client;
7
+ pluginAlias?: string;
8
+ }) => UserFinder<TPlugin>;
9
+ export declare const proxyUser: <TPlugin extends BasePlugin, TConversationId extends string | undefined>(props: {
10
+ client: BotSpecificClient<TPlugin> | client.Client;
11
+ conversationId?: TConversationId;
12
+ pluginAlias?: string;
13
+ user: client.User;
14
+ }) => ActionableUser<TPlugin, TConversationId>;
@@ -0,0 +1,30 @@
1
+ import { ClientInputs, User } from '@holocronlab/botruntime-client';
2
+ import type { commonTypes } from '../../common';
3
+ import type { AsyncCollection } from '../../utils/api-paging-utils';
4
+ import type * as typeUtils from '../../utils/type-utils';
5
+ import { BasePlugin } from '../common';
6
+ export type UserFinder<TPlugin extends BasePlugin> = {
7
+ list: <TConversationId extends string | undefined = undefined>(props?: {
8
+ conversationId?: TConversationId;
9
+ tags?: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['user']['tags']>>;
10
+ }) => AsyncCollection<ActionableUser<TPlugin, TConversationId>>;
11
+ getById: (props: {
12
+ id: string;
13
+ }) => Promise<ActionableUser<TPlugin>>;
14
+ };
15
+ export type ActionableUser<TPlugin extends BasePlugin, TConversationId extends string | undefined = undefined> = TConversationId extends string ? ActionableUserWithConversation<TPlugin, TConversationId> : ActionableUserWithoutConversation<TPlugin, TConversationId>;
16
+ export type ActionableUserWithConversation<TPlugin extends BasePlugin, TConversationId extends string | undefined> = BaseActionableUser<TPlugin, TConversationId> & {
17
+ removeFromConversation: () => Promise<ActionableUser<TPlugin, undefined>>;
18
+ };
19
+ export type ActionableUserWithoutConversation<TPlugin extends BasePlugin, TConversationId extends string | undefined> = BaseActionableUser<TPlugin, TConversationId> & {
20
+ addToConversation: <TNewConversationId extends string>(props: {
21
+ conversationId: TNewConversationId;
22
+ }) => Promise<ActionableUser<TPlugin, TNewConversationId>>;
23
+ };
24
+ export type BaseActionableUser<TPlugin extends BasePlugin, TConversationId extends string | undefined = undefined> = typeUtils.Merge<User, {
25
+ tags: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['user']['tags']>>;
26
+ }> & {
27
+ update: (props: typeUtils.Merge<Omit<ClientInputs['updateUser'], 'id'>, {
28
+ tags?: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['user']['tags']>>;
29
+ }>) => Promise<ActionableUser<TPlugin, TConversationId>>;
30
+ };
@@ -0,0 +1,9 @@
1
+ export declare const WELL_KNOWN_ATTRIBUTES: {
2
+ readonly HIDDEN_IN_STUDIO: {
3
+ readonly bpActionHiddenInStudio: "true";
4
+ };
5
+ readonly AWAIT_RETURN: {
6
+ readonly bpActionAwaitReturn: "true";
7
+ };
8
+ };
9
+ export declare const OAUTH_IDENTIFIER_HEADER = "x-bp-integration-identifier";
@@ -0,0 +1,2 @@
1
+ import * as client from '@holocronlab/botruntime-client';
2
+ export declare const retryConfig: client.RetryConfig;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { z } from './zui';
2
+ type SchemaOptions<T> = {
3
+ title: string;
4
+ examples: T[];
5
+ };
6
+ type IsEmptyObject<T> = keyof T extends never ? true : false;
7
+ type UiDefinition<TSchema extends z.ZuiObjectOrRefSchema = z.ZuiObjectOrRefSchema> = IsEmptyObject<z.infer<TSchema>> extends true ? Record<string, never> : {
8
+ [K in keyof z.infer<TSchema>]: Partial<SchemaOptions<z.infer<TSchema>[K]>>;
9
+ };
10
+ export type SchemaDefinition<TSchema extends z.ZuiObjectOrRefSchema = z.ZuiObjectOrRefSchema> = {
11
+ schema: TSchema;
12
+ /**
13
+ * @deprecated
14
+ * Use zod.Schema.displayAs() instead
15
+ **/
16
+ ui?: Partial<UiDefinition<TSchema>>;
17
+ };
18
+ export {};