@botpress/runtime 1.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.
- package/dist/_types/actions.d.ts +3 -0
- package/dist/_types/actions.d.ts.map +1 -0
- package/dist/_types/events.d.ts +5 -0
- package/dist/_types/events.d.ts.map +1 -0
- package/dist/_types/integration-actions.d.ts +3 -0
- package/dist/_types/integration-actions.d.ts.map +1 -0
- package/dist/_types/state.d.ts +4 -0
- package/dist/_types/state.d.ts.map +1 -0
- package/dist/_types/tables.d.ts +3 -0
- package/dist/_types/tables.d.ts.map +1 -0
- package/dist/_types/triggers.d.ts +3 -0
- package/dist/_types/triggers.d.ts.map +1 -0
- package/dist/_types/workflows.d.ts +12 -0
- package/dist/_types/workflows.d.ts.map +1 -0
- package/dist/constants.d.ts +58 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/consts.d.ts +8 -0
- package/dist/consts.d.ts.map +1 -0
- package/dist/debugging/node-inspector.d.ts +5 -0
- package/dist/debugging/node-inspector.d.ts.map +1 -0
- package/dist/define-config.d.ts +70 -0
- package/dist/define-config.d.ts.map +1 -0
- package/dist/definition.d.ts +10 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +88 -0
- package/dist/definition.js.map +7 -0
- package/dist/environment.d.ts +60 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/errors.d.ts +36 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/globals.d.ts +21 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/internal.d.ts +15 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +46573 -0
- package/dist/internal.js.map +7 -0
- package/dist/library.d.ts +16 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +45943 -0
- package/dist/library.js.map +7 -0
- package/dist/primitives/action.d.ts +37 -0
- package/dist/primitives/action.d.ts.map +1 -0
- package/dist/primitives/asset.d.ts +28 -0
- package/dist/primitives/asset.d.ts.map +1 -0
- package/dist/primitives/conversation.d.ts +104 -0
- package/dist/primitives/conversation.d.ts.map +1 -0
- package/dist/primitives/data-sources/index.d.ts +7 -0
- package/dist/primitives/data-sources/index.d.ts.map +1 -0
- package/dist/primitives/data-sources/source-base.d.ts +251 -0
- package/dist/primitives/data-sources/source-base.d.ts.map +1 -0
- package/dist/primitives/data-sources/source-directory.d.ts +119 -0
- package/dist/primitives/data-sources/source-directory.d.ts.map +1 -0
- package/dist/primitives/data-sources/source-table.d.ts +135 -0
- package/dist/primitives/data-sources/source-table.d.ts.map +1 -0
- package/dist/primitives/data-sources/source-website.d.ts +226 -0
- package/dist/primitives/data-sources/source-website.d.ts.map +1 -0
- package/dist/primitives/definition.d.ts +68 -0
- package/dist/primitives/definition.d.ts.map +1 -0
- package/dist/primitives/index.d.ts +149 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/knowledge.d.ts +36 -0
- package/dist/primitives/knowledge.d.ts.map +1 -0
- package/dist/primitives/table.d.ts +153 -0
- package/dist/primitives/table.d.ts.map +1 -0
- package/dist/primitives/trigger.d.ts +26 -0
- package/dist/primitives/trigger.d.ts.map +1 -0
- package/dist/primitives/workflow-instance.d.ts +80 -0
- package/dist/primitives/workflow-instance.d.ts.map +1 -0
- package/dist/primitives/workflow-step.d.ts +184 -0
- package/dist/primitives/workflow-step.d.ts.map +1 -0
- package/dist/primitives/workflow-utils.d.ts +36 -0
- package/dist/primitives/workflow-utils.d.ts.map +1 -0
- package/dist/primitives/workflow.d.ts +86 -0
- package/dist/primitives/workflow.d.ts.map +1 -0
- package/dist/runtime/actions.d.ts +6 -0
- package/dist/runtime/actions.d.ts.map +1 -0
- package/dist/runtime/adk.d.ts +54 -0
- package/dist/runtime/adk.d.ts.map +1 -0
- package/dist/runtime/agent-registry.d.ts +33 -0
- package/dist/runtime/agent-registry.d.ts.map +1 -0
- package/dist/runtime/assets.d.ts +48 -0
- package/dist/runtime/assets.d.ts.map +1 -0
- package/dist/runtime/autonomous.d.ts +86 -0
- package/dist/runtime/autonomous.d.ts.map +1 -0
- package/dist/runtime/chat/chat.d.ts +42 -0
- package/dist/runtime/chat/chat.d.ts.map +1 -0
- package/dist/runtime/chat/citations.d.ts +9 -0
- package/dist/runtime/chat/citations.d.ts.map +1 -0
- package/dist/runtime/chat/html.d.ts +2 -0
- package/dist/runtime/chat/html.d.ts.map +1 -0
- package/dist/runtime/chat/index.d.ts +5 -0
- package/dist/runtime/chat/index.d.ts.map +1 -0
- package/dist/runtime/chat/messages.d.ts +35 -0
- package/dist/runtime/chat/messages.d.ts.map +1 -0
- package/dist/runtime/chat/transcript.d.ts +75 -0
- package/dist/runtime/chat/transcript.d.ts.map +1 -0
- package/dist/runtime/chat/truncate-object.d.ts +12 -0
- package/dist/runtime/chat/truncate-object.d.ts.map +1 -0
- package/dist/runtime/chat/truncate-transcript.d.ts +6 -0
- package/dist/runtime/chat/truncate-transcript.d.ts.map +1 -0
- package/dist/runtime/config.d.ts +19 -0
- package/dist/runtime/config.d.ts.map +1 -0
- package/dist/runtime/context/cognitive.d.ts +7 -0
- package/dist/runtime/context/cognitive.d.ts.map +1 -0
- package/dist/runtime/context/context.d.ts +59 -0
- package/dist/runtime/context/context.d.ts.map +1 -0
- package/dist/runtime/context/handlers.d.ts +14 -0
- package/dist/runtime/context/handlers.d.ts.map +1 -0
- package/dist/runtime/context/http.d.ts +38 -0
- package/dist/runtime/context/http.d.ts.map +1 -0
- package/dist/runtime/context/inspector-handler.d.ts +59 -0
- package/dist/runtime/context/inspector-handler.d.ts.map +1 -0
- package/dist/runtime/context/promises.d.ts +36 -0
- package/dist/runtime/context/promises.d.ts.map +1 -0
- package/dist/runtime/events.d.ts +89 -0
- package/dist/runtime/events.d.ts.map +1 -0
- package/dist/runtime/handlers/conversation.d.ts +3 -0
- package/dist/runtime/handlers/conversation.d.ts.map +1 -0
- package/dist/runtime/handlers/event.d.ts +3 -0
- package/dist/runtime/handlers/event.d.ts.map +1 -0
- package/dist/runtime/handlers/index.d.ts +11 -0
- package/dist/runtime/handlers/index.d.ts.map +1 -0
- package/dist/runtime/handlers/trigger.d.ts +3 -0
- package/dist/runtime/handlers/trigger.d.ts.map +1 -0
- package/dist/runtime/handlers/workflow.d.ts +3 -0
- package/dist/runtime/handlers/workflow.d.ts.map +1 -0
- package/dist/runtime/heavy-imports.d.ts +10 -0
- package/dist/runtime/heavy-imports.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/interfaces.d.ts +16 -0
- package/dist/runtime/interfaces.d.ts.map +1 -0
- package/dist/runtime/singletons.d.ts +21 -0
- package/dist/runtime/singletons.d.ts.map +1 -0
- package/dist/runtime/state.d.ts +8 -0
- package/dist/runtime/state.d.ts.map +1 -0
- package/dist/runtime/tracked-state-schema.d.ts +36 -0
- package/dist/runtime/tracked-state-schema.d.ts.map +1 -0
- package/dist/runtime/tracked-state.d.ts +57 -0
- package/dist/runtime/tracked-state.d.ts.map +1 -0
- package/dist/runtime/workflows/index.d.ts +7 -0
- package/dist/runtime/workflows/index.d.ts.map +1 -0
- package/dist/runtime/workflows/knowledge-indexing.d.ts +109 -0
- package/dist/runtime/workflows/knowledge-indexing.d.ts.map +1 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +47545 -0
- package/dist/runtime.js.map +7 -0
- package/dist/telemetry/context-manager.d.ts +16 -0
- package/dist/telemetry/context-manager.d.ts.map +1 -0
- package/dist/telemetry/file-exporter.d.ts +11 -0
- package/dist/telemetry/file-exporter.d.ts.map +1 -0
- package/dist/telemetry/instrument-http.d.ts +4 -0
- package/dist/telemetry/instrument-http.d.ts.map +1 -0
- package/dist/telemetry/live-file-processor.d.ts +13 -0
- package/dist/telemetry/live-file-processor.d.ts.map +1 -0
- package/dist/telemetry/span-helpers.d.ts +30 -0
- package/dist/telemetry/span-helpers.d.ts.map +1 -0
- package/dist/telemetry/spans/factory.d.ts +44 -0
- package/dist/telemetry/spans/factory.d.ts.map +1 -0
- package/dist/telemetry/spans/index.d.ts +1009 -0
- package/dist/telemetry/spans/index.d.ts.map +1 -0
- package/dist/telemetry/spans/well-known-attributes.d.ts +78 -0
- package/dist/telemetry/spans/well-known-attributes.d.ts.map +1 -0
- package/dist/telemetry/structured-logging.d.ts +34 -0
- package/dist/telemetry/structured-logging.d.ts.map +1 -0
- package/dist/telemetry/tracing.d.ts +6 -0
- package/dist/telemetry/tracing.d.ts.map +1 -0
- package/dist/telemetry/utils.d.ts +3 -0
- package/dist/telemetry/utils.d.ts.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/ui.d.ts +10 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +749 -0
- package/dist/ui.js.map +7 -0
- package/dist/utilities/abort-signal.d.ts +41 -0
- package/dist/utilities/abort-signal.d.ts.map +1 -0
- package/dist/utilities/events.d.ts +10 -0
- package/dist/utilities/events.d.ts.map +1 -0
- package/dist/utilities/promises.d.ts +3 -0
- package/dist/utilities/promises.d.ts.map +1 -0
- package/dist/utilities/size.d.ts +12 -0
- package/dist/utilities/size.d.ts.map +1 -0
- package/dist/utilities/strings.d.ts +18 -0
- package/dist/utilities/strings.d.ts.map +1 -0
- package/dist/utilities/trigger-tags.d.ts +31 -0
- package/dist/utilities/trigger-tags.d.ts.map +1 -0
- package/dist/utilities/types.d.ts +2 -0
- package/dist/utilities/types.d.ts.map +1 -0
- package/dist/workers/dev_worker.d.ts +6 -0
- package/dist/workers/dev_worker.d.ts.map +1 -0
- package/dist/workers/index.d.ts +5 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/parent_worker.d.ts +5 -0
- package/dist/workers/parent_worker.d.ts.map +1 -0
- package/dist/workers/worker_pool.d.ts +109 -0
- package/dist/workers/worker_pool.d.ts.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Definitions } from "./definition";
|
|
2
|
+
import { z } from "@bpinternal/zui";
|
|
3
|
+
import { Table } from "@botpress/client";
|
|
4
|
+
import { ZuiObjectSchema } from "@botpress/sdk";
|
|
5
|
+
import { TableDefinitions } from "../_types/tables";
|
|
6
|
+
export declare namespace Typings {
|
|
7
|
+
type ColumnDefinition<TName extends string = string> = {
|
|
8
|
+
computed?: boolean;
|
|
9
|
+
searchable?: boolean;
|
|
10
|
+
schema: z.ZodTypeAny;
|
|
11
|
+
dependencies?: ReadonlyArray<keyof TableDefinitions[TName]["Output"]>;
|
|
12
|
+
value?: (row: any) => Promise<any>;
|
|
13
|
+
};
|
|
14
|
+
type Props<TName extends string = string> = {
|
|
15
|
+
name: TName;
|
|
16
|
+
description?: string;
|
|
17
|
+
factor?: number;
|
|
18
|
+
columns: Record<string, z.ZodTypeAny | ColumnDefinition<TName>>;
|
|
19
|
+
};
|
|
20
|
+
const Primitive: "table";
|
|
21
|
+
}
|
|
22
|
+
type NestedKeyOf<T> = T extends object ? {
|
|
23
|
+
[K in keyof T & string]: K | (T[K] extends (infer U)[] ? K | `${K}.${number}` | (U extends object ? `${K}.${number}.${NestedKeyOf<U>}` : never) : T[K] extends object ? K | `${K}.${NestedKeyOf<T[K]>}` : K);
|
|
24
|
+
}[keyof T & string] : never;
|
|
25
|
+
export type PrimitiveFilter<T> = {
|
|
26
|
+
$eq?: T;
|
|
27
|
+
$gt?: T;
|
|
28
|
+
$gte?: T;
|
|
29
|
+
$lt?: T;
|
|
30
|
+
$lte?: T;
|
|
31
|
+
$ne?: T;
|
|
32
|
+
$in?: T[];
|
|
33
|
+
$nin?: T[];
|
|
34
|
+
$exists?: boolean;
|
|
35
|
+
$regex?: string;
|
|
36
|
+
$options?: "i" | "c";
|
|
37
|
+
};
|
|
38
|
+
export type LogicalFilter<TColumns, TName extends string = string> = {
|
|
39
|
+
$and?: TableFilter<TColumns, TName>[];
|
|
40
|
+
$or?: TableFilter<TColumns, TName>[];
|
|
41
|
+
$not?: TableFilter<TColumns, TName>;
|
|
42
|
+
};
|
|
43
|
+
export type TableFilter<TColumns, TName extends string = string> = {
|
|
44
|
+
[K in keyof TColumns]?: TColumns[K] | PrimitiveFilter<TColumns[K]>;
|
|
45
|
+
} & {
|
|
46
|
+
[K in NestedKeyOf<TColumns>]?: any | PrimitiveFilter<any>;
|
|
47
|
+
} & LogicalFilter<TColumns, TName>;
|
|
48
|
+
export type OrderDirection = "asc" | "desc";
|
|
49
|
+
type NumberAggregations = "key" | "count" | "sum" | "avg" | "max" | "min" | "unique";
|
|
50
|
+
type StringAggregations = "key" | "count" | "max" | "min" | "unique";
|
|
51
|
+
type DateAggregations = "key" | "count" | "max" | "min" | "unique";
|
|
52
|
+
type BooleanAggregations = "key" | "count" | "unique";
|
|
53
|
+
type ArrayAggregations = "key" | "count" | "unique";
|
|
54
|
+
type ObjectAggregations = "key" | "count" | "unique";
|
|
55
|
+
type GetAggregations<T> = T extends number ? NumberAggregations : T extends string ? StringAggregations : T extends Date ? DateAggregations : T extends boolean ? BooleanAggregations : T extends any[] ? ArrayAggregations : T extends object ? ObjectAggregations : "key" | "count" | "unique";
|
|
56
|
+
type GetTypeAtPath<T, Path> = Path extends `${infer K}.${infer Rest}` ? K extends keyof T ? GetTypeAtPath<T[K], Rest> : any : Path extends keyof T ? T[Path] : any;
|
|
57
|
+
export type TableGroup<TColumns> = {
|
|
58
|
+
[K in NestedKeyOf<TColumns>]?: GetAggregations<GetTypeAtPath<TColumns, K>> | GetAggregations<GetTypeAtPath<TColumns, K>>[];
|
|
59
|
+
};
|
|
60
|
+
type CamelCasePath<S extends string> = S extends `${infer A}.${infer B}` ? `${A}${Capitalize<CamelCasePath<B>>}` : S;
|
|
61
|
+
type AggregatedFieldName<Path extends string, Op extends string> = Op extends "key" ? `${CamelCasePath<Path>}Key` : `${CamelCasePath<Path>}${Capitalize<Op>}`;
|
|
62
|
+
type AggregationResultType<T, Op extends string> = Op extends "count" ? number : Op extends "sum" ? number : Op extends "avg" ? number : Op extends "max" ? T : Op extends "min" ? T : Op extends "unique" ? T[] : Op extends "key" ? T : never;
|
|
63
|
+
type GroupResultShape<TColumns, TGroup> = TGroup extends TableGroup<TColumns> ? {
|
|
64
|
+
[K in keyof TGroup as TGroup[K] extends string ? AggregatedFieldName<K & string, TGroup[K]> : TGroup[K] extends readonly string[] ? TGroup[K][number] extends string ? AggregatedFieldName<K & string, TGroup[K][number]> : never : never]: TGroup[K] extends string ? AggregationResultType<GetTypeAtPath<TColumns, K & string>, TGroup[K]> : TGroup[K] extends readonly string[] ? TGroup[K][number] extends string ? AggregationResultType<GetTypeAtPath<TColumns, K & string>, TGroup[K][number]> : never : never;
|
|
65
|
+
} : never;
|
|
66
|
+
export interface FindRowsOptions<TName extends string> {
|
|
67
|
+
filter?: TableFilter<TableDefinitions[TName]["Input"], TName>;
|
|
68
|
+
orderBy?: keyof TableDefinitions[TName]["Output"];
|
|
69
|
+
orderDirection?: OrderDirection;
|
|
70
|
+
limit?: number;
|
|
71
|
+
offset?: number;
|
|
72
|
+
search?: string;
|
|
73
|
+
group?: TableGroup<TableDefinitions[TName]["Output"]>;
|
|
74
|
+
}
|
|
75
|
+
type Row<Shape> = {
|
|
76
|
+
id: number;
|
|
77
|
+
createdAt: string;
|
|
78
|
+
updatedAt: string;
|
|
79
|
+
} & Shape;
|
|
80
|
+
type SearchResult<Shape> = {
|
|
81
|
+
id: number;
|
|
82
|
+
createdAt: string;
|
|
83
|
+
updatedAt: string;
|
|
84
|
+
similarity: number;
|
|
85
|
+
} & Shape;
|
|
86
|
+
export declare class BaseTable<TName extends string = string> implements Definitions.Primitive {
|
|
87
|
+
readonly name: TName;
|
|
88
|
+
readonly description?: string;
|
|
89
|
+
readonly factor: number;
|
|
90
|
+
readonly columns: Record<string, Typings.ColumnDefinition<TName>>;
|
|
91
|
+
readonly schema: ZuiObjectSchema;
|
|
92
|
+
readonly nullableColumns: Set<string>;
|
|
93
|
+
readonly searchableColumns: Set<string>;
|
|
94
|
+
readonly computedColumns: Set<string>;
|
|
95
|
+
private get client();
|
|
96
|
+
constructor(props: Typings.Props<TName>);
|
|
97
|
+
getRow(props: {
|
|
98
|
+
id: number;
|
|
99
|
+
}): Promise<Row<TableDefinitions[TName]["Output"]>>;
|
|
100
|
+
findRows<TOptions extends FindRowsOptions<TName>>(options?: TOptions): Promise<{
|
|
101
|
+
rows: TOptions["group"] extends TableGroup<TableDefinitions[TName]["Output"]> ? GroupResultShape<TableDefinitions[TName]["Output"], TOptions["group"]>[] : SearchResult<TableDefinitions[TName]["Output"]>[];
|
|
102
|
+
hasMore: boolean;
|
|
103
|
+
limit: number;
|
|
104
|
+
offset: number;
|
|
105
|
+
}>;
|
|
106
|
+
createRows({ rows, waitComputed, }: {
|
|
107
|
+
rows: TableDefinitions[TName]["Input"][];
|
|
108
|
+
waitComputed?: boolean;
|
|
109
|
+
}): Promise<{
|
|
110
|
+
rows: Row<TableDefinitions[TName]["Output"]>[];
|
|
111
|
+
errors?: string[];
|
|
112
|
+
warnings?: string[];
|
|
113
|
+
}>;
|
|
114
|
+
deleteAllRows(): Promise<{
|
|
115
|
+
deletedRows: number;
|
|
116
|
+
}>;
|
|
117
|
+
deleteRowIds(ids: number[]): Promise<{
|
|
118
|
+
deletedRows: number;
|
|
119
|
+
}>;
|
|
120
|
+
deleteRows(filter: FindRowsOptions<TName>["filter"]): Promise<{
|
|
121
|
+
deletedRows: number;
|
|
122
|
+
}>;
|
|
123
|
+
updateRows(props: {
|
|
124
|
+
rows: (Partial<TableDefinitions[TName]["Input"]> & {
|
|
125
|
+
id: number;
|
|
126
|
+
})[];
|
|
127
|
+
waitComputed?: boolean;
|
|
128
|
+
}): Promise<{
|
|
129
|
+
rows: Row<TableDefinitions[TName]["Output"]>[];
|
|
130
|
+
errors?: string[];
|
|
131
|
+
warnings?: string[];
|
|
132
|
+
}>;
|
|
133
|
+
upsertRows(props: {
|
|
134
|
+
rows: (Partial<TableDefinitions[TName]["Input"]> & {
|
|
135
|
+
id?: number;
|
|
136
|
+
})[];
|
|
137
|
+
waitComputed?: boolean;
|
|
138
|
+
keyColumn?: keyof TableDefinitions[TName]["Input"];
|
|
139
|
+
}): Promise<{
|
|
140
|
+
updated: Row<TableDefinitions[TName]["Output"]>[];
|
|
141
|
+
inserted: Row<TableDefinitions[TName]["Output"]>[];
|
|
142
|
+
errors?: string[];
|
|
143
|
+
warnings?: string[];
|
|
144
|
+
}>;
|
|
145
|
+
getTable(): Promise<{
|
|
146
|
+
rows: number;
|
|
147
|
+
stale: number;
|
|
148
|
+
indexing: number;
|
|
149
|
+
table: Table;
|
|
150
|
+
}>;
|
|
151
|
+
}
|
|
152
|
+
export { BaseTable as Table };
|
|
153
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/primitives/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAc,CAAC,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAU,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,yBAAiB,OAAO,CAAC;IACvB,KAAY,gBAAgB,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI;QAC5D,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC;QACrB,YAAY,CAAC,EAAE,aAAa,CAAC,MAAM,gBAAgB,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtE,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;KACpC,CAAC;IAEF,KAAY,KAAK,CAAC,KAAK,SAAS,MAAM,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AAQ,CAAC,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;KACrB,CAAC;IAgBI,QAAQ,IAAI,OAAO,CAAC;QACxB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,KAAK,CAAC;KACd,CAAC;CAWH;AAGD,OAAO,EAAE,SAAS,IAAI,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Definitions } from "./definition";
|
|
2
|
+
import { EventName } from "../_types/events";
|
|
3
|
+
import { Triggers } from "../_types/triggers";
|
|
4
|
+
export declare namespace Typings {
|
|
5
|
+
type TriggerHandlerProps<TName extends keyof Triggers> = {
|
|
6
|
+
event: TName extends keyof Triggers ? Triggers[TName]["event"] : any;
|
|
7
|
+
};
|
|
8
|
+
type Props<TName extends keyof Triggers = keyof Triggers> = {
|
|
9
|
+
name: TName;
|
|
10
|
+
description?: string;
|
|
11
|
+
events: EventName[];
|
|
12
|
+
/**
|
|
13
|
+
* Handler function that receives the matched event
|
|
14
|
+
*/
|
|
15
|
+
handler: (props: TriggerHandlerProps<TName>) => Promise<void> | void;
|
|
16
|
+
};
|
|
17
|
+
const Primitive: "trigger";
|
|
18
|
+
}
|
|
19
|
+
export declare class Trigger<TName extends keyof Triggers> implements Definitions.Primitive {
|
|
20
|
+
readonly name: TName;
|
|
21
|
+
readonly description: string | undefined;
|
|
22
|
+
readonly events: EventName[];
|
|
23
|
+
readonly handler: Typings.Props<TName>["handler"];
|
|
24
|
+
constructor(props: Typings.Props<TName>);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=trigger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger.d.ts","sourceRoot":"","sources":["../../src/primitives/trigger.ts"],"names":[],"mappings":"AACA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{ WorkflowDefinitions } from "../_types/workflows";
|
|
5
|
+
import { Autonomous } from "../runtime/autonomous";
|
|
6
|
+
import { TrackedState } from "../runtime/index";
|
|
7
|
+
export type WorkflowStepContext = {
|
|
8
|
+
output?: unknown;
|
|
9
|
+
attempts: number;
|
|
10
|
+
startedAt: string;
|
|
11
|
+
finishedAt?: string;
|
|
12
|
+
steps?: Record<string, WorkflowStepContext>;
|
|
13
|
+
};
|
|
14
|
+
declare const StepSymbol: unique symbol;
|
|
15
|
+
type StepExecutionSignal = {
|
|
16
|
+
[StepSymbol]: true;
|
|
17
|
+
};
|
|
18
|
+
export declare function isStepSignal(e: unknown): e is StepExecutionSignal;
|
|
19
|
+
export declare function createStepSignal(): StepExecutionSignal;
|
|
20
|
+
/**
|
|
21
|
+
* Base class for all workflow instances
|
|
22
|
+
*/
|
|
23
|
+
export declare class BaseWorkflowInstance<TName extends keyof WorkflowDefinitions> {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly name: TName;
|
|
26
|
+
readonly key?: string | undefined;
|
|
27
|
+
readonly input: WorkflowDefinitions[TName]["input"];
|
|
28
|
+
readonly createdAt: Date;
|
|
29
|
+
readonly updatedAt: Date;
|
|
30
|
+
readonly client: BotClient<any>;
|
|
31
|
+
readonly status: string;
|
|
32
|
+
readonly workflow: Workflow;
|
|
33
|
+
set state(state: WorkflowDefinitions[TName]["state"]);
|
|
34
|
+
get state(): WorkflowDefinitions[TName]["state"];
|
|
35
|
+
constructor(workflow: Workflow, client: BotClient<any>);
|
|
36
|
+
static readonly Primitive: "workflow_instance";
|
|
37
|
+
static load<TName extends keyof WorkflowDefinitions>(props: {
|
|
38
|
+
id: string;
|
|
39
|
+
workflow?: Workflow;
|
|
40
|
+
}): Promise<BaseWorkflowInstance<TName>>;
|
|
41
|
+
/**
|
|
42
|
+
* Executes the workflow with the provided autonomous engine configuration.
|
|
43
|
+
* Workflows always run in "worker" mode (no chat capabilities).
|
|
44
|
+
*/
|
|
45
|
+
execute(props: Autonomous.Props): Promise<import("llmz").ExecutionResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Provide data in response to a workflow data request (instance method).
|
|
48
|
+
* Call this method from a conversation handler when you receive a WorkflowDataRequestEvent.
|
|
49
|
+
* @param request - The name of the request being responded to
|
|
50
|
+
* @param data - The data to provide to the workflow
|
|
51
|
+
* @example
|
|
52
|
+
* if (type === 'workflow_request') {
|
|
53
|
+
* await workflow.provide('topic', { topic: "Hello" });
|
|
54
|
+
* }
|
|
55
|
+
*/
|
|
56
|
+
provide<TRequest extends keyof WorkflowDefinitions[TName]["requests"] & string>(request: TRequest, data: WorkflowDefinitions[TName]["requests"][TRequest]): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns a string representation for console.log
|
|
59
|
+
*/
|
|
60
|
+
toString(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Returns a JSON representation for serialization
|
|
63
|
+
*/
|
|
64
|
+
toJSON(): any;
|
|
65
|
+
}
|
|
66
|
+
export declare function createWorkflowExecutionState(client: Client, workflowId: string): TrackedState<import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodObject<{
|
|
67
|
+
executionCount: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodNumber>;
|
|
68
|
+
revision: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodNumber>;
|
|
69
|
+
steps: import("@bpinternal/zui").ZodRecord<import("@bpinternal/zui").ZodString, z.ZodType<WorkflowStepContext>>;
|
|
70
|
+
}, "strip", {
|
|
71
|
+
executionCount: number;
|
|
72
|
+
revision: number;
|
|
73
|
+
steps: Record<string, WorkflowStepContext>;
|
|
74
|
+
}, {
|
|
75
|
+
steps: Record<string, WorkflowStepContext>;
|
|
76
|
+
executionCount?: number | undefined;
|
|
77
|
+
revision?: number | undefined;
|
|
78
|
+
}>>>;
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=workflow-instance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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"../types";
|
|
4
|
+
import { z, type ZodType } from "@botpress/sdk";
|
|
5
|
+
type WorkflowStepOptions = {
|
|
6
|
+
maxAttempts?: number;
|
|
7
|
+
};
|
|
8
|
+
type MapOptions = {
|
|
9
|
+
maxAttempts?: number;
|
|
10
|
+
concurrency?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Workflow step execution API. Steps are the building blocks of workflows with automatic retry logic and state persistence.
|
|
14
|
+
*/
|
|
15
|
+
export interface WorkflowStep {
|
|
16
|
+
/**
|
|
17
|
+
* Execute a workflow step with automatic retry logic and state persistence.
|
|
18
|
+
* Steps are idempotent and resumable - if a step has already been executed, its cached result is returned immediately.
|
|
19
|
+
* @param name - Unique identifier for this step within the workflow
|
|
20
|
+
* @param run - Function to execute, receives the current attempt number
|
|
21
|
+
* @param options - Configuration options
|
|
22
|
+
* @param options.maxAttempts - Maximum number of retry attempts (default: 5)
|
|
23
|
+
* @returns The result of the step execution
|
|
24
|
+
* @example
|
|
25
|
+
* const data = await step("fetch-user", async () => {
|
|
26
|
+
* return await fetchUser(userId);
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
<T>(name: string, run: ({ attempt }: {
|
|
30
|
+
attempt: number;
|
|
31
|
+
}) => T | Promise<T>, options?: WorkflowStepOptions): Promise<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Put the workflow into listening mode, waiting for external events to resume.
|
|
34
|
+
* The workflow will pause at this step and can be resumed by triggering it with an event.
|
|
35
|
+
* @param name - The name of the step
|
|
36
|
+
* @example
|
|
37
|
+
* await step.listen("wait-for-approval");
|
|
38
|
+
* // Workflow pauses here until an event triggers it to continue
|
|
39
|
+
*/
|
|
40
|
+
listen(name: string): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Mark the workflow as failed with a specific reason and stop execution.
|
|
43
|
+
* This immediately terminates the workflow and sets its status to "failed".
|
|
44
|
+
* @param reason - Description of why the workflow failed
|
|
45
|
+
* @example
|
|
46
|
+
* if (!user.isVerified) {
|
|
47
|
+
* await step.fail("User verification required");
|
|
48
|
+
* }
|
|
49
|
+
*/
|
|
50
|
+
fail(reason: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Record a progress checkpoint in the workflow without performing any action.
|
|
53
|
+
* Useful for tracking workflow execution stages and creating audit trails.
|
|
54
|
+
* @param name - The name of the progress checkpoint
|
|
55
|
+
* @example
|
|
56
|
+
* await step.progress("Started processing");
|
|
57
|
+
* // ... do work ...
|
|
58
|
+
* await step.progress("Finished processing");
|
|
59
|
+
*/
|
|
60
|
+
progress(name: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Immediately abort the workflow execution without marking it as failed.
|
|
63
|
+
* The workflow status remains unchanged and can potentially be resumed later.
|
|
64
|
+
* This is different from step.fail() which marks the workflow as failed.
|
|
65
|
+
* @example
|
|
66
|
+
* if (shouldPause) {
|
|
67
|
+
* step.abort(); // Stop execution but keep workflow in current state
|
|
68
|
+
* }
|
|
69
|
+
*/
|
|
70
|
+
abort(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Pause workflow execution for the specified duration in milliseconds.
|
|
73
|
+
* For delays >= 10 seconds, the workflow enters listening mode to save resources.
|
|
74
|
+
* For shorter delays, uses an in-memory timeout.
|
|
75
|
+
* @param name - The name of the step
|
|
76
|
+
* @param ms - Duration to sleep in milliseconds
|
|
77
|
+
* @example
|
|
78
|
+
* await step.sleep("wait-5-min", 5 * 60 * 1000);
|
|
79
|
+
* await step.sleep("short-delay", 1000);
|
|
80
|
+
*/
|
|
81
|
+
sleep(name: string, ms: number): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Sleep until the specified date, minus a buffer to ensure the step can complete before the workflow times out.
|
|
84
|
+
* If the date is in the past, the step will return immediately.
|
|
85
|
+
* @param name - The name of the step
|
|
86
|
+
* @param date - The date to sleep until
|
|
87
|
+
* @example
|
|
88
|
+
* await step.sleepUntil("wait-until-noon", new Date("2025-01-15T12:00:00Z"));
|
|
89
|
+
*/
|
|
90
|
+
sleepUntil(name: string, date: Date | string): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Wait for another workflow to complete before continuing.
|
|
93
|
+
* The current workflow will pause and poll until the target workflow finishes.
|
|
94
|
+
* @param name - The name of the step
|
|
95
|
+
* @param workflowId - ID of the workflow to wait for
|
|
96
|
+
* @returns The completed workflow object
|
|
97
|
+
* @throws Error if attempting to wait for the same workflow (would cause deadlock)
|
|
98
|
+
* @example
|
|
99
|
+
* const childWorkflow = await childWorkflowInstance.start({});
|
|
100
|
+
* const result = await step.waitForWorkflow("wait-for-child", childWorkflow.id);
|
|
101
|
+
*/
|
|
102
|
+
waitForWorkflow(name: string, workflowId: string): Promise<Workflow>;
|
|
103
|
+
/**
|
|
104
|
+
* Start another workflow and wait for it to complete, returning its output.
|
|
105
|
+
* This is a convenience method that combines workflow.start() and step.waitForWorkflow().
|
|
106
|
+
* @param name - The name of the step
|
|
107
|
+
* @param workflow - The workflow instance to execute
|
|
108
|
+
* @returns The output of the completed workflow
|
|
109
|
+
* @example
|
|
110
|
+
* const processedData = await step.executeWorkflow(
|
|
111
|
+
* "process-data",
|
|
112
|
+
* dataProcessingWorkflow
|
|
113
|
+
* );
|
|
114
|
+
*/
|
|
115
|
+
executeWorkflow<TName extends string, TInput extends ZuiType, TOutput extends ZodType>(name: string, workflow: BaseWorkflow<TName, TInput, TOutput>, input?: z.infer<TInput>): Promise<z.infer<TOutput>>;
|
|
116
|
+
/**
|
|
117
|
+
* Process an array of items in parallel with controlled concurrency, collecting results.
|
|
118
|
+
* Each item is processed in its own step with automatic retry logic.
|
|
119
|
+
* @param name - The name of the map operation
|
|
120
|
+
* @param items - Array of items to process
|
|
121
|
+
* @param run - Function to process each item, receives the item and its index
|
|
122
|
+
* @param opts - Configuration options
|
|
123
|
+
* @param opts.maxAttempts - Maximum retry attempts per item (default: 5)
|
|
124
|
+
* @param opts.concurrency - Maximum number of concurrent operations (default: 1)
|
|
125
|
+
* @returns Array of results in the same order as input items
|
|
126
|
+
* @example
|
|
127
|
+
* const results = await step.map(
|
|
128
|
+
* "process-users",
|
|
129
|
+
* users,
|
|
130
|
+
* async (user, { i }) => processUser(user),
|
|
131
|
+
* { concurrency: 5 }
|
|
132
|
+
* );
|
|
133
|
+
*/
|
|
134
|
+
map<T, U>(name: string, items: T[], run: (input: T, opts: {
|
|
135
|
+
i: number;
|
|
136
|
+
}) => Promise<U>, opts?: MapOptions): Promise<U[]>;
|
|
137
|
+
/**
|
|
138
|
+
* Process an array of items in parallel without collecting results.
|
|
139
|
+
* Similar to step.map but doesn't return an array of results (for side effects only).
|
|
140
|
+
* @param name - The name of the forEach operation
|
|
141
|
+
* @param items - Array of items to process
|
|
142
|
+
* @param run - Function to process each item, receives the item and its index
|
|
143
|
+
* @param opts - Configuration options
|
|
144
|
+
* @param opts.maxAttempts - Maximum retry attempts per item (default: 5)
|
|
145
|
+
* @param opts.concurrency - Maximum number of concurrent operations (default: 1)
|
|
146
|
+
* @example
|
|
147
|
+
* await step.forEach(
|
|
148
|
+
* "notify-users",
|
|
149
|
+
* users,
|
|
150
|
+
* async (user) => sendNotification(user),
|
|
151
|
+
* { concurrency: 10 }
|
|
152
|
+
* );
|
|
153
|
+
*/
|
|
154
|
+
forEach<T>(name: string, items: T[], run: (input: T, opts: {
|
|
155
|
+
i: number;
|
|
156
|
+
}) => Promise<void>, opts?: MapOptions): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Process an array of items in sequential batches.
|
|
159
|
+
* Items are grouped into batches and each batch is processed as a single step.
|
|
160
|
+
* Useful for bulk operations with external APIs that accept multiple items.
|
|
161
|
+
* @param name - The name of the batch operation
|
|
162
|
+
* @param items - Array of items to process
|
|
163
|
+
* @param run - Function to process each batch, receives the batch array and starting index
|
|
164
|
+
* @param opts - Configuration options
|
|
165
|
+
* @param opts.batchSize - Number of items per batch (default: 20)
|
|
166
|
+
* @param opts.maxAttempts - Maximum retry attempts per batch (default: 5)
|
|
167
|
+
* @example
|
|
168
|
+
* await step.batch(
|
|
169
|
+
* "bulk-insert",
|
|
170
|
+
* records,
|
|
171
|
+
* async (batch) => database.bulkInsert(batch),
|
|
172
|
+
* { batchSize: 100 }
|
|
173
|
+
* );
|
|
174
|
+
*/
|
|
175
|
+
batch<T>(name: string, items: T[], run: (input: T[], opts: {
|
|
176
|
+
i: number;
|
|
177
|
+
}) => Promise<void>, opts?: {
|
|
178
|
+
batchSize?: number;
|
|
179
|
+
maxAttempts?: number;
|
|
180
|
+
}): Promise<void>;
|
|
181
|
+
}
|
|
182
|
+
export declare const step: WorkflowStep;
|
|
183
|
+
export {};
|
|
184
|
+
//# sourceMappingURL=workflow-step.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-step.d.ts","sourceRoot":"","sources":["../../src/primitives/workflow-step.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAU,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAezD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAc,CAAC,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAM5D,KAAK,mBAAmB,GAAG;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,UAAU,GAAG;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;;;OAYG;IACH,CAAC,CAAC,EACA,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACzD,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC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E,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAClD,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAEhB;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,CAAC,EACP,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE;QAAE,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,EACrD,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjB;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,CAAC,EACL,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,EAAE,EACV,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE;QAAE,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,EACvD,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAClD,OAAO,CAAC,IAAI,CAAC,CAAC;CAQlB;AAgKD,eAAO,MAAM,IAAI,EAMX,YAAY,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Client } from "@botpress/client";
|
|
2
|
+
import { z } from "../library";
|
|
3
|
+
import { WorkflowDataRequestEvent } from "../runtime";
|
|
4
|
+
type UpdateWorkflowInput = Client["updateWorkflow"];
|
|
5
|
+
export declare const updateWorkflow: UpdateWorkflowInput;
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if an event is a workflow data request.
|
|
8
|
+
* Use this in conversation handlers to detect when a workflow needs data.
|
|
9
|
+
* @param event - The event to check
|
|
10
|
+
* @returns True if the event is a WorkflowDataRequestEvent
|
|
11
|
+
* @example
|
|
12
|
+
* if (isWorkflowDataRequest(event)) {
|
|
13
|
+
* await MyWorkflow.provide(event, { orderId: "12345" });
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export declare function isWorkflowDataRequest(event: unknown): event is {
|
|
17
|
+
type: typeof WorkflowDataRequestEvent.name;
|
|
18
|
+
payload: z.infer<typeof WorkflowDataRequestEvent.schema>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Type guard to narrow workflow instance by name.
|
|
22
|
+
* Use this in conversation handlers to get properly typed workflow instances.
|
|
23
|
+
* @param workflow - The workflow instance to check
|
|
24
|
+
* @param name - The workflow name to check against
|
|
25
|
+
* @returns True if the workflow matches the given name
|
|
26
|
+
* @example
|
|
27
|
+
* if (type === 'workflow_request' && isWorkflow(workflow, 'test3')) {
|
|
28
|
+
* // workflow is now typed as BaseWorkflowInstance<'test3'>
|
|
29
|
+
* await workflow.provide('topic', { topic: "Hello" });
|
|
30
|
+
* }
|
|
31
|
+
*/
|
|
32
|
+
export declare function isWorkflow<TName extends string>(workflow: {
|
|
33
|
+
name: string;
|
|
34
|
+
} | undefined, name: TName): workflow is import("./workflow-instance").BaseWorkflowInstance<TName extends keyof import("../_types/workflows").WorkflowDefinitions ? TName : never>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=workflow-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-utils.d.ts","sourceRoot":"","sources":["../../src/primitives/workflow-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAW,CAAC,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAGtD,KAAK,mBAAmB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACpD,eAAO,MAAM,cAAc,EAAE,mBAqC5B,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAC9D,IAAI,EAAE,OAAO,wBAAwB,CAAC,IAAI,CAAC;IAC3C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;CAC1D,CAEA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,MAAM,EAC7C,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,EACtC,IAAI,EAAE,KAAK,GACV,QAAQ,IAAI,OAAO,qBAAqB,EAAE,oBAAoB,CAAC,KAAK,SAAS,MAAM,OAAO,qBAAqB,EAAE,mBAAmB,GAAG,KAAK,GAAG,KAAK,CAAC,CAEvJ"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z, ZodType } from "@botpress/sdk";
|
|
2
|
+
import { ZuiType } from "../types";
|
|
3
|
+
import { WorkflowDefinitions } from "../_types/workflows";
|
|
4
|
+
import { BaseWorkflowInstance } from "./workflow-instance";
|
|
5
|
+
import type { WorkflowStep } from "./workflow-step";
|
|
6
|
+
import type { BaseBot, BotClient } from "@botpress/sdk/dist/bot";
|
|
7
|
+
import { Workflow } from "@botpress/client";
|
|
8
|
+
import { Autonomous, WorkflowDataRequestEvent } from "../runtime";
|
|
9
|
+
export declare namespace Typings {
|
|
10
|
+
type StepCallSignature = <T>(name: string, run: ({ attempt }: {
|
|
11
|
+
attempt: number;
|
|
12
|
+
}) => T | Promise<T>, options?: {
|
|
13
|
+
maxAttempts?: number;
|
|
14
|
+
}) => Promise<T>;
|
|
15
|
+
type StepMethods = Pick<WorkflowStep, "listen" | "fail" | "progress" | "abort" | "sleep" | "sleepUntil" | "waitForWorkflow" | "executeWorkflow" | "map" | "forEach" | "batch">;
|
|
16
|
+
export type TypedWorkflowStep<Requests extends Record<string, ZuiType>> = StepCallSignature & StepMethods & {
|
|
17
|
+
/**
|
|
18
|
+
* Request data from the conversation and wait for a response.
|
|
19
|
+
* The workflow will pause and send a data request event to the conversation.
|
|
20
|
+
* Use WorkflowInstance.provide() in the conversation handler to respond.
|
|
21
|
+
* @param request - The name of the request (must be defined in workflow requests)
|
|
22
|
+
* @param message - Message to display to the user describing what data is needed
|
|
23
|
+
* @param stepName - Optional custom name for the step (defaults to request)
|
|
24
|
+
* @returns The provided data validated against the request schema
|
|
25
|
+
* @throws Error if workflow has no conversationId or request not found
|
|
26
|
+
*/
|
|
27
|
+
request<TRequest extends keyof Requests & string>(request: TRequest, message: string, stepName?: string): Promise<z.infer<Requests[TRequest]>>;
|
|
28
|
+
};
|
|
29
|
+
export type HandlerProps<Input extends ZuiType = ZuiType, _Output extends ZuiType = ZuiType, State extends ZuiType = ZuiType, Requests extends Record<string, ZuiType> = Record<string, ZuiType>, TBot extends BaseBot = BaseBot> = {
|
|
30
|
+
input: z.infer<Input>;
|
|
31
|
+
state: z.infer<State>;
|
|
32
|
+
step: TypedWorkflowStep<Requests>;
|
|
33
|
+
client: BotClient<TBot>;
|
|
34
|
+
execute: Autonomous.ExecuteFn;
|
|
35
|
+
};
|
|
36
|
+
export type Handler<TName extends string = string, Input extends ZuiType = ZuiType, Output extends ZuiType = ZuiType, State extends ZuiType = ZuiType, Requests extends Record<string, ZuiType> = Record<string, ZuiType>> = (this: BaseWorkflowInstance<TName>, props: HandlerProps<Input, Output, State, Requests>) => Promise<z.infer<Output>> | z.infer<Output>;
|
|
37
|
+
export type Props<TName extends string = string, Input extends ZuiType = ZuiType, Output extends ZuiType = ZuiType, State extends ZuiType = ZuiType, Requests extends Record<string, ZuiType> = Record<string, ZuiType>> = {
|
|
38
|
+
name: TName;
|
|
39
|
+
description?: string;
|
|
40
|
+
input?: Input;
|
|
41
|
+
output?: Output;
|
|
42
|
+
state?: State;
|
|
43
|
+
requests?: Requests;
|
|
44
|
+
handler: Handler<TName, Input, Output, State, Requests>;
|
|
45
|
+
schedule?: string;
|
|
46
|
+
timeout?: `${number}s` | `${number}m` | `${number}h`;
|
|
47
|
+
};
|
|
48
|
+
export const Primitive: "workflow";
|
|
49
|
+
export {};
|
|
50
|
+
}
|
|
51
|
+
export declare class BaseWorkflow<TName extends string = string, Input extends ZuiType = WorkflowDefinitions[TName] extends never ? ZuiType : WorkflowDefinitions[TName]["input"] extends ZodType ? WorkflowDefinitions[TName]["input"] : ZuiType, Output extends ZuiType = WorkflowDefinitions[TName] extends never ? ZuiType : WorkflowDefinitions[TName]["output"] extends ZodType ? WorkflowDefinitions[TName]["output"] : ZuiType, State extends ZuiType = WorkflowDefinitions[TName] extends never ? ZuiType : WorkflowDefinitions[TName]["state"] extends ZodType ? WorkflowDefinitions[TName]["state"] : ZuiType, Requests extends Record<string, ZuiType> = Record<string, ZuiType>> {
|
|
52
|
+
readonly name: TName;
|
|
53
|
+
readonly description?: string;
|
|
54
|
+
readonly timeout: number;
|
|
55
|
+
state: z.infer<State>;
|
|
56
|
+
constructor(props: Typings.Props<TName, Input, Output, State, Requests>);
|
|
57
|
+
/**
|
|
58
|
+
* Get or create a workflow instance with the given key and input
|
|
59
|
+
*
|
|
60
|
+
* @param props.key - Optional unique key for workflow deduplication
|
|
61
|
+
* @param props.start - Whether to start the workflow immediately (default: true)
|
|
62
|
+
* @param props.input - The input data for the workflow
|
|
63
|
+
* @returns The workflow instance
|
|
64
|
+
*/
|
|
65
|
+
getOrCreate(props: {
|
|
66
|
+
key?: string;
|
|
67
|
+
statuses?: Workflow["status"][];
|
|
68
|
+
input: WorkflowDefinitions[TName] extends never ? z.infer<Input> : WorkflowDefinitions[TName]["input"];
|
|
69
|
+
}): Promise<BaseWorkflowInstance<TName>>;
|
|
70
|
+
/**
|
|
71
|
+
* Provide data in response to a workflow data request.
|
|
72
|
+
* Call this method from a conversation handler when you receive a WorkflowDataRequestEvent.
|
|
73
|
+
* @param event - The event object from the conversation handler
|
|
74
|
+
* @param data - The data to provide to the workflow
|
|
75
|
+
* @example
|
|
76
|
+
* if (isWorkflowDataRequest(event)) {
|
|
77
|
+
* await SomeWorkflow.provide(event, { orderId: "12345" });
|
|
78
|
+
* }
|
|
79
|
+
*/
|
|
80
|
+
provide(event: {
|
|
81
|
+
type: string;
|
|
82
|
+
payload: z.infer<typeof WorkflowDataRequestEvent.schema>;
|
|
83
|
+
}, data: any): Promise<void>;
|
|
84
|
+
start(input: z.infer<Input>): Promise<BaseWorkflowInstance<TName>>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/primitives/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,oBAAoB,EAErB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAU,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EACL,UAAU,EAEV,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAKpB,yBAAiB,OAAO,CAAC;IAEvB,KAAK,iBAAiB,GAAG,CAAC,CAAC,EACzB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACzD,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,KAC/B,OAAO,CAAC,CAAC,CAAC,CAAC;IAGhB,KAAK,WAAW,GAAG,IA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AAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;KACzC,GAAG,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAoDxC;;;;;;;;;OASG;IACG,OAAO,CACX,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;KAC1D,EACD,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,IAAI,CAAC;IAkDV,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;CAwBzE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BotActions } from "../_types/actions";
|
|
2
|
+
import { IntegrationActions } from "../_types/integration-actions";
|
|
3
|
+
type ActionsProxy = IntegrationActions & BotActions;
|
|
4
|
+
export declare const actions: ActionsProxy;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/runtime/actions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAKnE,KAAK,YAAY,GAAG,kBAAkB,GAAG,UAAU,CAAC;AAEpD,eAAO,MAAM,OAAO,EAAE,YA6LpB,CAAC"}
|