flowcraft 2.9.3 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +3 -3
  2. package/dist/adapter-DzeZVjSE.d.mts +133 -0
  3. package/dist/adapters/index.d.mts +2 -0
  4. package/dist/adapters/index.mjs +3 -0
  5. package/dist/adapters/persistent-event-bus.d.mts +2 -0
  6. package/dist/adapters/persistent-event-bus.mjs +59 -0
  7. package/dist/analysis-B5Twr7sD.d.mts +52 -0
  8. package/dist/analysis.d.mts +2 -0
  9. package/dist/analysis.mjs +164 -0
  10. package/dist/batch-gather-BhF-IzQR.d.mts +8 -0
  11. package/dist/batch-scatter-DD8TU0Wm.d.mts +8 -0
  12. package/dist/container-BKdd-9wf.d.mts +24 -0
  13. package/dist/container-factory-fDY2kkxt.d.mts +17 -0
  14. package/dist/container-factory.d.mts +2 -0
  15. package/dist/container-factory.mjs +23 -0
  16. package/dist/container.d.mts +2 -0
  17. package/dist/container.mjs +43 -0
  18. package/dist/context-ZVtzXuZu.d.mts +64 -0
  19. package/dist/context.d.mts +2 -0
  20. package/dist/context.mjs +145 -0
  21. package/dist/error-mapper-BAv_YQMQ.d.mts +14 -0
  22. package/dist/error-mapper.d.mts +2 -0
  23. package/dist/error-mapper.mjs +37 -0
  24. package/dist/errors-CyyIj3OO.d.mts +21 -0
  25. package/dist/errors.d.mts +2 -0
  26. package/dist/errors.mjs +24 -0
  27. package/dist/evaluator-Dnj5qJ92.d.mts +31 -0
  28. package/dist/evaluator.d.mts +2 -0
  29. package/dist/evaluator.mjs +80 -0
  30. package/dist/flow-CZGpYpl-.d.mts +94 -0
  31. package/dist/flow.d.mts +2 -0
  32. package/dist/flow.mjs +328 -0
  33. package/dist/index-9iG2qHLe.d.mts +1 -0
  34. package/dist/index-Bk0eNZmQ.d.mts +1 -0
  35. package/dist/index-CNgSR_kt.d.mts +1 -0
  36. package/dist/index-CW2WHUXP.d.mts +1 -0
  37. package/dist/index.d.mts +24 -1
  38. package/dist/index.mjs +31 -746
  39. package/dist/linter-B8KALEae.d.mts +25 -0
  40. package/dist/linter.d.mts +2 -0
  41. package/dist/linter.mjs +74 -0
  42. package/dist/logger-BvDgvNHQ.d.mts +19 -0
  43. package/dist/logger.d.mts +2 -0
  44. package/dist/logger.mjs +26 -0
  45. package/dist/node.d.mts +2 -0
  46. package/dist/node.mjs +55 -0
  47. package/dist/nodes/batch-gather.d.mts +2 -0
  48. package/dist/nodes/batch-gather.mjs +47 -0
  49. package/dist/nodes/batch-scatter.d.mts +2 -0
  50. package/dist/nodes/batch-scatter.mjs +52 -0
  51. package/dist/nodes/index.d.mts +7 -0
  52. package/dist/nodes/index.mjs +8 -0
  53. package/dist/nodes/sleep.d.mts +2 -0
  54. package/dist/nodes/sleep.mjs +41 -0
  55. package/dist/nodes/subflow.d.mts +2 -0
  56. package/dist/nodes/subflow.mjs +64 -0
  57. package/dist/nodes/wait.d.mts +2 -0
  58. package/dist/nodes/wait.mjs +12 -0
  59. package/dist/nodes/webhook.d.mts +2 -0
  60. package/dist/nodes/webhook.mjs +24 -0
  61. package/dist/orchestrator-DwMIJRFI.d.mts +8 -0
  62. package/dist/persistent-event-bus-COiQOpWh.d.mts +68 -0
  63. package/dist/replay-CVOy6d_L.d.mts +44 -0
  64. package/dist/runtime/adapter.d.mts +2 -0
  65. package/dist/runtime/adapter.mjs +349 -0
  66. package/dist/runtime/builtin-keys.d.mts +37 -0
  67. package/dist/runtime/builtin-keys.mjs +12 -0
  68. package/dist/runtime/execution-context.d.mts +2 -0
  69. package/dist/runtime/execution-context.mjs +26 -0
  70. package/dist/runtime/executors.d.mts +2 -0
  71. package/dist/runtime/executors.mjs +259 -0
  72. package/dist/runtime/index.d.mts +6 -0
  73. package/dist/runtime/index.mjs +10 -0
  74. package/dist/runtime/node-executor-factory.d.mts +11 -0
  75. package/dist/runtime/node-executor-factory.mjs +41 -0
  76. package/dist/runtime/orchestrator.d.mts +2 -0
  77. package/dist/runtime/orchestrator.mjs +41 -0
  78. package/dist/runtime/orchestrators/replay.d.mts +2 -0
  79. package/dist/{replay-BB11M6K1.mjs → runtime/orchestrators/replay.mjs} +1 -20
  80. package/dist/runtime/orchestrators/step-by-step.d.mts +15 -0
  81. package/dist/runtime/orchestrators/step-by-step.mjs +41 -0
  82. package/dist/runtime/orchestrators/utils.d.mts +2 -0
  83. package/dist/runtime/orchestrators/utils.mjs +79 -0
  84. package/dist/runtime/runtime.d.mts +2 -0
  85. package/dist/runtime/runtime.mjs +425 -0
  86. package/dist/runtime/scheduler.d.mts +2 -0
  87. package/dist/runtime/scheduler.mjs +64 -0
  88. package/dist/runtime/state.d.mts +2 -0
  89. package/dist/runtime/state.mjs +127 -0
  90. package/dist/runtime/traverser.d.mts +2 -0
  91. package/dist/runtime/traverser.mjs +213 -0
  92. package/dist/runtime/types.d.mts +2 -0
  93. package/dist/runtime/types.mjs +1 -0
  94. package/dist/runtime/workflow-logic-handler.d.mts +16 -0
  95. package/dist/runtime/workflow-logic-handler.mjs +159 -0
  96. package/dist/sanitizer-Bi00YjvO.d.mts +11 -0
  97. package/dist/sanitizer.d.mts +2 -0
  98. package/dist/sanitizer.mjs +37 -0
  99. package/dist/sdk.d.mts +1 -2
  100. package/dist/sdk.mjs +1 -2
  101. package/dist/serializer-BnmJr13R.d.mts +17 -0
  102. package/dist/serializer.d.mts +2 -0
  103. package/dist/serializer.mjs +34 -0
  104. package/dist/sleep-DpwYaY5b.d.mts +8 -0
  105. package/dist/subflow-n2IMsRe2.d.mts +8 -0
  106. package/dist/testing/event-logger.d.mts +62 -0
  107. package/dist/testing/event-logger.mjs +98 -0
  108. package/dist/testing/index.d.mts +5 -172
  109. package/dist/testing/index.mjs +6 -276
  110. package/dist/testing/run-with-trace.d.mts +37 -0
  111. package/dist/testing/run-with-trace.mjs +49 -0
  112. package/dist/testing/stepper.d.mts +78 -0
  113. package/dist/testing/stepper.mjs +100 -0
  114. package/dist/types-BcrXJEPI.d.mts +687 -0
  115. package/dist/types.d.mts +2 -0
  116. package/dist/types.mjs +1 -0
  117. package/dist/utils-BUEgr9V2.d.mts +34 -0
  118. package/dist/wait-2Q-LA7V7.d.mts +8 -0
  119. package/dist/webhook-BiCm-HLx.d.mts +12 -0
  120. package/package.json +4 -4
  121. package/dist/index-DUPpyNvU.d.mts +0 -1326
  122. package/dist/index.mjs.map +0 -1
  123. package/dist/replay-BB11M6K1.mjs.map +0 -1
  124. package/dist/runtime-lNm7WbD1.mjs +0 -2250
  125. package/dist/runtime-lNm7WbD1.mjs.map +0 -1
  126. package/dist/sdk.mjs.map +0 -1
  127. package/dist/testing/index.mjs.map +0 -1
@@ -0,0 +1,78 @@
1
+ import { A as FlowRuntime, D as WorkflowResult, F as GraphTraverser, U as WorkflowState, d as NodeClass, h as NodeFunction, w as WorkflowBlueprint } from "../types-BcrXJEPI.mjs";
2
+
3
+ //#region src/testing/stepper.d.ts
4
+ /**
5
+ * Represents the controlled, step-by-step execution of a workflow.
6
+ * Returned by the `createStepper` utility.
7
+ */
8
+ interface IWorkflowStepper<TContext extends Record<string, any>> {
9
+ /** The current state of the workflow. Can be inspected after each step. */
10
+ readonly state: WorkflowState<TContext>;
11
+ /** The graph traverser instance. Can be used to inspect the frontier or completed nodes. */
12
+ readonly traverser: GraphTraverser;
13
+ /**
14
+ * Executes the next "turn" or batch of ready nodes in the workflow.
15
+ * @param options Optional configuration for this specific step, like a cancellation signal.
16
+ * @returns A `WorkflowResult` representing the state after the step, or `null` if the workflow has already completed.
17
+ */
18
+ next(options?: {
19
+ signal?: AbortSignal;
20
+ concurrency?: number;
21
+ }): Promise<WorkflowResult<TContext> | null>;
22
+ /**
23
+ * Reverts the workflow to its previous state.
24
+ * @returns The `WorkflowResult` of the previous state, or `null` if there is no history to revert to.
25
+ */
26
+ prev(): Promise<WorkflowResult<TContext> | null>;
27
+ /**
28
+ * Resets the stepper to its initial state, clearing all progress and history.
29
+ */
30
+ reset(): void;
31
+ /**
32
+ * A convenience method to check if the workflow has any more steps to run.
33
+ * @returns `true` if the workflow is complete or stalled, `false` otherwise.
34
+ */
35
+ isDone(): boolean;
36
+ }
37
+ /**
38
+ * A test utility that creates a stepper to execute a workflow one "turn" at a time.
39
+ * This is invaluable for debugging and writing fine-grained tests where you need to
40
+ * assert the state of the workflow after each logical step.
41
+ *
42
+ * @example
43
+ * // In your test file
44
+ * it('should correctly execute step-by-step', async () => {
45
+ * const runtime = new FlowRuntime({ ... });
46
+ * const flow = createFlow('test')
47
+ * .node('a', async () => ({ output: 10 }))
48
+ * .node('b', async ({ input }) => ({ output: input * 2 }))
49
+ * .edge('a', 'b');
50
+ *
51
+ * const stepper = await createStepper(runtime, flow.toBlueprint(), flow.getFunctionRegistry());
52
+ *
53
+ * // First step (executes node 'a')
54
+ * const result1 = await stepper.next();
55
+ * expect(stepper.isDone()).toBe(false);
56
+ * expect(result1.status).toBe('stalled');
57
+ * expect(result1.context._outputs.a).toBe(10);
58
+ *
59
+ * // Second step (executes node 'b')
60
+ * const result2 = await stepper.next();
61
+ * expect(stepper.isDone()).toBe(true);
62
+ * expect(result2.status).toBe('completed');
63
+ * expect(result2.context._outputs.b).toBe(20);
64
+ *
65
+ * // Final step (no more work)
66
+ * const result3 = await stepper.next();
67
+ * expect(result3).toBeNull();
68
+ * });
69
+ *
70
+ * @param runtime The `FlowRuntime` instance, used for its configuration.
71
+ * @param blueprint The `WorkflowBlueprint` to execute.
72
+ * @param functionRegistry The function registry from createFlow, containing the node implementations.
73
+ * @param initialState The initial state for the workflow run.
74
+ * @returns A Promise that resolves to an `IWorkflowStepper` instance.
75
+ */
76
+ declare function createStepper<TContext extends Record<string, any>, TDependencies extends Record<string, any>>(runtime: FlowRuntime<TContext, TDependencies>, blueprint: WorkflowBlueprint, functionRegistry: Map<string, NodeFunction | NodeClass>, initialState?: Partial<TContext>): Promise<IWorkflowStepper<TContext>>;
77
+ //#endregion
78
+ export { IWorkflowStepper, createStepper };
@@ -0,0 +1,100 @@
1
+ import { WorkflowState } from "../runtime/state.mjs";
2
+ import { ExecutionContext } from "../runtime/execution-context.mjs";
3
+ import { GraphTraverser } from "../runtime/traverser.mjs";
4
+ import { StepByStepOrchestrator } from "../runtime/orchestrators/step-by-step.mjs";
5
+
6
+ //#region src/testing/stepper.ts
7
+ /**
8
+ * A test utility that creates a stepper to execute a workflow one "turn" at a time.
9
+ * This is invaluable for debugging and writing fine-grained tests where you need to
10
+ * assert the state of the workflow after each logical step.
11
+ *
12
+ * @example
13
+ * // In your test file
14
+ * it('should correctly execute step-by-step', async () => {
15
+ * const runtime = new FlowRuntime({ ... });
16
+ * const flow = createFlow('test')
17
+ * .node('a', async () => ({ output: 10 }))
18
+ * .node('b', async ({ input }) => ({ output: input * 2 }))
19
+ * .edge('a', 'b');
20
+ *
21
+ * const stepper = await createStepper(runtime, flow.toBlueprint(), flow.getFunctionRegistry());
22
+ *
23
+ * // First step (executes node 'a')
24
+ * const result1 = await stepper.next();
25
+ * expect(stepper.isDone()).toBe(false);
26
+ * expect(result1.status).toBe('stalled');
27
+ * expect(result1.context._outputs.a).toBe(10);
28
+ *
29
+ * // Second step (executes node 'b')
30
+ * const result2 = await stepper.next();
31
+ * expect(stepper.isDone()).toBe(true);
32
+ * expect(result2.status).toBe('completed');
33
+ * expect(result2.context._outputs.b).toBe(20);
34
+ *
35
+ * // Final step (no more work)
36
+ * const result3 = await stepper.next();
37
+ * expect(result3).toBeNull();
38
+ * });
39
+ *
40
+ * @param runtime The `FlowRuntime` instance, used for its configuration.
41
+ * @param blueprint The `WorkflowBlueprint` to execute.
42
+ * @param functionRegistry The function registry from createFlow, containing the node implementations.
43
+ * @param initialState The initial state for the workflow run.
44
+ * @returns A Promise that resolves to an `IWorkflowStepper` instance.
45
+ */
46
+ async function createStepper(runtime, blueprint, functionRegistry, initialState = {}) {
47
+ const _initialBlueprint = structuredClone(blueprint);
48
+ const _initialState = structuredClone(initialState);
49
+ let state;
50
+ let traverser;
51
+ const history = [];
52
+ const orchestrator = new StepByStepOrchestrator();
53
+ const executionId = globalThis.crypto?.randomUUID();
54
+ const nodeRegistry = new Map([...runtime.registry, ...functionRegistry]);
55
+ const initialize = () => {
56
+ state = new WorkflowState(_initialState);
57
+ traverser = new GraphTraverser(_initialBlueprint);
58
+ history.length = 0;
59
+ };
60
+ initialize();
61
+ const stepper = {
62
+ get state() {
63
+ return state;
64
+ },
65
+ get traverser() {
66
+ return traverser;
67
+ },
68
+ isDone() {
69
+ return !traverser.hasMoreWork() && !state.isAwaiting();
70
+ },
71
+ reset() {
72
+ initialize();
73
+ },
74
+ async prev() {
75
+ const previousStateJson = history.pop();
76
+ if (!previousStateJson) return null;
77
+ state = new WorkflowState(runtime.serializer.deserialize(previousStateJson));
78
+ traverser = GraphTraverser.fromState(_initialBlueprint, state);
79
+ return state.toResult(runtime.serializer, void 0);
80
+ },
81
+ async next(options = {}) {
82
+ if (stepper.isDone()) return null;
83
+ const serializedContext = (await state.toResult(runtime.serializer, void 0)).serializedContext;
84
+ history.push(serializedContext);
85
+ const executionContext = new ExecutionContext(_initialBlueprint, state, nodeRegistry, executionId, runtime, {
86
+ logger: runtime.logger,
87
+ eventBus: runtime.eventBus,
88
+ serializer: runtime.serializer,
89
+ evaluator: runtime.evaluator,
90
+ middleware: runtime.middleware,
91
+ dependencies: runtime.dependencies
92
+ }, options.signal, options.concurrency);
93
+ return orchestrator.run(executionContext, traverser);
94
+ }
95
+ };
96
+ return stepper;
97
+ }
98
+
99
+ //#endregion
100
+ export { createStepper };