@mastra/factory 0.28.0 → 0.29.0-alpha.1

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 (407) hide show
  1. package/README.md +26 -8
  2. package/dist/board-changes.d.ts +16 -0
  3. package/dist/board-changes.d.ts.map +1 -0
  4. package/dist/board-changes.js +40 -0
  5. package/dist/board-changes.js.map +1 -0
  6. package/dist/boards/index.js +2 -1
  7. package/dist/boards/reroute.d.ts +31 -0
  8. package/dist/boards/reroute.d.ts.map +1 -0
  9. package/dist/boards/reroute.js +71 -0
  10. package/dist/boards/reroute.js.map +1 -0
  11. package/dist/boards/semantics.d.ts +1 -3
  12. package/dist/boards/semantics.d.ts.map +1 -1
  13. package/dist/boards/semantics.js +1 -5
  14. package/dist/boards/semantics.js.map +1 -1
  15. package/dist/environment/repository-access.d.ts +2 -0
  16. package/dist/environment/repository-access.d.ts.map +1 -1
  17. package/dist/environment/repository-access.js +9 -4
  18. package/dist/environment/repository-access.js.map +1 -1
  19. package/dist/factory.d.ts +4 -0
  20. package/dist/factory.d.ts.map +1 -1
  21. package/dist/factory.js +60 -9
  22. package/dist/factory.js.map +1 -1
  23. package/dist/integrations/base.d.ts +17 -0
  24. package/dist/integrations/base.d.ts.map +1 -1
  25. package/dist/integrations/dependabot/default-rules.d.ts +38 -0
  26. package/dist/integrations/dependabot/default-rules.d.ts.map +1 -0
  27. package/dist/integrations/dependabot/default-rules.js +63 -0
  28. package/dist/integrations/dependabot/default-rules.js.map +1 -0
  29. package/dist/integrations/dependabot/rules.d.ts +42 -0
  30. package/dist/integrations/dependabot/rules.d.ts.map +1 -0
  31. package/dist/integrations/dependabot/rules.js +187 -0
  32. package/dist/integrations/dependabot/rules.js.map +1 -0
  33. package/dist/integrations/dependabot/sync.d.ts +76 -0
  34. package/dist/integrations/dependabot/sync.d.ts.map +1 -0
  35. package/dist/integrations/dependabot/sync.js +111 -0
  36. package/dist/integrations/dependabot/sync.js.map +1 -0
  37. package/dist/integrations/github/pull-request-source.js +2 -1
  38. package/dist/integrations/github/pull-request-source.js.map +1 -1
  39. package/dist/integrations/github/reconcile-worker.js +1 -1
  40. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  41. package/dist/integrations/github/routes.d.ts.map +1 -1
  42. package/dist/integrations/github/routes.js +7 -2
  43. package/dist/integrations/github/routes.js.map +1 -1
  44. package/dist/integrations/github/rules.d.ts +5 -2
  45. package/dist/integrations/github/rules.d.ts.map +1 -1
  46. package/dist/integrations/github/rules.js +16 -13
  47. package/dist/integrations/github/rules.js.map +1 -1
  48. package/dist/integrations/github/sandbox.d.ts +12 -0
  49. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  50. package/dist/integrations/github/sandbox.js +24 -3
  51. package/dist/integrations/github/sandbox.js.map +1 -1
  52. package/dist/integrations/gitlab/default-rules.js +2 -1
  53. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  54. package/dist/integrations/gitlab/discovery.d.ts +16 -0
  55. package/dist/integrations/gitlab/discovery.d.ts.map +1 -0
  56. package/dist/integrations/gitlab/discovery.js +107 -0
  57. package/dist/integrations/gitlab/discovery.js.map +1 -0
  58. package/dist/integrations/gitlab/integration.d.ts.map +1 -1
  59. package/dist/integrations/gitlab/integration.js +1 -2
  60. package/dist/integrations/gitlab/integration.js.map +1 -1
  61. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -1
  62. package/dist/integrations/gitlab/issue-reconciler.js +1 -0
  63. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
  64. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
  65. package/dist/integrations/gitlab/merge-request-reconciler.js +26 -10
  66. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
  67. package/dist/integrations/gitlab/reconciler.d.ts.map +1 -1
  68. package/dist/integrations/gitlab/reconciler.js +4 -2
  69. package/dist/integrations/gitlab/reconciler.js.map +1 -1
  70. package/dist/integrations/gitlab/reconciliation-config.d.ts +0 -1
  71. package/dist/integrations/gitlab/reconciliation-config.d.ts.map +1 -1
  72. package/dist/integrations/gitlab/reconciliation-config.js +2 -8
  73. package/dist/integrations/gitlab/reconciliation-config.js.map +1 -1
  74. package/dist/integrations/gitlab/routes.d.ts +17 -0
  75. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  76. package/dist/integrations/gitlab/routes.js +28 -22
  77. package/dist/integrations/gitlab/routes.js.map +1 -1
  78. package/dist/integrations/gitlab/rules.d.ts +10 -4
  79. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  80. package/dist/integrations/gitlab/rules.js +32 -8
  81. package/dist/integrations/gitlab/rules.js.map +1 -1
  82. package/dist/integrations/incidentio/integration.d.ts +2 -1
  83. package/dist/integrations/incidentio/integration.d.ts.map +1 -1
  84. package/dist/integrations/incidentio/integration.js +7 -7
  85. package/dist/integrations/incidentio/integration.js.map +1 -1
  86. package/dist/integrations/incidentio/issue-reconciler.d.ts +7 -0
  87. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
  88. package/dist/integrations/incidentio/issue-reconciler.js +36 -1
  89. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
  90. package/dist/integrations/incidentio/reconciliation-config.d.ts +0 -1
  91. package/dist/integrations/incidentio/reconciliation-config.d.ts.map +1 -1
  92. package/dist/integrations/incidentio/reconciliation-config.js +2 -5
  93. package/dist/integrations/incidentio/reconciliation-config.js.map +1 -1
  94. package/dist/integrations/incidentio/routes.d.ts +24 -8
  95. package/dist/integrations/incidentio/routes.d.ts.map +1 -1
  96. package/dist/integrations/incidentio/routes.js +33 -35
  97. package/dist/integrations/incidentio/routes.js.map +1 -1
  98. package/dist/integrations/incidentio/rules.d.ts +0 -4
  99. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  100. package/dist/integrations/incidentio/rules.js +17 -14
  101. package/dist/integrations/incidentio/rules.js.map +1 -1
  102. package/dist/integrations/intake-discovery.d.ts +44 -0
  103. package/dist/integrations/intake-discovery.d.ts.map +1 -0
  104. package/dist/integrations/intake-discovery.js +60 -0
  105. package/dist/integrations/intake-discovery.js.map +1 -0
  106. package/dist/integrations/issue-reconcile-worker.js +1 -1
  107. package/dist/integrations/issue-reconcile-worker.js.map +1 -1
  108. package/dist/integrations/issue-reconciler.d.ts +7 -0
  109. package/dist/integrations/issue-reconciler.d.ts.map +1 -1
  110. package/dist/integrations/issue-reconciler.js +47 -12
  111. package/dist/integrations/issue-reconciler.js.map +1 -1
  112. package/dist/integrations/jira/integration.d.ts +3 -2
  113. package/dist/integrations/jira/integration.d.ts.map +1 -1
  114. package/dist/integrations/jira/integration.js +5 -7
  115. package/dist/integrations/jira/integration.js.map +1 -1
  116. package/dist/integrations/jira/issue-reconciler.d.ts +17 -1
  117. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
  118. package/dist/integrations/jira/issue-reconciler.js +34 -1
  119. package/dist/integrations/jira/issue-reconciler.js.map +1 -1
  120. package/dist/integrations/jira/reconciliation-config.d.ts +0 -1
  121. package/dist/integrations/jira/reconciliation-config.d.ts.map +1 -1
  122. package/dist/integrations/jira/reconciliation-config.js +2 -5
  123. package/dist/integrations/jira/reconciliation-config.js.map +1 -1
  124. package/dist/integrations/jira/routes.d.ts +0 -7
  125. package/dist/integrations/jira/routes.d.ts.map +1 -1
  126. package/dist/integrations/jira/routes.js +2 -12
  127. package/dist/integrations/jira/routes.js.map +1 -1
  128. package/dist/integrations/jira/rules.d.ts +0 -4
  129. package/dist/integrations/jira/rules.d.ts.map +1 -1
  130. package/dist/integrations/jira/rules.js +3 -13
  131. package/dist/integrations/jira/rules.js.map +1 -1
  132. package/dist/integrations/kept-cards.d.ts +49 -0
  133. package/dist/integrations/kept-cards.d.ts.map +1 -0
  134. package/dist/integrations/kept-cards.js +97 -0
  135. package/dist/integrations/kept-cards.js.map +1 -0
  136. package/dist/integrations/linear/intake-discovery.d.ts +34 -0
  137. package/dist/integrations/linear/intake-discovery.d.ts.map +1 -0
  138. package/dist/integrations/linear/intake-discovery.js +112 -0
  139. package/dist/integrations/linear/intake-discovery.js.map +1 -0
  140. package/dist/integrations/linear/integration.d.ts.map +1 -1
  141. package/dist/integrations/linear/integration.js +1 -4
  142. package/dist/integrations/linear/integration.js.map +1 -1
  143. package/dist/integrations/linear/issue-reconciler.d.ts +13 -4
  144. package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -1
  145. package/dist/integrations/linear/issue-reconciler.js +24 -20
  146. package/dist/integrations/linear/issue-reconciler.js.map +1 -1
  147. package/dist/integrations/linear/reconciliation-config.d.ts +0 -1
  148. package/dist/integrations/linear/reconciliation-config.d.ts.map +1 -1
  149. package/dist/integrations/linear/reconciliation-config.js +2 -8
  150. package/dist/integrations/linear/reconciliation-config.js.map +1 -1
  151. package/dist/integrations/linear/routes.d.ts +0 -2
  152. package/dist/integrations/linear/routes.d.ts.map +1 -1
  153. package/dist/integrations/linear/routes.js +3 -9
  154. package/dist/integrations/linear/routes.js.map +1 -1
  155. package/dist/integrations/platform/api-client.d.ts +2 -0
  156. package/dist/integrations/platform/api-client.d.ts.map +1 -1
  157. package/dist/integrations/platform/api-client.js +6 -1
  158. package/dist/integrations/platform/api-client.js.map +1 -1
  159. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  160. package/dist/integrations/platform/connect/routes.js +8 -1
  161. package/dist/integrations/platform/connect/routes.js.map +1 -1
  162. package/dist/integrations/platform/github/event-worker.d.ts +17 -0
  163. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  164. package/dist/integrations/platform/github/event-worker.js +89 -7
  165. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  166. package/dist/integrations/platform/github/integration.d.ts +20 -1
  167. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  168. package/dist/integrations/platform/github/integration.js +54 -3
  169. package/dist/integrations/platform/github/integration.js.map +1 -1
  170. package/dist/integrations/platform/gitlab/event-worker.js +1 -1
  171. package/dist/integrations/platform/gitlab/event-worker.js.map +1 -1
  172. package/dist/integrations/platform/incidentio/integration.d.ts +3 -2
  173. package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
  174. package/dist/integrations/platform/incidentio/integration.js +7 -7
  175. package/dist/integrations/platform/incidentio/integration.js.map +1 -1
  176. package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
  177. package/dist/integrations/platform/jira/integration.js +4 -7
  178. package/dist/integrations/platform/jira/integration.js.map +1 -1
  179. package/dist/integrations/platform/jira/routes.d.ts +0 -7
  180. package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
  181. package/dist/integrations/platform/jira/routes.js +2 -12
  182. package/dist/integrations/platform/jira/routes.js.map +1 -1
  183. package/dist/integrations/platform/linear/event-worker.d.ts +2 -2
  184. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  185. package/dist/integrations/platform/linear/event-worker.js +1 -1
  186. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  187. package/dist/integrations/platform/linear/integration.d.ts +1 -0
  188. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  189. package/dist/integrations/platform/linear/integration.js +7 -7
  190. package/dist/integrations/platform/linear/integration.js.map +1 -1
  191. package/dist/integrations/platform/vanta/integration.d.ts +38 -0
  192. package/dist/integrations/platform/vanta/integration.d.ts.map +1 -0
  193. package/dist/integrations/platform/vanta/integration.js +149 -0
  194. package/dist/integrations/platform/vanta/integration.js.map +1 -0
  195. package/dist/integrations/reconciliation-config.d.ts +0 -1
  196. package/dist/integrations/reconciliation-config.d.ts.map +1 -1
  197. package/dist/integrations/reconciliation-config.js +1 -8
  198. package/dist/integrations/reconciliation-config.js.map +1 -1
  199. package/dist/integrations/slack/channel-reply-processor.js +1 -1
  200. package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
  201. package/dist/integrations/startup-summary.d.ts +8 -0
  202. package/dist/integrations/startup-summary.d.ts.map +1 -0
  203. package/dist/integrations/startup-summary.js +36 -0
  204. package/dist/integrations/startup-summary.js.map +1 -0
  205. package/dist/integrations/vanta/default-rules.d.ts +34 -0
  206. package/dist/integrations/vanta/default-rules.d.ts.map +1 -0
  207. package/dist/integrations/vanta/default-rules.js +61 -0
  208. package/dist/integrations/vanta/default-rules.js.map +1 -0
  209. package/dist/integrations/vanta/rules.d.ts +40 -0
  210. package/dist/integrations/vanta/rules.d.ts.map +1 -0
  211. package/dist/integrations/vanta/rules.js +208 -0
  212. package/dist/integrations/vanta/rules.js.map +1 -0
  213. package/dist/integrations/vanta/sync.d.ts +40 -0
  214. package/dist/integrations/vanta/sync.d.ts.map +1 -0
  215. package/dist/integrations/vanta/sync.js +81 -0
  216. package/dist/integrations/vanta/sync.js.map +1 -0
  217. package/dist/linked-repositories-changed.d.ts +14 -0
  218. package/dist/linked-repositories-changed.d.ts.map +1 -0
  219. package/dist/linked-repositories-changed.js +48 -0
  220. package/dist/linked-repositories-changed.js.map +1 -0
  221. package/dist/mcp/routes.d.ts.map +1 -1
  222. package/dist/mcp/routes.js +1 -1
  223. package/dist/mcp/routes.js.map +1 -1
  224. package/dist/routes/board-snapshot.d.ts +8 -1
  225. package/dist/routes/board-snapshot.d.ts.map +1 -1
  226. package/dist/routes/board-snapshot.js +23 -2
  227. package/dist/routes/board-snapshot.js.map +1 -1
  228. package/dist/routes/contracts.d.ts +322 -0
  229. package/dist/routes/contracts.d.ts.map +1 -1
  230. package/dist/routes/contracts.js +202 -5
  231. package/dist/routes/contracts.js.map +1 -1
  232. package/dist/routes/intake-routes.d.ts +3 -0
  233. package/dist/routes/intake-routes.d.ts.map +1 -1
  234. package/dist/routes/intake-routes.js +44 -0
  235. package/dist/routes/intake-routes.js.map +1 -1
  236. package/dist/routes/knowledge.d.ts.map +1 -1
  237. package/dist/routes/knowledge.js +3 -2
  238. package/dist/routes/knowledge.js.map +1 -1
  239. package/dist/routes/run-queue.d.ts +17 -0
  240. package/dist/routes/run-queue.d.ts.map +1 -0
  241. package/dist/routes/run-queue.js +69 -0
  242. package/dist/routes/run-queue.js.map +1 -0
  243. package/dist/routes/source-control-sessions.d.ts +1 -1
  244. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  245. package/dist/routes/source-control-sessions.js +109 -3
  246. package/dist/routes/source-control-sessions.js.map +1 -1
  247. package/dist/routes/surface.d.ts +14 -1
  248. package/dist/routes/surface.d.ts.map +1 -1
  249. package/dist/routes/surface.js +76 -11
  250. package/dist/routes/surface.js.map +1 -1
  251. package/dist/routes/work-item-selection.d.ts +4 -5
  252. package/dist/routes/work-item-selection.d.ts.map +1 -1
  253. package/dist/routes/work-item-selection.js +11 -23
  254. package/dist/routes/work-item-selection.js.map +1 -1
  255. package/dist/routes/work-item-starters.d.ts.map +1 -1
  256. package/dist/routes/work-item-starters.js +4 -21
  257. package/dist/routes/work-item-starters.js.map +1 -1
  258. package/dist/routes/work-items.d.ts +5 -0
  259. package/dist/routes/work-items.d.ts.map +1 -1
  260. package/dist/routes/work-items.js +129 -36
  261. package/dist/routes/work-items.js.map +1 -1
  262. package/dist/rules/dispatch-errors.d.ts +3 -0
  263. package/dist/rules/dispatch-errors.d.ts.map +1 -1
  264. package/dist/rules/dispatch-errors.js +5 -0
  265. package/dist/rules/dispatch-errors.js.map +1 -1
  266. package/dist/rules/dispatcher.d.ts +15 -1
  267. package/dist/rules/dispatcher.d.ts.map +1 -1
  268. package/dist/rules/dispatcher.js +48 -20
  269. package/dist/rules/dispatcher.js.map +1 -1
  270. package/dist/rules/index.d.ts +2 -2
  271. package/dist/rules/index.d.ts.map +1 -1
  272. package/dist/rules/index.js +2 -2
  273. package/dist/rules/review-source-tool.js +2 -1
  274. package/dist/rules/review-source-tool.js.map +1 -1
  275. package/dist/rules/start-coordinator.d.ts +6 -1
  276. package/dist/rules/start-coordinator.d.ts.map +1 -1
  277. package/dist/rules/start-coordinator.js +6 -2
  278. package/dist/rules/start-coordinator.js.map +1 -1
  279. package/dist/rules/transition-service.d.ts.map +1 -1
  280. package/dist/rules/transition-service.js +3 -2
  281. package/dist/rules/transition-service.js.map +1 -1
  282. package/dist/rules/types.d.ts +71 -3
  283. package/dist/rules/types.d.ts.map +1 -1
  284. package/dist/rules/types.js +10 -2
  285. package/dist/rules/types.js.map +1 -1
  286. package/dist/rules/validation.d.ts.map +1 -1
  287. package/dist/rules/validation.js +5 -0
  288. package/dist/rules/validation.js.map +1 -1
  289. package/dist/session/factory-session.d.ts +20 -5
  290. package/dist/session/factory-session.d.ts.map +1 -1
  291. package/dist/session/factory-session.js +20 -6
  292. package/dist/session/factory-session.js.map +1 -1
  293. package/dist/storage/domains/audit/actions.d.ts +1 -1
  294. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  295. package/dist/storage/domains/audit/actions.js +2 -1
  296. package/dist/storage/domains/audit/actions.js.map +1 -1
  297. package/dist/storage/domains/audit/actors.d.ts.map +1 -1
  298. package/dist/storage/domains/audit/actors.js +1 -1
  299. package/dist/storage/domains/audit/actors.js.map +1 -1
  300. package/dist/storage/domains/intake/base.d.ts +1 -1
  301. package/dist/storage/domains/intake/base.js +2 -2
  302. package/dist/storage/domains/intake/base.js.map +1 -1
  303. package/dist/storage/domains/projects/base.d.ts +10 -0
  304. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  305. package/dist/storage/domains/projects/base.js +24 -2
  306. package/dist/storage/domains/projects/base.js.map +1 -1
  307. package/dist/storage/domains/source-control/base.d.ts +32 -0
  308. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  309. package/dist/storage/domains/source-control/base.js +54 -4
  310. package/dist/storage/domains/source-control/base.js.map +1 -1
  311. package/dist/storage/domains/source-control/inmemory.d.ts +3 -0
  312. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  313. package/dist/storage/domains/source-control/inmemory.js +17 -0
  314. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  315. package/dist/storage/domains/work-items/base.d.ts +16 -4
  316. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  317. package/dist/storage/domains/work-items/base.js +28 -1
  318. package/dist/storage/domains/work-items/base.js.map +1 -1
  319. package/dist/timing.d.ts +8 -1
  320. package/dist/timing.d.ts.map +1 -1
  321. package/dist/timing.js +10 -2
  322. package/dist/timing.js.map +1 -1
  323. package/dist/tools/approval-tools.d.ts +20 -0
  324. package/dist/tools/approval-tools.d.ts.map +1 -1
  325. package/dist/tools/approval-tools.js +79 -30
  326. package/dist/tools/approval-tools.js.map +1 -1
  327. package/dist/tools/audit-events-tool.d.ts +1 -1
  328. package/dist/tools/messaging-tools.d.ts.map +1 -1
  329. package/dist/tools/messaging-tools.js +1 -1
  330. package/dist/tools/messaging-tools.js.map +1 -1
  331. package/dist/tools/read-tools.d.ts +0 -2
  332. package/dist/tools/read-tools.d.ts.map +1 -1
  333. package/dist/tools/read-tools.js +2 -7
  334. package/dist/tools/read-tools.js.map +1 -1
  335. package/dist/tools/reports.d.ts +3 -0
  336. package/dist/tools/reports.d.ts.map +1 -1
  337. package/dist/tools/reports.js +3 -3
  338. package/dist/tools/reports.js.map +1 -1
  339. package/dist/tools/run-watch.d.ts +14 -2
  340. package/dist/tools/run-watch.d.ts.map +1 -1
  341. package/dist/tools/run-watch.js +24 -4
  342. package/dist/tools/run-watch.js.map +1 -1
  343. package/dist/tools/session-tools.d.ts.map +1 -1
  344. package/dist/tools/session-tools.js +17 -6
  345. package/dist/tools/session-tools.js.map +1 -1
  346. package/dist/tools/side-sessions.d.ts.map +1 -1
  347. package/dist/tools/side-sessions.js +1 -1
  348. package/dist/tools/side-sessions.js.map +1 -1
  349. package/dist/tools/work-item-tools.d.ts.map +1 -1
  350. package/dist/tools/work-item-tools.js +12 -2
  351. package/dist/tools/work-item-tools.js.map +1 -1
  352. package/dist/work-item-branch.d.ts +1 -1
  353. package/dist/work-item-branch.d.ts.map +1 -1
  354. package/dist/work-item-branch.js +2 -0
  355. package/dist/work-item-branch.js.map +1 -1
  356. package/dist/work-items/board-filter-options.d.ts +5 -0
  357. package/dist/work-items/board-filter-options.d.ts.map +1 -0
  358. package/dist/work-items/board-filter-options.js +27 -0
  359. package/dist/work-items/board-filter-options.js.map +1 -0
  360. package/dist/work-items/board-phases.d.ts +28 -0
  361. package/dist/work-items/board-phases.d.ts.map +1 -0
  362. package/dist/work-items/board-phases.js +165 -0
  363. package/dist/work-items/board-phases.js.map +1 -0
  364. package/dist/work-items/card-facts.d.ts +24 -0
  365. package/dist/work-items/card-facts.d.ts.map +1 -0
  366. package/dist/work-items/card-facts.js +75 -0
  367. package/dist/work-items/card-facts.js.map +1 -0
  368. package/dist/work-items/card-labels.d.ts +5 -0
  369. package/dist/work-items/card-labels.d.ts.map +1 -0
  370. package/dist/work-items/card-labels.js +13 -0
  371. package/dist/work-items/card-labels.js.map +1 -0
  372. package/dist/work-items/card-number.d.ts +10 -0
  373. package/dist/work-items/card-number.d.ts.map +1 -0
  374. package/dist/work-items/card-number.js +15 -0
  375. package/dist/work-items/card-number.js.map +1 -0
  376. package/dist/work-items/card-people.d.ts +25 -0
  377. package/dist/work-items/card-people.d.ts.map +1 -0
  378. package/dist/work-items/card-people.js +100 -0
  379. package/dist/work-items/card-people.js.map +1 -0
  380. package/dist/work-items/card-search-text.d.ts +4 -0
  381. package/dist/work-items/card-search-text.d.ts.map +1 -0
  382. package/dist/work-items/card-search-text.js +15 -0
  383. package/dist/work-items/card-search-text.js.map +1 -0
  384. package/dist/work-items/card-source-filters.d.ts +23 -0
  385. package/dist/work-items/card-source-filters.d.ts.map +1 -0
  386. package/dist/work-items/card-source-filters.js +25 -0
  387. package/dist/work-items/card-source-filters.js.map +1 -0
  388. package/dist/work-items/create-work-item.d.ts +0 -6
  389. package/dist/work-items/create-work-item.d.ts.map +1 -1
  390. package/dist/work-items/create-work-item.js +2 -7
  391. package/dist/work-items/create-work-item.js.map +1 -1
  392. package/dist/work-items/list-related-cards.d.ts +4 -0
  393. package/dist/work-items/list-related-cards.d.ts.map +1 -0
  394. package/dist/work-items/list-related-cards.js +24 -0
  395. package/dist/work-items/list-related-cards.js.map +1 -0
  396. package/dist/work-items/search-words.d.ts +5 -0
  397. package/dist/work-items/search-words.d.ts.map +1 -0
  398. package/dist/work-items/search-words.js +12 -0
  399. package/dist/work-items/search-words.js.map +1 -0
  400. package/dist/work-items/source-external-id.d.ts +4 -0
  401. package/dist/work-items/source-external-id.d.ts.map +1 -0
  402. package/dist/work-items/source-external-id.js +9 -0
  403. package/dist/work-items/source-external-id.js.map +1 -0
  404. package/dist/workspace.d.ts.map +1 -1
  405. package/dist/workspace.js +92 -47
  406. package/dist/workspace.js.map +1 -1
  407. package/package.json +9 -8
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/gitlab/default-rules.ts"],"sourcesContent":["import {\n isPullRequestCard,\n newestOpenPullRequestNumber,\n pullRequestSources,\n reviewedPullRequest,\n reviewsPullRequest,\n sourceExternalId,\n} from '../../boards/index.js';\nimport {\n closedByRoutes,\n pullRequestMoveByRoutes,\n recordExplicitRuleOverrides,\n routedOnly,\n unreviewedPullRequestCard,\n} from '../../rules/event-rules.js';\nimport type { FactoryGitLabEventName, FactoryGitLabRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport type { WorkItemSourceRow } from '../../storage/domains/work-items/work-item-schema.js';\n\nexport type GitLabRuleOverrides = Partial<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null | undefined>\n>;\nexport type GitLabEventRules = Readonly<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null>\n>;\n\nfunction actorUsername(context: Pick<FactoryGitLabRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'gitlab' ? context.actor.username : undefined;\n}\n\nfunction trustedGitLabActor(context: Pick<FactoryGitLabRuleContext, 'actor'>): boolean {\n return context.actor.type === 'gitlab' && context.actor.trusted;\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * The card whose session authored the merge request, as opposed to the merge request's own card,\n * on a board that reviews merge requests.\n */\nfunction authoringCard(context: FactoryGitLabRuleContext): boolean {\n return (\n context.flow?.pullRequestReview !== undefined && context.item !== undefined && !isPullRequestCard(context.item)\n );\n}\n\n/** Whether the card sits in its board's pull request review phase, alone. */\nfunction inPullRequestReview(context: FactoryGitLabRuleContext): boolean {\n const phase = context.flow?.pullRequestReview;\n return phase !== undefined && context.item?.stages.length === 1 && context.item.stages[0] === phase;\n}\n\n/** Whether the rule's card carries the event's merge request as one of its sources, attached to its issue. */\nfunction attachedMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const { item, mergeRequest } = context;\n if (!item || !mergeRequest || isPullRequestCard(item)) return false;\n return pullRequestSources(item).some(source => isEventMergeRequest(context, source));\n}\n\n/**\n * Whether a source row is the event's merge request. Iids repeat across GitLab projects, so\n * the row's full key (host, project and iid) has to match, not the iid alone.\n */\nfunction isEventMergeRequest(context: FactoryGitLabRuleContext, source: WorkItemSourceRow): boolean {\n return (\n context.mergeRequest !== undefined &&\n source.integrationId === 'gitlab' &&\n sourceExternalId(source) === context.mergeRequest.sourceKey\n );\n}\n\n/** Whether the merge request the card's PR review covers is the event's merge request. */\nfunction reviewsThisMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const reviewed = context.item ? reviewedPullRequest(context.item) : undefined;\n return reviewed !== undefined && isEventMergeRequest(context, reviewed);\n}\n\nfunction issueOpened(context: FactoryGitLabRuleContext) {\n if (!context.issue || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake.board,\n source: 'gitlab-issue',\n sourceKey: context.issue.sourceKey,\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake.initialPhase,\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabIssueIid: context.issue.number,\n identifier: `${context.repository.fullName}#${context.issue.number}`,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...((context.issue.author ?? actorUsername(context))\n ? { author: context.issue.author ?? actorUsername(context) }\n : {}),\n authorTrusted: context.issue.authorTrusted,\n autoStartCandidate:\n trustedGitLabActor(context) &&\n context.issue.authorTrusted &&\n createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n labelColors: context.issue.labelColors ?? {},\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || context.item.source !== 'gitlab-issue') return;\n // The project's intake routes decide where a closed source sends the card. The board's\n // `sourceClosed` mapping applies only when no route on the board handles closes; without\n // one the close goes to the routes alone (see `routeEventDecision`).\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // GitLab reports no close reason, so every closure counts as completed.\n return closedByRoutes(false, {\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: closure.completed.phase,\n message: {\n text: `GitLab issue #${context.issue?.number ?? ''} was closed; this ${closure.boardTitle} card was moved to ${closure.completed.title}.`,\n },\n });\n}\n\nfunction materializeMergeRequest(context: FactoryGitLabRuleContext) {\n if (!context.mergeRequest || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:merge-request-intake`,\n board: context.intake.board,\n source: 'gitlab-pr',\n sourceKey: context.mergeRequest.sourceKey,\n title: context.mergeRequest.title,\n url: context.mergeRequest.url,\n stage: context.intake.initialPhase,\n // A merge request for a card already on the board is filed on that card. For one that closes\n // an issue on the board, the project's intake routes decide whether it joins that card.\n ...(context.pullRequestHome\n ? context.pullRequestHome.reason === 'closes'\n ? { closesIssue: { workItemId: context.pullRequestHome.workItemId } }\n : { attachTo: { workItemId: context.pullRequestHome.workItemId } }\n : {}),\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabMergeRequestIid: context.mergeRequest.number,\n ...(context.mergeRequest.createdAt ? { sourceCreatedAt: context.mergeRequest.createdAt } : {}),\n factoryAuthored: context.mergeRequest.factoryAuthored,\n authorTrusted: context.mergeRequest.authorTrusted,\n autoStartCandidate:\n ((trustedGitLabActor(context) && context.mergeRequest.authorTrusted) || context.mergeRequest.factoryAuthored) &&\n createdAfterFactory(context.mergeRequest.createdAt, context.factory.createdAt),\n state: context.mergeRequest.state,\n draft: context.mergeRequest.draft,\n merged: context.mergeRequest.merged,\n assignees: context.mergeRequest.assignees ?? [],\n requestedReviewers: context.mergeRequest.reviewers ?? [],\n labels: context.mergeRequest.labels ?? [],\n labelColors: context.mergeRequest.labelColors ?? {},\n headBranch: context.mergeRequest.headBranch,\n baseBranch: context.mergeRequest.baseBranch,\n ...(context.mergeRequest.author ? { author: context.mergeRequest.author } : {}),\n },\n } as const;\n}\n\nfunction mergeRequestUpdated(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !reviewsPullRequest(context)) return;\n if (!context.mergeRequest || context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n const stage = context.flow?.pullRequestReview;\n if (!stage) return;\n const reviewing = inPullRequestReview(context);\n // An issue card re-reviews only while its PR review covers this merge request.\n if (\n context.item.source !== 'gitlab-pr' &&\n !(\n attachedMergeRequest(context) &&\n reviewing &&\n reviewsThisMergeRequest(context)\n )\n )\n return;\n // A resting card has not started a review pass yet.\n if (context.phase?.kind === 'resting') return;\n // An untrusted push must not start review passes on demand.\n if (!trustedGitLabActor(context) && !context.mergeRequest.factoryAuthored) return;\n return pullRequestMoveByRoutes('pull_request.synchronized', {\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: context.board,\n stage,\n ...(reviewing ? { reenter: true } : {}),\n });\n}\n\nfunction mergeRequestCommented(context: FactoryGitLabRuleContext) {\n const role = context.flow?.buildRole;\n if (!context.item || !context.mergeRequest || !context.note || !authoringCard(context) || !role) return;\n // Someone else's merge request attached to the issue is not the builder's to fix.\n if (attachedMergeRequest(context) && !context.mergeRequest.factoryAuthored) return;\n if (context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n if (context.actor.type === 'gitlab' && context.actor.factoryAuthored) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-merge-request-comment`,\n role,\n priority: 'high',\n message:\n `${context.note.author ?? 'Someone'} commented on GitLab merge request !${context.mergeRequest.number} ` +\n `(${context.note.url ?? context.mergeRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the merge-request branch. Reply in GitLab to anything you are deliberately not changing.',\n } as const;\n}\n\nfunction mergeRequestMerged(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest?.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.merged');\n const done = context.boardClosure?.completed ?? context.flow?.completed;\n if (isPullRequestCard(context.item) && reviewsPullRequest(context)) {\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:merge-request-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this merge request card was moved to ${done.title}.`,\n },\n });\n }\n if (!authoringCard(context)) return;\n const role = context.flow?.buildRole;\n // A merge request on the card itself finishes the work, unless another one it carries is still out.\n if (attachedMergeRequest(context)) {\n const recorded = context.item.metadata?.openPullRequestNumber;\n const open =\n typeof recorded === 'number' && recorded !== context.mergeRequest.number\n ? recorded\n : newestOpenPullRequestNumber(context.item, context.mergeRequest.number);\n if (typeof open === 'number' && open !== context.mergeRequest.number) {\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Merge request !${open} is still open, ` +\n 'so this card stays where it is until it merges.',\n } as const;\n }\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this card was moved to ${done.title}.`,\n },\n });\n }\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:assess-work-completion`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Assess whether the linked work item is complete. ` +\n 'Do not move it to a finished phase solely because this merge request merged.',\n } as const;\n}\n\nfunction mergeRequestClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest || context.mergeRequest.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.closed');\n if (!reviewsPullRequest(context)) return;\n if (!isPullRequestCard(context.item)) {\n // An issue card waiting in pull request review on its last open merge request goes back to\n // where its board's cards rest.\n const initialPhase = context.flow?.initialPhase;\n if (!initialPhase || !attachedMergeRequest(context) || !inPullRequestReview(context)) return;\n if (newestOpenPullRequestNumber(context.item, context.mergeRequest.number) !== null) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: initialPhase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} was closed without merging; this card was moved back to ${initialPhase}.`,\n },\n });\n }\n const canceled = context.boardClosure?.canceled ?? context.flow?.canceled;\n if (!canceled) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: canceled.phase,\n message: {\n text:\n `GitLab merge request !${context.mergeRequest.number} was closed without merging; ` +\n `this merge request card was moved to ${canceled.title}.`,\n },\n });\n}\n\nexport const defaultGitLabRules = Object.freeze({\n issueOpened,\n // Triage runs once, when a person moves the card into Triage or starts the run; later edits and\n // comments on the issue don't run it again.\n issueUpdated: null,\n issueClosed,\n // A reopen files a card when the issue has none, as an open does. A card the issue already has\n // is left to the project's intake routes.\n issueReopened: context => (context.item ? undefined : issueOpened(context)),\n issueCommented: null,\n mergeRequestOpened: materializeMergeRequest,\n mergeRequestUpdated,\n mergeRequestCommented,\n mergeRequestMerged,\n mergeRequestClosed,\n} satisfies GitLabEventRules);\n\nexport function resolveGitLabRules(overrides?: GitLabRuleOverrides): GitLabEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitLab rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGitLabRuleContext> | null> = { ...defaultGitLabRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGitLabRules, key)) {\n throw new Error(`Unknown GitLab rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGitLabEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitLab rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as GitLabEventRules, overrides);\n}\n"],"mappings":";;;;AAyBA,SAAS,cAAc,SAAsE;CAC3F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,WAAW,KAAA;AACpE;AAEA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,oBAAoB,WAA+B,kBAAmC;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,kBAAkB,KAAK,MAAM,SAAS;CAC5C,MAAM,mBAAmB,KAAK,MAAM,gBAAgB;CACpD,OAAO,OAAO,SAAS,eAAe,KAAK,OAAO,SAAS,gBAAgB,KAAK,kBAAkB;AACpG;;;;;AAMA,SAAS,cAAc,SAA4C;CACjE,OACE,QAAQ,MAAM,sBAAsB,KAAA,KAAa,QAAQ,SAAS,KAAA,KAAa,CAAC,kBAAkB,QAAQ,IAAI;AAElH;;AAGA,SAAS,oBAAoB,SAA4C;CACvE,MAAM,QAAQ,QAAQ,MAAM;CAC5B,OAAO,UAAU,KAAA,KAAa,QAA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AAC;CACH;CACA,MAAM,WAAW,QAAQ,cAAc,YAAY,QAAQ,MAAM;CACjE,IAAI,CAAC,UAAU;CACf,OAAO,wBAAwB,uBAAuB;EACpD,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,OAAO,QAAQ;EACf,OAAO,SAAS;EAChB,SAAS,EACP,MACE,yBAAyB,QAAQ,aAAa,OAAO,oEACb,SAAS,MAAM,GAC3D;CACF,CAAC;AACH;AAEA,MAAa,qBAAqB,OAAO,OAAO;CAC9C;CAGA,cAAc;CACd;CAGA,gBAAe,YAAY,QAAQ,OAAO,KAAA,IAAY,YAAY,OAAO;CACzE,gBAAgB;CAChB,oBAAoB;CACpB;CACA;CACA;CACA;AACF,CAA4B;AAE5B,SAAgB,mBAAmB,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAuB,SAAS;AACxF"}
1
+ {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/gitlab/default-rules.ts"],"sourcesContent":["import {\n isPullRequestCard,\n newestOpenPullRequestNumber,\n pullRequestSources,\n reviewedPullRequest,\n reviewsPullRequest,\n sourceExternalId,\n} from '../../boards/index.js';\nimport {\n closedByRoutes,\n pullRequestMoveByRoutes,\n recordExplicitRuleOverrides,\n routedOnly,\n unreviewedPullRequestCard,\n} from '../../rules/event-rules.js';\nimport type { FactoryGitLabEventName, FactoryGitLabRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport type { WorkItemSourceRow } from '../../storage/domains/work-items/work-item-schema.js';\n\nexport type GitLabRuleOverrides = Partial<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null | undefined>\n>;\nexport type GitLabEventRules = Readonly<\n Record<FactoryGitLabEventName, FactoryRuleHandler<FactoryGitLabRuleContext> | null>\n>;\n\nfunction actorUsername(context: Pick<FactoryGitLabRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'gitlab' ? context.actor.username : undefined;\n}\n\nfunction trustedGitLabActor(context: Pick<FactoryGitLabRuleContext, 'actor'>): boolean {\n return context.actor.type === 'gitlab' && context.actor.trusted;\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * The card whose session authored the merge request, as opposed to the merge request's own card,\n * on a board that reviews merge requests.\n */\nfunction authoringCard(context: FactoryGitLabRuleContext): boolean {\n return (\n context.flow?.pullRequestReview !== undefined && context.item !== undefined && !isPullRequestCard(context.item)\n );\n}\n\n/** Whether the card sits in its board's pull request review phase, alone. */\nfunction inPullRequestReview(context: FactoryGitLabRuleContext): boolean {\n const phase = context.flow?.pullRequestReview;\n return phase !== undefined && context.item?.stages.length === 1 && context.item.stages[0] === phase;\n}\n\n/** Whether the rule's card carries the event's merge request as one of its sources, attached to its issue. */\nfunction attachedMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const { item, mergeRequest } = context;\n if (!item || !mergeRequest || isPullRequestCard(item)) return false;\n return pullRequestSources(item).some(source => isEventMergeRequest(context, source));\n}\n\n/**\n * Whether a source row is the event's merge request. Iids repeat across GitLab projects, so\n * the row's full key (host, project and iid) has to match, not the iid alone.\n */\nfunction isEventMergeRequest(context: FactoryGitLabRuleContext, source: WorkItemSourceRow): boolean {\n return (\n context.mergeRequest !== undefined &&\n source.integrationId === 'gitlab' &&\n sourceExternalId(source) === context.mergeRequest.sourceKey\n );\n}\n\n/** Whether the merge request the card's PR review covers is the event's merge request. */\nfunction reviewsThisMergeRequest(context: FactoryGitLabRuleContext): boolean {\n const reviewed = context.item ? reviewedPullRequest(context.item) : undefined;\n return reviewed !== undefined && isEventMergeRequest(context, reviewed);\n}\n\nfunction issueOpened(context: FactoryGitLabRuleContext) {\n if (!context.issue || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake.board,\n source: 'gitlab-issue',\n sourceKey: context.issue.sourceKey,\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake.initialPhase,\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabIssueIid: context.issue.number,\n identifier: `${context.repository.fullName}#${context.issue.number}`,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...((context.issue.author ?? actorUsername(context))\n ? { author: context.issue.author ?? actorUsername(context) }\n : {}),\n authorTrusted: context.issue.authorTrusted,\n autoStartCandidate:\n trustedGitLabActor(context) &&\n context.issue.authorTrusted &&\n createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n labelColors: context.issue.labelColors ?? {},\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || context.item.source !== 'gitlab-issue') return;\n // The project's intake routes decide where a closed source sends the card. The board's\n // `sourceClosed` mapping applies only when no route on the board handles closes; without\n // one the close goes to the routes alone (see `routeEventDecision`).\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // GitLab reports no close reason, so every closure counts as completed.\n return closedByRoutes(false, {\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: closure.completed.phase,\n message: {\n text: `GitLab issue #${context.issue?.number ?? ''} was closed; this ${closure.boardTitle} card was moved to ${closure.completed.title}.`,\n },\n });\n}\n\nfunction materializeMergeRequest(context: FactoryGitLabRuleContext) {\n if (!context.mergeRequest || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:merge-request-intake`,\n board: context.intake.board,\n source: 'gitlab-pr',\n sourceKey: context.mergeRequest.sourceKey,\n title: context.mergeRequest.title,\n url: context.mergeRequest.url,\n stage: context.intake.initialPhase,\n // A merge request for a card already on the board is filed on that card. For one that closes\n // an issue on the board, the project's intake routes decide whether it joins that card.\n ...(context.pullRequestHome\n ? context.pullRequestHome.reason === 'closes'\n ? { closesIssue: { workItemId: context.pullRequestHome.workItemId } }\n : { attachTo: { workItemId: context.pullRequestHome.workItemId } }\n : {}),\n metadata: {\n gitlabHost: context.repository.host,\n gitlabProjectId: context.repository.id,\n gitlabMergeRequestIid: context.mergeRequest.number,\n ...(context.mergeRequest.createdAt ? { sourceCreatedAt: context.mergeRequest.createdAt } : {}),\n factoryAuthored: context.mergeRequest.factoryAuthored,\n authorTrusted: context.mergeRequest.authorTrusted,\n autoStartCandidate:\n ((trustedGitLabActor(context) && context.mergeRequest.authorTrusted) || context.mergeRequest.factoryAuthored) &&\n createdAfterFactory(context.mergeRequest.createdAt, context.factory.createdAt),\n state: context.mergeRequest.state,\n draft: context.mergeRequest.draft,\n merged: context.mergeRequest.merged,\n assignees: context.mergeRequest.assignees ?? [],\n requestedReviewers: context.mergeRequest.reviewers ?? [],\n labels: context.mergeRequest.labels ?? [],\n labelColors: context.mergeRequest.labelColors ?? {},\n headBranch: context.mergeRequest.headBranch,\n baseBranch: context.mergeRequest.baseBranch,\n ...(context.mergeRequest.author ? { author: context.mergeRequest.author } : {}),\n },\n } as const;\n}\n\nfunction mergeRequestUpdated(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !reviewsPullRequest(context)) return;\n if (!context.mergeRequest || context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n const stage = context.flow?.pullRequestReview;\n if (!stage) return;\n const reviewing = inPullRequestReview(context);\n // An issue card re-reviews only while its PR review covers this merge request.\n if (\n context.item.source !== 'gitlab-pr' &&\n !(\n attachedMergeRequest(context) &&\n reviewing &&\n reviewsThisMergeRequest(context)\n )\n )\n return;\n // A resting card has not started a review pass yet.\n if (context.phase?.kind === 'resting') return;\n // An untrusted push must not start review passes on demand.\n if (!trustedGitLabActor(context) && !context.mergeRequest.factoryAuthored) return;\n return pullRequestMoveByRoutes('pull_request.synchronized', {\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: context.board,\n stage,\n ...(reviewing ? { reenter: true } : {}),\n });\n}\n\nfunction mergeRequestCommented(context: FactoryGitLabRuleContext) {\n const role = context.flow?.buildRole;\n if (!context.item || !context.mergeRequest || !context.note || !authoringCard(context) || !role) return;\n // Someone else's merge request attached to the issue is not the builder's to fix.\n if (attachedMergeRequest(context) && !context.mergeRequest.factoryAuthored) return;\n if (context.mergeRequest.state !== 'open' || context.mergeRequest.merged) return;\n if (context.actor.type === 'gitlab' && context.actor.factoryAuthored) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-merge-request-comment`,\n role,\n priority: 'high',\n message:\n `${context.note.author ?? 'Someone'} commented on GitLab merge request !${context.mergeRequest.number} ` +\n `(${context.note.url ?? context.mergeRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the merge-request branch. Reply in GitLab to anything you are deliberately not changing.',\n } as const;\n}\n\nfunction mergeRequestMerged(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest?.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.merged');\n const done = context.boardClosure?.completed ?? context.flow?.completed;\n if (isPullRequestCard(context.item) && reviewsPullRequest(context)) {\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:merge-request-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this merge request card was moved to ${done.title}.`,\n },\n });\n }\n if (!authoringCard(context)) return;\n const role = context.flow?.buildRole;\n // A merge request on the card itself finishes the work, unless another one it carries is still out.\n if (attachedMergeRequest(context)) {\n const recorded = context.item.metadata?.openPullRequestNumber;\n const open =\n typeof recorded === 'number' && recorded !== context.mergeRequest.number\n ? recorded\n : newestOpenPullRequestNumber(context.item, context.mergeRequest.number);\n if (typeof open === 'number' && open !== context.mergeRequest.number) {\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Merge request !${open} is still open, ` +\n 'so this card stays where it is until it merges.',\n } as const;\n }\n if (!done) return;\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} merged; this card was moved to ${done.title}.`,\n },\n });\n }\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:assess-work-completion`,\n role,\n message:\n `GitLab merge request !${context.mergeRequest.number} merged. Assess whether the linked work item is complete. ` +\n 'Do not move it to a finished phase solely because this merge request merged.',\n } as const;\n}\n\nfunction mergeRequestClosed(context: FactoryGitLabRuleContext) {\n if (!context.item || !context.board || !context.mergeRequest || context.mergeRequest.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.closed');\n if (!reviewsPullRequest(context)) return;\n if (!isPullRequestCard(context.item)) {\n // An issue card waiting in pull request review on its last open merge request goes back to\n // where its board's cards rest.\n const initialPhase = context.flow?.initialPhase;\n if (!initialPhase || !attachedMergeRequest(context) || !inPullRequestReview(context)) return;\n if (newestOpenPullRequestNumber(context.item, context.mergeRequest.number) !== null) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: initialPhase,\n message: {\n text: `GitLab merge request !${context.mergeRequest.number} was closed without merging; this card was moved back to ${initialPhase}.`,\n },\n });\n }\n const canceled = context.boardClosure?.canceled ?? context.flow?.canceled;\n if (!canceled) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:merge-request-closed`,\n board: context.board,\n stage: canceled.phase,\n message: {\n text:\n `GitLab merge request !${context.mergeRequest.number} was closed without merging; ` +\n `this merge request card was moved to ${canceled.title}.`,\n },\n });\n}\n\nexport const defaultGitLabRules = Object.freeze({\n issueOpened,\n // Triage runs once, when a person moves the card into Triage or starts the run; later edits and\n // comments on the issue don't run it again.\n issueUpdated: null,\n issueClosed,\n // A reopen files a card when the issue has none, as an open does. A card the issue already has\n // is left to the project's intake routes.\n issueReopened: context => (context.item ? undefined : issueOpened(context)),\n issueCommented: null,\n mergeRequestOpened: materializeMergeRequest,\n mergeRequestUpdated,\n mergeRequestCommented,\n mergeRequestMerged,\n mergeRequestClosed,\n} satisfies GitLabEventRules);\n\nexport function resolveGitLabRules(overrides?: GitLabRuleOverrides): GitLabEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitLab rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGitLabRuleContext> | null> = { ...defaultGitLabRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGitLabRules, key)) {\n throw new Error(`Unknown GitLab rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGitLabEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitLab rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as GitLabEventRules, overrides);\n}\n"],"mappings":";;;;;AAyBA,SAAS,cAAc,SAAsE;CAC3F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,WAAW,KAAA;AACpE;AAEA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,oBAAoB,WAA+B,kBAAmC;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,kBAAkB,KAAK,MAAM,SAAS;CAC5C,MAAM,mBAAmB,KAAK,MAAM,gBAAgB;CACpD,OAAO,OAAO,SAAS,eAAe,KAAK,OAAO,SAAS,gBAAgB,KAAK,kBAAkB;AACpG;;;;;AAMA,SAAS,cAAc,SAA4C;CACjE,OACE,QAAQ,MAAM,sBAAsB,KAAA,KAAa,QAAQ,SAAS,KAAA,KAAa,CAAC,kBAAkB,QAAQ,IAAI;AAElH;;AAGA,SAAS,oBAAoB,SAA4C;CACvE,MAAM,QAAQ,QAAQ,MAAM;CAC5B,OAAO,UAAU,KAAA,KAAa,QAAQ,MAAM,OAAO,WAAW,KAAK,QAAQ,KAAK,OAAO,OAAO;AAChG;;AAGA,SAAS,qBAAqB,SAA4C;CACxE,MAAM,EAAE,MAAM,iBAAiB;CAC/B,IAAI,CAAC,QAAQ,CAAC,gBAAgB,kBAAkB,IAAI,GAAG,OAAO;CAC9D,OAAO,mBAAmB,IAAI,CAAC,CAAC,MAAK,WAAU,oBAAoB,SAAS,MAAM,CAAC;AACrF;;;;;AAMA,SAAS,oBAAoB,SAAmC,QAAoC;CAClG,OACE,QAAQ,iBAAiB,KAAA,KACzB,OAAO,kBAAkB,YACzB,iBAAiB,MAAM,MAAM,QAAQ,aAAa;AAEtD;;AAGA,SAAS,wBAAwB,SAA4C;CAC3E,MAAM,WAAW,QAAQ,OAAO,o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,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAuB,SAAS;AACxF"}
@@ -0,0 +1,16 @@
1
+ import type { IntegrationContext } from '../base.js';
2
+ import type { IssueReconciler } from '../issue-reconciler.js';
3
+ import type { GitLabIntegrationBase } from './integration.js';
4
+ /**
5
+ * First observation of the merge requests and issues GitLab sent no event
6
+ * for. It runs inside the leased reconcile sweep, so a card appears whether or
7
+ * not anyone has the board open, and the list routes stay pure reads.
8
+ *
9
+ * A listed delivery every Factory has settled would only replay, after paying
10
+ * for its rule evaluation and GitLab member lookups. The sweep remembers those
11
+ * per project and skips them, so an unchanged GitLab costs listings only. The
12
+ * memory holds what the last sweep listed and nothing older; a restart or a
13
+ * lease moving to another replica costs one pass that replays.
14
+ */
15
+ export declare function attachGitLabDiscovery(gitlab: Pick<GitLabIntegrationBase, 'versionControl' | 'intake' | 'getLinkedRepository' | 'rules' | 'getProjectMemberAccessLevel' | 'getWorkItemAuthorUsername' | 'resolveActiveConnectionForHost'>, context: IntegrationContext): IssueReconciler | undefined;
16
+ //# sourceMappingURL=discovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAyB,MAAM,wBAAwB,CAAC;AACrF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAY9D;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,IAAI,CACV,qBAAqB,EACnB,gBAAgB,GAChB,QAAQ,GACR,qBAAqB,GACrB,OAAO,GACP,6BAA6B,GAC7B,2BAA2B,GAC3B,gCAAgC,CACnC,EACD,OAAO,EAAE,kBAAkB,GAC1B,eAAe,GAAG,SAAS,CAuF7B"}
@@ -0,0 +1,107 @@
1
+ import { ingestListedEvents, listedIssueEvent, listedMergeRequestEvents, positiveId, routedGitLabSourceIds } from "./routes.js";
2
+ import { attachGitLabRules } from "./rules.js";
3
+ // src/integrations/gitlab/discovery.ts
4
+ /**
5
+ * First observation of the merge requests and issues GitLab sent no event
6
+ * for. It runs inside the leased reconcile sweep, so a card appears whether or
7
+ * not anyone has the board open, and the list routes stay pure reads.
8
+ *
9
+ * A listed delivery every Factory has settled would only replay, after paying
10
+ * for its rule evaluation and GitLab member lookups. The sweep remembers those
11
+ * per project and skips them, so an unchanged GitLab costs listings only. The
12
+ * memory holds what the last sweep listed and nothing older; a restart or a
13
+ * lease moving to another replica costs one pass that replays.
14
+ */
15
+ function attachGitLabDiscovery(gitlab, context) {
16
+ const ingest = attachGitLabRules(gitlab, context);
17
+ if (!ingest) return void 0;
18
+ const { projects, sourceControl, intake } = context.storage;
19
+ let settled = /* @__PURE__ */ new Set();
20
+ return async () => {
21
+ const listed = /* @__PURE__ */ new Set();
22
+ const summary = {
23
+ projects: 0,
24
+ checked: 0,
25
+ updated: 0,
26
+ closed: 0,
27
+ missing: 0,
28
+ failed: 0,
29
+ errors: []
30
+ };
31
+ for (const project of await projects.listAll()) {
32
+ summary.projects += 1;
33
+ const scope = {
34
+ orgId: project.orgId,
35
+ factoryProjectId: project.id
36
+ };
37
+ const failed = (error) => {
38
+ summary.failed += 1;
39
+ summary.errors.push({
40
+ projectId: project.id,
41
+ error: error instanceof Error ? error.message : String(error)
42
+ });
43
+ };
44
+ const key = (event) => `${project.id}\u0000${event.deliveryId}`;
45
+ const unsettled = (events) => events.filter((event) => {
46
+ if (!event || !settled.has(key(event))) return event !== null;
47
+ listed.add(key(event));
48
+ return false;
49
+ });
50
+ const remembered = async (event) => {
51
+ const result = await ingest(event);
52
+ if (result.settled) listed.add(key(event));
53
+ return result;
54
+ };
55
+ const each = async (list, discover) => {
56
+ for (const entry of await list().catch((error) => (failed(error), []))) await discover(entry).catch(failed);
57
+ };
58
+ await each(() => sourceControl.projectRepositories.listByProject(scope), async (link) => {
59
+ const linked = await gitlab.getLinkedRepository({
60
+ ...scope,
61
+ projectRepositoryId: link.id
62
+ });
63
+ const projectId = linked && positiveId(linked.repository.externalId);
64
+ if (!linked || !projectId) return;
65
+ const target = await gitlab.versionControl.getRepositoryTarget({
66
+ orgId: project.orgId,
67
+ repositoryId: linked.repository.id
68
+ });
69
+ for (let page = 1; page <= 5; page += 1) {
70
+ const result = await gitlab.versionControl.listPullRequests({
71
+ ...target,
72
+ includeDrafts: false,
73
+ cursor: String(page)
74
+ });
75
+ const events = result.pullRequests.flatMap((pr) => listedMergeRequestEvents({
76
+ host: linked.host,
77
+ projectId,
78
+ projectPath: linked.repository.slug
79
+ }, pr));
80
+ (await ingestListedEvents(unsettled(events), remembered)).forEach(failed);
81
+ if (result.nextCursor === null) break;
82
+ }
83
+ });
84
+ await each(async () => await routedGitLabSourceIds(intake, scope) ?? [], async (sourceId) => {
85
+ let cursor;
86
+ for (let page = 1; page <= 5; page += 1) {
87
+ const result = await gitlab.intake.listIssues({
88
+ connection: {
89
+ type: "oauth",
90
+ accessToken: "gitlab-sweep"
91
+ },
92
+ sourceIds: [sourceId],
93
+ cursor
94
+ });
95
+ (await ingestListedEvents(unsettled(result.issues.map(listedIssueEvent)), remembered)).forEach(failed);
96
+ if (result.nextCursor === null) break;
97
+ cursor = result.nextCursor;
98
+ }
99
+ });
100
+ }
101
+ settled = listed;
102
+ return summary;
103
+ };
104
+ }
105
+ export { attachGitLabDiscovery };
106
+
107
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","names":[],"sources":["../../../src/integrations/gitlab/discovery.ts"],"sourcesContent":["import type { IntegrationContext } from '../base.js';\nimport type { IssueReconciler, IssueReconcileSummary } from '../issue-reconciler.js';\nimport type { GitLabIntegrationBase } from './integration.js';\nimport {\n ingestListedEvents,\n LINKED_BACKLOG_MAX_PAGES,\n listedIssueEvent,\n listedMergeRequestEvents,\n positiveId,\n routedGitLabSourceIds,\n} from './routes.js';\nimport { attachGitLabRules } from './rules.js';\nimport type { ParsedGitLabWebhook } from './webhook.js';\n\n/**\n * First observation of the merge requests and issues GitLab sent no event\n * for. It runs inside the leased reconcile sweep, so a card appears whether or\n * not anyone has the board open, and the list routes stay pure reads.\n *\n * A listed delivery every Factory has settled would only replay, after paying\n * for its rule evaluation and GitLab member lookups. The sweep remembers those\n * per project and skips them, so an unchanged GitLab costs listings only. The\n * memory holds what the last sweep listed and nothing older; a restart or a\n * lease moving to another replica costs one pass that replays.\n */\nexport function attachGitLabDiscovery(\n gitlab: Pick<\n GitLabIntegrationBase,\n | 'versionControl'\n | 'intake'\n | 'getLinkedRepository'\n | 'rules'\n | 'getProjectMemberAccessLevel'\n | 'getWorkItemAuthorUsername'\n | 'resolveActiveConnectionForHost'\n >,\n context: IntegrationContext,\n): IssueReconciler | undefined {\n const ingest = attachGitLabRules(gitlab, context);\n if (!ingest) return undefined;\n const { projects, sourceControl, intake } = context.storage;\n let settled = new Set<string>();\n\n return async () => {\n const listed = new Set<string>();\n const summary: IssueReconcileSummary = {\n projects: 0,\n checked: 0,\n updated: 0,\n closed: 0,\n missing: 0,\n failed: 0,\n errors: [],\n };\n for (const project of await projects.listAll()) {\n summary.projects += 1;\n const scope = { orgId: project.orgId, factoryProjectId: project.id };\n const failed = (error: unknown) => {\n summary.failed += 1;\n summary.errors.push({ projectId: project.id, error: error instanceof Error ? error.message : String(error) });\n };\n const key = (event: ParsedGitLabWebhook) => `${project.id}\\u0000${event.deliveryId}`;\n const unsettled = (events: Array<ParsedGitLabWebhook | null>) =>\n events.filter((event): event is ParsedGitLabWebhook => {\n if (!event || !settled.has(key(event))) return event !== null;\n listed.add(key(event));\n return false;\n });\n const remembered = async (event: ParsedGitLabWebhook) => {\n const result = await ingest(event);\n if (result.settled) listed.add(key(event));\n return result;\n };\n // One unreachable repository or source must not hide the others.\n const each = async <T>(list: () => Promise<T[]>, discover: (entry: T) => Promise<void>) => {\n for (const entry of await list().catch(error => (failed(error), []))) await discover(entry).catch(failed);\n };\n\n await each(\n () => sourceControl.projectRepositories.listByProject(scope),\n async link => {\n const linked = await gitlab.getLinkedRepository({ ...scope, projectRepositoryId: link.id });\n const projectId = linked && positiveId(linked.repository.externalId);\n if (!linked || !projectId) return;\n const target = await gitlab.versionControl.getRepositoryTarget({\n orgId: project.orgId,\n repositoryId: linked.repository.id,\n });\n for (let page = 1; page <= LINKED_BACKLOG_MAX_PAGES; page += 1) {\n const result = await gitlab.versionControl.listPullRequests({\n ...target,\n includeDrafts: false,\n cursor: String(page),\n });\n const events = result.pullRequests.flatMap(pr =>\n listedMergeRequestEvents({ host: linked.host, projectId, projectPath: linked.repository.slug }, pr),\n );\n (await ingestListedEvents(unsettled(events), remembered)).forEach(failed);\n if (result.nextCursor === null) break;\n }\n },\n );\n\n await each(\n async () => (await routedGitLabSourceIds(intake, scope)) ?? [],\n async sourceId => {\n let cursor: string | undefined;\n for (let page = 1; page <= LINKED_BACKLOG_MAX_PAGES; page += 1) {\n const result = await gitlab.intake.listIssues({\n // GitLab resolves the credential from the source id; no caller identity is read.\n connection: { type: 'oauth', accessToken: 'gitlab-sweep' },\n sourceIds: [sourceId],\n cursor,\n });\n (await ingestListedEvents(unsettled(result.issues.map(listedIssueEvent)), remembered)).forEach(failed);\n if (result.nextCursor === null) break;\n cursor = result.nextCursor;\n }\n },\n );\n }\n settled = listed;\n return summary;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAyBA,SAAgB,sBACd,QAUA,SAC6B;CAC7B,MAAM,SAAS,kBAAkB,QAAQ,OAAO;CAChD,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,MAAM,EAAE,UAAU,eAAe,WAAW,QAAQ;CACpD,IAAI,0BAAU,IAAI,IAAY;CAE9B,OAAO,YAAY;EACjB,MAAM,yBAAS,IAAI,IAAY;EAC/B,MAAM,UAAiC;GACrC,UAAU;GACV,SAAS;GACT,SAAS;GACT,QAAQ;GACR,SAAS;GACT,QAAQ;GACR,QAAQ,CAAC;EACX;EACA,KAAK,MAAM,WAAW,MAAM,SAAS,QAAQ,GAAG;GAC9C,QAAQ,YAAY;GACpB,MAAM,QAAQ;IAAE,OAAO,QAAQ;IAAO,kBAAkB,QAAQ;GAAG;GACnE,MAAM,UAAU,UAAmB;IACjC,QAAQ,UAAU;IAClB,QAAQ,OAAO,KAAK;KAAE,WAAW,QAAQ;KAAI,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAAE,CAAC;GAC9G;GACA,MAAM,OAAO,UAA+B,GAAG,QAAQ,GAAG,QAAQ,MAAM;GACxE,MAAM,aAAa,WACjB,OAAO,QAAQ,UAAwC;IACrD,IAAI,CAAC,SAAS,CAAC,QAAQ,IAAI,IAAI,KAAK,CAAC,GAAG,OAAO,UAAU;IACzD,OAAO,IAAI,IAAI,KAAK,CAAC;IACrB,OAAO;GACT,CAAC;GACH,MAAM,aAAa,OAAO,UAA+B;IACvD,MAAM,SAAS,MAAM,OAAO,KAAK;IACjC,IAAI,OAAO,SAAS,OAAO,IAAI,IAAI,KAAK,CAAC;IACzC,OAAO;GACT;GAEA,MAAM,O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abApiClient, GitLabApiError } from "./api.js";
4
4
  import { resolveGitLabRules } from "./default-rules.js";
5
5
  import { attachGitLabReconciler } from "./reconciler.js";
6
- import { gitlabReconciliationEnabled, gitlabReconciliationInterval } from "./reconciliation-config.js";
6
+ import { gitlabReconciliationInterval } from "./reconciliation-config.js";
7
7
  import { buildGitLabRoutes, ingestLinkedGitLabRepositoryBacklog } from "./routes.js";
8
8
  import { attachGitLabRules } from "./rules.js";
9
9
  import { createGitLabSubscriptionTools, parseCreatedMergeRequest, subscribeCurrentSessionToMergeRequest } from "./session-subscriptions.js";
@@ -184,7 +184,6 @@ var GitLabIntegrationBase = class {
184
184
  async verifyStatus() {}
185
185
  get webhookSecret() {}
186
186
  workers(ctx) {
187
- if (!gitlabReconciliationEnabled()) return [];
188
187
  const reconcile = attachGitLabReconciler(this, ctx);
189
188
  if (!reconcile) return [];
190
189
  const intervalMs = gitlabReconciliationInterval();
@@ -1 +1 @@
1
- {"version":3,"file":"integration.js","names":[],"sources":["../../../src/integrations/gitlab/integration.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\n\nimport type { IntegrationConnection } from '../../capabilities/connection.js';\nimport type {\n CreateIntakeCommentInput,\n CreatedIntakeComment,\n GetIntakeIssueInput,\n Intake,\n IntakeIssue,\n IntakeIssueDetail,\n IntakeItemPage,\n IntakeSource,\n ListIntakeIssuesInput,\n ListIntakeItemsInput,\n ResolveIntakeDispatchInput,\n ResolvedIntakeDispatch,\n UpdateIntakeIssueInput,\n} from '../../capabilities/intake.js';\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';\nimport { IssueReconcileWorker } from '../issue-reconcile-worker.js';\nimport { buildGitLabAgentTools } from './agent-tools.js';\nimport {\n GITLAB_ISSUES_PAGE_SIZE,\n GITLAB_NOTES_PAGE_SIZE,\n GITLAB_PROJECTS_PAGE_SIZE,\n GitLabApiClient,\n GitLabApiError,\n} from './api.js';\nimport type { GitLabIssue, GitLabNote, GitLabProject } from './api.js';\nimport { resolveGitLabRules } from './default-rules.js';\nimport type { GitLabEventRules, GitLabRuleOverrides } from './default-rules.js';\nimport { attachGitLabReconciler } from './reconciler.js';\nimport { gitlabReconciliationEnabled, gitlabReconciliationInterval } from './reconciliation-config.js';\nimport { buildGitLabRoutes, ingestLinkedGitLabRepositoryBacklog } from './routes.js';\nimport { attachGitLabRules } from './rules.js';\nimport {\n createGitLabSubscriptionTools,\n parseCreatedMergeRequest,\n subscribeCurrentSessionToMergeRequest,\n} from './session-subscriptions.js';\nimport type { GitLabSubscriptionStorage } from './subscriptions.js';\nimport { buildGitLabVersionControl } from './version-control.js';\n\ninterface GitLabConnectionContext {\n id: string;\n label: string | null;\n api: GitLabApiClient;\n connection: IntegrationConnection;\n host: string;\n webBaseUrl?: string;\n /** Resolves a fresh provider token for a single brokered git operation. */\n repositoryAccessToken?: () => Promise<string>;\n}\n\ninterface GitLabSourceReference {\n /** Present only on legacy v1 ids; authentication is not resource identity. */\n connectionId?: string;\n /** Canonical v2 ids use the GitLab instance host plus immutable project id. */\n host?: string;\n projectId: string;\n /** Legacy ids carry display metadata; v2 resolves it from GitLab. */\n projectPath?: string;\n}\n\ninterface ResolvedGitLabSourceReference extends GitLabSourceReference {\n connectionId: string;\n host: string;\n projectPath: string;\n}\n\ninterface GitLabIssueReference extends GitLabSourceReference {\n issueIid: number;\n}\n\nexport interface GitLabMergeRequestReference {\n version: 1;\n host: string;\n projectId: number;\n mergeRequestIid: number;\n}\n\ninterface GitLabPageCursor {\n source: number;\n page: number;\n}\n\nexport interface GitLabStatusConnection {\n id: string;\n integrationId: string;\n status: 'active' | 'needs_reauth';\n accountLabel: string | null;\n}\n\nconst DIRECT_CONNECTION_ID = 'direct';\nconst GITLAB_CONNECTION_TOKEN_PREFIX = 'gitlab-connection:';\nconst GITLAB_SOURCE_PREFIX = 'gitlab-project:';\nconst GITLAB_ISSUE_PREFIX = 'gitlab-issue:';\nconst GITLAB_MERGE_REQUEST_PREFIX = 'gitlab-pr:';\nexport const GITLAB_TRUSTED_ACCESS_LEVEL = 30;\n// Bound issue detail reads to 2,000 notes. GitLab does not expose truncation through the Intake contract.\nconst MAX_NOTES_PAGES = 20;\nconst UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nexport abstract class GitLabIntegrationBase implements FactoryIntegration {\n readonly id = 'gitlab';\n #projects: FactoryProjectsStorage | undefined;\n #sourceControl: SourceControlStorageHandle | undefined;\n #integrationStorage: GitLabSubscriptionStorage | undefined;\n #auth: RouteAuth | undefined;\n #ingestFactoryEvent: ReturnType<typeof attachGitLabRules>;\n readonly #orgIdByResourceId = new Map<string, string | null>();\n readonly rules: GitLabEventRules;\n\n constructor(rules?: GitLabRuleOverrides) {\n this.rules = resolveGitLabRules(rules);\n }\n\n readonly intake: Intake = {\n resolveIntakeDispatch: input => this.#resolveIntakeDispatch(input),\n listSources: () => this.#listSources(),\n listItems: input => this.#listItems(input),\n listIssues: input => this.#listIssues(input),\n getIssue: input => this.#getIssue(input),\n createComment: input => this.#createComment(input),\n updateIssue: input => this.#updateIssue(input),\n };\n readonly versionControl = buildGitLabVersionControl({\n contextForConnection: connection => this.#versionControlContext(connection),\n contextForStoredInstallation: (connection, host) => this.#versionControlContextForInstallation(connection, host),\n });\n initialize({\n storage,\n projects,\n auth,\n sourceControl,\n }: {\n storage?: IntegrationStorageHandle;\n projects: FactoryProjectsStorage;\n auth: RouteAuth;\n sourceControl?: SourceControlStorageHandle;\n }): void {\n this.#projects = projects;\n this.#auth = auth;\n this.#sourceControl = sourceControl;\n this.#integrationStorage = storage as GitLabSubscriptionStorage | undefined;\n }\n\n /** Generic integration persistence (merge-request subscriptions). */\n get integrationStorage(): GitLabSubscriptionStorage {\n if (!this.#integrationStorage) {\n throw new Error(`${this.constructor.name} is not initialized — the factory binds storage during prepare().`);\n }\n return this.#integrationStorage;\n }\n\n /** Source-control rows for this integration; absent when the host runs without them. */\n get sourceControlStorage(): SourceControlStorageHandle | undefined {\n return this.#sourceControl;\n }\n\n get authEnabled(): boolean {\n return this.#auth?.enabled() ?? false;\n }\n\n get projects(): FactoryProjectsStorage {\n if (!this.#projects) {\n throw new Error(`${this.constructor.name} is not initialized — the factory binds storage during prepare().`);\n }\n return this.#projects;\n }\n\n async resolveOrgId(resourceId: string): Promise<string | null> {\n const cached = this.#orgIdByResourceId.get(resourceId);\n if (cached !== undefined) return cached;\n if (!UUID_PATTERN.test(resourceId)) {\n this.#orgIdByResourceId.set(resourceId, null);\n return null;\n }\n try {\n await this.projects.ensureReady();\n const project = await this.projects.getById({ id: resourceId });\n const orgId = project?.orgId ?? null;\n this.#orgIdByResourceId.set(resourceId, orgId);\n return orgId;\n } catch {\n return null;\n }\n }\n\n clearCaches(): void {\n this.#orgIdByResourceId.clear();\n }\n\n abstract hasActiveConnections(): Promise<boolean>;\n abstract authFailureMessage(): string;\n protected abstract activeContexts(): Promise<GitLabConnectionContext[]>;\n protected abstract contextById(connectionId: string): Promise<GitLabConnectionContext>;\n\n /** Resolve only a GitLab repository linked to this Factory in this organization. */\n async getLinkedRepository(input: { orgId: string; factoryProjectId: string; projectRepositoryId: string }) {\n if (!this.#sourceControl) return null;\n const connections = await this.#sourceControl.connections.list({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n for (const connection of connections) {\n if (connection.integrationId !== 'gitlab') continue;\n const links = await this.#sourceControl.projectRepositories.list({\n orgId: input.orgId,\n connectionId: connection.id,\n });\n const link = links.find(candidate => candidate.id === input.projectRepositoryId);\n if (!link) continue;\n const repository = await this.#sourceControl.repositories.get({ orgId: input.orgId, id: link.repositoryId });\n const installation = await this.#sourceControl.installations.get({\n orgId: input.orgId,\n id: connection.installationId,\n });\n if (!repository || !installation) return null;\n const host = installation.providerMetadata.host;\n if (typeof host !== 'string' || !host) return null;\n return { repository, host: normalizeGitLabHost(host) };\n }\n return null;\n }\n\n async getProjectMemberAccessLevel(\n connectionId: string,\n projectId: string,\n username: string,\n ): Promise<number | undefined> {\n const normalized = username.trim().toLowerCase();\n if (!normalized) return undefined;\n const members = await (await this.contextById(connectionId)).api.listProjectMembers(projectId, { query: username });\n const member = members.find(\n candidate => candidate.username.toLowerCase() === normalized && candidate.state !== 'blocked',\n );\n return member?.access_level;\n }\n\n async getWorkItemAuthorUsername(\n connectionId: string,\n projectId: string,\n kind: 'issue' | 'merge_request',\n iid: number,\n ): Promise<string | undefined> {\n const api = (await this.contextById(connectionId)).api;\n const item = kind === 'issue' ? await api.getIssue(projectId, iid) : await api.getMergeRequest(projectId, iid);\n return item.author?.username;\n }\n\n async isProjectMemberTrustedForSource(sourceId: string, username: string): Promise<boolean> {\n const reference = decodeSourceId(sourceId);\n if (!reference) throw new GitLabApiError('GitLab source identity is invalid.', 400);\n const { context, source } = await this.#resolveSourceReference(reference);\n const accessLevel = await this.getProjectMemberAccessLevel(context.id, source.projectId, username);\n return (accessLevel ?? 0) >= GITLAB_TRUSTED_ACCESS_LEVEL;\n }\n\n async getIssueForFactoryProject(input: {\n orgId: string;\n factoryProjectId: string;\n issueId: string;\n }): Promise<IntakeIssueDetail | null> {\n if (!this.#sourceControl) throw new GitLabApiError('GitLab source control is unavailable.', 503);\n const reference = decodeIssueReference(input.issueId);\n const locator = parseIssueLocator(input.issueId);\n if (!reference && !locator) {\n throw new GitLabApiError('GitLab issue must include a project and issue IID.', 400);\n }\n\n const normalizePath = (value: string) => value.replace(/^\\/+|\\/+$/g, '').toLowerCase();\n const matches: Array<{\n connectionId: string;\n projectId: string;\n projectPath: string;\n }> = [];\n const connections = await this.#sourceControl.connections.list({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n for (const connection of connections) {\n const installation = await this.#sourceControl.installations.get({\n orgId: input.orgId,\n id: connection.installationId,\n });\n if (!installation) continue;\n for (const projectRepository of await this.#sourceControl.projectRepositories.list({\n orgId: input.orgId,\n connectionId: connection.id,\n })) {\n const repository = await this.#sourceControl.repositories.get({\n orgId: input.orgId,\n id: projectRepository.repositoryId,\n });\n if (!repository) continue;\n if (reference?.projectId && repository.externalId !== reference.projectId) continue;\n if (reference?.projectPath && normalizePath(repository.slug) !== normalizePath(reference.projectPath)) continue;\n if (locator?.projectPath && normalizePath(repository.slug) !== normalizePath(locator.projectPath)) continue;\n if (reference?.connectionId && installation.externalId !== reference.connectionId) continue;\n const installationHost =\n typeof installation.providerMetadata.host === 'string'\n ? normalizeGitLabHost(installation.providerMetadata.host)\n : null;\n if (reference?.host && installationHost !== normalizeGitLabHost(reference.host)) continue;\n if (locator?.host && installationHost !== normalizeGitLabHost(locator.host)) continue;\n matches.push({\n connectionId: installation.externalId,\n projectId: repository.externalId,\n projectPath: repository.slug,\n });\n }\n }\n const match = matches.sort((left, right) => left.connectionId.localeCompare(right.connectionId))[0];\n if (!match) throw new GitLabApiError('GitLab issue is outside the active Factory project.', 404);\n return this.intake.getIssue({\n connection: gitlabConnection(match.connectionId),\n sourceId: encodeSourceId(match),\n issueId: input.issueId,\n });\n }\n\n /** Platform mode exposes org connections; direct mode returns undefined. */\n async statusConnections(): Promise<GitLabStatusConnection[] | undefined> {\n return undefined;\n }\n\n /** Direct mode verifies its configured credential; Platform mode uses connection status. */\n async verifyStatus(): Promise<void> {\n // Platform connection state is authoritative unless a provider overrides this probe.\n }\n\n protected get webhookSecret(): string | undefined {\n return undefined;\n }\n\n workers(ctx: IntegrationContext): MastraWorker[] {\n if (!gitlabReconciliationEnabled()) return [];\n const reconcile = attachGitLabReconciler(this, ctx);\n if (!reconcile) return [];\n const intervalMs = gitlabReconciliationInterval();\n return [\n new IssueReconcileWorker({\n integrationId: this.id,\n reconcile,\n ...(intervalMs ? { intervalMs } : {}),\n }),\n ];\n }\n routes(ctx: IntegrationContext): ApiRoute[] {\n const ingestFactoryEvent = attachGitLabRules(this, ctx);\n this.#ingestFactoryEvent = ingestFactoryEvent;\n return buildGitLabRoutes({\n gitlab: this,\n auth: ctx.auth,\n intake: ctx.storage?.intake,\n emitAudit: ctx.hooks?.emitAudit,\n sandbox: ctx.sandbox,\n webhookSecret: this.webhookSecret,\n ingestFactoryEvent,\n ...(ctx.controller ? { controller: ctx.controller } : {}),\n });\n }\n\n async ingestLinkedRepositoryBacklog(args: { orgId: string; projectRepositoryId: string }): Promise<void> {\n await ingestLinkedGitLabRepositoryBacklog({ gitlab: this, ...args, ingestFactoryEvent: this.#ingestFactoryEvent });\n }\n\n async agentTools(args: { requestContext: RequestContext }): Promise<IntegrationTools> {\n return buildGitLabAgentTools({ requestContext: args.requestContext, gitlab: this });\n }\n\n sessionTools({ requestContext }: { requestContext: RequestContext }): IntegrationTools {\n return createGitLabSubscriptionTools(requestContext, this);\n }\n\n async postToolObserver({\n toolContext,\n requestContext,\n }: Parameters<NonNullable<FactoryIntegration['postToolObserver']>>[0]): Promise<void> {\n const mergeRequestUrl = parseCreatedMergeRequest(toolContext);\n if (!mergeRequestUrl || !requestContext) return;\n await subscribeCurrentSessionToMergeRequest(requestContext, mergeRequestUrl, 'auto-create-change-request', this);\n }\n\n abstract diagnostics(): Record<string, unknown>;\n\n /** Prefer the configured direct token over an older Platform installation on the same host. */\n async resolveActiveConnectionForHost(storedConnectionId: string, host: string): Promise<string> {\n if (this.diagnostics().mode !== 'direct') return storedConnectionId;\n const [direct] = await this.activeContexts();\n return direct && normalizeGitLabHost(direct.host) === normalizeGitLabHost(host) ? direct.id : storedConnectionId;\n }\n\n async #versionControlContext(connection: IntegrationConnection): Promise<GitLabConnectionContext> {\n const connectionId = connectionIdFromConnection(connection);\n if (connectionId) return this.contextById(connectionId);\n const contexts = await this.activeContexts();\n if (contexts.length !== 1) {\n throw new GitLabApiError(\n 'GitLab version-control requests must identify a connection when multiple GitLab accounts are connected.',\n 400,\n );\n }\n return contexts[0]!;\n }\n async #versionControlContextForInstallation(\n connection: IntegrationConnection,\n host: string | undefined,\n ): Promise<GitLabConnectionContext> {\n // A direct PAT intentionally overrides Platform credentials. Old links can\n // retain their Platform connection id; use the PAT only for the same host.\n if (this.diagnostics().mode === 'direct' && host) {\n const [direct] = await this.activeContexts();\n if (direct && normalizeGitLabHost(host) === normalizeGitLabHost(direct.host)) return direct;\n }\n return this.#versionControlContext(connection);\n }\n async #contextForReference(reference: GitLabSourceReference): Promise<GitLabConnectionContext> {\n if (reference.connectionId) return this.contextById(reference.connectionId);\n const contexts = (await this.activeContexts()).filter(\n context => !reference.host || normalizeGitLabHost(context.host) === normalizeGitLabHost(reference.host),\n );\n if (contexts.length === 0) {\n throw new GitLabApiError('No active GitLab connection can access this source.', 401);\n }\n if (contexts.length === 1) return contexts[0]!;\n\n if (this.#sourceControl) {\n const linkedConnectionIds = new Set(\n (await this.#sourceControl.projectRepositories.listConfiguredExternalKeys())\n .filter(key => key.repositoryExternalId === reference.projectId)\n .map(key => key.installationExternalId),\n );\n const linked = contexts.filter(context => linkedConnectionIds.has(context.id));\n if (linked.length > 0) return linked.sort((left, right) => left.id.localeCompare(right.id))[0]!;\n }\n\n for (const context of contexts.sort((left, right) => left.id.localeCompare(right.id))) {\n try {\n await context.api.getProject(reference.projectId);\n return context;\n } catch (error) {\n if (!(error instanceof GitLabApiError) || ![401, 403, 404].includes(error.status ?? 0)) throw error;\n // This credential cannot access the project; try another active account for the same canonical source.\n }\n }\n throw new GitLabApiError('No active GitLab connection can access this source.', 404);\n }\n\n async #resolveSourceReference(\n reference: GitLabSourceReference,\n ): Promise<{ context: GitLabConnectionContext; source: ResolvedGitLabSourceReference }> {\n const context = await this.#contextForReference(reference);\n const projectPath =\n reference.projectPath ?? (await context.api.getProject(reference.projectId)).path_with_namespace;\n return {\n context,\n source: {\n connectionId: context.id,\n host: normalizeGitLabHost(reference.host ?? context.host),\n projectId: reference.projectId,\n projectPath,\n },\n };\n }\n\n async #resolveIntakeDispatch({ externalSource }: ResolveIntakeDispatchInput): Promise<ResolvedIntakeDispatch | null> {\n if (externalSource.type !== 'issue') return null;\n const reference = decodeIssueReference(externalSource.externalId);\n if (!reference) return null;\n const { context, source } = await this.#resolveSourceReference(reference);\n return {\n connection: context.connection,\n sourceId: encodeSourceId(source),\n issueId: String(reference.issueIid),\n };\n }\n\n async #listSources(): Promise<IntakeSource[]> {\n const sources = new Map<string, IntakeSource>();\n for (const context of await this.activeContexts()) {\n for (let page = 1; ; page++) {\n const projects = await context.api.listProjects({ page });\n for (const project of projects) {\n const source = this.#toIntakeSource(context, project);\n if (!sources.has(source.id)) sources.set(source.id, source);\n }\n if (projects.length < GITLAB_PROJECTS_PAGE_SIZE) break;\n }\n }\n return [...sources.values()];\n }\n\n async #listItems(input: ListIntakeItemsInput): Promise<IntakeItemPage> {\n const result = await this.#listIssuePage(input.sourceIds, input.cursor);\n return {\n items: result.issues.map(({ issue, source, context }) => ({\n source: {\n type: 'issue',\n externalId: encodeIssueReference({ ...source, issueIid: issue.iid }),\n url: issue.web_url,\n },\n sourceId: encodeSourceId(source),\n title: `${source.projectPath}#${issue.iid}: ${issue.title}`,\n status: issue.state,\n labels: issue.labels ?? [],\n assignee: displayName(issue.assignee),\n createdAt: issue.created_at,\n updatedAt: issue.updated_at,\n metadata: {\n identifier: `${source.projectPath}#${issue.iid}`,\n projectId: source.projectId,\n projectPath: source.projectPath,\n connectionId: context.id,\n accountLabel: context.label,\n labelColors: Object.fromEntries((issue.labelDetails ?? []).map(label => [label.name, label.color])),\n },\n })),\n nextCursor: result.nextCursor,\n };\n }\n\n async #listIssues(input: ListIntakeIssuesInput) {\n const result = await this.#listIssuePage(input.sourceIds, input.cursor, input.labels);\n return {\n issues: result.issues.map(({ issue, source }) => ({\n ...this.#toIntakeIssue(issue, source.projectPath),\n sourceId: encodeSourceId(source),\n })),\n nextCursor: result.nextCursor,\n };\n }\n\n async #listIssuePage(sourceIds: string[], cursor?: string, labels?: string[]) {\n const sources = sourceIds.map(decodeSourceId).filter((source): source is GitLabSourceReference => source !== null);\n if (sources.length === 0) return { issues: [], nextCursor: null };\n const current = decodePageCursor(cursor);\n if (!current || current.source >= sources.length) return { issues: [], nextCursor: null };\n\n for (let sourceIndex = current.source; sourceIndex < sources.length; sourceIndex++) {\n const { source, context } = await this.#resolveSourceReference(sources[sourceIndex]!);\n const page = sourceIndex === current.source ? current.page : 1;\n const issues = await context.api.listIssues(source.projectId, { page, labels });\n const nextCursor =\n issues.length === GITLAB_ISSUES_PAGE_SIZE\n ? encodePageCursor({ source: sourceIndex, page: page + 1 })\n : sourceIndex + 1 < sources.length\n ? encodePageCursor({ source: sourceIndex + 1, page: 1 })\n : null;\n return { issues: issues.map(issue => ({ issue, source, context })), nextCursor };\n }\n return { issues: [], nextCursor: null };\n }\n\n async #getIssue(input: GetIntakeIssueInput): Promise<IntakeIssueDetail | null> {\n const resolved = await this.#resolveRequest(input);\n let issue: GitLabIssue;\n try {\n issue = await resolved.context.api.getIssue(resolved.projectId, resolved.issueIid);\n } catch (error) {\n if (error instanceof GitLabApiError && error.status === 404) return null;\n throw error;\n }\n const notes = await this.#listAllNotes(resolved.context.api, resolved.projectId, resolved.issueIid);\n return {\n ...this.#toIntakeIssue(issue, resolved.projectPath),\n description: issue.description?.trim() || null,\n comments: notes\n .filter(note => !note.system)\n .map(note => ({ author: displayName(note.author), body: note.body, createdAt: note.created_at })),\n };\n }\n\n async #listAllNotes(api: GitLabApiClient, projectId: string, issueIid: number): Promise<GitLabNote[]> {\n const notes: GitLabNote[] = [];\n for (let page = 1; page <= MAX_NOTES_PAGES; page++) {\n const result = await api.listNotes(projectId, issueIid, { page });\n notes.push(...result);\n if (result.length < GITLAB_NOTES_PAGE_SIZE) break;\n }\n return notes;\n }\n\n async #createComment(input: CreateIntakeCommentInput): Promise<CreatedIntakeComment | null> {\n const resolved = await this.#resolveRequest(input);\n try {\n const issue = await resolved.context.api.getIssue(resolved.projectId, resolved.issueIid);\n const note = await resolved.context.api.createNote(resolved.projectId, resolved.issueIid, input.body);\n return { id: String(note.id), url: `${issue.web_url}#note_${note.id}` };\n } catch (error) {\n if (error instanceof GitLabApiError && error.status === 404) return null;\n throw error;\n }\n }\n\n async #updateIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n const resolved = await this.#resolveRequest(input);\n let issue: GitLabIssue;\n try {\n issue = await resolved.context.api.getIssue(resolved.projectId, resolved.issueIid);\n } catch (error) {\n if (error instanceof GitLabApiError && error.status === 404) return null;\n throw error;\n }\n const stateEvent = targetStateEvent(input);\n if (!stateEvent) return null;\n if ((stateEvent === 'close' && issue.state === 'closed') || (stateEvent === 'reopen' && issue.state === 'opened')) {\n return this.#toIntakeIssue(issue, resolved.projectPath);\n }\n const updated = await resolved.context.api.updateIssueState(resolved.projectId, resolved.issueIid, stateEvent);\n return this.#toIntakeIssue(updated, resolved.projectPath);\n }\n\n async #resolveRequest(input: GetIntakeIssueInput): Promise<{\n context: GitLabConnectionContext;\n projectId: string;\n projectPath: string;\n issueIid: number;\n }> {\n const issueReference = decodeIssueReference(input.issueId);\n const source = input.sourceId ? decodeSourceId(input.sourceId) : null;\n const locator = parseIssueLocator(input.issueId);\n const reference = issueReference ?? source;\n let context: GitLabConnectionContext;\n if (reference) {\n context = await this.#contextForReference(reference);\n } else {\n const connectionId = connectionIdFromConnection(input.connection);\n const contexts = connectionId ? [await this.contextById(connectionId)] : await this.activeContexts();\n if (contexts.length !== 1) {\n throw new GitLabApiError('GitLab issue reference must resolve to exactly one active connection.', 400);\n }\n context = contexts[0]!;\n }\n const projectId = issueReference?.projectId ?? source?.projectId ?? locator?.projectPath;\n const issueIid = issueReference?.issueIid ?? locator?.issueIid ?? parsePositiveInteger(input.issueId);\n if (!projectId || !issueIid) {\n throw new GitLabApiError(\n 'GitLab issue must include a project and issue IID (for example, group/project#42).',\n 400,\n );\n }\n const projectPath =\n issueReference?.projectPath ??\n source?.projectPath ??\n locator?.projectPath ??\n (await context.api.getProject(projectId)).path_with_namespace;\n return { context, projectId, projectPath, issueIid };\n }\n\n #toIntakeSource(context: GitLabConnectionContext, project: GitLabProject): IntakeSource {\n const reference: GitLabSourceReference = {\n host: normalizeGitLabHost(context.host),\n projectId: String(project.id),\n projectPath: project.path_with_namespace,\n };\n return {\n id: encodeSourceId(reference),\n name: project.path_with_namespace,\n type: 'project',\n metadata: {\n projectId: String(project.id),\n projectPath: project.path_with_namespace,\n defaultBranch: project.default_branch ?? null,\n connectionId: context.id,\n accountLabel: context.label,\n url: project.web_url,\n },\n };\n }\n\n #toIntakeIssue(issue: GitLabIssue, projectPath: string): IntakeIssue {\n const assignees = issue.assignees?.map(displayName).filter((name): name is string => name !== null) ?? [];\n return {\n id: String(issue.iid),\n identifier: `${projectPath}#${issue.iid}`,\n title: issue.title,\n url: issue.web_url,\n author: displayName(issue.author),\n authorUsername: issue.author?.username ?? null,\n state: issue.state,\n stateType: issue.state === 'closed' ? 'completed' : 'unstarted',\n priority: typeof issue.weight === 'number' ? String(issue.weight) : null,\n assignee: displayName(issue.assignee) ?? assignees[0] ?? null,\n assignees,\n source: projectPath,\n labels: issue.labels ?? [],\n labelColors: Object.fromEntries((issue.labelDetails ?? []).map(label => [label.name, label.color])),\n commentCount: issue.user_notes_count ?? null,\n createdAt: issue.created_at,\n updatedAt: issue.updated_at,\n };\n }\n}\n\nexport type GitLabAccessTokenType = 'personal' | 'group';\n\nexport interface GitLabIntegrationConfig {\n rules?: GitLabRuleOverrides;\n accessToken?: string;\n /** Defaults to `personal`; both token types authenticate identically but have different resource reach. */\n accessTokenType?: GitLabAccessTokenType;\n baseUrl?: string;\n webhookSecret?: string;\n fetchImpl?: typeof fetch;\n}\n\nconst DIRECT_CONNECTION_TOKEN = 'gitlab-direct-access-token';\n\nexport class GitLabIntegration extends GitLabIntegrationBase {\n readonly #accessToken: string;\n readonly #accessTokenType: GitLabAccessTokenType;\n readonly #baseUrl: string;\n readonly #webhookSecret: string | undefined;\n readonly #context: GitLabConnectionContext;\n\n constructor(config: GitLabIntegrationConfig = {}) {\n super(config.rules);\n const accessToken = config.accessToken?.trim() || process.env.GITLAB_ACCESS_TOKEN?.trim();\n if (!accessToken) {\n throw new Error('GitLabIntegration: missing required GITLAB_ACCESS_TOKEN.');\n }\n this.#accessToken = accessToken;\n this.#accessTokenType = parseAccessTokenType(\n config.accessTokenType ?? process.env.GITLAB_ACCESS_TOKEN_TYPE?.trim(),\n );\n this.#baseUrl = (config.baseUrl ?? process.env.GITLAB_BASE_URL?.trim() ?? 'https://gitlab.com').replace(/\\/+$/, '');\n this.#webhookSecret = config.webhookSecret?.trim() || process.env.GITLAB_WEBHOOK_SECRET?.trim() || undefined;\n const api = new GitLabApiClient({\n baseUrl: this.#baseUrl,\n accessToken: this.#accessToken,\n ...(config.fetchImpl ? { fetchImpl: config.fetchImpl } : {}),\n });\n this.#context = {\n id: DIRECT_CONNECTION_ID,\n label: new URL(this.#baseUrl).host,\n api,\n connection: { type: 'oauth', accessToken: DIRECT_CONNECTION_TOKEN },\n host: new URL(this.#baseUrl).host,\n webBaseUrl: this.#baseUrl,\n repositoryAccessToken: async () => this.#accessToken,\n };\n }\n\n protected override get webhookSecret(): string | undefined {\n return this.#webhookSecret;\n }\n\n async hasActiveConnections(): Promise<boolean> {\n return true;\n }\n\n override async verifyStatus(): Promise<void> {\n await this.#context.api.getCurrentUser();\n }\n\n authFailureMessage(): string {\n return `GitLab rejected the configured ${this.#accessTokenType} access token. Check the token and its scopes.`;\n }\n\n protected async activeContexts(): Promise<GitLabConnectionContext[]> {\n return [this.#context];\n }\n\n protected async contextById(connectionId: string): Promise<GitLabConnectionContext> {\n if (connectionId !== DIRECT_CONNECTION_ID) {\n throw new GitLabApiError('GitLab connection is unavailable.', 401);\n }\n return this.#context;\n }\n\n diagnostics(): Record<string, unknown> {\n return {\n configured: true,\n mode: 'direct',\n accessTokenType: this.#accessTokenType,\n endpointHost: new URL(this.#baseUrl).host,\n webhookConfigured: Boolean(this.#webhookSecret),\n };\n }\n}\n\nfunction parseAccessTokenType(value: string | undefined): GitLabAccessTokenType {\n const normalized = value?.trim().toLowerCase() || 'personal';\n if (normalized === 'personal' || normalized === 'group') return normalized;\n throw new Error(\"GitLabIntegration: GITLAB_ACCESS_TOKEN_TYPE must be 'personal' or 'group'.\");\n}\n\nexport function encodeSourceId(reference: GitLabSourceReference): string {\n if (reference.host) {\n return `${GITLAB_SOURCE_PREFIX}${encodeOpaque({\n version: 2,\n host: normalizeGitLabHost(reference.host),\n projectId: reference.projectId,\n })}`;\n }\n if (!reference.connectionId || !reference.projectPath) {\n throw new Error('GitLab source reference is missing its instance host.');\n }\n return `${GITLAB_SOURCE_PREFIX}${encodeOpaque(reference)}`;\n}\n\nexport function decodeSourceId(value: string): GitLabSourceReference | null {\n return decodeOpaque(value, GITLAB_SOURCE_PREFIX, isSourceReference);\n}\n\nexport function encodeIssueReference(reference: GitLabIssueReference): string {\n if (reference.host) {\n return `${GITLAB_ISSUE_PREFIX}${encodeOpaque({\n version: 2,\n host: normalizeGitLabHost(reference.host),\n projectId: reference.projectId,\n issueIid: reference.issueIid,\n })}`;\n }\n if (!reference.connectionId || !reference.projectPath) {\n throw new Error('GitLab issue reference is missing its instance host.');\n }\n return `${GITLAB_ISSUE_PREFIX}${encodeOpaque(reference)}`;\n}\n\nexport function decodeIssueReference(value: string): GitLabIssueReference | null {\n return decodeOpaque(value, GITLAB_ISSUE_PREFIX, isIssueReference);\n}\n\nexport function decodeMergeRequestReference(value: string): GitLabMergeRequestReference | null {\n return decodeOpaque(value, GITLAB_MERGE_REQUEST_PREFIX, isMergeRequestReference);\n}\n\nexport function gitlabConnection(connectionId: string): IntegrationConnection {\n return { type: 'oauth', accessToken: `${GITLAB_CONNECTION_TOKEN_PREFIX}${connectionId}` };\n}\n\nfunction connectionIdFromConnection(connection: IntegrationConnection): string | null {\n if (connection.type !== 'oauth' || !connection.accessToken.startsWith(GITLAB_CONNECTION_TOKEN_PREFIX)) return null;\n return connection.accessToken.slice(GITLAB_CONNECTION_TOKEN_PREFIX.length) || null;\n}\n\nfunction encodeOpaque(value: unknown): string {\n return Buffer.from(JSON.stringify(value)).toString('base64url');\n}\n\nfunction decodeOpaque<T>(value: string, prefix: string, guard: (value: unknown) => value is T): T | null {\n if (!value.startsWith(prefix)) return null;\n try {\n const decoded = JSON.parse(Buffer.from(value.slice(prefix.length), 'base64url').toString('utf8')) as unknown;\n return guard(decoded) ? decoded : null;\n } catch {\n return null;\n }\n}\n\nexport function normalizeGitLabHost(host: string): string {\n return host.trim().toLowerCase().replace(/\\.$/, '');\n}\n\nfunction isSourceReference(value: unknown): value is GitLabSourceReference {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const ref = value as Record<string, unknown>;\n if (typeof ref.projectId !== 'string' || ref.projectId.length === 0) return false;\n const canonical = ref.version === 2 && typeof ref.host === 'string' && normalizeGitLabHost(ref.host).length > 0;\n const legacy =\n typeof ref.connectionId === 'string' &&\n ref.connectionId.length > 0 &&\n typeof ref.projectPath === 'string' &&\n ref.projectPath.length > 0;\n return canonical || legacy;\n}\n\nfunction isIssueReference(value: unknown): value is GitLabIssueReference {\n return (\n isSourceReference(value) &&\n Number.isSafeInteger((value as GitLabIssueReference).issueIid) &&\n (value as GitLabIssueReference).issueIid > 0\n );\n}\n\nfunction isMergeRequestReference(value: unknown): value is GitLabMergeRequestReference {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const ref = value as Record<string, unknown>;\n return (\n ref.version === 1 &&\n typeof ref.host === 'string' &&\n normalizeGitLabHost(ref.host).length > 0 &&\n Number.isSafeInteger(ref.projectId) &&\n (ref.projectId as number) > 0 &&\n Number.isSafeInteger(ref.mergeRequestIid) &&\n (ref.mergeRequestIid as number) > 0\n );\n}\n\nfunction encodePageCursor(cursor: GitLabPageCursor): string {\n return encodeOpaque(cursor);\n}\n\nfunction decodePageCursor(value: string | undefined): GitLabPageCursor | null {\n if (!value) return { source: 0, page: 1 };\n try {\n const decoded = JSON.parse(Buffer.from(value, 'base64url').toString('utf8')) as Record<string, unknown>;\n if (!Number.isSafeInteger(decoded.source) || Number(decoded.source) < 0) return null;\n if (!Number.isSafeInteger(decoded.page) || Number(decoded.page) < 1) return null;\n return { source: Number(decoded.source), page: Number(decoded.page) };\n } catch {\n return null;\n }\n}\n\nfunction displayName(user: { name?: string | null; username: string } | null | undefined): string | null {\n return user?.name?.trim() || user?.username || null;\n}\n\nfunction parsePositiveInteger(value: string): number | null {\n if (!/^\\d+$/.test(value)) return null;\n const parsed = Number(value);\n return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;\n}\n\nfunction parseIssueLocator(value: string): {\n host?: string;\n projectPath: string;\n issueIid: number;\n} | null {\n const shorthand = value.match(/^(.+?)#(\\d+)$/);\n if (shorthand) {\n const issueIid = parsePositiveInteger(shorthand[2]!);\n const projectPath = shorthand[1]!.replace(/^\\/+|\\/+$/g, '');\n return issueIid && projectPath ? { projectPath, issueIid } : null;\n }\n try {\n const url = new URL(value);\n const match = url.pathname.match(/^\\/(.+)\\/-\\/issues\\/(\\d+)\\/?$/);\n if (!match) return null;\n const issueIid = parsePositiveInteger(match[2]!);\n if (!issueIid) return null;\n const projectPath = decodeURIComponent(match[1]!);\n return { host: url.host, projectPath, issueIid };\n } catch {\n return null;\n }\n}\n\nfunction targetStateEvent(input: UpdateIntakeIssueInput): 'close' | 'reopen' | null {\n if (input.state.kind === 'byType') {\n // GitLab issues have only opened/closed states, so canceled is intentionally mapped to close.\n return input.state.stateType === 'completed' || input.state.stateType === 'canceled' ? 'close' : 'reopen';\n }\n const name = input.state.name.trim().toLowerCase();\n if (name === 'closed' || name === 'close') return 'close';\n if (name === 'opened' || name === 'open' || name === 'reopen') return 'reopen';\n return null;\n}\n"],"mappings":";;;;;;;;;;;AAmGA,MAAM,uBAAuB;AAC7B,MAAM,iCAAiC;AACvC,MAAM,uBAAuB;AAC7B,MAA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AM,cAAc,aAAa,UAAU;CAEnG,MAAM,OAAO,MAAM,MAAM,KAAK,KAAK,CAAC,CAAC,YAAY;CACjD,IAAI,SAAS,YAAY,SAAS,SAAS,OAAO;CAClD,IAAI,SAAS,YAAY,SAAS,UAAU,SAAS,UAAU,OAAO;CACtE,OAAO;AACT"}
1
+ {"version":3,"file":"integration.js","names":[],"sources":["../../../src/integrations/gitlab/integration.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\n\nimport type { IntegrationConnection } from '../../capabilities/connection.js';\nimport type {\n CreateIntakeCommentInput,\n CreatedIntakeComment,\n GetIntakeIssueInput,\n Intake,\n IntakeIssue,\n IntakeIssueDetail,\n IntakeItemPage,\n IntakeSource,\n ListIntakeIssuesInput,\n ListIntakeItemsInput,\n ResolveIntakeDispatchInput,\n ResolvedIntakeDispatch,\n UpdateIntakeIssueInput,\n} from '../../capabilities/intake.js';\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';\nimport { IssueReconcileWorker } from '../issue-reconcile-worker.js';\nimport { buildGitLabAgentTools } from './agent-tools.js';\nimport {\n GITLAB_ISSUES_PAGE_SIZE,\n GITLAB_NOTES_PAGE_SIZE,\n GITLAB_PROJECTS_PAGE_SIZE,\n GitLabApiClient,\n GitLabApiError,\n} from './api.js';\nimport type { GitLabIssue, GitLabNote, GitLabProject } from './api.js';\nimport { resolveGitLabRules } from './default-rules.js';\nimport type { GitLabEventRules, GitLabRuleOverrides } from './default-rules.js';\nimport { attachGitLabReconciler } from './reconciler.js';\nimport { gitlabReconciliationInterval } from './reconciliation-config.js';\nimport { buildGitLabRoutes, ingestLinkedGitLabRepositoryBacklog } from './routes.js';\nimport { attachGitLabRules } from './rules.js';\nimport {\n createGitLabSubscriptionTools,\n parseCreatedMergeRequest,\n subscribeCurrentSessionToMergeRequest,\n} from './session-subscriptions.js';\nimport type { GitLabSubscriptionStorage } from './subscriptions.js';\nimport { buildGitLabVersionControl } from './version-control.js';\n\ninterface GitLabConnectionContext {\n id: string;\n label: string | null;\n api: GitLabApiClient;\n connection: IntegrationConnection;\n host: string;\n webBaseUrl?: string;\n /** Resolves a fresh provider token for a single brokered git operation. */\n repositoryAccessToken?: () => Promise<string>;\n}\n\ninterface GitLabSourceReference {\n /** Present only on legacy v1 ids; authentication is not resource identity. */\n connectionId?: string;\n /** Canonical v2 ids use the GitLab instance host plus immutable project id. */\n host?: string;\n projectId: string;\n /** Legacy ids carry display metadata; v2 resolves it from GitLab. */\n projectPath?: string;\n}\n\ninterface ResolvedGitLabSourceReference extends GitLabSourceReference {\n connectionId: string;\n host: string;\n projectPath: string;\n}\n\ninterface GitLabIssueReference extends GitLabSourceReference {\n issueIid: number;\n}\n\nexport interface GitLabMergeRequestReference {\n version: 1;\n host: string;\n projectId: number;\n mergeRequestIid: number;\n}\n\ninterface GitLabPageCursor {\n source: number;\n page: number;\n}\n\nexport interface GitLabStatusConnection {\n id: string;\n integrationId: string;\n status: 'active' | 'needs_reauth';\n accountLabel: string | null;\n}\n\nconst DIRECT_CONNECTION_ID = 'direct';\nconst GITLAB_CONNECTION_TOKEN_PREFIX = 'gitlab-connection:';\nconst GITLAB_SOURCE_PREFIX = 'gitlab-project:';\nconst GITLAB_ISSUE_PREFIX = 'gitlab-issue:';\nconst GITLAB_MERGE_REQUEST_PREFIX = 'gitlab-pr:';\nexport const GITLAB_TRUSTED_ACCESS_LEVEL = 30;\n// Bound issue detail reads to 2,000 notes. GitLab does not expose truncation through the Intake contract.\nconst MAX_NOTES_PAGES = 20;\nconst UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nexport abstract class GitLabIntegrationBase implements FactoryIntegration {\n readonly id = 'gitlab';\n #projects: FactoryProjectsStorage | undefined;\n #sourceControl: SourceControlStorageHandle | undefined;\n #integrationStorage: GitLabSubscriptionStorage | undefined;\n #auth: RouteAuth | undefined;\n #ingestFactoryEvent: ReturnType<typeof attachGitLabRules>;\n readonly #orgIdByResourceId = new Map<string, string | null>();\n readonly rules: GitLabEventRules;\n\n constructor(rules?: GitLabRuleOverrides) {\n this.rules = resolveGitLabRules(rules);\n }\n\n readonly intake: Intake = {\n resolveIntakeDispatch: input => this.#resolveIntakeDispatch(input),\n listSources: () => this.#listSources(),\n listItems: input => this.#listItems(input),\n listIssues: input => this.#listIssues(input),\n getIssue: input => this.#getIssue(input),\n createComment: input => this.#createComment(input),\n updateIssue: input => this.#updateIssue(input),\n };\n readonly versionControl = buildGitLabVersionControl({\n contextForConnection: connection => this.#versionControlContext(connection),\n contextForStoredInstallation: (connection, host) => this.#versionControlContextForInstallation(connection, host),\n });\n initialize({\n storage,\n projects,\n auth,\n sourceControl,\n }: {\n storage?: IntegrationStorageHandle;\n projects: FactoryProjectsStorage;\n auth: RouteAuth;\n sourceControl?: SourceControlStorageHandle;\n }): void {\n this.#projects = projects;\n this.#auth = auth;\n this.#sourceControl = sourceControl;\n this.#integrationStorage = storage as GitLabSubscriptionStorage | undefined;\n }\n\n /** Generic integration persistence (merge-request subscriptions). */\n get integrationStorage(): GitLabSubscriptionStorage {\n if (!this.#integrationStorage) {\n throw new Error(`${this.constructor.name} is not initialized — the factory binds storage during prepare().`);\n }\n return this.#integrationStorage;\n }\n\n /** Source-control rows for this integration; absent when the host runs without them. */\n get sourceControlStorage(): SourceControlStorageHandle | undefined {\n return this.#sourceControl;\n }\n\n get authEnabled(): boolean {\n return this.#auth?.enabled() ?? false;\n }\n\n get projects(): FactoryProjectsStorage {\n if (!this.#projects) {\n throw new Error(`${this.constructor.name} is not initialized — the factory binds storage during prepare().`);\n }\n return this.#projects;\n }\n\n async resolveOrgId(resourceId: string): Promise<string | null> {\n const cached = this.#orgIdByResourceId.get(resourceId);\n if (cached !== undefined) return cached;\n if (!UUID_PATTERN.test(resourceId)) {\n this.#orgIdByResourceId.set(resourceId, null);\n return null;\n }\n try {\n await this.projects.ensureReady();\n const project = await this.projects.getById({ id: resourceId });\n const orgId = project?.orgId ?? null;\n this.#orgIdByResourceId.set(resourceId, orgId);\n return orgId;\n } catch {\n return null;\n }\n }\n\n clearCaches(): void {\n this.#orgIdByResourceId.clear();\n }\n\n abstract hasActiveConnections(): Promise<boolean>;\n abstract authFailureMessage(): string;\n protected abstract activeContexts(): Promise<GitLabConnectionContext[]>;\n protected abstract contextById(connectionId: string): Promise<GitLabConnectionContext>;\n\n /** Resolve only a GitLab repository linked to this Factory in this organization. */\n async getLinkedRepository(input: { orgId: string; factoryProjectId: string; projectRepositoryId: string }) {\n if (!this.#sourceControl) return null;\n const connections = await this.#sourceControl.connections.list({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n for (const connection of connections) {\n if (connection.integrationId !== 'gitlab') continue;\n const links = await this.#sourceControl.projectRepositories.list({\n orgId: input.orgId,\n connectionId: connection.id,\n });\n const link = links.find(candidate => candidate.id === input.projectRepositoryId);\n if (!link) continue;\n const repository = await this.#sourceControl.repositories.get({ orgId: input.orgId, id: link.repositoryId });\n const installation = await this.#sourceControl.installations.get({\n orgId: input.orgId,\n id: connection.installationId,\n });\n if (!repository || !installation) return null;\n const host = installation.providerMetadata.host;\n if (typeof host !== 'string' || !host) return null;\n return { repository, host: normalizeGitLabHost(host) };\n }\n return null;\n }\n\n async getProjectMemberAccessLevel(\n connectionId: string,\n projectId: string,\n username: string,\n ): Promise<number | undefined> {\n const normalized = username.trim().toLowerCase();\n if (!normalized) return undefined;\n const members = await (await this.contextById(connectionId)).api.listProjectMembers(projectId, { query: username });\n const member = members.find(\n candidate => candidate.username.toLowerCase() === normalized && candidate.state !== 'blocked',\n );\n return member?.access_level;\n }\n\n async getWorkItemAuthorUsername(\n connectionId: string,\n projectId: string,\n kind: 'issue' | 'merge_request',\n iid: number,\n ): Promise<string | undefined> {\n const api = (await this.contextById(connectionId)).api;\n const item = kind === 'issue' ? await api.getIssue(projectId, iid) : await api.getMergeRequest(projectId, iid);\n return item.author?.username;\n }\n\n async isProjectMemberTrustedForSource(sourceId: string, username: string): Promise<boolean> {\n const reference = decodeSourceId(sourceId);\n if (!reference) throw new GitLabApiError('GitLab source identity is invalid.', 400);\n const { context, source } = await this.#resolveSourceReference(reference);\n const accessLevel = await this.getProjectMemberAccessLevel(context.id, source.projectId, username);\n return (accessLevel ?? 0) >= GITLAB_TRUSTED_ACCESS_LEVEL;\n }\n\n async getIssueForFactoryProject(input: {\n orgId: string;\n factoryProjectId: string;\n issueId: string;\n }): Promise<IntakeIssueDetail | null> {\n if (!this.#sourceControl) throw new GitLabApiError('GitLab source control is unavailable.', 503);\n const reference = decodeIssueReference(input.issueId);\n const locator = parseIssueLocator(input.issueId);\n if (!reference && !locator) {\n throw new GitLabApiError('GitLab issue must include a project and issue IID.', 400);\n }\n\n const normalizePath = (value: string) => value.replace(/^\\/+|\\/+$/g, '').toLowerCase();\n const matches: Array<{\n connectionId: string;\n projectId: string;\n projectPath: string;\n }> = [];\n const connections = await this.#sourceControl.connections.list({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n for (const connection of connections) {\n const installation = await this.#sourceControl.installations.get({\n orgId: input.orgId,\n id: connection.installationId,\n });\n if (!installation) continue;\n for (const projectRepository of await this.#sourceControl.projectRepositories.list({\n orgId: input.orgId,\n connectionId: connection.id,\n })) {\n const repository = await this.#sourceControl.repositories.get({\n orgId: input.orgId,\n id: projectRepository.repositoryId,\n });\n if (!repository) continue;\n if (reference?.projectId && repository.externalId !== reference.projectId) continue;\n if (reference?.projectPath && normalizePath(repository.slug) !== normalizePath(reference.projectPath)) continue;\n if (locator?.projectPath && normalizePath(repository.slug) !== normalizePath(locator.projectPath)) continue;\n if (reference?.connectionId && installation.externalId !== reference.connectionId) continue;\n const installationHost =\n typeof installation.providerMetadata.host === 'string'\n ? normalizeGitLabHost(installation.providerMetadata.host)\n : null;\n if (reference?.host && installationHost !== normalizeGitLabHost(reference.host)) continue;\n if (locator?.host && installationHost !== normalizeGitLabHost(locator.host)) continue;\n matches.push({\n connectionId: installation.externalId,\n projectId: repository.externalId,\n projectPath: repository.slug,\n });\n }\n }\n const match = matches.sort((left, right) => left.connectionId.localeCompare(right.connectionId))[0];\n if (!match) throw new GitLabApiError('GitLab issue is outside the active Factory project.', 404);\n return this.intake.getIssue({\n connection: gitlabConnection(match.connectionId),\n sourceId: encodeSourceId(match),\n issueId: input.issueId,\n });\n }\n\n /** Platform mode exposes org connections; direct mode returns undefined. */\n async statusConnections(): Promise<GitLabStatusConnection[] | undefined> {\n return undefined;\n }\n\n /** Direct mode verifies its configured credential; Platform mode uses connection status. */\n async verifyStatus(): Promise<void> {\n // Platform connection state is authoritative unless a provider overrides this probe.\n }\n\n protected get webhookSecret(): string | undefined {\n return undefined;\n }\n\n workers(ctx: IntegrationContext): MastraWorker[] {\n const reconcile = attachGitLabReconciler(this, ctx);\n if (!reconcile) return [];\n const intervalMs = gitlabReconciliationInterval();\n return [\n new IssueReconcileWorker({\n integrationId: this.id,\n reconcile,\n ...(intervalMs ? { intervalMs } : {}),\n }),\n ];\n }\n routes(ctx: IntegrationContext): ApiRoute[] {\n const ingestFactoryEvent = attachGitLabRules(this, ctx);\n this.#ingestFactoryEvent = ingestFactoryEvent;\n return buildGitLabRoutes({\n gitlab: this,\n auth: ctx.auth,\n intake: ctx.storage?.intake,\n emitAudit: ctx.hooks?.emitAudit,\n sandbox: ctx.sandbox,\n webhookSecret: this.webhookSecret,\n ingestFactoryEvent,\n ...(ctx.controller ? { controller: ctx.controller } : {}),\n });\n }\n\n async ingestLinkedRepositoryBacklog(args: { orgId: string; projectRepositoryId: string }): Promise<void> {\n await ingestLinkedGitLabRepositoryBacklog({ gitlab: this, ...args, ingestFactoryEvent: this.#ingestFactoryEvent });\n }\n\n async agentTools(args: { requestContext: RequestContext }): Promise<IntegrationTools> {\n return buildGitLabAgentTools({ requestContext: args.requestContext, gitlab: this });\n }\n\n sessionTools({ requestContext }: { requestContext: RequestContext }): IntegrationTools {\n return createGitLabSubscriptionTools(requestContext, this);\n }\n\n async postToolObserver({\n toolContext,\n requestContext,\n }: Parameters<NonNullable<FactoryIntegration['postToolObserver']>>[0]): Promise<void> {\n const mergeRequestUrl = parseCreatedMergeRequest(toolContext);\n if (!mergeRequestUrl || !requestContext) return;\n await subscribeCurrentSessionToMergeRequest(requestContext, mergeRequestUrl, 'auto-create-change-request', this);\n }\n\n abstract diagnostics(): Record<string, unknown>;\n\n /** Prefer the configured direct token over an older Platform installation on the same host. */\n async resolveActiveConnectionForHost(storedConnectionId: string, host: string): Promise<string> {\n if (this.diagnostics().mode !== 'direct') return storedConnectionId;\n const [direct] = await this.activeContexts();\n return direct && normalizeGitLabHost(direct.host) === normalizeGitLabHost(host) ? direct.id : storedConnectionId;\n }\n\n async #versionControlContext(connection: IntegrationConnection): Promise<GitLabConnectionContext> {\n const connectionId = connectionIdFromConnection(connection);\n if (connectionId) return this.contextById(connectionId);\n const contexts = await this.activeContexts();\n if (contexts.length !== 1) {\n throw new GitLabApiError(\n 'GitLab version-control requests must identify a connection when multiple GitLab accounts are connected.',\n 400,\n );\n }\n return contexts[0]!;\n }\n async #versionControlContextForInstallation(\n connection: IntegrationConnection,\n host: string | undefined,\n ): Promise<GitLabConnectionContext> {\n // A direct PAT intentionally overrides Platform credentials. Old links can\n // retain their Platform connection id; use the PAT only for the same host.\n if (this.diagnostics().mode === 'direct' && host) {\n const [direct] = await this.activeContexts();\n if (direct && normalizeGitLabHost(host) === normalizeGitLabHost(direct.host)) return direct;\n }\n return this.#versionControlContext(connection);\n }\n async #contextForReference(reference: GitLabSourceReference): Promise<GitLabConnectionContext> {\n if (reference.connectionId) return this.contextById(reference.connectionId);\n const contexts = (await this.activeContexts()).filter(\n context => !reference.host || normalizeGitLabHost(context.host) === normalizeGitLabHost(reference.host),\n );\n if (contexts.length === 0) {\n throw new GitLabApiError('No active GitLab connection can access this source.', 401);\n }\n if (contexts.length === 1) return contexts[0]!;\n\n if (this.#sourceControl) {\n const linkedConnectionIds = new Set(\n (await this.#sourceControl.projectRepositories.listConfiguredExternalKeys())\n .filter(key => key.repositoryExternalId === reference.projectId)\n .map(key => key.installationExternalId),\n );\n const linked = contexts.filter(context => linkedConnectionIds.has(context.id));\n if (linked.length > 0) return linked.sort((left, right) => left.id.localeCompare(right.id))[0]!;\n }\n\n for (const context of contexts.sort((left, right) => left.id.localeCompare(right.id))) {\n try {\n await context.api.getProject(reference.projectId);\n return context;\n } catch (error) {\n if (!(error instanceof GitLabApiError) || ![401, 403, 404].includes(error.status ?? 0)) throw error;\n // This credential cannot access the project; try another active account for the same canonical source.\n }\n }\n throw new GitLabApiError('No active GitLab connection can access this source.', 404);\n }\n\n async #resolveSourceReference(\n reference: GitLabSourceReference,\n ): Promise<{ context: GitLabConnectionContext; source: ResolvedGitLabSourceReference }> {\n const context = await this.#contextForReference(reference);\n const projectPath =\n reference.projectPath ?? (await context.api.getProject(reference.projectId)).path_with_namespace;\n return {\n context,\n source: {\n connectionId: context.id,\n host: normalizeGitLabHost(reference.host ?? context.host),\n projectId: reference.projectId,\n projectPath,\n },\n };\n }\n\n async #resolveIntakeDispatch({ externalSource }: ResolveIntakeDispatchInput): Promise<ResolvedIntakeDispatch | null> {\n if (externalSource.type !== 'issue') return null;\n const reference = decodeIssueReference(externalSource.externalId);\n if (!reference) return null;\n const { context, source } = await this.#resolveSourceReference(reference);\n return {\n connection: context.connection,\n sourceId: encodeSourceId(source),\n issueId: String(reference.issueIid),\n };\n }\n\n async #listSources(): Promise<IntakeSource[]> {\n const sources = new Map<string, IntakeSource>();\n for (const context of await this.activeContexts()) {\n for (let page = 1; ; page++) {\n const projects = await context.api.listProjects({ page });\n for (const project of projects) {\n const source = this.#toIntakeSource(context, project);\n if (!sources.has(source.id)) sources.set(source.id, source);\n }\n if (projects.length < GITLAB_PROJECTS_PAGE_SIZE) break;\n }\n }\n return [...sources.values()];\n }\n\n async #listItems(input: ListIntakeItemsInput): Promise<IntakeItemPage> {\n const result = await this.#listIssuePage(input.sourceIds, input.cursor);\n return {\n items: result.issues.map(({ issue, source, context }) => ({\n source: {\n type: 'issue',\n externalId: encodeIssueReference({ ...source, issueIid: issue.iid }),\n url: issue.web_url,\n },\n sourceId: encodeSourceId(source),\n title: `${source.projectPath}#${issue.iid}: ${issue.title}`,\n status: issue.state,\n labels: issue.labels ?? [],\n assignee: displayName(issue.assignee),\n createdAt: issue.created_at,\n updatedAt: issue.updated_at,\n metadata: {\n identifier: `${source.projectPath}#${issue.iid}`,\n projectId: source.projectId,\n projectPath: source.projectPath,\n connectionId: context.id,\n accountLabel: context.label,\n labelColors: Object.fromEntries((issue.labelDetails ?? []).map(label => [label.name, label.color])),\n },\n })),\n nextCursor: result.nextCursor,\n };\n }\n\n async #listIssues(input: ListIntakeIssuesInput) {\n const result = await this.#listIssuePage(input.sourceIds, input.cursor, input.labels);\n return {\n issues: result.issues.map(({ issue, source }) => ({\n ...this.#toIntakeIssue(issue, source.projectPath),\n sourceId: encodeSourceId(source),\n })),\n nextCursor: result.nextCursor,\n };\n }\n\n async #listIssuePage(sourceIds: string[], cursor?: string, labels?: string[]) {\n const sources = sourceIds.map(decodeSourceId).filter((source): source is GitLabSourceReference => source !== null);\n if (sources.length === 0) return { issues: [], nextCursor: null };\n const current = decodePageCursor(cursor);\n if (!current || current.source >= sources.length) return { issues: [], nextCursor: null };\n\n for (let sourceIndex = current.source; sourceIndex < sources.length; sourceIndex++) {\n const { source, context } = await this.#resolveSourceReference(sources[sourceIndex]!);\n const page = sourceIndex === current.source ? current.page : 1;\n const issues = await context.api.listIssues(source.projectId, { page, labels });\n const nextCursor =\n issues.length === GITLAB_ISSUES_PAGE_SIZE\n ? encodePageCursor({ source: sourceIndex, page: page + 1 })\n : sourceIndex + 1 < sources.length\n ? encodePageCursor({ source: sourceIndex + 1, page: 1 })\n : null;\n return { issues: issues.map(issue => ({ issue, source, context })), nextCursor };\n }\n return { issues: [], nextCursor: null };\n }\n\n async #getIssue(input: GetIntakeIssueInput): Promise<IntakeIssueDetail | null> {\n const resolved = await this.#resolveRequest(input);\n let issue: GitLabIssue;\n try {\n issue = await resolved.context.api.getIssue(resolved.projectId, resolved.issueIid);\n } catch (error) {\n if (error instanceof GitLabApiError && error.status === 404) return null;\n throw error;\n }\n const notes = await this.#listAllNotes(resolved.context.api, resolved.projectId, resolved.issueIid);\n return {\n ...this.#toIntakeIssue(issue, resolved.projectPath),\n description: issue.description?.trim() || null,\n comments: notes\n .filter(note => !note.system)\n .map(note => ({ author: displayName(note.author), body: note.body, createdAt: note.created_at })),\n };\n }\n\n async #listAllNotes(api: GitLabApiClient, projectId: string, issueIid: number): Promise<GitLabNote[]> {\n const notes: GitLabNote[] = [];\n for (let page = 1; page <= MAX_NOTES_PAGES; page++) {\n const result = await api.listNotes(projectId, issueIid, { page });\n notes.push(...result);\n if (result.length < GITLAB_NOTES_PAGE_SIZE) break;\n }\n return notes;\n }\n\n async #createComment(input: CreateIntakeCommentInput): Promise<CreatedIntakeComment | null> {\n const resolved = await this.#resolveRequest(input);\n try {\n const issue = await resolved.context.api.getIssue(resolved.projectId, resolved.issueIid);\n const note = await resolved.context.api.createNote(resolved.projectId, resolved.issueIid, input.body);\n return { id: String(note.id), url: `${issue.web_url}#note_${note.id}` };\n } catch (error) {\n if (error instanceof GitLabApiError && error.status === 404) return null;\n throw error;\n }\n }\n\n async #updateIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n const resolved = await this.#resolveRequest(input);\n let issue: GitLabIssue;\n try {\n issue = await resolved.context.api.getIssue(resolved.projectId, resolved.issueIid);\n } catch (error) {\n if (error instanceof GitLabApiError && error.status === 404) return null;\n throw error;\n }\n const stateEvent = targetStateEvent(input);\n if (!stateEvent) return null;\n if ((stateEvent === 'close' && issue.state === 'closed') || (stateEvent === 'reopen' && issue.state === 'opened')) {\n return this.#toIntakeIssue(issue, resolved.projectPath);\n }\n const updated = await resolved.context.api.updateIssueState(resolved.projectId, resolved.issueIid, stateEvent);\n return this.#toIntakeIssue(updated, resolved.projectPath);\n }\n\n async #resolveRequest(input: GetIntakeIssueInput): Promise<{\n context: GitLabConnectionContext;\n projectId: string;\n projectPath: string;\n issueIid: number;\n }> {\n const issueReference = decodeIssueReference(input.issueId);\n const source = input.sourceId ? decodeSourceId(input.sourceId) : null;\n const locator = parseIssueLocator(input.issueId);\n const reference = issueReference ?? source;\n let context: GitLabConnectionContext;\n if (reference) {\n context = await this.#contextForReference(reference);\n } else {\n const connectionId = connectionIdFromConnection(input.connection);\n const contexts = connectionId ? [await this.contextById(connectionId)] : await this.activeContexts();\n if (contexts.length !== 1) {\n throw new GitLabApiError('GitLab issue reference must resolve to exactly one active connection.', 400);\n }\n context = contexts[0]!;\n }\n const projectId = issueReference?.projectId ?? source?.projectId ?? locator?.projectPath;\n const issueIid = issueReference?.issueIid ?? locator?.issueIid ?? parsePositiveInteger(input.issueId);\n if (!projectId || !issueIid) {\n throw new GitLabApiError(\n 'GitLab issue must include a project and issue IID (for example, group/project#42).',\n 400,\n );\n }\n const projectPath =\n issueReference?.projectPath ??\n source?.projectPath ??\n locator?.projectPath ??\n (await context.api.getProject(projectId)).path_with_namespace;\n return { context, projectId, projectPath, issueIid };\n }\n\n #toIntakeSource(context: GitLabConnectionContext, project: GitLabProject): IntakeSource {\n const reference: GitLabSourceReference = {\n host: normalizeGitLabHost(context.host),\n projectId: String(project.id),\n projectPath: project.path_with_namespace,\n };\n return {\n id: encodeSourceId(reference),\n name: project.path_with_namespace,\n type: 'project',\n metadata: {\n projectId: String(project.id),\n projectPath: project.path_with_namespace,\n defaultBranch: project.default_branch ?? null,\n connectionId: context.id,\n accountLabel: context.label,\n url: project.web_url,\n },\n };\n }\n\n #toIntakeIssue(issue: GitLabIssue, projectPath: string): IntakeIssue {\n const assignees = issue.assignees?.map(displayName).filter((name): name is string => name !== null) ?? [];\n return {\n id: String(issue.iid),\n identifier: `${projectPath}#${issue.iid}`,\n title: issue.title,\n url: issue.web_url,\n author: displayName(issue.author),\n authorUsername: issue.author?.username ?? null,\n state: issue.state,\n stateType: issue.state === 'closed' ? 'completed' : 'unstarted',\n priority: typeof issue.weight === 'number' ? String(issue.weight) : null,\n assignee: displayName(issue.assignee) ?? assignees[0] ?? null,\n assignees,\n source: projectPath,\n labels: issue.labels ?? [],\n labelColors: Object.fromEntries((issue.labelDetails ?? []).map(label => [label.name, label.color])),\n commentCount: issue.user_notes_count ?? null,\n createdAt: issue.created_at,\n updatedAt: issue.updated_at,\n };\n }\n}\n\nexport type GitLabAccessTokenType = 'personal' | 'group';\n\nexport interface GitLabIntegrationConfig {\n rules?: GitLabRuleOverrides;\n accessToken?: string;\n /** Defaults to `personal`; both token types authenticate identically but have different resource reach. */\n accessTokenType?: GitLabAccessTokenType;\n baseUrl?: string;\n webhookSecret?: string;\n fetchImpl?: typeof fetch;\n}\n\nconst DIRECT_CONNECTION_TOKEN = 'gitlab-direct-access-token';\n\nexport class GitLabIntegration extends GitLabIntegrationBase {\n readonly #accessToken: string;\n readonly #accessTokenType: GitLabAccessTokenType;\n readonly #baseUrl: string;\n readonly #webhookSecret: string | undefined;\n readonly #context: GitLabConnectionContext;\n\n constructor(config: GitLabIntegrationConfig = {}) {\n super(config.rules);\n const accessToken = config.accessToken?.trim() || process.env.GITLAB_ACCESS_TOKEN?.trim();\n if (!accessToken) {\n throw new Error('GitLabIntegration: missing required GITLAB_ACCESS_TOKEN.');\n }\n this.#accessToken = accessToken;\n this.#accessTokenType = parseAccessTokenType(\n config.accessTokenType ?? process.env.GITLAB_ACCESS_TOKEN_TYPE?.trim(),\n );\n this.#baseUrl = (config.baseUrl ?? process.env.GITLAB_BASE_URL?.trim() ?? 'https://gitlab.com').replace(/\\/+$/, '');\n this.#webhookSecret = config.webhookSecret?.trim() || process.env.GITLAB_WEBHOOK_SECRET?.trim() || undefined;\n const api = new GitLabApiClient({\n baseUrl: this.#baseUrl,\n accessToken: this.#accessToken,\n ...(config.fetchImpl ? { fetchImpl: config.fetchImpl } : {}),\n });\n this.#context = {\n id: DIRECT_CONNECTION_ID,\n label: new URL(this.#baseUrl).host,\n api,\n connection: { type: 'oauth', accessToken: DIRECT_CONNECTION_TOKEN },\n host: new URL(this.#baseUrl).host,\n webBaseUrl: this.#baseUrl,\n repositoryAccessToken: async () => this.#accessToken,\n };\n }\n\n protected override get webhookSecret(): string | undefined {\n return this.#webhookSecret;\n }\n\n async hasActiveConnections(): Promise<boolean> {\n return true;\n }\n\n override async verifyStatus(): Promise<void> {\n await this.#context.api.getCurrentUser();\n }\n\n authFailureMessage(): string {\n return `GitLab rejected the configured ${this.#accessTokenType} access token. Check the token and its scopes.`;\n }\n\n protected async activeContexts(): Promise<GitLabConnectionContext[]> {\n return [this.#context];\n }\n\n protected async contextById(connectionId: string): Promise<GitLabConnectionContext> {\n if (connectionId !== DIRECT_CONNECTION_ID) {\n throw new GitLabApiError('GitLab connection is unavailable.', 401);\n }\n return this.#context;\n }\n\n diagnostics(): Record<string, unknown> {\n return {\n configured: true,\n mode: 'direct',\n accessTokenType: this.#accessTokenType,\n endpointHost: new URL(this.#baseUrl).host,\n webhookConfigured: Boolean(this.#webhookSecret),\n };\n }\n}\n\nfunction parseAccessTokenType(value: string | undefined): GitLabAccessTokenType {\n const normalized = value?.trim().toLowerCase() || 'personal';\n if (normalized === 'personal' || normalized === 'group') return normalized;\n throw new Error(\"GitLabIntegration: GITLAB_ACCESS_TOKEN_TYPE must be 'personal' or 'group'.\");\n}\n\nexport function encodeSourceId(reference: GitLabSourceReference): string {\n if (reference.host) {\n return `${GITLAB_SOURCE_PREFIX}${encodeOpaque({\n version: 2,\n host: normalizeGitLabHost(reference.host),\n projectId: reference.projectId,\n })}`;\n }\n if (!reference.connectionId || !reference.projectPath) {\n throw new Error('GitLab source reference is missing its instance host.');\n }\n return `${GITLAB_SOURCE_PREFIX}${encodeOpaque(reference)}`;\n}\n\nexport function decodeSourceId(value: string): GitLabSourceReference | null {\n return decodeOpaque(value, GITLAB_SOURCE_PREFIX, isSourceReference);\n}\n\nexport function encodeIssueReference(reference: GitLabIssueReference): string {\n if (reference.host) {\n return `${GITLAB_ISSUE_PREFIX}${encodeOpaque({\n version: 2,\n host: normalizeGitLabHost(reference.host),\n projectId: reference.projectId,\n issueIid: reference.issueIid,\n })}`;\n }\n if (!reference.connectionId || !reference.projectPath) {\n throw new Error('GitLab issue reference is missing its instance host.');\n }\n return `${GITLAB_ISSUE_PREFIX}${encodeOpaque(reference)}`;\n}\n\nexport function decodeIssueReference(value: string): GitLabIssueReference | null {\n return decodeOpaque(value, GITLAB_ISSUE_PREFIX, isIssueReference);\n}\n\nexport function decodeMergeRequestReference(value: string): GitLabMergeRequestReference | null {\n return decodeOpaque(value, GITLAB_MERGE_REQUEST_PREFIX, isMergeRequestReference);\n}\n\nexport function gitlabConnection(connectionId: string): IntegrationConnection {\n return { type: 'oauth', accessToken: `${GITLAB_CONNECTION_TOKEN_PREFIX}${connectionId}` };\n}\n\nfunction connectionIdFromConnection(connection: IntegrationConnection): string | null {\n if (connection.type !== 'oauth' || !connection.accessToken.startsWith(GITLAB_CONNECTION_TOKEN_PREFIX)) return null;\n return connection.accessToken.slice(GITLAB_CONNECTION_TOKEN_PREFIX.length) || null;\n}\n\nfunction encodeOpaque(value: unknown): string {\n return Buffer.from(JSON.stringify(value)).toString('base64url');\n}\n\nfunction decodeOpaque<T>(value: string, prefix: string, guard: (value: unknown) => value is T): T | null {\n if (!value.startsWith(prefix)) return null;\n try {\n const decoded = JSON.parse(Buffer.from(value.slice(prefix.length), 'base64url').toString('utf8')) as unknown;\n return guard(decoded) ? decoded : null;\n } catch {\n return null;\n }\n}\n\nexport function normalizeGitLabHost(host: string): string {\n return host.trim().toLowerCase().replace(/\\.$/, '');\n}\n\nfunction isSourceReference(value: unknown): value is GitLabSourceReference {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const ref = value as Record<string, unknown>;\n if (typeof ref.projectId !== 'string' || ref.projectId.length === 0) return false;\n const canonical = ref.version === 2 && typeof ref.host === 'string' && normalizeGitLabHost(ref.host).length > 0;\n const legacy =\n typeof ref.connectionId === 'string' &&\n ref.connectionId.length > 0 &&\n typeof ref.projectPath === 'string' &&\n ref.projectPath.length > 0;\n return canonical || legacy;\n}\n\nfunction isIssueReference(value: unknown): value is GitLabIssueReference {\n return (\n isSourceReference(value) &&\n Number.isSafeInteger((value as GitLabIssueReference).issueIid) &&\n (value as GitLabIssueReference).issueIid > 0\n );\n}\n\nfunction isMergeRequestReference(value: unknown): value is GitLabMergeRequestReference {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return false;\n const ref = value as Record<string, unknown>;\n return (\n ref.version === 1 &&\n typeof ref.host === 'string' &&\n normalizeGitLabHost(ref.host).length > 0 &&\n Number.isSafeInteger(ref.projectId) &&\n (ref.projectId as number) > 0 &&\n Number.isSafeInteger(ref.mergeRequestIid) &&\n (ref.mergeRequestIid as number) > 0\n );\n}\n\nfunction encodePageCursor(cursor: GitLabPageCursor): string {\n return encodeOpaque(cursor);\n}\n\nfunction decodePageCursor(value: string | undefined): GitLabPageCursor | null {\n if (!value) return { source: 0, page: 1 };\n try {\n const decoded = JSON.parse(Buffer.from(value, 'base64url').toString('utf8')) as Record<string, unknown>;\n if (!Number.isSafeInteger(decoded.source) || Number(decoded.source) < 0) return null;\n if (!Number.isSafeInteger(decoded.page) || Number(decoded.page) < 1) return null;\n return { source: Number(decoded.source), page: Number(decoded.page) };\n } catch {\n return null;\n }\n}\n\nfunction displayName(user: { name?: string | null; username: string } | null | undefined): string | null {\n return user?.name?.trim() || user?.username || null;\n}\n\nfunction parsePositiveInteger(value: string): number | null {\n if (!/^\\d+$/.test(value)) return null;\n const parsed = Number(value);\n return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;\n}\n\nfunction parseIssueLocator(value: string): {\n host?: string;\n projectPath: string;\n issueIid: number;\n} | null {\n const shorthand = value.match(/^(.+?)#(\\d+)$/);\n if (shorthand) {\n const issueIid = parsePositiveInteger(shorthand[2]!);\n const projectPath = shorthand[1]!.replace(/^\\/+|\\/+$/g, '');\n return issueIid && projectPath ? { projectPath, issueIid } : null;\n }\n try {\n const url = new URL(value);\n const match = url.pathname.match(/^\\/(.+)\\/-\\/issues\\/(\\d+)\\/?$/);\n if (!match) return null;\n const issueIid = parsePositiveInteger(match[2]!);\n if (!issueIid) return null;\n const projectPath = decodeURIComponent(match[1]!);\n return { host: url.host, projectPath, issueIid };\n } catch {\n return null;\n }\n}\n\nfunction targetStateEvent(input: UpdateIntakeIssueInput): 'close' | 'reopen' | null {\n if (input.state.kind === 'byType') {\n // GitLab issues have only opened/closed states, so canceled is intentionally mapped to close.\n return input.state.stateType === 'completed' || input.state.stateType === 'canceled' ? 'close' : 'reopen';\n }\n const name = input.state.name.trim().toLowerCase();\n if (name === 'closed' || name === 'close') return 'close';\n if (name === 'opened' || name === 'open' || name === 'reopen') return 'reopen';\n return null;\n}\n"],"mappings":";;;;;;;;;;;AAmGA,MAAM,uBAAuB;AAC7B,MAAM,iCAAiC;AACvC,MAAM,uBAAuB;AAC7B,MAAM,sBAAsB;AAC5B,MAAM,8BAA8B;AACpC,MAAa,8BAA8B;AAE3C,MAAM,kBAAkB;AACxB,MAAM,eAAe;AAErB,IAAsB,wBAAtB,MAA0E;CACxE,KAAc;CACd;CACA;CACA;CACA;CACA;CACA,qCAA8B,IAAI,IAA2B;CAC7D;CAEA,YAAY,OAA6B;EACvC,KAAK,QAAQ,mBAAmB,KAAK;CACvC;CAEA,SAA0B;EACxB,wBAAuB,UAAS,KAAK,uBAAuB,KAAK;EACjE,mBAAmB,KAAK,aAAa;EACrC,YAAW,UAAS,KAAK,WAAW,KAAK;EACzC,aAAY,UAAS,KAAK,YAAY,KAAK;EAC3C,WAAU,UAAS,KAAK,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AC;AAI9D,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;AA+EpD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,IAAI,CACV,qBAAqB,EACrB,QAAQ,GAAG,OAAO,GAAG,6BAA6B,GAAG,2BAA2B,GAAG,iCAAiC,CACrH,EACD,OAAO,EAAE,kBAAkB,GAC1B,qBAAqB,GAAG,SAAS,CAkDnC"}
1
+ {"version":3,"file":"issue-reconciler.d.ts","sourceRoot":"","sources":["../../../src/integrations/gitlab/issue-reconciler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAI9D,MAAM,MAAM,qBAAqB,GAAG,eAAe,CAAC;AA+EpD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,IAAI,CACV,qBAAqB,EACrB,QAAQ,GAAG,OAAO,GAAG,6BAA6B,GAAG,2BAA2B,GAAG,iCAAiC,CACrH,EACD,OAAO,EAAE,kBAAkB,GAC1B,qBAAqB,GAAG,SAAS,CAmDnC"}
@@ -100,6 +100,7 @@ function attachGitLabIssueReconciler(gitlab, context) {
100
100
  intake: gitlab.intake,
101
101
  projects: context.storage.projects,
102
102
  storage: context.runtime.workItems,
103
+ ...context.runtime.keptCards ? { cards: context.runtime.keptCards } : {},
103
104
  isTerminal: (item) => workItemPhaseSemantics(toBoardSource(boards).forProject(item), item)?.kind === "terminal",
104
105
  issueId: (item) => {
105
106
  const issueIid = identityForItem(item)?.issueIid;