@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,351 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MastraGraphExecutionBackend = void 0;
4
+ const db_decorators_1 = require("@decaf-ts/db-decorators");
5
+ const constants_js_1 = require("./../shared/graph/constants.cjs");
6
+ const GraphExecutionBackendRegistry_js_1 = require("./../engine/execution/GraphExecutionBackendRegistry.cjs");
7
+ const ownership_js_1 = require("./../engine/runs/ownership.cjs");
8
+ const GraphWorkflowService_js_1 = require("./../engine/services/GraphWorkflowService.cjs");
9
+ const GraphExecutionError_js_1 = require("./../engine/errors/GraphExecutionError.cjs");
10
+ const GraphRunFingerprint_js_1 = require("./../engine/runs/GraphRunFingerprint.cjs");
11
+ const GraphExecutionResult_js_1 = require("./../engine/execution/GraphExecutionResult.cjs");
12
+ const MastraWorkflowCompiler_js_1 = require("./MastraWorkflowCompiler.cjs");
13
+ const MastraWorkflowManager_js_1 = require("./MastraWorkflowManager.cjs");
14
+ const MastraEventBridge_js_1 = require("./MastraEventBridge.cjs");
15
+ const MastraResumeGuard_js_1 = require("./MastraResumeGuard.cjs");
16
+ const MastraSchemaConverter_js_1 = require("./MastraSchemaConverter.cjs");
17
+ const MastraCapabilities_js_1 = require("./MastraCapabilities.cjs");
18
+ const types_js_1 = require("./types.cjs");
19
+ const DEFAULT_MAX_RESUME_BYTES = 64 * 1024;
20
+ function isRecord(value) {
21
+ return !!value && typeof value === "object" && !Array.isArray(value);
22
+ }
23
+ /**
24
+ * Structural check for a Decaf execution {@link Context} inside a
25
+ * {@link MaybeContextualArg} argument list. Mirrors `@decaf-ts/core`'s own
26
+ * `isContextLike` realm-safe duck-typing (multiple linked core builds defeat
27
+ * `instanceof`).
28
+ *
29
+ * @param value - A candidate argument.
30
+ * @returns `true` when the value is a Decaf execution context.
31
+ */
32
+ function isMastraContextLike(value) {
33
+ if (!value || typeof value !== "object")
34
+ return false;
35
+ const candidate = value;
36
+ return (typeof candidate.get === "function" &&
37
+ typeof candidate.accumulate === "function" &&
38
+ typeof candidate.override === "function" &&
39
+ typeof candidate.toOverrides === "function" &&
40
+ candidate.cache !== undefined);
41
+ }
42
+ /**
43
+ * Resolves the caller owner from the forwarded contextual arguments (C23). The
44
+ * catalogue methods receive the same `...args` the facade forwards to every
45
+ * backend; the trailing context, when present, carries the authenticated principal
46
+ * the service layer resolves with {@link graphWorkflowOwnerOf}.
47
+ *
48
+ * @param args - The forwarded contextual arguments.
49
+ * @returns The caller owner, or `undefined` for owner-less callers.
50
+ */
51
+ function mastraCallerOwnerOf(args) {
52
+ for (let index = args.length - 1; index >= 0; index -= 1) {
53
+ const candidate = args[index];
54
+ if (isMastraContextLike(candidate)) {
55
+ return (0, GraphWorkflowService_js_1.graphWorkflowOwnerOf)(candidate);
56
+ }
57
+ }
58
+ return undefined;
59
+ }
60
+ /**
61
+ * `@mastra/core`-translated execution backend (SAA-196). Translates the
62
+ * canonical document into a Mastra workflow, runs it through the injected Mastra
63
+ * runtime, bridges Mastra's `fullStream` onto the facade event sink, and enforces
64
+ * the SAA-193 resume guard conditions. Code-mode surfaces are not executed:
65
+ * `codeMode` is `unsupported`, so the facade fails closed before delegating.
66
+ */
67
+ class MastraGraphExecutionBackend {
68
+ constructor() {
69
+ /** Translated backend: never executes in-process. */
70
+ this.local = false;
71
+ /** Code-mode surfaces are rejected by the facade gate (C3). */
72
+ this.codeMode = "unsupported";
73
+ this.compiler = new MastraWorkflowCompiler_js_1.MastraWorkflowCompiler();
74
+ this.documents = new Map();
75
+ this.runWorkflows = new Map();
76
+ this.maxResumeBytes = DEFAULT_MAX_RESUME_BYTES;
77
+ this.initialized = false;
78
+ GraphExecutionBackendRegistry_js_1.GraphExecutionBackendRegistry.register(types_js_1.MASTRA_BACKEND_FLAVOUR, this);
79
+ }
80
+ async initialize(config) {
81
+ this._config = config;
82
+ this.runtime = config.mastra;
83
+ // Re-initializing rewires the runtime/compiler, so a previously cached
84
+ // management surface must not survive the rebind (C7).
85
+ this.managementManager = undefined;
86
+ this.suspendStateReader = config.suspendStateReader;
87
+ if (typeof config.maxResumeBytes === "number" && config.maxResumeBytes > 0) {
88
+ this.maxResumeBytes = config.maxResumeBytes;
89
+ }
90
+ const stepHandlers = Array.isArray(config.stepHandlers)
91
+ ? [...config.stepHandlers]
92
+ : [];
93
+ this.compiler = new MastraWorkflowCompiler_js_1.MastraWorkflowCompiler({ stepHandlers });
94
+ this.initialized = true;
95
+ }
96
+ get capabilities() {
97
+ return (0, MastraCapabilities_js_1.resolveMastraCapabilities)();
98
+ }
99
+ /**
100
+ * The workflow-management surface over the wired real `@mastra/core` runtime
101
+ * (SAA-346). The manager translates canonical documents through the same
102
+ * compiler the backend executes with, so a created/updated workflow is the one
103
+ * `execute` runs. Every operation fails closed when the wired runtime exposes
104
+ * no real Mastra method.
105
+ */
106
+ get management() {
107
+ // Cache the manager per backend (C7): revisions recorded at `create` must
108
+ // survive the next `management` access, otherwise `get`/`serialize` silently
109
+ // drop the wrapper-tracked revision.
110
+ if (!this.managementManager) {
111
+ this.managementManager = new MastraWorkflowManager_js_1.MastraWorkflowManager({
112
+ runtime: this.runtime,
113
+ compiler: this.compiler,
114
+ });
115
+ }
116
+ return this.managementManager;
117
+ }
118
+ /**
119
+ * Lists the translated workflows visible to the requesting caller (C23). The
120
+ * catalogue is ownership-filtered with the same
121
+ * {@link canAccessGraphResource} predicate the service layer uses: a document
122
+ * executed by a named owner is visible only to that owner, an owner-less
123
+ * document stays visible to every caller, and an anonymous caller sees only
124
+ * owner-less documents. The caller owner is resolved from the forwarded
125
+ * contextual arguments; a missing context denies foreign-owner rows.
126
+ *
127
+ * @param args - Optional decaf contextual arguments carrying the caller principal.
128
+ * @returns Workflow summaries visible to the caller.
129
+ */
130
+ async listWorkflows(...args) {
131
+ const callerOwner = mastraCallerOwnerOf(args);
132
+ return [...this.documents.values()]
133
+ .filter((entry) => (0, ownership_js_1.canAccessGraphResource)({ owner: entry.owner }, callerOwner))
134
+ .map((entry) => ({
135
+ id: entry.document.id,
136
+ ...(entry.document.name ? { name: entry.document.name } : {}),
137
+ }));
138
+ }
139
+ /**
140
+ * Reads a single translated workflow document, enforcing the C23 ownership
141
+ * predicate. An unknown id and a foreign-owner id both fail closed: an unknown
142
+ * id keeps the backend's existing translated-catalogue error, and a foreign-owner
143
+ * id is denied with a constant `NotFoundError` that maps to `404` and never
144
+ * carries `GraphExecutionError.details`, so a foreign caller cannot read
145
+ * another owner's canonical document.
146
+ *
147
+ * @param workflowId - The canonical workflow id to read.
148
+ * @param args - Optional decaf contextual arguments carrying the caller principal.
149
+ * @returns The canonical workflow document.
150
+ * @throws {GraphExecutionError} when no translated workflow exists for the id.
151
+ * @throws {NotFoundError} when the workflow is owned by another user.
152
+ */
153
+ async getWorkflow(workflowId, ...args) {
154
+ const callerOwner = mastraCallerOwnerOf(args);
155
+ const entry = this.documents.get(workflowId);
156
+ if (!entry) {
157
+ throw new GraphExecutionError_js_1.GraphExecutionError(`Mastra backend has no translated workflow '${workflowId}'`, types_js_1.GRAPH_MASTRA_UNSUPPORTED_KIND, { workflowId });
158
+ }
159
+ if (!(0, ownership_js_1.canAccessGraphResource)({ owner: entry.owner }, callerOwner)) {
160
+ throw new db_decorators_1.NotFoundError(`No graph workflow found for workflowId '${workflowId}'`);
161
+ }
162
+ return entry.document;
163
+ }
164
+ async execute(request, ...args) {
165
+ const sink = request.events;
166
+ const frame = sink.frame;
167
+ if (!frame) {
168
+ throw new GraphExecutionError_js_1.GraphExecutionError("MastraGraphExecutionBackend requires the frame-bound event sink created by GraphExecutionEngine", types_js_1.GRAPH_MASTRA_UNSUPPORTED_KIND, { workflowId: request.document.id });
169
+ }
170
+ const runId = frame.runId;
171
+ const owner = this.callerOwnerOf(request, args);
172
+ this.documents.set(request.document.id, {
173
+ document: request.document,
174
+ ...(owner ? { owner } : {}),
175
+ });
176
+ this.runWorkflows.set(runId, request.document.id);
177
+ const compiled = this.compiler.compile(request.document);
178
+ const workflow = compiled.workflow;
179
+ if (typeof workflow.createRun !== "function") {
180
+ throw new GraphExecutionError_js_1.GraphExecutionError("Mastra backend received a workflow without a createRun method", types_js_1.GRAPH_MASTRA_AGENT_UNAVAILABLE, { workflowId: request.document.id });
181
+ }
182
+ const bridge = new MastraEventBridge_js_1.MastraEventBridge({
183
+ runId,
184
+ parentRunId: request.options.parentRunId,
185
+ workflowId: request.document.id,
186
+ document: request.document,
187
+ sink,
188
+ path: [],
189
+ });
190
+ let status = constants_js_1.GraphExecutionStatus.SUCCEEDED;
191
+ try {
192
+ const run = await workflow.createRun({ runId });
193
+ const stream = await run.stream({ inputData: request.inputs });
194
+ if (stream.fullStream) {
195
+ await bridge.attach(stream.fullStream);
196
+ }
197
+ if (typeof run.getResult === "function") {
198
+ await run.getResult();
199
+ }
200
+ else if (stream.result) {
201
+ await stream.result;
202
+ }
203
+ }
204
+ catch (error) {
205
+ status = constants_js_1.GraphExecutionStatus.FAILED;
206
+ await sink.emit({
207
+ type: constants_js_1.GraphExecutionEventType.WORKFLOW_FAILED,
208
+ status,
209
+ error: this.errorPayload(error),
210
+ });
211
+ }
212
+ frame.finish();
213
+ return (0, GraphExecutionResult_js_1.buildGraphExecutionResult)(frame, request.document, request.inputs, status, { backend: types_js_1.MASTRA_BACKEND_FLAVOUR, documentFingerprint: compiled.fingerprint });
214
+ }
215
+ /**
216
+ * Resumes a suspended Mastra run after enforcing the SAA-193 resume guard
217
+ * (C13/C15/C16/C17/C18). The Mastra run snapshot is authoritative for the
218
+ * suspended state; the current document fingerprint must match the snapshot
219
+ * (C17). Returns the C18 audit record, never the raw `resumeData`.
220
+ */
221
+ async resume(runId, request, ..._args) {
222
+ const reader = this.suspendStateReader;
223
+ if (!reader) {
224
+ throw new GraphExecutionError_js_1.GraphExecutionError("Mastra backend has no suspendStateReader configured; resume is not available", types_js_1.GRAPH_MASTRA_UNSUPPORTED_KIND, { runId });
225
+ }
226
+ const snapshot = await reader.readRunState(runId, ..._args);
227
+ if (!snapshot) {
228
+ throw new GraphExecutionError_js_1.GraphExecutionError(`Mastra backend has no suspended snapshot for run '${runId}'`, "GRAPH_MASTRA_RESUME_STATE_INVALID", { runId });
229
+ }
230
+ const document = this.documents.get(snapshot.workflowId)?.document;
231
+ if (!document) {
232
+ throw new GraphExecutionError_js_1.GraphExecutionError(`Mastra backend has no translated workflow '${snapshot.workflowId}'`, "GRAPH_MASTRA_RESUME_STATE_INVALID", { runId, workflowId: snapshot.workflowId });
233
+ }
234
+ const allowlistedSteps = snapshot.suspendedSteps;
235
+ const suspendedStep = request.step ?? snapshot.suspendedSteps[0] ?? "";
236
+ const suspendedNode = (document.nodes ?? []).find((node) => node.id === suspendedStep);
237
+ const declaredResumeSchema = suspendedNode?.parameters?.["resumeSchema"];
238
+ const resumeSchema = declaredResumeSchema
239
+ ? (0, MastraSchemaConverter_js_1.assertMastraResumeSchemaSafe)(declaredResumeSchema)
240
+ : undefined;
241
+ const audit = (0, MastraResumeGuard_js_1.assertMastraResumeAllowed)(request, {
242
+ runId,
243
+ workflowId: snapshot.workflowId,
244
+ documentFingerprint: snapshot.documentFingerprint,
245
+ status: snapshot.status,
246
+ step: request.step ?? snapshot.suspendedSteps[0] ?? "",
247
+ forEachIndex: request.forEachIndex ??
248
+ snapshot.suspendedForEachIndexes?.[request.step ?? snapshot.suspendedSteps[0] ?? ""],
249
+ state: snapshot,
250
+ }, {
251
+ maxResumeBytes: this.maxResumeBytes,
252
+ allowlistedSteps,
253
+ documentFingerprint: (0, GraphRunFingerprint_js_1.graphRunDocumentFingerprint)(document),
254
+ ...(resumeSchema ? { resumeSchema } : {}),
255
+ });
256
+ const run = await this.loadRun(runId);
257
+ if (!run || typeof run.resume !== "function") {
258
+ throw new GraphExecutionError_js_1.GraphExecutionError(`Mastra backend cannot resume run '${runId}': no resumable run handle`, types_js_1.GRAPH_MASTRA_UNSUPPORTED_KIND, { runId });
259
+ }
260
+ await run.resume({
261
+ step: audit.step,
262
+ resumeData: request.resumeData,
263
+ ...(audit.forEachIndex !== undefined
264
+ ? { forEachIndex: audit.forEachIndex }
265
+ : {}),
266
+ });
267
+ return audit;
268
+ }
269
+ /**
270
+ * Resolves the owner recorded for a run (C23). The facade-resolved principal
271
+ * bound onto `options.auth` is authoritative; when absent (a direct backend call)
272
+ * the owner is resolved from the forwarded contextual arguments. Returns
273
+ * `undefined` for owner-less runs, matching the service-layer owner-less
274
+ * visibility rule.
275
+ *
276
+ * @param request - The execution request carrying the facade-resolved options.
277
+ * @param args - The forwarded contextual arguments.
278
+ * @returns The run's owner, or `undefined` when owner-less.
279
+ */
280
+ callerOwnerOf(request, args) {
281
+ const authUser = request.options?.auth?.user;
282
+ if (typeof authUser === "string" && authUser.length > 0) {
283
+ return authUser;
284
+ }
285
+ return mastraCallerOwnerOf(args);
286
+ }
287
+ /**
288
+ * Releases the per-run catalogue state (C23). Removes the run's workflow
289
+ * association and drops the translated document once no other live run still
290
+ * references it, so the process-lifetime catalogue cannot grow unbounded and
291
+ * widen the BOLA surface over time.
292
+ *
293
+ * @param runId - The completed run whose resources are released.
294
+ */
295
+ async release(runId) {
296
+ const workflowId = this.runWorkflows.get(runId);
297
+ if (workflowId === undefined)
298
+ return;
299
+ this.runWorkflows.delete(runId);
300
+ const stillReferenced = [...this.runWorkflows.values()].includes(workflowId);
301
+ if (!stillReferenced) {
302
+ this.documents.delete(workflowId);
303
+ }
304
+ }
305
+ async dispose() {
306
+ this.compiler.clear();
307
+ this.documents.clear();
308
+ this.runWorkflows.clear();
309
+ this.runtime = undefined;
310
+ this.managementManager = undefined;
311
+ this.initialized = false;
312
+ }
313
+ /**
314
+ * The configuration most recently resolved by {@link initialize}. Exposed so
315
+ * `GraphExecutionEngine.initialize` can merge its facade-owned collaborators
316
+ * over the host's keys (`mastra`, `stepHandlers`, `suspendStateReader`, ...)
317
+ * instead of dropping them when it re-initializes the backend at boot.
318
+ */
319
+ get config() {
320
+ return this._config;
321
+ }
322
+ /** Whether {@link initialize} has resolved. */
323
+ get ready() {
324
+ return this.initialized;
325
+ }
326
+ async loadRun(runId) {
327
+ const runtime = this.runtime;
328
+ if (!isRecord(runtime))
329
+ return undefined;
330
+ const getRun = runtime["getRun"];
331
+ if (typeof getRun !== "function")
332
+ return undefined;
333
+ const run = await getRun.call(runtime, runId);
334
+ return isRecord(run) ? run : undefined;
335
+ }
336
+ errorPayload(error) {
337
+ if (error instanceof Error) {
338
+ return {
339
+ name: error.name,
340
+ message: error.message,
341
+ ...(typeof error.code === "string"
342
+ ? { code: error.code }
343
+ : {}),
344
+ };
345
+ }
346
+ return { name: "MastraError", message: String(error) };
347
+ }
348
+ }
349
+ exports.MastraGraphExecutionBackend = MastraGraphExecutionBackend;
350
+ //# sourceMappingURL=MastraGraphExecutionBackend.js.map
351
+ //# sourceMappingURL=MastraGraphExecutionBackend.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mastra/MastraGraphExecutionBackend.cjs","sourceRoot":"","sources":["mastra/MastraGraphExecutionBackend.js"],"names":[],"mappings":";;;AAAA,2DAAwD;AACxD,iEAA+F;AAC/F,6GAAuG;AACvG,gEAAuE;AACvE,0FAAoF;AACpF,sFAAgF;AAChF,oFAAsF;AACtF,2FAA0F;AAC1F,2EAAqE;AACrE,yEAAmE;AACnE,iEAA2D;AAC3D,iEAAmE;AACnE,yEAA0E;AAC1E,mEAAqE;AACrE,yCAAoH;AACpH,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,CAA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astraResumeAllowed = assertMastraResumeAllowed;
4
+ /**
5
+ * @module as-graph/mastra/MastraResumeGuard
6
+ * @summary Untrusted-resume validation for the Mastra backend (SAA-193
7
+ * C13/C15/C16/C17/C18).
8
+ * @description Every resume request is validated against the Mastra-authoritative
9
+ * snapshot of the suspended run and the current document fingerprint before any
10
+ * state is handed back to Mastra. Rejections carry specific error codes and the
11
+ * returned audit record carries only identity and provenance — the raw
12
+ * `resumeData` is never logged or echoed.
13
+ */
14
+ const GraphExecutionError_js_1 = require("./../engine/errors/GraphExecutionError.cjs");
15
+ const GraphJsonValue_js_1 = require("./../shared/graph/document/GraphJsonValue.cjs");
16
+ const types_js_1 = require("./types.cjs");
17
+ /**
18
+ * Measures the serialised byte size of a value, treating non-serialisable
19
+ * values as unbounded.
20
+ *
21
+ * @param value - The value to measure.
22
+ * @returns The serialised size in bytes, or infinity when not serialisable.
23
+ */
24
+ function serializedSize(value) {
25
+ if (value === undefined)
26
+ return 0;
27
+ try {
28
+ return new TextEncoder().encode(JSON.stringify(value)).length;
29
+ }
30
+ catch {
31
+ return Number.POSITIVE_INFINITY;
32
+ }
33
+ }
34
+ /**
35
+ * Computes a stable, non-reversible FNV-1a hash of a value for the C18 audit
36
+ * record; the raw value is never logged.
37
+ *
38
+ * @param value - The value to hash.
39
+ * @returns The `fnv1a` hash string with the serialised length.
40
+ */
41
+ function stableHash(value) {
42
+ const text = JSON.stringify(value ?? null);
43
+ let hash = 0x811c9dc5;
44
+ for (let index = 0; index < text.length; index += 1) {
45
+ hash ^= text.charCodeAt(index);
46
+ hash = Math.imul(hash, 0x01000193);
47
+ }
48
+ return `fnv1a:${(hash >>> 0).toString(16).padStart(8, "0")}:${text.length}`;
49
+ }
50
+ /**
51
+ * Validates an untrusted resume request against the Mastra-authoritative
52
+ * snapshot and the current document, enforcing C13/C15/C16/C17 before any state
53
+ * is handed back to Mastra. On success it returns the C18 audit record; the raw
54
+ * `resumeData` is never logged or echoed.
55
+ *
56
+ * @param request - The untrusted resume request to validate.
57
+ * @param snapshot - The Mastra-authoritative suspended-run snapshot.
58
+ * @param options - Document-derived validation options (byte cap, allowlist,
59
+ * fingerprint, and the suspended step's resume schema).
60
+ * @returns The C18 audit record for the accepted resume.
61
+ * @throws {GraphExecutionError} `GRAPH_MASTRA_RESUME_INVALID` for non-JSON-safe or
62
+ * oversized `resumeData`; `GRAPH_MASTRA_RESUME_STEP_UNKNOWN` when the suspended
63
+ * step or iteration is not allowlisted; `GRAPH_MASTRA_RESUME_STATE_INVALID`
64
+ * when the snapshot is not suspended or its fingerprint does not match.
65
+ */
66
+ function assertMastraResumeAllowed(request, snapshot, options) {
67
+ if (!request || typeof request !== "object") {
68
+ throw new GraphExecutionError_js_1.GraphExecutionError("Mastra resume request must be an object", types_js_1.GRAPH_MASTRA_RESUME_INVALID, { runId: snapshot.runId });
69
+ }
70
+ const size = serializedSize(request.resumeData);
71
+ if (size > options.maxResumeBytes || !(0, GraphJsonValue_js_1.isGraphJsonSafeValue)(request.resumeData)) {
72
+ throw new GraphExecutionError_js_1.GraphExecutionError("Mastra resume data is not JSON-safe or exceeds the byte cap", types_js_1.GRAPH_MASTRA_RESUME_INVALID, {
73
+ runId: snapshot.runId,
74
+ step: snapshot.step,
75
+ size,
76
+ maxBytes: options.maxResumeBytes,
77
+ });
78
+ }
79
+ if (options.resumeSchema &&
80
+ !options.resumeSchema.safeParse(request.resumeData).success) {
81
+ throw new GraphExecutionError_js_1.GraphExecutionError("Mastra resume data does not satisfy the suspended step's resume schema", types_js_1.GRAPH_MASTRA_RESUME_INVALID, { runId: snapshot.runId, step: snapshot.step });
82
+ }
83
+ const allowlisted = new Set(options.allowlistedSteps);
84
+ if (!allowlisted.has(snapshot.step)) {
85
+ throw new GraphExecutionError_js_1.GraphExecutionError(`Mastra resume step '${snapshot.step}' is not resumable in the current document`, types_js_1.GRAPH_MASTRA_RESUME_STEP_UNKNOWN, { runId: snapshot.runId, step: snapshot.step });
86
+ }
87
+ const step = request.step ?? snapshot.step;
88
+ if (step !== snapshot.step || !allowlisted.has(step)) {
89
+ throw new GraphExecutionError_js_1.GraphExecutionError(`Mastra resume step '${String(step)}' does not match the suspended step`, types_js_1.GRAPH_MASTRA_RESUME_STEP_UNKNOWN, { runId: snapshot.runId, step, suspendedStep: snapshot.step });
90
+ }
91
+ const forEachIndex = request.forEachIndex;
92
+ if (forEachIndex !== undefined) {
93
+ if (!Number.isInteger(forEachIndex) ||
94
+ forEachIndex < 0 ||
95
+ (typeof snapshot.forEachCount === "number" &&
96
+ forEachIndex >= snapshot.forEachCount)) {
97
+ throw new GraphExecutionError_js_1.GraphExecutionError("Mastra resume iteration index is out of range", types_js_1.GRAPH_MASTRA_RESUME_STEP_UNKNOWN, {
98
+ runId: snapshot.runId,
99
+ step: snapshot.step,
100
+ forEachIndex,
101
+ forEachCount: snapshot.forEachCount,
102
+ });
103
+ }
104
+ }
105
+ if (snapshot.status !== "suspended" ||
106
+ snapshot.documentFingerprint !== options.documentFingerprint ||
107
+ snapshot.state === undefined ||
108
+ snapshot.state === null) {
109
+ throw new GraphExecutionError_js_1.GraphExecutionError("Mastra resume snapshot is not a suspended run of the current document", types_js_1.GRAPH_MASTRA_RESUME_STATE_INVALID, {
110
+ runId: snapshot.runId,
111
+ status: snapshot.status,
112
+ snapshotFingerprint: snapshot.documentFingerprint,
113
+ documentFingerprint: options.documentFingerprint,
114
+ });
115
+ }
116
+ return {
117
+ runId: snapshot.runId,
118
+ workflowId: snapshot.workflowId,
119
+ step: snapshot.step,
120
+ forEachIndex,
121
+ resumeDataHash: stableHash(request.resumeData),
122
+ resumeDataBytes: size,
123
+ at: new Date().toISOString(),
124
+ };
125
+ }
126
+ //# sourceMappingURL=MastraResumeGuard.js.map
127
+ //# sourceMappingURL=MastraResumeGuard.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mastra/MastraResumeGuard.cjs","sourceRoot":"","sources":["mastra/MastraResumeGuard.js"],"names":[],"mappings":";;AA8DA,8DA2DC;AAzHD;;;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I,EAAE,QAAQ,CAAC,IAAI;QACnB,YAAY;QACZ,cAAc,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC;QAC9C,eAAe,EAAE,IAAI;QACrB,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAC/B,CAAC;AACN,CAAC;AACD,6CAA6C"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toMastraZodSchema = toMastraZodSchema;
4
+ exports.assertMastraResumeSchemaSafe = assertMastraResumeSchemaSafe;
5
+ /**
6
+ * @module as-graph/mastra/MastraSchemaConverter
7
+ * @summary Converts canonical {@link GraphValueSchema} declarations into Zod
8
+ * schemas for the Mastra backend (SAA-196).
9
+ * @description Mastra workflows are built on Zod schemas. The converter maps
10
+ * every canonical schema shape to its closest Zod equivalent, tracking whether
11
+ * the conversion degraded (or collapsed to `any`), so suspendable steps can be
12
+ * required to declare a strict, non-degraded resume schema before translation.
13
+ */
14
+ const zod_1 = require("zod");
15
+ const GraphExecutionError_js_1 = require("./../engine/errors/GraphExecutionError.cjs");
16
+ const types_js_1 = require("./types.cjs");
17
+ /**
18
+ * Recursively converts one canonical schema node into a Zod schema.
19
+ *
20
+ * @param schema - The canonical schema node to convert.
21
+ * @returns The conversion result with its degradation flags.
22
+ */
23
+ function convertValue(schema) {
24
+ switch (schema.type) {
25
+ case "string":
26
+ return { schema: zod_1.z.string(), degraded: false, any: false };
27
+ case "number": {
28
+ let value = zod_1.z.number();
29
+ if (schema.integer === true)
30
+ value = value.int();
31
+ if (schema.min !== undefined)
32
+ value = value.min(schema.min);
33
+ if (schema.max !== undefined)
34
+ value = value.max(schema.max);
35
+ return { schema: value, degraded: false, any: false };
36
+ }
37
+ case "boolean":
38
+ return { schema: zod_1.z.boolean(), degraded: false, any: false };
39
+ case "array": {
40
+ const items = convertValue(schema.items);
41
+ let value = zod_1.z.array(items.schema);
42
+ if (schema.minItems !== undefined)
43
+ value = value.min(schema.minItems);
44
+ if (schema.maxItems !== undefined)
45
+ value = value.max(schema.maxItems);
46
+ return { schema: value, degraded: items.degraded, any: false };
47
+ }
48
+ case "object": {
49
+ const shape = {};
50
+ let degraded = false;
51
+ for (const [key, property] of Object.entries(schema.properties ?? {})) {
52
+ const converted = convertValue(property);
53
+ shape[key] = converted.schema;
54
+ degraded = degraded || converted.degraded;
55
+ }
56
+ let value = zod_1.z.object(shape);
57
+ if (schema.additionalProperties === true) {
58
+ value = value.catchall(zod_1.z.any());
59
+ }
60
+ return { schema: value, degraded, any: false };
61
+ }
62
+ case "enum": {
63
+ const values = schema.values ?? [];
64
+ if (values.length === 0) {
65
+ return { schema: zod_1.z.any(), degraded: true, any: true };
66
+ }
67
+ if (values.every((entry) => typeof entry === "string")) {
68
+ return {
69
+ schema: zod_1.z.enum(values),
70
+ degraded: false,
71
+ any: false,
72
+ };
73
+ }
74
+ const literals = values.map((entry) => zod_1.z.literal(entry));
75
+ const union = literals.length === 1 ? literals[0] : zod_1.z.union(literals);
76
+ return { schema: union, degraded: false, any: false };
77
+ }
78
+ case "model": {
79
+ const shape = {};
80
+ let degraded = false;
81
+ for (const [key, property] of Object.entries(schema.properties ?? {})) {
82
+ const converted = convertValue(property);
83
+ shape[key] = converted.schema;
84
+ degraded = degraded || converted.degraded;
85
+ }
86
+ return { schema: zod_1.z.object(shape), degraded, any: false };
87
+ }
88
+ case "any":
89
+ default:
90
+ return { schema: zod_1.z.any(), degraded: true, any: true };
91
+ }
92
+ }
93
+ /**
94
+ * Converts a canonical schema (or the absence of one) into a Zod schema.
95
+ * A missing schema converts to a degraded `any` schema.
96
+ *
97
+ * @param schema - The canonical schema to convert, if declared.
98
+ * @returns The conversion result with its degradation flags.
99
+ */
100
+ function toMastraZodSchema(schema) {
101
+ if (!schema) {
102
+ return { schema: zod_1.z.any(), degraded: true, any: true };
103
+ }
104
+ return convertValue(schema);
105
+ }
106
+ /**
107
+ * Requires that a suspendable Mastra step declares a strict resume schema: the
108
+ * conversion must be neither degraded nor collapsed to `any`, otherwise resume
109
+ * payloads could not be validated (C15).
110
+ *
111
+ * @param schema - The declared resume schema of the suspended step.
112
+ * @returns The validated Zod resume schema.
113
+ * @throws {GraphExecutionError} {@link GRAPH_MASTRA_RESUME_SCHEMA_UNSAFE} when
114
+ * the schema is missing, degraded, or collapsed to `any`.
115
+ */
116
+ function assertMastraResumeSchemaSafe(schema) {
117
+ const converted = toMastraZodSchema(schema);
118
+ if (converted.any || converted.degraded) {
119
+ throw new GraphExecutionError_js_1.GraphExecutionError("A suspendable Mastra step requires a declared, non-degraded resume schema", types_js_1.GRAPH_MASTRA_RESUME_SCHEMA_UNSAFE);
120
+ }
121
+ return converted.schema;
122
+ }
123
+ //# sourceMappingURL=MastraSchemaConverter.js.map
124
+ //# sourceMappingURL=MastraSchemaConverter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mastra/MastraSchemaConverter.cjs","sourceRoot":"","sources":["mastra/MastraSchemaConverter.js"],"names":[],"mappings":";;AA+FA,8CAKC;AAWD,oEAMC;AArHD;;;;;;;;GAQG;AACH,6BAAwB;AACxB,sFAAgF;AAChF,yCAA+D;AAC/D;;;;;GAKG;AACH,SAAS,YAAY,CAAC,MAAM;IACxB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACT,OAAO,EAAE,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;QAC/D,KAAK,QAAQ,CAAC,CAAC,CAAC;YACZ,IAAI,KAAK,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC;YACvB,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI;gBACvB,KAAK,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;YACxB,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS;gBACxB,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG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