@mastra/factory 0.24.0-alpha.0 → 0.24.0-alpha.10

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 (406) hide show
  1. package/README.md +106 -4
  2. package/dist/auth.d.ts +14 -0
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js +45 -9
  5. package/dist/auth.js.map +1 -1
  6. package/dist/boards/review.d.ts.map +1 -1
  7. package/dist/boards/review.js +21 -1
  8. package/dist/boards/review.js.map +1 -1
  9. package/dist/boards/work-transition-policy.d.ts.map +1 -1
  10. package/dist/boards/work-transition-policy.js +12 -1
  11. package/dist/boards/work-transition-policy.js.map +1 -1
  12. package/dist/boards/work.d.ts +14 -0
  13. package/dist/boards/work.d.ts.map +1 -1
  14. package/dist/boards/work.js +70 -7
  15. package/dist/boards/work.js.map +1 -1
  16. package/dist/capabilities/version-control.d.ts +26 -0
  17. package/dist/capabilities/version-control.d.ts.map +1 -1
  18. package/dist/factory.d.ts +8 -0
  19. package/dist/factory.d.ts.map +1 -1
  20. package/dist/factory.js +354 -27
  21. package/dist/factory.js.map +1 -1
  22. package/dist/integrations/base.d.ts +1 -1
  23. package/dist/integrations/base.d.ts.map +1 -1
  24. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  25. package/dist/integrations/github/default-rules.js +1 -16
  26. package/dist/integrations/github/default-rules.js.map +1 -1
  27. package/dist/integrations/github/integration.d.ts.map +1 -1
  28. package/dist/integrations/github/integration.js +37 -1
  29. package/dist/integrations/github/integration.js.map +1 -1
  30. package/dist/integrations/github/routes.d.ts +1 -1
  31. package/dist/integrations/github/routes.d.ts.map +1 -1
  32. package/dist/integrations/github/routes.js +19 -11
  33. package/dist/integrations/github/routes.js.map +1 -1
  34. package/dist/integrations/github/rules.d.ts.map +1 -1
  35. package/dist/integrations/github/rules.js +26 -22
  36. package/dist/integrations/github/rules.js.map +1 -1
  37. package/dist/integrations/github/sandbox-release.d.ts +15 -3
  38. package/dist/integrations/github/sandbox-release.d.ts.map +1 -1
  39. package/dist/integrations/github/sandbox-release.js +20 -3
  40. package/dist/integrations/github/sandbox-release.js.map +1 -1
  41. package/dist/integrations/github/sandbox.d.ts +2 -3
  42. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  43. package/dist/integrations/github/sandbox.js +78 -7
  44. package/dist/integrations/github/sandbox.js.map +1 -1
  45. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
  46. package/dist/integrations/github/session-subscriptions.js +1 -2
  47. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  48. package/dist/integrations/github/subscriptions.d.ts +7 -4
  49. package/dist/integrations/github/subscriptions.d.ts.map +1 -1
  50. package/dist/integrations/github/subscriptions.js +5 -5
  51. package/dist/integrations/github/subscriptions.js.map +1 -1
  52. package/dist/integrations/github/webhook.d.ts +4 -2
  53. package/dist/integrations/github/webhook.d.ts.map +1 -1
  54. package/dist/integrations/github/webhook.js +59 -36
  55. package/dist/integrations/github/webhook.js.map +1 -1
  56. package/dist/integrations/gitlab/api.d.ts +16 -1
  57. package/dist/integrations/gitlab/api.d.ts.map +1 -1
  58. package/dist/integrations/gitlab/api.js +9 -0
  59. package/dist/integrations/gitlab/api.js.map +1 -1
  60. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  61. package/dist/integrations/gitlab/routes.js +10 -6
  62. package/dist/integrations/gitlab/routes.js.map +1 -1
  63. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  64. package/dist/integrations/gitlab/rules.js +28 -21
  65. package/dist/integrations/gitlab/rules.js.map +1 -1
  66. package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -1
  67. package/dist/integrations/gitlab/session-subscriptions.js +1 -2
  68. package/dist/integrations/gitlab/session-subscriptions.js.map +1 -1
  69. package/dist/integrations/gitlab/subscriptions.d.ts +7 -4
  70. package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -1
  71. package/dist/integrations/gitlab/subscriptions.js +5 -5
  72. package/dist/integrations/gitlab/subscriptions.js.map +1 -1
  73. package/dist/integrations/gitlab/version-control.d.ts.map +1 -1
  74. package/dist/integrations/gitlab/version-control.js +37 -3
  75. package/dist/integrations/gitlab/version-control.js.map +1 -1
  76. package/dist/integrations/incidentio/api.d.ts +9 -0
  77. package/dist/integrations/incidentio/api.d.ts.map +1 -1
  78. package/dist/integrations/incidentio/api.js +3 -0
  79. package/dist/integrations/incidentio/api.js.map +1 -1
  80. package/dist/integrations/incidentio/intake.d.ts +1 -1
  81. package/dist/integrations/incidentio/intake.d.ts.map +1 -1
  82. package/dist/integrations/incidentio/intake.js.map +1 -1
  83. package/dist/integrations/incidentio/integration.d.ts.map +1 -1
  84. package/dist/integrations/incidentio/integration.js +1 -0
  85. package/dist/integrations/incidentio/integration.js.map +1 -1
  86. package/dist/integrations/jira/api.d.ts +7 -0
  87. package/dist/integrations/jira/api.d.ts.map +1 -1
  88. package/dist/integrations/jira/api.js +4 -0
  89. package/dist/integrations/jira/api.js.map +1 -1
  90. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  91. package/dist/integrations/linear/agent-tools.js.map +1 -1
  92. package/dist/integrations/platform/api-client.d.ts +6 -0
  93. package/dist/integrations/platform/api-client.d.ts.map +1 -1
  94. package/dist/integrations/platform/api-client.js +6 -1
  95. package/dist/integrations/platform/api-client.js.map +1 -1
  96. package/dist/integrations/platform/connect/routes.d.ts +1 -1
  97. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  98. package/dist/integrations/platform/connect/routes.js.map +1 -1
  99. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  100. package/dist/integrations/platform/github/integration.js +27 -1
  101. package/dist/integrations/platform/github/integration.js.map +1 -1
  102. package/dist/integrations/platform/incidentio/integration.d.ts +1 -1
  103. package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
  104. package/dist/integrations/platform/incidentio/integration.js +1 -0
  105. package/dist/integrations/platform/incidentio/integration.js.map +1 -1
  106. package/dist/integrations/platform/jira/integration.d.ts +1 -1
  107. package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
  108. package/dist/integrations/platform/jira/integration.js +1 -0
  109. package/dist/integrations/platform/jira/integration.js.map +1 -1
  110. package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
  111. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  112. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  113. package/dist/integrations/slack/integration.d.ts.map +1 -1
  114. package/dist/integrations/slack/integration.js +33 -6
  115. package/dist/integrations/slack/integration.js.map +1 -1
  116. package/dist/integrations/slack/slack.d.ts +16 -5
  117. package/dist/integrations/slack/slack.d.ts.map +1 -1
  118. package/dist/integrations/slack/slack.js +137 -64
  119. package/dist/integrations/slack/slack.js.map +1 -1
  120. package/dist/integrations/subscription-session.d.ts +14 -0
  121. package/dist/integrations/subscription-session.d.ts.map +1 -1
  122. package/dist/integrations/subscription-session.js +30 -16
  123. package/dist/integrations/subscription-session.js.map +1 -1
  124. package/dist/mcp/disconnect.d.ts +10 -0
  125. package/dist/mcp/disconnect.d.ts.map +1 -0
  126. package/dist/mcp/disconnect.js +44 -0
  127. package/dist/mcp/disconnect.js.map +1 -0
  128. package/dist/mcp/routes.d.ts +46 -0
  129. package/dist/mcp/routes.d.ts.map +1 -0
  130. package/dist/mcp/routes.js +243 -0
  131. package/dist/mcp/routes.js.map +1 -0
  132. package/dist/provider-display-name.d.ts +2 -0
  133. package/dist/provider-display-name.d.ts.map +1 -0
  134. package/dist/provider-display-name.js +16 -0
  135. package/dist/provider-display-name.js.map +1 -0
  136. package/dist/review-verdict.d.ts +11 -0
  137. package/dist/review-verdict.d.ts.map +1 -1
  138. package/dist/review-verdict.js +16 -1
  139. package/dist/review-verdict.js.map +1 -1
  140. package/dist/routes/attention-activity.d.ts.map +1 -1
  141. package/dist/routes/attention-activity.js +5 -2
  142. package/dist/routes/attention-activity.js.map +1 -1
  143. package/dist/routes/attention-providers.d.ts +0 -1
  144. package/dist/routes/attention-providers.d.ts.map +1 -1
  145. package/dist/routes/attention-providers.js +5 -6
  146. package/dist/routes/attention-providers.js.map +1 -1
  147. package/dist/routes/config.d.ts +44 -5
  148. package/dist/routes/config.d.ts.map +1 -1
  149. package/dist/routes/config.js +181 -58
  150. package/dist/routes/config.js.map +1 -1
  151. package/dist/routes/contracts.d.ts +4 -0
  152. package/dist/routes/contracts.d.ts.map +1 -1
  153. package/dist/routes/contracts.js +3 -1
  154. package/dist/routes/contracts.js.map +1 -1
  155. package/dist/routes/custom-provider-source.d.ts +8 -0
  156. package/dist/routes/custom-provider-source.d.ts.map +1 -1
  157. package/dist/routes/custom-provider-source.js +22 -1
  158. package/dist/routes/custom-provider-source.js.map +1 -1
  159. package/dist/routes/oauth.js +1 -1
  160. package/dist/routes/oauth.js.map +1 -1
  161. package/dist/routes/projects.d.ts +1 -1
  162. package/dist/routes/projects.d.ts.map +1 -1
  163. package/dist/routes/projects.js +1 -1
  164. package/dist/routes/projects.js.map +1 -1
  165. package/dist/routes/provider-credentials.d.ts +7 -2
  166. package/dist/routes/provider-credentials.d.ts.map +1 -1
  167. package/dist/routes/provider-credentials.js +30 -8
  168. package/dist/routes/provider-credentials.js.map +1 -1
  169. package/dist/routes/skills.d.ts +2 -4
  170. package/dist/routes/skills.d.ts.map +1 -1
  171. package/dist/routes/skills.js +19 -65
  172. package/dist/routes/skills.js.map +1 -1
  173. package/dist/routes/source-control-sessions.d.ts +9 -1
  174. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  175. package/dist/routes/source-control-sessions.js +131 -7
  176. package/dist/routes/source-control-sessions.js.map +1 -1
  177. package/dist/routes/surface.d.ts +3 -2
  178. package/dist/routes/surface.d.ts.map +1 -1
  179. package/dist/routes/surface.js +7 -3
  180. package/dist/routes/surface.js.map +1 -1
  181. package/dist/routes/work-items.d.ts.map +1 -1
  182. package/dist/routes/work-items.js +60 -120
  183. package/dist/routes/work-items.js.map +1 -1
  184. package/dist/rules/binding-context.js +7 -7
  185. package/dist/rules/binding-context.js.map +1 -1
  186. package/dist/rules/dispatch-errors.d.ts.map +1 -1
  187. package/dist/rules/dispatch-errors.js +12 -0
  188. package/dist/rules/dispatch-errors.js.map +1 -1
  189. package/dist/rules/dispatcher.d.ts +8 -1
  190. package/dist/rules/dispatcher.d.ts.map +1 -1
  191. package/dist/rules/dispatcher.js +117 -12
  192. package/dist/rules/dispatcher.js.map +1 -1
  193. package/dist/rules/processor.d.ts.map +1 -1
  194. package/dist/rules/processor.js +2 -1
  195. package/dist/rules/processor.js.map +1 -1
  196. package/dist/rules/start-coordinator.d.ts +4 -0
  197. package/dist/rules/start-coordinator.d.ts.map +1 -1
  198. package/dist/rules/start-coordinator.js +36 -4
  199. package/dist/rules/start-coordinator.js.map +1 -1
  200. package/dist/rules/tools.d.ts.map +1 -1
  201. package/dist/rules/tools.js +82 -3
  202. package/dist/rules/tools.js.map +1 -1
  203. package/dist/rules/transition-service.d.ts +17 -0
  204. package/dist/rules/transition-service.d.ts.map +1 -1
  205. package/dist/rules/transition-service.js +25 -0
  206. package/dist/rules/transition-service.js.map +1 -1
  207. package/dist/rules/types.d.ts +2 -4
  208. package/dist/rules/types.d.ts.map +1 -1
  209. package/dist/rules/types.js +1 -4
  210. package/dist/rules/types.js.map +1 -1
  211. package/dist/sandbox/local-factory-sandbox.d.ts.map +1 -1
  212. package/dist/sandbox/local-factory-sandbox.js +1 -0
  213. package/dist/sandbox/local-factory-sandbox.js.map +1 -1
  214. package/dist/sandbox/session-retirement.d.ts +27 -3
  215. package/dist/sandbox/session-retirement.d.ts.map +1 -1
  216. package/dist/sandbox/session-retirement.js +158 -20
  217. package/dist/sandbox/session-retirement.js.map +1 -1
  218. package/dist/secret-encryption.d.ts.map +1 -1
  219. package/dist/secret-encryption.js +65 -25
  220. package/dist/secret-encryption.js.map +1 -1
  221. package/dist/session/channel-reply-processor.d.ts +36 -0
  222. package/dist/session/channel-reply-processor.d.ts.map +1 -0
  223. package/dist/session/channel-reply-processor.js +46 -0
  224. package/dist/session/channel-reply-processor.js.map +1 -0
  225. package/dist/session/channel-session-link-processor.d.ts +39 -0
  226. package/dist/session/channel-session-link-processor.d.ts.map +1 -0
  227. package/dist/session/channel-session-link-processor.js +100 -0
  228. package/dist/session/channel-session-link-processor.js.map +1 -0
  229. package/dist/session/credential-policy.d.ts +1 -1
  230. package/dist/session/credential-policy.d.ts.map +1 -1
  231. package/dist/session/credential-policy.js +7 -6
  232. package/dist/session/credential-policy.js.map +1 -1
  233. package/dist/session/default-model-hydration.d.ts +1 -0
  234. package/dist/session/default-model-hydration.d.ts.map +1 -1
  235. package/dist/session/default-model-hydration.js +3 -2
  236. package/dist/session/default-model-hydration.js.map +1 -1
  237. package/dist/session/environment-state-processor.js +1 -1
  238. package/dist/session/environment-state-processor.js.map +1 -1
  239. package/dist/session/factory-session.d.ts +19 -1
  240. package/dist/session/factory-session.d.ts.map +1 -1
  241. package/dist/session/factory-session.js +5 -2
  242. package/dist/session/factory-session.js.map +1 -1
  243. package/dist/session/filesystem-capture.d.ts +3 -3
  244. package/dist/session/filesystem-capture.d.ts.map +1 -1
  245. package/dist/session/filesystem-capture.js +16 -17
  246. package/dist/session/filesystem-capture.js.map +1 -1
  247. package/dist/session/first-exec-capture.d.ts +1 -1
  248. package/dist/session/first-exec-capture.d.ts.map +1 -1
  249. package/dist/session/first-exec-capture.js +1 -1
  250. package/dist/session/first-exec-capture.js.map +1 -1
  251. package/dist/session/first-message-capture.d.ts +1 -1
  252. package/dist/session/first-message-capture.d.ts.map +1 -1
  253. package/dist/session/first-message-capture.js +1 -1
  254. package/dist/session/first-message-capture.js.map +1 -1
  255. package/dist/session/live-sessions.d.ts +1 -1
  256. package/dist/session/live-sessions.js +1 -1
  257. package/dist/session/live-sessions.js.map +1 -1
  258. package/dist/session/memory-settings-hydration.d.ts +1 -1
  259. package/dist/session/memory-settings-hydration.d.ts.map +1 -1
  260. package/dist/session/memory-settings-hydration.js +1 -1
  261. package/dist/session/memory-settings-hydration.js.map +1 -1
  262. package/dist/session/reply-credential-processor.d.ts +15 -0
  263. package/dist/session/reply-credential-processor.d.ts.map +1 -0
  264. package/dist/session/reply-credential-processor.js +38 -0
  265. package/dist/session/reply-credential-processor.js.map +1 -0
  266. package/dist/session/resource-migration.d.ts +87 -0
  267. package/dist/session/resource-migration.d.ts.map +1 -0
  268. package/dist/session/resource-migration.js +163 -0
  269. package/dist/session/resource-migration.js.map +1 -0
  270. package/dist/session/run-audit.d.ts +24 -0
  271. package/dist/session/run-audit.d.ts.map +1 -1
  272. package/dist/session/run-audit.js +93 -7
  273. package/dist/session/run-audit.js.map +1 -1
  274. package/dist/session/session-threads.d.ts +49 -0
  275. package/dist/session/session-threads.d.ts.map +1 -0
  276. package/dist/session/session-threads.js +70 -0
  277. package/dist/session/session-threads.js.map +1 -0
  278. package/dist/session/source-control-tools.d.ts +19 -1
  279. package/dist/session/source-control-tools.d.ts.map +1 -1
  280. package/dist/session/source-control-tools.js +78 -11
  281. package/dist/session/source-control-tools.js.map +1 -1
  282. package/dist/session/thinking-default.d.ts.map +1 -1
  283. package/dist/session/thinking-default.js +3 -4
  284. package/dist/session/thinking-default.js.map +1 -1
  285. package/dist/session/thread-session-stamp.d.ts +21 -0
  286. package/dist/session/thread-session-stamp.d.ts.map +1 -0
  287. package/dist/session/thread-session-stamp.js +20 -0
  288. package/dist/session/thread-session-stamp.js.map +1 -0
  289. package/dist/session/thread-title-mirror.d.ts +1 -1
  290. package/dist/session/thread-title-mirror.d.ts.map +1 -1
  291. package/dist/session/thread-title-mirror.js +1 -1
  292. package/dist/session/thread-title-mirror.js.map +1 -1
  293. package/dist/session/work-item-repository.d.ts +1 -1
  294. package/dist/session/work-item-repository.d.ts.map +1 -1
  295. package/dist/session/work-item-repository.js.map +1 -1
  296. package/dist/skills/service.d.ts +6 -8
  297. package/dist/skills/service.d.ts.map +1 -1
  298. package/dist/skills/service.js +3 -3
  299. package/dist/skills/service.js.map +1 -1
  300. package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -1
  301. package/dist/storage/domains/audit/agent-audit.js +2 -2
  302. package/dist/storage/domains/audit/agent-audit.js.map +1 -1
  303. package/dist/storage/domains/audit/domain.js +1 -1
  304. package/dist/storage/domains/filesystem/base.d.ts +4 -0
  305. package/dist/storage/domains/filesystem/base.d.ts.map +1 -1
  306. package/dist/storage/domains/filesystem/base.js +5 -0
  307. package/dist/storage/domains/filesystem/base.js.map +1 -1
  308. package/dist/storage/domains/integrations/base.d.ts +8 -0
  309. package/dist/storage/domains/integrations/base.d.ts.map +1 -1
  310. package/dist/storage/domains/integrations/base.js +7 -0
  311. package/dist/storage/domains/integrations/base.js.map +1 -1
  312. package/dist/storage/domains/projects/base.d.ts +6 -0
  313. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  314. package/dist/storage/domains/projects/base.js +12 -0
  315. package/dist/storage/domains/projects/base.js.map +1 -1
  316. package/dist/storage/domains/source-control/base.d.ts +28 -0
  317. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  318. package/dist/storage/domains/source-control/base.js +48 -0
  319. package/dist/storage/domains/source-control/base.js.map +1 -1
  320. package/dist/storage/domains/source-control/inmemory.d.ts +8 -0
  321. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  322. package/dist/storage/domains/source-control/inmemory.js +13 -1
  323. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  324. package/dist/storage/domains/work-items/base.d.ts +79 -7
  325. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  326. package/dist/storage/domains/work-items/base.js +172 -30
  327. package/dist/storage/domains/work-items/base.js.map +1 -1
  328. package/dist/timing.d.ts +23 -0
  329. package/dist/timing.d.ts.map +1 -1
  330. package/dist/timing.js +85 -6
  331. package/dist/timing.js.map +1 -1
  332. package/dist/tools/annotations.d.ts +7 -0
  333. package/dist/tools/annotations.d.ts.map +1 -0
  334. package/dist/tools/annotations.js +102 -0
  335. package/dist/tools/annotations.js.map +1 -0
  336. package/dist/tools/approval-tools.d.ts +15 -0
  337. package/dist/tools/approval-tools.d.ts.map +1 -0
  338. package/dist/tools/approval-tools.js +79 -0
  339. package/dist/tools/approval-tools.js.map +1 -0
  340. package/dist/tools/deliver.d.ts +71 -0
  341. package/dist/tools/deliver.d.ts.map +1 -0
  342. package/dist/tools/deliver.js +129 -0
  343. package/dist/tools/deliver.js.map +1 -0
  344. package/dist/tools/index.d.ts +30 -0
  345. package/dist/tools/index.d.ts.map +1 -0
  346. package/dist/tools/index.js +36 -0
  347. package/dist/tools/index.js.map +1 -0
  348. package/dist/tools/messaging-tools.d.ts +28 -0
  349. package/dist/tools/messaging-tools.d.ts.map +1 -0
  350. package/dist/tools/messaging-tools.js +396 -0
  351. package/dist/tools/messaging-tools.js.map +1 -0
  352. package/dist/tools/permissions.d.ts +31 -0
  353. package/dist/tools/permissions.d.ts.map +1 -0
  354. package/dist/tools/permissions.js +48 -0
  355. package/dist/tools/permissions.js.map +1 -0
  356. package/dist/tools/read-tools.d.ts +30 -0
  357. package/dist/tools/read-tools.d.ts.map +1 -0
  358. package/dist/tools/read-tools.js +293 -0
  359. package/dist/tools/read-tools.js.map +1 -0
  360. package/dist/tools/reports.d.ts +174 -0
  361. package/dist/tools/reports.d.ts.map +1 -0
  362. package/dist/tools/reports.js +380 -0
  363. package/dist/tools/reports.js.map +1 -0
  364. package/dist/tools/run-watch.d.ts +46 -0
  365. package/dist/tools/run-watch.d.ts.map +1 -0
  366. package/dist/tools/run-watch.js +102 -0
  367. package/dist/tools/run-watch.js.map +1 -0
  368. package/dist/tools/scope.d.ts +54 -0
  369. package/dist/tools/scope.d.ts.map +1 -0
  370. package/dist/tools/scope.js +87 -0
  371. package/dist/tools/scope.js.map +1 -0
  372. package/dist/tools/session-tools.d.ts +43 -0
  373. package/dist/tools/session-tools.d.ts.map +1 -0
  374. package/dist/tools/session-tools.js +410 -0
  375. package/dist/tools/session-tools.js.map +1 -0
  376. package/dist/tools/sessions-state-processor.d.ts +41 -0
  377. package/dist/tools/sessions-state-processor.d.ts.map +1 -0
  378. package/dist/tools/sessions-state-processor.js +190 -0
  379. package/dist/tools/sessions-state-processor.js.map +1 -0
  380. package/dist/tools/side-sessions.d.ts +53 -0
  381. package/dist/tools/side-sessions.d.ts.map +1 -0
  382. package/dist/tools/side-sessions.js +83 -0
  383. package/dist/tools/side-sessions.js.map +1 -0
  384. package/dist/tools/work-item-tools.d.ts +28 -0
  385. package/dist/tools/work-item-tools.d.ts.map +1 -0
  386. package/dist/tools/work-item-tools.js +342 -0
  387. package/dist/tools/work-item-tools.js.map +1 -0
  388. package/dist/work-items/create-work-item.d.ts +55 -0
  389. package/dist/work-items/create-work-item.d.ts.map +1 -0
  390. package/dist/work-items/create-work-item.js +101 -0
  391. package/dist/work-items/create-work-item.js.map +1 -0
  392. package/dist/work-items/decision-actions.d.ts +42 -0
  393. package/dist/work-items/decision-actions.d.ts.map +1 -0
  394. package/dist/work-items/decision-actions.js +70 -0
  395. package/dist/work-items/decision-actions.js.map +1 -0
  396. package/dist/workspace.d.ts +1 -1
  397. package/dist/workspace.d.ts.map +1 -1
  398. package/dist/workspace.js +15 -7
  399. package/dist/workspace.js.map +1 -1
  400. package/factory-skills/factory-gitlab-rereview/SKILL.md +1 -1
  401. package/factory-skills/factory-gitlab-review/SKILL.md +1 -1
  402. package/factory-skills/factory-plan/SKILL.md +4 -4
  403. package/factory-skills/factory-rereview/SKILL.md +3 -1
  404. package/factory-skills/factory-review/SKILL.md +3 -1
  405. package/factory-skills/factory-self-review/SKILL.md +46 -0
  406. package/package.json +15 -15
@@ -2,11 +2,27 @@ import { createSlackConnectRoutes } from "./connect-route.js";
2
2
  import { SlackFeedPublisher } from "./feed-publisher.js";
3
3
  import { createSlackChannelsConfig } from "./slack.js";
4
4
  //#region src/integrations/slack/integration.ts
5
+ /** Slack renders the status inline next to the app name; keep it to one short line. */
6
+ const MAX_STATUS_LENGTH = 80;
7
+ /**
8
+ * Turns a tool's `description` arg ("Listing the repo root") into a status
9
+ * line that reads after the app name ("<App> is listing the repo root…").
10
+ * Only the first line counts: issue/PR creators carry whole bodies there.
11
+ */
12
+ function describeToolCall(args) {
13
+ if (!args || typeof args !== "object") return void 0;
14
+ const { description } = args;
15
+ if (typeof description !== "string") return void 0;
16
+ const line = description.split("\n").map((part) => part.replace(/\s+/g, " ").trim()).find(Boolean);
17
+ if (!line) return void 0;
18
+ const text = line.length > MAX_STATUS_LENGTH ? `${line.slice(0, MAX_STATUS_LENGTH - 1)}…` : line;
19
+ return `is ${/^[A-Z][a-z]/.test(text) ? text.charAt(0).toLowerCase() + text.slice(1) : text}`;
20
+ }
5
21
  const factoryTypingStatus = (chunk) => {
6
22
  switch (chunk.type) {
7
23
  case "reasoning-delta": return "is thinking...";
8
24
  case "text-delta": return "is typing...";
9
- case "tool-call": return "is working...";
25
+ case "tool-call": return describeToolCall(chunk.payload.args) ?? "is working...";
10
26
  default: return;
11
27
  }
12
28
  };
@@ -17,6 +33,21 @@ const factoryTypingStatus = (chunk) => {
17
33
  function adapterOverrides(options) {
18
34
  return Object.fromEntries(Object.entries(options ?? {}).filter(([, value]) => value !== void 0));
19
35
  }
36
+ /**
37
+ * Factory defaults under the caller's overrides. Tool calls stay out of the
38
+ * thread: a Factory session runs hundreds of them, and a row per call (or a
39
+ * card per call) buries the reply. Progress shows through the typing status
40
+ * instead, which names the tool's current step; the session link carries the
41
+ * full trace. `grouped` remains available via `adapterOptions` for callers
42
+ * who want Slack's "Thinking Steps" widget.
43
+ */
44
+ function factoryAdapterOptions(overrides) {
45
+ return {
46
+ typingStatus: factoryTypingStatus,
47
+ toolDisplay: "hidden",
48
+ ...overrides
49
+ };
50
+ }
20
51
  var SlackIntegration = class {
21
52
  id = "slack";
22
53
  /**
@@ -52,11 +83,7 @@ var SlackIntegration = class {
52
83
  modelDefaults: ctx.storage.modelDefaults,
53
84
  workItems: ctx.runtime?.workItems,
54
85
  feed: ctx.feed,
55
- adapterOptions: {
56
- toolDisplay: "hidden",
57
- typingStatus: factoryTypingStatus,
58
- ...adapterOverrides(this.#config.adapterOptions)
59
- }
86
+ adapterOptions: factoryAdapterOptions(adapterOverrides(this.#config.adapterOptions))
60
87
  });
61
88
  }
62
89
  feedPublisher(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"integration.js","names":["#config","#repoBackedSessions"],"sources":["../../../src/integrations/slack/integration.ts"],"sourcesContent":["/**\n * `SlackIntegration` — Slack as a `FactoryIntegration`.\n *\n * Slack contributes two things to a factory: the chat channels that carry\n * inbound messages into agent runs (`channels()`), and the browser-facing\n * account-link routes that bind a Slack sender to a Mastra tenant (`routes()`).\n * Both used to be assembled by hand in the deploy entry, which had to reach\n * into the prepared agent controller by string key, resolve storage domains\n * itself, mint its own state signer, and splice routes onto the factory's\n * assembled server config. Implementing the integration interface instead means\n * the factory does all of that the same way it already does for GitHub and\n * Linear, and the entry's job shrinks to reading Slack's env vars once.\n *\n * Slack ships as a factory built-in alongside GitHub and Linear (it originally\n * lived in `mastracode/web` to keep `@mastra/slack`/`chat` out of this package;\n * the team reversed that so `create-factory` consumers get Slack channels out\n * of the box). The integration interface remains open — third parties still add\n * capabilities by implementing `FactoryIntegration` from outside the package.\n */\n\nimport type { TypingStatusFn } from '@mastra/core/channels';\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { SlackAdapterChannelConfig } from '@mastra/slack';\n\nimport type { WorkItemFeedPublisher } from '../../storage/domains/comments/feed-sync.js';\nimport type { FactoryChannelsConfig, FactoryIntegration, IntegrationContext } from '../base.js';\n\nimport { createSlackConnectRoutes } from './connect-route.js';\nimport { SlackFeedPublisher } from './feed-publisher.js';\nimport { createSlackChannelsConfig } from './slack.js';\n\n/**\n * Slack app credentials, read from env ONCE by the deploy entry. `signingSecret`\n * is required because the Slack adapter validates it at construction — an\n * integration constructed without it would throw during `prepare()` rather than\n * reporting itself unconfigured.\n */\nexport interface SlackIntegrationConfig {\n /** Verifies inbound Slack request signatures. Required. */\n signingSecret: string;\n /** Bot token used to post replies and ephemeral cards. */\n botToken?: string;\n /**\n * OAuth client credentials. Required for account linking: \"Sign in with\n * Slack\" (OIDC) is the only flow that writes a link, so without these the\n * settings surface reports `canConnect: false` and no sender can link.\n */\n clientId?: string;\n clientSecret?: string;\n /**\n * HTTPS origin Slack redirects back to. Slack requires HTTPS, so locally this\n * is the tunnel origin rather than the app's own public URL.\n */\n oidcRedirectBaseUrl?: string;\n /** SPA origin the post-connect redirect returns to. */\n uiOrigin?: string;\n /**\n * Overrides for the Slack channel adapter entry.\n *\n * @example\n * ```ts\n * new SlackIntegration({\n * signingSecret,\n * adapterOptions: {\n * streaming: true,\n * toolDisplay: 'grouped',\n * },\n * });\n * ```\n */\n adapterOptions?: SlackAdapterChannelConfig;\n}\n\nconst factoryTypingStatus: TypingStatusFn = chunk => {\n switch (chunk.type) {\n case 'reasoning-delta':\n return 'is thinking...';\n case 'text-delta':\n return 'is typing...';\n case 'tool-call':\n return 'is working...';\n default:\n return undefined;\n }\n};\n\n/**\n * Drops keys the caller set to `undefined` so spreading the overrides cannot\n * erase the Factory defaults they sit on top of.\n */\nfunction adapterOverrides(options: SlackAdapterChannelConfig | undefined): SlackAdapterChannelConfig {\n return Object.fromEntries(\n Object.entries(options ?? {}).filter(([, value]) => value !== undefined),\n ) as SlackAdapterChannelConfig;\n}\n\nexport class SlackIntegration implements FactoryIntegration {\n readonly id = 'slack';\n /**\n * The OIDC connect flow round-trips a signed `state` through Slack, so the\n * replica handling the callback must be able to verify a state a different\n * replica signed.\n */\n readonly requiresStableStateSigner = true;\n\n readonly #config: SlackIntegrationConfig;\n /**\n * Whether `channels()` found a source-control owner on the context and wired\n * repo-backed sessions. Set at the channels() attach path, which runs once at\n * boot before diagnostics are served.\n */\n #repoBackedSessions = false;\n\n constructor(config: SlackIntegrationConfig) {\n if (!config.signingSecret) {\n throw new Error(\n \"SlackIntegration: 'signingSecret' is required — Slack cannot verify inbound requests without it.\",\n );\n }\n this.#config = config;\n }\n\n channels(ctx: IntegrationContext): FactoryChannelsConfig {\n // Repo-backed sessions select the source-control provider from the linked\n // repository on each Factory project.\n const sourceControls =\n ctx.storage.sourceControls ?? (ctx.storage.sourceControlOwner ? [ctx.storage.sourceControlOwner] : []);\n this.#repoBackedSessions = sourceControls.length > 0;\n return createSlackChannelsConfig({\n slack: {\n clientId: this.#config.clientId,\n clientSecret: this.#config.clientSecret,\n signingSecret: this.#config.signingSecret,\n botToken: this.#config.botToken,\n },\n accountLinks: ctx.storage.channelIdentity,\n projects: ctx.storage.projects,\n sourceControls,\n modelDefaults: ctx.storage.modelDefaults,\n workItems: ctx.runtime?.workItems,\n feed: ctx.feed,\n adapterOptions: {\n toolDisplay: 'hidden',\n typingStatus: factoryTypingStatus,\n ...adapterOverrides(this.#config.adapterOptions),\n },\n });\n }\n\n feedPublisher(ctx: IntegrationContext): WorkItemFeedPublisher {\n return new SlackFeedPublisher({ controller: ctx.controller });\n }\n\n routes(ctx: IntegrationContext): ApiRoute[] {\n const { clientId, clientSecret, oidcRedirectBaseUrl, uiOrigin } = this.#config;\n return createSlackConnectRoutes({\n auth: ctx.auth,\n accountLinks: ctx.storage.channelIdentity,\n tenantStateSigner: ctx.stateSigner,\n oidc:\n clientId && clientSecret && oidcRedirectBaseUrl\n ? { clientId, clientSecret, redirectBaseUrl: oidcRedirectBaseUrl, uiOrigin }\n : undefined,\n projects: ctx.storage.projects,\n });\n }\n\n diagnostics(): Record<string, unknown> {\n const { clientId, clientSecret, botToken, oidcRedirectBaseUrl } = this.#config;\n return {\n configured: true,\n botTokenConfigured: Boolean(botToken),\n oidcConfigured: Boolean(clientId && clientSecret && oidcRedirectBaseUrl),\n repoBackedSessions: this.#repoBackedSessions,\n };\n }\n}\n"],"mappings":";;;;AAyEA,MAAM,uBAAsC,UAAS;CACnD,QAAQ,MAAM,MAAd;EACE,KAAK,mBACH,OAAO;EACT,KAAK,cACH,OAAO;EACT,KAAK,aACH,OAAO;EACT,SACE;CACJ;AACF;;;;;AAMA,SAAS,iBAAiB,SAA2E;CACnG,OAAO,OAAO,YACZ,OAAO,QAAQ,WAAW,CA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;GACZ,oBAAoB,QAAQ,QAAQ;GACpC,gBAAgB,QAAQ,YAAY,gBAAgB,mBAAmB;GACvE,oBAAoB,KAAKC;EAC3B;CACF;AACF"}
1
+ {"version":3,"file":"integration.js","names":["#config","#repoBackedSessions"],"sources":["../../../src/integrations/slack/integration.ts"],"sourcesContent":["/**\n * `SlackIntegration` — Slack as a `FactoryIntegration`.\n *\n * Slack contributes two things to a factory: the chat channels that carry\n * inbound messages into agent runs (`channels()`), and the browser-facing\n * account-link routes that bind a Slack sender to a Mastra tenant (`routes()`).\n * Both used to be assembled by hand in the deploy entry, which had to reach\n * into the prepared agent controller by string key, resolve storage domains\n * itself, mint its own state signer, and splice routes onto the factory's\n * assembled server config. Implementing the integration interface instead means\n * the factory does all of that the same way it already does for GitHub and\n * Linear, and the entry's job shrinks to reading Slack's env vars once.\n *\n * Slack ships as a factory built-in alongside GitHub and Linear (it originally\n * lived in `mastracode/web` to keep `@mastra/slack`/`chat` out of this package;\n * the team reversed that so `create-factory` consumers get Slack channels out\n * of the box). The integration interface remains open — third parties still add\n * capabilities by implementing `FactoryIntegration` from outside the package.\n */\n\nimport type { TypingStatusFn } from '@mastra/core/channels';\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { SlackAdapterChannelConfig } from '@mastra/slack';\n\nimport type { WorkItemFeedPublisher } from '../../storage/domains/comments/feed-sync.js';\nimport type { FactoryChannelsConfig, FactoryIntegration, IntegrationContext } from '../base.js';\n\nimport { createSlackConnectRoutes } from './connect-route.js';\nimport { SlackFeedPublisher } from './feed-publisher.js';\nimport { createSlackChannelsConfig } from './slack.js';\n\n/**\n * Slack app credentials, read from env ONCE by the deploy entry. `signingSecret`\n * is required because the Slack adapter validates it at construction — an\n * integration constructed without it would throw during `prepare()` rather than\n * reporting itself unconfigured.\n */\nexport interface SlackIntegrationConfig {\n /** Verifies inbound Slack request signatures. Required. */\n signingSecret: string;\n /** Bot token used to post replies and ephemeral cards. */\n botToken?: string;\n /**\n * OAuth client credentials. Required for account linking: \"Sign in with\n * Slack\" (OIDC) is the only flow that writes a link, so without these the\n * settings surface reports `canConnect: false` and no sender can link.\n */\n clientId?: string;\n clientSecret?: string;\n /**\n * HTTPS origin Slack redirects back to. Slack requires HTTPS, so locally this\n * is the tunnel origin rather than the app's own public URL.\n */\n oidcRedirectBaseUrl?: string;\n /** SPA origin the post-connect redirect returns to. */\n uiOrigin?: string;\n /**\n * Overrides for the Slack channel adapter entry.\n *\n * @example\n * ```ts\n * new SlackIntegration({\n * signingSecret,\n * adapterOptions: {\n * streaming: true,\n * toolDisplay: 'grouped',\n * },\n * });\n * ```\n */\n adapterOptions?: SlackAdapterChannelConfig;\n}\n\n/** Slack renders the status inline next to the app name; keep it to one short line. */\nconst MAX_STATUS_LENGTH = 80;\n\n/**\n * Turns a tool's `description` arg (\"Listing the repo root\") into a status\n * line that reads after the app name (\"<App> is listing the repo root…\").\n * Only the first line counts: issue/PR creators carry whole bodies there.\n */\nfunction describeToolCall(args: unknown): string | undefined {\n if (!args || typeof args !== 'object') return undefined;\n const { description } = args as { description?: unknown };\n if (typeof description !== 'string') return undefined;\n const line = description\n .split('\\n')\n .map(part => part.replace(/\\s+/g, ' ').trim())\n .find(Boolean);\n if (!line) return undefined;\n const text = line.length > MAX_STATUS_LENGTH ? `${line.slice(0, MAX_STATUS_LENGTH - 1)}…` : line;\n // Drop the sentence-case capital (\"Listing\" → \"listing\") but leave acronyms\n // and identifiers (\"PR lookup\", \"CI status\") alone.\n return `is ${/^[A-Z][a-z]/.test(text) ? text.charAt(0).toLowerCase() + text.slice(1) : text}`;\n}\n\nconst factoryTypingStatus: TypingStatusFn = chunk => {\n switch (chunk.type) {\n case 'reasoning-delta':\n return 'is thinking...';\n case 'text-delta':\n return 'is typing...';\n case 'tool-call':\n return describeToolCall(chunk.payload.args) ?? 'is working...';\n default:\n return undefined;\n }\n};\n\n/**\n * Drops keys the caller set to `undefined` so spreading the overrides cannot\n * erase the Factory defaults they sit on top of.\n */\nfunction adapterOverrides(options: SlackAdapterChannelConfig | undefined): SlackAdapterChannelConfig {\n return Object.fromEntries(\n Object.entries(options ?? {}).filter(([, value]) => value !== undefined),\n ) as SlackAdapterChannelConfig;\n}\n\n/**\n * Factory defaults under the caller's overrides. Tool calls stay out of the\n * thread: a Factory session runs hundreds of them, and a row per call (or a\n * card per call) buries the reply. Progress shows through the typing status\n * instead, which names the tool's current step; the session link carries the\n * full trace. `grouped` remains available via `adapterOptions` for callers\n * who want Slack's \"Thinking Steps\" widget.\n */\nfunction factoryAdapterOptions(overrides: SlackAdapterChannelConfig): SlackAdapterChannelConfig {\n return { typingStatus: factoryTypingStatus, toolDisplay: 'hidden', ...overrides };\n}\n\nexport class SlackIntegration implements FactoryIntegration {\n readonly id = 'slack';\n /**\n * The OIDC connect flow round-trips a signed `state` through Slack, so the\n * replica handling the callback must be able to verify a state a different\n * replica signed.\n */\n readonly requiresStableStateSigner = true;\n\n readonly #config: SlackIntegrationConfig;\n /**\n * Whether `channels()` found a source-control owner on the context and wired\n * repo-backed sessions. Set at the channels() attach path, which runs once at\n * boot before diagnostics are served.\n */\n #repoBackedSessions = false;\n\n constructor(config: SlackIntegrationConfig) {\n if (!config.signingSecret) {\n throw new Error(\n \"SlackIntegration: 'signingSecret' is required — Slack cannot verify inbound requests without it.\",\n );\n }\n this.#config = config;\n }\n\n channels(ctx: IntegrationContext): FactoryChannelsConfig {\n // Repo-backed sessions select the source-control provider from the linked\n // repository on each Factory project.\n const sourceControls =\n ctx.storage.sourceControls ?? (ctx.storage.sourceControlOwner ? [ctx.storage.sourceControlOwner] : []);\n this.#repoBackedSessions = sourceControls.length > 0;\n return createSlackChannelsConfig({\n slack: {\n clientId: this.#config.clientId,\n clientSecret: this.#config.clientSecret,\n signingSecret: this.#config.signingSecret,\n botToken: this.#config.botToken,\n },\n accountLinks: ctx.storage.channelIdentity,\n projects: ctx.storage.projects,\n sourceControls,\n modelDefaults: ctx.storage.modelDefaults,\n workItems: ctx.runtime?.workItems,\n feed: ctx.feed,\n adapterOptions: factoryAdapterOptions(adapterOverrides(this.#config.adapterOptions)),\n });\n }\n\n feedPublisher(ctx: IntegrationContext): WorkItemFeedPublisher {\n return new SlackFeedPublisher({ controller: ctx.controller });\n }\n\n routes(ctx: IntegrationContext): ApiRoute[] {\n const { clientId, clientSecret, oidcRedirectBaseUrl, uiOrigin } = this.#config;\n return createSlackConnectRoutes({\n auth: ctx.auth,\n accountLinks: ctx.storage.channelIdentity,\n tenantStateSigner: ctx.stateSigner,\n oidc:\n clientId && clientSecret && oidcRedirectBaseUrl\n ? { clientId, clientSecret, redirectBaseUrl: oidcRedirectBaseUrl, uiOrigin }\n : undefined,\n projects: ctx.storage.projects,\n });\n }\n\n diagnostics(): Record<string, unknown> {\n const { clientId, clientSecret, botToken, oidcRedirectBaseUrl } = this.#config;\n return {\n configured: true,\n botTokenConfigured: Boolean(botToken),\n oidcConfigured: Boolean(clientId && clientSecret && oidcRedirectBaseUrl),\n repoBackedSessions: this.#repoBackedSessions,\n };\n }\n}\n"],"mappings":";;;;;AA0EA,MAAM,oBAAoB;;;;;;AAO1B,SAAS,iBAAiB,MAAmC;CAC3D,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU,OAAO,KAAA;CAC9C,MAAM,EAAE,gBAAgB;CACxB,IAAI,OAAO,gBAAgB,UAAU,OAAO,KAAA;CAC5C,MAAM,OAAO,YACV,MAAM,IAAI,CAAC,CACX,KAAI,SAAQ,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAC7C,KAAK,OAAO;CACf,IAAI,CAAC,MAAM,OAAO,KAAA;CAClB,MAAM,OAAO,KAAK,SAAS,oBAAoB,GAAG,KAAK,MAAM,GAAG,oBAAoB,CAAC,EAAE,KAAK;CAG5F,OAAO,MAAM,cAAc,KAAK,IAAI,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,MAAM,CAAC,IAAI;AACzF;AAEA,MAAM,uBAAsC,UAAS;CACn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;EACvE,OAAO,yBAAyB;GAC9B,MAAM,IAAI;GACV,cAAc,IAAI,QAAQ;GAC1B,mBAAmB,IAAI;GACvB,MACE,YAAY,gBAAgB,sBACxB;IAAE;IAAU;IAAc,iBAAiB;IAAqB;GAAS,IACzE,KAAA;GACN,UAAU,IAAI,QAAQ;EACxB,CAAC;CACH;CAEA,cAAuC;EACrC,MAAM,EAAE,UAAU,cAAc,UAAU,wBAAwB,KAAKA;EACvE,OAAO;GACL,YAAY;GACZ,oBAAoB,QAAQ,QAAQ;GACpC,gBAAgB,QAAQ,YAAY,gBAAgB,mBAAmB;GACvE,oBAAoB,KAAKC;EAC3B;CACF;AACF"}
@@ -121,9 +121,20 @@ export declare function resolveFactoryForLink({ thread, link, key, accountLinks,
121
121
  accountLinks: ChannelIdentityStorage;
122
122
  projects?: FactoryProjectsStorage;
123
123
  }): Promise<FactoryRouteResult>;
124
+ /**
125
+ * Session ids of repo-backed Slack threads, keyed by the message that started
126
+ * them. The resourceId resolver records the session it found or created; the
127
+ * thread-id resolver, which core runs next for the same message, names the new
128
+ * thread after it.
129
+ */
130
+ export type SlackStartedSessions = WeakMap<object, string>;
124
131
  /**
125
132
  * Resolve the resourceId for a NEW Slack channel thread. A linked sender whose
126
- * factory has a repository gets a Factory user-session id — the controller
133
+ * factory has a repository gets a Factory session. A channel thread belongs to
134
+ * the Factory: its resourceId is the Factory id, so the thread shares the
135
+ * Factory's memory. A DM is private to the sender, so it runs under the
136
+ * sender's user id and shares memory with their own sessions. The session id is recorded in `startedSessions` for the
137
+ * thread-id resolver. The controller
127
138
  * session then materializes the repo sandbox via the factory's dynamic
128
139
  * workspace (clone + PAT), the session shows up in the web Sessions list, and
129
140
  * View Session deep-links land on the normal workspace route.
@@ -147,17 +158,17 @@ export declare function resolveFactoryForLink({ thread, link, key, accountLinks,
147
158
  * Pure lookups only — cards for unlinked/unrouted senders are the dispatch
148
159
  * gate's job; this hook must never post.
149
160
  */
150
- export declare function createChannelResourceIdResolver(deps: SlackChannelDeps): ResolveResourceId;
161
+ export declare function createChannelResourceIdResolver(deps: SlackChannelDeps, startedSessions?: SlackStartedSessions): ResolveResourceId;
151
162
  /**
152
163
  * Thread id for a NEW Slack channel thread. Repo-backed threads take the
153
- * user-session id AS their thread id, matching the web convention
164
+ * session id AS their thread id, matching the web convention
154
165
  * (FactoryStartCoordinator seeds threads with threadId = sessionId) so
155
166
  * `/workspaces/{sessionId}/threads/{sessionId}` resolves Slack-created
156
- * sessions exactly like web-created ones — no `?resourceId=` override needed.
167
+ * sessions exactly like web-created ones — no `?sessionId=` override needed.
157
168
  * Chat-only threads keep the default random id: their `channel:...`
158
169
  * resourceId is a memory key, not a unique thread id.
159
170
  */
160
- export declare const resolveChannelThreadId: ResolveThreadId;
171
+ export declare function createChannelThreadIdResolver(startedSessions: SlackStartedSessions): ResolveThreadId;
161
172
  /** Create channel sessions with their Factory ownership present in initial controller state. */
162
173
  export declare function createChannelSessionResolver(deps: SlackChannelDeps): ChannelSessionResolve;
163
174
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"slack.d.ts","sourceRoot":"","sources":["../../../src/integrations/slack/slack.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,cAAc,EAEd,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAgB/D,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,gDAAgD,CAAC;AAGxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AACzF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OA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G;IAAE,KAAK,EAAE,gBAAgB,CAAA;CAAE,GAAG,qBAAqB,CAsBrH"}
@@ -1,8 +1,12 @@
1
1
  import { actorFromChannelAuthor } from "../../storage/domains/comments/actor.js";
2
+ import { FACTORY_INTERACTIVE_KEY } from "../../auth.js";
3
+ import { isRunBound, memoryResourceOf, sessionStampCounts } from "../../session/session-threads.js";
2
4
  import { primeTenantCredentialsForRequestContext, primeTenantCredentialsForTenant } from "../../routes/tenant-credentials.js";
3
5
  import { readRequestContextOrgId, seedSessionOrg } from "../../session/org-seed.js";
4
6
  import { prepareSessionRunContext } from "../subscription-session.js";
5
7
  import { FactorySourceControlConflictError, createSourceControlSessionLookup, hydrateFactorySession, resolveFactorySessionModel, resolveFactorySourceControl, resolvePrimaryEnvironmentRepository } from "../../session/factory-session.js";
8
+ import { FACTORY_SLACK_SENDER_KEY } from "../../tools/scope.js";
9
+ import { markNewChannelSession } from "../../session/channel-session-link-processor.js";
6
10
  import { resolveEmojiShortcodes } from "./emoji.js";
7
11
  import { slackCommentSource } from "./feed-publisher.js";
8
12
  import { ChannelSessionRejectedError } from "@mastra/core/channels";
@@ -149,7 +153,11 @@ function threadBranch(threadId) {
149
153
  }
150
154
  /**
151
155
  * Resolve the resourceId for a NEW Slack channel thread. A linked sender whose
152
- * factory has a repository gets a Factory user-session id — the controller
156
+ * factory has a repository gets a Factory session. A channel thread belongs to
157
+ * the Factory: its resourceId is the Factory id, so the thread shares the
158
+ * Factory's memory. A DM is private to the sender, so it runs under the
159
+ * sender's user id and shares memory with their own sessions. The session id is recorded in `startedSessions` for the
160
+ * thread-id resolver. The controller
153
161
  * session then materializes the repo sandbox via the factory's dynamic
154
162
  * workspace (clone + PAT), the session shows up in the web Sessions list, and
155
163
  * View Session deep-links land on the normal workspace route.
@@ -173,7 +181,7 @@ function threadBranch(threadId) {
173
181
  * Pure lookups only — cards for unlinked/unrouted senders are the dispatch
174
182
  * gate's job; this hook must never post.
175
183
  */
176
- function createChannelResourceIdResolver(deps) {
184
+ function createChannelResourceIdResolver(deps, startedSessions = /* @__PURE__ */ new WeakMap()) {
177
185
  const { accountLinks, projects } = deps;
178
186
  const sourceControls = configuredSourceControls(deps);
179
187
  return async ({ platform, thread, message }) => {
@@ -216,13 +224,17 @@ function createChannelResourceIdResolver(deps) {
216
224
  });
217
225
  if (!repo.found) throw new SlackSessionStartError(repo.reason === "connection" ? "Could not start a session: connect source control to this Factory project." : "Could not start a session: link a repository to this Factory project.");
218
226
  const branch = threadBranch(thread.id);
227
+ const memoryResourceId = thread.isDM ? link.userId : factoryProjectId;
219
228
  const existing = await sourceControl.sessions.getForBranch({
220
229
  factoryProjectId,
221
230
  userId: link.userId,
222
231
  branch
223
232
  });
224
- if (existing) return existing.sessionId;
225
- return (await sourceControl.sessions.create({
233
+ if (existing) {
234
+ startedSessions.set(message, existing.sessionId);
235
+ return memoryResourceId;
236
+ }
237
+ const session = await sourceControl.sessions.create({
226
238
  sessionId: globalThis.crypto.randomUUID(),
227
239
  projectRepositoryId: repo.projectRepositoryId,
228
240
  factoryProjectId,
@@ -231,7 +243,9 @@ function createChannelResourceIdResolver(deps) {
231
243
  branch,
232
244
  baseBranch: repo.baseBranch,
233
245
  visibility: thread.isDM ? "private" : "org"
234
- })).sessionId;
246
+ });
247
+ startedSessions.set(message, session.sessionId);
248
+ return memoryResourceId;
235
249
  } catch (error) {
236
250
  if (error instanceof ChannelSessionRejectedError || error instanceof SlackSessionStartError) throw error;
237
251
  if (error instanceof FactorySourceControlConflictError) throw new SlackSessionStartError("Could not start a session: this Factory project has repositories from more than one source-control provider.", { cause: error });
@@ -242,22 +256,55 @@ function createChannelResourceIdResolver(deps) {
242
256
  }
243
257
  /**
244
258
  * Thread id for a NEW Slack channel thread. Repo-backed threads take the
245
- * user-session id AS their thread id, matching the web convention
259
+ * session id AS their thread id, matching the web convention
246
260
  * (FactoryStartCoordinator seeds threads with threadId = sessionId) so
247
261
  * `/workspaces/{sessionId}/threads/{sessionId}` resolves Slack-created
248
- * sessions exactly like web-created ones — no `?resourceId=` override needed.
262
+ * sessions exactly like web-created ones — no `?sessionId=` override needed.
249
263
  * Chat-only threads keep the default random id: their `channel:...`
250
264
  * resourceId is a memory key, not a unique thread id.
251
265
  */
252
- const resolveChannelThreadId = ({ resourceId, defaultThreadId }) => resourceId.startsWith("channel:") ? defaultThreadId : resourceId;
266
+ function createChannelThreadIdResolver(startedSessions) {
267
+ return ({ message, defaultThreadId }) => startedSessions.get(message) ?? defaultThreadId;
268
+ }
269
+ /**
270
+ * The Factory session a repo-backed Slack thread belongs to. A thread under
271
+ * the Factory resource is stamped with its session id (the startup migration
272
+ * stamps threads it moved there). An unmigrated thread runs under its session
273
+ * id as its resource, and a newer thread is named after its session. A stamp
274
+ * or thread id only counts under that session's memory resource; a thread
275
+ * named after a session it can't claim is refused. With no session row for
276
+ * either, the thread is addressed by its own id and fails authorization like
277
+ * any session without a row.
278
+ */
279
+ const UNCLAIMED_SESSION = Symbol("unclaimed-session");
280
+ async function slackThreadSessionId(sessions, thread, loadThread, runs) {
281
+ if (thread.resourceId.startsWith("channel:")) return null;
282
+ const claims = async (sessionId) => {
283
+ const row = await sessions.getBySessionId(sessionId);
284
+ if (!row) return false;
285
+ if (sessionId !== thread.id && !sessionStampCounts(row, thread.resourceId)) return false;
286
+ const own = sessionId === thread.id ? thread : await loadThread(sessionId);
287
+ return thread.resourceId === memoryResourceOf(row, own, await isRunBound(row, runs));
288
+ };
289
+ const stamped = thread.metadata?.factorySessionId;
290
+ if (typeof stamped === "string" && stamped && await claims(stamped)) return stamped;
291
+ if (await sessions.getSourceControlBySessionId(thread.resourceId)) return thread.resourceId;
292
+ if (await claims(thread.id)) return thread.id;
293
+ if (await sessions.getBySessionId(thread.id)) return UNCLAIMED_SESSION;
294
+ return thread.id;
295
+ }
253
296
  /** Create channel sessions with their Factory ownership present in initial controller state. */
254
297
  function createChannelSessionResolver(deps) {
255
298
  const sourceControlSessions = createSourceControlSessionLookup(configuredSourceControls(deps));
256
299
  return async ({ controller, thread, requestContext }) => {
257
- const sourceControl = thread.resourceId.startsWith("channel:") ? null : await sourceControlSessions.getSourceControlBySessionId(thread.resourceId);
258
- const session = sourceControl ? await sourceControl.sessions.getBySessionId(thread.resourceId) : null;
300
+ const stored = thread.metadata?.factorySessionId || thread.resourceId.startsWith("channel:") ? thread : await controller.queryThreadById({ threadId: thread.id }) ?? thread;
301
+ const resolved = await slackThreadSessionId(sourceControlSessions, stored, (threadId) => controller.queryThreadById({ threadId }), deps.workItems);
302
+ if (resolved === UNCLAIMED_SESSION) throw new Error(`Slack thread ${thread.id} is named after a Factory session it doesn't belong to.`);
303
+ const sessionId = resolved ?? thread.resourceId;
304
+ const sourceControl = sessionId.startsWith("channel:") ? null : await sourceControlSessions.getSourceControlBySessionId(sessionId);
305
+ const session = sourceControl ? await sourceControl.sessions.getBySessionId(sessionId) : null;
259
306
  return controller.createSession({
260
- id: thread.resourceId,
307
+ id: sessionId,
261
308
  ownerId: controller.id,
262
309
  resourceId: thread.resourceId,
263
310
  threadId: thread.id,
@@ -296,15 +343,16 @@ function createChannelSessionStartHook(deps) {
296
343
  await seedSessionOrg(session, readRequestContextOrgId(requestContext));
297
344
  if (!projects) return;
298
345
  if (thread.resourceId.startsWith("channel:")) return;
299
- const sourceControl = await sourceControlSessions.getSourceControlBySessionId(thread.resourceId);
346
+ const sessionId = session.identity.getId();
347
+ const sourceControl = await sourceControlSessions.getSourceControlBySessionId(sessionId);
300
348
  if (!sourceControl) return;
301
- const sourceSession = await sourceControl.sessions.getBySessionId(thread.resourceId);
349
+ const sourceSession = await sourceControl.sessions.getBySessionId(sessionId);
302
350
  if (!sourceSession?.factoryProjectId) return;
303
351
  const threadId = session.thread.getId();
304
352
  const binding = threadId && deps.workItems ? await deps.workItems.findRunBindingByThread({
305
353
  orgId: sourceSession.orgId,
306
- resourceId: thread.resourceId,
307
- sessionId: thread.resourceId,
354
+ resourceId: session.identity.getResourceId(),
355
+ sessionId,
308
356
  threadId,
309
357
  rejectAmbiguous: true
310
358
  }) : null;
@@ -332,11 +380,15 @@ function createChannelSessionStartHook(deps) {
332
380
  userId: owner.userId,
333
381
  credentialScope: sessionModel.modelScope
334
382
  });
335
- const modeId = session.mode.get();
336
383
  const activeThreadId = session.thread.getId();
384
+ if (activeThreadId) await session.thread.setSettingOn({
385
+ threadId: activeThreadId,
386
+ key: "factorySessionId",
387
+ value: sessionId
388
+ });
337
389
  if (await migratePersistedModelSelection({
338
390
  getMetadata: async () => activeThreadId ? (await session.thread.getById({ threadId: activeThreadId }))?.metadata ?? {} : {},
339
- modeId,
391
+ modeId: session.mode.get(),
340
392
  set: (key, value) => activeThreadId ? session.thread.setSettingOn({
341
393
  threadId: activeThreadId,
342
394
  key,
@@ -413,13 +465,17 @@ async function prepareExistingSessionOwnerContext(thread, deps, ctx, options) {
413
465
  return "ready";
414
466
  }
415
467
  if (sourceControls.length === 0 || internalThread.resourceId.startsWith("channel:")) return "ready";
416
- if (!options.expectedOrgId) throw new Error(`Could not authorize the owner of Slack Factory session ${internalThread.resourceId}: the sender's account link has no organization.`);
417
- const preparation = await prepareSessionRunContext(ctx.requestContext, internalThread.resourceId, { sessions: createSourceControlSessionLookup(sourceControls) }, { expectedOrgId: options.expectedOrgId });
468
+ const sessions = createSourceControlSessionLookup(sourceControls);
469
+ const memory = await ctx.mastra?.getStorage()?.getStore("memory");
470
+ const resolved = await slackThreadSessionId(sessions, internalThread, async (threadId) => memory?.getThreadById({ threadId }), deps.workItems);
471
+ if (resolved === UNCLAIMED_SESSION) return "access-denied";
472
+ const sessionId = resolved ?? internalThread.resourceId;
473
+ const sessionRow = await sessions.getBySessionId(sessionId);
474
+ if (sessionRow && sessionRow.orgId === options.expectedOrgId && sessionRow.visibility === "private" && sessionRow.userId !== options.senderUserId) return "access-denied";
475
+ if (!options.expectedOrgId) throw new Error(`Could not authorize the owner of Slack Factory session ${sessionId}: the sender's account link has no organization.`);
476
+ const preparation = await prepareSessionRunContext(ctx.requestContext, sessionId, { sessions }, { expectedOrgId: options.expectedOrgId });
418
477
  if (preparation === "organization-mismatch") return preparation;
419
- if (preparation !== "prepared") {
420
- const reason = preparation === "session-not-found" ? "no source-control session row exists for it, or its project repository row is missing" : "its source-control session row has no organization";
421
- throw new Error(`Could not authorize the owner of Slack Factory session ${internalThread.resourceId}: ${reason}.`);
422
- }
478
+ if (preparation !== "prepared") throw new Error(`Could not authorize the owner of Slack Factory session ${sessionId}: ${preparation === "session-not-found" ? "no source-control session row exists for it, or its project repository row is missing" : "its source-control session row has no organization"}.`);
423
479
  return "ready";
424
480
  }
425
481
  /**
@@ -446,10 +502,16 @@ async function gateDispatch(thread, message, deps, ctx, options = { requireInter
446
502
  id: sender.link.userId,
447
503
  organizationId: sender.link.orgId
448
504
  });
449
- if (await prepareExistingSessionOwnerContext(thread, deps, ctx, {
505
+ const ownerContext = await prepareExistingSessionOwnerContext(thread, deps, ctx, {
450
506
  expectedOrgId: sender.link.orgId,
507
+ senderUserId: sender.link.userId,
451
508
  requireInternalThread: options.requireInternalThread
452
- }) === "organization-mismatch") {
509
+ });
510
+ if (ownerContext === "access-denied") {
511
+ await thread.post("This private Factory session belongs to another user.");
512
+ return null;
513
+ }
514
+ if (ownerContext === "organization-mismatch") {
453
515
  await thread.post("This thread belongs to a Factory session in another organization.");
454
516
  return null;
455
517
  }
@@ -461,10 +523,19 @@ async function gateDispatch(thread, message, deps, ctx, options = { requireInter
461
523
  projects
462
524
  });
463
525
  if (route.status === "blocked") return null;
464
- if (route.status === "resolved") return { routed: {
465
- link: sender.link,
466
- factoryProjectId: route.factoryProjectId
467
- } };
526
+ if (route.status === "resolved") {
527
+ if (sender.link.orgId) {
528
+ ctx.requestContext.set(FACTORY_SLACK_SENDER_KEY, {
529
+ userId: sender.link.userId,
530
+ orgId: sender.link.orgId
531
+ });
532
+ ctx.requestContext.set(FACTORY_INTERACTIVE_KEY, true);
533
+ }
534
+ return { routed: {
535
+ link: sender.link,
536
+ factoryProjectId: route.factoryProjectId
537
+ } };
538
+ }
468
539
  }
469
540
  return {};
470
541
  }
@@ -528,38 +599,37 @@ async function reportPreDispatchError(thread, message, ctx, error) {
528
599
  })}`);
529
600
  }
530
601
  }
602
+ /**
603
+ * What the sender sees while nothing has been posted yet. Core's typing
604
+ * wrapper only sets a status once the agent stream yields its first chunk,
605
+ * and everything before that — credential priming, session rows, the
606
+ * controller start hook, model time-to-first-token — is silent. Pin the same
607
+ * status Factory's `typingStatus` uses for reasoning so the bot visibly
608
+ * "picks up" as soon as the gate passes, and the stream's own status replaces
609
+ * it without a visual change. Slack clears it on the first post; core clears
610
+ * it when a run ends without posting.
611
+ */
612
+ const EARLY_TYPING_STATUS = "is thinking...";
613
+ function acknowledgeReceipt(thread, deps) {
614
+ if (deps.adapterOptions?.typingStatus === false) return;
615
+ thread.startTyping(EARLY_TYPING_STATUS).catch((error) => {
616
+ console.warn("[slack] early typing status failed", {
617
+ thread: thread.id,
618
+ error
619
+ });
620
+ });
621
+ }
531
622
  function createNewSessionChatHandler(deps) {
532
623
  return async (thread, message, defaultHandler, ctx) => {
533
- let gate;
534
- let isNewSession;
535
624
  try {
536
- gate = await gateDispatch(thread, message, deps, ctx);
537
- if (!gate) return;
538
- isNewSession = !await thread.isSubscribed();
625
+ if (!await gateDispatch(thread, message, deps, ctx)) return;
626
+ if (!await thread.isSubscribed()) markNewChannelSession(ctx.requestContext);
627
+ acknowledgeReceipt(thread, deps);
539
628
  } catch (error) {
540
629
  await reportPreDispatchError(thread, message, ctx, error);
541
630
  return;
542
631
  }
543
632
  await defaultHandler(thread, message);
544
- if (!isNewSession) return;
545
- const internalThread = await findInternalThread(ctx.mastra, thread);
546
- if (!internalThread) {
547
- console.warn("[onMention] no internal thread found for", thread.id);
548
- return;
549
- }
550
- const isChatOnly = internalThread.resourceId.startsWith("channel:");
551
- const workspaceSegment = isChatOnly ? "channel" : encodeURIComponent(internalThread.resourceId);
552
- const threadPath = gate.routed ? `/factories/${encodeURIComponent(gate.routed.factoryProjectId)}/workspaces/${workspaceSegment}/threads/${encodeURIComponent(internalThread.id)}` : `/threads/${internalThread.id}`;
553
- const needsResourceParam = isChatOnly || !gate.routed;
554
- const deepLink = process.env.MASTRACODE_PUBLIC_URL ? needsResourceParam ? `${process.env.MASTRACODE_PUBLIC_URL}${threadPath}?resourceId=${encodeURIComponent(internalThread.resourceId)}` : `${process.env.MASTRACODE_PUBLIC_URL}${threadPath}` : void 0;
555
- if (!deepLink) return;
556
- await thread.post(Card({
557
- title: "New session started",
558
- children: [Actions([LinkButton({
559
- url: deepLink,
560
- label: "View session"
561
- })])]
562
- }));
563
633
  };
564
634
  }
565
635
  /**
@@ -622,6 +692,7 @@ const createHandlers = (deps) => {
622
692
  await reportPreDispatchError(thread, message, ctx, error);
623
693
  return;
624
694
  }
695
+ acknowledgeReceipt(thread, deps);
625
696
  await defaultHandler(thread, message);
626
697
  },
627
698
  onMention: newSessionChatHandler,
@@ -633,23 +704,25 @@ function createSlackChannelsConfig(deps) {
633
704
  ...deps.slack,
634
705
  webClientOptions: { timeout: SLACK_REQUEST_TIMEOUT_MS }
635
706
  });
707
+ const slack = deps.adapterOptions?.streaming === false ? {
708
+ adapter,
709
+ ...deps.adapterOptions
710
+ } : {
711
+ adapter,
712
+ ...deps.adapterOptions,
713
+ streaming: deps.adapterOptions?.streaming ?? true
714
+ };
715
+ const startedSessions = /* @__PURE__ */ new WeakMap();
636
716
  return {
637
- adapters: { slack: deps.adapterOptions?.streaming === false ? {
638
- adapter,
639
- ...deps.adapterOptions
640
- } : {
641
- adapter,
642
- ...deps.adapterOptions,
643
- streaming: deps.adapterOptions?.streaming ?? true
644
- } },
717
+ adapters: { slack },
645
718
  handlers: createHandlers(deps),
646
- resolveResourceId: createChannelResourceIdResolver(deps),
647
- resolveThreadId: resolveChannelThreadId,
719
+ resolveResourceId: createChannelResourceIdResolver(deps, startedSessions),
720
+ resolveThreadId: createChannelThreadIdResolver(startedSessions),
648
721
  resolveSession: createChannelSessionResolver(deps),
649
722
  onSessionStart: createChannelSessionStartHook(deps)
650
723
  };
651
724
  }
652
725
  //#endregion
653
- export { createChannelResourceIdResolver, createChannelSessionResolver, createChannelSessionStartHook, createHandlers, createSlackChannelsConfig, resolveChannelThreadId, resolveFactoryForLink, resolveLinkedSender, slackThreadSource };
726
+ export { createChannelResourceIdResolver, createChannelSessionResolver, createChannelSessionStartHook, createChannelThreadIdResolver, createHandlers, createSlackChannelsConfig, resolveFactoryForLink, resolveLinkedSender, slackThreadSource };
654
727
 
655
728
  //# sourceMappingURL=slack.js.map