@mastra/factory 0.24.0-alpha.9 → 0.25.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (377) hide show
  1. package/README.md +40 -13
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +18 -4
  4. package/dist/auth.js.map +1 -1
  5. package/dist/boards/review.d.ts.map +1 -1
  6. package/dist/boards/review.js +3 -2
  7. package/dist/boards/review.js.map +1 -1
  8. package/dist/environment/build-runner.js +2 -1
  9. package/dist/environment/build-runner.js.map +1 -1
  10. package/dist/environment/build-workflow.js +1 -1
  11. package/dist/environment/build-workflow.js.map +1 -1
  12. package/dist/environment/build.js +16 -14
  13. package/dist/environment/build.js.map +1 -1
  14. package/dist/factory.d.ts +3 -0
  15. package/dist/factory.d.ts.map +1 -1
  16. package/dist/factory.js +172 -88
  17. package/dist/factory.js.map +1 -1
  18. package/dist/integrations/base.d.ts +15 -2
  19. package/dist/integrations/base.d.ts.map +1 -1
  20. package/dist/integrations/github/app-identity.js.map +1 -1
  21. package/dist/integrations/github/integration.js +1 -1
  22. package/dist/integrations/github/integration.js.map +1 -1
  23. package/dist/integrations/github/reconcile-worker.js +1 -1
  24. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  25. package/dist/integrations/github/routes.d.ts +1 -1
  26. package/dist/integrations/github/routes.d.ts.map +1 -1
  27. package/dist/integrations/github/routes.js +24 -13
  28. package/dist/integrations/github/routes.js.map +1 -1
  29. package/dist/integrations/github/rules.d.ts.map +1 -1
  30. package/dist/integrations/github/rules.js +53 -9
  31. package/dist/integrations/github/rules.js.map +1 -1
  32. package/dist/integrations/github/sandbox.js +2 -2
  33. package/dist/integrations/github/sandbox.js.map +1 -1
  34. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
  35. package/dist/integrations/github/session-subscriptions.js +1 -2
  36. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  37. package/dist/integrations/github/subscriptions.d.ts +7 -4
  38. package/dist/integrations/github/subscriptions.d.ts.map +1 -1
  39. package/dist/integrations/github/subscriptions.js +5 -5
  40. package/dist/integrations/github/subscriptions.js.map +1 -1
  41. package/dist/integrations/gitlab/api.js.map +1 -1
  42. package/dist/integrations/gitlab/integration.js.map +1 -1
  43. package/dist/integrations/gitlab/reconciliation-config.js +2 -1
  44. package/dist/integrations/gitlab/reconciliation-config.js.map +1 -1
  45. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  46. package/dist/integrations/gitlab/routes.js +10 -6
  47. package/dist/integrations/gitlab/routes.js.map +1 -1
  48. package/dist/integrations/gitlab/rules.js.map +1 -1
  49. package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -1
  50. package/dist/integrations/gitlab/session-subscriptions.js +1 -2
  51. package/dist/integrations/gitlab/session-subscriptions.js.map +1 -1
  52. package/dist/integrations/gitlab/subscriptions.d.ts +7 -4
  53. package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -1
  54. package/dist/integrations/gitlab/subscriptions.js +5 -5
  55. package/dist/integrations/gitlab/subscriptions.js.map +1 -1
  56. package/dist/integrations/incidentio/api.js.map +1 -1
  57. package/dist/integrations/incidentio/integration.js.map +1 -1
  58. package/dist/integrations/incidentio/rules.js.map +1 -1
  59. package/dist/integrations/issue-reconcile-worker.js +1 -1
  60. package/dist/integrations/issue-reconcile-worker.js.map +1 -1
  61. package/dist/integrations/issue-reconciler.js +1 -1
  62. package/dist/integrations/issue-reconciler.js.map +1 -1
  63. package/dist/integrations/jira/api.js.map +1 -1
  64. package/dist/integrations/jira/integration.js.map +1 -1
  65. package/dist/integrations/jira/rules.js.map +1 -1
  66. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  67. package/dist/integrations/linear/agent-tools.js.map +1 -1
  68. package/dist/integrations/linear/integration.js.map +1 -1
  69. package/dist/integrations/linear/rules.js.map +1 -1
  70. package/dist/integrations/platform/api-client.js.map +1 -1
  71. package/dist/integrations/platform/github/event-worker.js +1 -1
  72. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  73. package/dist/integrations/platform/github/integration.js +2 -2
  74. package/dist/integrations/platform/github/integration.js.map +1 -1
  75. package/dist/integrations/platform/gitlab/event-worker.js.map +1 -1
  76. package/dist/integrations/platform/gitlab/integration.js.map +1 -1
  77. package/dist/integrations/platform/incidentio/integration.js +2 -1
  78. package/dist/integrations/platform/incidentio/integration.js.map +1 -1
  79. package/dist/integrations/platform/jira/integration.js.map +1 -1
  80. package/dist/integrations/platform/linear/event-worker.js +1 -1
  81. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  82. package/dist/integrations/platform/linear/integration.js.map +1 -1
  83. package/dist/{session → integrations/slack}/channel-reply-processor.d.ts +11 -9
  84. package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -0
  85. package/dist/integrations/slack/channel-reply-processor.js +61 -0
  86. package/dist/integrations/slack/channel-reply-processor.js.map +1 -0
  87. package/dist/integrations/slack/channel-session-link-processor.d.ts.map +1 -0
  88. package/dist/{session → integrations/slack}/channel-session-link-processor.js +14 -4
  89. package/dist/integrations/slack/channel-session-link-processor.js.map +1 -0
  90. package/dist/integrations/slack/connect-route.js +1 -1
  91. package/dist/integrations/slack/connect-route.js.map +1 -1
  92. package/dist/integrations/slack/feed-publisher.js +1 -1
  93. package/dist/integrations/slack/feed-publisher.js.map +1 -1
  94. package/dist/integrations/slack/integration.d.ts +25 -1
  95. package/dist/integrations/slack/integration.d.ts.map +1 -1
  96. package/dist/integrations/slack/integration.js +56 -6
  97. package/dist/integrations/slack/integration.js.map +1 -1
  98. package/dist/integrations/slack/reply-reminder-processor.d.ts +23 -0
  99. package/dist/integrations/slack/reply-reminder-processor.d.ts.map +1 -0
  100. package/dist/integrations/slack/reply-reminder-processor.js +58 -0
  101. package/dist/integrations/slack/reply-reminder-processor.js.map +1 -0
  102. package/dist/integrations/slack/reply-tool.d.ts +31 -0
  103. package/dist/integrations/slack/reply-tool.d.ts.map +1 -0
  104. package/dist/integrations/slack/reply-tool.js +203 -0
  105. package/dist/integrations/slack/reply-tool.js.map +1 -0
  106. package/dist/integrations/slack/share-file-tool.d.ts +45 -0
  107. package/dist/integrations/slack/share-file-tool.d.ts.map +1 -0
  108. package/dist/integrations/slack/share-file-tool.js +106 -0
  109. package/dist/integrations/slack/share-file-tool.js.map +1 -0
  110. package/dist/integrations/slack/slack.d.ts +16 -5
  111. package/dist/integrations/slack/slack.d.ts.map +1 -1
  112. package/dist/integrations/slack/slack.js +141 -40
  113. package/dist/integrations/slack/slack.js.map +1 -1
  114. package/dist/integrations/subscription-session.d.ts +0 -1
  115. package/dist/integrations/subscription-session.d.ts.map +1 -1
  116. package/dist/integrations/subscription-session.js +1 -4
  117. package/dist/integrations/subscription-session.js.map +1 -1
  118. package/dist/integrations/workos/integration.js.map +1 -1
  119. package/dist/mcp/events.d.ts +73 -0
  120. package/dist/mcp/events.d.ts.map +1 -0
  121. package/dist/mcp/events.js +158 -0
  122. package/dist/mcp/events.js.map +1 -0
  123. package/dist/mcp/routes.d.ts +0 -1
  124. package/dist/mcp/routes.d.ts.map +1 -1
  125. package/dist/mcp/routes.js +31 -4
  126. package/dist/mcp/routes.js.map +1 -1
  127. package/dist/packages/_internals/workspace/dist/index.js +18 -1
  128. package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
  129. package/dist/platform-auth-host.d.ts.map +1 -1
  130. package/dist/platform-auth-host.js +1 -1
  131. package/dist/platform-auth-host.js.map +1 -1
  132. package/dist/routes/attention-activity.js.map +1 -1
  133. package/dist/routes/attention-parked.js.map +1 -1
  134. package/dist/routes/attention-providers.js.map +1 -1
  135. package/dist/routes/automation-runs.js.map +1 -1
  136. package/dist/routes/config.d.ts +8 -7
  137. package/dist/routes/config.d.ts.map +1 -1
  138. package/dist/routes/config.js +70 -28
  139. package/dist/routes/config.js.map +1 -1
  140. package/dist/routes/contracts.d.ts +2 -0
  141. package/dist/routes/contracts.d.ts.map +1 -1
  142. package/dist/routes/contracts.js +2 -2
  143. package/dist/routes/contracts.js.map +1 -1
  144. package/dist/routes/custom-provider-source.js.map +1 -1
  145. package/dist/routes/fs.d.ts +31 -23
  146. package/dist/routes/fs.d.ts.map +1 -1
  147. package/dist/routes/fs.js +218 -64
  148. package/dist/routes/fs.js.map +1 -1
  149. package/dist/routes/intake.js +2 -1
  150. package/dist/routes/intake.js.map +1 -1
  151. package/dist/routes/knowledge.js +1 -1
  152. package/dist/routes/knowledge.js.map +1 -1
  153. package/dist/routes/oauth.js +3 -2
  154. package/dist/routes/oauth.js.map +1 -1
  155. package/dist/routes/projects.d.ts +1 -1
  156. package/dist/routes/projects.d.ts.map +1 -1
  157. package/dist/routes/projects.js +33 -31
  158. package/dist/routes/projects.js.map +1 -1
  159. package/dist/routes/provider-credentials.d.ts.map +1 -1
  160. package/dist/routes/provider-credentials.js +6 -1
  161. package/dist/routes/provider-credentials.js.map +1 -1
  162. package/dist/routes/session-access.d.ts +60 -0
  163. package/dist/routes/session-access.d.ts.map +1 -0
  164. package/dist/routes/session-access.js +202 -0
  165. package/dist/routes/session-access.js.map +1 -0
  166. package/dist/routes/skills.d.ts +2 -4
  167. package/dist/routes/skills.d.ts.map +1 -1
  168. package/dist/routes/skills.js +23 -68
  169. package/dist/routes/skills.js.map +1 -1
  170. package/dist/routes/source-control-sessions.d.ts +8 -1
  171. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  172. package/dist/routes/source-control-sessions.js +239 -19
  173. package/dist/routes/source-control-sessions.js.map +1 -1
  174. package/dist/routes/surface.d.ts +7 -0
  175. package/dist/routes/surface.d.ts.map +1 -1
  176. package/dist/routes/surface.js +20 -8
  177. package/dist/routes/surface.js.map +1 -1
  178. package/dist/routes/tenant-credentials.js.map +1 -1
  179. package/dist/routes/work-items.js.map +1 -1
  180. package/dist/rules/binding-context.js +11 -9
  181. package/dist/rules/binding-context.js.map +1 -1
  182. package/dist/rules/dispatcher.d.ts +1 -1
  183. package/dist/rules/dispatcher.d.ts.map +1 -1
  184. package/dist/rules/dispatcher.js +21 -13
  185. package/dist/rules/dispatcher.js.map +1 -1
  186. package/dist/rules/processor.d.ts +2 -2
  187. package/dist/rules/processor.d.ts.map +1 -1
  188. package/dist/rules/processor.js +3 -3
  189. package/dist/rules/processor.js.map +1 -1
  190. package/dist/rules/start-coordinator.d.ts +4 -0
  191. package/dist/rules/start-coordinator.d.ts.map +1 -1
  192. package/dist/rules/start-coordinator.js +36 -4
  193. package/dist/rules/start-coordinator.js.map +1 -1
  194. package/dist/rules/tools.js +2 -2
  195. package/dist/rules/tools.js.map +1 -1
  196. package/dist/rules/transition-service.js.map +1 -1
  197. package/dist/sandbox/callback-factory-sandbox.js.map +1 -1
  198. package/dist/sandbox/local-factory-sandbox.js.map +1 -1
  199. package/dist/sandbox/session-retirement.d.ts +11 -0
  200. package/dist/sandbox/session-retirement.d.ts.map +1 -1
  201. package/dist/sandbox/session-retirement.js +38 -1
  202. package/dist/sandbox/session-retirement.js.map +1 -1
  203. package/dist/sandbox/session-sandbox.d.ts +2 -0
  204. package/dist/sandbox/session-sandbox.d.ts.map +1 -1
  205. package/dist/sandbox/session-sandbox.js +5 -1
  206. package/dist/sandbox/session-sandbox.js.map +1 -1
  207. package/dist/secret-encryption.d.ts.map +1 -1
  208. package/dist/secret-encryption.js +65 -25
  209. package/dist/secret-encryption.js.map +1 -1
  210. package/dist/session/credential-policy.d.ts +4 -2
  211. package/dist/session/credential-policy.d.ts.map +1 -1
  212. package/dist/session/credential-policy.js +18 -7
  213. package/dist/session/credential-policy.js.map +1 -1
  214. package/dist/session/default-model-hydration.d.ts +1 -0
  215. package/dist/session/default-model-hydration.d.ts.map +1 -1
  216. package/dist/session/default-model-hydration.js +3 -2
  217. package/dist/session/default-model-hydration.js.map +1 -1
  218. package/dist/session/environment-state-processor.js +1 -1
  219. package/dist/session/environment-state-processor.js.map +1 -1
  220. package/dist/session/factory-session.d.ts.map +1 -1
  221. package/dist/session/factory-session.js +14 -1
  222. package/dist/session/factory-session.js.map +1 -1
  223. package/dist/session/filesystem-capture.d.ts +3 -3
  224. package/dist/session/filesystem-capture.d.ts.map +1 -1
  225. package/dist/session/filesystem-capture.js +16 -17
  226. package/dist/session/filesystem-capture.js.map +1 -1
  227. package/dist/session/first-exec-capture.d.ts +1 -1
  228. package/dist/session/first-exec-capture.d.ts.map +1 -1
  229. package/dist/session/first-exec-capture.js +1 -1
  230. package/dist/session/first-exec-capture.js.map +1 -1
  231. package/dist/session/first-message-capture.d.ts +1 -1
  232. package/dist/session/first-message-capture.d.ts.map +1 -1
  233. package/dist/session/first-message-capture.js +1 -1
  234. package/dist/session/first-message-capture.js.map +1 -1
  235. package/dist/session/live-sessions.d.ts +1 -1
  236. package/dist/session/live-sessions.js +1 -1
  237. package/dist/session/live-sessions.js.map +1 -1
  238. package/dist/session/memory-settings-hydration.d.ts +1 -1
  239. package/dist/session/memory-settings-hydration.d.ts.map +1 -1
  240. package/dist/session/memory-settings-hydration.js +2 -1
  241. package/dist/session/memory-settings-hydration.js.map +1 -1
  242. package/dist/session/resource-migration.d.ts +105 -0
  243. package/dist/session/resource-migration.d.ts.map +1 -0
  244. package/dist/session/resource-migration.js +195 -0
  245. package/dist/session/resource-migration.js.map +1 -0
  246. package/dist/session/run-audit.d.ts +1 -0
  247. package/dist/session/run-audit.d.ts.map +1 -1
  248. package/dist/session/run-audit.js +7 -2
  249. package/dist/session/run-audit.js.map +1 -1
  250. package/dist/session/session-threads.d.ts +63 -0
  251. package/dist/session/session-threads.d.ts.map +1 -0
  252. package/dist/session/session-threads.js +97 -0
  253. package/dist/session/session-threads.js.map +1 -0
  254. package/dist/session/source-control-tools.js +8 -8
  255. package/dist/session/source-control-tools.js.map +1 -1
  256. package/dist/session/thinking-default.d.ts +6 -13
  257. package/dist/session/thinking-default.d.ts.map +1 -1
  258. package/dist/session/thinking-default.js +19 -24
  259. package/dist/session/thinking-default.js.map +1 -1
  260. package/dist/session/thread-session-stamp.d.ts +21 -0
  261. package/dist/session/thread-session-stamp.d.ts.map +1 -0
  262. package/dist/session/thread-session-stamp.js +20 -0
  263. package/dist/session/thread-session-stamp.js.map +1 -0
  264. package/dist/session/thread-title-mirror.d.ts +1 -1
  265. package/dist/session/thread-title-mirror.d.ts.map +1 -1
  266. package/dist/session/thread-title-mirror.js +1 -1
  267. package/dist/session/thread-title-mirror.js.map +1 -1
  268. package/dist/session-owner-signal.d.ts +2 -0
  269. package/dist/session-owner-signal.d.ts.map +1 -0
  270. package/dist/session-owner-signal.js +6 -0
  271. package/dist/session-owner-signal.js.map +1 -0
  272. package/dist/skills/service.d.ts +11 -14
  273. package/dist/skills/service.d.ts.map +1 -1
  274. package/dist/skills/service.js +12 -22
  275. package/dist/skills/service.js.map +1 -1
  276. package/dist/spa-static.js.map +1 -1
  277. package/dist/state-signing.js +1 -1
  278. package/dist/state-signing.js.map +1 -1
  279. package/dist/storage/domains/audit/actions.d.ts +1 -0
  280. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  281. package/dist/storage/domains/audit/actions.js +2 -1
  282. package/dist/storage/domains/audit/actions.js.map +1 -1
  283. package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -1
  284. package/dist/storage/domains/audit/agent-audit.js +2 -2
  285. package/dist/storage/domains/audit/agent-audit.js.map +1 -1
  286. package/dist/storage/domains/audit/base.d.ts +18 -2
  287. package/dist/storage/domains/audit/base.d.ts.map +1 -1
  288. package/dist/storage/domains/audit/base.js +22 -4
  289. package/dist/storage/domains/audit/base.js.map +1 -1
  290. package/dist/storage/domains/audit/domain.js.map +1 -1
  291. package/dist/storage/domains/channel-identity/base.js.map +1 -1
  292. package/dist/storage/domains/comments/base.js.map +1 -1
  293. package/dist/storage/domains/comments/domain.js.map +1 -1
  294. package/dist/storage/domains/comments/feed-context.js.map +1 -1
  295. package/dist/storage/domains/credentials/base.js.map +1 -1
  296. package/dist/storage/domains/custom-providers/base.js.map +1 -1
  297. package/dist/storage/domains/intake/base.js.map +1 -1
  298. package/dist/storage/domains/integrations/base.d.ts +8 -0
  299. package/dist/storage/domains/integrations/base.d.ts.map +1 -1
  300. package/dist/storage/domains/integrations/base.js +7 -0
  301. package/dist/storage/domains/integrations/base.js.map +1 -1
  302. package/dist/storage/domains/memory-settings/base.js.map +1 -1
  303. package/dist/storage/domains/model-defaults/base.d.ts +8 -0
  304. package/dist/storage/domains/model-defaults/base.d.ts.map +1 -1
  305. package/dist/storage/domains/model-defaults/base.js +18 -0
  306. package/dist/storage/domains/model-defaults/base.js.map +1 -1
  307. package/dist/storage/domains/projects/base.js.map +1 -1
  308. package/dist/storage/domains/queue-health/base.js.map +1 -1
  309. package/dist/storage/domains/source-control/base.d.ts +44 -0
  310. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  311. package/dist/storage/domains/source-control/base.js +109 -3
  312. package/dist/storage/domains/source-control/base.js.map +1 -1
  313. package/dist/storage/domains/source-control/inmemory.d.ts +23 -1
  314. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  315. package/dist/storage/domains/source-control/inmemory.js +35 -0
  316. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  317. package/dist/storage/domains/work-items/base.d.ts +14 -0
  318. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  319. package/dist/storage/domains/work-items/base.js +25 -1
  320. package/dist/storage/domains/work-items/base.js.map +1 -1
  321. package/dist/storage/domains/work-items/board-version.js.map +1 -1
  322. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  323. package/dist/tools/approval-tools.js +1 -1
  324. package/dist/tools/approval-tools.js.map +1 -1
  325. package/dist/tools/deliver.d.ts +8 -5
  326. package/dist/tools/deliver.d.ts.map +1 -1
  327. package/dist/tools/deliver.js +22 -8
  328. package/dist/tools/deliver.js.map +1 -1
  329. package/dist/tools/messaging-tools.d.ts +1 -1
  330. package/dist/tools/messaging-tools.d.ts.map +1 -1
  331. package/dist/tools/messaging-tools.js +203 -72
  332. package/dist/tools/messaging-tools.js.map +1 -1
  333. package/dist/tools/permissions.d.ts +1 -1
  334. package/dist/tools/permissions.d.ts.map +1 -1
  335. package/dist/tools/permissions.js +3 -2
  336. package/dist/tools/permissions.js.map +1 -1
  337. package/dist/tools/reports.d.ts.map +1 -1
  338. package/dist/tools/reports.js +10 -3
  339. package/dist/tools/reports.js.map +1 -1
  340. package/dist/tools/run-watch.d.ts +2 -0
  341. package/dist/tools/run-watch.d.ts.map +1 -1
  342. package/dist/tools/run-watch.js +42 -2
  343. package/dist/tools/run-watch.js.map +1 -1
  344. package/dist/tools/sandbox-tools.d.ts +12 -0
  345. package/dist/tools/sandbox-tools.d.ts.map +1 -0
  346. package/dist/tools/sandbox-tools.js +40 -0
  347. package/dist/tools/sandbox-tools.js.map +1 -0
  348. package/dist/tools/scope.d.ts +2 -1
  349. package/dist/tools/scope.d.ts.map +1 -1
  350. package/dist/tools/scope.js +5 -7
  351. package/dist/tools/scope.js.map +1 -1
  352. package/dist/tools/session-tools.d.ts +1 -1
  353. package/dist/tools/session-tools.d.ts.map +1 -1
  354. package/dist/tools/session-tools.js +39 -18
  355. package/dist/tools/session-tools.js.map +1 -1
  356. package/dist/tools/sessions-state-processor.js +2 -2
  357. package/dist/tools/sessions-state-processor.js.map +1 -1
  358. package/dist/tools/side-sessions.d.ts +1 -1
  359. package/dist/tools/side-sessions.d.ts.map +1 -1
  360. package/dist/tools/side-sessions.js +1 -1
  361. package/dist/tools/side-sessions.js.map +1 -1
  362. package/dist/work-item-branch.d.ts +11 -3
  363. package/dist/work-item-branch.d.ts.map +1 -1
  364. package/dist/work-item-branch.js +34 -9
  365. package/dist/work-item-branch.js.map +1 -1
  366. package/dist/workspace.d.ts +7 -3
  367. package/dist/workspace.d.ts.map +1 -1
  368. package/dist/workspace.js +32 -17
  369. package/dist/workspace.js.map +1 -1
  370. package/factory-skills/configure-factory-rules/SKILL.md +2 -2
  371. package/package.json +16 -15
  372. package/dist/session/channel-reply-processor.d.ts.map +0 -1
  373. package/dist/session/channel-reply-processor.js +0 -46
  374. package/dist/session/channel-reply-processor.js.map +0 -1
  375. package/dist/session/channel-session-link-processor.d.ts.map +0 -1
  376. package/dist/session/channel-session-link-processor.js.map +0 -1
  377. /package/dist/{session → integrations/slack}/channel-session-link-processor.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"reconcile-worker.js","names":["#reconcile","#reconcileIssues","#sourceControl","#intervalMs","#issueIntervalMs","#leaseTtlMs","#leaseOwner","#now","#leaseProvider","#running","#schedule","#timer","#inFlight","#tick","#nextDelay","#nextPullRequestReconcileAt","#nextIssueReconcileAt","#targets"],"sources":["../../../src/integrations/github/reconcile-worker.ts"],"sourcesContent":["import { isLeaseProvider, NoopLeaseProvider } from '@mastra/core/events';\nimport type { LeaseProvider, PubSub } from '@mastra/core/events';\nimport { MastraWorker } from '@mastra/core/worker';\nimport type { WorkerDeps } from '@mastra/core/worker';\n\nimport type {\n ConfiguredExternalRepositoryKey,\n ExternalRepositoryProjectTarget,\n SourceControlRepository,\n} from '../../storage/domains/source-control/base.js';\nimport type { GithubIssueReconciler } from './issue-reconciler.js';\nimport type { GithubPullRequestReconciler, ReconcileRepository } from './rules.js';\n\n// Webhooks are the primary sync; the sweeps only catch drift, so hourly.\nexport const DEFAULT_GITHUB_RECONCILE_INTERVAL_MS = 60 * 60_000;\nconst MIN_LEASE_TTL_MS = 30_000;\nconst LEASE_KEY = 'github:pull-request-reconcile';\n\n/** Storage slice the sweep needs to turn configured repositories into targets. */\nexport interface GithubReconcileRepositorySource {\n projectRepositories: {\n listConfiguredExternalKeys(): Promise<ConfiguredExternalRepositoryKey[]>;\n listByExternalRepository(args: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]>;\n };\n repositories: {\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlRepository | null>;\n };\n}\n\nexport interface GithubReconcileWorkerConfig {\n reconcile?: GithubPullRequestReconciler;\n reconcileIssues?: GithubIssueReconciler;\n sourceControl: GithubReconcileRepositorySource;\n intervalMs?: number;\n issueIntervalMs?: number;\n now?: () => number;\n}\n\n/**\n * Periodic GitHub state sweeps for the self-hosted integration. Pull requests\n * drive review cards and issues drive work cards, but both share discovery and\n * a lease so replicas never sweep the same configured repositories together.\n */\nexport class GithubReconcileWorker extends MastraWorker {\n readonly name = 'github-pull-request-reconcile';\n\n readonly #reconcile: GithubPullRequestReconciler | undefined;\n readonly #reconcileIssues: GithubIssueReconciler | undefined;\n readonly #sourceControl: GithubReconcileRepositorySource;\n readonly #intervalMs: number;\n readonly #issueIntervalMs: number;\n readonly #leaseTtlMs: number;\n readonly #leaseOwner = globalThis.crypto.randomUUID();\n readonly #now: () => number;\n\n #running = false;\n #timer: ReturnType<typeof setTimeout> | undefined;\n #inFlight: Promise<void> | undefined;\n #leaseProvider: LeaseProvider = NoopLeaseProvider;\n #nextPullRequestReconcileAt = 0;\n #nextIssueReconcileAt = 0;\n\n constructor(config: GithubReconcileWorkerConfig) {\n super();\n if (!config.reconcile && !config.reconcileIssues) {\n throw new Error('GitHub reconcile worker requires a pull request or issue reconciler.');\n }\n this.#reconcile = config.reconcile;\n this.#reconcileIssues = config.reconcileIssues;\n this.#sourceControl = config.sourceControl;\n this.#intervalMs = config.intervalMs ?? DEFAULT_GITHUB_RECONCILE_INTERVAL_MS;\n this.#issueIntervalMs = config.issueIntervalMs ?? this.#intervalMs;\n if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {\n throw new Error('GitHub pull request reconcile interval must be a positive number.');\n }\n if (!Number.isFinite(this.#issueIntervalMs) || this.#issueIntervalMs <= 0) {\n throw new Error('GitHub issue reconcile interval must be a positive number.');\n }\n this.#leaseTtlMs = Math.max(MIN_LEASE_TTL_MS, Math.min(this.#intervalMs, this.#issueIntervalMs) * 3);\n this.#now = config.now ?? Date.now;\n }\n\n async init(deps: WorkerDeps): Promise<void> {\n await super.init(deps);\n this.#leaseProvider = getLeaseProvider(deps.pubsub);\n }\n\n async start(): Promise<void> {\n if (this.#running) return;\n if (!this.deps) throw new Error('GithubReconcileWorker: call init() before start()');\n this.#running = true;\n this.deps.logger.info('GitHub reconcile worker started', {\n pullRequestIntervalMs: this.#reconcile ? this.#intervalMs : undefined,\n issueIntervalMs: this.#reconcileIssues ? this.#issueIntervalMs : undefined,\n });\n // Sweep on boot: a restart is exactly when webhooks were most likely missed.\n this.#schedule(0);\n }\n\n async stop(): Promise<void> {\n if (!this.#running) return;\n this.#running = false;\n if (this.#timer) clearTimeout(this.#timer);\n this.#timer = undefined;\n await this.#inFlight;\n }\n\n get isRunning(): boolean {\n return this.#running;\n }\n\n #schedule(delayMs: number): void {\n if (!this.#running) return;\n this.#timer = setTimeout(() => {\n this.#timer = undefined;\n const run = this.#tick().finally(() => {\n this.#inFlight = undefined;\n this.#schedule(this.#nextDelay());\n });\n this.#inFlight = run;\n }, delayMs);\n this.#timer.unref?.();\n }\n\n #nextDelay(): number {\n const now = this.#now();\n const due = [\n this.#reconcile ? this.#nextPullRequestReconcileAt : undefined,\n this.#reconcileIssues ? this.#nextIssueReconcileAt : undefined,\n ].filter((at): at is number => at !== undefined);\n return Math.max(0, Math.min(...due) - now);\n }\n\n async #tick(): Promise<void> {\n const now = this.#now();\n const reconcilePullRequests = Boolean(this.#reconcile && now >= this.#nextPullRequestReconcileAt);\n const reconcileIssues = Boolean(this.#reconcileIssues && now >= this.#nextIssueReconcileAt);\n if (!reconcilePullRequests && !reconcileIssues) return;\n if (reconcilePullRequests) this.#nextPullRequestReconcileAt = now + this.#intervalMs;\n if (reconcileIssues) this.#nextIssueReconcileAt = now + this.#issueIntervalMs;\n\n // Replicas share one sweep: the ingress dedupes duplicate writes, but the\n // reads still burn the installation's rate limit.\n const lease = await this.#leaseProvider\n .acquireLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .catch(() => ({ acquired: false }));\n if (!lease.acquired) return;\n\n let hasLease = true;\n const renewalTimer = setInterval(\n () => {\n void this.#leaseProvider\n .renewLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .then(renewed => {\n if (!renewed) {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease was lost mid-sweep; aborting further writes');\n }\n })\n .catch(error => {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease renewal failed; aborting further writes', {\n error: error instanceof Error ? error.message : String(error),\n });\n });\n },\n Math.max(1_000, Math.floor(this.#leaseTtlMs / 3)),\n );\n renewalTimer.unref?.();\n\n try {\n const targets = await this.#targets();\n if (targets.length === 0) return;\n\n if (reconcilePullRequests && this.#reconcile) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcile(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub pull request reconcile sweep completed with failures', {\n ...context,\n errors,\n });\n } else if (counts.merged > 0 || counts.closed > 0) {\n this.deps?.logger.info('GitHub pull request reconcile replayed missed merges/closes', context);\n } else {\n this.deps?.logger.debug('GitHub pull request reconcile sweep completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub pull request reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n if (reconcileIssues && this.#reconcileIssues && hasLease) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcileIssues(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub issue reconcile sweep completed with failures', { ...context, errors });\n } else if (counts.closed > 0) {\n this.deps?.logger.info('GitHub issue reconcile replayed closed work items', context);\n } else if (counts.relabeled > 0) {\n this.deps?.logger.info('GitHub issue reconcile re-applied label routing', context);\n } else if (counts.updated > 0) {\n this.deps?.logger.info('GitHub issue reconcile patched stale metadata', context);\n } else {\n this.deps?.logger.debug('GitHub issue reconcile sweep completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub issue reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n } else if (reconcileIssues && this.#reconcileIssues && !hasLease) {\n this.deps?.logger.debug('GitHub issue reconcile skipped: lease lost during pull-request sweep');\n }\n } finally {\n clearInterval(renewalTimer);\n if (hasLease) {\n await this.#leaseProvider.releaseLease(LEASE_KEY, this.#leaseOwner).catch(() => undefined);\n }\n }\n }\n\n /**\n * Configured (installation, repository) pairs resolved to the numeric ids and\n * slug the sweep addresses GitHub with. A pair whose repository row is gone\n * is skipped rather than failing the sweep for the others.\n */\n async #targets(): Promise<ReconcileRepository[]> {\n const keys = await this.#sourceControl.projectRepositories.listConfiguredExternalKeys();\n const targets: ReconcileRepository[] = [];\n for (const key of keys) {\n const installationId = Number(key.installationExternalId);\n const repositoryId = Number(key.repositoryExternalId);\n if (!Number.isSafeInteger(installationId) || !Number.isSafeInteger(repositoryId)) continue;\n const projects = await this.#sourceControl.projectRepositories.listByExternalRepository(key);\n const orgId = projects[0]?.orgId;\n if (!orgId) continue;\n const repository = await this.#sourceControl.repositories.findByExternalId({\n orgId,\n externalId: key.repositoryExternalId,\n });\n if (!repository?.slug) continue;\n targets.push({ id: repositoryId, fullName: repository.slug, installationId });\n }\n return targets;\n }\n}\n\nfunction getLeaseProvider(pubsub: PubSub): LeaseProvider {\n const getProvider = (pubsub as PubSub & { getLeaseProvider?: () => LeaseProvider | undefined }).getLeaseProvider;\n if (typeof getProvider === 'function') return getProvider.call(pubsub) ?? NoopLeaseProvider;\n return isLeaseProvider(pubsub) ? pubsub : NoopLeaseProvider;\n}\n"],"mappings":";;;AAcA,MAAa,uCAAuC,KAAK;AACzD,MAAM,mBAAmB;AACzB,MAAM,YAAY;;;;;;AA8BlB,IAAa,wBAAb,cAA2C,aAAa;CACtD,OAAgB;CAEhB;CACA;CACA;CACA;CACA;CACA;CACA,cAAuB,WAAW,OAAO,WAAW;CACpD;CAEA,WAAW;CACX;CACA;CACA,iBAAgC;CAChC,8BAA8B;CAC9B,wBAAwB;CAExB,YAAY,QAAqC;EAC/C,MAAM;EACN,IAAI,CAA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,MAAM,cAAe,OAA2E;CAChG,IAAI,OAAO,gBAAgB,YAAY,OAAO,YAAY,KAAK,MAAM,KAAK;CAC1E,OAAO,gBAAgB,MAAM,IAAI,SAAS;AAC5C"}
1
+ {"version":3,"file":"reconcile-worker.js","names":[],"sources":["../../../src/integrations/github/reconcile-worker.ts"],"sourcesContent":["import { isLeaseProvider, NoopLeaseProvider } from '@mastra/core/events';\nimport type { LeaseProvider, PubSub } from '@mastra/core/events';\nimport { MastraWorker } from '@mastra/core/worker';\nimport type { WorkerDeps } from '@mastra/core/worker';\n\nimport type {\n ConfiguredExternalRepositoryKey,\n ExternalRepositoryProjectTarget,\n SourceControlRepository,\n} from '../../storage/domains/source-control/base.js';\nimport type { GithubIssueReconciler } from './issue-reconciler.js';\nimport type { GithubPullRequestReconciler, ReconcileRepository } from './rules.js';\n\n// Webhooks are the primary sync; the sweeps only catch drift, so hourly.\nexport const DEFAULT_GITHUB_RECONCILE_INTERVAL_MS = 60 * 60_000;\nconst MIN_LEASE_TTL_MS = 30_000;\nconst LEASE_KEY = 'github:pull-request-reconcile';\n\n/** Storage slice the sweep needs to turn configured repositories into targets. */\nexport interface GithubReconcileRepositorySource {\n projectRepositories: {\n listConfiguredExternalKeys(): Promise<ConfiguredExternalRepositoryKey[]>;\n listByExternalRepository(args: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]>;\n };\n repositories: {\n findByExternalId(args: { orgId: string; externalId: string }): Promise<SourceControlRepository | null>;\n };\n}\n\nexport interface GithubReconcileWorkerConfig {\n reconcile?: GithubPullRequestReconciler;\n reconcileIssues?: GithubIssueReconciler;\n sourceControl: GithubReconcileRepositorySource;\n intervalMs?: number;\n issueIntervalMs?: number;\n now?: () => number;\n}\n\n/**\n * Periodic GitHub state sweeps for the self-hosted integration. Pull requests\n * drive review cards and issues drive work cards, but both share discovery and\n * a lease so replicas never sweep the same configured repositories together.\n */\nexport class GithubReconcileWorker extends MastraWorker {\n readonly name = 'github-pull-request-reconcile';\n\n readonly #reconcile: GithubPullRequestReconciler | undefined;\n readonly #reconcileIssues: GithubIssueReconciler | undefined;\n readonly #sourceControl: GithubReconcileRepositorySource;\n readonly #intervalMs: number;\n readonly #issueIntervalMs: number;\n readonly #leaseTtlMs: number;\n readonly #leaseOwner = globalThis.crypto.randomUUID();\n readonly #now: () => number;\n\n #running = false;\n #timer: ReturnType<typeof setTimeout> | undefined;\n #inFlight: Promise<void> | undefined;\n #leaseProvider: LeaseProvider = NoopLeaseProvider;\n #nextPullRequestReconcileAt = 0;\n #nextIssueReconcileAt = 0;\n\n constructor(config: GithubReconcileWorkerConfig) {\n super();\n if (!config.reconcile && !config.reconcileIssues) {\n throw new Error('GitHub reconcile worker requires a pull request or issue reconciler.');\n }\n this.#reconcile = config.reconcile;\n this.#reconcileIssues = config.reconcileIssues;\n this.#sourceControl = config.sourceControl;\n this.#intervalMs = config.intervalMs ?? DEFAULT_GITHUB_RECONCILE_INTERVAL_MS;\n this.#issueIntervalMs = config.issueIntervalMs ?? this.#intervalMs;\n if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {\n throw new Error('GitHub pull request reconcile interval must be a positive number.');\n }\n if (!Number.isFinite(this.#issueIntervalMs) || this.#issueIntervalMs <= 0) {\n throw new Error('GitHub issue reconcile interval must be a positive number.');\n }\n this.#leaseTtlMs = Math.max(MIN_LEASE_TTL_MS, Math.min(this.#intervalMs, this.#issueIntervalMs) * 3);\n this.#now = config.now ?? Date.now;\n }\n\n async init(deps: WorkerDeps): Promise<void> {\n await super.init(deps);\n this.#leaseProvider = getLeaseProvider(deps.pubsub);\n }\n\n async start(): Promise<void> {\n if (this.#running) return;\n if (!this.deps) throw new Error('GithubReconcileWorker: call init() before start()');\n this.#running = true;\n this.deps.logger.info('GitHub reconcile worker started', {\n pullRequestIntervalMs: this.#reconcile ? this.#intervalMs : undefined,\n issueIntervalMs: this.#reconcileIssues ? this.#issueIntervalMs : undefined,\n });\n // Sweep on boot: a restart is exactly when webhooks were most likely missed.\n this.#schedule(0);\n }\n\n async stop(): Promise<void> {\n if (!this.#running) return;\n this.#running = false;\n if (this.#timer) clearTimeout(this.#timer);\n this.#timer = undefined;\n await this.#inFlight;\n }\n\n get isRunning(): boolean {\n return this.#running;\n }\n\n #schedule(delayMs: number): void {\n if (!this.#running) return;\n this.#timer = setTimeout(() => {\n this.#timer = undefined;\n const run = this.#tick().finally(() => {\n this.#inFlight = undefined;\n this.#schedule(this.#nextDelay());\n });\n this.#inFlight = run;\n }, delayMs);\n this.#timer.unref?.();\n }\n\n #nextDelay(): number {\n const now = this.#now();\n const due = [\n this.#reconcile ? this.#nextPullRequestReconcileAt : undefined,\n this.#reconcileIssues ? this.#nextIssueReconcileAt : undefined,\n ].filter((at): at is number => at !== undefined);\n return Math.max(0, Math.min(...due) - now);\n }\n\n async #tick(): Promise<void> {\n const now = this.#now();\n const reconcilePullRequests = Boolean(this.#reconcile && now >= this.#nextPullRequestReconcileAt);\n const reconcileIssues = Boolean(this.#reconcileIssues && now >= this.#nextIssueReconcileAt);\n if (!reconcilePullRequests && !reconcileIssues) return;\n if (reconcilePullRequests) this.#nextPullRequestReconcileAt = now + this.#intervalMs;\n if (reconcileIssues) this.#nextIssueReconcileAt = now + this.#issueIntervalMs;\n\n // Replicas share one sweep: the ingress dedupes duplicate writes, but the\n // reads still burn the installation's rate limit.\n const lease = await this.#leaseProvider\n .acquireLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .catch(() => ({ acquired: false }));\n if (!lease.acquired) return;\n\n let hasLease = true;\n const renewalTimer = setInterval(\n () => {\n void this.#leaseProvider\n .renewLease(LEASE_KEY, this.#leaseOwner, this.#leaseTtlMs)\n .then(renewed => {\n if (!renewed) {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease was lost mid-sweep; aborting further writes');\n }\n })\n .catch(error => {\n hasLease = false;\n clearInterval(renewalTimer);\n this.deps?.logger.warn('GitHub reconcile lease renewal failed; aborting further writes', {\n error: error instanceof Error ? error.message : String(error),\n });\n });\n },\n Math.max(1_000, Math.floor(this.#leaseTtlMs / 3)),\n );\n renewalTimer.unref?.();\n\n try {\n const targets = await this.#targets();\n if (targets.length === 0) return;\n\n if (reconcilePullRequests && this.#reconcile) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcile(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub pull request reconcile sweep completed with failures', {\n ...context,\n errors,\n });\n } else if (counts.merged > 0 || counts.closed > 0) {\n this.deps?.logger.info('GitHub pull request reconcile replayed missed merges/closes', context);\n } else {\n this.deps?.logger.debug('GitHub pull request reconcile sweep completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub pull request reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n if (reconcileIssues && this.#reconcileIssues && hasLease) {\n const startedAt = Date.now();\n try {\n const { errors, ...counts } = await this.#reconcileIssues(targets);\n const context = { ...counts, candidateRepositories: targets.length, durationMs: Date.now() - startedAt };\n if (counts.failed > 0) {\n this.deps?.logger.warn('GitHub issue reconcile sweep completed with failures', { ...context, errors });\n } else if (counts.closed > 0) {\n this.deps?.logger.info('GitHub issue reconcile replayed closed work items', context);\n } else if (counts.relabeled > 0) {\n this.deps?.logger.info('GitHub issue reconcile re-applied label routing', context);\n } else if (counts.updated > 0) {\n this.deps?.logger.info('GitHub issue reconcile patched stale metadata', context);\n } else {\n this.deps?.logger.debug('GitHub issue reconcile sweep completed', context);\n }\n } catch (error) {\n this.deps?.logger.warn('GitHub issue reconcile sweep failed', {\n error: error instanceof Error ? error.message : String(error),\n });\n }\n } else if (reconcileIssues && this.#reconcileIssues && !hasLease) {\n this.deps?.logger.debug('GitHub issue reconcile skipped: lease lost during pull-request sweep');\n }\n } finally {\n clearInterval(renewalTimer);\n if (hasLease) {\n await this.#leaseProvider.releaseLease(LEASE_KEY, this.#leaseOwner).catch(() => undefined);\n }\n }\n }\n\n /**\n * Configured (installation, repository) pairs resolved to the numeric ids and\n * slug the sweep addresses GitHub with. A pair whose repository row is gone\n * is skipped rather than failing the sweep for the others.\n */\n async #targets(): Promise<ReconcileRepository[]> {\n const keys = await this.#sourceControl.projectRepositories.listConfiguredExternalKeys();\n const targets: ReconcileRepository[] = [];\n for (const key of keys) {\n const installationId = Number(key.installationExternalId);\n const repositoryId = Number(key.repositoryExternalId);\n if (!Number.isSafeInteger(installationId) || !Number.isSafeInteger(repositoryId)) continue;\n const projects = await this.#sourceControl.projectRepositories.listByExternalRepository(key);\n const orgId = projects[0]?.orgId;\n if (!orgId) continue;\n const repository = await this.#sourceControl.repositories.findByExternalId({\n orgId,\n externalId: key.repositoryExternalId,\n });\n if (!repository?.slug) continue;\n targets.push({ id: repositoryId, fullName: repository.slug, installationId });\n }\n return targets;\n }\n}\n\nfunction getLeaseProvider(pubsub: PubSub): LeaseProvider {\n const getProvider = (pubsub as PubSub & { getLeaseProvider?: () => LeaseProvider | undefined }).getLeaseProvider;\n if (typeof getProvider === 'function') return getProvider.call(pubsub) ?? NoopLeaseProvider;\n return isLeaseProvider(pubsub) ? pubsub : NoopLeaseProvider;\n}\n"],"mappings":";;;AAcA,MAAa,uCAAuC;AACpD,MAAM,mBAAmB;AACzB,MAAM,YAAY;;;;;;AA8BlB,IAAa,wBAAb,cAA2C,aAAa;CACtD,OAAgB;CAEhB;CACA;CACA;CACA;CACA;CACA;CACA,cAAuB,WAAW,OAAO,WAAW;CACpD;CAEA,WAAW;CACX;CACA;CACA,iBAAgC;CAChC,8BAA8B;CAC9B,wBAAwB;CAExB,YAAY,QAAqC;EAC/C,MAAM;EACN,IAAI,CAAC,OAAO,aAAa,CAAC,OAAO,iBAC/B,MAAM,IAAI,MAAM,sEAAsE;EAExF,KAAK,aAAa,OAAO;EACzB,KAAK,mBAAmB,OAAO;EAC/B,KAAK,iBAAiB,OAAO;EAC7B,KA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AA0C,OAAO;IAE7E,SAAS,OAAO;KACd,KAAK,MAAM,OAAO,KAAK,uCAAuC,EAC5D,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAC9D,CAAC;IACH;GACF,OAAO,IAAI,mBAAmB,KAAK,oBAAoB,CAAC,UACtD,KAAK,MAAM,OAAO,MAAM,sEAAsE;EAElG,UAAU;GACR,cAAc,YAAY;GAC1B,IAAI,UACF,MAAM,KAAK,eAAe,aAAa,WAAW,KAAK,WAAW,CAAC,CAAC,YAAY,KAAA,CAAS;EAE7F;CACF;;;;;;CAOA,MAAM,WAA2C;EAC/C,MAAM,OAAO,MAAM,KAAK,eAAe,oBAAoB,2BAA2B;EACtF,MAAM,UAAiC,CAAC;EACxC,KAAK,MAAM,OAAO,MAAM;GACtB,MAAM,iBAAiB,OAAO,IAAI,sBAAsB;GACxD,MAAM,eAAe,OAAO,IAAI,oBAAoB;GACpD,IAAI,CAAC,OAAO,cAAc,cAAc,KAAK,CAAC,OAAO,cAAc,YAAY,GAAG;GAElF,MAAM,SAAQ,MADS,KAAK,eAAe,oBAAoB,yBAAyB,GAAG,EAAA,CACpE,EAAE,EAAE;GAC3B,IAAI,CAAC,OAAO;GACZ,MAAM,aAAa,MAAM,KAAK,eAAe,aAAa,iBAAiB;IACzE;IACA,YAAY,IAAI;GAClB,CAAC;GACD,IAAI,CAAC,YAAY,MAAM;GACvB,QAAQ,KAAK;IAAE,IAAI;IAAc,UAAU,WAAW;IAAM;GAAe,CAAC;EAC9E;EACA,OAAO;CACT;AACF;AAEA,SAAS,iBAAiB,QAA+B;CACvD,MAAM,cAAe,OAA2E;CAChG,IAAI,OAAO,gBAAgB,YAAY,OAAO,YAAY,KAAK,MAAM,KAAK;CAC1E,OAAO,gBAAgB,MAAM,IAAI,SAAS;AAC5C"}
@@ -64,7 +64,7 @@ export interface MountGithubRoutesOptions {
64
64
  projects?: FactoryProjectsStorage;
65
65
  sessionRetirement?: import('../../sandbox/session-retirement.js').SessionRetirementCoordinator;
66
66
  /** Work-items domain — session deletion strips the refs work items hold on it. */
67
- workItems?: Pick<import('../../storage/domains/work-items/base.js').WorkItemsStorage, 'clearSessionReferences'>;
67
+ workItems?: Pick<import('../../storage/domains/work-items/base.js').WorkItemsStorage, 'clearSessionReferences' | 'hasRunBindingForSession'>;
68
68
  /** Authoritative Factory rule ingress for normalized, signature-verified GitHub deliveries. */
69
69
  ingestFactoryEvent?: (event: ParsedGithubWebhook) => Promise<unknown>;
70
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAQvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAC3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AASrF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAyC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAgBxD,MAAM,WAAW,wBAAwB;IACvC,4EAA4E;IAC5E,IAAI,EAAE,SAAS,CAAC;IAChB,8EAA8E;IAC9E,KAAK,CAAC,EAAE,wBAAwB,CAAC;IACjC;;;;;OAKG;IACH,OA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iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,UAAU,CAAC,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC7C,gGAAgG;IAChG,cAAc,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IACnD,6EAA6E;IAC7E,SAAS,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,iBAAiB,CAAC,EAAE,OAAO,qCAAqC,EAAE,4BAA4B,CAAC;IAC/F,kFAAkF;IAClF,SAAS,CAAC,EAAE,IAAI,CACd,OAAO,0CAA0C,EAAE,gBAAgB,EACnE,wBAAwB,GAAG,yBAAyB,CACrD,CAAC;IACF,+FAA+F;IAC/F,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvE;AAyQD;;;;;GAKG;AACH,wBAAsB,6BAA6B,CAAC,IAAI,EAAE;IACxD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,wBAAwB,CAAC,oBAAoB,CAAC,CAAC;CACpE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgChB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,QAAQ,EAAE,CAgpB/E;AA+GD,KAAK,wBAAwB,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC"}
@@ -8,7 +8,9 @@ import { sanitizeSegment } from "../../sandbox/workdir.js";
8
8
  import { peekSessionSandbox } from "../../sandbox/session-sandbox.js";
9
9
  import { listPullRequestSubscriptionsForThread, subscribeToPullRequest } from "./subscriptions.js";
10
10
  import { polledPullRequestEvent } from "./rules.js";
11
+ import { canReadSessionResource, canViewSourceControlSession } from "../../routes/session-access.js";
11
12
  import { waitForPendingFilesystemCapture } from "../../session/filesystem-capture.js";
13
+ import { listFactorySessionThreads, sessionMemoryResourceId } from "../../session/session-threads.js";
12
14
  import { normalizeSessionTitle } from "../../session/session-title.js";
13
15
  import { getGithubFeatureDiagnostics, isGithubFeatureEnabled } from "./config.js";
14
16
  import { reclaimDeletedSessionSandbox } from "./sandbox-release.js";
@@ -320,16 +322,20 @@ function buildGithubRoutes(options) {
320
322
  await auth.ensureUser(loose(c));
321
323
  const tenant = auth.tenant(loose(c));
322
324
  if (!tenant?.orgId) return c.json({ error: "unauthorized" }, 401);
325
+ const sessionId = c.req.query("sessionId");
323
326
  const resourceId = c.req.query("resourceId");
324
327
  const threadId = c.req.query("threadId");
325
- const sessionScope = c.req.query("scope");
326
- if (!resourceId || !threadId) return c.json({ error: "resourceId and threadId are required" }, 400);
327
- const subscriptions = await listPullRequestSubscriptionsForThread({
328
+ const target = !threadId ? null : sessionId ? {
329
+ orgId: tenant.orgId,
330
+ sessionId,
331
+ threadId
332
+ } : resourceId ? {
328
333
  orgId: tenant.orgId,
329
334
  resourceId,
330
- threadId,
331
- sessionScope
332
- }, github.integrationStorage);
335
+ threadId
336
+ } : null;
337
+ if (!target) return c.json({ error: "sessionId (or resourceId) and threadId are required" }, 400);
338
+ const subscriptions = await listPullRequestSubscriptionsForThread(target, github.integrationStorage);
333
339
  return c.json({ subscriptions: subscriptions.map((subscription) => ({
334
340
  id: subscription.id,
335
341
  repoFullName: subscription.data.repositorySlug,
@@ -872,7 +878,7 @@ const DEFAULT_COMMIT_PAGE = 20;
872
878
  const MAX_COMMIT_PAGE = 100;
873
879
  const MAX_SESSION_OWNER_PROFILES = 100;
874
880
  const MAX_SESSION_OWNER_PROFILE_CACHE_ENTRIES = 500;
875
- const SESSION_OWNER_PROFILE_TTL_MS = 5 * 6e4;
881
+ const SESSION_OWNER_PROFILE_TTL_MS = 3e5;
876
882
  function createSessionOwnerProfileResolver(users) {
877
883
  const cache = /* @__PURE__ */ new Map();
878
884
  const cacheProfile = (userId, profile, expiresAt) => {
@@ -1025,8 +1031,13 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1025
1031
  const resolved = await resolveOrgTenant(loose(c), auth);
1026
1032
  if ("response" in resolved) return resolved.response;
1027
1033
  const session = await github.sourceControlStorage.sessions.getBySessionId(c.req.param("sessionId"));
1028
- if (!session || session.orgId !== resolved.tenant.orgId || session.visibility === "private" && session.userId !== resolved.tenant.userId) return c.json({ error: "Session not found" }, 404);
1029
- return c.json({ session });
1034
+ if (!session || !canViewSourceControlSession(session, resolved.tenant)) return c.json({ error: "Session not found" }, 404);
1035
+ const resourceId = await sessionMemoryResourceId(controller, session, workItems);
1036
+ if (!canReadSessionResource(session, resourceId, resolved.tenant)) return c.json({ error: "Session not found" }, 404);
1037
+ return c.json({ session: {
1038
+ ...session,
1039
+ resourceId
1040
+ } });
1030
1041
  }
1031
1042
  }),
1032
1043
  registerApiRoute("/web/user-sessions/:sessionId", {
@@ -1044,7 +1055,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1044
1055
  error
1045
1056
  });
1046
1057
  });
1047
- await controller?.deleteSession({ resourceId: session.sessionId });
1058
+ await controller?.deleteSession({ sessionId: session.sessionId });
1048
1059
  } catch (error) {
1049
1060
  console.error("[GitHub Sessions] Failed to tear down live controller session", {
1050
1061
  sessionId: session.sessionId,
@@ -1085,7 +1096,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1085
1096
  const row = await github.sourceControlStorage.sessions.getBySessionId(sessionId);
1086
1097
  if (!row || row.orgId !== resolved.tenant.orgId || row.userId !== resolved.tenant.userId) return c.json({ error: "Session not found" }, 404);
1087
1098
  if (!controller) return c.json({ error: "Sessions are not available on this server." }, 503);
1088
- const thread = (await controller.queryThreads({ resourceId: sessionId })).sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime())[0];
1099
+ const thread = (await listFactorySessionThreads(controller, row, workItems)).sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime())[0];
1089
1100
  if (!thread) return c.json({ error: "This session has no conversation to name yet." }, 409);
1090
1101
  const stored = await memorySettings.get({
1091
1102
  orgId: row.orgId,
@@ -1101,7 +1112,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1101
1112
  const title = await nameSession(sessionId, async () => {
1102
1113
  const generated = await controller.generateThreadTitle({
1103
1114
  threadId: thread.id,
1104
- resourceId: sessionId,
1115
+ sessionId,
1105
1116
  requestContext,
1106
1117
  ...stored?.observerModelId ? { model: titleModel(stored.observerModelId) } : {}
1107
1118
  });
@@ -1323,7 +1334,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1323
1334
  changeRequestId: pullRequestNumber.toString(),
1324
1335
  sessionId,
1325
1336
  ownerId: userId,
1326
- resourceId: sessionId,
1337
+ resourceId: project.factoryProjectId,
1327
1338
  threadId: sessionId,
1328
1339
  source: "factory-pr-create",
1329
1340
  subscribedByUserId: userId