@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,423 @@
1
+ import * as client from '@holocronlab/botruntime-client';
2
+ import * as plugin from '../../plugin';
3
+ import type { Request } from '../../serve';
4
+ import * as utils from '../../utils/type-utils';
5
+ import { type BotLogger } from '../bot-logger';
6
+ import { BotSpecificClient } from '../client';
7
+ import * as common from '../common';
8
+ import type * as workflowProxy from '../workflow-proxy/types';
9
+ export type BotOperation = 'event_received' | 'register' | 'unregister' | 'ping' | 'action_triggered';
10
+ export type BotContext = {
11
+ botId: string;
12
+ type: string;
13
+ operation: BotOperation;
14
+ configuration: {
15
+ payload: string;
16
+ };
17
+ };
18
+ type _IncomingEvents<TBot extends common.BaseBot> = {
19
+ [K in utils.StringKeys<common.EnumerateEvents<TBot>>]: utils.Merge<client.Event, {
20
+ type: K;
21
+ payload: common.EnumerateEvents<TBot>[K];
22
+ }>;
23
+ };
24
+ type _IncomingMessages<TBot extends common.BaseBot> = {
25
+ [K in utils.StringKeys<common.GetMessages<TBot>>]: utils.Merge<client.Message, {
26
+ type: K;
27
+ payload: common.GetMessages<TBot>[K];
28
+ }>;
29
+ };
30
+ type _IncomingStates<TBot extends common.BaseBot> = {
31
+ [K in utils.StringKeys<common.EnumerateStates<TBot>>]: utils.Merge<client.State, {
32
+ name: K;
33
+ type: common.EnumerateStates<TBot>[K]['type'];
34
+ payload: common.EnumerateStates<TBot>[K]['payload'];
35
+ }>;
36
+ };
37
+ type _OutgoingMessageRequests<TBot extends common.BaseBot> = {
38
+ [K in utils.StringKeys<common.GetMessages<TBot>>]: utils.Merge<client.ClientInputs['createMessage'], {
39
+ type: K;
40
+ payload: common.GetMessages<TBot>[K];
41
+ }>;
42
+ };
43
+ type _OutgoingMessageResponses<TBot extends common.BaseBot> = {
44
+ [K in utils.StringKeys<common.GetMessages<TBot>>]: utils.Merge<client.ClientOutputs['createMessage'], {
45
+ message: utils.Merge<client.Message, {
46
+ type: K;
47
+ payload: common.GetMessages<TBot>[K];
48
+ }>;
49
+ }>;
50
+ };
51
+ type _OutgoingCallActionRequests<TBot extends common.BaseBot> = {
52
+ [K in utils.StringKeys<common.EnumerateActionInputs<TBot>>]: utils.Merge<client.ClientInputs['callAction'], {
53
+ type: K;
54
+ input: common.EnumerateActionInputs<TBot>[K];
55
+ }>;
56
+ };
57
+ type _OutgoingCallActionResponses<TBot extends common.BaseBot> = {
58
+ [K in utils.StringKeys<common.EnumerateActionOutputs<TBot>>]: utils.Merge<client.ClientOutputs['callAction'], {
59
+ type: K;
60
+ output: common.EnumerateActionOutputs<TBot>[K];
61
+ }>;
62
+ };
63
+ type _IncomingCallActionRequest<TBot extends common.BaseBot> = {
64
+ [K in utils.StringKeys<TBot['actions']>]: {
65
+ type: K;
66
+ input: TBot['actions'][K]['input'];
67
+ };
68
+ };
69
+ type _IncomingCallActionResponses<TBot extends common.BaseBot> = {
70
+ [K in utils.StringKeys<TBot['actions']>]: {
71
+ type: K;
72
+ output: TBot['actions'][K]['output'];
73
+ };
74
+ };
75
+ export type AnyIncomingEvent<TBot extends common.BaseBot> = utils.ValueOf<_IncomingEvents<TBot>>;
76
+ export type AnyIncomingMessage<TBot extends common.BaseBot> = utils.ValueOf<_IncomingMessages<TBot>>;
77
+ export type AnyOutgoingMessageRequest<TBot extends common.BaseBot> = utils.ValueOf<_OutgoingMessageRequests<TBot>>;
78
+ export type AnyOutgoingMessageResponse<TBot extends common.BaseBot> = utils.ValueOf<_OutgoingMessageResponses<TBot>>;
79
+ export type AnyOutgoingCallActionRequest<TBot extends common.BaseBot> = utils.ValueOf<_OutgoingCallActionRequests<TBot>>;
80
+ export type AnyOutgoingCallActionResponse<TBot extends common.BaseBot> = utils.ValueOf<_OutgoingCallActionResponses<TBot>>;
81
+ export type AnyIncomingCallActionRequest<TBot extends common.BaseBot> = utils.ValueOf<_IncomingCallActionRequest<TBot>>;
82
+ export type AnyIncomingCallActionResponse<TBot extends common.BaseBot> = utils.ValueOf<_IncomingCallActionResponses<TBot>>;
83
+ export type IncomingEvents<TBot extends common.BaseBot> = _IncomingEvents<TBot> & {
84
+ '*': AnyIncomingEvent<TBot>;
85
+ };
86
+ export type IncomingMessages<TBot extends common.BaseBot> = _IncomingMessages<TBot> & {
87
+ '*': AnyIncomingMessage<TBot>;
88
+ };
89
+ export type IncomingStates<_TBot extends common.BaseBot> = _IncomingStates<_TBot> & {
90
+ '*': client.State;
91
+ };
92
+ export type OutgoingMessageRequests<TBot extends common.BaseBot> = _OutgoingMessageRequests<TBot> & {
93
+ '*': AnyOutgoingMessageRequest<TBot>;
94
+ };
95
+ export type OutgoingMessageResponses<TBot extends common.BaseBot> = _OutgoingMessageResponses<TBot> & {
96
+ '*': AnyOutgoingMessageResponse<TBot>;
97
+ };
98
+ export type OutgoingCallActionRequests<TBot extends common.BaseBot> = _OutgoingCallActionRequests<TBot> & {
99
+ '*': AnyOutgoingCallActionRequest<TBot>;
100
+ };
101
+ export type OutgoingCallActionResponses<TBot extends common.BaseBot> = _OutgoingCallActionResponses<TBot> & {
102
+ '*': AnyOutgoingCallActionResponse<TBot>;
103
+ };
104
+ export type IncomingCallActionRequest<TBot extends common.BaseBot> = _IncomingCallActionRequest<TBot> & {
105
+ '*': AnyIncomingCallActionRequest<TBot>;
106
+ };
107
+ export type IncomingCallActionResponses<TBot extends common.BaseBot> = _IncomingCallActionResponses<TBot> & {
108
+ '*': AnyIncomingCallActionResponse<TBot>;
109
+ };
110
+ export type BotClient<TBot extends common.BaseBot> = BotSpecificClient<TBot>;
111
+ export type CommonHandlerProps<TBot extends common.BaseBot> = {
112
+ ctx: BotContext;
113
+ logger: BotLogger;
114
+ client: BotClient<TBot>;
115
+ };
116
+ export type InjectedHandlerProps<TBot extends common.BaseBot> = {
117
+ /**
118
+ * # EXPERIMENTAL
119
+ * This API is experimental and may change in the future.
120
+ */
121
+ workflows: workflowProxy.WorkflowProxy<TBot>;
122
+ };
123
+ export type ExtendedHandlerProps<TBot extends common.BaseBot> = CommonHandlerProps<TBot> & InjectedHandlerProps<TBot>;
124
+ export type MessagePayloads<TBot extends common.BaseBot> = {
125
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]: ExtendedHandlerProps<TBot> & {
126
+ message: IncomingMessages<TBot>[TMessageName];
127
+ user: client.User;
128
+ conversation: client.Conversation;
129
+ event: client.Event;
130
+ };
131
+ };
132
+ export type MessageHandlers<TBot extends common.BaseBot> = {
133
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]: (args: MessagePayloads<TBot>[TMessageName]) => Promise<void>;
134
+ };
135
+ export type EventPayloads<TBot extends common.BaseBot> = {
136
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]: ExtendedHandlerProps<TBot> & {
137
+ event: IncomingEvents<TBot>[TEventName];
138
+ };
139
+ };
140
+ export type EventHandlers<TBot extends common.BaseBot> = {
141
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]: (args: EventPayloads<TBot>[TEventName]) => Promise<void>;
142
+ };
143
+ export type StateExpiredPayloads<TBot extends common.BaseBot> = {
144
+ [TSateName in utils.StringKeys<IncomingStates<TBot>>]: ExtendedHandlerProps<TBot> & {
145
+ state: IncomingStates<TBot>[TSateName];
146
+ };
147
+ };
148
+ export type StateExpiredHandlers<TBot extends common.BaseBot> = {
149
+ [TSateName in utils.StringKeys<IncomingStates<TBot>>]: (args: StateExpiredPayloads<TBot>[TSateName]) => Promise<void>;
150
+ };
151
+ export type ActionHandlerPayloads<TBot extends common.BaseBot> = {
152
+ [TActionName in utils.StringKeys<TBot['actions']>]: ExtendedHandlerProps<TBot> & {
153
+ type?: TActionName;
154
+ input: TBot['actions'][TActionName]['input'];
155
+ };
156
+ };
157
+ export type ActionHandlers<TBot extends common.BaseBot> = {
158
+ [TActionName in utils.StringKeys<TBot['actions']>]: (props: ActionHandlerPayloads<TBot>[TActionName]) => Promise<TBot['actions'][TActionName]['output']>;
159
+ };
160
+ export type ActionHandlersMap<TBot extends common.BaseBot> = {
161
+ [TActionName in utils.StringKeys<TBot['actions']>]?: (props: Omit<Parameters<ActionHandlers<TBot>[TActionName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<Awaited<ReturnType<ActionHandlers<TBot>[TActionName]>>>;
162
+ };
163
+ export type BridgeWorkflowUpdateType = 'child_workflow_deleted' | 'child_workflow_finished' | 'workflow_timedout' | 'workflow_started' | 'workflow_continued';
164
+ export type WorkflowUpdateEventPayload = {
165
+ type: BridgeWorkflowUpdateType;
166
+ childWorkflow?: client.Workflow;
167
+ workflow: client.Workflow;
168
+ conversation?: client.Conversation;
169
+ user?: client.User;
170
+ };
171
+ export type WorkflowUpdateEvent = utils.Merge<client.Event, {
172
+ type: 'workflow_update';
173
+ payload: WorkflowUpdateEventPayload;
174
+ }>;
175
+ export type WorkflowPayloads<TBot extends common.BaseBot> = {
176
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]: ExtendedHandlerProps<TBot> & {
177
+ conversation?: client.Conversation;
178
+ user?: client.User;
179
+ event: WorkflowUpdateEvent;
180
+ /**
181
+ * # EXPERIMENTAL
182
+ * This API is experimental and may change in the future.
183
+ */
184
+ workflow: workflowProxy.ActionableWorkflow<TBot, TWorkflowName>;
185
+ };
186
+ };
187
+ export type WorkflowHandlers<TBot extends common.BaseBot> = {
188
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]: (props: WorkflowPayloads<TBot>[TWorkflowName]) => Promise<void>;
189
+ };
190
+ type BaseHookDefinition = {
191
+ stoppable?: boolean;
192
+ data: any;
193
+ /**
194
+ * Per-hook-type extra props injected into the hook handler input. Only set
195
+ * for hooks where the bot runtime already has the relevant context (e.g.
196
+ * incoming message hooks).
197
+ */
198
+ extraInputs?: object;
199
+ };
200
+ type HookDefinition<THookDef extends BaseHookDefinition = BaseHookDefinition> = THookDef;
201
+ /**
202
+ * TODO: add hooks for:
203
+ * - before_register
204
+ * - after_register
205
+ * - before_state_expired
206
+ * - after_state_expired
207
+ */
208
+ export type HookDefinitions<TBot extends common.BaseBot> = {
209
+ before_incoming_event: HookDefinition<{
210
+ stoppable: true;
211
+ data: _IncomingEvents<TBot> & {
212
+ '*': AnyIncomingEvent<TBot>;
213
+ };
214
+ }>;
215
+ before_incoming_message: HookDefinition<{
216
+ stoppable: true;
217
+ data: _IncomingMessages<TBot> & {
218
+ '*': AnyIncomingMessage<TBot>;
219
+ };
220
+ extraInputs: {
221
+ user?: client.User;
222
+ conversation?: client.Conversation;
223
+ };
224
+ }>;
225
+ before_outgoing_message: HookDefinition<{
226
+ stoppable: false;
227
+ data: _OutgoingMessageRequests<TBot> & {
228
+ '*': AnyOutgoingMessageRequest<TBot>;
229
+ };
230
+ }>;
231
+ before_outgoing_call_action: HookDefinition<{
232
+ stoppable: false;
233
+ data: _OutgoingCallActionRequests<TBot> & {
234
+ '*': AnyOutgoingCallActionRequest<TBot>;
235
+ };
236
+ }>;
237
+ before_incoming_call_action: HookDefinition<{
238
+ stoppable: false;
239
+ data: _IncomingCallActionRequest<TBot> & {
240
+ '*': AnyIncomingCallActionRequest<TBot>;
241
+ };
242
+ }>;
243
+ after_incoming_event: HookDefinition<{
244
+ stoppable: true;
245
+ data: _IncomingEvents<TBot> & {
246
+ '*': AnyIncomingEvent<TBot>;
247
+ };
248
+ }>;
249
+ after_incoming_message: HookDefinition<{
250
+ stoppable: true;
251
+ data: _IncomingMessages<TBot> & {
252
+ '*': AnyIncomingMessage<TBot>;
253
+ };
254
+ extraInputs: {
255
+ user?: client.User;
256
+ conversation?: client.Conversation;
257
+ };
258
+ }>;
259
+ after_outgoing_message: HookDefinition<{
260
+ stoppable: false;
261
+ data: _OutgoingMessageResponses<TBot> & {
262
+ '*': AnyOutgoingMessageResponse<TBot>;
263
+ };
264
+ }>;
265
+ after_outgoing_call_action: HookDefinition<{
266
+ stoppable: false;
267
+ data: _OutgoingCallActionResponses<TBot> & {
268
+ '*': AnyOutgoingCallActionResponse<TBot>;
269
+ };
270
+ }>;
271
+ after_incoming_call_action: HookDefinition<{
272
+ stoppable: false;
273
+ data: _IncomingCallActionResponses<TBot> & {
274
+ '*': AnyIncomingCallActionResponse<TBot>;
275
+ };
276
+ }>;
277
+ };
278
+ export type HookData<TBot extends common.BaseBot> = {
279
+ [THookType in utils.StringKeys<HookDefinitions<TBot>>]: {
280
+ [THookDataName in utils.StringKeys<HookDefinitions<TBot>[THookType]['data']>]: HookDefinitions<TBot>[THookType]['data'][THookDataName];
281
+ };
282
+ };
283
+ type _HookExtraInputs<TBot extends common.BaseBot> = {
284
+ [THookType in utils.StringKeys<HookDefinitions<TBot>>]: HookDefinitions<TBot>[THookType] extends {
285
+ extraInputs: infer T;
286
+ } ? T : {};
287
+ };
288
+ export type HookInputs<TBot extends common.BaseBot> = {
289
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
290
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: ExtendedHandlerProps<TBot> & _HookExtraInputs<TBot>[THookType] & {
291
+ data: HookData<TBot>[THookType][THookDataName];
292
+ };
293
+ };
294
+ };
295
+ export type HookOutputs<TBot extends common.BaseBot> = {
296
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
297
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: {
298
+ data?: HookData<TBot>[THookType][THookDataName];
299
+ } & (HookDefinitions<TBot>[THookType]['stoppable'] extends true ? {
300
+ stop?: boolean;
301
+ } : {});
302
+ };
303
+ };
304
+ export type HookHandlers<TBot extends common.BaseBot> = {
305
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
306
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]: (input: HookInputs<TBot>[THookType][THookDataName]) => Promise<HookOutputs<TBot>[THookType][THookDataName] | undefined>;
307
+ };
308
+ };
309
+ export type MessageHandlersMap<TBot extends common.BaseBot> = {
310
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: ((props: Omit<Parameters<MessageHandlers<TBot>[TMessageName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<void>)[];
311
+ };
312
+ export type EventHandlersMap<TBot extends common.BaseBot> = {
313
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: ((props: Omit<Parameters<EventHandlers<TBot>[TEventName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<void>)[];
314
+ };
315
+ export type StateExpiredHandlersMap<TBot extends common.BaseBot> = {
316
+ [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: ((props: Omit<Parameters<StateExpiredHandlers<TBot>[TStateName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<void>)[];
317
+ };
318
+ export type HookHandlersMap<TBot extends common.BaseBot> = {
319
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
320
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: ((props: Omit<Parameters<HookHandlers<TBot>[THookType][THookDataName]>[0], keyof InjectedHandlerProps<TBot>>) => Promise<Awaited<ReturnType<HookHandlers<TBot>[THookType][THookDataName]>>>)[];
321
+ };
322
+ };
323
+ export type WorkflowUpdateType = 'started' | 'continued' | 'timed_out';
324
+ export type WorkflowHandlersMap<TBot extends common.BaseBot> = {
325
+ [TWorkflowUpdateType in WorkflowUpdateType]: {
326
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: ((props: Omit<Parameters<WorkflowHandlers<TBot>[TWorkflowName]>[0], keyof InjectedHandlerProps<TBot> | 'workflow'> & {
327
+ workflow: client.Workflow;
328
+ }) => Promise<client.Workflow>)[];
329
+ };
330
+ };
331
+ export type OrderedMessageHandlersMap<TBot extends common.BaseBot> = {
332
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: {
333
+ handler: MessageHandlers<TBot>[TMessageName];
334
+ order: number;
335
+ }[];
336
+ };
337
+ export type OrderedEventHandlersMap<TBot extends common.BaseBot> = {
338
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: {
339
+ handler: EventHandlers<TBot>[TEventName];
340
+ order: number;
341
+ }[];
342
+ };
343
+ export type OrderedStateExpiredHandlersMap<TBot extends common.BaseBot> = {
344
+ [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: {
345
+ handler: StateExpiredHandlers<TBot>[TStateName];
346
+ order: number;
347
+ }[];
348
+ };
349
+ export type OrderedHookHandlersMap<TBot extends common.BaseBot> = {
350
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
351
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: {
352
+ handler: HookHandlers<TBot>[THookType][THookDataName];
353
+ order: number;
354
+ }[];
355
+ };
356
+ };
357
+ export type OrderedWorkflowHandlersMap<TBot extends common.BaseBot> = {
358
+ [TWorkflowUpdateType in WorkflowUpdateType]: {
359
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: {
360
+ handler: WorkflowHandlers<TBot>[TWorkflowName];
361
+ order: number;
362
+ }[];
363
+ };
364
+ };
365
+ export type RegisterHandler<TBot extends common.BaseBot> = (props: CommonHandlerProps<TBot>) => Promise<void>;
366
+ /**
367
+ * Bot handlers without InjectedHandlerProps
368
+ *
369
+ * TODO:
370
+ * the consumer of this type shouldnt be able to access "*" directly;
371
+ * "*" is meant the user who registers an handler, not for the user who calls the handler
372
+ */
373
+ export type BotHandlers<TBot extends common.BaseBot> = {
374
+ registerHandler?: RegisterHandler<TBot>;
375
+ actionHandlers: ActionHandlersMap<TBot>;
376
+ messageHandlers: MessageHandlersMap<TBot>;
377
+ eventHandlers: EventHandlersMap<TBot>;
378
+ stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
379
+ hookHandlers: HookHandlersMap<TBot>;
380
+ workflowHandlers: WorkflowHandlersMap<TBot>;
381
+ };
382
+ /** identical to BotHandlers, but contains the injected properties */
383
+ export type InjectedBotHandlers<TBot extends common.BaseBot> = {
384
+ registerHandler?: RegisterHandler<TBot>;
385
+ actionHandlers: ActionHandlers<TBot>;
386
+ messageHandlers: {
387
+ [TMessageName in utils.StringKeys<IncomingMessages<TBot>>]?: MessageHandlers<TBot>[TMessageName][];
388
+ };
389
+ eventHandlers: {
390
+ [TEventName in utils.StringKeys<IncomingEvents<TBot>>]?: EventHandlers<TBot>[TEventName][];
391
+ };
392
+ stateExpiredHandlers: {
393
+ [TStateName in utils.StringKeys<IncomingStates<TBot>>]?: StateExpiredHandlers<TBot>[TStateName][];
394
+ };
395
+ hookHandlers: {
396
+ [THookType in utils.StringKeys<HookData<TBot>>]: {
397
+ [THookDataName in utils.StringKeys<HookData<TBot>[THookType]>]?: HookHandlers<TBot>[THookType][THookDataName][];
398
+ };
399
+ };
400
+ workflowHandlers: {
401
+ [TWorkflowUpdateType in WorkflowUpdateType]: {
402
+ [TWorkflowName in utils.StringKeys<TBot['workflows']>]?: WorkflowHandlers<TBot>[TWorkflowName][];
403
+ };
404
+ };
405
+ };
406
+ type _GetPluginPrefix<TKey extends string> = `${TKey}#`;
407
+ type ImplementedActions<_TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = utils.UnionToIntersection<utils.ValueOf<{
408
+ [TPlugin in utils.StringKeys<TPlugins>]: {
409
+ [TAction in utils.StringKeys<TPlugins[TPlugin]['actions']> as `${_GetPluginPrefix<utils.Cast<TPlugin, string>>}${utils.Cast<TAction, string>}`]: TPlugins[TPlugin]['actions'][TAction];
410
+ };
411
+ }>>;
412
+ type UnimplementedActions<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = Omit<TBot['actions'], utils.StringKeys<ImplementedActions<TBot, TPlugins>>>;
413
+ export type ImplementedActionHandlers<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
414
+ [K in utils.StringKeys<ImplementedActions<TBot, TPlugins>>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
415
+ };
416
+ export type UnimplementedActionHandlers<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
417
+ [K in utils.StringKeys<UnimplementedActions<TBot, TPlugins>>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
418
+ };
419
+ export type ServerProps = CommonHandlerProps<common.BaseBot> & {
420
+ req: Request;
421
+ self: BotHandlers<common.BaseBot>;
422
+ };
423
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Response } from '../../../serve';
2
+ import * as types from '../types';
3
+ export declare const handleWorkflowUpdateEvent: (rawProps: types.ServerProps, event: types.WorkflowUpdateEvent) => Promise<Response>;
@@ -0,0 +1,2 @@
1
+ import * as types from '../types';
2
+ export declare const bridgeUpdateTypeToSnakeCase: (updateType: types.BridgeWorkflowUpdateType) => types.WorkflowUpdateType;
@@ -0,0 +1,2 @@
1
+ export * from './proxy';
2
+ export * from './types';
@@ -0,0 +1,17 @@
1
+ import type * as client from '@holocronlab/botruntime-client';
2
+ import type { BotSpecificClient } from '../../bot';
3
+ import type * as typeUtils from '../../utils/type-utils';
4
+ import type { BaseBot } from '../common';
5
+ import * as botServerTypes from '../server/types';
6
+ import type { WorkflowProxy, ActionableWorkflow } from './types';
7
+ export declare const proxyWorkflows: <TBot extends BaseBot>(props: {
8
+ client: BotSpecificClient<TBot> | client.Client;
9
+ pluginAlias?: string;
10
+ }) => WorkflowProxy<TBot>;
11
+ export declare const wrapWorkflowInstance: <TBot extends BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot["workflows"]>>(props: {
12
+ client: BotSpecificClient<TBot> | client.Client;
13
+ workflow: client.Workflow;
14
+ event?: botServerTypes.WorkflowUpdateEvent;
15
+ onWorkflowUpdate?: (newState: client.Workflow) => Promise<void> | void;
16
+ pluginAlias?: string;
17
+ }) => ActionableWorkflow<TBot, TWorkflowName>;
@@ -0,0 +1,80 @@
1
+ import type * as client from '@holocronlab/botruntime-client';
2
+ import { AsyncCollection } from '../../utils/api-paging-utils';
3
+ import type * as typeUtils from '../../utils/type-utils';
4
+ import type * as commonTypes from '../common';
5
+ export type WorkflowProxy<TBot extends commonTypes.BaseBot = commonTypes.BaseBot> = Readonly<{
6
+ [TWorkflowName in typeUtils.StringKeys<TBot['workflows']>]: Readonly<{
7
+ startNewInstance: (x: Pick<client.ClientInputs['createWorkflow'], 'conversationId' | 'userId' | 'timeoutAt'> & {
8
+ tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
9
+ input: TBot['workflows'][TWorkflowName]['input'];
10
+ }) => Promise<Readonly<Omit<client.ClientOutputs['createWorkflow'], 'workflow'> & {
11
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
12
+ }>>;
13
+ listInstances: (x?: Pick<client.ClientInputs['listWorkflows'], 'conversationId' | 'userId'> & {
14
+ tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
15
+ /**
16
+ * Filter by statuses:
17
+ *
18
+ * - `pending` - Workflow is created but not started yet
19
+ * - `in_progress` - Workflow is currently running
20
+ * - `failed` - Workflow finished with errors
21
+ * - `completed` - Workflow finished successfully
22
+ * - `cancelled` - Workflow finished due to cancellation through the API
23
+ * - `timedout` - Workflow finished due to timeout
24
+ * - `listening` - Workflow is waiting for an event to continue
25
+ * - `paused` - Workflow was paused through the API
26
+ */
27
+ statuses?: client.Workflow['status'][];
28
+ }) => AsyncCollection<ActionableWorkflow<TBot, TWorkflowName>>;
29
+ }>;
30
+ }>;
31
+ export type ActionableWorkflow<TBot extends commonTypes.BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot['workflows']>> = Readonly<client.Workflow & {
32
+ name: TWorkflowName;
33
+ input: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['input'];
34
+ output: Partial<typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output']>;
35
+ tags: Partial<TBot['workflows'][TWorkflowName]['tags']>;
36
+ /**
37
+ * Updates the current workflow instance
38
+ */
39
+ update(x: typeUtils.AtLeastOneProperty<Pick<client.ClientInputs['updateWorkflow'], 'userId' | 'timeoutAt'> & {
40
+ tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
41
+ output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
42
+ }>): Promise<{
43
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
44
+ }>;
45
+ /**
46
+ * Acknowledges the start of processing for a pending workflow instance.
47
+ * If the workflow is not in pending status or has already been
48
+ * acknowledged, this is a no-op.
49
+ *
50
+ * This method **should be called in every workflow handler** as soon as the
51
+ * workflow **starts doing work**. If no work needs to be done, setCompleted
52
+ * or setFailed should be called instead.
53
+ *
54
+ * Should a workflow not be acknowledged **in a timely fashion**, it will be
55
+ * retriggered 3 times before being marked as failed.
56
+ */
57
+ acknowledgeStartOfProcessing(): Promise<{
58
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
59
+ }>;
60
+ /**
61
+ * Marks the current workflow instance as failed and stops execution
62
+ */
63
+ setFailed(x: Required<Pick<client.ClientInputs['updateWorkflow'], 'failureReason'>>): Promise<{
64
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
65
+ }>;
66
+ /**
67
+ * Marks the current workflow instance as completed and stops execution
68
+ */
69
+ setCompleted(x?: {
70
+ output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
71
+ }): Promise<{
72
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
73
+ }>;
74
+ /**
75
+ * Discards all output data and cancels the current workflow instance
76
+ */
77
+ cancel(): Promise<{
78
+ workflow: ActionableWorkflow<TBot, TWorkflowName>;
79
+ }>;
80
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export type * as commonTypes from './types';
@@ -0,0 +1,9 @@
1
+ import { BotDefinitionProps, EventDefinition } from '../bot/definition';
2
+ import { SafeOmit } from '../utils/type-utils';
3
+ type StrippedEvents<TEvents extends Record<string, EventDefinition>> = {
4
+ [K in keyof TEvents]: SafeOmit<TEvents[K], 'recurrence'>;
5
+ };
6
+ export declare function stripRecurringFromEvents<TEvents extends Record<string, EventDefinition>>(events: TEvents): StrippedEvents<TEvents>;
7
+ export declare function stripRecurringFromEvents<TEvents extends Record<string, EventDefinition>>(events: TEvents | undefined): StrippedEvents<TEvents> | undefined;
8
+ export declare function resolveRecurringEvents(events: Record<string, EventDefinition> | undefined, explicitRecurringEvents: BotDefinitionProps['recurringEvents']): BotDefinitionProps['recurringEvents'];
9
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import * as typeUtils from '../utils/type-utils';
2
+ import { z } from '../zui';
3
+ export type ToTags<TTags extends string | number | symbol> = typeUtils.Cast<Partial<Record<TTags, string>>, Record<string, string>>;
4
+ export type ToNullableTags<TTags extends string | number | symbol> = typeUtils.Cast<Partial<Record<TTags, string | null>>, Record<string, string | null>>;
5
+ export type SchemaTransformOptions = {
6
+ useLegacyZuiTransformer?: boolean;
7
+ toJSONSchemaOptions?: Partial<z.transforms.JSONSchemaGenerationOptions>;
8
+ };
@@ -0,0 +1,11 @@
1
+ export * from './public-consts';
2
+ export declare const PLUGIN_PREFIX_SEPARATOR = "#";
3
+ export declare const BOT_ID_HEADER = "x-bot-id";
4
+ export declare const BOT_USER_ID_HEADER = "x-bot-user-id";
5
+ export declare const INTEGRATION_ID_HEADER = "x-integration-id";
6
+ export declare const INTEGRATION_ALIAS_HEADER = "x-integration-alias";
7
+ export declare const WEBHOOK_ID_HEADER = "x-webhook-id";
8
+ export declare const CONFIGURATION_TYPE_HEADER = "x-bp-configuration-type";
9
+ export declare const CONFIGURATION_PAYLOAD_HEADER = "x-bp-configuration";
10
+ export declare const OPERATION_TYPE_HEADER = "x-bp-operation";
11
+ export declare const OPERATION_SUBTYPE_HEADER = "x-bp-type";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Thrown by SDK definition classes (BotDefinition, IntegrationDefinition, PluginDefinition, etc.)
3
+ * for intentional validation errors whose message is already clear.
4
+ *
5
+ * The CLI detects this class to suppress the "Offending code:" section that it normally
6
+ * appends to errors thrown during definition file evaluation.
7
+ */
8
+ export declare class DefinitionError extends Error {
9
+ /** @internal Marker used by {@link isDefinitionError} to survive esbuild bundle boundaries. */
10
+ readonly __IS_SDK_ERROR__: true;
11
+ readonly type: "definition_error";
12
+ }
13
+ /**
14
+ * Type guard to detect {@link DefinitionError} across esbuild bundle boundaries.
15
+ *
16
+ * Tries `instanceof` first (same bundle), then falls back to the `__IS_SDK_ERROR__` marker
17
+ * and `type` field for cross-bundle cases where esbuild inlines a separate copy of the SDK class.
18
+ */
19
+ export declare const isDefinitionError: (error: unknown) => error is DefinitionError;