@livechat/platform-workflows 0.1.8 → 0.44.0-beta.v1

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.
@@ -0,0 +1,298 @@
1
+ import { Workflow, WorkflowCore, WorkflowTask, WorkflowTriggerDto, WorkflowElement, WorkflowIntrospection, WorkflowTrigger, WorkflowExecutionTriggerData, WorkflowExecutionTaskData, WorkflowTaskIntrospection, WorkflowExecution, CredentialDto, DeepPartial, WorkflowDto, ProductDto } from '@livechat/developer-studio-api';
2
+ export { AccountDto, DeepPartial, IntegrationNames, ProductDto } from '@livechat/developer-studio-api';
3
+ import { S as Specification, g as WorkflowItemConfig, A as WorkflowItemConfigBase, k as WorkflowItemCustomization, f as WorkflowItemSpecificationRef, a as WorkflowDomain, i as WorkflowItemSpecification, d as WorkflowReferenceDefinition } from './types-BSdHiBvO.mjs';
4
+ import { FieldErrors } from '@rjsf/utils';
5
+ import { ErrorObject } from 'ajv';
6
+ import { JSONSchema7 } from 'json-schema';
7
+ export * from '@livechat/developer-studio-api/workflow-contracts';
8
+
9
+ interface BuildWorkflowResult {
10
+ workflow: Workflow;
11
+ errors: string[];
12
+ }
13
+ declare function buildWorkflowFromLight(input: WorkflowCore, spec?: Specification): BuildWorkflowResult;
14
+
15
+ declare enum WorkflowElementActionType {
16
+ AddTrigger = "add_trigger",
17
+ SwitchTrigger = "switch_trigger",
18
+ AddToTrigger = "add_to_trigger"
19
+ }
20
+ interface WorkflowElementAction {
21
+ type: WorkflowElementActionType;
22
+ referenceName?: string;
23
+ }
24
+ type WorkflowElementActions = Record<string, WorkflowElementAction>;
25
+
26
+ type WorkflowConfigs = Record<string, WorkflowItemConfig>;
27
+ type WorkflowElementSpecification<TData> = WorkflowItemConfigBase<TData>['specifications']['versions'][string];
28
+ type WorkflowElementCustomization = WorkflowItemCustomization & {
29
+ providerDisplay: string;
30
+ productDisplay?: string;
31
+ };
32
+ type WorkflowElementConfig<TData> = Omit<WorkflowItemConfigBase<TData>, 'specifications' | 'customization'> & {
33
+ customization: WorkflowElementCustomization;
34
+ specification: WorkflowElementSpecification<TData>;
35
+ };
36
+
37
+ interface WorkflowElementSuggestion {
38
+ value: string;
39
+ isNotConfirmed?: boolean;
40
+ contextMatch?: boolean;
41
+ }
42
+ type WorkflowElementSuggestions = Record<string, WorkflowElementSuggestion[]>;
43
+
44
+ type FieldErrorObject = ErrorObject & {
45
+ severity?: 'error' | 'warning';
46
+ };
47
+ type FieldErrorsExtended = FieldErrors & {
48
+ __errorsExtended?: FieldErrorObject[];
49
+ __errorsByKeyword?: Record<string, FieldErrorObject>;
50
+ };
51
+ type ErrorSchema<T = unknown> = FieldErrorsExtended & {
52
+ [key in keyof T]?: T[key] extends (infer U)[] ? Record<string, ErrorSchema<U>> & FieldErrorsExtended : ErrorSchema<T[key]>;
53
+ };
54
+ type ErrorSchemaExtended<T = unknown> = ErrorSchema<T> & {
55
+ __allErrors?: FieldErrorObject[];
56
+ };
57
+
58
+ interface WorkflowElementAssetReference {
59
+ taskName: string;
60
+ ref: WorkflowItemSpecificationRef<string>;
61
+ }
62
+ interface WorkflowElementAsset {
63
+ reference: WorkflowElementAssetReference;
64
+ resource?: WorkflowElementAssetReference;
65
+ isNotConfirmed?: boolean;
66
+ subject?: WorkflowDomain;
67
+ }
68
+ type WorkflowElementAssets = Record<string, WorkflowElementAsset[]>;
69
+
70
+ declare function mergeAssets(prevAssets: WorkflowElementAssets, newAssets: WorkflowElementAssets): WorkflowElementAssets;
71
+ declare const getTriggerAssets: (trigger: WorkflowTriggerDto, specification: WorkflowItemSpecification) => WorkflowElementAssets;
72
+ declare const getTaskAssets: (task: WorkflowTask, specification: WorkflowItemSpecification, prevAssets: WorkflowElementAssets) => WorkflowElementAssets;
73
+
74
+ interface ObjectMeta {
75
+ properties: Record<string, JSONSchema7 | null>;
76
+ }
77
+ type ObjectWithMeta = object & {
78
+ __meta: ObjectMeta;
79
+ };
80
+
81
+ type WorkflowFrameMeta = ObjectMeta & {
82
+ index: number;
83
+ basePath: string;
84
+ credentialId?: string;
85
+ contentBasePath: string | null;
86
+ config: {
87
+ stale: boolean;
88
+ specification: WorkflowItemSpecification;
89
+ customization: WorkflowItemCustomization;
90
+ };
91
+ };
92
+ type WorkflowElementFrame<TContent = unknown> = TContent & {
93
+ __meta: WorkflowFrameMeta;
94
+ };
95
+ type WorkflowInputFrame = WorkflowElementFrame<Record<string, string> | {
96
+ body?: ObjectWithMeta;
97
+ }>;
98
+ type WorkflowTaskFrame = WorkflowElementFrame<{
99
+ output?: ObjectWithMeta;
100
+ }>;
101
+ interface WorkflowFrames {
102
+ input?: WorkflowInputFrame;
103
+ }
104
+ type WorkflowFrame = WorkflowInputFrame | WorkflowTaskFrame;
105
+ interface WorkflowFrameReference {
106
+ value: string;
107
+ targetValue: string;
108
+ path?: string | null;
109
+ relativePath?: string | null;
110
+ name: string;
111
+ displayName: string;
112
+ type: string;
113
+ displayType: string | string[];
114
+ example?: string | number | boolean | object;
115
+ description?: string;
116
+ outcome?: unknown;
117
+ schema: JSONSchema7 | undefined;
118
+ reference: WorkflowReferenceDefinition | undefined;
119
+ invalid?: boolean;
120
+ invalidReason?: string;
121
+ invalidLevel?: 'error' | 'warning';
122
+ source: {
123
+ index?: number;
124
+ reference?: string;
125
+ credentialId?: string;
126
+ customization?: WorkflowItemCustomization;
127
+ };
128
+ }
129
+ type WorkflowElementEnvironment = {
130
+ workflow: WorkflowFrames;
131
+ } & Record<string, WorkflowTaskFrame | undefined>;
132
+
133
+ declare function getWorkflowElementConfig<TElement extends WorkflowElement>(elementData: TElement, workflowIntrospection: WorkflowIntrospection, specification: Specification, environment?: WorkflowElementEnvironment): WorkflowElementConfig<TElement>;
134
+
135
+ interface WorkflowElementExecution<TTaskData, TTaskExecutionData = unknown> {
136
+ isSuccess: boolean;
137
+ timestamp: string | undefined;
138
+ data: NonNullable<TTaskExecutionData>;
139
+ runtimeData: TTaskData | undefined;
140
+ }
141
+
142
+ declare function createFrameReferenceByContext(path: string, context: WorkflowElementContext | undefined): WorkflowFrameReference;
143
+ declare function createFrameReferenceByEnvironment(path: string, environment: WorkflowElementEnvironment | undefined): WorkflowFrameReference;
144
+ declare const createFrameReference: (path: string, frame: WorkflowTaskFrame | WorkflowInputFrame | undefined, options?: {
145
+ supportAdditionalItems?: boolean;
146
+ }) => WorkflowFrameReference;
147
+
148
+ interface ElementState<TElementData, TElementExecutionData = unknown> {
149
+ definition: TElementData;
150
+ execution: TElementExecutionData | undefined;
151
+ }
152
+ type WorkflowTriggerState = ElementState<WorkflowTrigger, WorkflowExecutionTriggerData>;
153
+ type WorkflowTaskState<TTask extends WorkflowTask = WorkflowTask> = ElementState<TTask, Extract<WorkflowExecutionTaskData, {
154
+ taskType: TTask['type'];
155
+ }>>;
156
+ type WorkflowElementState = WorkflowTriggerState | WorkflowTaskState;
157
+ type WorkflowExecutionElement = WorkflowElementExecution<WorkflowElementState['definition'], WorkflowElementState['execution']>;
158
+ interface WorkflowElementContextBase<TElement extends WorkflowElementState> {
159
+ index: number;
160
+ data: TElement['definition'];
161
+ config: WorkflowElementConfig<TElement['definition']>;
162
+ execution?: WorkflowElementExecution<TElement['definition'], TElement['execution']>;
163
+ frame?: WorkflowElementFrame;
164
+ environment: WorkflowElementEnvironment;
165
+ assets?: WorkflowElementAssets;
166
+ suggestions?: WorkflowElementSuggestions;
167
+ actions?: WorkflowElementActions;
168
+ errors?: ErrorSchemaExtended<TElement['definition']>;
169
+ }
170
+ type WorkflowTriggerContext = WorkflowElementContextBase<WorkflowTriggerState> & {
171
+ frame?: WorkflowInputFrame;
172
+ };
173
+ type WorkflowTaskContext<TTask extends WorkflowTask = WorkflowTask> = WorkflowElementContextBase<WorkflowTaskState<TTask>> & {
174
+ introspection: WorkflowTaskIntrospection | undefined;
175
+ frame: WorkflowTaskFrame;
176
+ };
177
+ type WorkflowElementContext = WorkflowTriggerContext | WorkflowTaskContext;
178
+ interface WorkflowContexts {
179
+ trigger?: WorkflowTriggerContext;
180
+ tasks: Record<string, WorkflowTaskContext>;
181
+ global: WorkflowTaskContext;
182
+ }
183
+
184
+ declare const getWorkflowTaskActions: (config: WorkflowElementConfig<WorkflowTask>, suggestions: WorkflowElementSuggestions, trigger: WorkflowTriggerContext | undefined) => WorkflowElementActions;
185
+
186
+ declare const getWorkflowContexts: (workflow: Workflow, sources?: {
187
+ introspection?: WorkflowIntrospection;
188
+ execution?: WorkflowExecution;
189
+ }, dependencies?: {
190
+ specification?: Specification;
191
+ }) => WorkflowContexts;
192
+
193
+ type WorkflowCredential = CredentialDto & {
194
+ isInternal: boolean;
195
+ };
196
+
197
+ declare const getWorkflowCredentials: (credentials: CredentialDto[]) => WorkflowCredential[];
198
+ declare const getWorkflowElementDefaultCredentialId: (elementProvider: string, credentials: WorkflowCredential[]) => string | undefined;
199
+
200
+ /**
201
+ * Merges a partial change into the workflow and normalizes `join` tasks'
202
+ * `joinOn` to point at the last task of each matching `forkJoin` branch.
203
+ *
204
+ * Assumes the caller owns `workflow` (the editor and `prefillWorkflow` clone at
205
+ * their boundary); `mergeDeep` writes into the first argument.
206
+ */
207
+ declare function applyChange<TWorkflow extends Workflow>(workflow: TWorkflow, change: DeepPartial<TWorkflow>): TWorkflow;
208
+ /**
209
+ * Assigns default credentials to the trigger and every (possibly nested) task.
210
+ * Assumes the caller owns `workflow` (mutates element credential slots in place).
211
+ */
212
+ declare function applyDefaultCredentials<TWorkflow extends Workflow>(workflow: TWorkflow, context: {
213
+ specification: Specification;
214
+ introspection: WorkflowIntrospection;
215
+ credentials: WorkflowCredential[];
216
+ }): TWorkflow;
217
+ /**
218
+ * Re-points / auto-fills the resource-kind input references of the workflow's
219
+ * tasks against the assets reachable from upstream tasks and the trigger:
220
+ *
221
+ * - an empty resource input with exactly one candidate asset is auto-filled,
222
+ * - a stale tag whose previously-bound asset moved is re-pointed to the
223
+ * equivalent current asset (using `previousContexts`),
224
+ * - a tag whose asset no longer exists is cleared.
225
+ *
226
+ * This is the same engine the editor runs on every `updateWorkflow`; pass the
227
+ * contexts of the pre-change workflow as `previousContexts`. Assumes the caller
228
+ * owns `workflow` (task input slots are mutated in place).
229
+ */
230
+ declare function applyWorkflowAssetBindings<TWorkflow extends Workflow>(workflow: TWorkflow, context: {
231
+ specification: Specification;
232
+ introspection: WorkflowIntrospection;
233
+ }, previousContexts: WorkflowContexts): TWorkflow;
234
+ /**
235
+ * Runs the full prefill over a workflow, headless (no React):
236
+ *
237
+ * 1. structural normalization (`applyChange`),
238
+ * 2. default credentials per element (`applyDefaultCredentials`),
239
+ * 3. automatching of resource references (`applyWorkflowAssetBindings`),
240
+ * reproducing the effect the editor applies on every update.
241
+ *
242
+ * Pure: clones the input, so the passed workflow is never mutated. Returns the
243
+ * level it was given — a stored `WorkflowDto` stays a `WorkflowDto`.
244
+ */
245
+ declare function prefillWorkflow<TWorkflow extends Workflow>(workflow: TWorkflow, sources: {
246
+ introspection?: WorkflowIntrospection;
247
+ }, dependencies: {
248
+ credentials: WorkflowCredential[];
249
+ specification?: Specification;
250
+ }): TWorkflow;
251
+
252
+ /**
253
+ * Transforms the (multiply-nested) task tree into a new task tree. The reducer
254
+ * is called for every task; returning a value REPLACES the default handling of
255
+ * that task (and skips recursion into its children), returning `undefined`
256
+ * keeps the task and recurses into `switch` / `forkJoin` / `doWhile` children.
257
+ * The return type is intrinsically `WorkflowTask[]` because the
258
+ * default branches rebuild the typed nested fields (`decisionCases`,
259
+ * `forkTasks`, `loopOver`). Use `reduceTasksRecursively` to fold into `T`.
260
+ */
261
+ declare function recursiveTaskReducer(tasks: WorkflowTask[], reducer: (result: WorkflowTask[], task: WorkflowTask, taskIndex: number, allTasks: WorkflowTask[], level: number) => WorkflowTask[] | undefined, level?: number): WorkflowTask[];
262
+ /**
263
+ * Generic depth-first fold over the (multiply-nested) task tree. Unlike
264
+ * `recursiveTaskReducer` it does NOT rebuild the tree — it threads an
265
+ * accumulator of arbitrary type `T` through every task at every nesting level
266
+ * (descending into `switch`, `forkJoin` and `doWhile` children) and returns
267
+ * whatever the reducer accumulates. Use this for collecting/aggregating;
268
+ * use `recursiveTaskReducer` when you need to transform the tree itself.
269
+ */
270
+ declare function reduceTasksRecursively<T>(tasks: WorkflowTask[], reducer: (accumulator: T, task: WorkflowTask, taskIndex: number, allTasks: WorkflowTask[], level: number) => T, initialValue: T, level?: number): T;
271
+
272
+ declare enum WorkflowValidationErrorType {
273
+ Schema = "schema",
274
+ Resolver = "resolver",
275
+ Connection = "connection",
276
+ Activation = "activation",
277
+ Execution = "execution",
278
+ Stale = "stale"
279
+ }
280
+ interface WorkflowValidation {
281
+ isValid: boolean;
282
+ raw: ErrorSchema<WorkflowDto>;
283
+ errors: {
284
+ trigger?: ErrorSchemaExtended<WorkflowTriggerDto>;
285
+ tasks: Record<string, ErrorSchemaExtended<WorkflowTask>>;
286
+ all: Record<string, ErrorSchemaExtended | undefined>;
287
+ };
288
+ }
289
+
290
+ declare function validateWorkflow(workflow: Workflow, sources: {
291
+ introspection?: WorkflowIntrospection;
292
+ }, dependencies: {
293
+ credentials: CredentialDto[];
294
+ products: ProductDto[];
295
+ specification?: Specification;
296
+ }): WorkflowValidation;
297
+
298
+ export { type BuildWorkflowResult, type WorkflowConfigs, type WorkflowContexts, type WorkflowCredential, type WorkflowElementAction, WorkflowElementActionType, type WorkflowElementActions, type WorkflowElementAsset, type WorkflowElementAssetReference, type WorkflowElementAssets, type WorkflowElementConfig, type WorkflowElementContext, type WorkflowElementContextBase, type WorkflowElementCustomization, type WorkflowElementEnvironment, type WorkflowElementExecution, type WorkflowElementFrame, type WorkflowElementSpecification, type WorkflowElementState, type WorkflowElementSuggestion, type WorkflowElementSuggestions, type WorkflowExecutionElement, type WorkflowFrame, type WorkflowFrameReference, type WorkflowFrames, type WorkflowInputFrame, type WorkflowTaskContext, type WorkflowTaskFrame, type WorkflowTaskState, type WorkflowTriggerContext, type WorkflowTriggerState, type WorkflowValidation, WorkflowValidationErrorType, applyChange, applyDefaultCredentials, applyWorkflowAssetBindings, buildWorkflowFromLight, createFrameReference, createFrameReferenceByContext, createFrameReferenceByEnvironment, getTaskAssets, getTriggerAssets, getWorkflowContexts, getWorkflowCredentials, getWorkflowElementConfig, getWorkflowElementDefaultCredentialId, getWorkflowTaskActions, mergeAssets, prefillWorkflow, recursiveTaskReducer, reduceTasksRecursively, validateWorkflow };
@@ -0,0 +1,298 @@
1
+ import { Workflow, WorkflowCore, WorkflowTask, WorkflowTriggerDto, WorkflowElement, WorkflowIntrospection, WorkflowTrigger, WorkflowExecutionTriggerData, WorkflowExecutionTaskData, WorkflowTaskIntrospection, WorkflowExecution, CredentialDto, DeepPartial, WorkflowDto, ProductDto } from '@livechat/developer-studio-api';
2
+ export { AccountDto, DeepPartial, IntegrationNames, ProductDto } from '@livechat/developer-studio-api';
3
+ import { S as Specification, g as WorkflowItemConfig, A as WorkflowItemConfigBase, k as WorkflowItemCustomization, f as WorkflowItemSpecificationRef, a as WorkflowDomain, i as WorkflowItemSpecification, d as WorkflowReferenceDefinition } from './types-BSdHiBvO.js';
4
+ import { FieldErrors } from '@rjsf/utils';
5
+ import { ErrorObject } from 'ajv';
6
+ import { JSONSchema7 } from 'json-schema';
7
+ export * from '@livechat/developer-studio-api/workflow-contracts';
8
+
9
+ interface BuildWorkflowResult {
10
+ workflow: Workflow;
11
+ errors: string[];
12
+ }
13
+ declare function buildWorkflowFromLight(input: WorkflowCore, spec?: Specification): BuildWorkflowResult;
14
+
15
+ declare enum WorkflowElementActionType {
16
+ AddTrigger = "add_trigger",
17
+ SwitchTrigger = "switch_trigger",
18
+ AddToTrigger = "add_to_trigger"
19
+ }
20
+ interface WorkflowElementAction {
21
+ type: WorkflowElementActionType;
22
+ referenceName?: string;
23
+ }
24
+ type WorkflowElementActions = Record<string, WorkflowElementAction>;
25
+
26
+ type WorkflowConfigs = Record<string, WorkflowItemConfig>;
27
+ type WorkflowElementSpecification<TData> = WorkflowItemConfigBase<TData>['specifications']['versions'][string];
28
+ type WorkflowElementCustomization = WorkflowItemCustomization & {
29
+ providerDisplay: string;
30
+ productDisplay?: string;
31
+ };
32
+ type WorkflowElementConfig<TData> = Omit<WorkflowItemConfigBase<TData>, 'specifications' | 'customization'> & {
33
+ customization: WorkflowElementCustomization;
34
+ specification: WorkflowElementSpecification<TData>;
35
+ };
36
+
37
+ interface WorkflowElementSuggestion {
38
+ value: string;
39
+ isNotConfirmed?: boolean;
40
+ contextMatch?: boolean;
41
+ }
42
+ type WorkflowElementSuggestions = Record<string, WorkflowElementSuggestion[]>;
43
+
44
+ type FieldErrorObject = ErrorObject & {
45
+ severity?: 'error' | 'warning';
46
+ };
47
+ type FieldErrorsExtended = FieldErrors & {
48
+ __errorsExtended?: FieldErrorObject[];
49
+ __errorsByKeyword?: Record<string, FieldErrorObject>;
50
+ };
51
+ type ErrorSchema<T = unknown> = FieldErrorsExtended & {
52
+ [key in keyof T]?: T[key] extends (infer U)[] ? Record<string, ErrorSchema<U>> & FieldErrorsExtended : ErrorSchema<T[key]>;
53
+ };
54
+ type ErrorSchemaExtended<T = unknown> = ErrorSchema<T> & {
55
+ __allErrors?: FieldErrorObject[];
56
+ };
57
+
58
+ interface WorkflowElementAssetReference {
59
+ taskName: string;
60
+ ref: WorkflowItemSpecificationRef<string>;
61
+ }
62
+ interface WorkflowElementAsset {
63
+ reference: WorkflowElementAssetReference;
64
+ resource?: WorkflowElementAssetReference;
65
+ isNotConfirmed?: boolean;
66
+ subject?: WorkflowDomain;
67
+ }
68
+ type WorkflowElementAssets = Record<string, WorkflowElementAsset[]>;
69
+
70
+ declare function mergeAssets(prevAssets: WorkflowElementAssets, newAssets: WorkflowElementAssets): WorkflowElementAssets;
71
+ declare const getTriggerAssets: (trigger: WorkflowTriggerDto, specification: WorkflowItemSpecification) => WorkflowElementAssets;
72
+ declare const getTaskAssets: (task: WorkflowTask, specification: WorkflowItemSpecification, prevAssets: WorkflowElementAssets) => WorkflowElementAssets;
73
+
74
+ interface ObjectMeta {
75
+ properties: Record<string, JSONSchema7 | null>;
76
+ }
77
+ type ObjectWithMeta = object & {
78
+ __meta: ObjectMeta;
79
+ };
80
+
81
+ type WorkflowFrameMeta = ObjectMeta & {
82
+ index: number;
83
+ basePath: string;
84
+ credentialId?: string;
85
+ contentBasePath: string | null;
86
+ config: {
87
+ stale: boolean;
88
+ specification: WorkflowItemSpecification;
89
+ customization: WorkflowItemCustomization;
90
+ };
91
+ };
92
+ type WorkflowElementFrame<TContent = unknown> = TContent & {
93
+ __meta: WorkflowFrameMeta;
94
+ };
95
+ type WorkflowInputFrame = WorkflowElementFrame<Record<string, string> | {
96
+ body?: ObjectWithMeta;
97
+ }>;
98
+ type WorkflowTaskFrame = WorkflowElementFrame<{
99
+ output?: ObjectWithMeta;
100
+ }>;
101
+ interface WorkflowFrames {
102
+ input?: WorkflowInputFrame;
103
+ }
104
+ type WorkflowFrame = WorkflowInputFrame | WorkflowTaskFrame;
105
+ interface WorkflowFrameReference {
106
+ value: string;
107
+ targetValue: string;
108
+ path?: string | null;
109
+ relativePath?: string | null;
110
+ name: string;
111
+ displayName: string;
112
+ type: string;
113
+ displayType: string | string[];
114
+ example?: string | number | boolean | object;
115
+ description?: string;
116
+ outcome?: unknown;
117
+ schema: JSONSchema7 | undefined;
118
+ reference: WorkflowReferenceDefinition | undefined;
119
+ invalid?: boolean;
120
+ invalidReason?: string;
121
+ invalidLevel?: 'error' | 'warning';
122
+ source: {
123
+ index?: number;
124
+ reference?: string;
125
+ credentialId?: string;
126
+ customization?: WorkflowItemCustomization;
127
+ };
128
+ }
129
+ type WorkflowElementEnvironment = {
130
+ workflow: WorkflowFrames;
131
+ } & Record<string, WorkflowTaskFrame | undefined>;
132
+
133
+ declare function getWorkflowElementConfig<TElement extends WorkflowElement>(elementData: TElement, workflowIntrospection: WorkflowIntrospection, specification: Specification, environment?: WorkflowElementEnvironment): WorkflowElementConfig<TElement>;
134
+
135
+ interface WorkflowElementExecution<TTaskData, TTaskExecutionData = unknown> {
136
+ isSuccess: boolean;
137
+ timestamp: string | undefined;
138
+ data: NonNullable<TTaskExecutionData>;
139
+ runtimeData: TTaskData | undefined;
140
+ }
141
+
142
+ declare function createFrameReferenceByContext(path: string, context: WorkflowElementContext | undefined): WorkflowFrameReference;
143
+ declare function createFrameReferenceByEnvironment(path: string, environment: WorkflowElementEnvironment | undefined): WorkflowFrameReference;
144
+ declare const createFrameReference: (path: string, frame: WorkflowTaskFrame | WorkflowInputFrame | undefined, options?: {
145
+ supportAdditionalItems?: boolean;
146
+ }) => WorkflowFrameReference;
147
+
148
+ interface ElementState<TElementData, TElementExecutionData = unknown> {
149
+ definition: TElementData;
150
+ execution: TElementExecutionData | undefined;
151
+ }
152
+ type WorkflowTriggerState = ElementState<WorkflowTrigger, WorkflowExecutionTriggerData>;
153
+ type WorkflowTaskState<TTask extends WorkflowTask = WorkflowTask> = ElementState<TTask, Extract<WorkflowExecutionTaskData, {
154
+ taskType: TTask['type'];
155
+ }>>;
156
+ type WorkflowElementState = WorkflowTriggerState | WorkflowTaskState;
157
+ type WorkflowExecutionElement = WorkflowElementExecution<WorkflowElementState['definition'], WorkflowElementState['execution']>;
158
+ interface WorkflowElementContextBase<TElement extends WorkflowElementState> {
159
+ index: number;
160
+ data: TElement['definition'];
161
+ config: WorkflowElementConfig<TElement['definition']>;
162
+ execution?: WorkflowElementExecution<TElement['definition'], TElement['execution']>;
163
+ frame?: WorkflowElementFrame;
164
+ environment: WorkflowElementEnvironment;
165
+ assets?: WorkflowElementAssets;
166
+ suggestions?: WorkflowElementSuggestions;
167
+ actions?: WorkflowElementActions;
168
+ errors?: ErrorSchemaExtended<TElement['definition']>;
169
+ }
170
+ type WorkflowTriggerContext = WorkflowElementContextBase<WorkflowTriggerState> & {
171
+ frame?: WorkflowInputFrame;
172
+ };
173
+ type WorkflowTaskContext<TTask extends WorkflowTask = WorkflowTask> = WorkflowElementContextBase<WorkflowTaskState<TTask>> & {
174
+ introspection: WorkflowTaskIntrospection | undefined;
175
+ frame: WorkflowTaskFrame;
176
+ };
177
+ type WorkflowElementContext = WorkflowTriggerContext | WorkflowTaskContext;
178
+ interface WorkflowContexts {
179
+ trigger?: WorkflowTriggerContext;
180
+ tasks: Record<string, WorkflowTaskContext>;
181
+ global: WorkflowTaskContext;
182
+ }
183
+
184
+ declare const getWorkflowTaskActions: (config: WorkflowElementConfig<WorkflowTask>, suggestions: WorkflowElementSuggestions, trigger: WorkflowTriggerContext | undefined) => WorkflowElementActions;
185
+
186
+ declare const getWorkflowContexts: (workflow: Workflow, sources?: {
187
+ introspection?: WorkflowIntrospection;
188
+ execution?: WorkflowExecution;
189
+ }, dependencies?: {
190
+ specification?: Specification;
191
+ }) => WorkflowContexts;
192
+
193
+ type WorkflowCredential = CredentialDto & {
194
+ isInternal: boolean;
195
+ };
196
+
197
+ declare const getWorkflowCredentials: (credentials: CredentialDto[]) => WorkflowCredential[];
198
+ declare const getWorkflowElementDefaultCredentialId: (elementProvider: string, credentials: WorkflowCredential[]) => string | undefined;
199
+
200
+ /**
201
+ * Merges a partial change into the workflow and normalizes `join` tasks'
202
+ * `joinOn` to point at the last task of each matching `forkJoin` branch.
203
+ *
204
+ * Assumes the caller owns `workflow` (the editor and `prefillWorkflow` clone at
205
+ * their boundary); `mergeDeep` writes into the first argument.
206
+ */
207
+ declare function applyChange<TWorkflow extends Workflow>(workflow: TWorkflow, change: DeepPartial<TWorkflow>): TWorkflow;
208
+ /**
209
+ * Assigns default credentials to the trigger and every (possibly nested) task.
210
+ * Assumes the caller owns `workflow` (mutates element credential slots in place).
211
+ */
212
+ declare function applyDefaultCredentials<TWorkflow extends Workflow>(workflow: TWorkflow, context: {
213
+ specification: Specification;
214
+ introspection: WorkflowIntrospection;
215
+ credentials: WorkflowCredential[];
216
+ }): TWorkflow;
217
+ /**
218
+ * Re-points / auto-fills the resource-kind input references of the workflow's
219
+ * tasks against the assets reachable from upstream tasks and the trigger:
220
+ *
221
+ * - an empty resource input with exactly one candidate asset is auto-filled,
222
+ * - a stale tag whose previously-bound asset moved is re-pointed to the
223
+ * equivalent current asset (using `previousContexts`),
224
+ * - a tag whose asset no longer exists is cleared.
225
+ *
226
+ * This is the same engine the editor runs on every `updateWorkflow`; pass the
227
+ * contexts of the pre-change workflow as `previousContexts`. Assumes the caller
228
+ * owns `workflow` (task input slots are mutated in place).
229
+ */
230
+ declare function applyWorkflowAssetBindings<TWorkflow extends Workflow>(workflow: TWorkflow, context: {
231
+ specification: Specification;
232
+ introspection: WorkflowIntrospection;
233
+ }, previousContexts: WorkflowContexts): TWorkflow;
234
+ /**
235
+ * Runs the full prefill over a workflow, headless (no React):
236
+ *
237
+ * 1. structural normalization (`applyChange`),
238
+ * 2. default credentials per element (`applyDefaultCredentials`),
239
+ * 3. automatching of resource references (`applyWorkflowAssetBindings`),
240
+ * reproducing the effect the editor applies on every update.
241
+ *
242
+ * Pure: clones the input, so the passed workflow is never mutated. Returns the
243
+ * level it was given — a stored `WorkflowDto` stays a `WorkflowDto`.
244
+ */
245
+ declare function prefillWorkflow<TWorkflow extends Workflow>(workflow: TWorkflow, sources: {
246
+ introspection?: WorkflowIntrospection;
247
+ }, dependencies: {
248
+ credentials: WorkflowCredential[];
249
+ specification?: Specification;
250
+ }): TWorkflow;
251
+
252
+ /**
253
+ * Transforms the (multiply-nested) task tree into a new task tree. The reducer
254
+ * is called for every task; returning a value REPLACES the default handling of
255
+ * that task (and skips recursion into its children), returning `undefined`
256
+ * keeps the task and recurses into `switch` / `forkJoin` / `doWhile` children.
257
+ * The return type is intrinsically `WorkflowTask[]` because the
258
+ * default branches rebuild the typed nested fields (`decisionCases`,
259
+ * `forkTasks`, `loopOver`). Use `reduceTasksRecursively` to fold into `T`.
260
+ */
261
+ declare function recursiveTaskReducer(tasks: WorkflowTask[], reducer: (result: WorkflowTask[], task: WorkflowTask, taskIndex: number, allTasks: WorkflowTask[], level: number) => WorkflowTask[] | undefined, level?: number): WorkflowTask[];
262
+ /**
263
+ * Generic depth-first fold over the (multiply-nested) task tree. Unlike
264
+ * `recursiveTaskReducer` it does NOT rebuild the tree — it threads an
265
+ * accumulator of arbitrary type `T` through every task at every nesting level
266
+ * (descending into `switch`, `forkJoin` and `doWhile` children) and returns
267
+ * whatever the reducer accumulates. Use this for collecting/aggregating;
268
+ * use `recursiveTaskReducer` when you need to transform the tree itself.
269
+ */
270
+ declare function reduceTasksRecursively<T>(tasks: WorkflowTask[], reducer: (accumulator: T, task: WorkflowTask, taskIndex: number, allTasks: WorkflowTask[], level: number) => T, initialValue: T, level?: number): T;
271
+
272
+ declare enum WorkflowValidationErrorType {
273
+ Schema = "schema",
274
+ Resolver = "resolver",
275
+ Connection = "connection",
276
+ Activation = "activation",
277
+ Execution = "execution",
278
+ Stale = "stale"
279
+ }
280
+ interface WorkflowValidation {
281
+ isValid: boolean;
282
+ raw: ErrorSchema<WorkflowDto>;
283
+ errors: {
284
+ trigger?: ErrorSchemaExtended<WorkflowTriggerDto>;
285
+ tasks: Record<string, ErrorSchemaExtended<WorkflowTask>>;
286
+ all: Record<string, ErrorSchemaExtended | undefined>;
287
+ };
288
+ }
289
+
290
+ declare function validateWorkflow(workflow: Workflow, sources: {
291
+ introspection?: WorkflowIntrospection;
292
+ }, dependencies: {
293
+ credentials: CredentialDto[];
294
+ products: ProductDto[];
295
+ specification?: Specification;
296
+ }): WorkflowValidation;
297
+
298
+ export { type BuildWorkflowResult, type WorkflowConfigs, type WorkflowContexts, type WorkflowCredential, type WorkflowElementAction, WorkflowElementActionType, type WorkflowElementActions, type WorkflowElementAsset, type WorkflowElementAssetReference, type WorkflowElementAssets, type WorkflowElementConfig, type WorkflowElementContext, type WorkflowElementContextBase, type WorkflowElementCustomization, type WorkflowElementEnvironment, type WorkflowElementExecution, type WorkflowElementFrame, type WorkflowElementSpecification, type WorkflowElementState, type WorkflowElementSuggestion, type WorkflowElementSuggestions, type WorkflowExecutionElement, type WorkflowFrame, type WorkflowFrameReference, type WorkflowFrames, type WorkflowInputFrame, type WorkflowTaskContext, type WorkflowTaskFrame, type WorkflowTaskState, type WorkflowTriggerContext, type WorkflowTriggerState, type WorkflowValidation, WorkflowValidationErrorType, applyChange, applyDefaultCredentials, applyWorkflowAssetBindings, buildWorkflowFromLight, createFrameReference, createFrameReferenceByContext, createFrameReferenceByEnvironment, getTaskAssets, getTriggerAssets, getWorkflowContexts, getWorkflowCredentials, getWorkflowElementConfig, getWorkflowElementDefaultCredentialId, getWorkflowTaskActions, mergeAssets, prefillWorkflow, recursiveTaskReducer, reduceTasksRecursively, validateWorkflow };