flowcraft 2.3.1 → 2.5.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 (121) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/analysis.d.ts +9 -2
  4. package/dist/analysis.js +1 -1
  5. package/dist/chunk-27STBUGG.js +44 -0
  6. package/dist/chunk-27STBUGG.js.map +1 -0
  7. package/dist/{chunk-QNYXQKFW.js → chunk-2ISKDTSN.js} +3 -3
  8. package/dist/{chunk-QNYXQKFW.js.map → chunk-2ISKDTSN.js.map} +1 -1
  9. package/dist/{chunk-CD4FUZOJ.js → chunk-5BOUGXZO.js} +25 -11
  10. package/dist/chunk-5BOUGXZO.js.map +1 -0
  11. package/dist/{chunk-ZNL7ZXPR.js → chunk-5XPW6YEP.js} +76 -32
  12. package/dist/chunk-5XPW6YEP.js.map +1 -0
  13. package/dist/{chunk-BN4MV36K.js → chunk-6MGLU3UU.js} +3 -3
  14. package/dist/{chunk-BN4MV36K.js.map → chunk-6MGLU3UU.js.map} +1 -1
  15. package/dist/{chunk-C4HYIJI3.js → chunk-7FIOROIR.js} +19 -11
  16. package/dist/chunk-7FIOROIR.js.map +1 -0
  17. package/dist/{chunk-G5BGBPFP.js → chunk-FBPY44WL.js} +3 -3
  18. package/dist/{chunk-G5BGBPFP.js.map → chunk-FBPY44WL.js.map} +1 -1
  19. package/dist/chunk-HNHM3FDK.js +52 -0
  20. package/dist/chunk-HNHM3FDK.js.map +1 -0
  21. package/dist/chunk-I53JB2KW.js +26 -0
  22. package/dist/chunk-I53JB2KW.js.map +1 -0
  23. package/dist/chunk-IDTYHLDQ.js +16 -0
  24. package/dist/chunk-IDTYHLDQ.js.map +1 -0
  25. package/dist/{chunk-EUJWJWFA.js → chunk-IKOTX22J.js} +3 -3
  26. package/dist/{chunk-EUJWJWFA.js.map → chunk-IKOTX22J.js.map} +1 -1
  27. package/dist/{chunk-XNRIM27H.js → chunk-JLDHCI2O.js} +5 -5
  28. package/dist/{chunk-XNRIM27H.js.map → chunk-JLDHCI2O.js.map} +1 -1
  29. package/dist/chunk-LM4ACVHL.js +73 -0
  30. package/dist/chunk-LM4ACVHL.js.map +1 -0
  31. package/dist/{chunk-FRKO3WX4.js → chunk-N4NLAIEN.js} +3 -3
  32. package/dist/{chunk-FRKO3WX4.js.map → chunk-N4NLAIEN.js.map} +1 -1
  33. package/dist/{chunk-HKX7WQLS.js → chunk-OPRR4TAO.js} +43 -11
  34. package/dist/chunk-OPRR4TAO.js.map +1 -0
  35. package/dist/{chunk-MCGK3FXQ.js → chunk-SEI4Z3MO.js} +3 -3
  36. package/dist/{chunk-MCGK3FXQ.js.map → chunk-SEI4Z3MO.js.map} +1 -1
  37. package/dist/{chunk-MKNZBKSR.js → chunk-UXIASXSG.js} +7 -7
  38. package/dist/chunk-UXIASXSG.js.map +1 -0
  39. package/dist/chunk-XDI4TJHA.js +95 -0
  40. package/dist/chunk-XDI4TJHA.js.map +1 -0
  41. package/dist/{chunk-33NO4PUJ.js → chunk-XTW36KQZ.js} +3 -3
  42. package/dist/{chunk-33NO4PUJ.js.map → chunk-XTW36KQZ.js.map} +1 -1
  43. package/dist/{chunk-233SESC2.js → chunk-ZLW4QOTS.js} +74 -3
  44. package/dist/chunk-ZLW4QOTS.js.map +1 -0
  45. package/dist/container-factory.d.ts +1 -1
  46. package/dist/container-factory.js +5 -5
  47. package/dist/context.d.ts +21 -2
  48. package/dist/context.js +1 -1
  49. package/dist/error-mapper.d.ts +15 -0
  50. package/dist/error-mapper.js +4 -0
  51. package/dist/error-mapper.js.map +1 -0
  52. package/dist/evaluator.d.ts +1 -1
  53. package/dist/flow.d.ts +14 -5
  54. package/dist/flow.js +1 -1
  55. package/dist/index.d.ts +5 -4
  56. package/dist/index.js +20 -16
  57. package/dist/linter.d.ts +1 -1
  58. package/dist/linter.js +2 -2
  59. package/dist/logger.d.ts +1 -1
  60. package/dist/node.d.ts +1 -1
  61. package/dist/nodes/batch-gather.d.ts +1 -1
  62. package/dist/nodes/batch-scatter.d.ts +1 -1
  63. package/dist/nodes/sleep.d.ts +9 -0
  64. package/dist/nodes/sleep.js +4 -0
  65. package/dist/nodes/sleep.js.map +1 -0
  66. package/dist/nodes/subflow.d.ts +1 -1
  67. package/dist/nodes/subflow.js +6 -6
  68. package/dist/nodes/wait.d.ts +1 -1
  69. package/dist/nodes/wait.js +1 -1
  70. package/dist/nodes/webhook.d.ts +13 -0
  71. package/dist/nodes/webhook.js +4 -0
  72. package/dist/nodes/webhook.js.map +1 -0
  73. package/dist/runtime/adapter.d.ts +14 -1
  74. package/dist/runtime/adapter.js +15 -12
  75. package/dist/runtime/execution-context.d.ts +1 -1
  76. package/dist/runtime/execution-context.js +3 -3
  77. package/dist/runtime/executors.d.ts +1 -1
  78. package/dist/runtime/index.d.ts +1 -1
  79. package/dist/runtime/index.js +15 -12
  80. package/dist/runtime/node-executor-factory.d.ts +1 -1
  81. package/dist/runtime/orchestrator.d.ts +1 -1
  82. package/dist/runtime/orchestrator.js +4 -4
  83. package/dist/runtime/orchestrators/step-by-step.d.ts +1 -1
  84. package/dist/runtime/orchestrators/utils.d.ts +1 -1
  85. package/dist/runtime/runtime.d.ts +1 -1
  86. package/dist/runtime/runtime.js +14 -11
  87. package/dist/runtime/scheduler.d.ts +3 -0
  88. package/dist/runtime/scheduler.js +3 -0
  89. package/dist/runtime/scheduler.js.map +1 -0
  90. package/dist/runtime/state.d.ts +1 -1
  91. package/dist/runtime/state.js +2 -2
  92. package/dist/runtime/traverser.d.ts +1 -1
  93. package/dist/runtime/traverser.js +2 -2
  94. package/dist/runtime/types.d.ts +1 -1
  95. package/dist/runtime/workflow-logic-handler.d.ts +1 -1
  96. package/dist/runtime/workflow-logic-handler.js +2 -2
  97. package/dist/sanitizer.d.ts +1 -1
  98. package/dist/sdk.d.ts +29 -0
  99. package/dist/sdk.js +20 -0
  100. package/dist/sdk.js.map +1 -0
  101. package/dist/serializer.d.ts +1 -1
  102. package/dist/testing/event-logger.d.ts +1 -1
  103. package/dist/testing/index.d.ts +1 -1
  104. package/dist/testing/index.js +18 -15
  105. package/dist/testing/run-with-trace.d.ts +1 -1
  106. package/dist/testing/run-with-trace.js +16 -13
  107. package/dist/testing/stepper.d.ts +1 -1
  108. package/dist/testing/stepper.js +6 -6
  109. package/dist/{types-ezHUBdpL.d.ts → types-B-Drn84R.d.ts} +62 -3
  110. package/dist/types.d.ts +1 -1
  111. package/package.json +59 -55
  112. package/dist/chunk-233SESC2.js.map +0 -1
  113. package/dist/chunk-C4HYIJI3.js.map +0 -1
  114. package/dist/chunk-CD3Q4N6V.js +0 -13
  115. package/dist/chunk-CD3Q4N6V.js.map +0 -1
  116. package/dist/chunk-CD4FUZOJ.js.map +0 -1
  117. package/dist/chunk-HKX7WQLS.js.map +0 -1
  118. package/dist/chunk-MKNZBKSR.js.map +0 -1
  119. package/dist/chunk-R3HQXIEL.js +0 -49
  120. package/dist/chunk-R3HQXIEL.js.map +0 -1
  121. package/dist/chunk-ZNL7ZXPR.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Feathers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -11,7 +11,7 @@ Build complex, multi-step processes with a lightweight, composable, and type-saf
11
11
  - **Zero Dependencies**: Lightweight and dependency-free, ensuring easy integration in any runtime.
12
12
  - **Declarative Workflows**: Define workflows as [serializable](https://flowcraft.js.org/guide/core-concepts#workflow-blueprint) objects with [nodes and edges](https://flowcraft.js.org/guide/core-concepts#nodes-edges).
13
13
  - **Unopinionated Logic**: Nodes can be simple [functions](https://flowcraft.js.org/guide/core-concepts#function-based-nodes) or structured [classes](https://flowcraft.js.org/guide/core-concepts#class-based-nodes), supporting any logic.
14
- - **Progressive Scalability**: Run [in-memory](https://flowcraft.js.org/guide/programmatic) or scale to [distributed systems](https://flowcraft.js.org/guide/distributed-execution) using the same blueprint.
14
+ - **Progressive Scalability**: Run [in-memory](https://flowcraft.js.org/guide/fluent) or scale to [distributed systems](https://flowcraft.js.org/guide/distributed-execution) using the same blueprint.
15
15
  - **Resilient Execution**: Built-in support for [retries](https://flowcraft.js.org/guide/error-handling#retries), [fallbacks](https://flowcraft.js.org/guide/error-handling#fallbacks), [timeouts](https://flowcraft.js.org/guide/core-concepts#config), and [cancellation](https://flowcraft.js.org/guide/core-concepts#cancellation).
16
16
  - **Advanced Patterns**: Includes [batches](https://flowcraft.js.org/guide/batches), [loops](https://flowcraft.js.org/guide/loops), [subflows](https://flowcraft.js.org/guide/subflows), and [HITL](https://flowcraft.js.org/guide/hitl) constructs for complex workflows.
17
17
  - **Extensibility**: Pluggable [loggers](https://flowcraft.js.org/guide/loggers), [evaluators](https://flowcraft.js.org/guide/evaluators), [serializers](https://flowcraft.js.org/guide/serializers), and [middleware](https://flowcraft.js.org/guide/middleware) for custom behavior.
@@ -1,4 +1,4 @@
1
- import { g as WorkflowBlueprint } from './types-ezHUBdpL.js';
1
+ import { h as WorkflowBlueprint, z as FlowcraftEvent } from './types-B-Drn84R.js';
2
2
  import './errors.js';
3
3
  import './container.js';
4
4
 
@@ -36,6 +36,13 @@ declare function checkForCycles(blueprint: WorkflowBlueprint): Cycles;
36
36
  * @returns Mermaid syntax string for the flowchart
37
37
  */
38
38
  declare function generateMermaid(blueprint: WorkflowBlueprint): string;
39
+ /**
40
+ * Generates Mermaid diagram syntax from a WorkflowBlueprint with execution history styling
41
+ * @param blueprint The WorkflowBlueprint object containing nodes and edges
42
+ * @param events Array of FlowcraftEvent objects from the workflow execution
43
+ * @returns Mermaid syntax string for the flowchart with execution path highlighting
44
+ */
45
+ declare function generateMermaidForRun(blueprint: WorkflowBlueprint, events: FlowcraftEvent[]): string;
39
46
  /**
40
47
  * Analyzes a workflow blueprint and returns comprehensive analysis
41
48
  * @param blueprint The WorkflowBlueprint object containing nodes and edges
@@ -43,4 +50,4 @@ declare function generateMermaid(blueprint: WorkflowBlueprint): string;
43
50
  */
44
51
  declare function analyzeBlueprint(blueprint: WorkflowBlueprint): BlueprintAnalysis;
45
52
 
46
- export { type BlueprintAnalysis, type Cycles, analyzeBlueprint, checkForCycles, generateMermaid };
53
+ export { type BlueprintAnalysis, type Cycles, analyzeBlueprint, checkForCycles, generateMermaid, generateMermaidForRun };
package/dist/analysis.js CHANGED
@@ -1,3 +1,3 @@
1
- export { analyzeBlueprint, checkForCycles, generateMermaid } from './chunk-233SESC2.js';
1
+ export { analyzeBlueprint, checkForCycles, generateMermaid, generateMermaidForRun } from './chunk-ZLW4QOTS.js';
2
2
  //# sourceMappingURL=analysis.js.map
3
3
  //# sourceMappingURL=analysis.js.map
@@ -0,0 +1,44 @@
1
+ import { FlowcraftError } from './chunk-BCRWXTWX.js';
2
+
3
+ // src/error-mapper.ts
4
+ function createErrorMapper(manifestBlueprints) {
5
+ const locationMap = /* @__PURE__ */ new Map();
6
+ for (const blueprint of Object.values(manifestBlueprints)) {
7
+ for (const node of blueprint.nodes) {
8
+ if (node._sourceLocation) {
9
+ locationMap.set(node.id, node._sourceLocation);
10
+ }
11
+ }
12
+ for (const edge of blueprint.edges) {
13
+ if (edge._sourceLocation) {
14
+ const edgeKey = `${edge.source}-${edge.target}`;
15
+ locationMap.set(edgeKey, edge._sourceLocation);
16
+ }
17
+ }
18
+ }
19
+ return function mapError(error) {
20
+ if (error instanceof FlowcraftError && error.nodeId) {
21
+ const location = locationMap.get(error.nodeId);
22
+ if (location) {
23
+ return new Error(
24
+ `Workflow error at ${location.file}:${location.line}:${location.column}. Original error: ${error.message}`
25
+ );
26
+ }
27
+ }
28
+ const nodeIdMatch = error.message.match(/nodeId[:\s]+([^\s,]+)/i);
29
+ if (nodeIdMatch) {
30
+ const nodeId = nodeIdMatch[1];
31
+ const location = locationMap.get(nodeId);
32
+ if (location) {
33
+ return new Error(
34
+ `Workflow error at ${location.file}:${location.line}:${location.column}. Original error: ${error.message}`
35
+ );
36
+ }
37
+ }
38
+ return error;
39
+ };
40
+ }
41
+
42
+ export { createErrorMapper };
43
+ //# sourceMappingURL=chunk-27STBUGG.js.map
44
+ //# sourceMappingURL=chunk-27STBUGG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/error-mapper.ts"],"names":[],"mappings":";;;AAWO,SAAS,kBAAkB,kBAAA,EAAuD;AACxF,EAAA,MAAM,WAAA,uBAAkB,GAAA,EAA4B;AAGpD,EAAA,KAAA,MAAW,SAAA,IAAa,MAAA,CAAO,MAAA,CAAO,kBAAkB,CAAA,EAAG;AAC1D,IAAA,KAAA,MAAW,IAAA,IAAQ,UAAU,KAAA,EAAO;AACnC,MAAA,IAAI,KAAK,eAAA,EAAiB;AACzB,QAAA,WAAA,CAAY,GAAA,CAAI,IAAA,CAAK,EAAA,EAAI,IAAA,CAAK,eAAe,CAAA;AAAA,MAC9C;AAAA,IACD;AACA,IAAA,KAAA,MAAW,IAAA,IAAQ,UAAU,KAAA,EAAO;A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-27STBUGG.js","sourcesContent":["import { FlowcraftError } from './errors'\nimport type { SourceLocation, WorkflowBlueprint } from './types'\n\n/**\n * Creates an error mapper function that enhances runtime errors with source location information.\n * The mapper looks up node IDs in the provided manifest blueprints and returns enhanced errors\n * that point to the original TypeScript source code.\n *\n * @param manifestBlueprints - The compiled blueprint manifest containing source location data\n * @returns A function that maps errors to enhanced errors with source location information\n */\nexport function createErrorMapper(manifestBlueprints: Record<string, WorkflowBlueprint>) {\n\tconst locationMap = new Map<string, SourceLocation>()\n\n\t// build a quick lookup map\n\tfor (const blueprint of Object.values(manifestBlueprints)) {\n\t\tfor (const node of blueprint.nodes) {\n\t\t\tif (node._sourceLocation) {\n\t\t\t\tlocationMap.set(node.id, node._sourceLocation)\n\t\t\t}\n\t\t}\n\t\tfor (const edge of blueprint.edges) {\n\t\t\tif (edge._sourceLocation) {\n\t\t\t\tconst edgeKey = `${edge.source}-${edge.target}`\n\t\t\t\tlocationMap.set(edgeKey, edge._sourceLocation)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn function mapError(error: Error): Error {\n\t\tif (error instanceof FlowcraftError && error.nodeId) {\n\t\t\tconst location = locationMap.get(error.nodeId)\n\t\t\tif (location) {\n\t\t\t\treturn new Error(\n\t\t\t\t\t`Workflow error at ${location.file}:${location.line}:${location.column}. Original error: ${error.message}`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\t// try to extract nodeId from error message\n\t\tconst nodeIdMatch = error.message.match(/nodeId[:\\s]+([^\\s,]+)/i)\n\t\tif (nodeIdMatch) {\n\t\t\tconst nodeId = nodeIdMatch[1]\n\t\t\tconst location = locationMap.get(nodeId)\n\t\t\tif (location) {\n\t\t\t\treturn new Error(\n\t\t\t\t\t`Workflow error at ${location.file}:${location.line}:${location.column}. Original error: ${error.message}`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn error\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { DefaultOrchestrator } from './chunk-33NO4PUJ.js';
1
+ import { DefaultOrchestrator } from './chunk-XTW36KQZ.js';
2
2
  import { NullLogger } from './chunk-4PELJWF7.js';
3
3
  import { JsonSerializer } from './chunk-CYHZ2YVH.js';
4
4
  import { DIContainer, ServiceTokens } from './chunk-WWGFIYKW.js';
@@ -21,5 +21,5 @@ function createDefaultContainer(options = {}) {
21
21
  }
22
22
 
23
23
  export { createDefaultContainer };
24
- //# sourceMappingURL=chunk-QNYXQKFW.js.map
25
- //# sourceMappingURL=chunk-QNYXQKFW.js.map
24
+ //# sourceMappingURL=chunk-2ISKDTSN.js.map
25
+ //# sourceMappingURL=chunk-2ISKDTSN.js.map
@@ -1 +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"]}
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-2ISKDTSN.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"]}
@@ -1,4 +1,4 @@
1
- import { AsyncContextView, Context } from './chunk-R3HQXIEL.js';
1
+ import { TrackedAsyncContext, AsyncContextView, Context } from './chunk-XDI4TJHA.js';
2
2
  import { FlowcraftError } from './chunk-BCRWXTWX.js';
3
3
 
4
4
  // src/runtime/state.ts
@@ -9,8 +9,9 @@ var WorkflowState = class {
9
9
  context;
10
10
  _isAwaiting = false;
11
11
  _awaitingNodeIds = /* @__PURE__ */ new Set();
12
+ _awaitingDetails = /* @__PURE__ */ new Map();
12
13
  constructor(initialData) {
13
- this.context = new AsyncContextView(new Context(initialData));
14
+ this.context = new TrackedAsyncContext(new AsyncContextView(new Context(initialData)));
14
15
  if (initialData._awaitingNodeIds) {
15
16
  this._isAwaiting = true;
16
17
  const awaitingIds = initialData._awaitingNodeIds;
@@ -20,6 +21,9 @@ var WorkflowState = class {
20
21
  }
21
22
  }
22
23
  }
24
+ if (initialData._awaitingDetails) {
25
+ this._awaitingDetails = new Map(Object.entries(initialData._awaitingDetails));
26
+ }
23
27
  for (const key of Object.keys(initialData)) {
24
28
  if (key.startsWith("_outputs.")) {
25
29
  const nodeId = key.substring("_outputs.".length);
@@ -41,7 +45,7 @@ var WorkflowState = class {
41
45
  ...flowcraftError,
42
46
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
43
47
  originalError: error
44
- // Legacy compatibility
48
+ // legacy compatibility
45
49
  });
46
50
  }
47
51
  clearError(nodeId) {
@@ -62,11 +66,14 @@ var WorkflowState = class {
62
66
  getAnyFallbackExecuted() {
63
67
  return this.anyFallbackExecuted;
64
68
  }
65
- markAsAwaiting(nodeId) {
69
+ async markAsAwaiting(nodeId, details) {
66
70
  this._isAwaiting = true;
67
71
  this._awaitingNodeIds.add(nodeId);
68
- const awaitingArray = Array.from(this._awaitingNodeIds);
69
- this.context.set("_awaitingNodeIds", awaitingArray);
72
+ if (details) {
73
+ this._awaitingDetails.set(nodeId, details);
74
+ }
75
+ await this.context.set("_awaitingNodeIds", Array.from(this._awaitingNodeIds));
76
+ await this.context.set("_awaitingDetails", Object.fromEntries(this._awaitingDetails));
70
77
  }
71
78
  isAwaiting() {
72
79
  return this._isAwaiting && this._awaitingNodeIds.size > 0;
@@ -74,18 +81,24 @@ var WorkflowState = class {
74
81
  getAwaitingNodeIds() {
75
82
  return Array.from(this._awaitingNodeIds);
76
83
  }
84
+ getAwaitingDetails(nodeId) {
85
+ return this._awaitingDetails.get(nodeId);
86
+ }
77
87
  clearAwaiting(nodeId) {
78
88
  if (nodeId) {
79
89
  this._awaitingNodeIds.delete(nodeId);
90
+ this._awaitingDetails.delete(nodeId);
80
91
  } else {
81
92
  this._awaitingNodeIds.clear();
93
+ this._awaitingDetails.clear();
82
94
  }
83
95
  this._isAwaiting = this._awaitingNodeIds.size > 0;
84
- const awaitingArray = Array.from(this._awaitingNodeIds);
85
- if (awaitingArray.length > 0) {
86
- this.context.set("_awaitingNodeIds", awaitingArray);
96
+ if (this._awaitingNodeIds.size > 0) {
97
+ this.context.set("_awaitingNodeIds", Array.from(this._awaitingNodeIds));
98
+ this.context.set("_awaitingDetails", Object.fromEntries(this._awaitingDetails));
87
99
  } else {
88
100
  this.context.delete("_awaitingNodeIds");
101
+ this.context.delete("_awaitingDetails");
89
102
  }
90
103
  }
91
104
  getStatus(isTraversalComplete = false) {
@@ -99,6 +112,7 @@ var WorkflowState = class {
99
112
  const contextJSON = await this.context.toJSON();
100
113
  if (!this._isAwaiting && contextJSON._awaitingNodeIds) {
101
114
  delete contextJSON._awaitingNodeIds;
115
+ delete contextJSON._awaitingDetails;
102
116
  }
103
117
  return {
104
118
  context: contextJSON,
@@ -110,5 +124,5 @@ var WorkflowState = class {
110
124
  };
111
125
 
112
126
  export { WorkflowState };
113
- //# sourceMappingURL=chunk-CD4FUZOJ.js.map
114
- //# sourceMappingURL=chunk-CD4FUZOJ.js.map
127
+ //# sourceMappingURL=chunk-5BOUGXZO.js.map
128
+ //# sourceMappingURL=chunk-5BOUGXZO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/state.ts"],"names":[],"mappings":";;;;AAIO,IAAM,gBAAN,MAA0D;AAAA,EACxD,eAAA,uBAAsB,GAAA,EAAY;AAAA,EAClC,SAA0B,EAAC;AAAA,EAC3B,mBAAA,GAAsB,KAAA;AAAA,EACtB,OAAA;AAAA,EACA,WAAA,GAAc,KAAA;AAAA,EACd,gBAAA,uBAAuB,GAAA,EAAY;AAAA,EACnC,gBAAA,uBAAuB,GAAA,EAAi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Q,OAAO,kBAAyB,CAAA;AAC7C,MAAA,IAAA,CAAK,OAAA,CAAQ,OAAO,kBAAyB,CAAA;AAAA,IAC9C;AAAA,EACD;AAAA,EAEA,SAAA,CAAU,sBAAsB,KAAA,EAAiC;AAChE,IAAA,IAAI,IAAA,CAAK,aAAa,OAAO,UAAA;AAC7B,IAAA,IAAI,IAAA,CAAK,qBAAqB,OAAO,WAAA;AACrC,IAAA,IAAI,IAAA,CAAK,MAAA,CAAO,MAAA,GAAS,CAAA,EAAG,OAAO,QAAA;AACnC,IAAA,IAAI,qBAAqB,OAAO,WAAA;AAChC,IAAA,OAAO,SAAA;AAAA,EACR;AAAA,EAEA,MAAM,SAAS,UAAA,EAA4D;AAC1E,IAAA,MAAM,WAAA,GAAe,MAAM,IAAA,CAAK,OAAA,CAAQ,MAAA,EAAO;AAC/C,IAAA,IAAI,CAAC,IAAA,CAAK,WAAA,IAAgB,WAAA,CAAoB,gBAAA,EAAkB;AAC/D,MAAA,OAAQ,WAAA,CAAoB,gBAAA;AAC5B,MAAA,OAAQ,WAAA,CAAoB,gBAAA;AAAA,IAC7B;AACA,IAAA,OAAO;AAAA,MACN,OAAA,EAAS,WAAA;AAAA,MACT,iBAAA,EAAmB,UAAA,CAAW,SAAA,CAAU,WAAW,CAAA;AAAA,MACnD,MAAA,EAAQ,KAAK,SAAA,EAAU;AAAA,MACvB,QAAQ,IAAA,CAAK,MAAA,CAAO,MAAA,GAAS,CAAA,GAAI,KAAK,MAAA,GAAS;AAAA,KAChD;AAAA,EACD;AACD","file":"chunk-5BOUGXZO.js","sourcesContent":["import { AsyncContextView, Context as SyncContext, TrackedAsyncContext } from '../context'\nimport { FlowcraftError } from '../errors'\nimport type { IAsyncContext, ISerializer, WorkflowError, WorkflowResult } from '../types'\n\nexport class WorkflowState<TContext extends Record<string, any>> {\n\tprivate _completedNodes = new Set<string>()\n\tprivate errors: WorkflowError[] = []\n\tprivate anyFallbackExecuted = false\n\tprivate context: IAsyncContext<TContext>\n\tprivate _isAwaiting = false\n\tprivate _awaitingNodeIds = new Set<string>()\n\tprivate _awaitingDetails = new Map<string, any>()\n\n\tconstructor(initialData: Partial<TContext>) {\n\t\tthis.context = new TrackedAsyncContext(new AsyncContextView(new SyncContext<TContext>(initialData)))\n\t\tif ((initialData as any)._awaitingNodeIds) {\n\t\t\tthis._isAwaiting = true\n\t\t\tconst awaitingIds = (initialData as any)._awaitingNodeIds\n\t\t\tif (Array.isArray(awaitingIds)) {\n\t\t\t\tfor (const id of awaitingIds) {\n\t\t\t\t\tthis._awaitingNodeIds.add(id)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif ((initialData as any)._awaitingDetails) {\n\t\t\tthis._awaitingDetails = new Map(Object.entries((initialData as any)._awaitingDetails))\n\t\t}\n\t\tfor (const key of Object.keys(initialData)) {\n\t\t\tif (key.startsWith('_outputs.')) {\n\t\t\t\tconst nodeId = key.substring('_outputs.'.length)\n\t\t\t\tthis._completedNodes.add(nodeId)\n\t\t\t}\n\t\t}\n\t}\n\n\tasync addCompletedNode(nodeId: string, output: any) {\n\t\tthis._completedNodes.add(nodeId)\n\t\tawait this.context.set(`_outputs.${nodeId}` as any, output)\n\t}\n\n\taddError(nodeId: string, error: Error) {\n\t\tconst flowcraftError = new FlowcraftError(error.message, {\n\t\t\tcause: error,\n\t\t\tnodeId,\n\t\t\tisFatal: false,\n\t\t})\n\t\tthis.errors.push({\n\t\t\t...flowcraftError,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\toriginalError: error, // legacy compatibility\n\t\t})\n\t}\n\n\tclearError(nodeId: string) {\n\t\tthis.errors = this.errors.filter((err) => err.nodeId !== nodeId)\n\t}\n\n\tmarkFallbackExecuted() {\n\t\tthis.anyFallbackExecuted = true\n\t}\n\n\tgetContext(): IAsyncContext<TContext> {\n\t\treturn this.context\n\t}\n\n\tgetCompletedNodes(): Set<string> {\n\t\treturn new Set(this._completedNodes)\n\t}\n\n\tgetErrors(): WorkflowError[] {\n\t\treturn this.errors\n\t}\n\n\tgetAnyFallbackExecuted(): boolean {\n\t\treturn this.anyFallbackExecuted\n\t}\n\n\tasync markAsAwaiting(nodeId: string, details?: any): Promise<void> {\n\t\tthis._isAwaiting = true\n\t\tthis._awaitingNodeIds.add(nodeId)\n\t\tif (details) {\n\t\t\tthis._awaitingDetails.set(nodeId, details)\n\t\t}\n\t\tawait this.context.set('_awaitingNodeIds' as any, Array.from(this._awaitingNodeIds))\n\t\tawait this.context.set('_awaitingDetails' as any, Object.fromEntries(this._awaitingDetails))\n\t}\n\n\tisAwaiting(): boolean {\n\t\treturn this._isAwaiting && this._awaitingNodeIds.size > 0\n\t}\n\n\tgetAwaitingNodeIds(): string[] {\n\t\treturn Array.from(this._awaitingNodeIds)\n\t}\n\n\tgetAwaitingDetails(nodeId: string): any {\n\t\treturn this._awaitingDetails.get(nodeId)\n\t}\n\n\tclearAwaiting(nodeId?: string): void {\n\t\tif (nodeId) {\n\t\t\tthis._awaitingNodeIds.delete(nodeId)\n\t\t\tthis._awaitingDetails.delete(nodeId)\n\t\t} else {\n\t\t\tthis._awaitingNodeIds.clear()\n\t\t\tthis._awaitingDetails.clear()\n\t\t}\n\t\tthis._isAwaiting = this._awaitingNodeIds.size > 0\n\n\t\tif (this._awaitingNodeIds.size > 0) {\n\t\t\tthis.context.set('_awaitingNodeIds' as any, Array.from(this._awaitingNodeIds))\n\t\t\tthis.context.set('_awaitingDetails' as any, Object.fromEntries(this._awaitingDetails))\n\t\t} else {\n\t\t\tthis.context.delete('_awaitingNodeIds' as any)\n\t\t\tthis.context.delete('_awaitingDetails' as any)\n\t\t}\n\t}\n\n\tgetStatus(isTraversalComplete = false): WorkflowResult['status'] {\n\t\tif (this._isAwaiting) return 'awaiting'\n\t\tif (this.anyFallbackExecuted) return 'completed'\n\t\tif (this.errors.length > 0) return 'failed'\n\t\tif (isTraversalComplete) return 'completed'\n\t\treturn 'stalled'\n\t}\n\n\tasync toResult(serializer: ISerializer): Promise<WorkflowResult<TContext>> {\n\t\tconst contextJSON = (await this.context.toJSON()) as TContext\n\t\tif (!this._isAwaiting && (contextJSON as any)._awaitingNodeIds) {\n\t\t\tdelete (contextJSON as any)._awaitingNodeIds\n\t\t\tdelete (contextJSON as any)._awaitingDetails\n\t\t}\n\t\treturn {\n\t\t\tcontext: contextJSON,\n\t\t\tserializedContext: serializer.serialize(contextJSON),\n\t\t\tstatus: this.getStatus(),\n\t\t\terrors: this.errors.length > 0 ? this.errors : undefined,\n\t\t}\n\t}\n}\n"]}
@@ -1,23 +1,34 @@
1
- import { FlowRuntime } from './chunk-HKX7WQLS.js';
2
- import { analyzeBlueprint } from './chunk-233SESC2.js';
1
+ import { FlowRuntime } from './chunk-OPRR4TAO.js';
2
+ import { analyzeBlueprint } from './chunk-ZLW4QOTS.js';
3
+ import { ConsoleLogger } from './chunk-4PELJWF7.js';
3
4
  import { JsonSerializer } from './chunk-CYHZ2YVH.js';
5
+ import { TrackedAsyncContext } from './chunk-XDI4TJHA.js';
4
6
 
5
7
  // src/runtime/adapter.ts
6
8
  var BaseDistributedAdapter = class {
7
9
  runtime;
8
10
  store;
9
11
  serializer;
12
+ logger;
10
13
  constructor(options) {
11
- this.runtime = new FlowRuntime(options.runtimeOptions);
14
+ const runtimeOptions = {
15
+ ...options.runtimeOptions,
16
+ dependencies: {
17
+ ...options.runtimeOptions.dependencies,
18
+ adapter: this
19
+ }
20
+ };
21
+ this.runtime = new FlowRuntime(runtimeOptions);
12
22
  this.store = options.coordinationStore;
13
23
  this.serializer = options.runtimeOptions.serializer || new JsonSerializer();
14
- console.log("[Adapter] BaseDistributedAdapter initialized.");
24
+ this.logger = options.runtimeOptions.logger || new ConsoleLogger();
25
+ this.logger.info("[Adapter] BaseDistributedAdapter initialized.");
15
26
  }
16
27
  /**
17
28
  * Starts the worker, which begins listening for and processing jobs from the queue.
18
29
  */
19
30
  start() {
20
- console.log("[Adapter] Starting worker...");
31
+ this.logger.info("[Adapter] Starting worker...");
21
32
  this.processJobs(this.handleJob.bind(this));
22
33
  }
23
34
  /**
@@ -35,28 +46,52 @@ var BaseDistributedAdapter = class {
35
46
  const blueprint = this.runtime.options.blueprints?.[blueprintId];
36
47
  if (!blueprint) {
37
48
  const reason = `Blueprint with ID '${blueprintId}' not found in the worker's runtime registry.`;
38
- console.error(`[Adapter] FATAL: ${reason}`);
49
+ this.logger.error(`[Adapter] FATAL: ${reason}`);
39
50
  await this.publishFinalResult(runId, { status: "failed", reason });
40
51
  return;
41
52
  }
42
53
  const context = this.createContext(runId);
54
+ const storedVersion = await context.get("blueprintVersion");
55
+ const currentVersion = blueprint.metadata?.version || null;
56
+ if (storedVersion !== currentVersion) {
57
+ const reason = `Blueprint version mismatch: stored version '${storedVersion}', current version '${currentVersion}'. Rejecting job to prevent state corruption.`;
58
+ this.logger.warn(`[Adapter] Version mismatch for run ${runId}, node ${nodeId}: ${reason}`);
59
+ return;
60
+ }
43
61
  const hasBlueprintId = await context.has("blueprintId");
44
62
  if (!hasBlueprintId) {
45
63
  await context.set("blueprintId", blueprintId);
46
- const blueprintKey = `flowcraft:blueprint:${runId}`;
47
- await this.store.setIfNotExist(blueprintKey, blueprintId, 3600);
64
+ await context.set("blueprintVersion", blueprint.metadata?.version || null);
65
+ const blueprintKey2 = `flowcraft:blueprint:${runId}`;
66
+ await this.store.setIfNotExist(blueprintKey2, blueprintId, 3600);
48
67
  }
49
- const workerState = {
50
- getContext: () => context,
51
- markFallbackExecuted: () => {
52
- },
53
- addError: (nodeId2, error) => {
54
- console.error(`[Adapter] Error in node ${nodeId2}:`, error);
55
- }
56
- };
68
+ const joinLockKey = `flowcraft:joinlock:${runId}:${nodeId}`;
69
+ const fanInKey = `flowcraft:fanin:${runId}:${nodeId}`;
70
+ const blueprintKey = `flowcraft:blueprint:${runId}`;
71
+ const heartbeatInterval = setInterval(async () => {
72
+ await this.store.extendTTL(joinLockKey, 3600);
73
+ await this.store.extendTTL(fanInKey, 3600);
74
+ await this.store.extendTTL(blueprintKey, 3600);
75
+ this.logger.debug(`[Adapter] Extended TTLs for run ${runId}, node ${nodeId}`);
76
+ }, 18e5);
57
77
  try {
78
+ const workerState = {
79
+ getContext: () => context,
80
+ markFallbackExecuted: () => {
81
+ },
82
+ addError: (nodeId2, error) => {
83
+ this.logger.error(`[Adapter] Error in node ${nodeId2}:`, error);
84
+ }
85
+ };
58
86
  const result = await this.runtime.executeNode(blueprint, nodeId, workerState);
59
87
  await context.set(`_outputs.${nodeId}`, result.output);
88
+ if (context instanceof TrackedAsyncContext) {
89
+ const deltas = context.getDeltas();
90
+ if (deltas.length > 0) {
91
+ await context.patch(deltas);
92
+ context.clearDeltas();
93
+ }
94
+ }
60
95
  const analysis = analyzeBlueprint(blueprint);
61
96
  const isTerminalNode = analysis.terminalNodeIds.includes(nodeId);
62
97
  if (isTerminalNode) {
@@ -69,7 +104,7 @@ var BaseDistributedAdapter = class {
69
104
  }
70
105
  const allTerminalNodesCompleted = analysis.terminalNodeIds.every((terminalId) => completedNodes.has(terminalId));
71
106
  if (allTerminalNodesCompleted) {
72
- console.log(`[Adapter] All terminal nodes completed for Run ID: ${runId}. Declaring workflow complete.`);
107
+ this.logger.info(`[Adapter] All terminal nodes completed for Run ID: ${runId}. Declaring workflow complete.`);
73
108
  const finalContext = await context.toJSON();
74
109
  const finalResult = {
75
110
  context: finalContext,
@@ -80,35 +115,39 @@ var BaseDistributedAdapter = class {
80
115
  status: "completed",
81
116
  payload: finalResult
82
117
  });
118
+ clearInterval(heartbeatInterval);
83
119
  return;
84
120
  } else {
85
- console.log(
121
+ this.logger.info(
86
122
  `[Adapter] Terminal node '${nodeId}' completed for Run ID '${runId}', but other terminal nodes are still running.`
87
123
  );
88
124
  }
89
125
  }
90
126
  const nextNodes = await this.runtime.determineNextNodes(blueprint, nodeId, result, context, runId);
91
127
  if (nextNodes.length === 0 && !isTerminalNode) {
92
- console.log(
128
+ this.logger.info(
93
129
  `[Adapter] Non-terminal node '${nodeId}' reached end of branch for Run ID '${runId}'. This branch will now terminate.`
94
130
  );
131
+ clearInterval(heartbeatInterval);
95
132
  return;
96
133
  }
97
134
  for (const { node: nextNodeDef, edge } of nextNodes) {
98
135
  await this.runtime.applyEdgeTransform(edge, result, nextNodeDef, context);
99
136
  const isReady = await this.isReadyForFanIn(runId, blueprint, nextNodeDef.id);
100
137
  if (isReady) {
101
- console.log(`[Adapter] Node '${nextNodeDef.id}' is ready. Enqueuing job.`);
138
+ this.logger.info(`[Adapter] Node '${nextNodeDef.id}' is ready. Enqueuing job.`);
102
139
  await this.enqueueJob({ runId, blueprintId, nodeId: nextNodeDef.id });
103
140
  } else {
104
- console.log(`[Adapter] Node '${nextNodeDef.id}' is waiting for other predecessors to complete.`);
141
+ this.logger.info(`[Adapter] Node '${nextNodeDef.id}' is waiting for other predecessors to complete.`);
105
142
  }
106
143
  }
107
144
  } catch (error) {
108
145
  const reason = error.message || "Unknown execution error";
109
- console.error(`[Adapter] FATAL: Job for node '${nodeId}' failed for Run ID '${runId}': ${reason}`);
146
+ this.logger.error(`[Adapter] FATAL: Job for node '${nodeId}' failed for Run ID '${runId}': ${reason}`);
110
147
  await this.publishFinalResult(runId, { status: "failed", reason });
111
148
  await this.writePoisonPillForSuccessors(runId, blueprint, nodeId);
149
+ } finally {
150
+ clearInterval(heartbeatInterval);
112
151
  }
113
152
  }
114
153
  /**
@@ -127,7 +166,7 @@ var BaseDistributedAdapter = class {
127
166
  const poisonKey = `flowcraft:fanin:poison:${runId}:${targetNodeId}`;
128
167
  const isPoisoned = await this.store.get(poisonKey);
129
168
  if (isPoisoned) {
130
- console.log(`[Adapter] Node '${targetNodeId}' is poisoned due to failed predecessor. Failing immediately.`);
169
+ this.logger.info(`[Adapter] Node '${targetNodeId}' is poisoned due to failed predecessor. Failing immediately.`);
131
170
  throw new Error(`Node '${targetNodeId}' failed due to poisoned predecessor in run '${runId}'`);
132
171
  }
133
172
  if (joinStrategy === "any") {
@@ -137,7 +176,9 @@ var BaseDistributedAdapter = class {
137
176
  const cancelKey = `flowcraft:fanin:cancel:${runId}:${targetNodeId}`;
138
177
  const isCancelled = !await this.store.setIfNotExist(cancelKey, "cancelled", 3600);
139
178
  if (isCancelled) {
140
- console.log(`[Adapter] Node '${targetNodeId}' is cancelled due to failed predecessor. Failing immediately.`);
179
+ this.logger.info(
180
+ `[Adapter] Node '${targetNodeId}' is cancelled due to failed predecessor. Failing immediately.`
181
+ );
141
182
  throw new Error(`Node '${targetNodeId}' failed due to cancelled predecessor in run '${runId}'`);
142
183
  }
143
184
  return false;
@@ -175,6 +216,9 @@ var BaseDistributedAdapter = class {
175
216
  }
176
217
  }
177
218
  const blueprint = this.runtime.options.blueprints?.[blueprintId];
219
+ if (blueprint && !await context.has("blueprintVersion")) {
220
+ await context.set("blueprintVersion", blueprint.metadata?.version || null);
221
+ }
178
222
  if (!blueprint) {
179
223
  throw new Error(`Cannot reconcile runId '${runId}': Blueprint with ID '${blueprintId}' not found.`);
180
224
  }
@@ -193,7 +237,7 @@ var BaseDistributedAdapter = class {
193
237
  const poisonKey = `flowcraft:fanin:poison:${runId}:${nodeId}`;
194
238
  const isPoisoned = await this.store.get(poisonKey);
195
239
  if (isPoisoned) {
196
- console.log(`[Adapter] Reconciling: Node '${nodeId}' is poisoned, skipping.`, { runId });
240
+ this.logger.info(`[Adapter] Reconciling: Node '${nodeId}' is poisoned, skipping.`, { runId });
197
241
  continue;
198
242
  }
199
243
  let shouldEnqueue = false;
@@ -202,18 +246,18 @@ var BaseDistributedAdapter = class {
202
246
  if (await this.store.setIfNotExist(lockKey, "locked-by-reconcile", 3600)) {
203
247
  shouldEnqueue = true;
204
248
  } else {
205
- console.log(`[Adapter] Reconciling: Node '${nodeId}' is an 'any' join and is already locked.`, { runId });
249
+ this.logger.info(`[Adapter] Reconciling: Node '${nodeId}' is an 'any' join and is already locked.`, { runId });
206
250
  }
207
251
  } else {
208
252
  const lockKey = `flowcraft:nodelock:${runId}:${nodeId}`;
209
253
  if (await this.store.setIfNotExist(lockKey, "locked", 120)) {
210
254
  shouldEnqueue = true;
211
255
  } else {
212
- console.log(`[Adapter] Reconciling: Node '${nodeId}' is already locked.`, { runId });
256
+ this.logger.info(`[Adapter] Reconciling: Node '${nodeId}' is already locked.`, { runId });
213
257
  }
214
258
  }
215
259
  if (shouldEnqueue) {
216
- console.log(`[Adapter] Reconciling: Enqueuing ready job for node '${nodeId}'`, { runId });
260
+ this.logger.info(`[Adapter] Reconciling: Enqueuing ready job for node '${nodeId}'`, { runId });
217
261
  await this.enqueueJob({ runId, blueprintId: blueprint.id, nodeId });
218
262
  enqueuedNodes.add(nodeId);
219
263
  }
@@ -258,13 +302,13 @@ var BaseDistributedAdapter = class {
258
302
  if (joinStrategy === "all") {
259
303
  const poisonKey = `flowcraft:fanin:poison:${runId}:${successor.id}`;
260
304
  await this.store.setIfNotExist(poisonKey, "poisoned", 3600);
261
- console.log(
305
+ this.logger.info(
262
306
  `[Adapter] Wrote poison pill for 'all' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`
263
307
  );
264
308
  } else if (joinStrategy === "any") {
265
309
  const cancelKey = `flowcraft:fanin:cancel:${runId}:${successor.id}`;
266
310
  await this.store.setIfNotExist(cancelKey, "cancelled", 3600);
267
- console.log(
311
+ this.logger.info(
268
312
  `[Adapter] Wrote cancellation pill for 'any' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`
269
313
  );
270
314
  }
@@ -274,5 +318,5 @@ var BaseDistributedAdapter = class {
274
318
  };
275
319
 
276
320
  export { BaseDistributedAdapter };
277
- //# sourceMappingURL=chunk-ZNL7ZXPR.js.map
278
- //# sourceMappingURL=chunk-ZNL7ZXPR.js.map
321
+ //# sourceMappingURL=chunk-5XPW6YEP.js.map
322
+ //# sourceMappingURL=chunk-5XPW6YEP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runtime/adapter.ts"],"names":["blueprintKey","nodeId"],"mappings":";;;;;;;AAiDO,IAAe,yBAAf,MAAsC;AAAA,EACzB,OAAA;AAAA,EACA,KAAA;AAAA,EACA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AAA,CAAK,MAAA,CAAO,IAAA;AAAA,YACX,CAAA,uDAAA,EAA0D,SAAA,CAAU,EAAE,CAAA,6BAAA,EAAgC,YAAY,CAAA,CAAA;AAAA,WACnH;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD","file":"chunk-5XPW6YEP.js","sourcesContent":["import { analyzeBlueprint } from '../analysis'\nimport { TrackedAsyncContext } from '../context'\nimport { ConsoleLogger } from '../logger'\nimport { JsonSerializer } from '../serializer'\nimport type {\n\tIAsyncContext,\n\tILogger,\n\tISerializer,\n\tNodeResult,\n\tRuntimeOptions,\n\tWorkflowBlueprint,\n\tWorkflowResult,\n} from '../types'\nimport { FlowRuntime } from './runtime'\n\n/**\n * Defines the contract for an atomic, distributed key-value store required by\n * the adapter for coordination tasks like fan-in joins and locking.\n */\nexport interface ICoordinationStore {\n\t/** Atomically increments a key and returns the new value. Ideal for 'all' joins. */\n\tincrement: (key: string, ttlSeconds: number) => Promise<number>\n\t/** Sets a key only if it does not already exist. Ideal for 'any' joins (locking). */\n\tsetIfNotExist: (key: string, value: string, ttlSeconds: number) => Promise<boolean>\n\t/** Extends the TTL of an existing key. Used for heartbeat mechanism in long-running jobs. */\n\textendTTL: (key: string, ttlSeconds: number) => Promise<boolean>\n\t/** Deletes a key. Used for cleanup. */\n\tdelete: (key: string) => Promise<void>\n\t/** Gets the value of a key. */\n\tget: (key: string) => Promise<string | undefined>\n}\n\n/** Configuration options for constructing a BaseDistributedAdapter. */\nexport interface AdapterOptions {\n\truntimeOptions: RuntimeOptions<any>\n\tcoordinationStore: ICoordinationStore\n}\n\n/** The data payload expected for a job in the queue. */\nexport interface JobPayload {\n\trunId: string\n\tblueprintId: string\n\tnodeId: string\n}\n\n/**\n * The base class for all distributed adapters. It handles the technology-agnostic\n * orchestration logic and leaves queue-specific implementation to subclasses.\n */\nexport abstract class BaseDistributedAdapter {\n\tprotected readonly runtime: FlowRuntime<any, any>\n\tprotected readonly store: ICoordinationStore\n\tprotected readonly serializer: ISerializer\n\tprotected readonly logger: ILogger\n\n\tconstructor(options: AdapterOptions) {\n\t\tconst runtimeOptions = {\n\t\t\t...options.runtimeOptions,\n\t\t\tdependencies: {\n\t\t\t\t...options.runtimeOptions.dependencies,\n\t\t\t\tadapter: this,\n\t\t\t} as any,\n\t\t}\n\t\tthis.runtime = new FlowRuntime(runtimeOptions)\n\t\tthis.store = options.coordinationStore\n\t\tthis.serializer = options.runtimeOptions.serializer || new JsonSerializer()\n\t\tthis.logger = options.runtimeOptions.logger || new ConsoleLogger()\n\t\tthis.logger.info('[Adapter] BaseDistributedAdapter initialized.')\n\t}\n\n\t/**\n\t * Starts the worker, which begins listening for and processing jobs from the queue.\n\t */\n\tpublic start(): void {\n\t\tthis.logger.info('[Adapter] Starting worker...')\n\t\tthis.processJobs(this.handleJob.bind(this))\n\t}\n\n\t/**\n\t * Creates a technology-specific distributed context for a given workflow run.\n\t * @param runId The unique ID for the workflow execution.\n\t */\n\tprotected abstract createContext(runId: string): IAsyncContext<Record<string, any>>\n\t/**\n\t * Sets up the listener for the message queue. The implementation should call the\n\t * provided `handler` function for each new job received.\n\t * @param handler The core logic to execute for each job.\n\t */\n\tprotected abstract processJobs(handler: (job: JobPayload) => Promise<void>): void\n\n\t/**\n\t * Enqueues a new job onto the message queue.\n\t * @param job The payload for the job to be enqueued.\n\t */\n\tprotected abstract enqueueJob(job: JobPayload): Promise<void>\n\n\t/**\n\t * Publishes the final result of a completed or failed workflow run.\n\t * @param runId The unique ID of the workflow run.\n\t * @param result The final status and payload of the workflow.\n\t */\n\tprotected abstract publishFinalResult(\n\t\trunId: string,\n\t\tresult: {\n\t\t\tstatus: 'completed' | 'failed'\n\t\t\tpayload?: WorkflowResult\n\t\t\treason?: string\n\t\t},\n\t): Promise<void>\n\n\t/**\n\t * Registers a webhook endpoint for a specific node in a workflow run.\n\t * @param runId The unique ID of the workflow run.\n\t * @param nodeId The ID of the node that will wait for the webhook.\n\t * @returns The URL and event name for the webhook.\n\t */\n\tpublic abstract registerWebhookEndpoint(runId: string, nodeId: string): Promise<{ url: string; event: string }>\n\n\t/**\n\t * Hook called at the start of job processing. Subclasses can override this\n\t * to perform additional setup (e.g., timestamp tracking for reconciliation).\n\t */\n\tprotected async onJobStart(_runId: string, _blueprintId: string, _nodeId: string): Promise<void> {\n\t\t// default implementation does nothing\n\t}\n\n\t/**\n\t * The main handler for processing a single job from the queue.\n\t */\n\tprotected async handleJob(job: JobPayload): Promise<void> {\n\t\tconst { runId, blueprintId, nodeId } = job\n\n\t\tawait this.onJobStart(runId, blueprintId, nodeId)\n\n\t\tconst blueprint = this.runtime.options.blueprints?.[blueprintId]\n\t\tif (!blueprint) {\n\t\t\tconst reason = `Blueprint with ID '${blueprintId}' not found in the worker's runtime registry.`\n\t\t\tthis.logger.error(`[Adapter] FATAL: ${reason}`)\n\t\t\tawait this.publishFinalResult(runId, { status: 'failed', reason })\n\t\t\treturn\n\t\t}\n\n\t\tconst context = this.createContext(runId)\n\n\t\tconst storedVersion = await context.get('blueprintVersion' as any)\n\t\tconst currentVersion = blueprint.metadata?.version || null\n\t\tif (storedVersion !== currentVersion) {\n\t\t\tconst reason = `Blueprint version mismatch: stored version '${storedVersion}', current version '${currentVersion}'. Rejecting job to prevent state corruption.`\n\t\t\tthis.logger.warn(`[Adapter] Version mismatch for run ${runId}, node ${nodeId}: ${reason}`)\n\t\t\treturn\n\t\t}\n\n\t\t// persist the blueprintId and version for the reconcile method to find later\n\t\tconst hasBlueprintId = await context.has('blueprintId' as any)\n\t\tif (!hasBlueprintId) {\n\t\t\tawait context.set('blueprintId' as any, blueprintId)\n\t\t\tawait context.set('blueprintVersion' as any, blueprint.metadata?.version || null)\n\t\t\t// also store in coordination store as fallback\n\t\t\tconst blueprintKey = `flowcraft:blueprint:${runId}`\n\t\t\tawait this.store.setIfNotExist(blueprintKey, blueprintId, 3600)\n\t\t}\n\n\t\t// heartbeat to extend TTLs of coordination keys for long-running jobs\n\t\tconst joinLockKey = `flowcraft:joinlock:${runId}:${nodeId}`\n\t\tconst fanInKey = `flowcraft:fanin:${runId}:${nodeId}`\n\t\tconst blueprintKey = `flowcraft:blueprint:${runId}`\n\t\tconst heartbeatInterval = setInterval(async () => {\n\t\t\tawait this.store.extendTTL(joinLockKey, 3600)\n\t\t\tawait this.store.extendTTL(fanInKey, 3600)\n\t\t\tawait this.store.extendTTL(blueprintKey, 3600)\n\t\t\tthis.logger.debug(`[Adapter] Extended TTLs for run ${runId}, node ${nodeId}`)\n\t\t}, 1800000) // 30 minutes\n\n\t\ttry {\n\t\t\tconst workerState = {\n\t\t\t\tgetContext: () => context,\n\t\t\t\tmarkFallbackExecuted: () => {},\n\t\t\t\taddError: (nodeId: string, error: Error) => {\n\t\t\t\t\tthis.logger.error(`[Adapter] Error in node ${nodeId}:`, error)\n\t\t\t\t},\n\t\t\t} as any\n\n\t\t\tconst result: NodeResult<any, any> = await this.runtime.executeNode(blueprint, nodeId, workerState)\n\t\t\tawait context.set(`_outputs.${nodeId}` as any, result.output)\n\n\t\t\tif (context instanceof TrackedAsyncContext) {\n\t\t\t\tconst deltas = context.getDeltas()\n\t\t\t\tif (deltas.length > 0) {\n\t\t\t\t\tawait context.patch(deltas)\n\t\t\t\t\tcontext.clearDeltas()\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst analysis = analyzeBlueprint(blueprint)\n\t\t\tconst isTerminalNode = analysis.terminalNodeIds.includes(nodeId)\n\n\t\t\tif (isTerminalNode) {\n\t\t\t\tconst allContextKeys = Object.keys(await context.toJSON())\n\t\t\t\tconst completedNodes = new Set<string>()\n\t\t\t\tfor (const key of allContextKeys) {\n\t\t\t\t\tif (key.startsWith('_outputs.')) {\n\t\t\t\t\t\tcompletedNodes.add(key.substring('_outputs.'.length))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst allTerminalNodesCompleted = analysis.terminalNodeIds.every((terminalId) => completedNodes.has(terminalId))\n\n\t\t\t\tif (allTerminalNodesCompleted) {\n\t\t\t\t\tthis.logger.info(`[Adapter] All terminal nodes completed for Run ID: ${runId}. Declaring workflow complete.`)\n\t\t\t\t\tconst finalContext = await context.toJSON()\n\t\t\t\t\tconst finalResult: WorkflowResult = {\n\t\t\t\t\t\tcontext: finalContext,\n\t\t\t\t\t\tserializedContext: this.serializer.serialize(finalContext),\n\t\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\t}\n\t\t\t\t\tawait this.publishFinalResult(runId, {\n\t\t\t\t\t\tstatus: 'completed',\n\t\t\t\t\t\tpayload: finalResult,\n\t\t\t\t\t})\n\t\t\t\t\tclearInterval(heartbeatInterval)\n\t\t\t\t\treturn\n\t\t\t\t} else {\n\t\t\t\t\tthis.logger.info(\n\t\t\t\t\t\t`[Adapter] Terminal node '${nodeId}' completed for Run ID '${runId}', but other terminal nodes are still running.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst nextNodes = await this.runtime.determineNextNodes(blueprint, nodeId, result, context, runId)\n\n\t\t\t// stop if a branch terminates but it wasn't a terminal node\n\t\t\tif (nextNodes.length === 0 && !isTerminalNode) {\n\t\t\t\tthis.logger.info(\n\t\t\t\t\t`[Adapter] Non-terminal node '${nodeId}' reached end of branch for Run ID '${runId}'. This branch will now terminate.`,\n\t\t\t\t)\n\t\t\t\tclearInterval(heartbeatInterval)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tfor (const { node: nextNodeDef, edge } of nextNodes) {\n\t\t\t\tawait this.runtime.applyEdgeTransform(edge, result, nextNodeDef, context)\n\t\t\t\tconst isReady = await this.isReadyForFanIn(runId, blueprint, nextNodeDef.id)\n\t\t\t\tif (isReady) {\n\t\t\t\t\tthis.logger.info(`[Adapter] Node '${nextNodeDef.id}' is ready. Enqueuing job.`)\n\t\t\t\t\tawait this.enqueueJob({ runId, blueprintId, nodeId: nextNodeDef.id })\n\t\t\t\t} else {\n\t\t\t\t\tthis.logger.info(`[Adapter] Node '${nextNodeDef.id}' is waiting for other predecessors to complete.`)\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error: any) {\n\t\t\tconst reason = error.message || 'Unknown execution error'\n\t\t\tthis.logger.error(`[Adapter] FATAL: Job for node '${nodeId}' failed for Run ID '${runId}': ${reason}`)\n\t\t\tawait this.publishFinalResult(runId, { status: 'failed', reason })\n\t\t\tawait this.writePoisonPillForSuccessors(runId, blueprint, nodeId)\n\t\t} finally {\n\t\t\tclearInterval(heartbeatInterval)\n\t\t}\n\t}\n\n\t/**\n\t * Encapsulates the fan-in join logic using the coordination store.\n\t */\n\tprotected async isReadyForFanIn(runId: string, blueprint: WorkflowBlueprint, targetNodeId: string): Promise<boolean> {\n\t\tconst targetNode = blueprint.nodes.find((n) => n.id === targetNodeId)\n\t\tif (!targetNode) {\n\t\t\tthrow new Error(`Node '${targetNodeId}' not found in blueprint`)\n\t\t}\n\t\tconst joinStrategy = targetNode.config?.joinStrategy || 'all'\n\t\tconst predecessors = blueprint.edges.filter((e) => e.target === targetNodeId)\n\n\t\tif (predecessors.length <= 1) {\n\t\t\treturn true\n\t\t}\n\n\t\tconst poisonKey = `flowcraft:fanin:poison:${runId}:${targetNodeId}`\n\t\tconst isPoisoned = await this.store.get(poisonKey)\n\t\tif (isPoisoned) {\n\t\t\tthis.logger.info(`[Adapter] Node '${targetNodeId}' is poisoned due to failed predecessor. Failing immediately.`)\n\t\t\tthrow new Error(`Node '${targetNodeId}' failed due to poisoned predecessor in run '${runId}'`)\n\t\t}\n\n\t\tif (joinStrategy === 'any') {\n\t\t\tconst lockKey = `flowcraft:joinlock:${runId}:${targetNodeId}`\n\t\t\tconst isLocked = await this.store.setIfNotExist(lockKey, 'locked', 3600)\n\t\t\tif (!isLocked) {\n\t\t\t\t// check if cancelled\n\t\t\t\tconst cancelKey = `flowcraft:fanin:cancel:${runId}:${targetNodeId}`\n\t\t\t\tconst isCancelled = !(await this.store.setIfNotExist(cancelKey, 'cancelled', 3600))\n\t\t\t\tif (isCancelled) {\n\t\t\t\t\tthis.logger.info(\n\t\t\t\t\t\t`[Adapter] Node '${targetNodeId}' is cancelled due to failed predecessor. Failing immediately.`,\n\t\t\t\t\t)\n\t\t\t\t\tthrow new Error(`Node '${targetNodeId}' failed due to cancelled predecessor in run '${runId}'`)\n\t\t\t\t}\n\t\t\t\treturn false // already locked by another predecessor\n\t\t\t}\n\t\t\treturn true\n\t\t} else {\n\t\t\tconst fanInKey = `flowcraft:fanin:${runId}:${targetNodeId}`\n\t\t\tconst readyCount = await this.store.increment(fanInKey, 3600)\n\t\t\tif (readyCount >= predecessors.length) {\n\t\t\t\tawait this.store.delete(fanInKey)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t}\n\n\t/**\n\t * Reconciles the state of a workflow run. It inspects the persisted\n\t * context to find completed nodes, determines the next set of executable\n\t * nodes (the frontier), and enqueues jobs for them if they aren't\n\t * already running. This is the core of the resume functionality.\n\t *\n\t * @param runId The unique ID of the workflow execution to reconcile.\n\t * @returns The set of node IDs that were enqueued for execution.\n\t */\n\tpublic async reconcile(runId: string): Promise<Set<string>> {\n\t\tconst context = this.createContext(runId)\n\t\tlet blueprintId = (await context.get('blueprintId' as any)) as string | undefined\n\n\t\tif (!blueprintId) {\n\t\t\t// fallback to coordination store\n\t\t\tconst blueprintKey = `flowcraft:blueprint:${runId}`\n\t\t\tblueprintId = await this.store.get(blueprintKey)\n\t\t\tif (blueprintId) {\n\t\t\t\t// set it back in context for future use\n\t\t\t\tawait context.set('blueprintId' as any, blueprintId)\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Cannot reconcile runId '${runId}': blueprintId not found in context or coordination store.`)\n\t\t\t}\n\t\t}\n\t\tconst blueprint = this.runtime.options.blueprints?.[blueprintId]\n\t\tif (blueprint && !(await context.has('blueprintVersion' as any))) {\n\t\t\tawait context.set('blueprintVersion' as any, blueprint.metadata?.version || null)\n\t\t}\n\t\tif (!blueprint) {\n\t\t\tthrow new Error(`Cannot reconcile runId '${runId}': Blueprint with ID '${blueprintId}' not found.`)\n\t\t}\n\n\t\tconst state = await context.toJSON()\n\t\tconst completedNodes = new Set<string>()\n\t\tfor (const key of Object.keys(state)) {\n\t\t\tif (key.startsWith('_outputs.')) {\n\t\t\t\tcompletedNodes.add(key.substring('_outputs.'.length))\n\t\t\t}\n\t\t}\n\n\t\tconst frontier = this.calculateResumedFrontier(blueprint, completedNodes)\n\n\t\tconst enqueuedNodes = new Set<string>()\n\t\tfor (const nodeId of frontier) {\n\t\t\tconst nodeDef = blueprint.nodes.find((n) => n.id === nodeId)\n\t\t\tconst joinStrategy = nodeDef?.config?.joinStrategy || 'all'\n\n\t\t\tconst poisonKey = `flowcraft:fanin:poison:${runId}:${nodeId}`\n\t\t\tconst isPoisoned = await this.store.get(poisonKey)\n\t\t\tif (isPoisoned) {\n\t\t\t\tthis.logger.info(`[Adapter] Reconciling: Node '${nodeId}' is poisoned, skipping.`, { runId })\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tlet shouldEnqueue = false\n\n\t\t\tif (joinStrategy === 'any') {\n\t\t\t\t// acquire the permanent join lock\n\t\t\t\tconst lockKey = `flowcraft:joinlock:${runId}:${nodeId}`\n\t\t\t\tif (await this.store.setIfNotExist(lockKey, 'locked-by-reconcile', 3600)) {\n\t\t\t\t\tshouldEnqueue = true\n\t\t\t\t} else {\n\t\t\t\t\tthis.logger.info(`[Adapter] Reconciling: Node '${nodeId}' is an 'any' join and is already locked.`, { runId })\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// 'all' joins and single-predecessor nodes use a temporary lock\n\t\t\t\tconst lockKey = `flowcraft:nodelock:${runId}:${nodeId}`\n\t\t\t\tif (await this.store.setIfNotExist(lockKey, 'locked', 120)) {\n\t\t\t\t\tshouldEnqueue = true\n\t\t\t\t} else {\n\t\t\t\t\tthis.logger.info(`[Adapter] Reconciling: Node '${nodeId}' is already locked.`, { runId })\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (shouldEnqueue) {\n\t\t\t\tthis.logger.info(`[Adapter] Reconciling: Enqueuing ready job for node '${nodeId}'`, { runId })\n\t\t\t\tawait this.enqueueJob({ runId, blueprintId: blueprint.id, nodeId })\n\t\t\t\tenqueuedNodes.add(nodeId)\n\t\t\t}\n\t\t}\n\n\t\treturn enqueuedNodes\n\t}\n\n\tprivate calculateResumedFrontier(blueprint: WorkflowBlueprint, completedNodes: Set<string>): Set<string> {\n\t\tconst newFrontier = new Set<string>()\n\t\tconst allPredecessors = new Map<string, Set<string>>()\n\t\t// (logic extracted from the GraphTraverser)\n\t\tfor (const node of blueprint.nodes) {\n\t\t\tallPredecessors.set(node.id, new Set())\n\t\t}\n\t\tfor (const edge of blueprint.edges) {\n\t\t\tallPredecessors.get(edge.target)?.add(edge.source)\n\t\t}\n\n\t\tfor (const node of blueprint.nodes) {\n\t\t\tif (completedNodes.has(node.id)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst predecessors = allPredecessors.get(node.id) ?? new Set()\n\t\t\tif (predecessors.size === 0 && !completedNodes.has(node.id)) {\n\t\t\t\tnewFrontier.add(node.id)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst joinStrategy = node.config?.joinStrategy || 'all'\n\t\t\tconst completedPredecessors = [...predecessors].filter((p) => completedNodes.has(p))\n\n\t\t\tconst isReady =\n\t\t\t\tjoinStrategy === 'any' ? completedPredecessors.length > 0 : completedPredecessors.length === predecessors.size\n\n\t\t\tif (isReady) {\n\t\t\t\tnewFrontier.add(node.id)\n\t\t\t}\n\t\t}\n\t\treturn newFrontier\n\t}\n\n\t/**\n\t * Writes a poison pill for 'all' join successors and a cancellation pill for 'any' join successors of a failed node to prevent stalling or ambiguous states.\n\t */\n\tprivate async writePoisonPillForSuccessors(\n\t\trunId: string,\n\t\tblueprint: WorkflowBlueprint,\n\t\tfailedNodeId: string,\n\t): Promise<void> {\n\t\tconst successors = blueprint.edges\n\t\t\t.filter((edge) => edge.source === failedNodeId)\n\t\t\t.map((edge) => edge.target)\n\t\t\t.map((targetId) => blueprint.nodes.find((node) => node.id === targetId))\n\t\t\t.filter((node) => node)\n\n\t\tfor (const successor of successors) {\n\t\t\tif (successor) {\n\t\t\t\tconst joinStrategy = successor.config?.joinStrategy || 'all'\n\t\t\t\tif (joinStrategy === 'all') {\n\t\t\t\t\tconst poisonKey = `flowcraft:fanin:poison:${runId}:${successor.id}`\n\t\t\t\t\tawait this.store.setIfNotExist(poisonKey, 'poisoned', 3600)\n\t\t\t\t\tthis.logger.info(\n\t\t\t\t\t\t`[Adapter] Wrote poison pill for 'all' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`,\n\t\t\t\t\t)\n\t\t\t\t} else if (joinStrategy === 'any') {\n\t\t\t\t\tconst cancelKey = `flowcraft:fanin:cancel:${runId}:${successor.id}`\n\t\t\t\t\tawait this.store.setIfNotExist(cancelKey, 'cancelled', 3600)\n\t\t\t\t\tthis.logger.info(\n\t\t\t\t\t\t`[Adapter] Wrote cancellation pill for 'any' join node '${successor.id}' due to failed predecessor '${failedNodeId}'`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { InMemoryEventLogger } from './chunk-MUYLRTSR.js';
2
- import { FlowRuntime } from './chunk-HKX7WQLS.js';
2
+ import { FlowRuntime } from './chunk-OPRR4TAO.js';
3
3
 
4
4
  // src/testing/run-with-trace.ts
5
5
  async function runWithTrace(runtime, blueprint, initialState = {}, options = {}) {
@@ -21,5 +21,5 @@ async function runWithTrace(runtime, blueprint, initialState = {}, options = {})
21
21
  }
22
22
 
23
23
  export { runWithTrace };
24
- //# sourceMappingURL=chunk-BN4MV36K.js.map
25
- //# sourceMappingURL=chunk-BN4MV36K.js.map
24
+ //# sourceMappingURL=chunk-6MGLU3UU.js.map
25
+ //# sourceMappingURL=chunk-6MGLU3UU.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing/run-with-trace.ts"],"names":[],"mappings":";;;;AA+BA,eAAsB,YAAA,CACrB,SACA,SAAA,EACA,YAAA,GAA2C,EAAC,EAC5C,OAAA,GAII,EAAC,EACJ;AACD,EAAA,MAAM,WAAA,GAAc,IAAI,mBAAA,EAAoB;AAC5C,EAAA,MAAM,WAAA,GAAc,IAAI,WAAA,CAAY;AAAA,IACnC,GAAG,OAAA,CAAQ,OAAA;AAAA,IACX,QAAA,EAAU;AAAA,GACV,CAAA;AAED,EAAA,IAAI;AACH,IAAA,MAAM,SAAS,MAAM,WAAA,CAAY,GAAA,CAAI,SAAA,EAAW,cAAc,OAAO,CAAA;AACrE,IAAA,IAAI,OAAA,CAAQ,IAAI,KAAA,EAAO;AACtB,MAAA,WAAA,CAAY,QAAA,CAAS,CAAA,kBAAA,EAAqB,SAAA,CAAU,EAAE,CAAA,CAAE,CAAA;AAAA,IACzD;AACA,IAAA,OAAO,MAAA;AAAA,EACR,SAAS,KAAA,EAAO;AACf,IAAA,WAAA,CAAY,QAAA,CAAS,CAAA,oBAAA,EAAuB,SAAA,CAAU,EAAE,CAAA,CAAE,CAAA;AAC1D,IAAA,MAAM,KAAA;AAAA,EACP;AACD","file":"chunk-BN4MV36K.js","sourcesContent":["import { FlowRuntime } from '../runtime'\nimport type { WorkflowBlueprint } from '../types'\nimport { InMemoryEventLogger } from './event-logger'\n\n/**\n * A test helper that executes a workflow and automatically prints a detailed\n * execution trace to the console if the workflow fails.\n *\n * @example\n * // In your test file (e.g., my-workflow.test.ts)\n * it('should process data correctly', async () => {\n * const flow = createFlow('my-flow')\n * .node('a', async () => ({ output: 1 }))\n * .node('b', async ({ input }) => ({ output: input + 1 })) // Bug: returns { output: 3 }\n * .edge('a', 'b')\n *\n * const runtime = new FlowRuntime({})\n *\n * // If this test fails, a full, human-readable trace of the execution\n * // (inputs, outputs, context changes) is printed to the console.\n * const result = await runWithTrace(runtime, flow.toBlueprint())\n *\n * expect(result.context.b).toBe(2)\n * })\n *\n * @param runtime The original FlowRuntime instance (its options will be used).\n * @param blueprint The WorkflowBlueprint to execute.\n * @param initialState The initial state for the workflow run.\n * @param options Additional options for the run.\n * @returns The WorkflowResult if successful.\n */\nexport async function runWithTrace<TContext extends Record<string, any>>(\n\truntime: FlowRuntime<TContext, any>,\n\tblueprint: WorkflowBlueprint,\n\tinitialState: Partial<TContext> | string = {},\n\toptions: {\n\t\tfunctionRegistry?: Map<string, any>\n\t\tstrict?: boolean\n\t\tsignal?: AbortSignal\n\t} = {},\n) {\n\tconst eventLogger = new InMemoryEventLogger()\n\tconst testRuntime = new FlowRuntime({\n\t\t...runtime.options,\n\t\teventBus: eventLogger,\n\t})\n\n\ttry {\n\t\tconst result = await testRuntime.run(blueprint, initialState, options)\n\t\tif (process.env.DEBUG) {\n\t\t\teventLogger.printLog(`Successful Trace: ${blueprint.id}`)\n\t\t}\n\t\treturn result\n\t} catch (error) {\n\t\teventLogger.printLog(`Failing Test Trace: ${blueprint.id}`)\n\t\tthrow error\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../src/testing/run-with-trace.ts"],"names":[],"mappings":";;;;AA+BA,eAAsB,YAAA,CACrB,SACA,SAAA,EACA,YAAA,GAA2C,EAAC,EAC5C,OAAA,GAII,EAAC,EACJ;AACD,EAAA,MAAM,WAAA,GAAc,IAAI,mBAAA,EAAoB;AAC5C,EAAA,MAAM,WAAA,GAAc,IAAI,WAAA,CAAY;AAAA,IACnC,GAAG,OAAA,CAAQ,OAAA;AAAA,IACX,QAAA,EAAU;AAAA,GACV,CAAA;AAED,EAAA,IAAI;AACH,IAAA,MAAM,SAAS,MAAM,WAAA,CAAY,GAAA,CAAI,SAAA,EAAW,cAAc,OAAO,CAAA;AACrE,IAAA,IAAI,OAAA,CAAQ,IAAI,KAAA,EAAO;AACtB,MAAA,WAAA,CAAY,QAAA,CAAS,CAAA,kBAAA,EAAqB,SAAA,CAAU,EAAE,CAAA,CAAE,CAAA;AAAA,IACzD;AACA,IAAA,OAAO,MAAA;AAAA,EACR,SAAS,KAAA,EAAO;AACf,IAAA,WAAA,CAAY,QAAA,CAAS,CAAA,oBAAA,EAAuB,SAAA,CAAU,EAAE,CAAA,CAAE,CAAA;AAC1D,IAAA,MAAM,KAAA;AAAA,EACP;AACD","file":"chunk-6MGLU3UU.js","sourcesContent":["import { FlowRuntime } from '../runtime'\nimport type { WorkflowBlueprint } from '../types'\nimport { InMemoryEventLogger } from './event-logger'\n\n/**\n * A test helper that executes a workflow and automatically prints a detailed\n * execution trace to the console if the workflow fails.\n *\n * @example\n * // In your test file (e.g., my-workflow.test.ts)\n * it('should process data correctly', async () => {\n * const flow = createFlow('my-flow')\n * .node('a', async () => ({ output: 1 }))\n * .node('b', async ({ input }) => ({ output: input + 1 })) // Bug: returns { output: 3 }\n * .edge('a', 'b')\n *\n * const runtime = new FlowRuntime({})\n *\n * // If this test fails, a full, human-readable trace of the execution\n * // (inputs, outputs, context changes) is printed to the console.\n * const result = await runWithTrace(runtime, flow.toBlueprint())\n *\n * expect(result.context.b).toBe(2)\n * })\n *\n * @param runtime The original FlowRuntime instance (its options will be used).\n * @param blueprint The WorkflowBlueprint to execute.\n * @param initialState The initial state for the workflow run.\n * @param options Additional options for the run.\n * @returns The WorkflowResult if successful.\n */\nexport async function runWithTrace<TContext extends Record<string, any>>(\n\truntime: FlowRuntime<TContext, any>,\n\tblueprint: WorkflowBlueprint,\n\tinitialState: Partial<TContext> | string = {},\n\toptions: {\n\t\tfunctionRegistry?: Map<string, any>\n\t\tstrict?: boolean\n\t\tsignal?: AbortSignal\n\t} = {},\n) {\n\tconst eventLogger = new InMemoryEventLogger()\n\tconst testRuntime = new FlowRuntime({\n\t\t...runtime.options,\n\t\teventBus: eventLogger,\n\t})\n\n\ttry {\n\t\tconst result = await testRuntime.run(blueprint, initialState, options)\n\t\tif (process.env.DEBUG) {\n\t\t\teventLogger.printLog(`Successful Trace: ${blueprint.id}`)\n\t\t}\n\t\treturn result\n\t} catch (error) {\n\t\teventLogger.printLog(`Failing Test Trace: ${blueprint.id}`)\n\t\tthrow error\n\t}\n}\n"]}