@mastra/factory 0.15.1-alpha.0 → 0.16.0-alpha.11

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 (372) hide show
  1. package/README.md +41 -3
  2. package/dist/auth.js +1 -1
  3. package/dist/auth.js.map +1 -1
  4. package/dist/boards/index.d.ts +1 -1
  5. package/dist/boards/index.d.ts.map +1 -1
  6. package/dist/boards/index.js +2 -2
  7. package/dist/boards/index.js.map +1 -1
  8. package/dist/boards/review.d.ts.map +1 -1
  9. package/dist/boards/review.js +23 -9
  10. package/dist/boards/review.js.map +1 -1
  11. package/dist/boards/semantics.d.ts +7 -0
  12. package/dist/boards/semantics.d.ts.map +1 -1
  13. package/dist/boards/semantics.js +15 -1
  14. package/dist/boards/semantics.js.map +1 -1
  15. package/dist/boards/work.d.ts.map +1 -1
  16. package/dist/boards/work.js +68 -6
  17. package/dist/boards/work.js.map +1 -1
  18. package/dist/capabilities/intake.d.ts +8 -0
  19. package/dist/capabilities/intake.d.ts.map +1 -1
  20. package/dist/capabilities/version-control.d.ts +15 -0
  21. package/dist/capabilities/version-control.d.ts.map +1 -1
  22. package/dist/factory.d.ts +8 -5
  23. package/dist/factory.d.ts.map +1 -1
  24. package/dist/factory.js +136 -53
  25. package/dist/factory.js.map +1 -1
  26. package/dist/integrations/base.d.ts +5 -0
  27. package/dist/integrations/base.d.ts.map +1 -1
  28. package/dist/integrations/github/integration.d.ts.map +1 -1
  29. package/dist/integrations/github/integration.js +21 -0
  30. package/dist/integrations/github/integration.js.map +1 -1
  31. package/dist/integrations/github/routes.js +2 -1
  32. package/dist/integrations/github/routes.js.map +1 -1
  33. package/dist/integrations/github/sandbox.d.ts +41 -42
  34. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  35. package/dist/integrations/github/sandbox.js +416 -227
  36. package/dist/integrations/github/sandbox.js.map +1 -1
  37. package/dist/integrations/github/webhook.d.ts +2 -5
  38. package/dist/integrations/github/webhook.d.ts.map +1 -1
  39. package/dist/integrations/github/webhook.js +8 -48
  40. package/dist/integrations/github/webhook.js.map +1 -1
  41. package/dist/integrations/gitlab/agent-tools.d.ts +14 -0
  42. package/dist/integrations/gitlab/agent-tools.d.ts.map +1 -0
  43. package/dist/integrations/gitlab/agent-tools.js +42 -0
  44. package/dist/integrations/gitlab/agent-tools.js.map +1 -0
  45. package/dist/integrations/gitlab/api.d.ts +222 -0
  46. package/dist/integrations/gitlab/api.d.ts.map +1 -0
  47. package/dist/integrations/gitlab/api.js +274 -0
  48. package/dist/integrations/gitlab/api.js.map +1 -0
  49. package/dist/integrations/gitlab/default-rules.d.ts +125 -0
  50. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -0
  51. package/dist/integrations/gitlab/default-rules.js +172 -0
  52. package/dist/integrations/gitlab/default-rules.js.map +1 -0
  53. package/dist/integrations/gitlab/integration.d.ts +138 -0
  54. package/dist/integrations/gitlab/integration.d.ts.map +1 -0
  55. package/dist/integrations/gitlab/integration.js +705 -0
  56. package/dist/integrations/gitlab/integration.js.map +1 -0
  57. package/dist/integrations/gitlab/issue-reconciler.d.ts +6 -0
  58. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -0
  59. package/dist/integrations/gitlab/issue-reconciler.js +123 -0
  60. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -0
  61. package/dist/integrations/gitlab/merge-request-reconciler.d.ts +6 -0
  62. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -0
  63. package/dist/integrations/gitlab/merge-request-reconciler.js +267 -0
  64. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -0
  65. package/dist/integrations/gitlab/reconciler.d.ts +5 -0
  66. package/dist/integrations/gitlab/reconciler.d.ts.map +1 -0
  67. package/dist/integrations/gitlab/reconciler.js +31 -0
  68. package/dist/integrations/gitlab/reconciler.js.map +1 -0
  69. package/dist/integrations/gitlab/reconciliation-config.d.ts +3 -0
  70. package/dist/integrations/gitlab/reconciliation-config.d.ts.map +1 -0
  71. package/dist/integrations/gitlab/reconciliation-config.js +17 -0
  72. package/dist/integrations/gitlab/reconciliation-config.js.map +1 -0
  73. package/dist/integrations/gitlab/routes.d.ts +20 -0
  74. package/dist/integrations/gitlab/routes.d.ts.map +1 -0
  75. package/dist/integrations/gitlab/routes.js +473 -0
  76. package/dist/integrations/gitlab/routes.js.map +1 -0
  77. package/dist/integrations/gitlab/rules.d.ts +35 -0
  78. package/dist/integrations/gitlab/rules.d.ts.map +1 -0
  79. package/dist/integrations/gitlab/rules.js +391 -0
  80. package/dist/integrations/gitlab/rules.js.map +1 -0
  81. package/dist/integrations/gitlab/session-subscriptions.d.ts +32 -0
  82. package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -0
  83. package/dist/integrations/gitlab/session-subscriptions.js +192 -0
  84. package/dist/integrations/gitlab/session-subscriptions.js.map +1 -0
  85. package/dist/integrations/gitlab/subscriptions.d.ts +70 -0
  86. package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -0
  87. package/dist/integrations/gitlab/subscriptions.js +76 -0
  88. package/dist/integrations/gitlab/subscriptions.js.map +1 -0
  89. package/dist/integrations/gitlab/version-control.d.ts +16 -0
  90. package/dist/integrations/gitlab/version-control.d.ts.map +1 -0
  91. package/dist/integrations/gitlab/version-control.js +622 -0
  92. package/dist/integrations/gitlab/version-control.js.map +1 -0
  93. package/dist/integrations/gitlab/webhook-dispatch.d.ts +75 -0
  94. package/dist/integrations/gitlab/webhook-dispatch.d.ts.map +1 -0
  95. package/dist/integrations/gitlab/webhook-dispatch.js +235 -0
  96. package/dist/integrations/gitlab/webhook-dispatch.js.map +1 -0
  97. package/dist/integrations/gitlab/webhook.d.ts +72 -0
  98. package/dist/integrations/gitlab/webhook.d.ts.map +1 -0
  99. package/dist/integrations/gitlab/webhook.js +201 -0
  100. package/dist/integrations/gitlab/webhook.js.map +1 -0
  101. package/dist/integrations/incidentio/agent-tools.d.ts +49 -0
  102. package/dist/integrations/incidentio/agent-tools.d.ts.map +1 -0
  103. package/dist/integrations/incidentio/agent-tools.js +90 -0
  104. package/dist/integrations/incidentio/agent-tools.js.map +1 -0
  105. package/dist/integrations/incidentio/claim.d.ts +8 -0
  106. package/dist/integrations/incidentio/claim.d.ts.map +1 -0
  107. package/dist/integrations/incidentio/claim.js +14 -0
  108. package/dist/integrations/incidentio/claim.js.map +1 -0
  109. package/dist/integrations/incidentio/default-rules.d.ts +46 -0
  110. package/dist/integrations/incidentio/default-rules.d.ts.map +1 -0
  111. package/dist/integrations/incidentio/default-rules.js +66 -0
  112. package/dist/integrations/incidentio/default-rules.js.map +1 -0
  113. package/dist/integrations/incidentio/integration.d.ts +48 -2
  114. package/dist/integrations/incidentio/integration.d.ts.map +1 -1
  115. package/dist/integrations/incidentio/integration.js +89 -3
  116. package/dist/integrations/incidentio/integration.js.map +1 -1
  117. package/dist/integrations/incidentio/issue-reconciler.d.ts +2 -0
  118. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
  119. package/dist/integrations/incidentio/issue-reconciler.js +38 -2
  120. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
  121. package/dist/integrations/incidentio/routes.d.ts +71 -0
  122. package/dist/integrations/incidentio/routes.d.ts.map +1 -0
  123. package/dist/integrations/incidentio/routes.js +245 -0
  124. package/dist/integrations/incidentio/routes.js.map +1 -0
  125. package/dist/integrations/incidentio/rules.d.ts +55 -0
  126. package/dist/integrations/incidentio/rules.d.ts.map +1 -0
  127. package/dist/integrations/incidentio/rules.js +175 -0
  128. package/dist/integrations/incidentio/rules.js.map +1 -0
  129. package/dist/integrations/issue-reconciler.d.ts +3 -3
  130. package/dist/integrations/issue-reconciler.d.ts.map +1 -1
  131. package/dist/integrations/issue-reconciler.js +22 -2
  132. package/dist/integrations/issue-reconciler.js.map +1 -1
  133. package/dist/integrations/jira/adf.d.ts +26 -0
  134. package/dist/integrations/jira/adf.d.ts.map +1 -0
  135. package/dist/integrations/jira/adf.js +73 -0
  136. package/dist/integrations/jira/adf.js.map +1 -0
  137. package/dist/integrations/jira/agent-tools.d.ts +45 -0
  138. package/dist/integrations/jira/agent-tools.d.ts.map +1 -0
  139. package/dist/integrations/jira/agent-tools.js +87 -0
  140. package/dist/integrations/jira/agent-tools.js.map +1 -0
  141. package/dist/integrations/jira/api.d.ts +157 -0
  142. package/dist/integrations/jira/api.d.ts.map +1 -0
  143. package/dist/integrations/jira/api.js +141 -0
  144. package/dist/integrations/jira/api.js.map +1 -0
  145. package/dist/integrations/jira/claim.d.ts +9 -0
  146. package/dist/integrations/jira/claim.d.ts.map +1 -0
  147. package/dist/integrations/jira/claim.js +15 -0
  148. package/dist/integrations/jira/claim.js.map +1 -0
  149. package/dist/integrations/jira/default-rules.d.ts +47 -0
  150. package/dist/integrations/jira/default-rules.d.ts.map +1 -0
  151. package/dist/integrations/jira/default-rules.js +67 -0
  152. package/dist/integrations/jira/default-rules.js.map +1 -0
  153. package/dist/integrations/jira/integration.d.ts +114 -0
  154. package/dist/integrations/jira/integration.d.ts.map +1 -0
  155. package/dist/integrations/jira/integration.js +401 -0
  156. package/dist/integrations/jira/integration.js.map +1 -0
  157. package/dist/integrations/jira/issue-reconciler.d.ts +10 -0
  158. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -0
  159. package/dist/integrations/jira/issue-reconciler.js +70 -0
  160. package/dist/integrations/jira/issue-reconciler.js.map +1 -0
  161. package/dist/integrations/jira/reconciliation-config.d.ts +3 -0
  162. package/dist/integrations/jira/reconciliation-config.d.ts.map +1 -0
  163. package/dist/integrations/jira/reconciliation-config.js +17 -0
  164. package/dist/integrations/jira/reconciliation-config.js.map +1 -0
  165. package/dist/integrations/jira/routes.d.ts +54 -0
  166. package/dist/integrations/jira/routes.d.ts.map +1 -0
  167. package/dist/integrations/jira/routes.js +260 -0
  168. package/dist/integrations/jira/routes.js.map +1 -0
  169. package/dist/integrations/jira/rules.d.ts +57 -0
  170. package/dist/integrations/jira/rules.d.ts.map +1 -0
  171. package/dist/integrations/jira/rules.js +175 -0
  172. package/dist/integrations/jira/rules.js.map +1 -0
  173. package/dist/integrations/linear/claim.d.ts +8 -0
  174. package/dist/integrations/linear/claim.d.ts.map +1 -0
  175. package/dist/integrations/linear/claim.js +14 -0
  176. package/dist/integrations/linear/claim.js.map +1 -0
  177. package/dist/integrations/linear/default-rules.d.ts +1 -0
  178. package/dist/integrations/linear/default-rules.d.ts.map +1 -1
  179. package/dist/integrations/linear/default-rules.js +2 -0
  180. package/dist/integrations/linear/default-rules.js.map +1 -1
  181. package/dist/integrations/linear/integration.d.ts +24 -6
  182. package/dist/integrations/linear/integration.d.ts.map +1 -1
  183. package/dist/integrations/linear/integration.js +257 -37
  184. package/dist/integrations/linear/integration.js.map +1 -1
  185. package/dist/integrations/linear/routes.d.ts +10 -0
  186. package/dist/integrations/linear/routes.d.ts.map +1 -1
  187. package/dist/integrations/linear/routes.js +74 -10
  188. package/dist/integrations/linear/routes.js.map +1 -1
  189. package/dist/integrations/linear/rules.d.ts +1 -1
  190. package/dist/integrations/linear/rules.d.ts.map +1 -1
  191. package/dist/integrations/linear/rules.js +27 -2
  192. package/dist/integrations/linear/rules.js.map +1 -1
  193. package/dist/integrations/platform/connect/routes.d.ts +39 -0
  194. package/dist/integrations/platform/connect/routes.d.ts.map +1 -0
  195. package/dist/integrations/platform/connect/routes.js +129 -0
  196. package/dist/integrations/platform/connect/routes.js.map +1 -0
  197. package/dist/integrations/platform/github/event-worker.js +1 -1
  198. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  199. package/dist/integrations/platform/github/integration.js +22 -1
  200. package/dist/integrations/platform/github/integration.js.map +1 -1
  201. package/dist/integrations/platform/gitlab/event-worker.d.ts +64 -0
  202. package/dist/integrations/platform/gitlab/event-worker.d.ts.map +1 -0
  203. package/dist/integrations/platform/gitlab/event-worker.js +306 -0
  204. package/dist/integrations/platform/gitlab/event-worker.js.map +1 -0
  205. package/dist/integrations/platform/gitlab/integration.d.ts +57 -0
  206. package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -0
  207. package/dist/integrations/platform/gitlab/integration.js +125 -0
  208. package/dist/integrations/platform/gitlab/integration.js.map +1 -0
  209. package/dist/integrations/platform/incidentio/integration.d.ts +61 -4
  210. package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
  211. package/dist/integrations/platform/incidentio/integration.js +372 -23
  212. package/dist/integrations/platform/incidentio/integration.js.map +1 -1
  213. package/dist/integrations/platform/jira/agent-tools.d.ts +36 -0
  214. package/dist/integrations/platform/jira/agent-tools.d.ts.map +1 -0
  215. package/dist/integrations/platform/jira/agent-tools.js +85 -0
  216. package/dist/integrations/platform/jira/agent-tools.js.map +1 -0
  217. package/dist/integrations/platform/jira/integration.d.ts +65 -0
  218. package/dist/integrations/platform/jira/integration.d.ts.map +1 -0
  219. package/dist/integrations/platform/jira/integration.js +540 -0
  220. package/dist/integrations/platform/jira/integration.js.map +1 -0
  221. package/dist/integrations/platform/jira/routes.d.ts +55 -0
  222. package/dist/integrations/platform/jira/routes.d.ts.map +1 -0
  223. package/dist/integrations/platform/jira/routes.js +274 -0
  224. package/dist/integrations/platform/jira/routes.js.map +1 -0
  225. package/dist/integrations/platform/linear/integration.d.ts +34 -1
  226. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  227. package/dist/integrations/platform/linear/integration.js +271 -48
  228. package/dist/integrations/platform/linear/integration.js.map +1 -1
  229. package/dist/integrations/slack/integration.d.ts.map +1 -1
  230. package/dist/integrations/slack/integration.js +3 -3
  231. package/dist/integrations/slack/integration.js.map +1 -1
  232. package/dist/integrations/slack/slack.d.ts +2 -0
  233. package/dist/integrations/slack/slack.d.ts.map +1 -1
  234. package/dist/integrations/slack/slack.js +21 -7
  235. package/dist/integrations/slack/slack.js.map +1 -1
  236. package/dist/integrations/subscription-session.d.ts +37 -0
  237. package/dist/integrations/subscription-session.d.ts.map +1 -0
  238. package/dist/integrations/subscription-session.js +83 -0
  239. package/dist/integrations/subscription-session.js.map +1 -0
  240. package/dist/packages/_internals/workspace/dist/index.js +1 -11
  241. package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
  242. package/dist/routes/intake.d.ts.map +1 -1
  243. package/dist/routes/intake.js +16 -4
  244. package/dist/routes/intake.js.map +1 -1
  245. package/dist/routes/oauth.js +3 -6
  246. package/dist/routes/oauth.js.map +1 -1
  247. package/dist/routes/projects.d.ts +1 -0
  248. package/dist/routes/projects.d.ts.map +1 -1
  249. package/dist/routes/projects.js +1 -0
  250. package/dist/routes/projects.js.map +1 -1
  251. package/dist/routes/source-control-sessions.d.ts +20 -0
  252. package/dist/routes/source-control-sessions.d.ts.map +1 -0
  253. package/dist/routes/source-control-sessions.js +319 -0
  254. package/dist/routes/source-control-sessions.js.map +1 -0
  255. package/dist/routes/source-control-settings.d.ts +10 -0
  256. package/dist/routes/source-control-settings.d.ts.map +1 -0
  257. package/dist/routes/source-control-settings.js +87 -0
  258. package/dist/routes/source-control-settings.js.map +1 -0
  259. package/dist/routes/surface.d.ts +3 -3
  260. package/dist/routes/surface.d.ts.map +1 -1
  261. package/dist/routes/surface.js +79 -17
  262. package/dist/routes/surface.js.map +1 -1
  263. package/dist/routes/tenant-credentials.d.ts +8 -0
  264. package/dist/routes/tenant-credentials.d.ts.map +1 -1
  265. package/dist/routes/tenant-credentials.js +20 -3
  266. package/dist/routes/tenant-credentials.js.map +1 -1
  267. package/dist/routes/work-items.d.ts.map +1 -1
  268. package/dist/routes/work-items.js +1 -1
  269. package/dist/routes/work-items.js.map +1 -1
  270. package/dist/rules/dispatch-errors.d.ts.map +1 -1
  271. package/dist/rules/dispatch-errors.js +8 -0
  272. package/dist/rules/dispatch-errors.js.map +1 -1
  273. package/dist/rules/dispatcher.d.ts +1 -0
  274. package/dist/rules/dispatcher.d.ts.map +1 -1
  275. package/dist/rules/dispatcher.js +186 -106
  276. package/dist/rules/dispatcher.js.map +1 -1
  277. package/dist/rules/index.d.ts +2 -2
  278. package/dist/rules/index.d.ts.map +1 -1
  279. package/dist/rules/index.js +2 -2
  280. package/dist/rules/start-coordinator.d.ts +1 -1
  281. package/dist/rules/start-coordinator.d.ts.map +1 -1
  282. package/dist/rules/start-coordinator.js +7 -3
  283. package/dist/rules/start-coordinator.js.map +1 -1
  284. package/dist/rules/terminal-cleanup.d.ts +14 -1
  285. package/dist/rules/terminal-cleanup.d.ts.map +1 -1
  286. package/dist/rules/terminal-cleanup.js +20 -0
  287. package/dist/rules/terminal-cleanup.js.map +1 -1
  288. package/dist/rules/tools.d.ts +2 -0
  289. package/dist/rules/tools.d.ts.map +1 -1
  290. package/dist/rules/tools.js +30 -2
  291. package/dist/rules/tools.js.map +1 -1
  292. package/dist/rules/transition-service.d.ts +3 -0
  293. package/dist/rules/transition-service.d.ts.map +1 -1
  294. package/dist/rules/transition-service.js +10 -5
  295. package/dist/rules/transition-service.js.map +1 -1
  296. package/dist/rules/types.d.ts +136 -3
  297. package/dist/rules/types.d.ts.map +1 -1
  298. package/dist/rules/types.js +31 -2
  299. package/dist/rules/types.js.map +1 -1
  300. package/dist/rules/validation.d.ts.map +1 -1
  301. package/dist/rules/validation.js +15 -2
  302. package/dist/rules/validation.js.map +1 -1
  303. package/dist/sandbox/git-ref.d.ts +7 -0
  304. package/dist/sandbox/git-ref.d.ts.map +1 -0
  305. package/dist/sandbox/git-ref.js +15 -0
  306. package/dist/sandbox/git-ref.js.map +1 -0
  307. package/dist/sandbox/session-retirement.js +1 -1
  308. package/dist/sandbox/workdir.d.ts.map +1 -1
  309. package/dist/sandbox/workdir.js +6 -6
  310. package/dist/sandbox/workdir.js.map +1 -1
  311. package/dist/session/factory-session.d.ts +31 -1
  312. package/dist/session/factory-session.d.ts.map +1 -1
  313. package/dist/session/factory-session.js +60 -1
  314. package/dist/session/factory-session.js.map +1 -1
  315. package/dist/session/run-audit.d.ts +9 -0
  316. package/dist/session/run-audit.d.ts.map +1 -1
  317. package/dist/session/run-audit.js +37 -6
  318. package/dist/session/run-audit.js.map +1 -1
  319. package/dist/session/source-control-tools.d.ts +16 -0
  320. package/dist/session/source-control-tools.d.ts.map +1 -0
  321. package/dist/session/source-control-tools.js +464 -0
  322. package/dist/session/source-control-tools.js.map +1 -0
  323. package/dist/skills/service.d.ts +12 -0
  324. package/dist/skills/service.d.ts.map +1 -1
  325. package/dist/skills/service.js +27 -1
  326. package/dist/skills/service.js.map +1 -1
  327. package/dist/storage/domains/intake/base.d.ts +18 -0
  328. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  329. package/dist/storage/domains/intake/base.js +77 -0
  330. package/dist/storage/domains/intake/base.js.map +1 -1
  331. package/dist/storage/domains/work-items/base.d.ts +41 -2
  332. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  333. package/dist/storage/domains/work-items/base.js +159 -12
  334. package/dist/storage/domains/work-items/base.js.map +1 -1
  335. package/dist/supervisor/session-messaging.d.ts +23 -0
  336. package/dist/supervisor/session-messaging.d.ts.map +1 -0
  337. package/dist/supervisor/session-messaging.js +15 -0
  338. package/dist/supervisor/session-messaging.js.map +1 -0
  339. package/dist/supervisor/write-tools.d.ts +2 -1
  340. package/dist/supervisor/write-tools.d.ts.map +1 -1
  341. package/dist/supervisor/write-tools.js +11 -7
  342. package/dist/supervisor/write-tools.js.map +1 -1
  343. package/dist/work-item-branch.d.ts +3 -1
  344. package/dist/work-item-branch.d.ts.map +1 -1
  345. package/dist/work-item-branch.js +26 -6
  346. package/dist/work-item-branch.js.map +1 -1
  347. package/dist/workspace.d.ts +15 -1
  348. package/dist/workspace.d.ts.map +1 -1
  349. package/dist/workspace.js +57 -23
  350. package/dist/workspace.js.map +1 -1
  351. package/factory-skills/factory-gitlab-rereview/SKILL.md +19 -0
  352. package/factory-skills/factory-gitlab-review/SKILL.md +30 -0
  353. package/factory-skills/factory-rereview/SKILL.md +13 -6
  354. package/factory-skills/factory-review/SKILL.md +13 -6
  355. package/factory-skills/factory-review/references/archaeology.md +225 -0
  356. package/factory-skills/factory-review/references/categories/README.md +34 -0
  357. package/factory-skills/factory-review/references/categories/behavior-change.md +36 -0
  358. package/factory-skills/factory-review/references/categories/bug-fix.md +37 -0
  359. package/factory-skills/factory-review/references/categories/docs.md +32 -0
  360. package/factory-skills/factory-review/references/categories/experimental-flagged.md +34 -0
  361. package/factory-skills/factory-review/references/categories/infra-tooling.md +37 -0
  362. package/factory-skills/factory-review/references/categories/internal-capability.md +35 -0
  363. package/factory-skills/factory-review/references/categories/large-cross-cutting.md +35 -0
  364. package/factory-skills/factory-review/references/categories/mechanical.md +36 -0
  365. package/factory-skills/factory-review/references/categories/performance.md +33 -0
  366. package/factory-skills/factory-review/references/categories/public-api.md +38 -0
  367. package/factory-skills/factory-review/references/categories/refactor.md +35 -0
  368. package/factory-skills/factory-review/references/categories/revert.md +31 -0
  369. package/factory-skills/factory-review/references/categories/schema-storage.md +39 -0
  370. package/factory-skills/factory-review/references/categories/security.md +35 -0
  371. package/factory-skills/factory-review/references/categories/tests-only.md +38 -0
  372. package/package.json +12 -12
@@ -0,0 +1,31 @@
1
+ import { attachGitLabIssueReconciler } from "./issue-reconciler.js";
2
+ import { attachGitLabMergeRequestReconciler } from "./merge-request-reconciler.js";
3
+ //#region src/integrations/gitlab/reconciler.ts
4
+ function attachGitLabReconciler(gitlab, context) {
5
+ const issues = attachGitLabIssueReconciler(gitlab, context);
6
+ const mergeRequests = attachGitLabMergeRequestReconciler(gitlab, context);
7
+ if (!issues && !mergeRequests) return void 0;
8
+ return async () => {
9
+ return (await Promise.all([issues?.(), mergeRequests?.()])).filter((result) => result !== void 0).reduce((summary, result) => ({
10
+ projects: Math.max(summary.projects, result.projects),
11
+ checked: summary.checked + result.checked,
12
+ updated: summary.updated + result.updated,
13
+ closed: summary.closed + result.closed,
14
+ missing: summary.missing + result.missing,
15
+ failed: summary.failed + result.failed,
16
+ errors: [...summary.errors, ...result.errors]
17
+ }), {
18
+ projects: 0,
19
+ checked: 0,
20
+ updated: 0,
21
+ closed: 0,
22
+ missing: 0,
23
+ failed: 0,
24
+ errors: []
25
+ });
26
+ };
27
+ }
28
+ //#endregion
29
+ export { attachGitLabReconciler };
30
+
31
+ //# sourceMappingURL=reconciler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciler.js","names":[],"sources":["../../../src/integrations/gitlab/reconciler.ts"],"sourcesContent":["import type { IntegrationContext } from '../base.js';\nimport type { IssueReconciler, IssueReconcileSummary } from '../issue-reconciler.js';\nimport type { GitLabIntegrationBase } from './integration.js';\nimport { attachGitLabIssueReconciler } from './issue-reconciler.js';\nimport { attachGitLabMergeRequestReconciler } from './merge-request-reconciler.js';\n\nexport function attachGitLabReconciler(\n gitlab: GitLabIntegrationBase,\n context: IntegrationContext,\n): IssueReconciler | undefined {\n const issues = attachGitLabIssueReconciler(gitlab, context);\n const mergeRequests = attachGitLabMergeRequestReconciler(gitlab, context);\n if (!issues && !mergeRequests) return undefined;\n return async () => {\n const results = await Promise.all([issues?.(), mergeRequests?.()]);\n return results.filter((result): result is IssueReconcileSummary => result !== undefined).reduce(\n (summary, result) => ({\n projects: Math.max(summary.projects, result.projects),\n checked: summary.checked + result.checked,\n updated: summary.updated + result.updated,\n closed: summary.closed + result.closed,\n missing: summary.missing + result.missing,\n failed: summary.failed + result.failed,\n errors: [...summary.errors, ...result.errors],\n }),\n { projects: 0, checked: 0, updated: 0, closed: 0, missing: 0, failed: 0, errors: [] },\n );\n };\n}\n"],"mappings":";;;AAMA,SAAgB,uBACd,QACA,SAC6B;CAC7B,MAAM,SAAS,4BAA4B,QAAQ,OAAO;CAC1D,MAAM,gBAAgB,mCAAmC,QAAQ,OAAO;CACxE,IAAI,CAAC,UAAU,CAAC,eAAe,OAAO,KAAA;CACtC,OAAO,YAAY;EAEjB,QAAO,MADe,QAAQ,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,CAAC,EAAA,CAClD,QAAQ,WAA4C,WAAW,KAAA,CAAS,CAAC,CAAC,QACtF,SAAS,YAAY;GACpB,UAAU,KAAK,IAAI,QAAQ,UAAU,OAAO,QAAQ;GACpD,SAAS,QAAQ,UAAU,OAAO;GAClC,SAAS,QAAQ,UAAU,OAAO;GAClC,QAAQ,QAAQ,SAAS,OAAO;GAChC,SAAS,QAAQ,UAAU,OAAO;GAClC,QAAQ,QAAQ,SAAS,OAAO;GAChC,QAAQ,CAAC,GAAG,QAAQ,QAAQ,GAAG,OAAO,MAAM;EAC9C,IACA;GAAE,UAAU;GAAG,SAAS;GAAG,SAAS;GAAG,QAAQ;GAAG,SAAS;GAAG,QAAQ;GAAG,QAAQ,CAAC;EAAE,CACtF;CACF;AACF"}
@@ -0,0 +1,3 @@
1
+ export declare function gitlabReconciliationEnabled(): boolean;
2
+ export declare function gitlabReconciliationInterval(): number | undefined;
3
+ //# sourceMappingURL=reconciliation-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciliation-config.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/reconciliation-config.ts"],"names":[],"mappings":"AAMA,wBAAgB,2BAA2B,IAAI,OAAO,CAOrD;AAED,wBAAgB,4BAA4B,IAAI,MAAM,GAAG,SAAS,CAOjE"}
@@ -0,0 +1,17 @@
1
+ import { optionalBoolean, optionalPositiveInteger } from "../reconciliation-config.js";
2
+ //#region src/integrations/gitlab/reconciliation-config.ts
3
+ function configuredValue(primary, legacy) {
4
+ return primary?.trim() ? primary : legacy;
5
+ }
6
+ function gitlabReconciliationEnabled() {
7
+ const primary = process.env.MASTRACODE_GITLAB_RECONCILE_ENABLED;
8
+ const value = configuredValue(primary, process.env.MASTRACODE_GITLAB_ISSUE_RECONCILE_ENABLED);
9
+ return optionalBoolean(primary?.trim() ? "MASTRACODE_GITLAB_RECONCILE_ENABLED" : "MASTRACODE_GITLAB_ISSUE_RECONCILE_ENABLED", value, "gitlab") ?? true;
10
+ }
11
+ function gitlabReconciliationInterval() {
12
+ return optionalPositiveInteger(configuredValue(process.env.MASTRACODE_GITLAB_RECONCILE_INTERVAL_MS, process.env.MASTRACODE_GITLAB_ISSUE_RECONCILE_INTERVAL_MS));
13
+ }
14
+ //#endregion
15
+ export { gitlabReconciliationEnabled, gitlabReconciliationInterval };
16
+
17
+ //# sourceMappingURL=reconciliation-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciliation-config.js","names":[],"sources":["../../../src/integrations/gitlab/reconciliation-config.ts"],"sourcesContent":["import { optionalBoolean, optionalPositiveInteger } from '../reconciliation-config.js';\n\nfunction configuredValue(primary: string | undefined, legacy: string | undefined): string | undefined {\n return primary?.trim() ? primary : legacy;\n}\n\nexport function gitlabReconciliationEnabled(): boolean {\n const primary = process.env.MASTRACODE_GITLAB_RECONCILE_ENABLED;\n const value = configuredValue(primary, process.env.MASTRACODE_GITLAB_ISSUE_RECONCILE_ENABLED);\n const name = primary?.trim()\n ? 'MASTRACODE_GITLAB_RECONCILE_ENABLED'\n : 'MASTRACODE_GITLAB_ISSUE_RECONCILE_ENABLED';\n return optionalBoolean(name, value, 'gitlab') ?? true;\n}\n\nexport function gitlabReconciliationInterval(): number | undefined {\n return optionalPositiveInteger(\n configuredValue(\n process.env.MASTRACODE_GITLAB_RECONCILE_INTERVAL_MS,\n process.env.MASTRACODE_GITLAB_ISSUE_RECONCILE_INTERVAL_MS,\n ),\n );\n}\n"],"mappings":";;AAEA,SAAS,gBAAgB,SAA6B,QAAgD;CACpG,OAAO,SAAS,KAAK,IAAI,UAAU;AACrC;AAEA,SAAgB,8BAAuC;CACrD,MAAM,UAAU,QAAQ,IAAI;CAC5B,MAAM,QAAQ,gBAAgB,SAAS,QAAQ,IAAI,yCAAyC;CAI5F,OAAO,gBAHM,SAAS,KAAK,IACvB,wCACA,6CACyB,OAAO,QAAQ,KAAK;AACnD;AAEA,SAAgB,+BAAmD;CACjE,OAAO,wBACL,gBACE,QAAQ,IAAI,yCACZ,QAAQ,IAAI,6CACd,CACF;AACF"}
@@ -0,0 +1,20 @@
1
+ import type { ApiRoute } from '@mastra/core/server';
2
+ import type { RouteAuth } from '../../routes/route.js';
3
+ import type { MastraFactorySandboxConfig } from '../../sandbox/session-sandbox.js';
4
+ import type { AuditEmitter } from '../../storage/domains/audit/domain.js';
5
+ import type { IntakeStorage } from '../../storage/domains/intake/base.js';
6
+ import type { GitLabIntegrationBase } from './integration.js';
7
+ import type { GitLabWebhookHandlerOptions, ParsedGitLabWebhook } from './webhook.js';
8
+ export interface BuildGitLabRoutesOptions {
9
+ gitlab?: GitLabIntegrationBase;
10
+ auth?: RouteAuth;
11
+ intake?: IntakeStorage;
12
+ sandbox?: MastraFactorySandboxConfig;
13
+ emitAudit?: AuditEmitter['emit'];
14
+ webhookSecret?: string;
15
+ ingestFactoryEvent?: (event: ParsedGitLabWebhook) => Promise<unknown>;
16
+ /** Mounted agent controller; enables webhook delivery to subscribed sessions. */
17
+ controller?: GitLabWebhookHandlerOptions['controller'];
18
+ }
19
+ export declare function buildGitLabRoutes(options: BuildGitLabRoutesOptions): ApiRoute[];
20
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAEnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAS1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAG9D,OAAO,KAAK,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAQrF,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,OAAO,CAAC,EAAE,0BAA0B,CAAC;IACrC,SAAS,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACtE,iFAAiF;IACjF,UAAU,CAAC,EAAE,2BAA2B,CAAC,YAAY,CAAC,CAAC;CACxD;AAkGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,QAAQ,EAAE,CAwZ/E"}
@@ -0,0 +1,473 @@
1
+ import { sanitizeSegment } from "../../sandbox/workdir.js";
2
+ import { GitLabApiError } from "./api.js";
3
+ import { listMergeRequestSubscriptionsForThread, mergeRequestUrl } from "./subscriptions.js";
4
+ import { handleGitLabWebhook } from "./webhook.js";
5
+ import { decodeIssueReference, decodeSourceId, encodeIssueReference, encodeSourceId, gitlabConnection } from "./integration.js";
6
+ import { registerApiRoute } from "@mastra/core/server";
7
+ //#region src/integrations/gitlab/routes.ts
8
+ function loose(c) {
9
+ return c;
10
+ }
11
+ async function resolveOrgTenant(c, auth) {
12
+ await auth.ensureUser(c);
13
+ const tenant = auth.tenant(c);
14
+ if (!tenant) return { response: c.json({
15
+ error: "unauthorized",
16
+ reason: "auth_required"
17
+ }, 401) };
18
+ if (!tenant.orgId) return { response: c.json({
19
+ error: "organization_required",
20
+ message: "GitLab intake requires an organization. Personal accounts cannot use GitLab intake."
21
+ }, 403) };
22
+ return { tenant: {
23
+ orgId: tenant.orgId,
24
+ userId: tenant.userId
25
+ } };
26
+ }
27
+ function gitlabFetchError(c, error) {
28
+ if (error instanceof GitLabApiError && error.code === "gitlab_auth_failed") return c.json({
29
+ error: "gitlab_auth_failed",
30
+ message: error.message
31
+ }, 409);
32
+ return c.json({
33
+ error: "gitlab_fetch_failed",
34
+ message: error instanceof Error ? error.message : String(error)
35
+ }, 502);
36
+ }
37
+ function gitlabProjectPayload(source) {
38
+ const connectionId = typeof source.metadata?.connectionId === "string" ? source.metadata.connectionId : null;
39
+ const projectId = typeof source.metadata?.projectId === "string" ? source.metadata.projectId : null;
40
+ const projectPath = typeof source.metadata?.projectPath === "string" ? source.metadata.projectPath : source.name;
41
+ if (!connectionId || !projectId) return null;
42
+ const repositoryName = projectPath.split("/").filter(Boolean).at(-1) ?? "repo";
43
+ return {
44
+ id: source.id,
45
+ name: source.name,
46
+ projectId,
47
+ projectPath,
48
+ connectionId,
49
+ accountLabel: typeof source.metadata?.accountLabel === "string" ? source.metadata.accountLabel : null,
50
+ defaultBranch: typeof source.metadata?.defaultBranch === "string" ? source.metadata.defaultBranch : "main",
51
+ sandboxProvider: "none",
52
+ sandboxWorkdir: `~/${sanitizeSegment(repositoryName)}`
53
+ };
54
+ }
55
+ function positiveId(value) {
56
+ const number = Number(value);
57
+ return value && /^[1-9]\d*$/.test(value) && Number.isSafeInteger(number) ? number : null;
58
+ }
59
+ function mergeRequestSourceKey(host, projectId, mergeRequestIid) {
60
+ return `gitlab-pr:${Buffer.from(JSON.stringify({
61
+ version: 1,
62
+ host,
63
+ projectId,
64
+ mergeRequestIid
65
+ }), "utf8").toString("base64url")}`;
66
+ }
67
+ async function reconcileGitLabSourceIdentity({ intake, orgId, sources }) {
68
+ await intake.ensureReady();
69
+ const [config, bindings] = await Promise.all([intake.getConfig({ orgId }), intake.listBindings({
70
+ orgId,
71
+ integrationId: "gitlab"
72
+ })]);
73
+ const selected = config.gitlab?.sourceIds ?? [];
74
+ const canonicalByProject = /* @__PURE__ */ new Map();
75
+ for (const source of sources) {
76
+ const reference = decodeSourceId(source.id);
77
+ if (!reference?.host) continue;
78
+ const ids = canonicalByProject.get(reference.projectId) ?? [];
79
+ ids.push(source.id);
80
+ canonicalByProject.set(reference.projectId, ids);
81
+ }
82
+ const migrations = /* @__PURE__ */ new Map();
83
+ for (const sourceId of /* @__PURE__ */ new Set([...selected, ...bindings.map((binding) => binding.sourceId)])) {
84
+ const reference = decodeSourceId(sourceId);
85
+ if (!reference || reference.host) continue;
86
+ const candidates = canonicalByProject.get(reference.projectId) ?? [];
87
+ if (candidates.length === 1) migrations.set(sourceId, candidates[0]);
88
+ }
89
+ return intake.migrateSourceIds({
90
+ orgId,
91
+ integrationId: "gitlab",
92
+ migrations: [...migrations].map(([from, to]) => ({
93
+ from,
94
+ to
95
+ }))
96
+ });
97
+ }
98
+ function buildGitLabRoutes(options) {
99
+ const routes = [];
100
+ const { gitlab, auth, intake, emitAudit } = options;
101
+ const enabled = Boolean(gitlab && auth?.enabled());
102
+ if (gitlab && auth) routes.push(registerApiRoute("/web/gitlab/status", {
103
+ method: "GET",
104
+ requiresAuth: false,
105
+ handler: async (c) => {
106
+ const diagnostics = gitlab.diagnostics();
107
+ if (!enabled) return c.json({
108
+ enabled: false,
109
+ configured: true,
110
+ reauthRequired: false,
111
+ reason: "missing_config"
112
+ });
113
+ await auth.ensureUser(loose(c));
114
+ const tenant = auth.tenant(loose(c));
115
+ if (!tenant) return c.json({
116
+ error: "unauthorized",
117
+ reason: "auth_required"
118
+ }, 401);
119
+ if (!tenant.orgId) return c.json({
120
+ enabled: true,
121
+ configured: false,
122
+ organizationRequired: true,
123
+ connections: [],
124
+ accounts: [],
125
+ reauthRequired: false,
126
+ reason: "organization_required"
127
+ });
128
+ try {
129
+ await gitlab.verifyStatus();
130
+ const connections = await gitlab.statusConnections();
131
+ const active = connections?.filter((connection) => connection.status === "active");
132
+ const direct = connections === void 0;
133
+ const endpointHost = typeof diagnostics.endpointHost === "string" ? diagnostics.endpointHost : null;
134
+ const accounts = direct ? endpointHost ? [endpointHost] : [] : (active ?? []).flatMap((connection) => connection.accountLabel ? [connection.accountLabel] : []);
135
+ const configured = direct || (active?.length ?? 0) > 0;
136
+ return c.json({
137
+ enabled: true,
138
+ configured,
139
+ mode: direct ? "direct" : "platform",
140
+ ...connections ? { connections } : {},
141
+ accounts,
142
+ reauthRequired: connections?.some((connection) => connection.status === "needs_reauth") ?? false,
143
+ reason: configured ? "ready" : "not_connected"
144
+ });
145
+ } catch (error) {
146
+ return gitlabFetchError(loose(c), error);
147
+ }
148
+ }
149
+ }), registerApiRoute("/web/gitlab/projects", {
150
+ method: "GET",
151
+ requiresAuth: false,
152
+ handler: async (c) => {
153
+ const resolved = await resolveOrgTenant(loose(c), auth);
154
+ if ("response" in resolved) return resolved.response;
155
+ try {
156
+ const sources = await gitlab.intake.listSources(resolved.tenant);
157
+ if (intake) {
158
+ const identity = await reconcileGitLabSourceIdentity({
159
+ intake,
160
+ orgId: resolved.tenant.orgId,
161
+ sources
162
+ });
163
+ if (identity.conflicts.length > 0) return c.json({
164
+ error: "gitlab_source_identity_conflict",
165
+ message: "Conflicting routes exist for the same GitLab project. Resolve the duplicate bindings.",
166
+ conflicts: identity.conflicts
167
+ }, 409);
168
+ if (identity.migrations.length > 0) await emitAudit?.({
169
+ context: loose(c),
170
+ input: {
171
+ action: "factory.intake.config_updated",
172
+ targets: identity.migrations.map((migration) => ({
173
+ type: "intake_source",
174
+ id: migration.to
175
+ })),
176
+ metadata: {
177
+ provider: "gitlab",
178
+ migrated: identity.migrations.length
179
+ }
180
+ }
181
+ });
182
+ }
183
+ return c.json({ projects: sources.flatMap((source) => {
184
+ const project = gitlabProjectPayload(source);
185
+ return project ? [{
186
+ ...project,
187
+ sandboxProvider: options.sandbox ? "custom" : "none"
188
+ }] : [];
189
+ }) });
190
+ } catch (error) {
191
+ return gitlabFetchError(loose(c), error);
192
+ }
193
+ }
194
+ }), registerApiRoute("/web/gitlab/projects/registration", {
195
+ method: "POST",
196
+ requiresAuth: false,
197
+ handler: async (c) => {
198
+ const resolved = await resolveOrgTenant(loose(c), auth);
199
+ if ("response" in resolved) return resolved.response;
200
+ const input = await c.req.json().catch(() => null);
201
+ const sourceId = typeof input?.sourceId === "string" ? input.sourceId.trim() : "";
202
+ if (!sourceId) return c.json({ error: "invalid_gitlab_source" }, 400);
203
+ try {
204
+ const source = (await gitlab.intake.listSources(resolved.tenant)).find((candidate) => candidate.id === sourceId);
205
+ const project = source ? gitlabProjectPayload(source) : null;
206
+ if (!project) return c.json({ error: "gitlab_project_not_found" }, 404);
207
+ const installation = await gitlab.versionControl.registerInstallation({
208
+ orgId: resolved.tenant.orgId,
209
+ userId: resolved.tenant.userId,
210
+ installation: {
211
+ externalId: project.connectionId,
212
+ accountName: project.accountLabel ?? "GitLab",
213
+ accountType: "GitLab",
214
+ metadata: { connection: gitlabConnection(project.connectionId) }
215
+ }
216
+ });
217
+ return c.json({ project: {
218
+ ...project,
219
+ installationStorageId: installation.id,
220
+ sandboxProvider: options.sandbox ? "custom" : "none"
221
+ } });
222
+ } catch (error) {
223
+ return gitlabFetchError(loose(c), error);
224
+ }
225
+ }
226
+ }), registerApiRoute("/web/gitlab/projects/:id/prs", {
227
+ method: "GET",
228
+ requiresAuth: false,
229
+ handler: async (c) => {
230
+ const resolved = await resolveOrgTenant(loose(c), auth);
231
+ if ("response" in resolved) return resolved.response;
232
+ const factoryProjectId = c.req.query("factoryProjectId")?.trim();
233
+ const page = positiveId(c.req.query("page") ?? "1");
234
+ if (!factoryProjectId || !page) return c.json({ error: "invalid_request" }, 400);
235
+ if (await gitlab.resolveOrgId(factoryProjectId) !== resolved.tenant.orgId) return c.json({ error: "factory_project_not_found" }, 404);
236
+ const linked = await gitlab.getLinkedRepository({
237
+ orgId: resolved.tenant.orgId,
238
+ factoryProjectId,
239
+ projectRepositoryId: c.req.param("id")
240
+ });
241
+ if (!linked) return c.json({ error: "project_repository_not_found" }, 404);
242
+ const projectId = positiveId(linked.repository.externalId);
243
+ if (!projectId) return c.json({ error: "invalid_gitlab_project" }, 502);
244
+ try {
245
+ const target = await gitlab.versionControl.getRepositoryTarget({
246
+ orgId: resolved.tenant.orgId,
247
+ repositoryId: linked.repository.id
248
+ });
249
+ const result = await gitlab.versionControl.listPullRequests({
250
+ ...target,
251
+ includeDrafts: false,
252
+ cursor: String(page)
253
+ });
254
+ return c.json({
255
+ pullRequests: result.pullRequests.map((pr) => ({
256
+ number: Number(pr.id),
257
+ externalId: mergeRequestSourceKey(linked.host, projectId, Number(pr.id)),
258
+ title: pr.title,
259
+ url: pr.url,
260
+ author: pr.author,
261
+ assignees: pr.assignees ?? [],
262
+ requestedReviewers: pr.requestedReviewers ?? [],
263
+ baseBranch: pr.baseBranch,
264
+ headBranch: pr.headBranch,
265
+ createdAt: pr.createdAt,
266
+ updatedAt: pr.updatedAt
267
+ })),
268
+ nextPage: result.nextCursor === null ? null : Number(result.nextCursor)
269
+ });
270
+ } catch (error) {
271
+ return gitlabFetchError(loose(c), error);
272
+ }
273
+ }
274
+ }), registerApiRoute("/web/gitlab/projects/:id/prs/:number", {
275
+ method: "GET",
276
+ requiresAuth: false,
277
+ handler: async (c) => {
278
+ const resolved = await resolveOrgTenant(loose(c), auth);
279
+ if ("response" in resolved) return resolved.response;
280
+ const factoryProjectId = c.req.query("factoryProjectId")?.trim();
281
+ const number = positiveId(c.req.param("number"));
282
+ if (!factoryProjectId || !number) return c.json({ error: "invalid_request" }, 400);
283
+ if (await gitlab.resolveOrgId(factoryProjectId) !== resolved.tenant.orgId) return c.json({ error: "factory_project_not_found" }, 404);
284
+ const linked = await gitlab.getLinkedRepository({
285
+ orgId: resolved.tenant.orgId,
286
+ factoryProjectId,
287
+ projectRepositoryId: c.req.param("id")
288
+ });
289
+ if (!linked) return c.json({ error: "project_repository_not_found" }, 404);
290
+ try {
291
+ const target = await gitlab.versionControl.getRepositoryTarget({
292
+ orgId: resolved.tenant.orgId,
293
+ repositoryId: linked.repository.id
294
+ });
295
+ const pr = await gitlab.versionControl.getPullRequest({
296
+ ...target,
297
+ pullRequestId: String(number)
298
+ });
299
+ if (!pr) return c.json({ error: "merge_request_not_found" }, 404);
300
+ return c.json({
301
+ number,
302
+ title: pr.title,
303
+ url: pr.url,
304
+ author: pr.author,
305
+ assignees: pr.assignees ?? [],
306
+ requestedReviewers: pr.requestedReviewers ?? [],
307
+ baseBranch: pr.baseBranch,
308
+ headBranch: pr.headBranch,
309
+ createdAt: pr.createdAt,
310
+ updatedAt: pr.updatedAt,
311
+ description: pr.body
312
+ });
313
+ } catch (error) {
314
+ return gitlabFetchError(loose(c), error);
315
+ }
316
+ }
317
+ }));
318
+ if (gitlab && auth && intake) {
319
+ routes.push(registerApiRoute("/web/gitlab/issues", {
320
+ method: "GET",
321
+ requiresAuth: false,
322
+ handler: async (c) => {
323
+ const resolved = await resolveOrgTenant(loose(c), auth);
324
+ if ("response" in resolved) return resolved.response;
325
+ const factoryProjectId = c.req.query("factoryProjectId")?.trim();
326
+ if (!factoryProjectId) return c.json({ error: "invalid_factory_project_id" }, 400);
327
+ const board = c.req.query("board")?.trim();
328
+ if (!board) return c.json({ error: "invalid_board" }, 400);
329
+ if (await gitlab.resolveOrgId(factoryProjectId) !== resolved.tenant.orgId) return c.json({ error: "factory_project_not_found" }, 404);
330
+ await intake.ensureReady();
331
+ const selection = (await intake.getConfig({
332
+ orgId: resolved.tenant.orgId,
333
+ integrationIds: ["gitlab"]
334
+ })).gitlab;
335
+ if (!selection.enabled) return c.json({
336
+ error: "gitlab_intake_disabled",
337
+ message: "GitLab intake is turned off in Settings."
338
+ }, 404);
339
+ const selected = new Set(selection.sourceIds ?? []);
340
+ const sourceIds = [...new Set((await intake.listBindings({
341
+ orgId: resolved.tenant.orgId,
342
+ integrationId: "gitlab"
343
+ })).filter((binding) => binding.factoryProjectId === factoryProjectId && binding.board === board && selected.has(binding.sourceId)).map((binding) => binding.sourceId))];
344
+ if (sourceIds.length === 0) return c.json({
345
+ issues: [],
346
+ nextCursor: null
347
+ });
348
+ try {
349
+ const result = await gitlab.intake.listIssues({
350
+ connection: {
351
+ type: "oauth",
352
+ accessToken: "gitlab-route"
353
+ },
354
+ sourceIds,
355
+ cursor: c.req.query("after")?.trim() || void 0
356
+ });
357
+ return c.json({
358
+ ...result,
359
+ issues: result.issues.map((issue) => {
360
+ const source = decodeSourceId(issue.sourceId ?? "");
361
+ const issueIid = Number(issue.id);
362
+ if (!source || !Number.isSafeInteger(issueIid) || issueIid <= 0) throw new Error("GitLab returned an invalid routed issue reference.");
363
+ return {
364
+ ...issue,
365
+ externalId: encodeIssueReference({
366
+ ...source,
367
+ issueIid
368
+ })
369
+ };
370
+ })
371
+ });
372
+ } catch (error) {
373
+ return gitlabFetchError(loose(c), error);
374
+ }
375
+ }
376
+ }));
377
+ routes.push(registerApiRoute("/web/gitlab/issues/:issueId", {
378
+ method: "GET",
379
+ requiresAuth: false,
380
+ handler: async (c) => {
381
+ const resolved = await resolveOrgTenant(loose(c), auth);
382
+ if ("response" in resolved) return resolved.response;
383
+ const factoryProjectId = c.req.query("factoryProjectId")?.trim();
384
+ if (!factoryProjectId) return c.json({ error: "invalid_factory_project_id" }, 400);
385
+ if (await gitlab.resolveOrgId(factoryProjectId) !== resolved.tenant.orgId) return c.json({ error: "factory_project_not_found" }, 404);
386
+ const issueId = c.req.param("issueId")?.trim();
387
+ const issueReference = issueId ? decodeIssueReference(issueId) : null;
388
+ if (!issueReference) return c.json({ error: "invalid_gitlab_issue_id" }, 400);
389
+ const { host, connectionId, projectId, projectPath } = issueReference;
390
+ const sourceId = host ? encodeSourceId({
391
+ host,
392
+ projectId
393
+ }) : encodeSourceId({
394
+ connectionId,
395
+ projectId,
396
+ projectPath
397
+ });
398
+ await intake.ensureReady();
399
+ const selection = (await intake.getConfig({
400
+ orgId: resolved.tenant.orgId,
401
+ integrationIds: ["gitlab"]
402
+ })).gitlab;
403
+ const selected = new Set(selection.sourceIds ?? []);
404
+ if (!(selection.enabled && selected.has(sourceId) && (await intake.listBindings({
405
+ orgId: resolved.tenant.orgId,
406
+ integrationId: "gitlab"
407
+ })).some((binding) => binding.factoryProjectId === factoryProjectId && binding.sourceId === sourceId))) return c.json({ error: "gitlab_issue_not_routed" }, 404);
408
+ try {
409
+ const issue = await gitlab.intake.getIssue({
410
+ connection: {
411
+ type: "oauth",
412
+ accessToken: "gitlab-route"
413
+ },
414
+ issueId
415
+ });
416
+ if (!issue) return c.json({ error: "gitlab_issue_not_found" }, 404);
417
+ return c.json(issue);
418
+ } catch (error) {
419
+ return gitlabFetchError(loose(c), error);
420
+ }
421
+ }
422
+ }));
423
+ }
424
+ if (gitlab && auth) routes.push(registerApiRoute("/web/gitlab/subscriptions", {
425
+ method: "GET",
426
+ requiresAuth: false,
427
+ handler: async (c) => {
428
+ await auth.ensureUser(loose(c));
429
+ const tenant = auth.tenant(loose(c));
430
+ if (!tenant?.orgId) return c.json({ error: "unauthorized" }, 401);
431
+ const resourceId = c.req.query("resourceId");
432
+ const threadId = c.req.query("threadId");
433
+ const sessionScope = c.req.query("scope");
434
+ if (!resourceId || !threadId) return c.json({ error: "resourceId and threadId are required" }, 400);
435
+ const subscriptions = await listMergeRequestSubscriptionsForThread({
436
+ orgId: tenant.orgId,
437
+ resourceId,
438
+ threadId,
439
+ sessionScope
440
+ }, gitlab.integrationStorage);
441
+ return c.json({ subscriptions: subscriptions.map((subscription) => ({
442
+ id: subscription.id,
443
+ repoFullName: subscription.data.projectPath,
444
+ pullRequestNumber: Number(subscription.data.changeRequestId),
445
+ status: subscription.status,
446
+ url: mergeRequestUrl(subscription.data.host, subscription.data.projectPath, subscription.data.changeRequestId)
447
+ })) });
448
+ }
449
+ }));
450
+ routes.push(registerApiRoute("/web/gitlab/webhook", {
451
+ method: "POST",
452
+ requiresAuth: false,
453
+ handler: async (c) => {
454
+ const result = await handleGitLabWebhook(loose(c), {
455
+ webhookSecret: options.webhookSecret,
456
+ ingestFactoryEvent: options.ingestFactoryEvent,
457
+ ...options.controller && gitlab ? {
458
+ controller: options.controller,
459
+ gitlab,
460
+ onTargetError: (subscription, error) => {
461
+ console.warn(`[GitLab Webhook] Delivery failed for subscription ${subscription.id} (${subscription.resourceId}/${subscription.threadId}).`, error);
462
+ }
463
+ } : {}
464
+ });
465
+ return c.json(result.body, result.status);
466
+ }
467
+ }));
468
+ return routes;
469
+ }
470
+ //#endregion
471
+ export { buildGitLabRoutes };
472
+
473
+ //# sourceMappingURL=routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","names":[],"sources":["../../../src/integrations/gitlab/routes.ts"],"sourcesContent":["import type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { MastraFactorySandboxConfig } from '../../sandbox/session-sandbox.js';\nimport { sanitizeSegment } from '../../sandbox/workdir.js';\nimport type { AuditEmitter } from '../../storage/domains/audit/domain.js';\nimport type { IntakeStorage } from '../../storage/domains/intake/base.js';\nimport { GitLabApiError } from './api.js';\nimport {\n decodeIssueReference,\n decodeSourceId,\n encodeIssueReference,\n encodeSourceId,\n gitlabConnection,\n} from './integration.js';\nimport type { GitLabIntegrationBase } from './integration.js';\nimport { listMergeRequestSubscriptionsForThread, mergeRequestUrl } from './subscriptions.js';\nimport { handleGitLabWebhook } from './webhook.js';\nimport type { GitLabWebhookHandlerOptions, ParsedGitLabWebhook } from './webhook.js';\n\ntype RouteContext = Context;\n\nfunction loose(c: unknown): RouteContext {\n return c as RouteContext;\n}\n\nexport interface BuildGitLabRoutesOptions {\n gitlab?: GitLabIntegrationBase;\n auth?: RouteAuth;\n intake?: IntakeStorage;\n sandbox?: MastraFactorySandboxConfig;\n emitAudit?: AuditEmitter['emit'];\n webhookSecret?: string;\n ingestFactoryEvent?: (event: ParsedGitLabWebhook) => Promise<unknown>;\n /** Mounted agent controller; enables webhook delivery to subscribed sessions. */\n controller?: GitLabWebhookHandlerOptions['controller'];\n}\n\nasync function resolveOrgTenant(\n c: RouteContext,\n auth: RouteAuth,\n): Promise<{ tenant: { orgId: string; userId: string } } | { response: Response }> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized', reason: 'auth_required' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json(\n {\n error: 'organization_required',\n message: 'GitLab intake requires an organization. Personal accounts cannot use GitLab intake.',\n },\n 403,\n ),\n };\n }\n return { tenant: { orgId: tenant.orgId, userId: tenant.userId } };\n}\n\nfunction gitlabFetchError(c: RouteContext, error: unknown) {\n if (error instanceof GitLabApiError && error.code === 'gitlab_auth_failed') {\n return c.json({ error: 'gitlab_auth_failed', message: error.message }, 409);\n }\n return c.json({ error: 'gitlab_fetch_failed', message: error instanceof Error ? error.message : String(error) }, 502);\n}\n\ntype GitLabSourceIdentityMigration = { from: string; to: string };\n\nfunction gitlabProjectPayload(source: { id: string; name: string; metadata?: Record<string, unknown> }) {\n const connectionId = typeof source.metadata?.connectionId === 'string' ? source.metadata.connectionId : null;\n const projectId = typeof source.metadata?.projectId === 'string' ? source.metadata.projectId : null;\n const projectPath = typeof source.metadata?.projectPath === 'string' ? source.metadata.projectPath : source.name;\n if (!connectionId || !projectId) return null;\n const repositoryName = projectPath.split('/').filter(Boolean).at(-1) ?? 'repo';\n return {\n id: source.id,\n name: source.name,\n projectId,\n projectPath,\n connectionId,\n accountLabel: typeof source.metadata?.accountLabel === 'string' ? source.metadata.accountLabel : null,\n defaultBranch: typeof source.metadata?.defaultBranch === 'string' ? source.metadata.defaultBranch : 'main',\n sandboxProvider: 'none',\n sandboxWorkdir: `~/${sanitizeSegment(repositoryName)}`,\n };\n}\n\nfunction positiveId(value: string | undefined): number | null {\n const number = Number(value);\n return value && /^[1-9]\\d*$/.test(value) && Number.isSafeInteger(number) ? number : null;\n}\n\nfunction mergeRequestSourceKey(host: string, projectId: number, mergeRequestIid: number): string {\n return `gitlab-pr:${Buffer.from(JSON.stringify({ version: 1, host, projectId, mergeRequestIid }), 'utf8').toString('base64url')}`;\n}\n\nasync function reconcileGitLabSourceIdentity({\n intake,\n orgId,\n sources,\n}: {\n intake: IntakeStorage;\n orgId: string;\n sources: Array<{ id: string; metadata?: Record<string, unknown> }>;\n}): Promise<{ migrations: GitLabSourceIdentityMigration[]; conflicts: GitLabSourceIdentityMigration[] }> {\n await intake.ensureReady();\n const [config, bindings] = await Promise.all([\n intake.getConfig({ orgId }),\n intake.listBindings({ orgId, integrationId: 'gitlab' }),\n ]);\n const selected = config.gitlab?.sourceIds ?? [];\n const canonicalByProject = new Map<string, string[]>();\n for (const source of sources) {\n const reference = decodeSourceId(source.id);\n if (!reference?.host) continue;\n const ids = canonicalByProject.get(reference.projectId) ?? [];\n ids.push(source.id);\n canonicalByProject.set(reference.projectId, ids);\n }\n\n const migrations = new Map<string, string>();\n for (const sourceId of new Set([...selected, ...bindings.map(binding => binding.sourceId)])) {\n const reference = decodeSourceId(sourceId);\n if (!reference || reference.host) continue;\n const candidates = canonicalByProject.get(reference.projectId) ?? [];\n if (candidates.length === 1) migrations.set(sourceId, candidates[0]!);\n }\n return intake.migrateSourceIds({\n orgId,\n integrationId: 'gitlab',\n migrations: [...migrations].map(([from, to]) => ({ from, to })),\n });\n}\n\nexport function buildGitLabRoutes(options: BuildGitLabRoutesOptions): ApiRoute[] {\n const routes: ApiRoute[] = [];\n const { gitlab, auth, intake, emitAudit } = options;\n const enabled = Boolean(gitlab && auth?.enabled());\n\n if (gitlab && auth) {\n routes.push(\n registerApiRoute('/web/gitlab/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const diagnostics = gitlab.diagnostics();\n if (!enabled) {\n return c.json({ enabled: false, configured: true, reauthRequired: false, reason: 'missing_config' });\n }\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n if (!tenant.orgId) {\n return c.json({\n enabled: true,\n configured: false,\n organizationRequired: true,\n connections: [],\n accounts: [],\n reauthRequired: false,\n reason: 'organization_required',\n });\n }\n\n try {\n await gitlab.verifyStatus();\n const connections = await gitlab.statusConnections();\n const active = connections?.filter(connection => connection.status === 'active');\n const direct = connections === undefined;\n const endpointHost = typeof diagnostics.endpointHost === 'string' ? diagnostics.endpointHost : null;\n const accounts = direct\n ? endpointHost\n ? [endpointHost]\n : []\n : (active ?? []).flatMap(connection => (connection.accountLabel ? [connection.accountLabel] : []));\n const configured = direct || (active?.length ?? 0) > 0;\n return c.json({\n enabled: true,\n configured,\n mode: direct ? 'direct' : 'platform',\n ...(connections ? { connections } : {}),\n accounts,\n reauthRequired: connections?.some(connection => connection.status === 'needs_reauth') ?? false,\n reason: configured ? 'ready' : 'not_connected',\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n try {\n const sources = await gitlab.intake.listSources(resolved.tenant);\n if (intake) {\n const identity = await reconcileGitLabSourceIdentity({\n intake,\n orgId: resolved.tenant.orgId,\n sources,\n });\n if (identity.conflicts.length > 0) {\n return c.json(\n {\n error: 'gitlab_source_identity_conflict',\n message: 'Conflicting routes exist for the same GitLab project. Resolve the duplicate bindings.',\n conflicts: identity.conflicts,\n },\n 409,\n );\n }\n if (identity.migrations.length > 0) {\n await emitAudit?.({\n context: loose(c),\n input: {\n action: 'factory.intake.config_updated',\n targets: identity.migrations.map(migration => ({ type: 'intake_source', id: migration.to })),\n metadata: { provider: 'gitlab', migrated: identity.migrations.length },\n },\n });\n }\n }\n return c.json({\n projects: sources.flatMap(source => {\n const project = gitlabProjectPayload(source);\n return project ? [{ ...project, sandboxProvider: options.sandbox ? 'custom' : 'none' }] : [];\n }),\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/registration', {\n method: 'POST',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const input = (await c.req.json().catch(() => null)) as { sourceId?: unknown } | null;\n const sourceId = typeof input?.sourceId === 'string' ? input.sourceId.trim() : '';\n if (!sourceId) return c.json({ error: 'invalid_gitlab_source' }, 400);\n try {\n const source = (await gitlab.intake.listSources(resolved.tenant)).find(\n candidate => candidate.id === sourceId,\n );\n const project = source ? gitlabProjectPayload(source) : null;\n if (!project) return c.json({ error: 'gitlab_project_not_found' }, 404);\n const installation = await gitlab.versionControl.registerInstallation({\n orgId: resolved.tenant.orgId,\n userId: resolved.tenant.userId,\n installation: {\n externalId: project.connectionId,\n accountName: project.accountLabel ?? 'GitLab',\n accountType: 'GitLab',\n metadata: { connection: gitlabConnection(project.connectionId) },\n },\n });\n return c.json({\n project: {\n ...project,\n installationStorageId: installation.id,\n sandboxProvider: options.sandbox ? 'custom' : 'none',\n },\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/:id/prs', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n const page = positiveId(c.req.query('page') ?? '1');\n if (!factoryProjectId || !page) return c.json({ error: 'invalid_request' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId)\n return c.json({ error: 'factory_project_not_found' }, 404);\n const linked = await gitlab.getLinkedRepository({\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n projectRepositoryId: c.req.param('id'),\n });\n if (!linked) return c.json({ error: 'project_repository_not_found' }, 404);\n const projectId = positiveId(linked.repository.externalId);\n if (!projectId) return c.json({ error: 'invalid_gitlab_project' }, 502);\n try {\n const target = await gitlab.versionControl.getRepositoryTarget({\n orgId: resolved.tenant.orgId,\n repositoryId: linked.repository.id,\n });\n const result = await gitlab.versionControl.listPullRequests({\n ...target,\n includeDrafts: false,\n cursor: String(page),\n });\n return c.json({\n pullRequests: result.pullRequests.map(pr => ({\n number: Number(pr.id),\n externalId: mergeRequestSourceKey(linked.host, projectId, Number(pr.id)),\n title: pr.title,\n url: pr.url,\n author: pr.author,\n assignees: pr.assignees ?? [],\n requestedReviewers: pr.requestedReviewers ?? [],\n baseBranch: pr.baseBranch,\n headBranch: pr.headBranch,\n createdAt: pr.createdAt,\n updatedAt: pr.updatedAt,\n })),\n nextPage: result.nextCursor === null ? null : Number(result.nextCursor),\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n registerApiRoute('/web/gitlab/projects/:id/prs/:number', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n const number = positiveId(c.req.param('number'));\n if (!factoryProjectId || !number) return c.json({ error: 'invalid_request' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId)\n return c.json({ error: 'factory_project_not_found' }, 404);\n const linked = await gitlab.getLinkedRepository({\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n projectRepositoryId: c.req.param('id'),\n });\n if (!linked) return c.json({ error: 'project_repository_not_found' }, 404);\n try {\n const target = await gitlab.versionControl.getRepositoryTarget({\n orgId: resolved.tenant.orgId,\n repositoryId: linked.repository.id,\n });\n const pr = await gitlab.versionControl.getPullRequest({ ...target, pullRequestId: String(number) });\n if (!pr) return c.json({ error: 'merge_request_not_found' }, 404);\n return c.json({\n number,\n title: pr.title,\n url: pr.url,\n author: pr.author,\n assignees: pr.assignees ?? [],\n requestedReviewers: pr.requestedReviewers ?? [],\n baseBranch: pr.baseBranch,\n headBranch: pr.headBranch,\n createdAt: pr.createdAt,\n updatedAt: pr.updatedAt,\n description: pr.body,\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n }\n\n if (gitlab && auth && intake) {\n routes.push(\n registerApiRoute('/web/gitlab/issues', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n if (!factoryProjectId) return c.json({ error: 'invalid_factory_project_id' }, 400);\n const board = c.req.query('board')?.trim();\n if (!board) return c.json({ error: 'invalid_board' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId) {\n return c.json({ error: 'factory_project_not_found' }, 404);\n }\n\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['gitlab'] });\n const selection = config.gitlab!;\n if (!selection.enabled) {\n return c.json(\n { error: 'gitlab_intake_disabled', message: 'GitLab intake is turned off in Settings.' },\n 404,\n );\n }\n const selected = new Set(selection.sourceIds ?? []);\n const sourceIds = [\n ...new Set(\n (await intake.listBindings({ orgId: resolved.tenant.orgId, integrationId: 'gitlab' }))\n .filter(\n binding =>\n binding.factoryProjectId === factoryProjectId &&\n binding.board === board &&\n selected.has(binding.sourceId),\n )\n .map(binding => binding.sourceId),\n ),\n ];\n if (sourceIds.length === 0) return c.json({ issues: [], nextCursor: null });\n\n try {\n const result = await gitlab.intake.listIssues({\n connection: { type: 'oauth', accessToken: 'gitlab-route' },\n sourceIds,\n cursor: c.req.query('after')?.trim() || undefined,\n });\n return c.json({\n ...result,\n issues: result.issues.map(issue => {\n const source = decodeSourceId(issue.sourceId ?? '');\n const issueIid = Number(issue.id);\n if (!source || !Number.isSafeInteger(issueIid) || issueIid <= 0) {\n throw new Error('GitLab returned an invalid routed issue reference.');\n }\n return { ...issue, externalId: encodeIssueReference({ ...source, issueIid }) };\n }),\n });\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n\n routes.push(\n registerApiRoute('/web/gitlab/issues/:issueId', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n const factoryProjectId = c.req.query('factoryProjectId')?.trim();\n if (!factoryProjectId) return c.json({ error: 'invalid_factory_project_id' }, 400);\n if ((await gitlab.resolveOrgId(factoryProjectId)) !== resolved.tenant.orgId) {\n return c.json({ error: 'factory_project_not_found' }, 404);\n }\n const issueId = c.req.param('issueId')?.trim();\n const issueReference = issueId ? decodeIssueReference(issueId) : null;\n if (!issueReference) return c.json({ error: 'invalid_gitlab_issue_id' }, 400);\n\n const { host, connectionId, projectId, projectPath } = issueReference;\n const sourceId = host\n ? encodeSourceId({ host, projectId })\n : encodeSourceId({ connectionId, projectId, projectPath });\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['gitlab'] });\n const selection = config.gitlab!;\n const selected = new Set(selection.sourceIds ?? []);\n const routed =\n selection.enabled &&\n selected.has(sourceId) &&\n (await intake.listBindings({ orgId: resolved.tenant.orgId, integrationId: 'gitlab' })).some(\n binding => binding.factoryProjectId === factoryProjectId && binding.sourceId === sourceId,\n );\n if (!routed) return c.json({ error: 'gitlab_issue_not_routed' }, 404);\n\n try {\n const issue = await gitlab.intake.getIssue({\n connection: { type: 'oauth', accessToken: 'gitlab-route' },\n issueId,\n });\n if (!issue) return c.json({ error: 'gitlab_issue_not_found' }, 404);\n return c.json(issue);\n } catch (error) {\n return gitlabFetchError(loose(c), error);\n }\n },\n }),\n );\n }\n\n if (gitlab && auth) {\n routes.push(\n registerApiRoute('/web/gitlab/subscriptions', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant?.orgId) return c.json({ error: 'unauthorized' }, 401);\n\n const resourceId = c.req.query('resourceId');\n const threadId = c.req.query('threadId');\n const sessionScope = c.req.query('scope');\n if (!resourceId || !threadId) return c.json({ error: 'resourceId and threadId are required' }, 400);\n\n const subscriptions = await listMergeRequestSubscriptionsForThread(\n { orgId: tenant.orgId, resourceId, threadId, sessionScope },\n gitlab.integrationStorage,\n );\n return c.json({\n subscriptions: subscriptions.map(subscription => ({\n id: subscription.id,\n repoFullName: subscription.data.projectPath,\n pullRequestNumber: Number(subscription.data.changeRequestId),\n status: subscription.status,\n url: mergeRequestUrl(\n subscription.data.host,\n subscription.data.projectPath,\n subscription.data.changeRequestId,\n ),\n })),\n });\n },\n }),\n );\n }\n\n routes.push(\n registerApiRoute('/web/gitlab/webhook', {\n method: 'POST',\n requiresAuth: false,\n handler: async c => {\n const result = await handleGitLabWebhook(loose(c), {\n webhookSecret: options.webhookSecret,\n ingestFactoryEvent: options.ingestFactoryEvent,\n ...(options.controller && gitlab\n ? {\n controller: options.controller,\n gitlab,\n onTargetError: (subscription, error) => {\n console.warn(\n `[GitLab Webhook] Delivery failed for subscription ${subscription.id} (${subscription.resourceId}/${subscription.threadId}).`,\n error,\n );\n },\n }\n : {}),\n });\n return c.json(result.body, result.status);\n },\n }),\n );\n return routes;\n}\n"],"mappings":";;;;;;;AAuBA,SAAS,MAAM,GAA0B;CACvC,OAAO;AACT;AAcA,eAAe,iBACb,GACA,MACiF;CACjF,MAAM,KAAK,WAAW,CAAC;CACvB,MAAM,SAAS,KAAK,OAAO,CAAC;CAC5B,IAAI,CAAC,QAAQ,OAAO,EAAE,UAAU,EAAE,KAAK;EAAE,OAAO;EAAgB,QAAQ;CAAgB,GAAG,GAAG,EAAE;CAChG,IAAI,CAAC,OAAO,OACV,OAAO,EACL,UAAU,EAAE,KACV;EACE,OAAO;EACP,SAAS;CACX,GACA,GACF,EACF;CAEF,OAAO,EAAE,QAAQ;EAAE,OAAO,OAAO;EAAO,QAAQ,OAAO;CAAO,EAAE;AAClE;AAEA,SAAS,iBAAiB,GAAiB,OAAgB;CACzD,IAAI,iBAAiB,kBAAkB,MAAM,SAAS,sBACpD,OAAO,EAAE,KAAK;EAAE,OAAO;EAAsB,SAAS,MAAM;CAAQ,GAAG,GAAG;CAE5E,OAAO,EAAE,KAAK;EAAE,OAAO;EAAuB,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CAAE,GAAG,GAAG;AACtH;AAIA,SAAS,qBAAqB,QAA0E;CACtG,MAAM,eAAe,OAAO,OAAO,UAAU,iBAAiB,WAAW,OAAO,SAAS,eAAe;CACxG,MAAM,YAAY,OAAO,OAAO,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