@botpress/sdk 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -4
- package/dist/bot/client/index.d.ts +5 -0
- package/dist/bot/client/types.d.ts +16 -0
- package/dist/bot/common/generic.d.ts +9 -0
- package/dist/bot/definition.d.ts +23 -4
- package/dist/bot/implementation.d.ts +8 -1
- package/dist/bot/server/responses.d.ts +3 -0
- package/dist/bot/server/types.d.ts +54 -1
- package/dist/bot/server/workflows/update-handler.d.ts +3 -0
- package/dist/bot/server/workflows/update-type-conv.d.ts +3 -0
- package/dist/bot/workflow-proxy/index.d.ts +2 -0
- package/dist/bot/workflow-proxy/proxy.d.ts +10 -0
- package/dist/bot/workflow-proxy/types.d.ts +64 -0
- package/dist/bot/workflow-proxy/types.test.d.ts +1 -0
- package/dist/fixtures.d.ts +30 -0
- package/dist/index.cjs +22 -22
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +43 -43
- package/dist/index.mjs.map +4 -4
- package/dist/package.d.ts +1 -0
- package/dist/plugin/common/generic.d.ts +11 -103
- package/dist/plugin/definition.d.ts +15 -6
- package/dist/plugin/implementation.d.ts +21 -2
- package/dist/plugin/server/types.d.ts +9 -2
- package/dist/utils/record-utils.d.ts +1 -0
- package/dist/utils/type-utils.d.ts +3 -2
- package/package.json +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/sdk@3.
|
|
2
|
+
> @botpress/sdk@3.5.0 build /home/runner/work/botpress/botpress/packages/sdk
|
|
3
3
|
> pnpm build:type && pnpm build:node && pnpm build:browser
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @botpress/sdk@3.
|
|
6
|
+
> @botpress/sdk@3.5.0 build:type /home/runner/work/botpress/botpress/packages/sdk
|
|
7
7
|
> tsc --emitDeclarationOnly --declaration
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
> @botpress/sdk@3.
|
|
10
|
+
> @botpress/sdk@3.5.0 build:node /home/runner/work/botpress/botpress/packages/sdk
|
|
11
11
|
> ts-node -T ./build.ts --node
|
|
12
12
|
|
|
13
13
|
Done
|
|
14
14
|
|
|
15
|
-
> @botpress/sdk@3.
|
|
15
|
+
> @botpress/sdk@3.5.0 build:browser /home/runner/work/botpress/botpress/packages/sdk
|
|
16
16
|
> ts-node -T ./build.ts --browser
|
|
17
17
|
|
|
18
18
|
Done
|
|
@@ -49,6 +49,11 @@ export declare class BotSpecificClient<TBot extends common.BaseBot> implements t
|
|
|
49
49
|
deleteTableRows: types.DeleteTableRows<TBot>;
|
|
50
50
|
updateTableRows: types.UpdateTableRows<TBot>;
|
|
51
51
|
upsertTableRows: types.UpsertTableRows<TBot>;
|
|
52
|
+
createWorkflow: types.CreateWorkflow<TBot>;
|
|
53
|
+
getWorkflow: types.GetWorkflow<TBot>;
|
|
54
|
+
updateWorkflow: types.UpdateWorkflow<TBot>;
|
|
55
|
+
deleteWorkflow: types.DeleteWorkflow<TBot>;
|
|
56
|
+
listWorkflows: types.ListWorkflows<TBot>;
|
|
52
57
|
/**
|
|
53
58
|
* @deprecated Use `callAction` to delegate the conversation creation to an integration.
|
|
54
59
|
*/
|
|
@@ -90,6 +90,22 @@ export type ListFiles<_TBot extends common.BaseBot> = client.Client['listFiles']
|
|
|
90
90
|
export type GetFile<_TBot extends common.BaseBot> = client.Client['getFile'];
|
|
91
91
|
export type UpdateFileMetadata<_TBot extends common.BaseBot> = client.Client['updateFileMetadata'];
|
|
92
92
|
export type SearchFiles<_TBot extends common.BaseBot> = client.Client['searchFiles'];
|
|
93
|
+
export type CreateWorkflow<TBot extends common.BaseBot> = <TWorkflowName extends utils.StringKeys<TBot['workflows']>>(x: utils.Merge<Arg<client.Client['createWorkflow']>, {
|
|
94
|
+
name: utils.Cast<TWorkflowName, string>;
|
|
95
|
+
input: utils.Cast<TBot['workflows'][TWorkflowName], common.IntegrationInstanceActionDefinition>['input'];
|
|
96
|
+
tags?: utils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
|
|
97
|
+
}>) => Promise<Readonly<{
|
|
98
|
+
workflow: utils.Merge<Awaited<Res<client.Client['createWorkflow']>>['workflow'], {
|
|
99
|
+
name: NoInfer<TWorkflowName>;
|
|
100
|
+
}>;
|
|
101
|
+
}>>;
|
|
102
|
+
export type GetWorkflow<_TBot extends common.BaseBot> = client.Client['getWorkflow'];
|
|
103
|
+
export type UpdateWorkflow<_TBot extends common.BaseBot> = client.Client['updateWorkflow'];
|
|
104
|
+
export type DeleteWorkflow<_TBot extends common.BaseBot> = client.Client['deleteWorkflow'];
|
|
105
|
+
export type ListWorkflows<TBot extends common.BaseBot> = <TWorkflowName extends utils.StringKeys<TBot['workflows']>>(x: utils.Merge<Arg<client.Client['listWorkflows']>, {
|
|
106
|
+
name?: utils.Cast<TWorkflowName, string>;
|
|
107
|
+
tags?: utils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
|
|
108
|
+
}>) => Promise<Readonly<Awaited<Res<client.Client['listWorkflows']>>>>;
|
|
93
109
|
export type GetTableRow<TBot extends common.BaseBot> = <TableName extends keyof common.EnumerateTables<TBot>, Columns = utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>>>(x: utils.Merge<Arg<client.Client['getTableRow']>, {
|
|
94
110
|
table: utils.Cast<TableName, string>;
|
|
95
111
|
id: client.Row['id'];
|
|
@@ -8,12 +8,20 @@ export type BaseAction = {
|
|
|
8
8
|
export type BaseTable = {
|
|
9
9
|
[k: string]: any;
|
|
10
10
|
};
|
|
11
|
+
export type BaseWorkflow = {
|
|
12
|
+
input: any;
|
|
13
|
+
output: any;
|
|
14
|
+
tags?: {
|
|
15
|
+
[k: string]: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
11
18
|
export type BaseBot = {
|
|
12
19
|
integrations: Record<string, BaseIntegration>;
|
|
13
20
|
events: Record<string, any>;
|
|
14
21
|
states: Record<string, any>;
|
|
15
22
|
actions: Record<string, BaseAction>;
|
|
16
23
|
tables: Record<string, BaseTable>;
|
|
24
|
+
workflows: Record<string, BaseWorkflow>;
|
|
17
25
|
};
|
|
18
26
|
export type InputBaseBot = utils.DeepPartial<BaseBot>;
|
|
19
27
|
export type DefaultBot<B extends InputBaseBot> = {
|
|
@@ -24,4 +32,5 @@ export type DefaultBot<B extends InputBaseBot> = {
|
|
|
24
32
|
[K in keyof B['integrations']]: DefaultIntegration<utils.Cast<B['integrations'][K], InputBaseIntegration>>;
|
|
25
33
|
};
|
|
26
34
|
tables: utils.Default<B['tables'], BaseBot['tables']>;
|
|
35
|
+
workflows: utils.Default<B['workflows'], BaseBot['workflows']>;
|
|
27
36
|
};
|
package/dist/bot/definition.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ type BaseStates = Record<string, ZuiObjectSchema>;
|
|
|
9
9
|
type BaseEvents = Record<string, ZuiObjectSchema>;
|
|
10
10
|
type BaseActions = Record<string, ZuiObjectSchema>;
|
|
11
11
|
type BaseTables = Record<string, ZuiObjectSchema>;
|
|
12
|
+
type BaseWorkflows = Record<string, ZuiObjectSchema>;
|
|
12
13
|
export type TagDefinition = {
|
|
13
14
|
title?: string;
|
|
14
15
|
description?: string;
|
|
@@ -44,6 +45,13 @@ export type ActionDefinition<TAction extends BaseActions[string] = BaseActions[s
|
|
|
44
45
|
input: SchemaDefinition<TAction>;
|
|
45
46
|
output: SchemaDefinition<ZuiObjectSchema>;
|
|
46
47
|
};
|
|
48
|
+
export type WorkflowDefinition<TWorkflow extends BaseWorkflows[string] = BaseWorkflows[string]> = {
|
|
49
|
+
title?: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
input: SchemaDefinition<TWorkflow>;
|
|
52
|
+
output: SchemaDefinition<ZuiObjectSchema>;
|
|
53
|
+
tags?: Record<string, TagDefinition>;
|
|
54
|
+
};
|
|
47
55
|
export type TableDefinition<TTable extends BaseTables[string] = BaseTables[string]> = Merge<Omit<Table, 'id' | 'createdAt' | 'updatedAt' | 'name'>, {
|
|
48
56
|
schema: TTable;
|
|
49
57
|
}>;
|
|
@@ -59,6 +67,7 @@ export type IntegrationConfigInstance<I extends IntegrationPackage = Integration
|
|
|
59
67
|
};
|
|
60
68
|
}>);
|
|
61
69
|
export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
|
|
70
|
+
alias?: string;
|
|
62
71
|
configuration: z.infer<NonNullable<P['definition']['configuration']>['schema']>;
|
|
63
72
|
interfaces: {
|
|
64
73
|
[I in keyof NonNullable<P['definition']['interfaces']>]: PluginInterfaceExtension;
|
|
@@ -66,7 +75,7 @@ export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
|
|
|
66
75
|
};
|
|
67
76
|
export type IntegrationInstance = IntegrationPackage & IntegrationConfigInstance;
|
|
68
77
|
export type PluginInstance = PluginPackage & PluginConfigInstance;
|
|
69
|
-
export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables> = {
|
|
78
|
+
export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> = {
|
|
70
79
|
integrations?: {
|
|
71
80
|
[K: string]: IntegrationInstance;
|
|
72
81
|
};
|
|
@@ -90,9 +99,16 @@ export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents
|
|
|
90
99
|
tables?: {
|
|
91
100
|
[K in keyof TTables]: TableDefinition<TTables[K]>;
|
|
92
101
|
};
|
|
102
|
+
/**
|
|
103
|
+
* # EXPERIMENTAL
|
|
104
|
+
* This API is experimental and may change in the future.
|
|
105
|
+
*/
|
|
106
|
+
workflows?: {
|
|
107
|
+
[K in keyof TWorkflows]: WorkflowDefinition<TWorkflows[K]>;
|
|
108
|
+
};
|
|
93
109
|
};
|
|
94
|
-
export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables> {
|
|
95
|
-
readonly props: BotDefinitionProps<TStates, TEvents, TActions, TTables>;
|
|
110
|
+
export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables, TWorkflows extends BaseWorkflows = BaseWorkflows> {
|
|
111
|
+
readonly props: BotDefinitionProps<TStates, TEvents, TActions, TTables, TWorkflows>;
|
|
96
112
|
readonly integrations: this['props']['integrations'];
|
|
97
113
|
readonly plugins: this['props']['plugins'];
|
|
98
114
|
readonly user: this['props']['user'];
|
|
@@ -104,7 +120,8 @@ export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEve
|
|
|
104
120
|
readonly recurringEvents: this['props']['recurringEvents'];
|
|
105
121
|
readonly actions: this['props']['actions'];
|
|
106
122
|
readonly tables: this['props']['tables'];
|
|
107
|
-
|
|
123
|
+
readonly workflows: this['props']['workflows'];
|
|
124
|
+
constructor(props: BotDefinitionProps<TStates, TEvents, TActions, TTables, TWorkflows>);
|
|
108
125
|
addIntegration<I extends IntegrationPackage>(integrationPkg: I, config: IntegrationConfigInstance<I>): this;
|
|
109
126
|
addPlugin<P extends PluginPackage>(pluginPkg: P, config: PluginConfigInstance<P>): this;
|
|
110
127
|
private _mergeUser;
|
|
@@ -115,5 +132,7 @@ export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEve
|
|
|
115
132
|
private _mergeRecurringEvents;
|
|
116
133
|
private _mergeActions;
|
|
117
134
|
private _mergeTables;
|
|
135
|
+
private _mergeWorkflows;
|
|
136
|
+
private _prefixKeys;
|
|
118
137
|
}
|
|
119
138
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Server } from 'node:http';
|
|
2
2
|
import { BasePlugin, PluginImplementation } from '../plugin';
|
|
3
3
|
import { BaseBot } from './common';
|
|
4
|
-
import { MessageHandlersMap, MessageHandlers, EventHandlersMap, EventHandlers, StateExpiredHandlersMap, StateExpiredHandlers, HookHandlersMap, HookData, HookHandlers, ActionHandlers, BotHandlers, UnimplementedActionHandlers } from './server';
|
|
4
|
+
import { type MessageHandlersMap, type MessageHandlers, type EventHandlersMap, type EventHandlers, type StateExpiredHandlersMap, type StateExpiredHandlers, type HookHandlersMap, type HookData, type HookHandlers, type ActionHandlers, type BotHandlers, type UnimplementedActionHandlers, type WorkflowHandlersMap, type WorkflowHandlersFnMap } from './server';
|
|
5
5
|
export type BotImplementationProps<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> = {
|
|
6
6
|
actions: UnimplementedActionHandlers<TBot, TPlugins>;
|
|
7
7
|
plugins: {
|
|
@@ -15,6 +15,7 @@ export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins
|
|
|
15
15
|
private _eventHandlers;
|
|
16
16
|
private _stateExpiredHandlers;
|
|
17
17
|
private _hookHandlers;
|
|
18
|
+
private _workflowHandlers;
|
|
18
19
|
private _plugins;
|
|
19
20
|
constructor(props: BotImplementationProps<TBot, TPlugins>);
|
|
20
21
|
get actionHandlers(): ActionHandlers<TBot>;
|
|
@@ -22,8 +23,14 @@ export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins
|
|
|
22
23
|
get eventHandlers(): EventHandlersMap<TBot>;
|
|
23
24
|
get stateExpiredHandlers(): StateExpiredHandlersMap<TBot>;
|
|
24
25
|
get hookHandlers(): HookHandlersMap<TBot>;
|
|
26
|
+
get workflowHandlers(): WorkflowHandlersMap<TBot>;
|
|
25
27
|
readonly on: {
|
|
26
28
|
message: <T extends keyof MessageHandlersMap<TBot>>(type: T, handler: MessageHandlers<TBot>[T]) => void;
|
|
29
|
+
/**
|
|
30
|
+
* # EXPERIMENTAL
|
|
31
|
+
* This API is experimental and may change in the future.
|
|
32
|
+
*/
|
|
33
|
+
workflows: WorkflowHandlersFnMap<TBot>;
|
|
27
34
|
event: <T extends keyof EventHandlersMap<TBot>>(type: T, handler: EventHandlers<TBot>[T]) => void;
|
|
28
35
|
stateExpired: <T extends keyof StateExpiredHandlersMap<TBot>>(type: T, handler: StateExpiredHandlers<TBot>[T]) => void;
|
|
29
36
|
beforeIncomingEvent: <T extends keyof HookData<TBot>["before_incoming_event"]>(type: T, handler: HookHandlers<TBot>["before_incoming_event"][T]) => void;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as client from '@botpress/client';
|
|
2
2
|
import * as plugin from '../../plugin';
|
|
3
|
+
import type { Request } from '../../serve';
|
|
3
4
|
import * as utils from '../../utils/type-utils';
|
|
4
5
|
import { type BotLogger } from '../bot-logger';
|
|
5
6
|
import { BotSpecificClient } from '../client';
|
|
6
7
|
import * as common from '../common';
|
|
8
|
+
import type * as workflowProxy from '../workflow-proxy/types';
|
|
7
9
|
export type BotOperation = 'event_received' | 'register' | 'unregister' | 'ping' | 'action_triggered';
|
|
8
10
|
export type BotContext = {
|
|
9
11
|
botId: string;
|
|
@@ -88,6 +90,11 @@ export type CommonHandlerProps<TBot extends common.BaseBot> = {
|
|
|
88
90
|
ctx: BotContext;
|
|
89
91
|
logger: BotLogger;
|
|
90
92
|
client: BotClient<TBot>;
|
|
93
|
+
/**
|
|
94
|
+
* # EXPERIMENTAL
|
|
95
|
+
* This API is experimental and may change in the future.
|
|
96
|
+
*/
|
|
97
|
+
workflows: workflowProxy.WorkflowProxy<TBot>;
|
|
91
98
|
};
|
|
92
99
|
export type MessagePayloads<TBot extends common.BaseBot> = {
|
|
93
100
|
[K in keyof IncomingMessages<TBot>]: CommonHandlerProps<TBot> & {
|
|
@@ -131,6 +138,18 @@ export type ActionHandlerPayloads<TBot extends common.BaseBot> = {
|
|
|
131
138
|
export type ActionHandlers<TBot extends common.BaseBot> = {
|
|
132
139
|
[K in keyof TBot['actions']]: (props: ActionHandlerPayloads<TBot>[K]) => Promise<TBot['actions'][K]['output']>;
|
|
133
140
|
};
|
|
141
|
+
export type BridgeWorkflowUpdateType = 'child_workflow_deleted' | 'child_workflow_finished' | 'workflow_timedout' | 'workflow_started' | 'workflow_continued';
|
|
142
|
+
export type WorkflowUpdateEventPayload = {
|
|
143
|
+
type: BridgeWorkflowUpdateType;
|
|
144
|
+
childWorkflow?: client.Workflow;
|
|
145
|
+
workflow: client.Workflow;
|
|
146
|
+
conversation?: client.Conversation;
|
|
147
|
+
user?: client.User;
|
|
148
|
+
};
|
|
149
|
+
export type WorkflowUpdateEvent = utils.Merge<client.Event, {
|
|
150
|
+
type: 'workflow_update';
|
|
151
|
+
payload: WorkflowUpdateEventPayload;
|
|
152
|
+
}>;
|
|
134
153
|
type BaseHookDefinition = {
|
|
135
154
|
stoppable?: boolean;
|
|
136
155
|
data: any;
|
|
@@ -235,6 +254,32 @@ export type HookHandlersMap<TBot extends common.BaseBot> = {
|
|
|
235
254
|
[T in keyof HookData<TBot>[H]]?: HookHandlers<TBot>[H][T][];
|
|
236
255
|
};
|
|
237
256
|
};
|
|
257
|
+
export type WorkflowPayloads<TBot extends common.BaseBot, TExtraTools extends object = {}> = {
|
|
258
|
+
[WorkflowName in utils.StringKeys<TBot['workflows']>]: CommonHandlerProps<TBot> & {
|
|
259
|
+
conversation?: client.Conversation;
|
|
260
|
+
user?: client.User;
|
|
261
|
+
/**
|
|
262
|
+
* # EXPERIMENTAL
|
|
263
|
+
* This API is experimental and may change in the future.
|
|
264
|
+
*/
|
|
265
|
+
workflow: workflowProxy.WorkflowWithUtilities<TBot, WorkflowName>;
|
|
266
|
+
} & TExtraTools;
|
|
267
|
+
};
|
|
268
|
+
export type WorkflowHandlers<TBot extends common.BaseBot, TExtraTools extends object = {}> = {
|
|
269
|
+
[K in utils.StringKeys<TBot['workflows']>]: (props: WorkflowPayloads<TBot, TExtraTools>[K]) => Promise<void>;
|
|
270
|
+
};
|
|
271
|
+
export type WorkflowUpdateTypeSnakeCase = 'started' | 'continued' | 'timed_out';
|
|
272
|
+
export type WorkflowUpdateTypeCamelCase = 'started' | 'continued' | 'timedOut';
|
|
273
|
+
export type WorkflowHandlersMap<TBot extends common.BaseBot, TExtraTools extends object = {}> = {
|
|
274
|
+
[UpdateType in WorkflowUpdateTypeSnakeCase]?: {
|
|
275
|
+
[WorkflowName in utils.StringKeys<TBot['workflows']>]?: WorkflowHandlers<TBot, TExtraTools>[WorkflowName][];
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
export type WorkflowHandlersFnMap<TBot extends common.BaseBot, TExtraTools extends object = {}> = {
|
|
279
|
+
[WorkflowName in utils.StringKeys<TBot['workflows']>]: {
|
|
280
|
+
[UType in WorkflowUpdateTypeCamelCase]: (handler: WorkflowHandlers<TBot, TExtraTools>[WorkflowName]) => void;
|
|
281
|
+
};
|
|
282
|
+
};
|
|
238
283
|
/**
|
|
239
284
|
* TODO:
|
|
240
285
|
* the consumer of this type shouldnt be able to access "*" directly;
|
|
@@ -246,9 +291,13 @@ export type BotHandlers<TBot extends common.BaseBot> = {
|
|
|
246
291
|
eventHandlers: EventHandlersMap<TBot>;
|
|
247
292
|
stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
|
|
248
293
|
hookHandlers: HookHandlersMap<TBot>;
|
|
294
|
+
workflowHandlers: WorkflowHandlersMap<TBot>;
|
|
249
295
|
};
|
|
296
|
+
type _GetPluginPrefix<TKey extends string, TPlugin extends plugin.BasePlugin> = TKey extends TPlugin['name'] ? '' : `${TKey}#`;
|
|
250
297
|
type ImplementedActions<_TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = utils.UnionToIntersection<utils.ValueOf<{
|
|
251
|
-
[
|
|
298
|
+
[TPlugin in keyof TPlugins]: {
|
|
299
|
+
[TAction in keyof TPlugins[TPlugin]['actions'] as `${_GetPluginPrefix<utils.Cast<TPlugin, string>, TPlugins[TPlugin]>}${utils.Cast<TAction, string>}`]: TPlugins[TPlugin]['actions'][TAction];
|
|
300
|
+
};
|
|
252
301
|
}>>;
|
|
253
302
|
type UnimplementedActions<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = Omit<TBot['actions'], keyof ImplementedActions<TBot, TPlugins>>;
|
|
254
303
|
export type ImplementedActionHandlers<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
|
|
@@ -257,4 +306,8 @@ export type ImplementedActionHandlers<TBot extends common.BaseBot, TPlugins exte
|
|
|
257
306
|
export type UnimplementedActionHandlers<TBot extends common.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = {
|
|
258
307
|
[K in keyof UnimplementedActions<TBot, TPlugins>]: ActionHandlers<TBot>[utils.Cast<K, keyof ActionHandlers<TBot>>];
|
|
259
308
|
};
|
|
309
|
+
export type ServerProps = Omit<CommonHandlerProps<common.BaseBot>, 'workflows'> & {
|
|
310
|
+
req: Request;
|
|
311
|
+
self: BotHandlers<common.BaseBot>;
|
|
312
|
+
};
|
|
260
313
|
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as types from '../types';
|
|
2
|
+
export declare const bridgeUpdateTypeToSnakeCase: (updateType: types.BridgeWorkflowUpdateType) => types.WorkflowUpdateTypeSnakeCase;
|
|
3
|
+
export declare const camelCaseUpdateTypeToSnakeCase: (updateType: types.WorkflowUpdateTypeCamelCase) => types.WorkflowUpdateTypeSnakeCase;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as client from '@botpress/client';
|
|
2
|
+
import type { BotSpecificClient } from '../../bot';
|
|
3
|
+
import type * as typeUtils from '../../utils/type-utils';
|
|
4
|
+
import type { BaseBot } from '../common';
|
|
5
|
+
import type { WorkflowProxy, WorkflowWithUtilities } from './types';
|
|
6
|
+
export declare const proxyWorkflows: <TBot extends BaseBot>(client: BotSpecificClient<TBot> | client.Client) => WorkflowProxy<TBot>;
|
|
7
|
+
export declare const wrapWorkflowInstance: <TBot extends BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot["workflows"]>>(props: {
|
|
8
|
+
client: BotSpecificClient<TBot> | client.Client;
|
|
9
|
+
workflow: client.Workflow;
|
|
10
|
+
}) => WorkflowWithUtilities<TBot, TWorkflowName>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type * as client from '@botpress/client';
|
|
2
|
+
import type * as typeUtils from '../../utils/type-utils';
|
|
3
|
+
import type * as commonTypes from '../common';
|
|
4
|
+
export type WorkflowProxy<TBot extends commonTypes.BaseBot = commonTypes.BaseBot> = Readonly<{
|
|
5
|
+
[TWorkflowName in typeUtils.StringKeys<TBot['workflows']>]: Readonly<{
|
|
6
|
+
startNewInstance: (x: Pick<client.ClientInputs['createWorkflow'], 'conversationId' | 'userId' | 'timeoutAt'> & {
|
|
7
|
+
tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
|
|
8
|
+
input: TBot['workflows'][TWorkflowName]['input'];
|
|
9
|
+
}) => Promise<Readonly<Omit<client.ClientOutputs['createWorkflow'], 'workflow'> & {
|
|
10
|
+
workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
|
|
11
|
+
}>>;
|
|
12
|
+
listInstances: Readonly<{
|
|
13
|
+
all: _ListInstances<TBot, TWorkflowName>;
|
|
14
|
+
running: _ListInstances<TBot, TWorkflowName>;
|
|
15
|
+
scheduled: _ListInstances<TBot, TWorkflowName>;
|
|
16
|
+
allFinished: _ListInstances<TBot, TWorkflowName>;
|
|
17
|
+
succeeded: _ListInstances<TBot, TWorkflowName>;
|
|
18
|
+
cancelled: _ListInstances<TBot, TWorkflowName>;
|
|
19
|
+
timedOut: _ListInstances<TBot, TWorkflowName>;
|
|
20
|
+
failed: _ListInstances<TBot, TWorkflowName>;
|
|
21
|
+
}>;
|
|
22
|
+
}>;
|
|
23
|
+
}>;
|
|
24
|
+
type _ListInstances<TBot extends commonTypes.BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot['workflows']>> = (x?: Pick<client.ClientInputs['listWorkflows'], 'nextToken' | 'conversationId' | 'userId'> & {
|
|
25
|
+
tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
|
|
26
|
+
}) => Promise<Readonly<Omit<client.ClientOutputs['listWorkflows'], 'workflows'> & {
|
|
27
|
+
workflows: WorkflowWithUtilities<TBot, TWorkflowName>[];
|
|
28
|
+
}>>;
|
|
29
|
+
export type WorkflowWithUtilities<TBot extends commonTypes.BaseBot, TWorkflowName extends typeUtils.StringKeys<TBot['workflows']>> = Readonly<client.Workflow & {
|
|
30
|
+
name: TWorkflowName;
|
|
31
|
+
input: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['input'];
|
|
32
|
+
output: Partial<typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output']>;
|
|
33
|
+
tags: Partial<TBot['workflows'][TWorkflowName]['tags']>;
|
|
34
|
+
/**
|
|
35
|
+
* Updates the current workflow instance
|
|
36
|
+
*/
|
|
37
|
+
update(x: typeUtils.AtLeastOneProperty<Pick<client.ClientInputs['updateWorkflow'], 'userId' | 'timeoutAt'> & {
|
|
38
|
+
tags?: typeUtils.AtLeastOneProperty<TBot['workflows'][TWorkflowName]['tags']>;
|
|
39
|
+
output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
|
|
40
|
+
}>): Promise<{
|
|
41
|
+
workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Marks the current workflow instance as failed and stops execution
|
|
45
|
+
*/
|
|
46
|
+
setFailed(x: Required<Pick<client.ClientInputs['updateWorkflow'], 'failureReason'>>): Promise<{
|
|
47
|
+
workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Marks the current workflow instance as completed and stops execution
|
|
51
|
+
*/
|
|
52
|
+
setCompleted(x?: {
|
|
53
|
+
output?: typeUtils.Cast<TBot['workflows'][TWorkflowName], commonTypes.IntegrationInstanceActionDefinition>['output'];
|
|
54
|
+
}): Promise<{
|
|
55
|
+
workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Discards all output data and cancels the current workflow instance
|
|
59
|
+
*/
|
|
60
|
+
cancel(): Promise<{
|
|
61
|
+
workflow: WorkflowWithUtilities<TBot, TWorkflowName>;
|
|
62
|
+
}>;
|
|
63
|
+
}>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/fixtures.d.ts
CHANGED
|
@@ -173,6 +173,21 @@ export type FooBarBazBot = DefaultBot<{
|
|
|
173
173
|
age: number;
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
|
+
workflows: {
|
|
177
|
+
fooWorkflow: {
|
|
178
|
+
tags: {
|
|
179
|
+
foo: string;
|
|
180
|
+
};
|
|
181
|
+
input: {
|
|
182
|
+
string: string;
|
|
183
|
+
optionalNumber?: number;
|
|
184
|
+
};
|
|
185
|
+
output: {
|
|
186
|
+
optionalString?: string;
|
|
187
|
+
number: number;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
};
|
|
176
191
|
}>;
|
|
177
192
|
export type FooBarBazPlugin = DefaultPlugin<{
|
|
178
193
|
integrations: {
|
|
@@ -191,6 +206,21 @@ export type FooBarBazPlugin = DefaultPlugin<{
|
|
|
191
206
|
};
|
|
192
207
|
};
|
|
193
208
|
};
|
|
209
|
+
workflows: {
|
|
210
|
+
fooWorkflow: {
|
|
211
|
+
tags: {
|
|
212
|
+
foo: string;
|
|
213
|
+
};
|
|
214
|
+
input: {
|
|
215
|
+
string: string;
|
|
216
|
+
optionalNumber?: number;
|
|
217
|
+
};
|
|
218
|
+
output: {
|
|
219
|
+
optionalString?: string;
|
|
220
|
+
number: number;
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
};
|
|
194
224
|
}>;
|
|
195
225
|
export type EmptyBot = DefaultBot<{
|
|
196
226
|
integrations: {};
|