@marktoflow/core 2.0.2 → 2.0.4
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/README.md +69 -6
- package/dist/built-in-operations.d.ts +2 -136
- package/dist/built-in-operations.d.ts.map +1 -1
- package/dist/built-in-operations.js +7 -743
- package/dist/built-in-operations.js.map +1 -1
- package/dist/engine/conditions.d.ts +29 -0
- package/dist/engine/conditions.d.ts.map +1 -0
- package/dist/engine/conditions.js +109 -0
- package/dist/engine/conditions.js.map +1 -0
- package/dist/engine/control-flow.d.ts +35 -0
- package/dist/engine/control-flow.d.ts.map +1 -0
- package/dist/engine/control-flow.js +653 -0
- package/dist/engine/control-flow.js.map +1 -0
- package/dist/engine/index.d.ts +12 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +11 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/retry.d.ts +35 -0
- package/dist/engine/retry.d.ts.map +1 -0
- package/dist/engine/retry.js +86 -0
- package/dist/engine/retry.js.map +1 -0
- package/dist/engine/subworkflow.d.ts +31 -0
- package/dist/engine/subworkflow.d.ts.map +1 -0
- package/dist/engine/subworkflow.js +240 -0
- package/dist/engine/subworkflow.js.map +1 -0
- package/dist/engine/types.d.ts +55 -0
- package/dist/engine/types.d.ts.map +1 -0
- package/dist/engine/types.js +5 -0
- package/dist/{secrets → engine}/types.js.map +1 -1
- package/dist/engine/variable-resolution.d.ts +29 -0
- package/dist/engine/variable-resolution.d.ts.map +1 -0
- package/dist/engine/variable-resolution.js +130 -0
- package/dist/engine/variable-resolution.js.map +1 -0
- package/dist/engine.d.ts +17 -211
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +84 -1351
- package/dist/engine.js.map +1 -1
- package/dist/file-operations.js +1 -1
- package/dist/file-operations.js.map +1 -1
- package/dist/filters/array.d.ts +9 -0
- package/dist/filters/array.d.ts.map +1 -0
- package/dist/filters/array.js +41 -0
- package/dist/filters/array.js.map +1 -0
- package/dist/filters/date.d.ts +9 -0
- package/dist/filters/date.d.ts.map +1 -0
- package/dist/filters/date.js +51 -0
- package/dist/filters/date.js.map +1 -0
- package/dist/filters/index.d.ts +13 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/index.js +13 -0
- package/dist/filters/index.js.map +1 -0
- package/dist/filters/json.d.ts +6 -0
- package/dist/filters/json.d.ts.map +1 -0
- package/dist/filters/json.js +15 -0
- package/dist/filters/json.js.map +1 -0
- package/dist/filters/logic.d.ts +8 -0
- package/dist/filters/logic.d.ts.map +1 -0
- package/dist/filters/logic.js +28 -0
- package/dist/filters/logic.js.map +1 -0
- package/dist/filters/math.d.ts +13 -0
- package/dist/filters/math.d.ts.map +1 -0
- package/dist/filters/math.js +39 -0
- package/dist/filters/math.js.map +1 -0
- package/dist/filters/object.d.ts +11 -0
- package/dist/filters/object.d.ts.map +1 -0
- package/dist/filters/object.js +64 -0
- package/dist/filters/object.js.map +1 -0
- package/dist/filters/regex.d.ts +7 -0
- package/dist/filters/regex.d.ts.map +1 -0
- package/dist/filters/regex.js +38 -0
- package/dist/filters/regex.js.map +1 -0
- package/dist/filters/string.d.ts +11 -0
- package/dist/filters/string.d.ts.map +1 -0
- package/dist/filters/string.js +35 -0
- package/dist/filters/string.js.map +1 -0
- package/dist/filters/type-checks.d.ts +10 -0
- package/dist/filters/type-checks.d.ts.map +1 -0
- package/dist/filters/type-checks.js +30 -0
- package/dist/filters/type-checks.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/nunjucks-filters.d.ts +2 -261
- package/dist/nunjucks-filters.d.ts.map +1 -1
- package/dist/nunjucks-filters.js +24 -582
- package/dist/nunjucks-filters.js.map +1 -1
- package/dist/operations/compress.d.ts +6 -0
- package/dist/operations/compress.d.ts.map +1 -0
- package/dist/operations/compress.js +36 -0
- package/dist/operations/compress.js.map +1 -0
- package/dist/operations/crypto.d.ts +5 -0
- package/dist/operations/crypto.d.ts.map +1 -0
- package/dist/operations/crypto.js +61 -0
- package/dist/operations/crypto.js.map +1 -0
- package/dist/operations/data-ops.d.ts +10 -0
- package/dist/operations/data-ops.d.ts.map +1 -0
- package/dist/operations/data-ops.js +124 -0
- package/dist/operations/data-ops.js.map +1 -0
- package/dist/operations/datetime.d.ts +5 -0
- package/dist/operations/datetime.d.ts.map +1 -0
- package/dist/operations/datetime.js +86 -0
- package/dist/operations/datetime.js.map +1 -0
- package/dist/operations/extract.d.ts +23 -0
- package/dist/operations/extract.d.ts.map +1 -0
- package/dist/operations/extract.js +31 -0
- package/dist/operations/extract.js.map +1 -0
- package/dist/operations/format.d.ts +14 -0
- package/dist/operations/format.d.ts.map +1 -0
- package/dist/operations/format.js +84 -0
- package/dist/operations/format.js.map +1 -0
- package/dist/operations/index.d.ts +13 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +13 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/operations/parse.d.ts +5 -0
- package/dist/operations/parse.d.ts.map +1 -0
- package/dist/operations/parse.js +59 -0
- package/dist/operations/parse.js.map +1 -0
- package/dist/operations/set.d.ts +21 -0
- package/dist/operations/set.d.ts.map +1 -0
- package/dist/operations/set.js +25 -0
- package/dist/operations/set.js.map +1 -0
- package/dist/operations/transform.d.ts +15 -0
- package/dist/operations/transform.d.ts.map +1 -0
- package/dist/operations/transform.js +110 -0
- package/dist/operations/transform.js.map +1 -0
- package/dist/parallel.d.ts +114 -0
- package/dist/parallel.d.ts.map +1 -0
- package/dist/parallel.js +325 -0
- package/dist/parallel.js.map +1 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +2 -0
- package/dist/parser.js.map +1 -1
- package/dist/routing.js +2 -2
- package/dist/routing.js.map +1 -1
- package/dist/sdk-registry.d.ts.map +1 -1
- package/dist/sdk-registry.js +9 -3
- package/dist/sdk-registry.js.map +1 -1
- package/dist/utils/duration.d.ts +23 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +41 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/errors.d.ts +20 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +37 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/workflow-templates.d.ts +80 -0
- package/dist/workflow-templates.d.ts.map +1 -0
- package/dist/workflow-templates.js +248 -0
- package/dist/workflow-templates.js.map +1 -0
- package/package.json +30 -5
- package/dist/secrets/index.d.ts +0 -12
- package/dist/secrets/index.d.ts.map +0 -1
- package/dist/secrets/index.js +0 -11
- package/dist/secrets/index.js.map +0 -1
- package/dist/secrets/providers/aws.d.ts +0 -32
- package/dist/secrets/providers/aws.d.ts.map +0 -1
- package/dist/secrets/providers/aws.js +0 -118
- package/dist/secrets/providers/aws.js.map +0 -1
- package/dist/secrets/providers/azure.d.ts +0 -40
- package/dist/secrets/providers/azure.d.ts.map +0 -1
- package/dist/secrets/providers/azure.js +0 -170
- package/dist/secrets/providers/azure.js.map +0 -1
- package/dist/secrets/providers/env.d.ts +0 -26
- package/dist/secrets/providers/env.d.ts.map +0 -1
- package/dist/secrets/providers/env.js +0 -59
- package/dist/secrets/providers/env.js.map +0 -1
- package/dist/secrets/providers/vault.d.ts +0 -39
- package/dist/secrets/providers/vault.d.ts.map +0 -1
- package/dist/secrets/providers/vault.js +0 -180
- package/dist/secrets/providers/vault.js.map +0 -1
- package/dist/secrets/secret-manager.d.ts +0 -72
- package/dist/secrets/secret-manager.d.ts.map +0 -1
- package/dist/secrets/secret-manager.js +0 -226
- package/dist/secrets/secret-manager.js.map +0 -1
- package/dist/secrets/types.d.ts +0 -105
- package/dist/secrets/types.d.ts.map +0 -1
- package/dist/secrets/types.js +0 -8
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variable and template resolution for marktoflow workflow engine.
|
|
3
|
+
*
|
|
4
|
+
* Handles resolving template expressions ({{ variable }}) and
|
|
5
|
+
* navigating nested variable paths in the execution context.
|
|
6
|
+
*/
|
|
7
|
+
import { renderTemplate } from '../template-engine.js';
|
|
8
|
+
/**
|
|
9
|
+
* Resolve template variables in a value.
|
|
10
|
+
* Supports {{variable}}, {{inputs.name}}, and Nunjucks filters.
|
|
11
|
+
*
|
|
12
|
+
* Uses Nunjucks as the template engine with:
|
|
13
|
+
* - Legacy regex operator support (=~, !~, //) converted to filters
|
|
14
|
+
* - Custom filters for string, array, object, date operations
|
|
15
|
+
* - Jinja2-style control flow ({% for %}, {% if %}, etc.)
|
|
16
|
+
*/
|
|
17
|
+
export function resolveTemplates(value, context) {
|
|
18
|
+
if (typeof value === 'string') {
|
|
19
|
+
// Build the template context with all available variables
|
|
20
|
+
// Spread inputs first, then variables (variables override inputs if same key)
|
|
21
|
+
// Also keep inputs accessible via inputs.* for explicit access
|
|
22
|
+
const templateContext = {
|
|
23
|
+
...context.inputs, // Spread inputs at root level for direct access ({{ path }})
|
|
24
|
+
...context.variables, // Variables override inputs if same key
|
|
25
|
+
inputs: context.inputs, // Also keep inputs accessible as inputs.*
|
|
26
|
+
};
|
|
27
|
+
// Use the new Nunjucks-based template engine with legacy syntax support
|
|
28
|
+
return renderTemplate(value, templateContext);
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return value.map((v) => resolveTemplates(v, context));
|
|
32
|
+
}
|
|
33
|
+
if (value && typeof value === 'object') {
|
|
34
|
+
const result = {};
|
|
35
|
+
for (const [k, v] of Object.entries(value)) {
|
|
36
|
+
result[k] = resolveTemplates(v, context);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a variable path from context.
|
|
44
|
+
* First checks inputs.*, then variables, then stepMetadata, then direct context properties.
|
|
45
|
+
* Exported to allow access from condition evaluation.
|
|
46
|
+
*/
|
|
47
|
+
export function resolveVariablePath(path, context) {
|
|
48
|
+
// Handle inputs.* prefix
|
|
49
|
+
if (path.startsWith('inputs.')) {
|
|
50
|
+
const inputPath = path.slice(7); // Remove 'inputs.'
|
|
51
|
+
return getNestedValue(context.inputs, inputPath);
|
|
52
|
+
}
|
|
53
|
+
// Check variables first (most common case)
|
|
54
|
+
const fromVars = getNestedValue(context.variables, path);
|
|
55
|
+
if (fromVars !== undefined) {
|
|
56
|
+
return fromVars;
|
|
57
|
+
}
|
|
58
|
+
// Check inputs (for bare variable names like "value" instead of "inputs.value")
|
|
59
|
+
const fromInputs = getNestedValue(context.inputs, path);
|
|
60
|
+
if (fromInputs !== undefined) {
|
|
61
|
+
return fromInputs;
|
|
62
|
+
}
|
|
63
|
+
// Check step metadata (for status checks like: step_id.status)
|
|
64
|
+
const fromStepMeta = getNestedValue(context.stepMetadata, path);
|
|
65
|
+
if (fromStepMeta !== undefined) {
|
|
66
|
+
return fromStepMeta;
|
|
67
|
+
}
|
|
68
|
+
// Fall back to direct context access
|
|
69
|
+
return getNestedValue(context, path);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get a nested value from an object using dot notation and array indexing.
|
|
73
|
+
* Supports paths like: "user.name", "items[0].name", "data.users[1].email"
|
|
74
|
+
*/
|
|
75
|
+
export function getNestedValue(obj, path) {
|
|
76
|
+
if (obj === null || obj === undefined) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
// Parse path into parts, handling both dot notation and array indexing
|
|
80
|
+
// Convert "a.b[0].c[1]" into ["a", "b", "0", "c", "1"]
|
|
81
|
+
const parts = [];
|
|
82
|
+
let current = '';
|
|
83
|
+
for (let i = 0; i < path.length; i++) {
|
|
84
|
+
const char = path[i];
|
|
85
|
+
if (char === '.') {
|
|
86
|
+
if (current) {
|
|
87
|
+
parts.push(current);
|
|
88
|
+
current = '';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (char === '[') {
|
|
92
|
+
if (current) {
|
|
93
|
+
parts.push(current);
|
|
94
|
+
current = '';
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (char === ']') {
|
|
98
|
+
if (current) {
|
|
99
|
+
parts.push(current);
|
|
100
|
+
current = '';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
current += char;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (current) {
|
|
108
|
+
parts.push(current);
|
|
109
|
+
}
|
|
110
|
+
// Traverse the object using the parsed parts
|
|
111
|
+
let result = obj;
|
|
112
|
+
for (const part of parts) {
|
|
113
|
+
if (result === null || result === undefined) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
// Check if part is a number (array index)
|
|
117
|
+
const index = Number(part);
|
|
118
|
+
if (!isNaN(index) && Array.isArray(result)) {
|
|
119
|
+
result = result[index];
|
|
120
|
+
}
|
|
121
|
+
else if (typeof result === 'object') {
|
|
122
|
+
result = result[part];
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=variable-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variable-resolution.js","sourceRoot":"","sources":["../../src/engine/variable-resolution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,OAAyB;IACxE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,0DAA0D;QAC1D,8EAA8E;QAC9E,+DAA+D;QAC/D,MAAM,eAAe,GAA4B;YAC/C,GAAG,OAAO,CAAC,MAA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AAC;YACxB,IAAI,OAAO,EAAE,CAAC;gBACZ,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACpB,OAAO,GAAG,EAAE,CAAC;YACf,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,IAAI,CAAC;QAClB,CAAC;IACH,CAAC;IAED,IAAI,OAAO,EAAE,CAAC;QACZ,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,6CAA6C;IAC7C,IAAI,MAAM,GAAY,GAAG,CAAC;IAE1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC5C,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,0CAA0C;QAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3C,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;aAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YACtC,MAAM,GAAI,MAAkC,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,104 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workflow Execution Engine for marktoflow v2.0
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Thin orchestrator that delegates to focused modules:
|
|
5
|
+
* - engine/control-flow.ts — if, switch, for-each, while, map, filter, reduce, parallel, try, script, wait, merge
|
|
6
|
+
* - engine/retry.ts — RetryPolicy, CircuitBreaker
|
|
7
|
+
* - engine/conditions.ts — condition evaluation
|
|
8
|
+
* - engine/variable-resolution.ts — template and variable resolution
|
|
9
|
+
* - engine/subworkflow.ts — sub-workflow and sub-agent execution
|
|
10
|
+
* - engine/types.ts — shared type definitions
|
|
11
|
+
* - utils/duration.ts — duration parsing
|
|
12
|
+
* - utils/errors.ts — error conversion utilities
|
|
6
13
|
*/
|
|
7
|
-
import { Workflow,
|
|
8
|
-
import { type EffectivePermissions, type SecurityPolicy } from './permissions.js';
|
|
14
|
+
import { Workflow, WorkflowResult } from './models.js';
|
|
9
15
|
import { StateStore } from './state.js';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
maxRetries?: number;
|
|
17
|
-
/** Base delay for retry backoff in milliseconds */
|
|
18
|
-
retryBaseDelay?: number;
|
|
19
|
-
/** Maximum delay for retry backoff in milliseconds */
|
|
20
|
-
retryMaxDelay?: number;
|
|
21
|
-
/** Optional rollback registry for rollback error handling */
|
|
22
|
-
rollbackRegistry?: RollbackRegistry;
|
|
23
|
-
/** Failover configuration for step execution */
|
|
24
|
-
failoverConfig?: Partial<FailoverConfig>;
|
|
25
|
-
/** Optional agent health tracker */
|
|
26
|
-
healthTracker?: AgentHealthTracker;
|
|
27
|
-
/** Default agent for AI steps */
|
|
28
|
-
defaultAgent?: string;
|
|
29
|
-
/** Default model for AI steps */
|
|
30
|
-
defaultModel?: string;
|
|
31
|
-
}
|
|
32
|
-
export interface SDKRegistryLike {
|
|
33
|
-
/** Load an SDK by name */
|
|
34
|
-
load(sdkName: string): Promise<unknown>;
|
|
35
|
-
/** Check if SDK is available */
|
|
36
|
-
has(sdkName: string): boolean;
|
|
37
|
-
}
|
|
38
|
-
export interface StepExecutorContext {
|
|
39
|
-
/** Effective model for this step (from step override or workflow default) */
|
|
40
|
-
model: string | undefined;
|
|
41
|
-
/** Effective agent for this step (from step override or workflow default) */
|
|
42
|
-
agent: string | undefined;
|
|
43
|
-
/** Effective permissions for this step */
|
|
44
|
-
permissions: EffectivePermissions | undefined;
|
|
45
|
-
/** Security policy derived from permissions */
|
|
46
|
-
securityPolicy: SecurityPolicy | undefined;
|
|
47
|
-
/** Base path for resolving relative paths */
|
|
48
|
-
basePath: string | undefined;
|
|
49
|
-
}
|
|
50
|
-
export type StepExecutor = (step: WorkflowStep, context: ExecutionContext, sdkRegistry: SDKRegistryLike, executorContext?: StepExecutorContext) => Promise<unknown>;
|
|
51
|
-
export interface EngineEvents {
|
|
52
|
-
onStepStart?: (step: WorkflowStep, context: ExecutionContext) => void;
|
|
53
|
-
onStepComplete?: (step: WorkflowStep, result: StepResult) => void;
|
|
54
|
-
onStepError?: (step: WorkflowStep, error: Error, retryCount: number) => void;
|
|
55
|
-
onWorkflowStart?: (workflow: Workflow, context: ExecutionContext) => void;
|
|
56
|
-
onWorkflowComplete?: (workflow: Workflow, result: WorkflowResult) => void;
|
|
57
|
-
}
|
|
58
|
-
export declare class RetryPolicy {
|
|
59
|
-
readonly maxRetries: number;
|
|
60
|
-
readonly baseDelay: number;
|
|
61
|
-
readonly maxDelay: number;
|
|
62
|
-
readonly exponentialBase: number;
|
|
63
|
-
readonly jitter: number;
|
|
64
|
-
constructor(maxRetries?: number, baseDelay?: number, maxDelay?: number, exponentialBase?: number, jitter?: number);
|
|
65
|
-
/**
|
|
66
|
-
* Calculate delay for a given retry attempt.
|
|
67
|
-
*/
|
|
68
|
-
getDelay(attempt: number): number;
|
|
69
|
-
}
|
|
70
|
-
export type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
|
|
71
|
-
export declare class CircuitBreaker {
|
|
72
|
-
readonly failureThreshold: number;
|
|
73
|
-
readonly recoveryTimeout: number;
|
|
74
|
-
readonly halfOpenMaxCalls: number;
|
|
75
|
-
private state;
|
|
76
|
-
private failures;
|
|
77
|
-
private lastFailureTime;
|
|
78
|
-
private halfOpenCalls;
|
|
79
|
-
constructor(failureThreshold?: number, recoveryTimeout?: number, halfOpenMaxCalls?: number);
|
|
80
|
-
canExecute(): boolean;
|
|
81
|
-
recordSuccess(): void;
|
|
82
|
-
recordFailure(): void;
|
|
83
|
-
getState(): CircuitState;
|
|
84
|
-
reset(): void;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Resolve template variables in a value.
|
|
88
|
-
* Supports {{variable}}, {{inputs.name}}, and Nunjucks filters.
|
|
89
|
-
*
|
|
90
|
-
* Uses Nunjucks as the template engine with:
|
|
91
|
-
* - Legacy regex operator support (=~, !~, //) converted to filters
|
|
92
|
-
* - Custom filters for string, array, object, date operations
|
|
93
|
-
* - Jinja2-style control flow ({% for %}, {% if %}, etc.)
|
|
94
|
-
*/
|
|
95
|
-
export declare function resolveTemplates(value: unknown, context: ExecutionContext): unknown;
|
|
96
|
-
/**
|
|
97
|
-
* Resolve a variable path from context.
|
|
98
|
-
* First checks inputs.*, then variables, then stepMetadata, then direct context properties.
|
|
99
|
-
* Exported to allow access from condition evaluation.
|
|
100
|
-
*/
|
|
101
|
-
export declare function resolveVariablePath(path: string, context: ExecutionContext): unknown;
|
|
16
|
+
import { type FailoverEvent } from './failover.js';
|
|
17
|
+
export { RetryPolicy, CircuitBreaker } from './engine/retry.js';
|
|
18
|
+
export type { CircuitState } from './engine/retry.js';
|
|
19
|
+
export { resolveTemplates, resolveVariablePath } from './engine/variable-resolution.js';
|
|
20
|
+
export type { EngineConfig, SDKRegistryLike, StepExecutorContext, StepExecutor, EngineEvents, } from './engine/types.js';
|
|
21
|
+
import type { EngineConfig, SDKRegistryLike, StepExecutor, EngineEvents } from './engine/types.js';
|
|
102
22
|
export declare class WorkflowEngine {
|
|
103
23
|
private config;
|
|
104
24
|
private retryPolicy;
|
|
@@ -114,7 +34,7 @@ export declare class WorkflowEngine {
|
|
|
114
34
|
private promptCache;
|
|
115
35
|
constructor(config?: EngineConfig, events?: EngineEvents, stateStore?: StateStore);
|
|
116
36
|
/**
|
|
117
|
-
* Execute a single step -
|
|
37
|
+
* Execute a single step - dispatches to specialized execution methods.
|
|
118
38
|
*/
|
|
119
39
|
private executeStep;
|
|
120
40
|
/**
|
|
@@ -123,42 +43,13 @@ export declare class WorkflowEngine {
|
|
|
123
43
|
execute(workflow: Workflow, inputs: Record<string, unknown> | undefined, sdkRegistry: SDKRegistryLike, stepExecutor: StepExecutor): Promise<WorkflowResult>;
|
|
124
44
|
/**
|
|
125
45
|
* Resume a paused execution (e.g., after form submission).
|
|
126
|
-
*
|
|
127
|
-
* @param runId - The execution run ID
|
|
128
|
-
* @param stepId - The step ID that was waiting
|
|
129
|
-
* @param resumeData - Data from the resume action (e.g., form submission)
|
|
130
|
-
* @param sdkRegistry - SDK registry for step execution
|
|
131
|
-
* @param stepExecutor - Step executor function
|
|
132
|
-
* @returns Workflow result from resumed execution
|
|
133
46
|
*/
|
|
134
47
|
resumeExecution(runId: string, stepId: string, resumeData: Record<string, unknown>, sdkRegistry: SDKRegistryLike, stepExecutor: StepExecutor): Promise<WorkflowResult>;
|
|
135
48
|
/**
|
|
136
49
|
* Execute a workflow from a file.
|
|
137
|
-
* This method automatically sets the workflow path for resolving sub-workflows.
|
|
138
50
|
*/
|
|
139
51
|
executeFile(workflowPath: string, inputs: Record<string, unknown> | undefined, sdkRegistry: SDKRegistryLike, stepExecutor: StepExecutor): Promise<WorkflowResult>;
|
|
140
52
|
getFailoverHistory(): FailoverEvent[];
|
|
141
|
-
/**
|
|
142
|
-
* Execute a sub-workflow.
|
|
143
|
-
*/
|
|
144
|
-
private executeSubWorkflow;
|
|
145
|
-
/**
|
|
146
|
-
* Execute a sub-workflow using an AI sub-agent.
|
|
147
|
-
* The agent interprets the workflow and executes it autonomously.
|
|
148
|
-
*/
|
|
149
|
-
private executeSubWorkflowWithAgent;
|
|
150
|
-
/**
|
|
151
|
-
* Build the default system prompt for sub-agent execution.
|
|
152
|
-
*/
|
|
153
|
-
private buildDefaultSubagentSystemPrompt;
|
|
154
|
-
/**
|
|
155
|
-
* Build the prompt for sub-agent workflow execution.
|
|
156
|
-
*/
|
|
157
|
-
private buildSubagentPrompt;
|
|
158
|
-
/**
|
|
159
|
-
* Parse the sub-agent's response to extract completion status and output.
|
|
160
|
-
*/
|
|
161
|
-
private parseSubagentResponse;
|
|
162
53
|
/**
|
|
163
54
|
* Build the step executor context with effective model/agent/permissions.
|
|
164
55
|
*/
|
|
@@ -179,27 +70,6 @@ export declare class WorkflowEngine {
|
|
|
179
70
|
* Execute a function with a timeout.
|
|
180
71
|
*/
|
|
181
72
|
private executeWithTimeout;
|
|
182
|
-
/**
|
|
183
|
-
* Evaluate step conditions.
|
|
184
|
-
*/
|
|
185
|
-
private evaluateConditions;
|
|
186
|
-
/**
|
|
187
|
-
* Evaluate a single condition.
|
|
188
|
-
* Supports: ==, !=, >, <, >=, <=
|
|
189
|
-
* Also supports nested property access (e.g., check_result.success)
|
|
190
|
-
* and step status checks (e.g., step_id.status == 'failed')
|
|
191
|
-
*/
|
|
192
|
-
private evaluateCondition;
|
|
193
|
-
/**
|
|
194
|
-
* Resolve a condition value with support for nested properties.
|
|
195
|
-
* Handles direct variable references and nested paths.
|
|
196
|
-
* Uses Nunjucks for template expressions with filters/regex.
|
|
197
|
-
*/
|
|
198
|
-
private resolveConditionValue;
|
|
199
|
-
/**
|
|
200
|
-
* Parse a value from a condition string.
|
|
201
|
-
*/
|
|
202
|
-
private parseValue;
|
|
203
73
|
/**
|
|
204
74
|
* Build the final workflow result.
|
|
205
75
|
*/
|
|
@@ -208,70 +78,6 @@ export declare class WorkflowEngine {
|
|
|
208
78
|
* Reset all circuit breakers.
|
|
209
79
|
*/
|
|
210
80
|
resetCircuitBreakers(): void;
|
|
211
|
-
/**
|
|
212
|
-
* Execute an if/else conditional step.
|
|
213
|
-
*/
|
|
214
|
-
private executeIfStep;
|
|
215
|
-
/**
|
|
216
|
-
* Execute a switch/case step.
|
|
217
|
-
*/
|
|
218
|
-
private executeSwitchStep;
|
|
219
|
-
/**
|
|
220
|
-
* Execute a for-each loop step.
|
|
221
|
-
* Supports optional batch_size and pause_between_batches for rate limiting.
|
|
222
|
-
*/
|
|
223
|
-
private executeForEachStep;
|
|
224
|
-
/**
|
|
225
|
-
* Execute for-each in batch mode.
|
|
226
|
-
* Items are split into batches; {{ batch }} contains the current batch array.
|
|
227
|
-
*/
|
|
228
|
-
private executeForEachBatched;
|
|
229
|
-
/**
|
|
230
|
-
* Execute a while loop step.
|
|
231
|
-
*/
|
|
232
|
-
private executeWhileStep;
|
|
233
|
-
/**
|
|
234
|
-
* Execute a map transformation step.
|
|
235
|
-
*/
|
|
236
|
-
private executeMapStep;
|
|
237
|
-
/**
|
|
238
|
-
* Execute a filter step.
|
|
239
|
-
*/
|
|
240
|
-
private executeFilterStep;
|
|
241
|
-
/**
|
|
242
|
-
* Execute a reduce/aggregate step.
|
|
243
|
-
*/
|
|
244
|
-
private executeReduceStep;
|
|
245
|
-
/**
|
|
246
|
-
* Execute parallel branches.
|
|
247
|
-
*/
|
|
248
|
-
private executeParallelStep;
|
|
249
|
-
/**
|
|
250
|
-
* Execute try/catch/finally step.
|
|
251
|
-
*/
|
|
252
|
-
private executeTryStep;
|
|
253
|
-
/**
|
|
254
|
-
* Execute a script step (inline JavaScript).
|
|
255
|
-
*/
|
|
256
|
-
private executeScriptStep;
|
|
257
|
-
/**
|
|
258
|
-
* Execute a wait/pause step.
|
|
259
|
-
*
|
|
260
|
-
* For mode=duration: In-process wait (suitable for short durations).
|
|
261
|
-
* For persistent long-duration waits, a WaitManager should checkpoint
|
|
262
|
-
* the execution and resume it later via the scheduler.
|
|
263
|
-
*
|
|
264
|
-
* For mode=webhook: Returns a resume URL. The execution will be
|
|
265
|
-
* checkpointed and resumed when the URL is called.
|
|
266
|
-
*
|
|
267
|
-
* For mode=form: Returns form fields. The execution will be
|
|
268
|
-
* checkpointed and resumed when the form is submitted.
|
|
269
|
-
*/
|
|
270
|
-
private executeWaitStep;
|
|
271
|
-
/**
|
|
272
|
-
* Execute a merge step - combines data from multiple sources.
|
|
273
|
-
*/
|
|
274
|
-
private executeMergeStep;
|
|
275
81
|
/**
|
|
276
82
|
* Clone execution context for parallel branches.
|
|
277
83
|
*/
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,QAAQ,EAIR,cAAc,EAqBf,MAAM,aAAa,CAAC;AAWrB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,eAAe,CAAC;AAgCvB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACxF,YAAY,EACV,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,YAAY,GACb,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAEf,YAAY,EACZ,YAAY,EACb,MAAM,mBAAmB,CAAC;AAe3B,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,eAAe,CAA0C;IACjE,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAyB;IAC5C,OAAO,CAAC,gBAAgB,CAAC,CAA+B;IACxD,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,cAAc,CAAuB;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,mBAA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