@capybara-hq/kernel 0.1.0-rc.0 → 0.1.0-rc.2

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 (626) hide show
  1. package/bootstrap.json +10 -6
  2. package/dist/admin/admin.controller.d.ts +17 -17
  3. package/dist/admin/admin.controller.js +43 -26
  4. package/dist/admin/admin.module.d.ts +3 -0
  5. package/dist/admin/admin.module.js +22 -0
  6. package/dist/admin/extensions.controller.d.ts +14 -14
  7. package/dist/admin/extensions.controller.js +30 -17
  8. package/dist/admin/setup-lock.d.ts +16 -0
  9. package/dist/admin/setup-lock.js +47 -0
  10. package/dist/admin/setup.controller.d.ts +8 -8
  11. package/dist/admin/setup.controller.js +27 -25
  12. package/dist/admin/setup.service.d.ts +19 -27
  13. package/dist/admin/setup.service.js +61 -61
  14. package/dist/agents/agent-lookup.d.ts +53 -0
  15. package/dist/agents/agent-lookup.js +179 -0
  16. package/dist/agents/agents.controller.d.ts +1 -1
  17. package/dist/agents/agents.controller.js +14 -8
  18. package/dist/agents/agents.module.d.ts +7 -0
  19. package/dist/agents/agents.module.js +41 -0
  20. package/dist/agents/agents.service.d.ts +39 -58
  21. package/dist/agents/agents.service.js +261 -329
  22. package/dist/agents/definition.d.ts +8 -0
  23. package/dist/agents/definition.js +8 -0
  24. package/dist/agents/models.controller.d.ts +1 -1
  25. package/dist/agents/models.controller.js +2 -2
  26. package/dist/agents/templates.controller.d.ts +1 -1
  27. package/dist/agents/templates.controller.js +2 -2
  28. package/dist/agents/templates.d.ts +6 -8
  29. package/dist/agents/templates.js +20 -4
  30. package/dist/app.d.ts +93 -0
  31. package/dist/app.js +150 -0
  32. package/dist/catalog/admin-catalog.controller.d.ts +3 -3
  33. package/dist/catalog/admin-catalog.controller.js +27 -13
  34. package/dist/catalog/catalog-content.d.ts +185 -0
  35. package/dist/catalog/catalog-content.js +323 -0
  36. package/dist/catalog/catalog-items.d.ts +186 -0
  37. package/dist/catalog/catalog-items.js +410 -0
  38. package/dist/catalog/catalog.module.d.ts +14 -0
  39. package/dist/catalog/catalog.module.js +71 -0
  40. package/dist/catalog/catalog.service.d.ts +34 -188
  41. package/dist/catalog/catalog.service.js +155 -489
  42. package/dist/catalog/cli.d.ts +3 -2
  43. package/dist/catalog/cli.js +13 -31
  44. package/dist/catalog/job-ids.d.ts +15 -0
  45. package/dist/catalog/job-ids.js +15 -0
  46. package/dist/catalog/jobs.d.ts +27 -0
  47. package/dist/catalog/jobs.js +70 -0
  48. package/dist/catalog/locks.d.ts +24 -0
  49. package/dist/catalog/locks.js +63 -0
  50. package/dist/catalog/marketplaces.controller.d.ts +4 -4
  51. package/dist/catalog/marketplaces.controller.js +22 -11
  52. package/dist/catalog/marketplaces.service.d.ts +30 -13
  53. package/dist/catalog/marketplaces.service.js +330 -256
  54. package/dist/catalog/org-catalog.controller.d.ts +4 -3
  55. package/dist/catalog/org-catalog.controller.js +29 -14
  56. package/dist/catalog/org-catalog.service.d.ts +32 -198
  57. package/dist/catalog/org-catalog.service.js +159 -400
  58. package/dist/catalog/plugin-import.d.ts +73 -34
  59. package/dist/catalog/plugin-import.js +356 -217
  60. package/dist/catalog/plugin-install.d.ts +83 -41
  61. package/dist/catalog/plugin-install.js +421 -269
  62. package/dist/catalog/plugin-upgrade.d.ts +59 -4
  63. package/dist/catalog/plugin-upgrade.js +407 -282
  64. package/dist/catalog/requests.service.d.ts +27 -15
  65. package/dist/catalog/requests.service.js +201 -145
  66. package/dist/catalog/upgrade-targets.d.ts +4 -7
  67. package/dist/channels/actions.d.ts +6 -4
  68. package/dist/channels/actions.js +1 -1
  69. package/dist/channels/cards.d.ts +2 -2
  70. package/dist/channels/channels.module.d.ts +40 -0
  71. package/dist/channels/channels.module.js +128 -0
  72. package/dist/channels/connections.controller.d.ts +1 -1
  73. package/dist/channels/connections.controller.js +11 -6
  74. package/dist/channels/connections.service.d.ts +43 -21
  75. package/dist/channels/connections.service.js +236 -131
  76. package/dist/channels/inbound.d.ts +34 -38
  77. package/dist/channels/inbound.js +107 -41
  78. package/dist/channels/job-ids.d.ts +10 -0
  79. package/dist/channels/job-ids.js +10 -0
  80. package/dist/channels/jobs.d.ts +85 -0
  81. package/dist/channels/jobs.js +157 -0
  82. package/dist/channels/outbound.d.ts +60 -82
  83. package/dist/channels/outbound.js +165 -193
  84. package/dist/channels/supervisor.d.ts +88 -46
  85. package/dist/channels/supervisor.js +230 -132
  86. package/dist/channels/threads.d.ts +29 -8
  87. package/dist/channels/threads.js +71 -13
  88. package/dist/channels/webhook.d.ts +20 -14
  89. package/dist/channels/webhook.js +51 -20
  90. package/dist/config/load.d.ts +3 -2
  91. package/dist/config/load.js +3 -2
  92. package/dist/config/nacos-source.js +11 -2
  93. package/dist/config/schema.d.ts +16 -1
  94. package/dist/config/schema.js +54 -7
  95. package/dist/conversations/access.d.ts +29 -0
  96. package/dist/conversations/access.js +86 -0
  97. package/dist/conversations/artifacts.d.ts +10 -10
  98. package/dist/conversations/artifacts.js +35 -9
  99. package/dist/conversations/attachments.controller.d.ts +1 -1
  100. package/dist/conversations/attachments.controller.js +8 -6
  101. package/dist/conversations/attachments.module.d.ts +7 -0
  102. package/dist/conversations/attachments.module.js +25 -0
  103. package/dist/conversations/attachments.service.d.ts +30 -22
  104. package/dist/conversations/attachments.service.js +119 -46
  105. package/dist/conversations/conversations.controller.d.ts +8 -7
  106. package/dist/conversations/conversations.controller.js +59 -29
  107. package/dist/conversations/conversations.module.d.ts +8 -0
  108. package/dist/conversations/conversations.module.js +69 -0
  109. package/dist/conversations/conversations.service.d.ts +40 -38
  110. package/dist/conversations/conversations.service.js +130 -140
  111. package/dist/conversations/event-log.d.ts +28 -18
  112. package/dist/conversations/event-log.js +74 -27
  113. package/dist/conversations/files.d.ts +10 -10
  114. package/dist/conversations/files.js +37 -11
  115. package/dist/conversations/idem-keys.d.ts +5 -0
  116. package/dist/conversations/idem-keys.js +5 -0
  117. package/dist/conversations/job-ids.d.ts +6 -0
  118. package/dist/conversations/job-ids.js +6 -0
  119. package/dist/conversations/outputs-read.d.ts +11 -11
  120. package/dist/conversations/outputs-read.js +31 -7
  121. package/dist/conversations/queue.d.ts +48 -56
  122. package/dist/conversations/queue.js +13 -289
  123. package/dist/conversations/queue.service.d.ts +60 -0
  124. package/dist/conversations/queue.service.js +343 -0
  125. package/dist/conversations/sandbox-status.d.ts +13 -10
  126. package/dist/conversations/sandbox-status.js +36 -8
  127. package/dist/conversations/titles.d.ts +71 -24
  128. package/dist/conversations/titles.js +159 -62
  129. package/dist/ctx/bus.js +9 -3
  130. package/dist/ctx/create-ctx.d.ts +6 -0
  131. package/dist/ctx/create-ctx.js +7 -9
  132. package/dist/ctx/lock.d.ts +7 -3
  133. package/dist/ctx/lock.js +9 -20
  134. package/dist/ctx/queue.js +3 -2
  135. package/dist/ctx/secrets.d.ts +10 -2
  136. package/dist/ctx/secrets.js +7 -3
  137. package/dist/db/kernel-schema.d.ts +2 -2
  138. package/dist/db/pool.d.ts +5 -0
  139. package/dist/db/pool.js +1 -0
  140. package/dist/errors.d.ts +2 -0
  141. package/dist/errors.js +2 -0
  142. package/dist/evals/budget.d.ts +42 -21
  143. package/dist/evals/budget.js +114 -62
  144. package/dist/evals/evals.module.d.ts +31 -0
  145. package/dist/evals/evals.module.js +114 -0
  146. package/dist/evals/jobs.d.ts +20 -0
  147. package/dist/evals/jobs.js +45 -0
  148. package/dist/evals/run-replay.d.ts +56 -8
  149. package/dist/evals/run-replay.js +140 -80
  150. package/dist/evals/runs.controller.d.ts +1 -1
  151. package/dist/evals/runs.controller.js +17 -8
  152. package/dist/evals/runs.service.d.ts +23 -45
  153. package/dist/evals/runs.service.js +245 -234
  154. package/dist/evals/sets.controller.d.ts +1 -1
  155. package/dist/evals/sets.controller.js +17 -8
  156. package/dist/evals/sets.service.d.ts +22 -6
  157. package/dist/evals/sets.service.js +248 -194
  158. package/dist/evals/snapshot.d.ts +2 -2
  159. package/dist/evals/step-replay.d.ts +2 -2
  160. package/dist/evals/step-replay.js +1 -1
  161. package/dist/evals/trajectory.controller.d.ts +1 -1
  162. package/dist/evals/trajectory.controller.js +11 -7
  163. package/dist/evals/trajectory.service.d.ts +5 -4
  164. package/dist/evals/trajectory.service.js +30 -7
  165. package/dist/evals/worker.d.ts +44 -27
  166. package/dist/evals/worker.js +220 -120
  167. package/dist/extensions/admin-ops.d.ts +61 -33
  168. package/dist/extensions/admin-ops.js +248 -154
  169. package/dist/extensions/admin-view.d.ts +38 -27
  170. package/dist/extensions/admin-view.js +126 -55
  171. package/dist/extensions/approvals.d.ts +12 -8
  172. package/dist/extensions/approvals.js +73 -46
  173. package/dist/extensions/blobs.d.ts +27 -10
  174. package/dist/extensions/blobs.js +111 -45
  175. package/dist/extensions/bootstrap.d.ts +96 -42
  176. package/dist/extensions/bootstrap.js +303 -155
  177. package/dist/extensions/cli.d.ts +20 -10
  178. package/dist/extensions/cli.js +41 -96
  179. package/dist/extensions/config-issues.d.ts +7 -0
  180. package/dist/extensions/config-issues.js +31 -0
  181. package/dist/extensions/deployment-config-store.d.ts +49 -0
  182. package/dist/extensions/deployment-config-store.js +133 -0
  183. package/dist/extensions/deployment-config.d.ts +58 -67
  184. package/dist/extensions/deployment-config.js +202 -230
  185. package/dist/extensions/enabled.d.ts +5 -5
  186. package/dist/extensions/extensions.module.d.ts +8 -0
  187. package/dist/extensions/extensions.module.js +77 -0
  188. package/dist/extensions/hooks.d.ts +3 -2
  189. package/dist/extensions/hooks.js +1 -1
  190. package/dist/extensions/host.d.ts +72 -68
  191. package/dist/extensions/host.js +191 -152
  192. package/dist/extensions/installs.d.ts +49 -16
  193. package/dist/extensions/installs.js +128 -32
  194. package/dist/extensions/job-ids.d.ts +6 -0
  195. package/dist/extensions/job-ids.js +6 -0
  196. package/dist/extensions/lifecycle-topics.d.ts +18 -0
  197. package/dist/extensions/lifecycle-topics.js +18 -0
  198. package/dist/extensions/lifecycle.d.ts +35 -47
  199. package/dist/extensions/lifecycle.js +103 -39
  200. package/dist/extensions/locks.d.ts +33 -0
  201. package/dist/extensions/locks.js +86 -0
  202. package/dist/extensions/migrate-lock.d.ts +3 -4
  203. package/dist/extensions/org-config.controller.d.ts +1 -1
  204. package/dist/extensions/org-config.controller.js +8 -5
  205. package/dist/extensions/org-config.d.ts +48 -46
  206. package/dist/extensions/org-config.js +284 -226
  207. package/dist/extensions/registry.d.ts +50 -2
  208. package/dist/extensions/registry.js +89 -4
  209. package/dist/extensions/sources.d.ts +12 -8
  210. package/dist/extensions/sources.js +34 -13
  211. package/dist/files/files.module.d.ts +3 -0
  212. package/dist/files/files.module.js +22 -0
  213. package/dist/files/previewers.controller.d.ts +7 -2
  214. package/dist/files/previewers.controller.js +17 -9
  215. package/dist/files/previewers.d.ts +13 -18
  216. package/dist/files/previewers.js +83 -36
  217. package/dist/http/adapter.d.ts +3 -0
  218. package/dist/http/adapter.js +25 -0
  219. package/dist/http/api.module.d.ts +3 -110
  220. package/dist/http/api.module.js +47 -355
  221. package/dist/http/app.d.ts +11 -15
  222. package/dist/http/app.js +52 -47
  223. package/dist/http/error-filter.module.d.ts +5 -0
  224. package/dist/http/error-filter.module.js +18 -0
  225. package/dist/http/error.filter.js +2 -2
  226. package/dist/identity/accounts.d.ts +82 -29
  227. package/dist/identity/accounts.js +294 -175
  228. package/dist/identity/api-tokens.d.ts +11 -7
  229. package/dist/identity/api-tokens.js +71 -44
  230. package/dist/identity/audit.d.ts +7 -4
  231. package/dist/identity/audit.js +5 -1
  232. package/dist/identity/auth.controller.d.ts +11 -10
  233. package/dist/identity/auth.controller.js +31 -25
  234. package/dist/identity/auth.guard.d.ts +3 -3
  235. package/dist/identity/auth.guard.js +6 -4
  236. package/dist/identity/binding.d.ts +9 -11
  237. package/dist/identity/binding.js +41 -13
  238. package/dist/identity/enterprise-admin.d.ts +18 -12
  239. package/dist/identity/enterprise-admin.js +67 -13
  240. package/dist/identity/external-identity-lock.d.ts +17 -0
  241. package/dist/identity/external-identity-lock.js +39 -0
  242. package/dist/identity/external.d.ts +19 -15
  243. package/dist/identity/external.js +163 -125
  244. package/dist/identity/identity.module.d.ts +6 -0
  245. package/dist/identity/identity.module.js +56 -0
  246. package/dist/identity/me.controller.d.ts +16 -15
  247. package/dist/identity/me.controller.js +37 -31
  248. package/dist/identity/sessions.d.ts +12 -10
  249. package/dist/identity/sessions.js +74 -42
  250. package/dist/identity/settings.d.ts +20 -14
  251. package/dist/identity/settings.js +85 -57
  252. package/dist/identity/sso.controller.d.ts +7 -7
  253. package/dist/identity/sso.controller.js +13 -9
  254. package/dist/identity/sso.d.ts +9 -12
  255. package/dist/identity/sso.js +54 -24
  256. package/dist/inbox/inbox.module.d.ts +3 -0
  257. package/dist/inbox/inbox.module.js +22 -0
  258. package/dist/inbox/inbox.service.d.ts +7 -9
  259. package/dist/inbox/inbox.service.js +32 -11
  260. package/dist/index.d.ts +19 -12
  261. package/dist/index.js +13 -8
  262. package/dist/infra/cache/cache.module.d.ts +3 -0
  263. package/dist/infra/cache/cache.module.js +16 -0
  264. package/dist/infra/cache/cache.service.d.ts +21 -0
  265. package/dist/infra/cache/cache.service.js +80 -0
  266. package/dist/infra/cache/cacheable.decorator.d.ts +32 -0
  267. package/dist/infra/cache/cacheable.decorator.js +83 -0
  268. package/dist/infra/cli/kernel-cli.module.d.ts +66 -0
  269. package/dist/infra/cli/kernel-cli.module.js +165 -0
  270. package/dist/infra/close-within.d.ts +15 -0
  271. package/dist/infra/close-within.js +36 -0
  272. package/dist/infra/config/config.module.d.ts +13 -0
  273. package/dist/infra/config/config.module.js +39 -0
  274. package/dist/infra/config/kernel-config.service.d.ts +25 -0
  275. package/dist/infra/config/kernel-config.service.js +126 -0
  276. package/dist/infra/database/after-commit.d.ts +6 -0
  277. package/dist/infra/database/after-commit.js +9 -0
  278. package/dist/infra/database/database.module.d.ts +25 -0
  279. package/dist/infra/database/database.module.js +90 -0
  280. package/dist/infra/database/kernel-db.d.ts +22 -0
  281. package/dist/infra/database/kernel-db.js +65 -0
  282. package/dist/infra/database/transaction-host.d.ts +50 -0
  283. package/dist/infra/database/transaction-host.js +125 -0
  284. package/dist/infra/database/transactional.decorator.d.ts +15 -0
  285. package/dist/infra/database/transactional.decorator.js +27 -0
  286. package/dist/infra/database/xact-lock.d.ts +17 -0
  287. package/dist/infra/database/xact-lock.js +43 -0
  288. package/dist/infra/events/kernel-events.d.ts +96 -0
  289. package/dist/infra/events/kernel-events.js +65 -0
  290. package/dist/infra/health/health.controller.d.ts +26 -0
  291. package/dist/infra/health/health.controller.js +104 -0
  292. package/dist/infra/health/health.module.d.ts +9 -0
  293. package/dist/infra/health/health.module.js +24 -0
  294. package/dist/infra/health/health.options.d.ts +10 -0
  295. package/dist/infra/health/health.options.js +15 -0
  296. package/dist/infra/health/shutdown-state.d.ts +6 -0
  297. package/dist/infra/health/shutdown-state.js +2 -0
  298. package/dist/infra/lifecycle/graceful-shutdown.module.d.ts +6 -0
  299. package/dist/infra/lifecycle/graceful-shutdown.module.js +23 -0
  300. package/dist/infra/lifecycle/graceful-shutdown.service.d.ts +70 -0
  301. package/dist/infra/lifecycle/graceful-shutdown.service.js +135 -0
  302. package/dist/infra/lifecycle/process-guards.d.ts +52 -0
  303. package/dist/infra/lifecycle/process-guards.js +86 -0
  304. package/dist/infra/lifecycle/shutdown-signals.d.ts +30 -0
  305. package/dist/infra/lifecycle/shutdown-signals.js +48 -0
  306. package/dist/infra/lock/key-template.d.ts +13 -0
  307. package/dist/infra/lock/key-template.js +46 -0
  308. package/dist/infra/lock/lock.module.d.ts +3 -0
  309. package/dist/infra/lock/lock.module.js +16 -0
  310. package/dist/infra/lock/lock.service.d.ts +120 -0
  311. package/dist/infra/lock/lock.service.js +343 -0
  312. package/dist/infra/lock/shared-lease.d.ts +44 -0
  313. package/dist/infra/lock/shared-lease.js +121 -0
  314. package/dist/infra/lock/with-lock.decorator.d.ts +28 -0
  315. package/dist/infra/lock/with-lock.decorator.js +49 -0
  316. package/dist/infra/logging/logging.module.d.ts +16 -0
  317. package/dist/infra/logging/logging.module.js +34 -0
  318. package/dist/infra/queue/configured-processor.d.ts +18 -0
  319. package/dist/infra/queue/configured-processor.js +23 -0
  320. package/dist/infra/queue/job-failure.d.ts +18 -0
  321. package/dist/infra/queue/job-failure.js +26 -0
  322. package/dist/infra/queue/queue-shutdown.d.ts +27 -0
  323. package/dist/infra/queue/queue-shutdown.js +81 -0
  324. package/dist/infra/queue/queue.module.d.ts +16 -0
  325. package/dist/infra/queue/queue.module.js +61 -0
  326. package/dist/infra/queue/redis-connection.d.ts +7 -0
  327. package/dist/infra/queue/redis-connection.js +18 -0
  328. package/dist/infra/queue/retired-schedulers.d.ts +7 -0
  329. package/dist/infra/queue/retired-schedulers.js +9 -0
  330. package/dist/infra/queue/run-job.d.ts +16 -0
  331. package/dist/infra/queue/run-job.js +19 -0
  332. package/dist/infra/redis/redis.module.d.ts +24 -0
  333. package/dist/infra/redis/redis.module.js +87 -0
  334. package/dist/infra/schedule/cron-tick.d.ts +12 -0
  335. package/dist/infra/schedule/cron-tick.js +25 -0
  336. package/dist/infra/schedule/locked-cron.decorator.d.ts +27 -0
  337. package/dist/infra/schedule/locked-cron.decorator.js +53 -0
  338. package/dist/infra/schedule/locked-interval.d.ts +69 -0
  339. package/dist/infra/schedule/locked-interval.js +190 -0
  340. package/dist/infra/schedule/locked-tick.d.ts +90 -0
  341. package/dist/infra/schedule/locked-tick.js +137 -0
  342. package/dist/infra/schedule/schedule.module.d.ts +8 -0
  343. package/dist/infra/schedule/schedule.module.js +27 -0
  344. package/dist/infra/schedule/scheduled-runs.d.ts +69 -0
  345. package/dist/infra/schedule/scheduled-runs.js +163 -0
  346. package/dist/infra/swagger/swagger.d.ts +16 -0
  347. package/dist/infra/swagger/swagger.js +31 -0
  348. package/dist/infra/throttler/credential-throttler.d.ts +35 -0
  349. package/dist/infra/throttler/credential-throttler.js +77 -0
  350. package/dist/infra/throttler/named-throttlers.d.ts +31 -0
  351. package/dist/infra/throttler/named-throttlers.js +119 -0
  352. package/dist/infra/throttler/redis-throttler-storage.d.ts +38 -0
  353. package/dist/infra/throttler/redis-throttler-storage.js +130 -0
  354. package/dist/infra/throttler/throttler.guard.d.ts +23 -0
  355. package/dist/infra/throttler/throttler.guard.js +68 -0
  356. package/dist/infra/throttler/throttler.module.d.ts +15 -0
  357. package/dist/infra/throttler/throttler.module.js +53 -0
  358. package/dist/infra/tokens.d.ts +15 -0
  359. package/dist/infra/tokens.js +15 -0
  360. package/dist/infra/validation/create-zod-dto.d.ts +23 -0
  361. package/dist/infra/validation/create-zod-dto.js +35 -0
  362. package/dist/infra/validation/parse-with-zod.d.ts +7 -0
  363. package/dist/infra/validation/parse-with-zod.js +12 -0
  364. package/dist/infra/validation/validation.module.d.ts +3 -0
  365. package/dist/infra/validation/validation.module.js +16 -0
  366. package/dist/infra/validation/zod-params.d.ts +7 -0
  367. package/dist/infra/validation/zod-params.js +42 -0
  368. package/dist/infra/validation/zod-validation.pipe.d.ts +11 -0
  369. package/dist/infra/validation/zod-validation.pipe.js +31 -0
  370. package/dist/kernel.d.ts +9 -241
  371. package/dist/kernel.js +8 -1305
  372. package/dist/kernel.module.d.ts +17 -0
  373. package/dist/kernel.module.js +136 -0
  374. package/dist/lifecycle/kernel-lifecycle.d.ts +140 -0
  375. package/dist/lifecycle/kernel-lifecycle.js +451 -0
  376. package/dist/lifecycle/tokens.d.ts +3 -0
  377. package/dist/lifecycle/tokens.js +3 -0
  378. package/dist/log-config.d.ts +9 -0
  379. package/dist/log-config.js +27 -0
  380. package/dist/log-context.d.ts +34 -0
  381. package/dist/log-context.js +44 -0
  382. package/dist/log-loki.d.ts +34 -0
  383. package/dist/log-loki.js +145 -0
  384. package/dist/log.d.ts +41 -10
  385. package/dist/log.js +91 -17
  386. package/dist/models/models.module.d.ts +3 -0
  387. package/dist/models/models.module.js +24 -0
  388. package/dist/models/prices.d.ts +8 -2
  389. package/dist/models/prices.js +65 -37
  390. package/dist/models/purposes.controller.d.ts +1 -1
  391. package/dist/models/purposes.controller.js +5 -6
  392. package/dist/models/purposes.d.ts +35 -13
  393. package/dist/models/purposes.js +101 -51
  394. package/dist/net/public-address.js +3 -2
  395. package/dist/orgs/directory-sync.controller.d.ts +1 -1
  396. package/dist/orgs/directory-sync.controller.js +2 -2
  397. package/dist/orgs/directory-sync.d.ts +61 -31
  398. package/dist/orgs/directory-sync.js +212 -125
  399. package/dist/orgs/invitations.controller.d.ts +8 -8
  400. package/dist/orgs/invitations.controller.js +27 -26
  401. package/dist/orgs/invitations.service.d.ts +12 -9
  402. package/dist/orgs/invitations.service.js +130 -92
  403. package/dist/orgs/job-ids.d.ts +8 -0
  404. package/dist/orgs/job-ids.js +8 -0
  405. package/dist/orgs/members.service.d.ts +19 -12
  406. package/dist/orgs/members.service.js +161 -117
  407. package/dist/orgs/offboarding.d.ts +54 -57
  408. package/dist/orgs/offboarding.js +161 -71
  409. package/dist/orgs/org-lock.d.ts +28 -19
  410. package/dist/orgs/org-lock.js +81 -35
  411. package/dist/orgs/org.guard.d.ts +1 -1
  412. package/dist/orgs/org.guard.js +2 -2
  413. package/dist/orgs/orgs.controller.d.ts +13 -13
  414. package/dist/orgs/orgs.controller.js +29 -17
  415. package/dist/orgs/orgs.module.d.ts +6 -0
  416. package/dist/orgs/orgs.module.js +68 -0
  417. package/dist/orgs/orgs.service.d.ts +30 -19
  418. package/dist/orgs/orgs.service.js +139 -86
  419. package/dist/orgs/settings.controller.d.ts +1 -1
  420. package/dist/orgs/settings.controller.js +8 -6
  421. package/dist/orgs/settings.service.d.ts +14 -8
  422. package/dist/orgs/settings.service.js +75 -46
  423. package/dist/overrides.d.ts +56 -0
  424. package/dist/overrides.js +30 -0
  425. package/dist/roles/gateway-role.d.ts +43 -0
  426. package/dist/roles/gateway-role.js +98 -0
  427. package/dist/roles/gateway.module.d.ts +8 -0
  428. package/dist/roles/gateway.module.js +28 -0
  429. package/dist/roles/worker-role.d.ts +63 -0
  430. package/dist/roles/worker-role.js +144 -0
  431. package/dist/roles/worker.module.d.ts +14 -0
  432. package/dist/roles/worker.module.js +90 -0
  433. package/dist/runtime/abort.js +19 -2
  434. package/dist/runtime/checkpointer.d.ts +8 -3
  435. package/dist/runtime/checkpointer.js +87 -55
  436. package/dist/runtime/conversation-lock.d.ts +20 -11
  437. package/dist/runtime/conversation-lock.js +62 -72
  438. package/dist/runtime/hook-calls.d.ts +3 -3
  439. package/dist/runtime/hook-calls.js +1 -6
  440. package/dist/runtime/job-ids.d.ts +10 -0
  441. package/dist/runtime/job-ids.js +10 -0
  442. package/dist/runtime/langgraph-loop.js +1 -1
  443. package/dist/runtime/loop.d.ts +7 -0
  444. package/dist/runtime/loop.js +14 -0
  445. package/dist/runtime/maintenance-queue.d.ts +10 -0
  446. package/dist/runtime/maintenance-queue.js +10 -0
  447. package/dist/runtime/maintenance.d.ts +45 -74
  448. package/dist/runtime/maintenance.js +139 -136
  449. package/dist/runtime/model-call.d.ts +7 -4
  450. package/dist/runtime/model-call.js +24 -57
  451. package/dist/runtime/providers.d.ts +17 -6
  452. package/dist/runtime/providers.js +66 -25
  453. package/dist/runtime/quota.d.ts +17 -3
  454. package/dist/runtime/quota.js +27 -2
  455. package/dist/runtime/retired-schedulers.d.ts +7 -0
  456. package/dist/runtime/retired-schedulers.js +31 -0
  457. package/dist/runtime/run-control.d.ts +33 -0
  458. package/dist/runtime/run-control.js +77 -0
  459. package/dist/runtime/run-finish.d.ts +26 -17
  460. package/dist/runtime/run-finish.js +98 -51
  461. package/dist/runtime/run-jobs.d.ts +48 -0
  462. package/dist/runtime/run-jobs.js +95 -0
  463. package/dist/runtime/run-processors.d.ts +60 -0
  464. package/dist/runtime/run-processors.js +185 -0
  465. package/dist/runtime/run-queue.d.ts +32 -57
  466. package/dist/runtime/run-queue.js +291 -295
  467. package/dist/runtime/run-steps.d.ts +39 -0
  468. package/dist/runtime/run-steps.js +96 -0
  469. package/dist/runtime/run-worker.d.ts +121 -75
  470. package/dist/runtime/run-worker.js +340 -225
  471. package/dist/runtime/runtime.module.d.ts +10 -0
  472. package/dist/runtime/runtime.module.js +112 -0
  473. package/dist/runtime/step-log.d.ts +40 -0
  474. package/dist/runtime/step-log.js +94 -0
  475. package/dist/runtime/stream.controller.d.ts +5 -8
  476. package/dist/runtime/stream.controller.js +14 -12
  477. package/dist/runtime/stream.d.ts +24 -6
  478. package/dist/runtime/stream.js +78 -7
  479. package/dist/runtime/subagents/child.d.ts +3 -44
  480. package/dist/runtime/subagents/child.js +0 -79
  481. package/dist/runtime/subagents/definition.d.ts +4 -4
  482. package/dist/runtime/subagents/definition.js +2 -2
  483. package/dist/runtime/subagents/dispatch.d.ts +87 -6
  484. package/dist/runtime/subagents/dispatch.js +135 -140
  485. package/dist/runtime/subagents/limits.d.ts +9 -4
  486. package/dist/runtime/subagents/limits.js +4 -2
  487. package/dist/runtime/subagents/org-agents.d.ts +4 -4
  488. package/dist/runtime/subagents/org-agents.js +1 -1
  489. package/dist/runtime/subagents/progress.d.ts +2 -2
  490. package/dist/runtime/subagents/roster.d.ts +3 -3
  491. package/dist/runtime/subagents/roster.js +1 -1
  492. package/dist/runtime/subagents/skill-fork.d.ts +6 -7
  493. package/dist/runtime/subagents/skill-fork.js +16 -5
  494. package/dist/runtime/subagents/subagents.service.d.ts +40 -0
  495. package/dist/runtime/subagents/subagents.service.js +101 -0
  496. package/dist/runtime/usage-report.d.ts +94 -52
  497. package/dist/runtime/usage-report.js +200 -99
  498. package/dist/runtime/waits.d.ts +125 -57
  499. package/dist/runtime/waits.js +431 -208
  500. package/dist/sandbox/job-ids.d.ts +10 -0
  501. package/dist/sandbox/job-ids.js +10 -0
  502. package/dist/sandbox/jobs.d.ts +41 -0
  503. package/dist/sandbox/jobs.js +113 -0
  504. package/dist/sandbox/leases.d.ts +39 -31
  505. package/dist/sandbox/leases.js +117 -257
  506. package/dist/sandbox/providers.d.ts +19 -0
  507. package/dist/sandbox/providers.js +38 -0
  508. package/dist/sandbox/sandbox.module.d.ts +8 -0
  509. package/dist/sandbox/sandbox.module.js +30 -0
  510. package/dist/sandbox/sandbox.service.d.ts +24 -29
  511. package/dist/sandbox/sandbox.service.js +106 -75
  512. package/dist/skills/catalog.d.ts +33 -20
  513. package/dist/skills/catalog.js +96 -53
  514. package/dist/skills/changes.controller.d.ts +4 -4
  515. package/dist/skills/changes.controller.js +15 -9
  516. package/dist/skills/changes.service.d.ts +28 -18
  517. package/dist/skills/changes.service.js +421 -364
  518. package/dist/skills/invocable.controller.d.ts +1 -1
  519. package/dist/skills/invocable.controller.js +8 -5
  520. package/dist/skills/invoke.d.ts +16 -15
  521. package/dist/skills/invoke.js +48 -17
  522. package/dist/skills/skills.controller.d.ts +1 -1
  523. package/dist/skills/skills.controller.js +11 -6
  524. package/dist/skills/skills.module.d.ts +6 -0
  525. package/dist/skills/skills.module.js +30 -0
  526. package/dist/skills/skills.service.d.ts +47 -30
  527. package/dist/skills/skills.service.js +221 -158
  528. package/dist/storage/job-ids.d.ts +6 -0
  529. package/dist/storage/job-ids.js +6 -0
  530. package/dist/storage/purge.d.ts +22 -7
  531. package/dist/storage/purge.js +55 -3
  532. package/dist/storage/storage.module.d.ts +6 -0
  533. package/dist/storage/storage.module.js +23 -0
  534. package/dist/storage/storage.service.d.ts +18 -4
  535. package/dist/storage/storage.service.js +44 -3
  536. package/dist/tools/approvals.controller.d.ts +1 -1
  537. package/dist/tools/approvals.controller.js +12 -8
  538. package/dist/tools/approvals.service.d.ts +27 -25
  539. package/dist/tools/approvals.service.js +324 -258
  540. package/dist/tools/breaker.d.ts +2 -2
  541. package/dist/tools/breaker.js +21 -3
  542. package/dist/tools/builtins/ask-user.d.ts +2 -2
  543. package/dist/tools/builtins/ask-user.js +1 -1
  544. package/dist/tools/builtins/builtin-tools.d.ts +21 -0
  545. package/dist/tools/builtins/builtin-tools.js +80 -0
  546. package/dist/tools/builtins/read-tool-output.d.ts +2 -2
  547. package/dist/tools/builtins/read-tool-output.js +1 -1
  548. package/dist/tools/builtins/sandbox/bash.js +2 -2
  549. package/dist/tools/builtins/sandbox/common.d.ts +7 -4
  550. package/dist/tools/builtins/sandbox/common.js +5 -3
  551. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  552. package/dist/tools/builtins/sandbox/edit.js +1 -1
  553. package/dist/tools/builtins/sandbox/glob.js +2 -2
  554. package/dist/tools/builtins/sandbox/grep.js +2 -2
  555. package/dist/tools/builtins/sandbox/read.js +1 -1
  556. package/dist/tools/builtins/sandbox/write.js +1 -1
  557. package/dist/tools/builtins/skill-load.d.ts +3 -3
  558. package/dist/tools/builtins/skill-load.js +1 -1
  559. package/dist/tools/canonical-json.d.ts +6 -0
  560. package/dist/tools/canonical-json.js +16 -0
  561. package/dist/tools/connector-content.controller.d.ts +1 -1
  562. package/dist/tools/connector-content.controller.js +11 -6
  563. package/dist/tools/connector-content.d.ts +12 -15
  564. package/dist/tools/connector-content.js +53 -18
  565. package/dist/tools/connectors.controller.d.ts +1 -1
  566. package/dist/tools/connectors.controller.js +21 -10
  567. package/dist/tools/connectors.service.d.ts +31 -13
  568. package/dist/tools/connectors.service.js +434 -344
  569. package/dist/tools/credentials.d.ts +17 -20
  570. package/dist/tools/credentials.js +55 -34
  571. package/dist/tools/drift.d.ts +29 -41
  572. package/dist/tools/drift.js +111 -79
  573. package/dist/tools/info.d.ts +12 -9
  574. package/dist/tools/info.js +33 -7
  575. package/dist/tools/job-ids.d.ts +13 -0
  576. package/dist/tools/job-ids.js +15 -0
  577. package/dist/tools/jobs.d.ts +24 -0
  578. package/dist/tools/jobs.js +69 -0
  579. package/dist/tools/oauth/flow-paths.d.ts +16 -0
  580. package/dist/tools/oauth/flow-paths.js +38 -0
  581. package/dist/tools/oauth/flow.d.ts +30 -30
  582. package/dist/tools/oauth/flow.js +109 -81
  583. package/dist/tools/oauth/oauth.controller.d.ts +3 -3
  584. package/dist/tools/oauth/oauth.controller.js +12 -9
  585. package/dist/tools/oauth/tokens.d.ts +11 -3
  586. package/dist/tools/oauth/tokens.js +15 -14
  587. package/dist/tools/outputs.d.ts +13 -4
  588. package/dist/tools/outputs.js +47 -3
  589. package/dist/tools/pipeline.d.ts +62 -46
  590. package/dist/tools/pipeline.js +145 -64
  591. package/dist/tools/policy.d.ts +2 -2
  592. package/dist/tools/questions.controller.d.ts +1 -1
  593. package/dist/tools/questions.controller.js +8 -5
  594. package/dist/tools/questions.service.d.ts +25 -24
  595. package/dist/tools/questions.service.js +201 -142
  596. package/dist/tools/registry.d.ts +30 -20
  597. package/dist/tools/registry.js +73 -37
  598. package/dist/tools/specs.d.ts +5 -4
  599. package/dist/tools/specs.js +3 -1
  600. package/dist/tools/tools.module.d.ts +10 -0
  601. package/dist/tools/tools.module.js +91 -0
  602. package/dist/ui/call-extension.d.ts +16 -0
  603. package/dist/ui/call-extension.js +38 -0
  604. package/dist/ui/embed-token.d.ts +9 -5
  605. package/dist/ui/embed-token.js +34 -6
  606. package/dist/ui/ui-stream.d.ts +22 -17
  607. package/dist/ui/ui-stream.js +72 -12
  608. package/dist/ui/ui.module.d.ts +7 -0
  609. package/dist/ui/ui.module.js +28 -0
  610. package/dist/ui/views.controller.d.ts +14 -12
  611. package/dist/ui/views.controller.js +32 -25
  612. package/dist/ui/views.d.ts +9 -57
  613. package/dist/ui/views.js +43 -45
  614. package/package.json +11 -2
  615. package/dist/http/health.controller.d.ts +0 -26
  616. package/dist/http/health.controller.js +0 -79
  617. package/dist/http/tokens.d.ts +0 -131
  618. package/dist/http/tokens.js +0 -131
  619. package/dist/http/zod.pipe.d.ts +0 -8
  620. package/dist/http/zod.pipe.js +0 -14
  621. package/dist/identity/rate-limit.d.ts +0 -55
  622. package/dist/identity/rate-limit.js +0 -121
  623. package/dist/sandbox/lifecycle.d.ts +0 -21
  624. package/dist/sandbox/lifecycle.js +0 -68
  625. /package/dist/http/{gateway.module.d.ts → gateway-routes.d.ts} +0 -0
  626. /package/dist/http/{gateway.module.js → gateway-routes.js} +0 -0
@@ -1,16 +1,36 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
1
10
  import { randomUUID } from "node:crypto";
2
11
  import { EXTENSION_POINTS, parseExtensionPoint, parseSkillMd, SKILL_ENTRY_FILE, } from "@capybara-hq/plugin-sdk";
12
+ import { Inject, Injectable } from "@nestjs/common";
3
13
  import { sql } from "kysely";
4
14
  import { normalizeToolRef } from "../agents/definition.js";
5
15
  import { putTemplateVersionIn, revertTemplateVersionIn, softDeleteTemplateIn, } from "../agents/templates.js";
6
16
  import { ApiError } from "../errors.js";
7
17
  import { isExtensionEnabled } from "../extensions/enabled.js";
18
+ import { OrgExtensionConfigs, } from "../extensions/org-config.js";
19
+ import { ExtensionRegistry } from "../extensions/registry.js";
8
20
  import { audit } from "../identity/audit.js";
9
- import { lockOrg } from "../orgs/org-lock.js";
21
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
22
+ import { afterCommit } from "../infra/database/after-commit.js";
23
+ import { KernelDb } from "../infra/database/kernel-db.js";
24
+ import { TransactionHost } from "../infra/database/transaction-host.js";
25
+ import { Transactional } from "../infra/database/transactional.decorator.js";
26
+ import { KERNEL_LOGGER } from "../infra/tokens.js";
27
+ import { OrgLock } from "../orgs/org-lock.js";
10
28
  import { packagePath } from "../packages/tgz.js";
11
- import { skillConflictError, skillConflicts, } from "../skills/skills.service.js";
12
- import { lockOrgForActions, readCatalogAgentTemplates, readCatalogFiles, readCatalogTemplates, requiredActions, skillOf, templateConnectorInput, templatePluginProblem, } from "./org-catalog.service.js";
13
- import { assertItemInstallable, disabledPluginItems, pluginItemDisabled, } from "./requests.service.js";
29
+ import { SkillsService, skillConflictError, skillConflicts, } from "../skills/skills.service.js";
30
+ import { StorageService } from "../storage/storage.service.js";
31
+ import { ConnectorsService } from "../tools/connectors.service.js";
32
+ import { findConnectorIn, lockOrgForActions, readCatalogAgentTemplates, readCatalogFiles, readCatalogTemplates, requiredActions, skillOf, templateConnectorInput, templatePluginProblem, } from "./catalog-content.js";
33
+ import { assertItemInstallable, CatalogRequestsService, disabledPluginItems, pluginItemDisabled, } from "./requests.service.js";
14
34
  import { upgradeInfo } from "./upgrade-targets.js";
15
35
  import { maxSatisfying, satisfiesRange } from "./versions.js";
16
36
  /** How deep plugin dependencies may nest (the root plugin's dependencies are level 1). */
@@ -183,14 +203,44 @@ export function under(e, at) {
183
203
  * (plugin-upgrade.ts), which reuses the planning, install and ledger methods here (the ones without
184
204
  * `private` are internal to the catalog, not an API).
185
205
  */
186
- export class PluginInstaller {
187
- d;
188
- constructor(d) {
189
- this.d = d;
206
+ let PluginInstaller = class PluginInstaller {
207
+ kdb;
208
+ orgLock;
209
+ storage;
210
+ registry;
211
+ skills;
212
+ orgConfigs;
213
+ requests;
214
+ config;
215
+ connectors;
216
+ log;
217
+ txHost;
218
+ constructor(kdb,
219
+ /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
220
+ orgLock, storage,
221
+ /** The loaded extensions and connectors of this replica (the extension registry). */
222
+ registry, skills, orgConfigs, requests, config,
223
+ /** Org connectors: installs create, upgrade and remove them. */
224
+ connectors, log, txHost) {
225
+ this.kdb = kdb;
226
+ this.orgLock = orgLock;
227
+ this.storage = storage;
228
+ this.registry = registry;
229
+ this.skills = skills;
230
+ this.orgConfigs = orgConfigs;
231
+ this.requests = requests;
232
+ this.config = config;
233
+ this.connectors = connectors;
234
+ this.log = log;
235
+ this.txHost = txHost;
190
236
  }
191
- /** The installer's dependencies (shared with `PluginUpgrader`). */
192
- get deps() {
193
- return this.d;
237
+ /** The kernel-schema handle of the current context (the transaction, else the pool). */
238
+ get db() {
239
+ return this.kdb.db;
240
+ }
241
+ /** `catalog.staleInstallMinutes`: an install `installing` for longer can be cleaned up by uninstalling it. */
242
+ staleInstallMinutes() {
243
+ return this.config.get().catalog.staleInstallMinutes;
194
244
  }
195
245
  /**
196
246
  * The checks an install runs before it creates anything, without the org's input (for the org
@@ -243,14 +293,17 @@ export class PluginInstaller {
243
293
  * and a name two plugins of the same plan both bring (the one installed first is the source).
244
294
  */
245
295
  async assertNoSkillConflicts(orgId, plan) {
246
- const conflicts = await planSkillConflicts(this.d.db, orgId, plan);
296
+ const conflicts = await planSkillConflicts(this.db, orgId, plan);
247
297
  if (conflicts.length > 0)
248
298
  throw skillConflictError(conflicts);
249
299
  }
250
300
  /** The connector checks of templates against what this replica loads right now. */
251
301
  templateDeps() {
252
- const versions = new Map(this.d.host.manifests().map((m) => [m.name, m.version]));
253
- return { findConnector: this.d.findConnector, pluginVersion: (n) => versions.get(n) };
302
+ const versions = new Map(this.registry.manifests().map((m) => [m.name, m.version]));
303
+ return {
304
+ findConnector: (plugin, kind) => findConnectorIn(this.registry, plugin, kind),
305
+ pluginVersion: (n) => versions.get(n),
306
+ };
254
307
  }
255
308
  /**
256
309
  * Plans the install of one plugin version and, depth first, of its dependencies not yet
@@ -261,7 +314,7 @@ export class PluginInstaller {
261
314
  async plan(orgId, actor, itemId, version, input, at, approvedBy) {
262
315
  if (!UUID_RE.test(itemId))
263
316
  throw new ApiError("catalog.item_not_found", "Plugin not found");
264
- const v = await this.d.db
317
+ const v = await this.db
265
318
  .selectFrom("catalog_item_versions as v")
266
319
  .innerJoin("catalog_items as i", "i.id", "v.item_id")
267
320
  .select([
@@ -279,11 +332,11 @@ export class PluginInstaller {
279
332
  if (!v)
280
333
  throw new ApiError("catalog.item_not_found", "Plugin version not found");
281
334
  const manifest = v.manifest;
282
- const deps = await resolveDependencies(this.d.db, manifest);
335
+ const deps = await resolveDependencies(this.db, manifest);
283
336
  const extension = await this.planExtension(orgId, manifest);
284
- const templates = await readCatalogTemplates(this.d.storage, v);
285
- const skillNames = await catalogSkillNames(this.d.storage, v, manifest);
286
- const agentTemplates = await readCatalogAgentTemplates(this.d.storage, v);
337
+ const templates = await readCatalogTemplates(this.storage, v);
338
+ const skillNames = await catalogSkillNames(this.storage, v, manifest);
339
+ const agentTemplates = await readCatalogAgentTemplates(this.storage, v);
287
340
  const connectors = new Map();
288
341
  if (input === null) {
289
342
  for (const ct of templates) {
@@ -300,7 +353,7 @@ export class PluginInstaller {
300
353
  }
301
354
  const dependencies = [];
302
355
  for (const dep of deps) {
303
- if (await this.liveDependency(this.d.db, orgId, dep)) {
356
+ if (await this.liveDependency(this.db, orgId, dep)) {
304
357
  dependencies.push({ dep, plan: null });
305
358
  continue;
306
359
  }
@@ -355,7 +408,7 @@ export class PluginInstaller {
355
408
  : `This connector template needs ${needs}`);
356
409
  }
357
410
  try {
358
- this.d.connectors.checkCreateInput(actor, ci);
411
+ this.connectors.checkCreateInput(actor, ci);
359
412
  }
360
413
  catch (e) {
361
414
  throw under(e, path);
@@ -397,30 +450,30 @@ export class PluginInstaller {
397
450
  * cannot leave the component pointing at a removed install. `created` false: the org's existing
398
451
  * install, if any (returns its id, undefined when there is none); it must be `installed`
399
452
  * (`installing` -> 409 `plugin.install_in_progress`, retry later) and in range. `created` true:
400
- * `child`, the dependency install this install just created, must still exist.
453
+ * `child`, the dependency install this install just created, must still exist. A step of an
454
+ * install or upgrade: it commits on its own (`requires_new`), the undo on failure relies on it.
401
455
  */
402
456
  async recordDependency(orgId, dep, record, child) {
403
- return this.d.db.transaction().execute(async (t) => {
404
- await lockOrg(t, orgId);
405
- const live = await this.findLiveDependency(t, orgId, dep, true);
406
- if (child !== undefined) {
407
- if (live?.id !== child || live.status !== "installed") {
408
- throw unresolved(dep.name, dep.range, "its install in this organization was removed meanwhile; try again");
409
- }
410
- await record({ kind: "plugin", ref: child, created: true, skillVersion: null }, t);
411
- return child;
412
- }
413
- if (!live)
414
- return undefined;
415
- if (!satisfiesRange(live.version, dep.range)) {
416
- throw unresolved(dep.name, dep.range, `this organization has version ${live.version} installed; uninstall it to install a matching version`);
417
- }
418
- if (live.status !== "installed") {
419
- throw new ApiError("plugin.install_in_progress", `Dependency ${dep.name} is being installed by another install in this organization; try again when it finishes. An install stuck for longer than catalog.staleInstallMinutes can be removed by uninstalling it`);
457
+ const t = this.db;
458
+ await this.orgLock.lock(orgId);
459
+ const live = await this.findLiveDependency(t, orgId, dep, true);
460
+ if (child !== undefined) {
461
+ if (live?.id !== child || live.status !== "installed") {
462
+ throw unresolved(dep.name, dep.range, "its install in this organization was removed meanwhile; try again");
420
463
  }
421
- await record({ kind: "plugin", ref: live.id, created: false, skillVersion: null }, t);
422
- return live.id;
423
- });
464
+ await record({ kind: "plugin", ref: child, created: true, skillVersion: null });
465
+ return child;
466
+ }
467
+ if (!live)
468
+ return undefined;
469
+ if (!satisfiesRange(live.version, dep.range)) {
470
+ throw unresolved(dep.name, dep.range, `this organization has version ${live.version} installed; uninstall it to install a matching version`);
471
+ }
472
+ if (live.status !== "installed") {
473
+ throw new ApiError("plugin.install_in_progress", `Dependency ${dep.name} is being installed by another install in this organization; try again when it finishes. An install stuck for longer than catalog.staleInstallMinutes can be removed by uninstalling it`);
474
+ }
475
+ await record({ kind: "plugin", ref: live.id, created: false, skillVersion: null });
476
+ return live.id;
424
477
  }
425
478
  /**
426
479
  * Runs a plan: the install row, then the steps (see the class comment). Throws
@@ -432,59 +485,15 @@ export class PluginInstaller {
432
485
  // The install row (role and item policy re-checked under the lock; one live install per org
433
486
  // and item)
434
487
  const installId = randomUUID();
435
- await this.d.db.transaction().execute(async (t) => {
436
- await lockOrgForActions(t, orgId, actor, ctx.actions);
437
- if (ctx.approvedBy !== undefined) {
438
- // A dependency disabled (or removed) since it was planned
439
- const own = await t
440
- .selectFrom("catalog_items")
441
- .select(["policy", "deleted_at"])
442
- .where("id", "=", itemId)
443
- .forShare()
444
- .executeTakeFirst();
445
- if (!own || own.deleted_at !== null) {
446
- throw unresolved(plan.name, plan.version, "it was removed from the enterprise catalog");
447
- }
448
- if (own.policy === "disabled")
449
- throw dependencyDisabled(plan.name);
450
- }
451
- await assertItemInstallable(t, orgId, itemId, ctx.approvedBy ?? itemId);
452
- const live = await t
453
- .selectFrom("plugin_installs")
454
- .select("id")
455
- .where("org_id", "=", orgId)
456
- .where("item_id", "=", itemId)
457
- .where("status", "<>", "failed")
458
- .executeTakeFirst();
459
- if (live)
460
- throw alreadyInstalled();
461
- try {
462
- await t
463
- .insertInto("plugin_installs")
464
- .values({
465
- id: installId,
466
- org_id: orgId,
467
- item_id: itemId,
468
- version,
469
- status: "installing",
470
- installed_by: actor,
471
- })
472
- .execute();
473
- }
474
- catch (e) {
475
- if (isUniqueViolation(e))
476
- throw alreadyInstalled();
477
- throw e;
478
- }
479
- });
488
+ await this.createInstallRow(orgId, actor, plan, ctx, installId);
480
489
  const done = [];
481
- // Records a component in the given transaction (the install row already cleaned up -> the FK
482
- // fails, the install aborts and rolls back)
483
- const record = async (c, t) => {
490
+ // Records a component in the transaction of the context (none: on its own; the install row
491
+ // already cleaned up -> the FK fails, the install aborts and rolls back)
492
+ const record = async (c) => {
484
493
  // Into `done` first: a component that exists is rolled back even when recording it fails
485
494
  // (enabling an extension and recording it share one transaction and fail together)
486
495
  done.push(c);
487
- await (t ?? this.d.db)
496
+ await this.db
488
497
  .insertInto("plugin_install_components")
489
498
  .values({
490
499
  install_id: installId,
@@ -532,25 +541,17 @@ export class PluginInstaller {
532
541
  }
533
542
  step = "extension";
534
543
  if (plan.extension !== null) {
535
- const p = plan.extension;
536
- // "Enabled before" is decided under the org row lock (already enabled: put writes nothing,
537
- // the config is untouched); the component is recorded in the same transaction
538
- await this.d.orgConfigs.put(orgId, p, {
544
+ await this.enableExtension(orgId, plan.extension, {
539
545
  enabled: true,
540
546
  ...(plan.extensionConfig !== undefined && { config: plan.extensionConfig }),
541
- }, actor, opts.actorTokenId, {
542
- viaItem: itemId,
543
- ...(nested && { approvedBy }),
544
- ifDisabled: { skipped: false },
545
- inTransaction: (t, skipped) => record({ kind: "extension", ref: p, created: !skipped, skillVersion: null }, t),
546
- });
547
+ }, actor, opts.actorTokenId, { viaItem: itemId, ...(nested && { approvedBy }) }, record);
547
548
  }
548
549
  step = "connectors";
549
550
  for (const ct of plan.templates) {
550
551
  const ci = plan.connectors.get(ct.id);
551
552
  if (!ci)
552
553
  throw new ApiError("internal", `Connector template ${ct.id} was not planned`);
553
- const r = await this.d.connectors.create(orgId, actor, ci, opts.actorTokenId);
554
+ const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId);
554
555
  await record({
555
556
  kind: "connector",
556
557
  ref: r.connector.id,
@@ -561,29 +562,12 @@ export class PluginInstaller {
561
562
  }
562
563
  step = "agent_templates";
563
564
  for (const a of plan.agentTemplates) {
564
- // Created (or a new version of the org's live template of this plugin and name) and
565
- // recorded in one transaction, under the org row lock
566
- await this.d.db.transaction().execute(async (t) => {
567
- await lockOrg(t, orgId);
568
- const r = await putTemplateVersionIn(t, {
569
- orgId,
570
- plugin: plan.name,
571
- catalogItemId: itemId,
572
- catalogVersion: version,
573
- sourceFormat: plan.sourceFormat,
574
- }, a.template);
575
- await record({
576
- kind: "agent_template",
577
- ref: r.id,
578
- created: r.created,
579
- skillVersion: !r.created && r.changed ? r.version : null,
580
- }, t);
581
- });
565
+ await this.installAgentTemplate(orgId, plan, a.template, record);
582
566
  }
583
567
  step = "skills";
584
568
  for (const s of manifest.skills ?? []) {
585
- const files = await readCatalogFiles(this.d.storage, plan.row.object_prefix, plan.row.files, packagePath(s.path));
586
- const r = await this.d.skills.createVersionFromFiles(orgId, actor, { ...skillOf(files), files }, {
569
+ const files = await readCatalogFiles(this.storage, plan.row.object_prefix, plan.row.files, packagePath(s.path));
570
+ const r = await this.skills.createVersionFromFiles(orgId, actor, { ...skillOf(files), files }, {
587
571
  catalog: {
588
572
  itemId,
589
573
  version,
@@ -600,68 +584,165 @@ export class PluginInstaller {
600
584
  skillVersion: r.created ? null : r.version,
601
585
  });
602
586
  }
603
- await this.d.db.transaction().execute(async (t) => {
604
- await lockOrg(t, orgId);
605
- const updated = await t
606
- .updateTable("plugin_installs")
607
- .set({ status: "installed" })
608
- .where("id", "=", installId)
609
- .where("status", "=", "installing")
610
- .executeTakeFirst();
611
- // The install row was already cleaned up as stale: do not audit plugin.org_installed, roll
612
- // back
613
- if (updated.numUpdatedRows === 0n) {
614
- throw new ApiError("plugin.install_not_found", "The install record was cleaned up as stale while the install was running");
615
- }
616
- await this.d.requests.resolveByInstall(t, orgId, itemId, actor, opts);
617
- await audit(t, {
618
- actorAccountId: actor,
619
- ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
620
- orgId,
621
- action: "plugin.org_installed",
622
- target: installId,
623
- detail: {
624
- itemId,
625
- name: plan.name,
626
- version,
627
- components: done,
628
- ...(ctx.parent !== undefined && { dependencyOf: ctx.parent }),
629
- },
630
- });
631
- });
587
+ await this.markInstalled(orgId, actor, installId, plan, done, ctx, opts);
632
588
  return installId;
633
589
  }
634
590
  catch (e) {
635
591
  const failure = e instanceof InstallFailure ? e : undefined;
636
592
  const code = failure ? failure.code : e instanceof ApiError ? e.code : "internal";
637
593
  const rollbackErrors = await this.rollback(orgId, actor, installId, done, opts);
638
- await this.d.db.transaction().execute(async (t) => {
639
- await t
640
- .updateTable("plugin_installs")
641
- .set({ status: "failed", error: JSON.stringify({ step, code }) })
642
- .where("id", "=", installId)
643
- .execute();
644
- await audit(t, {
645
- actorAccountId: actor,
646
- ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
647
- orgId,
648
- action: "plugin.org_install_failed",
649
- target: installId,
650
- detail: {
651
- itemId,
652
- name: plan.name,
653
- version,
654
- step,
655
- code,
656
- rolledBack: done,
657
- rollbackErrors,
658
- ...(ctx.parent !== undefined && { dependencyOf: ctx.parent }),
659
- },
660
- });
661
- });
594
+ await this.markFailed(orgId, actor, installId, plan, ctx, { step, code, done, rollbackErrors }, opts);
662
595
  throw new InstallFailure(failure ? failure.step : step, failure ? failure.cause : e, failure ? failure.dependency : [], rollbackErrors.length === 0 && (failure?.rolledBack ?? true));
663
596
  }
664
597
  }
598
+ /**
599
+ * The install row (role and item policy re-checked under the lock; one live install per org and
600
+ * item). A step of the install: committed on its own.
601
+ */
602
+ /**
603
+ * Enables a plugin's extension for the org and records it as a component of the install, in one
604
+ * transaction (`put` joins it): "enabled before" is decided under the org row lock (already
605
+ * enabled: `put` writes nothing, the config is untouched, the component is recorded as not
606
+ * created), and the ledger row is written before the COMMIT, so no concurrent uninstall fits
607
+ * between enabling and recording. Used by the install and the upgrade.
608
+ */
609
+ async enableExtension(orgId, name, input, actor, actorTokenId, opts, record) {
610
+ const ifDisabled = { skipped: false };
611
+ await this.orgConfigs.put(orgId, name, input, actor, actorTokenId, { ...opts, ifDisabled });
612
+ await record({
613
+ kind: "extension",
614
+ ref: name,
615
+ created: !ifDisabled.skipped,
616
+ skillVersion: null,
617
+ });
618
+ }
619
+ async createInstallRow(orgId, actor, plan, ctx, installId) {
620
+ const { itemId, version } = plan;
621
+ const t = this.db;
622
+ await lockOrgForActions(this.orgLock, orgId, actor, ctx.actions);
623
+ if (ctx.approvedBy !== undefined) {
624
+ // A dependency disabled (or removed) since it was planned
625
+ const own = await t
626
+ .selectFrom("catalog_items")
627
+ .select(["policy", "deleted_at"])
628
+ .where("id", "=", itemId)
629
+ .forShare()
630
+ .executeTakeFirst();
631
+ if (!own || own.deleted_at !== null) {
632
+ throw unresolved(plan.name, plan.version, "it was removed from the enterprise catalog");
633
+ }
634
+ if (own.policy === "disabled")
635
+ throw dependencyDisabled(plan.name);
636
+ }
637
+ await assertItemInstallable(t, orgId, itemId, ctx.approvedBy ?? itemId);
638
+ const live = await t
639
+ .selectFrom("plugin_installs")
640
+ .select("id")
641
+ .where("org_id", "=", orgId)
642
+ .where("item_id", "=", itemId)
643
+ .where("status", "<>", "failed")
644
+ .executeTakeFirst();
645
+ if (live)
646
+ throw alreadyInstalled();
647
+ try {
648
+ await t
649
+ .insertInto("plugin_installs")
650
+ .values({
651
+ id: installId,
652
+ org_id: orgId,
653
+ item_id: itemId,
654
+ version,
655
+ status: "installing",
656
+ installed_by: actor,
657
+ })
658
+ .execute();
659
+ }
660
+ catch (e) {
661
+ if (isUniqueViolation(e))
662
+ throw alreadyInstalled();
663
+ throw e;
664
+ }
665
+ }
666
+ /**
667
+ * An agent template step: created (or a new version of the org's live template of this plugin and
668
+ * name) and recorded in one transaction of its own, under the org row lock.
669
+ */
670
+ async installAgentTemplate(orgId, plan, template, record) {
671
+ await this.orgLock.lock(orgId);
672
+ const r = await putTemplateVersionIn(this.db, {
673
+ orgId,
674
+ plugin: plan.name,
675
+ catalogItemId: plan.itemId,
676
+ catalogVersion: plan.version,
677
+ sourceFormat: plan.sourceFormat,
678
+ }, template);
679
+ await record({
680
+ kind: "agent_template",
681
+ ref: r.id,
682
+ created: r.created,
683
+ skillVersion: !r.created && r.changed ? r.version : null,
684
+ });
685
+ }
686
+ /** The install `installed` and its `plugin.org_installed` audit, under the org row lock (its own transaction). */
687
+ async markInstalled(orgId, actor, installId, plan, done, ctx, opts) {
688
+ const { itemId, version } = plan;
689
+ const t = this.db;
690
+ await this.orgLock.lock(orgId);
691
+ const updated = await t
692
+ .updateTable("plugin_installs")
693
+ .set({ status: "installed" })
694
+ .where("id", "=", installId)
695
+ .where("status", "=", "installing")
696
+ .executeTakeFirst();
697
+ // The install row was already cleaned up as stale: do not audit plugin.org_installed, roll
698
+ // back
699
+ if (updated.numUpdatedRows === 0n) {
700
+ throw new ApiError("plugin.install_not_found", "The install record was cleaned up as stale while the install was running");
701
+ }
702
+ await this.requests.resolveByInstall(orgId, itemId, actor, opts);
703
+ await audit(t, {
704
+ actorAccountId: actor,
705
+ ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
706
+ orgId,
707
+ action: "plugin.org_installed",
708
+ target: installId,
709
+ detail: {
710
+ itemId,
711
+ name: plan.name,
712
+ version,
713
+ components: done,
714
+ ...(ctx.parent !== undefined && { dependencyOf: ctx.parent }),
715
+ },
716
+ });
717
+ }
718
+ /** The install `failed` with `{ step, code }` and its `plugin.org_install_failed` audit (its own transaction). */
719
+ async markFailed(orgId, actor, installId, plan, ctx, f, opts) {
720
+ const { itemId, version } = plan;
721
+ const { step, code, done, rollbackErrors } = f;
722
+ const t = this.db;
723
+ await t
724
+ .updateTable("plugin_installs")
725
+ .set({ status: "failed", error: JSON.stringify({ step, code }) })
726
+ .where("id", "=", installId)
727
+ .execute();
728
+ await audit(t, {
729
+ actorAccountId: actor,
730
+ ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
731
+ orgId,
732
+ action: "plugin.org_install_failed",
733
+ target: installId,
734
+ detail: {
735
+ itemId,
736
+ name: plan.name,
737
+ version,
738
+ step,
739
+ code,
740
+ rolledBack: done,
741
+ rollbackErrors,
742
+ ...(ctx.parent !== undefined && { dependencyOf: ctx.parent }),
743
+ },
744
+ });
745
+ }
665
746
  /**
666
747
  * The extension to enable: the plugin's own, when it has one. Not loaded on this replica ->
667
748
  * `catalog.not_deployed`; not yet enabled in this org while its own catalog item is disabled ->
@@ -672,11 +753,11 @@ export class PluginInstaller {
672
753
  if (!manifest.extension)
673
754
  return null;
674
755
  const name = manifest.name;
675
- if (!this.d.host.manifests().some((m) => m.name === name)) {
756
+ if (!this.registry.manifests().some((m) => m.name === name)) {
676
757
  throw new ApiError("catalog.not_deployed", `The extension of plugin ${name} is not deployed; ask the enterprise admin to install and enable it`);
677
758
  }
678
- const enabled = await isExtensionEnabled(this.d.db, orgId, name);
679
- if (!enabled && (await disabledPluginItems(this.d.db, [name])).length > 0) {
759
+ const enabled = await isExtensionEnabled(this.db, orgId, name);
760
+ if (!enabled && (await disabledPluginItems(this.db, [name])).length > 0) {
680
761
  throw pluginItemDisabled([name]);
681
762
  }
682
763
  return name;
@@ -705,46 +786,13 @@ export class PluginInstaller {
705
786
  if (!c.created && c.skillVersion === null)
706
787
  continue;
707
788
  try {
708
- const disabled = [];
709
- await this.d.db.transaction().execute(async (t) => {
710
- await lockOrg(t, orgId);
711
- if (c.kind === "plugin") {
712
- // A dependency install this install created: uninstalled by the usual rules
713
- const sub = { removed: [], kept: [] };
714
- await this.uninstallIn(t, orgId, actor, c.ref, {
715
- report: sub,
716
- removing: new Set([installId]),
717
- from: installId,
718
- authorize: false,
719
- reason: "plugin_install_rollback",
720
- opts,
721
- });
722
- disabled.push(...sub.removed.filter((r) => r.kind === "extension").map((r) => r.ref));
723
- }
724
- else {
725
- // Another enabled extension depends on it (only it provides what that one needs in this
726
- // org): kept (its component row too), so the other does not lose its dependency
727
- if (c.kind === "extension" &&
728
- (await this.d.orgConfigs.enabledDependents(t, orgId, c.ref)).length > 0) {
729
- return;
730
- }
731
- const removed = await this.removeComponent(t, orgId, actor, c, "plugin_install_rollback");
732
- if (removed && c.kind === "extension")
733
- disabled.push(c.ref);
734
- }
735
- await t
736
- .deleteFrom("plugin_install_components")
737
- .where("install_id", "=", installId)
738
- .where("kind", "=", c.kind)
739
- .where("ref", "=", c.ref)
740
- .execute();
741
- });
789
+ const disabled = await this.rollbackOne(orgId, actor, installId, c, opts);
742
790
  for (const p of disabled)
743
- await this.d.orgConfigs.afterDisable(orgId, p);
791
+ await this.orgConfigs.afterDisable(orgId, p);
744
792
  }
745
793
  catch (e) {
746
794
  errors.push({ kind: c.kind, ref: c.ref });
747
- this.d.log?.warn("plugin install rollback step failed", {
795
+ this.log.warn("plugin install rollback step failed", {
748
796
  orgId,
749
797
  kind: c.kind,
750
798
  ref: c.ref,
@@ -754,11 +802,53 @@ export class PluginInstaller {
754
802
  }
755
803
  return errors;
756
804
  }
805
+ /**
806
+ * Undoes one component of a failed install and deletes its component row, under the org row lock,
807
+ * in a transaction of its own (committed when it returns); returns the extensions it disabled
808
+ * (the caller notifies them).
809
+ */
810
+ async rollbackOne(orgId, actor, installId, c, opts) {
811
+ const disabled = [];
812
+ const t = this.db;
813
+ await this.orgLock.lock(orgId);
814
+ if (c.kind === "plugin") {
815
+ // A dependency install this install created: uninstalled by the usual rules
816
+ const sub = { removed: [], kept: [] };
817
+ await this.uninstallIn(orgId, actor, c.ref, {
818
+ report: sub,
819
+ removing: new Set([installId]),
820
+ from: installId,
821
+ authorize: false,
822
+ reason: "plugin_install_rollback",
823
+ opts,
824
+ });
825
+ disabled.push(...sub.removed.filter((r) => r.kind === "extension").map((r) => r.ref));
826
+ }
827
+ else {
828
+ // Another enabled extension depends on it (only it provides what that one needs in this
829
+ // org): kept (its component row too), so the other does not lose its dependency
830
+ if (c.kind === "extension" &&
831
+ (await this.orgConfigs.enabledDependents(orgId, c.ref)).length > 0) {
832
+ return [];
833
+ }
834
+ const removed = await this.removeComponent(orgId, actor, c, "plugin_install_rollback");
835
+ if (removed && c.kind === "extension")
836
+ disabled.push(c.ref);
837
+ }
838
+ await t
839
+ .deleteFrom("plugin_install_components")
840
+ .where("install_id", "=", installId)
841
+ .where("kind", "=", c.kind)
842
+ .where("ref", "=", c.ref)
843
+ .execute();
844
+ return disabled;
845
+ }
757
846
  /** Removes one component (one already gone is no error); returns whether anything changed. */
758
- async removeComponent(t, orgId, actor, c, reason) {
847
+ async removeComponent(orgId, actor, c, reason) {
759
848
  if (c.kind === "extension") {
760
- return this.d.orgConfigs.disableIn(t, orgId, c.ref, actor, reason);
849
+ return this.orgConfigs.disableIn(orgId, c.ref, actor, reason);
761
850
  }
851
+ const t = this.db;
762
852
  if (c.kind === "connector") {
763
853
  const live = await t
764
854
  .selectFrom("connectors")
@@ -769,7 +859,7 @@ export class PluginInstaller {
769
859
  .executeTakeFirst();
770
860
  if (!live)
771
861
  return false;
772
- await this.d.connectors.removeIn(t, orgId, c.ref, actor, undefined, reason);
862
+ await this.connectors.removeIn(orgId, c.ref, actor, undefined, reason);
773
863
  return true;
774
864
  }
775
865
  if (c.kind === "plugin")
@@ -783,9 +873,9 @@ export class PluginInstaller {
783
873
  return false;
784
874
  }
785
875
  if (c.created)
786
- return this.d.skills.softDeleteIn(t, orgId, c.ref, actor, reason);
876
+ return this.skills.softDeleteIn(orgId, c.ref, actor, reason);
787
877
  if (c.skillVersion !== null) {
788
- return this.d.skills.revertVersionIn(t, orgId, c.ref, c.skillVersion, actor, reason);
878
+ return this.skills.revertVersionIn(orgId, c.ref, c.skillVersion, actor, reason);
789
879
  }
790
880
  return false;
791
881
  }
@@ -814,32 +904,36 @@ export class PluginInstaller {
814
904
  async uninstall(orgId, actor, installId, opts = {}) {
815
905
  if (!UUID_RE.test(installId))
816
906
  throw installNotFound();
907
+ return this.writeUninstall(orgId, actor, installId, opts);
908
+ }
909
+ /** The uninstall's one transaction; the extensions it disabled are notified once it commits. */
910
+ async writeUninstall(orgId, actor, installId, opts) {
817
911
  const report = { removed: [], kept: [] };
818
- await this.d.db.transaction().execute(async (t) => {
819
- const outcome = await this.uninstallIn(t, orgId, actor, installId, {
820
- report,
821
- removing: new Set(),
822
- authorize: true,
823
- opts,
824
- });
825
- if (outcome === "missing")
826
- throw installNotFound();
827
- if (outcome === "kept") {
828
- report.kept.push({ kind: "plugin", ref: installId, reason: "used_by_other_install" });
829
- }
912
+ const outcome = await this.uninstallIn(orgId, actor, installId, {
913
+ report,
914
+ removing: new Set(),
915
+ authorize: true,
916
+ opts,
830
917
  });
831
- for (const r of report.removed) {
832
- if (r.kind === "extension")
833
- await this.d.orgConfigs.afterDisable(orgId, r.ref);
918
+ if (outcome === "missing")
919
+ throw installNotFound();
920
+ if (outcome === "kept") {
921
+ report.kept.push({ kind: "plugin", ref: installId, reason: "used_by_other_install" });
834
922
  }
923
+ afterCommit(async () => {
924
+ for (const r of report.removed) {
925
+ if (r.kind === "extension")
926
+ await this.orgConfigs.afterDisable(orgId, r.ref);
927
+ }
928
+ });
835
929
  return report;
836
930
  }
837
931
  /**
838
932
  * The oldest other live install (not in `removing`) that has component `kind` / `ref`, or
839
933
  * undefined.
840
934
  */
841
- async heir(t, orgId, removing, kind, ref) {
842
- let q = t
935
+ async heir(orgId, removing, kind, ref) {
936
+ let q = this.db
843
937
  .selectFrom("plugin_install_components as c")
844
938
  .innerJoin("plugin_installs as a", "a.id", "c.install_id")
845
939
  .select("a.id")
@@ -853,8 +947,8 @@ export class PluginInstaller {
853
947
  return row?.id;
854
948
  }
855
949
  /** Passes ownership of a component to `heir` (its component row becomes created=true). */
856
- async handOver(t, heir, kind, ref) {
857
- await t
950
+ async handOver(heir, kind, ref) {
951
+ await this.db
858
952
  .updateTable("plugin_install_components")
859
953
  .set({ created: true })
860
954
  .where("install_id", "=", heir)
@@ -868,7 +962,8 @@ export class PluginInstaller {
868
962
  * outcome of the install itself is returned for the caller to report: `missing`, `kept` (another
869
963
  * install outside this uninstall depends on it) or `removed`.
870
964
  */
871
- async uninstallIn(t, orgId, actor, installId, ctx) {
965
+ async uninstallIn(orgId, actor, installId, ctx) {
966
+ const t = this.db;
872
967
  const { removing } = ctx;
873
968
  if (removing.has(installId))
874
969
  return "removed";
@@ -882,7 +977,7 @@ export class PluginInstaller {
882
977
  mine.kept.push(x);
883
978
  ctx.report.kept.push(x);
884
979
  };
885
- const staleMinutes = this.d.staleInstallMinutes();
980
+ const staleMinutes = this.staleInstallMinutes();
886
981
  if (ctx.authorize) {
887
982
  const target = await t
888
983
  .selectFrom("plugin_installs as a")
@@ -891,7 +986,7 @@ export class PluginInstaller {
891
986
  .where("a.id", "=", installId)
892
987
  .where("a.org_id", "=", orgId)
893
988
  .executeTakeFirst();
894
- await lockOrgForActions(t, orgId, actor, target ? requiredActions(target.manifest) : ALL_ACTIONS);
989
+ await lockOrgForActions(this.orgLock, orgId, actor, target ? requiredActions(target.manifest) : ALL_ACTIONS);
895
990
  }
896
991
  const row = await t
897
992
  .selectFrom("plugin_installs as a")
@@ -914,10 +1009,10 @@ export class PluginInstaller {
914
1009
  return "missing";
915
1010
  // Another install outside this uninstall depends on it: kept (a dependency uninstall hands
916
1011
  // ownership over)
917
- const user = await this.heir(t, orgId, new Set([...removing, installId]), "plugin", installId);
1012
+ const user = await this.heir(orgId, new Set([...removing, installId]), "plugin", installId);
918
1013
  if (user !== undefined) {
919
1014
  if (ctx.from !== undefined)
920
- await this.handOver(t, user, "plugin", installId);
1015
+ await this.handOver(user, "plugin", installId);
921
1016
  return "kept";
922
1017
  }
923
1018
  if (row.status === "uninstalling" ||
@@ -927,7 +1022,7 @@ export class PluginInstaller {
927
1022
  }
928
1023
  if (row.status === "upgrading") {
929
1024
  // An upgrade interrupted midway (a replica crashed): undone first, back at the old version
930
- const undone = await this.undoUpgradeIn(t, orgId, actor, installId, journalEntries(row.upgrade), "plugin_upgrade_cleanup");
1025
+ const undone = await this.undoUpgradeIn(orgId, actor, installId, journalEntries(row.upgrade), "plugin_upgrade_cleanup");
931
1026
  for (const x of undone)
932
1027
  addRemoved(x);
933
1028
  }
@@ -953,7 +1048,7 @@ export class PluginInstaller {
953
1048
  ? 2 + extensionOrder.indexOf(c.ref)
954
1049
  : 1000 + (c.created ? 0 : 1);
955
1050
  comps.sort((a, b) => rank(a) - rank(b));
956
- const agentRefs = await this.agentRefs(t, orgId);
1051
+ const agentRefs = await this.agentRefs(orgId);
957
1052
  for (const c of comps) {
958
1053
  const keep = (reason) => addKept({ kind: c.kind, ref: c.ref, reason });
959
1054
  let created = c.created;
@@ -983,7 +1078,7 @@ export class PluginInstaller {
983
1078
  if (rollbackMode &&
984
1079
  (c.kind === "skill" || c.kind === "agent_template") &&
985
1080
  c.skill_version !== null &&
986
- (await this.removeComponent(t, orgId, actor, comp, "plugin_install_cleanup"))) {
1081
+ (await this.removeComponent(orgId, actor, comp, "plugin_install_cleanup"))) {
987
1082
  addRemoved({ kind: c.kind, ref: c.ref });
988
1083
  continue;
989
1084
  }
@@ -991,7 +1086,7 @@ export class PluginInstaller {
991
1086
  continue;
992
1087
  }
993
1088
  if (c.kind === "plugin") {
994
- const outcome = await this.uninstallIn(t, orgId, actor, c.ref, { ...ctx, from: installId });
1089
+ const outcome = await this.uninstallIn(orgId, actor, c.ref, { ...ctx, from: installId });
995
1090
  if (outcome === "removed")
996
1091
  addRemoved({ kind: "plugin", ref: c.ref });
997
1092
  else if (outcome === "kept")
@@ -999,7 +1094,7 @@ export class PluginInstaller {
999
1094
  continue;
1000
1095
  }
1001
1096
  const reason = rollbackMode ? "plugin_install_cleanup" : (ctx.reason ?? "plugin_uninstall");
1002
- const outcome = await this.decideRemovalIn(t, orgId, actor, comp, removing, agentRefs, reason);
1097
+ const outcome = await this.decideRemovalIn(orgId, actor, comp, removing, agentRefs, reason);
1003
1098
  if (outcome === "removed")
1004
1099
  addRemoved({ kind: c.kind, ref: c.ref });
1005
1100
  else if (outcome !== "gone")
@@ -1034,7 +1129,7 @@ export class PluginInstaller {
1034
1129
  * (`used_by_plugins`); otherwise removed (`removed`, or `gone` when it no longer existed). Used
1035
1130
  * by uninstall and by an upgrade's removals.
1036
1131
  */
1037
- async decideRemovalIn(t, orgId, actor, c, removing, agentRefs, reason) {
1132
+ async decideRemovalIn(orgId, actor, c, removing, agentRefs, reason) {
1038
1133
  if (c.kind === "skill" && agentRefs.skills.has(c.ref))
1039
1134
  return "used_by_agents";
1040
1135
  if (c.kind === "agent_template" && agentRefs.templates.has(c.ref))
@@ -1042,16 +1137,16 @@ export class PluginInstaller {
1042
1137
  if (c.kind === "connector" && agentRefs.connectors.has(c.ref))
1043
1138
  return "used_by_agents";
1044
1139
  if (c.kind !== "connector") {
1045
- const heir = await this.heir(t, orgId, removing, c.kind, c.ref);
1140
+ const heir = await this.heir(orgId, removing, c.kind, c.ref);
1046
1141
  if (heir !== undefined) {
1047
- await this.handOver(t, heir, c.kind, c.ref);
1142
+ await this.handOver(heir, c.kind, c.ref);
1048
1143
  return "used_by_other_install";
1049
1144
  }
1050
1145
  }
1051
1146
  if (c.kind === "extension") {
1052
1147
  const kinds = this.connectorKindsOf(c.ref);
1053
1148
  if (kinds.length > 0) {
1054
- const used = await t
1149
+ const used = await this.db
1055
1150
  .selectFrom("connectors")
1056
1151
  .select("id")
1057
1152
  .where("org_id", "=", orgId)
@@ -1061,21 +1156,21 @@ export class PluginInstaller {
1061
1156
  if (used)
1062
1157
  return "used_by_connectors";
1063
1158
  }
1064
- if ((await this.d.orgConfigs.enabledDependents(t, orgId, c.ref)).length > 0) {
1159
+ if ((await this.orgConfigs.enabledDependents(orgId, c.ref)).length > 0) {
1065
1160
  return "used_by_plugins";
1066
1161
  }
1067
1162
  }
1068
- return (await this.removeComponent(t, orgId, actor, c, reason)) ? "removed" : "gone";
1163
+ return (await this.removeComponent(orgId, actor, c, reason)) ? "removed" : "gone";
1069
1164
  }
1070
1165
  /** The order extensions are uninstalled in: the reverse of the install (requires) order; extensions not loaded on this replica last. */
1071
1166
  uninstallExtensionOrder(refs) {
1072
- const loaded = new Map(this.d.host.manifests().map((m) => [m.name, m]));
1167
+ const loaded = new Map(this.registry.manifests().map((m) => [m.name, m]));
1073
1168
  const known = refs.filter((r) => loaded.has(r)).map((r) => loaded.get(r));
1074
1169
  return [...orderByRequires(known).reverse(), ...refs.filter((r) => !loaded.has(r))];
1075
1170
  }
1076
1171
  /** The org's plugin installs (failed ones included), newest first; `installId` picks one. */
1077
1172
  async list(orgId, installId) {
1078
- let q = this.d.db
1173
+ let q = this.db
1079
1174
  .selectFrom("plugin_installs as a")
1080
1175
  .innerJoin("catalog_items as i", "i.id", "a.item_id")
1081
1176
  .select([
@@ -1094,8 +1189,8 @@ export class PluginInstaller {
1094
1189
  const rows = await q.orderBy("a.installed_at", "desc").orderBy("a.id").execute();
1095
1190
  if (rows.length === 0)
1096
1191
  return [];
1097
- const info = await upgradeInfo(this.d.db, this.d.host, rows.map((r) => ({ itemId: r.item_id, name: r.name, version: r.version })));
1098
- const comps = await this.d.db
1192
+ const info = await upgradeInfo(this.db, this.registry, rows.map((r) => ({ itemId: r.item_id, name: r.name, version: r.version })));
1193
+ const comps = await this.db
1099
1194
  .selectFrom("plugin_install_components")
1100
1195
  .select(["install_id", "kind", "ref", "created", "skill_version", "dropped"])
1101
1196
  .where("install_id", "in", rows.map((r) => r.id))
@@ -1131,9 +1226,9 @@ export class PluginInstaller {
1131
1226
  * extension among them needs `afterDisable` once committed). Used when an upgrade fails and when
1132
1227
  * an interrupted one is cleaned up.
1133
1228
  */
1134
- async undoUpgradeIn(t, orgId, actor, installId, steps, reason) {
1229
+ async undoUpgradeIn(orgId, actor, installId, steps, reason) {
1135
1230
  const removed = [];
1136
- const dropRow = (kind, ref) => t
1231
+ const dropRow = (kind, ref) => this.db
1137
1232
  .deleteFrom("plugin_install_components")
1138
1233
  .where("install_id", "=", installId)
1139
1234
  .where("kind", "=", kind)
@@ -1141,11 +1236,11 @@ export class PluginInstaller {
1141
1236
  .execute();
1142
1237
  for (const s of [...steps].reverse()) {
1143
1238
  if (s.op === "skill_version") {
1144
- await this.d.skills.revertVersionIn(t, orgId, s.ref, s.version, actor, reason);
1239
+ await this.skills.revertVersionIn(orgId, s.ref, s.version, actor, reason);
1145
1240
  continue;
1146
1241
  }
1147
1242
  if (s.op === "template_version") {
1148
- await revertTemplateVersionIn(t, orgId, s.ref, s.version);
1243
+ await revertTemplateVersionIn(this.db, orgId, s.ref, s.version);
1149
1244
  continue;
1150
1245
  }
1151
1246
  if (s.op === "recorded") {
@@ -1155,7 +1250,7 @@ export class PluginInstaller {
1155
1250
  if (s.kind === "plugin") {
1156
1251
  const sub = { removed: [], kept: [] };
1157
1252
  await dropRow(s.kind, s.ref);
1158
- const outcome = await this.uninstallIn(t, orgId, actor, s.ref, {
1253
+ const outcome = await this.uninstallIn(orgId, actor, s.ref, {
1159
1254
  report: sub,
1160
1255
  removing: new Set([installId]),
1161
1256
  from: installId,
@@ -1169,12 +1264,12 @@ export class PluginInstaller {
1169
1264
  continue;
1170
1265
  }
1171
1266
  if (s.kind === "extension" &&
1172
- (await this.d.orgConfigs.enabledDependents(t, orgId, s.ref)).length > 0) {
1267
+ (await this.orgConfigs.enabledDependents(orgId, s.ref)).length > 0) {
1173
1268
  // Another enabled extension needs it: kept, and stays this install's component
1174
1269
  continue;
1175
1270
  }
1176
1271
  const c = { kind: s.kind, ref: s.ref, created: true, skillVersion: null };
1177
- if (await this.removeComponent(t, orgId, actor, c, reason)) {
1272
+ if (await this.removeComponent(orgId, actor, c, reason)) {
1178
1273
  removed.push({ kind: s.kind, ref: s.ref });
1179
1274
  }
1180
1275
  await dropRow(s.kind, s.ref);
@@ -1183,7 +1278,7 @@ export class PluginInstaller {
1183
1278
  }
1184
1279
  /** The connector kinds an extension provides (the `connector@1` implementations loaded on this replica). */
1185
1280
  connectorKindsOf(plugin) {
1186
- return this.d.host
1281
+ return this.registry
1187
1282
  .list("connector")
1188
1283
  .filter((e) => e.plugin === plugin)
1189
1284
  .map((e) => e.impl?.kind)
@@ -1193,8 +1288,8 @@ export class PluginInstaller {
1193
1288
  * The connectors, org skills and agent templates (`subagents.templates`) referenced by the
1194
1289
  * current definitions of the org's live agents.
1195
1290
  */
1196
- async agentRefs(t, orgId) {
1197
- const rows = await t
1291
+ async agentRefs(orgId) {
1292
+ const rows = await this.db
1198
1293
  .selectFrom("agents as a")
1199
1294
  .innerJoin("agent_versions as v", (j) => j.onRef("v.agent_id", "=", "a.id").onRef("v.version", "=", "a.current_version"))
1200
1295
  .select("v.definition")
@@ -1221,7 +1316,64 @@ export class PluginInstaller {
1221
1316
  }
1222
1317
  return { connectors, skills, templates };
1223
1318
  }
1224
- }
1319
+ };
1320
+ __decorate([
1321
+ Transactional({ propagation: "requires_new" })
1322
+ ], PluginInstaller.prototype, "recordDependency", null);
1323
+ __decorate([
1324
+ Transactional()
1325
+ ], PluginInstaller.prototype, "enableExtension", null);
1326
+ __decorate([
1327
+ Transactional({ propagation: "requires_new" })
1328
+ ], PluginInstaller.prototype, "createInstallRow", null);
1329
+ __decorate([
1330
+ Transactional({ propagation: "requires_new" })
1331
+ ], PluginInstaller.prototype, "installAgentTemplate", null);
1332
+ __decorate([
1333
+ Transactional({ propagation: "requires_new" })
1334
+ ], PluginInstaller.prototype, "markInstalled", null);
1335
+ __decorate([
1336
+ Transactional({ propagation: "requires_new" })
1337
+ ], PluginInstaller.prototype, "markFailed", null);
1338
+ __decorate([
1339
+ Transactional({ propagation: "requires_new" })
1340
+ ], PluginInstaller.prototype, "rollbackOne", null);
1341
+ __decorate([
1342
+ Transactional({ propagation: "mandatory" })
1343
+ ], PluginInstaller.prototype, "removeComponent", null);
1344
+ __decorate([
1345
+ Transactional()
1346
+ ], PluginInstaller.prototype, "writeUninstall", null);
1347
+ __decorate([
1348
+ Transactional({ propagation: "mandatory" })
1349
+ ], PluginInstaller.prototype, "heir", null);
1350
+ __decorate([
1351
+ Transactional({ propagation: "mandatory" })
1352
+ ], PluginInstaller.prototype, "handOver", null);
1353
+ __decorate([
1354
+ Transactional({ propagation: "mandatory" })
1355
+ ], PluginInstaller.prototype, "uninstallIn", null);
1356
+ __decorate([
1357
+ Transactional({ propagation: "mandatory" })
1358
+ ], PluginInstaller.prototype, "decideRemovalIn", null);
1359
+ __decorate([
1360
+ Transactional({ propagation: "mandatory" })
1361
+ ], PluginInstaller.prototype, "undoUpgradeIn", null);
1362
+ PluginInstaller = __decorate([
1363
+ Injectable(),
1364
+ __param(0, Inject(KernelDb)),
1365
+ __param(1, Inject(OrgLock)),
1366
+ __param(2, Inject(StorageService)),
1367
+ __param(3, Inject(ExtensionRegistry)),
1368
+ __param(4, Inject(SkillsService)),
1369
+ __param(5, Inject(OrgExtensionConfigs)),
1370
+ __param(6, Inject(CatalogRequestsService)),
1371
+ __param(7, Inject(KernelConfigService)),
1372
+ __param(8, Inject(ConnectorsService)),
1373
+ __param(9, Inject(KERNEL_LOGGER)),
1374
+ __param(10, Inject(TransactionHost))
1375
+ ], PluginInstaller);
1376
+ export { PluginInstaller };
1225
1377
  /**
1226
1378
  * The skill names of a catalog version, read from each skill's SKILL.md in storage (the names are
1227
1379
  * not in plugin.json). Used by install planning and the upgrade preview.