@botpress/sdk 2.5.0 → 3.0.1

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 (47) hide show
  1. package/.turbo/turbo-build.log +11 -5
  2. package/dist/bot/client/index.d.ts +6 -0
  3. package/dist/bot/client/types.d.ts +87 -0
  4. package/dist/bot/definition.d.ts +17 -9
  5. package/dist/bot/implementation.d.ts +11 -10
  6. package/dist/bot/index.d.ts +1 -1
  7. package/dist/bot/server/types.d.ts +32 -26
  8. package/dist/bot/types/common.d.ts +6 -2
  9. package/dist/bot/types/generic.d.ts +110 -9
  10. package/dist/fixtures.d.ts +49 -0
  11. package/dist/index.cjs +129 -0
  12. package/dist/index.cjs.map +7 -0
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.mjs +123 -0
  15. package/dist/index.mjs.map +7 -0
  16. package/dist/integration/client/types.d.ts +2 -1
  17. package/dist/integration/definition/index.d.ts +48 -12
  18. package/dist/integration/definition/types.d.ts +6 -1
  19. package/dist/integration/index.d.ts +1 -1
  20. package/dist/integration/types/common.d.ts +0 -7
  21. package/dist/interface/definition.d.ts +0 -2
  22. package/dist/interface/index.d.ts +1 -0
  23. package/dist/interface/resolve.d.ts +18 -0
  24. package/dist/interface/types/index.d.ts +1 -0
  25. package/dist/package.d.ts +4 -2
  26. package/dist/plugin/action-proxy/index.d.ts +2 -0
  27. package/dist/plugin/action-proxy/proxy.d.ts +5 -0
  28. package/dist/plugin/action-proxy/types.d.ts +14 -0
  29. package/dist/plugin/action-proxy/types.test.d.ts +1 -0
  30. package/dist/plugin/definition.d.ts +11 -6
  31. package/dist/plugin/implementation.d.ts +21 -15
  32. package/dist/plugin/index.d.ts +2 -1
  33. package/dist/plugin/interface-resolution.d.ts +15 -0
  34. package/dist/plugin/server/index.d.ts +1 -0
  35. package/dist/plugin/server/types.d.ts +241 -1
  36. package/dist/plugin/types/common.d.ts +41 -0
  37. package/dist/plugin/types/generic.d.ts +110 -2
  38. package/dist/plugin/types/index.d.ts +2 -0
  39. package/dist/serve.d.ts +2 -2
  40. package/dist/utils/record-utils.d.ts +2 -0
  41. package/dist/utils/record-utils.test.d.ts +1 -0
  42. package/dist/utils/type-utils.d.ts +15 -0
  43. package/dist/zui.d.ts +1 -0
  44. package/package.json +9 -5
  45. package/dist/bot/merge-bots.d.ts +0 -2
  46. package/dist/index.js +0 -129
  47. package/dist/index.js.map +0 -7
@@ -1,12 +1,18 @@
1
1
 
2
- > @botpress/sdk@2.5.0 build /home/runner/work/botpress/botpress/packages/sdk
3
- > pnpm build:type && pnpm build:node
2
+ > @botpress/sdk@3.0.1 build /home/runner/work/botpress/botpress/packages/sdk
3
+ > pnpm build:type && pnpm build:node && pnpm build:browser
4
4
 
5
5
 
6
- > @botpress/sdk@2.5.0 build:type /home/runner/work/botpress/botpress/packages/sdk
6
+ > @botpress/sdk@3.0.1 build:type /home/runner/work/botpress/botpress/packages/sdk
7
7
  > tsc --emitDeclarationOnly --declaration
8
8
 
9
9
 
10
- > @botpress/sdk@2.5.0 build:node /home/runner/work/botpress/botpress/packages/sdk
11
- > ts-node -T build.ts
10
+ > @botpress/sdk@3.0.1 build:node /home/runner/work/botpress/botpress/packages/sdk
11
+ > ts-node -T ./build.ts --node
12
12
 
13
+ Done
14
+
15
+ > @botpress/sdk@3.0.1 build:browser /home/runner/work/botpress/botpress/packages/sdk
16
+ > ts-node -T ./build.ts --browser
17
+
18
+ Done
@@ -42,6 +42,12 @@ export declare class BotSpecificClient<TBot extends common.BaseBot> implements t
42
42
  updateFileMetadata: types.UpdateFileMetadata<TBot>;
43
43
  searchFiles: types.SearchFiles<TBot>;
44
44
  trackAnalytics: types.TrackAnalytics<TBot>;
45
+ getTableRow: types.GetTableRow<TBot>;
46
+ createTableRows: types.CreateTableRows<TBot>;
47
+ findTableRows: types.FindTableRows<TBot>;
48
+ deleteTableRows: types.DeleteTableRows<TBot>;
49
+ updateTableRows: types.UpdateTableRows<TBot>;
50
+ upsertTableRows: types.UpsertTableRows<TBot>;
45
51
  /**
46
52
  * @deprecated Use `callAction` to delegate the conversation creation to an integration.
47
53
  */
@@ -86,6 +86,87 @@ export type ListFiles<_TBot extends common.BaseBot> = client.Client['listFiles']
86
86
  export type GetFile<_TBot extends common.BaseBot> = client.Client['getFile'];
87
87
  export type UpdateFileMetadata<_TBot extends common.BaseBot> = client.Client['updateFileMetadata'];
88
88
  export type SearchFiles<_TBot extends common.BaseBot> = client.Client['searchFiles'];
89
+ 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']>, {
90
+ table: utils.Cast<TableName, string>;
91
+ id: client.Row['id'];
92
+ }>) => Promise<Readonly<utils.Merge<Awaited<Res<client.Client['getTableRow']>>, {
93
+ row: Awaited<Res<client.Client['getTableRow']>>['row'] & Columns;
94
+ }>>>;
95
+ export type CreateTableRows<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['createTableRows']>, {
96
+ table: utils.Cast<TableName, string>;
97
+ rows: utils.AtLeastOne<utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>>>;
98
+ }>) => Promise<Readonly<utils.Merge<Awaited<Res<client.Client['createTableRows']>>, {
99
+ rows: Awaited<Res<client.Client['createTableRows']>>['rows'] & Columns[];
100
+ }>>>;
101
+ type TableRowQueryGroup = 'key' | 'avg' | 'max' | 'min' | 'sum' | 'count';
102
+ type TableRowExtraColumns = {
103
+ /**
104
+ * Unique identifier for the row.
105
+ */
106
+ id: number;
107
+ /**
108
+ * Timestamp of row creation.
109
+ */
110
+ createdAt: string;
111
+ /**
112
+ * Timestamp of the last row update.
113
+ */
114
+ updatedAt: string;
115
+ };
116
+ type TableRowFilter<TBot extends common.BaseBot, TableName extends keyof common.EnumerateTables<TBot>, Columns = utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>> & TableRowExtraColumns> = TableRowColumnFilters<Columns> | TableRowLogicalFilter<TBot, TableName, Columns>;
117
+ type TableRowColumnFilters<Columns> = utils.AtLeastOneProperty<{
118
+ [K in Extract<keyof Columns, string>]: TableColumnComparisonFilter<Columns[K]>;
119
+ }>;
120
+ type TableRowLogicalFilter<TBot extends common.BaseBot, TableName extends keyof common.EnumerateTables<TBot>, Columns = utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>> & TableRowExtraColumns> = utils.ExactlyOneProperty<{
121
+ $and: utils.AtLeastOne<TableRowFilter<TBot, TableName, Columns>>;
122
+ $or: utils.AtLeastOne<TableRowFilter<TBot, TableName, Columns>>;
123
+ $not: TableRowColumnFilters<Columns>;
124
+ }>;
125
+ type TableColumnComparisonFilter<ColumnType> = ColumnType | utils.ExactlyOneProperty<{
126
+ $eq: ColumnType;
127
+ $gt: ColumnType;
128
+ $gte: ColumnType;
129
+ $lt: ColumnType;
130
+ $lte: ColumnType;
131
+ $ne: ColumnType;
132
+ $mod: [number, number];
133
+ $in: utils.AtLeastOne<ColumnType>;
134
+ $nin: utils.AtLeastOne<ColumnType>;
135
+ $exists: boolean;
136
+ $size: number;
137
+ }>;
138
+ export type FindTableRows<TBot extends common.BaseBot> = <TableName extends keyof common.EnumerateTables<TBot>, Columns = utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>> & TableRowExtraColumns>(x: utils.Merge<Arg<client.Client['findTableRows']>, {
139
+ table: utils.Cast<TableName, string>;
140
+ filter?: TableRowFilter<TBot, TableName, Columns>;
141
+ group?: utils.AtLeastOneProperty<{
142
+ [K in Extract<keyof Columns, string>]: TableRowQueryGroup | TableRowQueryGroup[];
143
+ }>;
144
+ orderBy?: Extract<keyof Columns, string>;
145
+ }>) => Promise<Readonly<utils.Merge<Awaited<Res<client.Client['findTableRows']>>, {
146
+ rows: Awaited<Res<client.Client['findTableRows']>>['rows'] & Columns[];
147
+ }>>>;
148
+ export type DeleteTableRows<TBot extends common.BaseBot> = <TableName extends keyof common.EnumerateTables<TBot>>(x: utils.Merge<Arg<client.Client['deleteTableRows']>, {
149
+ table: utils.Cast<TableName, string>;
150
+ filter?: TableRowFilter<TBot, TableName>;
151
+ }>) => Promise<Readonly<Awaited<Res<client.Client['deleteTableRows']>>>>;
152
+ export type UpdateTableRows<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['updateTableRows']>, {
153
+ table: utils.Cast<TableName, string>;
154
+ rows: utils.AtLeastOne<utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>> & {
155
+ id: number;
156
+ }>;
157
+ }>) => Promise<Readonly<utils.Merge<Awaited<Res<client.Client['updateTableRows']>>, {
158
+ rows: Awaited<Res<client.Client['updateTableRows']>>['rows'] & Columns[];
159
+ }>>>;
160
+ export type UpsertTableRows<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['upsertTableRows']>, {
161
+ table: utils.Cast<TableName, string>;
162
+ rows: utils.AtLeastOne<utils.Cast<common.EnumerateTables<TBot>[TableName], Record<string, any>> & {
163
+ id: number;
164
+ }>;
165
+ keyColumn?: Extract<keyof common.EnumerateTables<TBot>[TableName], string> | 'id';
166
+ }>) => Promise<Readonly<utils.Merge<Awaited<Res<client.Client['upsertTableRows']>>, {
167
+ inserted: Awaited<Res<client.Client['upsertTableRows']>>['inserted'] & Columns[];
168
+ updated: Awaited<Res<client.Client['upsertTableRows']>>['updated'] & Columns[];
169
+ }>>>;
89
170
  export type TrackAnalytics<_TBot extends common.BaseBot> = client.Client['trackAnalytics'];
90
171
  export type ClientOperations<TBot extends common.BaseBot> = {
91
172
  getConversation: GetConversation<TBot>;
@@ -121,6 +202,12 @@ export type ClientOperations<TBot extends common.BaseBot> = {
121
202
  updateFileMetadata: UpdateFileMetadata<TBot>;
122
203
  searchFiles: SearchFiles<TBot>;
123
204
  trackAnalytics: TrackAnalytics<TBot>;
205
+ getTableRow: GetTableRow<TBot>;
206
+ createTableRows: CreateTableRows<TBot>;
207
+ findTableRows: FindTableRows<TBot>;
208
+ deleteTableRows: DeleteTableRows<TBot>;
209
+ updateTableRows: UpdateTableRows<TBot>;
210
+ upsertTableRows: UpsertTableRows<TBot>;
124
211
  };
125
212
  export type ClientInputs<TBot extends common.BaseBot> = {
126
213
  [K in keyof ClientOperations<TBot>]: Arg<ClientOperations<TBot>[K]>;
@@ -1,11 +1,14 @@
1
+ import { Table } from '@botpress/client';
1
2
  import { IntegrationPackage, PluginPackage } from '../package';
3
+ import { PluginInterfaceExtension } from '../plugin';
2
4
  import { SchemaDefinition } from '../schema';
3
- import { ValueOf } from '../utils/type-utils';
5
+ import { ValueOf, Merge } from '../utils/type-utils';
4
6
  import z, { ZuiObjectSchema } from '../zui';
5
7
  type BaseConfig = ZuiObjectSchema;
6
8
  type BaseStates = Record<string, ZuiObjectSchema>;
7
9
  type BaseEvents = Record<string, ZuiObjectSchema>;
8
10
  type BaseActions = Record<string, ZuiObjectSchema>;
11
+ type BaseTables = Record<string, ZuiObjectSchema>;
9
12
  export type TagDefinition = {
10
13
  title?: string;
11
14
  description?: string;
@@ -41,6 +44,9 @@ export type ActionDefinition<TAction extends BaseActions[string] = BaseActions[s
41
44
  input: SchemaDefinition<TAction>;
42
45
  output: SchemaDefinition<ZuiObjectSchema>;
43
46
  };
47
+ export type TableDefinition<TTable extends BaseTables[string] = BaseTables[string]> = Merge<Omit<Table, 'id' | 'createdAt' | 'updatedAt' | 'name'>, {
48
+ schema: TTable;
49
+ }>;
44
50
  export type IntegrationConfigInstance<I extends IntegrationPackage = IntegrationPackage> = {
45
51
  enabled: boolean;
46
52
  } & ({
@@ -55,15 +61,12 @@ export type IntegrationConfigInstance<I extends IntegrationPackage = Integration
55
61
  export type PluginConfigInstance<P extends PluginPackage = PluginPackage> = {
56
62
  configuration: z.infer<NonNullable<P['definition']['configuration']>['schema']>;
57
63
  interfaces: {
58
- [I in keyof NonNullable<P['definition']['interfaces']>]: {
59
- name: string;
60
- version: string;
61
- };
64
+ [I in keyof NonNullable<P['definition']['interfaces']>]: PluginInterfaceExtension;
62
65
  };
63
66
  };
64
67
  export type IntegrationInstance = IntegrationPackage & IntegrationConfigInstance;
65
68
  export type PluginInstance = PluginPackage & PluginConfigInstance;
66
- export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions> = {
69
+ export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions, TTables extends BaseTables = BaseTables> = {
67
70
  integrations?: {
68
71
  [K: string]: IntegrationInstance;
69
72
  };
@@ -84,9 +87,12 @@ export type BotDefinitionProps<TStates extends BaseStates = BaseStates, TEvents
84
87
  actions?: {
85
88
  [K in keyof TActions]: ActionDefinition<TActions[K]>;
86
89
  };
90
+ tables?: {
91
+ [K in keyof TTables]: TableDefinition<TTables[K]>;
92
+ };
87
93
  };
88
- export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEvents extends BaseEvents = BaseEvents, TActions extends BaseActions = BaseActions> {
89
- readonly props: BotDefinitionProps<TStates, TEvents, TActions>;
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>;
90
96
  readonly integrations: this['props']['integrations'];
91
97
  readonly plugins: this['props']['plugins'];
92
98
  readonly user: this['props']['user'];
@@ -97,7 +103,8 @@ export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEve
97
103
  readonly events: this['props']['events'];
98
104
  readonly recurringEvents: this['props']['recurringEvents'];
99
105
  readonly actions: this['props']['actions'];
100
- constructor(props: BotDefinitionProps<TStates, TEvents, TActions>);
106
+ readonly tables: this['props']['tables'];
107
+ constructor(props: BotDefinitionProps<TStates, TEvents, TActions, TTables>);
101
108
  addIntegration<I extends IntegrationPackage>(integrationPkg: I, config: IntegrationConfigInstance<I>): this;
102
109
  addPlugin<P extends PluginPackage>(pluginPkg: P, config: PluginConfigInstance<P>): this;
103
110
  private _mergeUser;
@@ -107,5 +114,6 @@ export declare class BotDefinition<TStates extends BaseStates = BaseStates, TEve
107
114
  private _mergeEvents;
108
115
  private _mergeRecurringEvents;
109
116
  private _mergeActions;
117
+ private _mergeTables;
110
118
  }
111
119
  export {};
@@ -10,16 +10,18 @@ export type BotImplementationProps<TBot extends BaseBot = BaseBot, TPlugins exte
10
10
  };
11
11
  export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins extends Record<string, BasePlugin> = {}> implements BotHandlers<TBot> {
12
12
  readonly props: BotImplementationProps<TBot, TPlugins>;
13
- readonly actionHandlers: ActionHandlers<TBot>;
14
- readonly messageHandlers: MessageHandlersMap<TBot>;
15
- readonly eventHandlers: EventHandlersMap<TBot>;
16
- readonly stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
17
- readonly hookHandlers: HookHandlersMap<TBot>;
18
- /**
19
- * alias for actionHandlers
20
- */
21
- get actions(): ActionHandlers<TBot>;
13
+ private _actionHandlers;
14
+ private _messageHandlers;
15
+ private _eventHandlers;
16
+ private _stateExpiredHandlers;
17
+ private _hookHandlers;
18
+ private _plugins;
22
19
  constructor(props: BotImplementationProps<TBot, TPlugins>);
20
+ get actionHandlers(): ActionHandlers<TBot>;
21
+ get messageHandlers(): MessageHandlersMap<TBot>;
22
+ get eventHandlers(): EventHandlersMap<TBot>;
23
+ get stateExpiredHandlers(): StateExpiredHandlersMap<TBot>;
24
+ get hookHandlers(): HookHandlersMap<TBot>;
23
25
  readonly on: {
24
26
  message: <T extends keyof MessageHandlersMap<TBot>>(type: T, handler: MessageHandlers<TBot>[T]) => void;
25
27
  event: <T extends keyof EventHandlersMap<TBot>>(type: T, handler: EventHandlers<TBot>[T]) => void;
@@ -33,7 +35,6 @@ export declare class BotImplementation<TBot extends BaseBot = BaseBot, TPlugins
33
35
  afterOutgoingMessage: <T extends keyof HookData<TBot>["after_outgoing_message"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_message"][T]) => void;
34
36
  afterOutgoingCallAction: <T extends keyof HookData<TBot>["after_outgoing_call_action"]>(type: T, handler: HookHandlers<TBot>["after_outgoing_call_action"][T]) => void;
35
37
  };
36
- private readonly _use;
37
38
  readonly handler: (req: import("../serve").Request) => Promise<import("../serve").Response | void>;
38
39
  readonly start: (port?: number) => Promise<Server>;
39
40
  }
@@ -2,5 +2,5 @@ export * from './definition';
2
2
  export * from './implementation';
3
3
  export * from './client';
4
4
  export * from './server';
5
- export * from './types/generic';
5
+ export * from './types';
6
6
  export * from './bot-logger';
@@ -25,6 +25,12 @@ type _IncomingMessages<TBot extends types.BaseBot> = {
25
25
  payload: types.GetMessages<TBot>[K];
26
26
  }>;
27
27
  };
28
+ type _IncomingStates<TBot extends types.BaseBot> = {
29
+ [K in keyof types.EnumerateStates<TBot>]: utils.Merge<client.State, {
30
+ name: K;
31
+ payload: types.EnumerateStates<TBot>[K];
32
+ }>;
33
+ };
28
34
  type _OutgoingMessageRequests<TBot extends types.BaseBot> = {
29
35
  [K in keyof types.GetMessages<TBot>]: utils.Merge<client.ClientInputs['createMessage'], {
30
36
  type: K;
@@ -50,19 +56,19 @@ type _OutgoingCallActionResponses<TBot extends types.BaseBot> = {
50
56
  output: types.EnumerateActionOutputs<TBot>[K];
51
57
  }>;
52
58
  };
53
- export type AnyIncomingEvent<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.Event : utils.ValueOf<_IncomingEvents<TBot>>;
54
- export type AnyIncomingMessage<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.Message : utils.ValueOf<_IncomingMessages<TBot>>;
55
- export type AnyOutgoingMessageRequest<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientInputs['createMessage'] : utils.ValueOf<_OutgoingMessageRequests<TBot>>;
56
- export type AnyOutgoingMessageResponse<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientOutputs['createMessage'] : utils.ValueOf<_OutgoingMessageResponses<TBot>>;
57
- export type AnyOutgoingCallActionRequest<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientInputs['callAction'] : utils.ValueOf<_OutgoingCallActionRequests<TBot>>;
58
- export type AnyOutgoingCallActionResponse<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? client.ClientOutputs['callAction'] : utils.ValueOf<_OutgoingCallActionResponses<TBot>>;
59
+ export type AnyIncomingEvent<TBot extends types.BaseBot> = utils.ValueOf<_IncomingEvents<TBot>>;
60
+ export type AnyIncomingMessage<TBot extends types.BaseBot> = utils.ValueOf<_IncomingMessages<TBot>>;
61
+ export type AnyOutgoingMessageRequest<TBot extends types.BaseBot> = utils.ValueOf<_OutgoingMessageRequests<TBot>>;
62
+ export type AnyOutgoingMessageResponse<TBot extends types.BaseBot> = utils.ValueOf<_OutgoingMessageResponses<TBot>>;
63
+ export type AnyOutgoingCallActionRequest<TBot extends types.BaseBot> = utils.ValueOf<_OutgoingCallActionRequests<TBot>>;
64
+ export type AnyOutgoingCallActionResponse<TBot extends types.BaseBot> = utils.ValueOf<_OutgoingCallActionResponses<TBot>>;
59
65
  export type IncomingEvents<TBot extends types.BaseBot> = _IncomingEvents<TBot> & {
60
66
  '*': AnyIncomingEvent<TBot>;
61
67
  };
62
68
  export type IncomingMessages<TBot extends types.BaseBot> = _IncomingMessages<TBot> & {
63
69
  '*': AnyIncomingMessage<TBot>;
64
70
  };
65
- export type IncomingStates<_TBot extends types.BaseBot> = {
71
+ export type IncomingStates<_TBot extends types.BaseBot> = _IncomingStates<_TBot> & {
66
72
  '*': client.State;
67
73
  };
68
74
  export type OutgoingMessageRequests<TBot extends types.BaseBot> = _OutgoingMessageRequests<TBot> & {
@@ -77,14 +83,14 @@ export type OutgoingCallActionRequests<TBot extends types.BaseBot> = _OutgoingCa
77
83
  export type OutgoingCallActionResponses<TBot extends types.BaseBot> = _OutgoingCallActionResponses<TBot> & {
78
84
  '*': AnyOutgoingCallActionResponse<TBot>;
79
85
  };
80
- export type BotClient<TBot extends types.BaseBot> = TBot['unknownDefinitions'] extends true ? BotSpecificClient<types.BaseBot> : BotSpecificClient<TBot>;
86
+ export type BotClient<TBot extends types.BaseBot> = BotSpecificClient<TBot>;
81
87
  export type CommonHandlerProps<TBot extends types.BaseBot> = {
82
88
  ctx: BotContext;
83
89
  logger: BotLogger;
84
90
  client: BotClient<TBot>;
85
91
  };
86
92
  export type MessagePayloads<TBot extends types.BaseBot> = {
87
- [K in keyof IncomingMessages<TBot>]: {
93
+ [K in keyof IncomingMessages<TBot>]: CommonHandlerProps<TBot> & {
88
94
  message: IncomingMessages<TBot>[K];
89
95
  user: client.User;
90
96
  conversation: client.Conversation;
@@ -98,32 +104,32 @@ export type MessagePayloads<TBot extends types.BaseBot> = {
98
104
  };
99
105
  };
100
106
  export type MessageHandlers<TBot extends types.BaseBot> = {
101
- [K in keyof IncomingMessages<TBot>]: (args: CommonHandlerProps<TBot> & MessagePayloads<TBot>[K]) => Promise<void>;
107
+ [K in keyof IncomingMessages<TBot>]: (args: MessagePayloads<TBot>[K]) => Promise<void>;
102
108
  };
103
109
  export type EventPayloads<TBot extends types.BaseBot> = {
104
- [K in keyof IncomingEvents<TBot>]: {
110
+ [K in keyof IncomingEvents<TBot>]: CommonHandlerProps<TBot> & {
105
111
  event: IncomingEvents<TBot>[K];
106
112
  };
107
113
  };
108
114
  export type EventHandlers<TBot extends types.BaseBot> = {
109
- [K in keyof IncomingEvents<TBot>]: (args: CommonHandlerProps<TBot> & EventPayloads<TBot>[K]) => Promise<void>;
115
+ [K in keyof IncomingEvents<TBot>]: (args: EventPayloads<TBot>[K]) => Promise<void>;
110
116
  };
111
117
  export type StateExpiredPayloads<TBot extends types.BaseBot> = {
112
- [K in keyof IncomingStates<TBot>]: {
118
+ [K in keyof IncomingStates<TBot>]: CommonHandlerProps<TBot> & {
113
119
  state: IncomingStates<TBot>[K];
114
120
  };
115
121
  };
116
122
  export type StateExpiredHandlers<TBot extends types.BaseBot> = {
117
- [K in keyof IncomingStates<TBot>]: (args: CommonHandlerProps<TBot> & StateExpiredPayloads<TBot>[K]) => Promise<void>;
123
+ [K in keyof IncomingStates<TBot>]: (args: StateExpiredPayloads<TBot>[K]) => Promise<void>;
118
124
  };
119
125
  export type ActionHandlerPayloads<TBot extends types.BaseBot> = {
120
- [K in keyof TBot['actions']]: {
126
+ [K in keyof TBot['actions']]: CommonHandlerProps<TBot> & {
121
127
  type?: K;
122
128
  input: TBot['actions'][K]['input'];
123
129
  };
124
130
  };
125
131
  export type ActionHandlers<TBot extends types.BaseBot> = {
126
- [K in keyof TBot['actions']]: (props: CommonHandlerProps<TBot> & ActionHandlerPayloads<TBot>[K]) => Promise<TBot['actions'][K]['output']>;
132
+ [K in keyof TBot['actions']]: (props: ActionHandlerPayloads<TBot>[K]) => Promise<TBot['actions'][K]['output']>;
127
133
  };
128
134
  type BaseHookDefinition = {
129
135
  stoppable?: boolean;
@@ -229,17 +235,17 @@ export type HookHandlersMap<TBot extends types.BaseBot> = {
229
235
  [T in keyof HookData<TBot>[H]]?: HookHandlers<TBot>[H][T][];
230
236
  };
231
237
  };
232
- export type BotActionHandlers<TBot extends types.BaseBot> = ActionHandlers<TBot>;
233
- export type BotMessageHandlers<TBot extends types.BaseBot> = MessageHandlersMap<TBot>;
234
- export type BotEventHandlers<TBot extends types.BaseBot> = EventHandlersMap<TBot>;
235
- export type BotStateExpiredHandlers<TBot extends types.BaseBot> = StateExpiredHandlersMap<TBot>;
236
- export type BotHookHandlers<TBot extends types.BaseBot> = HookHandlersMap<TBot>;
238
+ /**
239
+ * TODO:
240
+ * the consumer of this type shouldnt be able to access "*" directly;
241
+ * "*" is meant the user who registers an handler, not for the user who calls the handler
242
+ */
237
243
  export type BotHandlers<TBot extends types.BaseBot> = {
238
- actionHandlers: BotActionHandlers<TBot>;
239
- messageHandlers: BotMessageHandlers<TBot>;
240
- eventHandlers: BotEventHandlers<TBot>;
241
- stateExpiredHandlers: BotStateExpiredHandlers<TBot>;
242
- hookHandlers: BotHookHandlers<TBot>;
244
+ actionHandlers: ActionHandlers<TBot>;
245
+ messageHandlers: MessageHandlersMap<TBot>;
246
+ eventHandlers: EventHandlersMap<TBot>;
247
+ stateExpiredHandlers: StateExpiredHandlersMap<TBot>;
248
+ hookHandlers: HookHandlersMap<TBot>;
243
249
  };
244
250
  type ImplementedActions<_TBot extends types.BaseBot, TPlugins extends Record<string, plugin.BasePlugin>> = utils.UnionToIntersection<utils.ValueOf<{
245
251
  [K in keyof TPlugins]: TPlugins[K]['actions'];
@@ -1,7 +1,5 @@
1
1
  import { Join, UnionToIntersection, Split, Cast } from '../../utils/type-utils';
2
2
  import { BaseBot } from './generic';
3
- export type EventDefinition = BaseBot['events'][string];
4
- export type StateDefinition = BaseBot['states'][string];
5
3
  export type IntegrationInstanceDefinition = BaseBot['integrations'][string];
6
4
  export type IntegrationInstanceConfigurationDefinition = IntegrationInstanceDefinition['configuration'];
7
5
  export type IntegrationInstanceActionDefinition = IntegrationInstanceDefinition['actions'][string];
@@ -47,4 +45,10 @@ export type EnumerateMessages<TBot extends BaseBot> = UnionToIntersection<{
47
45
  export type GetMessages<TBot extends BaseBot> = {
48
46
  [K in keyof EnumerateMessages<TBot> as Cast<Split<K, ':'>[2], string>]: EnumerateMessages<TBot>[K];
49
47
  };
48
+ export type EnumerateStates<TBot extends BaseBot> = {
49
+ [K in keyof TBot['states']]: TBot['states'][K];
50
+ };
51
+ export type EnumerateTables<TBot extends BaseBot> = {
52
+ [K in keyof TBot['tables']]: TBot['tables'][K];
53
+ };
50
54
  export {};
@@ -5,27 +5,128 @@ export type BaseAction = {
5
5
  input: any;
6
6
  output: any;
7
7
  };
8
+ export type BaseTable = {
9
+ /**
10
+ * Required. This name is used to identify your table.
11
+ */
12
+ name: string;
13
+ /**
14
+ * The 'factor' multiplies the row's data storage limit by 4KB and its quota count, but can only be set at table creation and not modified later. For instance, a factor of 2 increases storage to 8KB but counts as 2 rows in your quota. The default factor is 1.
15
+ */
16
+ factor?: number;
17
+ /**
18
+ * A table designated as "frozen" is immutable in terms of its name and schema structure; modifications to its schema or a renaming operation are not permitted. The only action that can be taken on such a table is deletion. The schema established at the time of creation is locked in as the final structure. To implement any changes, the table must be duplicated with the desired alterations.
19
+ */
20
+ frozen?: boolean;
21
+ schema: {
22
+ $schema?: string;
23
+ /**
24
+ * List of keys/columns in the table.
25
+ */
26
+ properties: {
27
+ [k: string]: {
28
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null';
29
+ format?: 'date-time';
30
+ description?: string;
31
+ /**
32
+ * String properties must match this pattern
33
+ */
34
+ pattern?: string;
35
+ /**
36
+ * String properties must be one of these values
37
+ */
38
+ enum?: string[];
39
+ /**
40
+ * Defines the shape of items in an array
41
+ */
42
+ items?: {
43
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null';
44
+ [k: string]: any;
45
+ };
46
+ nullable?: boolean;
47
+ properties?: {
48
+ [k: string]: {
49
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'null';
50
+ [k: string]: any;
51
+ };
52
+ };
53
+ 'x-zui': {
54
+ index: number;
55
+ /**
56
+ * Indicates if the column is vectorized and searchable.
57
+ */
58
+ searchable?: boolean;
59
+ /**
60
+ * Indicates if the field is hidden in the UI
61
+ */
62
+ hidden?: boolean;
63
+ /**
64
+ * Order of the column in the UI
65
+ */
66
+ order?: number;
67
+ /**
68
+ * Width of the column in the UI
69
+ */
70
+ width?: number;
71
+ computed?: {
72
+ action: 'ai' | 'code' | 'workflow';
73
+ dependencies?: string[];
74
+ /**
75
+ * Prompt when action is "ai"
76
+ */
77
+ prompt?: string;
78
+ /**
79
+ * Code to execute when action is "code"
80
+ */
81
+ code?: string;
82
+ /**
83
+ * Model to use when action is "ai"
84
+ */
85
+ model?: string;
86
+ /**
87
+ * ID of Workflow to execute when action is "workflow"
88
+ */
89
+ workflowId?: string;
90
+ enabled?: boolean;
91
+ };
92
+ };
93
+ };
94
+ };
95
+ /**
96
+ * Additional properties can be provided, but they will be ignored if no column matches.
97
+ */
98
+ additionalProperties: true;
99
+ /**
100
+ * Array of required properties.
101
+ */
102
+ required?: string[];
103
+ type: 'object';
104
+ };
105
+ /**
106
+ * Optional tags to help organize your tables. These should be passed here as an object representing key/value pairs.
107
+ */
108
+ tags?: {
109
+ [k: string]: string;
110
+ };
111
+ /**
112
+ * Indicates if the table is enabled for computation.
113
+ */
114
+ isComputeEnabled?: boolean;
115
+ };
8
116
  export type BaseBot = {
9
117
  integrations: Record<string, BaseIntegration>;
10
118
  events: Record<string, any>;
11
119
  states: Record<string, any>;
12
120
  actions: Record<string, BaseAction>;
13
- /**
14
- * In a bot, all events, actions, states, and integrations definitions are known.
15
- * This mean the Bot typings should not allow for unknown types.
16
- *
17
- * In a plugin, we don't known about extra definitions of the bot that installed the plugin.
18
- * This mean the Plugin typings should allow for unknown types.
19
- */
20
- unknownDefinitions: boolean;
121
+ tables: Record<string, BaseTable>;
21
122
  };
22
123
  export type InputBaseBot = utils.DeepPartial<BaseBot>;
23
124
  export type DefaultBot<B extends InputBaseBot> = {
24
125
  events: utils.Default<B['events'], BaseBot['events']>;
25
126
  states: utils.Default<B['states'], BaseBot['states']>;
26
127
  actions: utils.Default<B['actions'], BaseBot['actions']>;
27
- unknownDefinitions: utils.Default<B['unknownDefinitions'], BaseBot['unknownDefinitions']>;
28
128
  integrations: undefined extends B['integrations'] ? BaseBot['integrations'] : {
29
129
  [K in keyof B['integrations']]: DefaultIntegration<utils.Cast<B['integrations'][K], InputBaseIntegration>>;
30
130
  };
131
+ tables: utils.Default<B['tables'], BaseBot['tables']>;
31
132
  };
@@ -63,7 +63,47 @@ type _FooBarBazIntegration = {
63
63
  }>;
64
64
  };
65
65
  };
66
+ type _TotoTutuTataInterface = {
67
+ actions: {
68
+ doToto: {
69
+ input: {
70
+ inputToto: string;
71
+ };
72
+ output: {
73
+ outputToto: string;
74
+ };
75
+ };
76
+ doTutu: {
77
+ input: {
78
+ inputTutu: number;
79
+ };
80
+ output: {
81
+ outputTutu: number;
82
+ };
83
+ };
84
+ doTata: {
85
+ input: {
86
+ inputTata: boolean;
87
+ };
88
+ output: {
89
+ outputTata: boolean;
90
+ };
91
+ };
92
+ };
93
+ events: {
94
+ onToto: {
95
+ eventToto: string;
96
+ };
97
+ onTutu: {
98
+ eventTutu: number;
99
+ };
100
+ onTata: {
101
+ eventTata: boolean;
102
+ };
103
+ };
104
+ };
66
105
  export type FooBarBazIntegration = DefaultIntegration<_FooBarBazIntegration>;
106
+ export type TotoTutuTataIntegration = DefaultIntegration<_TotoTutuTataInterface>;
67
107
  export type FooBarBazBot = DefaultBot<{
68
108
  integrations: {
69
109
  fooBarBaz: _FooBarBazIntegration;
@@ -78,11 +118,20 @@ export type FooBarBazBot = DefaultBot<{
78
118
  };
79
119
  };
80
120
  };
121
+ states: {
122
+ currentUser: {
123
+ name: string;
124
+ age: number;
125
+ };
126
+ };
81
127
  }>;
82
128
  export type FooBarBazPlugin = DefaultPlugin<{
83
129
  integrations: {
84
130
  fooBarBaz: _FooBarBazIntegration;
85
131
  };
132
+ interfaces: {
133
+ totoTutuTata: _TotoTutuTataInterface;
134
+ };
86
135
  actions: {
87
136
  act: {
88
137
  input: {