foliko 2.0.22 → 2.0.24

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.
@@ -1,66 +1,66 @@
1
- /**
2
- * FlowEngine v2 - Main entry point for v2 workflow system
3
- * Supports JSON and JS workflow formats
4
- */
5
-
6
- const { JsonRunner } = require('./json-runner');
7
- const { JsRunner } = require('./js-runner');
8
-
9
- class FlowEngine {
10
- constructor(framework) {
11
- this.framework = framework;
12
- this._jsonRunner = new JsonRunner(framework);
13
- this._jsRunner = new JsRunner(framework);
14
- this._log = require('../../../src/common/logger').logger.child('FlowEngine');
15
- }
16
-
17
- /**
18
- * Execute a workflow
19
- * @param {Object|string} workflow - Workflow definition
20
- * @param {Object} input - Input data
21
- * @param {string} sessionId - Session ID
22
- * @returns {Promise<Object>} execution result
23
- */
24
- async execute(workflow, input = {}, sessionId = null) {
25
- // Parse workflow if string
26
- if (typeof workflow === 'string') {
27
- try {
28
- workflow = JSON.parse(workflow);
29
- // It's JSON, use JsonRunner
30
- return await this._jsonRunner.execute(workflow, input, sessionId);
31
- } catch {
32
- // Not JSON, treat as JS workflow
33
- return await this._jsRunner.execute(workflow, input, sessionId);
34
- }
35
- }
36
-
37
- // Object format detection
38
- // v2 JSON: has flow + stages
39
- if (workflow.flow && Array.isArray(workflow.stages)) {
40
- return await this._jsonRunner.execute(workflow, input, sessionId);
41
- }
42
-
43
- // Assume JS format if it's a function (exported)
44
- if (typeof workflow === 'function') {
45
- return await this._jsRunner.execute(workflow, input, sessionId);
46
- }
47
-
48
- throw new Error(`Invalid workflow format. Expected { flow, stages } or JS function.`);
49
- }
50
-
51
- /**
52
- * Get the JSON runner for direct access
53
- */
54
- getJsonRunner() {
55
- return this._jsonRunner;
56
- }
57
-
58
- /**
59
- * Get the JS runner for direct access
60
- */
61
- getJsRunner() {
62
- return this._jsRunner;
63
- }
64
- }
65
-
66
- module.exports = { FlowEngine };
1
+ /**
2
+ * FlowEngine v2 - Main entry point for v2 workflow system
3
+ * Supports JSON and JS workflow formats
4
+ */
5
+
6
+ const { JsonRunner } = require('./json-runner');
7
+ const { JsRunner } = require('./js-runner');
8
+
9
+ class FlowEngine {
10
+ constructor(framework) {
11
+ this.framework = framework;
12
+ this._jsonRunner = new JsonRunner(framework);
13
+ this._jsRunner = new JsRunner(framework);
14
+ this._log = require('../../../src/common/logger').logger.child('FlowEngine');
15
+ }
16
+
17
+ /**
18
+ * Execute a workflow
19
+ * @param {Object|string} workflow - Workflow definition
20
+ * @param {Object} input - Input data
21
+ * @param {string} sessionId - Session ID
22
+ * @returns {Promise<Object>} execution result
23
+ */
24
+ async execute(workflow, input = {}, sessionId = null) {
25
+ // Parse workflow if string
26
+ if (typeof workflow === 'string') {
27
+ try {
28
+ workflow = JSON.parse(workflow);
29
+ // It's JSON, use JsonRunner
30
+ return await this._jsonRunner.execute(workflow, input, sessionId);
31
+ } catch {
32
+ // Not JSON, treat as JS workflow
33
+ return await this._jsRunner.execute(workflow, input, sessionId);
34
+ }
35
+ }
36
+
37
+ // Object format detection
38
+ // v2 JSON: has flow + stages
39
+ if (workflow.flow && Array.isArray(workflow.stages)) {
40
+ return await this._jsonRunner.execute(workflow, input, sessionId);
41
+ }
42
+
43
+ // Assume JS format if it's a function (exported)
44
+ if (typeof workflow === 'function') {
45
+ return await this._jsRunner.execute(workflow, input, sessionId);
46
+ }
47
+
48
+ throw new Error(`Invalid workflow format. Expected { flow, stages } or JS function.`);
49
+ }
50
+
51
+ /**
52
+ * Get the JSON runner for direct access
53
+ */
54
+ getJsonRunner() {
55
+ return this._jsonRunner;
56
+ }
57
+
58
+ /**
59
+ * Get the JS runner for direct access
60
+ */
61
+ getJsRunner() {
62
+ return this._jsRunner;
63
+ }
64
+ }
65
+
66
+ module.exports = { FlowEngine };