flowcraft 2.7.1 → 2.8.1
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 +1 -1
- package/dist/index-D3dyjW2G.d.mts +1269 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +727 -0
- package/dist/index.mjs.map +1 -0
- package/dist/replay-BB11M6K1.mjs +107 -0
- package/dist/replay-BB11M6K1.mjs.map +1 -0
- package/dist/runtime-CmefIAu_.mjs +2216 -0
- package/dist/runtime-CmefIAu_.mjs.map +1 -0
- package/dist/{sdk.d.ts → sdk.d.mts} +14 -12
- package/dist/sdk.mjs +29 -0
- package/dist/sdk.mjs.map +1 -0
- package/dist/testing/index.d.mts +172 -0
- package/dist/testing/index.mjs +277 -0
- package/dist/testing/index.mjs.map +1 -0
- package/package.json +59 -59
- package/LICENSE +0 -21
- package/dist/adapters/index.d.ts +0 -4
- package/dist/adapters/index.js +0 -4
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/persistent-event-bus.d.ts +0 -69
- package/dist/adapters/persistent-event-bus.js +0 -3
- package/dist/adapters/persistent-event-bus.js.map +0 -1
- package/dist/analysis.d.ts +0 -53
- package/dist/analysis.js +0 -3
- package/dist/analysis.js.map +0 -1
- package/dist/chunk-27STBUGG.js +0 -44
- package/dist/chunk-27STBUGG.js.map +0 -1
- package/dist/chunk-2TSADFQX.js +0 -46
- package/dist/chunk-2TSADFQX.js.map +0 -1
- package/dist/chunk-3Y5O5EGB.js +0 -3
- package/dist/chunk-3Y5O5EGB.js.map +0 -1
- package/dist/chunk-4PELJWF7.js +0 -29
- package/dist/chunk-4PELJWF7.js.map +0 -1
- package/dist/chunk-55J6XMHW.js +0 -3
- package/dist/chunk-55J6XMHW.js.map +0 -1
- package/dist/chunk-6RKHCJUU.js +0 -29
- package/dist/chunk-6RKHCJUU.js.map +0 -1
- package/dist/chunk-7EBKWATZ.js +0 -86
- package/dist/chunk-7EBKWATZ.js.map +0 -1
- package/dist/chunk-7EMUOH77.js +0 -90
- package/dist/chunk-7EMUOH77.js.map +0 -1
- package/dist/chunk-7M6FHFHP.js +0 -25
- package/dist/chunk-7M6FHFHP.js.map +0 -1
- package/dist/chunk-AKDL2ZX7.js +0 -287
- package/dist/chunk-AKDL2ZX7.js.map +0 -1
- package/dist/chunk-BC4G7OM6.js +0 -42
- package/dist/chunk-BC4G7OM6.js.map +0 -1
- package/dist/chunk-BCMR7Y4U.js +0 -76
- package/dist/chunk-BCMR7Y4U.js.map +0 -1
- package/dist/chunk-BCRWXTWX.js +0 -21
- package/dist/chunk-BCRWXTWX.js.map +0 -1
- package/dist/chunk-BEHVGFIM.js +0 -532
- package/dist/chunk-BEHVGFIM.js.map +0 -1
- package/dist/chunk-DL7KVYZF.js +0 -39
- package/dist/chunk-DL7KVYZF.js.map +0 -1
- package/dist/chunk-DV2CXHOY.js +0 -74
- package/dist/chunk-DV2CXHOY.js.map +0 -1
- package/dist/chunk-H4JTZYIT.js +0 -172
- package/dist/chunk-H4JTZYIT.js.map +0 -1
- package/dist/chunk-HFJXYY4E.js +0 -3
- package/dist/chunk-HFJXYY4E.js.map +0 -1
- package/dist/chunk-HNHM3FDK.js +0 -52
- package/dist/chunk-HNHM3FDK.js.map +0 -1
- package/dist/chunk-HXSK5P2X.js +0 -150
- package/dist/chunk-HXSK5P2X.js.map +0 -1
- package/dist/chunk-I53JB2KW.js +0 -26
- package/dist/chunk-I53JB2KW.js.map +0 -1
- package/dist/chunk-IDTYHLDQ.js +0 -16
- package/dist/chunk-IDTYHLDQ.js.map +0 -1
- package/dist/chunk-IKOTX22J.js +0 -85
- package/dist/chunk-IKOTX22J.js.map +0 -1
- package/dist/chunk-L3MX5MTA.js +0 -33
- package/dist/chunk-L3MX5MTA.js.map +0 -1
- package/dist/chunk-L46TQXCV.js +0 -144
- package/dist/chunk-L46TQXCV.js.map +0 -1
- package/dist/chunk-LM4ACVHL.js +0 -73
- package/dist/chunk-LM4ACVHL.js.map +0 -1
- package/dist/chunk-LNK7LZER.js +0 -51
- package/dist/chunk-LNK7LZER.js.map +0 -1
- package/dist/chunk-N63S5NEG.js +0 -107
- package/dist/chunk-N63S5NEG.js.map +0 -1
- package/dist/chunk-NVLZFLYM.js +0 -3
- package/dist/chunk-NVLZFLYM.js.map +0 -1
- package/dist/chunk-ONH7PIJZ.js +0 -300
- package/dist/chunk-ONH7PIJZ.js.map +0 -1
- package/dist/chunk-PH2IYZHV.js +0 -48
- package/dist/chunk-PH2IYZHV.js.map +0 -1
- package/dist/chunk-RAZWRNAJ.js +0 -54
- package/dist/chunk-RAZWRNAJ.js.map +0 -1
- package/dist/chunk-RM677CNU.js +0 -52
- package/dist/chunk-RM677CNU.js.map +0 -1
- package/dist/chunk-TKSSRS5U.js +0 -39
- package/dist/chunk-TKSSRS5U.js.map +0 -1
- package/dist/chunk-U7DKCIWT.js +0 -340
- package/dist/chunk-U7DKCIWT.js.map +0 -1
- package/dist/chunk-UNORA7EM.js +0 -103
- package/dist/chunk-UNORA7EM.js.map +0 -1
- package/dist/chunk-WWGFIYKW.js +0 -47
- package/dist/chunk-WWGFIYKW.js.map +0 -1
- package/dist/chunk-XZZWIJ4G.js +0 -25
- package/dist/chunk-XZZWIJ4G.js.map +0 -1
- package/dist/chunk-ZETQCNEF.js +0 -139
- package/dist/chunk-ZETQCNEF.js.map +0 -1
- package/dist/chunk-ZLW4QOTS.js +0 -192
- package/dist/chunk-ZLW4QOTS.js.map +0 -1
- package/dist/container-factory.d.ts +0 -17
- package/dist/container-factory.js +0 -13
- package/dist/container-factory.js.map +0 -1
- package/dist/container.d.ts +0 -23
- package/dist/container.js +0 -3
- package/dist/container.js.map +0 -1
- package/dist/context.d.ts +0 -65
- package/dist/context.js +0 -3
- package/dist/context.js.map +0 -1
- package/dist/error-mapper.d.ts +0 -15
- package/dist/error-mapper.js +0 -4
- package/dist/error-mapper.js.map +0 -1
- package/dist/errors.d.ts +0 -20
- package/dist/errors.js +0 -3
- package/dist/errors.js.map +0 -1
- package/dist/evaluator.d.ts +0 -32
- package/dist/evaluator.js +0 -3
- package/dist/evaluator.js.map +0 -1
- package/dist/flow.d.ts +0 -85
- package/dist/flow.js +0 -4
- package/dist/flow.js.map +0 -1
- package/dist/index.d.ts +0 -18
- package/dist/index.js +0 -38
- package/dist/index.js.map +0 -1
- package/dist/linter.d.ts +0 -26
- package/dist/linter.js +0 -4
- package/dist/linter.js.map +0 -1
- package/dist/logger.d.ts +0 -20
- package/dist/logger.js +0 -3
- package/dist/logger.js.map +0 -1
- package/dist/node.d.ts +0 -3
- package/dist/node.js +0 -3
- package/dist/node.js.map +0 -1
- package/dist/nodes/batch-gather.d.ts +0 -9
- package/dist/nodes/batch-gather.js +0 -4
- package/dist/nodes/batch-gather.js.map +0 -1
- package/dist/nodes/batch-scatter.d.ts +0 -9
- package/dist/nodes/batch-scatter.js +0 -4
- package/dist/nodes/batch-scatter.js.map +0 -1
- package/dist/nodes/sleep.d.ts +0 -9
- package/dist/nodes/sleep.js +0 -4
- package/dist/nodes/sleep.js.map +0 -1
- package/dist/nodes/subflow.d.ts +0 -9
- package/dist/nodes/subflow.js +0 -10
- package/dist/nodes/subflow.js.map +0 -1
- package/dist/nodes/wait.d.ts +0 -9
- package/dist/nodes/wait.js +0 -4
- package/dist/nodes/wait.js.map +0 -1
- package/dist/nodes/webhook.d.ts +0 -13
- package/dist/nodes/webhook.js +0 -4
- package/dist/nodes/webhook.js.map +0 -1
- package/dist/runtime/adapter.d.ts +0 -114
- package/dist/runtime/adapter.js +0 -28
- package/dist/runtime/adapter.js.map +0 -1
- package/dist/runtime/builtin-keys.d.ts +0 -38
- package/dist/runtime/builtin-keys.js +0 -10
- package/dist/runtime/builtin-keys.js.map +0 -1
- package/dist/runtime/execution-context.d.ts +0 -3
- package/dist/runtime/execution-context.js +0 -6
- package/dist/runtime/execution-context.js.map +0 -1
- package/dist/runtime/executors.d.ts +0 -3
- package/dist/runtime/executors.js +0 -4
- package/dist/runtime/executors.js.map +0 -1
- package/dist/runtime/index.d.ts +0 -7
- package/dist/runtime/index.js +0 -31
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/node-executor-factory.d.ts +0 -12
- package/dist/runtime/node-executor-factory.js +0 -6
- package/dist/runtime/node-executor-factory.js.map +0 -1
- package/dist/runtime/orchestrator.d.ts +0 -9
- package/dist/runtime/orchestrator.js +0 -8
- package/dist/runtime/orchestrator.js.map +0 -1
- package/dist/runtime/orchestrators/replay.d.ts +0 -45
- package/dist/runtime/orchestrators/replay.js +0 -3
- package/dist/runtime/orchestrators/replay.js.map +0 -1
- package/dist/runtime/orchestrators/step-by-step.d.ts +0 -16
- package/dist/runtime/orchestrators/step-by-step.js +0 -5
- package/dist/runtime/orchestrators/step-by-step.js.map +0 -1
- package/dist/runtime/orchestrators/utils.d.ts +0 -35
- package/dist/runtime/orchestrators/utils.js +0 -4
- package/dist/runtime/orchestrators/utils.js.map +0 -1
- package/dist/runtime/runtime.d.ts +0 -3
- package/dist/runtime/runtime.js +0 -27
- package/dist/runtime/runtime.js.map +0 -1
- package/dist/runtime/scheduler.d.ts +0 -3
- package/dist/runtime/scheduler.js +0 -3
- package/dist/runtime/scheduler.js.map +0 -1
- package/dist/runtime/state.d.ts +0 -3
- package/dist/runtime/state.js +0 -5
- package/dist/runtime/state.js.map +0 -1
- package/dist/runtime/traverser.d.ts +0 -3
- package/dist/runtime/traverser.js +0 -4
- package/dist/runtime/traverser.js.map +0 -1
- package/dist/runtime/types.d.ts +0 -3
- package/dist/runtime/types.js +0 -3
- package/dist/runtime/types.js.map +0 -1
- package/dist/runtime/workflow-logic-handler.d.ts +0 -17
- package/dist/runtime/workflow-logic-handler.js +0 -5
- package/dist/runtime/workflow-logic-handler.js.map +0 -1
- package/dist/sanitizer.d.ts +0 -12
- package/dist/sanitizer.js +0 -3
- package/dist/sanitizer.js.map +0 -1
- package/dist/sdk.js +0 -20
- package/dist/sdk.js.map +0 -1
- package/dist/serializer.d.ts +0 -18
- package/dist/serializer.js +0 -3
- package/dist/serializer.js.map +0 -1
- package/dist/testing/event-logger.d.ts +0 -63
- package/dist/testing/event-logger.js +0 -3
- package/dist/testing/event-logger.js.map +0 -1
- package/dist/testing/index.d.ts +0 -7
- package/dist/testing/index.js +0 -37
- package/dist/testing/index.js.map +0 -1
- package/dist/testing/run-with-trace.d.ts +0 -38
- package/dist/testing/run-with-trace.js +0 -33
- package/dist/testing/run-with-trace.js.map +0 -1
- package/dist/testing/stepper.d.ts +0 -79
- package/dist/testing/stepper.js +0 -11
- package/dist/testing/stepper.js.map +0 -1
- package/dist/types-CKhffqyb.d.ts +0 -666
- package/dist/types.d.ts +0 -3
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
package/dist/chunk-ONH7PIJZ.js
DELETED
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { FlowcraftError } from './chunk-BCRWXTWX.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 FlowcraftError("Workflow cancelled", {
|
|
22
|
-
isFatal: false
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (error instanceof FlowcraftError && error.isFatal) break;
|
|
26
|
-
if (attempt < maxRetries) {
|
|
27
|
-
context.dependencies.logger.warn(`Node execution failed, retrying`, {
|
|
28
|
-
nodeId: nodeDef.id,
|
|
29
|
-
attempt,
|
|
30
|
-
maxRetries,
|
|
31
|
-
error: error instanceof Error ? error.message : String(error),
|
|
32
|
-
executionId
|
|
33
|
-
});
|
|
34
|
-
if (eventBus) {
|
|
35
|
-
await eventBus.emit({
|
|
36
|
-
type: "node:retry",
|
|
37
|
-
payload: {
|
|
38
|
-
nodeId: nodeDef.id,
|
|
39
|
-
attempt,
|
|
40
|
-
executionId: executionId || "",
|
|
41
|
-
blueprintId: context.dependencies.blueprint?.id || ""
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
context.dependencies.logger.error(`Node execution failed after all retries`, {
|
|
47
|
-
nodeId: nodeDef.id,
|
|
48
|
-
attempts: maxRetries,
|
|
49
|
-
error: error instanceof Error ? error.message : String(error),
|
|
50
|
-
executionId
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
throw lastError;
|
|
56
|
-
}
|
|
57
|
-
var FunctionNodeExecutor = class {
|
|
58
|
-
constructor(implementation, maxRetries, eventBus) {
|
|
59
|
-
this.implementation = implementation;
|
|
60
|
-
this.maxRetries = maxRetries;
|
|
61
|
-
this.eventBus = eventBus;
|
|
62
|
-
}
|
|
63
|
-
async execute(nodeDef, context, executionId, signal) {
|
|
64
|
-
return withRetries(
|
|
65
|
-
() => this.implementation(context),
|
|
66
|
-
this.maxRetries,
|
|
67
|
-
nodeDef,
|
|
68
|
-
context,
|
|
69
|
-
executionId,
|
|
70
|
-
signal,
|
|
71
|
-
this.eventBus
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var ClassNodeExecutor = class {
|
|
76
|
-
constructor(implementation, maxRetries, eventBus) {
|
|
77
|
-
this.implementation = implementation;
|
|
78
|
-
this.maxRetries = maxRetries;
|
|
79
|
-
this.eventBus = eventBus;
|
|
80
|
-
}
|
|
81
|
-
async execute(nodeDef, context, executionId, signal) {
|
|
82
|
-
const instance = new this.implementation(nodeDef.params || {}, nodeDef.id);
|
|
83
|
-
let lastError;
|
|
84
|
-
try {
|
|
85
|
-
signal?.throwIfAborted();
|
|
86
|
-
const prepResult = await instance.prep(context);
|
|
87
|
-
let execResult;
|
|
88
|
-
try {
|
|
89
|
-
execResult = await withRetries(
|
|
90
|
-
() => instance.exec(prepResult, context),
|
|
91
|
-
this.maxRetries,
|
|
92
|
-
nodeDef,
|
|
93
|
-
context,
|
|
94
|
-
executionId,
|
|
95
|
-
signal,
|
|
96
|
-
this.eventBus
|
|
97
|
-
);
|
|
98
|
-
} catch (error) {
|
|
99
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
100
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
101
|
-
throw new FlowcraftError("Workflow cancelled", {
|
|
102
|
-
isFatal: false
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (error instanceof FlowcraftError && error.isFatal) {
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (lastError) {
|
|
110
|
-
signal?.throwIfAborted();
|
|
111
|
-
execResult = await instance.fallback(lastError, context);
|
|
112
|
-
}
|
|
113
|
-
signal?.throwIfAborted();
|
|
114
|
-
if (!execResult) {
|
|
115
|
-
throw new Error("Execution failed after all retries");
|
|
116
|
-
}
|
|
117
|
-
return await instance.post(execResult, context);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
120
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
121
|
-
throw new FlowcraftError("Workflow cancelled", {
|
|
122
|
-
isFatal: false
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
throw error;
|
|
126
|
-
} finally {
|
|
127
|
-
if (lastError) {
|
|
128
|
-
try {
|
|
129
|
-
await instance.recover(lastError, context);
|
|
130
|
-
} catch (recoverError) {
|
|
131
|
-
context.dependencies.logger.warn(`Recover phase failed`, {
|
|
132
|
-
nodeId: nodeDef.id,
|
|
133
|
-
originalError: lastError.message,
|
|
134
|
-
recoverError: recoverError instanceof Error ? recoverError.message : String(recoverError),
|
|
135
|
-
executionId
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
var NodeExecutor = class {
|
|
143
|
-
context;
|
|
144
|
-
nodeDef;
|
|
145
|
-
strategy;
|
|
146
|
-
constructor(config) {
|
|
147
|
-
this.context = config.context;
|
|
148
|
-
this.nodeDef = config.nodeDef;
|
|
149
|
-
this.strategy = config.strategy;
|
|
150
|
-
}
|
|
151
|
-
async execute(input) {
|
|
152
|
-
const asyncContext = this.context.state.getContext();
|
|
153
|
-
const nodeContext = {
|
|
154
|
-
context: asyncContext,
|
|
155
|
-
input,
|
|
156
|
-
params: this.nodeDef.params || {},
|
|
157
|
-
dependencies: {
|
|
158
|
-
...this.context.services.dependencies,
|
|
159
|
-
logger: this.context.services.logger,
|
|
160
|
-
runtime: this.context,
|
|
161
|
-
workflowState: this.context.state
|
|
162
|
-
},
|
|
163
|
-
signal: this.context.signal
|
|
164
|
-
};
|
|
165
|
-
const beforeHooks = this.context.services.middleware.map((m) => m.beforeNode).filter((hook) => !!hook);
|
|
166
|
-
const afterHooks = this.context.services.middleware.map((m) => m.afterNode).filter((hook) => !!hook);
|
|
167
|
-
const aroundHooks = this.context.services.middleware.map((m) => m.aroundNode).filter((hook) => !!hook);
|
|
168
|
-
const coreExecution = async () => {
|
|
169
|
-
let result;
|
|
170
|
-
let error;
|
|
171
|
-
try {
|
|
172
|
-
for (const hook of beforeHooks) await hook(nodeContext.context, this.nodeDef.id);
|
|
173
|
-
result = await this.strategy.execute(this.nodeDef, nodeContext, this.context.executionId, this.context.signal);
|
|
174
|
-
return { status: "success", result };
|
|
175
|
-
} catch (e) {
|
|
176
|
-
error = e instanceof Error ? e : new Error(String(e));
|
|
177
|
-
const flowcraftError = error instanceof FlowcraftError ? error : new FlowcraftError(`Node '${this.nodeDef.id}' execution failed`, {
|
|
178
|
-
cause: error,
|
|
179
|
-
nodeId: this.nodeDef.id,
|
|
180
|
-
blueprintId: this.context.blueprint.id,
|
|
181
|
-
executionId: this.context.executionId,
|
|
182
|
-
isFatal: false
|
|
183
|
-
});
|
|
184
|
-
const fallbackNodeId = this.nodeDef.config?.fallback;
|
|
185
|
-
if (fallbackNodeId && !flowcraftError.isFatal) {
|
|
186
|
-
this.context.services.logger.warn(`Node failed, fallback required`, {
|
|
187
|
-
nodeId: this.nodeDef.id,
|
|
188
|
-
fallbackNodeId,
|
|
189
|
-
error: error.message,
|
|
190
|
-
executionId: this.context.executionId
|
|
191
|
-
});
|
|
192
|
-
await this.context.services.eventBus.emit({
|
|
193
|
-
type: "node:fallback",
|
|
194
|
-
payload: {
|
|
195
|
-
nodeId: this.nodeDef.id,
|
|
196
|
-
executionId: this.context.executionId || "",
|
|
197
|
-
fallback: fallbackNodeId,
|
|
198
|
-
blueprintId: this.context.blueprint.id
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
return { status: "failed_with_fallback", fallbackNodeId, error: flowcraftError };
|
|
202
|
-
}
|
|
203
|
-
return { status: "failed", error: flowcraftError };
|
|
204
|
-
} finally {
|
|
205
|
-
for (const hook of afterHooks) await hook(nodeContext.context, this.nodeDef.id, result, error);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
let executionChain = coreExecution;
|
|
209
|
-
for (let i = aroundHooks.length - 1; i >= 0; i--) {
|
|
210
|
-
const hook = aroundHooks[i];
|
|
211
|
-
const next = executionChain;
|
|
212
|
-
executionChain = async () => {
|
|
213
|
-
let capturedResult;
|
|
214
|
-
const middlewareResult = await hook(nodeContext.context, this.nodeDef.id, async () => {
|
|
215
|
-
capturedResult = await next();
|
|
216
|
-
if (capturedResult.status === "success") {
|
|
217
|
-
return capturedResult.result;
|
|
218
|
-
}
|
|
219
|
-
throw capturedResult.error;
|
|
220
|
-
});
|
|
221
|
-
if (!capturedResult && middlewareResult) {
|
|
222
|
-
return { status: "success", result: middlewareResult };
|
|
223
|
-
}
|
|
224
|
-
if (!capturedResult) {
|
|
225
|
-
throw new Error("Middleware did not call next() and did not return a result");
|
|
226
|
-
}
|
|
227
|
-
return capturedResult;
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
await this.context.services.eventBus.emit({
|
|
232
|
-
type: "node:start",
|
|
233
|
-
payload: {
|
|
234
|
-
nodeId: this.nodeDef.id,
|
|
235
|
-
executionId: this.context.executionId || "",
|
|
236
|
-
input: nodeContext.input,
|
|
237
|
-
blueprintId: this.context.blueprint.id
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
const executionResult = await executionChain();
|
|
241
|
-
if (executionResult.status === "success") {
|
|
242
|
-
await this.context.services.eventBus.emit({
|
|
243
|
-
type: "node:finish",
|
|
244
|
-
payload: {
|
|
245
|
-
nodeId: this.nodeDef.id,
|
|
246
|
-
result: executionResult.result,
|
|
247
|
-
executionId: this.context.executionId || "",
|
|
248
|
-
blueprintId: this.context.blueprint.id
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
} else {
|
|
252
|
-
await this.context.services.eventBus.emit({
|
|
253
|
-
type: "node:error",
|
|
254
|
-
payload: {
|
|
255
|
-
nodeId: this.nodeDef.id,
|
|
256
|
-
error: executionResult.error,
|
|
257
|
-
executionId: this.context.executionId || "",
|
|
258
|
-
blueprintId: this.context.blueprint.id
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
return executionResult;
|
|
263
|
-
} catch (error) {
|
|
264
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
265
|
-
const flowcraftError = err instanceof FlowcraftError ? err : new FlowcraftError(`Node '${this.nodeDef.id}' failed execution.`, {
|
|
266
|
-
cause: err,
|
|
267
|
-
nodeId: this.nodeDef.id,
|
|
268
|
-
blueprintId: this.context.blueprint.id,
|
|
269
|
-
executionId: this.context.executionId,
|
|
270
|
-
isFatal: false
|
|
271
|
-
});
|
|
272
|
-
await this.context.services.eventBus.emit({
|
|
273
|
-
type: "node:error",
|
|
274
|
-
payload: {
|
|
275
|
-
nodeId: this.nodeDef.id,
|
|
276
|
-
error: flowcraftError,
|
|
277
|
-
executionId: this.context.executionId || "",
|
|
278
|
-
blueprintId: this.context.blueprint.id
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
282
|
-
throw new FlowcraftError("Workflow cancelled", {
|
|
283
|
-
executionId: this.context.executionId,
|
|
284
|
-
isFatal: false
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
throw error instanceof FlowcraftError && !error.isFatal ? error : new FlowcraftError(`Node '${this.nodeDef.id}' failed execution.`, {
|
|
288
|
-
cause: error,
|
|
289
|
-
nodeId: this.nodeDef.id,
|
|
290
|
-
blueprintId: this.context.blueprint.id,
|
|
291
|
-
executionId: this.context.executionId,
|
|
292
|
-
isFatal: false
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
export { ClassNodeExecutor, FunctionNodeExecutor, NodeExecutor };
|
|
299
|
-
//# sourceMappingURL=chunk-ONH7PIJZ.js.map
|
|
300
|
-
//# sourceMappingURL=chunk-ONH7PIJZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/executors.ts"],"names":[],"mappings":";;;AAIA,eAAe,YACd,QAAA,EACA,UAAA,EACA,SACA,OAAA,EACA,WAAA,EACA,QACA,QAAA,EACa;AACb,EAAA,IAAI,SAAA;AACJ,EAAA,KAAA,IAAS,OAAA,GAAU,CAAA,EAAG,OAAA,IAAW,UAAA,EAAY,OAAA,EAAA,EAAW;AACvD,IAAA,IAAI;AACH,MAAA,MAAA,EAAQ,cAAA,EAAe;AACvB,MAAA,MAAM,MAAA,GAAS,MA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jE,QAAA,MAAM,IAAI,eAAe,oBAAA,EAAsB;AAAA,UAC9C,WAAA,EAAa,KAAK,OAAA,CAAQ,WAAA;AAAA,UAC1B,OAAA,EAAS;AAAA,SACT,CAAA;AAAA,MACF;AACA,MAAA,MAAM,KAAA,YAAiB,cAAA,IAAkB,CAAC,KAAA,CAAM,OAAA,GAC7C,KAAA,GACA,IAAI,cAAA,CAAe,CAAA,MAAA,EAAS,IAAA,CAAK,OAAA,CAAQ,EAAE,CAAA,mBAAA,CAAA,EAAuB;AAAA,QAClE,KAAA,EAAO,KAAA;AAAA,QACP,MAAA,EAAQ,KAAK,OAAA,CAAQ,EAAA;AAAA,QACrB,WAAA,EAAa,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU,EAAA;AAAA,QACpC,WAAA,EAAa,KAAK,OAAA,CAAQ,WAAA;AAAA,QAC1B,OAAA,EAAS;AAAA,OACT,CAAA;AAAA,IACJ;AAAA,EACD;AACD","file":"chunk-ONH7PIJZ.js","sourcesContent":["import { FlowcraftError } from '../errors'\nimport type { IEventBus, Middleware, NodeClass, NodeContext, NodeDefinition, NodeFunction, NodeResult } from '../types'\nimport type { ExecutionContext } from './execution-context'\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 FlowcraftError('Workflow cancelled', {\n\t\t\t\t\tisFatal: false,\n\t\t\t\t})\n\t\t\t}\n\t\t\tif (error instanceof FlowcraftError && error.isFatal) 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({\n\t\t\t\t\t\ttype: 'node:retry',\n\t\t\t\t\t\tpayload: {\n\t\t\t\t\t\t\tnodeId: nodeDef.id,\n\t\t\t\t\t\t\tattempt,\n\t\t\t\t\t\t\texecutionId: executionId || '',\n\t\t\t\t\t\t\tblueprintId: context.dependencies.blueprint?.id || '',\n\t\t\t\t\t\t},\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 || {}, nodeDef.id)\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 FlowcraftError('Workflow cancelled', {\n\t\t\t\t\t\tisFatal: false,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tif (error instanceof FlowcraftError && error.isFatal) {\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 FlowcraftError('Workflow cancelled', {\n\t\t\t\t\tisFatal: false,\n\t\t\t\t})\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 type NodeExecutionResult =\n\t| { status: 'success'; result: NodeResult<any, any> }\n\t| { status: 'failed_with_fallback'; fallbackNodeId: string; error: FlowcraftError }\n\t| { status: 'failed'; error: FlowcraftError }\n\nexport interface NodeExecutorConfig<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {\n\tcontext: ExecutionContext<TContext, TDependencies>\n\tnodeDef: NodeDefinition\n\tstrategy: ExecutionStrategy\n}\n\nexport class NodeExecutor<TContext extends Record<string, any>, TDependencies extends Record<string, any>> {\n\tprivate context: ExecutionContext<TContext, TDependencies>\n\tprivate nodeDef: NodeDefinition\n\tprivate strategy: ExecutionStrategy\n\n\tconstructor(config: NodeExecutorConfig<TContext, TDependencies>) {\n\t\tthis.context = config.context\n\t\tthis.nodeDef = config.nodeDef\n\t\tthis.strategy = config.strategy\n\t}\n\n\tasync execute(input: any): Promise<NodeExecutionResult> {\n\t\tconst asyncContext = this.context.state.getContext()\n\n\t\tconst nodeContext: NodeContext<TContext, TDependencies, any> = {\n\t\t\tcontext: asyncContext,\n\t\t\tinput,\n\t\t\tparams: this.nodeDef.params || {},\n\t\t\tdependencies: {\n\t\t\t\t...this.context.services.dependencies,\n\t\t\t\tlogger: this.context.services.logger,\n\t\t\t\truntime: this.context,\n\t\t\t\tworkflowState: this.context.state,\n\t\t\t},\n\t\t\tsignal: this.context.signal,\n\t\t}\n\n\t\tconst beforeHooks = this.context.services.middleware\n\t\t\t.map((m) => m.beforeNode)\n\t\t\t.filter((hook): hook is NonNullable<Middleware['beforeNode']> => !!hook)\n\t\tconst afterHooks = this.context.services.middleware\n\t\t\t.map((m) => m.afterNode)\n\t\t\t.filter((hook): hook is NonNullable<Middleware['afterNode']> => !!hook)\n\t\tconst aroundHooks = this.context.services.middleware\n\t\t\t.map((m) => m.aroundNode)\n\t\t\t.filter((hook): hook is NonNullable<Middleware['aroundNode']> => !!hook)\n\n\t\tconst coreExecution = async (): Promise<NodeExecutionResult> => {\n\t\t\tlet result: NodeResult | undefined\n\t\t\tlet error: Error | undefined\n\t\t\ttry {\n\t\t\t\tfor (const hook of beforeHooks) await hook(nodeContext.context, this.nodeDef.id)\n\t\t\t\tresult = await this.strategy.execute(this.nodeDef, nodeContext, this.context.executionId, this.context.signal)\n\t\t\t\treturn { status: 'success', result }\n\t\t\t} catch (e: any) {\n\t\t\t\terror = e instanceof Error ? e : new Error(String(e))\n\t\t\t\tconst flowcraftError =\n\t\t\t\t\terror instanceof FlowcraftError\n\t\t\t\t\t\t? error\n\t\t\t\t\t\t: new FlowcraftError(`Node '${this.nodeDef.id}' execution failed`, {\n\t\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t\t\t\t\texecutionId: this.context.executionId,\n\t\t\t\t\t\t\t\tisFatal: false,\n\t\t\t\t\t\t\t})\n\n\t\t\t\tconst fallbackNodeId = this.nodeDef.config?.fallback\n\t\t\t\tif (fallbackNodeId && !flowcraftError.isFatal) {\n\t\t\t\t\tthis.context.services.logger.warn(`Node failed, fallback required`, {\n\t\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\t\tfallbackNodeId,\n\t\t\t\t\t\terror: error.message,\n\t\t\t\t\t\texecutionId: this.context.executionId,\n\t\t\t\t\t})\n\t\t\t\t\tawait this.context.services.eventBus.emit({\n\t\t\t\t\t\ttype: 'node:fallback',\n\t\t\t\t\t\tpayload: {\n\t\t\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\t\t\texecutionId: this.context.executionId || '',\n\t\t\t\t\t\t\tfallback: fallbackNodeId,\n\t\t\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t\treturn { status: 'failed_with_fallback', fallbackNodeId, error: flowcraftError }\n\t\t\t\t}\n\t\t\t\treturn { status: 'failed', error: flowcraftError }\n\t\t\t} finally {\n\t\t\t\tfor (const hook of afterHooks) await hook(nodeContext.context, this.nodeDef.id, result, error)\n\t\t\t}\n\t\t}\n\n\t\tlet executionChain: () => Promise<NodeExecutionResult> = coreExecution\n\t\tfor (let i = aroundHooks.length - 1; i >= 0; i--) {\n\t\t\tconst hook = aroundHooks[i]\n\t\t\tconst next = executionChain\n\t\t\texecutionChain = async () => {\n\t\t\t\tlet capturedResult: NodeExecutionResult | undefined\n\t\t\t\tconst middlewareResult = await hook(nodeContext.context, this.nodeDef.id, async () => {\n\t\t\t\t\tcapturedResult = await next()\n\t\t\t\t\tif (capturedResult.status === 'success') {\n\t\t\t\t\t\treturn capturedResult.result\n\t\t\t\t\t}\n\t\t\t\t\tthrow capturedResult.error\n\t\t\t\t})\n\t\t\t\tif (!capturedResult && middlewareResult) {\n\t\t\t\t\treturn { status: 'success', result: middlewareResult }\n\t\t\t\t}\n\t\t\t\tif (!capturedResult) {\n\t\t\t\t\tthrow new Error('Middleware did not call next() and did not return a result')\n\t\t\t\t}\n\t\t\t\treturn capturedResult\n\t\t\t}\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.context.services.eventBus.emit({\n\t\t\t\ttype: 'node:start',\n\t\t\t\tpayload: {\n\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\texecutionId: this.context.executionId || '',\n\t\t\t\t\tinput: nodeContext.input,\n\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t},\n\t\t\t})\n\t\t\tconst executionResult = await executionChain()\n\t\t\tif (executionResult.status === 'success') {\n\t\t\t\tawait this.context.services.eventBus.emit({\n\t\t\t\t\ttype: 'node:finish',\n\t\t\t\t\tpayload: {\n\t\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\t\tresult: executionResult.result,\n\t\t\t\t\t\texecutionId: this.context.executionId || '',\n\t\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tawait this.context.services.eventBus.emit({\n\t\t\t\t\ttype: 'node:error',\n\t\t\t\t\tpayload: {\n\t\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\t\terror: executionResult.error,\n\t\t\t\t\t\texecutionId: this.context.executionId || '',\n\t\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn executionResult\n\t\t} catch (error: any) {\n\t\t\tconst err = error instanceof Error ? error : new Error(String(error))\n\t\t\tconst flowcraftError =\n\t\t\t\terr instanceof FlowcraftError\n\t\t\t\t\t? err\n\t\t\t\t\t: new FlowcraftError(`Node '${this.nodeDef.id}' failed execution.`, {\n\t\t\t\t\t\t\tcause: err,\n\t\t\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t\t\t\texecutionId: this.context.executionId,\n\t\t\t\t\t\t\tisFatal: false,\n\t\t\t\t\t\t})\n\t\t\tawait this.context.services.eventBus.emit({\n\t\t\t\ttype: 'node:error',\n\t\t\t\tpayload: {\n\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\terror: flowcraftError,\n\t\t\t\t\texecutionId: this.context.executionId || '',\n\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t},\n\t\t\t})\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\tthrow new FlowcraftError('Workflow cancelled', {\n\t\t\t\t\texecutionId: this.context.executionId,\n\t\t\t\t\tisFatal: false,\n\t\t\t\t})\n\t\t\t}\n\t\t\tthrow error instanceof FlowcraftError && !error.isFatal\n\t\t\t\t? error\n\t\t\t\t: new FlowcraftError(`Node '${this.nodeDef.id}' failed execution.`, {\n\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\tnodeId: this.nodeDef.id,\n\t\t\t\t\t\tblueprintId: this.context.blueprint.id,\n\t\t\t\t\t\texecutionId: this.context.executionId,\n\t\t\t\t\t\tisFatal: false,\n\t\t\t\t\t})\n\t\t}\n\t}\n}\n"]}
|
package/dist/chunk-PH2IYZHV.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// src/evaluator.ts
|
|
2
|
-
var PropertyEvaluator = class {
|
|
3
|
-
evaluate(expression, context) {
|
|
4
|
-
try {
|
|
5
|
-
if (!/^[a-zA-Z0-9_$.]+$/.test(expression)) {
|
|
6
|
-
console.error(`Error evaluating expression: "${expression}" contains invalid characters.`);
|
|
7
|
-
return void 0;
|
|
8
|
-
}
|
|
9
|
-
const parts = expression.split(".");
|
|
10
|
-
const startKey = parts[0];
|
|
11
|
-
if (!Object.hasOwn(context, startKey)) {
|
|
12
|
-
return void 0;
|
|
13
|
-
}
|
|
14
|
-
let current = context[startKey];
|
|
15
|
-
for (let i = 1; i < parts.length; i++) {
|
|
16
|
-
if (current === null || current === void 0) {
|
|
17
|
-
return void 0;
|
|
18
|
-
}
|
|
19
|
-
current = current[parts[i]];
|
|
20
|
-
}
|
|
21
|
-
return current;
|
|
22
|
-
} catch (error) {
|
|
23
|
-
console.error(`Error evaluating property expression "${expression}":`, error);
|
|
24
|
-
return void 0;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
var UnsafeEvaluator = class {
|
|
29
|
-
evaluate(expression, context) {
|
|
30
|
-
try {
|
|
31
|
-
const validIdentifierRegex = /^[a-z_$][\w$]*$/i;
|
|
32
|
-
const validKeys = Object.keys(context).filter((key) => validIdentifierRegex.test(key));
|
|
33
|
-
const validContext = {};
|
|
34
|
-
for (const key of validKeys) {
|
|
35
|
-
validContext[key] = context[key];
|
|
36
|
-
}
|
|
37
|
-
const sandbox = new Function(...validKeys, `return ${expression}`);
|
|
38
|
-
return sandbox(...validKeys.map((k) => validContext[k]));
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.error(`Error evaluating expression "${expression}":`, error);
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export { PropertyEvaluator, UnsafeEvaluator };
|
|
47
|
-
//# sourceMappingURL=chunk-PH2IYZHV.js.map
|
|
48
|
-
//# sourceMappingURL=chunk-PH2IYZHV.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/evaluator.ts"],"names":[],"mappings":";AAWO,IAAM,oBAAN,MAA8C;AAAA,EACpD,QAAA,CAAS,YAAoB,OAAA,EAAmC;AAC/D,IAAA,IAAI;AAEH,MAAA,IAAI,CAAC,mBAAA,CAAoB,IAAA,CAAK,UAAU,CAAA,EAAG;AAC1C,QAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,8BAAA,EAAiC,UAAU,CAAA,8BAAA,CAAgC,CAAA;AACzF,QAAA,OAAO,KAAA,CAAA;AAAA,MACR;AAEA,MAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,KAAA,CAAM,GAAG,CAAA;AAClC,MAAA,MAAM,QAAA,GAAW,MAAM,CAAC,CAAA;AAExB,MAAA,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A,CAAU,GAAA,CAAI,CAAC,CAAA,KAAM,YAAA,CAAa,CAAC,CAAC,CAAC,CAAA;AAAA,IACxD,SAAS,KAAA,EAAO;AACf,MAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,6BAAA,EAAgC,UAAU,CAAA,EAAA,CAAA,EAAM,KAAK,CAAA;AAEnE,MAAA,OAAO,MAAA;AAAA,IACR;AAAA,EACD;AACD","file":"chunk-PH2IYZHV.js","sourcesContent":["import type { IEvaluator } from './types'\n\n/**\n * A safe evaluator that only allows simple property access.\n * It cannot execute arbitrary code and is secure for untrusted inputs.\n *\n * Example expressions:\n * - \"result.output.status\"\n * - \"context.user.isAdmin\"\n * - \"input.value\"\n */\nexport class PropertyEvaluator implements IEvaluator {\n\tevaluate(expression: string, context: Record<string, any>): any {\n\t\ttry {\n\t\t\t// Basic validation to ensure it's a simple path\n\t\t\tif (!/^[a-zA-Z0-9_$.]+$/.test(expression)) {\n\t\t\t\tconsole.error(`Error evaluating expression: \"${expression}\" contains invalid characters.`)\n\t\t\t\treturn undefined\n\t\t\t}\n\n\t\t\tconst parts = expression.split('.')\n\t\t\tconst startKey = parts[0]\n\n\t\t\tif (!Object.hasOwn(context, startKey)) {\n\t\t\t\treturn undefined\n\t\t\t}\n\n\t\t\tlet current = context[startKey]\n\t\t\tfor (let i = 1; i < parts.length; i++) {\n\t\t\t\tif (current === null || current === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tcurrent = current[parts[i]]\n\t\t\t}\n\t\t\treturn current\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error evaluating property expression \"${expression}\":`, error)\n\t\t\treturn undefined\n\t\t}\n\t}\n}\n\n/**\n * @warning This evaluator uses `new Function()` and can execute arbitrary\n * JavaScript code. It poses a significant security risk if the expressions\n * are not from a trusted source (e.g., user input).\n *\n * It should only be used in controlled environments where all workflow\n * definitions are static and authored by trusted developers.\n *\n * For safer evaluation, use the default `PropertyEvaluator` or install a\n * sandboxed library like `jsep` to create a custom, secure evaluator.\n */\nexport class UnsafeEvaluator implements IEvaluator {\n\tevaluate(expression: string, context: Record<string, any>): any {\n\t\ttry {\n\t\t\t// filter out keys that aren't valid JavaScript identifiers\n\t\t\tconst validIdentifierRegex = /^[a-z_$][\\w$]*$/i\n\t\t\tconst validKeys = Object.keys(context).filter((key) => validIdentifierRegex.test(key))\n\t\t\tconst validContext: Record<string, any> = {}\n\t\t\tfor (const key of validKeys) {\n\t\t\t\tvalidContext[key] = context[key]\n\t\t\t}\n\n\t\t\t// sandboxed function prevents access to global scope (e.g., `window`, `process`).\n\t\t\tconst sandbox = new Function(...validKeys, `return ${expression}`)\n\t\t\treturn sandbox(...validKeys.map((k) => validContext[k]))\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error evaluating expression \"${expression}\":`, error)\n\t\t\t// default to a \"falsy\" value.\n\t\t\treturn undefined\n\t\t}\n\t}\n}\n"]}
|
package/dist/chunk-RAZWRNAJ.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { executeBatch, processResults } from './chunk-N63S5NEG.js';
|
|
2
|
-
import { FlowcraftError } from './chunk-BCRWXTWX.js';
|
|
3
|
-
|
|
4
|
-
// src/runtime/orchestrators/step-by-step.ts
|
|
5
|
-
var StepByStepOrchestrator = class {
|
|
6
|
-
async run(context, traverser) {
|
|
7
|
-
try {
|
|
8
|
-
context.signal?.throwIfAborted();
|
|
9
|
-
} catch (error) {
|
|
10
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
11
|
-
throw new FlowcraftError("Workflow cancelled", { isFatal: false });
|
|
12
|
-
}
|
|
13
|
-
throw error;
|
|
14
|
-
}
|
|
15
|
-
if (!traverser.hasMoreWork()) {
|
|
16
|
-
const isTraversalComplete2 = !traverser.hasMoreWork();
|
|
17
|
-
const status2 = context.state.getStatus(isTraversalComplete2);
|
|
18
|
-
const result2 = await context.state.toResult(context.services.serializer, context.executionId);
|
|
19
|
-
result2.status = status2;
|
|
20
|
-
return result2;
|
|
21
|
-
}
|
|
22
|
-
const allReadyNodes = traverser.getReadyNodes();
|
|
23
|
-
const nodesToExecute = context.concurrency ? allReadyNodes.slice(0, context.concurrency) : allReadyNodes;
|
|
24
|
-
const nodesToSkip = context.concurrency ? allReadyNodes.slice(context.concurrency) : [];
|
|
25
|
-
const settledResults = await executeBatch(
|
|
26
|
-
nodesToExecute,
|
|
27
|
-
traverser.getDynamicBlueprint(),
|
|
28
|
-
context.state,
|
|
29
|
-
(nodeId) => context.runtime.getExecutorForNode(nodeId, context),
|
|
30
|
-
context.runtime,
|
|
31
|
-
context.concurrency
|
|
32
|
-
);
|
|
33
|
-
await processResults(
|
|
34
|
-
settledResults,
|
|
35
|
-
traverser,
|
|
36
|
-
context.state,
|
|
37
|
-
context.runtime,
|
|
38
|
-
context.blueprint,
|
|
39
|
-
context.executionId
|
|
40
|
-
);
|
|
41
|
-
for (const { nodeId } of nodesToSkip) {
|
|
42
|
-
traverser.addToFrontier(nodeId);
|
|
43
|
-
}
|
|
44
|
-
const isTraversalComplete = !traverser.hasMoreWork();
|
|
45
|
-
const status = context.state.getStatus(isTraversalComplete);
|
|
46
|
-
const result = await context.state.toResult(context.services.serializer, context.executionId);
|
|
47
|
-
result.status = status;
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export { StepByStepOrchestrator };
|
|
53
|
-
//# sourceMappingURL=chunk-RAZWRNAJ.js.map
|
|
54
|
-
//# sourceMappingURL=chunk-RAZWRNAJ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/orchestrators/step-by-step.ts"],"names":["isTraversalComplete","status","result"],"mappings":";;;;AAeO,IAAM,yBAAN,MAAsD;AAAA,EAC5D,MAAa,GAAA,CAAI,OAAA,EAAqC,SAAA,EAAyD;AAC9G,IAAA,IAAI;AACH,MAAA,OAAA,CAAQ,QAAQ,cAAA,EAAe;AAAA,IAChC,SAAS,KAAA,EAA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A,MACA,OAAA,CAAQ,KAAA;AAAA,MACR,OAAA,CAAQ,OAAA;AAAA,MACR,OAAA,CAAQ,SAAA;AAAA,MACR,OAAA,CAAQ;AAAA,KACT;AAEA,IAAA,KAAA,MAAW,EAAE,MAAA,EAAO,IAAK,WAAA,EAAa;AACrC,MAAA,SAAA,CAAU,cAAc,MAAM,CAAA;AAAA,IAC/B;AAEA,IAAA,MAAM,mBAAA,GAAsB,CAAC,SAAA,CAAU,WAAA,EAAY;AACnD,IAAA,MAAM,MAAA,GAAS,OAAA,CAAQ,KAAA,CAAM,SAAA,CAAU,mBAAmB,CAAA;AAC1D,IAAA,MAAM,MAAA,GAAS,MAAM,OAAA,CAAQ,KAAA,CAAM,SAAS,OAAA,CAAQ,QAAA,CAAS,UAAA,EAAY,OAAA,CAAQ,WAAW,CAAA;AAC5F,IAAA,MAAA,CAAO,MAAA,GAAS,MAAA;AAChB,IAAA,OAAO,MAAA;AAAA,EACR;AACD","file":"chunk-RAZWRNAJ.js","sourcesContent":["import { FlowcraftError } from '../../errors'\n\nimport type { WorkflowResult } from '../../types'\nimport type { ExecutionContext } from '../execution-context'\nimport type { GraphTraverser } from '../traverser'\nimport type { IOrchestrator } from '../types'\nimport { executeBatch, processResults } from './utils'\n\n/**\n * An orchestrator that executes only one \"tick\" or \"turn\" of the workflow.\n * It processes a single batch of ready nodes from the frontier and then returns,\n * allowing the caller to inspect the intermediate state before proceeding.\n *\n * Useful for debugging, testing, or building interactive tools.\n */\nexport class StepByStepOrchestrator implements IOrchestrator {\n\tpublic async run(context: ExecutionContext<any, any>, traverser: GraphTraverser): Promise<WorkflowResult<any>> {\n\t\ttry {\n\t\t\tcontext.signal?.throwIfAborted()\n\t\t} catch (error) {\n\t\t\tif (error instanceof DOMException && error.name === 'AbortError') {\n\t\t\t\tthrow new FlowcraftError('Workflow cancelled', { isFatal: false })\n\t\t\t}\n\t\t\tthrow error\n\t\t}\n\n\t\tif (!traverser.hasMoreWork()) {\n\t\t\tconst isTraversalComplete = !traverser.hasMoreWork()\n\t\t\tconst status = context.state.getStatus(isTraversalComplete)\n\t\t\tconst result = await context.state.toResult(context.services.serializer, context.executionId)\n\t\t\tresult.status = status\n\t\t\treturn result\n\t\t}\n\n\t\tconst allReadyNodes = traverser.getReadyNodes()\n\t\tconst nodesToExecute = context.concurrency ? allReadyNodes.slice(0, context.concurrency) : allReadyNodes\n\t\tconst nodesToSkip = context.concurrency ? allReadyNodes.slice(context.concurrency) : []\n\n\t\tconst settledResults = await executeBatch(\n\t\t\tnodesToExecute,\n\t\t\ttraverser.getDynamicBlueprint(),\n\t\t\tcontext.state,\n\t\t\t(nodeId: string) => context.runtime.getExecutorForNode(nodeId, context),\n\t\t\tcontext.runtime,\n\t\t\tcontext.concurrency,\n\t\t)\n\n\t\tawait processResults(\n\t\t\tsettledResults,\n\t\t\ttraverser,\n\t\t\tcontext.state,\n\t\t\tcontext.runtime,\n\t\t\tcontext.blueprint,\n\t\t\tcontext.executionId,\n\t\t)\n\n\t\tfor (const { nodeId } of nodesToSkip) {\n\t\t\ttraverser.addToFrontier(nodeId)\n\t\t}\n\n\t\tconst isTraversalComplete = !traverser.hasMoreWork()\n\t\tconst status = context.state.getStatus(isTraversalComplete)\n\t\tconst result = await context.state.toResult(context.services.serializer, context.executionId)\n\t\tresult.status = status\n\t\treturn result\n\t}\n}\n"]}
|
package/dist/chunk-RM677CNU.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { BaseNode } from './chunk-LNK7LZER.js';
|
|
2
|
-
|
|
3
|
-
// src/nodes/batch-scatter.ts
|
|
4
|
-
var BatchScatterNode = class extends BaseNode {
|
|
5
|
-
async exec(_prepResult, context) {
|
|
6
|
-
const inputArray = context.input || [];
|
|
7
|
-
if (!Array.isArray(inputArray)) {
|
|
8
|
-
throw new Error(`Input for batch-scatter node '${this.nodeId}' must be an array.`);
|
|
9
|
-
}
|
|
10
|
-
const { chunkSize = inputArray.length, workerUsesKey, gatherNodeId } = this.params || {};
|
|
11
|
-
if (!workerUsesKey || !gatherNodeId) {
|
|
12
|
-
throw new Error(`BatchScatterNode requires 'workerUsesKey' and 'gatherNodeId' parameters.`);
|
|
13
|
-
}
|
|
14
|
-
const batchId = globalThis.crypto.randomUUID();
|
|
15
|
-
const currentIndex = await context.context.get(`${this.nodeId}_currentIndex`) || 0;
|
|
16
|
-
const endIndex = Math.min(currentIndex + chunkSize, inputArray.length);
|
|
17
|
-
const dynamicNodes = [];
|
|
18
|
-
const workerIds = [];
|
|
19
|
-
for (let i = currentIndex; i < endIndex; i++) {
|
|
20
|
-
const item = inputArray[i];
|
|
21
|
-
const itemInputKey = `_batch.${this.nodeId}_${batchId}_item_${i}`;
|
|
22
|
-
await context.context.set(itemInputKey, item);
|
|
23
|
-
const workerId = `${workerUsesKey}_${batchId}_${i}`;
|
|
24
|
-
workerIds.push(workerId);
|
|
25
|
-
dynamicNodes.push({
|
|
26
|
-
id: workerId,
|
|
27
|
-
uses: workerUsesKey,
|
|
28
|
-
inputs: itemInputKey
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
const parentBatchId = this.nodeId?.replace("_scatter", "") || "";
|
|
32
|
-
await context.dependencies.runtime.services.eventBus.emit({
|
|
33
|
-
type: "batch:start",
|
|
34
|
-
payload: {
|
|
35
|
-
batchId: parentBatchId,
|
|
36
|
-
scatterNodeId: this.nodeId,
|
|
37
|
-
workerNodeIds: workerIds
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
await context.context.set(`${this.nodeId}_currentIndex`, endIndex);
|
|
41
|
-
const hasMore = endIndex < inputArray.length;
|
|
42
|
-
await context.context.set(`${gatherNodeId}_hasMore`, hasMore);
|
|
43
|
-
const existingWorkerIds = await context.context.get(`${gatherNodeId}_allWorkerIds`) || [];
|
|
44
|
-
const allWorkerIds = [...existingWorkerIds, ...workerIds];
|
|
45
|
-
await context.context.set(`${gatherNodeId}_allWorkerIds`, allWorkerIds);
|
|
46
|
-
return { dynamicNodes, output: { gatherNodeId, hasMore } };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export { BatchScatterNode };
|
|
51
|
-
//# sourceMappingURL=chunk-RM677CNU.js.map
|
|
52
|
-
//# sourceMappingURL=chunk-RM677CNU.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nodes/batch-scatter.ts"],"names":[],"mappings":";;;AAGO,IAAM,gBAAA,GAAN,cAA+B,QAAA,CAAS;AAAA,EAC9C,MAAM,IAAA,CAAK,WAAA,EAAkB,OAAA,EAAyE;AACrG,IAAA,MAAM,UAAA,GAAa,OAAA,CAAQ,KAAA,IAAS,EAAC;AACrC,IAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,UAAU,CAAA,EAAG;AAC/B,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,8BAAA,EAAiC,IAAA,CAAK,MAAM,CAAA,mBAAA,CAAqB,CAAA;AAAA,IAClF;AACA,IAAA,MAAM,EAAE,YAAY,UAAA,CAAW,MAAA,EAAQ,eAAe,YAAA,EAAa,GAAK,IAAA,CAAK,MAAA,IAAkB,EAAC;AAChG,IAAA,IAAI,CAAC,aAAA,IAAiB,CAAC,YAAA,EAAc;AACpC,MAAA,MAAM,IAAI,MAAM,CAAA,wEAAA,CAA0E,CAAA;AAAA,IAC3F;AACA,IAAA,MAAM,OAAA,GAAU,UAAA,CAAW,MAAA,CAAO,UAAA,EAAW;AAC7C,IAAA,MAAM,YAAA,GAAgB,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAI,CAAA,EAAG,IAAA,CAAK,MAAM,CAAA,aAAA,CAAe,CAAA,IAAM,CAAA;AACnF,IAAA,MAAM,WAAW,IAAA,CAAK,GAAA,CAAI,YAAA,GAAe,SAAA,EAAW,WAAW,MAAM,CAAA;AACrE,IAAA,MAAM,eAAsB,EAAC;AAC7B,IAAA,MAAM,YAAY,EAAC;AACnB,IAAA,KAAA,IAAS,CAAA,GAAI,YAAA,EA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A,EAAG,YAAY,CAAA,aAAA,CAAe,CAAA,IAAM,EAAC;AAC1F,IAAA,MAAM,YAAA,GAAe,CAAC,GAAG,iBAAA,EAAmB,GAAG,SAAS,CAAA;AACxD,IAAA,MAAM,QAAQ,OAAA,CAAQ,GAAA,CAAI,CAAA,EAAG,YAAY,iBAAiB,YAAY,CAAA;AACtE,IAAA,OAAO,EAAE,YAAA,EAAc,MAAA,EAAQ,EAAE,YAAA,EAAc,SAAQ,EAAE;AAAA,EAC1D;AACD","file":"chunk-RM677CNU.js","sourcesContent":["import { BaseNode } from '../node'\nimport type { NodeContext, NodeResult } from '../types'\n\nexport class BatchScatterNode extends BaseNode {\n\tasync exec(_prepResult: any, context: NodeContext<any, any, any>): Promise<Omit<NodeResult, 'error'>> {\n\t\tconst inputArray = context.input || []\n\t\tif (!Array.isArray(inputArray)) {\n\t\t\tthrow new Error(`Input for batch-scatter node '${this.nodeId}' must be an array.`)\n\t\t}\n\t\tconst { chunkSize = inputArray.length, workerUsesKey, gatherNodeId } = (this.params as any) || {}\n\t\tif (!workerUsesKey || !gatherNodeId) {\n\t\t\tthrow new Error(`BatchScatterNode requires 'workerUsesKey' and 'gatherNodeId' parameters.`)\n\t\t}\n\t\tconst batchId = globalThis.crypto.randomUUID()\n\t\tconst currentIndex = (await context.context.get(`${this.nodeId}_currentIndex`)) || 0\n\t\tconst endIndex = Math.min(currentIndex + chunkSize, inputArray.length)\n\t\tconst dynamicNodes: any[] = []\n\t\tconst workerIds = []\n\t\tfor (let i = currentIndex; i < endIndex; i++) {\n\t\t\tconst item = inputArray[i]\n\t\t\tconst itemInputKey = `_batch.${this.nodeId}_${batchId}_item_${i}`\n\t\t\tawait context.context.set(itemInputKey as any, item)\n\t\t\tconst workerId = `${workerUsesKey}_${batchId}_${i}`\n\t\t\tworkerIds.push(workerId)\n\t\t\tdynamicNodes.push({\n\t\t\t\tid: workerId,\n\t\t\t\tuses: workerUsesKey,\n\t\t\t\tinputs: itemInputKey,\n\t\t\t})\n\t\t}\n\n\t\tconst parentBatchId = this.nodeId?.replace('_scatter', '') || ''\n\t\tawait context.dependencies.runtime.services.eventBus.emit({\n\t\t\ttype: 'batch:start',\n\t\t\tpayload: {\n\t\t\t\tbatchId: parentBatchId,\n\t\t\t\tscatterNodeId: this.nodeId,\n\t\t\t\tworkerNodeIds: workerIds,\n\t\t\t},\n\t\t})\n\n\t\tawait context.context.set(`${this.nodeId}_currentIndex`, endIndex)\n\t\tconst hasMore = endIndex < inputArray.length\n\t\tawait context.context.set(`${gatherNodeId}_hasMore`, hasMore)\n\t\tconst existingWorkerIds = (await context.context.get(`${gatherNodeId}_allWorkerIds`)) || []\n\t\tconst allWorkerIds = [...existingWorkerIds, ...workerIds]\n\t\tawait context.context.set(`${gatherNodeId}_allWorkerIds`, allWorkerIds)\n\t\treturn { dynamicNodes, output: { gatherNodeId, hasMore } }\n\t}\n}\n"]}
|
package/dist/chunk-TKSSRS5U.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// src/sanitizer.ts
|
|
2
|
-
function sanitizeBlueprint(raw) {
|
|
3
|
-
let nodesArray = [];
|
|
4
|
-
if (Array.isArray(raw.nodes)) {
|
|
5
|
-
nodesArray = raw.nodes;
|
|
6
|
-
} else if (typeof raw.nodes === "object" && raw.nodes !== null) {
|
|
7
|
-
nodesArray = Object.values(raw.nodes);
|
|
8
|
-
}
|
|
9
|
-
const nodes = nodesArray.map((node) => ({
|
|
10
|
-
id: node.id,
|
|
11
|
-
uses: node.uses,
|
|
12
|
-
params: node.params,
|
|
13
|
-
inputs: node.inputs,
|
|
14
|
-
config: node.config
|
|
15
|
-
}));
|
|
16
|
-
let edgesArray = [];
|
|
17
|
-
if (Array.isArray(raw.edges)) {
|
|
18
|
-
edgesArray = raw.edges;
|
|
19
|
-
} else if (typeof raw.edges === "object" && raw.edges !== null) {
|
|
20
|
-
edgesArray = Object.values(raw.edges);
|
|
21
|
-
}
|
|
22
|
-
const edges = edgesArray.map((edge) => ({
|
|
23
|
-
source: edge.source,
|
|
24
|
-
target: edge.target,
|
|
25
|
-
action: edge.action,
|
|
26
|
-
condition: edge.condition,
|
|
27
|
-
transform: edge.transform
|
|
28
|
-
}));
|
|
29
|
-
return {
|
|
30
|
-
id: raw.id,
|
|
31
|
-
nodes,
|
|
32
|
-
edges,
|
|
33
|
-
metadata: raw.metadata
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { sanitizeBlueprint };
|
|
38
|
-
//# sourceMappingURL=chunk-TKSSRS5U.js.map
|
|
39
|
-
//# sourceMappingURL=chunk-TKSSRS5U.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sanitizer.ts"],"names":[],"mappings":";AAOO,SAAS,kBAAkB,GAAA,EAA6B;AAC9D,EAAA,IAAI,aAAoB,EAAC;AACzB,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,GAAA,CAAI,KAAK,CAAA,EAAG;AAC7B,IAAA,UAAA,GAAa,GAAA,CAAI,KAAA;AAAA,EAClB,WAAW,OAAO,GAAA,CAAI,UAAU,QAAA,IAAY,GAAA,CAAI,UAAU,IAAA,EAAM;AAC/D,IAAA,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,GAAA,CAAI,KAAK,CAAA;AAAA,EACrC;AAEA,EAAA,MAAM,KAAA,GAA0B,UAAA,CAAW,GAAA,CAAI,CAAC,IAAA,MAAe;AAAA,IAC9D,IAAI,IAAA,CAAK,EAAA;AAAA,IACT,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,QAAQ,IAAA,CAAK,MAAA;AAAA,IACb,QAAQ,IAAA,CAAK,MAAA;AAAA,IACb,QAAQ,IAAA,CAAK;AAAA,GACd,CAAE,CAAA;AAEF,EAAA,IAAI,aAAoB,EAAC;AACzB,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,GAAA,CAAI,KAAK,CAAA,EAAG;AAC7B,IAAA,UAAA,GAAa,GAAA,CAAI,KAAA;AAAA,EAClB,WAAW,OAAO,GAAA,CAAI,UAAU,QAAA,IAAY,GAAA,CAAI,UAAU,IAAA,EAAM;AAC/D,IAAA,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,GAAA,CAAI,KAAK,CAAA;AAAA,EACrC;AAEA,EAAA,MAAM,KAAA,GAA0B,UAAA,CAAW,GAAA,CAAI,CAAC,IAAA,MAAe;AAAA,IAC9D,QAAQ,IAAA,CAAK,MAAA;AAAA,IACb,QAAQ,IAAA,CAAK,MAAA;AAAA,IACb,QAAQ,IAAA,CAAK,MAAA;AAAA,IACb,WAAW,IAAA,CAAK,SAAA;AAAA,IAChB,WAAW,IAAA,CAAK;AAAA,GACjB,CAAE,CAAA;AAEF,EAAA,OAAO;AAAA,IACN,IAAI,GAAA,CAAI,EAAA;AAAA,IACR,KAAA;AAAA,IACA,KAAA;AAAA,IACA,UAAU,GAAA,CAAI;AAAA,GACf;AACD","file":"chunk-TKSSRS5U.js","sourcesContent":["import type { EdgeDefinition, NodeDefinition, WorkflowBlueprint } from './types'\n\n/**\n * Sanitizes a raw workflow blueprint by removing extra properties\n * added by UI tools (e.g., position, style) and keeping only the\n * properties defined in NodeDefinition and EdgeDefinition.\n */\nexport function sanitizeBlueprint(raw: any): WorkflowBlueprint {\n\tlet nodesArray: any[] = []\n\tif (Array.isArray(raw.nodes)) {\n\t\tnodesArray = raw.nodes\n\t} else if (typeof raw.nodes === 'object' && raw.nodes !== null) {\n\t\tnodesArray = Object.values(raw.nodes)\n\t}\n\n\tconst nodes: NodeDefinition[] = nodesArray.map((node: any) => ({\n\t\tid: node.id,\n\t\tuses: node.uses,\n\t\tparams: node.params,\n\t\tinputs: node.inputs,\n\t\tconfig: node.config,\n\t}))\n\n\tlet edgesArray: any[] = []\n\tif (Array.isArray(raw.edges)) {\n\t\tedgesArray = raw.edges\n\t} else if (typeof raw.edges === 'object' && raw.edges !== null) {\n\t\tedgesArray = Object.values(raw.edges)\n\t}\n\n\tconst edges: EdgeDefinition[] = edgesArray.map((edge: any) => ({\n\t\tsource: edge.source,\n\t\ttarget: edge.target,\n\t\taction: edge.action,\n\t\tcondition: edge.condition,\n\t\ttransform: edge.transform,\n\t}))\n\n\treturn {\n\t\tid: raw.id,\n\t\tnodes,\n\t\tedges,\n\t\tmetadata: raw.metadata,\n\t}\n}\n"]}
|