flowcraft 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +1 -1
  2. package/dist/index-B7cJxomy.d.mts +1291 -0
  3. package/dist/index.d.mts +2 -0
  4. package/dist/index.mjs +747 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/dist/replay-BB11M6K1.mjs +107 -0
  7. package/dist/replay-BB11M6K1.mjs.map +1 -0
  8. package/dist/runtime-Bob_ca8M.mjs +2215 -0
  9. package/dist/runtime-Bob_ca8M.mjs.map +1 -0
  10. package/dist/{sdk.d.ts → sdk.d.mts} +14 -12
  11. package/dist/sdk.mjs +29 -0
  12. package/dist/sdk.mjs.map +1 -0
  13. package/dist/testing/index.d.mts +172 -0
  14. package/dist/testing/index.mjs +277 -0
  15. package/dist/testing/index.mjs.map +1 -0
  16. package/package.json +13 -13
  17. package/dist/adapters/index.d.ts +0 -4
  18. package/dist/adapters/index.js +0 -4
  19. package/dist/adapters/index.js.map +0 -1
  20. package/dist/adapters/persistent-event-bus.d.ts +0 -69
  21. package/dist/adapters/persistent-event-bus.js +0 -3
  22. package/dist/adapters/persistent-event-bus.js.map +0 -1
  23. package/dist/analysis.d.ts +0 -53
  24. package/dist/analysis.js +0 -3
  25. package/dist/analysis.js.map +0 -1
  26. package/dist/chunk-26VTGQAF.js +0 -103
  27. package/dist/chunk-26VTGQAF.js.map +0 -1
  28. package/dist/chunk-27STBUGG.js +0 -44
  29. package/dist/chunk-27STBUGG.js.map +0 -1
  30. package/dist/chunk-2TSADFQX.js +0 -46
  31. package/dist/chunk-2TSADFQX.js.map +0 -1
  32. package/dist/chunk-3Y5O5EGB.js +0 -3
  33. package/dist/chunk-3Y5O5EGB.js.map +0 -1
  34. package/dist/chunk-4JUPOFSL.js +0 -76
  35. package/dist/chunk-4JUPOFSL.js.map +0 -1
  36. package/dist/chunk-4PELJWF7.js +0 -29
  37. package/dist/chunk-4PELJWF7.js.map +0 -1
  38. package/dist/chunk-55J6XMHW.js +0 -3
  39. package/dist/chunk-55J6XMHW.js.map +0 -1
  40. package/dist/chunk-5A24LVGQ.js +0 -90
  41. package/dist/chunk-5A24LVGQ.js.map +0 -1
  42. package/dist/chunk-6RKHCJUU.js +0 -29
  43. package/dist/chunk-6RKHCJUU.js.map +0 -1
  44. package/dist/chunk-7EBKWATZ.js +0 -86
  45. package/dist/chunk-7EBKWATZ.js.map +0 -1
  46. package/dist/chunk-BC4G7OM6.js +0 -42
  47. package/dist/chunk-BC4G7OM6.js.map +0 -1
  48. package/dist/chunk-BCRWXTWX.js +0 -21
  49. package/dist/chunk-BCRWXTWX.js.map +0 -1
  50. package/dist/chunk-BV6MXL74.js +0 -340
  51. package/dist/chunk-BV6MXL74.js.map +0 -1
  52. package/dist/chunk-CIXL7AKH.js +0 -532
  53. package/dist/chunk-CIXL7AKH.js.map +0 -1
  54. package/dist/chunk-DL7KVYZF.js +0 -39
  55. package/dist/chunk-DL7KVYZF.js.map +0 -1
  56. package/dist/chunk-E6ICIXVR.js +0 -25
  57. package/dist/chunk-E6ICIXVR.js.map +0 -1
  58. package/dist/chunk-HFJXYY4E.js +0 -3
  59. package/dist/chunk-HFJXYY4E.js.map +0 -1
  60. package/dist/chunk-HNHM3FDK.js +0 -52
  61. package/dist/chunk-HNHM3FDK.js.map +0 -1
  62. package/dist/chunk-I53JB2KW.js +0 -26
  63. package/dist/chunk-I53JB2KW.js.map +0 -1
  64. package/dist/chunk-IDTYHLDQ.js +0 -16
  65. package/dist/chunk-IDTYHLDQ.js.map +0 -1
  66. package/dist/chunk-IKOTX22J.js +0 -85
  67. package/dist/chunk-IKOTX22J.js.map +0 -1
  68. package/dist/chunk-K446NZ4E.js +0 -25
  69. package/dist/chunk-K446NZ4E.js.map +0 -1
  70. package/dist/chunk-L3MX5MTA.js +0 -33
  71. package/dist/chunk-L3MX5MTA.js.map +0 -1
  72. package/dist/chunk-L46TQXCV.js +0 -144
  73. package/dist/chunk-L46TQXCV.js.map +0 -1
  74. package/dist/chunk-LM4ACVHL.js +0 -73
  75. package/dist/chunk-LM4ACVHL.js.map +0 -1
  76. package/dist/chunk-LNK7LZER.js +0 -51
  77. package/dist/chunk-LNK7LZER.js.map +0 -1
  78. package/dist/chunk-NVLZFLYM.js +0 -3
  79. package/dist/chunk-NVLZFLYM.js.map +0 -1
  80. package/dist/chunk-ONH7PIJZ.js +0 -300
  81. package/dist/chunk-ONH7PIJZ.js.map +0 -1
  82. package/dist/chunk-OOJEXFYY.js +0 -47
  83. package/dist/chunk-OOJEXFYY.js.map +0 -1
  84. package/dist/chunk-PH2IYZHV.js +0 -48
  85. package/dist/chunk-PH2IYZHV.js.map +0 -1
  86. package/dist/chunk-PU2VTWJD.js +0 -164
  87. package/dist/chunk-PU2VTWJD.js.map +0 -1
  88. package/dist/chunk-QA2WDZPV.js +0 -74
  89. package/dist/chunk-QA2WDZPV.js.map +0 -1
  90. package/dist/chunk-RM677CNU.js +0 -52
  91. package/dist/chunk-RM677CNU.js.map +0 -1
  92. package/dist/chunk-TKSSRS5U.js +0 -39
  93. package/dist/chunk-TKSSRS5U.js.map +0 -1
  94. package/dist/chunk-UNORA7EM.js +0 -103
  95. package/dist/chunk-UNORA7EM.js.map +0 -1
  96. package/dist/chunk-VZ4BRDBK.js +0 -54
  97. package/dist/chunk-VZ4BRDBK.js.map +0 -1
  98. package/dist/chunk-X5RJOZY2.js +0 -279
  99. package/dist/chunk-X5RJOZY2.js.map +0 -1
  100. package/dist/chunk-ZETQCNEF.js +0 -139
  101. package/dist/chunk-ZETQCNEF.js.map +0 -1
  102. package/dist/chunk-ZKINHLMS.js +0 -230
  103. package/dist/chunk-ZKINHLMS.js.map +0 -1
  104. package/dist/chunk-ZLW4QOTS.js +0 -192
  105. package/dist/chunk-ZLW4QOTS.js.map +0 -1
  106. package/dist/container-factory.d.ts +0 -17
  107. package/dist/container-factory.js +0 -13
  108. package/dist/container-factory.js.map +0 -1
  109. package/dist/container.d.ts +0 -23
  110. package/dist/container.js +0 -3
  111. package/dist/container.js.map +0 -1
  112. package/dist/context.d.ts +0 -65
  113. package/dist/context.js +0 -3
  114. package/dist/context.js.map +0 -1
  115. package/dist/error-mapper.d.ts +0 -15
  116. package/dist/error-mapper.js +0 -4
  117. package/dist/error-mapper.js.map +0 -1
  118. package/dist/errors.d.ts +0 -20
  119. package/dist/errors.js +0 -3
  120. package/dist/errors.js.map +0 -1
  121. package/dist/evaluator.d.ts +0 -32
  122. package/dist/evaluator.js +0 -3
  123. package/dist/evaluator.js.map +0 -1
  124. package/dist/flow.d.ts +0 -83
  125. package/dist/flow.js +0 -4
  126. package/dist/flow.js.map +0 -1
  127. package/dist/index.d.ts +0 -18
  128. package/dist/index.js +0 -38
  129. package/dist/index.js.map +0 -1
  130. package/dist/linter.d.ts +0 -26
  131. package/dist/linter.js +0 -4
  132. package/dist/linter.js.map +0 -1
  133. package/dist/logger.d.ts +0 -20
  134. package/dist/logger.js +0 -3
  135. package/dist/logger.js.map +0 -1
  136. package/dist/node.d.ts +0 -3
  137. package/dist/node.js +0 -3
  138. package/dist/node.js.map +0 -1
  139. package/dist/nodes/batch-gather.d.ts +0 -9
  140. package/dist/nodes/batch-gather.js +0 -4
  141. package/dist/nodes/batch-gather.js.map +0 -1
  142. package/dist/nodes/batch-scatter.d.ts +0 -9
  143. package/dist/nodes/batch-scatter.js +0 -4
  144. package/dist/nodes/batch-scatter.js.map +0 -1
  145. package/dist/nodes/sleep.d.ts +0 -9
  146. package/dist/nodes/sleep.js +0 -4
  147. package/dist/nodes/sleep.js.map +0 -1
  148. package/dist/nodes/subflow.d.ts +0 -9
  149. package/dist/nodes/subflow.js +0 -10
  150. package/dist/nodes/subflow.js.map +0 -1
  151. package/dist/nodes/wait.d.ts +0 -9
  152. package/dist/nodes/wait.js +0 -4
  153. package/dist/nodes/wait.js.map +0 -1
  154. package/dist/nodes/webhook.d.ts +0 -13
  155. package/dist/nodes/webhook.js +0 -4
  156. package/dist/nodes/webhook.js.map +0 -1
  157. package/dist/runtime/adapter.d.ts +0 -114
  158. package/dist/runtime/adapter.js +0 -28
  159. package/dist/runtime/adapter.js.map +0 -1
  160. package/dist/runtime/builtin-keys.d.ts +0 -38
  161. package/dist/runtime/builtin-keys.js +0 -10
  162. package/dist/runtime/builtin-keys.js.map +0 -1
  163. package/dist/runtime/execution-context.d.ts +0 -3
  164. package/dist/runtime/execution-context.js +0 -6
  165. package/dist/runtime/execution-context.js.map +0 -1
  166. package/dist/runtime/executors.d.ts +0 -3
  167. package/dist/runtime/executors.js +0 -4
  168. package/dist/runtime/executors.js.map +0 -1
  169. package/dist/runtime/index.d.ts +0 -7
  170. package/dist/runtime/index.js +0 -31
  171. package/dist/runtime/index.js.map +0 -1
  172. package/dist/runtime/node-executor-factory.d.ts +0 -12
  173. package/dist/runtime/node-executor-factory.js +0 -6
  174. package/dist/runtime/node-executor-factory.js.map +0 -1
  175. package/dist/runtime/orchestrator.d.ts +0 -9
  176. package/dist/runtime/orchestrator.js +0 -8
  177. package/dist/runtime/orchestrator.js.map +0 -1
  178. package/dist/runtime/orchestrators/replay.d.ts +0 -45
  179. package/dist/runtime/orchestrators/replay.js +0 -3
  180. package/dist/runtime/orchestrators/replay.js.map +0 -1
  181. package/dist/runtime/orchestrators/step-by-step.d.ts +0 -16
  182. package/dist/runtime/orchestrators/step-by-step.js +0 -5
  183. package/dist/runtime/orchestrators/step-by-step.js.map +0 -1
  184. package/dist/runtime/orchestrators/utils.d.ts +0 -35
  185. package/dist/runtime/orchestrators/utils.js +0 -4
  186. package/dist/runtime/orchestrators/utils.js.map +0 -1
  187. package/dist/runtime/runtime.d.ts +0 -3
  188. package/dist/runtime/runtime.js +0 -27
  189. package/dist/runtime/runtime.js.map +0 -1
  190. package/dist/runtime/scheduler.d.ts +0 -3
  191. package/dist/runtime/scheduler.js +0 -3
  192. package/dist/runtime/scheduler.js.map +0 -1
  193. package/dist/runtime/state.d.ts +0 -3
  194. package/dist/runtime/state.js +0 -5
  195. package/dist/runtime/state.js.map +0 -1
  196. package/dist/runtime/traverser.d.ts +0 -3
  197. package/dist/runtime/traverser.js +0 -5
  198. package/dist/runtime/traverser.js.map +0 -1
  199. package/dist/runtime/types.d.ts +0 -3
  200. package/dist/runtime/types.js +0 -3
  201. package/dist/runtime/types.js.map +0 -1
  202. package/dist/runtime/workflow-logic-handler.d.ts +0 -17
  203. package/dist/runtime/workflow-logic-handler.js +0 -5
  204. package/dist/runtime/workflow-logic-handler.js.map +0 -1
  205. package/dist/sanitizer.d.ts +0 -12
  206. package/dist/sanitizer.js +0 -3
  207. package/dist/sanitizer.js.map +0 -1
  208. package/dist/sdk.js +0 -20
  209. package/dist/sdk.js.map +0 -1
  210. package/dist/serializer.d.ts +0 -18
  211. package/dist/serializer.js +0 -3
  212. package/dist/serializer.js.map +0 -1
  213. package/dist/testing/event-logger.d.ts +0 -63
  214. package/dist/testing/event-logger.js +0 -3
  215. package/dist/testing/event-logger.js.map +0 -1
  216. package/dist/testing/index.d.ts +0 -7
  217. package/dist/testing/index.js +0 -37
  218. package/dist/testing/index.js.map +0 -1
  219. package/dist/testing/run-with-trace.d.ts +0 -38
  220. package/dist/testing/run-with-trace.js +0 -33
  221. package/dist/testing/run-with-trace.js.map +0 -1
  222. package/dist/testing/stepper.d.ts +0 -79
  223. package/dist/testing/stepper.js +0 -11
  224. package/dist/testing/stepper.js.map +0 -1
  225. package/dist/types-Biip2gLh.d.ts +0 -676
  226. package/dist/types.d.ts +0 -3
  227. package/dist/types.js +0 -3
  228. package/dist/types.js.map +0 -1
@@ -1,51 +0,0 @@
1
- // src/node.ts
2
- function isNodeClass(impl) {
3
- return typeof impl === "function" && !!impl.prototype?.exec;
4
- }
5
- var BaseNode = class {
6
- /**
7
- * @param params Static parameters for this node instance, passed from the blueprint.
8
- * @param nodeId The ID of the node in the blueprint.
9
- */
10
- constructor(params, nodeId) {
11
- this.params = params;
12
- this.nodeId = nodeId;
13
- }
14
- /**
15
- * Phase 1: Gathers and prepares data for execution. This phase is NOT retried on failure.
16
- * @param context The node's execution context.
17
- * @returns The data needed for the `exec` phase.
18
- */
19
- async prep(context) {
20
- return context.input;
21
- }
22
- /**
23
- * Phase 3: Processes the result and saves state. This phase is NOT retried.
24
- * @param execResult The successful result from the `exec` or `fallback` phase.
25
- * @param _context The node's execution context.
26
- */
27
- async post(execResult, _context) {
28
- return execResult;
29
- }
30
- /**
31
- * An optional safety net that runs if all `exec` retries fail.
32
- * @param error The final error from the last `exec` attempt.
33
- * @param _context The node's execution context.
34
- */
35
- async fallback(error, _context) {
36
- throw error;
37
- }
38
- /**
39
- * An optional cleanup phase for non-retriable errors that occur outside the main `exec` method.
40
- * This method is invoked in a `finally` block or equivalent construct if a fatal, unhandled exception occurs in the `prep`, `exec`, or `post` phases.
41
- * Allows nodes to perform crucial cleanup, such as closing database connections or releasing locks.
42
- * @param _error The error that caused the failure.
43
- * @param _context The node's execution context.
44
- */
45
- async recover(_error, _context) {
46
- }
47
- };
48
-
49
- export { BaseNode, isNodeClass };
50
- //# sourceMappingURL=chunk-LNK7LZER.js.map
51
- //# sourceMappingURL=chunk-LNK7LZER.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/node.ts"],"names":[],"mappings":";AAGO,SAAS,YAAY,IAAA,EAA8B;AACzD,EAAA,OAAO,OAAO,IAAA,KAAS,UAAA,IAAc,CAAC,CAAC,KAAK,SAAA,EAAW,IAAA;AACxD;AAOO,IAAe,WAAf,MAML;AAAA;AAAA;AAAA;AAAA;AAAA,EAKD,WAAA,CACW,QACA,MAAA,EACT;AAFS,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOH,MAAM,KAAK,OAAA,EAAqE;AAC/E,IAAA,OAAO,OAAA,CAAQ,KAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,MAAM,IAAA,CACL,UAAA,EACA,QAAA,EACwC;AACxC,IAAA,OAAO,UAAA;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,QAAA,CACL,KAAA,EACA,QAAA,EACuD;AAEvD,IAAA,MAAM,KAAA;AAAA,EACP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,OAAA,CAAQ,MAAA,EAAe,QAAA,EAAuE;AAAA,EAEpG;AACD","file":"chunk-LNK7LZER.js","sourcesContent":["import type { NodeClass, NodeContext, NodeResult, RuntimeDependencies } from './types'\n\n/** A type guard to reliably distinguish a NodeClass from a NodeFunction. */\nexport function isNodeClass(impl: any): impl is NodeClass {\n\treturn typeof impl === 'function' && !!impl.prototype?.exec\n}\n\n/**\n * A structured, class-based node for complex logic with a safe, granular lifecycle.\n * This class is generic, allowing implementations to specify the exact context\n * and dependency types they expect.\n */\nexport abstract class BaseNode<\n\tTContext extends Record<string, any> = Record<string, any>,\n\tTDependencies extends RuntimeDependencies = RuntimeDependencies,\n\tTInput = any,\n\tTOutput = any,\n\tTAction extends string = string,\n> {\n\t/**\n\t * @param params Static parameters for this node instance, passed from the blueprint.\n\t * @param nodeId The ID of the node in the blueprint.\n\t */\n\tconstructor(\n\t\tprotected params?: Record<string, any>,\n\t\tprotected nodeId?: string,\n\t) {}\n\n\t/**\n\t * Phase 1: Gathers and prepares data for execution. This phase is NOT retried on failure.\n\t * @param context The node's execution context.\n\t * @returns The data needed for the `exec` phase.\n\t */\n\tasync prep(context: NodeContext<TContext, TDependencies, TInput>): Promise<any> {\n\t\treturn context.input\n\t}\n\n\t/**\n\t * Phase 2: Performs the core, isolated logic. This is the ONLY phase that is retried.\n\t * @param prepResult The data returned from the `prep` phase.\n\t * @param context The node's execution context.\n\t */\n\tabstract exec(\n\t\tprepResult: any,\n\t\tcontext: NodeContext<TContext, TDependencies, TInput>,\n\t): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>>\n\n\t/**\n\t * Phase 3: Processes the result and saves state. This phase is NOT retried.\n\t * @param execResult The successful result from the `exec` or `fallback` phase.\n\t * @param _context The node's execution context.\n\t */\n\tasync post(\n\t\texecResult: Omit<NodeResult<TOutput, TAction>, 'error'>,\n\t\t_context: NodeContext<TContext, TDependencies, TInput>,\n\t): Promise<NodeResult<TOutput, TAction>> {\n\t\treturn execResult\n\t}\n\n\t/**\n\t * An optional safety net that runs if all `exec` retries fail.\n\t * @param error The final error from the last `exec` attempt.\n\t * @param _context The node's execution context.\n\t */\n\tasync fallback(\n\t\terror: Error,\n\t\t_context: NodeContext<TContext, TDependencies, TInput>,\n\t): Promise<Omit<NodeResult<TOutput, TAction>, 'error'>> {\n\t\t// By default, re-throw the error, failing the node.\n\t\tthrow error\n\t}\n\n\t/**\n\t * An optional cleanup phase for non-retriable errors that occur outside the main `exec` method.\n\t * This method is invoked in a `finally` block or equivalent construct if a fatal, unhandled exception occurs in the `prep`, `exec`, or `post` phases.\n\t * Allows nodes to perform crucial cleanup, such as closing database connections or releasing locks.\n\t * @param _error The error that caused the failure.\n\t * @param _context The node's execution context.\n\t */\n\tasync recover(_error: Error, _context: NodeContext<TContext, TDependencies, TInput>): Promise<void> {\n\t\t// Default no-op implementation. Subclasses can override for cleanup.\n\t}\n}\n"]}
@@ -1,3 +0,0 @@
1
-
2
- //# sourceMappingURL=chunk-NVLZFLYM.js.map
3
- //# sourceMappingURL=chunk-NVLZFLYM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-NVLZFLYM.js"}
@@ -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,MAAM,QAAA,EAAS;AAC9B,MAAA,IAAI,UAAU,CAAA,EAAG;AAChB,QAAA,OAAA,CAAQ,YAAA,CAAa,MAAA,CAAO,IAAA,CAAK,CAAA,oCAAA,CAAA,EAAwC;AAAA,UACxE,QAAQ,OAAA,CAAQ,EAAA;AAAA,UAChB,OAAA;AAAA,UACA;AAAA,SACA,CAAA;AAAA,MACF;AACA,MAAA,OAAO,MAAA;AAAA,IACR,SAAS,KAAA,EAAO;AACf,MAAA,SAAA,GAAY,KAAA;AACZ,MAAA,IAAI,KAAA,YAAiB,YAAA,IAAgB,KAAA,CAAM,IAAA,KAAS,YAAA,EAAc;AACjE,QAAA,MAAM,IAAI,eAAe,oBAAA,EAAsB;AAAA,UAC9C,OAAA,EAAS;AAAA,SACT,CAAA;AAAA,MACF;AACA,MAAA,IAAI,KAAA,YAAiB,cAAA,IAAkB,KAAA,CAAM,OAAA,EAAS;AACtD,MAAA,IAAI,UAAU,UAAA,EAAY;AACzB,QAAA,OAAA,CAAQ,YAAA,CAAa,MAAA,CAAO,IAAA,CAAK,CAAA,+BAAA,CAAA,EAAmC;AAAA,UACnE,QAAQ,OAAA,CAAQ,EAAA;AAAA,UAChB,OAAA;AAAA,UACA,UAAA;AAAA,UACA,OAAO,KAAA,YAAiB,KAAA,GAA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,MAAM,IAAA,CAAK,OAAA,CAAQ,QAAA,CAAS,QAAA,CAAS,IAAA,CAAK;AAAA,QACzC,IAAA,EAAM,YAAA;AAAA,QACN,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"]}
@@ -1,47 +0,0 @@
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: /* @__PURE__ */ Symbol.for("flowcraft:logger"),
35
- Serializer: /* @__PURE__ */ Symbol.for("flowcraft:serializer"),
36
- Evaluator: /* @__PURE__ */ Symbol.for("flowcraft:evaluator"),
37
- EventBus: /* @__PURE__ */ Symbol.for("flowcraft:eventBus"),
38
- Orchestrator: /* @__PURE__ */ Symbol.for("flowcraft:orchestrator"),
39
- Middleware: /* @__PURE__ */ Symbol.for("flowcraft:middleware"),
40
- NodeRegistry: /* @__PURE__ */ Symbol.for("flowcraft:nodeRegistry"),
41
- BlueprintRegistry: /* @__PURE__ */ Symbol.for("flowcraft:blueprintRegistry"),
42
- Dependencies: /* @__PURE__ */ Symbol.for("flowcraft:dependencies")
43
- };
44
-
45
- export { DIContainer, ServiceTokens };
46
- //# sourceMappingURL=chunk-OOJEXFYY.js.map
47
- //# sourceMappingURL=chunk-OOJEXFYY.js.map
@@ -1 +0,0 @@
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,EA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CAAA;AAAA,EACrC,UAAA,kBAAY,MAAA,CAAO,GAAA,CAAI,sBAAsB,CAAA;AAAA,EAC7C,SAAA,kBAAW,MAAA,CAAO,GAAA,CAAI,qBAAqB,CAAA;AAAA,EAC3C,QAAA,kBAAU,MAAA,CAAO,GAAA,CAAI,oBAAoB,CAAA;AAAA,EACzC,YAAA,kBAAc,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAAA,EACjD,UAAA,kBAAY,MAAA,CAAO,GAAA,CAAI,sBAAsB,CAAA;AAAA,EAC7C,YAAA,kBAAc,MAAA,CAAO,GAAA,CAAI,wBAAwB,CAAA;AAAA,EACjD,iBAAA,kBAAmB,MAAA,CAAO,GAAA,CAAI,6BAA6B,CAAA;AAAA,EAC3D,YAAA,kBAAc,MAAA,CAAO,GAAA,CAAI,wBAAwB;AAClD","file":"chunk-OOJEXFYY.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"]}
@@ -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
- //# sour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C;AAC/D,IAAA,IAAI;AAEH,MAAA,MAAM,oBAAA,GAAuB,kBAAA;AAC7B,MAAA,MAAM,SAAA,GAAY,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA,CAAE,MAAA,CAAO,CAAC,GAAA,KAAQ,oBAAA,CAAqB,IAAA,CAAK,GAAG,CAAC,CAAA;AACrF,MAAA,MAAM,eAAoC,EAAC;AAC3C,MAAA,KAAA,MAAW,OAAO,SAAA,EAAW;AAC5B,QAAA,YAAA,CAAa,GAAG,CAAA,GAAI,OAAA,CAAQ,GAAG,CAAA;AAAA,MAChC;AAGA,MAAA,MAAM,UAAU,IAAI,QAAA,CAAS,GAAG,SAAA,EAAW,CAAA,OAAA,EAAU,UAAU,CAAA,CAAE,CAAA;AACjE,MAAA,OAAO,OAAA,CAAQ,GAAG,SAAA,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"]}