flowcraft 2.2.0 → 2.3.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 +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-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-BN4MV36K.js +25 -0
- package/dist/chunk-BN4MV36K.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-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-HKX7WQLS.js +446 -0
- package/dist/chunk-HKX7WQLS.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-MKNZBKSR.js +90 -0
- package/dist/chunk-MKNZBKSR.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/{chunk-QLGJUDQF.js → chunk-ZNL7ZXPR.js} +26 -11
- package/dist/chunk-ZNL7ZXPR.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
|
@@ -0,0 +1,300 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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OAAA,EAAS;AAAA,UACR,MAAA,EAAQ,KAAK,OAAA,CAAQ,EAAA;AAAA,UACrB,KAAA,EAAO,cAAA;AAAA,UACP,WAAA,EAAa,IAAA,CAAK,OAAA,CAAQ,WAAA,IAAe,EAAA;AAAA,UACzC,WAAA,EAAa,IAAA,CAAK,OAAA,CAAQ,SAAA,CAAU;AAAA;AACrC,OACA,CAAA;AACD,MAAA,IAAI,KAAA,YAAiB,YAAA,IAAgB,KAAA,CAAM,IAAA,KAAS,YAAA,EAAc;AACjE,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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DefaultOrchestrator } from './chunk-33NO4PUJ.js';
|
|
2
|
+
import { NullLogger } from './chunk-4PELJWF7.js';
|
|
3
|
+
import { JsonSerializer } from './chunk-CYHZ2YVH.js';
|
|
4
|
+
import { DIContainer, ServiceTokens } from './chunk-WWGFIYKW.js';
|
|
5
|
+
import { PropertyEvaluator } from './chunk-PH2IYZHV.js';
|
|
6
|
+
|
|
7
|
+
// src/container-factory.ts
|
|
8
|
+
function createDefaultContainer(options = {}) {
|
|
9
|
+
const container = new DIContainer();
|
|
10
|
+
container.register(ServiceTokens.Logger, options.logger || new NullLogger());
|
|
11
|
+
container.register(ServiceTokens.Serializer, options.serializer || new JsonSerializer());
|
|
12
|
+
container.register(ServiceTokens.Evaluator, options.evaluator || new PropertyEvaluator());
|
|
13
|
+
container.register(ServiceTokens.EventBus, options.eventBus || { emit: async () => {
|
|
14
|
+
} });
|
|
15
|
+
container.register(ServiceTokens.Middleware, options.middleware || []);
|
|
16
|
+
container.register(ServiceTokens.NodeRegistry, options.registry || {});
|
|
17
|
+
container.register(ServiceTokens.BlueprintRegistry, options.blueprints || {});
|
|
18
|
+
container.register(ServiceTokens.Dependencies, options.dependencies || {});
|
|
19
|
+
container.registerFactory(ServiceTokens.Orchestrator, () => new DefaultOrchestrator());
|
|
20
|
+
return container;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { createDefaultContainer };
|
|
24
|
+
//# sourceMappingURL=chunk-QNYXQKFW.js.map
|
|
25
|
+
//# sourceMappingURL=chunk-QNYXQKFW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/container-factory.ts"],"names":[],"mappings":";;;;;;;AA4BO,SAAS,sBAAA,CACf,OAAA,GAA2C,EAAC,EAC9B;AACd,EAAA,MAAM,SAAA,GAAY,IAAI,WAAA,EAAY;AAElC,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,MAAA,EAAQ,QAAQ,MAAA,IAAU,IAAI,YAAY,CAAA;AAC3E,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,UAAA,EAAY,QAAQ,UAAA,IAAc,IAAI,gBAAgB,CAAA;AACvF,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,SAAA,EAAW,QAAQ,SAAA,IAAa,IAAI,mBAAmB,CAAA;AACxF,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,QAAA,EAAU,QAAQ,QAAA,IAAY,EAAE,MAAM,YAAY;AAAA,EAAC,GAAG,CAAA;AACvF,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,UAAA,EAAY,OAAA,CAAQ,UAAA,IAAc,EAAE,CAAA;AACrE,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,YAAA,EAAc,OAAA,CAAQ,QAAA,IAAY,EAAE,CAAA;AACrE,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,iBAAA,EAAmB,OAAA,CAAQ,UAAA,IAAc,EAAE,CAAA;AAC5E,EAAA,SAAA,CAAU,SAAS,aAAA,CAAc,YAAA,EAAc,OAAA,CAAQ,YAAA,IAAiB,EAAoB,CAAA;AAE5F,EAAA,SAAA,CAAU,gBAAgB,aAAA,CAAc,YAAA,EAAc,MAAM,IAAI,qBAAqB,CAAA;AAErF,EAAA,OAAO,SAAA;AACR","file":"chunk-QNYXQKFW.js","sourcesContent":["import { DIContainer, ServiceTokens } from './container'\nimport { PropertyEvaluator } from './evaluator'\nimport { NullLogger } from './logger'\nimport { DefaultOrchestrator } from './runtime/orchestrator'\nimport { JsonSerializer } from './serializer'\nimport type {\n\tIEvaluator,\n\tIEventBus,\n\tILogger,\n\tISerializer,\n\tMiddleware,\n\tNodeClass,\n\tNodeFunction,\n\tRuntimeDependencies,\n\tWorkflowBlueprint,\n} from './types'\n\nexport interface ContainerOptions<TDependencies extends RuntimeDependencies = RuntimeDependencies> {\n\tlogger?: ILogger\n\tserializer?: ISerializer\n\tevaluator?: IEvaluator\n\teventBus?: IEventBus\n\tmiddleware?: Middleware[]\n\tregistry?: Record<string, NodeFunction | NodeClass>\n\tblueprints?: Record<string, WorkflowBlueprint>\n\tdependencies?: TDependencies\n}\n\nexport function createDefaultContainer<TDependencies extends RuntimeDependencies = RuntimeDependencies>(\n\toptions: ContainerOptions<TDependencies> = {},\n): DIContainer {\n\tconst container = new DIContainer()\n\n\tcontainer.register(ServiceTokens.Logger, options.logger || new NullLogger())\n\tcontainer.register(ServiceTokens.Serializer, options.serializer || new JsonSerializer())\n\tcontainer.register(ServiceTokens.Evaluator, options.evaluator || new PropertyEvaluator())\n\tcontainer.register(ServiceTokens.EventBus, options.eventBus || { emit: async () => {} })\n\tcontainer.register(ServiceTokens.Middleware, options.middleware || [])\n\tcontainer.register(ServiceTokens.NodeRegistry, options.registry || {})\n\tcontainer.register(ServiceTokens.BlueprintRegistry, options.blueprints || {})\n\tcontainer.register(ServiceTokens.Dependencies, options.dependencies || ({} as TDependencies))\n\n\tcontainer.registerFactory(ServiceTokens.Orchestrator, () => new DefaultOrchestrator())\n\n\treturn container\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAA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AAI,QAAA;AAAA,QACJ,IAAA,EAAM,aAAA;AAAA,QACN,MAAA,EAAQ;AAAA,OACR,CAAA;AAAA,IACF;AAEA,IAAA,MAAM,gBAAgB,IAAA,CAAK,MAAA,EAAQ,OAAA,CAAQ,UAAA,EAAY,EAAE,CAAA,IAAK,EAAA;AAC9D,IAAA,MAAM,OAAA,CAAQ,YAAA,CAAa,OAAA,CAAQ,QAAA,CAAS,SAAS,IAAA,CAAK;AAAA,MACzD,IAAA,EAAM,aAAA;AAAA,MACN,OAAA,EAAS;AAAA,QACR,OAAA,EAAS,aAAA;AAAA,QACT,eAAe,IAAA,CAAK,MAAA;AAAA,QACpB,aAAA,EAAe;AAAA;AAChB,KACA,CAAA;AAED,IAAA,MAAM,QAAQ,OAAA,CAAQ,GAAA,CAAI,GAAG,IAAA,CAAK,MAAM,iBAAiB,QAAQ,CAAA;AACjE,IAAA,MAAM,OAAA,GAAU,WAAW,UAAA,CAAW,MAAA;AACtC,IAAA,MAAM,QAAQ,OAAA,CAAQ,GAAA,CAAI,CAAA,EAAG,YAAY,YAAY,OAAO,CAAA;AAC5D,IAAA,MAAM,iBAAA,GAAqB,MAAM,OAAA,CAAQ,OAAA,CAAQ,IAAI,CAAA,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"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/container.ts
|
|
2
|
+
var DIContainer = class _DIContainer {
|
|
3
|
+
services = /* @__PURE__ */ new Map();
|
|
4
|
+
factories = /* @__PURE__ */ new Map();
|
|
5
|
+
register(token, implementation) {
|
|
6
|
+
this.services.set(token, implementation);
|
|
7
|
+
}
|
|
8
|
+
registerFactory(token, factory) {
|
|
9
|
+
this.factories.set(token, factory);
|
|
10
|
+
}
|
|
11
|
+
resolve(token) {
|
|
12
|
+
if (this.services.has(token)) {
|
|
13
|
+
return this.services.get(token);
|
|
14
|
+
}
|
|
15
|
+
if (this.factories.has(token)) {
|
|
16
|
+
const factory = this.factories.get(token);
|
|
17
|
+
const instance = factory?.(this);
|
|
18
|
+
this.services.set(token, instance);
|
|
19
|
+
return instance;
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Service not found for token: ${String(token)}`);
|
|
22
|
+
}
|
|
23
|
+
has(token) {
|
|
24
|
+
return this.services.has(token) || this.factories.has(token);
|
|
25
|
+
}
|
|
26
|
+
createChild() {
|
|
27
|
+
const child = new _DIContainer();
|
|
28
|
+
child.services = new Map(this.services);
|
|
29
|
+
child.factories = new Map(this.factories);
|
|
30
|
+
return child;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var ServiceTokens = {
|
|
34
|
+
Logger: Symbol.for("flowcraft:logger"),
|
|
35
|
+
Serializer: Symbol.for("flowcraft:serializer"),
|
|
36
|
+
Evaluator: Symbol.for("flowcraft:evaluator"),
|
|
37
|
+
EventBus: Symbol.for("flowcraft:eventBus"),
|
|
38
|
+
Orchestrator: Symbol.for("flowcraft:orchestrator"),
|
|
39
|
+
Middleware: Symbol.for("flowcraft:middleware"),
|
|
40
|
+
NodeRegistry: Symbol.for("flowcraft:nodeRegistry"),
|
|
41
|
+
BlueprintRegistry: Symbol.for("flowcraft:blueprintRegistry"),
|
|
42
|
+
Dependencies: Symbol.for("flowcraft:dependencies")
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { DIContainer, ServiceTokens };
|
|
46
|
+
//# sourceMappingURL=chunk-WWGFIYKW.js.map
|
|
47
|
+
//# sourceMappingURL=chunk-WWGFIYKW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/container.ts"],"names":[],"mappings":";AAEO,IAAM,WAAA,GAAN,MAAM,YAAA,CAAY;AAAA,EAChB,QAAA,uBAAuC,GAAA,EAAI;AAAA,EAC3C,SAAA,uBAAoE,GAAA,EAAI;AAAA,EAEhF,QAAA,CAAY,OAAwB,cAAA,EAAyB;AAC5D,IAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,KAAA,EAAO,cAAc,CAAA;AAAA,EACxC;AAAA,EAEA,eAAA,CAAmB,OAAwB,OAAA,EAA8C;AACxF,IAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAA,EAAO,OAAO,CAAA;AAAA,EAClC;AAAA,EAEA,QAAW,KAAA,EAA2B;AACrC,IAAA,IAAI,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,KAAK,CAAA,EAAG;AAC7B,MAAA,OAAO,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,KAAK,CAAA;AAAA,IAC/B;AAEA,IAAA,IAAI,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA,EAAG;AAC9B,MAAA,MAAM,OAAA,GAAU,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AACxC,MAAA,MAAM,QAAA,GAAW,UAAU,IAAI,CAAA;AAC/B,MAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,KAAA,EAAO,QAAQ,CAAA;AACjC,MAAA,OAAO,QAAA;AAAA,IACR;AAEA,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,6BAAA,EAAgC,MAAA,CAAO,KAAK,CAAC,CAAA,CAAE,CAAA;AAAA,EAChE;AAAA,EAEA,IAAI,KAAA,EAA8B;AACjC,IAAA,OAAO,IAAA,CAAK,SAAS,GAAA,CAAI,KAAK,KAAK,IAAA,CAAK,SAAA,CAAU,IAAI,KAAK,CAAA;AAAA,EAC5D;AAAA,EAEA,WAAA,GAA2B;AAC1B,IAAA,MAAM,KAAA,GAAQ,IAAI,YAAA,EAAY;AAC9B,IAAA,KAAA,CAAM,QAAA,GAAW,IAAI,GAAA,CAAI,IAAA,CAAK,QAAQ,CAAA;AACtC,IAAA,KAAA,CAAM,SAAA,GAAY,IAAI,GAAA,CAAI,IAAA,CAAK,SAAS,CAAA;AACxC,IAAA,OAAO,KAAA;AAAA,EACR;AACD;AAEO,IAAM,aAAA,GAAgB;AAAA,EAC5B,MAAA,EAAQ,MAAA,CAAO,GAAA,CAAI,kBAAkB,CAAA;AAAA,EACrC,UAAA,EAAY,MAAA,CAAO,GAAA,CAAI,sBAAsB,CAAA;AAAA,EAC7C,SAAA,EAAW,MAAA,CAAO,GAAA,CAAI,qBAAqB,CAAA;AAAA,EAC3C,QAAA,EAAU,MAAA,CAAO,GAAA,CAAI,oBAAoB,CAAA;AAAA,EACzC,YAAA,EAAc,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAAA,EACjD,UAAA,EAAY,MAAA,CAAO,GAAA,CAAI,sBAAsB,CAAA;AAAA,EAC7C,YAAA,EAAc,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAAA,EACjD,iBAAA,EAAmB,MAAA,CAAO,GAAA,CAAI,6BAA6B,CAAA;AAAA,EAC3D,YAAA,EAAc,MAAA,CAAO,GAAA,CAAI,wBAAwB;AAClD","file":"chunk-WWGFIYKW.js","sourcesContent":["export type ServiceToken<_T = any> = string | symbol\n\nexport class DIContainer {\n\tprivate services: Map<ServiceToken, any> = new Map()\n\tprivate factories: Map<ServiceToken, (container: DIContainer) => any> = new Map()\n\n\tregister<T>(token: ServiceToken<T>, implementation: T): void {\n\t\tthis.services.set(token, implementation)\n\t}\n\n\tregisterFactory<T>(token: ServiceToken<T>, factory: (container: DIContainer) => T): void {\n\t\tthis.factories.set(token, factory)\n\t}\n\n\tresolve<T>(token: ServiceToken<T>): T {\n\t\tif (this.services.has(token)) {\n\t\t\treturn this.services.get(token)\n\t\t}\n\n\t\tif (this.factories.has(token)) {\n\t\t\tconst factory = this.factories.get(token)\n\t\t\tconst instance = factory?.(this)\n\t\t\tthis.services.set(token, instance)\n\t\t\treturn instance\n\t\t}\n\n\t\tthrow new Error(`Service not found for token: ${String(token)}`)\n\t}\n\n\thas(token: ServiceToken): boolean {\n\t\treturn this.services.has(token) || this.factories.has(token)\n\t}\n\n\tcreateChild(): DIContainer {\n\t\tconst child = new DIContainer()\n\t\tchild.services = new Map(this.services)\n\t\tchild.factories = new Map(this.factories)\n\t\treturn child\n\t}\n}\n\nexport const ServiceTokens = {\n\tLogger: Symbol.for('flowcraft:logger'),\n\tSerializer: Symbol.for('flowcraft:serializer'),\n\tEvaluator: Symbol.for('flowcraft:evaluator'),\n\tEventBus: Symbol.for('flowcraft:eventBus'),\n\tOrchestrator: Symbol.for('flowcraft:orchestrator'),\n\tMiddleware: Symbol.for('flowcraft:middleware'),\n\tNodeRegistry: Symbol.for('flowcraft:nodeRegistry'),\n\tBlueprintRegistry: Symbol.for('flowcraft:blueprintRegistry'),\n\tDependencies: Symbol.for('flowcraft:dependencies'),\n} as const\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { StepByStepOrchestrator } from './chunk-G53CSLBF.js';
|
|
2
|
+
import { GraphTraverser } from './chunk-G5BGBPFP.js';
|
|
3
|
+
import { ExecutionContext } from './chunk-FRKO3WX4.js';
|
|
4
|
+
import { WorkflowState } from './chunk-CD4FUZOJ.js';
|
|
5
|
+
|
|
6
|
+
// src/testing/stepper.ts
|
|
7
|
+
async function createStepper(runtime, blueprint, functionRegistry, initialState = {}) {
|
|
8
|
+
const _initialBlueprint = structuredClone(blueprint);
|
|
9
|
+
const _initialState = structuredClone(initialState);
|
|
10
|
+
let state;
|
|
11
|
+
let traverser;
|
|
12
|
+
const history = [];
|
|
13
|
+
const orchestrator = new StepByStepOrchestrator();
|
|
14
|
+
const executionId = globalThis.crypto?.randomUUID();
|
|
15
|
+
const nodeRegistry = new Map([...runtime.registry, ...functionRegistry]);
|
|
16
|
+
const initialize = () => {
|
|
17
|
+
state = new WorkflowState(_initialState);
|
|
18
|
+
traverser = new GraphTraverser(_initialBlueprint);
|
|
19
|
+
history.length = 0;
|
|
20
|
+
};
|
|
21
|
+
initialize();
|
|
22
|
+
const stepper = {
|
|
23
|
+
get state() {
|
|
24
|
+
return state;
|
|
25
|
+
},
|
|
26
|
+
get traverser() {
|
|
27
|
+
return traverser;
|
|
28
|
+
},
|
|
29
|
+
isDone() {
|
|
30
|
+
return !traverser.hasMoreWork() && !state.isAwaiting();
|
|
31
|
+
},
|
|
32
|
+
reset() {
|
|
33
|
+
initialize();
|
|
34
|
+
},
|
|
35
|
+
async prev() {
|
|
36
|
+
const previousStateJson = history.pop();
|
|
37
|
+
if (!previousStateJson) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const previousStateData = runtime.serializer.deserialize(previousStateJson);
|
|
41
|
+
state = new WorkflowState(previousStateData);
|
|
42
|
+
traverser = GraphTraverser.fromState(_initialBlueprint, state);
|
|
43
|
+
return state.toResult(runtime.serializer);
|
|
44
|
+
},
|
|
45
|
+
async next(options = {}) {
|
|
46
|
+
if (stepper.isDone()) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const serializedContext = (await state.toResult(runtime.serializer)).serializedContext;
|
|
50
|
+
history.push(serializedContext);
|
|
51
|
+
const executionContext = new ExecutionContext(
|
|
52
|
+
_initialBlueprint,
|
|
53
|
+
state,
|
|
54
|
+
nodeRegistry,
|
|
55
|
+
executionId,
|
|
56
|
+
runtime,
|
|
57
|
+
{
|
|
58
|
+
logger: runtime.logger,
|
|
59
|
+
eventBus: runtime.eventBus,
|
|
60
|
+
serializer: runtime.serializer,
|
|
61
|
+
evaluator: runtime.evaluator,
|
|
62
|
+
middleware: runtime.middleware,
|
|
63
|
+
dependencies: runtime.dependencies
|
|
64
|
+
},
|
|
65
|
+
options.signal,
|
|
66
|
+
options.concurrency
|
|
67
|
+
);
|
|
68
|
+
return orchestrator.run(executionContext, traverser);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return stepper;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { createStepper };
|
|
75
|
+
//# sourceMappingURL=chunk-XNRIM27H.js.map
|
|
76
|
+
//# sourceMappingURL=chunk-XNRIM27H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing/stepper.ts"],"names":[],"mappings":";;;;;;AAkFA,eAAsB,cACrB,OAAA,EACA,SAAA,EACA,gBAAA,EACA,YAAA,GAAkC,EAAC,EACG;AACtC,EAAA,MAAM,iBAAA,GAAoB,gBAAgB,SAAS,CAAA;AACnD,EAAA,MAAM,aAAA,GAAgB,gBAAgB,YAAY,CAAA;AAElD,EAAA,IAAI,KAAA;AACJ,EAAA,IAAI,SAAA;AACJ,EAAA,MAAM,UAAoB,EAAC;AAE3B,EAAA,MAAM,YAAA,GAAe,IAAI,sBAAA,EAAuB;AAChD,EAAA,MAAM,WAAA,GAAc,UAAA,CAAW,MAAA,EAAQ,UAAA,EAAW;AAClD,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,CAAC,GAAG,OAAA,CAAQ,QAAA,EAAU,GAAG,gBAAgB,CAAC,CAAA;AAEvE,EAAA,MAAM,aAAa,MAAM;AACxB,IAAA,KAAA,GAAQ,IAAI,cAAwB,aAAa,CAAA;AACjD,IAAA,SAAA,GAAY,IAAI,eAAe,iBAAiB,CAAA;AAChD,IAAA,OAAA,CAAQ,MAAA,GAAS,CAAA;AAAA,EAClB,CAAA;AAEA,EAAA,UAAA,EAAW;AAEX,EA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AAA,CAAQ,MAAA;AAAA,UAChB,UAAU,OAAA,CAAQ,QAAA;AAAA,UAClB,YAAY,OAAA,CAAQ,UAAA;AAAA,UACpB,WAAW,OAAA,CAAQ,SAAA;AAAA,UACnB,YAAY,OAAA,CAAQ,UAAA;AAAA,UACpB,cAAc,OAAA,CAAQ;AAAA,SACvB;AAAA,QACA,OAAA,CAAQ,MAAA;AAAA,QACR,OAAA,CAAQ;AAAA,OACT;AACA,MAAA,OAAO,YAAA,CAAa,GAAA,CAAI,gBAAA,EAAkB,SAAS,CAAA;AAAA,IACpD;AAAA,GACD;AAEA,EAAA,OAAO,OAAA;AACR","file":"chunk-XNRIM27H.js","sourcesContent":["import type { FlowRuntime } from '../runtime'\nimport { ExecutionContext } from '../runtime/execution-context'\nimport { StepByStepOrchestrator } from '../runtime/orchestrators/step-by-step'\nimport { WorkflowState } from '../runtime/state'\nimport { GraphTraverser } from '../runtime/traverser'\nimport type { NodeClass, NodeFunction, WorkflowBlueprint, WorkflowResult } from '../types'\n\n/**\n * Represents the controlled, step-by-step execution of a workflow.\n * Returned by the `createStepper` utility.\n */\nexport interface IWorkflowStepper<TContext extends Record<string, any>> {\n\t/** The current state of the workflow. Can be inspected after each step. */\n\treadonly state: WorkflowState<TContext>\n\n\t/** The graph traverser instance. Can be used to inspect the frontier or completed nodes. */\n\treadonly traverser: GraphTraverser\n\n\t/**\n\t * Executes the next \"turn\" or batch of ready nodes in the workflow.\n\t * @param options Optional configuration for this specific step, like a cancellation signal.\n\t * @returns A `WorkflowResult` representing the state after the step, or `null` if the workflow has already completed.\n\t */\n\tnext(options?: { signal?: AbortSignal; concurrency?: number }): Promise<WorkflowResult<TContext> | null>\n\n\t/**\n\t * Reverts the workflow to its previous state.\n\t * @returns The `WorkflowResult` of the previous state, or `null` if there is no history to revert to.\n\t */\n\tprev(): Promise<WorkflowResult<TContext> | null>\n\n\t/**\n\t * Resets the stepper to its initial state, clearing all progress and history.\n\t */\n\treset(): void\n\n\t/**\n\t * A convenience method to check if the workflow has any more steps to run.\n\t * @returns `true` if the workflow is complete or stalled, `false` otherwise.\n\t */\n\tisDone(): boolean\n}\n\n/**\n * A test utility that creates a stepper to execute a workflow one \"turn\" at a time.\n * This is invaluable for debugging and writing fine-grained tests where you need to\n * assert the state of the workflow after each logical step.\n *\n * @example\n * // In your test file\n * it('should correctly execute step-by-step', async () => {\n * const runtime = new FlowRuntime({ ... });\n * const flow = createFlow('test')\n * .node('a', async () => ({ output: 10 }))\n * .node('b', async ({ input }) => ({ output: input * 2 }))\n * .edge('a', 'b');\n *\n * const stepper = await createStepper(runtime, flow.toBlueprint(), flow.getFunctionRegistry());\n *\n * // First step (executes node 'a')\n * const result1 = await stepper.next();\n * expect(stepper.isDone()).toBe(false);\n * expect(result1.status).toBe('stalled');\n * expect(result1.context._outputs.a).toBe(10);\n *\n * // Second step (executes node 'b')\n * const result2 = await stepper.next();\n * expect(stepper.isDone()).toBe(true);\n * expect(result2.status).toBe('completed');\n * expect(result2.context._outputs.b).toBe(20);\n *\n * // Final step (no more work)\n * const result3 = await stepper.next();\n * expect(result3).toBeNull();\n * });\n *\n * @param runtime The `FlowRuntime` instance, used for its configuration.\n * @param blueprint The `WorkflowBlueprint` to execute.\n * @param functionRegistry The function registry from createFlow, containing the node implementations.\n * @param initialState The initial state for the workflow run.\n * @returns A Promise that resolves to an `IWorkflowStepper` instance.\n */\nexport async function createStepper<TContext extends Record<string, any>, TDependencies extends Record<string, any>>(\n\truntime: FlowRuntime<TContext, TDependencies>,\n\tblueprint: WorkflowBlueprint,\n\tfunctionRegistry: Map<string, NodeFunction | NodeClass>,\n\tinitialState: Partial<TContext> = {},\n): Promise<IWorkflowStepper<TContext>> {\n\tconst _initialBlueprint = structuredClone(blueprint)\n\tconst _initialState = structuredClone(initialState)\n\n\tlet state: WorkflowState<TContext>\n\tlet traverser: GraphTraverser\n\tconst history: string[] = []\n\n\tconst orchestrator = new StepByStepOrchestrator()\n\tconst executionId = globalThis.crypto?.randomUUID()\n\tconst nodeRegistry = new Map([...runtime.registry, ...functionRegistry])\n\n\tconst initialize = () => {\n\t\tstate = new WorkflowState<TContext>(_initialState)\n\t\ttraverser = new GraphTraverser(_initialBlueprint)\n\t\thistory.length = 0\n\t}\n\n\tinitialize()\n\n\tconst stepper: IWorkflowStepper<TContext> = {\n\t\tget state() {\n\t\t\treturn state\n\t\t},\n\t\tget traverser() {\n\t\t\treturn traverser\n\t\t},\n\t\tisDone() {\n\t\t\treturn !traverser.hasMoreWork() && !state.isAwaiting()\n\t\t},\n\t\treset() {\n\t\t\tinitialize()\n\t\t},\n\t\tasync prev() {\n\t\t\tconst previousStateJson = history.pop()\n\t\t\tif (!previousStateJson) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst previousStateData = runtime.serializer.deserialize(previousStateJson) as Partial<TContext>\n\n\t\t\tstate = new WorkflowState(previousStateData)\n\t\t\ttraverser = GraphTraverser.fromState(_initialBlueprint, state)\n\n\t\t\treturn state.toResult(runtime.serializer)\n\t\t},\n\t\tasync next(options: { signal?: AbortSignal; concurrency?: number } = {}) {\n\t\t\tif (stepper.isDone()) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\tconst serializedContext = (await state.toResult(runtime.serializer)).serializedContext\n\t\t\thistory.push(serializedContext)\n\n\t\t\tconst executionContext = new ExecutionContext(\n\t\t\t\t_initialBlueprint,\n\t\t\t\tstate,\n\t\t\t\tnodeRegistry,\n\t\t\t\texecutionId,\n\t\t\t\truntime,\n\t\t\t\t{\n\t\t\t\t\tlogger: runtime.logger,\n\t\t\t\t\teventBus: runtime.eventBus,\n\t\t\t\t\tserializer: runtime.serializer,\n\t\t\t\t\tevaluator: runtime.evaluator,\n\t\t\t\t\tmiddleware: runtime.middleware,\n\t\t\t\t\tdependencies: runtime.dependencies,\n\t\t\t\t},\n\t\t\t\toptions.signal,\n\t\t\t\toptions.concurrency,\n\t\t\t)\n\t\t\treturn orchestrator.run(executionContext, traverser)\n\t\t},\n\t}\n\n\treturn stepper\n}\n"]}
|