@mastra/factory 0.0.0-aggregate-trace-20261015182851

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 (926) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +671 -0
  3. package/dist/auth.d.ts +201 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +623 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/boards/define-board.d.ts +111 -0
  8. package/dist/boards/define-board.d.ts.map +1 -0
  9. package/dist/boards/define-board.js +156 -0
  10. package/dist/boards/define-board.js.map +1 -0
  11. package/dist/boards/index.d.ts +14 -0
  12. package/dist/boards/index.d.ts.map +1 -0
  13. package/dist/boards/index.js +21 -0
  14. package/dist/boards/index.js.map +1 -0
  15. package/dist/boards/registry.d.ts +16 -0
  16. package/dist/boards/registry.d.ts.map +1 -0
  17. package/dist/boards/registry.js +25 -0
  18. package/dist/boards/registry.js.map +1 -0
  19. package/dist/boards/relocate.d.ts +21 -0
  20. package/dist/boards/relocate.d.ts.map +1 -0
  21. package/dist/boards/relocate.js +58 -0
  22. package/dist/boards/relocate.js.map +1 -0
  23. package/dist/boards/review.d.ts +6 -0
  24. package/dist/boards/review.d.ts.map +1 -0
  25. package/dist/boards/review.js +104 -0
  26. package/dist/boards/review.js.map +1 -0
  27. package/dist/boards/semantics.d.ts +68 -0
  28. package/dist/boards/semantics.d.ts.map +1 -0
  29. package/dist/boards/semantics.js +119 -0
  30. package/dist/boards/semantics.js.map +1 -0
  31. package/dist/boards/transition-policy.d.ts +67 -0
  32. package/dist/boards/transition-policy.d.ts.map +1 -0
  33. package/dist/boards/transition-policy.js +36 -0
  34. package/dist/boards/transition-policy.js.map +1 -0
  35. package/dist/boards/work-tool-rules.d.ts +8 -0
  36. package/dist/boards/work-tool-rules.d.ts.map +1 -0
  37. package/dist/boards/work-tool-rules.js +20 -0
  38. package/dist/boards/work-tool-rules.js.map +1 -0
  39. package/dist/boards/work-transition-policy.d.ts +3 -0
  40. package/dist/boards/work-transition-policy.d.ts.map +1 -0
  41. package/dist/boards/work-transition-policy.js +46 -0
  42. package/dist/boards/work-transition-policy.js.map +1 -0
  43. package/dist/boards/work.d.ts +4 -0
  44. package/dist/boards/work.d.ts.map +1 -0
  45. package/dist/boards/work.js +222 -0
  46. package/dist/boards/work.js.map +1 -0
  47. package/dist/capabilities/connection.d.ts +9 -0
  48. package/dist/capabilities/connection.d.ts.map +1 -0
  49. package/dist/capabilities/connection.js +1 -0
  50. package/dist/capabilities/intake.d.ts +153 -0
  51. package/dist/capabilities/intake.d.ts.map +1 -0
  52. package/dist/capabilities/intake.js +1 -0
  53. package/dist/capabilities/version-control.d.ts +268 -0
  54. package/dist/capabilities/version-control.d.ts.map +1 -0
  55. package/dist/capabilities/version-control.js +1 -0
  56. package/dist/environment/build-runner.d.ts +72 -0
  57. package/dist/environment/build-runner.d.ts.map +1 -0
  58. package/dist/environment/build-runner.js +131 -0
  59. package/dist/environment/build-runner.js.map +1 -0
  60. package/dist/environment/build-schedule.d.ts +40 -0
  61. package/dist/environment/build-schedule.d.ts.map +1 -0
  62. package/dist/environment/build-schedule.js +94 -0
  63. package/dist/environment/build-schedule.js.map +1 -0
  64. package/dist/environment/build-workflow.d.ts +62 -0
  65. package/dist/environment/build-workflow.d.ts.map +1 -0
  66. package/dist/environment/build-workflow.js +149 -0
  67. package/dist/environment/build-workflow.js.map +1 -0
  68. package/dist/environment/build.d.ts +111 -0
  69. package/dist/environment/build.d.ts.map +1 -0
  70. package/dist/environment/build.js +344 -0
  71. package/dist/environment/build.js.map +1 -0
  72. package/dist/environment/heads.d.ts +36 -0
  73. package/dist/environment/heads.d.ts.map +1 -0
  74. package/dist/environment/heads.js +60 -0
  75. package/dist/environment/heads.js.map +1 -0
  76. package/dist/factory.d.ts +225 -0
  77. package/dist/factory.d.ts.map +1 -0
  78. package/dist/factory.js +1006 -0
  79. package/dist/factory.js.map +1 -0
  80. package/dist/feed-events.d.ts +13 -0
  81. package/dist/feed-events.d.ts.map +1 -0
  82. package/dist/feed-events.js +25 -0
  83. package/dist/feed-events.js.map +1 -0
  84. package/dist/index.d.ts +22 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +15 -0
  87. package/dist/integrations/base.d.ts +302 -0
  88. package/dist/integrations/base.d.ts.map +1 -0
  89. package/dist/integrations/base.js +1 -0
  90. package/dist/integrations/github/acceptance-labels.d.ts +16 -0
  91. package/dist/integrations/github/acceptance-labels.d.ts.map +1 -0
  92. package/dist/integrations/github/acceptance-labels.js +55 -0
  93. package/dist/integrations/github/acceptance-labels.js.map +1 -0
  94. package/dist/integrations/github/app-identity.d.ts +43 -0
  95. package/dist/integrations/github/app-identity.d.ts.map +1 -0
  96. package/dist/integrations/github/app-identity.js +62 -0
  97. package/dist/integrations/github/app-identity.js.map +1 -0
  98. package/dist/integrations/github/commits.d.ts +40 -0
  99. package/dist/integrations/github/commits.d.ts.map +1 -0
  100. package/dist/integrations/github/commits.js +48 -0
  101. package/dist/integrations/github/commits.js.map +1 -0
  102. package/dist/integrations/github/config.d.ts +60 -0
  103. package/dist/integrations/github/config.d.ts.map +1 -0
  104. package/dist/integrations/github/config.js +42 -0
  105. package/dist/integrations/github/config.js.map +1 -0
  106. package/dist/integrations/github/default-rules.d.ts +218 -0
  107. package/dist/integrations/github/default-rules.d.ts.map +1 -0
  108. package/dist/integrations/github/default-rules.js +296 -0
  109. package/dist/integrations/github/default-rules.js.map +1 -0
  110. package/dist/integrations/github/integration.d.ts +270 -0
  111. package/dist/integrations/github/integration.d.ts.map +1 -0
  112. package/dist/integrations/github/integration.js +1375 -0
  113. package/dist/integrations/github/integration.js.map +1 -0
  114. package/dist/integrations/github/issue-reconciler.d.ts +28 -0
  115. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -0
  116. package/dist/integrations/github/issue-reconciler.js +138 -0
  117. package/dist/integrations/github/issue-reconciler.js.map +1 -0
  118. package/dist/integrations/github/pat.d.ts +38 -0
  119. package/dist/integrations/github/pat.d.ts.map +1 -0
  120. package/dist/integrations/github/pat.js +59 -0
  121. package/dist/integrations/github/pat.js.map +1 -0
  122. package/dist/integrations/github/provenance.d.ts +34 -0
  123. package/dist/integrations/github/provenance.d.ts.map +1 -0
  124. package/dist/integrations/github/provenance.js +91 -0
  125. package/dist/integrations/github/provenance.js.map +1 -0
  126. package/dist/integrations/github/reconcile-worker.d.ts +45 -0
  127. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -0
  128. package/dist/integrations/github/reconcile-worker.js +189 -0
  129. package/dist/integrations/github/reconcile-worker.js.map +1 -0
  130. package/dist/integrations/github/reconciliation-config.d.ts +3 -0
  131. package/dist/integrations/github/reconciliation-config.d.ts.map +1 -0
  132. package/dist/integrations/github/reconciliation-config.js +19 -0
  133. package/dist/integrations/github/reconciliation-config.js.map +1 -0
  134. package/dist/integrations/github/routes.d.ts +90 -0
  135. package/dist/integrations/github/routes.d.ts.map +1 -0
  136. package/dist/integrations/github/routes.js +1362 -0
  137. package/dist/integrations/github/routes.js.map +1 -0
  138. package/dist/integrations/github/rules.d.ts +173 -0
  139. package/dist/integrations/github/rules.d.ts.map +1 -0
  140. package/dist/integrations/github/rules.js +1021 -0
  141. package/dist/integrations/github/rules.js.map +1 -0
  142. package/dist/integrations/github/sandbox-release.d.ts +25 -0
  143. package/dist/integrations/github/sandbox-release.d.ts.map +1 -0
  144. package/dist/integrations/github/sandbox-release.js +38 -0
  145. package/dist/integrations/github/sandbox-release.js.map +1 -0
  146. package/dist/integrations/github/sandbox.d.ts +234 -0
  147. package/dist/integrations/github/sandbox.d.ts.map +1 -0
  148. package/dist/integrations/github/sandbox.js +947 -0
  149. package/dist/integrations/github/sandbox.js.map +1 -0
  150. package/dist/integrations/github/session-subscriptions.d.ts +28 -0
  151. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -0
  152. package/dist/integrations/github/session-subscriptions.js +283 -0
  153. package/dist/integrations/github/session-subscriptions.js.map +1 -0
  154. package/dist/integrations/github/settle-or-abort.d.ts +7 -0
  155. package/dist/integrations/github/settle-or-abort.d.ts.map +1 -0
  156. package/dist/integrations/github/settle-or-abort.js +25 -0
  157. package/dist/integrations/github/settle-or-abort.js.map +1 -0
  158. package/dist/integrations/github/stale-reviews.d.ts +22 -0
  159. package/dist/integrations/github/stale-reviews.d.ts.map +1 -0
  160. package/dist/integrations/github/stale-reviews.js +70 -0
  161. package/dist/integrations/github/stale-reviews.js.map +1 -0
  162. package/dist/integrations/github/subscriptions.d.ts +54 -0
  163. package/dist/integrations/github/subscriptions.d.ts.map +1 -0
  164. package/dist/integrations/github/subscriptions.js +64 -0
  165. package/dist/integrations/github/subscriptions.js.map +1 -0
  166. package/dist/integrations/github/token-refresh.d.ts +31 -0
  167. package/dist/integrations/github/token-refresh.d.ts.map +1 -0
  168. package/dist/integrations/github/token-refresh.js +42 -0
  169. package/dist/integrations/github/token-refresh.js.map +1 -0
  170. package/dist/integrations/github/webhook.d.ts +139 -0
  171. package/dist/integrations/github/webhook.d.ts.map +1 -0
  172. package/dist/integrations/github/webhook.js +432 -0
  173. package/dist/integrations/github/webhook.js.map +1 -0
  174. package/dist/integrations/gitlab/agent-tools.d.ts +14 -0
  175. package/dist/integrations/gitlab/agent-tools.d.ts.map +1 -0
  176. package/dist/integrations/gitlab/agent-tools.js +42 -0
  177. package/dist/integrations/gitlab/agent-tools.js.map +1 -0
  178. package/dist/integrations/gitlab/api.d.ts +222 -0
  179. package/dist/integrations/gitlab/api.d.ts.map +1 -0
  180. package/dist/integrations/gitlab/api.js +274 -0
  181. package/dist/integrations/gitlab/api.js.map +1 -0
  182. package/dist/integrations/gitlab/default-rules.d.ts +125 -0
  183. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -0
  184. package/dist/integrations/gitlab/default-rules.js +180 -0
  185. package/dist/integrations/gitlab/default-rules.js.map +1 -0
  186. package/dist/integrations/gitlab/integration.d.ts +138 -0
  187. package/dist/integrations/gitlab/integration.d.ts.map +1 -0
  188. package/dist/integrations/gitlab/integration.js +705 -0
  189. package/dist/integrations/gitlab/integration.js.map +1 -0
  190. package/dist/integrations/gitlab/issue-reconciler.d.ts +6 -0
  191. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -0
  192. package/dist/integrations/gitlab/issue-reconciler.js +123 -0
  193. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -0
  194. package/dist/integrations/gitlab/merge-request-reconciler.d.ts +6 -0
  195. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -0
  196. package/dist/integrations/gitlab/merge-request-reconciler.js +267 -0
  197. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -0
  198. package/dist/integrations/gitlab/reconciler.d.ts +5 -0
  199. package/dist/integrations/gitlab/reconciler.d.ts.map +1 -0
  200. package/dist/integrations/gitlab/reconciler.js +31 -0
  201. package/dist/integrations/gitlab/reconciler.js.map +1 -0
  202. package/dist/integrations/gitlab/reconciliation-config.d.ts +3 -0
  203. package/dist/integrations/gitlab/reconciliation-config.d.ts.map +1 -0
  204. package/dist/integrations/gitlab/reconciliation-config.js +17 -0
  205. package/dist/integrations/gitlab/reconciliation-config.js.map +1 -0
  206. package/dist/integrations/gitlab/routes.d.ts +20 -0
  207. package/dist/integrations/gitlab/routes.d.ts.map +1 -0
  208. package/dist/integrations/gitlab/routes.js +474 -0
  209. package/dist/integrations/gitlab/routes.js.map +1 -0
  210. package/dist/integrations/gitlab/rules.d.ts +35 -0
  211. package/dist/integrations/gitlab/rules.d.ts.map +1 -0
  212. package/dist/integrations/gitlab/rules.js +502 -0
  213. package/dist/integrations/gitlab/rules.js.map +1 -0
  214. package/dist/integrations/gitlab/session-subscriptions.d.ts +32 -0
  215. package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -0
  216. package/dist/integrations/gitlab/session-subscriptions.js +193 -0
  217. package/dist/integrations/gitlab/session-subscriptions.js.map +1 -0
  218. package/dist/integrations/gitlab/subscriptions.d.ts +70 -0
  219. package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -0
  220. package/dist/integrations/gitlab/subscriptions.js +76 -0
  221. package/dist/integrations/gitlab/subscriptions.js.map +1 -0
  222. package/dist/integrations/gitlab/version-control.d.ts +16 -0
  223. package/dist/integrations/gitlab/version-control.d.ts.map +1 -0
  224. package/dist/integrations/gitlab/version-control.js +621 -0
  225. package/dist/integrations/gitlab/version-control.js.map +1 -0
  226. package/dist/integrations/gitlab/webhook-dispatch.d.ts +75 -0
  227. package/dist/integrations/gitlab/webhook-dispatch.d.ts.map +1 -0
  228. package/dist/integrations/gitlab/webhook-dispatch.js +235 -0
  229. package/dist/integrations/gitlab/webhook-dispatch.js.map +1 -0
  230. package/dist/integrations/gitlab/webhook.d.ts +72 -0
  231. package/dist/integrations/gitlab/webhook.d.ts.map +1 -0
  232. package/dist/integrations/gitlab/webhook.js +201 -0
  233. package/dist/integrations/gitlab/webhook.js.map +1 -0
  234. package/dist/integrations/incidentio/agent-tools.d.ts +49 -0
  235. package/dist/integrations/incidentio/agent-tools.d.ts.map +1 -0
  236. package/dist/integrations/incidentio/agent-tools.js +90 -0
  237. package/dist/integrations/incidentio/agent-tools.js.map +1 -0
  238. package/dist/integrations/incidentio/api.d.ts +400 -0
  239. package/dist/integrations/incidentio/api.d.ts.map +1 -0
  240. package/dist/integrations/incidentio/api.js +192 -0
  241. package/dist/integrations/incidentio/api.js.map +1 -0
  242. package/dist/integrations/incidentio/claim.d.ts +8 -0
  243. package/dist/integrations/incidentio/claim.d.ts.map +1 -0
  244. package/dist/integrations/incidentio/claim.js +14 -0
  245. package/dist/integrations/incidentio/claim.js.map +1 -0
  246. package/dist/integrations/incidentio/default-rules.d.ts +46 -0
  247. package/dist/integrations/incidentio/default-rules.d.ts.map +1 -0
  248. package/dist/integrations/incidentio/default-rules.js +68 -0
  249. package/dist/integrations/incidentio/default-rules.js.map +1 -0
  250. package/dist/integrations/incidentio/intake.d.ts +10 -0
  251. package/dist/integrations/incidentio/intake.d.ts.map +1 -0
  252. package/dist/integrations/incidentio/intake.js +307 -0
  253. package/dist/integrations/incidentio/intake.js.map +1 -0
  254. package/dist/integrations/incidentio/integration.d.ts +63 -0
  255. package/dist/integrations/incidentio/integration.d.ts.map +1 -0
  256. package/dist/integrations/incidentio/integration.js +141 -0
  257. package/dist/integrations/incidentio/integration.js.map +1 -0
  258. package/dist/integrations/incidentio/issue-reconciler.d.ts +10 -0
  259. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -0
  260. package/dist/integrations/incidentio/issue-reconciler.js +75 -0
  261. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -0
  262. package/dist/integrations/incidentio/reconciliation-config.d.ts +3 -0
  263. package/dist/integrations/incidentio/reconciliation-config.d.ts.map +1 -0
  264. package/dist/integrations/incidentio/reconciliation-config.js +17 -0
  265. package/dist/integrations/incidentio/reconciliation-config.js.map +1 -0
  266. package/dist/integrations/incidentio/routes.d.ts +76 -0
  267. package/dist/integrations/incidentio/routes.d.ts.map +1 -0
  268. package/dist/integrations/incidentio/routes.js +249 -0
  269. package/dist/integrations/incidentio/routes.js.map +1 -0
  270. package/dist/integrations/incidentio/rules.d.ts +55 -0
  271. package/dist/integrations/incidentio/rules.d.ts.map +1 -0
  272. package/dist/integrations/incidentio/rules.js +189 -0
  273. package/dist/integrations/incidentio/rules.js.map +1 -0
  274. package/dist/integrations/issue-reconcile-worker.d.ts +19 -0
  275. package/dist/integrations/issue-reconcile-worker.d.ts.map +1 -0
  276. package/dist/integrations/issue-reconcile-worker.js +97 -0
  277. package/dist/integrations/issue-reconcile-worker.js.map +1 -0
  278. package/dist/integrations/issue-reconciler.d.ts +51 -0
  279. package/dist/integrations/issue-reconciler.d.ts.map +1 -0
  280. package/dist/integrations/issue-reconciler.js +158 -0
  281. package/dist/integrations/issue-reconciler.js.map +1 -0
  282. package/dist/integrations/jira/adf.d.ts +26 -0
  283. package/dist/integrations/jira/adf.d.ts.map +1 -0
  284. package/dist/integrations/jira/adf.js +73 -0
  285. package/dist/integrations/jira/adf.js.map +1 -0
  286. package/dist/integrations/jira/agent-tools.d.ts +45 -0
  287. package/dist/integrations/jira/agent-tools.d.ts.map +1 -0
  288. package/dist/integrations/jira/agent-tools.js +87 -0
  289. package/dist/integrations/jira/agent-tools.js.map +1 -0
  290. package/dist/integrations/jira/api.d.ts +157 -0
  291. package/dist/integrations/jira/api.d.ts.map +1 -0
  292. package/dist/integrations/jira/api.js +141 -0
  293. package/dist/integrations/jira/api.js.map +1 -0
  294. package/dist/integrations/jira/claim.d.ts +9 -0
  295. package/dist/integrations/jira/claim.d.ts.map +1 -0
  296. package/dist/integrations/jira/claim.js +15 -0
  297. package/dist/integrations/jira/claim.js.map +1 -0
  298. package/dist/integrations/jira/default-rules.d.ts +47 -0
  299. package/dist/integrations/jira/default-rules.d.ts.map +1 -0
  300. package/dist/integrations/jira/default-rules.js +69 -0
  301. package/dist/integrations/jira/default-rules.js.map +1 -0
  302. package/dist/integrations/jira/integration.d.ts +114 -0
  303. package/dist/integrations/jira/integration.d.ts.map +1 -0
  304. package/dist/integrations/jira/integration.js +407 -0
  305. package/dist/integrations/jira/integration.js.map +1 -0
  306. package/dist/integrations/jira/issue-reconciler.d.ts +10 -0
  307. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -0
  308. package/dist/integrations/jira/issue-reconciler.js +70 -0
  309. package/dist/integrations/jira/issue-reconciler.js.map +1 -0
  310. package/dist/integrations/jira/reconciliation-config.d.ts +3 -0
  311. package/dist/integrations/jira/reconciliation-config.d.ts.map +1 -0
  312. package/dist/integrations/jira/reconciliation-config.js +17 -0
  313. package/dist/integrations/jira/reconciliation-config.js.map +1 -0
  314. package/dist/integrations/jira/routes.d.ts +54 -0
  315. package/dist/integrations/jira/routes.d.ts.map +1 -0
  316. package/dist/integrations/jira/routes.js +260 -0
  317. package/dist/integrations/jira/routes.js.map +1 -0
  318. package/dist/integrations/jira/rules.d.ts +57 -0
  319. package/dist/integrations/jira/rules.d.ts.map +1 -0
  320. package/dist/integrations/jira/rules.js +189 -0
  321. package/dist/integrations/jira/rules.js.map +1 -0
  322. package/dist/integrations/linear/agent-tools.d.ts +34 -0
  323. package/dist/integrations/linear/agent-tools.d.ts.map +1 -0
  324. package/dist/integrations/linear/agent-tools.js +87 -0
  325. package/dist/integrations/linear/agent-tools.js.map +1 -0
  326. package/dist/integrations/linear/claim.d.ts +8 -0
  327. package/dist/integrations/linear/claim.d.ts.map +1 -0
  328. package/dist/integrations/linear/claim.js +14 -0
  329. package/dist/integrations/linear/claim.js.map +1 -0
  330. package/dist/integrations/linear/default-rules.d.ts +46 -0
  331. package/dist/integrations/linear/default-rules.d.ts.map +1 -0
  332. package/dist/integrations/linear/default-rules.js +70 -0
  333. package/dist/integrations/linear/default-rules.js.map +1 -0
  334. package/dist/integrations/linear/integration.d.ts +260 -0
  335. package/dist/integrations/linear/integration.d.ts.map +1 -0
  336. package/dist/integrations/linear/integration.js +900 -0
  337. package/dist/integrations/linear/integration.js.map +1 -0
  338. package/dist/integrations/linear/issue-reconciler.d.ts +8 -0
  339. package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -0
  340. package/dist/integrations/linear/issue-reconciler.js +73 -0
  341. package/dist/integrations/linear/issue-reconciler.js.map +1 -0
  342. package/dist/integrations/linear/reconciliation-config.d.ts +3 -0
  343. package/dist/integrations/linear/reconciliation-config.d.ts.map +1 -0
  344. package/dist/integrations/linear/reconciliation-config.js +21 -0
  345. package/dist/integrations/linear/reconciliation-config.js.map +1 -0
  346. package/dist/integrations/linear/routes.d.ts +81 -0
  347. package/dist/integrations/linear/routes.d.ts.map +1 -0
  348. package/dist/integrations/linear/routes.js +380 -0
  349. package/dist/integrations/linear/routes.js.map +1 -0
  350. package/dist/integrations/linear/rules.d.ts +54 -0
  351. package/dist/integrations/linear/rules.d.ts.map +1 -0
  352. package/dist/integrations/linear/rules.js +189 -0
  353. package/dist/integrations/linear/rules.js.map +1 -0
  354. package/dist/integrations/linear/storage.d.ts +65 -0
  355. package/dist/integrations/linear/storage.d.ts.map +1 -0
  356. package/dist/integrations/linear/storage.js +1 -0
  357. package/dist/integrations/platform/api-client.d.ts +26 -0
  358. package/dist/integrations/platform/api-client.d.ts.map +1 -0
  359. package/dist/integrations/platform/api-client.js +177 -0
  360. package/dist/integrations/platform/api-client.js.map +1 -0
  361. package/dist/integrations/platform/connect/routes.d.ts +39 -0
  362. package/dist/integrations/platform/connect/routes.d.ts.map +1 -0
  363. package/dist/integrations/platform/connect/routes.js +133 -0
  364. package/dist/integrations/platform/connect/routes.js.map +1 -0
  365. package/dist/integrations/platform/github/event-worker.d.ts +58 -0
  366. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -0
  367. package/dist/integrations/platform/github/event-worker.js +449 -0
  368. package/dist/integrations/platform/github/event-worker.js.map +1 -0
  369. package/dist/integrations/platform/github/integration.d.ts +89 -0
  370. package/dist/integrations/platform/github/integration.d.ts.map +1 -0
  371. package/dist/integrations/platform/github/integration.js +1266 -0
  372. package/dist/integrations/platform/github/integration.js.map +1 -0
  373. package/dist/integrations/platform/gitlab/event-worker.d.ts +64 -0
  374. package/dist/integrations/platform/gitlab/event-worker.d.ts.map +1 -0
  375. package/dist/integrations/platform/gitlab/event-worker.js +305 -0
  376. package/dist/integrations/platform/gitlab/event-worker.js.map +1 -0
  377. package/dist/integrations/platform/gitlab/integration.d.ts +57 -0
  378. package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -0
  379. package/dist/integrations/platform/gitlab/integration.js +113 -0
  380. package/dist/integrations/platform/gitlab/integration.js.map +1 -0
  381. package/dist/integrations/platform/incidentio/integration.d.ts +74 -0
  382. package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -0
  383. package/dist/integrations/platform/incidentio/integration.js +406 -0
  384. package/dist/integrations/platform/incidentio/integration.js.map +1 -0
  385. package/dist/integrations/platform/jira/agent-tools.d.ts +36 -0
  386. package/dist/integrations/platform/jira/agent-tools.d.ts.map +1 -0
  387. package/dist/integrations/platform/jira/agent-tools.js +85 -0
  388. package/dist/integrations/platform/jira/agent-tools.js.map +1 -0
  389. package/dist/integrations/platform/jira/integration.d.ts +65 -0
  390. package/dist/integrations/platform/jira/integration.d.ts.map +1 -0
  391. package/dist/integrations/platform/jira/integration.js +546 -0
  392. package/dist/integrations/platform/jira/integration.js.map +1 -0
  393. package/dist/integrations/platform/jira/routes.d.ts +55 -0
  394. package/dist/integrations/platform/jira/routes.d.ts.map +1 -0
  395. package/dist/integrations/platform/jira/routes.js +274 -0
  396. package/dist/integrations/platform/jira/routes.js.map +1 -0
  397. package/dist/integrations/platform/linear/event-worker.d.ts +105 -0
  398. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -0
  399. package/dist/integrations/platform/linear/event-worker.js +379 -0
  400. package/dist/integrations/platform/linear/event-worker.js.map +1 -0
  401. package/dist/integrations/platform/linear/integration.d.ts +92 -0
  402. package/dist/integrations/platform/linear/integration.d.ts.map +1 -0
  403. package/dist/integrations/platform/linear/integration.js +754 -0
  404. package/dist/integrations/platform/linear/integration.js.map +1 -0
  405. package/dist/integrations/pull-request-head.d.ts +18 -0
  406. package/dist/integrations/pull-request-head.d.ts.map +1 -0
  407. package/dist/integrations/pull-request-head.js +45 -0
  408. package/dist/integrations/pull-request-head.js.map +1 -0
  409. package/dist/integrations/reconciliation-config.d.ts +3 -0
  410. package/dist/integrations/reconciliation-config.d.ts.map +1 -0
  411. package/dist/integrations/reconciliation-config.js +16 -0
  412. package/dist/integrations/reconciliation-config.js.map +1 -0
  413. package/dist/integrations/slack/connect-route.d.ts +46 -0
  414. package/dist/integrations/slack/connect-route.d.ts.map +1 -0
  415. package/dist/integrations/slack/connect-route.js +186 -0
  416. package/dist/integrations/slack/connect-route.js.map +1 -0
  417. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +8 -0
  418. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +1 -0
  419. package/dist/integrations/slack/emoji-shortcodes.generated.js +1985 -0
  420. package/dist/integrations/slack/emoji-shortcodes.generated.js.map +1 -0
  421. package/dist/integrations/slack/emoji.d.ts +3 -0
  422. package/dist/integrations/slack/emoji.d.ts.map +1 -0
  423. package/dist/integrations/slack/emoji.js +12 -0
  424. package/dist/integrations/slack/emoji.js.map +1 -0
  425. package/dist/integrations/slack/feed-publisher.d.ts +26 -0
  426. package/dist/integrations/slack/feed-publisher.d.ts.map +1 -0
  427. package/dist/integrations/slack/feed-publisher.js +44 -0
  428. package/dist/integrations/slack/feed-publisher.js.map +1 -0
  429. package/dist/integrations/slack/integration.d.ts +80 -0
  430. package/dist/integrations/slack/integration.d.ts.map +1 -0
  431. package/dist/integrations/slack/integration.js +93 -0
  432. package/dist/integrations/slack/integration.js.map +1 -0
  433. package/dist/integrations/slack/slack.d.ts +205 -0
  434. package/dist/integrations/slack/slack.d.ts.map +1 -0
  435. package/dist/integrations/slack/slack.js +653 -0
  436. package/dist/integrations/slack/slack.js.map +1 -0
  437. package/dist/integrations/subscription-session.d.ts +49 -0
  438. package/dist/integrations/subscription-session.d.ts.map +1 -0
  439. package/dist/integrations/subscription-session.js +103 -0
  440. package/dist/integrations/subscription-session.js.map +1 -0
  441. package/dist/integrations/workos/integration.d.ts +39 -0
  442. package/dist/integrations/workos/integration.d.ts.map +1 -0
  443. package/dist/integrations/workos/integration.js +91 -0
  444. package/dist/integrations/workos/integration.js.map +1 -0
  445. package/dist/packages/_internals/workspace/dist/index.js +48 -0
  446. package/dist/packages/_internals/workspace/dist/index.js.map +1 -0
  447. package/dist/platform-auth-host.d.ts +4 -0
  448. package/dist/platform-auth-host.d.ts.map +1 -0
  449. package/dist/platform-auth-host.js +18 -0
  450. package/dist/platform-auth-host.js.map +1 -0
  451. package/dist/review-verdict.d.ts +6 -0
  452. package/dist/review-verdict.d.ts.map +1 -0
  453. package/dist/review-verdict.js +14 -0
  454. package/dist/review-verdict.js.map +1 -0
  455. package/dist/routes/attention-activity.d.ts +23 -0
  456. package/dist/routes/attention-activity.d.ts.map +1 -0
  457. package/dist/routes/attention-activity.js +152 -0
  458. package/dist/routes/attention-activity.js.map +1 -0
  459. package/dist/routes/attention-parked.d.ts +22 -0
  460. package/dist/routes/attention-parked.d.ts.map +1 -0
  461. package/dist/routes/attention-parked.js +136 -0
  462. package/dist/routes/attention-parked.js.map +1 -0
  463. package/dist/routes/attention-proposed.d.ts +3 -0
  464. package/dist/routes/attention-proposed.d.ts.map +1 -0
  465. package/dist/routes/attention-proposed.js +21 -0
  466. package/dist/routes/attention-proposed.js.map +1 -0
  467. package/dist/routes/attention-providers.d.ts +159 -0
  468. package/dist/routes/attention-providers.d.ts.map +1 -0
  469. package/dist/routes/attention-providers.js +524 -0
  470. package/dist/routes/attention-providers.js.map +1 -0
  471. package/dist/routes/attention.d.ts +23 -0
  472. package/dist/routes/attention.d.ts.map +1 -0
  473. package/dist/routes/attention.js +219 -0
  474. package/dist/routes/attention.js.map +1 -0
  475. package/dist/routes/automation-runs.d.ts +37 -0
  476. package/dist/routes/automation-runs.d.ts.map +1 -0
  477. package/dist/routes/automation-runs.js +196 -0
  478. package/dist/routes/automation-runs.js.map +1 -0
  479. package/dist/routes/config.d.ts +238 -0
  480. package/dist/routes/config.d.ts.map +1 -0
  481. package/dist/routes/config.js +1011 -0
  482. package/dist/routes/config.js.map +1 -0
  483. package/dist/routes/contracts.d.ts +1080 -0
  484. package/dist/routes/contracts.d.ts.map +1 -0
  485. package/dist/routes/contracts.js +673 -0
  486. package/dist/routes/contracts.js.map +1 -0
  487. package/dist/routes/custom-provider-source.d.ts +52 -0
  488. package/dist/routes/custom-provider-source.d.ts.map +1 -0
  489. package/dist/routes/custom-provider-source.js +124 -0
  490. package/dist/routes/custom-provider-source.js.map +1 -0
  491. package/dist/routes/fs.d.ts +189 -0
  492. package/dist/routes/fs.d.ts.map +1 -0
  493. package/dist/routes/fs.js +916 -0
  494. package/dist/routes/fs.js.map +1 -0
  495. package/dist/routes/intake.d.ts +64 -0
  496. package/dist/routes/intake.d.ts.map +1 -0
  497. package/dist/routes/intake.js +627 -0
  498. package/dist/routes/intake.js.map +1 -0
  499. package/dist/routes/knowledge.d.ts +247 -0
  500. package/dist/routes/knowledge.d.ts.map +1 -0
  501. package/dist/routes/knowledge.js +1128 -0
  502. package/dist/routes/knowledge.js.map +1 -0
  503. package/dist/routes/oauth.d.ts +43 -0
  504. package/dist/routes/oauth.d.ts.map +1 -0
  505. package/dist/routes/oauth.js +477 -0
  506. package/dist/routes/oauth.js.map +1 -0
  507. package/dist/routes/projects.d.ts +68 -0
  508. package/dist/routes/projects.d.ts.map +1 -0
  509. package/dist/routes/projects.js +919 -0
  510. package/dist/routes/projects.js.map +1 -0
  511. package/dist/routes/provider-credentials.d.ts +82 -0
  512. package/dist/routes/provider-credentials.d.ts.map +1 -0
  513. package/dist/routes/provider-credentials.js +80 -0
  514. package/dist/routes/provider-credentials.js.map +1 -0
  515. package/dist/routes/route.d.ts +48 -0
  516. package/dist/routes/route.d.ts.map +1 -0
  517. package/dist/routes/route.js +15 -0
  518. package/dist/routes/route.js.map +1 -0
  519. package/dist/routes/skills.d.ts +30 -0
  520. package/dist/routes/skills.d.ts.map +1 -0
  521. package/dist/routes/skills.js +198 -0
  522. package/dist/routes/skills.js.map +1 -0
  523. package/dist/routes/source-control-sessions.d.ts +22 -0
  524. package/dist/routes/source-control-sessions.d.ts.map +1 -0
  525. package/dist/routes/source-control-sessions.js +356 -0
  526. package/dist/routes/source-control-sessions.js.map +1 -0
  527. package/dist/routes/source-control-settings.d.ts +10 -0
  528. package/dist/routes/source-control-settings.d.ts.map +1 -0
  529. package/dist/routes/source-control-settings.js +87 -0
  530. package/dist/routes/source-control-settings.js.map +1 -0
  531. package/dist/routes/supervisor.d.ts +25 -0
  532. package/dist/routes/supervisor.d.ts.map +1 -0
  533. package/dist/routes/supervisor.js +35 -0
  534. package/dist/routes/supervisor.js.map +1 -0
  535. package/dist/routes/surface.d.ts +133 -0
  536. package/dist/routes/surface.d.ts.map +1 -0
  537. package/dist/routes/surface.js +518 -0
  538. package/dist/routes/surface.js.map +1 -0
  539. package/dist/routes/telemetry.d.ts +13 -0
  540. package/dist/routes/telemetry.d.ts.map +1 -0
  541. package/dist/routes/telemetry.js +60 -0
  542. package/dist/routes/telemetry.js.map +1 -0
  543. package/dist/routes/tenant-credentials.d.ts +87 -0
  544. package/dist/routes/tenant-credentials.d.ts.map +1 -0
  545. package/dist/routes/tenant-credentials.js +219 -0
  546. package/dist/routes/tenant-credentials.js.map +1 -0
  547. package/dist/routes/work-items.d.ts +49 -0
  548. package/dist/routes/work-items.d.ts.map +1 -0
  549. package/dist/routes/work-items.js +633 -0
  550. package/dist/routes/work-items.js.map +1 -0
  551. package/dist/rules/binding-context.d.ts +59 -0
  552. package/dist/rules/binding-context.d.ts.map +1 -0
  553. package/dist/rules/binding-context.js +134 -0
  554. package/dist/rules/binding-context.js.map +1 -0
  555. package/dist/rules/decision-applicability.d.ts +32 -0
  556. package/dist/rules/decision-applicability.d.ts.map +1 -0
  557. package/dist/rules/decision-applicability.js +56 -0
  558. package/dist/rules/decision-applicability.js.map +1 -0
  559. package/dist/rules/dispatch-errors.d.ts +13 -0
  560. package/dist/rules/dispatch-errors.d.ts.map +1 -0
  561. package/dist/rules/dispatch-errors.js +105 -0
  562. package/dist/rules/dispatch-errors.js.map +1 -0
  563. package/dist/rules/dispatcher.d.ts +86 -0
  564. package/dist/rules/dispatcher.d.ts.map +1 -0
  565. package/dist/rules/dispatcher.js +1159 -0
  566. package/dist/rules/dispatcher.js.map +1 -0
  567. package/dist/rules/event-rules.d.ts +23 -0
  568. package/dist/rules/event-rules.d.ts.map +1 -0
  569. package/dist/rules/event-rules.js +46 -0
  570. package/dist/rules/event-rules.js.map +1 -0
  571. package/dist/rules/index.d.ts +6 -0
  572. package/dist/rules/index.d.ts.map +1 -0
  573. package/dist/rules/index.js +4 -0
  574. package/dist/rules/processor.d.ts +90 -0
  575. package/dist/rules/processor.d.ts.map +1 -0
  576. package/dist/rules/processor.js +486 -0
  577. package/dist/rules/processor.js.map +1 -0
  578. package/dist/rules/resolve.d.ts +15 -0
  579. package/dist/rules/resolve.d.ts.map +1 -0
  580. package/dist/rules/resolve.js +23 -0
  581. package/dist/rules/resolve.js.map +1 -0
  582. package/dist/rules/review-source-tool.d.ts +105 -0
  583. package/dist/rules/review-source-tool.d.ts.map +1 -0
  584. package/dist/rules/review-source-tool.js +109 -0
  585. package/dist/rules/review-source-tool.js.map +1 -0
  586. package/dist/rules/start-coordinator.d.ts +64 -0
  587. package/dist/rules/start-coordinator.d.ts.map +1 -0
  588. package/dist/rules/start-coordinator.js +246 -0
  589. package/dist/rules/start-coordinator.js.map +1 -0
  590. package/dist/rules/terminal-cleanup.d.ts +38 -0
  591. package/dist/rules/terminal-cleanup.d.ts.map +1 -0
  592. package/dist/rules/terminal-cleanup.js +68 -0
  593. package/dist/rules/terminal-cleanup.js.map +1 -0
  594. package/dist/rules/tools.d.ts +15 -0
  595. package/dist/rules/tools.d.ts.map +1 -0
  596. package/dist/rules/tools.js +185 -0
  597. package/dist/rules/tools.js.map +1 -0
  598. package/dist/rules/transition-service.d.ts +93 -0
  599. package/dist/rules/transition-service.d.ts.map +1 -0
  600. package/dist/rules/transition-service.js +402 -0
  601. package/dist/rules/transition-service.js.map +1 -0
  602. package/dist/rules/types.d.ts +553 -0
  603. package/dist/rules/types.d.ts.map +1 -0
  604. package/dist/rules/types.js +154 -0
  605. package/dist/rules/types.js.map +1 -0
  606. package/dist/rules/validation.d.ts +21 -0
  607. package/dist/rules/validation.d.ts.map +1 -0
  608. package/dist/rules/validation.js +327 -0
  609. package/dist/rules/validation.js.map +1 -0
  610. package/dist/sandbox/callback-factory-sandbox.d.ts +15 -0
  611. package/dist/sandbox/callback-factory-sandbox.d.ts.map +1 -0
  612. package/dist/sandbox/callback-factory-sandbox.js +22 -0
  613. package/dist/sandbox/callback-factory-sandbox.js.map +1 -0
  614. package/dist/sandbox/git-ref.d.ts +7 -0
  615. package/dist/sandbox/git-ref.d.ts.map +1 -0
  616. package/dist/sandbox/git-ref.js +15 -0
  617. package/dist/sandbox/git-ref.js.map +1 -0
  618. package/dist/sandbox/local-factory-sandbox.d.ts +20 -0
  619. package/dist/sandbox/local-factory-sandbox.d.ts.map +1 -0
  620. package/dist/sandbox/local-factory-sandbox.js +27 -0
  621. package/dist/sandbox/local-factory-sandbox.js.map +1 -0
  622. package/dist/sandbox/materialization.d.ts +41 -0
  623. package/dist/sandbox/materialization.d.ts.map +1 -0
  624. package/dist/sandbox/materialization.js +18 -0
  625. package/dist/sandbox/materialization.js.map +1 -0
  626. package/dist/sandbox/session-retirement.d.ts +45 -0
  627. package/dist/sandbox/session-retirement.d.ts.map +1 -0
  628. package/dist/sandbox/session-retirement.js +153 -0
  629. package/dist/sandbox/session-retirement.js.map +1 -0
  630. package/dist/sandbox/session-sandbox.d.ts +185 -0
  631. package/dist/sandbox/session-sandbox.d.ts.map +1 -0
  632. package/dist/sandbox/session-sandbox.js +248 -0
  633. package/dist/sandbox/session-sandbox.js.map +1 -0
  634. package/dist/sandbox/workdir.d.ts +45 -0
  635. package/dist/sandbox/workdir.d.ts.map +1 -0
  636. package/dist/sandbox/workdir.js +64 -0
  637. package/dist/sandbox/workdir.js.map +1 -0
  638. package/dist/secret-encryption.d.ts +25 -0
  639. package/dist/secret-encryption.d.ts.map +1 -0
  640. package/dist/secret-encryption.js +107 -0
  641. package/dist/secret-encryption.js.map +1 -0
  642. package/dist/server-error.d.ts +12 -0
  643. package/dist/server-error.d.ts.map +1 -0
  644. package/dist/server-error.js +16 -0
  645. package/dist/server-error.js.map +1 -0
  646. package/dist/session/credential-policy.d.ts +20 -0
  647. package/dist/session/credential-policy.d.ts.map +1 -0
  648. package/dist/session/credential-policy.js +70 -0
  649. package/dist/session/credential-policy.js.map +1 -0
  650. package/dist/session/default-model-hydration.d.ts +46 -0
  651. package/dist/session/default-model-hydration.d.ts.map +1 -0
  652. package/dist/session/default-model-hydration.js +85 -0
  653. package/dist/session/default-model-hydration.js.map +1 -0
  654. package/dist/session/environment-repositories.d.ts +31 -0
  655. package/dist/session/environment-repositories.d.ts.map +1 -0
  656. package/dist/session/environment-repositories.js +89 -0
  657. package/dist/session/environment-repositories.js.map +1 -0
  658. package/dist/session/environment-state-processor.d.ts +59 -0
  659. package/dist/session/environment-state-processor.d.ts.map +1 -0
  660. package/dist/session/environment-state-processor.js +105 -0
  661. package/dist/session/environment-state-processor.js.map +1 -0
  662. package/dist/session/factory-session.d.ts +159 -0
  663. package/dist/session/factory-session.d.ts.map +1 -0
  664. package/dist/session/factory-session.js +226 -0
  665. package/dist/session/factory-session.js.map +1 -0
  666. package/dist/session/filesystem-capture.d.ts +50 -0
  667. package/dist/session/filesystem-capture.d.ts.map +1 -0
  668. package/dist/session/filesystem-capture.js +231 -0
  669. package/dist/session/filesystem-capture.js.map +1 -0
  670. package/dist/session/first-exec-capture.d.ts +38 -0
  671. package/dist/session/first-exec-capture.d.ts.map +1 -0
  672. package/dist/session/first-exec-capture.js +91 -0
  673. package/dist/session/first-exec-capture.js.map +1 -0
  674. package/dist/session/first-message-capture.d.ts +33 -0
  675. package/dist/session/first-message-capture.d.ts.map +1 -0
  676. package/dist/session/first-message-capture.js +35 -0
  677. package/dist/session/first-message-capture.js.map +1 -0
  678. package/dist/session/live-sessions.d.ts +63 -0
  679. package/dist/session/live-sessions.d.ts.map +1 -0
  680. package/dist/session/live-sessions.js +90 -0
  681. package/dist/session/live-sessions.js.map +1 -0
  682. package/dist/session/memory-settings-hydration.d.ts +36 -0
  683. package/dist/session/memory-settings-hydration.d.ts.map +1 -0
  684. package/dist/session/memory-settings-hydration.js +43 -0
  685. package/dist/session/memory-settings-hydration.js.map +1 -0
  686. package/dist/session/org-seed.d.ts +67 -0
  687. package/dist/session/org-seed.d.ts.map +1 -0
  688. package/dist/session/org-seed.js +53 -0
  689. package/dist/session/org-seed.js.map +1 -0
  690. package/dist/session/run-audit.d.ts +54 -0
  691. package/dist/session/run-audit.d.ts.map +1 -0
  692. package/dist/session/run-audit.js +124 -0
  693. package/dist/session/run-audit.js.map +1 -0
  694. package/dist/session/session-title.d.ts +7 -0
  695. package/dist/session/session-title.d.ts.map +1 -0
  696. package/dist/session/session-title.js +14 -0
  697. package/dist/session/session-title.js.map +1 -0
  698. package/dist/session/shell-commands.d.ts +5 -0
  699. package/dist/session/shell-commands.d.ts.map +1 -0
  700. package/dist/session/shell-commands.js +25 -0
  701. package/dist/session/shell-commands.js.map +1 -0
  702. package/dist/session/source-control-tools.d.ts +25 -0
  703. package/dist/session/source-control-tools.d.ts.map +1 -0
  704. package/dist/session/source-control-tools.js +594 -0
  705. package/dist/session/source-control-tools.js.map +1 -0
  706. package/dist/session/thread-title-mirror.d.ts +35 -0
  707. package/dist/session/thread-title-mirror.d.ts.map +1 -0
  708. package/dist/session/thread-title-mirror.js +51 -0
  709. package/dist/session/thread-title-mirror.js.map +1 -0
  710. package/dist/session/work-item-repository.d.ts +21 -0
  711. package/dist/session/work-item-repository.d.ts.map +1 -0
  712. package/dist/session/work-item-repository.js +113 -0
  713. package/dist/session/work-item-repository.js.map +1 -0
  714. package/dist/skills/catalog.d.ts +14 -0
  715. package/dist/skills/catalog.d.ts.map +1 -0
  716. package/dist/skills/catalog.js +62 -0
  717. package/dist/skills/catalog.js.map +1 -0
  718. package/dist/skills/service.d.ts +70 -0
  719. package/dist/skills/service.d.ts.map +1 -0
  720. package/dist/skills/service.js +88 -0
  721. package/dist/skills/service.js.map +1 -0
  722. package/dist/spa-static.d.ts +33 -0
  723. package/dist/spa-static.d.ts.map +1 -0
  724. package/dist/spa-static.js +104 -0
  725. package/dist/spa-static.js.map +1 -0
  726. package/dist/state-signing.d.ts +59 -0
  727. package/dist/state-signing.d.ts.map +1 -0
  728. package/dist/state-signing.js +83 -0
  729. package/dist/state-signing.js.map +1 -0
  730. package/dist/storage/domains/audit/actions.d.ts +24 -0
  731. package/dist/storage/domains/audit/actions.d.ts.map +1 -0
  732. package/dist/storage/domains/audit/actions.js +69 -0
  733. package/dist/storage/domains/audit/actions.js.map +1 -0
  734. package/dist/storage/domains/audit/actors.d.ts +5 -0
  735. package/dist/storage/domains/audit/actors.d.ts.map +1 -0
  736. package/dist/storage/domains/audit/actors.js +25 -0
  737. package/dist/storage/domains/audit/actors.js.map +1 -0
  738. package/dist/storage/domains/audit/agent-audit.d.ts +30 -0
  739. package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -0
  740. package/dist/storage/domains/audit/agent-audit.js +93 -0
  741. package/dist/storage/domains/audit/agent-audit.js.map +1 -0
  742. package/dist/storage/domains/audit/base.d.ts +133 -0
  743. package/dist/storage/domains/audit/base.d.ts.map +1 -0
  744. package/dist/storage/domains/audit/base.js +206 -0
  745. package/dist/storage/domains/audit/base.js.map +1 -0
  746. package/dist/storage/domains/audit/domain.d.ts +79 -0
  747. package/dist/storage/domains/audit/domain.d.ts.map +1 -0
  748. package/dist/storage/domains/audit/domain.js +248 -0
  749. package/dist/storage/domains/audit/domain.js.map +1 -0
  750. package/dist/storage/domains/audit/wire.d.ts +24 -0
  751. package/dist/storage/domains/audit/wire.d.ts.map +1 -0
  752. package/dist/storage/domains/audit/wire.js +16 -0
  753. package/dist/storage/domains/audit/wire.js.map +1 -0
  754. package/dist/storage/domains/channel-identity/base.d.ts +100 -0
  755. package/dist/storage/domains/channel-identity/base.d.ts.map +1 -0
  756. package/dist/storage/domains/channel-identity/base.js +164 -0
  757. package/dist/storage/domains/channel-identity/base.js.map +1 -0
  758. package/dist/storage/domains/comments/activity.d.ts +40 -0
  759. package/dist/storage/domains/comments/activity.d.ts.map +1 -0
  760. package/dist/storage/domains/comments/activity.js +94 -0
  761. package/dist/storage/domains/comments/activity.js.map +1 -0
  762. package/dist/storage/domains/comments/actor.d.ts +51 -0
  763. package/dist/storage/domains/comments/actor.d.ts.map +1 -0
  764. package/dist/storage/domains/comments/actor.js +38 -0
  765. package/dist/storage/domains/comments/actor.js.map +1 -0
  766. package/dist/storage/domains/comments/base.d.ts +245 -0
  767. package/dist/storage/domains/comments/base.d.ts.map +1 -0
  768. package/dist/storage/domains/comments/base.js +533 -0
  769. package/dist/storage/domains/comments/base.js.map +1 -0
  770. package/dist/storage/domains/comments/domain.d.ts +135 -0
  771. package/dist/storage/domains/comments/domain.d.ts.map +1 -0
  772. package/dist/storage/domains/comments/domain.js +285 -0
  773. package/dist/storage/domains/comments/domain.js.map +1 -0
  774. package/dist/storage/domains/comments/feed-context.d.ts +22 -0
  775. package/dist/storage/domains/comments/feed-context.d.ts.map +1 -0
  776. package/dist/storage/domains/comments/feed-context.js +89 -0
  777. package/dist/storage/domains/comments/feed-context.js.map +1 -0
  778. package/dist/storage/domains/comments/feed-sync.d.ts +21 -0
  779. package/dist/storage/domains/comments/feed-sync.d.ts.map +1 -0
  780. package/dist/storage/domains/comments/feed-sync.js +1 -0
  781. package/dist/storage/domains/comments/parse.d.ts +23 -0
  782. package/dist/storage/domains/comments/parse.d.ts.map +1 -0
  783. package/dist/storage/domains/comments/parse.js +90 -0
  784. package/dist/storage/domains/comments/parse.js.map +1 -0
  785. package/dist/storage/domains/comments/routes.d.ts +24 -0
  786. package/dist/storage/domains/comments/routes.d.ts.map +1 -0
  787. package/dist/storage/domains/comments/routes.js +302 -0
  788. package/dist/storage/domains/comments/routes.js.map +1 -0
  789. package/dist/storage/domains/comments/schema.d.ts +5 -0
  790. package/dist/storage/domains/comments/schema.d.ts.map +1 -0
  791. package/dist/storage/domains/comments/schema.js +179 -0
  792. package/dist/storage/domains/comments/schema.js.map +1 -0
  793. package/dist/storage/domains/comments/wire.d.ts +40 -0
  794. package/dist/storage/domains/comments/wire.d.ts.map +1 -0
  795. package/dist/storage/domains/comments/wire.js +37 -0
  796. package/dist/storage/domains/comments/wire.js.map +1 -0
  797. package/dist/storage/domains/credentials/base.d.ts +136 -0
  798. package/dist/storage/domains/credentials/base.d.ts.map +1 -0
  799. package/dist/storage/domains/credentials/base.js +294 -0
  800. package/dist/storage/domains/credentials/base.js.map +1 -0
  801. package/dist/storage/domains/custom-providers/base.d.ts +59 -0
  802. package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
  803. package/dist/storage/domains/custom-providers/base.js +176 -0
  804. package/dist/storage/domains/custom-providers/base.js.map +1 -0
  805. package/dist/storage/domains/filesystem/base.d.ts +26 -0
  806. package/dist/storage/domains/filesystem/base.d.ts.map +1 -0
  807. package/dist/storage/domains/filesystem/base.js +74 -0
  808. package/dist/storage/domains/filesystem/base.js.map +1 -0
  809. package/dist/storage/domains/intake/base.d.ts +150 -0
  810. package/dist/storage/domains/intake/base.d.ts.map +1 -0
  811. package/dist/storage/domains/intake/base.js +431 -0
  812. package/dist/storage/domains/intake/base.js.map +1 -0
  813. package/dist/storage/domains/integrations/base.d.ts +128 -0
  814. package/dist/storage/domains/integrations/base.d.ts.map +1 -0
  815. package/dist/storage/domains/integrations/base.js +333 -0
  816. package/dist/storage/domains/integrations/base.js.map +1 -0
  817. package/dist/storage/domains/memory-settings/base.d.ts +58 -0
  818. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
  819. package/dist/storage/domains/memory-settings/base.js +129 -0
  820. package/dist/storage/domains/memory-settings/base.js.map +1 -0
  821. package/dist/storage/domains/model-defaults/base.d.ts +29 -0
  822. package/dist/storage/domains/model-defaults/base.d.ts.map +1 -0
  823. package/dist/storage/domains/model-defaults/base.js +79 -0
  824. package/dist/storage/domains/model-defaults/base.js.map +1 -0
  825. package/dist/storage/domains/projects/base.d.ts +191 -0
  826. package/dist/storage/domains/projects/base.d.ts.map +1 -0
  827. package/dist/storage/domains/projects/base.js +352 -0
  828. package/dist/storage/domains/projects/base.js.map +1 -0
  829. package/dist/storage/domains/queue-health/base.d.ts +52 -0
  830. package/dist/storage/domains/queue-health/base.d.ts.map +1 -0
  831. package/dist/storage/domains/queue-health/base.js +122 -0
  832. package/dist/storage/domains/queue-health/base.js.map +1 -0
  833. package/dist/storage/domains/source-control/base.d.ts +422 -0
  834. package/dist/storage/domains/source-control/base.d.ts.map +1 -0
  835. package/dist/storage/domains/source-control/base.js +1114 -0
  836. package/dist/storage/domains/source-control/base.js.map +1 -0
  837. package/dist/storage/domains/source-control/inmemory.d.ts +147 -0
  838. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -0
  839. package/dist/storage/domains/source-control/inmemory.js +416 -0
  840. package/dist/storage/domains/source-control/inmemory.js.map +1 -0
  841. package/dist/storage/domains/work-items/base.d.ts +794 -0
  842. package/dist/storage/domains/work-items/base.d.ts.map +1 -0
  843. package/dist/storage/domains/work-items/base.js +2747 -0
  844. package/dist/storage/domains/work-items/base.js.map +1 -0
  845. package/dist/storage/domains/work-items/board-version.d.ts +26 -0
  846. package/dist/storage/domains/work-items/board-version.d.ts.map +1 -0
  847. package/dist/storage/domains/work-items/board-version.js +110 -0
  848. package/dist/storage/domains/work-items/board-version.js.map +1 -0
  849. package/dist/storage/domains/work-items/metrics.d.ts +97 -0
  850. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -0
  851. package/dist/storage/domains/work-items/metrics.js +226 -0
  852. package/dist/storage/domains/work-items/metrics.js.map +1 -0
  853. package/dist/supervisor/health-worker.d.ts +19 -0
  854. package/dist/supervisor/health-worker.d.ts.map +1 -0
  855. package/dist/supervisor/health-worker.js +74 -0
  856. package/dist/supervisor/health-worker.js.map +1 -0
  857. package/dist/supervisor/health.d.ts +79 -0
  858. package/dist/supervisor/health.d.ts.map +1 -0
  859. package/dist/supervisor/health.js +228 -0
  860. package/dist/supervisor/health.js.map +1 -0
  861. package/dist/supervisor/instructions.d.ts +6 -0
  862. package/dist/supervisor/instructions.d.ts.map +1 -0
  863. package/dist/supervisor/instructions.js +66 -0
  864. package/dist/supervisor/instructions.js.map +1 -0
  865. package/dist/supervisor/read-tools.d.ts +43 -0
  866. package/dist/supervisor/read-tools.d.ts.map +1 -0
  867. package/dist/supervisor/read-tools.js +343 -0
  868. package/dist/supervisor/read-tools.js.map +1 -0
  869. package/dist/supervisor/session-messaging.d.ts +26 -0
  870. package/dist/supervisor/session-messaging.d.ts.map +1 -0
  871. package/dist/supervisor/session-messaging.js +21 -0
  872. package/dist/supervisor/session-messaging.js.map +1 -0
  873. package/dist/supervisor/session.d.ts +38 -0
  874. package/dist/supervisor/session.d.ts.map +1 -0
  875. package/dist/supervisor/session.js +79 -0
  876. package/dist/supervisor/session.js.map +1 -0
  877. package/dist/supervisor/write-tools.d.ts +30 -0
  878. package/dist/supervisor/write-tools.d.ts.map +1 -0
  879. package/dist/supervisor/write-tools.js +231 -0
  880. package/dist/supervisor/write-tools.js.map +1 -0
  881. package/dist/telemetry-types.d.ts +7 -0
  882. package/dist/telemetry-types.d.ts.map +1 -0
  883. package/dist/telemetry-types.js +24 -0
  884. package/dist/telemetry-types.js.map +1 -0
  885. package/dist/telemetry.d.ts +9 -0
  886. package/dist/telemetry.d.ts.map +1 -0
  887. package/dist/telemetry.js +47 -0
  888. package/dist/telemetry.js.map +1 -0
  889. package/dist/timing.d.ts +15 -0
  890. package/dist/timing.d.ts.map +1 -0
  891. package/dist/timing.js +34 -0
  892. package/dist/timing.js.map +1 -0
  893. package/dist/work-item-branch.d.ts +33 -0
  894. package/dist/work-item-branch.d.ts.map +1 -0
  895. package/dist/work-item-branch.js +70 -0
  896. package/dist/work-item-branch.js.map +1 -0
  897. package/dist/workspace.d.ts +131 -0
  898. package/dist/workspace.d.ts.map +1 -0
  899. package/dist/workspace.js +995 -0
  900. package/dist/workspace.js.map +1 -0
  901. package/factory-skills/configure-factory-rules/SKILL.md +122 -0
  902. package/factory-skills/factory-complete-issue/SKILL.md +24 -0
  903. package/factory-skills/factory-gitlab-rereview/SKILL.md +22 -0
  904. package/factory-skills/factory-gitlab-review/SKILL.md +48 -0
  905. package/factory-skills/factory-plan/SKILL.md +72 -0
  906. package/factory-skills/factory-rereview/SKILL.md +225 -0
  907. package/factory-skills/factory-review/SKILL.md +214 -0
  908. package/factory-skills/factory-review/references/archaeology.md +225 -0
  909. package/factory-skills/factory-review/references/categories/README.md +34 -0
  910. package/factory-skills/factory-review/references/categories/behavior-change.md +36 -0
  911. package/factory-skills/factory-review/references/categories/bug-fix.md +37 -0
  912. package/factory-skills/factory-review/references/categories/docs.md +32 -0
  913. package/factory-skills/factory-review/references/categories/experimental-flagged.md +34 -0
  914. package/factory-skills/factory-review/references/categories/infra-tooling.md +37 -0
  915. package/factory-skills/factory-review/references/categories/internal-capability.md +35 -0
  916. package/factory-skills/factory-review/references/categories/large-cross-cutting.md +35 -0
  917. package/factory-skills/factory-review/references/categories/mechanical.md +36 -0
  918. package/factory-skills/factory-review/references/categories/performance.md +33 -0
  919. package/factory-skills/factory-review/references/categories/public-api.md +38 -0
  920. package/factory-skills/factory-review/references/categories/refactor.md +35 -0
  921. package/factory-skills/factory-review/references/categories/revert.md +31 -0
  922. package/factory-skills/factory-review/references/categories/schema-storage.md +39 -0
  923. package/factory-skills/factory-review/references/categories/security.md +35 -0
  924. package/factory-skills/factory-review/references/categories/tests-only.md +38 -0
  925. package/factory-skills/factory-triage/SKILL.md +197 -0
  926. package/package.json +92 -0
@@ -0,0 +1,248 @@
1
+ import { getFactoryAuthUser } from "../../../auth.js";
2
+ import { auditActionsInNamespaces, isAuditNamespace } from "./actions.js";
3
+ import { isHumanActorId } from "./actors.js";
4
+ import { ACTOR_PROFILE_METADATA_KEY, auditActorProfile } from "./base.js";
5
+ import { toWireAuditEvent } from "./wire.js";
6
+ import { registerApiRoute } from "@mastra/core/server";
7
+ //#region src/storage/domains/audit/domain.ts
8
+ function readStoredActorProfile(metadata) {
9
+ if (!metadata) return void 0;
10
+ const raw = metadata[ACTOR_PROFILE_METADATA_KEY];
11
+ if (!raw || typeof raw !== "object") return void 0;
12
+ const profile = raw;
13
+ const name = typeof profile.name === "string" && profile.name.trim() ? profile.name.trim() : void 0;
14
+ const avatarUrl = typeof profile.avatarUrl === "string" && profile.avatarUrl.trim() ? profile.avatarUrl.trim() : void 0;
15
+ if (!name && !avatarUrl) return void 0;
16
+ return {
17
+ ...name ? { name } : {},
18
+ ...avatarUrl ? { avatarUrl } : {}
19
+ };
20
+ }
21
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
22
+ const MAX_ACTOR_PROFILES = 100;
23
+ function loose(c) {
24
+ return c;
25
+ }
26
+ /** The actions a `namespaces=` query names: none when it names only unknown ones, `undefined` when it names nothing. */
27
+ function actionsInRequestedNamespaces(raw) {
28
+ if (!raw) return void 0;
29
+ return auditActionsInNamespaces(raw.split(",").map((namespace) => namespace.trim()).filter(isAuditNamespace));
30
+ }
31
+ function parseActorIdsParam(raw) {
32
+ if (!raw) return [];
33
+ return [...new Set(raw.split(",").map((actorId) => actorId.trim()).filter(isHumanActorId))].slice(0, MAX_ACTOR_PROFILES);
34
+ }
35
+ function parseLimitParam(raw) {
36
+ if (!raw) return void 0;
37
+ const limit = Number.parseInt(raw, 10);
38
+ return Number.isFinite(limit) ? limit : void 0;
39
+ }
40
+ function auditRequestContext(c) {
41
+ const location = c.req.header("x-forwarded-for")?.split(",")[0]?.trim();
42
+ const userAgent = c.req.header("user-agent");
43
+ return {
44
+ ...location ? { location } : {},
45
+ ...userAgent ? { userAgent } : {}
46
+ };
47
+ }
48
+ /** Who a browser request is and where it came from: the pair every funnel row carries. */
49
+ function auditRequestOrigin(c) {
50
+ return {
51
+ actorProfile: auditActorProfile(getFactoryAuthUser(c)),
52
+ context: auditRequestContext(c)
53
+ };
54
+ }
55
+ /** Factory-owned audit behavior backed by the audit storage domain. */
56
+ var AuditDomain = class {
57
+ #auth;
58
+ #audit;
59
+ #projects;
60
+ #users;
61
+ #sinks;
62
+ #agentTenant;
63
+ constructor({ auth, audit, projects, users, sinks = [], agentTenant }) {
64
+ this.#auth = auth;
65
+ this.#audit = audit;
66
+ this.#projects = projects;
67
+ this.#users = users;
68
+ this.#sinks = sinks;
69
+ this.#agentTenant = agentTenant;
70
+ const ids = /* @__PURE__ */ new Set();
71
+ for (const sink of this.#sinks) {
72
+ if (!sink.id) throw new Error("Audit integration id must not be empty");
73
+ if (ids.has(sink.id)) throw new Error(`Duplicate audit integration id '${sink.id}'`);
74
+ ids.add(sink.id);
75
+ }
76
+ }
77
+ async record(input) {
78
+ try {
79
+ await this.#audit.ensureReady();
80
+ const { event: row, created } = input.idempotencyKey ? await this.#audit.recordOnce(input) : {
81
+ event: await this.#audit.record(input),
82
+ created: true
83
+ };
84
+ if (!created) return row;
85
+ for (const sink of this.#sinks) {
86
+ if (!sink.audit) continue;
87
+ Promise.resolve().then(() => sink.audit?.({ event: row })).catch((err) => {
88
+ console.warn("[Audit] Audit integration failed", {
89
+ integration: sink.id,
90
+ action: row.action,
91
+ error: err instanceof Error ? err.message : String(err)
92
+ });
93
+ });
94
+ }
95
+ return row;
96
+ } catch (err) {
97
+ console.warn("[Audit] Failed to record audit event", {
98
+ action: input.action,
99
+ error: err instanceof Error ? err.message : String(err)
100
+ });
101
+ return null;
102
+ }
103
+ }
104
+ async list(input) {
105
+ await this.#audit.ensureReady();
106
+ return this.#audit.list(input);
107
+ }
108
+ async emit({ context, input }) {
109
+ try {
110
+ const tenant = this.#auth.tenant(context);
111
+ if (!tenant?.orgId) return;
112
+ await this.record({
113
+ orgId: tenant.orgId,
114
+ actorId: tenant.userId,
115
+ actorProfile: auditActorProfile(getFactoryAuthUser(context)),
116
+ action: input.action,
117
+ targets: input.targets,
118
+ metadata: input.metadata,
119
+ factoryProjectId: input.factoryProjectId,
120
+ projectRepositoryId: input.projectRepositoryId,
121
+ context: auditRequestContext(context)
122
+ });
123
+ } catch (err) {
124
+ console.warn("[Audit] Failed to emit audit event", {
125
+ action: input.action,
126
+ error: err instanceof Error ? err.message : String(err)
127
+ });
128
+ }
129
+ }
130
+ async emitAgent({ requestContext, input }) {
131
+ try {
132
+ const context = requestContext.get("controller");
133
+ const tenant = this.#agentTenant?.(requestContext);
134
+ const orgId = tenant?.orgId;
135
+ const userId = tenant?.userId;
136
+ const threadId = context?.threadId;
137
+ const state = context?.getState();
138
+ if (!orgId || !userId || !threadId || !state?.factoryProjectId) return;
139
+ const modelId = context.session.modelId?.trim();
140
+ await this.record({
141
+ orgId,
142
+ actorId: `agent:${threadId}`,
143
+ actorType: "agent",
144
+ action: input.action,
145
+ targets: input.targets,
146
+ metadata: {
147
+ ...input.metadata,
148
+ startedBy: userId,
149
+ ...modelId ? { modelId } : {}
150
+ },
151
+ factoryProjectId: state.factoryProjectId,
152
+ projectRepositoryId: state.projectRepositoryId,
153
+ context: {}
154
+ });
155
+ } catch (err) {
156
+ console.warn("[Audit] Failed to emit agent audit event", {
157
+ action: input.action,
158
+ error: err instanceof Error ? err.message : String(err)
159
+ });
160
+ }
161
+ }
162
+ async #resolveActorProfiles(events, requestedActorIds = []) {
163
+ const humanActorIds = [...new Set([...requestedActorIds, ...events.filter((event) => event.actorType === "human").map((event) => event.actorId)].filter(isHumanActorId))].slice(0, MAX_ACTOR_PROFILES);
164
+ if (humanActorIds.length === 0) return {};
165
+ const profiles = {};
166
+ for (const event of events) {
167
+ if (event.actorType !== "human") continue;
168
+ if (!isHumanActorId(event.actorId)) continue;
169
+ if (profiles[event.actorId]) continue;
170
+ const stored = readStoredActorProfile(event.metadata);
171
+ if (!stored?.name) continue;
172
+ profiles[event.actorId] = {
173
+ id: event.actorId,
174
+ name: stored.name,
175
+ ...stored.avatarUrl ? { avatarUrl: stored.avatarUrl } : {}
176
+ };
177
+ }
178
+ const unresolved = humanActorIds.filter((actorId) => !profiles[actorId]);
179
+ if (unresolved.length === 0 || !this.#users) return profiles;
180
+ try {
181
+ const users = this.#users.getUsers ? await this.#users.getUsers(unresolved) : await Promise.all(unresolved.map((actorId) => this.#users?.getUser(actorId) ?? null));
182
+ for (const [index, user] of users.entries()) {
183
+ if (!user) continue;
184
+ const name = user.name?.trim() || user.email?.trim() || user.id;
185
+ const actorId = unresolved[index] ?? user.id;
186
+ profiles[actorId] = {
187
+ id: user.id,
188
+ name,
189
+ ...user.avatarUrl ? { avatarUrl: user.avatarUrl } : {}
190
+ };
191
+ }
192
+ } catch (err) {
193
+ console.warn("[Audit] Failed to resolve audit actor profiles", { error: err instanceof Error ? err.message : String(err) });
194
+ }
195
+ return profiles;
196
+ }
197
+ routes() {
198
+ return [registerApiRoute("/web/factory/projects/:id/audit", {
199
+ method: "GET",
200
+ handler: async (cc) => {
201
+ const c = loose(cc);
202
+ const tenant = await this.#resolveTenant(c);
203
+ if ("response" in tenant) return tenant.response;
204
+ const projectId = c.req.param("id");
205
+ if (!projectId || !UUID_RE.test(projectId)) return c.json({ error: "Project not found" }, 404);
206
+ await this.#projects.ensureReady();
207
+ if (!await this.#projects.get({
208
+ orgId: tenant.orgId,
209
+ id: projectId
210
+ })) return c.json({ error: "Project not found" }, 404);
211
+ const actions = actionsInRequestedNamespaces(c.req.query("namespaces"));
212
+ if (actions?.length === 0) return c.json({ error: "unknown_namespaces" }, 400);
213
+ const page = await this.list({
214
+ orgId: tenant.orgId,
215
+ factoryProjectId: projectId,
216
+ actions,
217
+ actorId: c.req.query("actor") || void 0,
218
+ before: c.req.query("before") || void 0,
219
+ limit: parseLimitParam(c.req.query("limit"))
220
+ });
221
+ const actors = await this.#resolveActorProfiles(page.events, parseActorIdsParam(c.req.query("actorIds")));
222
+ const body = {
223
+ events: page.events.map(toWireAuditEvent),
224
+ actors,
225
+ ...page.nextCursor ? { nextCursor: page.nextCursor } : {}
226
+ };
227
+ return c.json(body);
228
+ }
229
+ })];
230
+ }
231
+ async #resolveTenant(c) {
232
+ await this.#auth.ensureUser(c);
233
+ const tenant = this.#auth.tenant(c);
234
+ if (!tenant) return { response: c.json({ error: "unauthorized" }, 401) };
235
+ if (!tenant.orgId) return { response: c.json({
236
+ error: "organization_required",
237
+ message: "The audit trail requires an organization."
238
+ }, 403) };
239
+ return {
240
+ orgId: tenant.orgId,
241
+ userId: tenant.userId
242
+ };
243
+ }
244
+ };
245
+ //#endregion
246
+ export { AuditDomain, auditRequestContext, auditRequestOrigin };
247
+
248
+ //# sourceMappingURL=domain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.js","names":["#auth","#audit","#projects","#users","#sinks","#agentTenant","#resolveActorProfiles","#resolveTenant"],"sources":["../../../../src/storage/domains/audit/domain.ts"],"sourcesContent":["import type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute, IUserProvider } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\n\nimport { getFactoryAuthUser } from '../../../auth.js';\nimport type { RouteAuth } from '../../../routes/route.js';\nimport type { FactoryProjectsStorage } from '../projects/base.js';\nimport { auditActionsInNamespaces, isAuditNamespace } from './actions.js';\nimport type { AuditAction } from './actions.js';\nimport { isHumanActorId } from './actors.js';\nimport { ACTOR_PROFILE_METADATA_KEY, auditActorProfile } from './base.js';\nimport type {\n AuditActorProfileInput,\n AuditContext,\n AuditEventPage,\n AuditEventRow,\n AuditStorage,\n AuditTarget,\n ListAuditEventsInput,\n RecordAuditEventInput,\n} from './base.js';\nimport { toWireAuditEvent } from './wire.js';\nimport type { WireAuditActor, WireAuditPage } from './wire.js';\n\nexport interface EmitAuditInput {\n action: AuditAction;\n factoryProjectId?: string;\n projectRepositoryId?: string;\n targets: AuditTarget[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface EmitAgentAuditInput {\n action: AuditAction;\n targets: AuditTarget[];\n metadata?: Record<string, unknown>;\n}\n\nexport interface AuditEmitter {\n emit(args: { context: Context; input: EmitAuditInput }): Promise<void>;\n}\n\nexport interface AuditAgentEmitter {\n emitAgent(args: { requestContext: RequestContext; input: EmitAgentAuditInput }): Promise<void>;\n}\n\n/** Records with an explicit actor, for the paths that have no request: rule transitions, run starts, run ends, supervisor tools. */\nexport type AuditRecorder = Pick<AuditDomain, 'record'>;\n\n/** Best-effort destination for locally persisted audit events (e.g. an integration's audit log). */\nexport interface AuditSink {\n id: string;\n audit?(args: { event: AuditEventRow }): Promise<void>;\n}\n\ninterface FactorySessionState {\n factoryProjectId?: string;\n projectRepositoryId?: string;\n}\n\nfunction readStoredActorProfile(metadata: Record<string, unknown> | undefined): AuditActorProfileInput | undefined {\n if (!metadata) return undefined;\n const raw = metadata[ACTOR_PROFILE_METADATA_KEY];\n if (!raw || typeof raw !== 'object') return undefined;\n const profile = raw as Record<string, unknown>;\n const name = typeof profile.name === 'string' && profile.name.trim() ? profile.name.trim() : undefined;\n const avatarUrl =\n typeof profile.avatarUrl === 'string' && profile.avatarUrl.trim() ? profile.avatarUrl.trim() : undefined;\n if (!name && !avatarUrl) return undefined;\n return { ...(name ? { name } : {}), ...(avatarUrl ? { avatarUrl } : {}) };\n}\n\nexport interface AuditDomainOptions {\n auth: RouteAuth;\n /** Audit storage domain handle. */\n audit: AuditStorage;\n /** Projects domain handle, used to scope the audit trail route. */\n projects: FactoryProjectsStorage;\n /** Resolve persisted human actor ids to display names and profile images. */\n users?: Pick<IUserProvider, 'getUser' | 'getUsers'>;\n /** Best-effort fan-out destinations notified after each recorded event. */\n sinks?: AuditSink[];\n /** Resolve the acting tenant for agent-emitted events from the request context. */\n agentTenant?: (requestContext: RequestContext) => { orgId?: string; userId?: string } | undefined;\n}\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nconst MAX_ACTOR_PROFILES = 100;\n\nfunction loose(c: unknown): Context {\n return c as Context;\n}\n\n/** The actions a `namespaces=` query names: none when it names only unknown ones, `undefined` when it names nothing. */\nfunction actionsInRequestedNamespaces(raw: string | undefined): string[] | undefined {\n if (!raw) return undefined;\n return auditActionsInNamespaces(\n raw\n .split(',')\n .map(namespace => namespace.trim())\n .filter(isAuditNamespace),\n );\n}\n\nfunction parseActorIdsParam(raw: string | undefined): string[] {\n if (!raw) return [];\n return [\n ...new Set(\n raw\n .split(',')\n .map(actorId => actorId.trim())\n .filter(isHumanActorId),\n ),\n ].slice(0, MAX_ACTOR_PROFILES);\n}\n\nfunction parseLimitParam(raw: string | undefined): number | undefined {\n if (!raw) return undefined;\n const limit = Number.parseInt(raw, 10);\n return Number.isFinite(limit) ? limit : undefined;\n}\n\nexport function auditRequestContext(c: Context): AuditContext {\n const location = c.req.header('x-forwarded-for')?.split(',')[0]?.trim();\n const userAgent = c.req.header('user-agent');\n return {\n ...(location ? { location } : {}),\n ...(userAgent ? { userAgent } : {}),\n };\n}\n\n/** Who a browser request is and where it came from: the pair every funnel row carries. */\nexport function auditRequestOrigin(c: Context): {\n actorProfile: AuditActorProfileInput | undefined;\n context: AuditContext;\n} {\n return { actorProfile: auditActorProfile(getFactoryAuthUser(c)), context: auditRequestContext(c) };\n}\n\n/** Factory-owned audit behavior backed by the audit storage domain. */\nexport class AuditDomain implements AuditEmitter, AuditAgentEmitter {\n readonly #auth: RouteAuth;\n readonly #audit: AuditStorage;\n readonly #projects: FactoryProjectsStorage;\n readonly #users: AuditDomainOptions['users'];\n readonly #sinks: AuditSink[];\n readonly #agentTenant: AuditDomainOptions['agentTenant'];\n\n constructor({ auth, audit, projects, users, sinks = [], agentTenant }: AuditDomainOptions) {\n this.#auth = auth;\n this.#audit = audit;\n this.#projects = projects;\n this.#users = users;\n this.#sinks = sinks;\n this.#agentTenant = agentTenant;\n\n const ids = new Set<string>();\n for (const sink of this.#sinks) {\n if (!sink.id) throw new Error('Audit integration id must not be empty');\n if (ids.has(sink.id)) throw new Error(`Duplicate audit integration id '${sink.id}'`);\n ids.add(sink.id);\n }\n }\n\n async record(input: RecordAuditEventInput<AuditAction>): Promise<AuditEventRow | null> {\n try {\n await this.#audit.ensureReady();\n const { event: row, created } = input.idempotencyKey\n ? await this.#audit.recordOnce(input)\n : { event: await this.#audit.record(input), created: true };\n if (!created) return row;\n for (const sink of this.#sinks) {\n if (!sink.audit) continue;\n void Promise.resolve()\n .then(() => sink.audit?.({ event: row }))\n .catch(err => {\n console.warn('[Audit] Audit integration failed', {\n integration: sink.id,\n action: row.action,\n error: err instanceof Error ? err.message : String(err),\n });\n });\n }\n return row;\n } catch (err) {\n console.warn('[Audit] Failed to record audit event', {\n action: input.action,\n error: err instanceof Error ? err.message : String(err),\n });\n return null;\n }\n }\n\n async list(input: ListAuditEventsInput): Promise<AuditEventPage> {\n await this.#audit.ensureReady();\n return this.#audit.list(input);\n }\n\n async emit({ context, input }: { context: Context; input: EmitAuditInput }): Promise<void> {\n try {\n const tenant = this.#auth.tenant(context);\n if (!tenant?.orgId) return;\n await this.record({\n orgId: tenant.orgId,\n actorId: tenant.userId,\n actorProfile: auditActorProfile(getFactoryAuthUser(context)),\n action: input.action,\n targets: input.targets,\n metadata: input.metadata,\n factoryProjectId: input.factoryProjectId,\n projectRepositoryId: input.projectRepositoryId,\n context: auditRequestContext(context),\n });\n } catch (err) {\n console.warn('[Audit] Failed to emit audit event', {\n action: input.action,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n async emitAgent({\n requestContext,\n input,\n }: {\n requestContext: RequestContext;\n input: EmitAgentAuditInput;\n }): Promise<void> {\n try {\n const context = requestContext.get('controller') as\n | AgentControllerRequestContext<FactorySessionState>\n | undefined;\n const tenant = this.#agentTenant?.(requestContext);\n const orgId = tenant?.orgId;\n const userId = tenant?.userId;\n const threadId = context?.threadId;\n const state = context?.getState();\n if (!orgId || !userId || !threadId || !state?.factoryProjectId) return;\n\n const modelId = context.session.modelId?.trim();\n await this.record({\n orgId,\n actorId: `agent:${threadId}`,\n actorType: 'agent',\n action: input.action,\n targets: input.targets,\n metadata: {\n ...input.metadata,\n startedBy: userId,\n ...(modelId ? { modelId } : {}),\n },\n factoryProjectId: state.factoryProjectId,\n projectRepositoryId: state.projectRepositoryId,\n context: {},\n });\n } catch (err) {\n console.warn('[Audit] Failed to emit agent audit event', {\n action: input.action,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n async #resolveActorProfiles(\n events: AuditEventRow[],\n requestedActorIds: string[] = [],\n ): Promise<Record<string, WireAuditActor>> {\n const humanActorIds = [\n ...new Set(\n [\n ...requestedActorIds,\n ...events.filter(event => event.actorType === 'human').map(event => event.actorId),\n ].filter(isHumanActorId),\n ),\n ].slice(0, MAX_ACTOR_PROFILES);\n if (humanActorIds.length === 0) return {};\n\n // Prefer the profile stamped into event metadata at record time: it works\n // regardless of the auth provider's ability to resolve a user by id\n // (MastraAuthStudio's getUser() always returns null, WorkOS looks up by\n // id but every provider stamps here uniformly).\n const profiles: Record<string, WireAuditActor> = {};\n for (const event of events) {\n if (event.actorType !== 'human') continue;\n if (!isHumanActorId(event.actorId)) continue;\n if (profiles[event.actorId]) continue;\n const stored = readStoredActorProfile(event.metadata);\n if (!stored?.name) continue;\n profiles[event.actorId] = {\n id: event.actorId,\n name: stored.name,\n ...(stored.avatarUrl ? { avatarUrl: stored.avatarUrl } : {}),\n };\n }\n\n const unresolved = humanActorIds.filter(actorId => !profiles[actorId]);\n if (unresolved.length === 0 || !this.#users) return profiles;\n\n try {\n const users = this.#users.getUsers\n ? await this.#users.getUsers(unresolved)\n : await Promise.all(unresolved.map(actorId => this.#users?.getUser(actorId) ?? null));\n for (const [index, user] of users.entries()) {\n if (!user) continue;\n const name = user.name?.trim() || user.email?.trim() || user.id;\n const actorId = unresolved[index] ?? user.id;\n profiles[actorId] = {\n id: user.id,\n name,\n ...(user.avatarUrl ? { avatarUrl: user.avatarUrl } : {}),\n };\n }\n } catch (err) {\n console.warn('[Audit] Failed to resolve audit actor profiles', {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return profiles;\n }\n\n routes(): ApiRoute[] {\n return [\n registerApiRoute('/web/factory/projects/:id/audit', {\n method: 'GET',\n handler: async cc => {\n const c = loose(cc);\n const tenant = await this.#resolveTenant(c);\n if ('response' in tenant) return tenant.response;\n\n const projectId = c.req.param('id');\n if (!projectId || !UUID_RE.test(projectId)) return c.json({ error: 'Project not found' }, 404);\n await this.#projects.ensureReady();\n const project = await this.#projects.get({ orgId: tenant.orgId, id: projectId });\n if (!project) return c.json({ error: 'Project not found' }, 404);\n\n const actions = actionsInRequestedNamespaces(c.req.query('namespaces'));\n if (actions?.length === 0) return c.json({ error: 'unknown_namespaces' }, 400);\n\n const page = await this.list({\n orgId: tenant.orgId,\n factoryProjectId: projectId,\n actions,\n actorId: c.req.query('actor') || undefined,\n before: c.req.query('before') || undefined,\n limit: parseLimitParam(c.req.query('limit')),\n });\n const actors = await this.#resolveActorProfiles(page.events, parseActorIdsParam(c.req.query('actorIds')));\n const body: WireAuditPage = {\n events: page.events.map(toWireAuditEvent),\n actors,\n ...(page.nextCursor ? { nextCursor: page.nextCursor } : {}),\n };\n return c.json(body);\n },\n }),\n ];\n }\n\n async #resolveTenant(c: Context): Promise<{ orgId: string; userId: string } | { response: Response }> {\n await this.#auth.ensureUser(c);\n const tenant = this.#auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json({ error: 'organization_required', message: 'The audit trail requires an organization.' }, 403),\n };\n }\n return { orgId: tenant.orgId, userId: tenant.userId };\n }\n}\n"],"mappings":";;;;;;;AA8DA,SAAS,uBAAuB,UAAmF;CACjH,IAAI,CAAC,UAAU,OAAO,KAAA;CACtB,MAAM,MAAM,SAAS;CACrB,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO,KAAA;CAC5C,MAAM,UAAU;CAChB,MAAM,OAAO,OAAO,QAAQ,SAAS,YAAY,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,KAAK,IAAI,KAAA;CAC7F,MAAM,YACJ,OAAO,QAAQ,cAAc,YAAY,QAAQ,UAAU,KAAK,IAAI,QAAQ,UAAU,KAAK,IAAI,KAAA;CACjG,IAAI,CAAC,QAAQ,CAAC,WAAW,OAAO,KAAA;CAChC,OAAO;EAAE,GAAI,OAAO,EAAE,KAAK,IAAI,CAAC;EAAI,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;CAAG;AAC1E;AAgBA,MAAM,UAAU;AAChB,MAAM,qBAAqB;AAE3B,SAAS,MAAM,GAAqB;CAClC,OAAO;AACT;;AAGA,SAAS,6BAA6B,KAA+C;CACnF,IAAI,CAAC,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AAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,eAAe,GAAG,GAAG,EAAE;EACvE,IAAI,CAAC,OAAO,OACV,OAAO,EACL,UAAU,EAAE,KAAK;GAAE,OAAO;GAAyB,SAAS;EAA4C,GAAG,GAAG,EAChH;EAEF,OAAO;GAAE,OAAO,OAAO;GAAO,QAAQ,OAAO;EAAO;CACtD;AACF"}
@@ -0,0 +1,24 @@
1
+ import type { AuditActorType } from './actors.js';
2
+ import type { AuditEventRow, AuditTarget } from './base.js';
3
+ export interface WireAuditActor {
4
+ id: string;
5
+ name: string;
6
+ avatarUrl?: string;
7
+ }
8
+ /** An `AuditEventRow` as the list route sends it: the date as ISO text, tenancy and request context left behind. */
9
+ export interface WireAuditEvent {
10
+ id: string;
11
+ actorId: string;
12
+ actorType: AuditActorType;
13
+ action: string;
14
+ targets: AuditTarget[];
15
+ metadata: Record<string, unknown>;
16
+ occurredAt: string;
17
+ }
18
+ export interface WireAuditPage {
19
+ events: WireAuditEvent[];
20
+ actors: Record<string, WireAuditActor>;
21
+ nextCursor?: string;
22
+ }
23
+ export declare function toWireAuditEvent(row: AuditEventRow): WireAuditEvent;
24
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/audit/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,oHAAoH;AACpH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,cAAc,CAUnE"}
@@ -0,0 +1,16 @@
1
+ //#region src/storage/domains/audit/wire.ts
2
+ function toWireAuditEvent(row) {
3
+ return {
4
+ id: row.id,
5
+ actorId: row.actorId,
6
+ actorType: row.actorType,
7
+ action: row.action,
8
+ targets: row.targets,
9
+ metadata: row.metadata,
10
+ occurredAt: row.occurredAt.toISOString()
11
+ };
12
+ }
13
+ //#endregion
14
+ export { toWireAuditEvent };
15
+
16
+ //# sourceMappingURL=wire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.js","names":[],"sources":["../../../../src/storage/domains/audit/wire.ts"],"sourcesContent":["import type { AuditActorType } from './actors.js';\nimport type { AuditEventRow, AuditTarget } from './base.js';\n\nexport interface WireAuditActor {\n id: string;\n name: string;\n avatarUrl?: string;\n}\n\n/** An `AuditEventRow` as the list route sends it: the date as ISO text, tenancy and request context left behind. */\nexport interface WireAuditEvent {\n id: string;\n actorId: string;\n actorType: AuditActorType;\n action: string;\n targets: AuditTarget[];\n metadata: Record<string, unknown>;\n occurredAt: string;\n}\n\nexport interface WireAuditPage {\n events: WireAuditEvent[];\n actors: Record<string, WireAuditActor>;\n nextCursor?: string;\n}\n\nexport function toWireAuditEvent(row: AuditEventRow): WireAuditEvent {\n return {\n id: row.id,\n actorId: row.actorId,\n actorType: row.actorType,\n action: row.action,\n targets: row.targets,\n metadata: row.metadata,\n occurredAt: row.occurredAt.toISOString(),\n };\n}\n"],"mappings":";AA0BA,SAAgB,iBAAiB,KAAoC;CACnE,OAAO;EACL,IAAI,IAAI;EACR,SAAS,IAAI;EACb,WAAW,IAAI;EACf,QAAQ,IAAI;EACZ,SAAS,IAAI;EACb,UAAU,IAAI;EACd,YAAY,IAAI,WAAW,YAAY;CACzC;AACF"}
@@ -0,0 +1,100 @@
1
+ import { FactoryStorageDomain } from '@mastra/core/storage';
2
+ import type { CollectionSchema } from '@mastra/core/storage';
3
+ /**
4
+ * A reverse index from a platform sender identity to a Mastra tenant.
5
+ *
6
+ * Inbound channel events (a Slack DM, a Discord mention, ...) carry only the
7
+ * platform-side sender ids — there is no Mastra `(orgId, userId)` on the event.
8
+ * Model credentials, however, resolve **per-tenant**, so a channel run cannot
9
+ * load the sender's stored model credentials until we know which tenant the
10
+ * sender is. This domain holds that mapping: an authenticated web user links
11
+ * their platform account, and the dispatch seam reads it back to stamp the
12
+ * tenant onto the run's request context.
13
+ *
14
+ * One row per `(platform, external_team_id, external_user_id)` — the same
15
+ * platform user in two workspaces (two team ids) is two independent links, so
16
+ * multi-workspace falls out of the key. `platform` is generic (`'slack'` today,
17
+ * reusable for Discord/Telegram later). The `external_` prefix disambiguates
18
+ * the platform-side ids from the tenant ids (`org_id` / `user_id`) that cohabit
19
+ * the row.
20
+ */
21
+ export interface ChannelAccountLink {
22
+ /** Undefined for personal accounts (no organization). */
23
+ orgId?: string;
24
+ userId: string;
25
+ /**
26
+ * Which Factory project this sender's channel runs route to. Unset until
27
+ * the user picks one (or the dispatch path auto-stamps their only factory).
28
+ */
29
+ defaultFactoryProjectId?: string;
30
+ linkedAt: Date;
31
+ }
32
+ /** The reverse-lookup key: a platform sender identity. */
33
+ export interface ChannelAccountLinkKey {
34
+ platform: string;
35
+ externalTeamId: string;
36
+ externalUserId: string;
37
+ }
38
+ /**
39
+ * Human-readable labels for a linked identity, captured at link time (e.g.
40
+ * from Slack OIDC id_token claims). Display-only — never part of the key.
41
+ */
42
+ export interface ChannelAccountLinkNames {
43
+ externalTeamName?: string;
44
+ externalUserName?: string;
45
+ }
46
+ export declare const CHANNEL_ACCOUNT_LINKS_SCHEMA: CollectionSchema;
47
+ /** A link row with its platform sender key, as listed for a tenant user. */
48
+ export interface ChannelAccountLinkEntry extends ChannelAccountLink, ChannelAccountLinkKey, ChannelAccountLinkNames {
49
+ }
50
+ export declare class ChannelIdentityStorage extends FactoryStorageDomain {
51
+ #private;
52
+ constructor();
53
+ init(): Promise<void>;
54
+ dangerouslyClearAll(): Promise<void>;
55
+ /**
56
+ * Bind a platform sender identity to a Mastra tenant. Last-write-wins: a
57
+ * re-link (e.g. the same Slack user connecting a different tenant) replaces
58
+ * the stored tenant and refreshes `linkedAt`.
59
+ */
60
+ saveAccountLink({ platform, externalTeamId, externalUserId, orgId, userId, externalTeamName, externalUserName, }: ChannelAccountLinkKey & ChannelAccountLinkNames & {
61
+ orgId?: string;
62
+ userId: string;
63
+ }): Promise<ChannelAccountLink>;
64
+ /**
65
+ * Set (or clear, with `null`) which Factory project a link's channel runs
66
+ * route to. The `userId` guard makes this self-service only — a caller can
67
+ * never repoint another tenant's link. Returns whether a row was updated.
68
+ *
69
+ * Note: `saveAccountLink` deliberately omits this column from its upsert
70
+ * row, so a re-link keeps the stored default.
71
+ */
72
+ setDefaultFactory({ platform, externalTeamId, externalUserId, userId, factoryProjectId, }: ChannelAccountLinkKey & {
73
+ userId: string;
74
+ factoryProjectId: string | null;
75
+ }): Promise<boolean>;
76
+ /** Resolve the tenant a platform sender is linked to, or `null` if unlinked. */
77
+ getAccountLink({ platform, externalTeamId, externalUserId, }: ChannelAccountLinkKey): Promise<ChannelAccountLink | null>;
78
+ /** Remove a platform sender's link. Returns whether a row was deleted. */
79
+ deleteAccountLink({ platform, externalTeamId, externalUserId }: ChannelAccountLinkKey): Promise<boolean>;
80
+ /**
81
+ * All platform identities linked to a tenant user, for the "Connected
82
+ * accounts" settings surface. Keyed by the tenant `userId` alone — a link
83
+ * belongs to the person, and their personal/org context at link time does
84
+ * not change who may see or sever it.
85
+ */
86
+ listAccountLinksForUser(userId: string): Promise<ChannelAccountLinkEntry[]>;
87
+ /** All links bound to an organization, for the mention-roster fallback. */
88
+ listAccountLinksForOrg(orgId: string, { limit }?: {
89
+ limit?: number;
90
+ }): Promise<ChannelAccountLinkEntry[]>;
91
+ /**
92
+ * Remove one of the tenant user's own links, addressed by its sender key.
93
+ * The `userId` guard makes the delete self-service only: a caller can never
94
+ * sever another tenant's link even with a known sender key.
95
+ */
96
+ deleteAccountLinkForUser({ userId, platform, externalTeamId, externalUserId, }: ChannelAccountLinkKey & {
97
+ userId: string;
98
+ }): Promise<boolean>;
99
+ }
100
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/channel-identity/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,EAAE,IAAI,CAAC;CAChB;AAED,0DAA0D;AAC1D,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,4BAA4B,EAAE,gBA0B1C,CAAC;AAwBF,4EAA4E;AAC5E,MAAM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,wBAAwB,CAAC,EAC7B,MAAM,EACN,QAAQ,EACR,cAAc,EACd,cAAc,GACf,EAAE,qBAAqB,GAAG;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CASjE"}
@@ -0,0 +1,164 @@
1
+ import { FactoryStorageDomain } from "@mastra/core/storage";
2
+ //#region src/storage/domains/channel-identity/base.ts
3
+ const CHANNEL_ACCOUNT_LINKS_SCHEMA = {
4
+ name: "channel_account_links",
5
+ columns: {
6
+ id: { type: "uuid-pk" },
7
+ platform: { type: "text" },
8
+ external_team_id: { type: "text" },
9
+ external_user_id: { type: "text" },
10
+ org_id: {
11
+ type: "text",
12
+ nullable: true
13
+ },
14
+ user_id: { type: "text" },
15
+ external_team_name: {
16
+ type: "text",
17
+ nullable: true
18
+ },
19
+ external_user_name: {
20
+ type: "text",
21
+ nullable: true
22
+ },
23
+ default_factory_project_id: {
24
+ type: "text",
25
+ nullable: true
26
+ },
27
+ linked_at: { type: "timestamp" }
28
+ },
29
+ uniqueIndexes: [{
30
+ name: "channel_account_links_sender_key",
31
+ columns: [
32
+ "platform",
33
+ "external_team_id",
34
+ "external_user_id"
35
+ ]
36
+ }],
37
+ indexes: [{
38
+ name: "channel_account_links_org_linked_at_id_idx",
39
+ columns: [
40
+ "org_id",
41
+ "linked_at",
42
+ "id"
43
+ ]
44
+ }]
45
+ };
46
+ function toLink(row) {
47
+ return {
48
+ ...row.org_id ? { orgId: row.org_id } : {},
49
+ userId: row.user_id,
50
+ ...row.default_factory_project_id ? { defaultFactoryProjectId: row.default_factory_project_id } : {},
51
+ linkedAt: row.linked_at
52
+ };
53
+ }
54
+ function toEntry(row) {
55
+ return {
56
+ ...toLink(row),
57
+ platform: row.platform,
58
+ externalTeamId: row.external_team_id,
59
+ externalUserId: row.external_user_id,
60
+ ...row.external_team_name ? { externalTeamName: row.external_team_name } : {},
61
+ ...row.external_user_name ? { externalUserName: row.external_user_name } : {}
62
+ };
63
+ }
64
+ var ChannelIdentityStorage = class extends FactoryStorageDomain {
65
+ constructor() {
66
+ super("channel-identity");
67
+ }
68
+ async init() {
69
+ await this.ensureCollections([CHANNEL_ACCOUNT_LINKS_SCHEMA]);
70
+ }
71
+ async dangerouslyClearAll() {
72
+ await this.ops.deleteMany("channel_account_links", {});
73
+ }
74
+ get #db() {
75
+ return this.ops;
76
+ }
77
+ /**
78
+ * Bind a platform sender identity to a Mastra tenant. Last-write-wins: a
79
+ * re-link (e.g. the same Slack user connecting a different tenant) replaces
80
+ * the stored tenant and refreshes `linkedAt`.
81
+ */
82
+ async saveAccountLink({ platform, externalTeamId, externalUserId, orgId, userId, externalTeamName, externalUserName }) {
83
+ return toLink(await this.#db.upsertOne("channel_account_links", [
84
+ "platform",
85
+ "external_team_id",
86
+ "external_user_id"
87
+ ], {
88
+ platform,
89
+ external_team_id: externalTeamId,
90
+ external_user_id: externalUserId,
91
+ org_id: orgId ?? null,
92
+ user_id: userId,
93
+ external_team_name: externalTeamName ?? null,
94
+ external_user_name: externalUserName ?? null,
95
+ linked_at: /* @__PURE__ */ new Date()
96
+ }));
97
+ }
98
+ /**
99
+ * Set (or clear, with `null`) which Factory project a link's channel runs
100
+ * route to. The `userId` guard makes this self-service only — a caller can
101
+ * never repoint another tenant's link. Returns whether a row was updated.
102
+ *
103
+ * Note: `saveAccountLink` deliberately omits this column from its upsert
104
+ * row, so a re-link keeps the stored default.
105
+ */
106
+ async setDefaultFactory({ platform, externalTeamId, externalUserId, userId, factoryProjectId }) {
107
+ return await this.#db.updateMany("channel_account_links", {
108
+ user_id: userId,
109
+ platform,
110
+ external_team_id: externalTeamId,
111
+ external_user_id: externalUserId
112
+ }, { default_factory_project_id: factoryProjectId }) > 0;
113
+ }
114
+ /** Resolve the tenant a platform sender is linked to, or `null` if unlinked. */
115
+ async getAccountLink({ platform, externalTeamId, externalUserId }) {
116
+ const row = await this.#db.findOne("channel_account_links", {
117
+ platform,
118
+ external_team_id: externalTeamId,
119
+ external_user_id: externalUserId
120
+ });
121
+ return row ? toLink(row) : null;
122
+ }
123
+ /** Remove a platform sender's link. Returns whether a row was deleted. */
124
+ async deleteAccountLink({ platform, externalTeamId, externalUserId }) {
125
+ return await this.#db.deleteMany("channel_account_links", {
126
+ platform,
127
+ external_team_id: externalTeamId,
128
+ external_user_id: externalUserId
129
+ }) > 0;
130
+ }
131
+ /**
132
+ * All platform identities linked to a tenant user, for the "Connected
133
+ * accounts" settings surface. Keyed by the tenant `userId` alone — a link
134
+ * belongs to the person, and their personal/org context at link time does
135
+ * not change who may see or sever it.
136
+ */
137
+ async listAccountLinksForUser(userId) {
138
+ return (await this.#db.findMany("channel_account_links", { user_id: userId })).map(toEntry);
139
+ }
140
+ /** All links bound to an organization, for the mention-roster fallback. */
141
+ async listAccountLinksForOrg(orgId, { limit = 200 } = {}) {
142
+ return (await this.#db.findMany("channel_account_links", { org_id: orgId }, {
143
+ orderBy: [["linked_at", "desc"], ["id", "desc"]],
144
+ limit
145
+ })).map(toEntry);
146
+ }
147
+ /**
148
+ * Remove one of the tenant user's own links, addressed by its sender key.
149
+ * The `userId` guard makes the delete self-service only: a caller can never
150
+ * sever another tenant's link even with a known sender key.
151
+ */
152
+ async deleteAccountLinkForUser({ userId, platform, externalTeamId, externalUserId }) {
153
+ return await this.#db.deleteMany("channel_account_links", {
154
+ user_id: userId,
155
+ platform,
156
+ external_team_id: externalTeamId,
157
+ external_user_id: externalUserId
158
+ }) > 0;
159
+ }
160
+ };
161
+ //#endregion
162
+ export { CHANNEL_ACCOUNT_LINKS_SCHEMA, ChannelIdentityStorage };
163
+
164
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","names":["#db"],"sources":["../../../../src/storage/domains/channel-identity/base.ts"],"sourcesContent":["import { FactoryStorageDomain } from '@mastra/core/storage';\nimport type { CollectionSchema, FactoryStorageOps } from '@mastra/core/storage';\n\n/**\n * A reverse index from a platform sender identity to a Mastra tenant.\n *\n * Inbound channel events (a Slack DM, a Discord mention, ...) carry only the\n * platform-side sender ids — there is no Mastra `(orgId, userId)` on the event.\n * Model credentials, however, resolve **per-tenant**, so a channel run cannot\n * load the sender's stored model credentials until we know which tenant the\n * sender is. This domain holds that mapping: an authenticated web user links\n * their platform account, and the dispatch seam reads it back to stamp the\n * tenant onto the run's request context.\n *\n * One row per `(platform, external_team_id, external_user_id)` — the same\n * platform user in two workspaces (two team ids) is two independent links, so\n * multi-workspace falls out of the key. `platform` is generic (`'slack'` today,\n * reusable for Discord/Telegram later). The `external_` prefix disambiguates\n * the platform-side ids from the tenant ids (`org_id` / `user_id`) that cohabit\n * the row.\n */\nexport interface ChannelAccountLink {\n /** Undefined for personal accounts (no organization). */\n orgId?: string;\n userId: string;\n /**\n * Which Factory project this sender's channel runs route to. Unset until\n * the user picks one (or the dispatch path auto-stamps their only factory).\n */\n defaultFactoryProjectId?: string;\n linkedAt: Date;\n}\n\n/** The reverse-lookup key: a platform sender identity. */\nexport interface ChannelAccountLinkKey {\n platform: string;\n externalTeamId: string;\n externalUserId: string;\n}\n\n/**\n * Human-readable labels for a linked identity, captured at link time (e.g.\n * from Slack OIDC id_token claims). Display-only — never part of the key.\n */\nexport interface ChannelAccountLinkNames {\n externalTeamName?: string;\n externalUserName?: string;\n}\n\nexport const CHANNEL_ACCOUNT_LINKS_SCHEMA: CollectionSchema = {\n name: 'channel_account_links',\n columns: {\n id: { type: 'uuid-pk' },\n platform: { type: 'text' },\n external_team_id: { type: 'text' },\n external_user_id: { type: 'text' },\n org_id: { type: 'text', nullable: true },\n user_id: { type: 'text' },\n external_team_name: { type: 'text', nullable: true },\n external_user_name: { type: 'text', nullable: true },\n default_factory_project_id: { type: 'text', nullable: true },\n linked_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'channel_account_links_sender_key',\n columns: ['platform', 'external_team_id', 'external_user_id'],\n },\n ],\n indexes: [\n {\n name: 'channel_account_links_org_linked_at_id_idx',\n columns: ['org_id', 'linked_at', 'id'],\n },\n ],\n};\n\ninterface ChannelAccountLinkDbRow extends Record<string, unknown> {\n id: string;\n platform: string;\n external_team_id: string;\n external_user_id: string;\n org_id: string | null;\n user_id: string;\n external_team_name: string | null;\n external_user_name: string | null;\n default_factory_project_id: string | null;\n linked_at: Date;\n}\n\nfunction toLink(row: ChannelAccountLinkDbRow): ChannelAccountLink {\n return {\n ...(row.org_id ? { orgId: row.org_id } : {}),\n userId: row.user_id,\n ...(row.default_factory_project_id ? { defaultFactoryProjectId: row.default_factory_project_id } : {}),\n linkedAt: row.linked_at,\n };\n}\n\n/** A link row with its platform sender key, as listed for a tenant user. */\nexport interface ChannelAccountLinkEntry extends ChannelAccountLink, ChannelAccountLinkKey, ChannelAccountLinkNames {}\n\nfunction toEntry(row: ChannelAccountLinkDbRow): ChannelAccountLinkEntry {\n return {\n ...toLink(row),\n platform: row.platform,\n externalTeamId: row.external_team_id,\n externalUserId: row.external_user_id,\n ...(row.external_team_name ? { externalTeamName: row.external_team_name } : {}),\n ...(row.external_user_name ? { externalUserName: row.external_user_name } : {}),\n };\n}\n\nexport class ChannelIdentityStorage extends FactoryStorageDomain {\n constructor() {\n super('channel-identity');\n }\n\n async init(): Promise<void> {\n await this.ensureCollections([CHANNEL_ACCOUNT_LINKS_SCHEMA]);\n }\n\n async dangerouslyClearAll(): Promise<void> {\n await this.ops.deleteMany('channel_account_links', {});\n }\n\n get #db(): FactoryStorageOps {\n return this.ops;\n }\n\n /**\n * Bind a platform sender identity to a Mastra tenant. Last-write-wins: a\n * re-link (e.g. the same Slack user connecting a different tenant) replaces\n * the stored tenant and refreshes `linkedAt`.\n */\n async saveAccountLink({\n platform,\n externalTeamId,\n externalUserId,\n orgId,\n userId,\n externalTeamName,\n externalUserName,\n }: ChannelAccountLinkKey &\n ChannelAccountLinkNames & { orgId?: string; userId: string }): Promise<ChannelAccountLink> {\n const row = await this.#db.upsertOne<ChannelAccountLinkDbRow>(\n 'channel_account_links',\n ['platform', 'external_team_id', 'external_user_id'],\n {\n platform,\n external_team_id: externalTeamId,\n external_user_id: externalUserId,\n org_id: orgId ?? null,\n user_id: userId,\n external_team_name: externalTeamName ?? null,\n external_user_name: externalUserName ?? null,\n linked_at: new Date(),\n },\n );\n return toLink(row);\n }\n\n /**\n * Set (or clear, with `null`) which Factory project a link's channel runs\n * route to. The `userId` guard makes this self-service only — a caller can\n * never repoint another tenant's link. Returns whether a row was updated.\n *\n * Note: `saveAccountLink` deliberately omits this column from its upsert\n * row, so a re-link keeps the stored default.\n */\n async setDefaultFactory({\n platform,\n externalTeamId,\n externalUserId,\n userId,\n factoryProjectId,\n }: ChannelAccountLinkKey & { userId: string; factoryProjectId: string | null }): Promise<boolean> {\n const updated = await this.#db.updateMany(\n 'channel_account_links',\n {\n user_id: userId,\n platform,\n external_team_id: externalTeamId,\n external_user_id: externalUserId,\n },\n { default_factory_project_id: factoryProjectId },\n );\n return updated > 0;\n }\n\n /** Resolve the tenant a platform sender is linked to, or `null` if unlinked. */\n async getAccountLink({\n platform,\n externalTeamId,\n externalUserId,\n }: ChannelAccountLinkKey): Promise<ChannelAccountLink | null> {\n const row = await this.#db.findOne<ChannelAccountLinkDbRow>('channel_account_links', {\n platform,\n external_team_id: externalTeamId,\n external_user_id: externalUserId,\n });\n return row ? toLink(row) : null;\n }\n\n /** Remove a platform sender's link. Returns whether a row was deleted. */\n async deleteAccountLink({ platform, externalTeamId, externalUserId }: ChannelAccountLinkKey): Promise<boolean> {\n const deleted = await this.#db.deleteMany('channel_account_links', {\n platform,\n external_team_id: externalTeamId,\n external_user_id: externalUserId,\n });\n return deleted > 0;\n }\n\n /**\n * All platform identities linked to a tenant user, for the \"Connected\n * accounts\" settings surface. Keyed by the tenant `userId` alone — a link\n * belongs to the person, and their personal/org context at link time does\n * not change who may see or sever it.\n */\n async listAccountLinksForUser(userId: string): Promise<ChannelAccountLinkEntry[]> {\n const rows = await this.#db.findMany<ChannelAccountLinkDbRow>('channel_account_links', { user_id: userId });\n return rows.map(toEntry);\n }\n\n /** All links bound to an organization, for the mention-roster fallback. */\n async listAccountLinksForOrg(\n orgId: string,\n { limit = 200 }: { limit?: number } = {},\n ): Promise<ChannelAccountLinkEntry[]> {\n const rows = await this.#db.findMany<ChannelAccountLinkDbRow>(\n 'channel_account_links',\n { org_id: orgId },\n {\n orderBy: [\n ['linked_at', 'desc'],\n ['id', 'desc'],\n ],\n limit,\n },\n );\n return rows.map(toEntry);\n }\n\n /**\n * Remove one of the tenant user's own links, addressed by its sender key.\n * The `userId` guard makes the delete self-service only: a caller can never\n * sever another tenant's link even with a known sender key.\n */\n async deleteAccountLinkForUser({\n userId,\n platform,\n externalTeamId,\n externalUserId,\n }: ChannelAccountLinkKey & { userId: string }): Promise<boolean> {\n const deleted = await this.#db.deleteMany('channel_account_links', {\n user_id: userId,\n platform,\n external_team_id: externalTeamId,\n external_user_id: externalUserId,\n });\n return deleted > 0;\n }\n}\n"],"mappings":";;AAiDA,MAAa,+BAAiD;CAC5D,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,UAAU,EAAE,MAAM,OAAO;EACzB,kBAAkB,EAAE,MAAM,OAAO;EACjC,kBAAkB,EAAE,MAAM,OAAO;EACjC,QAAQ;GAAE,MAAM;GAAQ,UAAU;EAAK;EACvC,SAAS,EAAE,MAAM,OAAO;EACxB,oBAAoB;GAAE,MAAM;GAAQ,UAAU;EAAK;EACnD,oBAAoB;GAAE,MAAM;GAAQ,UAAU;EAAK;EACnD,4BAA4B;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC3D,WAAW,EAAE,MAAM,YAAY;CACjC;CACA,eAAe,CACb;EACE,MAAM;EACN,SAAS;GAAC;GAAY;GAAoB;EAAkB;CAC9D,CACF;CACA,SAAS,CACP;EACE,MAAM;EACN,SAAS;GAAC;GAAU;GAAa;EAAI;CACvC,CACF;AACF;AAeA,SAAS,OAAO,KAAkD;CAChE,OAAO;EACL,GAAI,IAAI,SAAS,EAAE,OAAO,IAAI,OAAO,IAAI,CAAC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