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