footprintjs 0.1.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.
- package/LICENSE +21 -0
- package/README.md +658 -0
- package/dist/advanced.js +84 -0
- package/dist/esm/advanced.js +26 -0
- package/dist/esm/index.js +30 -0
- package/dist/esm/lib/builder/FlowChartBuilder.js +809 -0
- package/dist/esm/lib/builder/index.js +12 -0
- package/dist/esm/lib/builder/types.js +9 -0
- package/dist/esm/lib/engine/graph/StageNode.js +38 -0
- package/dist/esm/lib/engine/graph/index.js +2 -0
- package/dist/esm/lib/engine/handlers/ChildrenExecutor.js +116 -0
- package/dist/esm/lib/engine/handlers/ContinuationResolver.js +121 -0
- package/dist/esm/lib/engine/handlers/DeciderHandler.js +78 -0
- package/dist/esm/lib/engine/handlers/ExtractorRunner.js +117 -0
- package/dist/esm/lib/engine/handlers/NodeResolver.js +72 -0
- package/dist/esm/lib/engine/handlers/RuntimeStructureManager.js +154 -0
- package/dist/esm/lib/engine/handlers/SelectorHandler.js +79 -0
- package/dist/esm/lib/engine/handlers/StageRunner.js +86 -0
- package/dist/esm/lib/engine/handlers/SubflowExecutor.js +322 -0
- package/dist/esm/lib/engine/handlers/SubflowInputMapper.js +113 -0
- package/dist/esm/lib/engine/handlers/index.js +23 -0
- package/dist/esm/lib/engine/index.js +18 -0
- package/dist/esm/lib/engine/narrative/CombinedNarrativeBuilder.js +158 -0
- package/dist/esm/lib/engine/narrative/ControlFlowNarrativeGenerator.js +90 -0
- package/dist/esm/lib/engine/narrative/NullControlFlowNarrativeGenerator.js +24 -0
- package/dist/esm/lib/engine/narrative/index.js +4 -0
- package/dist/esm/lib/engine/narrative/types.js +11 -0
- package/dist/esm/lib/engine/traversal/FlowchartTraverser.js +419 -0
- package/dist/esm/lib/engine/traversal/index.js +2 -0
- package/dist/esm/lib/engine/types.js +16 -0
- package/dist/esm/lib/memory/DiagnosticCollector.js +44 -0
- package/dist/esm/lib/memory/EventLog.js +44 -0
- package/dist/esm/lib/memory/SharedMemory.js +53 -0
- package/dist/esm/lib/memory/StageContext.js +221 -0
- package/dist/esm/lib/memory/TransactionBuffer.js +66 -0
- package/dist/esm/lib/memory/index.js +16 -0
- package/dist/esm/lib/memory/types.js +7 -0
- package/dist/esm/lib/memory/utils.js +155 -0
- package/dist/esm/lib/runner/ExecutionRuntime.js +64 -0
- package/dist/esm/lib/runner/FlowChartExecutor.js +108 -0
- package/dist/esm/lib/runner/index.js +3 -0
- package/dist/esm/lib/scope/ScopeFacade.js +175 -0
- package/dist/esm/lib/scope/index.js +19 -0
- package/dist/esm/lib/scope/protection/createProtectedScope.js +59 -0
- package/dist/esm/lib/scope/protection/index.js +3 -0
- package/dist/esm/lib/scope/protection/types.js +8 -0
- package/dist/esm/lib/scope/providers/baseStateCompatible.js +29 -0
- package/dist/esm/lib/scope/providers/guards.js +43 -0
- package/dist/esm/lib/scope/providers/index.js +7 -0
- package/dist/esm/lib/scope/providers/providers.js +18 -0
- package/dist/esm/lib/scope/providers/registry.js +36 -0
- package/dist/esm/lib/scope/providers/resolve.js +11 -0
- package/dist/esm/lib/scope/providers/types.js +8 -0
- package/dist/esm/lib/scope/recorders/DebugRecorder.js +81 -0
- package/dist/esm/lib/scope/recorders/MetricRecorder.js +81 -0
- package/dist/esm/lib/scope/recorders/NarrativeRecorder.js +167 -0
- package/dist/esm/lib/scope/recorders/index.js +4 -0
- package/dist/esm/lib/scope/state/installResolvers.js +15 -0
- package/dist/esm/lib/scope/state/zod/defineScopeFromZod.js +14 -0
- package/dist/esm/lib/scope/state/zod/index.js +5 -0
- package/dist/esm/lib/scope/state/zod/resolver.js +28 -0
- package/dist/esm/lib/scope/state/zod/schema/builder.js +16 -0
- package/dist/esm/lib/scope/state/zod/scopeFactory.js +156 -0
- package/dist/esm/lib/scope/state/zod/utils/validateHelper.js +97 -0
- package/dist/esm/lib/scope/types.js +9 -0
- package/dist/esm/types/advanced.d.ts +35 -0
- package/dist/esm/types/index.d.ts +22 -0
- package/dist/esm/types/lib/builder/FlowChartBuilder.d.ts +121 -0
- package/dist/esm/types/lib/builder/index.d.ts +9 -0
- package/dist/esm/types/lib/builder/types.d.ts +152 -0
- package/dist/esm/types/lib/engine/graph/StageNode.d.ts +78 -0
- package/dist/esm/types/lib/engine/graph/index.d.ts +2 -0
- package/dist/esm/types/lib/engine/handlers/ChildrenExecutor.d.ts +33 -0
- package/dist/esm/types/lib/engine/handlers/ContinuationResolver.d.ts +57 -0
- package/dist/esm/types/lib/engine/handlers/DeciderHandler.d.ts +34 -0
- package/dist/esm/types/lib/engine/handlers/ExtractorRunner.d.ts +41 -0
- package/dist/esm/types/lib/engine/handlers/NodeResolver.d.ts +26 -0
- package/dist/esm/types/lib/engine/handlers/RuntimeStructureManager.d.ts +36 -0
- package/dist/esm/types/lib/engine/handlers/SelectorHandler.d.ts +26 -0
- package/dist/esm/types/lib/engine/handlers/StageRunner.d.ts +17 -0
- package/dist/esm/types/lib/engine/handlers/SubflowExecutor.d.ts +57 -0
- package/dist/esm/types/lib/engine/handlers/SubflowInputMapper.d.ts +40 -0
- package/dist/esm/types/lib/engine/handlers/index.d.ts +15 -0
- package/dist/esm/types/lib/engine/index.d.ts +16 -0
- package/dist/esm/types/lib/engine/narrative/CombinedNarrativeBuilder.d.ts +33 -0
- package/dist/esm/types/lib/engine/narrative/ControlFlowNarrativeGenerator.d.ts +29 -0
- package/dist/esm/types/lib/engine/narrative/NullControlFlowNarrativeGenerator.d.ts +21 -0
- package/dist/esm/types/lib/engine/narrative/index.d.ts +5 -0
- package/dist/esm/types/lib/engine/narrative/types.d.ts +33 -0
- package/dist/esm/types/lib/engine/traversal/FlowchartTraverser.d.ts +87 -0
- package/dist/esm/types/lib/engine/traversal/index.d.ts +2 -0
- package/dist/esm/types/lib/engine/types.d.ts +208 -0
- package/dist/esm/types/lib/memory/DiagnosticCollector.d.ts +33 -0
- package/dist/esm/types/lib/memory/EventLog.d.ts +27 -0
- package/dist/esm/types/lib/memory/SharedMemory.d.ts +34 -0
- package/dist/esm/types/lib/memory/StageContext.d.ts +74 -0
- package/dist/esm/types/lib/memory/TransactionBuffer.d.ts +38 -0
- package/dist/esm/types/lib/memory/index.d.ts +13 -0
- package/dist/esm/types/lib/memory/types.d.ts +60 -0
- package/dist/esm/types/lib/memory/utils.d.ts +67 -0
- package/dist/esm/types/lib/runner/ExecutionRuntime.d.ts +39 -0
- package/dist/esm/types/lib/runner/FlowChartExecutor.d.ts +34 -0
- package/dist/esm/types/lib/runner/index.d.ts +3 -0
- package/dist/esm/types/lib/scope/ScopeFacade.d.ts +47 -0
- package/dist/esm/types/lib/scope/index.d.ts +23 -0
- package/dist/esm/types/lib/scope/protection/createProtectedScope.d.ts +9 -0
- package/dist/esm/types/lib/scope/protection/index.d.ts +2 -0
- package/dist/esm/types/lib/scope/protection/types.d.ts +13 -0
- package/dist/esm/types/lib/scope/providers/baseStateCompatible.d.ts +26 -0
- package/dist/esm/types/lib/scope/providers/guards.d.ts +14 -0
- package/dist/esm/types/lib/scope/providers/index.d.ts +6 -0
- package/dist/esm/types/lib/scope/providers/providers.d.ts +8 -0
- package/dist/esm/types/lib/scope/providers/registry.d.ts +11 -0
- package/dist/esm/types/lib/scope/providers/resolve.d.ts +8 -0
- package/dist/esm/types/lib/scope/providers/types.d.ts +40 -0
- package/dist/esm/types/lib/scope/recorders/DebugRecorder.d.ts +35 -0
- package/dist/esm/types/lib/scope/recorders/MetricRecorder.d.ts +36 -0
- package/dist/esm/types/lib/scope/recorders/NarrativeRecorder.d.ts +45 -0
- package/dist/esm/types/lib/scope/recorders/index.d.ts +7 -0
- package/dist/esm/types/lib/scope/state/installResolvers.d.ts +4 -0
- package/dist/esm/types/lib/scope/state/zod/defineScopeFromZod.d.ts +9 -0
- package/dist/esm/types/lib/scope/state/zod/index.d.ts +5 -0
- package/dist/esm/types/lib/scope/state/zod/resolver.d.ts +5 -0
- package/dist/esm/types/lib/scope/state/zod/schema/builder.d.ts +12 -0
- package/dist/esm/types/lib/scope/state/zod/scopeFactory.d.ts +9 -0
- package/dist/esm/types/lib/scope/state/zod/utils/validateHelper.d.ts +10 -0
- package/dist/esm/types/lib/scope/types.d.ts +53 -0
- package/dist/index.js +42 -0
- package/dist/lib/builder/FlowChartBuilder.js +817 -0
- package/dist/lib/builder/index.js +20 -0
- package/dist/lib/builder/types.js +10 -0
- package/dist/lib/engine/graph/StageNode.js +42 -0
- package/dist/lib/engine/graph/index.js +6 -0
- package/dist/lib/engine/handlers/ChildrenExecutor.js +120 -0
- package/dist/lib/engine/handlers/ContinuationResolver.js +125 -0
- package/dist/lib/engine/handlers/DeciderHandler.js +82 -0
- package/dist/lib/engine/handlers/ExtractorRunner.js +121 -0
- package/dist/lib/engine/handlers/NodeResolver.js +76 -0
- package/dist/lib/engine/handlers/RuntimeStructureManager.js +159 -0
- package/dist/lib/engine/handlers/SelectorHandler.js +83 -0
- package/dist/lib/engine/handlers/StageRunner.js +90 -0
- package/dist/lib/engine/handlers/SubflowExecutor.js +326 -0
- package/dist/lib/engine/handlers/SubflowInputMapper.js +121 -0
- package/dist/lib/engine/handlers/index.js +42 -0
- package/dist/lib/engine/index.js +40 -0
- package/dist/lib/engine/narrative/CombinedNarrativeBuilder.js +162 -0
- package/dist/lib/engine/narrative/ControlFlowNarrativeGenerator.js +94 -0
- package/dist/lib/engine/narrative/NullControlFlowNarrativeGenerator.js +28 -0
- package/dist/lib/engine/narrative/index.js +10 -0
- package/dist/lib/engine/narrative/types.js +12 -0
- package/dist/lib/engine/traversal/FlowchartTraverser.js +423 -0
- package/dist/lib/engine/traversal/index.js +6 -0
- package/dist/lib/engine/types.js +19 -0
- package/dist/lib/memory/DiagnosticCollector.js +48 -0
- package/dist/lib/memory/EventLog.js +48 -0
- package/dist/lib/memory/SharedMemory.js +60 -0
- package/dist/lib/memory/StageContext.js +225 -0
- package/dist/lib/memory/TransactionBuffer.js +73 -0
- package/dist/lib/memory/index.js +34 -0
- package/dist/lib/memory/types.js +8 -0
- package/dist/lib/memory/utils.js +170 -0
- package/dist/lib/runner/ExecutionRuntime.js +68 -0
- package/dist/lib/runner/FlowChartExecutor.js +112 -0
- package/dist/lib/runner/index.js +8 -0
- package/dist/lib/scope/ScopeFacade.js +179 -0
- package/dist/lib/scope/index.js +44 -0
- package/dist/lib/scope/protection/createProtectedScope.js +64 -0
- package/dist/lib/scope/protection/index.js +8 -0
- package/dist/lib/scope/protection/types.js +9 -0
- package/dist/lib/scope/providers/baseStateCompatible.js +33 -0
- package/dist/lib/scope/providers/guards.js +49 -0
- package/dist/lib/scope/providers/index.js +21 -0
- package/dist/lib/scope/providers/providers.js +23 -0
- package/dist/lib/scope/providers/registry.js +42 -0
- package/dist/lib/scope/providers/resolve.js +16 -0
- package/dist/lib/scope/providers/types.js +9 -0
- package/dist/lib/scope/recorders/DebugRecorder.js +85 -0
- package/dist/lib/scope/recorders/MetricRecorder.js +85 -0
- package/dist/lib/scope/recorders/NarrativeRecorder.js +171 -0
- package/dist/lib/scope/recorders/index.js +10 -0
- package/dist/lib/scope/state/installResolvers.js +19 -0
- package/dist/lib/scope/state/zod/defineScopeFromZod.js +18 -0
- package/dist/lib/scope/state/zod/index.js +13 -0
- package/dist/lib/scope/state/zod/resolver.js +31 -0
- package/dist/lib/scope/state/zod/schema/builder.js +21 -0
- package/dist/lib/scope/state/zod/scopeFactory.js +160 -0
- package/dist/lib/scope/state/zod/utils/validateHelper.js +104 -0
- package/dist/lib/scope/types.js +10 -0
- package/dist/types/advanced.d.ts +35 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/lib/builder/FlowChartBuilder.d.ts +121 -0
- package/dist/types/lib/builder/index.d.ts +9 -0
- package/dist/types/lib/builder/types.d.ts +152 -0
- package/dist/types/lib/engine/graph/StageNode.d.ts +78 -0
- package/dist/types/lib/engine/graph/index.d.ts +2 -0
- package/dist/types/lib/engine/handlers/ChildrenExecutor.d.ts +33 -0
- package/dist/types/lib/engine/handlers/ContinuationResolver.d.ts +57 -0
- package/dist/types/lib/engine/handlers/DeciderHandler.d.ts +34 -0
- package/dist/types/lib/engine/handlers/ExtractorRunner.d.ts +41 -0
- package/dist/types/lib/engine/handlers/NodeResolver.d.ts +26 -0
- package/dist/types/lib/engine/handlers/RuntimeStructureManager.d.ts +36 -0
- package/dist/types/lib/engine/handlers/SelectorHandler.d.ts +26 -0
- package/dist/types/lib/engine/handlers/StageRunner.d.ts +17 -0
- package/dist/types/lib/engine/handlers/SubflowExecutor.d.ts +57 -0
- package/dist/types/lib/engine/handlers/SubflowInputMapper.d.ts +40 -0
- package/dist/types/lib/engine/handlers/index.d.ts +15 -0
- package/dist/types/lib/engine/index.d.ts +16 -0
- package/dist/types/lib/engine/narrative/CombinedNarrativeBuilder.d.ts +33 -0
- package/dist/types/lib/engine/narrative/ControlFlowNarrativeGenerator.d.ts +29 -0
- package/dist/types/lib/engine/narrative/NullControlFlowNarrativeGenerator.d.ts +21 -0
- package/dist/types/lib/engine/narrative/index.d.ts +5 -0
- package/dist/types/lib/engine/narrative/types.d.ts +33 -0
- package/dist/types/lib/engine/traversal/FlowchartTraverser.d.ts +87 -0
- package/dist/types/lib/engine/traversal/index.d.ts +2 -0
- package/dist/types/lib/engine/types.d.ts +208 -0
- package/dist/types/lib/memory/DiagnosticCollector.d.ts +33 -0
- package/dist/types/lib/memory/EventLog.d.ts +27 -0
- package/dist/types/lib/memory/SharedMemory.d.ts +34 -0
- package/dist/types/lib/memory/StageContext.d.ts +74 -0
- package/dist/types/lib/memory/TransactionBuffer.d.ts +38 -0
- package/dist/types/lib/memory/index.d.ts +13 -0
- package/dist/types/lib/memory/types.d.ts +60 -0
- package/dist/types/lib/memory/utils.d.ts +67 -0
- package/dist/types/lib/runner/ExecutionRuntime.d.ts +39 -0
- package/dist/types/lib/runner/FlowChartExecutor.d.ts +34 -0
- package/dist/types/lib/runner/index.d.ts +3 -0
- package/dist/types/lib/scope/ScopeFacade.d.ts +47 -0
- package/dist/types/lib/scope/index.d.ts +23 -0
- package/dist/types/lib/scope/protection/createProtectedScope.d.ts +9 -0
- package/dist/types/lib/scope/protection/index.d.ts +2 -0
- package/dist/types/lib/scope/protection/types.d.ts +13 -0
- package/dist/types/lib/scope/providers/baseStateCompatible.d.ts +26 -0
- package/dist/types/lib/scope/providers/guards.d.ts +14 -0
- package/dist/types/lib/scope/providers/index.d.ts +6 -0
- package/dist/types/lib/scope/providers/providers.d.ts +8 -0
- package/dist/types/lib/scope/providers/registry.d.ts +11 -0
- package/dist/types/lib/scope/providers/resolve.d.ts +8 -0
- package/dist/types/lib/scope/providers/types.d.ts +40 -0
- package/dist/types/lib/scope/recorders/DebugRecorder.d.ts +35 -0
- package/dist/types/lib/scope/recorders/MetricRecorder.d.ts +36 -0
- package/dist/types/lib/scope/recorders/NarrativeRecorder.d.ts +45 -0
- package/dist/types/lib/scope/recorders/index.d.ts +7 -0
- package/dist/types/lib/scope/state/installResolvers.d.ts +4 -0
- package/dist/types/lib/scope/state/zod/defineScopeFromZod.d.ts +9 -0
- package/dist/types/lib/scope/state/zod/index.d.ts +5 -0
- package/dist/types/lib/scope/state/zod/resolver.d.ts +5 -0
- package/dist/types/lib/scope/state/zod/schema/builder.d.ts +12 -0
- package/dist/types/lib/scope/state/zod/scopeFactory.d.ts +9 -0
- package/dist/types/lib/scope/state/zod/utils/validateHelper.d.ts +10 -0
- package/dist/types/lib/scope/types.d.ts +53 -0
- package/package.json +148 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SelectorHandler — Multi-choice filtered fan-out.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Execute scope-based selector nodes (stage → commit → resolve children → parallel execution)
|
|
6
|
+
* - The selector function IS a stage: reads scope, returns string[] of branch IDs
|
|
7
|
+
* - Delegates parallel execution of selected children to ChildrenExecutor
|
|
8
|
+
*/
|
|
9
|
+
import type { StageContext } from '../../memory/StageContext';
|
|
10
|
+
import type { StageNode } from '../graph/StageNode';
|
|
11
|
+
import type { HandlerDeps, NodeResultType, StageFunction } from '../types';
|
|
12
|
+
import type { ChildrenExecutor } from './ChildrenExecutor';
|
|
13
|
+
import type { CallExtractorFn, ExecuteNodeFn, GetStagePathFn, RunStageFn } from './DeciderHandler';
|
|
14
|
+
export declare class SelectorHandler<TOut = any, TScope = any> {
|
|
15
|
+
private readonly deps;
|
|
16
|
+
private readonly childrenExecutor;
|
|
17
|
+
constructor(deps: HandlerDeps<TOut, TScope>, childrenExecutor: ChildrenExecutor<TOut, TScope>);
|
|
18
|
+
/**
|
|
19
|
+
* Handle a scope-based selector node (created via addSelectorFunction).
|
|
20
|
+
* The stage function IS the selector — its return value contains branch IDs.
|
|
21
|
+
* Execution order: runStage(fn) → commit → resolve children → parallel execute.
|
|
22
|
+
*/
|
|
23
|
+
handleScopeBased(node: StageNode<TOut, TScope>, stageFunc: StageFunction<TOut, TScope>, context: StageContext, breakFlag: {
|
|
24
|
+
shouldBreak: boolean;
|
|
25
|
+
}, branchPath: string | undefined, runStage: RunStageFn<TOut, TScope>, executeNode: ExecuteNodeFn<TOut, TScope>, callExtractor: CallExtractorFn<TOut, TScope>, getStagePath: GetStagePathFn<TOut, TScope>): Promise<Record<string, NodeResultType>>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StageRunner — Executes individual stage functions.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Create scope via ScopeFactory for each stage
|
|
6
|
+
* - Apply scope protection (createProtectedScope) to intercept direct assignments
|
|
7
|
+
* - Handle streaming stages (onStart, onToken, onEnd lifecycle)
|
|
8
|
+
* - Sync+async safety: only await real Promises (instanceof check)
|
|
9
|
+
*/
|
|
10
|
+
import type { StageContext } from '../../memory/StageContext';
|
|
11
|
+
import type { StageNode } from '../graph/StageNode';
|
|
12
|
+
import type { HandlerDeps, StageFunction } from '../types';
|
|
13
|
+
export declare class StageRunner<TOut = any, TScope = any> {
|
|
14
|
+
private readonly deps;
|
|
15
|
+
constructor(deps: HandlerDeps<TOut, TScope>);
|
|
16
|
+
run(node: StageNode<TOut, TScope>, stageFunc: StageFunction<TOut, TScope>, context: StageContext, breakFn: () => void): Promise<TOut>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SubflowExecutor — Isolated recursive execution with I/O mapping.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* - Execute subflows with isolated ExecutionRuntime contexts
|
|
6
|
+
* - Apply input/output mapping via SubflowInputMapper
|
|
7
|
+
* - Handle nested subflow detection and delegation
|
|
8
|
+
* - Track subflow results for debugging/visualization
|
|
9
|
+
*
|
|
10
|
+
* Each subflow gets its own GlobalStore for isolation.
|
|
11
|
+
* The subflow's `next` chain after children is NOT executed inside —
|
|
12
|
+
* the parent's executeNode continues with node.next after return.
|
|
13
|
+
*/
|
|
14
|
+
import type { StageContext } from '../../memory/StageContext';
|
|
15
|
+
import type { StageNode } from '../graph/StageNode';
|
|
16
|
+
import type { HandlerDeps, StageFunction, SubflowResult } from '../types';
|
|
17
|
+
import type { NodeResolver } from './NodeResolver';
|
|
18
|
+
/** Callback for running a stage function. Avoids circular dep with traverser. */
|
|
19
|
+
export type ExecuteStageFn<TOut = any, TScope = any> = (node: StageNode<TOut, TScope>, stageFunc: StageFunction<TOut, TScope>, context: StageContext, breakFn: () => void) => Promise<TOut>;
|
|
20
|
+
/** Callback for calling the traversal extractor. */
|
|
21
|
+
export type CallExtractorFn<TOut = any, TScope = any> = (node: StageNode<TOut, TScope>, context: StageContext, stagePath: string, stageOutput?: unknown, errorInfo?: {
|
|
22
|
+
type: string;
|
|
23
|
+
message: string;
|
|
24
|
+
}) => void;
|
|
25
|
+
/** Callback for getting a stage function from the stage map. */
|
|
26
|
+
export type GetStageFnFn<TOut = any, TScope = any> = (node: StageNode<TOut, TScope>) => StageFunction<TOut, TScope> | undefined;
|
|
27
|
+
export declare class SubflowExecutor<TOut = any, TScope = any> {
|
|
28
|
+
private deps;
|
|
29
|
+
private nodeResolver;
|
|
30
|
+
private executeStage;
|
|
31
|
+
private callExtractor;
|
|
32
|
+
private getStageFn;
|
|
33
|
+
private currentSubflowDeps?;
|
|
34
|
+
private currentSubflowRoot?;
|
|
35
|
+
private subflowResultsMap?;
|
|
36
|
+
constructor(deps: HandlerDeps<TOut, TScope>, nodeResolver: NodeResolver<TOut, TScope>, executeStage: ExecuteStageFn<TOut, TScope>, callExtractor: CallExtractorFn<TOut, TScope>, getStageFn: GetStageFnFn<TOut, TScope>);
|
|
37
|
+
/**
|
|
38
|
+
* Execute a subflow with isolated context.
|
|
39
|
+
*
|
|
40
|
+
* 1. Creates a fresh ExecutionRuntime for the subflow
|
|
41
|
+
* 2. Applies input mapping to seed the subflow's GlobalStore
|
|
42
|
+
* 3. Executes the subflow's internal structure
|
|
43
|
+
* 4. Applies output mapping to write results back to parent scope
|
|
44
|
+
* 5. Stores execution data for debugging/visualization
|
|
45
|
+
*/
|
|
46
|
+
executeSubflow(node: StageNode<TOut, TScope>, parentContext: StageContext, breakFlag: {
|
|
47
|
+
shouldBreak: boolean;
|
|
48
|
+
}, branchPath: string | undefined, subflowResultsMap: Map<string, SubflowResult>): Promise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* Internal execution within subflow context.
|
|
51
|
+
* Mirrors the traverser's executeNode but within the subflow's isolated runtime.
|
|
52
|
+
*/
|
|
53
|
+
private executeSubflowInternal;
|
|
54
|
+
private getStagePath;
|
|
55
|
+
private executeNodeChildrenInternal;
|
|
56
|
+
private executeSelectedChildrenInternal;
|
|
57
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SubflowInputMapper — Pure functions for subflow data contracts.
|
|
3
|
+
*
|
|
4
|
+
* Mental model: Subflow = Pure Function
|
|
5
|
+
* - Isolated scope (own GlobalStore)
|
|
6
|
+
* - Explicit inputs via inputMapper
|
|
7
|
+
* - Explicit outputs via outputMapper
|
|
8
|
+
*
|
|
9
|
+
* | Scenario | Behavior |
|
|
10
|
+
* |-----------------|-------------------------------------------|
|
|
11
|
+
* | No inputMapper | Subflow starts with empty scope |
|
|
12
|
+
* | No outputMapper | Subflow scope changes discarded |
|
|
13
|
+
* | Both present | Full data contract (args in, results out) |
|
|
14
|
+
* | Neither present | Complete isolation (side effects only) |
|
|
15
|
+
*/
|
|
16
|
+
import type { StageContext } from '../../memory/StageContext';
|
|
17
|
+
import type { HandlerDeps, IExecutionRuntime, SubflowMountOptions } from '../types';
|
|
18
|
+
/** Extract values from parent scope using inputMapper. */
|
|
19
|
+
export declare function extractParentScopeValues<TParentScope, TSubflowInput>(parentScope: TParentScope, options?: SubflowMountOptions<TParentScope, TSubflowInput>): TSubflowInput | Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the initial scope values for a subflow.
|
|
22
|
+
* Always isolated — only inputMapper values are included.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getInitialScopeValues<TParentScope, TSubflowInput>(parentScope: TParentScope, options?: SubflowMountOptions<TParentScope, TSubflowInput>): Record<string, unknown>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new HandlerDeps for subflow execution.
|
|
27
|
+
* Key: sets readOnlyContext to mapped input so StageRunner passes it to ScopeFactory.
|
|
28
|
+
*/
|
|
29
|
+
export declare function createSubflowHandlerDeps<TOut = any, TScope = any>(parentDeps: HandlerDeps<TOut, TScope>, subflowRuntime: IExecutionRuntime, mappedInput: Record<string, unknown>): HandlerDeps<TOut, TScope>;
|
|
30
|
+
/**
|
|
31
|
+
* Seed the subflow's GlobalStore with initial values.
|
|
32
|
+
* Called before subflow execution to make inputMapper values available.
|
|
33
|
+
*/
|
|
34
|
+
export declare function seedSubflowGlobalStore(subflowRuntime: IExecutionRuntime, initialValues: Record<string, unknown>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Apply output mapping after subflow completion.
|
|
37
|
+
* Writes mapped values back to parent scope using merge semantics:
|
|
38
|
+
* arrays are appended, objects are shallow-merged, scalars are replaced.
|
|
39
|
+
*/
|
|
40
|
+
export declare function applyOutputMapping<TParentScope, TSubflowOutput>(subflowOutput: TSubflowOutput, parentScope: TParentScope, parentContext: StageContext, options?: SubflowMountOptions<TParentScope, any, TSubflowOutput>): Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Barrel export for all engine handler modules.
|
|
3
|
+
*/
|
|
4
|
+
export { StageRunner } from './StageRunner';
|
|
5
|
+
export { NodeResolver } from './NodeResolver';
|
|
6
|
+
export type { ExecuteNodeFn } from './ChildrenExecutor';
|
|
7
|
+
export { ChildrenExecutor } from './ChildrenExecutor';
|
|
8
|
+
export type { CallExtractorFn, GetStagePathFn, RunStageFn } from './DeciderHandler';
|
|
9
|
+
export { DeciderHandler } from './DeciderHandler';
|
|
10
|
+
export { SelectorHandler } from './SelectorHandler';
|
|
11
|
+
export { ContinuationResolver, DEFAULT_MAX_ITERATIONS } from './ContinuationResolver';
|
|
12
|
+
export { SubflowExecutor } from './SubflowExecutor';
|
|
13
|
+
export { applyOutputMapping, createSubflowHandlerDeps, extractParentScopeValues, getInitialScopeValues, seedSubflowGlobalStore, } from './SubflowInputMapper';
|
|
14
|
+
export { ExtractorRunner } from './ExtractorRunner';
|
|
15
|
+
export { computeNodeType, RuntimeStructureManager } from './RuntimeStructureManager';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* engine/ — Graph traversal engine library.
|
|
3
|
+
*
|
|
4
|
+
* Executes flowcharts built by FlowChartBuilder via pre-order DFS traversal.
|
|
5
|
+
* Handles linear, fork, decider, selector, loop, and subflow node shapes.
|
|
6
|
+
*/
|
|
7
|
+
export type { TraverserOptions } from './traversal/FlowchartTraverser';
|
|
8
|
+
export { FlowchartTraverser } from './traversal/FlowchartTraverser';
|
|
9
|
+
export { isStageNodeReturn } from './graph/StageNode';
|
|
10
|
+
export * from './types';
|
|
11
|
+
export * from './handlers';
|
|
12
|
+
export type { CombinedNarrativeEntry, CombinedNarrativeOptions } from './narrative/CombinedNarrativeBuilder';
|
|
13
|
+
export { CombinedNarrativeBuilder } from './narrative/CombinedNarrativeBuilder';
|
|
14
|
+
export { ControlFlowNarrativeGenerator } from './narrative/ControlFlowNarrativeGenerator';
|
|
15
|
+
export { NullControlFlowNarrativeGenerator } from './narrative/NullControlFlowNarrativeGenerator';
|
|
16
|
+
export type { IControlFlowNarrative } from './narrative/types';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CombinedNarrativeBuilder — Merges flow-level narrative with data-level operations.
|
|
3
|
+
*
|
|
4
|
+
* ControlFlowNarrativeGenerator captures FLOW — what stages ran, which branches were taken.
|
|
5
|
+
* NarrativeRecorder (scope/) captures DATA — what values were read, written, updated.
|
|
6
|
+
*
|
|
7
|
+
* This builder weaves both into a single unified narrative:
|
|
8
|
+
* Stage 1: "Receive Application"
|
|
9
|
+
* Step 1: Write applicantName = 'Bob'
|
|
10
|
+
* [Condition]: risk tier is high → chose "Reject Application"
|
|
11
|
+
*/
|
|
12
|
+
import type { NarrativeRecorder } from '../../scope/recorders/NarrativeRecorder';
|
|
13
|
+
export interface CombinedNarrativeEntry {
|
|
14
|
+
type: 'stage' | 'step' | 'condition' | 'fork' | 'subflow' | 'loop' | 'break' | 'error';
|
|
15
|
+
text: string;
|
|
16
|
+
depth: number;
|
|
17
|
+
stageName?: string;
|
|
18
|
+
stepNumber?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface CombinedNarrativeOptions {
|
|
21
|
+
includeStepNumbers?: boolean;
|
|
22
|
+
includeValues?: boolean;
|
|
23
|
+
indent?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class CombinedNarrativeBuilder {
|
|
26
|
+
private options;
|
|
27
|
+
constructor(options?: CombinedNarrativeOptions);
|
|
28
|
+
buildEntries(flowSentences: string[], recorder: NarrativeRecorder): CombinedNarrativeEntry[];
|
|
29
|
+
build(flowSentences: string[], recorder: NarrativeRecorder): string[];
|
|
30
|
+
private addStepEntries;
|
|
31
|
+
private findStageData;
|
|
32
|
+
private parseSentence;
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ControlFlowNarrativeGenerator — Active implementation of IControlFlowNarrative.
|
|
3
|
+
*
|
|
4
|
+
* Converts traversal events into plain-English sentences at traversal time.
|
|
5
|
+
* Produces a human-readable story as a first-class output, enabling any consumer
|
|
6
|
+
* (cheaper LLM, follow-up agent, logging system) to understand what happened
|
|
7
|
+
* without parsing technical structures.
|
|
8
|
+
*
|
|
9
|
+
* This is the FLOW narrative — it captures control flow decisions.
|
|
10
|
+
* The DATA narrative comes from scope/recorders/NarrativeRecorder.
|
|
11
|
+
* CombinedNarrativeBuilder merges both into one story.
|
|
12
|
+
*/
|
|
13
|
+
import type { IControlFlowNarrative } from './types';
|
|
14
|
+
export declare class ControlFlowNarrativeGenerator implements IControlFlowNarrative {
|
|
15
|
+
private sentences;
|
|
16
|
+
private isFirstStage;
|
|
17
|
+
onStageExecuted(stageName: string, displayName?: string, description?: string): void;
|
|
18
|
+
onNext(fromStage: string, toStage: string, toDisplayName?: string, description?: string): void;
|
|
19
|
+
onDecision(deciderName: string, chosenBranch: string, chosenDisplayName?: string, rationale?: string, deciderDescription?: string): void;
|
|
20
|
+
onFork(parentStage: string, childNames: string[]): void;
|
|
21
|
+
onSelected(parentStage: string, selectedNames: string[], totalCount: number): void;
|
|
22
|
+
onSubflowEntry(subflowName: string): void;
|
|
23
|
+
onSubflowExit(subflowName: string): void;
|
|
24
|
+
onLoop(targetStage: string, targetDisplayName: string | undefined, iteration: number, description?: string): void;
|
|
25
|
+
onBreak(stageName: string, displayName?: string): void;
|
|
26
|
+
onError(stageName: string, errorMessage: string, displayName?: string): void;
|
|
27
|
+
/** Returns a defensive copy of accumulated sentences. */
|
|
28
|
+
getSentences(): string[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NullControlFlowNarrativeGenerator — Zero-cost no-op (Null Object pattern).
|
|
3
|
+
*
|
|
4
|
+
* When narrative is disabled, handlers call this unconditionally.
|
|
5
|
+
* All methods are empty bodies — zero allocation, zero string formatting.
|
|
6
|
+
* getSentences() returns a bare [] literal to avoid even a single array allocation.
|
|
7
|
+
*/
|
|
8
|
+
import type { IControlFlowNarrative } from './types';
|
|
9
|
+
export declare class NullControlFlowNarrativeGenerator implements IControlFlowNarrative {
|
|
10
|
+
onStageExecuted(): void;
|
|
11
|
+
onNext(): void;
|
|
12
|
+
onDecision(): void;
|
|
13
|
+
onFork(): void;
|
|
14
|
+
onSelected(): void;
|
|
15
|
+
onSubflowEntry(): void;
|
|
16
|
+
onSubflowExit(): void;
|
|
17
|
+
onLoop(): void;
|
|
18
|
+
onBreak(): void;
|
|
19
|
+
onError(): void;
|
|
20
|
+
getSentences(): string[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { CombinedNarrativeEntry, CombinedNarrativeOptions } from './CombinedNarrativeBuilder';
|
|
2
|
+
export { CombinedNarrativeBuilder } from './CombinedNarrativeBuilder';
|
|
3
|
+
export { ControlFlowNarrativeGenerator } from './ControlFlowNarrativeGenerator';
|
|
4
|
+
export { NullControlFlowNarrativeGenerator } from './NullControlFlowNarrativeGenerator';
|
|
5
|
+
export type { IControlFlowNarrative } from './types';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IControlFlowNarrative — Interface for control flow narrative generation.
|
|
3
|
+
*
|
|
4
|
+
* Captures FLOW events during traversal: decisions, forks, loops, subflows.
|
|
5
|
+
* Complementary to scope/recorders/NarrativeRecorder which captures DATA events.
|
|
6
|
+
*
|
|
7
|
+
* Uses Null Object pattern: NullControlFlowNarrativeGenerator satisfies this
|
|
8
|
+
* interface with empty methods for zero-cost disabled path.
|
|
9
|
+
*/
|
|
10
|
+
export interface IControlFlowNarrative {
|
|
11
|
+
/** Called when a stage executes. First stage uses distinct opening pattern. */
|
|
12
|
+
onStageExecuted(stageName: string, displayName?: string, description?: string): void;
|
|
13
|
+
/** Called on linear continuation from one stage to the next. */
|
|
14
|
+
onNext(fromStage: string, toStage: string, toDisplayName?: string, description?: string): void;
|
|
15
|
+
/** Called when a decider selects a branch. Most valuable for LLM context. */
|
|
16
|
+
onDecision(deciderName: string, chosenBranch: string, chosenDisplayName?: string, rationale?: string, deciderDescription?: string): void;
|
|
17
|
+
/** Called when a fork executes all children in parallel. */
|
|
18
|
+
onFork(parentStage: string, childNames: string[]): void;
|
|
19
|
+
/** Called when a selector picks a subset of children. */
|
|
20
|
+
onSelected(parentStage: string, selectedNames: string[], totalCount: number): void;
|
|
21
|
+
/** Called when entering a subflow (nested context boundary). */
|
|
22
|
+
onSubflowEntry(subflowName: string): void;
|
|
23
|
+
/** Called when exiting a subflow. */
|
|
24
|
+
onSubflowExit(subflowName: string): void;
|
|
25
|
+
/** Called on loop iteration (back-edge traversal). */
|
|
26
|
+
onLoop(targetStage: string, targetDisplayName: string | undefined, iteration: number, description?: string): void;
|
|
27
|
+
/** Called when a stage triggers break (early termination). */
|
|
28
|
+
onBreak(stageName: string, displayName?: string): void;
|
|
29
|
+
/** Called when a stage throws an error. */
|
|
30
|
+
onError(stageName: string, errorMessage: string, displayName?: string): void;
|
|
31
|
+
/** Returns accumulated narrative sentences in execution order. */
|
|
32
|
+
getSentences(): string[];
|
|
33
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlowchartTraverser — Pre-order DFS traversal of StageNode graph.
|
|
3
|
+
*
|
|
4
|
+
* Unified traversal algorithm for all node shapes:
|
|
5
|
+
* const pre = await prep();
|
|
6
|
+
* const [x, y] = await Promise.all([fx(pre), fy(pre)]);
|
|
7
|
+
* return await next(x, y);
|
|
8
|
+
*
|
|
9
|
+
* For each node, executeNode follows 7 phases:
|
|
10
|
+
* 0. CLASSIFY — subflow detection, early delegation
|
|
11
|
+
* 1. VALIDATE — node invariants, role markers
|
|
12
|
+
* 2. EXECUTE — run stage fn, commit, break check
|
|
13
|
+
* 3. DYNAMIC — StageNode return detection, subflow auto-registration, structure updates
|
|
14
|
+
* 4. CHILDREN — fork/selector/decider dispatch
|
|
15
|
+
* 5. CONTINUE — dynamic next / linear next resolution
|
|
16
|
+
* 6. LEAF — no continuation, return output
|
|
17
|
+
*
|
|
18
|
+
* Break semantics: If a stage calls breakFn(), commit and STOP.
|
|
19
|
+
* Patch model: Stage writes into local patch; commitPatch() after return or throw.
|
|
20
|
+
*/
|
|
21
|
+
/// <reference types="node" />
|
|
22
|
+
import type { ScopeProtectionMode } from '../../scope/protection/types';
|
|
23
|
+
import type { ExtractorError, IExecutionRuntime, ILogger, ScopeFactory, SerializedPipelineStructure, StageFunction, StageNode, StreamHandlers, SubflowResult, TraversalExtractor, TraversalResult } from '../types';
|
|
24
|
+
export interface TraverserOptions<TOut = any, TScope = any> {
|
|
25
|
+
root: StageNode<TOut, TScope>;
|
|
26
|
+
stageMap: Map<string, StageFunction<TOut, TScope>>;
|
|
27
|
+
scopeFactory: ScopeFactory<TScope>;
|
|
28
|
+
executionRuntime: IExecutionRuntime;
|
|
29
|
+
readOnlyContext?: unknown;
|
|
30
|
+
throttlingErrorChecker?: (error: unknown) => boolean;
|
|
31
|
+
streamHandlers?: StreamHandlers;
|
|
32
|
+
extractor?: TraversalExtractor;
|
|
33
|
+
scopeProtectionMode?: ScopeProtectionMode;
|
|
34
|
+
subflows?: Record<string, {
|
|
35
|
+
root: StageNode<TOut, TScope>;
|
|
36
|
+
}>;
|
|
37
|
+
enrichSnapshots?: boolean;
|
|
38
|
+
narrativeEnabled?: boolean;
|
|
39
|
+
buildTimeStructure?: SerializedPipelineStructure;
|
|
40
|
+
logger: ILogger;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
export declare class FlowchartTraverser<TOut = any, TScope = any> {
|
|
44
|
+
private readonly root;
|
|
45
|
+
private stageMap;
|
|
46
|
+
private readonly executionRuntime;
|
|
47
|
+
private subflows?;
|
|
48
|
+
private readonly logger;
|
|
49
|
+
private readonly signal?;
|
|
50
|
+
private readonly nodeResolver;
|
|
51
|
+
private readonly childrenExecutor;
|
|
52
|
+
private readonly subflowExecutor;
|
|
53
|
+
private readonly stageRunner;
|
|
54
|
+
private readonly continuationResolver;
|
|
55
|
+
private readonly deciderHandler;
|
|
56
|
+
private readonly selectorHandler;
|
|
57
|
+
private readonly structureManager;
|
|
58
|
+
private readonly extractorRunner;
|
|
59
|
+
private readonly narrativeGenerator;
|
|
60
|
+
private subflowResults;
|
|
61
|
+
constructor(opts: TraverserOptions<TOut, TScope>);
|
|
62
|
+
private createDeps;
|
|
63
|
+
execute(): Promise<TraversalResult>;
|
|
64
|
+
getRuntimeStructure(): SerializedPipelineStructure | undefined;
|
|
65
|
+
getSnapshot(): {
|
|
66
|
+
sharedState: Record<string, unknown>;
|
|
67
|
+
executionTree: unknown;
|
|
68
|
+
commitLog: unknown[];
|
|
69
|
+
};
|
|
70
|
+
getRuntime(): IExecutionRuntime;
|
|
71
|
+
setRootObject(path: string[], key: string, value: unknown): void;
|
|
72
|
+
getBranchIds(): string[];
|
|
73
|
+
getRuntimeRoot(): StageNode;
|
|
74
|
+
getSubflowResults(): Map<string, SubflowResult>;
|
|
75
|
+
getExtractedResults<TResult = unknown>(): Map<string, TResult>;
|
|
76
|
+
getExtractorErrors(): ExtractorError[];
|
|
77
|
+
getNarrative(): string[];
|
|
78
|
+
private getStageFn;
|
|
79
|
+
private executeStage;
|
|
80
|
+
/**
|
|
81
|
+
* Pre-order DFS traversal — the core algorithm.
|
|
82
|
+
* Each call processes one node through all 7 phases.
|
|
83
|
+
*/
|
|
84
|
+
private executeNode;
|
|
85
|
+
private captureDynamicChildrenResult;
|
|
86
|
+
private autoRegisterSubflowDef;
|
|
87
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* types.ts — All type definitions for the engine library.
|
|
3
|
+
*
|
|
4
|
+
* Centralizes type definitions to avoid circular dependencies.
|
|
5
|
+
* Every handler receives HandlerDeps (the DI bag) instead of importing the traverser.
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
import type { StageContext } from '../memory/StageContext';
|
|
9
|
+
import type { ScopeProtectionMode } from '../scope/protection/types';
|
|
10
|
+
import type { StageNode } from './graph/StageNode';
|
|
11
|
+
import type { IControlFlowNarrative } from './narrative/types';
|
|
12
|
+
export type { Decider, Selector, StageNode } from './graph/StageNode';
|
|
13
|
+
/** Minimal logging contract. Mirrors Console API subset. */
|
|
14
|
+
export interface ILogger {
|
|
15
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
16
|
+
log(message?: any, ...optionalParams: any[]): void;
|
|
17
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
18
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
19
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
20
|
+
}
|
|
21
|
+
/** Default console-based logger. */
|
|
22
|
+
export declare const defaultLogger: ILogger;
|
|
23
|
+
/** Callback that receives tokens during streaming. */
|
|
24
|
+
export type StreamCallback = (token: string) => void;
|
|
25
|
+
/**
|
|
26
|
+
* The function signature for stage handlers.
|
|
27
|
+
* - TOut: return type produced by the stage
|
|
28
|
+
* - TScope: the scope object passed to the stage
|
|
29
|
+
* - Optional 3rd parameter `streamCallback` injected for streaming stages.
|
|
30
|
+
*/
|
|
31
|
+
export type StageFunction<TOut = any, TScope = any> = (scope: TScope, breakPipeline: () => void, streamCallback?: StreamCallback) => Promise<TOut> | TOut;
|
|
32
|
+
/** Factory that creates a scope instance for each stage. */
|
|
33
|
+
export type ScopeFactory<TScope = any> = (context: StageContext, stageName: string, readOnlyContext?: unknown) => TScope;
|
|
34
|
+
export type StreamTokenHandler = (streamId: string, token: string) => void;
|
|
35
|
+
export type StreamLifecycleHandler = (streamId: string, fullText?: string) => void;
|
|
36
|
+
export interface StreamHandlers {
|
|
37
|
+
onToken?: StreamTokenHandler;
|
|
38
|
+
onStart?: StreamLifecycleHandler;
|
|
39
|
+
onEnd?: StreamLifecycleHandler;
|
|
40
|
+
}
|
|
41
|
+
export interface SubflowMountOptions<TParentScope = any, TSubflowInput = any, TSubflowOutput = any> {
|
|
42
|
+
inputMapper?: (parentScope: TParentScope) => TSubflowInput;
|
|
43
|
+
outputMapper?: (subflowOutput: TSubflowOutput, parentScope: TParentScope) => Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
export interface SubflowResult {
|
|
46
|
+
subflowId: string;
|
|
47
|
+
subflowName: string;
|
|
48
|
+
treeContext: {
|
|
49
|
+
globalContext: Record<string, unknown>;
|
|
50
|
+
stageContexts: Record<string, unknown>;
|
|
51
|
+
history: unknown[];
|
|
52
|
+
};
|
|
53
|
+
parentStageId: string;
|
|
54
|
+
pipelineStructure?: unknown;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* IExecutionRuntime — Interface for the runtime environment.
|
|
58
|
+
*
|
|
59
|
+
* Defines the contract that engine handlers need from the runner layer,
|
|
60
|
+
* avoiding circular imports between engine/ and runner/.
|
|
61
|
+
*/
|
|
62
|
+
export interface IExecutionRuntime {
|
|
63
|
+
globalStore: {
|
|
64
|
+
getState(): Record<string, unknown>;
|
|
65
|
+
};
|
|
66
|
+
rootStageContext: StageContext;
|
|
67
|
+
executionHistory: {
|
|
68
|
+
list(): unknown[];
|
|
69
|
+
};
|
|
70
|
+
getSnapshot(): {
|
|
71
|
+
sharedState: Record<string, unknown>;
|
|
72
|
+
executionTree: unknown;
|
|
73
|
+
commitLog: unknown[];
|
|
74
|
+
};
|
|
75
|
+
setRootObject(path: string[], key: string, value: unknown): void;
|
|
76
|
+
getPipelines(): string[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* HandlerDeps — Dependency injection bag passed to all handler modules.
|
|
80
|
+
*
|
|
81
|
+
* Provides shared state (stageMap, runtime, scopeFactory, etc.) without
|
|
82
|
+
* handlers needing to import the traverser directly. Avoids circular deps.
|
|
83
|
+
*/
|
|
84
|
+
export interface HandlerDeps<TOut = any, TScope = any> {
|
|
85
|
+
stageMap: Map<string, StageFunction<TOut, TScope>>;
|
|
86
|
+
root: StageNode<TOut, TScope>;
|
|
87
|
+
executionRuntime: IExecutionRuntime;
|
|
88
|
+
ScopeFactory: ScopeFactory<TScope>;
|
|
89
|
+
subflows?: Record<string, {
|
|
90
|
+
root: StageNode<TOut, TScope>;
|
|
91
|
+
}>;
|
|
92
|
+
throttlingErrorChecker?: (error: unknown) => boolean;
|
|
93
|
+
streamHandlers?: StreamHandlers;
|
|
94
|
+
scopeProtectionMode: ScopeProtectionMode;
|
|
95
|
+
readOnlyContext?: unknown;
|
|
96
|
+
narrativeGenerator: IControlFlowNarrative;
|
|
97
|
+
logger: ILogger;
|
|
98
|
+
signal?: AbortSignal;
|
|
99
|
+
}
|
|
100
|
+
/** Options for FlowChartExecutor.run(). */
|
|
101
|
+
export interface RunOptions {
|
|
102
|
+
/** AbortSignal for cooperative cancellation. */
|
|
103
|
+
signal?: AbortSignal;
|
|
104
|
+
/** Timeout in milliseconds. Creates an internal AbortController. */
|
|
105
|
+
timeoutMs?: number;
|
|
106
|
+
}
|
|
107
|
+
export type FlowControlType = 'next' | 'branch' | 'children' | 'selected' | 'subflow' | 'loop';
|
|
108
|
+
export interface FlowMessage {
|
|
109
|
+
type: FlowControlType;
|
|
110
|
+
description: string;
|
|
111
|
+
targetStage?: string | string[];
|
|
112
|
+
rationale?: string;
|
|
113
|
+
count?: number;
|
|
114
|
+
iteration?: number;
|
|
115
|
+
timestamp?: number;
|
|
116
|
+
}
|
|
117
|
+
export interface RuntimeStructureMetadata {
|
|
118
|
+
type: 'stage' | 'decider' | 'fork' | 'streaming';
|
|
119
|
+
subflowId?: string;
|
|
120
|
+
isSubflowRoot?: boolean;
|
|
121
|
+
subflowName?: string;
|
|
122
|
+
isParallelChild?: boolean;
|
|
123
|
+
parallelGroupId?: string;
|
|
124
|
+
loopTarget?: string;
|
|
125
|
+
isDynamic?: boolean;
|
|
126
|
+
isLoopReference?: boolean;
|
|
127
|
+
streamId?: string;
|
|
128
|
+
}
|
|
129
|
+
export interface StageSnapshot<TOut = any, TScope = any> {
|
|
130
|
+
node: StageNode<TOut, TScope>;
|
|
131
|
+
context: StageContext;
|
|
132
|
+
stepNumber: number;
|
|
133
|
+
structureMetadata: RuntimeStructureMetadata;
|
|
134
|
+
scopeState?: Record<string, unknown>;
|
|
135
|
+
debugInfo?: {
|
|
136
|
+
logs: Record<string, unknown>;
|
|
137
|
+
errors: Record<string, unknown>;
|
|
138
|
+
metrics: Record<string, unknown>;
|
|
139
|
+
evals: Record<string, unknown>;
|
|
140
|
+
flowMessages?: FlowMessage[];
|
|
141
|
+
};
|
|
142
|
+
stageOutput?: unknown;
|
|
143
|
+
errorInfo?: {
|
|
144
|
+
type: string;
|
|
145
|
+
message: string;
|
|
146
|
+
};
|
|
147
|
+
historyIndex?: number;
|
|
148
|
+
}
|
|
149
|
+
export type TraversalExtractor<TResult = unknown> = (snapshot: StageSnapshot) => TResult | undefined | null;
|
|
150
|
+
export interface ExtractorError {
|
|
151
|
+
stagePath: string;
|
|
152
|
+
message: string;
|
|
153
|
+
error: unknown;
|
|
154
|
+
}
|
|
155
|
+
export type NodeResultType = {
|
|
156
|
+
id: string;
|
|
157
|
+
result: unknown;
|
|
158
|
+
isError?: boolean;
|
|
159
|
+
};
|
|
160
|
+
export type BranchResult = {
|
|
161
|
+
result: string | Error;
|
|
162
|
+
isError: boolean;
|
|
163
|
+
};
|
|
164
|
+
export type BranchResults = {
|
|
165
|
+
[branchId: string]: BranchResult;
|
|
166
|
+
};
|
|
167
|
+
export type TraversalResult = BranchResults | string | Error;
|
|
168
|
+
export interface SerializedPipelineNode {
|
|
169
|
+
name: string;
|
|
170
|
+
id?: string;
|
|
171
|
+
type?: 'stage' | 'decider' | 'fork' | 'streaming' | 'loop' | 'user' | 'tool' | 'function' | 'sequence';
|
|
172
|
+
displayName?: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
children?: SerializedPipelineNode[];
|
|
175
|
+
next?: SerializedPipelineNode;
|
|
176
|
+
branches?: Record<string, SerializedPipelineNode>;
|
|
177
|
+
hasDecider?: boolean;
|
|
178
|
+
hasSelector?: boolean;
|
|
179
|
+
hasSubtree?: boolean;
|
|
180
|
+
isStreaming?: boolean;
|
|
181
|
+
streamId?: string;
|
|
182
|
+
isSubflowRoot?: boolean;
|
|
183
|
+
subflowId?: string;
|
|
184
|
+
subflowName?: string;
|
|
185
|
+
loopTarget?: string;
|
|
186
|
+
isLoopReference?: boolean;
|
|
187
|
+
isParallelChild?: boolean;
|
|
188
|
+
parallelGroupId?: string;
|
|
189
|
+
isDynamic?: boolean;
|
|
190
|
+
}
|
|
191
|
+
export type FlowChart<TOut = any, TScope = any> = {
|
|
192
|
+
root: StageNode<TOut, TScope>;
|
|
193
|
+
stageMap: Map<string, StageFunction<TOut, TScope>>;
|
|
194
|
+
extractor?: TraversalExtractor;
|
|
195
|
+
subflows?: Record<string, {
|
|
196
|
+
root: StageNode<TOut, TScope>;
|
|
197
|
+
}>;
|
|
198
|
+
enrichSnapshots?: boolean;
|
|
199
|
+
enableNarrative?: boolean;
|
|
200
|
+
logger?: ILogger;
|
|
201
|
+
buildTimeStructure?: SerializedPipelineStructure;
|
|
202
|
+
};
|
|
203
|
+
/** Alias for SerializedPipelineNode used as full structure */
|
|
204
|
+
export type SerializedPipelineStructure = SerializedPipelineNode & {
|
|
205
|
+
branchIds?: string[];
|
|
206
|
+
subflowStructure?: SerializedPipelineStructure;
|
|
207
|
+
iterationCount?: number;
|
|
208
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DiagnosticCollector — Per-stage metadata collector
|
|
3
|
+
*
|
|
4
|
+
* Collects non-execution metadata during a stage's run:
|
|
5
|
+
* - logs, errors, metrics, evals, flowMessages
|
|
6
|
+
*
|
|
7
|
+
* Like a compiler's diagnostic collector — gathers warnings, errors,
|
|
8
|
+
* and timing info without affecting the compilation output.
|
|
9
|
+
*/
|
|
10
|
+
import type { FlowMessage } from './types';
|
|
11
|
+
export declare class DiagnosticCollector {
|
|
12
|
+
logContext: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
errorContext: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
18
|
+
metricContext: {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
evalContext: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
};
|
|
24
|
+
flowMessages: FlowMessage[];
|
|
25
|
+
addLog(key: string, value: any, path?: string[]): void;
|
|
26
|
+
setLog(key: string, value: any, path?: string[]): void;
|
|
27
|
+
addError(key: string, value: any, path?: string[]): void;
|
|
28
|
+
addMetric(key: string, value: any, path?: string[]): void;
|
|
29
|
+
setMetric(key: string, value: any, path?: string[]): void;
|
|
30
|
+
addEval(key: string, value: any, path?: string[]): void;
|
|
31
|
+
setEval(key: string, value: any, path?: string[]): void;
|
|
32
|
+
addFlowMessage(flowMessage: FlowMessage): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventLog — Time-travel snapshot storage for flowchart execution
|
|
3
|
+
*
|
|
4
|
+
* Like git history: stores commit bundles (diffs), not full snapshots.
|
|
5
|
+
* materialise(stepIdx) reconstructs state at any point by replaying commits.
|
|
6
|
+
*/
|
|
7
|
+
import type { CommitBundle } from './types';
|
|
8
|
+
export declare class EventLog {
|
|
9
|
+
/** Base snapshot BEFORE the first stage mutates anything. */
|
|
10
|
+
private base;
|
|
11
|
+
/** Ordered list of commit bundles. */
|
|
12
|
+
private steps;
|
|
13
|
+
constructor(initialMemory: any);
|
|
14
|
+
/**
|
|
15
|
+
* Reconstructs the full state at any given step.
|
|
16
|
+
* Replays commits from the beginning — O(n) but low memory footprint.
|
|
17
|
+
*/
|
|
18
|
+
materialise(stepIdx?: number): any;
|
|
19
|
+
/** Persists a commit bundle for a finished stage. */
|
|
20
|
+
record(bundle: CommitBundle): void;
|
|
21
|
+
/** Gets all recorded commit bundles. */
|
|
22
|
+
list(): CommitBundle[];
|
|
23
|
+
/** Number of recorded commits. */
|
|
24
|
+
get length(): number;
|
|
25
|
+
/** Wipes history (useful for test resets). */
|
|
26
|
+
clear(): void;
|
|
27
|
+
}
|