@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
@@ -0,0 +1,781 @@
1
+ import { GraphExecutionError } from "./../engine/errors/index.js";
2
+ import { GraphExecutionBackendRegistry } from "./../engine/execution/GraphExecutionBackendRegistry.js";
3
+ import { DAGSTER_BACKEND_FLAVOUR, DAGSTER_DEFAULT_NODE_KIND, DAGSTER_ERROR, DAGSTER_TAG_NAMESPACE, } from "./constants.js";
4
+ import { dagsterBackendCapabilities } from "./capabilities.js";
5
+ import { DagsterGraphEventBridge } from "./DagsterGraphEventBridge.js";
6
+ import { DagsterResultMapper } from "./DagsterResultMapper.js";
7
+ /**
8
+ * Default maximum time (ms) `execute`/`replayRun` await a launched/re-executed run
9
+ * to reach a terminal state before failing the operation closed. Matches the event
10
+ * bridge's default terminal timeout.
11
+ */
12
+ const DEFAULT_EXECUTION_TERMINAL_TIMEOUT_MS = 5 * 60 * 1000;
13
+ /**
14
+ * Default interval (ms) between `getRun` polls while awaiting a launched run's
15
+ * terminal state. The driver waits through the read-only `getRun` surface and then
16
+ * observes the completed run through the event bridge.
17
+ */
18
+ const DEFAULT_EXECUTION_POLL_INTERVAL_MS = 500;
19
+ /**
20
+ * The Dagster run statuses that are terminal. Only these end the terminal wait;
21
+ * every other status (including the real pending `QUEUED`/`STARTING`) is polled
22
+ * toward terminal, caller abort, or timeout (C5 fail-closed).
23
+ */
24
+ const DAGSTER_TERMINAL_RUN_STATUSES = new Set([
25
+ "success",
26
+ "failure",
27
+ "canceled",
28
+ ]);
29
+ /**
30
+ * Maximum accepted nesting depth of the allowlisted raw run config. Bounds the shape
31
+ * check so a deeply nested object cannot be forwarded as a transport bomb.
32
+ */
33
+ const DAGSTER_RUN_CONFIG_MAX_DEPTH = 16;
34
+ /**
35
+ * Resolves the canonical node id of an inspected op. The deployment's own node id
36
+ * is used when exposed; otherwise the op name is the identity.
37
+ *
38
+ * @param op - The inspected Dagster op.
39
+ * @returns The canonical node id.
40
+ */
41
+ function dagsterNodeIdOf(op) {
42
+ return op.nodeId ?? op.name;
43
+ }
44
+ /**
45
+ * Builds the inspected job's op-name → canonical node-id map. The event bridge
46
+ * uses it to resolve Dagster step keys onto canonical node ids for an existing run.
47
+ *
48
+ * @param job - The inspected Dagster job record.
49
+ * @returns The op-name → node-id map.
50
+ */
51
+ export function dagsterNodeIdsByOpName(job) {
52
+ const map = {};
53
+ for (const op of job.ops ?? []) {
54
+ map[op.name] = dagsterNodeIdOf(op);
55
+ }
56
+ return map;
57
+ }
58
+ /**
59
+ * Builds the op-name → canonical node-id map from an already-mapped canonical
60
+ * document. The event bridge uses it to resolve Dagster step keys onto canonical
61
+ * node ids for a run the driver launched from that document, without re-reading
62
+ * the job.
63
+ *
64
+ * @param document - The canonical document of the launched job.
65
+ * @returns The op-name → node-id map.
66
+ */
67
+ export function dagsterNodeIdsByOpNameFromDocument(document) {
68
+ const map = {};
69
+ for (const node of document.nodes ?? []) {
70
+ const opName = node.metadata?.["dagsterOpName"];
71
+ if (typeof opName === "string")
72
+ map[opName] = node.id;
73
+ }
74
+ return map;
75
+ }
76
+ /**
77
+ * Resolves the canonical workflow id a document describes from the document's own
78
+ * identity — never from its metadata. The document id wins; the document name is the
79
+ * fallback. Untrusted metadata can never steer which deployed job is selected (C2).
80
+ *
81
+ * @param document - The canonical workflow document.
82
+ * @returns The canonical workflow id.
83
+ */
84
+ function dagsterCanonicalWorkflowIdOf(document) {
85
+ return document.id || document.name || "";
86
+ }
87
+ /**
88
+ * Deep-clones a caller-supplied raw Dagster run config through a JSON-safe
89
+ * allowlist: only finite numbers, strings, booleans, `null`, arrays, and plain
90
+ * objects survive. Functions, symbols, `undefined`, class instances, dates, maps,
91
+ * and cyclic/over-deep structures are rejected with
92
+ * `GRAPH_DAGSTER_RUN_CONFIG_INVALID` (C4).
93
+ *
94
+ * @param value - The raw run config value to allowlist.
95
+ * @param depth - The current nesting depth.
96
+ * @returns The allowlisted clone.
97
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_RUN_CONFIG_INVALID` when the value
98
+ * is not JSON-safe.
99
+ */
100
+ function dagsterAllowlistedRunConfig(value, depth) {
101
+ if (depth > DAGSTER_RUN_CONFIG_MAX_DEPTH) {
102
+ throw new GraphExecutionError(`Dagster run config exceeds the maximum nesting depth of ${DAGSTER_RUN_CONFIG_MAX_DEPTH}`, DAGSTER_ERROR.RUN_CONFIG_INVALID);
103
+ }
104
+ const result = {};
105
+ for (const [key, entry] of Object.entries(value)) {
106
+ result[key] = dagsterAllowlistedRunConfigValue(entry, depth + 1);
107
+ }
108
+ return result;
109
+ }
110
+ /**
111
+ * Allowlists a single raw run config value, recursively. See
112
+ * {@link dagsterAllowlistedRunConfig}.
113
+ *
114
+ * @param value - The value to allowlist.
115
+ * @param depth - The current nesting depth.
116
+ * @returns The allowlisted clone.
117
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_RUN_CONFIG_INVALID` when the value
118
+ * is not JSON-safe.
119
+ */
120
+ function dagsterAllowlistedRunConfigValue(value, depth) {
121
+ if (depth > DAGSTER_RUN_CONFIG_MAX_DEPTH) {
122
+ throw new GraphExecutionError(`Dagster run config exceeds the maximum nesting depth of ${DAGSTER_RUN_CONFIG_MAX_DEPTH}`, DAGSTER_ERROR.RUN_CONFIG_INVALID);
123
+ }
124
+ if (value === null || typeof value === "string" || typeof value === "boolean") {
125
+ return value;
126
+ }
127
+ if (typeof value === "number") {
128
+ if (!Number.isFinite(value)) {
129
+ throw new GraphExecutionError("Dagster run config contains a non-finite number", DAGSTER_ERROR.RUN_CONFIG_INVALID);
130
+ }
131
+ return value;
132
+ }
133
+ if (Array.isArray(value)) {
134
+ return value.map((entry) => dagsterAllowlistedRunConfigValue(entry, depth + 1));
135
+ }
136
+ if (typeof value === "object") {
137
+ const prototype = Object.getPrototypeOf(value);
138
+ if (prototype !== Object.prototype && prototype !== null) {
139
+ throw new GraphExecutionError("Dagster run config contains a non-plain object", DAGSTER_ERROR.RUN_CONFIG_INVALID);
140
+ }
141
+ return dagsterAllowlistedRunConfig(value, depth);
142
+ }
143
+ throw new GraphExecutionError("Dagster run config contains a non-JSON-safe value", DAGSTER_ERROR.RUN_CONFIG_INVALID);
144
+ }
145
+ /**
146
+ * Maps one inspected Dagster op onto a canonical node instance. Port names and
147
+ * asset keys travel as node metadata; no op body or Python source is carried.
148
+ *
149
+ * @param op - The inspected Dagster op.
150
+ * @returns The canonical node instance.
151
+ */
152
+ function dagsterNodeOf(op) {
153
+ const metadata = { dagsterOpName: op.name };
154
+ if (op.inputs)
155
+ metadata["inputPorts"] = [...op.inputs];
156
+ if (op.outputs)
157
+ metadata["outputPorts"] = [...op.outputs];
158
+ if (op.assetKeys)
159
+ metadata["assetKeys"] = [...op.assetKeys];
160
+ return {
161
+ id: dagsterNodeIdOf(op),
162
+ kind: op.kind ?? DAGSTER_DEFAULT_NODE_KIND,
163
+ label: op.name,
164
+ parameters: {},
165
+ metadata: metadata,
166
+ };
167
+ }
168
+ /**
169
+ * Maps the inspected job's op dependencies onto canonical edges. Each dependency
170
+ * connects the upstream op's first declared output to the downstream op's first
171
+ * declared input, falling back to stable default port names.
172
+ *
173
+ * @param job - The inspected Dagster job record.
174
+ * @returns The canonical edge instances.
175
+ */
176
+ function dagsterEdgesOf(job) {
177
+ const byName = new Map();
178
+ for (const op of job.ops ?? [])
179
+ byName.set(op.name, op);
180
+ const edges = [];
181
+ (job.dependencies ?? []).forEach((dependency, index) => {
182
+ const from = byName.get(dependency.from);
183
+ const to = byName.get(dependency.to);
184
+ if (!from || !to)
185
+ return;
186
+ edges.push({
187
+ id: `dagster_dep_${index}`,
188
+ type: "data",
189
+ source: {
190
+ scope: "node",
191
+ nodeId: dagsterNodeIdOf(from),
192
+ port: from.outputs?.[0] ?? "result",
193
+ },
194
+ target: {
195
+ scope: "node",
196
+ nodeId: dagsterNodeIdOf(to),
197
+ port: to.inputs?.[0] ?? "value",
198
+ },
199
+ });
200
+ });
201
+ return edges;
202
+ }
203
+ /**
204
+ * Maps an inspected Dagster job record onto the canonical workflow document
205
+ * shape. The deployment structure (job name, ops, dependencies, asset keys,
206
+ * schedules/sensors) is carried as document metadata for read-only inspection;
207
+ * nothing is authored.
208
+ *
209
+ * @param job - The inspected Dagster job record.
210
+ * @returns The canonical workflow document.
211
+ */
212
+ export function dagsterJobDocument(job) {
213
+ const metadata = { dagsterJobName: job.name };
214
+ if (job.description !== undefined) {
215
+ metadata["description"] = job.description;
216
+ }
217
+ if (job.assetKeys !== undefined) {
218
+ metadata["assetKeys"] = [...job.assetKeys];
219
+ }
220
+ if (job.schedules !== undefined) {
221
+ metadata["schedules"] = job.schedules.map((schedule) => ({
222
+ name: schedule.name,
223
+ ...(schedule.cron !== undefined ? { cron: schedule.cron } : {}),
224
+ ...(schedule.timezone !== undefined
225
+ ? { timezone: schedule.timezone }
226
+ : {}),
227
+ }));
228
+ }
229
+ if (job.sensors !== undefined) {
230
+ metadata["sensors"] = job.sensors.map((sensor) => ({
231
+ name: sensor.name,
232
+ ...(sensor.kind !== undefined ? { kind: sensor.kind } : {}),
233
+ }));
234
+ }
235
+ return {
236
+ id: job.name,
237
+ name: job.name,
238
+ inputs: [],
239
+ outputs: [],
240
+ nodes: (job.ops ?? []).map(dagsterNodeOf),
241
+ edges: dagsterEdgesOf(job),
242
+ metadata: metadata,
243
+ };
244
+ }
245
+ /**
246
+ * Non-local Dagster backend. Read-only by default; launches/replays EXISTING
247
+ * workflows only behind the explicit `executionEnabled` gate. Registers itself
248
+ * under {@link DAGSTER_BACKEND_FLAVOUR} on construction.
249
+ */
250
+ export class DagsterGraphExecutionBackend {
251
+ constructor() {
252
+ /** This backend reads a remote Dagster deployment, not an in-process engine. */
253
+ this.local = false;
254
+ /**
255
+ * Dagster never authors code-mode surfaces; the facade rejects them before
256
+ * delegating.
257
+ */
258
+ this.codeMode = "unsupported";
259
+ this.mapper = new DagsterResultMapper();
260
+ this.bridges = new Map();
261
+ this.defaultTags = {};
262
+ this.executionEnabled = false;
263
+ GraphExecutionBackendRegistry.register(DAGSTER_BACKEND_FLAVOUR, this);
264
+ }
265
+ /**
266
+ * Resolves the host-injected client port and the explicit execution gate. The
267
+ * backend never reads a code sandbox evaluator.
268
+ *
269
+ * @param config - The backend configuration.
270
+ */
271
+ async initialize(config) {
272
+ this.client = config.client;
273
+ this.defaultTags = config.tags ?? {};
274
+ this.executionEnabled = config.executionEnabled === true;
275
+ this._config = { ...config };
276
+ }
277
+ /**
278
+ * The backend configuration most recently resolved by {@link initialize}. The
279
+ * facade reads this during `GraphExecutionEngine.initialize` and merges its own
280
+ * facade-owned keys over it, so a host that configured the backend directly
281
+ * (including `executionEnabled`) before booting the engine does not lose that
282
+ * wiring.
283
+ */
284
+ get config() {
285
+ return this._config;
286
+ }
287
+ /**
288
+ * Effective capability metadata: code-mode is `unsupported`; workflow
289
+ * listing/lookup is supported exactly when the client port exposes it.
290
+ */
291
+ get capabilities() {
292
+ return dagsterBackendCapabilities(this.client);
293
+ }
294
+ /**
295
+ * Lists the deployment's Dagster jobs through the client port.
296
+ *
297
+ * @returns Real workflow summaries.
298
+ * @throws {GraphExecutionError} when the client port exposes no job listing.
299
+ */
300
+ async listWorkflows() {
301
+ const client = this.requireClient();
302
+ if (typeof client.listJobs !== "function") {
303
+ throw new GraphExecutionError("Dagster client port exposes no job listing; workflow listing is not supported", DAGSTER_ERROR.WORKFLOWS_NOT_SUPPORTED);
304
+ }
305
+ const jobs = await client.listJobs();
306
+ return jobs.map((job) => ({
307
+ id: job.name,
308
+ name: job.name,
309
+ ...(job.updatedAt !== undefined ? { updatedAt: job.updatedAt } : {}),
310
+ }));
311
+ }
312
+ /**
313
+ * Reads a single already-deployed Dagster job through the client port and maps
314
+ * its ACTUAL deployment structure (graph/op structure, asset keys,
315
+ * schedules/sensors) into the canonical document shape.
316
+ *
317
+ * @param workflowId - The canonical workflow id (the Dagster job name).
318
+ * @returns A canonical document describing the existing job.
319
+ * @throws {GraphExecutionError} when the client port exposes no job lookup.
320
+ */
321
+ async getWorkflow(workflowId) {
322
+ const client = this.requireClient();
323
+ if (typeof client.getJob !== "function") {
324
+ throw new GraphExecutionError("Dagster client port exposes no job lookup; workflow lookup is not supported", DAGSTER_ERROR.WORKFLOWS_NOT_SUPPORTED);
325
+ }
326
+ const job = await client.getJob(workflowId);
327
+ return dagsterJobDocument(job);
328
+ }
329
+ /**
330
+ * Reads an EXISTING Dagster run's terminal record through the client port.
331
+ *
332
+ * @param runId - The Dagster run id.
333
+ * @returns The terminal run record.
334
+ */
335
+ async getRun(runId) {
336
+ return await this.requireClient().getRun(runId);
337
+ }
338
+ /**
339
+ * Observes an EXISTING Dagster run: subscribes to its event stream, maps every
340
+ * event onto the canonical sink, and returns the canonical result of the terminal
341
+ * record. The driver never launches the run; the caller supplies the id of a run
342
+ * that already exists in the deployment.
343
+ *
344
+ * The request's bounds (`signal`, `maxEvents`, `maxPages`, `terminalTimeoutMs`)
345
+ * are forwarded to the event bridge so the observation always terminates: the
346
+ * event cap fails closed with `GRAPH_DAGSTER_EVENT_LIMIT_EXCEEDED`, the terminal
347
+ * wait with `GRAPH_DAGSTER_OBSERVE_TIMEOUT`, and an abort with
348
+ * `GRAPH_DAGSTER_OBSERVE_ABORTED`.
349
+ *
350
+ * @param request - The observe request (existing run id, workflow id, sink, and
351
+ * optional observation bounds).
352
+ * @returns The canonical execution result of the observed run.
353
+ * @throws {GraphExecutionError} when the run cannot be read or subscribed to,
354
+ * or when an observation bound is hit (see above).
355
+ */
356
+ async observeRun(request) {
357
+ const client = this.requireClient();
358
+ const job = await client.getJob(request.workflowId);
359
+ const document = dagsterJobDocument(job);
360
+ const graphRunId = request.graphRunId ?? request.dagsterRunId;
361
+ return await this.observeRunEvents({
362
+ dagsterRunId: request.dagsterRunId,
363
+ graphRunId,
364
+ workflowId: request.workflowId,
365
+ document,
366
+ nodeIdsByOpName: dagsterNodeIdsByOpName(job),
367
+ events: request.events,
368
+ ...(request.inputs !== undefined ? { inputs: request.inputs } : {}),
369
+ ...(request.metadata !== undefined ? { metadata: request.metadata } : {}),
370
+ ...(request.signal ? { signal: request.signal } : {}),
371
+ ...(request.maxEvents !== undefined
372
+ ? { maxEvents: request.maxEvents }
373
+ : {}),
374
+ ...(request.maxPages !== undefined ? { maxPages: request.maxPages } : {}),
375
+ ...(request.terminalTimeoutMs !== undefined
376
+ ? { terminalTimeoutMs: request.terminalTimeoutMs }
377
+ : {}),
378
+ });
379
+ }
380
+ /**
381
+ * Executes an ALREADY-DEPLOYED Dagster job: launches a run of the job the
382
+ * supplied document describes through the client port's `launchRun`, then
383
+ * observes it through the existing event bridge to a canonical result.
384
+ *
385
+ * The operation is gated: when `executionEnabled` is off it fails closed with
386
+ * `GRAPH_DAGSTER_EXECUTION_NOT_ENABLED` BEFORE any network call, and when the
387
+ * client port exposes no `launchRun` it fails closed with
388
+ * `GRAPH_DAGSTER_EXECUTION_NOT_SUPPORTED`. The driver never translates a
389
+ * document into Python; it launches a job the deployment already defines.
390
+ *
391
+ * The job is bound from the document's canonical workflow id and confirmed
392
+ * through the read-only `getJob` surface, never from the document's untrusted
393
+ * `metadata.dagsterJobName` (C2): a document whose metadata names a different
394
+ * job is rejected before any launch.
395
+ *
396
+ * @param request - The execution request (document, plan, inputs, options, sink).
397
+ * @returns The canonical execution result of the launched run.
398
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_EXECUTION_NOT_ENABLED` when the
399
+ * gate is off, `GRAPH_DAGSTER_EXECUTION_NOT_SUPPORTED` when the port exposes no
400
+ * launch, `GRAPH_DAGSTER_RUN_WORKFLOW_MISMATCH` when the document metadata
401
+ * names a different job, or `GRAPH_DAGSTER_RUN_LAUNCH_FAILED` when the launch
402
+ * fails.
403
+ */
404
+ async execute(request) {
405
+ this.assertExecutionEnabled();
406
+ const client = this.requireClient();
407
+ if (typeof client.launchRun !== "function") {
408
+ throw new GraphExecutionError("Dagster client port exposes no launchRun; executing an existing workflow is not supported", DAGSTER_ERROR.EXECUTION_NOT_SUPPORTED);
409
+ }
410
+ const document = request.document;
411
+ const workflowId = dagsterCanonicalWorkflowIdOf(document);
412
+ const jobName = await this.resolveCanonicalJobName(client, workflowId, document);
413
+ const graphRunId = request.options.runId ?? `dagster-${workflowId}-${Date.now()}`;
414
+ const runConfig = this.dagsterRunConfigOf(request.options.metadata);
415
+ const launched = await this.launchThroughPort(client, {
416
+ jobName,
417
+ graphRunId,
418
+ workflowId,
419
+ ...(runConfig ? { runConfig } : {}),
420
+ });
421
+ await this.awaitRunTerminal(client, launched.runId, {
422
+ ...(request.options.abortSignal
423
+ ? { signal: request.options.abortSignal }
424
+ : {}),
425
+ });
426
+ return await this.observeRunEvents({
427
+ dagsterRunId: launched.runId,
428
+ graphRunId,
429
+ workflowId,
430
+ document,
431
+ nodeIdsByOpName: dagsterNodeIdsByOpNameFromDocument(document),
432
+ events: request.events,
433
+ inputs: request.inputs,
434
+ ...(request.options.metadata !== undefined
435
+ ? { metadata: request.options.metadata }
436
+ : {}),
437
+ });
438
+ }
439
+ /**
440
+ * Replays (re-executes) an EXISTING Dagster run through the client port's
441
+ * `replayRun`, then observes the new run through the existing event bridge to a
442
+ * canonical result.
443
+ *
444
+ * The operation is gated: when `executionEnabled` is off it fails closed with
445
+ * `GRAPH_DAGSTER_EXECUTION_NOT_ENABLED` BEFORE any network call, and when the
446
+ * client port exposes no `replayRun` it fails closed with
447
+ * `GRAPH_DAGSTER_REPLAY_NOT_SUPPORTED`. The re-execution mechanism (GraphQL
448
+ * re-execution from the run id, or a re-launch of the run's job with its original
449
+ * configuration) is owned by the host transport; the driver only observes the
450
+ * resulting run.
451
+ *
452
+ * The caller-supplied run id is bound to the requested workflow before any
453
+ * re-execution (C1): the run's owning job is resolved through the read-only
454
+ * `getRun` surface and a cross-job replay, or a run whose owning job cannot be
455
+ * determined, is rejected before the re-execution is issued.
456
+ *
457
+ * @param request - The replay request (existing run id, workflow id, sink, bounds).
458
+ * @returns The canonical execution result of the re-executed run.
459
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_EXECUTION_NOT_ENABLED` when the
460
+ * gate is off, `GRAPH_DAGSTER_REPLAY_NOT_SUPPORTED` when the port exposes no
461
+ * replay, `GRAPH_DAGSTER_RUN_WORKFLOW_MISMATCH` when the run does not belong
462
+ * to the requested workflow, or `GRAPH_DAGSTER_RUN_LAUNCH_FAILED` when the
463
+ * re-execution fails.
464
+ */
465
+ async replayRun(request) {
466
+ this.assertExecutionEnabled();
467
+ const client = this.requireClient();
468
+ if (typeof client.replayRun !== "function") {
469
+ throw new GraphExecutionError("Dagster client port exposes no replayRun; replaying an existing run is not supported", DAGSTER_ERROR.REPLAY_NOT_SUPPORTED);
470
+ }
471
+ await this.assertRunOwnedByWorkflow(client, request.dagsterRunId, request.workflowId);
472
+ const job = await client.getJob(request.workflowId);
473
+ const document = dagsterJobDocument(job);
474
+ const graphRunId = request.graphRunId ?? `dagster-replay-${request.dagsterRunId}`;
475
+ const launched = await this.replayThroughPort(client, {
476
+ dagsterRunId: request.dagsterRunId,
477
+ jobName: request.workflowId,
478
+ graphRunId,
479
+ workflowId: request.workflowId,
480
+ });
481
+ await this.awaitRunTerminal(client, launched.runId, {
482
+ ...(request.signal ? { signal: request.signal } : {}),
483
+ ...(request.terminalTimeoutMs !== undefined
484
+ ? { timeoutMs: request.terminalTimeoutMs }
485
+ : {}),
486
+ });
487
+ return await this.observeRunEvents({
488
+ dagsterRunId: launched.runId,
489
+ graphRunId,
490
+ workflowId: request.workflowId,
491
+ document,
492
+ nodeIdsByOpName: dagsterNodeIdsByOpName(job),
493
+ events: request.events,
494
+ ...(request.inputs !== undefined ? { inputs: request.inputs } : {}),
495
+ ...(request.metadata !== undefined ? { metadata: request.metadata } : {}),
496
+ ...(request.signal ? { signal: request.signal } : {}),
497
+ ...(request.maxEvents !== undefined
498
+ ? { maxEvents: request.maxEvents }
499
+ : {}),
500
+ ...(request.maxPages !== undefined ? { maxPages: request.maxPages } : {}),
501
+ ...(request.terminalTimeoutMs !== undefined
502
+ ? { terminalTimeoutMs: request.terminalTimeoutMs }
503
+ : {}),
504
+ });
505
+ }
506
+ /**
507
+ * Terminates an EXISTING run through the client port.
508
+ *
509
+ * @param runId - The Dagster run id.
510
+ * @param reason - Optional cancellation reason.
511
+ * @returns `true` when a run was terminated.
512
+ */
513
+ async cancel(runId, reason) {
514
+ const client = this.client;
515
+ if (!client)
516
+ return false;
517
+ await client.terminateRun(runId, reason);
518
+ return true;
519
+ }
520
+ /**
521
+ * Releases the bridge resources associated with a run.
522
+ *
523
+ * @param runId - The canonical run id.
524
+ */
525
+ async release(runId) {
526
+ const bridge = this.bridges.get(runId);
527
+ if (!bridge)
528
+ return;
529
+ await bridge.stop();
530
+ this.bridges.delete(runId);
531
+ }
532
+ /** Disposes the backend and the host-injected client port. */
533
+ async dispose() {
534
+ for (const bridge of this.bridges.values()) {
535
+ await bridge.stop();
536
+ }
537
+ this.bridges.clear();
538
+ await this.client?.dispose?.();
539
+ }
540
+ /**
541
+ * Subscribes to an EXISTING (or just-launched) run's event stream, maps every
542
+ * event onto the canonical sink, and returns the canonical result of the
543
+ * terminal record. Shared by `observeRun`, `execute`, and `replayRun`.
544
+ *
545
+ * @param input - The run identity, document, op map, sink, and observation bounds.
546
+ * @returns The canonical execution result.
547
+ * @throws {GraphExecutionError} when the run cannot be read or subscribed to, or
548
+ * when an observation bound is hit.
549
+ */
550
+ async observeRunEvents(input) {
551
+ const client = this.requireClient();
552
+ const bridge = new DagsterGraphEventBridge({
553
+ dagsterRunId: input.dagsterRunId,
554
+ graphRunId: input.graphRunId,
555
+ workflowId: input.workflowId,
556
+ nodeIdsByOpName: input.nodeIdsByOpName,
557
+ sink: input.events,
558
+ client,
559
+ ...(input.signal ? { signal: input.signal } : {}),
560
+ ...(input.maxEvents !== undefined ? { maxEvents: input.maxEvents } : {}),
561
+ ...(input.maxPages !== undefined ? { maxPages: input.maxPages } : {}),
562
+ ...(input.terminalTimeoutMs !== undefined
563
+ ? { terminalTimeoutMs: input.terminalTimeoutMs }
564
+ : {}),
565
+ });
566
+ this.bridges.set(input.graphRunId, bridge);
567
+ try {
568
+ await bridge.start();
569
+ const record = await bridge.waitForTerminal();
570
+ return this.mapper.map({
571
+ runId: input.graphRunId,
572
+ document: input.document,
573
+ inputs: input.inputs ?? {},
574
+ options: { runId: input.graphRunId, metadata: input.metadata },
575
+ record,
576
+ nodeResults: bridge.collectedNodeResults(),
577
+ events: [],
578
+ });
579
+ }
580
+ catch (error) {
581
+ if (error instanceof GraphExecutionError)
582
+ throw error;
583
+ throw new GraphExecutionError(error instanceof Error ? error.message : String(error), DAGSTER_ERROR.RUN_FAILED, { runId: input.graphRunId });
584
+ }
585
+ finally {
586
+ await bridge.stop();
587
+ this.bridges.delete(input.graphRunId);
588
+ }
589
+ }
590
+ /**
591
+ * Launches a run through the port, mapping any transport failure onto the
592
+ * driver's machine-readable launch error.
593
+ *
594
+ * @param client - The wired client port.
595
+ * @param input - The job name, canonical run id, workflow id, and run config.
596
+ * @returns The launched run handle.
597
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_RUN_LAUNCH_FAILED`.
598
+ */
599
+ async launchThroughPort(client, input) {
600
+ try {
601
+ return await client.launchRun({
602
+ jobName: input.jobName,
603
+ ...(input.runConfig ? { runConfig: input.runConfig } : {}),
604
+ tags: this.executionTags(input.graphRunId, input.workflowId),
605
+ });
606
+ }
607
+ catch (error) {
608
+ if (error instanceof GraphExecutionError)
609
+ throw error;
610
+ throw new GraphExecutionError(error instanceof Error ? error.message : String(error), DAGSTER_ERROR.RUN_LAUNCH_FAILED, { jobName: input.jobName, runId: input.graphRunId });
611
+ }
612
+ }
613
+ /**
614
+ * Re-executes an existing run through the port, mapping any transport failure
615
+ * onto the driver's machine-readable launch error.
616
+ *
617
+ * @param client - The wired client port.
618
+ * @param input - The existing run id, job name, canonical run id, workflow id.
619
+ * @returns The re-executed run handle.
620
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_RUN_LAUNCH_FAILED`.
621
+ */
622
+ async replayThroughPort(client, input) {
623
+ try {
624
+ return await client.replayRun({
625
+ dagsterRunId: input.dagsterRunId,
626
+ jobName: input.jobName,
627
+ tags: this.executionTags(input.graphRunId, input.workflowId),
628
+ });
629
+ }
630
+ catch (error) {
631
+ if (error instanceof GraphExecutionError)
632
+ throw error;
633
+ throw new GraphExecutionError(error instanceof Error ? error.message : String(error), DAGSTER_ERROR.RUN_LAUNCH_FAILED, { runId: input.graphRunId });
634
+ }
635
+ }
636
+ /**
637
+ * Resolves the canonical deployed job a requested workflow binds to and rejects
638
+ * any document whose untrusted `metadata.dagsterJobName` claims a different job
639
+ * BEFORE any launch (C2). The canonical id comes from the document's own
640
+ * identity and is confirmed through the read-only `getJob` surface, mirroring
641
+ * `replayRun`; an unknown workflow fails closed as a launch failure.
642
+ *
643
+ * @param client - The wired client port.
644
+ * @param workflowId - The canonical workflow id (the document's own identity).
645
+ * @param document - The canonical document whose metadata must agree.
646
+ * @returns The canonical deployed job name to launch.
647
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_RUN_WORKFLOW_MISMATCH` when the
648
+ * metadata names a different job, or `GRAPH_DAGSTER_RUN_LAUNCH_FAILED` when the
649
+ * canonical job cannot be resolved.
650
+ */
651
+ async resolveCanonicalJobName(client, workflowId, document) {
652
+ const claimed = document.metadata?.["dagsterJobName"];
653
+ if (typeof claimed === "string" &&
654
+ claimed.length > 0 &&
655
+ claimed !== workflowId) {
656
+ throw new GraphExecutionError(`Workflow document '${workflowId}' declares a different Dagster job ('${claimed}'); refusing to launch a mismatched job`, DAGSTER_ERROR.RUN_WORKFLOW_MISMATCH, { workflowId, claimedJobName: claimed });
657
+ }
658
+ try {
659
+ const job = await client.getJob(workflowId);
660
+ return job.name || workflowId;
661
+ }
662
+ catch (error) {
663
+ if (error instanceof GraphExecutionError)
664
+ throw error;
665
+ throw new GraphExecutionError(error instanceof Error ? error.message : String(error), DAGSTER_ERROR.RUN_LAUNCH_FAILED, { jobName: workflowId });
666
+ }
667
+ }
668
+ /**
669
+ * Asserts that a caller-supplied Dagster run id belongs to the requested
670
+ * workflow before it is re-executed (C1 BOLA guard). The run's owning job is
671
+ * resolved from the read-only `getRun` surface; a cross-job run, or a run whose
672
+ * owning job cannot be determined, is rejected before any re-execution.
673
+ *
674
+ * @param client - The wired client port.
675
+ * @param dagsterRunId - The caller-supplied run id to bind.
676
+ * @param workflowId - The workflow the run must belong to.
677
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_RUN_WORKFLOW_MISMATCH` when the
678
+ * run is foreign or its owning job cannot be determined.
679
+ */
680
+ async assertRunOwnedByWorkflow(client, dagsterRunId, workflowId) {
681
+ let record;
682
+ try {
683
+ record = await client.getRun(dagsterRunId);
684
+ }
685
+ catch (error) {
686
+ if (error instanceof GraphExecutionError)
687
+ throw error;
688
+ throw new GraphExecutionError(`Dagster run '${dagsterRunId}' could not be read to bind it to workflow '${workflowId}'`, DAGSTER_ERROR.RUN_WORKFLOW_MISMATCH, { runId: dagsterRunId, workflowId });
689
+ }
690
+ const owner = record.jobName ?? record.pipelineName;
691
+ if (typeof owner !== "string" || owner.length === 0 || owner !== workflowId) {
692
+ throw new GraphExecutionError(`Dagster run '${dagsterRunId}' does not belong to workflow '${workflowId}'`, DAGSTER_ERROR.RUN_WORKFLOW_MISMATCH, { runId: dagsterRunId, workflowId, ...(owner ? { owner } : {}) });
693
+ }
694
+ }
695
+ /**
696
+ * Awaits a launched/re-executed run's terminal state through the read-only
697
+ * `getRun` surface, bounded by the signal and timeout. The run is then observed
698
+ * through the event bridge; this keeps the transport's replay-based subscription
699
+ * (which does not stream) sufficient without a live transport.
700
+ *
701
+ * @param client - The wired client port.
702
+ * @param runId - The launched/re-executed Dagster run id.
703
+ * @param options - Optional signal, timeout, and poll interval.
704
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_OBSERVE_ABORTED` on abort, or
705
+ * `GRAPH_DAGSTER_OBSERVE_TIMEOUT` when the run does not terminate in time.
706
+ */
707
+ async awaitRunTerminal(client, runId, options = {}) {
708
+ const timeoutMs = options.timeoutMs ?? DEFAULT_EXECUTION_TERMINAL_TIMEOUT_MS;
709
+ const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_EXECUTION_POLL_INTERVAL_MS;
710
+ const deadline = Date.now() + timeoutMs;
711
+ for (;;) {
712
+ if (options.signal?.aborted) {
713
+ throw new GraphExecutionError(`Dagster run '${runId}' wait was aborted by the caller`, DAGSTER_ERROR.OBSERVE_ABORTED, { runId });
714
+ }
715
+ const record = await client.getRun(runId);
716
+ if (DAGSTER_TERMINAL_RUN_STATUSES.has(record.status))
717
+ return;
718
+ if (Date.now() >= deadline) {
719
+ throw new GraphExecutionError(`Dagster run '${runId}' did not reach a terminal state within ${timeoutMs}ms`, DAGSTER_ERROR.OBSERVE_TIMEOUT, { runId, timeoutMs });
720
+ }
721
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
722
+ }
723
+ }
724
+ /**
725
+ * Fails closed when the explicit execution gate is off, BEFORE any client or
726
+ * network call.
727
+ *
728
+ * @throws {GraphExecutionError} `GRAPH_DAGSTER_EXECUTION_NOT_ENABLED`.
729
+ */
730
+ assertExecutionEnabled() {
731
+ if (!this.executionEnabled) {
732
+ throw new GraphExecutionError("Dagster execution is disabled: set `executionEnabled: true` on the backend config to execute or replay EXISTING workflows", DAGSTER_ERROR.EXECUTION_NOT_ENABLED);
733
+ }
734
+ }
735
+ /**
736
+ * Builds the run tags the driver attaches to a launched/re-executed run: the
737
+ * host defaults plus the canonical run/workflow identity under the
738
+ * {@link DAGSTER_TAG_NAMESPACE} namespace. No document content or Python source
739
+ * is carried.
740
+ *
741
+ * @param graphRunId - The canonical run id.
742
+ * @param workflowId - The canonical workflow id.
743
+ * @returns The run tags.
744
+ */
745
+ executionTags(graphRunId, workflowId) {
746
+ return {
747
+ ...this.defaultTags,
748
+ [`${DAGSTER_TAG_NAMESPACE}graphRunId`]: graphRunId,
749
+ [`${DAGSTER_TAG_NAMESPACE}workflowId`]: workflowId,
750
+ };
751
+ }
752
+ /**
753
+ * Reads the optional raw Dagster run configuration from execution metadata. The
754
+ * driver forwards it verbatim; it never synthesizes run config.
755
+ *
756
+ * @param metadata - The execution options metadata.
757
+ * @returns The raw run config, when present.
758
+ */
759
+ dagsterRunConfigOf(metadata) {
760
+ const runConfig = metadata?.["dagsterRunConfig"];
761
+ if (runConfig === undefined || runConfig === null)
762
+ return undefined;
763
+ if (typeof runConfig !== "object" || Array.isArray(runConfig)) {
764
+ throw new GraphExecutionError("Dagster run config must be a JSON-safe object", DAGSTER_ERROR.RUN_CONFIG_INVALID);
765
+ }
766
+ return dagsterAllowlistedRunConfig(runConfig, 0);
767
+ }
768
+ /**
769
+ * Returns the wired client port or fails loudly.
770
+ *
771
+ * @returns The client port.
772
+ * @throws {GraphExecutionError} when no client is configured.
773
+ */
774
+ requireClient() {
775
+ if (!this.client) {
776
+ throw new GraphExecutionError("DagsterGraphExecutionBackend has no client configured; call initialize(config) first", DAGSTER_ERROR.CLIENT_NOT_CONFIGURED);
777
+ }
778
+ return this.client;
779
+ }
780
+ }
781
+ //# sourceMappingURL=DagsterGraphExecutionBackend.js.map