@mastra/factory 0.29.0-alpha.4 → 0.29.0-alpha.6

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 (401) hide show
  1. package/README.md +172 -89
  2. package/dist/boards/board-events.d.ts +89 -9
  3. package/dist/boards/board-events.d.ts.map +1 -1
  4. package/dist/boards/board-events.js +176 -13
  5. package/dist/boards/board-events.js.map +1 -1
  6. package/dist/boards/board-writes.d.ts.map +1 -1
  7. package/dist/boards/board-writes.js +14 -1
  8. package/dist/boards/board-writes.js.map +1 -1
  9. package/dist/boards/busy-card.d.ts +11 -0
  10. package/dist/boards/busy-card.d.ts.map +1 -0
  11. package/dist/boards/busy-card.js +15 -0
  12. package/dist/boards/busy-card.js.map +1 -0
  13. package/dist/boards/card-facts.d.ts.map +1 -1
  14. package/dist/boards/card-facts.js +18 -4
  15. package/dist/boards/card-facts.js.map +1 -1
  16. package/dist/boards/index.d.ts +2 -1
  17. package/dist/boards/index.d.ts.map +1 -1
  18. package/dist/boards/index.js +3 -2
  19. package/dist/boards/intake-dry-run.d.ts +109 -0
  20. package/dist/boards/intake-dry-run.d.ts.map +1 -0
  21. package/dist/boards/intake-dry-run.js +158 -0
  22. package/dist/boards/intake-dry-run.js.map +1 -0
  23. package/dist/boards/intake-lookup.d.ts +32 -0
  24. package/dist/boards/intake-lookup.d.ts.map +1 -0
  25. package/dist/boards/intake-lookup.js +12 -0
  26. package/dist/boards/intake-lookup.js.map +1 -0
  27. package/dist/boards/intake-order.d.ts +32 -0
  28. package/dist/boards/intake-order.d.ts.map +1 -0
  29. package/dist/boards/intake-order.js +60 -0
  30. package/dist/boards/intake-order.js.map +1 -0
  31. package/dist/boards/intake-routing.d.ts +246 -35
  32. package/dist/boards/intake-routing.d.ts.map +1 -1
  33. package/dist/boards/intake-routing.js +437 -52
  34. package/dist/boards/intake-routing.js.map +1 -1
  35. package/dist/boards/reroute.d.ts +7 -3
  36. package/dist/boards/reroute.d.ts.map +1 -1
  37. package/dist/boards/reroute.js +21 -4
  38. package/dist/boards/reroute.js.map +1 -1
  39. package/dist/boards/semantics.d.ts +8 -28
  40. package/dist/boards/semantics.d.ts.map +1 -1
  41. package/dist/boards/semantics.js +14 -40
  42. package/dist/boards/semantics.js.map +1 -1
  43. package/dist/boards/work-routes.d.ts +31 -11
  44. package/dist/boards/work-routes.d.ts.map +1 -1
  45. package/dist/boards/work-routes.js +104 -20
  46. package/dist/boards/work-routes.js.map +1 -1
  47. package/dist/factory.d.ts +37 -1
  48. package/dist/factory.d.ts.map +1 -1
  49. package/dist/factory.js +127 -48
  50. package/dist/factory.js.map +1 -1
  51. package/dist/integrations/base.d.ts +9 -0
  52. package/dist/integrations/base.d.ts.map +1 -1
  53. package/dist/integrations/dependabot/rules.js +1 -1
  54. package/dist/integrations/dependabot/rules.js.map +1 -1
  55. package/dist/integrations/github/default-rules.d.ts +22 -1
  56. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  57. package/dist/integrations/github/default-rules.js +23 -5
  58. package/dist/integrations/github/default-rules.js.map +1 -1
  59. package/dist/integrations/github/intake-lookup.d.ts +16 -0
  60. package/dist/integrations/github/intake-lookup.d.ts.map +1 -0
  61. package/dist/integrations/github/intake-lookup.js +76 -0
  62. package/dist/integrations/github/intake-lookup.js.map +1 -0
  63. package/dist/integrations/github/integration.d.ts +19 -5
  64. package/dist/integrations/github/integration.d.ts.map +1 -1
  65. package/dist/integrations/github/integration.js +21 -6
  66. package/dist/integrations/github/integration.js.map +1 -1
  67. package/dist/integrations/github/issue-intake.d.ts +15 -0
  68. package/dist/integrations/github/issue-intake.d.ts.map +1 -0
  69. package/dist/integrations/github/issue-intake.js +50 -0
  70. package/dist/integrations/github/issue-intake.js.map +1 -0
  71. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
  72. package/dist/integrations/github/issue-reconciler.js +10 -1
  73. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  74. package/dist/integrations/github/review-status-reporter.js +1 -1
  75. package/dist/integrations/github/routes.d.ts.map +1 -1
  76. package/dist/integrations/github/routes.js +14 -2
  77. package/dist/integrations/github/routes.js.map +1 -1
  78. package/dist/integrations/github/rules.d.ts +14 -1
  79. package/dist/integrations/github/rules.d.ts.map +1 -1
  80. package/dist/integrations/github/rules.js +221 -30
  81. package/dist/integrations/github/rules.js.map +1 -1
  82. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  83. package/dist/integrations/github/sandbox.js +30 -4
  84. package/dist/integrations/github/sandbox.js.map +1 -1
  85. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  86. package/dist/integrations/gitlab/default-rules.js +19 -3
  87. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  88. package/dist/integrations/gitlab/intake-lookup.d.ts +17 -0
  89. package/dist/integrations/gitlab/intake-lookup.d.ts.map +1 -0
  90. package/dist/integrations/gitlab/intake-lookup.js +85 -0
  91. package/dist/integrations/gitlab/intake-lookup.js.map +1 -0
  92. package/dist/integrations/gitlab/integration.d.ts +5 -0
  93. package/dist/integrations/gitlab/integration.d.ts.map +1 -1
  94. package/dist/integrations/gitlab/integration.js +21 -1
  95. package/dist/integrations/gitlab/integration.js.map +1 -1
  96. package/dist/integrations/gitlab/rules.d.ts +20 -0
  97. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  98. package/dist/integrations/gitlab/rules.js +108 -12
  99. package/dist/integrations/gitlab/rules.js.map +1 -1
  100. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  101. package/dist/integrations/incidentio/rules.js +14 -4
  102. package/dist/integrations/incidentio/rules.js.map +1 -1
  103. package/dist/integrations/jira/rules.d.ts.map +1 -1
  104. package/dist/integrations/jira/rules.js +12 -2
  105. package/dist/integrations/jira/rules.js.map +1 -1
  106. package/dist/integrations/linear/rules.d.ts.map +1 -1
  107. package/dist/integrations/linear/rules.js +13 -2
  108. package/dist/integrations/linear/rules.js.map +1 -1
  109. package/dist/integrations/platform/connect/routes.d.ts +43 -1
  110. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  111. package/dist/integrations/platform/connect/routes.js +82 -7
  112. package/dist/integrations/platform/connect/routes.js.map +1 -1
  113. package/dist/integrations/platform/connect/session-tools.d.ts +12 -0
  114. package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -1
  115. package/dist/integrations/platform/connect/session-tools.js +28 -10
  116. package/dist/integrations/platform/connect/session-tools.js.map +1 -1
  117. package/dist/integrations/platform/github/event-worker.js +9 -1
  118. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  119. package/dist/integrations/platform/github/integration.d.ts +6 -6
  120. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  121. package/dist/integrations/platform/github/integration.js +22 -3
  122. package/dist/integrations/platform/github/integration.js.map +1 -1
  123. package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
  124. package/dist/integrations/platform/vanta/integration.js +3 -3
  125. package/dist/integrations/platform/vanta/integration.js.map +1 -1
  126. package/dist/integrations/pull-request-head.d.ts +1 -1
  127. package/dist/integrations/pull-request-head.d.ts.map +1 -1
  128. package/dist/integrations/pull-request-head.js +5 -0
  129. package/dist/integrations/pull-request-head.js.map +1 -1
  130. package/dist/integrations/vanta/rules.js +1 -1
  131. package/dist/integrations/vanta/rules.js.map +1 -1
  132. package/dist/integrations/vanta/sync.d.ts +9 -0
  133. package/dist/integrations/vanta/sync.d.ts.map +1 -1
  134. package/dist/integrations/vanta/sync.js +10 -1
  135. package/dist/integrations/vanta/sync.js.map +1 -1
  136. package/dist/routes/board-snapshot.d.ts +13 -6
  137. package/dist/routes/board-snapshot.d.ts.map +1 -1
  138. package/dist/routes/board-snapshot.js +42 -20
  139. package/dist/routes/board-snapshot.js.map +1 -1
  140. package/dist/routes/boards.js.map +1 -1
  141. package/dist/routes/config.d.ts +17 -2
  142. package/dist/routes/config.d.ts.map +1 -1
  143. package/dist/routes/config.js +247 -77
  144. package/dist/routes/config.js.map +1 -1
  145. package/dist/routes/contracts.d.ts +1294 -7
  146. package/dist/routes/contracts.d.ts.map +1 -1
  147. package/dist/routes/contracts.js +603 -20
  148. package/dist/routes/contracts.js.map +1 -1
  149. package/dist/routes/custom-endpoint-url.d.ts +8 -0
  150. package/dist/routes/custom-endpoint-url.d.ts.map +1 -0
  151. package/dist/routes/custom-endpoint-url.js +45 -0
  152. package/dist/routes/custom-endpoint-url.js.map +1 -0
  153. package/dist/routes/custom-provider-source.d.ts +24 -8
  154. package/dist/routes/custom-provider-source.d.ts.map +1 -1
  155. package/dist/routes/custom-provider-source.js +93 -43
  156. package/dist/routes/custom-provider-source.js.map +1 -1
  157. package/dist/routes/intake-check.d.ts +92 -0
  158. package/dist/routes/intake-check.d.ts.map +1 -0
  159. package/dist/routes/intake-check.js +322 -0
  160. package/dist/routes/intake-check.js.map +1 -0
  161. package/dist/routes/intake-routes.d.ts +10 -2
  162. package/dist/routes/intake-routes.d.ts.map +1 -1
  163. package/dist/routes/intake-routes.js +292 -11
  164. package/dist/routes/intake-routes.js.map +1 -1
  165. package/dist/routes/intake.d.ts +6 -0
  166. package/dist/routes/intake.d.ts.map +1 -1
  167. package/dist/routes/intake.js +20 -0
  168. package/dist/routes/intake.js.map +1 -1
  169. package/dist/routes/mastra-gateway.d.ts.map +1 -1
  170. package/dist/routes/mastra-gateway.js +3 -2
  171. package/dist/routes/mastra-gateway.js.map +1 -1
  172. package/dist/routes/project-sessions.d.ts +61 -0
  173. package/dist/routes/project-sessions.d.ts.map +1 -0
  174. package/dist/routes/project-sessions.js +135 -0
  175. package/dist/routes/project-sessions.js.map +1 -0
  176. package/dist/routes/projects.d.ts +6 -1
  177. package/dist/routes/projects.d.ts.map +1 -1
  178. package/dist/routes/projects.js +19 -3
  179. package/dist/routes/projects.js.map +1 -1
  180. package/dist/routes/provider-credentials.d.ts +10 -1
  181. package/dist/routes/provider-credentials.d.ts.map +1 -1
  182. package/dist/routes/provider-credentials.js +13 -16
  183. package/dist/routes/provider-credentials.js.map +1 -1
  184. package/dist/routes/run-queue.d.ts +6 -6
  185. package/dist/routes/run-queue.d.ts.map +1 -1
  186. package/dist/routes/run-queue.js +28 -8
  187. package/dist/routes/run-queue.js.map +1 -1
  188. package/dist/routes/session-rows.d.ts +30 -0
  189. package/dist/routes/session-rows.d.ts.map +1 -0
  190. package/dist/routes/session-rows.js +94 -0
  191. package/dist/routes/session-rows.js.map +1 -0
  192. package/dist/routes/source-control-sessions.d.ts +4 -5
  193. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  194. package/dist/routes/source-control-sessions.js +8 -87
  195. package/dist/routes/source-control-sessions.js.map +1 -1
  196. package/dist/routes/surface.d.ts +16 -1
  197. package/dist/routes/surface.d.ts.map +1 -1
  198. package/dist/routes/surface.js +41 -30
  199. package/dist/routes/surface.js.map +1 -1
  200. package/dist/routes/tenant-credentials.d.ts.map +1 -1
  201. package/dist/routes/tenant-credentials.js +4 -4
  202. package/dist/routes/tenant-credentials.js.map +1 -1
  203. package/dist/routes/work-item-starters.d.ts +1 -0
  204. package/dist/routes/work-item-starters.d.ts.map +1 -1
  205. package/dist/routes/work-item-starters.js +14 -2
  206. package/dist/routes/work-item-starters.js.map +1 -1
  207. package/dist/routes/work-items.d.ts +22 -3
  208. package/dist/routes/work-items.d.ts.map +1 -1
  209. package/dist/routes/work-items.js +124 -48
  210. package/dist/routes/work-items.js.map +1 -1
  211. package/dist/rules/binding-context.d.ts +5 -0
  212. package/dist/rules/binding-context.d.ts.map +1 -1
  213. package/dist/rules/binding-context.js +51 -5
  214. package/dist/rules/binding-context.js.map +1 -1
  215. package/dist/rules/dispatch-errors.js +1 -1
  216. package/dist/rules/dispatch-errors.js.map +1 -1
  217. package/dist/rules/dispatcher.d.ts +39 -7
  218. package/dist/rules/dispatcher.d.ts.map +1 -1
  219. package/dist/rules/dispatcher.js +363 -123
  220. package/dist/rules/dispatcher.js.map +1 -1
  221. package/dist/rules/event-rules.d.ts +69 -1
  222. package/dist/rules/event-rules.d.ts.map +1 -1
  223. package/dist/rules/event-rules.js +151 -5
  224. package/dist/rules/event-rules.js.map +1 -1
  225. package/dist/rules/review-source-tool.js +1 -1
  226. package/dist/rules/rule-group.d.ts +18 -1
  227. package/dist/rules/rule-group.d.ts.map +1 -1
  228. package/dist/rules/rule-group.js +52 -8
  229. package/dist/rules/rule-group.js.map +1 -1
  230. package/dist/rules/run-bearing.d.ts +8 -0
  231. package/dist/rules/run-bearing.d.ts.map +1 -0
  232. package/dist/rules/run-bearing.js +11 -0
  233. package/dist/rules/run-bearing.js.map +1 -0
  234. package/dist/rules/start-coordinator.d.ts +2 -3
  235. package/dist/rules/start-coordinator.d.ts.map +1 -1
  236. package/dist/rules/start-coordinator.js +25 -38
  237. package/dist/rules/start-coordinator.js.map +1 -1
  238. package/dist/rules/tools.js +2 -1
  239. package/dist/rules/tools.js.map +1 -1
  240. package/dist/rules/transition-service.d.ts +16 -0
  241. package/dist/rules/transition-service.d.ts.map +1 -1
  242. package/dist/rules/transition-service.js +34 -10
  243. package/dist/rules/transition-service.js.map +1 -1
  244. package/dist/rules/types.d.ts +18 -5
  245. package/dist/rules/types.d.ts.map +1 -1
  246. package/dist/rules/types.js +2 -1
  247. package/dist/rules/types.js.map +1 -1
  248. package/dist/rules/update-fold.d.ts +32 -0
  249. package/dist/rules/update-fold.d.ts.map +1 -0
  250. package/dist/rules/update-fold.js +60 -0
  251. package/dist/rules/update-fold.js.map +1 -0
  252. package/dist/rules/validation.d.ts.map +1 -1
  253. package/dist/rules/validation.js +54 -6
  254. package/dist/rules/validation.js.map +1 -1
  255. package/dist/sandbox/session-retirement.d.ts +6 -0
  256. package/dist/sandbox/session-retirement.d.ts.map +1 -1
  257. package/dist/sandbox/session-retirement.js +17 -0
  258. package/dist/sandbox/session-retirement.js.map +1 -1
  259. package/dist/session/factory-session.d.ts.map +1 -1
  260. package/dist/session/factory-session.js +2 -1
  261. package/dist/session/factory-session.js.map +1 -1
  262. package/dist/session/live-sessions.d.ts +6 -1
  263. package/dist/session/live-sessions.d.ts.map +1 -1
  264. package/dist/session/live-sessions.js +4 -0
  265. package/dist/session/live-sessions.js.map +1 -1
  266. package/dist/session/resource-migration.d.ts.map +1 -1
  267. package/dist/session/resource-migration.js +2 -3
  268. package/dist/session/resource-migration.js.map +1 -1
  269. package/dist/session/run-audit.d.ts +10 -1
  270. package/dist/session/run-audit.d.ts.map +1 -1
  271. package/dist/session/run-audit.js +9 -1
  272. package/dist/session/run-audit.js.map +1 -1
  273. package/dist/session/self-review-gate.d.ts +26 -2
  274. package/dist/session/self-review-gate.d.ts.map +1 -1
  275. package/dist/session/self-review-gate.js +60 -10
  276. package/dist/session/self-review-gate.js.map +1 -1
  277. package/dist/session/session-row-query.d.ts +25 -0
  278. package/dist/session/session-row-query.d.ts.map +1 -0
  279. package/dist/session/session-row-query.js +47 -0
  280. package/dist/session/session-row-query.js.map +1 -0
  281. package/dist/session/session-row-status.d.ts +16 -0
  282. package/dist/session/session-row-status.d.ts.map +1 -0
  283. package/dist/session/session-row-status.js +14 -0
  284. package/dist/session/session-row-status.js.map +1 -0
  285. package/dist/session/session-row-view.d.ts +13 -0
  286. package/dist/session/session-row-view.d.ts.map +1 -0
  287. package/dist/session/session-row-view.js +118 -0
  288. package/dist/session/session-row-view.js.map +1 -0
  289. package/dist/session/session-rows.d.ts +60 -0
  290. package/dist/session/session-rows.d.ts.map +1 -0
  291. package/dist/session/session-rows.js +307 -0
  292. package/dist/session/session-rows.js.map +1 -0
  293. package/dist/session/session-threads.d.ts.map +1 -1
  294. package/dist/session/session-threads.js +1 -0
  295. package/dist/session/session-threads.js.map +1 -1
  296. package/dist/session/session-unloader.d.ts +101 -0
  297. package/dist/session/session-unloader.d.ts.map +1 -0
  298. package/dist/session/session-unloader.js +278 -0
  299. package/dist/session/session-unloader.js.map +1 -0
  300. package/dist/session/source-control-tools.d.ts +14 -7
  301. package/dist/session/source-control-tools.d.ts.map +1 -1
  302. package/dist/session/source-control-tools.js +10 -2
  303. package/dist/session/source-control-tools.js.map +1 -1
  304. package/dist/session/work-item-repository.d.ts +49 -1
  305. package/dist/session/work-item-repository.d.ts.map +1 -1
  306. package/dist/session/work-item-repository.js +118 -15
  307. package/dist/session/work-item-repository.js.map +1 -1
  308. package/dist/session/work-item-state-processor.d.ts.map +1 -1
  309. package/dist/session/work-item-state-processor.js +44 -8
  310. package/dist/session/work-item-state-processor.js.map +1 -1
  311. package/dist/session-list-changes.d.ts +9 -0
  312. package/dist/session-list-changes.d.ts.map +1 -0
  313. package/dist/session-list-changes.js +54 -0
  314. package/dist/session-list-changes.js.map +1 -0
  315. package/dist/storage/announced-lists.d.ts +14 -0
  316. package/dist/storage/announced-lists.d.ts.map +1 -0
  317. package/dist/storage/announced-lists.js +78 -0
  318. package/dist/storage/announced-lists.js.map +1 -0
  319. package/dist/storage/domains/audit/actions.d.ts +2 -1
  320. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  321. package/dist/storage/domains/audit/actions.js +3 -1
  322. package/dist/storage/domains/audit/actions.js.map +1 -1
  323. package/dist/storage/domains/boards/base.d.ts +163 -15
  324. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  325. package/dist/storage/domains/boards/base.js +440 -48
  326. package/dist/storage/domains/boards/base.js.map +1 -1
  327. package/dist/storage/domains/boards/schemas.d.ts +6 -0
  328. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  329. package/dist/storage/domains/boards/schemas.js +95 -1
  330. package/dist/storage/domains/boards/schemas.js.map +1 -1
  331. package/dist/storage/domains/custom-providers/base.d.ts +62 -19
  332. package/dist/storage/domains/custom-providers/base.d.ts.map +1 -1
  333. package/dist/storage/domains/custom-providers/base.js +131 -100
  334. package/dist/storage/domains/custom-providers/base.js.map +1 -1
  335. package/dist/storage/domains/intake/base.d.ts +25 -7
  336. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  337. package/dist/storage/domains/intake/base.js +83 -19
  338. package/dist/storage/domains/intake/base.js.map +1 -1
  339. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  340. package/dist/storage/domains/projects/base.js +19 -10
  341. package/dist/storage/domains/projects/base.js.map +1 -1
  342. package/dist/storage/domains/source-control/base.d.ts +8 -0
  343. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  344. package/dist/storage/domains/source-control/base.js +110 -61
  345. package/dist/storage/domains/source-control/base.js.map +1 -1
  346. package/dist/storage/domains/source-control/inmemory.d.ts +4 -0
  347. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  348. package/dist/storage/domains/source-control/inmemory.js +8 -5
  349. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  350. package/dist/storage/domains/work-items/base.d.ts +57 -18
  351. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  352. package/dist/storage/domains/work-items/base.js +168 -83
  353. package/dist/storage/domains/work-items/base.js.map +1 -1
  354. package/dist/storage/domains/work-items/cards.d.ts +3 -2
  355. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  356. package/dist/storage/domains/work-items/cards.js +4 -2
  357. package/dist/storage/domains/work-items/cards.js.map +1 -1
  358. package/dist/tools/audit-events-tool.d.ts +2 -2
  359. package/dist/tools/read-tools.d.ts +9 -5
  360. package/dist/tools/read-tools.d.ts.map +1 -1
  361. package/dist/tools/read-tools.js +61 -54
  362. package/dist/tools/read-tools.js.map +1 -1
  363. package/dist/tools/session-tools.d.ts +0 -13
  364. package/dist/tools/session-tools.d.ts.map +1 -1
  365. package/dist/tools/session-tools.js +128 -341
  366. package/dist/tools/session-tools.js.map +1 -1
  367. package/dist/tools/work-item-tools.d.ts +3 -0
  368. package/dist/tools/work-item-tools.d.ts.map +1 -1
  369. package/dist/tools/work-item-tools.js +99 -27
  370. package/dist/tools/work-item-tools.js.map +1 -1
  371. package/dist/work-item-branch.d.ts +4 -0
  372. package/dist/work-item-branch.d.ts.map +1 -1
  373. package/dist/work-item-branch.js +7 -1
  374. package/dist/work-item-branch.js.map +1 -1
  375. package/dist/work-items/card-context-sessions.d.ts +50 -0
  376. package/dist/work-items/card-context-sessions.d.ts.map +1 -0
  377. package/dist/work-items/card-context-sessions.js +84 -0
  378. package/dist/work-items/card-context-sessions.js.map +1 -0
  379. package/dist/work-items/card-reference.d.ts +21 -0
  380. package/dist/work-items/card-reference.d.ts.map +1 -0
  381. package/dist/work-items/card-reference.js +58 -0
  382. package/dist/work-items/card-reference.js.map +1 -0
  383. package/dist/work-items/change-requests.d.ts +87 -0
  384. package/dist/work-items/change-requests.d.ts.map +1 -0
  385. package/dist/work-items/change-requests.js +134 -0
  386. package/dist/work-items/change-requests.js.map +1 -0
  387. package/dist/work-items/create-work-item.d.ts +7 -2
  388. package/dist/work-items/create-work-item.d.ts.map +1 -1
  389. package/dist/work-items/create-work-item.js +44 -13
  390. package/dist/work-items/create-work-item.js.map +1 -1
  391. package/dist/work-items/list-related-cards.d.ts.map +1 -1
  392. package/dist/work-items/list-related-cards.js +1 -1
  393. package/dist/work-items/list-related-cards.js.map +1 -1
  394. package/dist/work-items/providers/github.d.ts.map +1 -1
  395. package/dist/work-items/providers/github.js +1 -0
  396. package/dist/work-items/providers/github.js.map +1 -1
  397. package/factory-skills/factory-build/SKILL.md +1 -1
  398. package/factory-skills/factory-plan/SKILL.md +5 -3
  399. package/factory-skills/factory-self-review/SKILL.md +2 -0
  400. package/factory-skills/factory-triage/SKILL.md +1 -1
  401. package/package.json +10 -10
@@ -1,11 +1,29 @@
1
1
  import { DEFAULT_ROUTE_EVENTS } from "../boards/board-events.js";
2
- import { intakeTargetProblem } from "../boards/intake-routing.js";
2
+ import { ROUTE_AGAIN_KEY_PREFIX, arrivalRuleFacts, compareIntakeOrder, intakeTargetProblem, projectIntakeEvaluator, resolveIntake } from "../boards/intake-routing.js";
3
3
  import { applyReroute, planReroute, summarizeReroute } from "../boards/reroute.js";
4
4
  import { StoredBoardError } from "../storage/domains/boards/base.js";
5
5
  import { FACTORY_ROUTE_CONTRACTS } from "./contracts.js";
6
+ import { IntakeCheck, IntakeCheckRefusal, isDraft } from "./intake-check.js";
6
7
  import { Route, loose } from "./route.js";
7
8
  import { registerApiRoute } from "@mastra/core/server";
8
9
  // src/routes/intake-routes.ts
10
+ function presentDecision(decision) {
11
+ const { boardKey, routeId, reason, sourceKey, title, url, decidedAt, id, outcome, evaluator } = decision;
12
+ return {
13
+ id,
14
+ outcome,
15
+ evaluator,
16
+ boardKey,
17
+ routeId,
18
+ reason,
19
+ sourceKey,
20
+ title,
21
+ url,
22
+ decidedAt
23
+ };
24
+ }
25
+ /** How far back the Rules page counts a card-move rule's skips. */
26
+ const SKIPPED_WINDOW_MS = 2592e6;
9
27
  /** A response the handler returns as is: a refusal or an error. */
10
28
  var Refusal = class {
11
29
  status;
@@ -92,23 +110,160 @@ var IntakeRouteRoutes = class extends Route {
92
110
  message: problem.message
93
111
  });
94
112
  }
113
+ #evaluator(scope) {
114
+ return projectIntakeEvaluator(this.deps.intakeEvaluator, this.deps.storage, scope);
115
+ }
116
+ async #order(scope, registry, evaluator) {
117
+ if (evaluator !== "intake-order") return [];
118
+ return (await this.deps.storage.readIntakeOrder(scope, { boards: [...registry.keys()] })).boardKeys.filter((key) => registry.has(key));
119
+ }
120
+ /** Pull requests link to the card of the issue they close on their own; a route can't join them any more. */
121
+ #refuseJoin(target, current) {
122
+ if (target?.joinClosedIssue === true && current?.joinClosedIssue !== true) throw new Refusal(422, {
123
+ error: "join_retired",
124
+ message: "Pull requests link to the card of the issue they close on their own. Use a card-move rule on pull_request.opened to move that card."
125
+ });
126
+ }
95
127
  async #planReroute(scope) {
96
128
  const [registry, routes, items] = await Promise.all([
97
129
  this.#registry(scope),
98
130
  this.deps.storage.listIntakeRoutes(scope),
99
131
  this.deps.workItems.listShared(scope)
100
132
  ]);
101
- return planReroute(routes, items, registry);
133
+ const evaluator = await this.#evaluator(scope);
134
+ return planReroute(routes, items, registry, {
135
+ evaluator,
136
+ order: await this.#order(scope, registry, evaluator)
137
+ });
138
+ }
139
+ async #canEdit(c, scope) {
140
+ const { auth } = this.deps;
141
+ return !auth.enabled() || await auth.isOrganizationAdmin(c, scope.orgId);
102
142
  }
103
143
  async #list(c, scope, routes) {
104
144
  const registry = await this.#registry(scope);
105
145
  routes ??= await this.deps.storage.listIntakeRoutes(scope);
106
- const { auth } = this.deps;
107
- const canEdit = !auth.enabled() || await auth.isOrganizationAdmin(c, scope.orgId);
108
146
  return c.json({
109
147
  intakeRoutes: routes.map((route) => present(route, registry)),
110
- canEdit
148
+ canEdit: await this.#canEdit(c, scope)
149
+ });
150
+ }
151
+ /** The project's boards in intake order: the stored order, with any board it lacks slotted in as a new one is. */
152
+ async #intakeOrder(c, scope) {
153
+ const registry = await this.#registry(scope);
154
+ const [stored, routes, cards, projectEvaluator] = await Promise.all([
155
+ this.deps.storage.readIntakeOrder(scope, { boards: [...registry.keys()] }),
156
+ this.deps.storage.listIntakeRoutes(scope),
157
+ this.deps.workItems.listShared(scope),
158
+ this.deps.storage.intakeEvaluator(scope)
159
+ ]);
160
+ const forced = this.deps.intakeEvaluator;
161
+ const listed = stored.boardKeys.filter((key) => registry.has(key));
162
+ const order = [...listed, ...[...registry.keys()].filter((key) => !listed.includes(key))];
163
+ return c.json({
164
+ boards: order.map((boardKey) => ({
165
+ boardKey,
166
+ name: registry.get(boardKey).name
167
+ })),
168
+ origin: stored.origin,
169
+ evaluator: forced ?? projectEvaluator ?? "route-list",
170
+ evaluatorSource: forced ? this.deps.intakeEvaluatorSource ?? "option" : projectEvaluator ? "project" : "legacy",
171
+ projectEvaluator,
172
+ comparison: compareIntakeOrder({
173
+ routes,
174
+ order,
175
+ registry,
176
+ cards
177
+ }),
178
+ canEdit: await this.#canEdit(c, scope)
179
+ });
180
+ }
181
+ #decisionId(c) {
182
+ const parsed = FACTORY_ROUTE_CONTRACTS.intakeRouteAgain.pathSchema.safeParse({
183
+ id: c.req.param("id"),
184
+ decisionId: c.req.param("decisionId")
111
185
  });
186
+ if (!parsed.success) throw new Refusal(404, { error: "intake_decision_not_found" });
187
+ return parsed.data.decisionId;
188
+ }
189
+ /**
190
+ * Runs intake again for an item no board took. Refuses while no board's rules take it; otherwise
191
+ * commits the item's arrival afresh, so the dispatcher files it as a new arrival would be.
192
+ */
193
+ async #routeAgain(c, scope) {
194
+ const { storage, workItems } = this.deps;
195
+ const decision = await storage.getIntakeDecision(scope, this.#decisionId(c));
196
+ if (!decision || decision.outcome !== "not_routed" || !decision.arrival) throw new Refusal(404, { error: "intake_decision_not_found" });
197
+ if (decision.resolvedAt) throw new Refusal(409, {
198
+ error: "intake_decision_resolved",
199
+ message: "This item has been filed since."
200
+ });
201
+ const arrival = decision.arrival;
202
+ const [registry, routes] = await Promise.all([this.#registry(scope), storage.listIntakeRoutes(scope)]);
203
+ const resolution = resolveIntake({
204
+ evaluator: "intake-order",
205
+ routes,
206
+ order: await this.#order(scope, registry, "intake-order"),
207
+ facts: await arrivalRuleFacts(arrival, {
208
+ factoryProjectId: scope.factoryProjectId,
209
+ registry,
210
+ card: (id) => workItems.get({
211
+ orgId: scope.orgId,
212
+ id
213
+ })
214
+ }),
215
+ registry
216
+ });
217
+ if (resolution.outcome === "not_routed") throw new Refusal(422, {
218
+ error: "intake_not_routed",
219
+ message: resolution.reason
220
+ });
221
+ if (resolution.routeId === null) throw new Refusal(422, {
222
+ error: "intake_not_routed",
223
+ message: "No board's intake rules match it."
224
+ });
225
+ const attempt = `${ROUTE_AGAIN_KEY_PREFIX}${decision.id}:${globalThis.crypto.randomUUID()}`;
226
+ await workItems.commitRuleEvaluation({
227
+ orgId: scope.orgId,
228
+ factoryProjectId: scope.factoryProjectId,
229
+ workItemId: null,
230
+ ingress: { identity: attempt },
231
+ expectedRevision: null,
232
+ actor: {
233
+ type: "system",
234
+ id: "factory-intake-route-again"
235
+ },
236
+ outcome: { status: "accepted" },
237
+ decisions: [{
238
+ ...arrival,
239
+ idempotencyKey: attempt
240
+ }],
241
+ causalChain: [],
242
+ now: /* @__PURE__ */ new Date()
243
+ });
244
+ await this.deps.audit.emit({
245
+ context: c,
246
+ input: {
247
+ action: "factory.intake.routed_again",
248
+ factoryProjectId: scope.factoryProjectId,
249
+ targets: [{
250
+ type: "intake_decision",
251
+ id: decision.id,
252
+ name: decision.title
253
+ }],
254
+ metadata: {
255
+ sourceKey: decision.sourceKey,
256
+ boardKey: resolution.board,
257
+ routeId: resolution.routeId
258
+ }
259
+ }
260
+ });
261
+ return c.json({
262
+ status: "queued",
263
+ boardKey: resolution.board,
264
+ phaseKey: resolution.phase,
265
+ routeId: resolution.routeId
266
+ }, 202);
112
267
  }
113
268
  async #respond(c, scope, route, status = 200) {
114
269
  return c.json({ intakeRoute: present(route, await this.#registry(scope)) }, status);
@@ -137,20 +292,138 @@ var IntakeRouteRoutes = class extends Route {
137
292
  return await handle(context);
138
293
  } catch (error) {
139
294
  if (error instanceof Refusal) return context.json(error.body, error.status);
295
+ if (error instanceof IntakeCheckRefusal) return context.json({
296
+ error: error.code,
297
+ message: error.message
298
+ }, error.status);
140
299
  if (error instanceof StoredBoardError) return context.json({
141
300
  error: error.code,
142
301
  message: error.message
143
- }, error.code === "intake_route_not_found" ? 404 : error.code === "invalid_intake_route" ? 422 : 409);
302
+ }, error.code === "intake_route_not_found" || error.code === "intake_decision_not_found" ? 404 : error.code === "invalid_intake_route" || error.code === "intake_route_limit" || error.code === "invalid_intake_cursor" ? 422 : 409);
144
303
  throw error;
145
304
  }
146
305
  }
147
306
  });
148
307
  }
308
+ /** Members read the saved rules; running a draft of them needs the right to edit them. */
309
+ async #check(c, schema) {
310
+ const scope = await this.#resolve(c);
311
+ const body = await this.#body(c, schema);
312
+ if (isDraft(body)) await this.#requireAdmin(c, scope);
313
+ return {
314
+ scope,
315
+ body,
316
+ check: new IntakeCheck({
317
+ storage: this.deps.storage,
318
+ workItems: this.deps.workItems,
319
+ ...this.deps.intakeLookups && { lookups: this.deps.intakeLookups }
320
+ }),
321
+ registry: await this.#registry(scope)
322
+ };
323
+ }
149
324
  routes() {
150
325
  const { storage } = this.deps;
151
326
  const contracts = FACTORY_ROUTE_CONTRACTS;
152
327
  return [
153
- this.#route(contracts.intakeRouteList, async (c) => this.#list(c, await this.#resolve(c))),
328
+ this.#route(contracts.intakeDryRun, async (c) => {
329
+ const { scope, body, check, registry } = await this.#check(c, contracts.intakeDryRun.bodySchema);
330
+ return c.json({
331
+ ...await check.dryRun(scope, registry, body),
332
+ evaluator: await this.#evaluator(scope),
333
+ canEdit: await this.#canEdit(c, scope)
334
+ });
335
+ }),
336
+ this.#route(contracts.intakeTest, async (c) => {
337
+ const { scope, body, check, registry } = await this.#check(c, contracts.intakeTest.bodySchema);
338
+ return c.json({
339
+ ...await check.test(scope, registry, body),
340
+ evaluator: await this.#evaluator(scope)
341
+ });
342
+ }),
343
+ this.#route(contracts.intakeRouteList, async (c) => {
344
+ const scope = await this.#resolve(c);
345
+ const query = contracts.intakeRouteList.querySchema.safeParse({ boardKey: c.req.query("boardKey") });
346
+ if (!query.success) throw new Refusal(422, {
347
+ error: "invalid_request",
348
+ message: issueMessage(query.error.issues)
349
+ });
350
+ const { boardKey } = query.data;
351
+ return this.#list(c, scope, boardKey === void 0 ? void 0 : await storage.listIntakeRoutes(scope, { boardKey }));
352
+ }),
353
+ this.#route(contracts.intakeOrderGet, async (c) => this.#intakeOrder(c, await this.#resolve(c))),
354
+ this.#route(contracts.intakeOrderUpdate, async (c) => {
355
+ const scope = await this.#resolve(c);
356
+ await this.#requireAdmin(c, scope);
357
+ const { boardKeys, evaluator } = await this.#body(c, contracts.intakeOrderUpdate.bodySchema);
358
+ const registry = await this.#registry(scope);
359
+ const targets = [{
360
+ type: "factory_project",
361
+ id: scope.factoryProjectId
362
+ }];
363
+ if (boardKeys) {
364
+ const before = await storage.readIntakeOrder(scope, { boards: [...registry.keys()] });
365
+ await storage.setIntakeOrder(scope, boardKeys, { boards: [...registry.keys()] });
366
+ await this.deps.audit.emit({
367
+ context: c,
368
+ input: {
369
+ action: "factory.intake_order.updated",
370
+ factoryProjectId: scope.factoryProjectId,
371
+ targets,
372
+ metadata: {
373
+ before: before.boardKeys,
374
+ after: boardKeys
375
+ }
376
+ }
377
+ });
378
+ }
379
+ if (evaluator) {
380
+ const before = await storage.setIntakeEvaluator(scope, evaluator);
381
+ if (before !== evaluator) await this.deps.audit.emit({
382
+ context: c,
383
+ input: {
384
+ action: "factory.intake_order.evaluator_updated",
385
+ factoryProjectId: scope.factoryProjectId,
386
+ targets,
387
+ metadata: {
388
+ before,
389
+ after: evaluator
390
+ }
391
+ }
392
+ });
393
+ }
394
+ return this.#intakeOrder(c, scope);
395
+ }),
396
+ this.#route(contracts.intakeNotRoutedList, async (c) => {
397
+ const scope = await this.#resolve(c);
398
+ const query = contracts.intakeNotRoutedList.querySchema.safeParse({
399
+ limit: c.req.query("limit"),
400
+ cursor: c.req.query("cursor")
401
+ });
402
+ if (!query.success) throw new Refusal(422, {
403
+ error: "invalid_request",
404
+ message: issueMessage(query.error.issues)
405
+ });
406
+ const page = await storage.listNotRouted(scope, query.data);
407
+ return c.json({
408
+ notRouted: page.notRouted.map(presentDecision),
409
+ nextCursor: page.nextCursor,
410
+ canEdit: await this.#canEdit(c, scope)
411
+ });
412
+ }),
413
+ this.#route(contracts.intakeSkippedList, async (c) => {
414
+ const scope = await this.#resolve(c);
415
+ const summary = await storage.summarizeSkippedByRoute(scope, /* @__PURE__ */ new Date(Date.now() - SKIPPED_WINDOW_MS));
416
+ return c.json({ skipped: Object.entries(summary).map(([routeId, { count, latest }]) => ({
417
+ routeId,
418
+ count,
419
+ latest: presentDecision(latest)
420
+ })) });
421
+ }),
422
+ this.#route(contracts.intakeRouteAgain, async (c) => {
423
+ const scope = await this.#resolve(c);
424
+ await this.#requireAdmin(c, scope);
425
+ return this.#routeAgain(c, scope);
426
+ }),
154
427
  this.#route(contracts.intakeRouteReroutePreview, async (c) => {
155
428
  const scope = await this.#resolve(c);
156
429
  const moves = await this.#planReroute(scope);
@@ -189,8 +462,8 @@ var IntakeRouteRoutes = class extends Route {
189
462
  this.#route(contracts.intakeRouteReorder, async (c) => {
190
463
  const scope = await this.#resolve(c);
191
464
  await this.#requireAdmin(c, scope);
192
- const { ids } = await this.#body(c, contracts.intakeRouteReorder.bodySchema);
193
- const routes = await storage.reorderIntakeRoutes(scope, ids, scope.userId);
465
+ const { ids, boardKey } = await this.#body(c, contracts.intakeRouteReorder.bodySchema);
466
+ const routes = await storage.reorderIntakeRoutes(scope, ids, scope.userId, boardKey === void 0 ? {} : { boardKey });
194
467
  await this.#audit(c, scope, "reordered", routes);
195
468
  return this.#list(c, scope, routes);
196
469
  }),
@@ -204,9 +477,11 @@ var IntakeRouteRoutes = class extends Route {
204
477
  const scope = await this.#resolve(c);
205
478
  await this.#requireAdmin(c, scope);
206
479
  const input = await this.#body(c, contracts.intakeRouteCreate.bodySchema);
480
+ this.#refuseJoin(input.target);
207
481
  await this.#checkTarget(scope, {
208
482
  target: input.target,
209
- on: input.on ?? DEFAULT_ROUTE_EVENTS
483
+ on: input.on ?? DEFAULT_ROUTE_EVENTS,
484
+ pullRequestOpenedMovesOnly: input.pullRequestOpenedMovesOnly
210
485
  });
211
486
  const route = await storage.createIntakeRoute(scope, input, scope.userId);
212
487
  await this.#audit(c, scope, "created", [route]);
@@ -220,9 +495,15 @@ var IntakeRouteRoutes = class extends Route {
220
495
  if (patch.target || patch.on) {
221
496
  const current = await storage.getIntakeRoute(scope, id);
222
497
  if (!current) throw new Refusal(404, { error: "intake_route_not_found" });
498
+ this.#refuseJoin(patch.target, current.target);
499
+ if (await this.#evaluator(scope) === "intake-order" && patch.target && patch.target.boardKey !== current.target.boardKey) throw new Refusal(422, {
500
+ error: "intake_route_board_fixed",
501
+ message: `This rule belongs to board "${current.target.boardKey}"; add a rule on the other board instead.`
502
+ });
223
503
  await this.#checkTarget(scope, {
224
504
  target: patch.target ?? current.target,
225
- on: patch.on ?? current.on
505
+ on: patch.on ?? current.on,
506
+ pullRequestOpenedMovesOnly: current.pullRequestOpenedMovesOnly
226
507
  });
227
508
  }
228
509
  const route = await storage.updateIntakeRoute(scope, id, patch, {
@@ -1 +1 @@
1
- {"version":3,"file":"intake-routes.js","names":[],"sources":["../../src/routes/intake-routes.ts"],"sourcesContent":["/**\n * Mastra `apiRoutes` for managing a project's intake routes: the ordered rules that place new\n * cards on a board and phase when they arrive.\n *\n * Reads need a signed-in user of the project's organization; writes need an organization admin in\n * tenant mode. A route's target must be an installed board and a phase new cards can reach when it\n * is written; a target that\n * stops existing later is reported in `problems` and skipped when cards arrive.\n */\n\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\nimport type { z } from 'zod';\n\nimport { DEFAULT_ROUTE_EVENTS } from '../boards/board-events.js';\nimport type { StatusEvent } from '../boards/board-events.js';\nimport { intakeTargetProblem } from '../boards/intake-routing.js';\nimport type { ProjectBoardCache } from '../boards/project-boards.js';\nimport type { BoardRegistry } from '../boards/registry.js';\nimport { applyReroute, planReroute, summarizeReroute } from '../boards/reroute.js';\nimport type { AuditEmitter } from '../storage/domains/audit/domain.js';\nimport { StoredBoardError } from '../storage/domains/boards/base.js';\nimport type { StoredBoardScope, StoredBoardsStorage, StoredIntakeRouteRecord } from '../storage/domains/boards/base.js';\nimport type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { FACTORY_ROUTE_CONTRACTS } from './contracts.js';\nimport type { RouteDependencies } from './route.js';\nimport { loose, Route } from './route.js';\n\nexport interface IntakeRouteRoutesDeps extends RouteDependencies {\n audit: AuditEmitter;\n projects: FactoryProjectsStorage;\n storage: StoredBoardsStorage;\n /** Cards an intake route change may move to another board. */\n workItems: Pick<WorkItemsStorage, 'listShared' | 'update' | 'supersedeDecisionsForWorkItem'>;\n /** The project's installed boards, to check route targets against. */\n boards: Pick<ProjectBoardCache, 'describe'>;\n}\n\ntype Resolved = StoredBoardScope & { userId: string };\n\n/** A response the handler returns as is: a refusal or an error. */\nclass Refusal {\n constructor(\n readonly status: 400 | 401 | 403 | 404 | 409 | 422,\n readonly body: Record<string, unknown>,\n ) {}\n}\n\nfunction issueMessage(issues: readonly z.core.$ZodIssue[]): string {\n return issues\n .map(issue => (issue.path.length > 0 ? `${issue.path.join('.')}: ${issue.message}` : issue.message))\n .join('; ');\n}\n\nfunction present(route: StoredIntakeRouteRecord, registry: BoardRegistry) {\n const { orgId: _orgId, factoryProjectId: _project, ...fields } = route;\n const problem = intakeTargetProblem(registry, route);\n return { ...fields, problems: problem ? [problem.message] : [] };\n}\n\nexport class IntakeRouteRoutes extends Route<IntakeRouteRoutesDeps> {\n async #resolve(c: Context): Promise<Resolved> {\n const { auth, projects } = this.deps;\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) throw new Refusal(401, { error: 'unauthorized' });\n if (!tenant.orgId) {\n throw new Refusal(403, { error: 'organization_required', message: 'Intake routes belong to an organization.' });\n }\n const parsed = FACTORY_ROUTE_CONTRACTS.intakeRouteList.pathSchema.safeParse({ id: c.req.param('id') });\n if (!parsed.success) throw new Refusal(404, { error: 'Project not found' });\n await projects.ensureReady();\n if (!(await projects.get({ orgId: tenant.orgId, id: parsed.data.id }))) {\n throw new Refusal(404, { error: 'Project not found' });\n }\n return { orgId: tenant.orgId, userId: tenant.userId, factoryProjectId: parsed.data.id };\n }\n\n async #requireAdmin(c: Context, scope: Resolved): Promise<void> {\n const { auth } = this.deps;\n if (auth.enabled() && !(await auth.isOrganizationAdmin(c, scope.orgId))) {\n throw new Refusal(403, {\n error: 'organization_admin_required',\n message: 'Organization administrator access is required to change intake routes.',\n });\n }\n }\n\n async #body<T>(c: Context, schema: z.ZodType<T>): Promise<T> {\n let body: unknown;\n try {\n body = await c.req.json();\n } catch {\n throw new Refusal(400, { error: 'invalid_request', message: 'Invalid JSON body.' });\n }\n const parsed = schema.safeParse(body);\n if (!parsed.success) {\n throw new Refusal(422, { error: 'invalid_intake_route', message: issueMessage(parsed.error.issues) });\n }\n return parsed.data;\n }\n\n #routeId(c: Context): string {\n const parsed = FACTORY_ROUTE_CONTRACTS.intakeRouteGet.pathSchema.safeParse({\n id: c.req.param('id'),\n routeId: c.req.param('routeId'),\n });\n if (!parsed.success) throw new Refusal(404, { error: 'intake_route_not_found' });\n return parsed.data.routeId;\n }\n\n async #registry(scope: Resolved): Promise<BoardRegistry> {\n return (await this.deps.boards.describe(scope)).registry;\n }\n\n /** Refuses a target that isn't an installed board and phase, or, for a route placing new cards, one they can't land in. */\n async #checkTarget(\n scope: Resolved,\n route: {\n target: { boardKey: string; phaseKey?: string | null; joinClosedIssue?: boolean };\n on: readonly StatusEvent[];\n },\n ) {\n const problem = intakeTargetProblem(await this.#registry(scope), route);\n if (problem) throw new Refusal(422, { error: problem.code, message: problem.message });\n }\n\n async #planReroute(scope: Resolved) {\n const [registry, routes, items] = await Promise.all([\n this.#registry(scope),\n this.deps.storage.listIntakeRoutes(scope),\n this.deps.workItems.listShared(scope),\n ]);\n return planReroute(routes, items, registry);\n }\n\n async #list(c: Context, scope: Resolved, routes?: StoredIntakeRouteRecord[]) {\n const registry = await this.#registry(scope);\n routes ??= await this.deps.storage.listIntakeRoutes(scope);\n const { auth } = this.deps;\n const canEdit = !auth.enabled() || (await auth.isOrganizationAdmin(c, scope.orgId));\n return c.json({ intakeRoutes: routes.map(route => present(route, registry)), canEdit });\n }\n\n async #respond(c: Context, scope: Resolved, route: StoredIntakeRouteRecord, status: 200 | 201 = 200) {\n return c.json({ intakeRoute: present(route, await this.#registry(scope)) }, status);\n }\n\n async #audit(\n c: Context,\n scope: Resolved,\n action: 'created' | 'updated' | 'deleted' | 'reordered',\n targets: { id: string; name: string }[],\n ) {\n await this.deps.audit.emit({\n context: c,\n input: {\n action: `factory.intake_route.${action}`,\n factoryProjectId: scope.factoryProjectId,\n targets: targets.map(route => ({ type: 'intake_route', id: route.id, name: route.name })),\n },\n });\n }\n\n #route(\n contract: { path: string; method: 'GET' | 'POST' | 'PATCH' | 'DELETE' },\n handle: (c: Context) => Promise<Response>,\n ): ApiRoute {\n return registerApiRoute(contract.path, {\n method: contract.method,\n requiresAuth: false,\n handler: async c => {\n const context = loose(c);\n try {\n return await handle(context);\n } catch (error) {\n if (error instanceof Refusal) return context.json(error.body, error.status);\n if (error instanceof StoredBoardError) {\n return context.json(\n { error: error.code, message: error.message },\n error.code === 'intake_route_not_found' ? 404 : error.code === 'invalid_intake_route' ? 422 : 409,\n );\n }\n throw error;\n }\n },\n });\n }\n\n routes(): ApiRoute[] {\n const { storage } = this.deps;\n const contracts = FACTORY_ROUTE_CONTRACTS;\n return [\n this.#route(contracts.intakeRouteList, async c => this.#list(c, await this.#resolve(c))),\n\n this.#route(contracts.intakeRouteReroutePreview, async c => {\n const scope = await this.#resolve(c);\n const moves = await this.#planReroute(scope);\n return c.json({ total: moves.length, moves: summarizeReroute(moves) });\n }),\n\n this.#route(contracts.intakeRouteRerouteApply, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const moves = await this.#planReroute(scope);\n const result = await applyReroute({\n moves,\n workItems: this.deps.workItems,\n registry: await this.#registry(scope),\n userId: scope.userId,\n });\n await this.deps.audit.emit({\n context: c,\n input: {\n action: 'factory.intake_route.rerouted',\n factoryProjectId: scope.factoryProjectId,\n targets: [...new Set(moves.map(move => move.routeId))].map(id => ({ type: 'intake_route', id })),\n metadata: { ...result, moves: summarizeReroute(moves) },\n },\n });\n return c.json(result);\n }),\n\n this.#route(contracts.intakeRouteReorder, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const { ids } = await this.#body(c, contracts.intakeRouteReorder.bodySchema);\n const routes = await storage.reorderIntakeRoutes(scope, ids, scope.userId);\n await this.#audit(c, scope, 'reordered', routes);\n return this.#list(c, scope, routes);\n }),\n\n this.#route(contracts.intakeRouteGet, async c => {\n const scope = await this.#resolve(c);\n const route = await storage.getIntakeRoute(scope, this.#routeId(c));\n if (!route) throw new Refusal(404, { error: 'intake_route_not_found' });\n return this.#respond(c, scope, route);\n }),\n\n this.#route(contracts.intakeRouteCreate, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const input = await this.#body(c, contracts.intakeRouteCreate.bodySchema);\n await this.#checkTarget(scope, { target: input.target, on: input.on ?? DEFAULT_ROUTE_EVENTS });\n const route = await storage.createIntakeRoute(scope, input, scope.userId);\n await this.#audit(c, scope, 'created', [route]);\n return this.#respond(c, scope, route, 201);\n }),\n\n this.#route(contracts.intakeRouteUpdate, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const id = this.#routeId(c);\n const { expectedRevision, ...patch } = await this.#body(c, contracts.intakeRouteUpdate.bodySchema);\n if (patch.target || patch.on) {\n // Narrowing or widening `on` changes which targets are allowed, so check the route as it will be.\n const current = await storage.getIntakeRoute(scope, id);\n if (!current) throw new Refusal(404, { error: 'intake_route_not_found' });\n await this.#checkTarget(scope, { target: patch.target ?? current.target, on: patch.on ?? current.on });\n }\n const route = await storage.updateIntakeRoute(scope, id, patch, { expectedRevision, actor: scope.userId });\n await this.#audit(c, scope, 'updated', [route]);\n return this.#respond(c, scope, route);\n }),\n\n this.#route(contracts.intakeRouteDelete, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const id = this.#routeId(c);\n const parsed = contracts.intakeRouteDelete.querySchema.safeParse({\n expectedRevision: c.req.query('expectedRevision'),\n });\n if (!parsed.success) {\n throw new Refusal(422, { error: 'invalid_request', message: issueMessage(parsed.error.issues) });\n }\n const route = await storage.getIntakeRoute(scope, id);\n if (!route) throw new Refusal(404, { error: 'intake_route_not_found' });\n await storage.deleteIntakeRoute(scope, id, { expectedRevision: parsed.data.expectedRevision });\n await this.#audit(c, scope, 'deleted', [route]);\n return c.body(null, 204);\n }),\n ];\n }\n}\n"],"mappings":";;;;;;;;;AA2CA,IAAM,UAAN,MAAc;CAED;CACA;CAFX,YACE,QACA,MACA;EAFS,KAAA,SAAA;EACA,KAAA,OAAA;CACR;AACL;AAEA,SAAS,aAAa,QAA6C;CACjE,OAAO,OACJ,KAAI,UAAU,MAAM,KAAK,SAAS,IAAI,GAAG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QAAQ,KAAK,EAAE,OAAO,yBAAyB,CAAC;KACxE,MAAM,KAAK,aAAa,OAAO;MAAE,QAAQ,MAAM,UAAU,QAAQ;MAAQ,IAAI,MAAM,MAAM,QAAQ;KAAG,CAAC;IACvG;IACA,MAAM,QAAQ,MAAM,QAAQ,kBAAkB,OAAO,IAAI,OAAO;KAAE;KAAkB,OAAO,MAAM;IAAO,CAAC;IACzG,MAAM,KAAK,OAAO,GAAG,OAAO,WAAW,CAAC,KAAK,CAAC;IAC9C,OAAO,KAAK,SAAS,GAAG,OAAO,KAAK;GACtC,CAAC;GAED,KAAK,OAAO,UAAU,mBAAmB,OAAM,MAAK;IAClD,MAAM,QAAQ,MAAM,KAAK,SAAS,CAAC;IACnC,MAAM,KAAK,cAAc,GAAG,KAAK;IACjC,MAAM,KAAK,KAAK,SAAS,CAAC;IAC1B,MAAM,SAAS,UAAU,kBAAkB,YAAY,UAAU,EAC/D,kBAAkB,EAAE,IAAI,MAAM,kBAAkB,EAClD,CAAC;IACD,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,QAAQ,KAAK;KAAE,OAAO;KAAmB,SAAS,aAAa,OAAO,MAAM,MAAM;IAAE,CAAC;IAEjG,MAAM,QAAQ,MAAM,QAAQ,eAAe,OAAO,EAAE;IACpD,IAAI,CAAC,OAAO,MAAM,IAAI,QAAQ,KAAK,EAAE,OAAO,yBAAyB,CAAC;IACtE,MAAM,QAAQ,kBAAkB,OAAO,IAAI,EAAE,kBAAkB,OAAO,KAAK,iBAAiB,CAAC;IAC7F,MAAM,KAAK,OAAO,GAAG,OAAO,WAAW,CAAC,KAAK,CAAC;IAC9C,OAAO,EAAE,KAAK,MAAM,GAAG;GACzB,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"intake-routes.js","names":[],"sources":["../../src/routes/intake-routes.ts"],"sourcesContent":["/**\n * Mastra `apiRoutes` for managing a project's intake routes: the ordered rules that place new\n * cards on a board and phase when they arrive.\n *\n * Reads need a signed-in user of the project's organization; writes need an organization admin in\n * tenant mode. A route's target must be an installed board and a phase new cards can reach when it\n * is written; a target that\n * stops existing later is reported in `problems` and skipped when cards arrive.\n */\n\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\nimport type { z } from 'zod';\nimport { DEFAULT_ROUTE_EVENTS } from '../boards/board-events.js';\n\nimport type { RouteEvent } from '../boards/board-events.js';\nimport type { IntakeItemLookup } from '../boards/intake-lookup.js';\nimport {\n arrivalRuleFacts,\n compareIntakeOrder,\n intakeTargetProblem,\n projectIntakeEvaluator,\n resolveIntake,\n ROUTE_AGAIN_KEY_PREFIX,\n} from '../boards/intake-routing.js';\nimport type { ForcedIntakeEvaluator } from '../boards/intake-routing.js';\nimport type { ProjectBoardCache } from '../boards/project-boards.js';\nimport type { BoardRegistry } from '../boards/registry.js';\nimport { applyReroute, planReroute, summarizeReroute } from '../boards/reroute.js';\nimport type { FactoryCommitDecision } from '../rules/types.js';\nimport type { AuditEmitter } from '../storage/domains/audit/domain.js';\nimport { StoredBoardError } from '../storage/domains/boards/base.js';\nimport type {\n IntakeEvaluator,\n StoredBoardScope,\n StoredBoardsStorage,\n StoredIntakeDecisionRecord,\n StoredIntakeRouteRecord,\n} from '../storage/domains/boards/base.js';\nimport type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';\nimport type { WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { FACTORY_ROUTE_CONTRACTS } from './contracts.js';\nimport { IntakeCheck, IntakeCheckRefusal, isDraft } from './intake-check.js';\nimport type { RouteDependencies } from './route.js';\nimport { loose, Route } from './route.js';\n\nexport interface IntakeRouteRoutesDeps extends RouteDependencies {\n audit: AuditEmitter;\n projects: FactoryProjectsStorage;\n storage: StoredBoardsStorage;\n /** Cards an intake route change may move to another board. */\n workItems: Pick<\n WorkItemsStorage,\n | 'listShared'\n | 'update'\n | 'supersedeDecisionsForWorkItem'\n | 'get'\n | 'commitRuleEvaluation'\n | 'listDeferredDecisions'\n | 'getTransitionResultByIngress'\n >;\n /** The project's installed boards, to check route targets against. */\n boards: Pick<ProjectBoardCache, 'describe'>;\n /** Forces an evaluator on every project; without it each project uses its own setting. */\n intakeEvaluator?: IntakeEvaluator;\n /** What forced `intakeEvaluator`. */\n intakeEvaluatorSource?: ForcedIntakeEvaluator['source'];\n /** Providers the tester can read an unseen item from by URL. */\n intakeLookups?: readonly IntakeItemLookup[];\n}\n\ntype LinkedDecision = Extract<FactoryCommitDecision, { type: 'upsertLinkedWorkItem' }>;\n\nfunction presentDecision(decision: StoredIntakeDecisionRecord) {\n const { boardKey, routeId, reason, sourceKey, title, url, decidedAt, id, outcome, evaluator } = decision;\n return { id, outcome, evaluator, boardKey, routeId, reason, sourceKey, title, url, decidedAt };\n}\n\n/** How far back the Rules page counts a card-move rule's skips. */\nconst SKIPPED_WINDOW_MS = 30 * 24 * 60 * 60 * 1000;\n\ntype Resolved = StoredBoardScope & { userId: string };\n\n/** A response the handler returns as is: a refusal or an error. */\nclass Refusal {\n constructor(\n readonly status: 400 | 401 | 403 | 404 | 409 | 422,\n readonly body: Record<string, unknown>,\n ) {}\n}\n\nfunction issueMessage(issues: readonly z.core.$ZodIssue[]): string {\n return issues\n .map(issue => (issue.path.length > 0 ? `${issue.path.join('.')}: ${issue.message}` : issue.message))\n .join('; ');\n}\n\nfunction present(route: StoredIntakeRouteRecord, registry: BoardRegistry) {\n const { orgId: _orgId, factoryProjectId: _project, ...fields } = route;\n const problem = intakeTargetProblem(registry, route);\n return { ...fields, problems: problem ? [problem.message] : [] };\n}\n\nexport class IntakeRouteRoutes extends Route<IntakeRouteRoutesDeps> {\n async #resolve(c: Context): Promise<Resolved> {\n const { auth, projects } = this.deps;\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) throw new Refusal(401, { error: 'unauthorized' });\n if (!tenant.orgId) {\n throw new Refusal(403, { error: 'organization_required', message: 'Intake routes belong to an organization.' });\n }\n const parsed = FACTORY_ROUTE_CONTRACTS.intakeRouteList.pathSchema.safeParse({ id: c.req.param('id') });\n if (!parsed.success) throw new Refusal(404, { error: 'Project not found' });\n await projects.ensureReady();\n if (!(await projects.get({ orgId: tenant.orgId, id: parsed.data.id }))) {\n throw new Refusal(404, { error: 'Project not found' });\n }\n return { orgId: tenant.orgId, userId: tenant.userId, factoryProjectId: parsed.data.id };\n }\n\n async #requireAdmin(c: Context, scope: Resolved): Promise<void> {\n const { auth } = this.deps;\n if (auth.enabled() && !(await auth.isOrganizationAdmin(c, scope.orgId))) {\n throw new Refusal(403, {\n error: 'organization_admin_required',\n message: 'Organization administrator access is required to change intake routes.',\n });\n }\n }\n\n async #body<T>(c: Context, schema: z.ZodType<T>): Promise<T> {\n let body: unknown;\n try {\n body = await c.req.json();\n } catch {\n throw new Refusal(400, { error: 'invalid_request', message: 'Invalid JSON body.' });\n }\n const parsed = schema.safeParse(body);\n if (!parsed.success) {\n throw new Refusal(422, { error: 'invalid_intake_route', message: issueMessage(parsed.error.issues) });\n }\n return parsed.data;\n }\n\n #routeId(c: Context): string {\n const parsed = FACTORY_ROUTE_CONTRACTS.intakeRouteGet.pathSchema.safeParse({\n id: c.req.param('id'),\n routeId: c.req.param('routeId'),\n });\n if (!parsed.success) throw new Refusal(404, { error: 'intake_route_not_found' });\n return parsed.data.routeId;\n }\n\n async #registry(scope: Resolved): Promise<BoardRegistry> {\n return (await this.deps.boards.describe(scope)).registry;\n }\n\n /** Refuses a target that isn't an installed board and phase, or, for a route placing new cards, one they can't land in. */\n async #checkTarget(\n scope: Resolved,\n route: {\n target: { boardKey: string; phaseKey?: string | null; joinClosedIssue?: boolean; moveToBoardKey?: string | null };\n on: readonly RouteEvent[];\n pullRequestOpenedMovesOnly?: boolean;\n },\n ) {\n const problem = intakeTargetProblem(await this.#registry(scope), route);\n if (problem) throw new Refusal(422, { error: problem.code, message: problem.message });\n }\n\n #evaluator(scope: Resolved): Promise<IntakeEvaluator> {\n return projectIntakeEvaluator(this.deps.intakeEvaluator, this.deps.storage, scope);\n }\n\n async #order(scope: Resolved, registry: BoardRegistry, evaluator: IntakeEvaluator): Promise<string[]> {\n if (evaluator !== 'intake-order') return [];\n const order = await this.deps.storage.readIntakeOrder(scope, { boards: [...registry.keys()] });\n return order.boardKeys.filter(key => registry.has(key));\n }\n\n /** Pull requests link to the card of the issue they close on their own; a route can't join them any more. */\n #refuseJoin(target: { joinClosedIssue?: boolean } | undefined, current?: { joinClosedIssue: boolean }) {\n if (target?.joinClosedIssue === true && current?.joinClosedIssue !== true) {\n throw new Refusal(422, {\n error: 'join_retired',\n message:\n 'Pull requests link to the card of the issue they close on their own. Use a card-move rule on pull_request.opened to move that card.',\n });\n }\n }\n\n async #planReroute(scope: Resolved) {\n const [registry, routes, items] = await Promise.all([\n this.#registry(scope),\n this.deps.storage.listIntakeRoutes(scope),\n this.deps.workItems.listShared(scope),\n ]);\n const evaluator = await this.#evaluator(scope);\n return planReroute(routes, items, registry, { evaluator, order: await this.#order(scope, registry, evaluator) });\n }\n\n async #canEdit(c: Context, scope: Resolved): Promise<boolean> {\n const { auth } = this.deps;\n return !auth.enabled() || (await auth.isOrganizationAdmin(c, scope.orgId));\n }\n\n async #list(c: Context, scope: Resolved, routes?: StoredIntakeRouteRecord[]) {\n const registry = await this.#registry(scope);\n routes ??= await this.deps.storage.listIntakeRoutes(scope);\n return c.json({\n intakeRoutes: routes.map(route => present(route, registry)),\n canEdit: await this.#canEdit(c, scope),\n });\n }\n\n /** The project's boards in intake order: the stored order, with any board it lacks slotted in as a new one is. */\n async #intakeOrder(c: Context, scope: Resolved) {\n const registry = await this.#registry(scope);\n const [stored, routes, cards, projectEvaluator] = await Promise.all([\n this.deps.storage.readIntakeOrder(scope, { boards: [...registry.keys()] }),\n this.deps.storage.listIntakeRoutes(scope),\n this.deps.workItems.listShared(scope),\n this.deps.storage.intakeEvaluator(scope),\n ]);\n const forced = this.deps.intakeEvaluator;\n const listed = stored.boardKeys.filter(key => registry.has(key));\n const order = [...listed, ...[...registry.keys()].filter(key => !listed.includes(key))];\n return c.json({\n boards: order.map(boardKey => ({ boardKey, name: registry.get(boardKey)!.name })),\n origin: stored.origin,\n evaluator: forced ?? projectEvaluator ?? 'route-list',\n evaluatorSource: forced ? (this.deps.intakeEvaluatorSource ?? 'option') : projectEvaluator ? 'project' : 'legacy',\n projectEvaluator,\n // Worked out on every read, so it always describes the order in force and today's rules.\n comparison: compareIntakeOrder({ routes, order, registry, cards }),\n canEdit: await this.#canEdit(c, scope),\n });\n }\n\n #decisionId(c: Context): string {\n const parsed = FACTORY_ROUTE_CONTRACTS.intakeRouteAgain.pathSchema.safeParse({\n id: c.req.param('id'),\n decisionId: c.req.param('decisionId'),\n });\n if (!parsed.success) throw new Refusal(404, { error: 'intake_decision_not_found' });\n return parsed.data.decisionId;\n }\n\n /**\n * Runs intake again for an item no board took. Refuses while no board's rules take it; otherwise\n * commits the item's arrival afresh, so the dispatcher files it as a new arrival would be.\n */\n async #routeAgain(c: Context, scope: Resolved) {\n const { storage, workItems } = this.deps;\n const decision = await storage.getIntakeDecision(scope, this.#decisionId(c));\n if (!decision || decision.outcome !== 'not_routed' || !decision.arrival) {\n throw new Refusal(404, { error: 'intake_decision_not_found' });\n }\n if (decision.resolvedAt) {\n throw new Refusal(409, { error: 'intake_decision_resolved', message: 'This item has been filed since.' });\n }\n const arrival = decision.arrival as unknown as LinkedDecision;\n const [registry, routes] = await Promise.all([this.#registry(scope), storage.listIntakeRoutes(scope)]);\n // Only intake order leaves an item Not routed, so it decides again whatever this replica runs.\n const resolution = resolveIntake({\n evaluator: 'intake-order',\n routes,\n order: await this.#order(scope, registry, 'intake-order'),\n facts: await arrivalRuleFacts(arrival, {\n factoryProjectId: scope.factoryProjectId,\n registry,\n card: id => workItems.get({ orgId: scope.orgId, id }),\n }),\n registry,\n });\n if (resolution.outcome === 'not_routed') {\n throw new Refusal(422, { error: 'intake_not_routed', message: resolution.reason });\n }\n if (resolution.routeId === null) {\n throw new Refusal(422, { error: 'intake_not_routed', message: \"No board's intake rules match it.\" });\n }\n const attempt = `${ROUTE_AGAIN_KEY_PREFIX}${decision.id}:${globalThis.crypto.randomUUID()}`;\n await workItems.commitRuleEvaluation({\n orgId: scope.orgId,\n factoryProjectId: scope.factoryProjectId,\n workItemId: null,\n ingress: { identity: attempt },\n expectedRevision: null,\n actor: { type: 'system', id: 'factory-intake-route-again' },\n outcome: { status: 'accepted' },\n decisions: [{ ...arrival, idempotencyKey: attempt }],\n causalChain: [],\n now: new Date(),\n });\n await this.deps.audit.emit({\n context: c,\n input: {\n action: 'factory.intake.routed_again',\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'intake_decision', id: decision.id, name: decision.title }],\n metadata: { sourceKey: decision.sourceKey, boardKey: resolution.board, routeId: resolution.routeId },\n },\n });\n return c.json(\n { status: 'queued', boardKey: resolution.board, phaseKey: resolution.phase, routeId: resolution.routeId },\n 202,\n );\n }\n\n async #respond(c: Context, scope: Resolved, route: StoredIntakeRouteRecord, status: 200 | 201 = 200) {\n return c.json({ intakeRoute: present(route, await this.#registry(scope)) }, status);\n }\n\n async #audit(\n c: Context,\n scope: Resolved,\n action: 'created' | 'updated' | 'deleted' | 'reordered',\n targets: { id: string; name: string }[],\n ) {\n await this.deps.audit.emit({\n context: c,\n input: {\n action: `factory.intake_route.${action}`,\n factoryProjectId: scope.factoryProjectId,\n targets: targets.map(route => ({ type: 'intake_route', id: route.id, name: route.name })),\n },\n });\n }\n\n #route(\n contract: { path: string; method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' },\n handle: (c: Context) => Promise<Response>,\n ): ApiRoute {\n return registerApiRoute(contract.path, {\n method: contract.method,\n requiresAuth: false,\n handler: async c => {\n const context = loose(c);\n try {\n return await handle(context);\n } catch (error) {\n if (error instanceof Refusal) return context.json(error.body, error.status);\n if (error instanceof IntakeCheckRefusal) {\n return context.json({ error: error.code, message: error.message }, error.status);\n }\n if (error instanceof StoredBoardError) {\n return context.json(\n { error: error.code, message: error.message },\n error.code === 'intake_route_not_found' || error.code === 'intake_decision_not_found'\n ? 404\n : error.code === 'invalid_intake_route' ||\n error.code === 'intake_route_limit' ||\n error.code === 'invalid_intake_cursor'\n ? 422\n : 409,\n );\n }\n throw error;\n }\n },\n });\n }\n\n /** Members read the saved rules; running a draft of them needs the right to edit them. */\n async #check<T extends { boards?: unknown; order?: unknown }>(c: Context, schema: z.ZodType<T>) {\n const scope = await this.#resolve(c);\n const body = await this.#body(c, schema);\n if (isDraft(body)) await this.#requireAdmin(c, scope);\n const check = new IntakeCheck({\n storage: this.deps.storage,\n workItems: this.deps.workItems,\n ...(this.deps.intakeLookups && { lookups: this.deps.intakeLookups }),\n });\n return { scope, body, check, registry: await this.#registry(scope) };\n }\n\n routes(): ApiRoute[] {\n const { storage } = this.deps;\n const contracts = FACTORY_ROUTE_CONTRACTS;\n return [\n this.#route(contracts.intakeDryRun, async c => {\n const { scope, body, check, registry } = await this.#check(c, contracts.intakeDryRun.bodySchema);\n return c.json({\n ...(await check.dryRun(scope, registry, body)),\n evaluator: await this.#evaluator(scope),\n canEdit: await this.#canEdit(c, scope),\n });\n }),\n\n this.#route(contracts.intakeTest, async c => {\n const { scope, body, check, registry } = await this.#check(c, contracts.intakeTest.bodySchema);\n return c.json({ ...(await check.test(scope, registry, body)), evaluator: await this.#evaluator(scope) });\n }),\n\n this.#route(contracts.intakeRouteList, async c => {\n const scope = await this.#resolve(c);\n const query = contracts.intakeRouteList.querySchema.safeParse({ boardKey: c.req.query('boardKey') });\n if (!query.success) {\n throw new Refusal(422, { error: 'invalid_request', message: issueMessage(query.error.issues) });\n }\n const { boardKey } = query.data;\n return this.#list(\n c,\n scope,\n boardKey === undefined ? undefined : await storage.listIntakeRoutes(scope, { boardKey }),\n );\n }),\n\n this.#route(contracts.intakeOrderGet, async c => this.#intakeOrder(c, await this.#resolve(c))),\n\n this.#route(contracts.intakeOrderUpdate, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const { boardKeys, evaluator } = await this.#body(c, contracts.intakeOrderUpdate.bodySchema);\n const registry = await this.#registry(scope);\n const targets = [{ type: 'factory_project', id: scope.factoryProjectId }];\n if (boardKeys) {\n const before = await storage.readIntakeOrder(scope, { boards: [...registry.keys()] });\n await storage.setIntakeOrder(scope, boardKeys, { boards: [...registry.keys()] });\n await this.deps.audit.emit({\n context: c,\n input: {\n action: 'factory.intake_order.updated',\n factoryProjectId: scope.factoryProjectId,\n targets,\n metadata: { before: before.boardKeys, after: boardKeys },\n },\n });\n }\n if (evaluator) {\n const before = await storage.setIntakeEvaluator(scope, evaluator);\n if (before !== evaluator) {\n await this.deps.audit.emit({\n context: c,\n input: {\n action: 'factory.intake_order.evaluator_updated',\n factoryProjectId: scope.factoryProjectId,\n targets,\n metadata: { before, after: evaluator },\n },\n });\n }\n }\n return this.#intakeOrder(c, scope);\n }),\n\n this.#route(contracts.intakeNotRoutedList, async c => {\n const scope = await this.#resolve(c);\n const query = contracts.intakeNotRoutedList.querySchema.safeParse({\n limit: c.req.query('limit'),\n cursor: c.req.query('cursor'),\n });\n if (!query.success) {\n throw new Refusal(422, { error: 'invalid_request', message: issueMessage(query.error.issues) });\n }\n const page = await storage.listNotRouted(scope, query.data);\n return c.json({\n notRouted: page.notRouted.map(presentDecision),\n nextCursor: page.nextCursor,\n canEdit: await this.#canEdit(c, scope),\n });\n }),\n\n this.#route(contracts.intakeSkippedList, async c => {\n const scope = await this.#resolve(c);\n const summary = await storage.summarizeSkippedByRoute(scope, new Date(Date.now() - SKIPPED_WINDOW_MS));\n return c.json({\n skipped: Object.entries(summary).map(([routeId, { count, latest }]) => ({\n routeId,\n count,\n latest: presentDecision(latest),\n })),\n });\n }),\n\n this.#route(contracts.intakeRouteAgain, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n return this.#routeAgain(c, scope);\n }),\n\n this.#route(contracts.intakeRouteReroutePreview, async c => {\n const scope = await this.#resolve(c);\n const moves = await this.#planReroute(scope);\n return c.json({ total: moves.length, moves: summarizeReroute(moves) });\n }),\n\n this.#route(contracts.intakeRouteRerouteApply, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const moves = await this.#planReroute(scope);\n const result = await applyReroute({\n moves,\n workItems: this.deps.workItems,\n registry: await this.#registry(scope),\n userId: scope.userId,\n });\n await this.deps.audit.emit({\n context: c,\n input: {\n action: 'factory.intake_route.rerouted',\n factoryProjectId: scope.factoryProjectId,\n targets: [...new Set(moves.map(move => move.routeId))].map(id => ({ type: 'intake_route', id })),\n metadata: { ...result, moves: summarizeReroute(moves) },\n },\n });\n return c.json(result);\n }),\n\n this.#route(contracts.intakeRouteReorder, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const { ids, boardKey } = await this.#body(c, contracts.intakeRouteReorder.bodySchema);\n const routes = await storage.reorderIntakeRoutes(\n scope,\n ids,\n scope.userId,\n boardKey === undefined ? {} : { boardKey },\n );\n await this.#audit(c, scope, 'reordered', routes);\n return this.#list(c, scope, routes);\n }),\n\n this.#route(contracts.intakeRouteGet, async c => {\n const scope = await this.#resolve(c);\n const route = await storage.getIntakeRoute(scope, this.#routeId(c));\n if (!route) throw new Refusal(404, { error: 'intake_route_not_found' });\n return this.#respond(c, scope, route);\n }),\n\n this.#route(contracts.intakeRouteCreate, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const input = await this.#body(c, contracts.intakeRouteCreate.bodySchema);\n this.#refuseJoin(input.target);\n await this.#checkTarget(scope, {\n target: input.target,\n on: input.on ?? DEFAULT_ROUTE_EVENTS,\n pullRequestOpenedMovesOnly: input.pullRequestOpenedMovesOnly,\n });\n const route = await storage.createIntakeRoute(scope, input, scope.userId);\n await this.#audit(c, scope, 'created', [route]);\n return this.#respond(c, scope, route, 201);\n }),\n\n this.#route(contracts.intakeRouteUpdate, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const id = this.#routeId(c);\n const { expectedRevision, ...patch } = await this.#body(c, contracts.intakeRouteUpdate.bodySchema);\n if (patch.target || patch.on) {\n // Narrowing or widening `on` changes which targets are allowed, so check the route as it will be.\n const current = await storage.getIntakeRoute(scope, id);\n if (!current) throw new Refusal(404, { error: 'intake_route_not_found' });\n this.#refuseJoin(patch.target, current.target);\n // Under intake order a rule belongs to its board: it moves with it, never to another.\n if (\n (await this.#evaluator(scope)) === 'intake-order' &&\n patch.target &&\n patch.target.boardKey !== current.target.boardKey\n ) {\n throw new Refusal(422, {\n error: 'intake_route_board_fixed',\n message: `This rule belongs to board \"${current.target.boardKey}\"; add a rule on the other board instead.`,\n });\n }\n // A 0.28 `pull_request.opened` route stays a card move through every edit, `on` included.\n await this.#checkTarget(scope, {\n target: patch.target ?? current.target,\n on: patch.on ?? current.on,\n pullRequestOpenedMovesOnly: current.pullRequestOpenedMovesOnly,\n });\n }\n const route = await storage.updateIntakeRoute(scope, id, patch, { expectedRevision, actor: scope.userId });\n await this.#audit(c, scope, 'updated', [route]);\n return this.#respond(c, scope, route);\n }),\n\n this.#route(contracts.intakeRouteDelete, async c => {\n const scope = await this.#resolve(c);\n await this.#requireAdmin(c, scope);\n const id = this.#routeId(c);\n const parsed = contracts.intakeRouteDelete.querySchema.safeParse({\n expectedRevision: c.req.query('expectedRevision'),\n });\n if (!parsed.success) {\n throw new Refusal(422, { error: 'invalid_request', message: issueMessage(parsed.error.issues) });\n }\n const route = await storage.getIntakeRoute(scope, id);\n if (!route) throw new Refusal(404, { error: 'intake_route_not_found' });\n await storage.deleteIntakeRoute(scope, id, { expectedRevision: parsed.data.expectedRevision });\n await this.#audit(c, scope, 'deleted', [route]);\n return c.body(null, 204);\n }),\n ];\n }\n}\n"],"mappings":";;;;;;;;;AA0EA,SAAS,gBAAgB,UAAsC;CAC7D,MAAM,EAAE,UAAU,SAAS,QAAQ,WAAW,OAAO,KAAK,WAAW,IAAI,SAAS,cAAc;CAChG,OAAO;EAAE;EAAI;EAAS;EAAW;EAAU;EAAS;EAAQ;EA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BAAkB,OAAO,IAAI,EAAE,kBAAkB,OAAO,KAAK,iBAAiB,CAAC;IAC7F,MAAM,KAAK,OAAO,GAAG,OAAO,WAAW,CAAC,KAAK,CAAC;IAC9C,OAAO,EAAE,KAAK,MAAM,GAAG;GACzB,CAAC;EACH;CACF;AACF"}
@@ -21,6 +21,12 @@ export interface IntakeRoutesDeps extends RouteDependencies {
21
21
  }): Promise<unknown | null>;
22
22
  };
23
23
  integrations?: IntakeIntegration[];
24
+ /** Sources newly selected by a config save, so their existing items can be brought in. */
25
+ onSourcesSelected?: (args: {
26
+ orgId: string;
27
+ integrationId: string;
28
+ sourceIds: string[];
29
+ }) => void;
24
30
  }
25
31
  /** One integration that failed while the rest of the aggregation succeeded. */
26
32
  export interface IntakeIntegrationFailure {
@@ -1 +1 @@
1
- {"version":3,"file":"intake.d.ts","sourceRoot":"","sources":["../../src/routes/intake.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,KAAK,EAAyB,YAAY,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAC5G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAS,KAAK,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,aAAa,GAAG,WAAW,GAAG,qBAAqB,CAAC,CAAC;CAC3E;AAYD,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,KAAK,EAAE,YAAY,CAAC;IACpB,sCAAsC;IACtC,MAAM,EAAE,aAAa,CAAC;I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@@ import { registerApiRoute } from "@mastra/core/server";
4
4
  import { z } from "zod";
5
5
  // src/routes/intake.ts
6
6
  const PROVIDER_READ_TIMEOUT_MS = 15e3;
7
+ function syncedSourceIds(selection) {
8
+ return selection?.enabled ? selection.sourceIds ?? [] : [];
9
+ }
7
10
  /** The Intake contract takes no abort signal, so a slow read is abandoned, not cancelled. */
8
11
  function withTimeout(integrationId, read, timeoutMs = PROVIDER_READ_TIMEOUT_MS) {
9
12
  return new Promise((resolve, reject) => {
@@ -176,10 +179,27 @@ var IntakeRoutes = class extends Route {
176
179
  if (selection.enabled || selection.sourceIds?.length) return c.json({ error: "invalid_config" }, 400);
177
180
  }
178
181
  await intake.ensureReady();
182
+ const before = await intake.getConfig({
183
+ orgId: tenant.orgId,
184
+ integrationIds
185
+ });
179
186
  await intake.mergeConfig({
180
187
  orgId: tenant.orgId,
181
188
  config: registeredConfig
182
189
  });
190
+ const after = await intake.getConfig({
191
+ orgId: tenant.orgId,
192
+ integrationIds
193
+ });
194
+ for (const integrationId of Object.keys(registeredConfig)) {
195
+ const synced = new Set(syncedSourceIds(before[integrationId]));
196
+ const added = syncedSourceIds(after[integrationId]).filter((sourceId) => !synced.has(sourceId));
197
+ if (added.length > 0) this.deps.onSourcesSelected?.({
198
+ orgId: tenant.orgId,
199
+ integrationId,
200
+ sourceIds: added
201
+ });
202
+ }
183
203
  await audit.emit({
184
204
  context: loose(c),
185
205
  input: {