@decaf-ts/as-graph 0.2.1 → 0.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.
- package/README.md +274 -2
- package/dist/as-graph.cjs +1 -1
- package/dist/as-graph.cjs.map +1 -1
- package/dist/as-graph.js +1 -1
- package/dist/as-graph.js.map +1 -1
- package/lib/cjs/dagster/DagsterGraphEventBridge.cjs +344 -0
- package/lib/cjs/dagster/DagsterGraphEventBridge.cjs.map +1 -0
- package/lib/cjs/dagster/DagsterGraphExecutionBackend.cjs +789 -0
- package/lib/cjs/dagster/DagsterGraphExecutionBackend.cjs.map +1 -0
- package/lib/cjs/dagster/DagsterGraphQLClient.cjs +738 -0
- package/lib/cjs/dagster/DagsterGraphQLClient.cjs.map +1 -0
- package/lib/cjs/dagster/DagsterResultMapper.cjs +56 -0
- package/lib/cjs/dagster/DagsterResultMapper.cjs.map +1 -0
- package/lib/cjs/dagster/DagsterTypes.cjs +4 -0
- package/lib/cjs/dagster/DagsterTypes.cjs.map +1 -0
- package/lib/cjs/dagster/capabilities.cjs +102 -0
- package/lib/cjs/dagster/capabilities.cjs.map +1 -0
- package/lib/cjs/dagster/constants.cjs +92 -0
- package/lib/cjs/dagster/constants.cjs.map +1 -0
- package/lib/cjs/dagster/index.cjs +33 -0
- package/lib/cjs/dagster/index.cjs.map +1 -0
- package/lib/cjs/engine/constants.cjs +6 -1
- package/lib/cjs/engine/constants.cjs.map +1 -1
- package/lib/cjs/engine/execution/GraphCodeMode.cjs +137 -0
- package/lib/cjs/engine/execution/GraphCodeMode.cjs.map +1 -0
- package/lib/cjs/engine/execution/GraphExecutionBackend.cjs +89 -0
- package/lib/cjs/engine/execution/GraphExecutionBackend.cjs.map +1 -0
- package/lib/cjs/engine/execution/GraphExecutionBackendRegistry.cjs +107 -0
- package/lib/cjs/engine/execution/GraphExecutionBackendRegistry.cjs.map +1 -0
- package/lib/cjs/engine/execution/GraphExecutionEngine.cjs +250 -733
- package/lib/cjs/engine/execution/GraphExecutionEngine.cjs.map +1 -1
- package/lib/cjs/engine/execution/LocalGraphExecutionBackend.cjs +804 -0
- package/lib/cjs/engine/execution/LocalGraphExecutionBackend.cjs.map +1 -0
- package/lib/cjs/engine/execution/index.cjs +4 -0
- package/lib/cjs/engine/execution/index.cjs.map +1 -1
- package/lib/cjs/engine/index.cjs +4 -0
- package/lib/cjs/engine/index.cjs.map +1 -1
- package/lib/cjs/engine/runs/GraphRunService.cjs +61 -0
- package/lib/cjs/engine/runs/GraphRunService.cjs.map +1 -1
- package/lib/cjs/engine/services/GraphWorkflowService.cjs +33 -14
- package/lib/cjs/engine/services/GraphWorkflowService.cjs.map +1 -1
- package/lib/cjs/mastra/MastraCapabilities.cjs +171 -0
- package/lib/cjs/mastra/MastraCapabilities.cjs.map +1 -0
- package/lib/cjs/mastra/MastraConditionBridge.cjs +39 -0
- package/lib/cjs/mastra/MastraConditionBridge.cjs.map +1 -0
- package/lib/cjs/mastra/MastraEventBridge.cjs +486 -0
- package/lib/cjs/mastra/MastraEventBridge.cjs.map +1 -0
- package/lib/cjs/mastra/MastraGraphExecutionBackend.cjs +351 -0
- package/lib/cjs/mastra/MastraGraphExecutionBackend.cjs.map +1 -0
- package/lib/cjs/mastra/MastraResumeGuard.cjs +127 -0
- package/lib/cjs/mastra/MastraResumeGuard.cjs.map +1 -0
- package/lib/cjs/mastra/MastraSchemaConverter.cjs +124 -0
- package/lib/cjs/mastra/MastraSchemaConverter.cjs.map +1 -0
- package/lib/cjs/mastra/MastraWorkflowCompiler.cjs +461 -0
- package/lib/cjs/mastra/MastraWorkflowCompiler.cjs.map +1 -0
- package/lib/cjs/mastra/MastraWorkflowManager.cjs +401 -0
- package/lib/cjs/mastra/MastraWorkflowManager.cjs.map +1 -0
- package/lib/cjs/mastra/index.cjs +35 -0
- package/lib/cjs/mastra/index.cjs.map +1 -0
- package/lib/cjs/mastra/types.cjs +34 -0
- package/lib/cjs/mastra/types.cjs.map +1 -0
- package/lib/cjs/nest/graph/GraphBackendHost.cjs +146 -0
- package/lib/cjs/nest/graph/GraphBackendHost.cjs.map +1 -0
- package/lib/cjs/nest/graph/GraphEngineCapabilityManifest.cjs +136 -0
- package/lib/cjs/nest/graph/GraphEngineCapabilityManifest.cjs.map +1 -0
- package/lib/cjs/nest/graph/GraphEngineCapabilityService.cjs +140 -0
- package/lib/cjs/nest/graph/GraphEngineCapabilityService.cjs.map +1 -0
- package/lib/cjs/nest/graph/GraphEngineController.cjs +227 -0
- package/lib/cjs/nest/graph/GraphEngineController.cjs.map +1 -0
- package/lib/cjs/nest/graph/GraphExecutionModule.cjs +31 -2
- package/lib/cjs/nest/graph/GraphExecutionModule.cjs.map +1 -1
- package/lib/cjs/nest/graph/index.cjs +4 -0
- package/lib/cjs/nest/graph/index.cjs.map +1 -1
- package/lib/cjs/nest/graph/main.cjs +139 -0
- package/lib/cjs/nest/graph/main.cjs.map +1 -0
- package/lib/cjs/nest/graph/servingErrors.cjs +3 -0
- package/lib/cjs/nest/graph/servingErrors.cjs.map +1 -1
- package/lib/cjs/node/utility/code/node.cjs +11 -3
- package/lib/cjs/node/utility/code/node.cjs.map +1 -1
- package/lib/cjs/shared/graph/catalog/GraphManifestCompiler.cjs +2 -3
- package/lib/cjs/shared/graph/catalog/GraphManifestCompiler.cjs.map +1 -1
- package/lib/cjs/shared/graph/constants.cjs +8 -0
- package/lib/cjs/shared/graph/constants.cjs.map +1 -1
- package/lib/cjs/shared/graph/index.cjs +2 -1
- package/lib/cjs/shared/graph/index.cjs.map +1 -1
- package/lib/cjs/shared/graph/layout/GraphWorkflowLayout.cjs +146 -0
- package/lib/cjs/shared/graph/layout/GraphWorkflowLayout.cjs.map +1 -0
- package/lib/cjs/shared/graph/layout/index.cjs +23 -0
- package/lib/cjs/shared/graph/layout/index.cjs.map +1 -0
- package/lib/cjs/shared/graph/layout/layout-options.cjs +93 -0
- package/lib/cjs/shared/graph/layout/layout-options.cjs.map +1 -0
- package/lib/cjs/shared/ui/index.cjs +8 -10
- package/lib/cjs/shared/ui/index.cjs.map +1 -1
- package/lib/esm/dagster/DagsterGraphEventBridge.js +339 -0
- package/lib/esm/dagster/DagsterGraphEventBridge.js.map +1 -0
- package/lib/esm/dagster/DagsterGraphExecutionBackend.js +781 -0
- package/lib/esm/dagster/DagsterGraphExecutionBackend.js.map +1 -0
- package/lib/esm/dagster/DagsterGraphQLClient.js +733 -0
- package/lib/esm/dagster/DagsterGraphQLClient.js.map +1 -0
- package/lib/esm/dagster/DagsterResultMapper.js +51 -0
- package/lib/esm/dagster/DagsterResultMapper.js.map +1 -0
- package/lib/esm/dagster/DagsterTypes.js +2 -0
- package/lib/esm/dagster/DagsterTypes.js.map +1 -0
- package/lib/esm/dagster/capabilities.js +97 -0
- package/lib/esm/dagster/capabilities.js.map +1 -0
- package/lib/esm/dagster/constants.js +88 -0
- package/lib/esm/dagster/constants.js.map +1 -0
- package/lib/esm/dagster/index.js +16 -0
- package/lib/esm/dagster/index.js.map +1 -0
- package/lib/esm/engine/constants.js +5 -0
- package/lib/esm/engine/constants.js.map +1 -1
- package/lib/esm/engine/execution/GraphCodeMode.js +132 -0
- package/lib/esm/engine/execution/GraphCodeMode.js.map +1 -0
- package/lib/esm/engine/execution/GraphExecutionBackend.js +83 -0
- package/lib/esm/engine/execution/GraphExecutionBackend.js.map +1 -0
- package/lib/esm/engine/execution/GraphExecutionBackendRegistry.js +102 -0
- package/lib/esm/engine/execution/GraphExecutionBackendRegistry.js.map +1 -0
- package/lib/esm/engine/execution/GraphExecutionEngine.js +232 -716
- package/lib/esm/engine/execution/GraphExecutionEngine.js.map +1 -1
- package/lib/esm/engine/execution/LocalGraphExecutionBackend.js +799 -0
- package/lib/esm/engine/execution/LocalGraphExecutionBackend.js.map +1 -0
- package/lib/esm/engine/execution/index.js +4 -0
- package/lib/esm/engine/execution/index.js.map +1 -1
- package/lib/esm/engine/index.js +4 -0
- package/lib/esm/engine/index.js.map +1 -1
- package/lib/esm/engine/runs/GraphRunService.js +62 -1
- package/lib/esm/engine/runs/GraphRunService.js.map +1 -1
- package/lib/esm/engine/services/GraphWorkflowService.js +33 -14
- package/lib/esm/engine/services/GraphWorkflowService.js.map +1 -1
- package/lib/esm/mastra/MastraCapabilities.js +164 -0
- package/lib/esm/mastra/MastraCapabilities.js.map +1 -0
- package/lib/esm/mastra/MastraConditionBridge.js +34 -0
- package/lib/esm/mastra/MastraConditionBridge.js.map +1 -0
- package/lib/esm/mastra/MastraEventBridge.js +481 -0
- package/lib/esm/mastra/MastraEventBridge.js.map +1 -0
- package/lib/esm/mastra/MastraGraphExecutionBackend.js +346 -0
- package/lib/esm/mastra/MastraGraphExecutionBackend.js.map +1 -0
- package/lib/esm/mastra/MastraResumeGuard.js +123 -0
- package/lib/esm/mastra/MastraResumeGuard.js.map +1 -0
- package/lib/esm/mastra/MastraSchemaConverter.js +119 -0
- package/lib/esm/mastra/MastraSchemaConverter.js.map +1 -0
- package/lib/esm/mastra/MastraWorkflowCompiler.js +456 -0
- package/lib/esm/mastra/MastraWorkflowCompiler.js.map +1 -0
- package/lib/esm/mastra/MastraWorkflowManager.js +396 -0
- package/lib/esm/mastra/MastraWorkflowManager.js.map +1 -0
- package/lib/esm/mastra/index.js +18 -0
- package/lib/esm/mastra/index.js.map +1 -0
- package/lib/esm/mastra/types.js +30 -0
- package/lib/esm/mastra/types.js.map +1 -0
- package/lib/esm/nest/graph/GraphBackendHost.js +138 -0
- package/lib/esm/nest/graph/GraphBackendHost.js.map +1 -0
- package/lib/esm/nest/graph/GraphEngineCapabilityManifest.js +129 -0
- package/lib/esm/nest/graph/GraphEngineCapabilityManifest.js.map +1 -0
- package/lib/esm/nest/graph/GraphEngineCapabilityService.js +131 -0
- package/lib/esm/nest/graph/GraphEngineCapabilityService.js.map +1 -0
- package/lib/esm/nest/graph/GraphEngineController.js +218 -0
- package/lib/esm/nest/graph/GraphEngineController.js.map +1 -0
- package/lib/esm/nest/graph/GraphExecutionModule.js +31 -2
- package/lib/esm/nest/graph/GraphExecutionModule.js.map +1 -1
- package/lib/esm/nest/graph/index.js +4 -0
- package/lib/esm/nest/graph/index.js.map +1 -1
- package/lib/esm/nest/graph/main.js +103 -0
- package/lib/esm/nest/graph/main.js.map +1 -0
- package/lib/esm/nest/graph/servingErrors.js +3 -0
- package/lib/esm/nest/graph/servingErrors.js.map +1 -1
- package/lib/esm/node/utility/code/node.js +11 -3
- package/lib/esm/node/utility/code/node.js.map +1 -1
- package/lib/esm/shared/graph/GraphExecutionStateMapper.js.map +1 -1
- package/lib/esm/shared/graph/catalog/GraphManifestCompiler.js +2 -3
- package/lib/esm/shared/graph/catalog/GraphManifestCompiler.js.map +1 -1
- package/lib/esm/shared/graph/constants.js +8 -0
- package/lib/esm/shared/graph/constants.js.map +1 -1
- package/lib/esm/shared/graph/index.js +2 -1
- package/lib/esm/shared/graph/index.js.map +1 -1
- package/lib/esm/shared/graph/layout/GraphWorkflowLayout.js +107 -0
- package/lib/esm/shared/graph/layout/GraphWorkflowLayout.js.map +1 -0
- package/lib/esm/shared/graph/layout/index.js +6 -0
- package/lib/esm/shared/graph/layout/index.js.map +1 -0
- package/lib/esm/shared/graph/layout/layout-options.js +96 -0
- package/lib/esm/shared/graph/layout/layout-options.js.map +1 -0
- package/lib/esm/shared/ui/index.js +8 -10
- package/lib/esm/shared/ui/index.js.map +1 -1
- package/lib/types/dagster/DagsterGraphEventBridge.d.cts +142 -0
- package/lib/types/dagster/DagsterGraphEventBridge.d.mts +142 -0
- package/lib/types/dagster/DagsterGraphExecutionBackend.d.cts +323 -0
- package/lib/types/dagster/DagsterGraphExecutionBackend.d.mts +323 -0
- package/lib/types/dagster/DagsterGraphQLClient.d.cts +231 -0
- package/lib/types/dagster/DagsterGraphQLClient.d.mts +231 -0
- package/lib/types/dagster/DagsterResultMapper.d.cts +50 -0
- package/lib/types/dagster/DagsterResultMapper.d.mts +50 -0
- package/lib/types/dagster/DagsterTypes.d.cts +355 -0
- package/lib/types/dagster/DagsterTypes.d.mts +355 -0
- package/lib/types/dagster/capabilities.d.cts +34 -0
- package/lib/types/dagster/capabilities.d.mts +34 -0
- package/lib/types/dagster/constants.d.cts +87 -0
- package/lib/types/dagster/constants.d.mts +87 -0
- package/lib/types/dagster/index.d.cts +15 -0
- package/lib/types/dagster/index.d.mts +15 -0
- package/lib/types/engine/constants.d.cts +5 -0
- package/lib/types/engine/constants.d.mts +5 -0
- package/lib/types/engine/execution/GraphCodeMode.d.cts +52 -0
- package/lib/types/engine/execution/GraphCodeMode.d.mts +52 -0
- package/lib/types/engine/execution/GraphExecutionBackend.d.cts +306 -0
- package/lib/types/engine/execution/GraphExecutionBackend.d.mts +306 -0
- package/lib/types/engine/execution/GraphExecutionBackendRegistry.d.cts +59 -0
- package/lib/types/engine/execution/GraphExecutionBackendRegistry.d.mts +59 -0
- package/lib/types/engine/execution/GraphExecutionEngine.d.cts +116 -135
- package/lib/types/engine/execution/GraphExecutionEngine.d.mts +116 -135
- package/lib/types/engine/execution/LocalGraphExecutionBackend.d.cts +232 -0
- package/lib/types/engine/execution/LocalGraphExecutionBackend.d.mts +232 -0
- package/lib/types/engine/execution/index.d.cts +4 -0
- package/lib/types/engine/execution/index.d.mts +4 -0
- package/lib/types/engine/index.d.cts +4 -0
- package/lib/types/engine/index.d.mts +4 -0
- package/lib/types/engine/runs/GraphRunService.d.cts +19 -0
- package/lib/types/engine/runs/GraphRunService.d.mts +19 -0
- package/lib/types/engine/services/GraphWorkflowService.d.cts +22 -0
- package/lib/types/engine/services/GraphWorkflowService.d.mts +22 -0
- package/lib/types/mastra/MastraCapabilities.d.cts +86 -0
- package/lib/types/mastra/MastraCapabilities.d.mts +86 -0
- package/lib/types/mastra/MastraConditionBridge.d.cts +38 -0
- package/lib/types/mastra/MastraConditionBridge.d.mts +38 -0
- package/lib/types/mastra/MastraEventBridge.d.cts +189 -0
- package/lib/types/mastra/MastraEventBridge.d.mts +189 -0
- package/lib/types/mastra/MastraGraphExecutionBackend.d.cts +119 -0
- package/lib/types/mastra/MastraGraphExecutionBackend.d.mts +119 -0
- package/lib/types/mastra/MastraResumeGuard.d.cts +58 -0
- package/lib/types/mastra/MastraResumeGuard.d.mts +58 -0
- package/lib/types/mastra/MastraSchemaConverter.d.cts +39 -0
- package/lib/types/mastra/MastraSchemaConverter.d.mts +39 -0
- package/lib/types/mastra/MastraWorkflowCompiler.d.cts +218 -0
- package/lib/types/mastra/MastraWorkflowCompiler.d.mts +218 -0
- package/lib/types/mastra/MastraWorkflowManager.d.cts +220 -0
- package/lib/types/mastra/MastraWorkflowManager.d.mts +220 -0
- package/lib/types/mastra/index.d.cts +17 -0
- package/lib/types/mastra/index.d.mts +17 -0
- package/lib/types/mastra/types.d.cts +222 -0
- package/lib/types/mastra/types.d.mts +222 -0
- package/lib/types/nest/graph/GraphBackendHost.d.cts +100 -0
- package/lib/types/nest/graph/GraphBackendHost.d.mts +100 -0
- package/lib/types/nest/graph/GraphEngineCapabilityManifest.d.cts +87 -0
- package/lib/types/nest/graph/GraphEngineCapabilityManifest.d.mts +87 -0
- package/lib/types/nest/graph/GraphEngineCapabilityService.d.cts +98 -0
- package/lib/types/nest/graph/GraphEngineCapabilityService.d.mts +98 -0
- package/lib/types/nest/graph/GraphEngineController.d.cts +74 -0
- package/lib/types/nest/graph/GraphEngineController.d.mts +74 -0
- package/lib/types/nest/graph/GraphExecutionModule.d.cts +20 -0
- package/lib/types/nest/graph/GraphExecutionModule.d.mts +20 -0
- package/lib/types/nest/graph/index.d.cts +4 -0
- package/lib/types/nest/graph/index.d.mts +4 -0
- package/lib/types/nest/graph/main.d.cts +1 -0
- package/lib/types/nest/graph/main.d.mts +1 -0
- package/lib/types/nest/graph/servingErrors.d.cts +3 -1
- package/lib/types/nest/graph/servingErrors.d.mts +3 -1
- package/lib/types/node/utility/code/node.d.cts +1 -1
- package/lib/types/node/utility/code/node.d.mts +1 -1
- package/lib/types/shared/graph/GraphExecutionStateMapper.d.cts +5 -5
- package/lib/types/shared/graph/GraphExecutionStateMapper.d.mts +5 -5
- package/lib/types/shared/graph/constants.d.cts +8 -0
- package/lib/types/shared/graph/constants.d.mts +8 -0
- package/lib/types/shared/graph/index.d.cts +2 -1
- package/lib/types/shared/graph/index.d.mts +2 -1
- package/lib/types/shared/graph/layout/GraphWorkflowLayout.d.cts +49 -0
- package/lib/types/shared/graph/layout/GraphWorkflowLayout.d.mts +49 -0
- package/lib/types/shared/graph/layout/index.d.cts +5 -0
- package/lib/types/shared/graph/layout/index.d.mts +5 -0
- package/lib/types/shared/graph/layout/layout-options.d.cts +46 -0
- package/lib/types/shared/graph/layout/layout-options.d.mts +46 -0
- package/lib/types/shared/graph/types.d.cts +4 -3
- package/lib/types/shared/graph/types.d.mts +4 -3
- package/lib/types/shared/ui/index.d.cts +8 -10
- package/lib/types/shared/ui/index.d.mts +8 -10
- package/package.json +55 -6
- package/lib/cjs/shared/ui/GraphNodeView.cjs +0 -114
- package/lib/cjs/shared/ui/GraphNodeView.cjs.map +0 -1
- package/lib/cjs/shared/ui/GraphRunView.cjs +0 -96
- package/lib/cjs/shared/ui/GraphRunView.cjs.map +0 -1
- package/lib/cjs/shared/ui/GraphWorkflowView.cjs +0 -78
- package/lib/cjs/shared/ui/GraphWorkflowView.cjs.map +0 -1
- package/lib/cjs/shared/ui/types.cjs +0 -4
- package/lib/cjs/shared/ui/types.cjs.map +0 -1
- package/lib/esm/shared/ui/GraphNodeView.js +0 -107
- package/lib/esm/shared/ui/GraphNodeView.js.map +0 -1
- package/lib/esm/shared/ui/GraphRunView.js +0 -90
- package/lib/esm/shared/ui/GraphRunView.js.map +0 -1
- package/lib/esm/shared/ui/GraphWorkflowView.js +0 -72
- package/lib/esm/shared/ui/GraphWorkflowView.js.map +0 -1
- package/lib/esm/shared/ui/types.js +0 -2
- package/lib/esm/shared/ui/types.js.map +0 -1
- package/lib/types/shared/ui/GraphNodeView.d.cts +0 -48
- package/lib/types/shared/ui/GraphNodeView.d.mts +0 -48
- package/lib/types/shared/ui/GraphRunView.d.cts +0 -88
- package/lib/types/shared/ui/GraphRunView.d.mts +0 -88
- package/lib/types/shared/ui/GraphWorkflowView.d.cts +0 -18
- package/lib/types/shared/ui/GraphWorkflowView.d.mts +0 -18
- package/lib/types/shared/ui/types.d.cts +0 -200
- package/lib/types/shared/ui/types.d.mts +0 -200
|
@@ -0,0 +1,799 @@
|
|
|
1
|
+
import { GraphExecutionEventType, GraphExecutionStatus, GraphVisualState, graphValueTemplateDefaultLanguage, isGraphValueTemplate, } from "./../../shared/graph/index.js";
|
|
2
|
+
import { GRAPH_DEFAULT_CONCURRENCY, GRAPH_LOCAL_EXECUTION_BACKEND, GRAPH_MAX_FOREACH_ITERATIONS, GRAPH_MAX_LOOP_ITERATIONS, GRAPH_WORKFLOW_BOUNDARY, } from "./../constants.js";
|
|
3
|
+
import { GraphBreakSignal, GraphExecutionError, GraphRunCancelledError, } from "./../errors/index.js";
|
|
4
|
+
import { GraphParameterValidator, isGraphCredentialReferenceLike, } from "./../validation/GraphParameterValidator.js";
|
|
5
|
+
import { createGraphValueRepository } from "./../store/GraphValueRepository.js";
|
|
6
|
+
import { GraphPinningService } from "./../pinning/GraphPinningService.js";
|
|
7
|
+
import { GraphPinningPolicy } from "./../pinning/GraphPinningPolicy.js";
|
|
8
|
+
import { GraphPinningDependencyResolver } from "./../pinning/GraphPinningDependencyResolver.js";
|
|
9
|
+
import { GraphExecutionContext } from "./GraphExecutionContext.js";
|
|
10
|
+
import { buildGraphExecutionResult } from "./GraphExecutionResult.js";
|
|
11
|
+
import { GraphExecutionBackendRegistry } from "./GraphExecutionBackendRegistry.js";
|
|
12
|
+
/**
|
|
13
|
+
* Compiles a `{{ ... }}` text template into a JavaScript template literal so
|
|
14
|
+
* the pluggable code sandbox evaluator can resolve its placeholders against
|
|
15
|
+
* the same `$input`/`$vars`/`$item` bindings used by expression bindings.
|
|
16
|
+
*
|
|
17
|
+
* @param template - The persisted template body.
|
|
18
|
+
* @returns A backtick-quoted template literal expression.
|
|
19
|
+
*/
|
|
20
|
+
function graphTemplateToExpression(template) {
|
|
21
|
+
const escaped = template.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
|
|
22
|
+
const interpolated = escaped.replace(/\{\{\s*([\s\S]*?)\s*\}\}/g, (_match, expression) => `\${${expression}}`);
|
|
23
|
+
return `\`${interpolated}\``;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Built-in reference graph execution backend. Registers itself under
|
|
27
|
+
* {@link GRAPH_LOCAL_EXECUTION_BACKEND} on construction.
|
|
28
|
+
*/
|
|
29
|
+
export class LocalGraphExecutionBackend {
|
|
30
|
+
constructor() {
|
|
31
|
+
/** This backend executes locally, in-process. */
|
|
32
|
+
this.local = true;
|
|
33
|
+
/**
|
|
34
|
+
* This backend executes code-mode surfaces host-side through the
|
|
35
|
+
* facade-owned `CodeSandboxEvaluator` (SAA-193 C1).
|
|
36
|
+
*/
|
|
37
|
+
this.codeMode = "hostSide";
|
|
38
|
+
GraphExecutionBackendRegistry.register(GRAPH_LOCAL_EXECUTION_BACKEND, this);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the backend's runtime collaborators. Called by the facade during
|
|
42
|
+
* `GraphExecutionEngine.initialize`.
|
|
43
|
+
*
|
|
44
|
+
* @param config - The facade-provided collaborators.
|
|
45
|
+
*/
|
|
46
|
+
async initialize(config) {
|
|
47
|
+
this.valueAdapter = config.valueAdapter;
|
|
48
|
+
this.codeSandboxEvaluator = config.codeSandboxEvaluator;
|
|
49
|
+
this.workflowStore = config.workflowStore;
|
|
50
|
+
this.engine = config.engine;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Effective capability metadata: code-mode is host-side and workflow
|
|
54
|
+
* listing/lookup is supported exactly when a catalogue port is wired in.
|
|
55
|
+
*/
|
|
56
|
+
get capabilities() {
|
|
57
|
+
const status = this.workflowStore ? "supported" : "not_supported";
|
|
58
|
+
return {
|
|
59
|
+
codeMode: this.codeMode,
|
|
60
|
+
workflows: { list: status, get: status },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Lists the workflows visible to the requesting principal through the wired
|
|
65
|
+
* `GraphWorkflowStore` port.
|
|
66
|
+
*
|
|
67
|
+
* @param args - Optional decaf contextual arguments forwarded to the store.
|
|
68
|
+
* @returns Workflow summaries, newest first when the store orders them.
|
|
69
|
+
* @throws {GraphExecutionError} when no workflow store is wired in.
|
|
70
|
+
*/
|
|
71
|
+
async listWorkflows(...args) {
|
|
72
|
+
const store = this.workflowStore;
|
|
73
|
+
if (!store) {
|
|
74
|
+
throw new GraphExecutionError("LocalGraphExecutionBackend has no workflowStore configured; workflow listing is not supported", "GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED");
|
|
75
|
+
}
|
|
76
|
+
const records = await store.listWorkflows(...args);
|
|
77
|
+
return records.map((record) => ({
|
|
78
|
+
id: record.workflowId,
|
|
79
|
+
...(record.name !== undefined ? { name: record.name } : {}),
|
|
80
|
+
...(record.updatedAt !== undefined && record.updatedAt !== null
|
|
81
|
+
? { updatedAt: record.updatedAt }
|
|
82
|
+
: {}),
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Reads a single canonical workflow document through the wired
|
|
87
|
+
* `GraphWorkflowStore` port.
|
|
88
|
+
*
|
|
89
|
+
* @param workflowId - The workflow id to read.
|
|
90
|
+
* @param args - Optional decaf contextual arguments forwarded to the store.
|
|
91
|
+
* @returns The canonical workflow document.
|
|
92
|
+
* @throws {GraphExecutionError} when no workflow store is wired in.
|
|
93
|
+
*/
|
|
94
|
+
async getWorkflow(workflowId, ...args) {
|
|
95
|
+
const store = this.workflowStore;
|
|
96
|
+
if (!store) {
|
|
97
|
+
throw new GraphExecutionError("LocalGraphExecutionBackend has no workflowStore configured; workflow lookup is not supported", "GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED");
|
|
98
|
+
}
|
|
99
|
+
return await store.getDocument(workflowId, ...args);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Executes a validated/resolved workflow's plan against the facade-owned
|
|
103
|
+
* frame carried by the request's event sink.
|
|
104
|
+
*
|
|
105
|
+
* @param request - The execution request.
|
|
106
|
+
* @returns The complete execution result.
|
|
107
|
+
* @throws {GraphExecutionError} when the request's sink is not the
|
|
108
|
+
* facade-created frame-aware sink.
|
|
109
|
+
*/
|
|
110
|
+
async execute(request) {
|
|
111
|
+
const { document, plan, inputs, options: opts, events } = request;
|
|
112
|
+
const sink = events;
|
|
113
|
+
const frame = sink.frame;
|
|
114
|
+
if (!frame) {
|
|
115
|
+
throw new GraphExecutionError("LocalGraphExecutionBackend requires the frame-bound event sink created by GraphExecutionEngine", "GRAPH_EXECUTION_FRAME_MISSING");
|
|
116
|
+
}
|
|
117
|
+
const valueStore = frame.valueStore;
|
|
118
|
+
const runId = frame.runId;
|
|
119
|
+
const path = opts.path ?? [];
|
|
120
|
+
const emitFn = async (partial) => {
|
|
121
|
+
await sink.emit(partial);
|
|
122
|
+
};
|
|
123
|
+
try {
|
|
124
|
+
for (const layer of plan.layers) {
|
|
125
|
+
this.assertNotAborted(opts);
|
|
126
|
+
await this.executeLayer(frame, plan, layer.nodes, opts, emitFn);
|
|
127
|
+
}
|
|
128
|
+
this.assertNotAborted(opts);
|
|
129
|
+
const firstFailure = [...frame.nodeResults.values()].find((result) => result.status === GraphExecutionStatus.FAILED);
|
|
130
|
+
if (firstFailure?.error) {
|
|
131
|
+
throw new GraphExecutionError(firstFailure.error.message, firstFailure.error.code ?? "GRAPH_EXECUTION_ERROR", firstFailure.error.details);
|
|
132
|
+
}
|
|
133
|
+
frame.finish();
|
|
134
|
+
await sink.emit({
|
|
135
|
+
type: GraphExecutionEventType.WORKFLOW_COMPLETED,
|
|
136
|
+
runId,
|
|
137
|
+
parentRunId: opts.parentRunId,
|
|
138
|
+
workflowId: plan.workflowId,
|
|
139
|
+
path,
|
|
140
|
+
status: GraphExecutionStatus.SUCCEEDED,
|
|
141
|
+
payload: { outputs: valueStore.getWorkflowValues() },
|
|
142
|
+
});
|
|
143
|
+
return buildGraphExecutionResult(frame, document, inputs, GraphExecutionStatus.SUCCEEDED, opts.metadata);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
// A cooperative `GraphBreakSignal` is loop-control flow, not a workflow
|
|
147
|
+
// failure: propagate it unchanged so the enclosing loop executor can stop
|
|
148
|
+
// iterating instead of seeing a failed child run.
|
|
149
|
+
if (error instanceof GraphBreakSignal) {
|
|
150
|
+
frame.finish();
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
frame.finish();
|
|
154
|
+
const errorPayload = this.toErrorPayload(error);
|
|
155
|
+
if (error instanceof GraphRunCancelledError ||
|
|
156
|
+
opts.abortSignal?.aborted === true) {
|
|
157
|
+
await sink.emit({
|
|
158
|
+
type: GraphExecutionEventType.WORKFLOW_CANCELLED,
|
|
159
|
+
runId,
|
|
160
|
+
parentRunId: opts.parentRunId,
|
|
161
|
+
workflowId: plan.workflowId,
|
|
162
|
+
path,
|
|
163
|
+
status: GraphExecutionStatus.CANCELLED,
|
|
164
|
+
error: errorPayload,
|
|
165
|
+
});
|
|
166
|
+
return buildGraphExecutionResult(frame, document, inputs, GraphExecutionStatus.CANCELLED, opts.metadata);
|
|
167
|
+
}
|
|
168
|
+
await sink.emit({
|
|
169
|
+
type: GraphExecutionEventType.WORKFLOW_FAILED,
|
|
170
|
+
runId,
|
|
171
|
+
parentRunId: opts.parentRunId,
|
|
172
|
+
workflowId: plan.workflowId,
|
|
173
|
+
path,
|
|
174
|
+
status: GraphExecutionStatus.FAILED,
|
|
175
|
+
error: errorPayload,
|
|
176
|
+
});
|
|
177
|
+
return buildGraphExecutionResult(frame, document, inputs, GraphExecutionStatus.FAILED, opts.metadata);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Executes a layer of nodes with the configured concurrency.
|
|
182
|
+
*/
|
|
183
|
+
async executeLayer(frame, plan, nodes, opts, emitFn) {
|
|
184
|
+
const concurrency = Math.max(1, opts.concurrency ?? GRAPH_DEFAULT_CONCURRENCY);
|
|
185
|
+
const queue = [...nodes];
|
|
186
|
+
while (queue.length > 0) {
|
|
187
|
+
const batch = queue.splice(0, concurrency);
|
|
188
|
+
await Promise.all(batch.map((node) => this.executeNode(frame, plan, node, opts, emitFn)));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Executes a single node, honouring disabled-node semantics (§4.9).
|
|
193
|
+
*/
|
|
194
|
+
async executeNode(frame, plan, planNode, opts, emitFn) {
|
|
195
|
+
this.assertNotAborted(opts);
|
|
196
|
+
if (!this.isNodeActivated(frame, plan, planNode)) {
|
|
197
|
+
await this.skipInactiveNode(frame, plan, planNode, opts, emitFn);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (planNode.instance.disabled === true) {
|
|
201
|
+
await this.executeDisabledNode(frame, plan, planNode, opts, emitFn);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const startedAt = new Date();
|
|
205
|
+
const nodePath = [...(opts.path ?? []), planNode.id];
|
|
206
|
+
await emitFn({
|
|
207
|
+
type: GraphExecutionEventType.NODE_STARTED,
|
|
208
|
+
runId: frame.runId,
|
|
209
|
+
workflowId: plan.workflowId,
|
|
210
|
+
nodeId: planNode.id,
|
|
211
|
+
path: nodePath,
|
|
212
|
+
status: GraphExecutionStatus.RUNNING,
|
|
213
|
+
});
|
|
214
|
+
this.emitNodeStateChanged(frame, plan, planNode, nodePath, GraphVisualState.RUNNING, GraphExecutionStatus.RUNNING, emitFn);
|
|
215
|
+
const inputs = await this.resolveNodeInputs(frame, plan, planNode, opts);
|
|
216
|
+
// Cache-hit: check for a pinned value before executing the node
|
|
217
|
+
if (opts.usePinnedValues) {
|
|
218
|
+
const cached = await this.tryPinnedValue(frame, plan, planNode, inputs);
|
|
219
|
+
if (cached) {
|
|
220
|
+
frame.valueStore.setNodeOutputs(planNode.id, cached.outputs);
|
|
221
|
+
this.routeOutgoingEdges(frame, plan, planNode, cached.outputs, emitFn);
|
|
222
|
+
const finishedAt = new Date();
|
|
223
|
+
const result = {
|
|
224
|
+
nodeId: planNode.id,
|
|
225
|
+
status: GraphExecutionStatus.CACHED,
|
|
226
|
+
inputs,
|
|
227
|
+
outputs: cached.outputs,
|
|
228
|
+
startedAt,
|
|
229
|
+
finishedAt,
|
|
230
|
+
fromCache: true,
|
|
231
|
+
pinned: true,
|
|
232
|
+
events: [],
|
|
233
|
+
};
|
|
234
|
+
frame.recordNodeResult(result);
|
|
235
|
+
await emitFn({
|
|
236
|
+
type: GraphExecutionEventType.NODE_CACHE_HIT,
|
|
237
|
+
runId: frame.runId,
|
|
238
|
+
workflowId: plan.workflowId,
|
|
239
|
+
nodeId: planNode.id,
|
|
240
|
+
path: nodePath,
|
|
241
|
+
status: GraphExecutionStatus.CACHED,
|
|
242
|
+
payload: { outputs: cached.outputs },
|
|
243
|
+
});
|
|
244
|
+
await emitFn({
|
|
245
|
+
type: GraphExecutionEventType.NODE_COMPLETED,
|
|
246
|
+
runId: frame.runId,
|
|
247
|
+
workflowId: plan.workflowId,
|
|
248
|
+
nodeId: planNode.id,
|
|
249
|
+
path: nodePath,
|
|
250
|
+
status: GraphExecutionStatus.SUCCEEDED,
|
|
251
|
+
payload: { outputs: cached.outputs, fromCache: true },
|
|
252
|
+
});
|
|
253
|
+
this.emitNodeStateChanged(frame, plan, planNode, nodePath, GraphVisualState.SUCCEEDED, GraphExecutionStatus.SUCCEEDED, emitFn);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const context = new GraphExecutionContext(frame.runId, opts.parentRunId, plan.workflowId, plan.resolved.document, planNode.instance, planNode.manifest, nodePath, emitFn, opts.metadata, this.engine, opts.abortSignal, this.executionLimits(opts));
|
|
259
|
+
const parameters = await this.resolveNodeParameters(planNode, inputs, opts);
|
|
260
|
+
const request = {
|
|
261
|
+
nodeId: planNode.id,
|
|
262
|
+
kind: planNode.kind,
|
|
263
|
+
inputs,
|
|
264
|
+
parameters,
|
|
265
|
+
credentials: this.collectCredentials(planNode),
|
|
266
|
+
metadata: planNode.instance.metadata,
|
|
267
|
+
};
|
|
268
|
+
const rawOutputs = await this.invokeExecutor(planNode, request, context);
|
|
269
|
+
const outputs = this.validateNodeOutputs(planNode, rawOutputs ?? {});
|
|
270
|
+
frame.valueStore.setNodeOutputs(planNode.id, outputs);
|
|
271
|
+
this.routeOutgoingEdges(frame, plan, planNode, outputs, emitFn);
|
|
272
|
+
const finishedAt = new Date();
|
|
273
|
+
const result = {
|
|
274
|
+
nodeId: planNode.id,
|
|
275
|
+
status: GraphExecutionStatus.SUCCEEDED,
|
|
276
|
+
inputs,
|
|
277
|
+
outputs,
|
|
278
|
+
startedAt,
|
|
279
|
+
finishedAt,
|
|
280
|
+
events: [],
|
|
281
|
+
};
|
|
282
|
+
frame.recordNodeResult(result);
|
|
283
|
+
await emitFn({
|
|
284
|
+
type: GraphExecutionEventType.NODE_COMPLETED,
|
|
285
|
+
runId: frame.runId,
|
|
286
|
+
workflowId: plan.workflowId,
|
|
287
|
+
nodeId: planNode.id,
|
|
288
|
+
path: nodePath,
|
|
289
|
+
status: GraphExecutionStatus.SUCCEEDED,
|
|
290
|
+
payload: { outputs },
|
|
291
|
+
});
|
|
292
|
+
this.emitNodeStateChanged(frame, plan, planNode, nodePath, GraphVisualState.SUCCEEDED, GraphExecutionStatus.SUCCEEDED, emitFn);
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
// Loop-control flow is not a node failure: rethrow the break token so
|
|
296
|
+
// the enclosing loop executor observes it rather than a FAILED node.
|
|
297
|
+
if (error instanceof GraphBreakSignal)
|
|
298
|
+
throw error;
|
|
299
|
+
const finishedAt = new Date();
|
|
300
|
+
const errorPayload = this.toErrorPayload(error);
|
|
301
|
+
const result = {
|
|
302
|
+
nodeId: planNode.id,
|
|
303
|
+
status: GraphExecutionStatus.FAILED,
|
|
304
|
+
inputs,
|
|
305
|
+
error: errorPayload,
|
|
306
|
+
startedAt,
|
|
307
|
+
finishedAt,
|
|
308
|
+
events: [],
|
|
309
|
+
};
|
|
310
|
+
frame.recordNodeResult(result);
|
|
311
|
+
await emitFn({
|
|
312
|
+
type: GraphExecutionEventType.NODE_FAILED,
|
|
313
|
+
runId: frame.runId,
|
|
314
|
+
workflowId: plan.workflowId,
|
|
315
|
+
nodeId: planNode.id,
|
|
316
|
+
path: nodePath,
|
|
317
|
+
status: GraphExecutionStatus.FAILED,
|
|
318
|
+
error: errorPayload,
|
|
319
|
+
});
|
|
320
|
+
this.emitNodeStateChanged(frame, plan, planNode, nodePath, GraphVisualState.FAILED, GraphExecutionStatus.FAILED, emitFn);
|
|
321
|
+
if (opts.failFast ?? true)
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Resolves whether a plan node is activated for execution under the
|
|
327
|
+
* DECAF-50 §4.9 branch semantics. A node with no incoming data edges is
|
|
328
|
+
* a root/source node and always runs. A node fed by one or more data
|
|
329
|
+
* edges runs only when at least one of those edges was activated by a
|
|
330
|
+
* routed upstream output port — a branch the upstream switch (or any
|
|
331
|
+
* partial-output node) did not select leaves its downstream edges
|
|
332
|
+
* unactivated, so the branch is never executed. Workflow-boundary edges
|
|
333
|
+
* are active from the start because workflow inputs are seeded before
|
|
334
|
+
* execution begins.
|
|
335
|
+
*/
|
|
336
|
+
isNodeActivated(frame, plan, planNode) {
|
|
337
|
+
const incoming = (plan.incomingByNode.get(planNode.id) ?? []).filter((edge) => edge.type === "data");
|
|
338
|
+
if (incoming.length === 0)
|
|
339
|
+
return true;
|
|
340
|
+
return incoming.some((edge) => edge.sourceNodeId === GRAPH_WORKFLOW_BOUNDARY ||
|
|
341
|
+
frame.isDataEdgeActive(edge.id));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Skips a node whose incoming data edges were all left unactivated by an
|
|
345
|
+
* upstream branch selection. The node is not executed and its outputs are
|
|
346
|
+
* never routed or collected into workflow outputs (DECAF-50 §4.9).
|
|
347
|
+
*/
|
|
348
|
+
async skipInactiveNode(frame, plan, planNode, opts, emitFn) {
|
|
349
|
+
const startedAt = new Date();
|
|
350
|
+
const nodePath = [...(opts.path ?? []), planNode.id];
|
|
351
|
+
await emitFn({
|
|
352
|
+
type: GraphExecutionEventType.NODE_SKIPPED,
|
|
353
|
+
runId: frame.runId,
|
|
354
|
+
workflowId: plan.workflowId,
|
|
355
|
+
nodeId: planNode.id,
|
|
356
|
+
path: nodePath,
|
|
357
|
+
status: GraphExecutionStatus.SKIPPED,
|
|
358
|
+
payload: { reason: "branchNotSelected" },
|
|
359
|
+
});
|
|
360
|
+
const result = {
|
|
361
|
+
nodeId: planNode.id,
|
|
362
|
+
status: GraphExecutionStatus.SKIPPED,
|
|
363
|
+
inputs: {},
|
|
364
|
+
startedAt,
|
|
365
|
+
finishedAt: new Date(),
|
|
366
|
+
events: [],
|
|
367
|
+
};
|
|
368
|
+
frame.recordNodeResult(result);
|
|
369
|
+
this.emitNodeStateChanged(frame, plan, planNode, nodePath, GraphVisualState.SKIPPED, GraphExecutionStatus.SKIPPED, emitFn);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Applies the explicit disabled-node semantics (§4.9):
|
|
373
|
+
* `skip`, `passThroughFirstInput`, or `emitDefaults`, resolved from the
|
|
374
|
+
* instance metadata, document settings, and the default.
|
|
375
|
+
*/
|
|
376
|
+
async executeDisabledNode(frame, plan, planNode, opts, emitFn) {
|
|
377
|
+
const startedAt = new Date();
|
|
378
|
+
const nodePath = [...(opts.path ?? []), planNode.id];
|
|
379
|
+
const behavior = GraphParameterValidator.disabledBehaviorOf(planNode.instance, plan.resolved.document.settings);
|
|
380
|
+
await emitFn({
|
|
381
|
+
type: GraphExecutionEventType.NODE_SKIPPED,
|
|
382
|
+
runId: frame.runId,
|
|
383
|
+
workflowId: plan.workflowId,
|
|
384
|
+
nodeId: planNode.id,
|
|
385
|
+
path: nodePath,
|
|
386
|
+
status: GraphExecutionStatus.SKIPPED,
|
|
387
|
+
payload: { disabled: true, behavior },
|
|
388
|
+
});
|
|
389
|
+
if (behavior === "skip") {
|
|
390
|
+
const result = {
|
|
391
|
+
nodeId: planNode.id,
|
|
392
|
+
status: GraphExecutionStatus.SKIPPED,
|
|
393
|
+
inputs: {},
|
|
394
|
+
startedAt,
|
|
395
|
+
finishedAt: new Date(),
|
|
396
|
+
events: [],
|
|
397
|
+
};
|
|
398
|
+
frame.recordNodeResult(result);
|
|
399
|
+
this.emitNodeStateChanged(frame, plan, planNode, nodePath, GraphVisualState.SKIPPED, GraphExecutionStatus.SKIPPED, emitFn);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const inputs = await this.resolveNodeInputs(frame, plan, planNode, opts);
|
|
403
|
+
let outputs;
|
|
404
|
+
if (behavior === "passThroughFirstInput") {
|
|
405
|
+
const firstIncoming = (plan.incomingByNode.get(planNode.id) ?? []).find((edge) => edge.type === "data");
|
|
406
|
+
const firstOutput = planNode.manifest.outputs[0]?.id ?? "value";
|
|
407
|
+
const value = firstIncoming
|
|
408
|
+
? frame.valueStore.getPort(firstIncoming.sourceNodeId, firstIncoming.sourcePort)
|
|
409
|
+
: Object.values(inputs)[0];
|
|
410
|
+
outputs = { [firstOutput]: value };
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
// emitDefaults — every declared output port is emitted with its
|
|
414
|
+
// declared default (absent a declared default, undefined).
|
|
415
|
+
outputs = {};
|
|
416
|
+
for (const port of planNode.manifest.outputs) {
|
|
417
|
+
outputs[port.id] = port.metadata?.["defaultValue"];
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
frame.valueStore.setNodeOutputs(planNode.id, outputs);
|
|
421
|
+
this.routeOutgoingEdges(frame, plan, planNode, outputs, emitFn);
|
|
422
|
+
const result = {
|
|
423
|
+
nodeId: planNode.id,
|
|
424
|
+
status: GraphExecutionStatus.SUCCEEDED,
|
|
425
|
+
inputs,
|
|
426
|
+
outputs,
|
|
427
|
+
startedAt,
|
|
428
|
+
finishedAt: new Date(),
|
|
429
|
+
events: [],
|
|
430
|
+
};
|
|
431
|
+
frame.recordNodeResult(result);
|
|
432
|
+
this.emitNodeStateChanged(frame, plan, planNode, nodePath, GraphVisualState.SUCCEEDED, GraphExecutionStatus.SUCCEEDED, emitFn);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Invokes the node's catalogue-resolved executor (§4.9 request contract,
|
|
436
|
+
* post-cutover: every executor receives the full request with
|
|
437
|
+
* configuration and input data separated).
|
|
438
|
+
*/
|
|
439
|
+
async invokeExecutor(planNode, request, context) {
|
|
440
|
+
return await planNode.executor.execute(request, context);
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Validates executor outputs against the effective output manifest
|
|
444
|
+
* (§4.9): unknown outputs are rejected by default; missing required
|
|
445
|
+
* outputs fail the node. Lenient transition manifests (legacy
|
|
446
|
+
* executor-only registrations) are exempt until cutover.
|
|
447
|
+
*/
|
|
448
|
+
validateNodeOutputs(planNode, outputs) {
|
|
449
|
+
const manifest = planNode.manifest;
|
|
450
|
+
if (manifest.policies?.allowUnknownOutputs === true) {
|
|
451
|
+
return outputs;
|
|
452
|
+
}
|
|
453
|
+
const declaredOutputs = new Set(manifest.outputs.map((port) => port.id));
|
|
454
|
+
const unknownOutputs = Object.keys(outputs).filter((key) => !declaredOutputs.has(key));
|
|
455
|
+
if (unknownOutputs.length > 0) {
|
|
456
|
+
throw new GraphExecutionError(`Node '${planNode.id}' of kind '${planNode.kind}' produced unknown output(s): ${unknownOutputs.join(", ")}`, "GRAPH_OUTPUT_VALIDATION_FAILED", { nodeId: planNode.id, unknownOutputs });
|
|
457
|
+
}
|
|
458
|
+
const missingRequired = manifest.outputs
|
|
459
|
+
.filter((port) => port.required === true && !(port.id in outputs))
|
|
460
|
+
.map((port) => port.id);
|
|
461
|
+
if (missingRequired.length > 0) {
|
|
462
|
+
throw new GraphExecutionError(`Node '${planNode.id}' of kind '${planNode.kind}' did not produce required output(s): ${missingRequired.join(", ")}`, "GRAPH_OUTPUT_VALIDATION_FAILED", { nodeId: planNode.id, missingRequired });
|
|
463
|
+
}
|
|
464
|
+
return outputs;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Collects the resolved credential references for a node: credential-type
|
|
468
|
+
* parameter values plus the `credentials` record in instance metadata.
|
|
469
|
+
* Documents carry references only — secret material never enters requests.
|
|
470
|
+
*/
|
|
471
|
+
collectCredentials(planNode) {
|
|
472
|
+
const credentials = {};
|
|
473
|
+
for (const parameter of planNode.manifest.parameters) {
|
|
474
|
+
if (parameter.type !== "credential")
|
|
475
|
+
continue;
|
|
476
|
+
const value = (planNode.instance.parameters ?? {})[parameter.id];
|
|
477
|
+
if (typeof value === "string" && value.length > 0) {
|
|
478
|
+
credentials[parameter.id] = {
|
|
479
|
+
credentialId: value,
|
|
480
|
+
credentialType: parameter.credentialType ?? "",
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
else if (isGraphCredentialReferenceLike(value)) {
|
|
484
|
+
credentials[parameter.id] = {
|
|
485
|
+
credentialId: value.credentialId,
|
|
486
|
+
credentialType: value.credentialType,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const extra = (planNode.instance.metadata ?? {})["credentials"];
|
|
491
|
+
if (extra && typeof extra === "object" && !Array.isArray(extra)) {
|
|
492
|
+
for (const [key, raw] of Object.entries(extra)) {
|
|
493
|
+
const value = raw;
|
|
494
|
+
if (typeof value === "string" && value.length > 0) {
|
|
495
|
+
credentials[key] = { credentialId: value, credentialType: "" };
|
|
496
|
+
}
|
|
497
|
+
else if (isGraphCredentialReferenceLike(value)) {
|
|
498
|
+
credentials[key] = {
|
|
499
|
+
credentialId: value.credentialId,
|
|
500
|
+
credentialType: value.credentialType,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return credentials;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Resolves a node's input values from routed data edges, literal bindings,
|
|
509
|
+
* allowed expression bindings, and manifest port defaults (§4.9).
|
|
510
|
+
*
|
|
511
|
+
* When multiple edges target the same port, their values are spread into the
|
|
512
|
+
* top-level inputs keyed by each edge's `sourcePort`. This allows multiple
|
|
513
|
+
* workflow input badges to connect to a single port (e.g. the Code node's
|
|
514
|
+
* `data` port) and have all values accessible directly as
|
|
515
|
+
* `$input.{sourcePort}` (e.g. `$input.count`, `$input.text`).
|
|
516
|
+
*/
|
|
517
|
+
async resolveNodeInputs(frame, plan, planNode, opts) {
|
|
518
|
+
const inputs = {};
|
|
519
|
+
const incoming = (plan.incomingByNode.get(planNode.id) ?? []).filter((edge) => edge.type === "data");
|
|
520
|
+
const edgesByTarget = new Map();
|
|
521
|
+
for (const edge of incoming) {
|
|
522
|
+
const list = edgesByTarget.get(edge.targetPort) ?? [];
|
|
523
|
+
list.push(edge);
|
|
524
|
+
edgesByTarget.set(edge.targetPort, list);
|
|
525
|
+
}
|
|
526
|
+
for (const [targetPort, edges] of edgesByTarget) {
|
|
527
|
+
if (edges.length === 1) {
|
|
528
|
+
inputs[targetPort] = frame.valueStore.getPort(edges[0].sourceNodeId, edges[0].sourcePort);
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
let definedValue;
|
|
532
|
+
let hasDefined = false;
|
|
533
|
+
for (const edge of edges) {
|
|
534
|
+
const value = frame.valueStore.getPort(edge.sourceNodeId, edge.sourcePort);
|
|
535
|
+
inputs[edge.sourcePort] = value;
|
|
536
|
+
if (value !== undefined) {
|
|
537
|
+
definedValue = value;
|
|
538
|
+
hasDefined = true;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
// Branch merges route several mutually-exclusive outputs onto the same
|
|
542
|
+
// target port (e.g. an if/switch branch). The port-keyed map above
|
|
543
|
+
// preserves distinct source ports, but the target port must also receive
|
|
544
|
+
// the single defined branch value so the node reads its own port.
|
|
545
|
+
if (hasDefined && inputs[targetPort] === undefined) {
|
|
546
|
+
inputs[targetPort] = definedValue;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// Literal bindings, expression bindings, and manifest defaults.
|
|
551
|
+
const bindings = planNode.instance.inputBindings ?? {};
|
|
552
|
+
for (const port of planNode.manifest.inputs) {
|
|
553
|
+
const binding = bindings[port.id];
|
|
554
|
+
if (binding?.mode === "literal") {
|
|
555
|
+
inputs[port.id] = binding.value;
|
|
556
|
+
}
|
|
557
|
+
else if (binding?.mode === "expression") {
|
|
558
|
+
inputs[port.id] = await this.evaluateExpressionBinding(planNode, binding.expression, inputs, opts);
|
|
559
|
+
}
|
|
560
|
+
else if (inputs[port.id] === undefined) {
|
|
561
|
+
const defaultValue = port.metadata?.["defaultValue"];
|
|
562
|
+
if (defaultValue !== undefined) {
|
|
563
|
+
inputs[port.id] = defaultValue;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return inputs;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Resolves a node's persisted parameters at execution time, evaluating any
|
|
571
|
+
* `GraphValueTemplate` user property through the code-evaluator VM and
|
|
572
|
+
* leaving straight literal values unchanged.
|
|
573
|
+
*/
|
|
574
|
+
async resolveNodeParameters(planNode, inputs, opts) {
|
|
575
|
+
const parameters = planNode.instance.parameters ?? {};
|
|
576
|
+
const resolved = {};
|
|
577
|
+
for (const [key, value] of Object.entries(parameters)) {
|
|
578
|
+
resolved[key] = isGraphValueTemplate(value)
|
|
579
|
+
? await this.evaluateValueTemplate(value, planNode, inputs, opts)
|
|
580
|
+
: value;
|
|
581
|
+
}
|
|
582
|
+
return resolved;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Evaluates a persisted `GraphValueTemplate` with the pluggable
|
|
586
|
+
* {@link CodeSandboxEvaluator} (DECAF-32 §22.4) — no new evaluator.
|
|
587
|
+
* `expression` mode evaluates the body directly; `template` mode compiles its
|
|
588
|
+
* `{{ ... }}` placeholders into a JavaScript template literal evaluated in
|
|
589
|
+
* the same sandbox, so both modes share the code-evaluator VM.
|
|
590
|
+
*/
|
|
591
|
+
async evaluateValueTemplate(template, planNode, inputs, opts) {
|
|
592
|
+
const evaluator = this.codeSandboxEvaluator;
|
|
593
|
+
if (!evaluator) {
|
|
594
|
+
throw new GraphExecutionError(`Value template on node '${planNode.id}' requires a CodeSandboxEvaluator to be registered in GraphExecutionEngineConfig.codeSandboxEvaluator`, "GRAPH_CODE_SANDBOX_NOT_CONFIGURED", { nodeId: planNode.id });
|
|
595
|
+
}
|
|
596
|
+
const language = template.language ?? graphValueTemplateDefaultLanguage(template.mode);
|
|
597
|
+
const code = template.mode === "template"
|
|
598
|
+
? graphTemplateToExpression(template.expression)
|
|
599
|
+
: template.expression;
|
|
600
|
+
const md = opts.metadata;
|
|
601
|
+
const result = await evaluator.evaluate({
|
|
602
|
+
code,
|
|
603
|
+
language: language === "typescript" ? "typescript" : "javascript",
|
|
604
|
+
input: inputs,
|
|
605
|
+
vars: md?.vars ?? undefined,
|
|
606
|
+
item: md?.item,
|
|
607
|
+
index: md?.index,
|
|
608
|
+
abortSignal: opts.abortSignal,
|
|
609
|
+
});
|
|
610
|
+
return result;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Evaluates an expression binding with the EXISTING allowed-expression
|
|
614
|
+
* machinery only (the pluggable {@link CodeSandboxEvaluator}, DECAF-32
|
|
615
|
+
* §22.4) — no new evaluator. The expression sees the already-routed input
|
|
616
|
+
* values as `$input` and the run metadata as context.
|
|
617
|
+
*/
|
|
618
|
+
async evaluateExpressionBinding(planNode, expression, inputs, opts) {
|
|
619
|
+
const evaluator = this.codeSandboxEvaluator;
|
|
620
|
+
if (!evaluator) {
|
|
621
|
+
throw new GraphExecutionError(`Expression binding on node '${planNode.id}' requires a CodeSandboxEvaluator to be registered in GraphExecutionEngineConfig.codeSandboxEvaluator`, "GRAPH_CODE_SANDBOX_NOT_CONFIGURED", { nodeId: planNode.id, expression });
|
|
622
|
+
}
|
|
623
|
+
const md = opts.metadata;
|
|
624
|
+
return await evaluator.evaluate({
|
|
625
|
+
code: expression,
|
|
626
|
+
language: "javascript",
|
|
627
|
+
input: inputs,
|
|
628
|
+
vars: md?.vars ?? undefined,
|
|
629
|
+
item: md?.item,
|
|
630
|
+
index: md?.index,
|
|
631
|
+
abortSignal: opts.abortSignal,
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Attempts to read a pinned value for the node. Returns the cached outputs
|
|
636
|
+
* when a valid pinned value exists, or `undefined` to proceed with normal
|
|
637
|
+
* execution.
|
|
638
|
+
*/
|
|
639
|
+
async tryPinnedValue(frame, plan, planNode, inputs) {
|
|
640
|
+
const policy = new GraphPinningPolicy();
|
|
641
|
+
if (!policy.shouldUsePinnedValue(planNode))
|
|
642
|
+
return undefined;
|
|
643
|
+
const service = this.createPinningService(frame);
|
|
644
|
+
const depFingerprints = this.computeDependencyFingerprints(frame, plan, planNode.id);
|
|
645
|
+
return service.readPinnedValue(plan.workflowId, planNode, inputs, depFingerprints);
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Recursively computes fingerprints for all upstream dependencies of a node
|
|
649
|
+
* using the results already accumulated in the frame.
|
|
650
|
+
*/
|
|
651
|
+
computeDependencyFingerprints(frame, plan, nodeId) {
|
|
652
|
+
const service = this.createPinningService(frame);
|
|
653
|
+
const depResolver = new GraphPinningDependencyResolver();
|
|
654
|
+
const deps = depResolver.getDependencies(plan, nodeId);
|
|
655
|
+
const fingerprints = {};
|
|
656
|
+
for (const dep of deps) {
|
|
657
|
+
const node = plan.nodes.find((n) => n.id === dep);
|
|
658
|
+
if (node) {
|
|
659
|
+
const depResult = frame.nodeResults.get(dep);
|
|
660
|
+
const inputs = depResult?.inputs ?? {};
|
|
661
|
+
const nestedDeps = this.computeDependencyFingerprints(frame, plan, dep);
|
|
662
|
+
fingerprints[dep] = service.computeFingerprint(plan.workflowId, node, inputs, nestedDeps);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return fingerprints;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Routes a node's outputs to downstream inputs and workflow outputs along
|
|
669
|
+
* data edges (connection edges are structural and never route values).
|
|
670
|
+
*
|
|
671
|
+
* An edge is traversed only when the source node actually emitted the
|
|
672
|
+
* edge's `sourcePort` (DECAF-50 §4.9 branch semantics). A node that
|
|
673
|
+
* emitted a subset of its declared outputs — e.g. a switch that selected
|
|
674
|
+
* one case — therefore activates only the downstream branch edges of the
|
|
675
|
+
* emitted ports; unselected branch edges are left unactivated, so their
|
|
676
|
+
* downstream nodes are skipped and never contribute to workflow outputs.
|
|
677
|
+
* Emitting an output port explicitly with `undefined` still counts as
|
|
678
|
+
* activated (the port was produced by the executor).
|
|
679
|
+
*/
|
|
680
|
+
routeOutgoingEdges(frame, plan, planNode, outputs, emitFn) {
|
|
681
|
+
const outgoing = (plan.outgoingByNode.get(planNode.id) ?? []).filter((edge) => edge.type === "data");
|
|
682
|
+
for (const edge of outgoing) {
|
|
683
|
+
if (!Object.prototype.hasOwnProperty.call(outputs, edge.sourcePort)) {
|
|
684
|
+
// The source node did not emit this output port: the edge's branch
|
|
685
|
+
// was not selected, so no value is routed.
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
const value = outputs[edge.sourcePort];
|
|
689
|
+
frame.activateDataEdge(edge.id);
|
|
690
|
+
if (edge.targetNodeId === GRAPH_WORKFLOW_BOUNDARY) {
|
|
691
|
+
frame.valueStore.setWorkflowOutput(edge.targetPort, value);
|
|
692
|
+
}
|
|
693
|
+
this.emitEdgeStateChanged(frame, plan, planNode, edge, GraphVisualState.SUCCEEDED, GraphExecutionStatus.SUCCEEDED, emitFn);
|
|
694
|
+
emitFn({
|
|
695
|
+
type: GraphExecutionEventType.EDGE_VALUE_ROUTED,
|
|
696
|
+
runId: frame.runId,
|
|
697
|
+
workflowId: plan.workflowId,
|
|
698
|
+
edgeId: edge.id,
|
|
699
|
+
nodeId: planNode.id,
|
|
700
|
+
path: [],
|
|
701
|
+
payload: { edge, value },
|
|
702
|
+
}).catch(() => {
|
|
703
|
+
// observer failures must not crash
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Emits a `NODE_STATE_CHANGED` event (DECAF-48 §4.4) carrying the given
|
|
709
|
+
* visual state for the node. Rides the existing Observable pipeline; no
|
|
710
|
+
* second out-of-band channel.
|
|
711
|
+
*/
|
|
712
|
+
emitNodeStateChanged(frame, plan, planNode, nodePath, state, status, emitFn) {
|
|
713
|
+
emitFn({
|
|
714
|
+
type: GraphExecutionEventType.NODE_STATE_CHANGED,
|
|
715
|
+
runId: frame.runId,
|
|
716
|
+
workflowId: plan.workflowId,
|
|
717
|
+
nodeId: planNode.id,
|
|
718
|
+
path: nodePath,
|
|
719
|
+
status,
|
|
720
|
+
payload: {
|
|
721
|
+
nodeId: planNode.id,
|
|
722
|
+
state,
|
|
723
|
+
runId: frame.runId,
|
|
724
|
+
workflowId: plan.workflowId,
|
|
725
|
+
status,
|
|
726
|
+
},
|
|
727
|
+
}).catch(() => {
|
|
728
|
+
// observer failures must not crash execution
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Emits an `EDGE_STATE_CHANGED` event (DECAF-48 §4.4) carrying the given
|
|
733
|
+
* visual state for a routed edge.
|
|
734
|
+
*/
|
|
735
|
+
emitEdgeStateChanged(frame, plan, planNode, edge, state, status, emitFn) {
|
|
736
|
+
emitFn({
|
|
737
|
+
type: GraphExecutionEventType.EDGE_STATE_CHANGED,
|
|
738
|
+
runId: frame.runId,
|
|
739
|
+
workflowId: plan.workflowId,
|
|
740
|
+
edgeId: edge.id,
|
|
741
|
+
nodeId: planNode.id,
|
|
742
|
+
path: [],
|
|
743
|
+
status,
|
|
744
|
+
payload: {
|
|
745
|
+
edgeId: edge.id,
|
|
746
|
+
state,
|
|
747
|
+
runId: frame.runId,
|
|
748
|
+
workflowId: plan.workflowId,
|
|
749
|
+
nodeId: planNode.id,
|
|
750
|
+
status,
|
|
751
|
+
},
|
|
752
|
+
}).catch(() => {
|
|
753
|
+
// observer failures must not crash execution
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Creates a {@link GraphPinningService} backed by the run's value store
|
|
758
|
+
* adapter.
|
|
759
|
+
*/
|
|
760
|
+
createPinningService(frame) {
|
|
761
|
+
const adapter = frame.valueStore.getAdapter() ?? this.valueAdapter;
|
|
762
|
+
const store = createGraphValueRepository(adapter);
|
|
763
|
+
return new GraphPinningService(store, new GraphPinningPolicy(), new GraphPinningDependencyResolver());
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Resolves the effective loop-iteration ceilings for a run. A node-level
|
|
767
|
+
* `maxIterations` can never exceed these; loop executors read them from the
|
|
768
|
+
* node context.
|
|
769
|
+
*/
|
|
770
|
+
executionLimits(opts) {
|
|
771
|
+
return {
|
|
772
|
+
maxLoopIterations: opts.maxLoopIterations ?? GRAPH_MAX_LOOP_ITERATIONS,
|
|
773
|
+
maxForeachIterations: opts.maxForeachIterations ?? GRAPH_MAX_FOREACH_ITERATIONS,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
assertNotAborted(opts) {
|
|
777
|
+
if (opts.abortSignal?.aborted === true) {
|
|
778
|
+
throw new GraphRunCancelledError(opts.runId ?? "unknown");
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Converts an error into a serialized payload.
|
|
783
|
+
*/
|
|
784
|
+
toErrorPayload(error) {
|
|
785
|
+
if (error instanceof Error) {
|
|
786
|
+
return {
|
|
787
|
+
name: error.name,
|
|
788
|
+
message: error.message,
|
|
789
|
+
stack: error.stack,
|
|
790
|
+
code: error.graphCode ??
|
|
791
|
+
(typeof error.code === "number"
|
|
792
|
+
? String(error.code)
|
|
793
|
+
: error.code),
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
return { name: "UnknownError", message: String(error) };
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
//# sourceMappingURL=LocalGraphExecutionBackend.js.map
|