flowcraft 2.2.0 → 2.3.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/README.md +40 -34
- package/dist/analysis.d.ts +3 -1
- package/dist/chunk-33NO4PUJ.js +74 -0
- package/dist/chunk-33NO4PUJ.js.map +1 -0
- package/dist/chunk-5KKSQWSC.js +90 -0
- package/dist/chunk-5KKSQWSC.js.map +1 -0
- package/dist/{chunk-QLGJUDQF.js → chunk-6INWPSZT.js} +6 -6
- package/dist/chunk-6INWPSZT.js.map +1 -0
- package/dist/chunk-BC4G7OM6.js +42 -0
- package/dist/chunk-BC4G7OM6.js.map +1 -0
- package/dist/chunk-BCRWXTWX.js +21 -0
- package/dist/chunk-BCRWXTWX.js.map +1 -0
- package/dist/{chunk-ZCHFZBGL.js → chunk-C4HYIJI3.js} +120 -5
- package/dist/chunk-C4HYIJI3.js.map +1 -0
- package/dist/chunk-CD3Q4N6V.js +13 -0
- package/dist/chunk-CD3Q4N6V.js.map +1 -0
- package/dist/chunk-CD4FUZOJ.js +114 -0
- package/dist/chunk-CD4FUZOJ.js.map +1 -0
- package/dist/chunk-CY755I7I.js +25 -0
- package/dist/chunk-CY755I7I.js.map +1 -0
- package/dist/chunk-DL7KVYZF.js +39 -0
- package/dist/chunk-DL7KVYZF.js.map +1 -0
- package/dist/chunk-FRKO3WX4.js +32 -0
- package/dist/chunk-FRKO3WX4.js.map +1 -0
- package/dist/chunk-G53CSLBF.js +54 -0
- package/dist/chunk-G53CSLBF.js.map +1 -0
- package/dist/chunk-G5BGBPFP.js +172 -0
- package/dist/chunk-G5BGBPFP.js.map +1 -0
- package/dist/chunk-HAZ26F3P.js +98 -0
- package/dist/chunk-HAZ26F3P.js.map +1 -0
- package/dist/chunk-IB2BISIC.js +446 -0
- package/dist/chunk-IB2BISIC.js.map +1 -0
- package/dist/{chunk-U5V5O5MN.js → chunk-LNK7LZER.js} +5 -3
- package/dist/chunk-LNK7LZER.js.map +1 -0
- package/dist/chunk-MCGK3FXQ.js +143 -0
- package/dist/chunk-MCGK3FXQ.js.map +1 -0
- package/dist/chunk-MUYLRTSR.js +82 -0
- package/dist/chunk-MUYLRTSR.js.map +1 -0
- package/dist/chunk-NVJ3ZO3P.js +3 -0
- package/dist/{chunk-HMR2GEGE.js.map → chunk-NVJ3ZO3P.js.map} +1 -1
- package/dist/chunk-NVLZFLYM.js +3 -0
- package/dist/chunk-NVLZFLYM.js.map +1 -0
- package/dist/chunk-ONH7PIJZ.js +300 -0
- package/dist/chunk-ONH7PIJZ.js.map +1 -0
- package/dist/chunk-QNYXQKFW.js +25 -0
- package/dist/chunk-QNYXQKFW.js.map +1 -0
- package/dist/chunk-RM677CNU.js +52 -0
- package/dist/chunk-RM677CNU.js.map +1 -0
- package/dist/chunk-WWGFIYKW.js +47 -0
- package/dist/chunk-WWGFIYKW.js.map +1 -0
- package/dist/chunk-XNRIM27H.js +76 -0
- package/dist/chunk-XNRIM27H.js.map +1 -0
- package/dist/container-factory.d.ts +17 -0
- package/dist/container-factory.js +13 -0
- package/dist/container-factory.js.map +1 -0
- package/dist/container.d.ts +23 -0
- package/dist/container.js +3 -0
- package/dist/container.js.map +1 -0
- package/dist/context.d.ts +3 -1
- package/dist/errors.d.ts +18 -17
- package/dist/errors.js +1 -1
- package/dist/evaluator.d.ts +3 -1
- package/dist/flow.d.ts +12 -2
- package/dist/flow.js +2 -2
- package/dist/index.d.ts +7 -8
- package/dist/index.js +26 -14
- package/dist/linter.d.ts +3 -1
- package/dist/logger.d.ts +3 -1
- package/dist/node.d.ts +3 -1
- package/dist/node.js +1 -1
- package/dist/nodes/batch-gather.d.ts +9 -0
- package/dist/nodes/batch-gather.js +4 -0
- package/dist/nodes/batch-gather.js.map +1 -0
- package/dist/nodes/batch-scatter.d.ts +9 -0
- package/dist/nodes/batch-scatter.js +4 -0
- package/dist/nodes/batch-scatter.js.map +1 -0
- package/dist/nodes/subflow.d.ts +9 -0
- package/dist/nodes/subflow.js +10 -0
- package/dist/nodes/subflow.js.map +1 -0
- package/dist/nodes/wait.d.ts +9 -0
- package/dist/nodes/wait.js +4 -0
- package/dist/nodes/wait.js.map +1 -0
- package/dist/runtime/adapter.d.ts +3 -5
- package/dist/runtime/adapter.js +19 -9
- package/dist/runtime/execution-context.d.ts +3 -0
- package/dist/runtime/execution-context.js +6 -0
- package/dist/runtime/execution-context.js.map +1 -0
- package/dist/runtime/executors.d.ts +3 -26
- package/dist/runtime/executors.js +2 -2
- package/dist/runtime/index.d.ts +5 -7
- package/dist/runtime/index.js +21 -10
- package/dist/runtime/node-executor-factory.d.ts +12 -0
- package/dist/runtime/node-executor-factory.js +6 -0
- package/dist/runtime/node-executor-factory.js.map +1 -0
- package/dist/runtime/orchestrator.d.ts +9 -0
- package/dist/runtime/orchestrator.js +8 -0
- package/dist/runtime/orchestrator.js.map +1 -0
- package/dist/runtime/orchestrators/step-by-step.d.ts +16 -0
- package/dist/runtime/orchestrators/step-by-step.js +5 -0
- package/dist/runtime/orchestrators/step-by-step.js.map +1 -0
- package/dist/runtime/orchestrators/utils.d.ts +35 -0
- package/dist/runtime/orchestrators/utils.js +4 -0
- package/dist/runtime/orchestrators/utils.js.map +1 -0
- package/dist/runtime/runtime.d.ts +3 -41
- package/dist/runtime/runtime.js +18 -8
- package/dist/runtime/state.d.ts +3 -21
- package/dist/runtime/state.js +2 -1
- package/dist/runtime/traverser.d.ts +3 -26
- package/dist/runtime/traverser.js +1 -2
- package/dist/runtime/types.d.ts +3 -16
- package/dist/runtime/types.js +1 -1
- package/dist/runtime/workflow-logic-handler.d.ts +17 -0
- package/dist/runtime/workflow-logic-handler.js +5 -0
- package/dist/runtime/workflow-logic-handler.js.map +1 -0
- package/dist/sanitizer.d.ts +3 -1
- package/dist/serializer.d.ts +3 -1
- package/dist/testing/event-logger.d.ts +63 -0
- package/dist/testing/event-logger.js +3 -0
- package/dist/testing/event-logger.js.map +1 -0
- package/dist/testing/index.d.ts +6 -0
- package/dist/testing/index.js +31 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/run-with-trace.d.ts +38 -0
- package/dist/testing/run-with-trace.js +29 -0
- package/dist/testing/run-with-trace.js.map +1 -0
- package/dist/testing/stepper.d.ts +79 -0
- package/dist/testing/stepper.js +11 -0
- package/dist/testing/stepper.js.map +1 -0
- package/dist/types-ezHUBdpL.d.ts +564 -0
- package/dist/types.d.ts +3 -1
- package/package.json +55 -51
- package/LICENSE +0 -21
- package/dist/chunk-5ZXV3R5D.js +0 -28
- package/dist/chunk-5ZXV3R5D.js.map +0 -1
- package/dist/chunk-GEKDR2SS.js +0 -201
- package/dist/chunk-GEKDR2SS.js.map +0 -1
- package/dist/chunk-HMR2GEGE.js +0 -3
- package/dist/chunk-M2FRTT2K.js +0 -144
- package/dist/chunk-M2FRTT2K.js.map +0 -1
- package/dist/chunk-OTS5YJ3S.js +0 -494
- package/dist/chunk-OTS5YJ3S.js.map +0 -1
- package/dist/chunk-QLGJUDQF.js.map +0 -1
- package/dist/chunk-U5V5O5MN.js.map +0 -1
- package/dist/chunk-VSGQDLBF.js +0 -61
- package/dist/chunk-VSGQDLBF.js.map +0 -1
- package/dist/chunk-ZCHFZBGL.js.map +0 -1
- package/dist/types-CsTeXTiA.d.ts +0 -222
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Feathers
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/chunk-5ZXV3R5D.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// src/errors.ts
|
|
2
|
-
var NodeExecutionError = class extends Error {
|
|
3
|
-
constructor(message, nodeId, blueprintId, originalError, executionId) {
|
|
4
|
-
super(message);
|
|
5
|
-
this.nodeId = nodeId;
|
|
6
|
-
this.blueprintId = blueprintId;
|
|
7
|
-
this.originalError = originalError;
|
|
8
|
-
this.executionId = executionId;
|
|
9
|
-
this.name = "NodeExecutionError";
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
var CancelledWorkflowError = class extends Error {
|
|
13
|
-
constructor(message = "Workflow execution was cancelled.", executionId) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.executionId = executionId;
|
|
16
|
-
this.name = "CancelledWorkflowError";
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
var FatalNodeExecutionError = class extends NodeExecutionError {
|
|
20
|
-
constructor(message, nodeId, blueprintId, originalError, executionId) {
|
|
21
|
-
super(message, nodeId, blueprintId, originalError, executionId);
|
|
22
|
-
this.name = "FatalNodeExecutionError";
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export { CancelledWorkflowError, FatalNodeExecutionError, NodeExecutionError };
|
|
27
|
-
//# sourceMappingURL=chunk-5ZXV3R5D.js.map
|
|
28
|
-
//# sourceMappingURL=chunk-5ZXV3R5D.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";AACO,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EAC7C,WAAA,CACC,OAAA,EACgB,MAAA,EACA,WAAA,EACA,eACA,WAAA,EACf;AACD,IAAA,KAAA,CAAM,OAAO,CAAA;AALG,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AACA,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AAAA,EACb;AACD;AAGO,IAAM,sBAAA,GAAN,cAAqC,KAAA,CAAM;AAAA,EACjD,WAAA,CACC,OAAA,GAAU,mCAAA,EACM,WAAA,EACf;AACD,IAAA,KAAA,CAAM,OAAO,CAAA;AAFG,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,wBAAA;AAAA,EACb;AACD;AAGO,IAAM,uBAAA,GAAN,cAAsC,kBAAA,CAAmB;AAAA,EAC/D,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAgB,WAAA,EAAqB,eAAuB,WAAA,EAAsB;AAC9G,IAAA,KAAA,CAAM,OAAA,EAAS,MAAA,EAAQ,WAAA,EAAa,aAAA,EAAe,WAAW,CAAA;AAC9D,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AAAA,EACb;AACD","file":"chunk-5ZXV3R5D.js","sourcesContent":["/** Error thrown when a node fails during execution. */\nexport class NodeExecutionError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly nodeId: string,\n\t\tpublic readonly blueprintId: string,\n\t\tpublic readonly originalError?: Error,\n\t\tpublic readonly executionId?: string,\n\t) {\n\t\tsuper(message)\n\t\tthis.name = 'NodeExecutionError'\n\t}\n}\n\n/** Error thrown when a workflow is gracefully aborted. */\nexport class CancelledWorkflowError extends Error {\n\tconstructor(\n\t\tmessage = 'Workflow execution was cancelled.',\n\t\tpublic readonly executionId?: string,\n\t) {\n\t\tsuper(message)\n\t\tthis.name = 'CancelledWorkflowError'\n\t}\n}\n\n/** Error thrown for a non-recoverable failure that should halt the workflow immediately. */\nexport class FatalNodeExecutionError extends NodeExecutionError {\n\tconstructor(message: string, nodeId: string, blueprintId: string, originalError?: Error, executionId?: string) {\n\t\tsuper(message, nodeId, blueprintId, originalError, executionId)\n\t\tthis.name = 'FatalNodeExecutionError'\n\t}\n}\n"]}
|
package/dist/chunk-GEKDR2SS.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { CancelledWorkflowError, NodeExecutionError } from './chunk-5ZXV3R5D.js';
|
|
2
|
-
import { analyzeBlueprint } from './chunk-233SESC2.js';
|
|
3
|
-
|
|
4
|
-
// src/runtime/traverser.ts
|
|
5
|
-
var GraphTraverser = class {
|
|
6
|
-
constructor(blueprint, runtime, state, functionRegistry, executionId, signal, concurrency) {
|
|
7
|
-
this.runtime = runtime;
|
|
8
|
-
this.state = state;
|
|
9
|
-
this.functionRegistry = functionRegistry;
|
|
10
|
-
this.executionId = executionId;
|
|
11
|
-
this.signal = signal;
|
|
12
|
-
this.concurrency = concurrency;
|
|
13
|
-
if (this.concurrency === void 0) {
|
|
14
|
-
const hardwareConcurrency = globalThis.navigator?.hardwareConcurrency || 4;
|
|
15
|
-
this.concurrency = Math.min(hardwareConcurrency, 10);
|
|
16
|
-
}
|
|
17
|
-
this.dynamicBlueprint = structuredClone(blueprint);
|
|
18
|
-
this.allPredecessors = /* @__PURE__ */ new Map();
|
|
19
|
-
for (const node of this.dynamicBlueprint.nodes) {
|
|
20
|
-
this.allPredecessors.set(node.id, /* @__PURE__ */ new Set());
|
|
21
|
-
}
|
|
22
|
-
for (const edge of this.dynamicBlueprint.edges) {
|
|
23
|
-
this.allPredecessors.get(edge.target)?.add(edge.source);
|
|
24
|
-
}
|
|
25
|
-
const analysis = analyzeBlueprint(blueprint);
|
|
26
|
-
this.frontier = new Set(analysis.startNodeIds.filter((id) => !this.isFallbackNode(id)));
|
|
27
|
-
if (this.frontier.size === 0 && analysis.cycles.length > 0 && this.runtime.options.strict !== true) {
|
|
28
|
-
const uniqueStartNodes = /* @__PURE__ */ new Set();
|
|
29
|
-
const cycleEntryPoints = new Set(blueprint.metadata?.cycleEntryPoints || []);
|
|
30
|
-
for (const cycle of analysis.cycles) {
|
|
31
|
-
if (cycle.length > 0) {
|
|
32
|
-
const entryPoint = cycle.find((node) => cycleEntryPoints.has(node));
|
|
33
|
-
uniqueStartNodes.add(entryPoint || cycle[0]);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
this.frontier = new Set(uniqueStartNodes);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
frontier = /* @__PURE__ */ new Set();
|
|
40
|
-
allPredecessors;
|
|
41
|
-
dynamicBlueprint;
|
|
42
|
-
isFallbackNode(nodeId) {
|
|
43
|
-
return this.dynamicBlueprint.nodes.some((n) => n.config?.fallback === nodeId);
|
|
44
|
-
}
|
|
45
|
-
getEffectiveJoinStrategy(nodeId) {
|
|
46
|
-
const node = this.dynamicBlueprint.nodes.find((n) => n.id === nodeId);
|
|
47
|
-
const baseJoinStrategy = node?.config?.joinStrategy || "all";
|
|
48
|
-
if (node?.uses === "loop-controller") {
|
|
49
|
-
return "any";
|
|
50
|
-
}
|
|
51
|
-
const predecessors = this.allPredecessors.get(nodeId);
|
|
52
|
-
if (predecessors) {
|
|
53
|
-
for (const predecessorId of predecessors) {
|
|
54
|
-
const predecessorNode = this.dynamicBlueprint.nodes.find((n) => n.id === predecessorId);
|
|
55
|
-
if (predecessorNode?.uses === "loop-controller") {
|
|
56
|
-
return "any";
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return baseJoinStrategy;
|
|
61
|
-
}
|
|
62
|
-
async traverse() {
|
|
63
|
-
try {
|
|
64
|
-
this.signal?.throwIfAborted();
|
|
65
|
-
} catch (error) {
|
|
66
|
-
if (error instanceof DOMException && error.name === "AbortError")
|
|
67
|
-
throw new CancelledWorkflowError("Workflow cancelled");
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
let iterations = 0;
|
|
71
|
-
const maxIterations = 1e4;
|
|
72
|
-
while (this.frontier.size > 0) {
|
|
73
|
-
if (++iterations > maxIterations) throw new Error("Traversal exceeded maximum iterations, possible infinite loop");
|
|
74
|
-
try {
|
|
75
|
-
this.signal?.throwIfAborted();
|
|
76
|
-
const currentJobs = Array.from(this.frontier);
|
|
77
|
-
this.frontier.clear();
|
|
78
|
-
const settledResults = await this.executeWithConcurrency(currentJobs);
|
|
79
|
-
const completedThisTurn = /* @__PURE__ */ new Set();
|
|
80
|
-
for (const promiseResult of settledResults) {
|
|
81
|
-
if (promiseResult.status === "rejected") {
|
|
82
|
-
const { nodeId: nodeId2, error } = promiseResult.reason;
|
|
83
|
-
if (error instanceof CancelledWorkflowError) throw error;
|
|
84
|
-
this.state.addError(nodeId2, error);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
const { nodeId, result } = promiseResult.value;
|
|
88
|
-
this.state.addCompletedNode(nodeId, result.output);
|
|
89
|
-
completedThisTurn.add(nodeId);
|
|
90
|
-
if (result._fallbackExecuted) this.state.markFallbackExecuted();
|
|
91
|
-
await this.handleDynamicNodes(nodeId, result);
|
|
92
|
-
if (!result._fallbackExecuted) {
|
|
93
|
-
const matched = await this.runtime.determineNextNodes(
|
|
94
|
-
this.dynamicBlueprint,
|
|
95
|
-
nodeId,
|
|
96
|
-
result,
|
|
97
|
-
this.state.getContext(),
|
|
98
|
-
this.executionId
|
|
99
|
-
);
|
|
100
|
-
const loopControllerMatch = matched.find((m) => m.node.uses === "loop-controller");
|
|
101
|
-
const finalMatched = loopControllerMatch ? [loopControllerMatch] : matched;
|
|
102
|
-
for (const { node, edge } of finalMatched) {
|
|
103
|
-
const joinStrategy = this.getEffectiveJoinStrategy(node.id);
|
|
104
|
-
if (joinStrategy !== "any" && this.state.getCompletedNodes().has(node.id)) continue;
|
|
105
|
-
await this.runtime.applyEdgeTransform(edge, result, node, this.state.getContext(), this.allPredecessors);
|
|
106
|
-
const requiredPredecessors = this.allPredecessors.get(node.id);
|
|
107
|
-
if (!requiredPredecessors) continue;
|
|
108
|
-
const isReady = joinStrategy === "any" ? [...requiredPredecessors].some((p) => completedThisTurn.has(p)) : [...requiredPredecessors].every((p) => this.state.getCompletedNodes().has(p));
|
|
109
|
-
if (isReady) this.frontier.add(node.id);
|
|
110
|
-
}
|
|
111
|
-
if (matched.length === 0) {
|
|
112
|
-
for (const [potentialNextId, predecessors] of this.allPredecessors) {
|
|
113
|
-
if (predecessors.has(nodeId) && !this.state.getCompletedNodes().has(potentialNextId)) {
|
|
114
|
-
const joinStrategy = this.getEffectiveJoinStrategy(potentialNextId);
|
|
115
|
-
const isReady = joinStrategy === "any" ? [...predecessors].some((p) => completedThisTurn.has(p)) : [...predecessors].every((p) => this.state.getCompletedNodes().has(p));
|
|
116
|
-
if (isReady) this.frontier.add(potentialNextId);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
} catch (error) {
|
|
123
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
124
|
-
throw new CancelledWorkflowError("Workflow cancelled");
|
|
125
|
-
}
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async executeWithConcurrency(nodeIds) {
|
|
131
|
-
const maxConcurrency = this.concurrency || nodeIds.length;
|
|
132
|
-
const results = [];
|
|
133
|
-
for (let i = 0; i < nodeIds.length; i += maxConcurrency) {
|
|
134
|
-
const batch = nodeIds.slice(i, i + maxConcurrency);
|
|
135
|
-
const batchPromises = batch.map(async (nodeId) => {
|
|
136
|
-
try {
|
|
137
|
-
const result = await this.runtime.executeNode(
|
|
138
|
-
this.dynamicBlueprint,
|
|
139
|
-
nodeId,
|
|
140
|
-
this.state,
|
|
141
|
-
this.allPredecessors,
|
|
142
|
-
this.functionRegistry,
|
|
143
|
-
this.executionId,
|
|
144
|
-
this.signal
|
|
145
|
-
);
|
|
146
|
-
results.push({
|
|
147
|
-
status: "fulfilled",
|
|
148
|
-
value: { nodeId, result }
|
|
149
|
-
});
|
|
150
|
-
} catch (error) {
|
|
151
|
-
results.push({
|
|
152
|
-
status: "rejected",
|
|
153
|
-
reason: { nodeId, error }
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
await Promise.all(batchPromises);
|
|
158
|
-
}
|
|
159
|
-
return results;
|
|
160
|
-
}
|
|
161
|
-
async handleDynamicNodes(nodeId, result) {
|
|
162
|
-
if (result.dynamicNodes && result.dynamicNodes.length > 0) {
|
|
163
|
-
const gatherNodeId = result.output?.gatherNodeId;
|
|
164
|
-
for (const dynamicNode of result.dynamicNodes) {
|
|
165
|
-
const implementation = this.functionRegistry?.get(dynamicNode.uses) || this.runtime.registry[dynamicNode.uses];
|
|
166
|
-
if (!implementation) {
|
|
167
|
-
throw new NodeExecutionError(
|
|
168
|
-
`Implementation for '${dynamicNode.uses}' not found for dynamic node '${dynamicNode.id}' generated by node '${nodeId}'.`,
|
|
169
|
-
dynamicNode.id,
|
|
170
|
-
this.dynamicBlueprint.id,
|
|
171
|
-
void 0,
|
|
172
|
-
this.executionId
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
this.dynamicBlueprint.nodes.push(dynamicNode);
|
|
176
|
-
this.allPredecessors.set(dynamicNode.id, /* @__PURE__ */ new Set([nodeId]));
|
|
177
|
-
if (gatherNodeId) {
|
|
178
|
-
this.allPredecessors.get(gatherNodeId)?.add(dynamicNode.id);
|
|
179
|
-
}
|
|
180
|
-
this.frontier.add(dynamicNode.id);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
getAllNodeIds() {
|
|
185
|
-
return new Set(this.dynamicBlueprint.nodes.map((n) => n.id));
|
|
186
|
-
}
|
|
187
|
-
getFallbackNodeIds() {
|
|
188
|
-
const fallbackNodeIds = /* @__PURE__ */ new Set();
|
|
189
|
-
for (const node of this.dynamicBlueprint.nodes) {
|
|
190
|
-
if (node.config?.fallback) fallbackNodeIds.add(node.config.fallback);
|
|
191
|
-
}
|
|
192
|
-
return fallbackNodeIds;
|
|
193
|
-
}
|
|
194
|
-
getDynamicBlueprint() {
|
|
195
|
-
return this.dynamicBlueprint;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export { GraphTraverser };
|
|
200
|
-
//# sourceMappingURL=chunk-GEKDR2SS.js.map
|
|
201
|
-
//# sourceMappingURL=chunk-GEKDR2SS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/traverser.ts"],"names":["nodeId"],"mappings":";;;;AAMO,IAAM,iBAAN,MAAsG;AAAA,EAK5G,YACC,SAAA,EACQ,OAAA,EACA,OACA,gBAAA,EACA,WAAA,EACA,QACA,WAAA,EACP;AANO,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AACA,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AACA,IAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA;AAER,IAAA,IAAI,IAAA,CAAK,gBAAgB,MAAA,EAAW;AACnC,MAAA,MAAM,mBAAA,GAAsB,UAAA,CAAW,SAAA,EAAW,mBAAA,IAAuB,CAAA;AACzE,MAAA,IAAA,CAAK,WAAA,GAAc,IAAA,CA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EA,aAAA,GAA6B;AAC5B,IAAA,OAAO,IAAI,GAAA,CAAI,IAAA,CAAK,gBAAA,CAAiB,KAAA,CAAM,IAAI,CAAC,CAAA,KAAM,CAAA,CAAE,EAAE,CAAC,CAAA;AAAA,EAC5D;AAAA,EAEA,kBAAA,GAAkC;AACjC,IAAA,MAAM,eAAA,uBAAsB,GAAA,EAAY;AACxC,IAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,gBAAA,CAAiB,KAAA,EAAO;AAC/C,MAAA,IAAI,KAAK,MAAA,EAAQ,QAAA,kBAA0B,GAAA,CAAI,IAAA,CAAK,OAAO,QAAQ,CAAA;AAAA,IACpE;AACA,IAAA,OAAO,eAAA;AAAA,EACR;AAAA,EAEA,mBAAA,GAAyC;AACxC,IAAA,OAAO,IAAA,CAAK,gBAAA;AAAA,EACb;AACD","file":"chunk-GEKDR2SS.js","sourcesContent":["import { analyzeBlueprint } from '../analysis'\nimport { CancelledWorkflowError, NodeExecutionError } from '../errors'\nimport type { NodeResult, WorkflowBlueprint } from '../types'\nimport type { WorkflowState } from './state'\nimport type { IRuntime } from './types'\n\nexport class GraphTraverser<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {\n\tprivate frontier = new Set<string>()\n\tprivate allPredecessors: Map<string, Set<string>>\n\tprivate dynamicBlueprint: WorkflowBlueprint\n\n\tconstructor(\n\t\tblueprint: WorkflowBlueprint,\n\t\tprivate runtime: IRuntime<TContext, TDependencies>,\n\t\tprivate state: WorkflowState<TContext>,\n\t\tprivate functionRegistry: Map<string, any> | undefined,\n\t\tprivate executionId: string,\n\t\tprivate signal?: AbortSignal,\n\t\tprivate concurrency?: number,\n\t) {\n\t\tif (this.concurrency === undefined) {\n\t\t\tconst hardwareConcurrency = globalThis.navigator?.hardwareConcurrency || 4\n\t\t\tthis.concurrency = Math.min(hardwareConcurrency, 10)\n\t\t}\n\t\tthis.dynamicBlueprint = structuredClone(blueprint) as WorkflowBlueprint\n\t\tthis.allPredecessors = new Map<string, Set<string>>()\n\t\tfor (const node of this.dynamicBlueprint.nodes) {\n\t\t\tthis.allPredecessors.set(node.id, new Set())\n\t\t}\n\t\tfor (const edge of this.dynamicBlueprint.edges) {\n\t\t\tthis.allPredecessors.get(edge.target)?.add(edge.source)\n\t\t}\n\t\tconst analysis = analyzeBlueprint(blueprint)\n\t\tthis.frontier = new Set(analysis.startNodeIds.filter((id) => !this.isFallbackNode(id)))\n\t\tif (this.frontier.size === 0 && analysis.cycles.length > 0 && this.runtime.options.strict !== true) {\n\t\t\tconst uniqueStartNodes = new Set<string>()\n\t\t\tconst cycleEntryPoints = new Set(blueprint.metadata?.cycleEntryPoints || [])\n\t\t\tfor (const cycle of analysis.cycles) {\n\t\t\t\tif (cycle.length > 0) {\n\t\t\t\t\t// prefer entry points if specified, otherwise use the first node\n\t\t\t\t\tconst entryPoint = cycle.find((node) => cycleEntryPoints.has(node))\n\t\t\t\t\tuniqueStartNodes.add(entryPoint || cycle[0])\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.frontier = new Set(uniqueStartNodes)\n\t\t}\n\t}\n\n\tprivate isFallbackNode(nodeId: string): boolean {\n\t\treturn this.dynamicBlueprint.nodes.some((n) => n.config?.fallback === nodeId)\n\t}\n\n\tprivate getEffectiveJoinStrategy(nodeId: string): 'any' | 'all' {\n\t\tconst node = this.dynamicBlueprint.nodes.find((n) => n.id === nodeId)\n\t\tconst baseJoinStrategy = node?.config?.joinStrategy || 'all'\n\n\t\tif (node?.uses === 'loop-controller') {\n\t\t\treturn 'any'\n\t\t}\n\n\t\tconst predecessors = this.allPredecessors.get(nodeId)\n\t\tif (predecessors) {\n\t\t\tfor (const predecessorId of predecessors) {\n\t\t\t\tconst predecessorNode = this.dynamicBlueprint.nodes.find((n) => n.id === predecessorId)\n\t\t\t\tif (predecessorNode?.uses === 'loop-controller') {\n\t\t\t\t\treturn 'any'\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn baseJoinStrategy\n\t}\n\n\tasync traverse(): Promise<void> {\n\t\ttry {\n\t\t\tthis.signal?.throwIfAborted()\n\t\t} catch (error) {\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError')\n\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\tthrow error\n\t\t}\n\t\tlet iterations = 0\n\t\tconst maxIterations = 10000\n\t\twhile (this.frontier.size > 0) {\n\t\t\tif (++iterations > maxIterations) throw new Error('Traversal exceeded maximum iterations, possible infinite loop')\n\n\t\t\ttry {\n\t\t\t\tthis.signal?.throwIfAborted()\n\t\t\t\tconst currentJobs = Array.from(this.frontier)\n\t\t\t\tthis.frontier.clear()\n\t\t\t\tconst settledResults = await this.executeWithConcurrency(currentJobs)\n\t\t\t\tconst completedThisTurn = new Set<string>()\n\t\t\t\tfor (const promiseResult of settledResults) {\n\t\t\t\t\tif (promiseResult.status === 'rejected') {\n\t\t\t\t\t\tconst { nodeId, error } = promiseResult.reason\n\t\t\t\t\t\tif (error instanceof CancelledWorkflowError) throw error\n\t\t\t\t\t\tthis.state.addError(nodeId, error as Error)\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst { nodeId, result } = promiseResult.value\n\t\t\t\t\tthis.state.addCompletedNode(nodeId, result.output)\n\t\t\t\t\tcompletedThisTurn.add(nodeId)\n\t\t\t\t\tif (result._fallbackExecuted) this.state.markFallbackExecuted()\n\t\t\t\t\tawait this.handleDynamicNodes(nodeId, result)\n\t\t\t\t\tif (!result._fallbackExecuted) {\n\t\t\t\t\t\tconst matched = await this.runtime.determineNextNodes(\n\t\t\t\t\t\t\tthis.dynamicBlueprint,\n\t\t\t\t\t\t\tnodeId,\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tthis.state.getContext(),\n\t\t\t\t\t\t\tthis.executionId,\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\t// if one of the next nodes is a loop controller, prioritize it to avoid ambiguity from manual cycle edges.\n\t\t\t\t\t\tconst loopControllerMatch = matched.find((m) => m.node.uses === 'loop-controller')\n\t\t\t\t\t\tconst finalMatched = loopControllerMatch ? [loopControllerMatch] : matched\n\n\t\t\t\t\t\tfor (const { node, edge } of finalMatched) {\n\t\t\t\t\t\t\tconst joinStrategy = this.getEffectiveJoinStrategy(node.id)\n\t\t\t\t\t\t\tif (joinStrategy !== 'any' && this.state.getCompletedNodes().has(node.id)) continue\n\t\t\t\t\t\t\tawait this.runtime.applyEdgeTransform(edge, result, node, this.state.getContext(), this.allPredecessors)\n\t\t\t\t\t\t\tconst requiredPredecessors = this.allPredecessors.get(node.id)\n\t\t\t\t\t\t\tif (!requiredPredecessors) continue\n\t\t\t\t\t\t\tconst isReady =\n\t\t\t\t\t\t\t\tjoinStrategy === 'any'\n\t\t\t\t\t\t\t\t\t? [...requiredPredecessors].some((p) => completedThisTurn.has(p))\n\t\t\t\t\t\t\t\t\t: [...requiredPredecessors].every((p) => this.state.getCompletedNodes().has(p))\n\t\t\t\t\t\t\tif (isReady) this.frontier.add(node.id)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (matched.length === 0) {\n\t\t\t\t\t\t\tfor (const [potentialNextId, predecessors] of this.allPredecessors) {\n\t\t\t\t\t\t\t\tif (predecessors.has(nodeId) && !this.state.getCompletedNodes().has(potentialNextId)) {\n\t\t\t\t\t\t\t\t\tconst joinStrategy = this.getEffectiveJoinStrategy(potentialNextId)\n\t\t\t\t\t\t\t\t\tconst isReady =\n\t\t\t\t\t\t\t\t\t\tjoinStrategy === 'any'\n\t\t\t\t\t\t\t\t\t\t\t? [...predecessors].some((p) => completedThisTurn.has(p))\n\t\t\t\t\t\t\t\t\t\t\t: [...predecessors].every((p) => this.state.getCompletedNodes().has(p))\n\t\t\t\t\t\t\t\t\tif (isReady) this.frontier.add(potentialNextId)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\t\t}\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async executeWithConcurrency(\n\t\tnodeIds: string[],\n\t): Promise<\n\t\tArray<\n\t\t\t| { status: 'fulfilled'; value: { nodeId: string; result: NodeResult<any, any> } }\n\t\t\t| { status: 'rejected'; reason: { nodeId: string; error: unknown } }\n\t\t>\n\t> {\n\t\tconst maxConcurrency = this.concurrency || nodeIds.length\n\t\tconst results: Array<\n\t\t\t| { status: 'fulfilled'; value: { nodeId: string; result: NodeResult<any, any> } }\n\t\t\t| { status: 'rejected'; reason: { nodeId: string; error: unknown } }\n\t\t> = []\n\n\t\tfor (let i = 0; i < nodeIds.length; i += maxConcurrency) {\n\t\t\tconst batch = nodeIds.slice(i, i + maxConcurrency)\n\t\t\tconst batchPromises = batch.map(async (nodeId) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await this.runtime.executeNode(\n\t\t\t\t\t\tthis.dynamicBlueprint,\n\t\t\t\t\t\tnodeId,\n\t\t\t\t\t\tthis.state,\n\t\t\t\t\t\tthis.allPredecessors,\n\t\t\t\t\t\tthis.functionRegistry,\n\t\t\t\t\t\tthis.executionId,\n\t\t\t\t\t\tthis.signal,\n\t\t\t\t\t)\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tstatus: 'fulfilled' as const,\n\t\t\t\t\t\tvalue: { nodeId, result },\n\t\t\t\t\t})\n\t\t\t\t} catch (error) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tstatus: 'rejected' as const,\n\t\t\t\t\t\treason: { nodeId, error },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tawait Promise.all(batchPromises)\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprivate async handleDynamicNodes(nodeId: string, result: NodeResult<any, any>) {\n\t\tif (result.dynamicNodes && result.dynamicNodes.length > 0) {\n\t\t\tconst gatherNodeId = result.output?.gatherNodeId\n\t\t\tfor (const dynamicNode of result.dynamicNodes) {\n\t\t\t\tconst implementation = this.functionRegistry?.get(dynamicNode.uses) || this.runtime.registry[dynamicNode.uses]\n\t\t\t\tif (!implementation) {\n\t\t\t\t\tthrow new NodeExecutionError(\n\t\t\t\t\t\t`Implementation for '${dynamicNode.uses}' not found for dynamic node '${dynamicNode.id}' generated by node '${nodeId}'.`,\n\t\t\t\t\t\tdynamicNode.id,\n\t\t\t\t\t\tthis.dynamicBlueprint.id,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tthis.executionId,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tthis.dynamicBlueprint.nodes.push(dynamicNode)\n\t\t\t\tthis.allPredecessors.set(dynamicNode.id, new Set([nodeId]))\n\t\t\t\tif (gatherNodeId) {\n\t\t\t\t\tthis.allPredecessors.get(gatherNodeId)?.add(dynamicNode.id)\n\t\t\t\t}\n\t\t\t\tthis.frontier.add(dynamicNode.id)\n\t\t\t}\n\t\t}\n\t}\n\n\tgetAllNodeIds(): Set<string> {\n\t\treturn new Set(this.dynamicBlueprint.nodes.map((n) => n.id))\n\t}\n\n\tgetFallbackNodeIds(): Set<string> {\n\t\tconst fallbackNodeIds = new Set<string>()\n\t\tfor (const node of this.dynamicBlueprint.nodes) {\n\t\t\tif (node.config?.fallback) fallbackNodeIds.add(node.config.fallback)\n\t\t}\n\t\treturn fallbackNodeIds\n\t}\n\n\tgetDynamicBlueprint(): WorkflowBlueprint {\n\t\treturn this.dynamicBlueprint\n\t}\n}\n"]}
|
package/dist/chunk-HMR2GEGE.js
DELETED
package/dist/chunk-M2FRTT2K.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { CancelledWorkflowError, FatalNodeExecutionError } from './chunk-5ZXV3R5D.js';
|
|
2
|
-
|
|
3
|
-
// src/runtime/executors.ts
|
|
4
|
-
async function withRetries(executor, maxRetries, nodeDef, context, executionId, signal, eventBus) {
|
|
5
|
-
let lastError;
|
|
6
|
-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
7
|
-
try {
|
|
8
|
-
signal?.throwIfAborted();
|
|
9
|
-
const result = await executor();
|
|
10
|
-
if (attempt > 1) {
|
|
11
|
-
context.dependencies.logger.info(`Node execution succeeded after retry`, {
|
|
12
|
-
nodeId: nodeDef.id,
|
|
13
|
-
attempt,
|
|
14
|
-
executionId
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return result;
|
|
18
|
-
} catch (error) {
|
|
19
|
-
lastError = error;
|
|
20
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
21
|
-
throw new CancelledWorkflowError("Workflow cancelled");
|
|
22
|
-
}
|
|
23
|
-
if (error instanceof FatalNodeExecutionError) break;
|
|
24
|
-
if (attempt < maxRetries) {
|
|
25
|
-
context.dependencies.logger.warn(`Node execution failed, retrying`, {
|
|
26
|
-
nodeId: nodeDef.id,
|
|
27
|
-
attempt,
|
|
28
|
-
maxRetries,
|
|
29
|
-
error: error instanceof Error ? error.message : String(error),
|
|
30
|
-
executionId
|
|
31
|
-
});
|
|
32
|
-
if (eventBus) {
|
|
33
|
-
await eventBus.emit("node:retry", {
|
|
34
|
-
blueprintId: context.dependencies.blueprint?.id || "",
|
|
35
|
-
nodeId: nodeDef.id,
|
|
36
|
-
attempt,
|
|
37
|
-
executionId
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
context.dependencies.logger.error(`Node execution failed after all retries`, {
|
|
42
|
-
nodeId: nodeDef.id,
|
|
43
|
-
attempts: maxRetries,
|
|
44
|
-
error: error instanceof Error ? error.message : String(error),
|
|
45
|
-
executionId
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
throw lastError;
|
|
51
|
-
}
|
|
52
|
-
var FunctionNodeExecutor = class {
|
|
53
|
-
constructor(implementation, maxRetries, eventBus) {
|
|
54
|
-
this.implementation = implementation;
|
|
55
|
-
this.maxRetries = maxRetries;
|
|
56
|
-
this.eventBus = eventBus;
|
|
57
|
-
}
|
|
58
|
-
async execute(nodeDef, context, executionId, signal) {
|
|
59
|
-
return withRetries(
|
|
60
|
-
() => this.implementation(context),
|
|
61
|
-
this.maxRetries,
|
|
62
|
-
nodeDef,
|
|
63
|
-
context,
|
|
64
|
-
executionId,
|
|
65
|
-
signal,
|
|
66
|
-
this.eventBus
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var ClassNodeExecutor = class {
|
|
71
|
-
constructor(implementation, maxRetries, eventBus) {
|
|
72
|
-
this.implementation = implementation;
|
|
73
|
-
this.maxRetries = maxRetries;
|
|
74
|
-
this.eventBus = eventBus;
|
|
75
|
-
}
|
|
76
|
-
async execute(nodeDef, context, executionId, signal) {
|
|
77
|
-
const instance = new this.implementation(nodeDef.params || {});
|
|
78
|
-
let lastError;
|
|
79
|
-
try {
|
|
80
|
-
signal?.throwIfAborted();
|
|
81
|
-
const prepResult = await instance.prep(context);
|
|
82
|
-
let execResult;
|
|
83
|
-
try {
|
|
84
|
-
execResult = await withRetries(
|
|
85
|
-
() => instance.exec(prepResult, context),
|
|
86
|
-
this.maxRetries,
|
|
87
|
-
nodeDef,
|
|
88
|
-
context,
|
|
89
|
-
executionId,
|
|
90
|
-
signal,
|
|
91
|
-
this.eventBus
|
|
92
|
-
);
|
|
93
|
-
} catch (error) {
|
|
94
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
95
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
96
|
-
throw new CancelledWorkflowError("Workflow cancelled");
|
|
97
|
-
}
|
|
98
|
-
if (error instanceof FatalNodeExecutionError) {
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (lastError) {
|
|
103
|
-
signal?.throwIfAborted();
|
|
104
|
-
execResult = await instance.fallback(lastError, context);
|
|
105
|
-
}
|
|
106
|
-
signal?.throwIfAborted();
|
|
107
|
-
if (!execResult) {
|
|
108
|
-
throw new Error("Execution failed after all retries");
|
|
109
|
-
}
|
|
110
|
-
return await instance.post(execResult, context);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
113
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
114
|
-
throw new CancelledWorkflowError("Workflow cancelled");
|
|
115
|
-
}
|
|
116
|
-
throw error;
|
|
117
|
-
} finally {
|
|
118
|
-
if (lastError) {
|
|
119
|
-
try {
|
|
120
|
-
await instance.recover(lastError, context);
|
|
121
|
-
} catch (recoverError) {
|
|
122
|
-
context.dependencies.logger.warn(`Recover phase failed`, {
|
|
123
|
-
nodeId: nodeDef.id,
|
|
124
|
-
originalError: lastError.message,
|
|
125
|
-
recoverError: recoverError instanceof Error ? recoverError.message : String(recoverError),
|
|
126
|
-
executionId
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var BuiltInNodeExecutor = class {
|
|
134
|
-
constructor(executeBuiltIn) {
|
|
135
|
-
this.executeBuiltIn = executeBuiltIn;
|
|
136
|
-
}
|
|
137
|
-
async execute(nodeDef, context) {
|
|
138
|
-
return this.executeBuiltIn(nodeDef, context.context);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export { BuiltInNodeExecutor, ClassNodeExecutor, FunctionNodeExecutor };
|
|
143
|
-
//# sourceMappingURL=chunk-M2FRTT2K.js.map
|
|
144
|
-
//# sourceMappingURL=chunk-M2FRTT2K.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/executors.ts"],"names":[],"mappings":";;;AAWA,eAAe,YACd,QAAA,EACA,UAAA,EACA,SACA,OAAA,EACA,WAAA,EACA,QACA,QAAA,EACa;AACb,EAAA,IAAI,SAAA;AACJ,EAAA,KAAA,IAAS,OAAA,GAA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AO,KAAK,CAAC,CAAA;AACpE,MAAA,IAAI,KAAA,YAAiB,YAAA,IAAgB,KAAA,CAAM,IAAA,KAAS,YAAA,EAAc;AACjE,QAAA,MAAM,IAAI,uBAAuB,oBAAoB,CAAA;AAAA,MACtD;AACA,MAAA,MAAM,KAAA;AAAA,IACP,CAAA,SAAE;AACD,MAAA,IAAI,SAAA,EAAW;AACd,QAAA,IAAI;AACH,UAAA,MAAM,QAAA,CAAS,OAAA,CAAQ,SAAA,EAAW,OAAO,CAAA;AAAA,QAC1C,SAAS,YAAA,EAAc;AACtB,UAAA,OAAA,CAAQ,YAAA,CAAa,MAAA,CAAO,IAAA,CAAK,CAAA,oBAAA,CAAA,EAAwB;AAAA,YACxD,QAAQ,OAAA,CAAQ,EAAA;AAAA,YAChB,eAAe,SAAA,CAAU,OAAA;AAAA,YACzB,cAAc,YAAA,YAAwB,KAAA,GAAQ,YAAA,CAAa,OAAA,GAAU,OAAO,YAAY,CAAA;AAAA,YACxF;AAAA,WACA,CAAA;AAAA,QACF;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AAEO,IAAM,sBAAN,MAAuD;AAAA,EAC7D,YACS,cAAA,EAIP;AAJO,IAAA,IAAA,CAAA,cAAA,GAAA,cAAA;AAAA,EAIN;AAAA,EAEH,MAAM,OAAA,CACL,OAAA,EACA,OAAA,EACgC;AAChC,IAAA,OAAO,IAAA,CAAK,cAAA,CAAe,OAAA,EAAS,OAAA,CAAQ,OAAqC,CAAA;AAAA,EAClF;AACD","file":"chunk-M2FRTT2K.js","sourcesContent":["import { CancelledWorkflowError, FatalNodeExecutionError } from '../errors'\nimport type {\n\tContextImplementation,\n\tIEventBus,\n\tNodeClass,\n\tNodeContext,\n\tNodeDefinition,\n\tNodeFunction,\n\tNodeResult,\n} from '../types'\n\nasync function withRetries<T>(\n\texecutor: () => Promise<T>,\n\tmaxRetries: number,\n\tnodeDef: NodeDefinition,\n\tcontext: NodeContext<any, any, any>,\n\texecutionId?: string,\n\tsignal?: AbortSignal,\n\teventBus?: IEventBus,\n): Promise<T> {\n\tlet lastError: any\n\tfor (let attempt = 1; attempt <= maxRetries; attempt++) {\n\t\ttry {\n\t\t\tsignal?.throwIfAborted()\n\t\t\tconst result = await executor()\n\t\t\tif (attempt > 1) {\n\t\t\t\tcontext.dependencies.logger.info(`Node execution succeeded after retry`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tattempt,\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn result\n\t\t} catch (error) {\n\t\t\tlastError = error\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\t}\n\t\t\tif (error instanceof FatalNodeExecutionError) break\n\t\t\tif (attempt < maxRetries) {\n\t\t\t\tcontext.dependencies.logger.warn(`Node execution failed, retrying`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tattempt,\n\t\t\t\t\tmaxRetries,\n\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t\tif (eventBus) {\n\t\t\t\t\tawait eventBus.emit('node:retry', {\n\t\t\t\t\t\tblueprintId: context.dependencies.blueprint?.id || '',\n\t\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\texecutionId,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcontext.dependencies.logger.error(`Node execution failed after all retries`, {\n\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\tattempts: maxRetries,\n\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t\texecutionId,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\tthrow lastError\n}\n\nexport interface ExecutionStrategy {\n\texecute: (\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<any, any, any>,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t) => Promise<NodeResult<any, any>>\n}\n\nexport class FunctionNodeExecutor implements ExecutionStrategy {\n\tconstructor(\n\t\tprivate implementation: NodeFunction,\n\t\tprivate maxRetries: number,\n\t\tprivate eventBus: IEventBus,\n\t) {}\n\n\tasync execute(\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<any, any, any>,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<NodeResult<any, any>> {\n\t\treturn withRetries(\n\t\t\t() => this.implementation(context),\n\t\t\tthis.maxRetries,\n\t\t\tnodeDef,\n\t\t\tcontext,\n\t\t\texecutionId,\n\t\t\tsignal,\n\t\t\tthis.eventBus,\n\t\t)\n\t}\n}\n\nexport class ClassNodeExecutor implements ExecutionStrategy {\n\tconstructor(\n\t\tprivate implementation: NodeClass,\n\t\tprivate maxRetries: number,\n\t\tprivate eventBus: IEventBus,\n\t) {}\n\n\tasync execute(\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<any, any, any>,\n\t\texecutionId?: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<NodeResult<any, any>> {\n\t\tconst instance = new this.implementation(nodeDef.params || {})\n\t\tlet lastError: Error | undefined\n\t\ttry {\n\t\t\tsignal?.throwIfAborted()\n\t\t\tconst prepResult = await instance.prep(context)\n\t\t\tlet execResult: Omit<NodeResult, 'error'> | undefined\n\t\t\ttry {\n\t\t\t\texecResult = await withRetries(\n\t\t\t\t\t() => instance.exec(prepResult, context),\n\t\t\t\t\tthis.maxRetries,\n\t\t\t\t\tnodeDef,\n\t\t\t\t\tcontext,\n\t\t\t\t\texecutionId,\n\t\t\t\t\tsignal,\n\t\t\t\t\tthis.eventBus,\n\t\t\t\t)\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error instanceof Error ? error : new Error(String(error))\n\t\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\t\t}\n\t\t\t\tif (error instanceof FatalNodeExecutionError) {\n\t\t\t\t\tthrow error\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (lastError) {\n\t\t\t\tsignal?.throwIfAborted()\n\t\t\t\texecResult = await instance.fallback(lastError, context)\n\t\t\t}\n\t\t\tsignal?.throwIfAborted()\n\t\t\tif (!execResult) {\n\t\t\t\tthrow new Error('Execution failed after all retries')\n\t\t\t}\n\t\t\treturn await instance.post(execResult, context)\n\t\t} catch (error) {\n\t\t\tlastError = error instanceof Error ? error : new Error(String(error))\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\tthrow new CancelledWorkflowError('Workflow cancelled')\n\t\t\t}\n\t\t\tthrow error\n\t\t} finally {\n\t\t\tif (lastError) {\n\t\t\t\ttry {\n\t\t\t\t\tawait instance.recover(lastError, context)\n\t\t\t\t} catch (recoverError) {\n\t\t\t\t\tcontext.dependencies.logger.warn(`Recover phase failed`, {\n\t\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\t\toriginalError: lastError.message,\n\t\t\t\t\t\trecoverError: recoverError instanceof Error ? recoverError.message : String(recoverError),\n\t\t\t\t\t\texecutionId,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class BuiltInNodeExecutor implements ExecutionStrategy {\n\tconstructor(\n\t\tprivate executeBuiltIn: (\n\t\t\tnodeDef: NodeDefinition,\n\t\t\tcontext: ContextImplementation<any>,\n\t\t) => Promise<NodeResult<any, any>>,\n\t) {}\n\n\tasync execute(\n\t\tnodeDef: NodeDefinition,\n\t\tcontext: NodeContext<Record<string, unknown>, Record<string, unknown>, any>,\n\t): Promise<NodeResult<any, any>> {\n\t\treturn this.executeBuiltIn(nodeDef, context.context as ContextImplementation<any>)\n\t}\n}\n"]}
|