@capybara-hq/kernel 0.1.0-rc.3 → 0.1.0-rc.31

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 (1215) hide show
  1. package/bootstrap.json +94 -5
  2. package/dist/admin/admin-agents.controller.d.ts +28 -0
  3. package/dist/admin/admin-agents.controller.js +79 -0
  4. package/dist/admin/admin-connectors.controller.d.ts +29 -0
  5. package/dist/admin/admin-connectors.controller.js +79 -0
  6. package/dist/admin/admin-items.schemas.d.ts +42 -0
  7. package/dist/admin/admin-items.schemas.js +48 -0
  8. package/dist/admin/admin.controller.d.ts +54 -82
  9. package/dist/admin/admin.controller.js +118 -83
  10. package/dist/admin/admin.module.d.ts +5 -1
  11. package/dist/admin/admin.module.js +56 -4
  12. package/dist/admin/admin.schemas.d.ts +87 -0
  13. package/dist/admin/admin.schemas.js +53 -0
  14. package/dist/admin/audit.controller.d.ts +14 -0
  15. package/dist/admin/audit.controller.js +42 -0
  16. package/dist/admin/audit.schemas.d.ts +8 -0
  17. package/dist/admin/audit.schemas.js +17 -0
  18. package/dist/admin/extensions.controller.d.ts +34 -3
  19. package/dist/admin/extensions.controller.js +66 -8
  20. package/dist/admin/extensions.schemas.d.ts +7 -0
  21. package/dist/admin/extensions.schemas.js +10 -0
  22. package/dist/admin/health.service.d.ts +104 -0
  23. package/dist/admin/health.service.js +250 -0
  24. package/dist/admin/limit-defaults.d.ts +20 -0
  25. package/dist/admin/limit-defaults.js +10 -0
  26. package/dist/admin/outbox-dead.controller.d.ts +23 -0
  27. package/dist/admin/outbox-dead.controller.js +62 -0
  28. package/dist/admin/outbox-dead.schemas.d.ts +8 -0
  29. package/dist/admin/outbox-dead.schemas.js +18 -0
  30. package/dist/admin/outbox-dead.service.d.ts +70 -0
  31. package/dist/admin/outbox-dead.service.js +190 -0
  32. package/dist/admin/overview.controller.d.ts +31 -0
  33. package/dist/admin/overview.controller.js +78 -0
  34. package/dist/admin/overview.schemas.d.ts +8 -0
  35. package/dist/admin/overview.schemas.js +13 -0
  36. package/dist/admin/overview.service.d.ts +147 -0
  37. package/dist/admin/overview.service.js +257 -0
  38. package/dist/admin/platform-audit.service.d.ts +41 -0
  39. package/dist/admin/platform-audit.service.js +70 -0
  40. package/dist/admin/setup-lock.d.ts +1 -1
  41. package/dist/admin/setup-lock.js +1 -1
  42. package/dist/admin/setup.controller.d.ts +1 -1
  43. package/dist/admin/setup.controller.js +1 -1
  44. package/dist/admin/setup.service.d.ts +4 -4
  45. package/dist/admin/setup.service.js +8 -8
  46. package/dist/admin/usage.service.d.ts +149 -0
  47. package/dist/admin/usage.service.js +321 -0
  48. package/dist/agents/admin-agents.d.ts +105 -0
  49. package/dist/agents/admin-agents.js +228 -0
  50. package/dist/agents/agent-lookup.d.ts +24 -0
  51. package/dist/agents/agent-lookup.js +36 -0
  52. package/dist/agents/agent-profile.service.d.ts +31 -0
  53. package/dist/agents/agent-profile.service.js +122 -0
  54. package/dist/agents/agents.controller.d.ts +53 -168
  55. package/dist/agents/agents.controller.js +163 -34
  56. package/dist/agents/agents.module.d.ts +6 -2
  57. package/dist/agents/agents.module.js +44 -7
  58. package/dist/agents/agents.schemas.d.ts +440 -0
  59. package/dist/agents/agents.schemas.js +126 -0
  60. package/dist/agents/agents.service.d.ts +130 -39
  61. package/dist/agents/agents.service.js +435 -136
  62. package/dist/agents/definition.d.ts +169 -23
  63. package/dist/agents/definition.js +310 -55
  64. package/dist/agents/from-template.d.ts +109 -0
  65. package/dist/agents/from-template.js +693 -0
  66. package/dist/agents/from-template.service.d.ts +72 -0
  67. package/dist/agents/from-template.service.js +178 -0
  68. package/dist/agents/instruction-files.d.ts +60 -0
  69. package/dist/agents/instruction-files.js +111 -0
  70. package/dist/agents/models.controller.d.ts +44 -6
  71. package/dist/agents/models.controller.js +84 -8
  72. package/dist/agents/org-templates.d.ts +186 -0
  73. package/dist/agents/org-templates.js +932 -0
  74. package/dist/agents/pending-connector-requests.d.ts +79 -0
  75. package/dist/agents/pending-connector-requests.js +215 -0
  76. package/dist/agents/pending-connectors.controller.d.ts +39 -0
  77. package/dist/agents/pending-connectors.controller.js +91 -0
  78. package/dist/agents/pending-connectors.service.d.ts +62 -0
  79. package/dist/agents/pending-connectors.service.js +282 -0
  80. package/dist/agents/profile.d.ts +114 -0
  81. package/dist/agents/profile.js +55 -0
  82. package/dist/agents/readiness.controller.d.ts +26 -0
  83. package/dist/agents/readiness.controller.js +56 -0
  84. package/dist/agents/templates.controller.d.ts +77 -5
  85. package/dist/agents/templates.controller.js +153 -7
  86. package/dist/agents/templates.d.ts +133 -23
  87. package/dist/agents/templates.js +490 -53
  88. package/dist/agents/templates.schemas.d.ts +20 -0
  89. package/dist/agents/templates.schemas.js +45 -0
  90. package/dist/app.js +2 -0
  91. package/dist/attribution/platform-attribution.d.ts +104 -0
  92. package/dist/attribution/platform-attribution.js +149 -0
  93. package/dist/background/background.controller.d.ts +38 -0
  94. package/dist/background/background.controller.js +88 -0
  95. package/dist/background/background.module.d.ts +10 -0
  96. package/dist/background/background.module.js +39 -0
  97. package/dist/background/background.schemas.d.ts +10 -0
  98. package/dist/background/background.schemas.js +16 -0
  99. package/dist/background/finish.d.ts +47 -0
  100. package/dist/background/finish.js +106 -0
  101. package/dist/background/launch-lock.d.ts +15 -0
  102. package/dist/background/launch-lock.js +40 -0
  103. package/dist/background/launch.d.ts +81 -0
  104. package/dist/background/launch.js +160 -0
  105. package/dist/background/poll.job.d.ts +56 -0
  106. package/dist/background/poll.job.js +195 -0
  107. package/dist/background/render.d.ts +23 -0
  108. package/dist/background/render.js +48 -0
  109. package/dist/background/session.d.ts +60 -0
  110. package/dist/background/session.js +102 -0
  111. package/dist/background/status.d.ts +35 -0
  112. package/dist/background/status.js +57 -0
  113. package/dist/background/stop.d.ts +66 -0
  114. package/dist/background/stop.js +224 -0
  115. package/dist/background/store.d.ts +175 -0
  116. package/dist/background/store.js +385 -0
  117. package/dist/background/store.module.d.ts +6 -0
  118. package/dist/background/store.module.js +22 -0
  119. package/dist/background/tasks.service.d.ts +109 -0
  120. package/dist/background/tasks.service.js +271 -0
  121. package/dist/background/wake-rules.d.ts +71 -0
  122. package/dist/background/wake-rules.js +124 -0
  123. package/dist/background/wake.d.ts +30 -0
  124. package/dist/background/wake.js +63 -0
  125. package/dist/catalog/admin-catalog.controller.d.ts +156 -55
  126. package/dist/catalog/admin-catalog.controller.js +313 -68
  127. package/dist/catalog/admin-catalog.schemas.d.ts +87 -0
  128. package/dist/catalog/admin-catalog.schemas.js +107 -0
  129. package/dist/catalog/appearance.schemas.d.ts +10 -0
  130. package/dist/catalog/appearance.schemas.js +20 -0
  131. package/dist/catalog/appearance.service.d.ts +105 -0
  132. package/dist/catalog/appearance.service.js +306 -0
  133. package/dist/catalog/catalog-content.d.ts +144 -35
  134. package/dist/catalog/catalog-content.js +122 -13
  135. package/dist/catalog/catalog-files.d.ts +42 -0
  136. package/dist/catalog/catalog-files.js +89 -0
  137. package/dist/catalog/catalog-import.module.d.ts +7 -0
  138. package/dist/catalog/catalog-import.module.js +59 -0
  139. package/dist/catalog/catalog-items.d.ts +122 -7
  140. package/dist/catalog/catalog-items.js +301 -13
  141. package/dist/catalog/catalog-scope.service.d.ts +330 -0
  142. package/dist/catalog/catalog-scope.service.js +1312 -0
  143. package/dist/catalog/catalog.module.d.ts +8 -9
  144. package/dist/catalog/catalog.module.js +55 -31
  145. package/dist/catalog/catalog.service.d.ts +129 -31
  146. package/dist/catalog/catalog.service.js +193 -105
  147. package/dist/catalog/claude/agents.js +2 -0
  148. package/dist/catalog/claude/report.d.ts +9 -2
  149. package/dist/catalog/claude/report.js +1 -0
  150. package/dist/catalog/claude/translate.js +4 -1
  151. package/dist/catalog/cli.d.ts +12 -1
  152. package/dist/catalog/cli.js +24 -1
  153. package/dist/catalog/component-promotion.d.ts +96 -0
  154. package/dist/catalog/component-promotion.js +394 -0
  155. package/dist/catalog/component-scope.controller.d.ts +102 -0
  156. package/dist/catalog/component-scope.controller.js +257 -0
  157. package/dist/catalog/component-scope.schemas.d.ts +118 -0
  158. package/dist/catalog/component-scope.schemas.js +97 -0
  159. package/dist/catalog/component-scope.service.d.ts +394 -0
  160. package/dist/catalog/component-scope.service.js +1133 -0
  161. package/dist/catalog/component-state.d.ts +219 -0
  162. package/dist/catalog/component-state.js +493 -0
  163. package/dist/catalog/git-source.d.ts +9 -1
  164. package/dist/catalog/git-source.js +29 -2
  165. package/dist/catalog/job-ids.d.ts +19 -1
  166. package/dist/catalog/job-ids.js +21 -1
  167. package/dist/catalog/marketplace-fetch.d.ts +6 -3
  168. package/dist/catalog/marketplace-fetch.js +4 -1
  169. package/dist/catalog/marketplace-icons.d.ts +64 -0
  170. package/dist/catalog/marketplace-icons.js +131 -0
  171. package/dist/catalog/marketplaces.controller.d.ts +50 -41
  172. package/dist/catalog/marketplaces.controller.js +130 -46
  173. package/dist/catalog/marketplaces.schemas.d.ts +48 -0
  174. package/dist/catalog/marketplaces.schemas.js +53 -0
  175. package/dist/catalog/marketplaces.service.d.ts +110 -17
  176. package/dist/catalog/marketplaces.service.js +339 -30
  177. package/dist/catalog/org-catalog.controller.d.ts +124 -62
  178. package/dist/catalog/org-catalog.controller.js +208 -93
  179. package/dist/catalog/org-catalog.schemas.d.ts +117 -0
  180. package/dist/catalog/org-catalog.schemas.js +141 -0
  181. package/dist/catalog/org-catalog.service.d.ts +72 -33
  182. package/dist/catalog/org-catalog.service.js +377 -158
  183. package/dist/catalog/org-extension-switch.d.ts +41 -0
  184. package/dist/catalog/org-extension-switch.js +115 -0
  185. package/dist/catalog/org-extension.controller.d.ts +133 -0
  186. package/dist/catalog/org-extension.controller.js +313 -0
  187. package/dist/catalog/org-extension.schemas.d.ts +15 -0
  188. package/dist/catalog/org-extension.schemas.js +22 -0
  189. package/dist/catalog/org-plugin-uploads.controller.d.ts +77 -0
  190. package/dist/catalog/org-plugin-uploads.controller.js +199 -0
  191. package/dist/catalog/org-plugin-uploads.d.ts +77 -0
  192. package/dist/catalog/org-plugin-uploads.js +134 -0
  193. package/dist/catalog/org-plugin-uploads.schemas.d.ts +19 -0
  194. package/dist/catalog/org-plugin-uploads.schemas.js +30 -0
  195. package/dist/catalog/owned-items.d.ts +181 -0
  196. package/dist/catalog/owned-items.js +790 -0
  197. package/dist/catalog/owned-plugin-cleanup.d.ts +47 -0
  198. package/dist/catalog/owned-plugin-cleanup.js +140 -0
  199. package/dist/catalog/ownership.d.ts +172 -0
  200. package/dist/catalog/ownership.js +326 -0
  201. package/dist/catalog/platform-components.d.ts +264 -0
  202. package/dist/catalog/platform-components.js +857 -0
  203. package/dist/catalog/platform-import-update.d.ts +50 -0
  204. package/dist/catalog/platform-import-update.js +116 -0
  205. package/dist/catalog/plugin-import.d.ts +289 -52
  206. package/dist/catalog/plugin-import.js +846 -143
  207. package/dist/catalog/plugin-install.d.ts +235 -51
  208. package/dist/catalog/plugin-install.js +915 -139
  209. package/dist/catalog/plugin-package.d.ts +50 -4
  210. package/dist/catalog/plugin-package.js +221 -8
  211. package/dist/catalog/plugin-upgrade.d.ts +325 -225
  212. package/dist/catalog/plugin-upgrade.js +1317 -1133
  213. package/dist/catalog/request-rules.d.ts +65 -0
  214. package/dist/catalog/request-rules.js +217 -0
  215. package/dist/catalog/requests.service.d.ts +251 -117
  216. package/dist/catalog/requests.service.js +701 -323
  217. package/dist/catalog/reserved-names.d.ts +8 -0
  218. package/dist/catalog/reserved-names.js +42 -0
  219. package/dist/catalog/scope-jobs.d.ts +59 -0
  220. package/dist/catalog/scope-jobs.js +65 -0
  221. package/dist/catalog/scope-orgs.d.ts +21 -0
  222. package/dist/catalog/scope-orgs.js +67 -0
  223. package/dist/catalog/scope-state.d.ts +35 -0
  224. package/dist/catalog/scope-state.js +87 -0
  225. package/dist/catalog/scope-sync-workers.d.ts +29 -0
  226. package/dist/catalog/scope-sync-workers.js +85 -0
  227. package/dist/catalog/scope-sync.d.ts +151 -0
  228. package/dist/catalog/scope-sync.js +568 -0
  229. package/dist/catalog/scope.d.ts +42 -0
  230. package/dist/catalog/scope.js +42 -0
  231. package/dist/catalog/unshare.d.ts +22 -0
  232. package/dist/catalog/unshare.js +119 -0
  233. package/dist/channels/actions.d.ts +5 -0
  234. package/dist/channels/actions.js +33 -7
  235. package/dist/channels/cards.d.ts +59 -9
  236. package/dist/channels/cards.js +173 -20
  237. package/dist/channels/channels.module.d.ts +13 -9
  238. package/dist/channels/channels.module.js +33 -11
  239. package/dist/channels/channels.schemas.d.ts +41 -0
  240. package/dist/channels/channels.schemas.js +40 -0
  241. package/dist/channels/connections.controller.d.ts +46 -37
  242. package/dist/channels/connections.controller.js +76 -34
  243. package/dist/channels/connections.service.d.ts +105 -13
  244. package/dist/channels/connections.service.js +277 -30
  245. package/dist/channels/deliver-job.d.ts +32 -0
  246. package/dist/channels/deliver-job.js +29 -0
  247. package/dist/channels/inbound.d.ts +12 -2
  248. package/dist/channels/inbound.js +89 -22
  249. package/dist/channels/jobs.d.ts +37 -20
  250. package/dist/channels/jobs.js +79 -27
  251. package/dist/channels/outbound.d.ts +40 -3
  252. package/dist/channels/outbound.js +187 -22
  253. package/dist/channels/phrases.d.ts +93 -2
  254. package/dist/channels/phrases.js +71 -1
  255. package/dist/channels/supervisor.d.ts +2 -0
  256. package/dist/channels/supervisor.js +4 -0
  257. package/dist/channels/threads.d.ts +21 -3
  258. package/dist/channels/threads.js +46 -3
  259. package/dist/channels/webhook.d.ts +21 -1
  260. package/dist/channels/webhook.js +39 -4
  261. package/dist/client/client-access.service.d.ts +102 -0
  262. package/dist/client/client-access.service.js +303 -0
  263. package/dist/client/client-builds.service.d.ts +109 -0
  264. package/dist/client/client-builds.service.js +229 -0
  265. package/dist/client/client-delivery.controller.d.ts +25 -0
  266. package/dist/client/client-delivery.controller.js +66 -0
  267. package/dist/client/client-files.d.ts +48 -0
  268. package/dist/client/client-files.js +136 -0
  269. package/dist/client/client-reports.cron.d.ts +13 -0
  270. package/dist/client/client-reports.cron.js +42 -0
  271. package/dist/client/client-reports.service.d.ts +30 -0
  272. package/dist/client/client-reports.service.js +102 -0
  273. package/dist/client/client-sign-in.service.d.ts +21 -0
  274. package/dist/client/client-sign-in.service.js +49 -0
  275. package/dist/client/client.controller.d.ts +49 -0
  276. package/dist/client/client.controller.js +129 -0
  277. package/dist/client/client.module.d.ts +8 -0
  278. package/dist/client/client.module.js +28 -0
  279. package/dist/client/client.schemas.d.ts +61 -0
  280. package/dist/client/client.schemas.js +27 -0
  281. package/dist/config/docs.js +5 -1
  282. package/dist/config/load.d.ts +6 -0
  283. package/dist/config/load.js +26 -0
  284. package/dist/config/schema.d.ts +71 -11
  285. package/dist/config/schema.js +432 -61
  286. package/dist/conversations/access.d.ts +6 -4
  287. package/dist/conversations/access.js +29 -5
  288. package/dist/conversations/agent-tree.d.ts +62 -0
  289. package/dist/conversations/agent-tree.js +128 -0
  290. package/dist/conversations/attachments.service.d.ts +30 -0
  291. package/dist/conversations/attachments.service.js +130 -5
  292. package/dist/conversations/conversations.controller.d.ts +91 -44
  293. package/dist/conversations/conversations.controller.js +161 -82
  294. package/dist/conversations/conversations.module.d.ts +1 -1
  295. package/dist/conversations/conversations.module.js +10 -7
  296. package/dist/conversations/conversations.schemas.d.ts +60 -0
  297. package/dist/conversations/conversations.schemas.js +93 -0
  298. package/dist/conversations/conversations.service.d.ts +291 -23
  299. package/dist/conversations/conversations.service.js +479 -82
  300. package/dist/conversations/device-status.d.ts +24 -0
  301. package/dist/conversations/device-status.js +71 -0
  302. package/dist/conversations/event-log.d.ts +61 -18
  303. package/dist/conversations/event-log.js +135 -21
  304. package/dist/conversations/events.d.ts +528 -17
  305. package/dist/conversations/events.js +537 -33
  306. package/dist/conversations/message-context.d.ts +82 -0
  307. package/dist/conversations/message-context.js +149 -0
  308. package/dist/conversations/queue.d.ts +20 -4
  309. package/dist/conversations/queue.js +44 -5
  310. package/dist/conversations/queue.service.d.ts +20 -9
  311. package/dist/conversations/queue.service.js +88 -23
  312. package/dist/conversations/source.d.ts +10 -0
  313. package/dist/conversations/source.js +17 -0
  314. package/dist/conversations/titles.d.ts +33 -11
  315. package/dist/conversations/titles.js +76 -25
  316. package/dist/conversations/tree.d.ts +27 -0
  317. package/dist/conversations/tree.js +77 -0
  318. package/dist/ctx/create-ctx.d.ts +48 -5
  319. package/dist/ctx/create-ctx.js +174 -34
  320. package/dist/db/kernel-schema.d.ts +819 -33
  321. package/dist/db/pool.d.ts +5 -0
  322. package/dist/db/pool.js +3 -0
  323. package/dist/devices/access.d.ts +66 -0
  324. package/dist/devices/access.js +113 -0
  325. package/dist/devices/conversation-devices.d.ts +107 -0
  326. package/dist/devices/conversation-devices.js +315 -0
  327. package/dist/devices/devices.controller.d.ts +52 -0
  328. package/dist/devices/devices.controller.js +162 -0
  329. package/dist/devices/devices.module.d.ts +8 -0
  330. package/dist/devices/devices.module.js +34 -0
  331. package/dist/devices/devices.schemas.d.ts +11 -0
  332. package/dist/devices/devices.schemas.js +22 -0
  333. package/dist/devices/devices.service.d.ts +421 -0
  334. package/dist/devices/devices.service.js +1080 -0
  335. package/dist/devices/dto.d.ts +55 -0
  336. package/dist/devices/dto.js +59 -0
  337. package/dist/devices/label.d.ts +11 -0
  338. package/dist/devices/label.js +25 -0
  339. package/dist/devices/legacy-cleanup.job.d.ts +34 -0
  340. package/dist/devices/legacy-cleanup.job.js +141 -0
  341. package/dist/devices/public-suffix.d.ts +6 -0
  342. package/dist/devices/public-suffix.js +79 -0
  343. package/dist/errors.d.ts +286 -8
  344. package/dist/errors.js +286 -8
  345. package/dist/evals/evals.module.js +16 -3
  346. package/dist/evals/evals.schemas.d.ts +110 -0
  347. package/dist/evals/evals.schemas.js +107 -0
  348. package/dist/evals/jobs.d.ts +14 -6
  349. package/dist/evals/jobs.js +21 -19
  350. package/dist/evals/plan.d.ts +20 -15
  351. package/dist/evals/plan.js +29 -6
  352. package/dist/evals/reconstruct.d.ts +52 -23
  353. package/dist/evals/reconstruct.js +147 -43
  354. package/dist/evals/recorded-tools.d.ts +11 -1
  355. package/dist/evals/recorded-tools.js +39 -3
  356. package/dist/evals/run-replay.d.ts +28 -5
  357. package/dist/evals/run-replay.js +101 -18
  358. package/dist/evals/runs.controller.d.ts +2 -57
  359. package/dist/evals/runs.controller.js +1 -42
  360. package/dist/evals/runs.service.d.ts +13 -13
  361. package/dist/evals/runs.service.js +55 -62
  362. package/dist/evals/sets.controller.d.ts +2 -28
  363. package/dist/evals/sets.controller.js +1 -31
  364. package/dist/evals/sets.service.d.ts +10 -9
  365. package/dist/evals/sets.service.js +39 -19
  366. package/dist/evals/snapshot.d.ts +10 -3
  367. package/dist/evals/snapshot.js +19 -5
  368. package/dist/evals/step-replay.d.ts +10 -6
  369. package/dist/evals/step-replay.js +21 -9
  370. package/dist/evals/trajectory.d.ts +19 -3
  371. package/dist/evals/trajectory.js +14 -1
  372. package/dist/evals/trajectory.service.d.ts +8 -3
  373. package/dist/evals/trajectory.service.js +26 -14
  374. package/dist/evals/worker.d.ts +5 -5
  375. package/dist/evals/worker.js +11 -4
  376. package/dist/extensions/admin-ops.d.ts +81 -14
  377. package/dist/extensions/admin-ops.js +181 -47
  378. package/dist/extensions/admin-view.d.ts +57 -10
  379. package/dist/extensions/admin-view.js +249 -27
  380. package/dist/extensions/approvals.d.ts +12 -2
  381. package/dist/extensions/blobs.d.ts +14 -1
  382. package/dist/extensions/blobs.js +49 -5
  383. package/dist/extensions/bootstrap.d.ts +86 -11
  384. package/dist/extensions/bootstrap.js +222 -37
  385. package/dist/extensions/cli.d.ts +12 -0
  386. package/dist/extensions/cli.js +11 -2
  387. package/dist/extensions/config-hash.d.ts +10 -0
  388. package/dist/extensions/config-hash.js +38 -0
  389. package/dist/extensions/config-issues.d.ts +13 -1
  390. package/dist/extensions/config-issues.js +22 -5
  391. package/dist/extensions/config-json-schema.d.ts +43 -7
  392. package/dist/extensions/config-json-schema.js +124 -58
  393. package/dist/extensions/deployment-config-store.d.ts +6 -0
  394. package/dist/extensions/deployment-config.d.ts +94 -9
  395. package/dist/extensions/deployment-config.js +255 -34
  396. package/dist/extensions/display-name.d.ts +22 -0
  397. package/dist/extensions/display-name.js +77 -0
  398. package/dist/extensions/effective-config.d.ts +133 -0
  399. package/dist/extensions/effective-config.js +379 -0
  400. package/dist/extensions/extensions.module.js +34 -12
  401. package/dist/extensions/guide-places.d.ts +68 -0
  402. package/dist/extensions/guide-places.js +152 -0
  403. package/dist/extensions/hooks.d.ts +59 -7
  404. package/dist/extensions/hooks.js +97 -17
  405. package/dist/extensions/host.d.ts +105 -12
  406. package/dist/extensions/host.js +372 -87
  407. package/dist/extensions/installs.d.ts +30 -9
  408. package/dist/extensions/installs.js +61 -17
  409. package/dist/extensions/instance.d.ts +17 -2
  410. package/dist/extensions/instance.js +21 -0
  411. package/dist/extensions/ledger.d.ts +1 -1
  412. package/dist/extensions/lifecycle-hooks.d.ts +99 -0
  413. package/dist/extensions/lifecycle-hooks.js +273 -0
  414. package/dist/extensions/lifecycle.d.ts +6 -1
  415. package/dist/extensions/lifecycle.js +9 -2
  416. package/dist/extensions/locks.d.ts +12 -0
  417. package/dist/extensions/locks.js +26 -0
  418. package/dist/extensions/org-config.d.ts +110 -8
  419. package/dist/extensions/org-config.js +234 -47
  420. package/dist/extensions/org-levels.d.ts +37 -0
  421. package/dist/extensions/org-levels.js +71 -0
  422. package/dist/extensions/org-overrides.d.ts +151 -0
  423. package/dist/extensions/org-overrides.js +524 -0
  424. package/dist/extensions/package.d.ts +18 -4
  425. package/dist/extensions/package.js +57 -4
  426. package/dist/extensions/permission-set.d.ts +35 -5
  427. package/dist/extensions/permission-set.js +36 -5
  428. package/dist/extensions/permission-view.d.ts +112 -15
  429. package/dist/extensions/permission-view.js +40 -17
  430. package/dist/extensions/plugin-guides.d.ts +282 -0
  431. package/dist/extensions/plugin-guides.js +554 -0
  432. package/dist/extensions/plugin-icons.d.ts +54 -0
  433. package/dist/extensions/plugin-icons.js +125 -0
  434. package/dist/extensions/plugin-items.d.ts +21 -0
  435. package/dist/extensions/plugin-items.js +42 -0
  436. package/dist/extensions/point-defaults.controller.d.ts +28 -0
  437. package/dist/extensions/point-defaults.controller.js +69 -0
  438. package/dist/extensions/point-defaults.d.ts +100 -0
  439. package/dist/extensions/point-defaults.js +267 -0
  440. package/dist/extensions/point-defaults.schemas.d.ts +9 -0
  441. package/dist/extensions/point-defaults.schemas.js +14 -0
  442. package/dist/extensions/registry.d.ts +1 -1
  443. package/dist/extensions/registry.js +2 -0
  444. package/dist/extensions/resolve.d.ts +51 -1
  445. package/dist/extensions/resolve.js +85 -3
  446. package/dist/extensions/single-provider.d.ts +92 -0
  447. package/dist/extensions/single-provider.js +180 -0
  448. package/dist/extensions/sources.d.ts +13 -2
  449. package/dist/extensions/sources.js +2 -0
  450. package/dist/extensions/state.module.d.ts +9 -0
  451. package/dist/extensions/state.module.js +46 -0
  452. package/dist/extensions/unavailable.d.ts +50 -0
  453. package/dist/extensions/unavailable.js +115 -0
  454. package/dist/extensions/usage-subscribers.d.ts +43 -0
  455. package/dist/extensions/usage-subscribers.js +108 -0
  456. package/dist/files/previewers.controller.js +2 -3
  457. package/dist/files/previewers.d.ts +10 -3
  458. package/dist/files/previewers.js +40 -11
  459. package/dist/files/previewers.schemas.d.ts +10 -0
  460. package/dist/files/previewers.schemas.js +9 -0
  461. package/dist/git/gateway.d.ts +93 -0
  462. package/dist/git/gateway.js +750 -0
  463. package/dist/git/gateway.route.d.ts +16 -0
  464. package/dist/git/gateway.route.js +41 -0
  465. package/dist/git/git.module.d.ts +10 -0
  466. package/dist/git/git.module.js +31 -0
  467. package/dist/git/identity.d.ts +80 -0
  468. package/dist/git/identity.js +209 -0
  469. package/dist/git/pkt-line.d.ts +53 -0
  470. package/dist/git/pkt-line.js +146 -0
  471. package/dist/git/run-end.d.ts +29 -0
  472. package/dist/git/run-end.js +121 -0
  473. package/dist/git/sources.d.ts +42 -0
  474. package/dist/git/sources.js +134 -0
  475. package/dist/git/tickets.d.ts +69 -0
  476. package/dist/git/tickets.js +194 -0
  477. package/dist/http/api.module.js +86 -4
  478. package/dist/http/app.d.ts +17 -2
  479. package/dist/http/app.js +34 -5
  480. package/dist/http/gateway-routes.d.ts +7 -3
  481. package/dist/http/gateway-routes.js +6 -3
  482. package/dist/http/nest-logger.d.ts +6 -5
  483. package/dist/http/nest-logger.js +24 -10
  484. package/dist/http/plugin-dispatch.d.ts +4 -1
  485. package/dist/http/plugin-dispatch.js +14 -2
  486. package/dist/identity/accounts.d.ts +77 -31
  487. package/dist/identity/accounts.js +133 -52
  488. package/dist/identity/audit.d.ts +2 -1
  489. package/dist/identity/auth.controller.js +9 -5
  490. package/dist/identity/auth.guard.d.ts +13 -5
  491. package/dist/identity/auth.guard.js +35 -9
  492. package/dist/identity/cookies.d.ts +26 -5
  493. package/dist/identity/cookies.js +58 -6
  494. package/dist/identity/identity.module.d.ts +1 -1
  495. package/dist/identity/identity.module.js +7 -4
  496. package/dist/identity/initial-passwords.controller.d.ts +22 -0
  497. package/dist/identity/initial-passwords.controller.js +49 -0
  498. package/dist/identity/initial-passwords.d.ts +61 -0
  499. package/dist/identity/initial-passwords.job.d.ts +16 -0
  500. package/dist/identity/initial-passwords.job.js +46 -0
  501. package/dist/identity/initial-passwords.js +159 -0
  502. package/dist/identity/me.controller.d.ts +17 -1
  503. package/dist/identity/me.controller.js +45 -4
  504. package/dist/identity/me.schemas.d.ts +24 -0
  505. package/dist/identity/me.schemas.js +25 -0
  506. package/dist/identity/principal.d.ts +11 -3
  507. package/dist/identity/principal.js +11 -3
  508. package/dist/identity/sessions.d.ts +12 -0
  509. package/dist/identity/sessions.js +45 -0
  510. package/dist/identity/settings.d.ts +216 -12
  511. package/dist/identity/settings.js +420 -29
  512. package/dist/identity/{enterprise-admin.d.ts → super-admin.d.ts} +5 -5
  513. package/dist/identity/{enterprise-admin.js → super-admin.js} +24 -24
  514. package/dist/identity/write-actor.d.ts +11 -0
  515. package/dist/identity/write-actor.js +7 -0
  516. package/dist/inbox/inbox.module.d.ts +4 -1
  517. package/dist/inbox/inbox.module.js +9 -4
  518. package/dist/inbox/inbox.schemas.d.ts +8 -0
  519. package/dist/inbox/inbox.schemas.js +11 -0
  520. package/dist/inbox/inbox.service.d.ts +65 -4
  521. package/dist/inbox/inbox.service.js +82 -4
  522. package/dist/inbox/org-notices.d.ts +63 -0
  523. package/dist/inbox/org-notices.js +91 -0
  524. package/dist/inbox/platform-inbox.controller.d.ts +23 -0
  525. package/dist/inbox/platform-inbox.controller.js +58 -0
  526. package/dist/inbox/platform-inbox.service.d.ts +128 -0
  527. package/dist/inbox/platform-inbox.service.js +232 -0
  528. package/dist/inbox/platform-notices.d.ts +19 -0
  529. package/dist/inbox/platform-notices.js +9 -0
  530. package/dist/index.d.ts +7 -2
  531. package/dist/index.js +8 -1
  532. package/dist/infra/cli/kernel-cli.module.js +14 -1
  533. package/dist/infra/config/kernel-config.service.d.ts +7 -0
  534. package/dist/infra/config/kernel-config.service.js +70 -1
  535. package/dist/infra/database/database.module.js +1 -0
  536. package/dist/infra/database/xact-lock.d.ts +1 -1
  537. package/dist/infra/database/xact-lock.js +1 -1
  538. package/dist/infra/events/kernel-events.d.ts +28 -25
  539. package/dist/infra/lifecycle/process-guards.js +4 -0
  540. package/dist/infra/lock/lock.service.d.ts +8 -0
  541. package/dist/infra/lock/lock.service.js +27 -0
  542. package/dist/infra/logging/logging.module.d.ts +4 -2
  543. package/dist/infra/logging/logging.module.js +24 -6
  544. package/dist/infra/outbox/outbox-relay.module.d.ts +6 -0
  545. package/dist/infra/outbox/outbox-relay.module.js +18 -0
  546. package/dist/infra/outbox/outbox.dispatcher.d.ts +103 -0
  547. package/dist/infra/outbox/outbox.dispatcher.js +310 -0
  548. package/dist/infra/outbox/outbox.module.d.ts +24 -0
  549. package/dist/infra/outbox/outbox.module.js +50 -0
  550. package/dist/infra/outbox/outbox.relay.d.ts +31 -0
  551. package/dist/infra/outbox/outbox.relay.js +76 -0
  552. package/dist/infra/outbox/outbox.service.d.ts +57 -0
  553. package/dist/infra/outbox/outbox.service.js +165 -0
  554. package/dist/infra/outbox/registry.d.ts +296 -0
  555. package/dist/infra/outbox/registry.js +291 -0
  556. package/dist/infra/presence/presence.module.d.ts +6 -0
  557. package/dist/infra/presence/presence.module.js +22 -0
  558. package/dist/infra/presence/replica-presence.d.ts +87 -0
  559. package/dist/infra/presence/replica-presence.js +189 -0
  560. package/dist/infra/queue/queue-names.d.ts +8 -0
  561. package/dist/infra/queue/queue-names.js +17 -0
  562. package/dist/infra/queue/redis-connection.d.ts +6 -0
  563. package/dist/infra/queue/redis-connection.js +7 -0
  564. package/dist/infra/redis/redis.module.js +6 -2
  565. package/dist/infra/throttler/named-throttlers.d.ts +12 -0
  566. package/dist/infra/throttler/named-throttlers.js +67 -0
  567. package/dist/infra/throttler/throttler.guard.js +1 -1
  568. package/dist/infra/tokens.d.ts +6 -1
  569. package/dist/infra/tokens.js +6 -1
  570. package/dist/kernel.module.js +18 -0
  571. package/dist/lifecycle/kernel-lifecycle.d.ts +9 -3
  572. package/dist/lifecycle/kernel-lifecycle.js +46 -11
  573. package/dist/local-devices/device-auth.controller.d.ts +42 -0
  574. package/dist/local-devices/device-auth.controller.js +116 -0
  575. package/dist/local-devices/device-auth.d.ts +124 -0
  576. package/dist/local-devices/device-auth.js +410 -0
  577. package/dist/local-devices/device-auth.module.d.ts +7 -0
  578. package/dist/local-devices/device-auth.module.js +25 -0
  579. package/dist/local-devices/device-policy.service.d.ts +174 -0
  580. package/dist/local-devices/device-policy.service.js +470 -0
  581. package/dist/local-devices/device-routes.d.ts +36 -0
  582. package/dist/local-devices/device-routes.js +90 -0
  583. package/dist/local-devices/dto.d.ts +66 -0
  584. package/dist/local-devices/dto.js +44 -0
  585. package/dist/local-devices/keys.d.ts +25 -0
  586. package/dist/local-devices/keys.js +25 -0
  587. package/dist/local-devices/local-device-gateway.d.ts +136 -0
  588. package/dist/local-devices/local-device-gateway.js +570 -0
  589. package/dist/local-devices/local-device-provider.d.ts +116 -0
  590. package/dist/local-devices/local-device-provider.js +203 -0
  591. package/dist/local-devices/local-devices.module.d.ts +17 -0
  592. package/dist/local-devices/local-devices.module.js +60 -0
  593. package/dist/local-devices/machines.d.ts +163 -0
  594. package/dist/local-devices/machines.js +540 -0
  595. package/dist/local-devices/network-grants.d.ts +88 -0
  596. package/dist/local-devices/network-grants.js +268 -0
  597. package/dist/local-devices/policy-op-jobs.d.ts +15 -0
  598. package/dist/local-devices/policy-op-jobs.js +12 -0
  599. package/dist/local-devices/policy-summary.d.ts +98 -0
  600. package/dist/local-devices/policy-summary.js +151 -0
  601. package/dist/local-devices/relay.d.ts +100 -0
  602. package/dist/local-devices/relay.js +373 -0
  603. package/dist/local-devices/targets.d.ts +28 -0
  604. package/dist/local-devices/targets.js +73 -0
  605. package/dist/log.d.ts +13 -1
  606. package/dist/log.js +93 -17
  607. package/dist/models/embeddings.d.ts +82 -0
  608. package/dist/models/embeddings.js +319 -0
  609. package/dist/models/enablement.controller.d.ts +40 -0
  610. package/dist/models/enablement.controller.js +74 -0
  611. package/dist/models/enablement.d.ts +101 -0
  612. package/dist/models/enablement.js +264 -0
  613. package/dist/models/models.module.d.ts +5 -1
  614. package/dist/models/models.module.js +19 -4
  615. package/dist/models/org-models.schemas.d.ts +8 -0
  616. package/dist/models/org-models.schemas.js +22 -0
  617. package/dist/models/prices.d.ts +8 -6
  618. package/dist/models/prices.js +11 -9
  619. package/dist/models/purposes.controller.d.ts +6 -4
  620. package/dist/models/purposes.controller.js +13 -7
  621. package/dist/models/purposes.d.ts +79 -14
  622. package/dist/models/purposes.js +120 -34
  623. package/dist/net/public-address.d.ts +14 -4
  624. package/dist/net/public-address.js +22 -12
  625. package/dist/net/safe-fetch.d.ts +2 -1
  626. package/dist/net/safe-fetch.js +16 -4
  627. package/dist/orgs/directory-sync.d.ts +14 -5
  628. package/dist/orgs/directory-sync.js +42 -18
  629. package/dist/orgs/members.service.js +1 -1
  630. package/dist/orgs/offboarding.d.ts +54 -57
  631. package/dist/orgs/offboarding.js +161 -185
  632. package/dist/orgs/org-lock.d.ts +5 -0
  633. package/dist/orgs/org-lock.js +13 -0
  634. package/dist/orgs/org.guard.d.ts +10 -0
  635. package/dist/orgs/org.guard.js +43 -32
  636. package/dist/orgs/orgs.controller.d.ts +2 -5
  637. package/dist/orgs/orgs.controller.js +3 -6
  638. package/dist/orgs/orgs.module.js +10 -10
  639. package/dist/orgs/orgs.schemas.d.ts +8 -0
  640. package/dist/orgs/orgs.schemas.js +16 -0
  641. package/dist/orgs/orgs.service.d.ts +29 -8
  642. package/dist/orgs/orgs.service.js +57 -16
  643. package/dist/orgs/roles.d.ts +1 -1
  644. package/dist/orgs/roles.js +11 -1
  645. package/dist/orgs/settings.controller.d.ts +1 -1
  646. package/dist/orgs/settings.controller.js +4 -3
  647. package/dist/orgs/settings.service.d.ts +278 -31
  648. package/dist/orgs/settings.service.js +357 -47
  649. package/dist/overrides.d.ts +49 -4
  650. package/dist/overrides.js +28 -2
  651. package/dist/packages/npm.d.ts +28 -9
  652. package/dist/packages/npm.js +30 -19
  653. package/dist/packages/provenance.d.ts +3 -1
  654. package/dist/packages/provenance.js +7 -3
  655. package/dist/platform/actor.d.ts +48 -0
  656. package/dist/platform/actor.js +100 -0
  657. package/dist/platform/agent-docs.d.ts +18 -0
  658. package/dist/platform/agent-docs.js +59 -0
  659. package/dist/platform/availability.d.ts +14 -0
  660. package/dist/platform/availability.js +43 -0
  661. package/dist/platform/errors.d.ts +28 -0
  662. package/dist/platform/errors.js +65 -0
  663. package/dist/platform/exclusions.d.ts +11 -0
  664. package/dist/platform/exclusions.js +792 -0
  665. package/dist/platform/method.d.ts +6 -0
  666. package/dist/platform/method.js +15 -0
  667. package/dist/platform/operation.d.ts +169 -0
  668. package/dist/platform/operation.js +106 -0
  669. package/dist/platform/ops/accounts.ops.d.ts +32 -0
  670. package/dist/platform/ops/accounts.ops.js +291 -0
  671. package/dist/platform/ops/admin-items.ops.d.ts +37 -0
  672. package/dist/platform/ops/admin-items.ops.js +278 -0
  673. package/dist/platform/ops/admin.ops.d.ts +38 -0
  674. package/dist/platform/ops/admin.ops.js +546 -0
  675. package/dist/platform/ops/agent-skills.ops.d.ts +50 -0
  676. package/dist/platform/ops/agent-skills.ops.js +509 -0
  677. package/dist/platform/ops/agent-templates.ops.d.ts +17 -0
  678. package/dist/platform/ops/agent-templates.ops.js +272 -0
  679. package/dist/platform/ops/agents.ops.d.ts +37 -0
  680. package/dist/platform/ops/agents.ops.js +726 -0
  681. package/dist/platform/ops/approvals.ops.d.ts +30 -0
  682. package/dist/platform/ops/approvals.ops.js +116 -0
  683. package/dist/platform/ops/background.ops.d.ts +14 -0
  684. package/dist/platform/ops/background.ops.js +134 -0
  685. package/dist/platform/ops/catalog-admin.ops.d.ts +94 -0
  686. package/dist/platform/ops/catalog-admin.ops.js +710 -0
  687. package/dist/platform/ops/channels.ops.d.ts +16 -0
  688. package/dist/platform/ops/channels.ops.js +195 -0
  689. package/dist/platform/ops/components.ops.d.ts +46 -0
  690. package/dist/platform/ops/components.ops.js +854 -0
  691. package/dist/platform/ops/connectors.ops.d.ts +17 -0
  692. package/dist/platform/ops/connectors.ops.js +190 -0
  693. package/dist/platform/ops/conversations.ops.d.ts +30 -0
  694. package/dist/platform/ops/conversations.ops.js +504 -0
  695. package/dist/platform/ops/devices.ops.d.ts +26 -0
  696. package/dist/platform/ops/devices.ops.js +313 -0
  697. package/dist/platform/ops/errors.d.ts +16 -0
  698. package/dist/platform/ops/errors.js +30 -0
  699. package/dist/platform/ops/evals.ops.d.ts +28 -0
  700. package/dist/platform/ops/evals.ops.js +794 -0
  701. package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
  702. package/dist/platform/ops/extensions-admin.ops.js +372 -0
  703. package/dist/platform/ops/extensions.ops.d.ts +25 -0
  704. package/dist/platform/ops/extensions.ops.js +347 -0
  705. package/dist/platform/ops/inbox.ops.d.ts +25 -0
  706. package/dist/platform/ops/inbox.ops.js +384 -0
  707. package/dist/platform/ops/marketplaces.ops.d.ts +22 -0
  708. package/dist/platform/ops/marketplaces.ops.js +466 -0
  709. package/dist/platform/ops/models.ops.d.ts +25 -0
  710. package/dist/platform/ops/models.ops.js +232 -0
  711. package/dist/platform/ops/org-plugins.ops.d.ts +35 -0
  712. package/dist/platform/ops/org-plugins.ops.js +388 -0
  713. package/dist/platform/ops/org-settings.ops.d.ts +18 -0
  714. package/dist/platform/ops/org-settings.ops.js +134 -0
  715. package/dist/platform/ops/orgs.ops.d.ts +28 -0
  716. package/dist/platform/ops/orgs.ops.js +301 -0
  717. package/dist/platform/ops/other-orgs.d.ts +20 -0
  718. package/dist/platform/ops/other-orgs.js +72 -0
  719. package/dist/platform/ops/outbox.ops.d.ts +21 -0
  720. package/dist/platform/ops/outbox.ops.js +125 -0
  721. package/dist/platform/ops/paging.d.ts +14 -0
  722. package/dist/platform/ops/paging.js +20 -0
  723. package/dist/platform/ops/platform.ops.d.ts +41 -0
  724. package/dist/platform/ops/platform.ops.js +261 -0
  725. package/dist/platform/ops/plugins.ops.d.ts +35 -0
  726. package/dist/platform/ops/plugins.ops.js +476 -0
  727. package/dist/platform/ops/previewers.ops.d.ts +14 -0
  728. package/dist/platform/ops/previewers.ops.js +109 -0
  729. package/dist/platform/ops/requests.ops.d.ts +14 -0
  730. package/dist/platform/ops/requests.ops.js +192 -0
  731. package/dist/platform/ops/role.d.ts +4 -0
  732. package/dist/platform/ops/role.js +10 -0
  733. package/dist/platform/ops/schedules.ops.d.ts +21 -0
  734. package/dist/platform/ops/schedules.ops.js +509 -0
  735. package/dist/platform/ops/setup.ops.d.ts +24 -0
  736. package/dist/platform/ops/setup.ops.js +212 -0
  737. package/dist/platform/ops/skills.ops.d.ts +17 -0
  738. package/dist/platform/ops/skills.ops.js +160 -0
  739. package/dist/platform/ops/summary.d.ts +10 -0
  740. package/dist/platform/ops/summary.js +18 -0
  741. package/dist/platform/ops/themes.ops.d.ts +14 -0
  742. package/dist/platform/ops/themes.ops.js +47 -0
  743. package/dist/platform/ops/ui.ops.d.ts +8 -0
  744. package/dist/platform/ops/ui.ops.js +41 -0
  745. package/dist/platform/ops/unavailable.d.ts +23 -0
  746. package/dist/platform/ops/unavailable.js +118 -0
  747. package/dist/platform/parity.d.ts +33 -0
  748. package/dist/platform/parity.js +272 -0
  749. package/dist/platform/platform-ops.module.d.ts +45 -0
  750. package/dist/platform/platform-ops.module.js +150 -0
  751. package/dist/platform/platform.module.d.ts +8 -0
  752. package/dist/platform/platform.module.js +25 -0
  753. package/dist/platform/registry.d.ts +30 -0
  754. package/dist/platform/registry.js +111 -0
  755. package/dist/platform/route-schemas.d.ts +18 -0
  756. package/dist/platform/route-schemas.js +91 -0
  757. package/dist/roles/gateway-role.d.ts +18 -3
  758. package/dist/roles/gateway-role.js +33 -5
  759. package/dist/roles/gateway.module.d.ts +2 -1
  760. package/dist/roles/gateway.module.js +6 -3
  761. package/dist/roles/worker-role.d.ts +11 -4
  762. package/dist/roles/worker-role.js +24 -7
  763. package/dist/roles/worker.module.d.ts +1 -1
  764. package/dist/roles/worker.module.js +33 -7
  765. package/dist/runtime/compaction-progress.d.ts +62 -0
  766. package/dist/runtime/compaction-progress.js +82 -0
  767. package/dist/runtime/compaction-settings.service.d.ts +16 -0
  768. package/dist/runtime/compaction-settings.service.js +42 -0
  769. package/dist/runtime/compaction.service.d.ts +50 -0
  770. package/dist/runtime/compaction.service.js +75 -0
  771. package/dist/runtime/context/build.d.ts +28 -8
  772. package/dist/runtime/context/build.js +156 -28
  773. package/dist/runtime/context/claude-tools.d.ts +3 -1
  774. package/dist/runtime/context/claude-tools.js +8 -6
  775. package/dist/runtime/context/compaction.d.ts +109 -12
  776. package/dist/runtime/context/compaction.js +387 -51
  777. package/dist/runtime/context/device-paths.d.ts +82 -0
  778. package/dist/runtime/context/device-paths.js +165 -0
  779. package/dist/runtime/context/fit.d.ts +111 -0
  780. package/dist/runtime/context/fit.js +278 -0
  781. package/dist/runtime/context/plugin-context.d.ts +20 -0
  782. package/dist/runtime/context/plugin-context.js +30 -0
  783. package/dist/runtime/context/reminders.d.ts +2 -0
  784. package/dist/runtime/context/reminders.js +2 -0
  785. package/dist/runtime/context/run-context.d.ts +88 -0
  786. package/dist/runtime/context/run-context.js +296 -0
  787. package/dist/runtime/context/skills.d.ts +14 -1
  788. package/dist/runtime/context/skills.js +45 -7
  789. package/dist/runtime/context/tool-changes.d.ts +27 -0
  790. package/dist/runtime/context/tool-changes.js +60 -0
  791. package/dist/runtime/hook-calls.d.ts +8 -1
  792. package/dist/runtime/hook-calls.js +40 -7
  793. package/dist/runtime/langgraph-loop.d.ts +3 -1
  794. package/dist/runtime/langgraph-loop.js +52 -21
  795. package/dist/runtime/limits.d.ts +15 -0
  796. package/dist/runtime/limits.js +25 -0
  797. package/dist/runtime/loop.d.ts +50 -8
  798. package/dist/runtime/loop.js +2 -1
  799. package/dist/runtime/maintenance.d.ts +19 -5
  800. package/dist/runtime/maintenance.js +102 -10
  801. package/dist/runtime/model-call.d.ts +191 -24
  802. package/dist/runtime/model-call.js +966 -365
  803. package/dist/runtime/plugin-context.service.d.ts +75 -0
  804. package/dist/runtime/plugin-context.service.js +220 -0
  805. package/dist/runtime/providers.d.ts +149 -29
  806. package/dist/runtime/providers.js +332 -63
  807. package/dist/runtime/queue-lost-jobs.d.ts +24 -0
  808. package/dist/runtime/queue-lost-jobs.js +51 -0
  809. package/dist/runtime/run-context.service.d.ts +82 -0
  810. package/dist/runtime/run-context.service.js +270 -0
  811. package/dist/runtime/run-control.d.ts +62 -5
  812. package/dist/runtime/run-control.js +98 -12
  813. package/dist/runtime/run-drafts.d.ts +85 -0
  814. package/dist/runtime/run-drafts.js +230 -0
  815. package/dist/runtime/run-finish.d.ts +49 -12
  816. package/dist/runtime/run-finish.js +125 -14
  817. package/dist/runtime/run-jobs.d.ts +112 -15
  818. package/dist/runtime/run-jobs.js +224 -32
  819. package/dist/runtime/run-orphan-check.job.d.ts +145 -0
  820. package/dist/runtime/run-orphan-check.job.js +344 -0
  821. package/dist/runtime/run-processors.d.ts +16 -9
  822. package/dist/runtime/run-processors.js +1 -1
  823. package/dist/runtime/run-queue.d.ts +134 -49
  824. package/dist/runtime/run-queue.js +519 -228
  825. package/dist/runtime/run-status.d.ts +12 -0
  826. package/dist/runtime/run-status.js +21 -0
  827. package/dist/runtime/run-steps.d.ts +3 -2
  828. package/dist/runtime/run-steps.js +15 -11
  829. package/dist/runtime/run-worker.d.ts +63 -22
  830. package/dist/runtime/run-worker.js +406 -117
  831. package/dist/runtime/runtime.module.d.ts +2 -3
  832. package/dist/runtime/runtime.module.js +36 -9
  833. package/dist/runtime/step-log.d.ts +31 -7
  834. package/dist/runtime/step-log.js +49 -11
  835. package/dist/runtime/stream.controller.d.ts +24 -4
  836. package/dist/runtime/stream.controller.js +60 -9
  837. package/dist/runtime/stream.d.ts +4 -1
  838. package/dist/runtime/stream.js +42 -3
  839. package/dist/runtime/subagents/child.d.ts +55 -7
  840. package/dist/runtime/subagents/child.js +106 -8
  841. package/dist/runtime/subagents/definition.d.ts +54 -25
  842. package/dist/runtime/subagents/definition.js +164 -212
  843. package/dist/runtime/subagents/deliveries.d.ts +74 -0
  844. package/dist/runtime/subagents/deliveries.js +237 -0
  845. package/dist/runtime/subagents/dispatch.d.ts +121 -32
  846. package/dist/runtime/subagents/dispatch.js +221 -173
  847. package/dist/runtime/subagents/limits.d.ts +24 -5
  848. package/dist/runtime/subagents/limits.js +40 -6
  849. package/dist/runtime/subagents/messages.d.ts +99 -0
  850. package/dist/runtime/subagents/messages.js +336 -0
  851. package/dist/runtime/subagents/preamble.d.ts +5 -4
  852. package/dist/runtime/subagents/preamble.js +10 -7
  853. package/dist/runtime/subagents/progress.d.ts +8 -6
  854. package/dist/runtime/subagents/progress.js +11 -6
  855. package/dist/runtime/subagents/render.d.ts +30 -0
  856. package/dist/runtime/subagents/render.js +53 -0
  857. package/dist/runtime/subagents/roster.d.ts +24 -7
  858. package/dist/runtime/subagents/roster.js +47 -11
  859. package/dist/runtime/subagents/skill-fork.d.ts +6 -5
  860. package/dist/runtime/subagents/skill-fork.js +16 -9
  861. package/dist/runtime/subagents/status.d.ts +14 -0
  862. package/dist/runtime/subagents/status.js +23 -0
  863. package/dist/runtime/subagents/subagents.service.d.ts +7 -4
  864. package/dist/runtime/subagents/subagents.service.js +12 -7
  865. package/dist/runtime/subagents/tree-jobs.d.ts +61 -0
  866. package/dist/runtime/subagents/tree-jobs.js +86 -0
  867. package/dist/runtime/usage-report-jobs.d.ts +63 -0
  868. package/dist/runtime/usage-report-jobs.js +106 -0
  869. package/dist/runtime/usage-report.d.ts +48 -98
  870. package/dist/runtime/usage-report.js +142 -243
  871. package/dist/runtime/waits.d.ts +134 -165
  872. package/dist/runtime/waits.js +352 -706
  873. package/dist/sandbox/jobs.d.ts +50 -13
  874. package/dist/sandbox/jobs.js +64 -21
  875. package/dist/sandbox/leases.d.ts +37 -54
  876. package/dist/sandbox/leases.js +71 -115
  877. package/dist/sandbox/modes.d.ts +108 -0
  878. package/dist/sandbox/modes.js +126 -0
  879. package/dist/sandbox/platform-auto-mode.d.ts +63 -0
  880. package/dist/sandbox/platform-auto-mode.js +63 -0
  881. package/dist/sandbox/providers.d.ts +34 -7
  882. package/dist/sandbox/providers.js +54 -9
  883. package/dist/sandbox/review/classifier.d.ts +135 -0
  884. package/dist/sandbox/review/classifier.js +419 -0
  885. package/dist/sandbox/review/index.d.ts +13 -0
  886. package/dist/sandbox/review/index.js +10 -0
  887. package/dist/sandbox/review/review.service.d.ts +133 -0
  888. package/dist/sandbox/review/review.service.js +370 -0
  889. package/dist/sandbox/review/rules.d.ts +85 -0
  890. package/dist/sandbox/review/rules.js +5196 -0
  891. package/dist/sandbox/review/types.d.ts +102 -0
  892. package/dist/sandbox/review/types.js +48 -0
  893. package/dist/sandbox/sandbox-file-reader.d.ts +35 -0
  894. package/dist/sandbox/sandbox-file-reader.js +98 -0
  895. package/dist/sandbox/sandbox.module.d.ts +3 -2
  896. package/dist/sandbox/sandbox.module.js +21 -5
  897. package/dist/sandbox/sandbox.service.d.ts +464 -133
  898. package/dist/sandbox/sandbox.service.js +1255 -407
  899. package/dist/sandbox/unreachable.d.ts +30 -0
  900. package/dist/sandbox/unreachable.js +108 -0
  901. package/dist/schedules/calendar.d.ts +134 -0
  902. package/dist/schedules/calendar.js +410 -0
  903. package/dist/schedules/effective-settings.d.ts +16 -0
  904. package/dist/schedules/effective-settings.js +17 -0
  905. package/dist/schedules/errors.d.ts +8 -0
  906. package/dist/schedules/errors.js +8 -0
  907. package/dist/schedules/fire.d.ts +137 -0
  908. package/dist/schedules/fire.js +697 -0
  909. package/dist/schedules/grant-rules.d.ts +118 -0
  910. package/dist/schedules/grant-rules.js +184 -0
  911. package/dist/schedules/job-ids.d.ts +81 -0
  912. package/dist/schedules/job-ids.js +95 -0
  913. package/dist/schedules/pause.d.ts +9 -0
  914. package/dist/schedules/pause.js +33 -0
  915. package/dist/schedules/run-tracker.d.ts +76 -0
  916. package/dist/schedules/run-tracker.js +321 -0
  917. package/dist/schedules/scan.job.d.ts +45 -0
  918. package/dist/schedules/scan.job.js +189 -0
  919. package/dist/schedules/schedule-math.d.ts +73 -0
  920. package/dist/schedules/schedule-math.js +275 -0
  921. package/dist/schedules/scheduled-tasks.service.d.ts +362 -0
  922. package/dist/schedules/scheduled-tasks.service.js +1246 -0
  923. package/dist/schedules/schedules.controller.d.ts +72 -0
  924. package/dist/schedules/schedules.controller.js +256 -0
  925. package/dist/schedules/schedules.module.d.ts +16 -0
  926. package/dist/schedules/schedules.module.js +61 -0
  927. package/dist/schedules/schedules.schemas.d.ts +351 -0
  928. package/dist/schedules/schedules.schemas.js +213 -0
  929. package/dist/schedules/store.d.ts +86 -0
  930. package/dist/schedules/store.js +410 -0
  931. package/dist/schedules/store.module.d.ts +6 -0
  932. package/dist/schedules/store.module.js +21 -0
  933. package/dist/schedules/types.d.ts +110 -0
  934. package/dist/schedules/types.js +1 -0
  935. package/dist/schedules/unattended.d.ts +87 -0
  936. package/dist/schedules/unattended.js +184 -0
  937. package/dist/setup/kernel-checks.d.ts +91 -0
  938. package/dist/setup/kernel-checks.js +296 -0
  939. package/dist/setup/oauth-token-probe.d.ts +40 -0
  940. package/dist/setup/oauth-token-probe.js +96 -0
  941. package/dist/setup/redact-check.d.ts +18 -0
  942. package/dist/setup/redact-check.js +46 -0
  943. package/dist/setup/setup-check-registry.d.ts +86 -0
  944. package/dist/setup/setup-check-registry.js +75 -0
  945. package/dist/setup/setup-checks.controller.d.ts +28 -0
  946. package/dist/setup/setup-checks.controller.js +78 -0
  947. package/dist/setup/setup-checks.schemas.d.ts +38 -0
  948. package/dist/setup/setup-checks.schemas.js +43 -0
  949. package/dist/setup/setup-checks.service.d.ts +144 -0
  950. package/dist/setup/setup-checks.service.js +683 -0
  951. package/dist/setup/setup-guides.controller.d.ts +18 -0
  952. package/dist/setup/setup-guides.controller.js +48 -0
  953. package/dist/setup/setup-guides.schemas.d.ts +10 -0
  954. package/dist/setup/setup-guides.schemas.js +6 -0
  955. package/dist/setup/setup-guides.service.d.ts +126 -0
  956. package/dist/setup/setup-guides.service.js +315 -0
  957. package/dist/setup/setup.module.d.ts +8 -0
  958. package/dist/setup/setup.module.js +31 -0
  959. package/dist/skills/agent-skills.controller.d.ts +48 -0
  960. package/dist/skills/agent-skills.controller.js +131 -0
  961. package/dist/skills/agent-skills.service.d.ts +258 -0
  962. package/dist/skills/agent-skills.service.js +961 -0
  963. package/dist/skills/catalog.d.ts +80 -70
  964. package/dist/skills/catalog.js +136 -241
  965. package/dist/skills/changes.controller.d.ts +12 -22
  966. package/dist/skills/changes.controller.js +27 -56
  967. package/dist/skills/changes.service.d.ts +69 -115
  968. package/dist/skills/changes.service.js +249 -599
  969. package/dist/skills/conversation-catalog.d.ts +53 -0
  970. package/dist/skills/conversation-catalog.js +142 -0
  971. package/dist/skills/invocable.controller.d.ts +1 -1
  972. package/dist/skills/invocable.controller.js +2 -2
  973. package/dist/skills/invocation-keys.d.ts +1 -1
  974. package/dist/skills/invocation-keys.js +1 -1
  975. package/dist/skills/invoke.d.ts +4 -4
  976. package/dist/skills/invoke.js +16 -4
  977. package/dist/skills/package.d.ts +15 -1
  978. package/dist/skills/package.js +14 -1
  979. package/dist/skills/skills.controller.d.ts +35 -7
  980. package/dist/skills/skills.controller.js +64 -11
  981. package/dist/skills/skills.module.js +25 -3
  982. package/dist/skills/skills.schemas.d.ts +44 -0
  983. package/dist/skills/skills.schemas.js +68 -0
  984. package/dist/skills/skills.service.d.ts +158 -60
  985. package/dist/skills/skills.service.js +640 -162
  986. package/dist/skills/usable.d.ts +131 -0
  987. package/dist/skills/usable.js +522 -0
  988. package/dist/themes/render-css.d.ts +13 -0
  989. package/dist/themes/render-css.js +135 -0
  990. package/dist/themes/theme-delivery.service.d.ts +36 -0
  991. package/dist/themes/theme-delivery.service.js +116 -0
  992. package/dist/themes/theme-state.d.ts +116 -0
  993. package/dist/themes/theme-state.js +221 -0
  994. package/dist/themes/theme-usage.d.ts +61 -0
  995. package/dist/themes/theme-usage.js +98 -0
  996. package/dist/themes/themes-public.controller.d.ts +33 -0
  997. package/dist/themes/themes-public.controller.js +98 -0
  998. package/dist/themes/themes.controller.d.ts +13 -0
  999. package/dist/themes/themes.controller.js +38 -0
  1000. package/dist/themes/themes.module.d.ts +3 -0
  1001. package/dist/themes/themes.module.js +21 -0
  1002. package/dist/themes/themes.schemas.d.ts +3 -0
  1003. package/dist/themes/themes.schemas.js +2 -0
  1004. package/dist/themes/themes.service.d.ts +50 -0
  1005. package/dist/themes/themes.service.js +99 -0
  1006. package/dist/time-zone.d.ts +5 -0
  1007. package/dist/time-zone.js +19 -0
  1008. package/dist/tools/admin-connectors.d.ts +69 -0
  1009. package/dist/tools/admin-connectors.js +135 -0
  1010. package/dist/tools/approvals.controller.d.ts +4 -2
  1011. package/dist/tools/approvals.controller.js +19 -5
  1012. package/dist/tools/approvals.schemas.d.ts +22 -0
  1013. package/dist/tools/approvals.schemas.js +17 -0
  1014. package/dist/tools/approvals.service.d.ts +479 -19
  1015. package/dist/tools/approvals.service.js +1472 -34
  1016. package/dist/tools/builtin-names.d.ts +78 -22
  1017. package/dist/tools/builtin-names.js +130 -28
  1018. package/dist/tools/builtins/agent.d.ts +23 -21
  1019. package/dist/tools/builtins/agent.js +62 -55
  1020. package/dist/tools/builtins/ask-user.js +3 -2
  1021. package/dist/tools/builtins/builtin-tools.d.ts +29 -3
  1022. package/dist/tools/builtins/builtin-tools.js +102 -11
  1023. package/dist/tools/builtins/current-time.d.ts +26 -0
  1024. package/dist/tools/builtins/current-time.js +99 -0
  1025. package/dist/tools/builtins/handback.d.ts +28 -0
  1026. package/dist/tools/builtins/handback.js +53 -0
  1027. package/dist/tools/builtins/platform.d.ts +51 -0
  1028. package/dist/tools/builtins/platform.js +451 -0
  1029. package/dist/tools/builtins/sandbox/bash.d.ts +3 -3
  1030. package/dist/tools/builtins/sandbox/bash.js +290 -18
  1031. package/dist/tools/builtins/sandbox/common.d.ts +162 -37
  1032. package/dist/tools/builtins/sandbox/common.js +273 -63
  1033. package/dist/tools/builtins/sandbox/deliver.js +9 -6
  1034. package/dist/tools/builtins/sandbox/device-code.d.ts +40 -0
  1035. package/dist/tools/builtins/sandbox/device-code.js +57 -0
  1036. package/dist/tools/builtins/sandbox/edit.js +48 -39
  1037. package/dist/tools/builtins/sandbox/file-state.d.ts +31 -1
  1038. package/dist/tools/builtins/sandbox/file-state.js +33 -3
  1039. package/dist/tools/builtins/sandbox/glob.js +16 -9
  1040. package/dist/tools/builtins/sandbox/grep.js +12 -9
  1041. package/dist/tools/builtins/sandbox/index.d.ts +9 -4
  1042. package/dist/tools/builtins/sandbox/index.js +15 -4
  1043. package/dist/tools/builtins/sandbox/read.js +12 -7
  1044. package/dist/tools/builtins/sandbox/task-list.d.ts +12 -0
  1045. package/dist/tools/builtins/sandbox/task-list.js +130 -0
  1046. package/dist/tools/builtins/sandbox/task-output.d.ts +110 -0
  1047. package/dist/tools/builtins/sandbox/task-output.js +401 -0
  1048. package/dist/tools/builtins/sandbox/task-stop.d.ts +10 -0
  1049. package/dist/tools/builtins/sandbox/task-stop.js +113 -0
  1050. package/dist/tools/builtins/sandbox/write.js +41 -33
  1051. package/dist/tools/builtins/schedules.d.ts +109 -0
  1052. package/dist/tools/builtins/schedules.js +947 -0
  1053. package/dist/tools/builtins/send-message.d.ts +56 -0
  1054. package/dist/tools/builtins/send-message.js +100 -0
  1055. package/dist/tools/builtins/skill-load.d.ts +27 -16
  1056. package/dist/tools/builtins/skill-load.js +97 -61
  1057. package/dist/tools/builtins/tool-search.js +4 -3
  1058. package/dist/tools/builtins/web/errors.d.ts +8 -0
  1059. package/dist/tools/builtins/web/errors.js +53 -0
  1060. package/dist/tools/builtins/web/extract.d.ts +60 -0
  1061. package/dist/tools/builtins/web/extract.js +268 -0
  1062. package/dist/tools/builtins/web/fetch.d.ts +55 -0
  1063. package/dist/tools/builtins/web/fetch.js +175 -0
  1064. package/dist/tools/builtins/web/index.d.ts +13 -0
  1065. package/dist/tools/builtins/web/index.js +12 -0
  1066. package/dist/tools/builtins/web/page-cache.d.ts +25 -0
  1067. package/dist/tools/builtins/web/page-cache.js +77 -0
  1068. package/dist/tools/builtins/web/search.d.ts +25 -0
  1069. package/dist/tools/builtins/web/search.js +210 -0
  1070. package/dist/tools/builtins/web/url.d.ts +17 -0
  1071. package/dist/tools/builtins/web/url.js +43 -0
  1072. package/dist/tools/connector-account-policies.d.ts +59 -0
  1073. package/dist/tools/connector-account-policies.js +173 -0
  1074. package/dist/tools/connectors.controller.d.ts +76 -9
  1075. package/dist/tools/connectors.controller.js +138 -17
  1076. package/dist/tools/connectors.schemas.d.ts +27 -0
  1077. package/dist/tools/connectors.schemas.js +34 -0
  1078. package/dist/tools/connectors.service.d.ts +147 -11
  1079. package/dist/tools/connectors.service.js +357 -30
  1080. package/dist/tools/credentials.d.ts +41 -0
  1081. package/dist/tools/credentials.js +150 -1
  1082. package/dist/tools/credentials.module.d.ts +7 -0
  1083. package/dist/tools/credentials.module.js +22 -0
  1084. package/dist/tools/device-op-resolver.d.ts +40 -0
  1085. package/dist/tools/device-op-resolver.js +121 -0
  1086. package/dist/tools/elicitation.d.ts +2 -0
  1087. package/dist/tools/elicitation.js +1 -1
  1088. package/dist/tools/extension-tools.controller.d.ts +14 -0
  1089. package/dist/tools/extension-tools.controller.js +37 -0
  1090. package/dist/tools/fixed-ask.d.ts +7 -0
  1091. package/dist/tools/fixed-ask.js +9 -0
  1092. package/dist/tools/git-asks.d.ts +113 -0
  1093. package/dist/tools/git-asks.js +174 -0
  1094. package/dist/tools/git-push-policy.d.ts +89 -0
  1095. package/dist/tools/git-push-policy.js +175 -0
  1096. package/dist/tools/info.d.ts +45 -4
  1097. package/dist/tools/info.js +67 -4
  1098. package/dist/tools/legacy-keys.js +0 -1
  1099. package/dist/tools/network-asks.d.ts +115 -0
  1100. package/dist/tools/network-asks.js +223 -0
  1101. package/dist/tools/oauth/discovery.d.ts +38 -16
  1102. package/dist/tools/oauth/discovery.js +59 -33
  1103. package/dist/tools/oauth/flow-paths.d.ts +1 -1
  1104. package/dist/tools/oauth/flow-paths.js +1 -1
  1105. package/dist/tools/oauth/flow.js +1 -1
  1106. package/dist/tools/oauth/tokens.d.ts +54 -7
  1107. package/dist/tools/oauth/tokens.js +87 -17
  1108. package/dist/tools/org-tool-switches.d.ts +89 -0
  1109. package/dist/tools/org-tool-switches.js +201 -0
  1110. package/dist/tools/pipeline.d.ts +173 -51
  1111. package/dist/tools/pipeline.js +797 -390
  1112. package/dist/tools/policy.d.ts +46 -13
  1113. package/dist/tools/policy.js +187 -49
  1114. package/dist/tools/questions.service.d.ts +50 -9
  1115. package/dist/tools/questions.service.js +128 -12
  1116. package/dist/tools/registry.d.ts +207 -54
  1117. package/dist/tools/registry.js +312 -212
  1118. package/dist/tools/tools.module.js +51 -5
  1119. package/dist/tools/validate.js +1 -1
  1120. package/dist/ui/admin-ui.controller.d.ts +56 -0
  1121. package/dist/ui/admin-ui.controller.js +192 -0
  1122. package/dist/ui/arrangement.d.ts +65 -0
  1123. package/dist/ui/arrangement.js +171 -0
  1124. package/dist/ui/embed-token.d.ts +2 -2
  1125. package/dist/ui/embed-token.js +30 -5
  1126. package/dist/ui/registry.d.ts +42 -17
  1127. package/dist/ui/registry.js +46 -14
  1128. package/dist/ui/slots.controller.d.ts +11 -0
  1129. package/dist/ui/slots.controller.js +25 -0
  1130. package/dist/ui/ui-stream.d.ts +20 -3
  1131. package/dist/ui/ui-stream.js +25 -7
  1132. package/dist/ui/ui.schemas.d.ts +70 -0
  1133. package/dist/ui/ui.schemas.js +65 -0
  1134. package/dist/ui/views.controller.d.ts +35 -49
  1135. package/dist/ui/views.controller.js +48 -70
  1136. package/dist/ui/views.d.ts +112 -18
  1137. package/dist/ui/views.js +254 -47
  1138. package/package.json +6 -3
  1139. package/src/migrations/0064_account_last_org.sql +7 -0
  1140. package/src/migrations/0065_conversation_archive.sql +8 -0
  1141. package/src/migrations/0066_extension_display_name.sql +4 -0
  1142. package/src/migrations/0067_agent_profiles.sql +20 -0
  1143. package/src/migrations/0068_agent_avatar_uploads.sql +7 -0
  1144. package/src/migrations/0069_attachments_agent_idx.sql +3 -0
  1145. package/src/migrations/0070_background_tasks.sql +37 -0
  1146. package/src/migrations/0071_background_tasks_reserve.sql +6 -0
  1147. package/src/migrations/0072_background_tasks_stopping.sql +5 -0
  1148. package/src/migrations/0073_org_extension_point_defaults.sql +11 -0
  1149. package/src/migrations/0074_subagent_tree.sql +50 -0
  1150. package/src/migrations/0075_plugin_scope.sql +61 -0
  1151. package/src/migrations/0076_skills_created_by_nullable.sql +6 -0
  1152. package/src/migrations/0077_scope_requests.sql +52 -0
  1153. package/src/migrations/0078_scope_grant_switches.sql +18 -0
  1154. package/src/migrations/0079_scope_live_install_switches.sql +19 -0
  1155. package/src/migrations/0080_rename_enterprise_admin.sql +18 -0
  1156. package/src/migrations/0081_platform_components.sql +129 -0
  1157. package/src/migrations/0082_platform_migration.sql +33 -0
  1158. package/src/migrations/0083_plugin_scope_sync_failures.sql +15 -0
  1159. package/src/migrations/0084_org_owned_items.sql +85 -0
  1160. package/src/migrations/0085_agent_templates_phase4.sql +45 -0
  1161. package/src/migrations/0086_org_layering.sql +30 -0
  1162. package/src/migrations/0087_approval_summary.sql +6 -0
  1163. package/src/migrations/0088_environments.sql +80 -0
  1164. package/src/migrations/0089_model_kinds_usage.sql +38 -0
  1165. package/src/migrations/0090_initial_passwords.sql +27 -0
  1166. package/src/migrations/0091_account_time_zone.sql +4 -0
  1167. package/src/migrations/0092_tools_default_on.sql +27 -0
  1168. package/src/migrations/0093_connected_environments.sql +37 -0
  1169. package/src/migrations/0094_environment_paths_idx.sql +7 -0
  1170. package/src/migrations/0095_environment_files_resets.sql +5 -0
  1171. package/src/migrations/0096_environment_demoted_default.sql +18 -0
  1172. package/src/migrations/0097_extension_installs_enabled_at.sql +16 -0
  1173. package/src/migrations/0098_single_provider_running_first.sql +41 -0
  1174. package/src/migrations/0099_channel_connection_guide_ack.sql +6 -0
  1175. package/src/migrations/0100_catalog_files.sql +13 -0
  1176. package/src/migrations/0101_marketplace_icons.sql +32 -0
  1177. package/src/migrations/0102_themes.sql +64 -0
  1178. package/src/migrations/0103_ui_theme_setting.sql +7 -0
  1179. package/src/migrations/0104_connector_tool_account_policies.sql +16 -0
  1180. package/src/migrations/0105_devices_rename.sql +136 -0
  1181. package/src/migrations/0106_setup_guides_v2.sql +10 -0
  1182. package/src/migrations/0107_extension_client_builds.sql +50 -0
  1183. package/src/migrations/0108_question_skipped.sql +6 -0
  1184. package/src/migrations/0109_audit_platform_idx.sql +5 -0
  1185. package/src/migrations/0110_usage_time_idx.sql +8 -0
  1186. package/src/migrations/0111_agent_skill_sharing.sql +22 -0
  1187. package/src/migrations/0112_skill_share_requests.sql +4 -0
  1188. package/src/migrations/0113_scheduled_tasks.sql +108 -0
  1189. package/src/migrations/0114_network_asks.sql +23 -0
  1190. package/src/migrations/0115_network_requests.sql +28 -0
  1191. package/src/migrations/0116_skills_default_on.sql +37 -0
  1192. package/src/migrations/0117_sandbox_tiers.sql +11 -0
  1193. package/src/migrations/0118_device_policy_ops.sql +6 -0
  1194. package/src/migrations/0119_outbox.sql +22 -0
  1195. package/src/migrations/0120_drop_usage_report_sweep.sql +7 -0
  1196. package/src/migrations/0121_drop_platform_migration_runs.sql +12 -0
  1197. package/src/migrations/0122_drop_scheduled_task_runs_rechecked_at.sql +5 -0
  1198. package/src/migrations/0123_pgvector.sql +27 -0
  1199. package/src/migrations/0124_conversation_source.sql +36 -0
  1200. package/src/migrations/0125_conversation_tree_stopped_at.sql +5 -0
  1201. package/src/migrations/0126_git_gateway.sql +10 -0
  1202. package/src/migrations/0127_git_push_policy.sql +12 -0
  1203. package/src/migrations/0128_scheduled_task_plugin_disabled.sql +10 -0
  1204. package/src/migrations/0129_connector_plugin_disabled.sql +5 -0
  1205. package/src/migrations/0130_auto_mode.sql +48 -0
  1206. package/src/migrations/0131_device_mode.sql +9 -0
  1207. package/src/migrations/0132_compact_runs.sql +6 -0
  1208. package/dist/catalog/upgrade-targets.d.ts +0 -56
  1209. package/dist/catalog/upgrade-targets.js +0 -90
  1210. package/dist/conversations/sandbox-status.d.ts +0 -24
  1211. package/dist/conversations/sandbox-status.js +0 -52
  1212. package/dist/extensions/org-config.controller.d.ts +0 -24
  1213. package/dist/extensions/org-config.controller.js +0 -62
  1214. package/dist/tools/builtins/skill-write.d.ts +0 -59
  1215. package/dist/tools/builtins/skill-write.js +0 -244
@@ -7,37 +7,62 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { createHash, randomUUID } from "node:crypto";
10
+ // The platform plugin update (plugin and component management spec §7, plugin scope phase 2,
11
+ // Task 7): a platform plugin has one version for the deployment, so an update is previewed and
12
+ // confirmed once by the super admin, per component. The per-org upgrade routes are retired (ruling
13
+ // F2).
14
+ import { createHash } from "node:crypto";
15
+ import { SDK_VERSION } from "@capybara-hq/plugin-sdk";
11
16
  import { Inject, Injectable } from "@nestjs/common";
12
17
  import { sql } from "kysely";
13
- import { putTemplateVersionIn } from "../agents/templates.js";
14
18
  import { ApiError } from "../errors.js";
15
- import { isExtensionEnabled } from "../extensions/enabled.js";
16
- import { OrgExtensionConfigs } from "../extensions/org-config.js";
19
+ import { ExtensionAdminOps } from "../extensions/admin-ops.js";
20
+ import { ExtensionBlobs } from "../extensions/blobs.js";
21
+ import { permissionSetOfPackage, readExtensionPackage } from "../extensions/package.js";
22
+ import { blockingKeys, diffPermissions } from "../extensions/permission-set.js";
23
+ import { PluginGuides } from "../extensions/plugin-guides.js";
17
24
  import { ExtensionRegistry } from "../extensions/registry.js";
18
25
  import { audit } from "../identity/audit.js";
26
+ import { SuperAdminLock } from "../identity/super-admin.js";
27
+ import { addOrgNotice, itemDisplayName, notifySharedUpdate } from "../inbox/org-notices.js";
28
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
19
29
  import { KernelDb } from "../infra/database/kernel-db.js";
20
30
  import { TransactionHost } from "../infra/database/transaction-host.js";
21
31
  import { Transactional } from "../infra/database/transactional.decorator.js";
32
+ import { LockService } from "../infra/lock/lock.service.js";
22
33
  import { KERNEL_LOGGER } from "../infra/tokens.js";
23
34
  import { OrgLock } from "../orgs/org-lock.js";
24
35
  import { packagePath } from "../packages/tgz.js";
25
- import { SkillsService, skillConflictError } from "../skills/skills.service.js";
26
36
  import { StorageService } from "../storage/storage.service.js";
37
+ import { assertNotPlatformDefault, pickedByIn, themesPreview, } from "../themes/theme-usage.js";
38
+ import { canonicalJson } from "../tools/canonical-json.js";
27
39
  import { ConnectorsService } from "../tools/connectors.service.js";
28
- import { canonicalJson } from "../tools/registry.js";
29
- import { getPath, lockOrgForActions, orgTemplateView, readCatalogAgentTemplates, readCatalogFiles, readCatalogTemplates, requiredActions, setPath, skillOf, templatePluginProblem, } from "./catalog-content.js";
30
- import { catalogSkillNames, InstallFailure, journalEntries, missingTemplateInput, PluginInstaller, planActions, planSkillConflicts, resolveDependencies, under, } from "./plugin-install.js";
31
- import { assertItemInstallable, CatalogRequestsService } from "./requests.service.js";
32
- import { deployedExtension, deploymentTarget } from "./upgrade-targets.js";
33
- import { satisfiesRange } from "./versions.js";
40
+ import { dirDigest, getPath, readCatalogAgentTemplates, readCatalogTemplates, readCatalogThemes, setPath, skillFilesDigest, templatePluginProblem, themeAssetsDigest, } from "./catalog-content.js";
41
+ import { markVersionApplied, versionUsable } from "./catalog-items.js";
42
+ import { agentsUsing, clashingOrgSkills, clashingPlatformSkills, componentOn, connectorsMadeFrom, connectorTemplatesOn, listedIn, loadComponents, loadScopeState, pluginFactsOf, switchOf, themeIdClashes, } from "./component-state.js";
43
+ import { CatalogItemLock } from "./locks.js";
44
+ import { itemPendingError, itemRemovedError } from "./ownership.js";
45
+ import { PlanStale, PlatformComponents } from "./platform-components.js";
46
+ import { catalogSkillNames, PluginInstaller } from "./plugin-install.js";
47
+ import { PluginScopeSync } from "./scope-sync.js";
48
+ import { compareVersions, satisfiesRange } from "./versions.js";
34
49
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
35
- const installNotFound = () => new ApiError("plugin.install_not_found", "Plugin install not found");
36
- const inProgress = () => new ApiError("plugin.install_in_progress", "This plugin install is being installed, upgraded or uninstalled; try again when it finishes");
37
- const stale = () => new ApiError("plugin.upgrade_stale", "The upgrade preview is out of date (the catalog version or this install's components changed); preview the upgrade again");
38
- const targetInvalid = (message, details) => new ApiError("plugin.upgrade_target_invalid", message, details);
39
- const fail = (path, message) => new ApiError("validation_failed", "Request validation failed", [{ path, message }]);
40
50
  const sha256 = (s) => createHash("sha256").update(s).digest("hex");
51
+ const itemNotFound = () => new ApiError("catalog.item_not_found", "Catalog item not found");
52
+ const stale = () => new ApiError("plugin.upgrade_stale", "The update preview is out of date (the catalog version, the platform components, a pin or a connector changed); preview the update again");
53
+ /** The pending version a super admin confirms was replaced by another upload (P3-11). */
54
+ const pendingStale = (name) => new ApiError("extension.approval_stale", `The pending upload of ${name} changed since it was reviewed; review it again`);
55
+ const targetInvalid = (message, details) => new ApiError("plugin.upgrade_target_invalid", message, details);
56
+ /** A version an org uploaded that was never applied or confirmed, or was rejected (P3-37, P3-52). */
57
+ const notApplied = (name, version) => targetInvalid(`Version ${version} of plugin ${name} was uploaded by an organization and never applied or confirmed (or was rejected); the generic update cannot apply it`, [{ reason: "org_version_not_applied", version }]);
58
+ const KIND_ORDER = {
59
+ skill: 0,
60
+ agent_template: 1,
61
+ connector_template: 2,
62
+ theme: 3,
63
+ };
64
+ /** How long one update holds its item (renewed while it runs). */
65
+ const UPDATE_LOCK_TTL_MS = 60_000;
41
66
  /**
42
67
  * What a credential of `auth` looks like: two auths with the same key take the same stored
43
68
  * credential (static: the type family, ownership and header names; OAuth: any change re-enters).
@@ -58,725 +83,678 @@ function credentialKey(auth) {
58
83
  }
59
84
  }
60
85
  /** The digest of all files of a catalog version. */
61
- const filesDigest = (row) => sha256(row.files
62
- .map((f) => `${f.path}\0${f.sha256}\n`)
63
- .sort()
64
- .join(""));
65
- /** The digest of the files under `dir/` of a catalog version (paths relative to it). */
66
- function dirDigest(row, dir) {
67
- const prefix = `${dir}/`;
68
- return sha256(row.files
69
- .filter((f) => f.path.startsWith(prefix))
70
- .map((f) => `${f.path.slice(prefix.length)}\0${f.sha256}\n`)
71
- .sort()
72
- .join(""));
73
- }
86
+ const filesDigest = (row) => skillFilesDigest(row.files.map((f) => ({ path: f.path, sha256: f.sha256 })));
74
87
  /**
75
- * Org in-place upgrade (and, for declarative plugins, rollback) of an installed plugin (package
76
- * ecosystem spec §10, Decisions 9–11):
77
- * - **preview** diffs the installed and the target version per component (extension, dependency
78
- * plugins, skills by name, connector templates by id) and returns the inputs needed and a
79
- * `diffHash`; the same checks as an install run first (dependencies resolve, extension and
80
- * template connectors deployed, skill conflicts -> `plugin.skill_conflict`), plus the target
81
- * rules (`plugin.upgrade_target_invalid`): an extension-bearing plugin can move only to the
82
- * catalog version carrying the deployment's extension, and installs depending on this plugin must
83
- * still accept the target;
84
- * - **upgrade** re-checks the `diffHash` (`plugin.upgrade_stale`), sets the install `upgrading`
85
- * under the org lock (another upgrade or an uninstall -> `plugin.install_in_progress`), then:
86
- * added dependencies (installed by the install flow), the added extension (enabled), added and
87
- * changed skills (a new version of the same skill; agents keep selecting it by id), added
88
- * connectors (created from the template), and in one final transaction the changed connectors
89
- * (template-owned fields only, `applyTemplateIn`), the removals by the uninstall rules, the new
90
- * version and the audit `plugin.org_upgraded`. Each step is journaled in
91
- * `plugin_installs.upgrade`; on failure the journal is undone (created components removed, skill
92
- * versions reverted; changed connectors were never committed), the install stays `installed` at
93
- * the old version with `error = { step, code }`, audit `plugin.org_upgrade_failed`, 502
94
- * `plugin.upgrade_failed`. An upgrade interrupted for longer than `catalog.staleInstallMinutes`
95
- * is undone by the next preview, upgrade or uninstall.
96
- * Approval follows the item's policy (the org catalog service creates the request). No in-process
97
- * state.
88
+ * The platform plugin update (spec §7; ruling F2 retires the per-org upgrades):
89
+ * - **preview** diffs the platform's current components of the plugin (the version recorded in
90
+ * `catalog_items.platform_synced_version`, components updated on their own included) against a
91
+ * catalog version: each skill (by name, by its files' digest), agent template (by name, canonical
92
+ * definition) and connector template (by id, canonical file) is `added`, `removed`, `same`, or
93
+ * `upgrade` / `downgrade` (the target's direction from the component's catalog version). It marks
94
+ * components updated on their own, components with their own scope and the orgs whose linked
95
+ * copy is pinned; lists removed components agents still use (they stay, spec §7.3), the org
96
+ * connectors made from changed templates (all orgs, ruling E2; `credentialsReset` when the
97
+ * credential shape changed), the templates it turns on that will need an org's input (added, or
98
+ * no longer shipped off) and those it turns off (now shipped off, on only by default), the
99
+ * deployment's extension move, and a `diffHash`. Refused: same version, a disabled or deleted
100
+ * item, a target without the extension the deployment runs for it or moving a config-declared
101
+ * one, a template moving to another connector, a plugin another platform plugin depends on
102
+ * outside its range, and an added skill whose name is taken where the plugin is on (rule 10).
103
+ * - **update** runs under a Redis lock per item (another update -> `plugin.install_in_progress`):
104
+ * the extension first (`ExtensionAdminOps.install`, enabled when the update installs it; added
105
+ * permissions wait for the admin's approval as for any extension upgrade), then one transaction
106
+ * under the item name's lock that recomputes the diff (`plugin.upgrade_stale` on a difference)
107
+ * and writes the platform versions (`PlatformComponents.applySyncIn`, which records
108
+ * `platform_synced_version`), the removals (a component no agent uses is soft-deleted, so
109
+ * unpinned linked copies go with it; pinned copies keep their own version; a removed connector
110
+ * template leaves its connectors as the orgs' own), clears the pins of linked copies, fans
111
+ * changed templates out to every connector made from them (`applyTemplateIn`, under each org's
112
+ * row lock, credentials cleared only for a changed credential shape), moves every org install to the version and audits
113
+ * `plugin.platform_updated`; the scope sync of the item and its dependencies is owed in that
114
+ * transaction (orgs get new dependencies by rule 9). A failure rolls the transaction back and
115
+ * puts the extension back where it was (audit `plugin.platform_update_failed`, 502
116
+ * `plugin.upgrade_failed`); files copied to `deployment/platform/` stay unreferenced.
117
+ * Storage is never read or written inside the transaction: the target's contents (and the
118
+ * extension package, for `needsApproval`) are read and the platform files copied
119
+ * (`PlatformComponents.prepareSync`) after the Redis lock is taken and before the transaction,
120
+ * which reuses them and writes rows only (`applySyncIn`). The confirm-time diff treats the
121
+ * extension this update moved as expected (the install record must point at that package).
122
+ * Recovery: a process that dies between the extension step and the transaction leaves the
123
+ * deployment on the target's extension with the platform components unchanged; a new preview
124
+ * then shows the extension unchanged (`extension: null`) and the components still to move, and
125
+ * confirming it completes the update (or an update back to the old version moves it back).
126
+ * No in-process state.
98
127
  */
99
- let PluginUpgrader = class PluginUpgrader {
100
- installer;
128
+ let PlatformPluginUpdater = class PlatformPluginUpdater {
101
129
  kdb;
130
+ txHost;
131
+ adminLock;
132
+ itemLock;
102
133
  orgLock;
134
+ locks;
103
135
  storage;
104
136
  registry;
105
- skills;
106
- orgConfigs;
107
- requests;
137
+ ops;
138
+ blobs;
139
+ config;
140
+ platform;
141
+ installer;
108
142
  connectors;
143
+ sync;
109
144
  log;
110
- txHost;
111
- constructor(
112
- /** Planning, installs, the ledger and the uninstall rules are the installer's. */
113
- installer, kdb,
114
- /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
115
- orgLock, storage, registry, skills, orgConfigs, requests,
116
- /** Org connectors: installs create, upgrade and remove them. */
117
- connectors, log, txHost) {
118
- this.installer = installer;
145
+ guides;
146
+ constructor(kdb, txHost, adminLock, itemLock, orgLock, locks, storage, registry, ops,
147
+ /** Reads the target's extension package (its permissions, for `needsApproval`). */
148
+ blobs, config, platform,
149
+ /** Template dependencies (the deployed connector kinds). */
150
+ installer, connectors, sync, log,
151
+ /** The connector template guides an update changes (the preview's `guideChanges`). */
152
+ guides) {
119
153
  this.kdb = kdb;
154
+ this.txHost = txHost;
155
+ this.adminLock = adminLock;
156
+ this.itemLock = itemLock;
120
157
  this.orgLock = orgLock;
158
+ this.locks = locks;
121
159
  this.storage = storage;
122
160
  this.registry = registry;
123
- this.skills = skills;
124
- this.orgConfigs = orgConfigs;
125
- this.requests = requests;
161
+ this.ops = ops;
162
+ this.blobs = blobs;
163
+ this.config = config;
164
+ this.platform = platform;
165
+ this.installer = installer;
126
166
  this.connectors = connectors;
167
+ this.sync = sync;
127
168
  this.log = log;
128
- this.txHost = txHost;
169
+ this.guides = guides;
129
170
  }
130
- /** The kernel-schema handle of the current context (the transaction, else the pool). */
131
171
  get db() {
132
172
  return this.kdb.db;
133
173
  }
134
- /** The upgrade preview (see the class comment). */
135
- async preview(orgId, actor, installId, version) {
136
- await this.recoverInterrupted(orgId, actor, installId);
137
- const diff = await this.diff(orgId, actor, installId, version, null);
138
- await this.authorizeActions(orgId, actor, diff.actions);
174
+ /** The update preview (see the class comment); writes nothing. */
175
+ async preview(itemId, version) {
176
+ return this.withGuideChanges(await this.diff(itemId, version));
177
+ }
178
+ /**
179
+ * The update preview of a version staged for import, not imported yet (the platform's import and
180
+ * update, `PlatformImportUpdate`): the same diff as {@link preview}, with the target read from the
181
+ * staging (`target`, whose files are where the import's version row will point), so the
182
+ * `diffHash` is the one {@link updateHeld} recomputes after the import. Writes nothing.
183
+ */
184
+ async previewStaged(itemId, version, target) {
185
+ if (target.version !== version) {
186
+ throw new Error(`internal: previewStaged got the staged target of version ${target.version} for version ${version}`);
187
+ }
188
+ return this.withGuideChanges(await this.diff(itemId, version, { target }));
189
+ }
190
+ /** The preview of a diff with the template guides it changes. */
191
+ async withGuideChanges(d) {
139
192
  return {
140
- from: diff.from.version,
141
- to: diff.to.version,
142
- diffHash: diff.diffHash,
143
- components: diff.components,
144
- inputs: diff.inputs,
145
- templates: diff.templates.flatMap((c) => c.target !== undefined &&
146
- (diff.inputs.connectors.includes(c.id) || diff.inputs.credentialsChanged.includes(c.id))
147
- ? [orgTemplateView(c.id, c.target)]
148
- : []),
193
+ ...previewOf(d),
194
+ guideChanges: await this.guides.templateGuideChanges(d.itemId, d.from, d.to),
149
195
  };
150
196
  }
151
- /** Re-checks the actor's org actions under the org row lock (a transaction of its own). */
152
- async authorizeActions(orgId, actor, actions) {
153
- await lockOrgForActions(this.orgLock, orgId, actor, actions);
154
- }
155
197
  /**
156
- * The checks of {@link upgrade} before an approval request (the org catalog service creates one
157
- * for a needs_approval item without a grant): the diff with the input, the `diffHash`. Returns
158
- * the item and the org actions the upgrade needs.
198
+ * The update preview of a new version of an org's own plugin (ruling P3-12): the item must be
199
+ * owned by `orgId` (else 404, as for any item the org cannot see), the target carries no
200
+ * extension (an extension-bearing version waits for the super admin, plan Task 6), and a target
201
+ * dropping the deployment's extension is allowed (P3-12'). `staged` is the target read from the
202
+ * org's staging (pre-flight F3); without it the imported version `version` is read. The route
203
+ * authorizes the org admin; writes nothing.
159
204
  */
160
- async check(orgId, actor, installId, input) {
161
- await this.recoverInterrupted(orgId, actor, installId);
162
- const diff = await this.diff(orgId, actor, installId, input.version, input);
163
- if (diff.diffHash !== input.diffHash)
164
- throw stale();
165
- return { itemId: diff.itemId, name: diff.name, actions: diff.actions, diff };
205
+ async previewForOwner(orgId, itemId, version, staged) {
206
+ // An internal invariant, not reachable from input: the only caller (OrgPluginUploads) passes
207
+ // the staged target together with its own version (PluginImport.stagedTarget)
208
+ if (staged !== undefined && staged.version !== version) {
209
+ throw new Error(`internal: previewForOwner got the staged target of version ${staged.version} for version ${version}`);
210
+ }
211
+ const preview = await this.withGuideChanges(await this.diff(itemId, version, {
212
+ owner: { orgId },
213
+ ...(staged !== undefined && { target: staged }),
214
+ }));
215
+ // The owner sees the names of the orgs whose default a removed theme is (named like the other
216
+ // orgs the preview mentions, P3-14 / P3-19), but people only of its own org: other orgs'
217
+ // member counts were never disclosed to it. Display only: `diffHash` covers the full preview.
218
+ const themes = preview.themes === undefined
219
+ ? undefined
220
+ : await Promise.all(preview.themes.map(async (t) => ({
221
+ ...t,
222
+ pickedBy: await pickedByIn(this.db, t.id, new Set([orgId])),
223
+ })));
224
+ const owned = { ...preview, ...(themes !== undefined && { themes }) };
225
+ return { ...owned, orgNames: await this.orgNamesOf(owned) };
166
226
  }
167
227
  /**
168
- * Runs an upgrade (see the class comment); returns the install view. `checked` is the diff
169
- * {@link check} computed for the same input (re-verified under the org lock: the install's
170
- * version and ledger must be unchanged), otherwise it is computed here.
228
+ * Locks, in sorted order and before the item (ruling P3-50), every live org the update may
229
+ * write in: the orgs with connectors made from the plugin's connector templates and the item's
230
+ * owner org. `acting`: the owner org an owner update acts for, locked with its admin re-checked
231
+ * (`catalog.upload`; deleted -> 404 `org.not_found`). Returns the live orgs locked; another
232
+ * deleted one is skipped.
171
233
  */
172
- async upgrade(orgId, actor, installId, input, opts = {}, checked) {
173
- let diff;
174
- if (checked !== undefined &&
175
- checked.installId === installId &&
176
- checked.to.version === input.version &&
177
- checked.diffHash === input.diffHash) {
178
- diff = checked;
179
- }
180
- else {
181
- await this.recoverInterrupted(orgId, actor, installId);
182
- diff = await this.diff(orgId, actor, installId, input.version, input);
183
- if (diff.diffHash !== input.diffHash)
184
- throw stale();
185
- }
186
- const { itemId } = diff;
187
- const upgradeId = randomUUID();
188
- // Start: the install `upgrading`, under the org lock (one upgrade or uninstall at a time)
189
- await this.start(orgId, actor, installId, diff, upgradeId);
190
- const done = [];
191
- /** The step whose journal write found the journal gone (cleaned up as interrupted meanwhile). */
192
- let unjournaled;
193
- // Appends a step to the journal in the transaction of the context (the journal gone: the
194
- // upgrade was cleaned up as interrupted)
195
- const journal = async (s) => {
196
- done.push(s);
197
- unjournaled = s;
198
- const r = await this.db
199
- .updateTable("plugin_installs")
200
- .set({
201
- upgrade: sql `jsonb_set(upgrade, '{done}', (upgrade->'done') || ${JSON.stringify([s])}::jsonb)`,
202
- })
203
- .where("id", "=", installId)
204
- .where(sql `upgrade->>'id'`, "=", upgradeId)
205
- .executeTakeFirst();
206
- if (r.numUpdatedRows === 0n)
207
- throw cleanedUp();
208
- unjournaled = undefined;
209
- };
210
- // Records a component in the ledger and the journal, in the transaction of the context
211
- const record = (c) => this.recordIn(installId, journal, c);
212
- let step = "dependencies";
213
- const disabled = [];
214
- try {
215
- for (const dep of diff.dependencies.filter((x) => x.change === "added")) {
216
- const resolved = dep.resolved;
217
- const rec = (c) => record(c);
218
- if ((await this.installer.recordDependency(orgId, resolved, rec)) !== undefined)
219
- continue;
220
- if (!dep.plan) {
221
- throw new ApiError("catalog.dependency_unresolved", `Dependency ${dep.name}@${resolved.range} cannot be resolved: its install in this organization was removed meanwhile; try again`, [{ dependency: dep.name, range: resolved.range }]);
222
- }
223
- let child;
224
- try {
225
- child = await this.installer.execute(orgId, actor, dep.plan, opts, {
226
- actions: requiredActions(dep.plan.manifest),
227
- approvedBy: itemId,
228
- parent: installId,
229
- });
230
- }
231
- catch (e) {
232
- if (e instanceof InstallFailure) {
233
- throw new InstallFailure(e.step, e.cause, [dep.name, ...e.dependency], e.rolledBack);
234
- }
235
- if (e instanceof ApiError &&
236
- e.code === "plugin.already_installed" &&
237
- (await this.installer.recordDependency(orgId, resolved, rec)) !== undefined) {
238
- continue;
239
- }
240
- throw new InstallFailure("dependencies", e, [dep.name], true);
241
- }
242
- await this.installer.recordDependency(orgId, resolved, rec, child);
243
- }
244
- step = "extension";
245
- if (diff.extension?.change === "added") {
246
- await this.installer.enableExtension(orgId, diff.extension.name, {
247
- enabled: true,
248
- ...(input.extensionConfig !== undefined && { config: input.extensionConfig }),
249
- }, actor, opts.actorTokenId, { viaItem: itemId }, record);
250
- }
251
- step = "skills";
252
- for (const s of diff.skills) {
253
- if (s.change !== "added" && s.change !== "changed")
254
- continue;
255
- const files = await readCatalogFiles(this.storage, diff.to.object_prefix, diff.to.files, s.dir);
256
- const r = await this.skills.createVersionFromFiles(orgId, actor, { ...skillOf(files), files }, {
257
- catalog: {
258
- itemId,
259
- version: diff.to.version,
260
- format: diff.to.source_format,
261
- suggestPinned: s.suggestPinned === true,
262
- },
263
- ...opts,
264
- });
265
- await this.journalSkill(r, record, journal);
266
- }
267
- step = "agent_templates";
268
- for (const a of diff.agentTemplates) {
269
- if (a.change !== "added" && a.change !== "changed")
270
- continue;
271
- await this.upgradeAgentTemplate(orgId, diff, a.template, record, journal);
234
+ async lockUpdateOrgs(itemId, acting) {
235
+ const item = await this.db
236
+ .selectFrom("catalog_items")
237
+ .select("owner_org_id")
238
+ .where("id", "=", itemId)
239
+ .executeTakeFirst();
240
+ const made = await this.db
241
+ .selectFrom("connectors as c")
242
+ .innerJoin("platform_connector_templates as t", "t.id", "c.platform_template_id")
243
+ .select("c.org_id")
244
+ .distinct()
245
+ .where("t.catalog_item_id", "=", itemId)
246
+ .where("c.deleted_at", "is", null)
247
+ .execute();
248
+ const ids = new Set(made.map((r) => r.org_id));
249
+ if (item?.owner_org_id)
250
+ ids.add(item.owner_org_id);
251
+ if (acting !== undefined)
252
+ ids.add(acting.orgId);
253
+ const live = new Set();
254
+ for (const orgId of [...ids].sort()) {
255
+ if (orgId === acting?.orgId) {
256
+ await this.orgLock.lockAndAuthorize(orgId, acting.actor, "catalog.upload");
257
+ live.add(orgId);
272
258
  }
273
- step = "connectors";
274
- for (const [templateId, ci] of diff.creates) {
275
- const r = await this.connectors.create(orgId, actor, ci, opts.actorTokenId);
276
- await this.recordStep(installId, journal, {
277
- kind: "connector",
278
- ref: r.connector.id,
279
- created: true,
280
- skillVersion: null,
281
- templateId,
282
- });
259
+ else if (await this.orgLock.tryLock(orgId)) {
260
+ live.add(orgId);
283
261
  }
284
- const prepared = [];
285
- for (const tpl of diff.templates) {
286
- const update = diff.updates.get(tpl.id);
287
- if (!update || !tpl.connector)
288
- continue;
289
- try {
290
- prepared.push({
291
- connectorId: tpl.connector.id,
292
- p: await this.connectors.prepareTemplateUpdate(actor, tpl.connector.connector, update),
293
- });
294
- }
295
- catch (e) {
296
- throw under(e, `connectors.${tpl.id}`);
297
- }
298
- }
299
- // Finish, in one transaction: changed connectors, removals, the version switch
300
- await this.finish(orgId, actor, installId, upgradeId, diff, prepared, disabled, opts, () => {
301
- step = "finish";
302
- });
303
- }
304
- catch (e) {
305
- throw await this.failed(orgId, actor, installId, upgradeId, diff, { done, unjournaled }, step, e, opts);
306
262
  }
307
- for (const p of disabled)
308
- await this.orgConfigs.afterDisable(orgId, p);
309
- const [view] = await this.installer.list(orgId, installId);
310
- if (!view)
311
- throw installNotFound();
312
- return view;
263
+ return live;
264
+ }
265
+ /** The names of the orgs a preview mentions, by id (an owner's preview, see `orgNames`). */
266
+ async orgNamesOf(p) {
267
+ const ids = new Set([
268
+ ...(p.extension?.orgs ?? []),
269
+ ...p.connectorOrgs.map((c) => c.orgId),
270
+ ...p.components.flatMap((c) => [...c.pinnedOrgs, ...(c.kept ?? []).map((k) => k.orgId)]),
271
+ ...(p.themes ?? []).flatMap((t) => t.orgDefaults.map((o) => o.orgId)),
272
+ ]);
273
+ if (ids.size === 0)
274
+ return {};
275
+ const rows = await this.db
276
+ .selectFrom("orgs")
277
+ .select(["id", "name"])
278
+ .where("id", "in", [...ids])
279
+ .where("deleted_at", "is", null)
280
+ .execute();
281
+ return Object.fromEntries(rows.map((r) => [r.id, r.name]));
313
282
  }
314
283
  /**
315
- * Undoes a failed upgrade (its journal, in one transaction): the install back `installed` at the
316
- * old version with `error = { step, code }`, audit `plugin.org_upgrade_failed`. When the journal
317
- * is no longer this upgrade's (another request cleaned it up as interrupted and undid what it
318
- * journaled), only the step whose journal write failed is undone and the install row is left as
319
- * the cleanup set it. Returns the error to throw: 502 `plugin.upgrade_failed` (a dependency
320
- * another install is still installing: its 409 as it is).
284
+ * Applies a new version of an org's own plugin for its owner (ruling P3-12, see
285
+ * {@link previewForOwner}): the actor must be an admin of the owner org (`catalog.upload`,
286
+ * re-checked under the org row lock in the transaction), then the platform update as
287
+ * {@link update} does, also removing the extension when the target drops it. In the update's
288
+ * transaction the orgs using the shared plugin are told (`shared_item_updated`, one notice per
289
+ * plugin) and a pending version is cleared (pre-flight F7: the new version replaces it).
321
290
  */
322
- async failed(orgId, actor, installId, upgradeId, diff, steps, step, e, opts) {
323
- const failure = e instanceof InstallFailure ? e : undefined;
324
- const cause = failure ? failure.cause : e;
325
- const code = cause instanceof ApiError ? cause.code : "internal";
326
- const at = failure ? failure.step : step;
327
- let rolledBack = failure?.rolledBack ?? true;
328
- try {
329
- const removed = await this.undoFailed(orgId, actor, installId, upgradeId, diff, steps, { at, code }, opts);
330
- for (const r of removed) {
331
- if (r.kind === "extension")
332
- await this.orgConfigs.afterDisable(orgId, r.ref);
333
- }
291
+ async updateAsOwner(orgId, actor, itemId, version, diffHash, opts = {}) {
292
+ if (!UUID_RE.test(itemId))
293
+ throw itemNotFound();
294
+ await this.authorizeOwner(orgId, actor);
295
+ return this.locked(itemId, () => this.updateLocked(actor, itemId, { version, diffHash }, opts, { orgId }));
296
+ }
297
+ /** The actor is an admin of the owner org (a read of the membership under the org row lock). */
298
+ async authorizeOwner(orgId, actor) {
299
+ await this.orgLock.lockAndAuthorize(orgId, actor, "catalog.upload");
300
+ }
301
+ /** Runs `f` holding the item's update lock (another update -> `plugin.install_in_progress`). */
302
+ async locked(itemId, f) {
303
+ const handle = await this.locks.acquire(`plugin-update-${itemId}`, {
304
+ ttlMs: UPDATE_LOCK_TTL_MS,
305
+ });
306
+ if (!handle) {
307
+ throw new ApiError("plugin.install_in_progress", "This plugin is being updated; try again when that update finishes");
334
308
  }
335
- catch (u) {
336
- // Left `upgrading` with its journal: undone once it is older than catalog.staleInstallMinutes
337
- rolledBack = false;
338
- this.log.warn("plugin upgrade rollback failed", {
339
- orgId,
340
- installId,
341
- error: u instanceof Error ? u.message : String(u),
342
- });
309
+ try {
310
+ return await f();
343
311
  }
344
- if (cause instanceof ApiError && cause.code === "plugin.install_in_progress" && rolledBack) {
345
- return cause;
312
+ finally {
313
+ await handle.release();
346
314
  }
347
- const dependency = failure && failure.dependency.length > 0 ? failure.dependency : [];
348
- const dep = dependency.length > 0 ? ` in dependency ${dependency.join(" > ")}` : "";
349
- return new ApiError("plugin.upgrade_failed", rolledBack
350
- ? `Upgrading the plugin failed at step ${at}${dep} (${code}); this organization's components are back at version ${diff.from.version}`
351
- : `Upgrading the plugin failed at step ${at}${dep} (${code}) and rolling back failed; it is undone after catalog.staleInstallMinutes`, [
352
- {
353
- step: at,
354
- code,
355
- ...(dependency.length > 0 && { dependency: dependency.join(" > ") }),
356
- ...(cause instanceof ApiError && { message: cause.message }),
357
- ...(cause instanceof ApiError &&
358
- cause.details !== undefined && { causeDetails: cause.details }),
359
- rolledBack,
360
- },
361
- ]);
362
315
  }
363
316
  /**
364
- * An upgrade interrupted for longer than `catalog.staleInstallMinutes` (a replica crashed
365
- * midway): its journal is undone, the install back `installed` at the old version (error step
366
- * `interrupted`), audit `plugin.org_upgrade_failed`. Nothing to do otherwise.
317
+ * The super admin's confirmation of an org upload's pending new version (rulings P3-10, P3-21,
318
+ * pre-flight F8): the update to `version` as {@link update} does it (the super admin's, the
319
+ * extension installed or upgraded on the deployment), with the version allowed although it is
320
+ * pending. Its transaction re-reads the item under the row lock: removed meanwhile -> 409
321
+ * `catalog.item_removed`, the pending version replaced -> 409 `extension.approval_stale` (both
322
+ * undo the extension step); then the pending state is cleared and the owner told
323
+ * (`upload_confirmed`). The caller checked the digest of the version's package.
367
324
  */
368
- async recoverInterrupted(orgId, actor, installId) {
369
- if (!UUID_RE.test(installId))
370
- throw installNotFound();
371
- const removed = await this.undoInterrupted(orgId, actor, installId);
372
- for (const r of removed) {
373
- if (r.kind === "extension")
374
- await this.orgConfigs.afterDisable(orgId, r.ref);
375
- }
325
+ async updateToPending(actor, itemId, version, opts = {}) {
326
+ if (!UUID_RE.test(itemId))
327
+ throw itemNotFound();
328
+ return this.locked(itemId, () => this.updateToPendingLocked(actor, itemId, version, opts));
376
329
  }
377
- /** The upgrade's start: the install `upgrading` with an empty journal (a transaction of its own). */
378
- async start(orgId, actor, installId, diff, upgradeId) {
379
- const { itemId } = diff;
380
- const t = this.db;
381
- await lockOrgForActions(this.orgLock, orgId, actor, diff.actions);
382
- const row = await t
383
- .selectFrom("plugin_installs")
384
- .select(["status", "version"])
385
- .where("id", "=", installId)
386
- .where("org_id", "=", orgId)
387
- .forUpdate()
388
- .executeTakeFirst();
389
- if (!row || row.status === "failed")
390
- throw installNotFound();
391
- if (row.status !== "installed")
392
- throw inProgress();
393
- if (row.version !== diff.from.version ||
394
- ledgerHash(await ledgerOf(t, installId)) !== diff.ledgerHash) {
395
- throw stale();
396
- }
397
- await assertItemInstallable(t, orgId, itemId);
398
- await t
399
- .updateTable("plugin_installs")
400
- .set({
401
- status: "upgrading",
402
- upgrade: sql `jsonb_build_object('id', ${upgradeId}::text, 'from', ${diff.from.version}::text, 'to', ${diff.to.version}::text, 'startedAt', now(), 'done', '[]'::jsonb)`,
403
- })
404
- .where("id", "=", installId)
405
- .execute();
330
+ /**
331
+ * {@link updateToPending} for a caller already holding the item's update lock
332
+ * ({@link withItemLock}): the super admin's confirmation runs all its steps under it (ruling
333
+ * P3-35).
334
+ */
335
+ async updateToPendingLocked(actor, itemId, version, opts = {}) {
336
+ const d = await this.diff(itemId, version, { confirmPending: version });
337
+ return this.updateLocked(actor, itemId, { version, diffHash: d.diffHash }, opts, undefined, version);
406
338
  }
407
- /** A skill step's ledger and journal rows, in a transaction of their own. */
408
- async journalSkill(r, record, journal) {
409
- if (r.created) {
410
- await record({ kind: "skill", ref: r.skill.id, created: true, skillVersion: null });
411
- return;
412
- }
413
- await journal({ op: "skill_version", ref: r.skill.id, version: r.version });
414
- await record({ kind: "skill", ref: r.skill.id, created: false, skillVersion: r.version });
339
+ /**
340
+ * Runs `f` holding the item's update lock (the one every platform update of the item takes;
341
+ * another holder -> 409 `plugin.install_in_progress`): the super admin's confirmation of an org
342
+ * upload runs every step under it (ruling P3-35).
343
+ */
344
+ withItemLock(itemId, f) {
345
+ if (!UUID_RE.test(itemId))
346
+ throw itemNotFound();
347
+ return this.locked(itemId, f);
415
348
  }
416
349
  /**
417
- * An agent template step: the new version (or template) and its ledger and journal rows, under
418
- * the org row lock, in a transaction of their own.
350
+ * {@link update} for a caller already holding the item's update lock ({@link withItemLock}):
351
+ * the platform's import and update runs its import and this update under one hold.
419
352
  */
420
- async upgradeAgentTemplate(orgId, diff, template, record, journal) {
421
- const { itemId } = diff;
422
- const t = this.db;
423
- await this.orgLock.lock(orgId);
424
- const r = await putTemplateVersionIn(t, {
425
- orgId,
426
- plugin: diff.name,
427
- catalogItemId: itemId,
428
- catalogVersion: diff.to.version,
429
- sourceFormat: diff.to.source_format,
430
- }, template);
431
- if (r.created) {
432
- await record({ kind: "agent_template", ref: r.id, created: true, skillVersion: null });
433
- return;
434
- }
435
- if (r.changed)
436
- await journal({ op: "template_version", ref: r.id, version: r.version });
437
- await record({
438
- kind: "agent_template",
439
- ref: r.id,
440
- created: false,
441
- skillVersion: r.changed ? r.version : null,
442
- });
353
+ async updateHeld(actor, itemId, input, opts = {}) {
354
+ return this.updateLocked(actor, itemId, input, opts);
443
355
  }
444
- /** One ledger record (and its journal row) in a transaction of its own. */
445
- async recordStep(installId, journal, c) {
446
- await this.recordIn(installId, journal, c);
356
+ /**
357
+ * Runs an update confirmed with the preview's `diffHash` (see the class comment). A version an
358
+ * org upload waits with, or an item whose first version waits, -> 409 `catalog.item_pending`
359
+ * (confirmed in 待确认 instead, pre-flight F8).
360
+ */
361
+ async update(actor, itemId, input, opts = {}) {
362
+ if (!UUID_RE.test(itemId))
363
+ throw itemNotFound();
364
+ return this.locked(itemId, () => this.updateLocked(actor, itemId, input, opts));
447
365
  }
448
- /** A component's ledger row and its journal step, in the transaction of the context. */
449
- async recordIn(installId, journal, c) {
450
- const inserted = await this.db
451
- .insertInto("plugin_install_components")
452
- .values({
453
- install_id: installId,
454
- kind: c.kind,
455
- ref: c.ref,
456
- created: c.created,
457
- skill_version: c.skillVersion,
458
- template_id: c.templateId ?? null,
459
- })
460
- .onConflict((oc) => oc.columns(["install_id", "kind", "ref"]).doNothing())
461
- .returning("ref")
462
- .executeTakeFirst();
463
- if (c.created)
464
- await journal({ op: "created", kind: c.kind, ref: c.ref });
465
- else if (inserted)
466
- await journal({ op: "recorded", kind: c.kind, ref: c.ref });
366
+ async updateLocked(actor, itemId, input, opts, owner, confirmPending) {
367
+ // Storage is read and written here, before any transaction (see the class comment)
368
+ const checked = await this.diff(itemId, input.version, {
369
+ ...(owner && { owner }),
370
+ ...(confirmPending !== undefined && { confirmPending }),
371
+ });
372
+ if (checked.diffHash !== input.diffHash)
373
+ throw stale();
374
+ const prepared = await this.platform.prepareSync(itemId, input.version);
375
+ const ext = checked.extension;
376
+ // The extension admin re-checks the actor: a super admin, or for an owner update the owner
377
+ // org's admin (and audits it with `ownerOrgId`)
378
+ const opsOwner = owner && { orgId: owner.orgId };
379
+ let step = "extension";
380
+ let extensionMoved = false;
381
+ let enabledHere = false;
382
+ let leftDisabled;
383
+ /** A removal: the extension was enabled before it (put back enabled on failure). */
384
+ let removedEnabled = false;
385
+ try {
386
+ if (ext?.sha256 === null) {
387
+ // The target drops the extension (P3-12'): disabled (drained), then uninstalled
388
+ const row = await this.db
389
+ .selectFrom("extension_installs")
390
+ .select("desired_state")
391
+ .where("name", "=", checked.name)
392
+ .executeTakeFirst();
393
+ removedEnabled = row?.desired_state === "enabled";
394
+ await this.ops.disable(checked.name, actor, opts.actorTokenId, opsOwner);
395
+ extensionMoved = true;
396
+ await this.ops.uninstall(checked.name, actor, opts.actorTokenId, opsOwner);
397
+ }
398
+ else if (ext) {
399
+ const installed = await this.ops.install(checked.name, ext.sha256, actor, opts.actorTokenId, { catalogItemId: itemId, ...(opsOwner && { owner: opsOwner }) });
400
+ extensionMoved = true;
401
+ // A new version newly providing a held single-provider point: left disabled by the install
402
+ leftDisabled = installed.leftDisabled;
403
+ if (ext.previous === null) {
404
+ // An occupied single-provider point leaves it installed disabled
405
+ const r = await this.ops.enableUnlessOccupied(checked.name, actor, opts.actorTokenId, opsOwner);
406
+ enabledHere = r.enabled;
407
+ if (!r.enabled)
408
+ leftDisabled = r.note;
409
+ }
410
+ }
411
+ step = "components";
412
+ const diff = await this.commit(actor, itemId, input, opts, { contents: checked.contents, extension: ext }, prepared, owner, confirmPending);
413
+ return {
414
+ itemId,
415
+ version: diff.to.version,
416
+ components: diff.components,
417
+ extension: extensionView(diff.extension),
418
+ connectorOrgs: diff.connectorOrgs,
419
+ ...(leftDisabled !== undefined && { extensionLeftDisabled: leftDisabled }),
420
+ };
421
+ }
422
+ catch (e) {
423
+ let rolledBack = true;
424
+ if (extensionMoved && ext) {
425
+ // An owner update was authorized at its start: the put-back is not checked again
426
+ const back = opsOwner && { ...opsOwner, rollback: true };
427
+ try {
428
+ if (ext.sha256 === null) {
429
+ // Removed by this update: the previous package reinstalled (as it was)
430
+ await this.ops.install(checked.name, ext.previous, actor, opts.actorTokenId, {
431
+ catalogItemId: itemId,
432
+ ...(back && { owner: back }),
433
+ });
434
+ if (removedEnabled)
435
+ await this.ops.enable(checked.name, actor, opts.actorTokenId, back);
436
+ }
437
+ else if (ext.previous !== null) {
438
+ await this.ops.install(checked.name, ext.previous, actor, opts.actorTokenId, {
439
+ ...(back && { owner: back }),
440
+ });
441
+ // The install left the enabled extension disabled (a held single-provider point): the
442
+ // previous version, which did not provide it, runs again
443
+ if (leftDisabled !== undefined) {
444
+ await this.ops.enable(checked.name, actor, opts.actorTokenId, back);
445
+ }
446
+ }
447
+ else {
448
+ // Installed by this update: an uninstall needs it disabled first
449
+ if (enabledHere)
450
+ await this.ops.disable(checked.name, actor, opts.actorTokenId, back);
451
+ await this.ops.uninstall(checked.name, actor, opts.actorTokenId, back);
452
+ }
453
+ }
454
+ catch (u) {
455
+ rolledBack = false;
456
+ this.log.error("putting a plugin's extension back after a failed update failed", {
457
+ itemId,
458
+ plugin: checked.name,
459
+ err: u,
460
+ });
461
+ }
462
+ }
463
+ const code = e instanceof ApiError ? e.code : "internal";
464
+ await this.auditFailure(actor, checked, { step, code, rolledBack }, opts);
465
+ // A refusal found under the lock (stale, disabled meanwhile, a conflict, a downgrade the
466
+ // extension's migrations refuse): returned as it is
467
+ if (e instanceof ApiError && e.status < 500 && rolledBack)
468
+ throw e;
469
+ throw new ApiError("plugin.upgrade_failed", rolledBack
470
+ ? `Updating the plugin failed at step ${step} (${code}); the platform is back at version ${checked.from ?? "(none)"}`
471
+ : `Updating the plugin failed at step ${step} (${code}) and putting its extension back failed; check the extension in the admin console`, [
472
+ {
473
+ step,
474
+ code,
475
+ ...(e instanceof ApiError && { message: e.message }),
476
+ ...(e instanceof ApiError && e.details !== undefined && { causeDetails: e.details }),
477
+ rolledBack,
478
+ },
479
+ ]);
480
+ }
481
+ }
482
+ /** `plugin.platform_update_failed`, in a transaction of its own. */
483
+ async auditFailure(actor, diff, f, opts) {
484
+ await audit(this.db, {
485
+ actorAccountId: actor,
486
+ ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
487
+ action: "plugin.platform_update_failed",
488
+ target: diff.itemId,
489
+ detail: { name: diff.name, from: diff.from, to: diff.to.version, ...f },
490
+ });
467
491
  }
468
492
  /**
469
- * The upgrade's last transaction (under the org row lock): the changed connectors, the removals,
470
- * the pinned suggestions and the version switch, `plugin.org_upgraded`. `onFinish` marks the step
471
- * once the connectors are applied.
493
+ * The update's transaction (see the class comment): the super admin re-checked, the diff
494
+ * recomputed under the item name's lock, then every write. Returns the diff it applied.
472
495
  */
473
- async finish(orgId, actor, installId, upgradeId, diff, prepared, disabled, opts, onFinish) {
474
- const { itemId } = diff;
475
- const t = this.db;
476
- await lockOrgForActions(this.orgLock, orgId, actor, diff.actions);
477
- const row = await t
478
- .selectFrom("plugin_installs")
479
- .select(["status", sql `upgrade->>'id'`.as("upgradeId")])
480
- .where("id", "=", installId)
481
- .forUpdate()
496
+ async commit(actor, itemId, input, opts, pre, prepared, owner, confirmPending) {
497
+ if (owner === undefined)
498
+ await this.adminLock.lockAndAuthorize(actor);
499
+ // The global lock order (ruling P3-50): the orgs (sorted; the acting owner org's admin
500
+ // re-checked at its place), then the item, then its components; an org deletion locks its org
501
+ // row, then the items it owns
502
+ const liveOrgs = await this.lockUpdateOrgs(itemId, owner && { orgId: owner.orgId, actor });
503
+ const named = await this.db
504
+ .selectFrom("catalog_items")
505
+ .select("name")
506
+ .where("id", "=", itemId)
482
507
  .executeTakeFirst();
483
- if (row?.status !== "upgrading" || row.upgradeId !== upgradeId)
484
- throw cleanedUp();
485
- await assertItemInstallable(t, orgId, itemId);
486
- for (const c of prepared) {
487
- await this.connectors.applyTemplateIn(orgId, c.connectorId, actor, c.p, opts.actorTokenId);
508
+ if (!named)
509
+ throw itemNotFound();
510
+ await this.itemLock.lock(named.name);
511
+ let pendingOwner = null;
512
+ if (confirmPending !== undefined) {
513
+ // The super admin's confirmation (P3-21): still pending with the version they reviewed
514
+ const row = await this.db
515
+ .selectFrom("catalog_items")
516
+ .select(["deleted_at", "pending_version", "owner_org_id"])
517
+ .where("id", "=", itemId)
518
+ .forUpdate()
519
+ .executeTakeFirstOrThrow();
520
+ if (row.deleted_at !== null)
521
+ throw itemRemovedError(named.name);
522
+ if (row.pending_version !== confirmPending)
523
+ throw pendingStale(named.name);
524
+ pendingOwner = row.owner_org_id;
488
525
  }
489
- onFinish();
490
- for (const dep of diff.dependencies) {
491
- if (dep.change !== "changed" || !dep.child)
492
- continue;
493
- const live = await t
494
- .selectFrom("plugin_installs")
495
- .select("version")
496
- .where("id", "=", dep.child.installId)
497
- .forShare()
498
- .executeTakeFirst();
499
- if (!live || !satisfiesRange(live.version, dep.range)) {
500
- throw new ApiError("catalog.dependency_unresolved", `Dependency ${dep.name}@${dep.range} cannot be resolved: its install in this organization changed meanwhile; preview the upgrade again`, [{ dependency: dep.name, range: dep.range }]);
501
- }
526
+ const diff = await this.diff(itemId, input.version, {
527
+ pre,
528
+ ...(owner && { owner }),
529
+ ...(confirmPending !== undefined && { confirmPending }),
530
+ });
531
+ if (diff.diffHash !== input.diffHash)
532
+ throw stale();
533
+ const t = this.db;
534
+ // The platform versions (files copied before the transaction; rows only here)
535
+ try {
536
+ await this.platform.applySyncIn(prepared);
502
537
  }
503
- const report = await this.removeIn(orgId, actor, diff, disabled);
504
- // An unchanged skill gets no new version, so the target's pinned suggestion goes onto its
505
- // current version (when that version is this plugin's) here, with the version switch.
506
- for (const sk of diff.skills) {
507
- if (sk.change !== "unchanged" || !sk.ledger)
538
+ catch (e) {
539
+ if (e instanceof PlanStale)
540
+ throw stale();
541
+ throw e;
542
+ }
543
+ // Removals (spec §7.3): kept while agents use it; otherwise soft-deleted
544
+ const now = sql `now()`;
545
+ for (const c of diff.components) {
546
+ if (c.change !== "removed" || c.id === null || c.kept !== undefined)
508
547
  continue;
548
+ const table = c.kind === "skill"
549
+ ? "platform_skills"
550
+ : c.kind === "agent_template"
551
+ ? "platform_agent_templates"
552
+ : c.kind === "theme"
553
+ ? "platform_themes"
554
+ : "platform_connector_templates";
509
555
  await t
510
- .updateTable("skill_versions as v")
511
- .set({ suggest_pinned: sk.suggestPinned === true })
512
- .from("skills as s")
513
- .whereRef("s.id", "=", "v.skill_id")
514
- .whereRef("s.current_version", "=", "v.version")
515
- .where("s.id", "=", sk.ledger.ref)
516
- .where("s.org_id", "=", orgId)
517
- .where("v.catalog_item_id", "=", itemId)
518
- .where("v.suggest_pinned", "<>", sk.suggestPinned === true)
556
+ .updateTable(table)
557
+ .set({ deleted_at: now, updated_at: now })
558
+ .where("id", "=", c.id)
519
559
  .execute();
520
560
  }
561
+ // Pins of linked copies: moved to the plugin's version (spec §7.1)
562
+ for (const c of diff.components) {
563
+ if (c.change === "removed" || c.id === null || c.pinnedOrgs.length === 0)
564
+ continue;
565
+ if (c.kind === "skill") {
566
+ await t
567
+ .updateTable("skills")
568
+ .set({ pinned_version: null, updated_at: now })
569
+ .where("platform_skill_id", "=", c.id)
570
+ .where("org_id", "in", c.pinnedOrgs)
571
+ .where("pinned_version", "is not", null)
572
+ .execute();
573
+ }
574
+ else if (c.kind === "agent_template") {
575
+ await t
576
+ .updateTable("agent_templates")
577
+ .set({ pinned_version: null, updated_at: now })
578
+ .where("platform_template_id", "=", c.id)
579
+ .where("org_id", "in", c.pinnedOrgs)
580
+ .where("pinned_version", "is not", null)
581
+ .execute();
582
+ }
583
+ }
584
+ // Connectors made from changed templates, in every org (ruling E2)
585
+ const orgs = [...new Set(diff.connectors.map((c) => c.orgId))].sort();
586
+ for (const orgId of orgs) {
587
+ if (!liveOrgs.has(orgId)) {
588
+ // Locked before the item (P3-50): an org not locked then is deleted (its connectors go
589
+ // with it), or its connector was made since, which changes what the update does
590
+ const live = await t
591
+ .selectFrom("orgs")
592
+ .select("id")
593
+ .where("id", "=", orgId)
594
+ .where("deleted_at", "is", null)
595
+ .executeTakeFirst();
596
+ if (live === undefined)
597
+ continue;
598
+ throw stale();
599
+ }
600
+ for (const c of diff.connectors.filter((x) => x.orgId === orgId)) {
601
+ const prepared = await this.prepare(actor, itemId, diff.to.version, c);
602
+ await this.connectors.applyTemplateIn(orgId, c.id, actor, prepared, opts.actorTokenId);
603
+ }
604
+ }
605
+ // One version for the deployment: every live org install of the plugin moves with it (one
606
+ // still installing too, and a legacy `upgrading` row; an install marked installed later
607
+ // records the platform version current at its commit, PluginInstaller.markInstalled)
521
608
  await t
522
609
  .updateTable("plugin_installs")
523
- .set({ version: diff.to.version, status: "installed", upgrade: null, error: null })
524
- .where("id", "=", installId)
610
+ .set({ version: diff.to.version, error: null })
611
+ .where("item_id", "=", itemId)
612
+ .where("status", "in", ["installing", "installed", "upgrading"])
525
613
  .execute();
526
- await this.requests.resolveByInstall(orgId, itemId, actor, opts);
527
- await audit(t, {
528
- actorAccountId: actor,
529
- ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
530
- orgId,
531
- action: "plugin.org_upgraded",
532
- target: installId,
533
- detail: {
614
+ if (owner !== undefined || confirmPending !== undefined) {
615
+ // An org's version becomes its latest once applied or confirmed (ruling P3-34)
616
+ await t
617
+ .updateTable("catalog_items")
618
+ .set({ latest_version: diff.to.version })
619
+ .where("id", "=", itemId)
620
+ .execute();
621
+ await markVersionApplied(t, itemId, diff.to.version);
622
+ // An owner's new version replaces a version waiting for the super admin (pre-flight F7):
623
+ // their confirmation of it is then refused (409 extension.not_pending); the super admin's
624
+ // confirmation applied it
625
+ await t
626
+ .updateTable("catalog_items")
627
+ .set({ pending_version: null, pending_by: null, pending_at: null })
628
+ .where("id", "=", itemId)
629
+ .where("pending_version", "is not", null)
630
+ .execute();
631
+ }
632
+ if (confirmPending !== undefined && pendingOwner !== null) {
633
+ await addOrgNotice(t, pendingOwner, "upload_confirmed", {
534
634
  itemId,
535
635
  name: diff.name,
536
- from: diff.from.version,
537
- to: diff.to.version,
538
- components: diff.components,
539
- removed: report.removed,
540
- kept: report.kept,
541
- },
542
- });
543
- }
544
- /** Undoes a failed upgrade's journal (see {@link failed}) in a transaction of its own. */
545
- async undoFailed(orgId, actor, installId, upgradeId, diff, steps, f, opts) {
546
- const { at, code } = f;
547
- const t = this.db;
548
- await this.orgLock.lock(orgId);
549
- const row = await t
550
- .selectFrom("plugin_installs")
551
- .select(sql `upgrade->>'id'`.as("upgradeId"))
552
- .where("id", "=", installId)
553
- .forUpdate()
554
- .executeTakeFirst();
555
- const ours = row?.upgradeId === upgradeId;
556
- // Cleaned up meanwhile: only the step whose journal write found the journal gone is ours to
557
- // undo. When that step ran in the same transaction as its journal write (the extension
558
- // enable, the ledger rows), the transaction rolled back with the failed write, so undoing
559
- // it is a no-op (a never-enabled extension, a never-inserted row); undoing is still safe.
560
- const undo = ours ? steps.done : steps.unjournaled ? [steps.unjournaled] : [];
561
- const out = await this.installer.undoUpgradeIn(orgId, actor, installId, undo, "plugin_upgrade_rollback");
562
- await t
563
- .updateTable("plugin_installs")
564
- .set({ status: "installed", upgrade: null, error: JSON.stringify({ step: at, code }) })
565
- .where("id", "=", installId)
566
- .where(sql `upgrade->>'id'`, "=", upgradeId)
567
- .execute();
636
+ displayName: await itemDisplayName(t, itemId),
637
+ version: diff.to.version,
638
+ });
639
+ }
640
+ // The orgs using a shared org-owned plugin are told, one notice per plugin (a platform-owned
641
+ // plugin tells nobody); a plugin never synced before has no version to come from
642
+ if (diff.from !== null) {
643
+ await notifySharedUpdate(t, { kind: "plugin", id: itemId }, { name: diff.name, from: diff.from, to: diff.to.version });
644
+ }
568
645
  await audit(t, {
569
646
  actorAccountId: actor,
570
647
  ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
571
- orgId,
572
- action: "plugin.org_upgrade_failed",
573
- target: installId,
648
+ action: "plugin.platform_updated",
649
+ target: itemId,
574
650
  detail: {
575
- itemId: diff.itemId,
576
651
  name: diff.name,
577
- from: diff.from.version,
652
+ from: diff.from,
578
653
  to: diff.to.version,
579
- step: at,
580
- code,
581
- rolledBack: undo,
582
- ...(!ours && { cleanedUpMeanwhile: true }),
583
- },
584
- });
585
- return out;
586
- }
587
- /** Undoes an interrupted upgrade (see {@link recoverInterrupted}) in a transaction of its own. */
588
- async undoInterrupted(orgId, actor, installId) {
589
- const staleMinutes = this.installer.staleInstallMinutes();
590
- const t = this.db;
591
- const peek = await t
592
- .selectFrom("plugin_installs")
593
- .select("status")
594
- .where("id", "=", installId)
595
- .where("org_id", "=", orgId)
596
- .executeTakeFirst();
597
- if (peek?.status !== "upgrading")
598
- return [];
599
- await this.orgLock.lock(orgId);
600
- const row = await t
601
- .selectFrom("plugin_installs as a")
602
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
603
- .select([
604
- "a.status",
605
- "a.upgrade",
606
- "a.item_id",
607
- "i.name",
608
- sql `coalesce((a.upgrade->>'startedAt')::timestamptz < now() - make_interval(mins => ${staleMinutes}), false)`.as("stale"),
609
- ])
610
- .where("a.id", "=", installId)
611
- .where("a.org_id", "=", orgId)
612
- .forUpdate("a")
613
- .executeTakeFirst();
614
- if (row?.status !== "upgrading" || !row.stale)
615
- return [];
616
- const steps = journalEntries(row.upgrade);
617
- const out = await this.installer.undoUpgradeIn(orgId, actor, installId, steps, "plugin_upgrade_cleanup");
618
- await t
619
- .updateTable("plugin_installs")
620
- .set({
621
- status: "installed",
622
- upgrade: null,
623
- error: JSON.stringify({ step: "interrupted", code: "internal" }),
624
- })
625
- .where("id", "=", installId)
626
- .execute();
627
- const j = row.upgrade;
628
- await audit(t, {
629
- actorAccountId: actor,
630
- orgId,
631
- action: "plugin.org_upgrade_failed",
632
- target: installId,
633
- detail: {
634
- itemId: row.item_id,
635
- name: row.name,
636
- from: j?.from ?? null,
637
- to: j?.to ?? null,
638
- step: "interrupted",
639
- code: "internal",
640
- rolledBack: steps,
654
+ ...(owner !== undefined && { ownerOrgId: owner.orgId }),
655
+ components: diff.components.map((c) => ({
656
+ kind: c.kind,
657
+ name: c.name,
658
+ change: c.change,
659
+ ...(c.kept !== undefined && { kept: true }),
660
+ ...(c.pinnedOrgs.length > 0 && c.change !== "removed" && { unpinned: c.pinnedOrgs }),
661
+ })),
662
+ ...(diff.extension && { extension: extensionView(diff.extension) }),
663
+ connectors: diff.connectors.map((c) => ({
664
+ orgId: c.orgId,
665
+ id: c.id,
666
+ credentialsReset: c.credentialsReset,
667
+ })),
668
+ ...opts.auditDetail,
641
669
  },
642
670
  });
643
- return out;
671
+ // The scope sync of the item and its dependencies is owed with the update (outbox spec §8.1)
672
+ for (const id of [itemId, ...diff.dependencies])
673
+ await this.sync.enqueueItem(id);
674
+ return diff;
644
675
  }
645
676
  /**
646
- * The removals of an upgrade, in the final transaction, by the uninstall rules
647
- * (`decideRemovalIn`): only components this install created are removed, and only when nothing
648
- * else uses them; one still used (by an agent, a connector or another extension) stays in the
649
- * ledger marked `dropped` ("no longer in the plugin", still this install's), every other removed
650
- * component leaves the ledger; a dropped component the target brings back is un-dropped. A dependency
651
- * install is uninstalled by the same rules (another install using it takes it over). Skills ->
652
- * connectors -> extension -> dependencies.
677
+ * The template update of one connector: the new endpoint preset with the org's values at the
678
+ * editable paths, the auth preset and default policies; credentials cleared (no new ones: they
679
+ * are the org's) when the credential shape changed.
653
680
  */
654
- async removeIn(orgId, actor, diff, disabled) {
655
- const report = { removed: [], kept: [] };
656
- const reason = "plugin_upgrade";
657
- const t = this.db;
658
- const keep = (kind, ref, why) => report.kept.push({ kind, ref, reason: why });
659
- const row = (kind, ref) => t
660
- .updateTable("plugin_install_components")
661
- .where("install_id", "=", diff.installId)
662
- .where("kind", "=", kind)
663
- .where("ref", "=", ref);
664
- const dropRow = (kind, ref) => t
665
- .deleteFrom("plugin_install_components")
666
- .where("install_id", "=", diff.installId)
667
- .where("kind", "=", kind)
668
- .where("ref", "=", ref)
669
- .execute();
670
- const removed = [
671
- ...diff.skills.flatMap((x) => (x.change === "removed" && x.ledger ? [x.ledger] : [])),
672
- ...diff.agentTemplates.flatMap((x) => (x.change === "removed" && x.ledger ? [x.ledger] : [])),
673
- ...diff.templates.flatMap((x) => (x.change === "removed" && x.ledger ? [x.ledger] : [])),
674
- ...(diff.extension?.change === "removed"
675
- ? diff.ledger.filter((l) => l.kind === "extension" && l.ref === diff.extension?.name)
676
- : []),
677
- ];
678
- const agentRefs = await this.installer.agentRefs(orgId);
679
- const self = new Set([diff.installId]);
680
- for (const l of removed) {
681
- if (!l.created) {
682
- await dropRow(l.kind, l.ref);
683
- keep(l.kind, l.ref, "pre_existing");
684
- continue;
685
- }
686
- const outcome = await this.installer.decideRemovalIn(orgId, actor, { kind: l.kind, ref: l.ref, created: true, skillVersion: null }, self, agentRefs, reason);
687
- if (outcome === "used_by_agents" ||
688
- outcome === "used_by_connectors" ||
689
- outcome === "used_by_plugins") {
690
- // Still used: stays this install's, marked dropped, so an uninstall (or a later upgrade
691
- // bringing it back) still finds it
692
- await row(l.kind, l.ref).set({ dropped: true }).execute();
693
- keep(l.kind, l.ref, outcome);
694
- continue;
695
- }
696
- await dropRow(l.kind, l.ref);
697
- if (outcome === "removed") {
698
- report.removed.push({ kind: l.kind, ref: l.ref });
699
- if (l.kind === "extension")
700
- disabled.push(l.ref);
701
- }
702
- else if (outcome !== "gone")
703
- keep(l.kind, l.ref, outcome);
704
- }
705
- // Components back in the plugin (dropped by an earlier upgrade, brought again by the target)
706
- const back = [
707
- ...diff.skills.flatMap((x) => x.change !== "removed" && x.ledger?.dropped
708
- ? [{ kind: "skill", ref: x.ledger.ref }]
709
- : []),
710
- ...diff.agentTemplates.flatMap((x) => x.change !== "removed" && x.ledger?.dropped
711
- ? [{ kind: "agent_template", ref: x.ledger.ref }]
712
- : []),
713
- ...diff.templates.flatMap((x) => x.change !== "removed" && x.ledger?.dropped
714
- ? [{ kind: "connector", ref: x.ledger.ref }]
715
- : []),
716
- ...(diff.extension && diff.extension.change !== "removed"
717
- ? diff.ledger
718
- .filter((l) => l.kind === "extension" && l.ref === diff.extension?.name && l.dropped)
719
- .map((l) => ({ kind: "extension", ref: l.ref }))
720
- : []),
721
- ];
722
- for (const b of back)
723
- await row(b.kind, b.ref).set({ dropped: false }).execute();
724
- for (const dep of diff.dependencies) {
725
- if (dep.change !== "removed" || !dep.child)
726
- continue;
727
- const ref = dep.child.installId;
728
- await dropRow("plugin", ref);
729
- if (!dep.child.ledger.created) {
730
- keep("plugin", ref, "pre_existing");
731
- continue;
732
- }
733
- const sub = { removed: [], kept: [] };
734
- const outcome = await this.installer.uninstallIn(orgId, actor, ref, {
735
- report: sub,
736
- removing: new Set(),
737
- from: diff.installId,
738
- authorize: false,
739
- reason,
740
- opts: {},
741
- });
742
- for (const r of sub.removed)
743
- if (r.kind === "extension")
744
- disabled.push(r.ref);
745
- if (outcome === "removed")
746
- report.removed.push({ kind: "plugin", ref });
747
- else if (outcome === "kept")
748
- keep("plugin", ref, "used_by_other_install");
681
+ async prepare(actor, itemId, version, c) {
682
+ const template = c.file.template;
683
+ const endpoint = structuredClone(template.endpoint);
684
+ for (const e of template.editableEndpoint ?? []) {
685
+ const v = getPath(c.endpoint, e);
686
+ if (v !== undefined)
687
+ setPath(endpoint, e, v);
749
688
  }
750
- return report;
689
+ const input = {
690
+ endpoint,
691
+ auth: template.auth,
692
+ ...(template.git !== undefined && { git: template.git }),
693
+ template: {
694
+ itemId,
695
+ version,
696
+ templateId: c.templateId,
697
+ ...(template.defaultToolPolicies !== undefined && {
698
+ defaultToolPolicies: template.defaultToolPolicies,
699
+ }),
700
+ },
701
+ resetCredentials: false,
702
+ };
703
+ // Checked without credentials (nothing outbound); a changed shape then clears the old ones
704
+ const prepared = await this.connectors.prepareTemplateUpdate(actor, c.connector, input);
705
+ return c.credentialsReset
706
+ ? { ...prepared, input: { ...prepared.input, resetCredentials: true } }
707
+ : prepared;
751
708
  }
752
709
  /**
753
- * Computes an upgrade (see the class comment). `input` null: the preview (no input checks);
754
- * otherwise the connector inputs are built and checked as at install.
710
+ * Computes an update (see the class comment). `target`: the target read from an org's staging
711
+ * instead of `catalog_item_versions` (pre-flight F3). `owner`: an owner update (P3-12): the item
712
+ * must be the org's, an extension-bearing target is refused, and a target dropping the
713
+ * extension removes it.
755
714
  */
756
- async diff(orgId, actor, installId, version, input) {
715
+ async diff(itemId, version, o = {}) {
757
716
  const db = this.db;
758
- if (!UUID_RE.test(installId))
759
- throw installNotFound();
760
- const install = await db
761
- .selectFrom("plugin_installs as a")
762
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
763
- .select(["a.item_id", "a.version", "a.status", "i.name", "i.policy", "i.deleted_at"])
764
- .where("a.id", "=", installId)
765
- .where("a.org_id", "=", orgId)
717
+ if (!UUID_RE.test(itemId))
718
+ throw itemNotFound();
719
+ const item = await db
720
+ .selectFrom("catalog_items")
721
+ .select([
722
+ "id",
723
+ "name",
724
+ "disabled",
725
+ "builtin",
726
+ "deleted_at",
727
+ "platform_synced_version",
728
+ "owner_org_id",
729
+ "awaiting_confirmation",
730
+ "pending_version",
731
+ "latest_version",
732
+ ])
733
+ .where("id", "=", itemId)
766
734
  .executeTakeFirst();
767
- if (!install || install.status === "failed")
768
- throw installNotFound();
769
- if (install.status !== "installed")
770
- throw inProgress();
771
- const itemId = install.item_id;
772
- const name = install.name;
773
- if (install.deleted_at !== null) {
774
- throw new ApiError("catalog.item_not_found", "This plugin is no longer in the enterprise catalog");
735
+ if (!item || item.deleted_at !== null)
736
+ throw itemNotFound();
737
+ // A version waiting for the super admin applies only through their confirmation (P3-9, F8)
738
+ if (o.confirmPending !== version) {
739
+ if (item.awaiting_confirmation)
740
+ throw itemPendingError(item.name);
741
+ if (item.pending_version !== null && item.pending_version === version) {
742
+ throw itemPendingError(item.name, version);
743
+ }
744
+ // The super admin's generic update of an org's plugin reaches only its applied version
745
+ // (`latest_version`, ruling P3-34/P3-37): one the org uploaded that was never applied or
746
+ // confirmed (a rejected or failed one) is not theirs to apply
747
+ if (o.owner === undefined && item.owner_org_id !== null && version !== item.latest_version) {
748
+ throw notApplied(item.name, version);
749
+ }
775
750
  }
776
- if (install.policy === "disabled") {
777
- throw new ApiError("catalog.item_disabled", "This catalog item is disabled by the enterprise admin and cannot be upgraded");
751
+ if (o.owner !== undefined && item.owner_org_id !== o.owner.orgId)
752
+ throw itemNotFound();
753
+ if (item.disabled) {
754
+ throw new ApiError("catalog.item_disabled", "This plugin is disabled on the deployment; enable it before updating");
778
755
  }
779
- const versions = await db
756
+ const name = item.name;
757
+ const versions = (await db
780
758
  .selectFrom("catalog_item_versions")
781
759
  .select([
782
760
  "version",
@@ -784,561 +762,767 @@ let PluginUpgrader = class PluginUpgrader {
784
762
  "object_prefix",
785
763
  "files",
786
764
  "extension_sha256",
787
- "imported_at",
788
- "source_format",
765
+ "applied_at",
766
+ "rejected_at",
789
767
  ])
790
768
  .where("item_id", "=", itemId)
791
- .execute();
792
- const fromRow = versions.find((v) => v.version === install.version);
793
- const toRow = versions.find((v) => v.version === version);
794
- if (!fromRow) {
795
- throw new ApiError("catalog.item_not_found", `The installed version ${install.version} is no longer in the enterprise catalog`);
796
- }
797
- if (!toRow)
769
+ .execute());
770
+ const to = o.target ?? versions.find((v) => v.version === version);
771
+ if (!to)
798
772
  throw new ApiError("catalog.item_not_found", `Version ${version} of this item not found`);
799
- const from = fromRow;
800
- const to = toRow;
801
- if (to.version === from.version) {
802
- // Confirming a preview whose upgrade already ran (a concurrent confirm won): stale
803
- if (input !== null)
773
+ // Whoever owns the item now (a transfer keeps the version rows), the generic update never
774
+ // reaches a version that was rejected or never applied (ruling P3-52)
775
+ const row = versions.find((v) => v.version === version);
776
+ if (o.owner === undefined && o.confirmPending !== version && row && !versionUsable(row)) {
777
+ throw notApplied(item.name, version);
778
+ }
779
+ if (o.owner !== undefined && to.manifest.extension) {
780
+ // An org's version with an extension waits for the super admin's confirmation (plan Task 6)
781
+ throw new ApiError("plugin.extension_upload_pending", `Version ${to.version} of plugin ${item.name} has an extension; it applies once a super admin confirms it`);
782
+ }
783
+ const from = item.platform_synced_version;
784
+ const fromRow = versions.find((v) => v.version === from);
785
+ if (from === to.version) {
786
+ // Confirming a preview whose update already ran (a concurrent confirm won): stale
787
+ if (o.pre)
804
788
  throw stale();
805
- throw targetInvalid(`This organization already has version ${from.version} installed`, [
806
- { reason: "same_version", version: from.version },
789
+ throw targetInvalid(`The platform already runs version ${from} of plugin ${name}`, [
790
+ { reason: "same_version", version: from },
807
791
  ]);
808
792
  }
809
- // Target rules (Decision 10)
810
- if (to.manifest.extension) {
811
- const deployed = await deployedExtension(db, this.registry, name);
812
- const allowed = deploymentTarget(versions, deployed);
813
- if (allowed?.version !== to.version) {
814
- throw targetInvalid(deployed === undefined
815
- ? `The deployment does not run the extension of plugin ${name}; ask the enterprise admin to install it first`
816
- : `The deployment runs the extension of plugin ${name} at version ${deployed.version}; this organization can upgrade only to ${allowed ? `catalog version ${allowed.version}` : "a catalog version carrying that extension, and none is imported"}`, [
817
- {
818
- reason: "deployment_version",
819
- deploymentVersion: deployed?.version ?? null,
820
- allowedVersion: allowed?.version ?? null,
821
- },
822
- ]);
793
+ const target = await this.extensionTarget(name, fromRow, to, o.owner !== undefined);
794
+ let extension;
795
+ if (o.pre) {
796
+ // The confirm's transaction: the extension this update moved is expected in place (a
797
+ // removed one gone)
798
+ if (o.pre.extension) {
799
+ const row = await db
800
+ .selectFrom("extension_installs")
801
+ .select("sha256")
802
+ .where("name", "=", name)
803
+ .executeTakeFirst();
804
+ if ((row?.sha256 ?? null) !== o.pre.extension.sha256)
805
+ throw stale();
806
+ extension = o.pre.extension;
823
807
  }
824
- }
825
- // Installs in this org depending on this one must accept the target
826
- const parents = await db
827
- .selectFrom("plugin_install_components as c")
828
- .innerJoin("plugin_installs as a", "a.id", "c.install_id")
829
- .innerJoin("catalog_item_versions as v", (j) => j.onRef("v.item_id", "=", "a.item_id").onRef("v.version", "=", "a.version"))
830
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
831
- .select(["i.name", "v.manifest"])
832
- .where("c.kind", "=", "plugin")
833
- .where("c.ref", "=", installId)
834
- .where("a.org_id", "=", orgId)
835
- .where("a.status", "<>", "failed")
836
- .execute();
837
- for (const p of parents) {
838
- const range = p.manifest.dependencies?.find((x) => x.name === name)?.version;
839
- if (range !== undefined && !satisfiesRange(to.version, range)) {
840
- throw targetInvalid(`Plugin ${p.name} installed in this organization depends on ${name}@${range}, which version ${to.version} does not satisfy`, [{ reason: "dependent_range", dependent: p.name, range, version: to.version }]);
808
+ else {
809
+ if (target !== null)
810
+ throw stale();
811
+ extension = null;
841
812
  }
842
813
  }
843
- const ledger = await ledgerOf(db, installId);
844
- const components = [];
845
- // Extension
846
- let extension = null;
847
- let extensionConfig = false;
848
- if (from.manifest.extension || to.manifest.extension) {
849
- const change = !from.manifest.extension
850
- ? "added"
851
- : !to.manifest.extension
852
- ? "removed"
853
- : from.extension_sha256 !== to.extension_sha256 ||
854
- from.manifest.extension.manifest.version !== to.manifest.extension.manifest.version
855
- ? "changed"
856
- : "unchanged";
857
- extension = { change, name };
858
- if (change === "added") {
859
- await this.installer.planExtension(orgId, to.manifest);
860
- extensionConfig = !(await isExtensionEnabled(db, orgId, name));
861
- }
862
- components.push({
863
- kind: "extension",
864
- ref: name,
865
- change,
866
- ...(change === "changed" && {
867
- detail: `${from.manifest.extension?.manifest.version} -> ${to.manifest.extension?.manifest.version}`,
868
- }),
869
- });
814
+ else {
815
+ extension = target && {
816
+ ...target,
817
+ needsApproval: target.sha256 !== null && (await this.needsApproval(name, target.sha256)),
818
+ orgs: [],
819
+ };
870
820
  }
871
- // Dependencies (by plugin name)
872
- const resolved = await resolveDependencies(db, to.manifest);
873
- const childIds = ledger.filter((l) => l.kind === "plugin").map((l) => l.ref);
874
- const children = childIds.length === 0
875
- ? []
876
- : await db
877
- .selectFrom("plugin_installs as a")
878
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
879
- .select(["a.id", "a.version", "i.name"])
880
- .where("a.id", "in", childIds)
881
- .execute();
882
- const childOf = (n) => {
883
- const c = children.find((x) => x.name === n);
884
- const l = c && ledger.find((x) => x.kind === "plugin" && x.ref === c.id);
885
- return c && l ? { installId: c.id, version: c.version, ledger: l } : undefined;
886
- };
887
- const dependencies = [];
888
- const fromDeps = from.manifest.dependencies ?? [];
889
- for (const r of resolved) {
890
- const before = fromDeps.find((x) => x.name === r.name);
891
- const child = childOf(r.name);
892
- if (before && child) {
893
- const change = before.version === r.range ? "unchanged" : "changed";
894
- if (change === "changed" && !satisfiesRange(child.version, r.range)) {
895
- throw new ApiError("catalog.dependency_unresolved", `Dependency ${r.name}@${r.range} cannot be resolved: this organization has version ${child.version} installed; upgrade it first`, [{ dependency: r.name, range: r.range }]);
896
- }
897
- dependencies.push({
898
- name: r.name,
899
- change,
900
- range: r.range,
901
- fromRange: before.version,
902
- resolved: r,
903
- child,
904
- });
821
+ const contents = o.pre?.contents ?? (await this.readContents(to));
822
+ const dependencies = await this.checkDependents(name, to);
823
+ // The platform's components of the plugin and the target's
824
+ const live = await this.liveComponents(itemId);
825
+ const components = [];
826
+ const direction = (fromVersion) => fromVersion === null || compareVersions(to.version, fromVersion) >= 0
827
+ ? "upgrade"
828
+ : "downgrade";
829
+ const added = (kind, n) => ({
830
+ kind,
831
+ id: null,
832
+ name: n,
833
+ change: "added",
834
+ from: null,
835
+ to: to.version,
836
+ updatedOnOwn: false,
837
+ ownScope: false,
838
+ pinnedOrgs: [],
839
+ });
840
+ // Skills (by name, by their files' digest)
841
+ const toSkills = contents.skillNames.map((n, i) => {
842
+ const entry = (to.manifest.skills ?? [])[i];
843
+ return {
844
+ name: n,
845
+ digest: dirDigest(to, packagePath(entry?.path)),
846
+ };
847
+ });
848
+ for (const s of toSkills) {
849
+ const l = live.skills.find((x) => x.name === s.name);
850
+ if (!l) {
851
+ components.push(added("skill", s.name));
905
852
  continue;
906
853
  }
907
- // New (or its install was not recorded): installed by the install flow
908
- const live = await this.installer.liveDependency(db, orgId, r);
909
- dependencies.push({
910
- name: r.name,
911
- change: "added",
912
- range: r.range,
913
- resolved: r,
914
- plan: live !== undefined
915
- ? null
916
- : await this.installer.plan(orgId, actor, r.itemId, r.version, input === null ? null : {}, `dependencies.${r.name}.`, itemId),
854
+ const same = skillFilesDigest(l.manifest.files) === s.digest;
855
+ components.push({
856
+ kind: "skill",
857
+ id: l.id,
858
+ name: s.name,
859
+ change: same ? "same" : direction(l.catalogVersion),
860
+ from: l.catalogVersion,
861
+ to: to.version,
862
+ updatedOnOwn: l.updatedOnOwn,
863
+ ownScope: l.ownScope,
864
+ pinnedOrgs: [],
917
865
  });
918
866
  }
919
- for (const before of fromDeps) {
920
- if (resolved.some((r) => r.name === before.name))
867
+ for (const l of live.skills) {
868
+ if (toSkills.some((s) => s.name === l.name))
921
869
  continue;
922
- const child = childOf(before.name);
923
- dependencies.push({
924
- name: before.name,
870
+ components.push({
871
+ kind: "skill",
872
+ id: l.id,
873
+ name: l.name,
925
874
  change: "removed",
926
- fromRange: before.version,
927
- ...(child && { child }),
875
+ from: l.catalogVersion,
876
+ to: null,
877
+ updatedOnOwn: l.updatedOnOwn,
878
+ ownScope: l.ownScope,
879
+ pinnedOrgs: [],
928
880
  });
929
881
  }
930
- for (const dep of dependencies) {
882
+ // Agent templates (by name, canonical definition)
883
+ const toAgents = contents.agents;
884
+ for (const a of toAgents) {
885
+ const l = live.agentTemplates.find((x) => x.name === a.template.name);
886
+ if (!l) {
887
+ components.push(added("agent_template", a.template.name));
888
+ continue;
889
+ }
890
+ const same = canonicalJson(l.definition) === canonicalJson(a.template);
931
891
  components.push({
932
- kind: "plugin",
933
- ref: dep.name,
934
- change: dep.change,
935
- ...(dep.change === "changed" && { detail: `${dep.fromRange} -> ${dep.range}` }),
936
- ...(dep.change === "added" && {
937
- detail: dep.plan === null ? "already installed" : `installs ${dep.resolved?.version}`,
938
- }),
939
- });
940
- }
941
- // Skills (by name)
942
- const fromNames = await catalogSkillNames(this.storage, from, from.manifest);
943
- const toNames = await catalogSkillNames(this.storage, to, to.manifest);
944
- const dirOf = (m, i) => packagePath((m.skills ?? [])[i]?.path);
945
- const fromSkills = new Map(fromNames.map((n, i) => [n, dirOf(from.manifest, i)]));
946
- const toSkills = new Map(toNames.map((n, i) => [n, dirOf(to.manifest, i)]));
947
- const toPinned = new Set(toNames.filter((_, i) => (to.manifest.skills ?? [])[i]?.pinned === true));
948
- const skillRefs = ledger.filter((l) => l.kind === "skill").map((l) => l.ref);
949
- const liveSkills = skillRefs.length === 0
950
- ? []
951
- : await db
952
- .selectFrom("skills")
953
- .select(["id", "name"])
954
- .where("id", "in", skillRefs)
955
- .where("org_id", "=", orgId)
956
- .where("deleted_at", "is", null)
957
- .execute();
958
- const ledgerOfSkill = (n) => {
959
- const s = liveSkills.find((x) => x.name === n);
960
- return s && ledger.find((l) => l.kind === "skill" && l.ref === s.id);
961
- };
962
- const skills = [];
963
- for (const [n, dir] of toSkills) {
964
- const before = fromSkills.get(n);
965
- const l = ledgerOfSkill(n);
966
- const change = before === undefined
967
- ? "added"
968
- : dirDigest(from, before) === dirDigest(to, dir)
969
- ? "unchanged"
970
- : "changed";
971
- skills.push({
972
- name: n,
973
- change,
974
- dir,
975
- suggestPinned: toPinned.has(n),
976
- ...(l && { ledger: l }),
892
+ kind: "agent_template",
893
+ id: l.id,
894
+ name: l.name,
895
+ change: same ? "same" : direction(l.catalogVersion),
896
+ from: l.catalogVersion,
897
+ to: to.version,
898
+ updatedOnOwn: l.updatedOnOwn,
899
+ ownScope: l.ownScope,
900
+ pinnedOrgs: [],
977
901
  });
978
902
  }
979
- for (const n of fromSkills.keys()) {
980
- if (toSkills.has(n))
903
+ for (const l of live.agentTemplates) {
904
+ if (toAgents.some((a) => a.template.name === l.name))
981
905
  continue;
982
- const l = ledgerOfSkill(n);
983
- skills.push({ name: n, change: "removed", ...(l && { ledger: l }) });
984
- }
985
- for (const s of skills)
986
- components.push({ kind: "skill", ref: s.name, change: s.change });
987
- // The same skill conflict check as an install (spec §9.2)
988
- const conflicts = await planSkillConflicts(db, orgId, {
989
- itemId,
990
- name,
991
- version: to.version,
992
- skillNames: toNames,
993
- dependencies: dependencies
994
- .filter((x) => x.change === "added")
995
- .map((x) => ({ plan: x.plan ?? null })),
996
- });
997
- if (conflicts.length > 0)
998
- throw skillConflictError(conflicts);
999
- // Agent templates (by name; phase C)
1000
- const fromAgents = await readCatalogAgentTemplates(this.storage, from);
1001
- const toAgents = await readCatalogAgentTemplates(this.storage, to);
1002
- const templateRefs = ledger.filter((l) => l.kind === "agent_template").map((l) => l.ref);
1003
- const liveTemplates = templateRefs.length === 0
1004
- ? []
1005
- : await db
1006
- .selectFrom("agent_templates")
1007
- .select(["id", "name"])
1008
- .where("id", "in", templateRefs)
1009
- .where("org_id", "=", orgId)
1010
- .where("deleted_at", "is", null)
1011
- .execute();
1012
- const ledgerOfTemplate = (n) => {
1013
- const r = liveTemplates.find((x) => x.name === n);
1014
- return r && ledger.find((l) => l.kind === "agent_template" && l.ref === r.id);
1015
- };
1016
- const agentTemplates = [];
1017
- for (const a of toAgents) {
1018
- const n = a.template.name;
1019
- const before = fromAgents.find((x) => x.template.name === n);
1020
- const l = ledgerOfTemplate(n);
1021
- const change = before === undefined
1022
- ? "added"
1023
- : canonicalJson(before.template) === canonicalJson(a.template)
1024
- ? "unchanged"
1025
- : "changed";
1026
- agentTemplates.push({ name: n, change, template: a.template, ...(l && { ledger: l }) });
1027
- }
1028
- for (const a of fromAgents) {
1029
- const n = a.template.name;
1030
- if (toAgents.some((x) => x.template.name === n))
1031
- continue;
1032
- const l = ledgerOfTemplate(n);
1033
- agentTemplates.push({ name: n, change: "removed", ...(l && { ledger: l }) });
1034
- }
1035
- for (const a of agentTemplates) {
1036
- components.push({ kind: "agent_template", ref: a.name, change: a.change });
906
+ components.push({
907
+ kind: "agent_template",
908
+ id: l.id,
909
+ name: l.name,
910
+ change: "removed",
911
+ from: l.catalogVersion,
912
+ to: null,
913
+ updatedOnOwn: l.updatedOnOwn,
914
+ ownScope: l.ownScope,
915
+ pinnedOrgs: [],
916
+ });
1037
917
  }
1038
- // Connector templates (by id)
1039
- const fromTemplates = await readCatalogTemplates(this.storage, from);
1040
- const toTemplates = await readCatalogTemplates(this.storage, to);
1041
- // The install's connectors by template; a dropped one (kept only for the agents using it) counts
1042
- // only while its connector is live, so a template the target brings back maps onto it
1043
- const connectorRows = ledger.filter((l) => l.kind === "connector" && l.template_id !== null);
1044
- const liveConnectors = connectorRows.length === 0
1045
- ? []
1046
- : await db
1047
- .selectFrom("connectors")
1048
- .select(["id", "connector", "endpoint", "auth"])
1049
- .where("id", "in", connectorRows.map((l) => l.ref))
1050
- .where("org_id", "=", orgId)
1051
- .where("deleted_at", "is", null)
1052
- .execute();
1053
- const connectorOf = (templateId) => {
1054
- const rows = connectorRows.filter((x) => x.template_id === templateId);
1055
- const l = rows.find((x) => !x.dropped) ??
1056
- rows.find((x) => liveConnectors.some((c) => c.id === x.ref));
1057
- const c = l && liveConnectors.find((x) => x.id === l.ref);
1058
- return {
1059
- ...(l && { ledger: l }),
1060
- ...(c && {
1061
- connector: {
1062
- id: c.id,
1063
- connector: c.connector,
1064
- endpoint: c.endpoint,
1065
- auth: c.auth,
1066
- },
1067
- }),
1068
- };
1069
- };
918
+ // Connector templates (by id, canonical file) and the connectors made from them
919
+ const toTemplates = contents.templates;
1070
920
  const deps = this.installer.templateDeps();
1071
- const templates = [];
921
+ const connectors = [];
922
+ const shippedOff = (f) => f.defaultEnabled === false;
923
+ /** Templates whose `defaultEnabled` the target flips: id -> shipped off, and the platform id. */
924
+ const flipped = new Map();
925
+ const flippedIds = new Map();
1072
926
  for (const ct of toTemplates) {
1073
- const problem = templatePluginProblem(deps, ct.file.template);
1074
- const before = fromTemplates.find((x) => x.id === ct.id);
1075
- const mapped = connectorOf(ct.id);
1076
- if (!before && mapped.ledger?.dropped && mapped.connector) {
1077
- // Back in the plugin (an earlier upgrade dropped it, its connector was kept): the kept
1078
- // connector is updated to the template, not created again (its slug would be taken)
927
+ const l = live.templates.find((x) => x.name === ct.id);
928
+ if (!l) {
929
+ const problem = templatePluginProblem(deps, ct.file.template);
1079
930
  if (problem !== undefined)
1080
931
  throw new ApiError("catalog.not_deployed", problem);
1081
- if (mapped.connector.connector !== ct.file.template.connector) {
1082
- throw targetInvalid(`Connector template ${ct.id} comes back for another connector (${ct.file.template.plugin} "${ct.file.template.connector}"); uninstall the plugin and install the new version instead`, [
1083
- {
1084
- reason: "template_connector",
1085
- template: ct.id,
1086
- plugin: ct.file.template.plugin,
1087
- connector: ct.file.template.connector,
1088
- },
1089
- ]);
1090
- }
1091
- const credentialsChanged = credentialKey(mapped.connector.auth) !==
1092
- credentialKey(ct.file.template.auth);
1093
- templates.push({
1094
- id: ct.id,
1095
- change: "changed",
1096
- target: ct.file,
1097
- ...mapped,
1098
- credentialsChanged,
1099
- });
932
+ components.push(added("connector_template", ct.id));
1100
933
  continue;
1101
934
  }
1102
- if (!before) {
1103
- if (problem !== undefined)
1104
- throw new ApiError("catalog.not_deployed", problem);
1105
- templates.push({ id: ct.id, change: "added", target: ct.file, credentialsChanged: false });
935
+ const same = canonicalJson(l.file) === canonicalJson(ct.file);
936
+ components.push({
937
+ kind: "connector_template",
938
+ id: l.id,
939
+ name: ct.id,
940
+ change: same ? "same" : direction(l.version),
941
+ from: l.version,
942
+ to: to.version,
943
+ updatedOnOwn: false,
944
+ ownScope: l.ownScope,
945
+ pinnedOrgs: [],
946
+ });
947
+ if (same)
1106
948
  continue;
949
+ if (shippedOff(l.file) !== shippedOff(ct.file)) {
950
+ flipped.set(ct.id, shippedOff(ct.file));
951
+ flippedIds.set(ct.id, l.id);
1107
952
  }
1108
- const change = canonicalJson(before.file) === canonicalJson(ct.file) ? "unchanged" : "changed";
1109
- if (change === "changed") {
1110
- if (before.file.template.plugin !== ct.file.template.plugin ||
1111
- before.file.template.connector !== ct.file.template.connector) {
1112
- throw targetInvalid(`Connector template ${ct.id} moves to another connector (${ct.file.template.plugin} "${ct.file.template.connector}"); uninstall the plugin and install the new version instead`, [
1113
- {
1114
- reason: "template_connector",
1115
- template: ct.id,
1116
- plugin: ct.file.template.plugin,
1117
- connector: ct.file.template.connector,
1118
- },
1119
- ]);
1120
- }
1121
- if (problem !== undefined && mapped.connector) {
953
+ const before = l.file.template;
954
+ const after = ct.file.template;
955
+ if (before.plugin !== after.plugin || before.connector !== after.connector) {
956
+ throw targetInvalid(`Connector template ${ct.id} moves to another connector (${after.plugin} "${after.connector}"); remove the plugin and import the new version as a new plugin instead`, [
957
+ {
958
+ reason: "template_connector",
959
+ template: ct.id,
960
+ plugin: after.plugin,
961
+ connector: after.connector,
962
+ },
963
+ ]);
964
+ }
965
+ const made = await db
966
+ .selectFrom("connectors")
967
+ .select(["id", "org_id", "name", "connector", "endpoint", "auth"])
968
+ .where("platform_template_id", "=", l.id)
969
+ .where("deleted_at", "is", null)
970
+ .orderBy("org_id")
971
+ .orderBy("id")
972
+ .execute();
973
+ if (made.length > 0) {
974
+ const problem = templatePluginProblem(deps, after);
975
+ if (problem !== undefined)
1122
976
  throw new ApiError("catalog.not_deployed", problem);
1123
- }
1124
977
  }
1125
- const credentialsChanged = change === "changed" &&
1126
- mapped.connector !== undefined &&
1127
- credentialKey(mapped.connector.auth) !==
1128
- credentialKey(ct.file.template.auth);
1129
- templates.push({ id: ct.id, change, target: ct.file, ...mapped, credentialsChanged });
978
+ for (const c of made) {
979
+ connectors.push({
980
+ orgId: c.org_id,
981
+ id: c.id,
982
+ name: c.name,
983
+ connector: c.connector,
984
+ endpoint: c.endpoint,
985
+ templateId: ct.id,
986
+ file: ct.file,
987
+ credentialsReset: credentialKey(c.auth) !==
988
+ credentialKey(after.auth),
989
+ });
990
+ }
1130
991
  }
1131
- for (const ct of fromTemplates) {
1132
- if (toTemplates.some((x) => x.id === ct.id))
992
+ for (const l of live.templates) {
993
+ if (toTemplates.some((x) => x.id === l.name))
1133
994
  continue;
1134
- templates.push({
1135
- id: ct.id,
995
+ components.push({
996
+ kind: "connector_template",
997
+ id: l.id,
998
+ name: l.name,
1136
999
  change: "removed",
1137
- ...connectorOf(ct.id),
1138
- credentialsChanged: false,
1000
+ from: l.version,
1001
+ to: null,
1002
+ updatedOnOwn: false,
1003
+ ownScope: l.ownScope,
1004
+ pinnedOrgs: [],
1139
1005
  });
1140
1006
  }
1141
- for (const c of templates) {
1007
+ // Themes (by id, canonical definition and their assets' digest)
1008
+ const toThemes = contents.themes;
1009
+ for (const th of toThemes) {
1010
+ const l = live.themes.find((x) => x.name === th.id);
1011
+ if (!l) {
1012
+ components.push(added("theme", th.id));
1013
+ continue;
1014
+ }
1015
+ const same = canonicalJson(l.definition) === canonicalJson(th.theme) &&
1016
+ l.assetsDigest === th.assetsDigest;
1142
1017
  components.push({
1143
- kind: "connector",
1144
- ref: c.id,
1145
- change: c.change,
1146
- ...(c.credentialsChanged && { detail: "credentials change" }),
1147
- ...(c.change !== "added" &&
1148
- c.change !== "removed" &&
1149
- !c.connector && { detail: "no connector in this organization" }),
1018
+ kind: "theme",
1019
+ id: l.id,
1020
+ name: th.id,
1021
+ change: same ? "same" : direction(l.catalogVersion),
1022
+ from: l.catalogVersion,
1023
+ to: to.version,
1024
+ updatedOnOwn: false,
1025
+ ownScope: l.ownScope,
1026
+ pinnedOrgs: [],
1150
1027
  });
1151
1028
  }
1152
- const inputs = {
1153
- connectors: templates.filter((c) => c.change === "added").map((c) => c.id),
1154
- credentialsChanged: templates.filter((c) => c.credentialsChanged).map((c) => c.id),
1155
- extensionConfig,
1156
- };
1157
- // The inputs (as at install), when given
1158
- const creates = new Map();
1159
- const updates = new Map();
1160
- if (input !== null) {
1161
- for (const k of Object.keys(input.connectors ?? {})) {
1162
- if (!inputs.connectors.includes(k) && !inputs.credentialsChanged.includes(k)) {
1163
- throw fail(`connectors.${k}`, "This upgrade takes no input for this connector template (only added templates and changed credentials)");
1164
- }
1029
+ for (const l of live.themes) {
1030
+ if (toThemes.some((x) => x.id === l.name))
1031
+ continue;
1032
+ components.push({
1033
+ kind: "theme",
1034
+ id: l.id,
1035
+ name: l.name,
1036
+ change: "removed",
1037
+ from: l.catalogVersion,
1038
+ to: null,
1039
+ updatedOnOwn: false,
1040
+ ownScope: l.ownScope,
1041
+ pinnedOrgs: [],
1042
+ });
1043
+ }
1044
+ // The orgs where the plugin is on (a live install; builtin: every org)
1045
+ const onOrgs = await this.pluginOrgs(itemId, item.builtin);
1046
+ if (extension)
1047
+ extension = { ...extension, orgs: onOrgs };
1048
+ // Rule 10: an added skill must not take a name already used where the plugin is on
1049
+ const conflicts = [];
1050
+ for (const c of components) {
1051
+ if (c.kind !== "skill" || c.change !== "added")
1052
+ continue;
1053
+ for (const orgId of onOrgs) {
1054
+ const ids = [
1055
+ ...(await clashingOrgSkills(db, orgId, { id: "", itemId }, c.name)),
1056
+ ...(await clashingPlatformSkills(db, orgId, { id: "" }, c.name)).map((x) => x.id),
1057
+ ];
1058
+ if (ids.length > 0)
1059
+ conflicts.push({ skill: c.name, orgId, conflicts: ids.sort() });
1165
1060
  }
1166
- if (input.extensionConfig !== undefined && !inputs.extensionConfig) {
1167
- throw fail("extensionConfig", "This upgrade does not enable the plugin's extension");
1061
+ }
1062
+ if (conflicts.length > 0) {
1063
+ throw new ApiError("plugin.skill_conflict", `The update adds skills whose names organizations already use where the plugin is on (${[...new Set(conflicts.map((c) => c.skill))].join(", ")}); remove or rename those skills first`, conflicts);
1064
+ }
1065
+ // Themes spec §7: an update never removes the platform default theme; rule 10 (§6): an added
1066
+ // theme must not take an id already on where the plugin is on
1067
+ const removedThemes = components
1068
+ .filter((c) => c.kind === "theme" && c.change === "removed" && c.id !== null)
1069
+ .map((c) => c.id);
1070
+ await assertNotPlatformDefault(db, removedThemes, () => "gone");
1071
+ const themeConflicts = [];
1072
+ for (const c of components) {
1073
+ if (c.kind !== "theme" || c.change !== "added")
1074
+ continue;
1075
+ for (const orgId of onOrgs) {
1076
+ const clash = await themeIdClashes(db, orgId, null, c.name);
1077
+ if (clash.length > 0) {
1078
+ themeConflicts.push({
1079
+ theme: c.name,
1080
+ orgId,
1081
+ themes: clash.map((x) => x.id),
1082
+ plugins: clash.map((x) => x.plugin ?? "platform"),
1083
+ });
1084
+ }
1168
1085
  }
1169
- for (const c of templates) {
1170
- if (c.change === "added") {
1171
- creates.set(c.id, this.installer.planConnector(actor, { itemId, version: to.version, name }, { id: c.id, file: c.target }, input, "", undefined));
1086
+ }
1087
+ if (themeConflicts.length > 0) {
1088
+ throw new ApiError("theme.id_taken", `The update adds themes whose ids are already on in organizations where the plugin is on (${[...new Set(themeConflicts.map((c) => c.theme))].join(", ")}); switch those themes off there first`, themeConflicts);
1089
+ }
1090
+ const themes = await this.themesLost(removedThemes);
1091
+ // Pinned copies (in orgs where the component is on) and removed components agents use
1092
+ for (const kind of ["skill", "agent_template"]) {
1093
+ const mine = components.filter((c) => c.kind === kind && c.id !== null);
1094
+ if (mine.length === 0)
1095
+ continue;
1096
+ const pins = kind === "skill"
1097
+ ? await db
1098
+ .selectFrom("skills")
1099
+ .select(["org_id", "platform_skill_id as platform_id"])
1100
+ .where("platform_skill_id", "in", mine.map((c) => c.id))
1101
+ .where("pinned_version", "is not", null)
1102
+ .where("deleted_at", "is", null)
1103
+ .execute()
1104
+ : await db
1105
+ .selectFrom("agent_templates")
1106
+ .select(["org_id", "platform_template_id as platform_id"])
1107
+ .where("platform_template_id", "in", mine.map((c) => c.id))
1108
+ .where("pinned_version", "is not", null)
1109
+ .where("deleted_at", "is", null)
1110
+ .execute();
1111
+ const facts = mine.map((c) => {
1112
+ const l = (kind === "skill" ? live.skills : live.agentTemplates).find((x) => x.id === c.id);
1113
+ return {
1114
+ id: c.id,
1115
+ itemId,
1116
+ scopeMode: l?.scopeMode ?? "follow",
1117
+ scope: l?.scope ?? "optional",
1118
+ disabled: l?.disabled ?? false,
1119
+ };
1120
+ });
1121
+ const st = await loadScopeState(db, kind, facts);
1122
+ for (const c of mine) {
1123
+ const f = facts.find((x) => x.id === c.id);
1124
+ if (!f)
1172
1125
  continue;
1173
- }
1174
- if (c.change !== "changed" || !c.connector || !c.target)
1126
+ const orgsPinned = [
1127
+ ...new Set(pins.filter((p) => p.platform_id === c.id).map((p) => p.org_id)),
1128
+ ];
1129
+ c.pinnedOrgs = orgsPinned
1130
+ .filter((orgId) => componentOn(f, pluginFactsOf(st, itemId, orgId), listedIn(st, f.id, orgId), switchOf(st, f.id, orgId)))
1131
+ .sort();
1132
+ if (c.change !== "removed")
1175
1133
  continue;
1176
- updates.set(c.id, this.templateUpdate(itemId, to.version, c, input));
1134
+ const kept = [];
1135
+ for (const orgId of await this.liveOrgs()) {
1136
+ const agents = await agentsUsing(db, orgId, kind, [c.id]);
1137
+ if (agents.length > 0) {
1138
+ kept.push({ orgId, agents: agents.map((a) => ({ id: a.id, name: a.name })) });
1139
+ }
1140
+ }
1141
+ if (kept.length > 0)
1142
+ c.kept = kept;
1177
1143
  }
1178
1144
  }
1179
- const actions = new Set([
1180
- ...requiredActions(from.manifest),
1181
- ...requiredActions(to.manifest),
1182
- ]);
1183
- for (const dep of dependencies)
1184
- if (dep.plan)
1185
- for (const a of planActions(dep.plan))
1186
- actions.add(a);
1187
- const removedDeps = dependencies.filter((x) => x.change === "removed" && x.child);
1188
- if (removedDeps.length > 0) {
1189
- const manifests = await db
1190
- .selectFrom("plugin_installs as a")
1191
- .innerJoin("catalog_item_versions as v", (j) => j.onRef("v.item_id", "=", "a.item_id").onRef("v.version", "=", "a.version"))
1192
- .select("v.manifest")
1193
- .where("a.id", "in", removedDeps.map((x) => x.child?.installId))
1194
- .execute();
1195
- for (const m of manifests)
1196
- for (const a of requiredActions(m.manifest))
1197
- actions.add(a);
1145
+ // The org connectors: changed templates' connectors, templates turned on (needing input) or off
1146
+ const addedTemplates = components
1147
+ .filter((c) => c.kind === "connector_template" && c.change === "added")
1148
+ .map((c) => c.name)
1149
+ // an added template shipped off is on nowhere (no org can have switched it on yet)
1150
+ .filter((id) => {
1151
+ const f = toTemplates.find((x) => x.id === id)?.file;
1152
+ return item.builtin || f === undefined || !shippedOff(f);
1153
+ });
1154
+ const byOrg = new Map();
1155
+ const entry = (orgId) => {
1156
+ const e = byOrg.get(orgId) ?? { orgId, connectors: [], needsConfig: [] };
1157
+ byOrg.set(orgId, e);
1158
+ return e;
1159
+ };
1160
+ for (const c of connectors) {
1161
+ entry(c.orgId).connectors.push({
1162
+ id: c.id,
1163
+ name: c.name,
1164
+ templateId: c.templateId,
1165
+ credentialsReset: c.credentialsReset,
1166
+ });
1198
1167
  }
1199
- const lh = ledgerHash(ledger);
1168
+ if (addedTemplates.length > 0) {
1169
+ for (const orgId of onOrgs) {
1170
+ const on = await connectorTemplatesOn(db, orgId, itemId, addedTemplates);
1171
+ if (on.size > 0)
1172
+ entry(orgId).needsConfig.push(...on);
1173
+ }
1174
+ }
1175
+ if (flipped.size > 0) {
1176
+ const ids = [...flipped.keys()].sort();
1177
+ for (const orgId of onOrgs) {
1178
+ const before = await connectorTemplatesOn(db, orgId, itemId, ids);
1179
+ const after = await connectorTemplatesOn(db, orgId, itemId, ids, flipped);
1180
+ for (const id of ids) {
1181
+ const platformId = flippedIds.get(id);
1182
+ if (after.has(id) && !before.has(id)) {
1183
+ // connectors already made from it (it was on before) need no input
1184
+ if ((await connectorsMadeFrom(db, orgId, platformId)) === 0) {
1185
+ entry(orgId).needsConfig.push(id);
1186
+ }
1187
+ }
1188
+ else if (before.has(id) && !after.has(id)) {
1189
+ const agents = await agentsUsing(db, orgId, "connector_template", [platformId]);
1190
+ const e = entry(orgId);
1191
+ e.turnedOff = [
1192
+ ...(e.turnedOff ?? []),
1193
+ {
1194
+ templateId: id,
1195
+ agents: agents.map((a) => ({ id: a.id, name: a.name })),
1196
+ connectorsKept: await connectorsMadeFrom(db, orgId, platformId),
1197
+ },
1198
+ ];
1199
+ }
1200
+ }
1201
+ }
1202
+ }
1203
+ const connectorOrgs = [...byOrg.values()]
1204
+ .map((e) => ({
1205
+ ...e,
1206
+ needsConfig: e.needsConfig.sort(),
1207
+ connectors: e.connectors.sort((a, b) => `${a.templateId}\0${a.id}`.localeCompare(`${b.templateId}\0${b.id}`)),
1208
+ }))
1209
+ .sort((a, b) => a.orgId.localeCompare(b.orgId));
1210
+ components.sort((a, b) => KIND_ORDER[a.kind] - KIND_ORDER[b.kind] || a.name.localeCompare(b.name));
1200
1211
  const diffHash = sha256(canonicalJson({
1201
- installId,
1202
- from: from.version,
1212
+ itemId,
1213
+ from,
1203
1214
  to: to.version,
1204
- fromFiles: filesDigest(from),
1205
- toFiles: filesDigest(to),
1206
- ledger: lh,
1215
+ manifest: to.manifest,
1216
+ files: filesDigest(to),
1217
+ // `needsApproval` is shown only: it does not change what the confirm does
1218
+ extension: extension && {
1219
+ from: extension.from,
1220
+ to: extension.to,
1221
+ orgs: extension.orgs,
1222
+ sha256: extension.sha256,
1223
+ },
1207
1224
  components,
1208
- inputs,
1225
+ connectors: connectors.map((c) => ({
1226
+ id: c.id,
1227
+ endpoint: c.endpoint,
1228
+ reset: c.credentialsReset,
1229
+ })),
1230
+ connectorOrgs,
1231
+ // only when present: a diff without themes keeps the hash it had before themes
1232
+ ...(themes !== undefined && { themes }),
1209
1233
  }));
1210
1234
  return {
1211
- installId,
1212
1235
  itemId,
1213
1236
  name,
1214
1237
  from,
1215
1238
  to,
1216
- ledger,
1239
+ components,
1217
1240
  extension,
1218
- skills,
1219
- agentTemplates,
1220
- templates,
1241
+ connectors,
1242
+ connectorOrgs,
1243
+ ...(themes !== undefined && { themes }),
1244
+ contents,
1221
1245
  dependencies,
1222
- components,
1223
- inputs,
1224
1246
  diffHash,
1225
- ledgerHash: lh,
1226
- actions: [...actions],
1227
- creates,
1228
- updates,
1229
1247
  };
1230
1248
  }
1231
1249
  /**
1232
- * The update of a changed template's connector: the new endpoint preset with the org's values at
1233
- * the editable paths, the new auth preset and policies; credentials only when the auth method or
1234
- * the credentials it needs changed (then the input must give what the template needs).
1250
+ * The target's skill names, agent templates, connector templates and themes, from object storage
1251
+ * (a theme failing its checks -> 400 `theme.invalid`, themes spec §6).
1235
1252
  */
1236
- templateUpdate(itemId, version, c, input) {
1237
- const template = c.target.template;
1238
- const connector = c.connector;
1239
- const path = `connectors.${c.id}`;
1240
- const given = input.connectors?.[c.id];
1241
- if (given !== undefined) {
1242
- for (const k of ["name", "slug", "endpoint"]) {
1243
- if (given[k] !== undefined) {
1244
- throw fail(`${path}.${k}`, "An existing connector keeps its name, slug and endpoint fields");
1245
- }
1253
+ async readContents(to) {
1254
+ return {
1255
+ skillNames: await catalogSkillNames(this.storage, to, to.manifest),
1256
+ agents: await readCatalogAgentTemplates(this.storage, to),
1257
+ templates: await readCatalogTemplates(this.storage, to),
1258
+ themes: await readCatalogThemes(this.storage, to),
1259
+ };
1260
+ }
1261
+ /**
1262
+ * Whether the target's extension package asks for permissions the approved snapshot does not
1263
+ * cover (no snapshot, or a blocking addition): it then loads only once approved (§7.4).
1264
+ */
1265
+ async needsApproval(name, sha) {
1266
+ if (this.config.get().extensionPermissions.autoApprove)
1267
+ return false;
1268
+ const pkg = await readExtensionPackage(await this.blobs.get(sha), {
1269
+ maxBytes: this.config.get().packages.maxBytes,
1270
+ hostSdkVersion: SDK_VERSION,
1271
+ });
1272
+ const snap = await this.db
1273
+ .selectFrom("extension_permission_snapshots")
1274
+ .select("permissions")
1275
+ .where("plugin", "=", name)
1276
+ .executeTakeFirst();
1277
+ if (!snap)
1278
+ return true;
1279
+ const { added } = diffPermissions(snap.permissions, permissionSetOfPackage(pkg));
1280
+ return blockingKeys(added).length > 0;
1281
+ }
1282
+ /**
1283
+ * The deployment's extension step: none when the target carries the extension the deployment
1284
+ * runs; a version without the extension the deployment runs for the plugin is refused, except
1285
+ * for an owner update (`allowRemove`, ruling P3-12': removing code runs none), which removes an
1286
+ * installed one; a move of a config-declared extension is refused.
1287
+ */
1288
+ async extensionTarget(name, from, to, allowRemove = false) {
1289
+ const want = to.manifest.extension;
1290
+ const row = await this.db
1291
+ .selectFrom("extension_installs")
1292
+ .select(["sha256", "version"])
1293
+ .where("name", "=", name)
1294
+ .executeTakeFirst();
1295
+ // Only an extension declared in the startup config runs without an install record; one this
1296
+ // replica still has loaded after its uninstall (until its reconcile) does not count
1297
+ const declared = this.registry.declared().get(name) === "config";
1298
+ const loaded = declared ? this.registry.manifests().find((m) => m.name === name) : undefined;
1299
+ if (!want) {
1300
+ if (allowRemove && from?.manifest.extension && row && !declared) {
1301
+ return { from: row.version, to: null, sha256: null, previous: row.sha256 };
1246
1302
  }
1303
+ if (from?.manifest.extension && (row || declared)) {
1304
+ throw targetInvalid(`Version ${to.version} of plugin ${name} has no extension, but the deployment runs it; uninstall the extension first`, [{ reason: "extension_removed", version: to.version }]);
1305
+ }
1306
+ return null;
1247
1307
  }
1248
- const endpoint = structuredClone(template.endpoint);
1249
- for (const e of template.editableEndpoint ?? []) {
1250
- const v = getPath(connector.endpoint, e);
1251
- if (v !== undefined)
1252
- setPath(endpoint, e, v);
1308
+ if (row) {
1309
+ if (row.sha256 === to.extension_sha256)
1310
+ return null;
1253
1311
  }
1254
- const auth = template.auth;
1255
- const oauth = auth.type === "oauth_code" || auth.type === "oauth_client";
1256
- if (c.credentialsChanged) {
1257
- const missing = missingTemplateInput(template, given, { personalCredential: false });
1258
- if (missing !== undefined) {
1259
- throw fail(`${path}.${missing}`, `The auth method of this connector template changed; it needs ${missing === "client" ? "an OAuth client" : "an org credential"}`);
1260
- }
1261
- if (oauth && given?.credential !== undefined) {
1262
- throw fail(`${path}.credential`, "This connector uses OAuth; provide client instead");
1263
- }
1264
- if (!oauth && given?.client !== undefined) {
1265
- throw fail(`${path}.client`, "This connector does not use OAuth; provide credential instead");
1266
- }
1312
+ else if (declared) {
1313
+ if (loaded?.version === want.manifest.version)
1314
+ return null;
1315
+ throw targetInvalid(`The extension of plugin ${name} is declared in the startup config at version ${loaded?.version ?? "(not loaded)"}; it cannot be moved to ${want.manifest.version} by an update`, [{ reason: "config_extension", deploymentVersion: loaded?.version ?? null }]);
1316
+ }
1317
+ if (to.extension_sha256 === null) {
1318
+ throw targetInvalid(`Version ${to.version} of plugin ${name} has no extension package`, [
1319
+ { reason: "extension_package", version: to.version },
1320
+ ]);
1267
1321
  }
1268
- const credential = oauth ? given?.client : given?.credential;
1269
1322
  return {
1270
- endpoint,
1271
- auth,
1272
- template: {
1273
- itemId,
1274
- version,
1275
- templateId: c.id,
1276
- ...(template.defaultToolPolicies !== undefined && {
1277
- defaultToolPolicies: template.defaultToolPolicies,
1278
- }),
1279
- },
1280
- resetCredentials: c.credentialsChanged,
1281
- ...(c.credentialsChanged && credential !== undefined && { credential }),
1323
+ from: row?.version ?? null,
1324
+ to: want.manifest.version,
1325
+ sha256: to.extension_sha256,
1326
+ previous: row?.sha256 ?? null,
1282
1327
  };
1283
1328
  }
1329
+ /**
1330
+ * Other platform plugins depending on this one must accept the target (their platform version's
1331
+ * dependency range); returns the catalog items of the target's own dependencies (their scope
1332
+ * sync is owed with the update: rule 9).
1333
+ */
1334
+ async checkDependents(name, to) {
1335
+ const rows = await this.db
1336
+ .selectFrom("catalog_items as i")
1337
+ .innerJoin("catalog_item_versions as v", (j) => j
1338
+ .onRef("v.item_id", "=", "i.id")
1339
+ .on(sql `v.version`, "=", sql `coalesce(i.platform_synced_version, i.latest_version)`))
1340
+ .select(["i.id", "i.name", "v.manifest"])
1341
+ .where("i.deleted_at", "is", null)
1342
+ .execute();
1343
+ for (const r of rows) {
1344
+ if (r.name === name)
1345
+ continue;
1346
+ const range = r.manifest.dependencies?.find((d) => d.name === name)?.version;
1347
+ if (range !== undefined && !satisfiesRange(to.version, range)) {
1348
+ throw targetInvalid(`Plugin ${r.name} depends on ${name}@${range}, which version ${to.version} does not satisfy`, [{ reason: "dependent_range", dependent: r.name, range, version: to.version }]);
1349
+ }
1350
+ }
1351
+ const wanted = new Set((to.manifest.dependencies ?? []).map((d) => d.name));
1352
+ return rows.filter((r) => wanted.has(r.name)).map((r) => r.id);
1353
+ }
1354
+ /** The plugin's live platform components with their current versions. */
1355
+ async liveComponents(itemId) {
1356
+ const db = this.db;
1357
+ const skills = (await db
1358
+ .selectFrom("platform_skills as p")
1359
+ .innerJoin("platform_skill_versions as v", (j) => j.onRef("v.skill_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
1360
+ .select([
1361
+ "p.id",
1362
+ "p.name",
1363
+ "p.scope_mode",
1364
+ "p.scope",
1365
+ "p.disabled",
1366
+ "v.manifest",
1367
+ "v.catalog_version",
1368
+ "v.updated_on_own",
1369
+ ])
1370
+ .where("p.catalog_item_id", "=", itemId)
1371
+ .where("p.deleted_at", "is", null)
1372
+ .execute()).map((r) => ({
1373
+ id: r.id,
1374
+ name: r.name,
1375
+ scopeMode: r.scope_mode,
1376
+ scope: r.scope,
1377
+ disabled: r.disabled,
1378
+ manifest: r.manifest,
1379
+ catalogVersion: r.catalog_version,
1380
+ updatedOnOwn: r.updated_on_own,
1381
+ ownScope: r.scope_mode === "own",
1382
+ }));
1383
+ const agentTemplates = (await db
1384
+ .selectFrom("platform_agent_templates as p")
1385
+ .innerJoin("platform_agent_template_versions as v", (j) => j.onRef("v.template_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
1386
+ .select([
1387
+ "p.id",
1388
+ "p.name",
1389
+ "p.scope_mode",
1390
+ "p.scope",
1391
+ "p.disabled",
1392
+ "v.definition",
1393
+ "v.catalog_version",
1394
+ "v.updated_on_own",
1395
+ ])
1396
+ .where("p.catalog_item_id", "=", itemId)
1397
+ .where("p.deleted_at", "is", null)
1398
+ .execute()).map((r) => ({
1399
+ id: r.id,
1400
+ name: r.name,
1401
+ scopeMode: r.scope_mode,
1402
+ scope: r.scope,
1403
+ disabled: r.disabled,
1404
+ definition: r.definition,
1405
+ catalogVersion: r.catalog_version,
1406
+ updatedOnOwn: r.updated_on_own,
1407
+ ownScope: r.scope_mode === "own",
1408
+ }));
1409
+ const templates = (await db
1410
+ .selectFrom("platform_connector_templates")
1411
+ .select(["id", "template_id", "current_version", "file", "scope_mode"])
1412
+ .where("catalog_item_id", "=", itemId)
1413
+ .where("deleted_at", "is", null)
1414
+ .execute()).map((r) => ({
1415
+ id: r.id,
1416
+ name: r.template_id,
1417
+ version: r.current_version,
1418
+ file: r.file,
1419
+ ownScope: r.scope_mode === "own",
1420
+ }));
1421
+ const themes = (await db
1422
+ .selectFrom("platform_themes as p")
1423
+ .innerJoin("platform_theme_versions as v", (j) => j.onRef("v.theme_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
1424
+ .leftJoin("catalog_item_versions as cv", (j) => j
1425
+ .onRef("cv.item_id", "=", "p.catalog_item_id")
1426
+ .onRef("cv.version", "=", "v.catalog_version"))
1427
+ .select(["p.id", "p.name", "p.scope_mode", "v.definition", "v.catalog_version", "cv.files"])
1428
+ .where("p.catalog_item_id", "=", itemId)
1429
+ .where("p.deleted_at", "is", null)
1430
+ .execute()).map((r) => ({
1431
+ id: r.id,
1432
+ name: r.name,
1433
+ definition: r.definition,
1434
+ catalogVersion: r.catalog_version,
1435
+ // no recorded files (should not happen): never equal, the update writes a new version
1436
+ assetsDigest: r.files === null ? null : themeAssetsDigest(r.files, r.definition),
1437
+ ownScope: r.scope_mode === "own",
1438
+ }));
1439
+ return { skills, agentTemplates, templates, themes };
1440
+ }
1441
+ /** The `themes` block of the preview: the orgs each of the removed themes `ids` is on in. */
1442
+ async themesLost(ids) {
1443
+ if (ids.length === 0)
1444
+ return undefined;
1445
+ const comps = await loadComponents(this.db, "theme", { ids });
1446
+ const st = await loadScopeState(this.db, "theme", comps);
1447
+ const orgs = await this.liveOrgs();
1448
+ const lost = new Map();
1449
+ for (const c of comps) {
1450
+ const on = orgs.filter((orgId) => componentOn(c, pluginFactsOf(st, c.itemId, orgId), listedIn(st, c.id, orgId), switchOf(st, c.id, orgId)));
1451
+ lost.set(c.id, new Set(on));
1452
+ }
1453
+ return themesPreview(this.db, lost);
1454
+ }
1455
+ /** The orgs where the plugin is on: a live install (builtin: every live org). */
1456
+ async pluginOrgs(itemId, builtin) {
1457
+ if (builtin)
1458
+ return this.liveOrgs();
1459
+ const rows = await this.db
1460
+ .selectFrom("plugin_installs as a")
1461
+ .innerJoin("orgs as o", "o.id", "a.org_id")
1462
+ .select("a.org_id")
1463
+ .distinct()
1464
+ .where("a.item_id", "=", itemId)
1465
+ .where("a.status", "in", ["installing", "installed", "upgrading"])
1466
+ .where("o.deleted_at", "is", null)
1467
+ .orderBy("a.org_id")
1468
+ .execute();
1469
+ return rows.map((r) => r.org_id);
1470
+ }
1471
+ async liveOrgs() {
1472
+ const rows = await this.db
1473
+ .selectFrom("orgs")
1474
+ .select("id")
1475
+ .where("deleted_at", "is", null)
1476
+ .orderBy("id")
1477
+ .execute();
1478
+ return rows.map((r) => r.id);
1479
+ }
1284
1480
  };
1285
1481
  __decorate([
1286
1482
  Transactional()
1287
- ], PluginUpgrader.prototype, "authorizeActions", null);
1288
- __decorate([
1289
- Transactional({ propagation: "requires_new" })
1290
- ], PluginUpgrader.prototype, "start", null);
1291
- __decorate([
1292
- Transactional({ propagation: "requires_new" })
1293
- ], PluginUpgrader.prototype, "journalSkill", null);
1294
- __decorate([
1295
- Transactional({ propagation: "requires_new" })
1296
- ], PluginUpgrader.prototype, "upgradeAgentTemplate", null);
1297
- __decorate([
1298
- Transactional({ propagation: "requires_new" })
1299
- ], PluginUpgrader.prototype, "recordStep", null);
1483
+ ], PlatformPluginUpdater.prototype, "authorizeOwner", null);
1300
1484
  __decorate([
1301
1485
  Transactional({ propagation: "requires_new" })
1302
- ], PluginUpgrader.prototype, "finish", null);
1486
+ ], PlatformPluginUpdater.prototype, "auditFailure", null);
1303
1487
  __decorate([
1304
1488
  Transactional({ propagation: "requires_new" })
1305
- ], PluginUpgrader.prototype, "undoFailed", null);
1306
- __decorate([
1307
- Transactional({ propagation: "requires_new" })
1308
- ], PluginUpgrader.prototype, "undoInterrupted", null);
1309
- __decorate([
1310
- Transactional({ propagation: "mandatory" })
1311
- ], PluginUpgrader.prototype, "removeIn", null);
1312
- PluginUpgrader = __decorate([
1489
+ ], PlatformPluginUpdater.prototype, "commit", null);
1490
+ PlatformPluginUpdater = __decorate([
1313
1491
  Injectable(),
1314
- __param(0, Inject(PluginInstaller)),
1315
- __param(1, Inject(KernelDb)),
1316
- __param(2, Inject(OrgLock)),
1317
- __param(3, Inject(StorageService)),
1318
- __param(4, Inject(ExtensionRegistry)),
1319
- __param(5, Inject(SkillsService)),
1320
- __param(6, Inject(OrgExtensionConfigs)),
1321
- __param(7, Inject(CatalogRequestsService)),
1322
- __param(8, Inject(ConnectorsService)),
1323
- __param(9, Inject(KERNEL_LOGGER)),
1324
- __param(10, Inject(TransactionHost))
1325
- ], PluginUpgrader);
1326
- export { PluginUpgrader };
1327
- const cleanedUp = () => new ApiError("plugin.install_not_found", "The upgrade was cleaned up as interrupted while it was running");
1328
- /** The install's ledger rows. */
1329
- function ledgerOf(db, installId) {
1330
- return db
1331
- .selectFrom("plugin_install_components")
1332
- .select(["kind", "ref", "created", "skill_version", "template_id", "dropped"])
1333
- .where("install_id", "=", installId)
1334
- .orderBy("kind")
1335
- .orderBy("ref")
1336
- .execute();
1492
+ __param(0, Inject(KernelDb)),
1493
+ __param(1, Inject(TransactionHost)),
1494
+ __param(2, Inject(SuperAdminLock)),
1495
+ __param(3, Inject(CatalogItemLock)),
1496
+ __param(4, Inject(OrgLock)),
1497
+ __param(5, Inject(LockService)),
1498
+ __param(6, Inject(StorageService)),
1499
+ __param(7, Inject(ExtensionRegistry)),
1500
+ __param(8, Inject(ExtensionAdminOps)),
1501
+ __param(9, Inject(ExtensionBlobs)),
1502
+ __param(10, Inject(KernelConfigService)),
1503
+ __param(11, Inject(PlatformComponents)),
1504
+ __param(12, Inject(PluginInstaller)),
1505
+ __param(13, Inject(ConnectorsService)),
1506
+ __param(14, Inject(PluginScopeSync)),
1507
+ __param(15, Inject(KERNEL_LOGGER)),
1508
+ __param(16, Inject(PluginGuides))
1509
+ ], PlatformPluginUpdater);
1510
+ export { PlatformPluginUpdater };
1511
+ /** The preview of a diff (without `guideChanges`, which reads PG). */
1512
+ function previewOf(d) {
1513
+ return {
1514
+ itemId: d.itemId,
1515
+ name: d.name,
1516
+ from: d.from,
1517
+ to: d.to.version,
1518
+ components: d.components,
1519
+ extension: extensionView(d.extension),
1520
+ connectorOrgs: d.connectorOrgs,
1521
+ ...(d.themes !== undefined && { themes: d.themes }),
1522
+ diffHash: d.diffHash,
1523
+ };
1337
1524
  }
1338
- /** A fingerprint of the ledger (order independent). */
1339
- function ledgerHash(rows) {
1340
- return sha256(rows
1341
- .map((r) => `${r.kind}\0${r.ref}\0${r.created}\0${r.skill_version}\0${r.template_id}\0${r.dropped}\n`)
1342
- .sort()
1343
- .join(""));
1525
+ /** The extension step as the preview and the result show it. */
1526
+ function extensionView(e) {
1527
+ return e && { from: e.from, to: e.to, orgs: e.orgs, needsApproval: e.needsApproval };
1344
1528
  }