@decaf-ts/as-graph 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/README.md +158 -2
  2. package/dist/as-graph.cjs +1 -1
  3. package/dist/as-graph.cjs.map +1 -1
  4. package/dist/as-graph.js +1 -1
  5. package/dist/as-graph.js.map +1 -1
  6. package/lib/cjs/dagster/DagsterGraphEventBridge.cjs +344 -0
  7. package/lib/cjs/dagster/DagsterGraphEventBridge.cjs.map +1 -0
  8. package/lib/cjs/dagster/DagsterGraphExecutionBackend.cjs +789 -0
  9. package/lib/cjs/dagster/DagsterGraphExecutionBackend.cjs.map +1 -0
  10. package/lib/cjs/dagster/DagsterResultMapper.cjs +56 -0
  11. package/lib/cjs/dagster/DagsterResultMapper.cjs.map +1 -0
  12. package/lib/cjs/dagster/DagsterTypes.cjs +4 -0
  13. package/lib/cjs/dagster/DagsterTypes.cjs.map +1 -0
  14. package/lib/cjs/dagster/capabilities.cjs +102 -0
  15. package/lib/cjs/dagster/capabilities.cjs.map +1 -0
  16. package/lib/cjs/dagster/constants.cjs +92 -0
  17. package/lib/cjs/dagster/constants.cjs.map +1 -0
  18. package/lib/cjs/dagster/index.cjs +32 -0
  19. package/lib/cjs/dagster/index.cjs.map +1 -0
  20. package/lib/cjs/engine/constants.cjs +6 -1
  21. package/lib/cjs/engine/constants.cjs.map +1 -1
  22. package/lib/cjs/engine/execution/GraphCodeMode.cjs +137 -0
  23. package/lib/cjs/engine/execution/GraphCodeMode.cjs.map +1 -0
  24. package/lib/cjs/engine/execution/GraphExecutionBackend.cjs +89 -0
  25. package/lib/cjs/engine/execution/GraphExecutionBackend.cjs.map +1 -0
  26. package/lib/cjs/engine/execution/GraphExecutionBackendRegistry.cjs +107 -0
  27. package/lib/cjs/engine/execution/GraphExecutionBackendRegistry.cjs.map +1 -0
  28. package/lib/cjs/engine/execution/GraphExecutionEngine.cjs +250 -733
  29. package/lib/cjs/engine/execution/GraphExecutionEngine.cjs.map +1 -1
  30. package/lib/cjs/engine/execution/LocalGraphExecutionBackend.cjs +804 -0
  31. package/lib/cjs/engine/execution/LocalGraphExecutionBackend.cjs.map +1 -0
  32. package/lib/cjs/engine/execution/index.cjs +4 -0
  33. package/lib/cjs/engine/execution/index.cjs.map +1 -1
  34. package/lib/cjs/engine/index.cjs +4 -0
  35. package/lib/cjs/engine/index.cjs.map +1 -1
  36. package/lib/cjs/engine/runs/GraphRunService.cjs +61 -0
  37. package/lib/cjs/engine/runs/GraphRunService.cjs.map +1 -1
  38. package/lib/cjs/engine/services/GraphWorkflowService.cjs +33 -14
  39. package/lib/cjs/engine/services/GraphWorkflowService.cjs.map +1 -1
  40. package/lib/cjs/mastra/MastraCapabilities.cjs +171 -0
  41. package/lib/cjs/mastra/MastraCapabilities.cjs.map +1 -0
  42. package/lib/cjs/mastra/MastraConditionBridge.cjs +39 -0
  43. package/lib/cjs/mastra/MastraConditionBridge.cjs.map +1 -0
  44. package/lib/cjs/mastra/MastraEventBridge.cjs +486 -0
  45. package/lib/cjs/mastra/MastraEventBridge.cjs.map +1 -0
  46. package/lib/cjs/mastra/MastraGraphExecutionBackend.cjs +351 -0
  47. package/lib/cjs/mastra/MastraGraphExecutionBackend.cjs.map +1 -0
  48. package/lib/cjs/mastra/MastraResumeGuard.cjs +127 -0
  49. package/lib/cjs/mastra/MastraResumeGuard.cjs.map +1 -0
  50. package/lib/cjs/mastra/MastraSchemaConverter.cjs +124 -0
  51. package/lib/cjs/mastra/MastraSchemaConverter.cjs.map +1 -0
  52. package/lib/cjs/mastra/MastraWorkflowCompiler.cjs +461 -0
  53. package/lib/cjs/mastra/MastraWorkflowCompiler.cjs.map +1 -0
  54. package/lib/cjs/mastra/MastraWorkflowManager.cjs +401 -0
  55. package/lib/cjs/mastra/MastraWorkflowManager.cjs.map +1 -0
  56. package/lib/cjs/mastra/index.cjs +35 -0
  57. package/lib/cjs/mastra/index.cjs.map +1 -0
  58. package/lib/cjs/mastra/types.cjs +34 -0
  59. package/lib/cjs/mastra/types.cjs.map +1 -0
  60. package/lib/cjs/nest/graph/GraphEngineCapabilityManifest.cjs +136 -0
  61. package/lib/cjs/nest/graph/GraphEngineCapabilityManifest.cjs.map +1 -0
  62. package/lib/cjs/nest/graph/GraphEngineCapabilityService.cjs +140 -0
  63. package/lib/cjs/nest/graph/GraphEngineCapabilityService.cjs.map +1 -0
  64. package/lib/cjs/nest/graph/GraphEngineController.cjs +227 -0
  65. package/lib/cjs/nest/graph/GraphEngineController.cjs.map +1 -0
  66. package/lib/cjs/nest/graph/GraphExecutionModule.cjs +30 -2
  67. package/lib/cjs/nest/graph/GraphExecutionModule.cjs.map +1 -1
  68. package/lib/cjs/nest/graph/index.cjs +3 -0
  69. package/lib/cjs/nest/graph/index.cjs.map +1 -1
  70. package/lib/cjs/nest/graph/main.cjs +54 -0
  71. package/lib/cjs/nest/graph/main.cjs.map +1 -0
  72. package/lib/cjs/nest/graph/servingErrors.cjs +3 -0
  73. package/lib/cjs/nest/graph/servingErrors.cjs.map +1 -1
  74. package/lib/cjs/node/utility/code/node.cjs +11 -3
  75. package/lib/cjs/node/utility/code/node.cjs.map +1 -1
  76. package/lib/cjs/shared/graph/catalog/GraphManifestCompiler.cjs +2 -3
  77. package/lib/cjs/shared/graph/catalog/GraphManifestCompiler.cjs.map +1 -1
  78. package/lib/cjs/shared/graph/constants.cjs +8 -0
  79. package/lib/cjs/shared/graph/constants.cjs.map +1 -1
  80. package/lib/cjs/shared/graph/index.cjs +2 -1
  81. package/lib/cjs/shared/graph/index.cjs.map +1 -1
  82. package/lib/cjs/shared/graph/layout/GraphWorkflowLayout.cjs +146 -0
  83. package/lib/cjs/shared/graph/layout/GraphWorkflowLayout.cjs.map +1 -0
  84. package/lib/cjs/shared/graph/layout/index.cjs +23 -0
  85. package/lib/cjs/shared/graph/layout/index.cjs.map +1 -0
  86. package/lib/cjs/shared/graph/layout/layout-options.cjs +93 -0
  87. package/lib/cjs/shared/graph/layout/layout-options.cjs.map +1 -0
  88. package/lib/cjs/shared/ui/index.cjs +8 -10
  89. package/lib/cjs/shared/ui/index.cjs.map +1 -1
  90. package/lib/esm/dagster/DagsterGraphEventBridge.js +339 -0
  91. package/lib/esm/dagster/DagsterGraphEventBridge.js.map +1 -0
  92. package/lib/esm/dagster/DagsterGraphExecutionBackend.js +781 -0
  93. package/lib/esm/dagster/DagsterGraphExecutionBackend.js.map +1 -0
  94. package/lib/esm/dagster/DagsterResultMapper.js +51 -0
  95. package/lib/esm/dagster/DagsterResultMapper.js.map +1 -0
  96. package/lib/esm/dagster/DagsterTypes.js +2 -0
  97. package/lib/esm/dagster/DagsterTypes.js.map +1 -0
  98. package/lib/esm/dagster/capabilities.js +97 -0
  99. package/lib/esm/dagster/capabilities.js.map +1 -0
  100. package/lib/esm/dagster/constants.js +88 -0
  101. package/lib/esm/dagster/constants.js.map +1 -0
  102. package/lib/esm/dagster/index.js +15 -0
  103. package/lib/esm/dagster/index.js.map +1 -0
  104. package/lib/esm/engine/constants.js +5 -0
  105. package/lib/esm/engine/constants.js.map +1 -1
  106. package/lib/esm/engine/execution/GraphCodeMode.js +132 -0
  107. package/lib/esm/engine/execution/GraphCodeMode.js.map +1 -0
  108. package/lib/esm/engine/execution/GraphExecutionBackend.js +83 -0
  109. package/lib/esm/engine/execution/GraphExecutionBackend.js.map +1 -0
  110. package/lib/esm/engine/execution/GraphExecutionBackendRegistry.js +102 -0
  111. package/lib/esm/engine/execution/GraphExecutionBackendRegistry.js.map +1 -0
  112. package/lib/esm/engine/execution/GraphExecutionEngine.js +232 -716
  113. package/lib/esm/engine/execution/GraphExecutionEngine.js.map +1 -1
  114. package/lib/esm/engine/execution/LocalGraphExecutionBackend.js +799 -0
  115. package/lib/esm/engine/execution/LocalGraphExecutionBackend.js.map +1 -0
  116. package/lib/esm/engine/execution/index.js +4 -0
  117. package/lib/esm/engine/execution/index.js.map +1 -1
  118. package/lib/esm/engine/index.js +4 -0
  119. package/lib/esm/engine/index.js.map +1 -1
  120. package/lib/esm/engine/runs/GraphRunService.js +62 -1
  121. package/lib/esm/engine/runs/GraphRunService.js.map +1 -1
  122. package/lib/esm/engine/services/GraphWorkflowService.js +33 -14
  123. package/lib/esm/engine/services/GraphWorkflowService.js.map +1 -1
  124. package/lib/esm/mastra/MastraCapabilities.js +164 -0
  125. package/lib/esm/mastra/MastraCapabilities.js.map +1 -0
  126. package/lib/esm/mastra/MastraConditionBridge.js +34 -0
  127. package/lib/esm/mastra/MastraConditionBridge.js.map +1 -0
  128. package/lib/esm/mastra/MastraEventBridge.js +481 -0
  129. package/lib/esm/mastra/MastraEventBridge.js.map +1 -0
  130. package/lib/esm/mastra/MastraGraphExecutionBackend.js +346 -0
  131. package/lib/esm/mastra/MastraGraphExecutionBackend.js.map +1 -0
  132. package/lib/esm/mastra/MastraResumeGuard.js +123 -0
  133. package/lib/esm/mastra/MastraResumeGuard.js.map +1 -0
  134. package/lib/esm/mastra/MastraSchemaConverter.js +119 -0
  135. package/lib/esm/mastra/MastraSchemaConverter.js.map +1 -0
  136. package/lib/esm/mastra/MastraWorkflowCompiler.js +456 -0
  137. package/lib/esm/mastra/MastraWorkflowCompiler.js.map +1 -0
  138. package/lib/esm/mastra/MastraWorkflowManager.js +396 -0
  139. package/lib/esm/mastra/MastraWorkflowManager.js.map +1 -0
  140. package/lib/esm/mastra/index.js +18 -0
  141. package/lib/esm/mastra/index.js.map +1 -0
  142. package/lib/esm/mastra/types.js +30 -0
  143. package/lib/esm/mastra/types.js.map +1 -0
  144. package/lib/esm/nest/graph/GraphEngineCapabilityManifest.js +129 -0
  145. package/lib/esm/nest/graph/GraphEngineCapabilityManifest.js.map +1 -0
  146. package/lib/esm/nest/graph/GraphEngineCapabilityService.js +131 -0
  147. package/lib/esm/nest/graph/GraphEngineCapabilityService.js.map +1 -0
  148. package/lib/esm/nest/graph/GraphEngineController.js +218 -0
  149. package/lib/esm/nest/graph/GraphEngineController.js.map +1 -0
  150. package/lib/esm/nest/graph/GraphExecutionModule.js +30 -2
  151. package/lib/esm/nest/graph/GraphExecutionModule.js.map +1 -1
  152. package/lib/esm/nest/graph/index.js +3 -0
  153. package/lib/esm/nest/graph/index.js.map +1 -1
  154. package/lib/esm/nest/graph/main.js +51 -0
  155. package/lib/esm/nest/graph/main.js.map +1 -0
  156. package/lib/esm/nest/graph/servingErrors.js +3 -0
  157. package/lib/esm/nest/graph/servingErrors.js.map +1 -1
  158. package/lib/esm/node/utility/code/node.js +11 -3
  159. package/lib/esm/node/utility/code/node.js.map +1 -1
  160. package/lib/esm/shared/graph/GraphExecutionStateMapper.js.map +1 -1
  161. package/lib/esm/shared/graph/catalog/GraphManifestCompiler.js +2 -3
  162. package/lib/esm/shared/graph/catalog/GraphManifestCompiler.js.map +1 -1
  163. package/lib/esm/shared/graph/constants.js +8 -0
  164. package/lib/esm/shared/graph/constants.js.map +1 -1
  165. package/lib/esm/shared/graph/index.js +2 -1
  166. package/lib/esm/shared/graph/index.js.map +1 -1
  167. package/lib/esm/shared/graph/layout/GraphWorkflowLayout.js +107 -0
  168. package/lib/esm/shared/graph/layout/GraphWorkflowLayout.js.map +1 -0
  169. package/lib/esm/shared/graph/layout/index.js +6 -0
  170. package/lib/esm/shared/graph/layout/index.js.map +1 -0
  171. package/lib/esm/shared/graph/layout/layout-options.js +96 -0
  172. package/lib/esm/shared/graph/layout/layout-options.js.map +1 -0
  173. package/lib/esm/shared/ui/index.js +8 -10
  174. package/lib/esm/shared/ui/index.js.map +1 -1
  175. package/lib/types/dagster/DagsterGraphEventBridge.d.cts +142 -0
  176. package/lib/types/dagster/DagsterGraphEventBridge.d.mts +142 -0
  177. package/lib/types/dagster/DagsterGraphExecutionBackend.d.cts +323 -0
  178. package/lib/types/dagster/DagsterGraphExecutionBackend.d.mts +323 -0
  179. package/lib/types/dagster/DagsterResultMapper.d.cts +50 -0
  180. package/lib/types/dagster/DagsterResultMapper.d.mts +50 -0
  181. package/lib/types/dagster/DagsterTypes.d.cts +355 -0
  182. package/lib/types/dagster/DagsterTypes.d.mts +355 -0
  183. package/lib/types/dagster/capabilities.d.cts +34 -0
  184. package/lib/types/dagster/capabilities.d.mts +34 -0
  185. package/lib/types/dagster/constants.d.cts +87 -0
  186. package/lib/types/dagster/constants.d.mts +87 -0
  187. package/lib/types/dagster/index.d.cts +14 -0
  188. package/lib/types/dagster/index.d.mts +14 -0
  189. package/lib/types/engine/constants.d.cts +5 -0
  190. package/lib/types/engine/constants.d.mts +5 -0
  191. package/lib/types/engine/execution/GraphCodeMode.d.cts +52 -0
  192. package/lib/types/engine/execution/GraphCodeMode.d.mts +52 -0
  193. package/lib/types/engine/execution/GraphExecutionBackend.d.cts +306 -0
  194. package/lib/types/engine/execution/GraphExecutionBackend.d.mts +306 -0
  195. package/lib/types/engine/execution/GraphExecutionBackendRegistry.d.cts +59 -0
  196. package/lib/types/engine/execution/GraphExecutionBackendRegistry.d.mts +59 -0
  197. package/lib/types/engine/execution/GraphExecutionEngine.d.cts +116 -135
  198. package/lib/types/engine/execution/GraphExecutionEngine.d.mts +116 -135
  199. package/lib/types/engine/execution/LocalGraphExecutionBackend.d.cts +232 -0
  200. package/lib/types/engine/execution/LocalGraphExecutionBackend.d.mts +232 -0
  201. package/lib/types/engine/execution/index.d.cts +4 -0
  202. package/lib/types/engine/execution/index.d.mts +4 -0
  203. package/lib/types/engine/index.d.cts +4 -0
  204. package/lib/types/engine/index.d.mts +4 -0
  205. package/lib/types/engine/runs/GraphRunService.d.cts +19 -0
  206. package/lib/types/engine/runs/GraphRunService.d.mts +19 -0
  207. package/lib/types/engine/services/GraphWorkflowService.d.cts +22 -0
  208. package/lib/types/engine/services/GraphWorkflowService.d.mts +22 -0
  209. package/lib/types/mastra/MastraCapabilities.d.cts +91 -0
  210. package/lib/types/mastra/MastraCapabilities.d.mts +91 -0
  211. package/lib/types/mastra/MastraConditionBridge.d.cts +38 -0
  212. package/lib/types/mastra/MastraConditionBridge.d.mts +38 -0
  213. package/lib/types/mastra/MastraEventBridge.d.cts +189 -0
  214. package/lib/types/mastra/MastraEventBridge.d.mts +189 -0
  215. package/lib/types/mastra/MastraGraphExecutionBackend.d.cts +119 -0
  216. package/lib/types/mastra/MastraGraphExecutionBackend.d.mts +119 -0
  217. package/lib/types/mastra/MastraResumeGuard.d.cts +58 -0
  218. package/lib/types/mastra/MastraResumeGuard.d.mts +58 -0
  219. package/lib/types/mastra/MastraSchemaConverter.d.cts +39 -0
  220. package/lib/types/mastra/MastraSchemaConverter.d.mts +39 -0
  221. package/lib/types/mastra/MastraWorkflowCompiler.d.cts +218 -0
  222. package/lib/types/mastra/MastraWorkflowCompiler.d.mts +218 -0
  223. package/lib/types/mastra/MastraWorkflowManager.d.cts +220 -0
  224. package/lib/types/mastra/MastraWorkflowManager.d.mts +220 -0
  225. package/lib/types/mastra/index.d.cts +17 -0
  226. package/lib/types/mastra/index.d.mts +17 -0
  227. package/lib/types/mastra/types.d.cts +222 -0
  228. package/lib/types/mastra/types.d.mts +222 -0
  229. package/lib/types/nest/graph/GraphEngineCapabilityManifest.d.cts +87 -0
  230. package/lib/types/nest/graph/GraphEngineCapabilityManifest.d.mts +87 -0
  231. package/lib/types/nest/graph/GraphEngineCapabilityService.d.cts +98 -0
  232. package/lib/types/nest/graph/GraphEngineCapabilityService.d.mts +98 -0
  233. package/lib/types/nest/graph/GraphEngineController.d.cts +74 -0
  234. package/lib/types/nest/graph/GraphEngineController.d.mts +74 -0
  235. package/lib/types/nest/graph/GraphExecutionModule.d.cts +8 -0
  236. package/lib/types/nest/graph/GraphExecutionModule.d.mts +8 -0
  237. package/lib/types/nest/graph/index.d.cts +3 -0
  238. package/lib/types/nest/graph/index.d.mts +3 -0
  239. package/lib/types/nest/graph/main.d.cts +1 -0
  240. package/lib/types/nest/graph/main.d.mts +1 -0
  241. package/lib/types/nest/graph/servingErrors.d.cts +3 -1
  242. package/lib/types/nest/graph/servingErrors.d.mts +3 -1
  243. package/lib/types/node/utility/code/node.d.cts +1 -1
  244. package/lib/types/node/utility/code/node.d.mts +1 -1
  245. package/lib/types/shared/graph/GraphExecutionStateMapper.d.cts +5 -5
  246. package/lib/types/shared/graph/GraphExecutionStateMapper.d.mts +5 -5
  247. package/lib/types/shared/graph/constants.d.cts +8 -0
  248. package/lib/types/shared/graph/constants.d.mts +8 -0
  249. package/lib/types/shared/graph/index.d.cts +2 -1
  250. package/lib/types/shared/graph/index.d.mts +2 -1
  251. package/lib/types/shared/graph/layout/GraphWorkflowLayout.d.cts +49 -0
  252. package/lib/types/shared/graph/layout/GraphWorkflowLayout.d.mts +49 -0
  253. package/lib/types/shared/graph/layout/index.d.cts +5 -0
  254. package/lib/types/shared/graph/layout/index.d.mts +5 -0
  255. package/lib/types/shared/graph/layout/layout-options.d.cts +46 -0
  256. package/lib/types/shared/graph/layout/layout-options.d.mts +46 -0
  257. package/lib/types/shared/graph/types.d.cts +4 -3
  258. package/lib/types/shared/graph/types.d.mts +4 -3
  259. package/lib/types/shared/ui/index.d.cts +8 -10
  260. package/lib/types/shared/ui/index.d.mts +8 -10
  261. package/package.json +49 -6
  262. package/lib/cjs/shared/ui/GraphNodeView.cjs +0 -114
  263. package/lib/cjs/shared/ui/GraphNodeView.cjs.map +0 -1
  264. package/lib/cjs/shared/ui/GraphRunView.cjs +0 -96
  265. package/lib/cjs/shared/ui/GraphRunView.cjs.map +0 -1
  266. package/lib/cjs/shared/ui/GraphWorkflowView.cjs +0 -78
  267. package/lib/cjs/shared/ui/GraphWorkflowView.cjs.map +0 -1
  268. package/lib/cjs/shared/ui/types.cjs +0 -4
  269. package/lib/cjs/shared/ui/types.cjs.map +0 -1
  270. package/lib/esm/shared/ui/GraphNodeView.js +0 -107
  271. package/lib/esm/shared/ui/GraphNodeView.js.map +0 -1
  272. package/lib/esm/shared/ui/GraphRunView.js +0 -90
  273. package/lib/esm/shared/ui/GraphRunView.js.map +0 -1
  274. package/lib/esm/shared/ui/GraphWorkflowView.js +0 -72
  275. package/lib/esm/shared/ui/GraphWorkflowView.js.map +0 -1
  276. package/lib/esm/shared/ui/types.js +0 -2
  277. package/lib/esm/shared/ui/types.js.map +0 -1
  278. package/lib/types/shared/ui/GraphNodeView.d.cts +0 -48
  279. package/lib/types/shared/ui/GraphNodeView.d.mts +0 -48
  280. package/lib/types/shared/ui/GraphRunView.d.cts +0 -88
  281. package/lib/types/shared/ui/GraphRunView.d.mts +0 -88
  282. package/lib/types/shared/ui/GraphWorkflowView.d.cts +0 -18
  283. package/lib/types/shared/ui/GraphWorkflowView.d.mts +0 -18
  284. package/lib/types/shared/ui/types.d.cts +0 -200
  285. package/lib/types/shared/ui/types.d.mts +0 -200
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphExecutionEngine = void 0;
4
+ exports.stripFacadeOwnedBackendConfig = stripFacadeOwnedBackendConfig;
4
5
  /**
5
6
  * @module as-graph/execution/GraphExecutionEngine
6
7
  * @summary Reference graph execution engine (DECAF-50 §4.9).
@@ -20,36 +21,57 @@ exports.GraphExecutionEngine = void 0;
20
21
  * events and the `graph.run.log` run-log channel.
21
22
  */
22
23
  const core_1 = require("@decaf-ts/core");
23
- const index_js_1 = require("./../../shared/graph/index.cjs");
24
24
  const constants_js_1 = require("./../constants.cjs");
25
- const index_js_2 = require("./../../shared/graph/index.cjs");
26
- const index_js_3 = require("./../errors/index.cjs");
25
+ const index_js_1 = require("./../../shared/graph/index.cjs");
26
+ const index_js_2 = require("./../errors/index.cjs");
27
27
  const GraphExecutionEventEmitter_js_1 = require("./../events/GraphExecutionEventEmitter.cjs");
28
28
  const GraphExecutionEventFactory_js_1 = require("./../events/GraphExecutionEventFactory.cjs");
29
29
  const GraphExecutionPlanner_js_1 = require("./../planning/GraphExecutionPlanner.cjs");
30
30
  const GraphWorkflowDocumentValidator_js_1 = require("./../validation/GraphWorkflowDocumentValidator.cjs");
31
- const GraphParameterValidator_js_1 = require("./../validation/GraphParameterValidator.cjs");
32
31
  const GraphValidationErrors_js_1 = require("./../validation/GraphValidationErrors.cjs");
33
32
  const GraphValueRepository_js_1 = require("./../store/GraphValueRepository.cjs");
34
33
  const GraphPinningService_js_1 = require("./../pinning/GraphPinningService.cjs");
35
34
  const GraphPinningPolicy_js_1 = require("./../pinning/GraphPinningPolicy.cjs");
36
35
  const GraphPinningDependencyResolver_js_1 = require("./../pinning/GraphPinningDependencyResolver.cjs");
37
- const GraphExecutionContext_js_1 = require("./GraphExecutionContext.cjs");
38
36
  const GraphExecutionFrame_js_1 = require("./GraphExecutionFrame.cjs");
39
- const GraphExecutionResult_js_1 = require("./GraphExecutionResult.cjs");
40
- const index_js_4 = require("./../auth/index.cjs");
37
+ const GraphExecutionBackend_js_1 = require("./GraphExecutionBackend.cjs");
38
+ const GraphCodeMode_js_1 = require("./GraphCodeMode.cjs");
39
+ const GraphExecutionBackendRegistry_js_1 = require("./GraphExecutionBackendRegistry.cjs");
40
+ const LocalGraphExecutionBackend_js_1 = require("./LocalGraphExecutionBackend.cjs");
41
+ const index_js_3 = require("./../auth/index.cjs");
42
+ /**
43
+ * Facade-owned backend-config keys the facade is the sole authority for. A value
44
+ * under one of these keys in a backend's retained `config` must never survive the
45
+ * engine's re-initialization merge unless the facade itself set it.
46
+ */
47
+ const FACADE_OWNED_BACKEND_CONFIG_KEYS = new Set([
48
+ "engine",
49
+ "valueAdapter",
50
+ "codeSandboxEvaluator",
51
+ "workflowStore",
52
+ ]);
41
53
  /**
42
- * Compiles a `{{ ... }}` text template into a JavaScript template literal so
43
- * the pluggable code sandbox evaluator can resolve its placeholders against
44
- * the same `$input`/`$vars`/`$item` bindings used by expression bindings.
54
+ * Strips facade-owned keys from a backend's retained configuration that the facade
55
+ * did not itself set (defense in depth). A backend's `config` getter may derive
56
+ * from lower-trust input; without this guard a same-key value would survive the
57
+ * merge whenever the facade omits that key and become a config-injection sink. Keys
58
+ * the facade itself set are kept: the facade is their authority and the caller
59
+ * merges its own values over them afterwards.
45
60
  *
46
- * @param template - The persisted template body.
47
- * @returns A backtick-quoted template literal expression.
61
+ * @param hostBackendConfig - The config the backend retained from a previous
62
+ * `initialize`; may be `undefined`.
63
+ * @param facadeSetKeys - The facade-owned keys the facade itself set on this pass.
64
+ * @returns A copy of the host config with unowned facade-owned keys removed.
48
65
  */
49
- function graphTemplateToExpression(template) {
50
- const escaped = template.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
51
- const interpolated = escaped.replace(/\{\{\s*([\s\S]*?)\s*\}\}/g, (_match, expression) => `\${${expression}}`);
52
- return `\`${interpolated}\``;
66
+ function stripFacadeOwnedBackendConfig(hostBackendConfig, facadeSetKeys) {
67
+ const sanitized = {};
68
+ for (const [key, value] of Object.entries(hostBackendConfig ?? {})) {
69
+ if (FACADE_OWNED_BACKEND_CONFIG_KEYS.has(key) && !facadeSetKeys.has(key)) {
70
+ continue;
71
+ }
72
+ sanitized[key] = value;
73
+ }
74
+ return sanitized;
53
75
  }
54
76
  /**
55
77
  * Reference graph execution engine.
@@ -79,6 +101,12 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
79
101
  * `Service.boot` may call this with only a decaf `Context`; an explicit
80
102
  * `initialize(config)` is required before the engine can execute.
81
103
  *
104
+ * The active backend is (re-)initialized with the facade-owned collaborators
105
+ * merged over any host config the backend already retains
106
+ * (`GraphExecutionBackend.config`). Facade-owned keys win on collision, so a
107
+ * host `backend.initialize({ mastra, stepHandlers, ... })` performed before
108
+ * `engine.boot` survives this pass instead of being dropped.
109
+ *
82
110
  * @param args - The engine config, optionally followed by a decaf `Context`.
83
111
  * @returns The resolved config and runtime client bundle.
84
112
  */
@@ -92,12 +120,16 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
92
120
  const catalogue = config.catalogue ?? config.registry.catalog;
93
121
  const valueAdapter = config.valueAdapter ?? core_1.Adapter.current;
94
122
  if (!valueAdapter) {
95
- throw new index_js_3.GraphExecutionError("GraphExecutionEngine requires a Decaf adapter for cached/pinned values: pass `valueAdapter` or configure one via `Adapter.setCurrent(...)`", "GRAPH_VALUE_ADAPTER_MISSING");
123
+ throw new index_js_2.GraphExecutionError("GraphExecutionEngine requires a Decaf adapter for cached/pinned values: pass `valueAdapter` or configure one via `Adapter.setCurrent(...)`", "GRAPH_VALUE_ADAPTER_MISSING");
96
124
  }
125
+ const backend = config.backend ??
126
+ GraphExecutionBackendRegistry_js_1.GraphExecutionBackendRegistry.current ??
127
+ new LocalGraphExecutionBackend_js_1.LocalGraphExecutionBackend();
97
128
  const client = {
98
129
  registry: config.registry,
99
130
  catalogue,
100
131
  planner: config.planner ?? new GraphExecutionPlanner_js_1.GraphExecutionPlanner(),
132
+ backend,
101
133
  valueAdapter,
102
134
  eventEmitter: config.eventEmitter ?? new GraphExecutionEventEmitter_js_1.GraphExecutionEventEmitter(),
103
135
  documentValidator: config.documentValidator ??
@@ -106,7 +138,7 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
106
138
  limits: config.documentLimits,
107
139
  credentialAuthorizer: config.credentialAuthorizer,
108
140
  }),
109
- authValidator: new index_js_4.GraphAuthValidator({
141
+ authValidator: new index_js_3.GraphAuthValidator({
110
142
  enabled: config.authEnabled === true,
111
143
  ...(config.authMatch ? { match: config.authMatch } : {}),
112
144
  }),
@@ -116,6 +148,39 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
116
148
  };
117
149
  this._config = config;
118
150
  this._client = client;
151
+ // Preserve any host-supplied backend configuration. A host may configure the
152
+ // backend directly (e.g. `backend.initialize({ mastra, stepHandlers })`)
153
+ // before booting the engine; this initialize pass must not silently drop that
154
+ // wiring. Merge the backend's retained config under the facade-owned keys so a
155
+ // host key survives unless the facade owns the same key. Facade-owned keys win
156
+ // on collision (`engine`, `valueAdapter`, `codeSandboxEvaluator`,
157
+ // `workflowStore`): the facade is the authority for the collaborators it
158
+ // owns, and a backend that already re-wired them itself is simply refreshed.
159
+ //
160
+ // Fail closed on facade-owned keys the facade did NOT itself set: strip them
161
+ // from the retained config before merging. A backend whose `config` getter
162
+ // derives from lower-trust input must not be able to inject a collaborator the
163
+ // facade owns just because this engine config omitted it (C2,
164
+ // defense-in-depth under Complete Mediation / Secure Defaults).
165
+ const facadeSetKeys = new Set(["engine", "valueAdapter"]);
166
+ if (config.codeSandboxEvaluator) {
167
+ facadeSetKeys.add("codeSandboxEvaluator");
168
+ }
169
+ if (config.workflowStore) {
170
+ facadeSetKeys.add("workflowStore");
171
+ }
172
+ const hostBackendConfig = stripFacadeOwnedBackendConfig(backend.config, facadeSetKeys);
173
+ await backend.initialize({
174
+ ...hostBackendConfig,
175
+ valueAdapter,
176
+ ...(config.codeSandboxEvaluator
177
+ ? { codeSandboxEvaluator: config.codeSandboxEvaluator }
178
+ : {}),
179
+ ...(config.workflowStore
180
+ ? { workflowStore: config.workflowStore }
181
+ : {}),
182
+ engine: this,
183
+ });
119
184
  await config.onEngineCreated?.(this);
120
185
  return { config, client };
121
186
  }
@@ -187,57 +252,47 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
187
252
  // Resolve the authenticated principal from the run context (bound by the host
188
253
  // AuthHandler) and/or the explicit option, and bind its app parameters onto
189
254
  // the run metadata so `ctx.logger` carries them for the whole run.
190
- const auth = (0, index_js_4.mergeGraphAuthData)((0, index_js_4.graphAuthDataOf)(ctx), opts.auth);
255
+ const auth = (0, index_js_3.mergeGraphAuthData)((0, index_js_3.graphAuthDataOf)(ctx), opts.auth);
191
256
  opts.auth = auth;
192
257
  opts.metadata = { ...(opts.metadata ?? {}), ...auth };
193
258
  const runId = opts.runId ?? this.generateRunId();
259
+ // Propagate the resolved run id onto the options so every backend
260
+ // (including remote/translated backends that never see the local frame)
261
+ // receives the authoritative run id.
262
+ opts.runId = runId;
194
263
  const path = opts.path ?? [];
195
264
  const eventFactory = new GraphExecutionEventFactory_js_1.GraphExecutionEventFactory();
196
265
  const valueStore = (0, GraphValueRepository_js_1.createGraphValueRepository)(this.valueAdapter);
197
266
  valueStore.seedWorkflowInputs(this.withWorkflowInputDefaults(document, inputs));
198
- const emitFn = async (partial) => {
199
- await this.emitEvent(frame, {
200
- type: partial.type ?? index_js_2.GraphExecutionEventType.NODE_OUTPUT,
201
- runId,
202
- parentRunId: opts.parentRunId,
203
- workflowId: document.id || document.name,
204
- nodeId: partial.nodeId,
205
- path: partial.path ?? path,
206
- ...partial,
207
- });
208
- };
209
- const emitValidationEvent = async (partial) => {
210
- const event = eventFactory.create({
211
- id: "",
212
- sequence: 0,
213
- timestamp: new Date(),
214
- runId,
215
- parentRunId: opts.parentRunId,
216
- workflowId: document.id || document.name,
217
- path,
218
- ...partial,
219
- });
220
- await this.emitter.updateObservers(event);
221
- };
267
+ const sink = new GraphExecutionBackend_js_1.GraphEngineEventSink(this.emitter, eventFactory, {
268
+ runId,
269
+ parentRunId: opts.parentRunId,
270
+ workflowId: document.id || document.name,
271
+ path,
272
+ engine: this,
273
+ ...(this.codeSandboxEvaluator
274
+ ? { codeSandboxEvaluator: this.codeSandboxEvaluator }
275
+ : {}),
276
+ });
222
277
  // ------------------------------------------------------------------
223
278
  // Validation + resolution (nine-stage gate, §4.8) — internal.
224
279
  // ------------------------------------------------------------------
225
- await emitValidationEvent({
226
- type: index_js_2.GraphExecutionEventType.VALIDATION_STARTED,
227
- status: index_js_2.GraphExecutionStatus.PLANNING,
280
+ await sink.emit({
281
+ type: index_js_1.GraphExecutionEventType.VALIDATION_STARTED,
282
+ status: index_js_1.GraphExecutionStatus.PLANNING,
228
283
  });
229
284
  const validation = await this.documentValidator.validate(document, 0, ctx);
230
285
  if (!validation.valid || !validation.resolved) {
231
- await emitValidationEvent({
232
- type: index_js_2.GraphExecutionEventType.VALIDATION_FAILED,
233
- status: index_js_2.GraphExecutionStatus.FAILED,
286
+ await sink.emit({
287
+ type: index_js_1.GraphExecutionEventType.VALIDATION_FAILED,
288
+ status: index_js_1.GraphExecutionStatus.FAILED,
234
289
  payload: { issues: validation.issues },
235
290
  });
236
291
  throw new GraphValidationErrors_js_1.GraphDocumentValidationError(`Graph workflow document '${document.id}' failed validation with ${validation.issues.length} issue(s)`, validation.issues);
237
292
  }
238
- await emitValidationEvent({
239
- type: index_js_2.GraphExecutionEventType.VALIDATION_COMPLETED,
240
- status: index_js_2.GraphExecutionStatus.PLANNING,
293
+ await sink.emit({
294
+ type: index_js_1.GraphExecutionEventType.VALIDATION_COMPLETED,
295
+ status: index_js_1.GraphExecutionStatus.PLANNING,
241
296
  payload: { issues: validation.issues.length },
242
297
  });
243
298
  this.assertNotAborted(opts);
@@ -247,80 +302,159 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
247
302
  // declares namespaces fails closed when the principal holds none of them.
248
303
  this.client.authValidator.validate(document, plan, auth, log);
249
304
  log.debug(`Authorized workflow '${document.id || document.name}' for user ${auth.user ?? "anonymous"}`);
305
+ // SAA-193 C1: fail closed before delegating a code-mode workflow to a
306
+ // non-local backend. A remote/translated backend can only run code-mode
307
+ // surfaces when it declares `codeMode: "hostSide"` AND the facade has a
308
+ // configured sandbox evaluator; otherwise the run is rejected here, before
309
+ // any remote launch.
310
+ this.assertCodeModeSupported(document);
250
311
  const frame = new GraphExecutionFrame_js_1.GraphExecutionFrame(runId, plan, valueStore, eventFactory);
251
- await this.emitEvent(frame, {
252
- type: index_js_2.GraphExecutionEventType.WORKFLOW_STARTED,
312
+ sink.bindFrame(frame);
313
+ await sink.emit({
314
+ type: index_js_1.GraphExecutionEventType.WORKFLOW_STARTED,
253
315
  runId,
254
316
  parentRunId: opts.parentRunId,
255
317
  workflowId: plan.workflowId,
256
318
  path,
257
- status: index_js_2.GraphExecutionStatus.RUNNING,
319
+ status: index_js_1.GraphExecutionStatus.RUNNING,
258
320
  payload: { inputs },
259
321
  });
260
- await this.emitEvent(frame, {
261
- type: index_js_2.GraphExecutionEventType.WORKFLOW_PLANNED,
322
+ await sink.emit({
323
+ type: index_js_1.GraphExecutionEventType.WORKFLOW_PLANNED,
262
324
  runId,
263
325
  parentRunId: opts.parentRunId,
264
326
  workflowId: plan.workflowId,
265
327
  path,
266
- status: index_js_2.GraphExecutionStatus.PLANNING,
328
+ status: index_js_1.GraphExecutionStatus.PLANNING,
267
329
  payload: { layers: plan.layers.length, nodes: plan.nodes.length },
268
330
  });
269
- try {
270
- for (const layer of plan.layers) {
271
- this.assertNotAborted(opts);
272
- await this.executeLayer(frame, plan, layer.nodes, opts, emitFn);
273
- }
274
- this.assertNotAborted(opts);
275
- const firstFailure = [...frame.nodeResults.values()].find((result) => result.status === index_js_2.GraphExecutionStatus.FAILED);
276
- if (firstFailure?.error) {
277
- throw new index_js_3.GraphExecutionError(firstFailure.error.message, firstFailure.error.code ?? "GRAPH_EXECUTION_ERROR", firstFailure.error.details);
278
- }
279
- frame.finish();
280
- await this.emitEvent(frame, {
281
- type: index_js_2.GraphExecutionEventType.WORKFLOW_COMPLETED,
282
- runId,
283
- parentRunId: opts.parentRunId,
284
- workflowId: plan.workflowId,
285
- path,
286
- status: index_js_2.GraphExecutionStatus.SUCCEEDED,
287
- payload: { outputs: valueStore.getWorkflowValues() },
288
- });
289
- return (0, GraphExecutionResult_js_1.buildGraphExecutionResult)(frame, document, inputs, index_js_2.GraphExecutionStatus.SUCCEEDED, opts.metadata);
331
+ return await this.client.backend.execute({ document, plan, inputs, options: opts, events: sink }, ...args);
332
+ }
333
+ /**
334
+ * The active pluggable execution backend. Exposed so the run lifecycle service
335
+ * can delegate optional backend extensions (e.g. the SAA-196 resume extension)
336
+ * without re-resolving the configured backend.
337
+ */
338
+ get backend() {
339
+ return this.client.backend;
340
+ }
341
+ /**
342
+ * Effective capability metadata of the active backend. Hosts and servers read
343
+ * this to surface what the current backend supports (code-mode handling and
344
+ * workflow listing/lookup) without probing it, and an unsupported operation is
345
+ * reported as `not_supported` rather than a silently empty result.
346
+ */
347
+ get backendCapabilities() {
348
+ return (0, GraphExecutionBackend_js_1.resolveGraphBackendCapabilities)(this.client.backend);
349
+ }
350
+ /**
351
+ * Lists the workflows the active backend can surface, through the engine-agnostic
352
+ * seam. Works identically for the default local backend (over its wired
353
+ * workflow store) and any remote/translated backend that implements the
354
+ * optional catalogue extension.
355
+ *
356
+ * @param args - Optional decaf contextual arguments forwarded to the backend.
357
+ * @returns Workflow summaries.
358
+ * @throws {GraphExecutionError} with `GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED`
359
+ * when the active backend declares no listing support.
360
+ */
361
+ async listWorkflows(...args) {
362
+ const backend = this.client.backend;
363
+ const capabilities = (0, GraphExecutionBackend_js_1.resolveGraphBackendCapabilities)(backend);
364
+ if (capabilities.workflows.list !== "supported" ||
365
+ typeof backend.listWorkflows !== "function") {
366
+ throw new index_js_2.GraphExecutionError(`Graph execution backend '${this.backendName}' does not support workflow listing`, "GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED", { backend: this.backendName });
290
367
  }
291
- catch (error) {
292
- // A cooperative `GraphBreakSignal` is loop-control flow, not a workflow
293
- // failure: propagate it unchanged so the enclosing loop executor can stop
294
- // iterating instead of seeing a failed child run.
295
- if (error instanceof index_js_3.GraphBreakSignal) {
296
- frame.finish();
297
- throw error;
298
- }
299
- frame.finish();
300
- const errorPayload = this.toErrorPayload(error);
301
- if (error instanceof index_js_3.GraphRunCancelledError ||
302
- opts.abortSignal?.aborted === true) {
303
- await this.emitEvent(frame, {
304
- type: index_js_2.GraphExecutionEventType.WORKFLOW_CANCELLED,
305
- runId,
306
- parentRunId: opts.parentRunId,
307
- workflowId: plan.workflowId,
308
- path,
309
- status: index_js_2.GraphExecutionStatus.CANCELLED,
310
- error: errorPayload,
311
- });
312
- return (0, GraphExecutionResult_js_1.buildGraphExecutionResult)(frame, document, inputs, index_js_2.GraphExecutionStatus.CANCELLED, opts.metadata);
313
- }
314
- await this.emitEvent(frame, {
315
- type: index_js_2.GraphExecutionEventType.WORKFLOW_FAILED,
316
- runId,
317
- parentRunId: opts.parentRunId,
318
- workflowId: plan.workflowId,
319
- path,
320
- status: index_js_2.GraphExecutionStatus.FAILED,
321
- error: errorPayload,
322
- });
323
- return (0, GraphExecutionResult_js_1.buildGraphExecutionResult)(frame, document, inputs, index_js_2.GraphExecutionStatus.FAILED, opts.metadata);
368
+ return await backend.listWorkflows(...args);
369
+ }
370
+ /**
371
+ * Looks up a single canonical workflow document through the active backend's
372
+ * engine-agnostic catalogue seam. The default local backend reads it from its
373
+ * wired workflow store; remote backends surface their own catalogue.
374
+ *
375
+ * @param workflowId - The canonical workflow id to read.
376
+ * @param args - Optional decaf contextual arguments forwarded to the backend.
377
+ * @returns The canonical workflow document.
378
+ * @throws {GraphExecutionError} with `GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED`
379
+ * when the active backend declares no lookup support.
380
+ */
381
+ async getWorkflow(workflowId, ...args) {
382
+ const backend = this.client.backend;
383
+ const capabilities = (0, GraphExecutionBackend_js_1.resolveGraphBackendCapabilities)(backend);
384
+ if (capabilities.workflows.get !== "supported" ||
385
+ typeof backend.getWorkflow !== "function") {
386
+ throw new index_js_2.GraphExecutionError(`Graph execution backend '${this.backendName}' does not support workflow lookup`, "GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED", { backend: this.backendName, workflowId });
387
+ }
388
+ return await backend.getWorkflow(workflowId, ...args);
389
+ }
390
+ /**
391
+ * Lists the workflows a *specific* registered backend can surface, resolved by
392
+ * flavour. This is the flavour-scoped counterpart of {@link listWorkflows}: the
393
+ * server exposes the engine catalogue per engine id, and every registered backend
394
+ * is reached through the same engine-agnostic {@link GraphExecutionBackend}
395
+ * listing seam with the same fail-closed capability gate and error code.
396
+ *
397
+ * @param flavour - The registered backend flavour (allowlisted engine id).
398
+ * @param args - Optional decaf contextual arguments forwarded to the backend.
399
+ * @returns Workflow summaries.
400
+ * @throws {GraphExecutionError} with `GRAPH_EXECUTION_BACKEND_NOT_REGISTERED`
401
+ * for an unknown flavour, or `GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED` when the
402
+ * backend declares no listing support.
403
+ */
404
+ async listEngineWorkflows(flavour, ...args) {
405
+ const backend = GraphExecutionBackendRegistry_js_1.GraphExecutionBackendRegistry.getOrFail(flavour);
406
+ const capabilities = (0, GraphExecutionBackend_js_1.resolveGraphBackendCapabilities)(backend);
407
+ if (capabilities.workflows.list !== "supported" ||
408
+ typeof backend.listWorkflows !== "function") {
409
+ throw new index_js_2.GraphExecutionError(`Graph execution backend '${flavour}' does not support workflow listing`, "GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED", { backend: flavour });
410
+ }
411
+ return await backend.listWorkflows(...args);
412
+ }
413
+ /**
414
+ * Looks up a single canonical workflow document on a *specific* registered
415
+ * backend, resolved by flavour. Flavour-scoped counterpart of
416
+ * {@link getWorkflow} with the same capability gate and error code.
417
+ *
418
+ * @param flavour - The registered backend flavour (allowlisted engine id).
419
+ * @param workflowId - The canonical workflow id to read.
420
+ * @param args - Optional decaf contextual arguments forwarded to the backend.
421
+ * @returns The canonical workflow document.
422
+ * @throws {GraphExecutionError} with `GRAPH_EXECUTION_BACKEND_NOT_REGISTERED`
423
+ * for an unknown flavour, or `GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED` when the
424
+ * backend declares no lookup support.
425
+ */
426
+ async getEngineWorkflow(flavour, workflowId, ...args) {
427
+ const backend = GraphExecutionBackendRegistry_js_1.GraphExecutionBackendRegistry.getOrFail(flavour);
428
+ const capabilities = (0, GraphExecutionBackend_js_1.resolveGraphBackendCapabilities)(backend);
429
+ if (capabilities.workflows.get !== "supported" ||
430
+ typeof backend.getWorkflow !== "function") {
431
+ throw new index_js_2.GraphExecutionError(`Graph execution backend '${flavour}' does not support workflow lookup`, "GRAPH_BACKEND_WORKFLOWS_NOT_SUPPORTED", { backend: flavour, workflowId });
432
+ }
433
+ return await backend.getWorkflow(workflowId, ...args);
434
+ }
435
+ /** Human-readable name of the active backend, for diagnostics. */
436
+ get backendName() {
437
+ return this.client.backend.constructor?.name ?? "GraphExecutionBackend";
438
+ }
439
+ /**
440
+ * SAA-193 C1 fail-closed gate. A non-local backend must not launch a
441
+ * workflow carrying any code-mode surface unless it declares
442
+ * `codeMode: "hostSide"` and the facade has a configured sandbox evaluator.
443
+ * Local backends are not gated: their code-mode surfaces fail naturally
444
+ * through the existing per-surface `GRAPH_CODE_SANDBOX_NOT_CONFIGURED` path.
445
+ */
446
+ assertCodeModeSupported(document) {
447
+ const backend = this.client.backend;
448
+ if (backend.local)
449
+ return;
450
+ const surfaces = (0, GraphCodeMode_js_1.detectGraphCodeModeSurfaces)(document);
451
+ if (surfaces.length === 0)
452
+ return;
453
+ if (backend.codeMode === "unsupported") {
454
+ throw new index_js_2.GraphExecutionError(`Graph execution backend '${this.backendName}' does not support code-mode workflows`, "GRAPH_CODE_MODE_UNSUPPORTED_BACKEND", { backend: this.backendName, surfaces });
455
+ }
456
+ if (!this.codeSandboxEvaluator) {
457
+ throw new index_js_2.GraphExecutionError("Code-mode workflows require a CodeSandboxEvaluator to be registered in GraphExecutionEngineConfig.codeSandboxEvaluator", "GRAPH_CODE_SANDBOX_NOT_CONFIGURED", { backend: this.backendName, surfaces });
324
458
  }
325
459
  }
326
460
  /**
@@ -332,7 +466,7 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
332
466
  async pinNode(options) {
333
467
  const service = this.createPinningService();
334
468
  await service.pinNode(options);
335
- await this.emitPinningEvent(options.nodeId, index_js_2.GraphExecutionEventType.NODE_PINNED);
469
+ await this.emitPinningEvent(options.nodeId, index_js_1.GraphExecutionEventType.NODE_PINNED);
336
470
  }
337
471
  /**
338
472
  * Unpins a node by its fingerprint.
@@ -340,7 +474,7 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
340
474
  async unpinNode(options) {
341
475
  const service = this.createPinningService();
342
476
  await service.unpinNode(options);
343
- await this.emitPinningEvent(options.nodeId, index_js_2.GraphExecutionEventType.NODE_UNPINNED);
477
+ await this.emitPinningEvent(options.nodeId, index_js_1.GraphExecutionEventType.NODE_UNPINNED);
344
478
  }
345
479
  /**
346
480
  * Creates a {@link GraphPinningService} backed by this engine's value store
@@ -380,595 +514,6 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
380
514
  }
381
515
  return seeded;
382
516
  }
383
- /**
384
- * Executes a layer of nodes with the configured concurrency.
385
- */
386
- async executeLayer(frame, plan, nodes, opts, emitFn) {
387
- const concurrency = Math.max(1, opts.concurrency ?? constants_js_1.GRAPH_DEFAULT_CONCURRENCY);
388
- const queue = [...nodes];
389
- while (queue.length > 0) {
390
- const batch = queue.splice(0, concurrency);
391
- await Promise.all(batch.map((node) => this.executeNode(frame, plan, node, opts, emitFn)));
392
- }
393
- }
394
- /**
395
- * Executes a single node, honouring disabled-node semantics (§4.9).
396
- */
397
- async executeNode(frame, plan, planNode, opts, emitFn) {
398
- this.assertNotAborted(opts);
399
- if (!this.isNodeActivated(frame, plan, planNode)) {
400
- await this.skipInactiveNode(frame, plan, planNode, opts);
401
- return;
402
- }
403
- if (planNode.instance.disabled === true) {
404
- await this.executeDisabledNode(frame, plan, planNode, opts);
405
- return;
406
- }
407
- const startedAt = new Date();
408
- const nodePath = [...(opts.path ?? []), planNode.id];
409
- await this.emitEvent(frame, {
410
- type: index_js_2.GraphExecutionEventType.NODE_STARTED,
411
- runId: frame.runId,
412
- workflowId: plan.workflowId,
413
- nodeId: planNode.id,
414
- path: nodePath,
415
- status: index_js_2.GraphExecutionStatus.RUNNING,
416
- });
417
- this.emitNodeStateChanged(frame, plan, planNode, nodePath, index_js_2.GraphVisualState.RUNNING, index_js_2.GraphExecutionStatus.RUNNING);
418
- const inputs = await this.resolveNodeInputs(frame, plan, planNode, opts);
419
- // Cache-hit: check for a pinned value before executing the node
420
- if (opts.usePinnedValues) {
421
- const cached = await this.tryPinnedValue(frame, plan, planNode, inputs);
422
- if (cached) {
423
- frame.valueStore.setNodeOutputs(planNode.id, cached.outputs);
424
- this.routeOutgoingEdges(frame, plan, planNode, cached.outputs);
425
- const finishedAt = new Date();
426
- const result = {
427
- nodeId: planNode.id,
428
- status: index_js_2.GraphExecutionStatus.CACHED,
429
- inputs,
430
- outputs: cached.outputs,
431
- startedAt,
432
- finishedAt,
433
- fromCache: true,
434
- pinned: true,
435
- events: [],
436
- };
437
- frame.recordNodeResult(result);
438
- await this.emitEvent(frame, {
439
- type: index_js_2.GraphExecutionEventType.NODE_CACHE_HIT,
440
- runId: frame.runId,
441
- workflowId: plan.workflowId,
442
- nodeId: planNode.id,
443
- path: nodePath,
444
- status: index_js_2.GraphExecutionStatus.CACHED,
445
- payload: { outputs: cached.outputs },
446
- });
447
- await this.emitEvent(frame, {
448
- type: index_js_2.GraphExecutionEventType.NODE_COMPLETED,
449
- runId: frame.runId,
450
- workflowId: plan.workflowId,
451
- nodeId: planNode.id,
452
- path: nodePath,
453
- status: index_js_2.GraphExecutionStatus.SUCCEEDED,
454
- payload: { outputs: cached.outputs, fromCache: true },
455
- });
456
- this.emitNodeStateChanged(frame, plan, planNode, nodePath, index_js_2.GraphVisualState.SUCCEEDED, index_js_2.GraphExecutionStatus.SUCCEEDED);
457
- return;
458
- }
459
- }
460
- try {
461
- const context = new GraphExecutionContext_js_1.GraphExecutionContext(frame.runId, opts.parentRunId, plan.workflowId, plan.resolved.document, planNode.instance, planNode.manifest, nodePath, emitFn, opts.metadata, this, opts.abortSignal, this.executionLimits(opts));
462
- const parameters = await this.resolveNodeParameters(planNode, inputs, opts);
463
- const request = {
464
- nodeId: planNode.id,
465
- kind: planNode.kind,
466
- inputs,
467
- parameters,
468
- credentials: this.collectCredentials(planNode),
469
- metadata: planNode.instance.metadata,
470
- };
471
- const rawOutputs = await this.invokeExecutor(planNode, request, context);
472
- const outputs = this.validateNodeOutputs(planNode, rawOutputs ?? {});
473
- frame.valueStore.setNodeOutputs(planNode.id, outputs);
474
- this.routeOutgoingEdges(frame, plan, planNode, outputs);
475
- const finishedAt = new Date();
476
- const result = {
477
- nodeId: planNode.id,
478
- status: index_js_2.GraphExecutionStatus.SUCCEEDED,
479
- inputs,
480
- outputs,
481
- startedAt,
482
- finishedAt,
483
- events: [],
484
- };
485
- frame.recordNodeResult(result);
486
- await this.emitEvent(frame, {
487
- type: index_js_2.GraphExecutionEventType.NODE_COMPLETED,
488
- runId: frame.runId,
489
- workflowId: plan.workflowId,
490
- nodeId: planNode.id,
491
- path: nodePath,
492
- status: index_js_2.GraphExecutionStatus.SUCCEEDED,
493
- payload: { outputs },
494
- });
495
- this.emitNodeStateChanged(frame, plan, planNode, nodePath, index_js_2.GraphVisualState.SUCCEEDED, index_js_2.GraphExecutionStatus.SUCCEEDED);
496
- }
497
- catch (error) {
498
- // Loop-control flow is not a node failure: rethrow the break token so
499
- // the enclosing loop executor observes it rather than a FAILED node.
500
- if (error instanceof index_js_3.GraphBreakSignal)
501
- throw error;
502
- const finishedAt = new Date();
503
- const errorPayload = this.toErrorPayload(error);
504
- const result = {
505
- nodeId: planNode.id,
506
- status: index_js_2.GraphExecutionStatus.FAILED,
507
- inputs,
508
- error: errorPayload,
509
- startedAt,
510
- finishedAt,
511
- events: [],
512
- };
513
- frame.recordNodeResult(result);
514
- await this.emitEvent(frame, {
515
- type: index_js_2.GraphExecutionEventType.NODE_FAILED,
516
- runId: frame.runId,
517
- workflowId: plan.workflowId,
518
- nodeId: planNode.id,
519
- path: nodePath,
520
- status: index_js_2.GraphExecutionStatus.FAILED,
521
- error: errorPayload,
522
- });
523
- this.emitNodeStateChanged(frame, plan, planNode, nodePath, index_js_2.GraphVisualState.FAILED, index_js_2.GraphExecutionStatus.FAILED);
524
- if (opts.failFast ?? true)
525
- throw error;
526
- }
527
- }
528
- /**
529
- * Resolves whether a plan node is activated for execution under the
530
- * DECAF-50 §4.9 branch semantics. A node with no incoming data edges is
531
- * a root/source node and always runs. A node fed by one or more data
532
- * edges runs only when at least one of those edges was activated by a
533
- * routed upstream output port — a branch the upstream switch (or any
534
- * partial-output node) did not select leaves its downstream edges
535
- * unactivated, so the branch is never executed. Workflow-boundary edges
536
- * are active from the start because workflow inputs are seeded before
537
- * execution begins.
538
- */
539
- isNodeActivated(frame, plan, planNode) {
540
- const incoming = (plan.incomingByNode.get(planNode.id) ?? []).filter((edge) => edge.type === "data");
541
- if (incoming.length === 0)
542
- return true;
543
- return incoming.some((edge) => edge.sourceNodeId === constants_js_1.GRAPH_WORKFLOW_BOUNDARY ||
544
- frame.isDataEdgeActive(edge.id));
545
- }
546
- /**
547
- * Skips a node whose incoming data edges were all left unactivated by an
548
- * upstream branch selection. The node is not executed and its outputs are
549
- * never routed or collected into workflow outputs (DECAF-50 §4.9).
550
- */
551
- async skipInactiveNode(frame, plan, planNode, opts) {
552
- const startedAt = new Date();
553
- const nodePath = [...(opts.path ?? []), planNode.id];
554
- await this.emitEvent(frame, {
555
- type: index_js_2.GraphExecutionEventType.NODE_SKIPPED,
556
- runId: frame.runId,
557
- workflowId: plan.workflowId,
558
- nodeId: planNode.id,
559
- path: nodePath,
560
- status: index_js_2.GraphExecutionStatus.SKIPPED,
561
- payload: { reason: "branchNotSelected" },
562
- });
563
- const result = {
564
- nodeId: planNode.id,
565
- status: index_js_2.GraphExecutionStatus.SKIPPED,
566
- inputs: {},
567
- startedAt,
568
- finishedAt: new Date(),
569
- events: [],
570
- };
571
- frame.recordNodeResult(result);
572
- this.emitNodeStateChanged(frame, plan, planNode, nodePath, index_js_2.GraphVisualState.SKIPPED, index_js_2.GraphExecutionStatus.SKIPPED);
573
- }
574
- /**
575
- * Applies the explicit disabled-node semantics (§4.9):
576
- * `skip`, `passThroughFirstInput`, or `emitDefaults`, resolved from the
577
- * instance metadata, document settings, and the default.
578
- */
579
- async executeDisabledNode(frame, plan, planNode, opts) {
580
- const startedAt = new Date();
581
- const nodePath = [...(opts.path ?? []), planNode.id];
582
- const behavior = GraphParameterValidator_js_1.GraphParameterValidator.disabledBehaviorOf(planNode.instance, plan.resolved.document.settings);
583
- await this.emitEvent(frame, {
584
- type: index_js_2.GraphExecutionEventType.NODE_SKIPPED,
585
- runId: frame.runId,
586
- workflowId: plan.workflowId,
587
- nodeId: planNode.id,
588
- path: nodePath,
589
- status: index_js_2.GraphExecutionStatus.SKIPPED,
590
- payload: { disabled: true, behavior },
591
- });
592
- if (behavior === "skip") {
593
- const result = {
594
- nodeId: planNode.id,
595
- status: index_js_2.GraphExecutionStatus.SKIPPED,
596
- inputs: {},
597
- startedAt,
598
- finishedAt: new Date(),
599
- events: [],
600
- };
601
- frame.recordNodeResult(result);
602
- this.emitNodeStateChanged(frame, plan, planNode, nodePath, index_js_2.GraphVisualState.SKIPPED, index_js_2.GraphExecutionStatus.SKIPPED);
603
- return;
604
- }
605
- const inputs = await this.resolveNodeInputs(frame, plan, planNode, opts);
606
- let outputs;
607
- if (behavior === "passThroughFirstInput") {
608
- const firstIncoming = (plan.incomingByNode.get(planNode.id) ?? []).find((edge) => edge.type === "data");
609
- const firstOutput = planNode.manifest.outputs[0]?.id ?? "value";
610
- const value = firstIncoming
611
- ? frame.valueStore.getPort(firstIncoming.sourceNodeId, firstIncoming.sourcePort)
612
- : Object.values(inputs)[0];
613
- outputs = { [firstOutput]: value };
614
- }
615
- else {
616
- // emitDefaults — every declared output port is emitted with its
617
- // declared default (absent a declared default, undefined).
618
- outputs = {};
619
- for (const port of planNode.manifest.outputs) {
620
- outputs[port.id] = port.metadata?.["defaultValue"];
621
- }
622
- }
623
- frame.valueStore.setNodeOutputs(planNode.id, outputs);
624
- this.routeOutgoingEdges(frame, plan, planNode, outputs);
625
- const result = {
626
- nodeId: planNode.id,
627
- status: index_js_2.GraphExecutionStatus.SUCCEEDED,
628
- inputs,
629
- outputs,
630
- startedAt,
631
- finishedAt: new Date(),
632
- events: [],
633
- };
634
- frame.recordNodeResult(result);
635
- this.emitNodeStateChanged(frame, plan, planNode, nodePath, index_js_2.GraphVisualState.SUCCEEDED, index_js_2.GraphExecutionStatus.SUCCEEDED);
636
- }
637
- /**
638
- * Invokes the node's catalogue-resolved executor (§4.9 request contract,
639
- * post-cutover: every executor receives the full request with
640
- * configuration and input data separated).
641
- */
642
- async invokeExecutor(planNode, request, context) {
643
- return await planNode.executor.execute(request, context);
644
- }
645
- /**
646
- * Validates executor outputs against the effective output manifest
647
- * (§4.9): unknown outputs are rejected by default; missing required
648
- * outputs fail the node. Lenient transition manifests (legacy
649
- * executor-only registrations) are exempt until cutover.
650
- */
651
- validateNodeOutputs(planNode, outputs) {
652
- const manifest = planNode.manifest;
653
- if (manifest.policies?.allowUnknownOutputs === true) {
654
- return outputs;
655
- }
656
- const declaredOutputs = new Set(manifest.outputs.map((port) => port.id));
657
- const unknownOutputs = Object.keys(outputs).filter((key) => !declaredOutputs.has(key));
658
- if (unknownOutputs.length > 0) {
659
- throw new index_js_3.GraphExecutionError(`Node '${planNode.id}' of kind '${planNode.kind}' produced unknown output(s): ${unknownOutputs.join(", ")}`, "GRAPH_OUTPUT_VALIDATION_FAILED", { nodeId: planNode.id, unknownOutputs });
660
- }
661
- const missingRequired = manifest.outputs
662
- .filter((port) => port.required === true && !(port.id in outputs))
663
- .map((port) => port.id);
664
- if (missingRequired.length > 0) {
665
- throw new index_js_3.GraphExecutionError(`Node '${planNode.id}' of kind '${planNode.kind}' did not produce required output(s): ${missingRequired.join(", ")}`, "GRAPH_OUTPUT_VALIDATION_FAILED", { nodeId: planNode.id, missingRequired });
666
- }
667
- return outputs;
668
- }
669
- /**
670
- * Collects the resolved credential references for a node: credential-type
671
- * parameter values plus the `credentials` record in instance metadata.
672
- * Documents carry references only — secret material never enters requests.
673
- */
674
- collectCredentials(planNode) {
675
- const credentials = {};
676
- for (const parameter of planNode.manifest.parameters) {
677
- if (parameter.type !== "credential")
678
- continue;
679
- const value = (planNode.instance.parameters ?? {})[parameter.id];
680
- if (typeof value === "string" && value.length > 0) {
681
- credentials[parameter.id] = {
682
- credentialId: value,
683
- credentialType: parameter.credentialType ?? "",
684
- };
685
- }
686
- else if ((0, GraphParameterValidator_js_1.isGraphCredentialReferenceLike)(value)) {
687
- credentials[parameter.id] = {
688
- credentialId: value.credentialId,
689
- credentialType: value.credentialType,
690
- };
691
- }
692
- }
693
- const extra = (planNode.instance.metadata ?? {})["credentials"];
694
- if (extra && typeof extra === "object" && !Array.isArray(extra)) {
695
- for (const [key, raw] of Object.entries(extra)) {
696
- const value = raw;
697
- if (typeof value === "string" && value.length > 0) {
698
- credentials[key] = { credentialId: value, credentialType: "" };
699
- }
700
- else if ((0, GraphParameterValidator_js_1.isGraphCredentialReferenceLike)(value)) {
701
- credentials[key] = {
702
- credentialId: value.credentialId,
703
- credentialType: value.credentialType,
704
- };
705
- }
706
- }
707
- }
708
- return credentials;
709
- }
710
- /**
711
- * Resolves a node's input values from routed data edges, literal bindings,
712
- * allowed expression bindings, and manifest port defaults (§4.9).
713
- *
714
- * When multiple edges target the same port, their values are spread into the
715
- * top-level inputs keyed by each edge's `sourcePort`. This allows multiple
716
- * workflow input badges to connect to a single port (e.g. the Code node's
717
- * `data` port) and have all values accessible directly as
718
- * `$input.{sourcePort}` (e.g. `$input.count`, `$input.text`).
719
- */
720
- async resolveNodeInputs(frame, plan, planNode, opts) {
721
- const inputs = {};
722
- const incoming = (plan.incomingByNode.get(planNode.id) ?? []).filter((edge) => edge.type === "data");
723
- const edgesByTarget = new Map();
724
- for (const edge of incoming) {
725
- const list = edgesByTarget.get(edge.targetPort) ?? [];
726
- list.push(edge);
727
- edgesByTarget.set(edge.targetPort, list);
728
- }
729
- for (const [targetPort, edges] of edgesByTarget) {
730
- if (edges.length === 1) {
731
- inputs[targetPort] = frame.valueStore.getPort(edges[0].sourceNodeId, edges[0].sourcePort);
732
- }
733
- else {
734
- let definedValue;
735
- let hasDefined = false;
736
- for (const edge of edges) {
737
- const value = frame.valueStore.getPort(edge.sourceNodeId, edge.sourcePort);
738
- inputs[edge.sourcePort] = value;
739
- if (value !== undefined) {
740
- definedValue = value;
741
- hasDefined = true;
742
- }
743
- }
744
- // Branch merges route several mutually-exclusive outputs onto the same
745
- // target port (e.g. an if/switch branch). The port-keyed map above
746
- // preserves distinct source ports, but the target port must also receive
747
- // the single defined branch value so the node reads its own port.
748
- if (hasDefined && inputs[targetPort] === undefined) {
749
- inputs[targetPort] = definedValue;
750
- }
751
- }
752
- }
753
- // Literal bindings, expression bindings, and manifest defaults.
754
- const bindings = planNode.instance.inputBindings ?? {};
755
- for (const port of planNode.manifest.inputs) {
756
- const binding = bindings[port.id];
757
- if (binding?.mode === "literal") {
758
- inputs[port.id] = binding.value;
759
- }
760
- else if (binding?.mode === "expression") {
761
- inputs[port.id] = await this.evaluateExpressionBinding(planNode, binding.expression, inputs, opts);
762
- }
763
- else if (inputs[port.id] === undefined) {
764
- const defaultValue = port.metadata?.["defaultValue"];
765
- if (defaultValue !== undefined) {
766
- inputs[port.id] = defaultValue;
767
- }
768
- }
769
- }
770
- return inputs;
771
- }
772
- /**
773
- * Resolves a node's persisted parameters at execution time, evaluating any
774
- * `GraphValueTemplate` user property through the code-evaluator VM and
775
- * leaving straight literal values unchanged.
776
- */
777
- async resolveNodeParameters(planNode, inputs, opts) {
778
- const parameters = planNode.instance.parameters ?? {};
779
- const resolved = {};
780
- for (const [key, value] of Object.entries(parameters)) {
781
- resolved[key] = (0, index_js_1.isGraphValueTemplate)(value)
782
- ? await this.evaluateValueTemplate(value, planNode, inputs, opts)
783
- : value;
784
- }
785
- return resolved;
786
- }
787
- /**
788
- * Evaluates a persisted `GraphValueTemplate` with the pluggable
789
- * {@link CodeSandboxEvaluator} (DECAF-32 §22.4) — no new evaluator.
790
- * `expression` mode evaluates the body directly; `template` mode compiles its
791
- * `{{ ... }}` placeholders into a JavaScript template literal evaluated in
792
- * the same sandbox, so both modes share the code-evaluator VM.
793
- */
794
- async evaluateValueTemplate(template, planNode, inputs, opts) {
795
- const evaluator = this.codeSandboxEvaluator;
796
- if (!evaluator) {
797
- throw new index_js_3.GraphExecutionError(`Value template on node '${planNode.id}' requires a CodeSandboxEvaluator to be registered in GraphExecutionEngineConfig.codeSandboxEvaluator`, "GRAPH_CODE_SANDBOX_NOT_CONFIGURED", { nodeId: planNode.id });
798
- }
799
- const language = template.language ?? (0, index_js_1.graphValueTemplateDefaultLanguage)(template.mode);
800
- const code = template.mode === "template"
801
- ? graphTemplateToExpression(template.expression)
802
- : template.expression;
803
- const md = opts.metadata;
804
- const result = await evaluator.evaluate({
805
- code,
806
- language: language === "typescript" ? "typescript" : "javascript",
807
- input: inputs,
808
- vars: md?.vars ?? undefined,
809
- item: md?.item,
810
- index: md?.index,
811
- abortSignal: opts.abortSignal,
812
- });
813
- return result;
814
- }
815
- /**
816
- * Evaluates an expression binding with the EXISTING allowed-expression
817
- * machinery only (the pluggable {@link CodeSandboxEvaluator}, DECAF-32
818
- * §22.4) — no new evaluator. The expression sees the already-routed input
819
- * values as `$input` and the run metadata as context.
820
- */
821
- async evaluateExpressionBinding(planNode, expression, inputs, opts) {
822
- const evaluator = this.codeSandboxEvaluator;
823
- if (!evaluator) {
824
- throw new index_js_3.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 });
825
- }
826
- const md = opts.metadata;
827
- return await evaluator.evaluate({
828
- code: expression,
829
- language: "javascript",
830
- input: inputs,
831
- vars: md?.vars ?? undefined,
832
- item: md?.item,
833
- index: md?.index,
834
- abortSignal: opts.abortSignal,
835
- });
836
- }
837
- /**
838
- * Attempts to read a pinned value for the node. Returns the cached outputs
839
- * when a valid pinned value exists, or `undefined` to proceed with normal
840
- * execution.
841
- */
842
- async tryPinnedValue(frame, plan, planNode, inputs) {
843
- const policy = new GraphPinningPolicy_js_1.GraphPinningPolicy();
844
- if (!policy.shouldUsePinnedValue(planNode))
845
- return undefined;
846
- const service = this.createPinningService();
847
- const depFingerprints = this.computeDependencyFingerprints(frame, plan, planNode.id);
848
- return service.readPinnedValue(plan.workflowId, planNode, inputs, depFingerprints);
849
- }
850
- /**
851
- * Recursively computes fingerprints for all upstream dependencies of a node
852
- * using the results already accumulated in the frame.
853
- */
854
- computeDependencyFingerprints(frame, plan, nodeId) {
855
- const service = this.createPinningService();
856
- const depResolver = new GraphPinningDependencyResolver_js_1.GraphPinningDependencyResolver();
857
- const deps = depResolver.getDependencies(plan, nodeId);
858
- const fingerprints = {};
859
- for (const dep of deps) {
860
- const node = plan.nodes.find((n) => n.id === dep);
861
- if (node) {
862
- const depResult = frame.nodeResults.get(dep);
863
- const inputs = depResult?.inputs ?? {};
864
- const nestedDeps = this.computeDependencyFingerprints(frame, plan, dep);
865
- fingerprints[dep] = service.computeFingerprint(plan.workflowId, node, inputs, nestedDeps);
866
- }
867
- }
868
- return fingerprints;
869
- }
870
- /**
871
- * Routes a node's outputs to downstream inputs and workflow outputs along
872
- * data edges (connection edges are structural and never route values).
873
- *
874
- * An edge is traversed only when the source node actually emitted the
875
- * edge's `sourcePort` (DECAF-50 §4.9 branch semantics). A node that
876
- * emitted a subset of its declared outputs — e.g. a switch that selected
877
- * one case — therefore activates only the downstream branch edges of the
878
- * emitted ports; unselected branch edges are left unactivated, so their
879
- * downstream nodes are skipped and never contribute to workflow outputs.
880
- * Emitting an output port explicitly with `undefined` still counts as
881
- * activated (the port was produced by the executor).
882
- */
883
- routeOutgoingEdges(frame, plan, planNode, outputs) {
884
- const outgoing = (plan.outgoingByNode.get(planNode.id) ?? []).filter((edge) => edge.type === "data");
885
- for (const edge of outgoing) {
886
- if (!Object.prototype.hasOwnProperty.call(outputs, edge.sourcePort)) {
887
- // The source node did not emit this output port: the edge's branch
888
- // was not selected, so no value is routed.
889
- continue;
890
- }
891
- const value = outputs[edge.sourcePort];
892
- frame.activateDataEdge(edge.id);
893
- if (edge.targetNodeId === constants_js_1.GRAPH_WORKFLOW_BOUNDARY) {
894
- frame.valueStore.setWorkflowOutput(edge.targetPort, value);
895
- }
896
- this.emitEdgeStateChanged(frame, plan, planNode, edge, index_js_2.GraphVisualState.SUCCEEDED, index_js_2.GraphExecutionStatus.SUCCEEDED);
897
- this.emitEvent(frame, {
898
- type: index_js_2.GraphExecutionEventType.EDGE_VALUE_ROUTED,
899
- runId: frame.runId,
900
- workflowId: plan.workflowId,
901
- edgeId: edge.id,
902
- nodeId: planNode.id,
903
- path: [],
904
- payload: { edge, value },
905
- }).catch(() => {
906
- // observer failures must not crash
907
- });
908
- }
909
- }
910
- /**
911
- * Emits an event, records it in the frame, and dispatches to observers.
912
- */
913
- async emitEvent(frame, partial) {
914
- const event = frame.eventFactory.create({
915
- id: "",
916
- sequence: 0,
917
- timestamp: new Date(),
918
- ...partial,
919
- });
920
- frame.appendEvent(event);
921
- await this.emitter.updateObservers(event);
922
- }
923
- /**
924
- * Emits a `NODE_STATE_CHANGED` event (DECAF-48 §4.4) carrying the given
925
- * visual state for the node. Rides the existing Observable pipeline; no
926
- * second out-of-band channel.
927
- */
928
- emitNodeStateChanged(frame, plan, planNode, nodePath, state, status) {
929
- this.emitEvent(frame, {
930
- type: index_js_2.GraphExecutionEventType.NODE_STATE_CHANGED,
931
- runId: frame.runId,
932
- workflowId: plan.workflowId,
933
- nodeId: planNode.id,
934
- path: nodePath,
935
- status,
936
- payload: {
937
- nodeId: planNode.id,
938
- state,
939
- runId: frame.runId,
940
- workflowId: plan.workflowId,
941
- status,
942
- },
943
- }).catch(() => {
944
- // observer failures must not crash execution
945
- });
946
- }
947
- /**
948
- * Emits an `EDGE_STATE_CHANGED` event (DECAF-48 §4.4) carrying the given
949
- * visual state for a routed edge.
950
- */
951
- emitEdgeStateChanged(frame, plan, planNode, edge, state, status) {
952
- this.emitEvent(frame, {
953
- type: index_js_2.GraphExecutionEventType.EDGE_STATE_CHANGED,
954
- runId: frame.runId,
955
- workflowId: plan.workflowId,
956
- edgeId: edge.id,
957
- nodeId: planNode.id,
958
- path: [],
959
- status,
960
- payload: {
961
- edgeId: edge.id,
962
- state,
963
- runId: frame.runId,
964
- workflowId: plan.workflowId,
965
- nodeId: planNode.id,
966
- status,
967
- },
968
- }).catch(() => {
969
- // observer failures must not crash execution
970
- });
971
- }
972
517
  /**
973
518
  * Merges default options with the given options.
974
519
  */
@@ -988,20 +533,9 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
988
533
  ...options,
989
534
  };
990
535
  }
991
- /**
992
- * Resolves the effective loop-iteration ceilings for a run. A node-level
993
- * `maxIterations` can never exceed these; loop executors read them from the
994
- * node context.
995
- */
996
- executionLimits(opts) {
997
- return {
998
- maxLoopIterations: opts.maxLoopIterations ?? constants_js_1.GRAPH_MAX_LOOP_ITERATIONS,
999
- maxForeachIterations: opts.maxForeachIterations ?? constants_js_1.GRAPH_MAX_FOREACH_ITERATIONS,
1000
- };
1001
- }
1002
536
  assertNotAborted(opts) {
1003
537
  if (opts.abortSignal?.aborted === true) {
1004
- throw new index_js_3.GraphRunCancelledError(opts.runId ?? "unknown");
538
+ throw new index_js_2.GraphRunCancelledError(opts.runId ?? "unknown");
1005
539
  }
1006
540
  }
1007
541
  /**
@@ -1015,27 +549,10 @@ class GraphExecutionEngine extends core_1.ClientBasedService {
1015
549
  generateRunId() {
1016
550
  const cryptoApi = globalThis.crypto;
1017
551
  if (!cryptoApi || typeof cryptoApi.randomUUID !== "function") {
1018
- throw new index_js_3.GraphExecutionError("Cannot generate a graph run id: crypto.randomUUID is unavailable in this runtime", "GRAPH_RUN_ID_ERROR", { runtime: typeof globalThis.crypto });
552
+ throw new index_js_2.GraphExecutionError("Cannot generate a graph run id: crypto.randomUUID is unavailable in this runtime", "GRAPH_RUN_ID_ERROR", { runtime: typeof globalThis.crypto });
1019
553
  }
1020
554
  return cryptoApi.randomUUID();
1021
555
  }
1022
- /**
1023
- * Converts an error into a serialized payload.
1024
- */
1025
- toErrorPayload(error) {
1026
- if (error instanceof Error) {
1027
- return {
1028
- name: error.name,
1029
- message: error.message,
1030
- stack: error.stack,
1031
- code: error.graphCode ??
1032
- (typeof error.code === "number"
1033
- ? String(error.code)
1034
- : error.code),
1035
- };
1036
- }
1037
- return { name: "UnknownError", message: String(error) };
1038
- }
1039
556
  }
1040
557
  exports.GraphExecutionEngine = GraphExecutionEngine;
1041
558
  //# sourceMappingURL=GraphExecutionEngine.js.map