@hexabot-ai/agentic 3.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +120 -0
- package/README.md +231 -0
- package/dist/cjs/action/abstract-action.js +141 -0
- package/dist/cjs/action/action.js +47 -0
- package/dist/cjs/action/action.types.js +7 -0
- package/dist/cjs/bindings/base-binding.js +278 -0
- package/dist/cjs/context.js +79 -0
- package/dist/cjs/dsl.types.js +318 -0
- package/dist/cjs/index.js +52 -0
- package/dist/cjs/runner-runtime-control.js +343 -0
- package/dist/cjs/step-executors/conditional-executor.js +63 -0
- package/dist/cjs/step-executors/loop-executor.js +187 -0
- package/dist/cjs/step-executors/parallel-executor.js +51 -0
- package/dist/cjs/step-executors/skip-helpers.js +29 -0
- package/dist/cjs/step-executors/task-executor.js +155 -0
- package/dist/cjs/step-executors/types.js +7 -0
- package/dist/cjs/suspension-rebuilder.js +301 -0
- package/dist/cjs/utils/deferred.js +17 -0
- package/dist/cjs/utils/naming.js +48 -0
- package/dist/cjs/utils/timeout.js +42 -0
- package/dist/cjs/utils/workflow-definition.js +102 -0
- package/dist/cjs/workflow-compiler.js +212 -0
- package/dist/cjs/workflow-event-emitter.js +40 -0
- package/dist/cjs/workflow-runner.js +448 -0
- package/dist/cjs/workflow-types.js +7 -0
- package/dist/cjs/workflow-values.js +99 -0
- package/dist/cjs/workflow.js +243 -0
- package/dist/esm/action/abstract-action.js +137 -0
- package/dist/esm/action/action.js +44 -0
- package/dist/esm/action/action.types.js +6 -0
- package/dist/esm/bindings/base-binding.js +273 -0
- package/dist/esm/context.js +75 -0
- package/dist/esm/dsl.types.js +309 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/runner-runtime-control.js +338 -0
- package/dist/esm/step-executors/conditional-executor.js +60 -0
- package/dist/esm/step-executors/loop-executor.js +182 -0
- package/dist/esm/step-executors/parallel-executor.js +48 -0
- package/dist/esm/step-executors/skip-helpers.js +25 -0
- package/dist/esm/step-executors/task-executor.js +152 -0
- package/dist/esm/step-executors/types.js +6 -0
- package/dist/esm/suspension-rebuilder.js +296 -0
- package/dist/esm/utils/deferred.js +14 -0
- package/dist/esm/utils/naming.js +42 -0
- package/dist/esm/utils/timeout.js +37 -0
- package/dist/esm/utils/workflow-definition.js +98 -0
- package/dist/esm/workflow-compiler.js +208 -0
- package/dist/esm/workflow-event-emitter.js +36 -0
- package/dist/esm/workflow-runner.js +444 -0
- package/dist/esm/workflow-types.js +6 -0
- package/dist/esm/workflow-values.js +89 -0
- package/dist/esm/workflow.js +236 -0
- package/dist/types/action/abstract-action.d.ts +54 -0
- package/dist/types/action/abstract-action.d.ts.map +1 -0
- package/dist/types/action/action.d.ts +23 -0
- package/dist/types/action/action.d.ts.map +1 -0
- package/dist/types/action/action.types.d.ts +55 -0
- package/dist/types/action/action.types.d.ts.map +1 -0
- package/dist/types/bindings/base-binding.d.ts +52 -0
- package/dist/types/bindings/base-binding.d.ts.map +1 -0
- package/dist/types/context.d.ts +105 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/dsl.types.d.ts +220 -0
- package/dist/types/dsl.types.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/runner-runtime-control.d.ts +64 -0
- package/dist/types/runner-runtime-control.d.ts.map +1 -0
- package/dist/types/step-executors/conditional-executor.d.ts +13 -0
- package/dist/types/step-executors/conditional-executor.d.ts.map +1 -0
- package/dist/types/step-executors/loop-executor.d.ts +33 -0
- package/dist/types/step-executors/loop-executor.d.ts.map +1 -0
- package/dist/types/step-executors/parallel-executor.d.ts +14 -0
- package/dist/types/step-executors/parallel-executor.d.ts.map +1 -0
- package/dist/types/step-executors/skip-helpers.d.ts +12 -0
- package/dist/types/step-executors/skip-helpers.d.ts.map +1 -0
- package/dist/types/step-executors/task-executor.d.ts +13 -0
- package/dist/types/step-executors/task-executor.d.ts.map +1 -0
- package/dist/types/step-executors/types.d.ts +24 -0
- package/dist/types/step-executors/types.d.ts.map +1 -0
- package/dist/types/suspension-rebuilder.d.ts +67 -0
- package/dist/types/suspension-rebuilder.d.ts.map +1 -0
- package/dist/types/utils/deferred.d.ts +7 -0
- package/dist/types/utils/deferred.d.ts.map +1 -0
- package/dist/types/utils/naming.d.ts +24 -0
- package/dist/types/utils/naming.d.ts.map +1 -0
- package/dist/types/utils/timeout.d.ts +17 -0
- package/dist/types/utils/timeout.d.ts.map +1 -0
- package/dist/types/utils/workflow-definition.d.ts +3 -0
- package/dist/types/utils/workflow-definition.d.ts.map +1 -0
- package/dist/types/workflow-compiler.d.ts +12 -0
- package/dist/types/workflow-compiler.d.ts.map +1 -0
- package/dist/types/workflow-event-emitter.d.ts +70 -0
- package/dist/types/workflow-event-emitter.d.ts.map +1 -0
- package/dist/types/workflow-runner.d.ts +179 -0
- package/dist/types/workflow-runner.d.ts.map +1 -0
- package/dist/types/workflow-types.d.ts +195 -0
- package/dist/types/workflow-types.d.ts.map +1 -0
- package/dist/types/workflow-values.d.ts +34 -0
- package/dist/types/workflow-values.d.ts.map +1 -0
- package/dist/types/workflow.d.ts +75 -0
- package/dist/types/workflow.d.ts.map +1 -0
- package/examples/defs-bindings-agent/actions/ai-agent.ts +110 -0
- package/examples/defs-bindings-agent/actions/caculate-score.ts +49 -0
- package/examples/defs-bindings-agent/actions/index.ts +15 -0
- package/examples/defs-bindings-agent/bindings.ts +20 -0
- package/examples/defs-bindings-agent/context.ts +32 -0
- package/examples/defs-bindings-agent/workflow.ts +67 -0
- package/examples/defs-bindings-agent/workflow.yml +28 -0
- package/examples/full/actions/await-user-input.ts +46 -0
- package/examples/full/actions/call-llm.ts +133 -0
- package/examples/full/actions/create-ticket.ts +46 -0
- package/examples/full/actions/decision-router.ts +83 -0
- package/examples/full/actions/get-calendar-events.ts +55 -0
- package/examples/full/actions/get-user-profile.ts +72 -0
- package/examples/full/actions/index.ts +33 -0
- package/examples/full/actions/query-memory.ts +45 -0
- package/examples/full/actions/search-web.ts +53 -0
- package/examples/full/actions/send-email.ts +50 -0
- package/examples/full/context.ts +41 -0
- package/examples/full/workflow.ts +75 -0
- package/examples/full/workflow.yml +359 -0
- package/examples/loop/actions/await-reply.ts +47 -0
- package/examples/loop/actions/index.ts +19 -0
- package/examples/loop/actions/send-text-message.ts +40 -0
- package/examples/loop/context.ts +32 -0
- package/examples/loop/workflow.ts +66 -0
- package/examples/loop/workflow.yml +66 -0
- package/examples/suspend-resume/actions/format-reply.ts +43 -0
- package/examples/suspend-resume/actions/index.ts +13 -0
- package/examples/suspend-resume/actions/wait-for-user.ts +51 -0
- package/examples/suspend-resume/context.ts +32 -0
- package/examples/suspend-resume/workflow.ts +79 -0
- package/examples/suspend-resume/workflow.yml +29 -0
- package/package.json +60 -0
- package/src/__tests__/parser.test.ts +95 -0
- package/src/__tests__/suspension-rebuilder.test.ts +361 -0
- package/src/__tests__/test-helpers.ts +36 -0
- package/src/__tests__/validation.test.ts +526 -0
- package/src/__tests__/workflow-compiler.test.ts +715 -0
- package/src/__tests__/workflow-definition-path.test.ts +381 -0
- package/src/__tests__/workflow-event-emitter.test.ts +50 -0
- package/src/__tests__/workflow-runner.test.ts +1397 -0
- package/src/__tests__/workflow-values.test.ts +132 -0
- package/src/__tests__/workflow.test.ts +320 -0
- package/src/action/__tests__/abstract-action-timing.test.ts +183 -0
- package/src/action/__tests__/action.test.ts +473 -0
- package/src/action/abstract-action.ts +215 -0
- package/src/action/action.ts +83 -0
- package/src/action/action.types.ts +93 -0
- package/src/bindings/base-binding.ts +508 -0
- package/src/context.ts +179 -0
- package/src/dsl.types.ts +473 -0
- package/src/index.ts +114 -0
- package/src/runner-runtime-control.ts +544 -0
- package/src/step-executors/conditional-executor.test.ts +192 -0
- package/src/step-executors/conditional-executor.ts +83 -0
- package/src/step-executors/loop-executor.test.ts +303 -0
- package/src/step-executors/loop-executor.ts +299 -0
- package/src/step-executors/parallel-executor.test.ts +182 -0
- package/src/step-executors/parallel-executor.ts +77 -0
- package/src/step-executors/skip-helpers.ts +68 -0
- package/src/step-executors/task-executor.test.ts +257 -0
- package/src/step-executors/task-executor.ts +248 -0
- package/src/step-executors/types.ts +70 -0
- package/src/suspension-rebuilder.ts +504 -0
- package/src/utils/deferred.ts +23 -0
- package/src/utils/naming.ts +55 -0
- package/src/utils/timeout.ts +48 -0
- package/src/utils/workflow-definition.ts +173 -0
- package/src/workflow-compiler.ts +317 -0
- package/src/workflow-event-emitter.ts +86 -0
- package/src/workflow-runner.ts +603 -0
- package/src/workflow-types.ts +207 -0
- package/src/workflow-values.ts +159 -0
- package/src/workflow.ts +387 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
4
|
+
* Copyright (c) 2025 Hexastack.
|
|
5
|
+
* Full terms: see LICENSE.md.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.safeRenameTaskInDefinition = void 0;
|
|
9
|
+
const dsl_types_1 = require("../dsl.types");
|
|
10
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
11
|
+
const replaceOutputTaskReferences = (source, currentTaskName, nextTaskName) => {
|
|
12
|
+
if (!source.includes('$output')) {
|
|
13
|
+
return source;
|
|
14
|
+
}
|
|
15
|
+
const escapedTaskName = escapeRegExp(currentTaskName);
|
|
16
|
+
const dotNotationPattern = new RegExp(`(\\$output\\.)${escapedTaskName}(?=[^a-zA-Z0-9_]|$)`, 'g');
|
|
17
|
+
const singleQuotePattern = new RegExp(`(\\$output\\s*\\[\\s*')${escapedTaskName}('\\s*\\])`, 'g');
|
|
18
|
+
const doubleQuotePattern = new RegExp(`(\\$output\\s*\\[\\s*")${escapedTaskName}("\\s*\\])`, 'g');
|
|
19
|
+
return source
|
|
20
|
+
.replace(dotNotationPattern, `$1${nextTaskName}`)
|
|
21
|
+
.replace(singleQuotePattern, `$1${nextTaskName}$2`)
|
|
22
|
+
.replace(doubleQuotePattern, `$1${nextTaskName}$2`);
|
|
23
|
+
};
|
|
24
|
+
const renameTaskInFlow = (steps, currentTaskName, nextTaskName) => {
|
|
25
|
+
return steps.map((step) => {
|
|
26
|
+
if ('do' in step) {
|
|
27
|
+
return {
|
|
28
|
+
...step,
|
|
29
|
+
do: step.do === currentTaskName ? nextTaskName : step.do,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if ('parallel' in step) {
|
|
33
|
+
return {
|
|
34
|
+
...step,
|
|
35
|
+
parallel: {
|
|
36
|
+
...step.parallel,
|
|
37
|
+
steps: renameTaskInFlow(step.parallel.steps, currentTaskName, nextTaskName),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if ('conditional' in step) {
|
|
42
|
+
return {
|
|
43
|
+
...step,
|
|
44
|
+
conditional: {
|
|
45
|
+
...step.conditional,
|
|
46
|
+
when: step.conditional.when.map((branch) => ({
|
|
47
|
+
...branch,
|
|
48
|
+
steps: renameTaskInFlow(branch.steps, currentTaskName, nextTaskName),
|
|
49
|
+
})),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if ('loop' in step) {
|
|
54
|
+
return {
|
|
55
|
+
...step,
|
|
56
|
+
loop: {
|
|
57
|
+
...step.loop,
|
|
58
|
+
steps: renameTaskInFlow(step.loop.steps, currentTaskName, nextTaskName),
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return step;
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const renameOutputTaskReferencesInValue = (value, currentTaskName, nextTaskName) => {
|
|
66
|
+
if (typeof value === 'string') {
|
|
67
|
+
return replaceOutputTaskReferences(value, currentTaskName, nextTaskName);
|
|
68
|
+
}
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
return value.map((item) => renameOutputTaskReferencesInValue(item, currentTaskName, nextTaskName));
|
|
71
|
+
}
|
|
72
|
+
if (!value || typeof value !== 'object') {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
return Object.entries(value).reduce((acc, [key, nestedValue]) => {
|
|
76
|
+
acc[key] = renameOutputTaskReferencesInValue(nestedValue, currentTaskName, nextTaskName);
|
|
77
|
+
return acc;
|
|
78
|
+
}, {});
|
|
79
|
+
};
|
|
80
|
+
const safeRenameTaskInDefinition = (definition, currentTaskName, nextTaskName) => {
|
|
81
|
+
if (currentTaskName === nextTaskName) {
|
|
82
|
+
return definition;
|
|
83
|
+
}
|
|
84
|
+
if (!Object.prototype.hasOwnProperty.call(definition.defs, currentTaskName)) {
|
|
85
|
+
return definition;
|
|
86
|
+
}
|
|
87
|
+
const currentDefinition = definition.defs[currentTaskName];
|
|
88
|
+
if (!currentDefinition || currentDefinition.kind !== dsl_types_1.TASK_KIND) {
|
|
89
|
+
return definition;
|
|
90
|
+
}
|
|
91
|
+
const renamedDefs = Object.entries(definition.defs).reduce((acc, [defName, def]) => {
|
|
92
|
+
acc[defName === currentTaskName ? nextTaskName : defName] = def;
|
|
93
|
+
return acc;
|
|
94
|
+
}, {});
|
|
95
|
+
const definitionWithRenamedFlow = {
|
|
96
|
+
...definition,
|
|
97
|
+
defs: renamedDefs,
|
|
98
|
+
flow: renameTaskInFlow(definition.flow, currentTaskName, nextTaskName),
|
|
99
|
+
};
|
|
100
|
+
return renameOutputTaskReferencesInValue(definitionWithRenamedFlow, currentTaskName, nextTaskName);
|
|
101
|
+
};
|
|
102
|
+
exports.safeRenameTaskInDefinition = safeRenameTaskInDefinition;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
4
|
+
* Copyright (c) 2025 Hexastack.
|
|
5
|
+
* Full terms: see LICENSE.md.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.compileWorkflow = void 0;
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const base_binding_1 = require("./bindings/base-binding");
|
|
11
|
+
const dsl_types_1 = require("./dsl.types");
|
|
12
|
+
const naming_1 = require("./utils/naming");
|
|
13
|
+
const workflow_event_emitter_1 = require("./workflow-event-emitter");
|
|
14
|
+
const workflow_values_1 = require("./workflow-values");
|
|
15
|
+
/** Build a stable identifier for a step using its path and label. */
|
|
16
|
+
const buildStepId = (path, label) => {
|
|
17
|
+
const pathPart = path.length > 0 ? path.join('.') : 'root';
|
|
18
|
+
return `${pathPart}:${label}`;
|
|
19
|
+
};
|
|
20
|
+
/** Convert workflow input field metadata to a zod schema. */
|
|
21
|
+
const inputFieldToZod = (field) => {
|
|
22
|
+
let schema;
|
|
23
|
+
switch (field.type) {
|
|
24
|
+
case 'string':
|
|
25
|
+
schema = zod_1.z.string();
|
|
26
|
+
break;
|
|
27
|
+
case 'number':
|
|
28
|
+
schema = zod_1.z.number();
|
|
29
|
+
break;
|
|
30
|
+
case 'integer':
|
|
31
|
+
schema = zod_1.z.int();
|
|
32
|
+
break;
|
|
33
|
+
case 'boolean':
|
|
34
|
+
schema = zod_1.z.boolean();
|
|
35
|
+
break;
|
|
36
|
+
case 'array':
|
|
37
|
+
schema = zod_1.z.array(field.items ? inputFieldToZod(field.items) : zod_1.z.any());
|
|
38
|
+
break;
|
|
39
|
+
case 'object': {
|
|
40
|
+
const properties = {};
|
|
41
|
+
if (field.properties) {
|
|
42
|
+
for (const [name, child] of Object.entries(field.properties)) {
|
|
43
|
+
properties[name] = inputFieldToZod(child).optional();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
schema =
|
|
47
|
+
Object.keys(properties).length > 0
|
|
48
|
+
? zod_1.z.strictObject(properties).partial()
|
|
49
|
+
: zod_1.z.record(zod_1.z.string(), zod_1.z.any());
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
default:
|
|
53
|
+
schema = zod_1.z.any();
|
|
54
|
+
}
|
|
55
|
+
if (field.enum) {
|
|
56
|
+
schema = schema.refine((value) => field.enum?.some((allowed) => allowed === value), {
|
|
57
|
+
message: `Value must be one of: ${field.enum.join(', ')}`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return schema;
|
|
61
|
+
};
|
|
62
|
+
/** Assemble a parser for the workflow top-level input payload. */
|
|
63
|
+
const buildInputParser = (schema) => {
|
|
64
|
+
if (!schema || Object.keys(schema).length === 0) {
|
|
65
|
+
return zod_1.z.looseObject({});
|
|
66
|
+
}
|
|
67
|
+
const shape = {};
|
|
68
|
+
for (const [name, field] of Object.entries(schema)) {
|
|
69
|
+
shape[name] = inputFieldToZod(field).optional();
|
|
70
|
+
}
|
|
71
|
+
return zod_1.z.strictObject(shape).partial();
|
|
72
|
+
};
|
|
73
|
+
/** Compile a raw mapping object into expression-aware value mappings. */
|
|
74
|
+
const compileMapping = (values, options) => {
|
|
75
|
+
if (!values) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
return Object.fromEntries(Object.entries(values).map(([key, value]) => [
|
|
79
|
+
key,
|
|
80
|
+
(0, workflow_values_1.compileValue)(value, options),
|
|
81
|
+
]));
|
|
82
|
+
};
|
|
83
|
+
/** Ensure every task references a provided action implementation. */
|
|
84
|
+
const assertActionsBound = (tasks, actions) => {
|
|
85
|
+
const missing = Object.values(tasks)
|
|
86
|
+
.map((task) => task.action)
|
|
87
|
+
.filter((actionName) => !Object.prototype.hasOwnProperty.call(actions, actionName));
|
|
88
|
+
if (missing.length > 0) {
|
|
89
|
+
throw new Error(`No action implementations provided for: ${missing.join(', ')}`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/** Parse settings, compile inputs, and bind actions for each task. */
|
|
93
|
+
const compileTasks = (definition, options) => {
|
|
94
|
+
const compiled = {};
|
|
95
|
+
const defaultSettings = definition.defaults?.settings;
|
|
96
|
+
const taskDefinitions = (0, dsl_types_1.extractTaskDefinitions)(definition.defs);
|
|
97
|
+
const bindingValidation = (0, base_binding_1.validateAndResolveBindings)(definition, {
|
|
98
|
+
bindingKinds: options.bindingKinds,
|
|
99
|
+
actions: options.actions,
|
|
100
|
+
});
|
|
101
|
+
if (bindingValidation.errors.length > 0) {
|
|
102
|
+
throw new Error(`Workflow bindings validation failed: ${bindingValidation.errors.join('; ')}`);
|
|
103
|
+
}
|
|
104
|
+
assertActionsBound(taskDefinitions, options.actions);
|
|
105
|
+
for (const [taskName, task] of Object.entries(taskDefinitions)) {
|
|
106
|
+
(0, naming_1.assertSnakeCaseName)(taskName, 'action');
|
|
107
|
+
const action = options.actions[task.action];
|
|
108
|
+
const settingsPayload = (0, workflow_values_1.mergeSettings)(defaultSettings, task.settings);
|
|
109
|
+
const parsedSettings = action.parseSettings(settingsPayload);
|
|
110
|
+
compiled[taskName] = {
|
|
111
|
+
name: taskName,
|
|
112
|
+
actionName: task.action,
|
|
113
|
+
definition: task,
|
|
114
|
+
action,
|
|
115
|
+
inputs: compileMapping(task.inputs, options) ?? {},
|
|
116
|
+
settings: parsedSettings,
|
|
117
|
+
bindings: (0, base_binding_1.mountTaskBindings)(task.bindings, bindingValidation.resolvedDefs, options.bindingKinds),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return compiled;
|
|
121
|
+
};
|
|
122
|
+
/** Recursively compile flow steps into executable nodes with generated ids. */
|
|
123
|
+
const compileFlowSteps = (steps, path = [], options) => steps.map((step, index) => {
|
|
124
|
+
const stepPath = [...path, index];
|
|
125
|
+
if ('do' in step) {
|
|
126
|
+
const label = step.do;
|
|
127
|
+
return {
|
|
128
|
+
type: workflow_event_emitter_1.StepType.Task,
|
|
129
|
+
id: buildStepId(stepPath, step.do),
|
|
130
|
+
label,
|
|
131
|
+
taskName: step.do,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if ('parallel' in step) {
|
|
135
|
+
const label = step.parallel.description ?? 'parallel';
|
|
136
|
+
return {
|
|
137
|
+
type: workflow_event_emitter_1.StepType.Parallel,
|
|
138
|
+
id: buildStepId(stepPath, 'parallel'),
|
|
139
|
+
label,
|
|
140
|
+
description: step.parallel.description,
|
|
141
|
+
strategy: step.parallel.strategy ?? 'wait_all',
|
|
142
|
+
steps: compileFlowSteps(step.parallel.steps, [...stepPath, 'parallel'], options),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if ('conditional' in step) {
|
|
146
|
+
const label = step.conditional.description ?? 'conditional';
|
|
147
|
+
const branches = step.conditional.when.map((branch, branchIdx) => ({
|
|
148
|
+
id: buildStepId([...stepPath, 'branch', branchIdx], 'conditional'),
|
|
149
|
+
condition: 'condition' in branch
|
|
150
|
+
? (0, workflow_values_1.compileValue)(branch.condition, options)
|
|
151
|
+
: undefined,
|
|
152
|
+
steps: compileFlowSteps(branch.steps, [...stepPath, 'branch', branchIdx], options),
|
|
153
|
+
}));
|
|
154
|
+
return {
|
|
155
|
+
type: workflow_event_emitter_1.StepType.Conditional,
|
|
156
|
+
id: buildStepId(stepPath, 'conditional'),
|
|
157
|
+
label,
|
|
158
|
+
description: step.conditional.description,
|
|
159
|
+
branches,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const loop = step.loop;
|
|
163
|
+
const label = loop.name ?? 'loop';
|
|
164
|
+
const commonLoop = {
|
|
165
|
+
type: workflow_event_emitter_1.StepType.Loop,
|
|
166
|
+
id: buildStepId(stepPath, label),
|
|
167
|
+
label,
|
|
168
|
+
name: loop.name,
|
|
169
|
+
description: loop.description,
|
|
170
|
+
accumulate: loop.accumulate
|
|
171
|
+
? {
|
|
172
|
+
as: loop.accumulate.as,
|
|
173
|
+
initial: loop.accumulate.initial,
|
|
174
|
+
merge: (0, workflow_values_1.compileValue)(loop.accumulate.merge, options),
|
|
175
|
+
}
|
|
176
|
+
: undefined,
|
|
177
|
+
steps: compileFlowSteps(loop.steps, [...stepPath, loop.name ?? 'loop'], options),
|
|
178
|
+
};
|
|
179
|
+
if (loop.type === 'for_each') {
|
|
180
|
+
return {
|
|
181
|
+
...commonLoop,
|
|
182
|
+
loopType: 'for_each',
|
|
183
|
+
forEach: {
|
|
184
|
+
item: loop.for_each.item,
|
|
185
|
+
in: (0, workflow_values_1.compileValue)(loop.for_each.in, options),
|
|
186
|
+
},
|
|
187
|
+
maxConcurrency: loop.max_concurrency,
|
|
188
|
+
until: loop.until ? (0, workflow_values_1.compileValue)(loop.until, options) : undefined,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
...commonLoop,
|
|
193
|
+
loopType: 'while',
|
|
194
|
+
while: (0, workflow_values_1.compileValue)(loop.while, options),
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
/** Compile a workflow definition into structures consumable by the runtime. */
|
|
198
|
+
const compileWorkflow = (definition, options) => {
|
|
199
|
+
const inputParser = buildInputParser(definition.inputs?.schema);
|
|
200
|
+
const tasks = compileTasks(definition, options);
|
|
201
|
+
const flow = compileFlowSteps(definition.flow, [], options);
|
|
202
|
+
const outputMapping = compileMapping(definition.outputs, options) ?? {};
|
|
203
|
+
return {
|
|
204
|
+
definition,
|
|
205
|
+
tasks,
|
|
206
|
+
flow,
|
|
207
|
+
outputMapping,
|
|
208
|
+
inputParser,
|
|
209
|
+
defaultSettings: definition.defaults?.settings,
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
exports.compileWorkflow = compileWorkflow;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Hexabot — Fair Core License (FCL-1.0-ALv2)
|
|
4
|
+
* Copyright (c) 2025 Hexastack.
|
|
5
|
+
* Full terms: see LICENSE.md.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.WorkflowEventEmitter = exports.StepType = void 0;
|
|
9
|
+
var StepType;
|
|
10
|
+
(function (StepType) {
|
|
11
|
+
StepType["Task"] = "task";
|
|
12
|
+
StepType["Parallel"] = "parallel";
|
|
13
|
+
StepType["Conditional"] = "conditional";
|
|
14
|
+
StepType["Loop"] = "loop";
|
|
15
|
+
})(StepType || (exports.StepType = StepType = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Minimal, browser-friendly event emitter that preserves the typed payloads
|
|
18
|
+
* exposed by {@link WorkflowEventMap}. It supports the subset of the Node.js
|
|
19
|
+
* EventEmitter API that the runtime relies on (`emit` and `on`).
|
|
20
|
+
*/
|
|
21
|
+
class WorkflowEventEmitter {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.listeners = new Map();
|
|
24
|
+
}
|
|
25
|
+
emit(event, payload) {
|
|
26
|
+
const eventListeners = this.listeners.get(event);
|
|
27
|
+
if (!eventListeners || eventListeners.size === 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
eventListeners.forEach((listener) => listener(payload));
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
on(event, listener) {
|
|
34
|
+
const listeners = this.listeners.get(event) ?? new Set();
|
|
35
|
+
listeners.add(listener);
|
|
36
|
+
this.listeners.set(event, listeners);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.WorkflowEventEmitter = WorkflowEventEmitter;
|