@capybara-hq/kernel 0.1.0-rc.1 → 0.1.0-rc.100

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 (1955) hide show
  1. package/bootstrap.json +113 -6
  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 +66 -89
  9. package/dist/admin/admin.controller.js +153 -92
  10. package/dist/admin/admin.module.d.ts +8 -0
  11. package/dist/admin/admin.module.js +92 -0
  12. package/dist/admin/admin.schemas.d.ts +110 -0
  13. package/dist/admin/admin.schemas.js +54 -0
  14. package/dist/admin/audit-log.service.d.ts +52 -0
  15. package/dist/admin/audit-log.service.js +81 -0
  16. package/dist/admin/audit.controller.d.ts +26 -0
  17. package/dist/admin/audit.controller.js +72 -0
  18. package/dist/admin/audit.schemas.d.ts +16 -0
  19. package/dist/admin/audit.schemas.js +37 -0
  20. package/dist/admin/extensions.controller.d.ts +72 -18
  21. package/dist/admin/extensions.controller.js +144 -26
  22. package/dist/admin/extensions.schemas.d.ts +28 -0
  23. package/dist/admin/extensions.schemas.js +49 -0
  24. package/dist/admin/health.service.d.ts +111 -0
  25. package/dist/admin/health.service.js +286 -0
  26. package/dist/admin/limit-defaults.d.ts +20 -0
  27. package/dist/admin/limit-defaults.js +10 -0
  28. package/dist/admin/login-sources.controller.d.ts +30 -0
  29. package/dist/admin/login-sources.controller.js +77 -0
  30. package/dist/admin/login-sources.schemas.d.ts +25 -0
  31. package/dist/admin/login-sources.schemas.js +49 -0
  32. package/dist/admin/org-network.controller.d.ts +30 -0
  33. package/dist/admin/org-network.controller.js +77 -0
  34. package/dist/admin/org-network.schemas.d.ts +16 -0
  35. package/dist/admin/org-network.schemas.js +27 -0
  36. package/dist/admin/org-network.service.d.ts +43 -0
  37. package/dist/admin/org-network.service.js +109 -0
  38. package/dist/admin/outbox-dead.controller.d.ts +21 -0
  39. package/dist/admin/outbox-dead.controller.js +65 -0
  40. package/dist/admin/outbox-dead.schemas.d.ts +24 -0
  41. package/dist/admin/outbox-dead.schemas.js +42 -0
  42. package/dist/admin/outbox-dead.service.d.ts +81 -0
  43. package/dist/admin/outbox-dead.service.js +264 -0
  44. package/dist/admin/overview.controller.d.ts +31 -0
  45. package/dist/admin/overview.controller.js +78 -0
  46. package/dist/admin/overview.schemas.d.ts +8 -0
  47. package/dist/admin/overview.schemas.js +13 -0
  48. package/dist/admin/overview.service.d.ts +147 -0
  49. package/dist/admin/overview.service.js +256 -0
  50. package/dist/admin/setup-lock.d.ts +16 -0
  51. package/dist/admin/setup-lock.js +47 -0
  52. package/dist/admin/setup.controller.d.ts +9 -9
  53. package/dist/admin/setup.controller.js +28 -26
  54. package/dist/admin/setup.service.d.ts +20 -28
  55. package/dist/admin/setup.service.js +65 -65
  56. package/dist/admin/usage.service.d.ts +149 -0
  57. package/dist/admin/usage.service.js +321 -0
  58. package/dist/agents/admin-agents.d.ts +106 -0
  59. package/dist/agents/admin-agents.js +234 -0
  60. package/dist/agents/agent-lookup.d.ts +80 -0
  61. package/dist/agents/agent-lookup.js +223 -0
  62. package/dist/agents/agent-profile.service.d.ts +34 -0
  63. package/dist/agents/agent-profile.service.js +136 -0
  64. package/dist/agents/agents.controller.d.ts +48 -171
  65. package/dist/agents/agents.controller.js +167 -40
  66. package/dist/agents/agents.module.d.ts +11 -0
  67. package/dist/agents/agents.module.js +84 -0
  68. package/dist/agents/agents.schemas.d.ts +450 -0
  69. package/dist/agents/agents.schemas.js +145 -0
  70. package/dist/agents/agents.service.d.ts +171 -78
  71. package/dist/agents/agents.service.js +704 -409
  72. package/dist/agents/avatar-view.d.ts +8 -0
  73. package/dist/agents/avatar-view.js +12 -0
  74. package/dist/agents/definition.d.ts +153 -24
  75. package/dist/agents/definition.js +246 -57
  76. package/dist/agents/from-template.d.ts +109 -0
  77. package/dist/agents/from-template.js +693 -0
  78. package/dist/agents/from-template.service.d.ts +72 -0
  79. package/dist/agents/from-template.service.js +178 -0
  80. package/dist/agents/instruction-files.d.ts +60 -0
  81. package/dist/agents/instruction-files.js +108 -0
  82. package/dist/agents/models.controller.d.ts +44 -6
  83. package/dist/agents/models.controller.js +84 -8
  84. package/dist/agents/org-templates.d.ts +186 -0
  85. package/dist/agents/org-templates.js +929 -0
  86. package/dist/agents/pending-connector-requests.d.ts +79 -0
  87. package/dist/agents/pending-connector-requests.js +221 -0
  88. package/dist/agents/pending-connectors.controller.d.ts +39 -0
  89. package/dist/agents/pending-connectors.controller.js +91 -0
  90. package/dist/agents/pending-connectors.service.d.ts +62 -0
  91. package/dist/agents/pending-connectors.service.js +284 -0
  92. package/dist/agents/profile.d.ts +139 -0
  93. package/dist/agents/profile.js +66 -0
  94. package/dist/agents/readiness.controller.d.ts +16 -0
  95. package/dist/agents/readiness.controller.js +43 -0
  96. package/dist/agents/readiness.service.d.ts +81 -0
  97. package/dist/agents/readiness.service.js +121 -0
  98. package/dist/agents/templates.controller.d.ts +78 -6
  99. package/dist/agents/templates.controller.js +154 -8
  100. package/dist/agents/templates.d.ts +132 -30
  101. package/dist/agents/templates.js +489 -46
  102. package/dist/agents/templates.schemas.d.ts +20 -0
  103. package/dist/agents/templates.schemas.js +45 -0
  104. package/dist/app.d.ts +99 -0
  105. package/dist/app.js +154 -0
  106. package/dist/attribution/platform-attribution.d.ts +113 -0
  107. package/dist/attribution/platform-attribution.js +166 -0
  108. package/dist/background/background.controller.d.ts +38 -0
  109. package/dist/background/background.controller.js +88 -0
  110. package/dist/background/background.module.d.ts +10 -0
  111. package/dist/background/background.module.js +39 -0
  112. package/dist/background/background.schemas.d.ts +10 -0
  113. package/dist/background/background.schemas.js +16 -0
  114. package/dist/background/finish.d.ts +57 -0
  115. package/dist/background/finish.js +163 -0
  116. package/dist/background/launch-lock.d.ts +15 -0
  117. package/dist/background/launch-lock.js +40 -0
  118. package/dist/background/launch.d.ts +54 -0
  119. package/dist/background/launch.js +93 -0
  120. package/dist/background/managed-output.d.ts +110 -0
  121. package/dist/background/managed-output.js +219 -0
  122. package/dist/background/managed.d.ts +56 -0
  123. package/dist/background/managed.js +131 -0
  124. package/dist/background/poll.job.d.ts +96 -0
  125. package/dist/background/poll.job.js +357 -0
  126. package/dist/background/render.d.ts +32 -0
  127. package/dist/background/render.js +68 -0
  128. package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
  129. package/dist/background/retire-legacy-tasks.job.js +149 -0
  130. package/dist/background/session.d.ts +7 -0
  131. package/dist/background/session.js +7 -0
  132. package/dist/background/stop.d.ts +130 -0
  133. package/dist/background/stop.js +393 -0
  134. package/dist/background/store.d.ts +272 -0
  135. package/dist/background/store.js +589 -0
  136. package/dist/background/store.module.d.ts +6 -0
  137. package/dist/background/store.module.js +22 -0
  138. package/dist/background/tasks.service.d.ts +131 -0
  139. package/dist/background/tasks.service.js +285 -0
  140. package/dist/background/wake-rules.d.ts +71 -0
  141. package/dist/background/wake-rules.js +126 -0
  142. package/dist/background/wake.d.ts +30 -0
  143. package/dist/background/wake.js +63 -0
  144. package/dist/catalog/admin-catalog.controller.d.ts +167 -60
  145. package/dist/catalog/admin-catalog.controller.js +347 -75
  146. package/dist/catalog/admin-catalog.schemas.d.ts +89 -0
  147. package/dist/catalog/admin-catalog.schemas.js +113 -0
  148. package/dist/catalog/appearance.schemas.d.ts +10 -0
  149. package/dist/catalog/appearance.schemas.js +20 -0
  150. package/dist/catalog/appearance.service.d.ts +105 -0
  151. package/dist/catalog/appearance.service.js +304 -0
  152. package/dist/catalog/catalog-content.d.ts +296 -0
  153. package/dist/catalog/catalog-content.js +382 -0
  154. package/dist/catalog/catalog-files.d.ts +42 -0
  155. package/dist/catalog/catalog-files.js +89 -0
  156. package/dist/catalog/catalog-import.module.d.ts +7 -0
  157. package/dist/catalog/catalog-import.module.js +59 -0
  158. package/dist/catalog/catalog-items.d.ts +301 -0
  159. package/dist/catalog/catalog-items.js +702 -0
  160. package/dist/catalog/catalog-scope.service.d.ts +312 -0
  161. package/dist/catalog/catalog-scope.service.js +1265 -0
  162. package/dist/catalog/catalog.module.d.ts +15 -0
  163. package/dist/catalog/catalog.module.js +108 -0
  164. package/dist/catalog/catalog.service.d.ts +162 -205
  165. package/dist/catalog/catalog.service.js +299 -536
  166. package/dist/catalog/claude/agents.js +15 -10
  167. package/dist/catalog/claude/report.d.ts +9 -2
  168. package/dist/catalog/claude/report.js +1 -0
  169. package/dist/catalog/claude/translate.js +5 -2
  170. package/dist/catalog/cli.d.ts +11 -3
  171. package/dist/catalog/cli.js +23 -32
  172. package/dist/catalog/component-promotion.d.ts +96 -0
  173. package/dist/catalog/component-promotion.js +396 -0
  174. package/dist/catalog/component-scope.controller.d.ts +96 -0
  175. package/dist/catalog/component-scope.controller.js +262 -0
  176. package/dist/catalog/component-scope.schemas.d.ts +118 -0
  177. package/dist/catalog/component-scope.schemas.js +99 -0
  178. package/dist/catalog/component-scope.service.d.ts +399 -0
  179. package/dist/catalog/component-scope.service.js +1150 -0
  180. package/dist/catalog/component-state.d.ts +242 -0
  181. package/dist/catalog/component-state.js +532 -0
  182. package/dist/catalog/credential-key.d.ts +10 -0
  183. package/dist/catalog/credential-key.js +28 -0
  184. package/dist/catalog/git-source.d.ts +30 -1
  185. package/dist/catalog/git-source.js +86 -13
  186. package/dist/catalog/install-status.d.ts +6 -0
  187. package/dist/catalog/install-status.js +6 -0
  188. package/dist/catalog/job-ids.d.ts +58 -0
  189. package/dist/catalog/job-ids.js +60 -0
  190. package/dist/catalog/jobs.d.ts +36 -0
  191. package/dist/catalog/jobs.js +91 -0
  192. package/dist/catalog/locks.d.ts +24 -0
  193. package/dist/catalog/locks.js +63 -0
  194. package/dist/catalog/marketplace-fetch.d.ts +16 -4
  195. package/dist/catalog/marketplace-fetch.js +14 -7
  196. package/dist/catalog/marketplace-icons.d.ts +64 -0
  197. package/dist/catalog/marketplace-icons.js +131 -0
  198. package/dist/catalog/marketplaces.controller.d.ts +56 -46
  199. package/dist/catalog/marketplaces.controller.js +151 -53
  200. package/dist/catalog/marketplaces.schemas.d.ts +55 -0
  201. package/dist/catalog/marketplaces.schemas.js +66 -0
  202. package/dist/catalog/marketplaces.service.d.ts +202 -33
  203. package/dist/catalog/marketplaces.service.js +867 -300
  204. package/dist/catalog/org-catalog.controller.d.ts +104 -65
  205. package/dist/catalog/org-catalog.controller.js +210 -102
  206. package/dist/catalog/org-catalog.schemas.d.ts +128 -0
  207. package/dist/catalog/org-catalog.schemas.js +173 -0
  208. package/dist/catalog/org-catalog.service.d.ts +100 -216
  209. package/dist/catalog/org-catalog.service.js +464 -479
  210. package/dist/catalog/org-extension-switch.d.ts +41 -0
  211. package/dist/catalog/org-extension-switch.js +123 -0
  212. package/dist/catalog/org-extension.controller.d.ts +113 -0
  213. package/dist/catalog/org-extension.controller.js +276 -0
  214. package/dist/catalog/org-extension.schemas.d.ts +45 -0
  215. package/dist/catalog/org-extension.schemas.js +85 -0
  216. package/dist/catalog/org-plugin-uploads.controller.d.ts +77 -0
  217. package/dist/catalog/org-plugin-uploads.controller.js +199 -0
  218. package/dist/catalog/org-plugin-uploads.d.ts +68 -0
  219. package/dist/catalog/org-plugin-uploads.js +116 -0
  220. package/dist/catalog/org-plugin-uploads.schemas.d.ts +19 -0
  221. package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
  222. package/dist/catalog/owned-items.d.ts +181 -0
  223. package/dist/catalog/owned-items.js +797 -0
  224. package/dist/catalog/owned-plugin-cleanup.d.ts +47 -0
  225. package/dist/catalog/owned-plugin-cleanup.js +140 -0
  226. package/dist/catalog/ownership.d.ts +172 -0
  227. package/dist/catalog/ownership.js +328 -0
  228. package/dist/catalog/platform-components.d.ts +264 -0
  229. package/dist/catalog/platform-components.js +857 -0
  230. package/dist/catalog/platform-import-update.d.ts +50 -0
  231. package/dist/catalog/platform-import-update.js +116 -0
  232. package/dist/catalog/plugin-import.d.ts +381 -79
  233. package/dist/catalog/plugin-import.js +1213 -336
  234. package/dist/catalog/plugin-install.d.ts +337 -142
  235. package/dist/catalog/plugin-install.js +1278 -508
  236. package/dist/catalog/plugin-package.d.ts +55 -13
  237. package/dist/catalog/plugin-package.js +227 -33
  238. package/dist/catalog/plugin-upgrade.d.ts +405 -188
  239. package/dist/catalog/plugin-upgrade.js +1559 -1079
  240. package/dist/catalog/request-rules.d.ts +65 -0
  241. package/dist/catalog/request-rules.js +223 -0
  242. package/dist/catalog/requests.service.d.ts +266 -116
  243. package/dist/catalog/requests.service.js +819 -355
  244. package/dist/catalog/reserved-names.d.ts +8 -0
  245. package/dist/catalog/reserved-names.js +36 -0
  246. package/dist/catalog/scope-jobs.d.ts +59 -0
  247. package/dist/catalog/scope-jobs.js +78 -0
  248. package/dist/catalog/scope-orgs.d.ts +21 -0
  249. package/dist/catalog/scope-orgs.js +67 -0
  250. package/dist/catalog/scope-state.d.ts +35 -0
  251. package/dist/catalog/scope-state.js +87 -0
  252. package/dist/catalog/scope-sync-workers.d.ts +30 -0
  253. package/dist/catalog/scope-sync-workers.js +100 -0
  254. package/dist/catalog/scope-sync.d.ts +154 -0
  255. package/dist/catalog/scope-sync.js +512 -0
  256. package/dist/catalog/scope.d.ts +42 -0
  257. package/dist/catalog/scope.js +42 -0
  258. package/dist/catalog/template-connector-ensure.d.ts +100 -0
  259. package/dist/catalog/template-connector-ensure.js +285 -0
  260. package/dist/catalog/template-connector-jobs.d.ts +28 -0
  261. package/dist/catalog/template-connector-jobs.js +54 -0
  262. package/dist/catalog/template-connector-reconcile.d.ts +44 -0
  263. package/dist/catalog/template-connector-reconcile.js +114 -0
  264. package/dist/catalog/template-connectors.processor.d.ts +32 -0
  265. package/dist/catalog/template-connectors.processor.js +101 -0
  266. package/dist/catalog/template-description.d.ts +17 -0
  267. package/dist/catalog/template-description.js +18 -0
  268. package/dist/catalog/unshare.d.ts +21 -0
  269. package/dist/catalog/unshare.js +119 -0
  270. package/dist/channels/actions.d.ts +8 -4
  271. package/dist/channels/actions.js +53 -9
  272. package/dist/channels/cards.d.ts +97 -12
  273. package/dist/channels/cards.js +292 -28
  274. package/dist/channels/channels.module.d.ts +44 -0
  275. package/dist/channels/channels.module.js +153 -0
  276. package/dist/channels/channels.schemas.d.ts +54 -0
  277. package/dist/channels/channels.schemas.js +55 -0
  278. package/dist/channels/connections.controller.d.ts +46 -37
  279. package/dist/channels/connections.controller.js +85 -38
  280. package/dist/channels/connections.service.d.ts +184 -35
  281. package/dist/channels/connections.service.js +554 -156
  282. package/dist/channels/deliver-job.d.ts +32 -0
  283. package/dist/channels/deliver-job.js +29 -0
  284. package/dist/channels/features.d.ts +20 -1
  285. package/dist/channels/features.js +31 -5
  286. package/dist/channels/file-delivery.d.ts +76 -0
  287. package/dist/channels/file-delivery.js +176 -0
  288. package/dist/channels/inbound.d.ts +54 -64
  289. package/dist/channels/inbound.js +246 -61
  290. package/dist/channels/job-ids.d.ts +6 -0
  291. package/dist/channels/job-ids.js +6 -0
  292. package/dist/channels/jobs.d.ts +102 -0
  293. package/dist/channels/jobs.js +210 -0
  294. package/dist/channels/outbound.d.ts +119 -82
  295. package/dist/channels/outbound.js +1080 -229
  296. package/dist/channels/phrases.d.ts +263 -10
  297. package/dist/channels/phrases.js +220 -10
  298. package/dist/channels/progress.d.ts +75 -0
  299. package/dist/channels/progress.js +216 -0
  300. package/dist/channels/supervisor.d.ts +89 -46
  301. package/dist/channels/supervisor.js +234 -132
  302. package/dist/channels/threads.d.ts +47 -8
  303. package/dist/channels/threads.js +115 -13
  304. package/dist/channels/webhook.d.ts +40 -14
  305. package/dist/channels/webhook.js +86 -20
  306. package/dist/client/client-access.service.d.ts +102 -0
  307. package/dist/client/client-access.service.js +303 -0
  308. package/dist/client/client-builds.service.d.ts +109 -0
  309. package/dist/client/client-builds.service.js +229 -0
  310. package/dist/client/client-delivery.controller.d.ts +25 -0
  311. package/dist/client/client-delivery.controller.js +66 -0
  312. package/dist/client/client-files.d.ts +48 -0
  313. package/dist/client/client-files.js +136 -0
  314. package/dist/client/client-reports.cron.d.ts +13 -0
  315. package/dist/client/client-reports.cron.js +42 -0
  316. package/dist/client/client-reports.service.d.ts +30 -0
  317. package/dist/client/client-reports.service.js +106 -0
  318. package/dist/client/client-sign-in.service.d.ts +21 -0
  319. package/dist/client/client-sign-in.service.js +49 -0
  320. package/dist/client/client.controller.d.ts +49 -0
  321. package/dist/client/client.controller.js +129 -0
  322. package/dist/client/client.module.d.ts +8 -0
  323. package/dist/client/client.module.js +28 -0
  324. package/dist/client/client.schemas.d.ts +61 -0
  325. package/dist/client/client.schemas.js +27 -0
  326. package/dist/config/docs.js +5 -1
  327. package/dist/config/env.js +19 -1
  328. package/dist/config/fields.js +20 -4
  329. package/dist/config/load.d.ts +35 -4
  330. package/dist/config/load.js +108 -6
  331. package/dist/config/nacos-source.js +11 -2
  332. package/dist/config/permission-migration.d.ts +34 -0
  333. package/dist/config/permission-migration.js +115 -0
  334. package/dist/config/product-name.d.ts +8 -0
  335. package/dist/config/product-name.js +9 -0
  336. package/dist/config/schema.d.ts +171 -49
  337. package/dist/config/schema.js +924 -137
  338. package/dist/conversations/access.d.ts +40 -0
  339. package/dist/conversations/access.js +120 -0
  340. package/dist/conversations/agent-tree.d.ts +62 -0
  341. package/dist/conversations/agent-tree.js +128 -0
  342. package/dist/conversations/approval-profile.d.ts +30 -0
  343. package/dist/conversations/approval-profile.js +62 -0
  344. package/dist/conversations/artifacts.d.ts +11 -11
  345. package/dist/conversations/artifacts.js +36 -10
  346. package/dist/conversations/attachments.controller.d.ts +12 -4
  347. package/dist/conversations/attachments.controller.js +25 -10
  348. package/dist/conversations/attachments.module.d.ts +7 -0
  349. package/dist/conversations/attachments.module.js +25 -0
  350. package/dist/conversations/attachments.service.d.ts +226 -29
  351. package/dist/conversations/attachments.service.js +806 -160
  352. package/dist/conversations/conversations.controller.d.ts +115 -85
  353. package/dist/conversations/conversations.controller.js +237 -131
  354. package/dist/conversations/conversations.module.d.ts +8 -0
  355. package/dist/conversations/conversations.module.js +88 -0
  356. package/dist/conversations/conversations.schemas.d.ts +73 -0
  357. package/dist/conversations/conversations.schemas.js +105 -0
  358. package/dist/conversations/conversations.service.d.ts +416 -64
  359. package/dist/conversations/conversations.service.js +894 -219
  360. package/dist/conversations/delivery-scope.d.ts +34 -0
  361. package/dist/conversations/delivery-scope.js +23 -0
  362. package/dist/conversations/device-status.d.ts +24 -0
  363. package/dist/conversations/device-status.js +71 -0
  364. package/dist/conversations/event-log.d.ts +124 -27
  365. package/dist/conversations/event-log.js +291 -32
  366. package/dist/conversations/event-people.d.ts +12 -0
  367. package/dist/conversations/event-people.js +28 -0
  368. package/dist/conversations/events.d.ts +1305 -34
  369. package/dist/conversations/events.js +1285 -95
  370. package/dist/conversations/files.d.ts +91 -21
  371. package/dist/conversations/files.js +244 -61
  372. package/dist/conversations/idem-keys.d.ts +5 -0
  373. package/dist/conversations/idem-keys.js +5 -0
  374. package/dist/conversations/leak-check.d.ts +26 -0
  375. package/dist/conversations/leak-check.js +69 -0
  376. package/dist/conversations/media-types.d.ts +25 -0
  377. package/dist/conversations/media-types.js +38 -0
  378. package/dist/conversations/message-context.d.ts +82 -0
  379. package/dist/conversations/message-context.js +149 -0
  380. package/dist/conversations/model-image.d.ts +39 -0
  381. package/dist/conversations/model-image.js +80 -0
  382. package/dist/conversations/outputs-read.d.ts +11 -11
  383. package/dist/conversations/outputs-read.js +31 -7
  384. package/dist/conversations/permission-profile-store.d.ts +50 -0
  385. package/dist/conversations/permission-profile-store.js +67 -0
  386. package/dist/conversations/permission-profile-store.module.d.ts +2 -0
  387. package/dist/conversations/permission-profile-store.module.js +19 -0
  388. package/dist/conversations/permission-profiles.controller.d.ts +97 -0
  389. package/dist/conversations/permission-profiles.controller.js +105 -0
  390. package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
  391. package/dist/conversations/permission-profiles.schemas.js +23 -0
  392. package/dist/conversations/permission-profiles.service.d.ts +69 -0
  393. package/dist/conversations/permission-profiles.service.js +191 -0
  394. package/dist/conversations/prompt-suggestion-request.d.ts +95 -0
  395. package/dist/conversations/prompt-suggestion-request.js +213 -0
  396. package/dist/conversations/prompt-suggestion-store.d.ts +51 -0
  397. package/dist/conversations/prompt-suggestion-store.js +136 -0
  398. package/dist/conversations/prompt-suggestions.d.ts +153 -0
  399. package/dist/conversations/prompt-suggestions.js +565 -0
  400. package/dist/conversations/queue.d.ts +70 -60
  401. package/dist/conversations/queue.js +65 -294
  402. package/dist/conversations/queue.service.d.ts +71 -0
  403. package/dist/conversations/queue.service.js +419 -0
  404. package/dist/conversations/source.d.ts +10 -0
  405. package/dist/conversations/source.js +19 -0
  406. package/dist/conversations/titles.d.ts +97 -28
  407. package/dist/conversations/titles.js +250 -83
  408. package/dist/conversations/tree.d.ts +27 -0
  409. package/dist/conversations/tree.js +83 -0
  410. package/dist/ctx/bus.js +11 -3
  411. package/dist/ctx/create-ctx.d.ts +136 -11
  412. package/dist/ctx/create-ctx.js +394 -67
  413. package/dist/ctx/device-provider-check.d.ts +11 -0
  414. package/dist/ctx/device-provider-check.js +36 -0
  415. package/dist/ctx/lock.d.ts +7 -3
  416. package/dist/ctx/lock.js +9 -20
  417. package/dist/ctx/net.d.ts +50 -0
  418. package/dist/ctx/net.js +67 -0
  419. package/dist/ctx/queue.js +4 -2
  420. package/dist/ctx/secrets.d.ts +47 -3
  421. package/dist/ctx/secrets.js +142 -28
  422. package/dist/db/kernel-schema.d.ts +1305 -44
  423. package/dist/db/pool.d.ts +16 -0
  424. package/dist/db/pool.js +7 -2
  425. package/dist/device-access/conversation-notice-delivery.d.ts +116 -0
  426. package/dist/device-access/conversation-notice-delivery.js +344 -0
  427. package/dist/device-access/conversation-notices.d.ts +27 -0
  428. package/dist/device-access/conversation-notices.js +42 -0
  429. package/dist/device-access/device-access.module.d.ts +7 -0
  430. package/dist/device-access/device-access.module.js +41 -0
  431. package/dist/device-access/device-access.service.d.ts +188 -0
  432. package/dist/device-access/device-access.service.js +695 -0
  433. package/dist/device-access/token.d.ts +6 -0
  434. package/dist/device-access/token.js +6 -0
  435. package/dist/device-access/viewer-routes.d.ts +45 -0
  436. package/dist/device-access/viewer-routes.js +81 -0
  437. package/dist/device-access/viewer.d.ts +247 -0
  438. package/dist/device-access/viewer.js +858 -0
  439. package/dist/devices/access.d.ts +35 -0
  440. package/dist/devices/access.js +76 -0
  441. package/dist/devices/access.module.d.ts +2 -0
  442. package/dist/devices/access.module.js +19 -0
  443. package/dist/devices/conversation-devices.d.ts +159 -0
  444. package/dist/devices/conversation-devices.js +352 -0
  445. package/dist/devices/default-provider-setting.d.ts +45 -0
  446. package/dist/devices/default-provider-setting.js +59 -0
  447. package/dist/devices/device-projects.service.d.ts +148 -0
  448. package/dist/devices/device-projects.service.js +471 -0
  449. package/dist/devices/device-provider-selection.d.ts +36 -0
  450. package/dist/devices/device-provider-selection.js +85 -0
  451. package/dist/devices/device-provider-selection.module.d.ts +3 -0
  452. package/dist/devices/device-provider-selection.module.js +22 -0
  453. package/dist/devices/devices.controller.d.ts +55 -0
  454. package/dist/devices/devices.controller.js +182 -0
  455. package/dist/devices/devices.module.d.ts +8 -0
  456. package/dist/devices/devices.module.js +53 -0
  457. package/dist/devices/devices.schemas.d.ts +7 -0
  458. package/dist/devices/devices.schemas.js +26 -0
  459. package/dist/devices/devices.service.d.ts +492 -0
  460. package/dist/devices/devices.service.js +1196 -0
  461. package/dist/devices/dto.d.ts +104 -0
  462. package/dist/devices/dto.js +101 -0
  463. package/dist/devices/errors.d.ts +14 -0
  464. package/dist/devices/errors.js +14 -0
  465. package/dist/devices/label.d.ts +9 -0
  466. package/dist/devices/label.js +14 -0
  467. package/dist/devices/legacy-cleanup.job.d.ts +34 -0
  468. package/dist/devices/legacy-cleanup.job.js +147 -0
  469. package/dist/devices/project-rules.d.ts +30 -0
  470. package/dist/devices/project-rules.js +16 -0
  471. package/dist/devices/public-suffix.d.ts +6 -0
  472. package/dist/devices/public-suffix.js +79 -0
  473. package/dist/devices/working-root.d.ts +43 -0
  474. package/dist/devices/working-root.js +56 -0
  475. package/dist/dial-in/access.d.ts +45 -0
  476. package/dist/dial-in/access.js +90 -0
  477. package/dist/dial-in/auth.controller.d.ts +48 -0
  478. package/dist/dial-in/auth.controller.js +131 -0
  479. package/dist/dial-in/auth.module.d.ts +7 -0
  480. package/dist/dial-in/auth.module.js +27 -0
  481. package/dist/dial-in/auth.service.d.ts +158 -0
  482. package/dist/dial-in/auth.service.js +475 -0
  483. package/dist/dial-in/dial-in.module.d.ts +9 -0
  484. package/dist/dial-in/dial-in.module.js +37 -0
  485. package/dist/dial-in/dto.d.ts +81 -0
  486. package/dist/dial-in/dto.js +56 -0
  487. package/dist/dial-in/envelope.d.ts +95 -0
  488. package/dist/dial-in/envelope.js +89 -0
  489. package/dist/dial-in/gateway.d.ts +273 -0
  490. package/dist/dial-in/gateway.js +1064 -0
  491. package/dist/dial-in/handlers.d.ts +56 -0
  492. package/dist/dial-in/handlers.js +100 -0
  493. package/dist/dial-in/keys.d.ts +37 -0
  494. package/dist/dial-in/keys.js +37 -0
  495. package/dist/dial-in/machines.d.ts +144 -0
  496. package/dist/dial-in/machines.js +337 -0
  497. package/dist/dial-in/relay.d.ts +167 -0
  498. package/dist/dial-in/relay.js +517 -0
  499. package/dist/dial-in/relay.module.d.ts +7 -0
  500. package/dist/dial-in/relay.module.js +24 -0
  501. package/dist/dial-in/routes.d.ts +56 -0
  502. package/dist/dial-in/routes.js +133 -0
  503. package/dist/dial-in/streams.d.ts +66 -0
  504. package/dist/dial-in/streams.js +296 -0
  505. package/dist/dial-in/targets.d.ts +45 -0
  506. package/dist/dial-in/targets.js +91 -0
  507. package/dist/errors.d.ts +462 -10
  508. package/dist/errors.js +462 -10
  509. package/dist/evals/budget.d.ts +42 -21
  510. package/dist/evals/budget.js +127 -62
  511. package/dist/evals/evals.module.d.ts +31 -0
  512. package/dist/evals/evals.module.js +127 -0
  513. package/dist/evals/evals.schemas.d.ts +110 -0
  514. package/dist/evals/evals.schemas.js +107 -0
  515. package/dist/evals/jobs.d.ts +28 -0
  516. package/dist/evals/jobs.js +47 -0
  517. package/dist/evals/plan.d.ts +20 -15
  518. package/dist/evals/plan.js +29 -6
  519. package/dist/evals/reconstruct.d.ts +104 -32
  520. package/dist/evals/reconstruct.js +208 -79
  521. package/dist/evals/recorded-permission-context.d.ts +79 -0
  522. package/dist/evals/recorded-permission-context.js +157 -0
  523. package/dist/evals/recorded-tools.d.ts +26 -1
  524. package/dist/evals/recorded-tools.js +55 -8
  525. package/dist/evals/run-replay.d.ts +103 -13
  526. package/dist/evals/run-replay.js +298 -109
  527. package/dist/evals/runs.controller.d.ts +3 -58
  528. package/dist/evals/runs.controller.js +18 -50
  529. package/dist/evals/runs.service.d.ts +32 -54
  530. package/dist/evals/runs.service.js +274 -264
  531. package/dist/evals/sets.controller.d.ts +3 -29
  532. package/dist/evals/sets.controller.js +18 -39
  533. package/dist/evals/sets.service.d.ts +46 -17
  534. package/dist/evals/sets.service.js +320 -210
  535. package/dist/evals/snapshot.d.ts +11 -5
  536. package/dist/evals/snapshot.js +5 -4
  537. package/dist/evals/step-replay.d.ts +12 -8
  538. package/dist/evals/step-replay.js +24 -12
  539. package/dist/evals/trajectory.controller.d.ts +1 -1
  540. package/dist/evals/trajectory.controller.js +11 -7
  541. package/dist/evals/trajectory.d.ts +21 -5
  542. package/dist/evals/trajectory.js +14 -1
  543. package/dist/evals/trajectory.service.d.ts +17 -8
  544. package/dist/evals/trajectory.service.js +59 -21
  545. package/dist/evals/worker.d.ts +57 -31
  546. package/dist/evals/worker.js +248 -125
  547. package/dist/extensions/admin-ops.d.ts +142 -42
  548. package/dist/extensions/admin-ops.js +433 -187
  549. package/dist/extensions/admin-view.d.ts +96 -35
  550. package/dist/extensions/admin-view.js +390 -89
  551. package/dist/extensions/approvals.d.ts +24 -10
  552. package/dist/extensions/approvals.js +73 -46
  553. package/dist/extensions/blobs.d.ts +40 -10
  554. package/dist/extensions/blobs.js +156 -46
  555. package/dist/extensions/bootstrap-defaults.d.ts +24 -0
  556. package/dist/extensions/bootstrap-defaults.js +78 -0
  557. package/dist/extensions/bootstrap-extra.d.ts +84 -0
  558. package/dist/extensions/bootstrap-extra.js +151 -0
  559. package/dist/extensions/bootstrap-manifest.d.ts +14 -0
  560. package/dist/extensions/bootstrap-manifest.js +23 -0
  561. package/dist/extensions/bootstrap-packages.d.ts +98 -0
  562. package/dist/extensions/bootstrap-packages.js +303 -0
  563. package/dist/extensions/bootstrap.d.ts +249 -76
  564. package/dist/extensions/bootstrap.js +703 -333
  565. package/dist/extensions/cli.d.ts +32 -10
  566. package/dist/extensions/cli.js +52 -99
  567. package/dist/extensions/config-hash.d.ts +12 -0
  568. package/dist/extensions/config-hash.js +38 -0
  569. package/dist/extensions/config-issues.d.ts +19 -0
  570. package/dist/extensions/config-issues.js +48 -0
  571. package/dist/extensions/config-json-schema.d.ts +43 -7
  572. package/dist/extensions/config-json-schema.js +122 -58
  573. package/dist/extensions/deployed-snapshots.d.ts +19 -0
  574. package/dist/extensions/deployed-snapshots.js +59 -0
  575. package/dist/extensions/deployment-config-store.d.ts +55 -0
  576. package/dist/extensions/deployment-config-store.js +133 -0
  577. package/dist/extensions/deployment-config.d.ts +152 -70
  578. package/dist/extensions/deployment-config.js +453 -248
  579. package/dist/extensions/display-name.d.ts +22 -0
  580. package/dist/extensions/display-name.js +77 -0
  581. package/dist/extensions/effective-config.d.ts +134 -0
  582. package/dist/extensions/effective-config.js +380 -0
  583. package/dist/extensions/enabled.d.ts +29 -9
  584. package/dist/extensions/enabled.js +48 -10
  585. package/dist/extensions/extensions.module.d.ts +8 -0
  586. package/dist/extensions/extensions.module.js +111 -0
  587. package/dist/extensions/guide-places.d.ts +82 -0
  588. package/dist/extensions/guide-places.js +175 -0
  589. package/dist/extensions/hooks.d.ts +62 -9
  590. package/dist/extensions/hooks.js +98 -18
  591. package/dist/extensions/host.d.ts +215 -85
  592. package/dist/extensions/host.js +610 -241
  593. package/dist/extensions/installs.d.ts +77 -22
  594. package/dist/extensions/installs.js +179 -38
  595. package/dist/extensions/instance.d.ts +16 -3
  596. package/dist/extensions/instance.js +22 -2
  597. package/dist/extensions/ledger.d.ts +1 -1
  598. package/dist/extensions/lifecycle-hooks.d.ts +99 -0
  599. package/dist/extensions/lifecycle-hooks.js +260 -0
  600. package/dist/extensions/lifecycle-topics.d.ts +18 -0
  601. package/dist/extensions/lifecycle-topics.js +18 -0
  602. package/dist/extensions/lifecycle.d.ts +40 -47
  603. package/dist/extensions/lifecycle.js +110 -39
  604. package/dist/extensions/locks.d.ts +45 -0
  605. package/dist/extensions/locks.js +112 -0
  606. package/dist/extensions/migrate-lock.d.ts +3 -4
  607. package/dist/extensions/org-config.d.ts +160 -92
  608. package/dist/extensions/org-config.js +372 -362
  609. package/dist/extensions/org-levels.d.ts +50 -0
  610. package/dist/extensions/org-levels.js +151 -0
  611. package/dist/extensions/org-overrides.d.ts +152 -0
  612. package/dist/extensions/org-overrides.js +525 -0
  613. package/dist/extensions/package.d.ts +20 -6
  614. package/dist/extensions/package.js +56 -7
  615. package/dist/extensions/permission-set.d.ts +68 -11
  616. package/dist/extensions/permission-set.js +67 -15
  617. package/dist/extensions/permission-view.d.ts +120 -19
  618. package/dist/extensions/permission-view.js +62 -22
  619. package/dist/extensions/plugin-guides.d.ts +320 -0
  620. package/dist/extensions/plugin-guides.js +635 -0
  621. package/dist/extensions/plugin-icons.d.ts +140 -0
  622. package/dist/extensions/plugin-icons.js +342 -0
  623. package/dist/extensions/plugin-items.d.ts +41 -0
  624. package/dist/extensions/plugin-items.js +70 -0
  625. package/dist/extensions/point-defaults.controller.d.ts +28 -0
  626. package/dist/extensions/point-defaults.controller.js +69 -0
  627. package/dist/extensions/point-defaults.d.ts +113 -0
  628. package/dist/extensions/point-defaults.js +287 -0
  629. package/dist/extensions/point-defaults.schemas.d.ts +9 -0
  630. package/dist/extensions/point-defaults.schemas.js +14 -0
  631. package/dist/extensions/registry.d.ts +50 -2
  632. package/dist/extensions/registry.js +92 -4
  633. package/dist/extensions/resolve.d.ts +51 -1
  634. package/dist/extensions/resolve.js +90 -3
  635. package/dist/extensions/single-provider.d.ts +92 -0
  636. package/dist/extensions/single-provider.js +180 -0
  637. package/dist/extensions/sources.d.ts +25 -10
  638. package/dist/extensions/sources.js +36 -13
  639. package/dist/extensions/state.module.d.ts +9 -0
  640. package/dist/extensions/state.module.js +46 -0
  641. package/dist/extensions/sync.js +5 -10
  642. package/dist/extensions/unavailable.d.ts +50 -0
  643. package/dist/extensions/unavailable.js +114 -0
  644. package/dist/extensions/usage-subscribers.d.ts +43 -0
  645. package/dist/extensions/usage-subscribers.js +108 -0
  646. package/dist/files/files.module.d.ts +6 -0
  647. package/dist/files/files.module.js +26 -0
  648. package/dist/files/previewers.controller.d.ts +19 -2
  649. package/dist/files/previewers.controller.js +71 -12
  650. package/dist/files/previewers.d.ts +109 -20
  651. package/dist/files/previewers.js +298 -66
  652. package/dist/files/previewers.schemas.d.ts +10 -0
  653. package/dist/files/previewers.schemas.js +9 -0
  654. package/dist/git/gateway.d.ts +102 -0
  655. package/dist/git/gateway.js +771 -0
  656. package/dist/git/gateway.route.d.ts +16 -0
  657. package/dist/git/gateway.route.js +39 -0
  658. package/dist/git/git.module.d.ts +10 -0
  659. package/dist/git/git.module.js +31 -0
  660. package/dist/git/identity.d.ts +80 -0
  661. package/dist/git/identity.js +209 -0
  662. package/dist/git/pkt-line.d.ts +53 -0
  663. package/dist/git/pkt-line.js +146 -0
  664. package/dist/git/run-end.d.ts +29 -0
  665. package/dist/git/run-end.js +121 -0
  666. package/dist/git/sources.d.ts +42 -0
  667. package/dist/git/sources.js +134 -0
  668. package/dist/git/tickets.d.ts +69 -0
  669. package/dist/git/tickets.js +194 -0
  670. package/dist/html/csp.d.ts +13 -0
  671. package/dist/html/csp.js +33 -0
  672. package/dist/html/html-document.controller.d.ts +31 -0
  673. package/dist/html/html-document.controller.js +75 -0
  674. package/dist/html/html-document.service.d.ts +49 -0
  675. package/dist/html/html-document.service.js +143 -0
  676. package/dist/html/html-token.d.ts +58 -0
  677. package/dist/html/html-token.js +154 -0
  678. package/dist/html/html-type.d.ts +15 -0
  679. package/dist/html/html-type.js +44 -0
  680. package/dist/html/html.module.d.ts +6 -0
  681. package/dist/html/html.module.js +26 -0
  682. package/dist/http/adapter.d.ts +3 -0
  683. package/dist/http/adapter.js +25 -0
  684. package/dist/http/api.module.d.ts +3 -110
  685. package/dist/http/api.module.js +180 -359
  686. package/dist/http/app.d.ts +35 -18
  687. package/dist/http/app.js +72 -67
  688. package/dist/http/error-filter.module.d.ts +5 -0
  689. package/dist/http/error-filter.module.js +18 -0
  690. package/dist/http/error.filter.d.ts +2 -0
  691. package/dist/http/error.filter.js +13 -4
  692. package/dist/http/gateway-routes.d.ts +23 -0
  693. package/dist/http/gateway-routes.js +17 -0
  694. package/dist/http/meta.controller.d.ts +49 -0
  695. package/dist/http/meta.controller.js +114 -0
  696. package/dist/http/nest-logger.d.ts +6 -5
  697. package/dist/http/nest-logger.js +24 -10
  698. package/dist/http/plugin-dispatch.d.ts +58 -18
  699. package/dist/http/plugin-dispatch.js +145 -30
  700. package/dist/http/plugin-route-access.d.ts +57 -0
  701. package/dist/http/plugin-route-access.js +208 -0
  702. package/dist/identity/account-avatar.controller.d.ts +30 -0
  703. package/dist/identity/account-avatar.controller.js +117 -0
  704. package/dist/identity/account-avatar.d.ts +67 -0
  705. package/dist/identity/account-avatar.js +136 -0
  706. package/dist/identity/account-avatars.service.d.ts +77 -0
  707. package/dist/identity/account-avatars.service.js +321 -0
  708. package/dist/identity/accounts.d.ts +176 -38
  709. package/dist/identity/accounts.js +523 -188
  710. package/dist/identity/api-tokens.d.ts +11 -7
  711. package/dist/identity/api-tokens.js +79 -44
  712. package/dist/identity/app-auth.controller.d.ts +26 -0
  713. package/dist/identity/app-auth.controller.js +65 -0
  714. package/dist/identity/app-auth.d.ts +84 -0
  715. package/dist/identity/app-auth.js +212 -0
  716. package/dist/identity/app-auth.schemas.d.ts +60 -0
  717. package/dist/identity/app-auth.schemas.js +46 -0
  718. package/dist/identity/audit.d.ts +9 -17
  719. package/dist/identity/audit.js +5 -28
  720. package/dist/identity/auth.controller.d.ts +13 -10
  721. package/dist/identity/auth.controller.js +31 -25
  722. package/dist/identity/auth.guard.d.ts +40 -18
  723. package/dist/identity/auth.guard.js +112 -45
  724. package/dist/identity/binding.d.ts +9 -11
  725. package/dist/identity/binding.js +41 -13
  726. package/dist/identity/cookies.d.ts +21 -5
  727. package/dist/identity/cookies.js +34 -6
  728. package/dist/identity/external-identity-lock.d.ts +17 -0
  729. package/dist/identity/external-identity-lock.js +39 -0
  730. package/dist/identity/external.d.ts +93 -51
  731. package/dist/identity/external.js +297 -168
  732. package/dist/identity/identity.module.d.ts +7 -0
  733. package/dist/identity/identity.module.js +79 -0
  734. package/dist/identity/initial-passwords.controller.d.ts +24 -0
  735. package/dist/identity/initial-passwords.controller.js +55 -0
  736. package/dist/identity/initial-passwords.d.ts +70 -0
  737. package/dist/identity/initial-passwords.job.d.ts +17 -0
  738. package/dist/identity/initial-passwords.job.js +52 -0
  739. package/dist/identity/initial-passwords.js +154 -0
  740. package/dist/identity/linked-accounts.d.ts +42 -0
  741. package/dist/identity/linked-accounts.js +78 -0
  742. package/dist/identity/login-sources.d.ts +160 -0
  743. package/dist/identity/login-sources.js +403 -0
  744. package/dist/identity/me.controller.d.ts +58 -17
  745. package/dist/identity/me.controller.js +131 -33
  746. package/dist/identity/me.schemas.d.ts +60 -0
  747. package/dist/identity/me.schemas.js +55 -0
  748. package/dist/identity/principal.d.ts +11 -3
  749. package/dist/identity/principal.js +11 -3
  750. package/dist/identity/sessions.d.ts +25 -10
  751. package/dist/identity/sessions.js +127 -46
  752. package/dist/identity/settings.d.ts +319 -23
  753. package/dist/identity/settings.js +817 -73
  754. package/dist/identity/sso-decisions.d.ts +75 -0
  755. package/dist/identity/sso-decisions.js +42 -0
  756. package/dist/identity/sso-link.d.ts +61 -0
  757. package/dist/identity/sso-link.js +157 -0
  758. package/dist/identity/sso-paths.d.ts +7 -0
  759. package/dist/identity/sso-paths.js +13 -0
  760. package/dist/identity/sso.controller.d.ts +102 -18
  761. package/dist/identity/sso.controller.js +232 -34
  762. package/dist/identity/sso.d.ts +87 -39
  763. package/dist/identity/sso.js +188 -84
  764. package/dist/identity/super-admin.d.ts +20 -0
  765. package/dist/identity/super-admin.js +81 -0
  766. package/dist/identity/write-actor.d.ts +11 -0
  767. package/dist/identity/write-actor.js +7 -0
  768. package/dist/inbox/inbox.module.d.ts +6 -0
  769. package/dist/inbox/inbox.module.js +27 -0
  770. package/dist/inbox/inbox.schemas.d.ts +8 -0
  771. package/dist/inbox/inbox.schemas.js +11 -0
  772. package/dist/inbox/inbox.service.d.ts +71 -12
  773. package/dist/inbox/inbox.service.js +112 -13
  774. package/dist/inbox/org-notices.d.ts +63 -0
  775. package/dist/inbox/org-notices.js +91 -0
  776. package/dist/inbox/platform-inbox.controller.d.ts +23 -0
  777. package/dist/inbox/platform-inbox.controller.js +58 -0
  778. package/dist/inbox/platform-inbox.service.d.ts +170 -0
  779. package/dist/inbox/platform-inbox.service.js +297 -0
  780. package/dist/inbox/platform-notices.d.ts +33 -0
  781. package/dist/inbox/platform-notices.js +29 -0
  782. package/dist/index.d.ts +40 -15
  783. package/dist/index.js +34 -10
  784. package/dist/infra/cache/cache.module.d.ts +3 -0
  785. package/dist/infra/cache/cache.module.js +16 -0
  786. package/dist/infra/cache/cache.service.d.ts +21 -0
  787. package/dist/infra/cache/cache.service.js +80 -0
  788. package/dist/infra/cache/cacheable.decorator.d.ts +32 -0
  789. package/dist/infra/cache/cacheable.decorator.js +83 -0
  790. package/dist/infra/cli/kernel-cli.module.d.ts +66 -0
  791. package/dist/infra/cli/kernel-cli.module.js +181 -0
  792. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  793. package/dist/infra/cli/master-key-rewrap.js +24 -0
  794. package/dist/infra/cli/permission-cutover.d.ts +59 -0
  795. package/dist/infra/cli/permission-cutover.js +107 -0
  796. package/dist/infra/close-within.d.ts +15 -0
  797. package/dist/infra/close-within.js +36 -0
  798. package/dist/infra/config/config.module.d.ts +13 -0
  799. package/dist/infra/config/config.module.js +39 -0
  800. package/dist/infra/config/kernel-config.service.d.ts +32 -0
  801. package/dist/infra/config/kernel-config.service.js +221 -0
  802. package/dist/infra/database/after-commit.d.ts +6 -0
  803. package/dist/infra/database/after-commit.js +9 -0
  804. package/dist/infra/database/database.module.d.ts +25 -0
  805. package/dist/infra/database/database.module.js +92 -0
  806. package/dist/infra/database/kernel-db.d.ts +22 -0
  807. package/dist/infra/database/kernel-db.js +65 -0
  808. package/dist/infra/database/org-scope.d.ts +59 -0
  809. package/dist/infra/database/org-scope.js +68 -0
  810. package/dist/infra/database/rls-role.d.ts +11 -0
  811. package/dist/infra/database/rls-role.js +33 -0
  812. package/dist/infra/database/scoped-dialect.d.ts +18 -0
  813. package/dist/infra/database/scoped-dialect.js +245 -0
  814. package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
  815. package/dist/infra/database/startup-activation-transaction.js +242 -0
  816. package/dist/infra/database/transaction-host.d.ts +129 -0
  817. package/dist/infra/database/transaction-host.js +281 -0
  818. package/dist/infra/database/transactional.decorator.d.ts +15 -0
  819. package/dist/infra/database/transactional.decorator.js +27 -0
  820. package/dist/infra/database/xact-lock.d.ts +34 -0
  821. package/dist/infra/database/xact-lock.js +76 -0
  822. package/dist/infra/events/kernel-events.d.ts +102 -0
  823. package/dist/infra/events/kernel-events.js +65 -0
  824. package/dist/infra/health/health.controller.d.ts +26 -0
  825. package/dist/infra/health/health.controller.js +112 -0
  826. package/dist/infra/health/health.module.d.ts +9 -0
  827. package/dist/infra/health/health.module.js +24 -0
  828. package/dist/infra/health/health.options.d.ts +10 -0
  829. package/dist/infra/health/health.options.js +15 -0
  830. package/dist/infra/health/process-fault.d.ts +16 -0
  831. package/dist/infra/health/process-fault.js +49 -0
  832. package/dist/infra/health/shutdown-state.d.ts +6 -0
  833. package/dist/infra/health/shutdown-state.js +2 -0
  834. package/dist/infra/lifecycle/graceful-shutdown.module.d.ts +6 -0
  835. package/dist/infra/lifecycle/graceful-shutdown.module.js +23 -0
  836. package/dist/infra/lifecycle/graceful-shutdown.service.d.ts +70 -0
  837. package/dist/infra/lifecycle/graceful-shutdown.service.js +135 -0
  838. package/dist/infra/lifecycle/process-guards.d.ts +58 -0
  839. package/dist/infra/lifecycle/process-guards.js +99 -0
  840. package/dist/infra/lifecycle/shutdown-signals.d.ts +39 -0
  841. package/dist/infra/lifecycle/shutdown-signals.js +63 -0
  842. package/dist/infra/lock/key-template.d.ts +13 -0
  843. package/dist/infra/lock/key-template.js +46 -0
  844. package/dist/infra/lock/lock.module.d.ts +3 -0
  845. package/dist/infra/lock/lock.module.js +16 -0
  846. package/dist/infra/lock/lock.service.d.ts +132 -0
  847. package/dist/infra/lock/lock.service.js +376 -0
  848. package/dist/infra/lock/shared-lease.d.ts +44 -0
  849. package/dist/infra/lock/shared-lease.js +121 -0
  850. package/dist/infra/lock/with-lock.decorator.d.ts +28 -0
  851. package/dist/infra/lock/with-lock.decorator.js +49 -0
  852. package/dist/infra/logging/logging.module.d.ts +18 -0
  853. package/dist/infra/logging/logging.module.js +52 -0
  854. package/dist/infra/outbox/outbox-relay.module.d.ts +6 -0
  855. package/dist/infra/outbox/outbox-relay.module.js +18 -0
  856. package/dist/infra/outbox/outbox.dispatcher.d.ts +103 -0
  857. package/dist/infra/outbox/outbox.dispatcher.js +321 -0
  858. package/dist/infra/outbox/outbox.module.d.ts +24 -0
  859. package/dist/infra/outbox/outbox.module.js +50 -0
  860. package/dist/infra/outbox/outbox.relay.d.ts +31 -0
  861. package/dist/infra/outbox/outbox.relay.js +76 -0
  862. package/dist/infra/outbox/outbox.service.d.ts +60 -0
  863. package/dist/infra/outbox/outbox.service.js +166 -0
  864. package/dist/infra/outbox/registry.d.ts +474 -0
  865. package/dist/infra/outbox/registry.js +438 -0
  866. package/dist/infra/presence/presence.module.d.ts +6 -0
  867. package/dist/infra/presence/presence.module.js +22 -0
  868. package/dist/infra/presence/replica-presence.d.ts +87 -0
  869. package/dist/infra/presence/replica-presence.js +189 -0
  870. package/dist/infra/queue/configured-processor.d.ts +18 -0
  871. package/dist/infra/queue/configured-processor.js +23 -0
  872. package/dist/infra/queue/job-failure.d.ts +18 -0
  873. package/dist/infra/queue/job-failure.js +26 -0
  874. package/dist/infra/queue/queue-names.d.ts +8 -0
  875. package/dist/infra/queue/queue-names.js +22 -0
  876. package/dist/infra/queue/queue-shutdown.d.ts +27 -0
  877. package/dist/infra/queue/queue-shutdown.js +81 -0
  878. package/dist/infra/queue/queue.module.d.ts +16 -0
  879. package/dist/infra/queue/queue.module.js +61 -0
  880. package/dist/infra/queue/redis-connection.d.ts +13 -0
  881. package/dist/infra/queue/redis-connection.js +25 -0
  882. package/dist/infra/queue/run-job.d.ts +22 -0
  883. package/dist/infra/queue/run-job.js +32 -0
  884. package/dist/infra/redis/redis.module.d.ts +24 -0
  885. package/dist/infra/redis/redis.module.js +91 -0
  886. package/dist/infra/schedule/cron-tick.d.ts +12 -0
  887. package/dist/infra/schedule/cron-tick.js +25 -0
  888. package/dist/infra/schedule/locked-cron.decorator.d.ts +27 -0
  889. package/dist/infra/schedule/locked-cron.decorator.js +53 -0
  890. package/dist/infra/schedule/locked-interval.d.ts +69 -0
  891. package/dist/infra/schedule/locked-interval.js +190 -0
  892. package/dist/infra/schedule/locked-tick.d.ts +90 -0
  893. package/dist/infra/schedule/locked-tick.js +145 -0
  894. package/dist/infra/schedule/schedule.module.d.ts +8 -0
  895. package/dist/infra/schedule/schedule.module.js +27 -0
  896. package/dist/infra/schedule/scheduled-runs.d.ts +69 -0
  897. package/dist/infra/schedule/scheduled-runs.js +165 -0
  898. package/dist/infra/swagger/swagger.d.ts +16 -0
  899. package/dist/infra/swagger/swagger.js +31 -0
  900. package/dist/infra/throttler/credential-throttler.d.ts +38 -0
  901. package/dist/infra/throttler/credential-throttler.js +80 -0
  902. package/dist/infra/throttler/named-throttlers.d.ts +51 -0
  903. package/dist/infra/throttler/named-throttlers.js +244 -0
  904. package/dist/infra/throttler/redis-throttler-storage.d.ts +38 -0
  905. package/dist/infra/throttler/redis-throttler-storage.js +130 -0
  906. package/dist/infra/throttler/throttler.guard.d.ts +24 -0
  907. package/dist/infra/throttler/throttler.guard.js +69 -0
  908. package/dist/infra/throttler/throttler.module.d.ts +15 -0
  909. package/dist/infra/throttler/throttler.module.js +53 -0
  910. package/dist/infra/tokens.d.ts +20 -0
  911. package/dist/infra/tokens.js +20 -0
  912. package/dist/infra/validation/create-zod-dto.d.ts +23 -0
  913. package/dist/infra/validation/create-zod-dto.js +35 -0
  914. package/dist/infra/validation/parse-with-zod.d.ts +7 -0
  915. package/dist/infra/validation/parse-with-zod.js +12 -0
  916. package/dist/infra/validation/validation.module.d.ts +3 -0
  917. package/dist/infra/validation/validation.module.js +16 -0
  918. package/dist/infra/validation/zod-params.d.ts +7 -0
  919. package/dist/infra/validation/zod-params.js +42 -0
  920. package/dist/infra/validation/zod-validation.pipe.d.ts +11 -0
  921. package/dist/infra/validation/zod-validation.pipe.js +31 -0
  922. package/dist/kernel.d.ts +9 -244
  923. package/dist/kernel.js +8 -1305
  924. package/dist/kernel.module.d.ts +17 -0
  925. package/dist/kernel.module.js +165 -0
  926. package/dist/lifecycle/kernel-lifecycle.d.ts +166 -0
  927. package/dist/lifecycle/kernel-lifecycle.js +618 -0
  928. package/dist/lifecycle/tokens.d.ts +3 -0
  929. package/dist/lifecycle/tokens.js +3 -0
  930. package/dist/log-context.d.ts +2 -0
  931. package/dist/log-context.js +4 -0
  932. package/dist/log.d.ts +13 -1
  933. package/dist/log.js +93 -17
  934. package/dist/media/image-header.d.ts +10 -0
  935. package/dist/media/image-header.js +87 -0
  936. package/dist/models/embeddings.d.ts +82 -0
  937. package/dist/models/embeddings.js +319 -0
  938. package/dist/models/enablement.controller.d.ts +40 -0
  939. package/dist/models/enablement.controller.js +74 -0
  940. package/dist/models/enablement.d.ts +100 -0
  941. package/dist/models/enablement.js +257 -0
  942. package/dist/models/image-usable.d.ts +46 -0
  943. package/dist/models/image-usable.js +60 -0
  944. package/dist/models/images.d.ts +127 -0
  945. package/dist/models/images.js +445 -0
  946. package/dist/models/models.module.d.ts +8 -0
  947. package/dist/models/models.module.js +50 -0
  948. package/dist/models/org-models.schemas.d.ts +8 -0
  949. package/dist/models/org-models.schemas.js +23 -0
  950. package/dist/models/prices.d.ts +13 -5
  951. package/dist/models/prices.js +69 -39
  952. package/dist/models/purposes.controller.d.ts +13 -4
  953. package/dist/models/purposes.controller.js +25 -11
  954. package/dist/models/purposes.d.ts +129 -57
  955. package/dist/models/purposes.js +275 -85
  956. package/dist/net/public-address.d.ts +38 -8
  957. package/dist/net/public-address.js +83 -24
  958. package/dist/net/safe-fetch.d.ts +28 -6
  959. package/dist/net/safe-fetch.js +105 -8
  960. package/dist/orgs/device-network-setting.d.ts +82 -0
  961. package/dist/orgs/device-network-setting.js +142 -0
  962. package/dist/orgs/directory-sync.controller.d.ts +1 -1
  963. package/dist/orgs/directory-sync.controller.js +2 -2
  964. package/dist/orgs/directory-sync.d.ts +85 -39
  965. package/dist/orgs/directory-sync.js +255 -139
  966. package/dist/orgs/invitations.controller.d.ts +9 -17
  967. package/dist/orgs/invitations.controller.js +31 -31
  968. package/dist/orgs/invitations.service.d.ts +24 -11
  969. package/dist/orgs/invitations.service.js +141 -94
  970. package/dist/orgs/members.service.d.ts +34 -15
  971. package/dist/orgs/members.service.js +181 -121
  972. package/dist/orgs/network-allowances.service.d.ts +79 -0
  973. package/dist/orgs/network-allowances.service.js +371 -0
  974. package/dist/orgs/offboarding.d.ts +86 -84
  975. package/dist/orgs/offboarding.js +287 -184
  976. package/dist/orgs/org-lock.d.ts +66 -20
  977. package/dist/orgs/org-lock.js +156 -36
  978. package/dist/orgs/org-owner.d.ts +7 -0
  979. package/dist/orgs/org-owner.js +16 -0
  980. package/dist/orgs/org.guard.d.ts +11 -1
  981. package/dist/orgs/org.guard.js +49 -34
  982. package/dist/orgs/orgs.controller.d.ts +24 -26
  983. package/dist/orgs/orgs.controller.js +51 -26
  984. package/dist/orgs/orgs.module.d.ts +7 -0
  985. package/dist/orgs/orgs.module.js +72 -0
  986. package/dist/orgs/orgs.schemas.d.ts +46 -0
  987. package/dist/orgs/orgs.schemas.js +43 -0
  988. package/dist/orgs/orgs.service.d.ts +57 -21
  989. package/dist/orgs/orgs.service.js +209 -91
  990. package/dist/orgs/roles.d.ts +1 -1
  991. package/dist/orgs/roles.js +11 -1
  992. package/dist/orgs/settings.controller.d.ts +6 -3
  993. package/dist/orgs/settings.controller.js +17 -10
  994. package/dist/orgs/settings.service.d.ts +474 -56
  995. package/dist/orgs/settings.service.js +786 -108
  996. package/dist/overrides.d.ts +126 -0
  997. package/dist/overrides.js +70 -0
  998. package/dist/packages/npm.d.ts +37 -10
  999. package/dist/packages/npm.js +67 -24
  1000. package/dist/packages/provenance.d.ts +3 -1
  1001. package/dist/packages/provenance.js +7 -3
  1002. package/dist/packages/tgz.d.ts +0 -2
  1003. package/dist/packages/tgz.js +0 -2
  1004. package/dist/platform/actor.d.ts +48 -0
  1005. package/dist/platform/actor.js +100 -0
  1006. package/dist/platform/agent-docs.d.ts +18 -0
  1007. package/dist/platform/agent-docs.js +59 -0
  1008. package/dist/platform/availability.d.ts +19 -0
  1009. package/dist/platform/availability.js +47 -0
  1010. package/dist/platform/connector-person-fields.d.ts +67 -0
  1011. package/dist/platform/connector-person-fields.js +129 -0
  1012. package/dist/platform/errors.d.ts +28 -0
  1013. package/dist/platform/errors.js +65 -0
  1014. package/dist/platform/exclusions.d.ts +11 -0
  1015. package/dist/platform/exclusions.js +789 -0
  1016. package/dist/platform/file-ref.d.ts +90 -0
  1017. package/dist/platform/file-ref.js +162 -0
  1018. package/dist/platform/method.d.ts +6 -0
  1019. package/dist/platform/method.js +16 -0
  1020. package/dist/platform/operation.d.ts +257 -0
  1021. package/dist/platform/operation.js +110 -0
  1022. package/dist/platform/ops/accounts.ops.d.ts +32 -0
  1023. package/dist/platform/ops/accounts.ops.js +292 -0
  1024. package/dist/platform/ops/admin-items.ops.d.ts +37 -0
  1025. package/dist/platform/ops/admin-items.ops.js +279 -0
  1026. package/dist/platform/ops/admin.ops.d.ts +40 -0
  1027. package/dist/platform/ops/admin.ops.js +684 -0
  1028. package/dist/platform/ops/agent-skills.ops.d.ts +52 -0
  1029. package/dist/platform/ops/agent-skills.ops.js +664 -0
  1030. package/dist/platform/ops/agent-templates.ops.d.ts +17 -0
  1031. package/dist/platform/ops/agent-templates.ops.js +272 -0
  1032. package/dist/platform/ops/agents.ops.d.ts +44 -0
  1033. package/dist/platform/ops/agents.ops.js +809 -0
  1034. package/dist/platform/ops/approvals.ops.d.ts +30 -0
  1035. package/dist/platform/ops/approvals.ops.js +121 -0
  1036. package/dist/platform/ops/background.ops.d.ts +14 -0
  1037. package/dist/platform/ops/background.ops.js +137 -0
  1038. package/dist/platform/ops/catalog-admin.ops.d.ts +102 -0
  1039. package/dist/platform/ops/catalog-admin.ops.js +793 -0
  1040. package/dist/platform/ops/channels.ops.d.ts +23 -0
  1041. package/dist/platform/ops/channels.ops.js +432 -0
  1042. package/dist/platform/ops/components.ops.d.ts +48 -0
  1043. package/dist/platform/ops/components.ops.js +913 -0
  1044. package/dist/platform/ops/connectors.ops.d.ts +35 -0
  1045. package/dist/platform/ops/connectors.ops.js +913 -0
  1046. package/dist/platform/ops/conversations.ops.d.ts +30 -0
  1047. package/dist/platform/ops/conversations.ops.js +508 -0
  1048. package/dist/platform/ops/devices.ops.d.ts +28 -0
  1049. package/dist/platform/ops/devices.ops.js +520 -0
  1050. package/dist/platform/ops/errors.d.ts +16 -0
  1051. package/dist/platform/ops/errors.js +30 -0
  1052. package/dist/platform/ops/evals.ops.d.ts +28 -0
  1053. package/dist/platform/ops/evals.ops.js +731 -0
  1054. package/dist/platform/ops/extensions-admin.ops.d.ts +66 -0
  1055. package/dist/platform/ops/extensions-admin.ops.js +766 -0
  1056. package/dist/platform/ops/extensions.ops.d.ts +45 -0
  1057. package/dist/platform/ops/extensions.ops.js +670 -0
  1058. package/dist/platform/ops/inbox.ops.d.ts +25 -0
  1059. package/dist/platform/ops/inbox.ops.js +417 -0
  1060. package/dist/platform/ops/list-handoff.d.ts +10 -0
  1061. package/dist/platform/ops/list-handoff.js +11 -0
  1062. package/dist/platform/ops/marketplaces.ops.d.ts +22 -0
  1063. package/dist/platform/ops/marketplaces.ops.js +490 -0
  1064. package/dist/platform/ops/models.ops.d.ts +25 -0
  1065. package/dist/platform/ops/models.ops.js +242 -0
  1066. package/dist/platform/ops/org-plugins.ops.d.ts +45 -0
  1067. package/dist/platform/ops/org-plugins.ops.js +537 -0
  1068. package/dist/platform/ops/org-settings.ops.d.ts +18 -0
  1069. package/dist/platform/ops/org-settings.ops.js +152 -0
  1070. package/dist/platform/ops/orgs.ops.d.ts +73 -0
  1071. package/dist/platform/ops/orgs.ops.js +722 -0
  1072. package/dist/platform/ops/other-orgs.d.ts +20 -0
  1073. package/dist/platform/ops/other-orgs.js +72 -0
  1074. package/dist/platform/ops/outbox.ops.d.ts +21 -0
  1075. package/dist/platform/ops/outbox.ops.js +126 -0
  1076. package/dist/platform/ops/paging.d.ts +14 -0
  1077. package/dist/platform/ops/paging.js +20 -0
  1078. package/dist/platform/ops/person-inputs.d.ts +61 -0
  1079. package/dist/platform/ops/person-inputs.js +121 -0
  1080. package/dist/platform/ops/platform-icons.ops.d.ts +14 -0
  1081. package/dist/platform/ops/platform-icons.ops.js +117 -0
  1082. package/dist/platform/ops/platform.ops.d.ts +43 -0
  1083. package/dist/platform/ops/platform.ops.js +314 -0
  1084. package/dist/platform/ops/plugins.ops.d.ts +39 -0
  1085. package/dist/platform/ops/plugins.ops.js +454 -0
  1086. package/dist/platform/ops/previewers.ops.d.ts +14 -0
  1087. package/dist/platform/ops/previewers.ops.js +109 -0
  1088. package/dist/platform/ops/requests.ops.d.ts +14 -0
  1089. package/dist/platform/ops/requests.ops.js +201 -0
  1090. package/dist/platform/ops/role.d.ts +4 -0
  1091. package/dist/platform/ops/role.js +10 -0
  1092. package/dist/platform/ops/schedules.ops.d.ts +21 -0
  1093. package/dist/platform/ops/schedules.ops.js +509 -0
  1094. package/dist/platform/ops/setup.ops.d.ts +24 -0
  1095. package/dist/platform/ops/setup.ops.js +212 -0
  1096. package/dist/platform/ops/shares.ops.d.ts +16 -0
  1097. package/dist/platform/ops/shares.ops.js +107 -0
  1098. package/dist/platform/ops/skills.ops.d.ts +23 -0
  1099. package/dist/platform/ops/skills.ops.js +279 -0
  1100. package/dist/platform/ops/summary.d.ts +15 -0
  1101. package/dist/platform/ops/summary.js +28 -0
  1102. package/dist/platform/ops/themes.ops.d.ts +14 -0
  1103. package/dist/platform/ops/themes.ops.js +47 -0
  1104. package/dist/platform/ops/ui.ops.d.ts +8 -0
  1105. package/dist/platform/ops/ui.ops.js +41 -0
  1106. package/dist/platform/ops/unavailable.d.ts +23 -0
  1107. package/dist/platform/ops/unavailable.js +118 -0
  1108. package/dist/platform/parity.d.ts +40 -0
  1109. package/dist/platform/parity.js +360 -0
  1110. package/dist/platform/person-fields.d.ts +120 -0
  1111. package/dist/platform/person-fields.js +404 -0
  1112. package/dist/platform/platform-ops.module.d.ts +47 -0
  1113. package/dist/platform/platform-ops.module.js +160 -0
  1114. package/dist/platform/platform.module.d.ts +9 -0
  1115. package/dist/platform/platform.module.js +28 -0
  1116. package/dist/platform/registry.d.ts +30 -0
  1117. package/dist/platform/registry.js +111 -0
  1118. package/dist/platform/route-schemas.d.ts +18 -0
  1119. package/dist/platform/route-schemas.js +107 -0
  1120. package/dist/platform/sealed-inputs.d.ts +44 -0
  1121. package/dist/platform/sealed-inputs.js +116 -0
  1122. package/dist/platform/sealed-reveals.controller.d.ts +17 -0
  1123. package/dist/platform/sealed-reveals.controller.js +48 -0
  1124. package/dist/platform/sealed-reveals.d.ts +54 -0
  1125. package/dist/platform/sealed-reveals.js +155 -0
  1126. package/dist/push/delivery.d.ts +88 -0
  1127. package/dist/push/delivery.js +269 -0
  1128. package/dist/push/fanout.d.ts +29 -0
  1129. package/dist/push/fanout.js +95 -0
  1130. package/dist/push/jobs.d.ts +43 -0
  1131. package/dist/push/jobs.js +19 -0
  1132. package/dist/push/preferences.service.d.ts +18 -0
  1133. package/dist/push/preferences.service.js +82 -0
  1134. package/dist/push/provider-host.d.ts +34 -0
  1135. package/dist/push/provider-host.js +94 -0
  1136. package/dist/push/push-owed.d.ts +33 -0
  1137. package/dist/push/push-owed.js +93 -0
  1138. package/dist/push/push-processor.d.ts +40 -0
  1139. package/dist/push/push-processor.js +114 -0
  1140. package/dist/push/push.controller.d.ts +28 -0
  1141. package/dist/push/push.controller.js +92 -0
  1142. package/dist/push/push.module.d.ts +6 -0
  1143. package/dist/push/push.module.js +29 -0
  1144. package/dist/push/push.schemas.d.ts +88 -0
  1145. package/dist/push/push.schemas.js +53 -0
  1146. package/dist/push/recipients.d.ts +29 -0
  1147. package/dist/push/recipients.js +270 -0
  1148. package/dist/push/registration-cleanup.d.ts +9 -0
  1149. package/dist/push/registration-cleanup.js +16 -0
  1150. package/dist/push/registrations.service.d.ts +55 -0
  1151. package/dist/push/registrations.service.js +254 -0
  1152. package/dist/push/stale.job.d.ts +25 -0
  1153. package/dist/push/stale.job.js +76 -0
  1154. package/dist/push/texts.d.ts +31 -0
  1155. package/dist/push/texts.js +46 -0
  1156. package/dist/push/token-store.d.ts +31 -0
  1157. package/dist/push/token-store.js +52 -0
  1158. package/dist/push/triggers.d.ts +19 -0
  1159. package/dist/push/triggers.js +30 -0
  1160. package/dist/roles/gateway-role.d.ts +65 -0
  1161. package/dist/roles/gateway-role.js +144 -0
  1162. package/dist/roles/gateway.module.d.ts +10 -0
  1163. package/dist/roles/gateway.module.js +41 -0
  1164. package/dist/roles/worker-role.d.ts +82 -0
  1165. package/dist/roles/worker-role.js +186 -0
  1166. package/dist/roles/worker.module.d.ts +14 -0
  1167. package/dist/roles/worker.module.js +151 -0
  1168. package/dist/runtime/abort.js +19 -2
  1169. package/dist/runtime/checkpointer.d.ts +11 -3
  1170. package/dist/runtime/checkpointer.js +93 -55
  1171. package/dist/runtime/compaction-progress.d.ts +62 -0
  1172. package/dist/runtime/compaction-progress.js +82 -0
  1173. package/dist/runtime/compaction-settings.service.d.ts +24 -0
  1174. package/dist/runtime/compaction-settings.service.js +48 -0
  1175. package/dist/runtime/compaction.service.d.ts +50 -0
  1176. package/dist/runtime/compaction.service.js +75 -0
  1177. package/dist/runtime/context/build.d.ts +162 -47
  1178. package/dist/runtime/context/build.js +512 -88
  1179. package/dist/runtime/context/claude-tools.d.ts +4 -1
  1180. package/dist/runtime/context/claude-tools.js +13 -12
  1181. package/dist/runtime/context/compaction.d.ts +111 -16
  1182. package/dist/runtime/context/compaction.js +434 -55
  1183. package/dist/runtime/context/device-paths.d.ts +92 -0
  1184. package/dist/runtime/context/device-paths.js +185 -0
  1185. package/dist/runtime/context/fit.d.ts +111 -0
  1186. package/dist/runtime/context/fit.js +278 -0
  1187. package/dist/runtime/context/permission-profile.d.ts +55 -0
  1188. package/dist/runtime/context/permission-profile.js +275 -0
  1189. package/dist/runtime/context/plugin-context.d.ts +20 -0
  1190. package/dist/runtime/context/plugin-context.js +30 -0
  1191. package/dist/runtime/context/project-root.d.ts +43 -0
  1192. package/dist/runtime/context/project-root.js +85 -0
  1193. package/dist/runtime/context/reminders.d.ts +2 -0
  1194. package/dist/runtime/context/reminders.js +2 -0
  1195. package/dist/runtime/context/run-context.d.ts +88 -0
  1196. package/dist/runtime/context/run-context.js +295 -0
  1197. package/dist/runtime/context/skills.d.ts +38 -36
  1198. package/dist/runtime/context/skills.js +90 -117
  1199. package/dist/runtime/context/tool-changes.d.ts +27 -0
  1200. package/dist/runtime/context/tool-changes.js +50 -0
  1201. package/dist/runtime/conversation-lock.d.ts +19 -17
  1202. package/dist/runtime/conversation-lock.js +66 -80
  1203. package/dist/runtime/hook-calls.d.ts +27 -10
  1204. package/dist/runtime/hook-calls.js +72 -21
  1205. package/dist/runtime/langgraph-loop.d.ts +3 -1
  1206. package/dist/runtime/langgraph-loop.js +62 -25
  1207. package/dist/runtime/limits.d.ts +15 -0
  1208. package/dist/runtime/limits.js +25 -0
  1209. package/dist/runtime/loop.d.ts +57 -8
  1210. package/dist/runtime/loop.js +15 -0
  1211. package/dist/runtime/maintenance-queue.d.ts +10 -0
  1212. package/dist/runtime/maintenance-queue.js +10 -0
  1213. package/dist/runtime/maintenance.d.ts +63 -74
  1214. package/dist/runtime/maintenance.js +288 -138
  1215. package/dist/runtime/model-call.d.ts +251 -23
  1216. package/dist/runtime/model-call.js +1142 -410
  1217. package/dist/runtime/permission-context-errors.d.ts +39 -0
  1218. package/dist/runtime/permission-context-errors.js +67 -0
  1219. package/dist/runtime/permission-context.service.d.ts +60 -0
  1220. package/dist/runtime/permission-context.service.js +289 -0
  1221. package/dist/runtime/plugin-context.service.d.ts +75 -0
  1222. package/dist/runtime/plugin-context.service.js +210 -0
  1223. package/dist/runtime/project/knowledge.d.ts +135 -0
  1224. package/dist/runtime/project/knowledge.js +256 -0
  1225. package/dist/runtime/project/knowledge.service.d.ts +94 -0
  1226. package/dist/runtime/project/knowledge.service.js +347 -0
  1227. package/dist/runtime/providers.d.ts +203 -37
  1228. package/dist/runtime/providers.js +458 -125
  1229. package/dist/runtime/queue-lost-jobs.d.ts +24 -0
  1230. package/dist/runtime/queue-lost-jobs.js +51 -0
  1231. package/dist/runtime/quota.d.ts +17 -3
  1232. package/dist/runtime/quota.js +27 -2
  1233. package/dist/runtime/run-context.service.d.ts +82 -0
  1234. package/dist/runtime/run-context.service.js +256 -0
  1235. package/dist/runtime/run-control.d.ts +90 -0
  1236. package/dist/runtime/run-control.js +163 -0
  1237. package/dist/runtime/run-deletion.d.ts +29 -0
  1238. package/dist/runtime/run-deletion.js +157 -0
  1239. package/dist/runtime/run-drafts.d.ts +127 -0
  1240. package/dist/runtime/run-drafts.js +331 -0
  1241. package/dist/runtime/run-execution.d.ts +80 -0
  1242. package/dist/runtime/run-execution.js +191 -0
  1243. package/dist/runtime/run-finish.d.ts +70 -24
  1244. package/dist/runtime/run-finish.js +230 -55
  1245. package/dist/runtime/run-jobs.d.ts +145 -0
  1246. package/dist/runtime/run-jobs.js +301 -0
  1247. package/dist/runtime/run-liveness.d.ts +11 -0
  1248. package/dist/runtime/run-liveness.js +19 -0
  1249. package/dist/runtime/run-orphan-check.job.d.ts +145 -0
  1250. package/dist/runtime/run-orphan-check.job.js +425 -0
  1251. package/dist/runtime/run-processors.d.ts +75 -0
  1252. package/dist/runtime/run-processors.js +220 -0
  1253. package/dist/runtime/run-queue.d.ts +148 -88
  1254. package/dist/runtime/run-queue.js +680 -368
  1255. package/dist/runtime/run-status.d.ts +12 -0
  1256. package/dist/runtime/run-status.js +21 -0
  1257. package/dist/runtime/run-steps.d.ts +47 -0
  1258. package/dist/runtime/run-steps.js +119 -0
  1259. package/dist/runtime/run-worker.d.ts +183 -82
  1260. package/dist/runtime/run-worker.js +783 -298
  1261. package/dist/runtime/runtime.module.d.ts +9 -0
  1262. package/dist/runtime/runtime.module.js +172 -0
  1263. package/dist/runtime/step-log.d.ts +69 -0
  1264. package/dist/runtime/step-log.js +138 -0
  1265. package/dist/runtime/stream.controller.d.ts +30 -11
  1266. package/dist/runtime/stream.controller.js +75 -18
  1267. package/dist/runtime/stream.d.ts +33 -6
  1268. package/dist/runtime/stream.js +184 -9
  1269. package/dist/runtime/subagents/child.d.ts +58 -51
  1270. package/dist/runtime/subagents/child.js +108 -87
  1271. package/dist/runtime/subagents/definition.d.ts +58 -38
  1272. package/dist/runtime/subagents/definition.js +165 -214
  1273. package/dist/runtime/subagents/deliveries.d.ts +74 -0
  1274. package/dist/runtime/subagents/deliveries.js +240 -0
  1275. package/dist/runtime/subagents/dispatch.d.ts +203 -29
  1276. package/dist/runtime/subagents/dispatch.js +353 -292
  1277. package/dist/runtime/subagents/limits.d.ts +32 -8
  1278. package/dist/runtime/subagents/limits.js +44 -8
  1279. package/dist/runtime/subagents/messages.d.ts +99 -0
  1280. package/dist/runtime/subagents/messages.js +338 -0
  1281. package/dist/runtime/subagents/org-agents.d.ts +4 -4
  1282. package/dist/runtime/subagents/org-agents.js +3 -2
  1283. package/dist/runtime/subagents/preamble.d.ts +6 -4
  1284. package/dist/runtime/subagents/preamble.js +11 -7
  1285. package/dist/runtime/subagents/progress.d.ts +10 -8
  1286. package/dist/runtime/subagents/progress.js +11 -6
  1287. package/dist/runtime/subagents/render.d.ts +29 -0
  1288. package/dist/runtime/subagents/render.js +52 -0
  1289. package/dist/runtime/subagents/roster.d.ts +27 -10
  1290. package/dist/runtime/subagents/roster.js +49 -13
  1291. package/dist/runtime/subagents/skill-fork.d.ts +14 -16
  1292. package/dist/runtime/subagents/skill-fork.js +29 -10
  1293. package/dist/runtime/subagents/status.d.ts +14 -0
  1294. package/dist/runtime/subagents/status.js +23 -0
  1295. package/dist/runtime/subagents/subagents.service.d.ts +43 -0
  1296. package/dist/runtime/subagents/subagents.service.js +106 -0
  1297. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  1298. package/dist/runtime/subagents/template-skills.js +77 -0
  1299. package/dist/runtime/subagents/tree-jobs.d.ts +62 -0
  1300. package/dist/runtime/subagents/tree-jobs.js +86 -0
  1301. package/dist/runtime/usage-report-jobs.d.ts +63 -0
  1302. package/dist/runtime/usage-report-jobs.js +107 -0
  1303. package/dist/runtime/usage-report.d.ts +111 -113
  1304. package/dist/runtime/usage-report.js +290 -266
  1305. package/dist/runtime/waits.d.ts +204 -167
  1306. package/dist/runtime/waits.js +581 -690
  1307. package/dist/runtime/write-base.d.ts +95 -0
  1308. package/dist/runtime/write-base.js +281 -0
  1309. package/dist/runtime/write-base.service.d.ts +68 -0
  1310. package/dist/runtime/write-base.service.js +184 -0
  1311. package/dist/sandbox/attachments-path.d.ts +15 -0
  1312. package/dist/sandbox/attachments-path.js +15 -0
  1313. package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
  1314. package/dist/sandbox/cloud-permission-snapshot.js +430 -0
  1315. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
  1316. package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
  1317. package/dist/sandbox/device-reports.d.ts +110 -0
  1318. package/dist/sandbox/device-reports.js +317 -0
  1319. package/dist/sandbox/device-reports.module.d.ts +7 -0
  1320. package/dist/sandbox/device-reports.module.js +25 -0
  1321. package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
  1322. package/dist/sandbox/device-sandbox-settings.js +470 -0
  1323. package/dist/sandbox/device-sandbox.d.ts +210 -0
  1324. package/dist/sandbox/device-sandbox.js +234 -0
  1325. package/dist/sandbox/device-services.d.ts +83 -0
  1326. package/dist/sandbox/device-services.js +234 -0
  1327. package/dist/sandbox/held-operations.d.ts +43 -0
  1328. package/dist/sandbox/held-operations.js +137 -0
  1329. package/dist/sandbox/job-ids.d.ts +10 -0
  1330. package/dist/sandbox/job-ids.js +10 -0
  1331. package/dist/sandbox/jobs.d.ts +89 -0
  1332. package/dist/sandbox/jobs.js +174 -0
  1333. package/dist/sandbox/kernel-read.d.ts +85 -0
  1334. package/dist/sandbox/kernel-read.js +87 -0
  1335. package/dist/sandbox/leases.d.ts +92 -81
  1336. package/dist/sandbox/leases.js +239 -343
  1337. package/dist/sandbox/legacy-retirement.d.ts +269 -0
  1338. package/dist/sandbox/legacy-retirement.js +925 -0
  1339. package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
  1340. package/dist/sandbox/legacy-retirement.module.js +25 -0
  1341. package/dist/sandbox/managed-device-context.d.ts +118 -0
  1342. package/dist/sandbox/managed-device-context.js +374 -0
  1343. package/dist/sandbox/managed-device-context.module.d.ts +6 -0
  1344. package/dist/sandbox/managed-device-context.module.js +37 -0
  1345. package/dist/sandbox/modes.d.ts +210 -0
  1346. package/dist/sandbox/modes.js +253 -0
  1347. package/dist/sandbox/network-grants.d.ts +69 -0
  1348. package/dist/sandbox/network-grants.js +227 -0
  1349. package/dist/sandbox/network-grants.module.d.ts +2 -0
  1350. package/dist/sandbox/network-grants.module.js +14 -0
  1351. package/dist/sandbox/operation-authority-types.d.ts +27 -0
  1352. package/dist/sandbox/operation-authority-types.js +50 -0
  1353. package/dist/sandbox/operation-authority.d.ts +166 -0
  1354. package/dist/sandbox/operation-authority.js +923 -0
  1355. package/dist/sandbox/operation-authority.module.d.ts +2 -0
  1356. package/dist/sandbox/operation-authority.module.js +29 -0
  1357. package/dist/sandbox/operation-intents.d.ts +263 -0
  1358. package/dist/sandbox/operation-intents.js +1464 -0
  1359. package/dist/sandbox/operation-intents.module.d.ts +2 -0
  1360. package/dist/sandbox/operation-intents.module.js +21 -0
  1361. package/dist/sandbox/operation-payloads.d.ts +33 -0
  1362. package/dist/sandbox/operation-payloads.js +332 -0
  1363. package/dist/sandbox/operation-reconcile.job.d.ts +73 -0
  1364. package/dist/sandbox/operation-reconcile.job.js +332 -0
  1365. package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
  1366. package/dist/sandbox/permission-authority-epochs.js +83 -0
  1367. package/dist/sandbox/permission-authority-lock.d.ts +44 -0
  1368. package/dist/sandbox/permission-authority-lock.js +167 -0
  1369. package/dist/sandbox/permission-authority.module.d.ts +9 -0
  1370. package/dist/sandbox/permission-authority.module.js +55 -0
  1371. package/dist/sandbox/permission-auto-grants.d.ts +42 -0
  1372. package/dist/sandbox/permission-auto-grants.js +145 -0
  1373. package/dist/sandbox/permission-availability.d.ts +63 -0
  1374. package/dist/sandbox/permission-availability.js +71 -0
  1375. package/dist/sandbox/permission-call-grants.d.ts +47 -0
  1376. package/dist/sandbox/permission-call-grants.js +427 -0
  1377. package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
  1378. package/dist/sandbox/permission-call-grants.module.js +28 -0
  1379. package/dist/sandbox/permission-call-types.d.ts +149 -0
  1380. package/dist/sandbox/permission-call-types.js +1 -0
  1381. package/dist/sandbox/permission-ceiling-writes.d.ts +57 -0
  1382. package/dist/sandbox/permission-ceiling-writes.js +236 -0
  1383. package/dist/sandbox/permission-config-publication.d.ts +126 -0
  1384. package/dist/sandbox/permission-config-publication.js +529 -0
  1385. package/dist/sandbox/permission-context-types.d.ts +60 -0
  1386. package/dist/sandbox/permission-context-types.js +11 -0
  1387. package/dist/sandbox/permission-facts.d.ts +384 -0
  1388. package/dist/sandbox/permission-facts.js +714 -0
  1389. package/dist/sandbox/permission-facts.module.d.ts +2 -0
  1390. package/dist/sandbox/permission-facts.module.js +20 -0
  1391. package/dist/sandbox/permission-instance-writes.d.ts +76 -0
  1392. package/dist/sandbox/permission-instance-writes.js +232 -0
  1393. package/dist/sandbox/permission-runtime-reports.d.ts +92 -0
  1394. package/dist/sandbox/permission-runtime-reports.js +337 -0
  1395. package/dist/sandbox/permission-transitions.d.ts +31 -0
  1396. package/dist/sandbox/permission-transitions.js +158 -0
  1397. package/dist/sandbox/providers.d.ts +60 -0
  1398. package/dist/sandbox/providers.js +101 -0
  1399. package/dist/sandbox/providers.module.d.ts +2 -0
  1400. package/dist/sandbox/providers.module.js +19 -0
  1401. package/dist/sandbox/request-not-sent.d.ts +15 -0
  1402. package/dist/sandbox/request-not-sent.js +20 -0
  1403. package/dist/sandbox/review/classifier.d.ts +221 -0
  1404. package/dist/sandbox/review/classifier.js +536 -0
  1405. package/dist/sandbox/review/index.d.ts +13 -0
  1406. package/dist/sandbox/review/index.js +10 -0
  1407. package/dist/sandbox/review/permission-candidate.d.ts +142 -0
  1408. package/dist/sandbox/review/permission-candidate.js +446 -0
  1409. package/dist/sandbox/review/review.service.d.ts +184 -0
  1410. package/dist/sandbox/review/review.service.js +586 -0
  1411. package/dist/sandbox/review/rules.d.ts +87 -0
  1412. package/dist/sandbox/review/rules.js +5363 -0
  1413. package/dist/sandbox/review/types.d.ts +122 -0
  1414. package/dist/sandbox/review/types.js +48 -0
  1415. package/dist/sandbox/sandbox-file-reader.d.ts +47 -0
  1416. package/dist/sandbox/sandbox-file-reader.js +125 -0
  1417. package/dist/sandbox/sandbox.module.d.ts +10 -0
  1418. package/dist/sandbox/sandbox.module.js +78 -0
  1419. package/dist/sandbox/sandbox.service.d.ts +929 -154
  1420. package/dist/sandbox/sandbox.service.js +3315 -493
  1421. package/dist/sandbox/unreachable.d.ts +30 -0
  1422. package/dist/sandbox/unreachable.js +125 -0
  1423. package/dist/sandbox/use-context.d.ts +20 -0
  1424. package/dist/sandbox/use-context.js +1 -0
  1425. package/dist/schedules/calendar.d.ts +134 -0
  1426. package/dist/schedules/calendar.js +410 -0
  1427. package/dist/schedules/effective-settings.d.ts +22 -0
  1428. package/dist/schedules/effective-settings.js +18 -0
  1429. package/dist/schedules/errors.d.ts +8 -0
  1430. package/dist/schedules/errors.js +8 -0
  1431. package/dist/schedules/fire.d.ts +146 -0
  1432. package/dist/schedules/fire.js +728 -0
  1433. package/dist/schedules/grant-rules.d.ts +120 -0
  1434. package/dist/schedules/grant-rules.js +186 -0
  1435. package/dist/schedules/job-ids.d.ts +81 -0
  1436. package/dist/schedules/job-ids.js +95 -0
  1437. package/dist/schedules/pause.d.ts +9 -0
  1438. package/dist/schedules/pause.js +35 -0
  1439. package/dist/schedules/run-tracker.d.ts +84 -0
  1440. package/dist/schedules/run-tracker.js +350 -0
  1441. package/dist/schedules/scan.job.d.ts +45 -0
  1442. package/dist/schedules/scan.job.js +189 -0
  1443. package/dist/schedules/schedule-math.d.ts +73 -0
  1444. package/dist/schedules/schedule-math.js +294 -0
  1445. package/dist/schedules/scheduled-tasks.service.d.ts +359 -0
  1446. package/dist/schedules/scheduled-tasks.service.js +1249 -0
  1447. package/dist/schedules/schedules.controller.d.ts +72 -0
  1448. package/dist/schedules/schedules.controller.js +256 -0
  1449. package/dist/schedules/schedules.module.d.ts +16 -0
  1450. package/dist/schedules/schedules.module.js +63 -0
  1451. package/dist/schedules/schedules.schemas.d.ts +351 -0
  1452. package/dist/schedules/schedules.schemas.js +213 -0
  1453. package/dist/schedules/store.d.ts +86 -0
  1454. package/dist/schedules/store.js +421 -0
  1455. package/dist/schedules/store.module.d.ts +6 -0
  1456. package/dist/schedules/store.module.js +21 -0
  1457. package/dist/schedules/types.d.ts +110 -0
  1458. package/dist/schedules/types.js +1 -0
  1459. package/dist/schedules/unattended.d.ts +89 -0
  1460. package/dist/schedules/unattended.js +193 -0
  1461. package/dist/setup/kernel-checks.d.ts +91 -0
  1462. package/dist/setup/kernel-checks.js +296 -0
  1463. package/dist/setup/oauth-token-probe.d.ts +40 -0
  1464. package/dist/setup/oauth-token-probe.js +96 -0
  1465. package/dist/setup/redact-check.d.ts +18 -0
  1466. package/dist/setup/redact-check.js +46 -0
  1467. package/dist/setup/setup-check-registry.d.ts +86 -0
  1468. package/dist/setup/setup-check-registry.js +75 -0
  1469. package/dist/setup/setup-checks.controller.d.ts +28 -0
  1470. package/dist/setup/setup-checks.controller.js +78 -0
  1471. package/dist/setup/setup-checks.schemas.d.ts +67 -0
  1472. package/dist/setup/setup-checks.schemas.js +75 -0
  1473. package/dist/setup/setup-checks.service.d.ts +168 -0
  1474. package/dist/setup/setup-checks.service.js +781 -0
  1475. package/dist/setup/setup-guides.controller.d.ts +18 -0
  1476. package/dist/setup/setup-guides.controller.js +48 -0
  1477. package/dist/setup/setup-guides.schemas.d.ts +10 -0
  1478. package/dist/setup/setup-guides.schemas.js +6 -0
  1479. package/dist/setup/setup-guides.service.d.ts +141 -0
  1480. package/dist/setup/setup-guides.service.js +348 -0
  1481. package/dist/setup/setup.module.d.ts +8 -0
  1482. package/dist/setup/setup.module.js +31 -0
  1483. package/dist/shares/liveness.d.ts +59 -0
  1484. package/dist/shares/liveness.js +163 -0
  1485. package/dist/shares/revoke.d.ts +26 -0
  1486. package/dist/shares/revoke.js +43 -0
  1487. package/dist/shares/settings.d.ts +76 -0
  1488. package/dist/shares/settings.js +117 -0
  1489. package/dist/shares/share-code.d.ts +4 -0
  1490. package/dist/shares/share-code.js +28 -0
  1491. package/dist/shares/share-objects.d.ts +52 -0
  1492. package/dist/shares/share-objects.js +123 -0
  1493. package/dist/shares/share-open.controller.d.ts +35 -0
  1494. package/dist/shares/share-open.controller.js +107 -0
  1495. package/dist/shares/share-open.service.d.ts +107 -0
  1496. package/dist/shares/share-open.service.js +288 -0
  1497. package/dist/shares/share-previews.controller.d.ts +50 -0
  1498. package/dist/shares/share-previews.controller.js +115 -0
  1499. package/dist/shares/shares.controller.d.ts +34 -0
  1500. package/dist/shares/shares.controller.js +114 -0
  1501. package/dist/shares/shares.module.d.ts +8 -0
  1502. package/dist/shares/shares.module.js +41 -0
  1503. package/dist/shares/shares.schemas.d.ts +31 -0
  1504. package/dist/shares/shares.schemas.js +25 -0
  1505. package/dist/shares/shares.service.d.ts +183 -0
  1506. package/dist/shares/shares.service.js +561 -0
  1507. package/dist/shares/sweep.job.d.ts +74 -0
  1508. package/dist/shares/sweep.job.js +332 -0
  1509. package/dist/skills/agent-skills.controller.d.ts +48 -0
  1510. package/dist/skills/agent-skills.controller.js +131 -0
  1511. package/dist/skills/agent-skills.service.d.ts +258 -0
  1512. package/dist/skills/agent-skills.service.js +971 -0
  1513. package/dist/skills/catalog.d.ts +112 -86
  1514. package/dist/skills/catalog.js +222 -269
  1515. package/dist/skills/changes.controller.d.ts +14 -24
  1516. package/dist/skills/changes.controller.js +35 -58
  1517. package/dist/skills/changes.service.d.ts +81 -116
  1518. package/dist/skills/changes.service.js +354 -641
  1519. package/dist/skills/conversation-catalog.d.ts +52 -0
  1520. package/dist/skills/conversation-catalog.js +142 -0
  1521. package/dist/skills/invocable.controller.d.ts +2 -2
  1522. package/dist/skills/invocable.controller.js +10 -7
  1523. package/dist/skills/invocation-keys.d.ts +1 -1
  1524. package/dist/skills/invocation-keys.js +1 -1
  1525. package/dist/skills/invoke.d.ts +104 -21
  1526. package/dist/skills/invoke.js +235 -26
  1527. package/dist/skills/package.d.ts +15 -1
  1528. package/dist/skills/package.js +14 -1
  1529. package/dist/skills/skill-files.d.ts +91 -0
  1530. package/dist/skills/skill-files.js +144 -0
  1531. package/dist/skills/skills.controller.d.ts +59 -15
  1532. package/dist/skills/skills.controller.js +139 -26
  1533. package/dist/skills/skills.module.d.ts +6 -0
  1534. package/dist/skills/skills.module.js +60 -0
  1535. package/dist/skills/skills.schemas.d.ts +96 -0
  1536. package/dist/skills/skills.schemas.js +151 -0
  1537. package/dist/skills/skills.service.d.ts +218 -76
  1538. package/dist/skills/skills.service.js +850 -292
  1539. package/dist/skills/usable.d.ts +131 -0
  1540. package/dist/skills/usable.js +521 -0
  1541. package/dist/storage/purge.d.ts +22 -7
  1542. package/dist/storage/purge.js +55 -3
  1543. package/dist/storage/storage.module.d.ts +6 -0
  1544. package/dist/storage/storage.module.js +23 -0
  1545. package/dist/storage/storage.service.d.ts +20 -4
  1546. package/dist/storage/storage.service.js +56 -4
  1547. package/dist/themes/avatar-preset-key.d.ts +6 -0
  1548. package/dist/themes/avatar-preset-key.js +9 -0
  1549. package/dist/themes/platform-icon-objects.d.ts +51 -0
  1550. package/dist/themes/platform-icon-objects.js +113 -0
  1551. package/dist/themes/platform-icon-public.controller.d.ts +17 -0
  1552. package/dist/themes/platform-icon-public.controller.js +58 -0
  1553. package/dist/themes/platform-icon.controller.d.ts +22 -0
  1554. package/dist/themes/platform-icon.controller.js +65 -0
  1555. package/dist/themes/platform-icon.schemas.d.ts +48 -0
  1556. package/dist/themes/platform-icon.schemas.js +53 -0
  1557. package/dist/themes/platform-icon.service.d.ts +83 -0
  1558. package/dist/themes/platform-icon.service.js +301 -0
  1559. package/dist/themes/render-css.d.ts +13 -0
  1560. package/dist/themes/render-css.js +135 -0
  1561. package/dist/themes/theme-delivery.service.d.ts +44 -0
  1562. package/dist/themes/theme-delivery.service.js +131 -0
  1563. package/dist/themes/theme-state.d.ts +157 -0
  1564. package/dist/themes/theme-state.js +278 -0
  1565. package/dist/themes/theme-usage.d.ts +61 -0
  1566. package/dist/themes/theme-usage.js +98 -0
  1567. package/dist/themes/themes-public.controller.d.ts +33 -0
  1568. package/dist/themes/themes-public.controller.js +98 -0
  1569. package/dist/themes/themes.controller.d.ts +13 -0
  1570. package/dist/themes/themes.controller.js +38 -0
  1571. package/dist/themes/themes.module.d.ts +6 -0
  1572. package/dist/themes/themes.module.js +26 -0
  1573. package/dist/themes/themes.schemas.d.ts +3 -0
  1574. package/dist/themes/themes.schemas.js +2 -0
  1575. package/dist/themes/themes.service.d.ts +77 -0
  1576. package/dist/themes/themes.service.js +133 -0
  1577. package/dist/time-zone.d.ts +5 -0
  1578. package/dist/time-zone.js +19 -0
  1579. package/dist/tools/admin-connectors.d.ts +71 -0
  1580. package/dist/tools/admin-connectors.js +139 -0
  1581. package/dist/tools/approvals.controller.d.ts +6 -2
  1582. package/dist/tools/approvals.controller.js +49 -12
  1583. package/dist/tools/approvals.schemas.d.ts +23 -0
  1584. package/dist/tools/approvals.schemas.js +19 -0
  1585. package/dist/tools/approvals.service.d.ts +605 -35
  1586. package/dist/tools/approvals.service.js +1875 -238
  1587. package/dist/tools/breaker.d.ts +2 -2
  1588. package/dist/tools/breaker.js +21 -3
  1589. package/dist/tools/builtin-names.d.ts +124 -0
  1590. package/dist/tools/builtin-names.js +213 -0
  1591. package/dist/tools/builtins/agent.d.ts +27 -25
  1592. package/dist/tools/builtins/agent.js +70 -63
  1593. package/dist/tools/builtins/artifacts.d.ts +69 -0
  1594. package/dist/tools/builtins/artifacts.js +143 -0
  1595. package/dist/tools/builtins/ask-user.d.ts +3 -3
  1596. package/dist/tools/builtins/ask-user.js +6 -5
  1597. package/dist/tools/builtins/builtin-tools.d.ts +66 -0
  1598. package/dist/tools/builtins/builtin-tools.js +298 -0
  1599. package/dist/tools/builtins/conversation-files.d.ts +48 -0
  1600. package/dist/tools/builtins/conversation-files.js +162 -0
  1601. package/dist/tools/builtins/current-time.d.ts +26 -0
  1602. package/dist/tools/builtins/current-time.js +99 -0
  1603. package/dist/tools/builtins/handback.d.ts +28 -0
  1604. package/dist/tools/builtins/handback.js +53 -0
  1605. package/dist/tools/builtins/image/generate.d.ts +65 -0
  1606. package/dist/tools/builtins/image/generate.js +594 -0
  1607. package/dist/tools/builtins/image/index.d.ts +2 -0
  1608. package/dist/tools/builtins/image/index.js +2 -0
  1609. package/dist/tools/builtins/image/paths.d.ts +12 -0
  1610. package/dist/tools/builtins/image/paths.js +26 -0
  1611. package/dist/tools/builtins/image/size.d.ts +12 -0
  1612. package/dist/tools/builtins/image/size.js +36 -0
  1613. package/dist/tools/builtins/platform.d.ts +96 -0
  1614. package/dist/tools/builtins/platform.js +756 -0
  1615. package/dist/tools/builtins/read-tool-output.d.ts +3 -3
  1616. package/dist/tools/builtins/read-tool-output.js +3 -3
  1617. package/dist/tools/builtins/sandbox/bash.d.ts +58 -6
  1618. package/dist/tools/builtins/sandbox/bash.js +463 -45
  1619. package/dist/tools/builtins/sandbox/common.d.ts +300 -40
  1620. package/dist/tools/builtins/sandbox/common.js +521 -140
  1621. package/dist/tools/builtins/sandbox/deliver.d.ts +4 -1
  1622. package/dist/tools/builtins/sandbox/deliver.js +122 -77
  1623. package/dist/tools/builtins/sandbox/device-code.d.ts +40 -0
  1624. package/dist/tools/builtins/sandbox/device-code.js +57 -0
  1625. package/dist/tools/builtins/sandbox/device-owner.d.ts +12 -0
  1626. package/dist/tools/builtins/sandbox/device-owner.js +13 -0
  1627. package/dist/tools/builtins/sandbox/edit.d.ts +1 -1
  1628. package/dist/tools/builtins/sandbox/edit.js +72 -51
  1629. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  1630. package/dist/tools/builtins/sandbox/fetch-attachment.js +126 -0
  1631. package/dist/tools/builtins/sandbox/file-state.d.ts +64 -0
  1632. package/dist/tools/builtins/sandbox/file-state.js +64 -0
  1633. package/dist/tools/builtins/sandbox/glob-match.d.ts +1 -1
  1634. package/dist/tools/builtins/sandbox/glob-match.js +1 -1
  1635. package/dist/tools/builtins/sandbox/glob.d.ts +1 -1
  1636. package/dist/tools/builtins/sandbox/glob.js +27 -17
  1637. package/dist/tools/builtins/sandbox/grep.d.ts +14 -4
  1638. package/dist/tools/builtins/sandbox/grep.js +166 -52
  1639. package/dist/tools/builtins/sandbox/index.d.ts +13 -5
  1640. package/dist/tools/builtins/sandbox/index.js +21 -5
  1641. package/dist/tools/builtins/sandbox/read.d.ts +57 -3
  1642. package/dist/tools/builtins/sandbox/read.js +279 -47
  1643. package/dist/tools/builtins/sandbox/search-command.d.ts +44 -0
  1644. package/dist/tools/builtins/sandbox/search-command.js +94 -0
  1645. package/dist/tools/builtins/sandbox/task-list.d.ts +12 -0
  1646. package/dist/tools/builtins/sandbox/task-list.js +136 -0
  1647. package/dist/tools/builtins/sandbox/task-output.d.ts +67 -0
  1648. package/dist/tools/builtins/sandbox/task-output.js +458 -0
  1649. package/dist/tools/builtins/sandbox/task-stop.d.ts +11 -0
  1650. package/dist/tools/builtins/sandbox/task-stop.js +142 -0
  1651. package/dist/tools/builtins/sandbox/write.d.ts +1 -1
  1652. package/dist/tools/builtins/sandbox/write.js +59 -46
  1653. package/dist/tools/builtins/schedules.d.ts +109 -0
  1654. package/dist/tools/builtins/schedules.js +952 -0
  1655. package/dist/tools/builtins/send-message.d.ts +56 -0
  1656. package/dist/tools/builtins/send-message.js +101 -0
  1657. package/dist/tools/builtins/size-text.d.ts +2 -0
  1658. package/dist/tools/builtins/size-text.js +8 -0
  1659. package/dist/tools/builtins/skill-load.d.ts +88 -25
  1660. package/dist/tools/builtins/skill-load.js +363 -81
  1661. package/dist/tools/builtins/tool-search.d.ts +9 -8
  1662. package/dist/tools/builtins/tool-search.js +21 -13
  1663. package/dist/tools/builtins/vision/read-image.d.ts +59 -0
  1664. package/dist/tools/builtins/vision/read-image.js +220 -0
  1665. package/dist/tools/builtins/web/errors.d.ts +8 -0
  1666. package/dist/tools/builtins/web/errors.js +53 -0
  1667. package/dist/tools/builtins/web/extract.d.ts +60 -0
  1668. package/dist/tools/builtins/web/extract.js +268 -0
  1669. package/dist/tools/builtins/web/fetch.d.ts +55 -0
  1670. package/dist/tools/builtins/web/fetch.js +175 -0
  1671. package/dist/tools/builtins/web/index.d.ts +13 -0
  1672. package/dist/tools/builtins/web/index.js +12 -0
  1673. package/dist/tools/builtins/web/page-cache.d.ts +25 -0
  1674. package/dist/tools/builtins/web/page-cache.js +77 -0
  1675. package/dist/tools/builtins/web/search.d.ts +25 -0
  1676. package/dist/tools/builtins/web/search.js +208 -0
  1677. package/dist/tools/builtins/web/url.d.ts +17 -0
  1678. package/dist/tools/builtins/web/url.js +43 -0
  1679. package/dist/tools/call-scope.d.ts +105 -0
  1680. package/dist/tools/call-scope.js +81 -0
  1681. package/dist/tools/canonical-json.d.ts +6 -0
  1682. package/dist/tools/canonical-json.js +16 -0
  1683. package/dist/tools/connector-account-policies.d.ts +86 -0
  1684. package/dist/tools/connector-account-policies.js +223 -0
  1685. package/dist/tools/connector-content.controller.d.ts +1 -1
  1686. package/dist/tools/connector-content.controller.js +11 -6
  1687. package/dist/tools/connector-content.d.ts +12 -15
  1688. package/dist/tools/connector-content.js +54 -18
  1689. package/dist/tools/connector-setup.d.ts +28 -0
  1690. package/dist/tools/connector-setup.js +33 -0
  1691. package/dist/tools/connector-tools-jobs.d.ts +35 -0
  1692. package/dist/tools/connector-tools-jobs.js +40 -0
  1693. package/dist/tools/connector-tools.processor.d.ts +32 -0
  1694. package/dist/tools/connector-tools.processor.js +97 -0
  1695. package/dist/tools/connectors.controller.d.ts +129 -19
  1696. package/dist/tools/connectors.controller.js +222 -66
  1697. package/dist/tools/connectors.schemas.d.ts +216 -0
  1698. package/dist/tools/connectors.schemas.js +142 -0
  1699. package/dist/tools/connectors.service.d.ts +367 -38
  1700. package/dist/tools/connectors.service.js +1290 -392
  1701. package/dist/tools/credentials.d.ts +95 -20
  1702. package/dist/tools/credentials.js +294 -36
  1703. package/dist/tools/credentials.module.d.ts +7 -0
  1704. package/dist/tools/credentials.module.js +22 -0
  1705. package/dist/tools/display-names.d.ts +9 -0
  1706. package/dist/tools/display-names.js +24 -0
  1707. package/dist/tools/drift.d.ts +39 -42
  1708. package/dist/tools/drift.js +175 -107
  1709. package/dist/tools/editable-endpoint.d.ts +23 -0
  1710. package/dist/tools/editable-endpoint.js +92 -0
  1711. package/dist/tools/elicitation.d.ts +2 -0
  1712. package/dist/tools/elicitation.js +2 -2
  1713. package/dist/tools/extension-tools.controller.d.ts +14 -0
  1714. package/dist/tools/extension-tools.controller.js +37 -0
  1715. package/dist/tools/fixed-ask.d.ts +7 -0
  1716. package/dist/tools/fixed-ask.js +9 -0
  1717. package/dist/tools/git-asks.d.ts +113 -0
  1718. package/dist/tools/git-asks.js +174 -0
  1719. package/dist/tools/git-push-policy.d.ts +92 -0
  1720. package/dist/tools/git-push-policy.js +180 -0
  1721. package/dist/tools/info.d.ts +92 -17
  1722. package/dist/tools/info.js +186 -44
  1723. package/dist/tools/job-ids.d.ts +9 -0
  1724. package/dist/tools/job-ids.js +10 -0
  1725. package/dist/tools/jobs.d.ts +24 -0
  1726. package/dist/tools/jobs.js +69 -0
  1727. package/dist/tools/naming.d.ts +1 -5
  1728. package/dist/tools/naming.js +1 -7
  1729. package/dist/tools/network-asks.d.ts +275 -0
  1730. package/dist/tools/network-asks.js +415 -0
  1731. package/dist/tools/oauth/authorization-params.d.ts +7 -0
  1732. package/dist/tools/oauth/authorization-params.js +19 -0
  1733. package/dist/tools/oauth/discovery.d.ts +40 -16
  1734. package/dist/tools/oauth/discovery.js +62 -34
  1735. package/dist/tools/oauth/flow-paths.d.ts +16 -0
  1736. package/dist/tools/oauth/flow-paths.js +38 -0
  1737. package/dist/tools/oauth/flow.d.ts +30 -30
  1738. package/dist/tools/oauth/flow.js +119 -82
  1739. package/dist/tools/oauth/oauth.controller.d.ts +6 -9
  1740. package/dist/tools/oauth/oauth.controller.js +13 -19
  1741. package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
  1742. package/dist/tools/oauth/oauth.schemas.js +27 -0
  1743. package/dist/tools/oauth/tokens.d.ts +65 -10
  1744. package/dist/tools/oauth/tokens.js +104 -32
  1745. package/dist/tools/org-tool-switches.d.ts +89 -0
  1746. package/dist/tools/org-tool-switches.js +201 -0
  1747. package/dist/tools/outputs.d.ts +19 -8
  1748. package/dist/tools/outputs.js +64 -16
  1749. package/dist/tools/permission-approval-jobs.d.ts +18 -0
  1750. package/dist/tools/permission-approval-jobs.js +95 -0
  1751. package/dist/tools/pipeline.d.ts +589 -96
  1752. package/dist/tools/pipeline.js +2641 -545
  1753. package/dist/tools/policy.d.ts +55 -26
  1754. package/dist/tools/policy.js +212 -67
  1755. package/dist/tools/questions.controller.d.ts +2 -2
  1756. package/dist/tools/questions.controller.js +11 -8
  1757. package/dist/tools/questions.service.d.ts +145 -28
  1758. package/dist/tools/questions.service.js +467 -142
  1759. package/dist/tools/registry.d.ts +371 -94
  1760. package/dist/tools/registry.js +446 -273
  1761. package/dist/tools/resources.d.ts +1 -1
  1762. package/dist/tools/resources.js +1 -1
  1763. package/dist/tools/result-images.d.ts +91 -0
  1764. package/dist/tools/result-images.js +195 -0
  1765. package/dist/tools/specs.d.ts +5 -4
  1766. package/dist/tools/specs.js +3 -1
  1767. package/dist/tools/tool-review.d.ts +113 -0
  1768. package/dist/tools/tool-review.js +303 -0
  1769. package/dist/tools/tool-watch-queue.d.ts +45 -0
  1770. package/dist/tools/tool-watch-queue.js +28 -0
  1771. package/dist/tools/tool-watch-queue.module.d.ts +7 -0
  1772. package/dist/tools/tool-watch-queue.module.js +24 -0
  1773. package/dist/tools/tool-watch.processor.d.ts +35 -0
  1774. package/dist/tools/tool-watch.processor.js +114 -0
  1775. package/dist/tools/tool-watch.service.d.ts +46 -0
  1776. package/dist/tools/tool-watch.service.js +199 -0
  1777. package/dist/tools/tools.module.d.ts +10 -0
  1778. package/dist/tools/tools.module.js +168 -0
  1779. package/dist/tools/validate.js +1 -1
  1780. package/dist/tools/watched-waits-lock.d.ts +15 -0
  1781. package/dist/tools/watched-waits-lock.js +40 -0
  1782. package/dist/ui/admin-ui.controller.d.ts +56 -0
  1783. package/dist/ui/admin-ui.controller.js +192 -0
  1784. package/dist/ui/arrangement.d.ts +65 -0
  1785. package/dist/ui/arrangement.js +171 -0
  1786. package/dist/ui/call-extension.d.ts +16 -0
  1787. package/dist/ui/call-extension.js +38 -0
  1788. package/dist/ui/embed-token.d.ts +11 -7
  1789. package/dist/ui/embed-token.js +140 -13
  1790. package/dist/ui/registry.d.ts +42 -17
  1791. package/dist/ui/registry.js +46 -14
  1792. package/dist/ui/slots.controller.d.ts +11 -0
  1793. package/dist/ui/slots.controller.js +25 -0
  1794. package/dist/ui/ui-stream.d.ts +41 -19
  1795. package/dist/ui/ui-stream.js +97 -19
  1796. package/dist/ui/ui.module.d.ts +7 -0
  1797. package/dist/ui/ui.module.js +28 -0
  1798. package/dist/ui/ui.schemas.d.ts +73 -0
  1799. package/dist/ui/ui.schemas.js +73 -0
  1800. package/dist/ui/views.controller.d.ts +46 -56
  1801. package/dist/ui/views.controller.js +97 -94
  1802. package/dist/ui/views.d.ts +151 -76
  1803. package/dist/ui/views.js +359 -99
  1804. package/dist/until-aborted.d.ts +5 -0
  1805. package/dist/until-aborted.js +16 -0
  1806. package/package.json +14 -3
  1807. package/src/migrations/0063_tool_keys_claude_code.sql +220 -0
  1808. package/src/migrations/0064_account_last_org.sql +7 -0
  1809. package/src/migrations/0065_conversation_archive.sql +8 -0
  1810. package/src/migrations/0066_extension_display_name.sql +4 -0
  1811. package/src/migrations/0067_agent_profiles.sql +20 -0
  1812. package/src/migrations/0068_agent_avatar_uploads.sql +7 -0
  1813. package/src/migrations/0069_attachments_agent_idx.sql +3 -0
  1814. package/src/migrations/0070_background_tasks.sql +37 -0
  1815. package/src/migrations/0071_background_tasks_reserve.sql +6 -0
  1816. package/src/migrations/0072_background_tasks_stopping.sql +5 -0
  1817. package/src/migrations/0073_org_extension_point_defaults.sql +11 -0
  1818. package/src/migrations/0074_subagent_tree.sql +50 -0
  1819. package/src/migrations/0075_plugin_scope.sql +61 -0
  1820. package/src/migrations/0076_skills_created_by_nullable.sql +6 -0
  1821. package/src/migrations/0077_scope_requests.sql +52 -0
  1822. package/src/migrations/0078_scope_grant_switches.sql +18 -0
  1823. package/src/migrations/0079_scope_live_install_switches.sql +19 -0
  1824. package/src/migrations/0080_rename_enterprise_admin.sql +18 -0
  1825. package/src/migrations/0081_platform_components.sql +129 -0
  1826. package/src/migrations/0082_platform_migration.sql +33 -0
  1827. package/src/migrations/0083_plugin_scope_sync_failures.sql +15 -0
  1828. package/src/migrations/0084_org_owned_items.sql +85 -0
  1829. package/src/migrations/0085_agent_templates_phase4.sql +45 -0
  1830. package/src/migrations/0086_org_layering.sql +30 -0
  1831. package/src/migrations/0087_approval_summary.sql +6 -0
  1832. package/src/migrations/0088_environments.sql +80 -0
  1833. package/src/migrations/0089_model_kinds_usage.sql +38 -0
  1834. package/src/migrations/0090_initial_passwords.sql +27 -0
  1835. package/src/migrations/0091_account_time_zone.sql +4 -0
  1836. package/src/migrations/0092_tools_default_on.sql +27 -0
  1837. package/src/migrations/0093_connected_environments.sql +37 -0
  1838. package/src/migrations/0094_environment_paths_idx.sql +7 -0
  1839. package/src/migrations/0095_environment_files_resets.sql +5 -0
  1840. package/src/migrations/0096_environment_demoted_default.sql +18 -0
  1841. package/src/migrations/0097_extension_installs_enabled_at.sql +16 -0
  1842. package/src/migrations/0098_single_provider_running_first.sql +41 -0
  1843. package/src/migrations/0099_channel_connection_guide_ack.sql +6 -0
  1844. package/src/migrations/0100_catalog_files.sql +13 -0
  1845. package/src/migrations/0101_marketplace_icons.sql +32 -0
  1846. package/src/migrations/0102_themes.sql +64 -0
  1847. package/src/migrations/0103_ui_theme_setting.sql +7 -0
  1848. package/src/migrations/0104_connector_tool_account_policies.sql +16 -0
  1849. package/src/migrations/0105_devices_rename.sql +136 -0
  1850. package/src/migrations/0106_setup_guides_v2.sql +10 -0
  1851. package/src/migrations/0107_extension_client_builds.sql +50 -0
  1852. package/src/migrations/0108_question_skipped.sql +6 -0
  1853. package/src/migrations/0109_audit_platform_idx.sql +5 -0
  1854. package/src/migrations/0110_usage_time_idx.sql +8 -0
  1855. package/src/migrations/0111_agent_skill_sharing.sql +22 -0
  1856. package/src/migrations/0112_skill_share_requests.sql +4 -0
  1857. package/src/migrations/0113_scheduled_tasks.sql +108 -0
  1858. package/src/migrations/0114_network_asks.sql +23 -0
  1859. package/src/migrations/0115_network_requests.sql +28 -0
  1860. package/src/migrations/0116_skills_default_on.sql +37 -0
  1861. package/src/migrations/0117_sandbox_tiers.sql +11 -0
  1862. package/src/migrations/0118_device_policy_ops.sql +6 -0
  1863. package/src/migrations/0119_outbox.sql +22 -0
  1864. package/src/migrations/0120_drop_usage_report_sweep.sql +7 -0
  1865. package/src/migrations/0121_drop_platform_migration_runs.sql +12 -0
  1866. package/src/migrations/0122_drop_scheduled_task_runs_rechecked_at.sql +5 -0
  1867. package/src/migrations/0123_pgvector.sql +27 -0
  1868. package/src/migrations/0124_conversation_source.sql +36 -0
  1869. package/src/migrations/0125_conversation_tree_stopped_at.sql +5 -0
  1870. package/src/migrations/0126_git_gateway.sql +10 -0
  1871. package/src/migrations/0127_git_push_policy.sql +12 -0
  1872. package/src/migrations/0128_scheduled_task_plugin_disabled.sql +10 -0
  1873. package/src/migrations/0129_connector_plugin_disabled.sql +5 -0
  1874. package/src/migrations/0130_auto_mode.sql +48 -0
  1875. package/src/migrations/0131_device_mode.sql +9 -0
  1876. package/src/migrations/0132_compact_runs.sql +6 -0
  1877. package/src/migrations/0133_project_root.sql +30 -0
  1878. package/src/migrations/0134_org_cloud_network_delta.sql +38 -0
  1879. package/src/migrations/0135_run_execution_claim.sql +2 -0
  1880. package/src/migrations/0136_run_recovery_cursor.sql +6 -0
  1881. package/src/migrations/0137_audit_org_idx.sql +5 -0
  1882. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  1883. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  1884. package/src/migrations/0140_retire_history_forms.sql +148 -0
  1885. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  1886. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  1887. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  1888. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  1889. package/src/migrations/0145_org_network_allowances.sql +12 -0
  1890. package/src/migrations/0146_permission_authority_epochs.sql +6 -0
  1891. package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
  1892. package/src/migrations/0148_first_message_request_hash.sql +2 -0
  1893. package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
  1894. package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
  1895. package/src/migrations/0151_starting_execution_grants.sql +8 -0
  1896. package/src/migrations/0152_background_launch_identity.sql +66 -0
  1897. package/src/migrations/0153_background_cancel_requester.sql +13 -0
  1898. package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
  1899. package/src/migrations/0155_device_instance_generations.sql +30 -0
  1900. package/src/migrations/0156_device_owner_report.sql +7 -0
  1901. package/src/migrations/0157_legacy_retirement.sql +116 -0
  1902. package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
  1903. package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
  1904. package/src/migrations/0160_model_usage_image_kind.sql +10 -0
  1905. package/src/migrations/0161_file_shares.sql +35 -0
  1906. package/src/migrations/0162_permission_call_escalation.sql +9 -0
  1907. package/src/migrations/0163_read_attachments.sql +10 -0
  1908. package/src/migrations/0164_platform_icons.sql +10 -0
  1909. package/src/migrations/0165_device_network_columns.sql +50 -0
  1910. package/src/migrations/0166_permission_grant_full_access.sql +17 -0
  1911. package/src/migrations/0167_device_network_backfill.sql +32 -0
  1912. package/src/migrations/0168_binding_installed_connection.sql +6 -0
  1913. package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
  1914. package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
  1915. package/src/migrations/0171_account_avatar.sql +26 -0
  1916. package/src/migrations/0172_push.sql +40 -0
  1917. package/src/migrations/0173_push_auth_notice.sql +10 -0
  1918. package/src/migrations/0174_marketplace_managed_username.sql +4 -0
  1919. package/src/migrations/0175_secure_input_kind.sql +8 -0
  1920. package/src/migrations/0176_device_report.sql +6 -0
  1921. package/src/migrations/0177_dial_in_contract.sql +32 -0
  1922. package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
  1923. package/src/migrations/0179_device_report_limit_text.sql +28 -0
  1924. package/src/migrations/0180_device_instance_abandoned.sql +6 -0
  1925. package/src/migrations/0181_connector_description.sql +3 -0
  1926. package/src/migrations/0182_rls_policies.sql +202 -0
  1927. package/src/migrations/0183_connectors_created_by_nullable.sql +5 -0
  1928. package/src/migrations/0184_background_cancel_failure.sql +10 -0
  1929. package/src/migrations/0185_channel_process_display.sql +13 -0
  1930. package/src/migrations/0186_question_woken.sql +5 -0
  1931. package/src/migrations/0187_device_conversation_notices.sql +35 -0
  1932. package/dist/catalog/upgrade-targets.d.ts +0 -59
  1933. package/dist/catalog/upgrade-targets.js +0 -90
  1934. package/dist/conversations/sandbox-status.d.ts +0 -21
  1935. package/dist/conversations/sandbox-status.js +0 -24
  1936. package/dist/extensions/org-config.controller.d.ts +0 -24
  1937. package/dist/extensions/org-config.controller.js +0 -59
  1938. package/dist/http/gateway.module.d.ts +0 -15
  1939. package/dist/http/gateway.module.js +0 -13
  1940. package/dist/http/health.controller.d.ts +0 -26
  1941. package/dist/http/health.controller.js +0 -79
  1942. package/dist/http/tokens.d.ts +0 -131
  1943. package/dist/http/tokens.js +0 -131
  1944. package/dist/http/zod.pipe.d.ts +0 -8
  1945. package/dist/http/zod.pipe.js +0 -14
  1946. package/dist/identity/enterprise-admin.d.ts +0 -14
  1947. package/dist/identity/enterprise-admin.js +0 -27
  1948. package/dist/identity/rate-limit.d.ts +0 -55
  1949. package/dist/identity/rate-limit.js +0 -121
  1950. package/dist/sandbox/lifecycle.d.ts +0 -21
  1951. package/dist/sandbox/lifecycle.js +0 -68
  1952. package/dist/tools/builtins/sandbox/names.d.ts +0 -7
  1953. package/dist/tools/builtins/sandbox/names.js +0 -20
  1954. package/dist/tools/builtins/skill-write.d.ts +0 -59
  1955. package/dist/tools/builtins/skill-write.js +0 -244
@@ -1,699 +1,808 @@
1
- import { createHash, randomUUID } from "node:crypto";
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
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";
16
+ import { Inject, Injectable } from "@nestjs/common";
2
17
  import { sql } from "kysely";
3
- import { putTemplateVersionIn } from "../agents/templates.js";
4
18
  import { ApiError } from "../errors.js";
5
- import { isExtensionEnabled } from "../extensions/enabled.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";
24
+ import { ExtensionRegistry } from "../extensions/registry.js";
6
25
  import { audit } from "../identity/audit.js";
7
- import { lockOrg } from "../orgs/org-lock.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";
29
+ import { KernelDb } from "../infra/database/kernel-db.js";
30
+ import { TransactionHost } from "../infra/database/transaction-host.js";
31
+ import { Transactional } from "../infra/database/transactional.decorator.js";
32
+ import { LockService } from "../infra/lock/lock.service.js";
33
+ import { OutboxService } from "../infra/outbox/outbox.service.js";
34
+ import { KERNEL_LOGGER } from "../infra/tokens.js";
35
+ import { OrgLock } from "../orgs/org-lock.js";
8
36
  import { packagePath } from "../packages/tgz.js";
9
- import { skillConflictError } from "../skills/skills.service.js";
10
- import { canonicalJson } from "../tools/registry.js";
11
- import { getPath, lockOrgForActions, orgTemplateView, readCatalogAgentTemplates, readCatalogFiles, readCatalogTemplates, requiredActions, setPath, skillOf, templatePluginProblem, } from "./org-catalog.service.js";
12
- import { catalogSkillNames, InstallFailure, journalEntries, missingTemplateInput, planActions, planSkillConflicts, resolveDependencies, under, } from "./plugin-install.js";
13
- import { assertItemInstallable } from "./requests.service.js";
14
- import { deployedExtension, deploymentTarget } from "./upgrade-targets.js";
15
- import { satisfiesRange } from "./versions.js";
37
+ import { StorageService } from "../storage/storage.service.js";
38
+ import { assertNotPlatformDefault, pickedByIn, themesPreview, } from "../themes/theme-usage.js";
39
+ import { canonicalJson } from "../tools/canonical-json.js";
40
+ import { setupNeed } from "../tools/connector-setup.js";
41
+ import { ConnectorsService } from "../tools/connectors.service.js";
42
+ import { dirDigest, getPath, readCatalogAgentTemplates, readCatalogTemplates, readCatalogThemes, setPath, skillFilesDigest, templatePluginProblem, themeAssetsDigest, } from "./catalog-content.js";
43
+ import { markVersionApplied, versionUsable } from "./catalog-items.js";
44
+ import { agentsUsing, clashingOrgSkills, clashingPlatformSkills, componentOn, connectorsMadeFrom, connectorTemplatesOn, listedIn, loadComponents, loadScopeState, pluginFactsOf, switchOf, themeIdClashes, } from "./component-state.js";
45
+ import { credentialKey } from "./credential-key.js";
46
+ import { LIVE_INSTALL_STATUSES } from "./install-status.js";
47
+ import { CatalogItemLock } from "./locks.js";
48
+ import { isUsable, itemPendingError, itemRemovedError } from "./ownership.js";
49
+ import { PlanStale, PlatformComponents } from "./platform-components.js";
50
+ import { catalogSkillNames, PluginInstaller } from "./plugin-install.js";
51
+ import { wantedOn } from "./scope.js";
52
+ import { PluginScopeSync } from "./scope-sync.js";
53
+ import { oweTemplateConnectors } from "./template-connector-jobs.js";
54
+ import { compareVersions, satisfiesRange } from "./versions.js";
16
55
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
17
- const installNotFound = () => new ApiError("plugin.install_not_found", "Plugin install not found");
18
- const inProgress = () => new ApiError("plugin.install_in_progress", "This plugin install is being installed, upgraded or uninstalled; try again when it finishes");
19
- 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");
20
- const targetInvalid = (message, details) => new ApiError("plugin.upgrade_target_invalid", message, details);
21
- const fail = (path, message) => new ApiError("validation_failed", "Request validation failed", [{ path, message }]);
22
56
  const sha256 = (s) => createHash("sha256").update(s).digest("hex");
23
- /**
24
- * What a credential of `auth` looks like: two auths with the same key take the same stored
25
- * credential (static: the type family, ownership and header names; OAuth: any change re-enters).
26
- */
27
- function credentialKey(auth) {
28
- switch (auth.type) {
29
- case "none":
30
- return "none";
31
- case "bearer":
32
- case "api_key":
33
- return `token:${auth.ownership}`;
34
- case "basic":
35
- return `basic:${auth.ownership}`;
36
- case "headers":
37
- return `headers:${auth.ownership}:${[...auth.names].sort().join(",")}`;
38
- default:
39
- return canonicalJson(auth);
40
- }
41
- }
57
+ const itemNotFound = () => new ApiError("catalog.item_not_found", "Catalog item not found");
58
+ 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");
59
+ /** The pending version a super admin confirms was replaced by another upload (P3-11). */
60
+ const pendingStale = (name) => new ApiError("extension.approval_stale", `The pending upload of ${name} changed since it was reviewed; review it again`);
61
+ const targetInvalid = (message, details) => new ApiError("plugin.upgrade_target_invalid", message, details);
62
+ /** A version an org uploaded that was never applied or confirmed, or was rejected (P3-37, P3-52). */
63
+ 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 }]);
64
+ const KIND_ORDER = {
65
+ skill: 0,
66
+ agent_template: 1,
67
+ connector_template: 2,
68
+ theme: 3,
69
+ };
70
+ /** How long one update holds its item (renewed while it runs). */
71
+ const UPDATE_LOCK_TTL_MS = 60_000;
42
72
  /** The digest of all files of a catalog version. */
43
- const filesDigest = (row) => sha256(row.files
44
- .map((f) => `${f.path}\0${f.sha256}\n`)
45
- .sort()
46
- .join(""));
47
- /** The digest of the files under `dir/` of a catalog version (paths relative to it). */
48
- function dirDigest(row, dir) {
49
- const prefix = `${dir}/`;
50
- return sha256(row.files
51
- .filter((f) => f.path.startsWith(prefix))
52
- .map((f) => `${f.path.slice(prefix.length)}\0${f.sha256}\n`)
53
- .sort()
54
- .join(""));
55
- }
73
+ const filesDigest = (row) => skillFilesDigest(row.files.map((f) => ({ path: f.path, sha256: f.sha256 })));
56
74
  /**
57
- * Org in-place upgrade (and, for declarative plugins, rollback) of an installed plugin (package
58
- * ecosystem spec §10, Decisions 9–11):
59
- * - **preview** diffs the installed and the target version per component (extension, dependency
60
- * plugins, skills by name, connector templates by id) and returns the inputs needed and a
61
- * `diffHash`; the same checks as an install run first (dependencies resolve, extension and
62
- * template connectors deployed, skill conflicts -> `plugin.skill_conflict`), plus the target
63
- * rules (`plugin.upgrade_target_invalid`): an extension-bearing plugin can move only to the
64
- * catalog version carrying the deployment's extension, and installs depending on this plugin must
65
- * still accept the target;
66
- * - **upgrade** re-checks the `diffHash` (`plugin.upgrade_stale`), sets the install `upgrading`
67
- * under the org lock (another upgrade or an uninstall -> `plugin.install_in_progress`), then:
68
- * added dependencies (installed by the install flow), the added extension (enabled), added and
69
- * changed skills (a new version of the same skill; agents keep selecting it by id), added
70
- * connectors (created from the template), and in one final transaction the changed connectors
71
- * (template-owned fields only, `applyTemplateIn`), the removals by the uninstall rules, the new
72
- * version and the audit `plugin.org_upgraded`. Each step is journaled in
73
- * `plugin_installs.upgrade`; on failure the journal is undone (created components removed, skill
74
- * versions reverted; changed connectors were never committed), the install stays `installed` at
75
- * the old version with `error = { step, code }`, audit `plugin.org_upgrade_failed`, 502
76
- * `plugin.upgrade_failed`. An upgrade interrupted for longer than `catalog.staleInstallMinutes`
77
- * is undone by the next preview, upgrade or uninstall.
78
- * Approval follows the item's policy (the org catalog service creates the request). No in-process
79
- * state.
75
+ * The platform plugin update (spec §7; ruling F2 retires the per-org upgrades):
76
+ * - **preview** diffs the platform's current components of the plugin (the version recorded in
77
+ * `catalog_items.platform_synced_version`, components updated on their own included) against a
78
+ * catalog version: each skill (by name, by its files' digest), agent template (by name, canonical
79
+ * definition) and connector template (by id, canonical file) is `added`, `removed`, `same`, or
80
+ * `upgrade` / `downgrade` (the target's direction from the component's catalog version). It marks
81
+ * components updated on their own, components with their own scope and the orgs whose linked
82
+ * copy is pinned; lists removed components agents still use (they stay, spec §7.3), the org
83
+ * connectors made from changed templates (all orgs, ruling E2; `credentialsReset` when the
84
+ * credential shape changed), the connectors it creates from the templates it turns on (added,
85
+ * or no longer shipped off; plugin pages spec §5.2.3) with the setup state each starts in, the
86
+ * templates it turns off (now shipped off, on only by default), the orgs where the scope sync
87
+ * owed with it will install the plugin, the deployment's extension move, and a `diffHash`. Refused: same version, a disabled or deleted
88
+ * item, a target without the extension the deployment runs for it or moving a config-declared
89
+ * one, a template moving to another connector, a plugin another platform plugin depends on
90
+ * outside its range, and an added skill whose name is taken where the plugin is on (rule 10).
91
+ * - **update** runs under a Redis lock per item (another update -> `plugin.install_in_progress`):
92
+ * the extension first (`ExtensionAdminOps.install`, enabled when the update installs it; added
93
+ * permissions wait for the admin's approval as for any extension upgrade), then one transaction
94
+ * under the item name's lock that recomputes the diff (`plugin.upgrade_stale` on a difference)
95
+ * and writes the platform versions (`PlatformComponents.applySyncIn`, which records
96
+ * `platform_synced_version`), the removals (a component no agent uses is soft-deleted, so
97
+ * unpinned linked copies go with it; pinned copies keep their own version; a removed connector
98
+ * template leaves its connectors as the orgs' own), clears the pins of linked copies, fans
99
+ * changed templates out to every connector made from them (`applyTemplateIn`, under each org's
100
+ * row lock, credentials cleared only for a changed credential shape), creates the connectors of
101
+ * the templates it turns on (`ConnectorsService.createDeferredIn`, no outbound call, those orgs
102
+ * locked with the others), moves every org install to the version and audits
103
+ * `plugin.platform_updated`; the scope sync of the item and its dependencies is owed in that
104
+ * transaction (orgs get new dependencies by rule 9). A failure rolls the transaction back and
105
+ * puts the extension back where it was (audit `plugin.platform_update_failed`, 502
106
+ * `plugin.upgrade_failed`); files copied to `deployment/platform/` stay unreferenced.
107
+ * Transaction size: the whole fan-out (every changed template's connectors and every created
108
+ * connector, in every org where the plugin is on) is one transaction holding every touched org's
109
+ * row lock, with no batching; it grows with orgs x templates, so a deployment with very many orgs
110
+ * sees one long transaction (and other writes to those orgs waiting) per update. Deferred
111
+ * connectors (ruling R27) add one outbox row per org and no connector rows. Builtin plugins get no
112
+ * created connectors (ruling R28).
113
+ * Storage is never read or written inside the transaction: the target's contents (and the
114
+ * extension package, for `needsApproval`) are read and the platform files copied
115
+ * (`PlatformComponents.prepareSync`) after the Redis lock is taken and before the transaction,
116
+ * which reuses them and writes rows only (`applySyncIn`). The confirm-time diff treats the
117
+ * extension this update moved as expected (the install record must point at that package).
118
+ * Recovery: a process that dies between the extension step and the transaction leaves the
119
+ * deployment on the target's extension with the platform components unchanged; a new preview
120
+ * then shows the extension unchanged (`extension: null`) and the components still to move, and
121
+ * confirming it completes the update (or an update back to the old version moves it back).
122
+ * No in-process state.
80
123
  */
81
- export class PluginUpgrader {
124
+ let PlatformPluginUpdater = class PlatformPluginUpdater {
125
+ kdb;
126
+ txHost;
127
+ adminLock;
128
+ itemLock;
129
+ orgLock;
130
+ locks;
131
+ storage;
132
+ registry;
133
+ ops;
134
+ blobs;
135
+ config;
136
+ platform;
82
137
  installer;
83
- d;
84
- constructor(installer) {
138
+ connectors;
139
+ sync;
140
+ log;
141
+ guides;
142
+ outbox;
143
+ constructor(kdb, txHost, adminLock, itemLock, orgLock, locks, storage, registry, ops,
144
+ /** Reads the target's extension package (its permissions, for `needsApproval`). */
145
+ blobs, config, platform,
146
+ /** Template dependencies (the deployed connector kinds). */
147
+ installer, connectors, sync, log,
148
+ /** The connector template guides an update changes (the preview's `guideChanges`). */
149
+ guides,
150
+ /** Owes the template connector ensure of the orgs with a deferred connector (ruling R27). */
151
+ outbox) {
152
+ this.kdb = kdb;
153
+ this.txHost = txHost;
154
+ this.adminLock = adminLock;
155
+ this.itemLock = itemLock;
156
+ this.orgLock = orgLock;
157
+ this.locks = locks;
158
+ this.storage = storage;
159
+ this.registry = registry;
160
+ this.ops = ops;
161
+ this.blobs = blobs;
162
+ this.config = config;
163
+ this.platform = platform;
85
164
  this.installer = installer;
86
- this.d = installer.deps;
165
+ this.connectors = connectors;
166
+ this.sync = sync;
167
+ this.log = log;
168
+ this.guides = guides;
169
+ this.outbox = outbox;
170
+ }
171
+ get db() {
172
+ return this.kdb.db;
173
+ }
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 }));
87
189
  }
88
- /** The upgrade preview (see the class comment). */
89
- async preview(orgId, actor, installId, version) {
90
- await this.recoverInterrupted(orgId, actor, installId);
91
- const diff = await this.diff(orgId, actor, installId, version, null);
92
- await this.d.db.transaction().execute((t) => lockOrgForActions(t, orgId, actor, diff.actions));
190
+ /** The preview of a diff with the template guides it changes. */
191
+ async withGuideChanges(d) {
93
192
  return {
94
- from: diff.from.version,
95
- to: diff.to.version,
96
- diffHash: diff.diffHash,
97
- components: diff.components,
98
- inputs: diff.inputs,
99
- templates: diff.templates.flatMap((c) => c.target !== undefined &&
100
- (diff.inputs.connectors.includes(c.id) || diff.inputs.credentialsChanged.includes(c.id))
101
- ? [orgTemplateView(c.id, c.target)]
102
- : []),
193
+ ...previewOf(d),
194
+ guideChanges: await this.guides.templateGuideChanges(d.itemId, d.from, d.to),
103
195
  };
104
196
  }
105
197
  /**
106
- * The checks of {@link upgrade} before an approval request (the org catalog service creates one
107
- * for a needs_approval item without a grant): the diff with the input, the `diffHash`. Returns
108
- * 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.
109
204
  */
110
- async check(orgId, actor, installId, input) {
111
- await this.recoverInterrupted(orgId, actor, installId);
112
- const diff = await this.diff(orgId, actor, installId, input.version, input);
113
- if (diff.diffHash !== input.diffHash)
114
- throw stale();
115
- 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
+ // Other orgs' scope sync failures are theirs: the owner sees only that the scope sync will try
225
+ // to install there (their names, P3-19), not whether or why it failed. Display only as well
226
+ const scopeInstalls = preview.scopeInstalls.map((o) => o.orgId === orgId ? o : { orgId: o.orgId, orgName: o.orgName });
227
+ const owned = { ...preview, scopeInstalls, ...(themes !== undefined && { themes }) };
228
+ return { ...owned, orgNames: await this.orgNamesOf(owned) };
116
229
  }
117
230
  /**
118
- * Runs an upgrade (see the class comment); returns the install view. `checked` is the diff
119
- * {@link check} computed for the same input (re-verified under the org lock: the install's
120
- * version and ledger must be unchanged), otherwise it is computed here.
231
+ * Locks, in sorted order and before the item (ruling P3-50), every live org the update may
232
+ * write in: the orgs with connectors made from the plugin's connector templates, the orgs the
233
+ * update creates connectors in (`creating`, from the diff before the transaction) and the item's
234
+ * owner org. `acting`: the owner org an owner update acts for, locked with its admin re-checked
235
+ * (`catalog.upload`; deleted -> 404 `org.not_found`). Returns the live orgs locked; another
236
+ * deleted one is skipped.
121
237
  */
122
- async upgrade(orgId, actor, installId, input, opts = {}, checked) {
123
- let diff;
124
- if (checked !== undefined &&
125
- checked.installId === installId &&
126
- checked.to.version === input.version &&
127
- checked.diffHash === input.diffHash) {
128
- diff = checked;
238
+ async lockUpdateOrgs(itemId, creating, acting) {
239
+ const item = await this.db
240
+ .selectFrom("catalog_items")
241
+ .select("owner_org_id")
242
+ .where("id", "=", itemId)
243
+ .executeTakeFirst();
244
+ const made = await this.db
245
+ .selectFrom("connectors as c")
246
+ .innerJoin("platform_connector_templates as t", "t.id", "c.platform_template_id")
247
+ .select("c.org_id")
248
+ .distinct()
249
+ .where("t.catalog_item_id", "=", itemId)
250
+ .where("c.deleted_at", "is", null)
251
+ .execute();
252
+ const ids = new Set([...made.map((r) => r.org_id), ...creating]);
253
+ if (item?.owner_org_id)
254
+ ids.add(item.owner_org_id);
255
+ if (acting !== undefined)
256
+ ids.add(acting.orgId);
257
+ const live = new Set();
258
+ for (const orgId of [...ids].sort()) {
259
+ if (orgId === acting?.orgId) {
260
+ await this.orgLock.lockAndAuthorize(orgId, acting.actor, "catalog.upload");
261
+ live.add(orgId);
262
+ }
263
+ else if (await this.orgLock.tryLock(orgId)) {
264
+ live.add(orgId);
265
+ }
129
266
  }
130
- else {
131
- await this.recoverInterrupted(orgId, actor, installId);
132
- diff = await this.diff(orgId, actor, installId, input.version, input);
133
- if (diff.diffHash !== input.diffHash)
134
- throw stale();
267
+ return live;
268
+ }
269
+ /** The names of the orgs a preview mentions, by id (an owner's preview, see `orgNames`). */
270
+ async orgNamesOf(p) {
271
+ const ids = new Set([
272
+ ...(p.extension?.orgs ?? []),
273
+ ...p.connectorOrgs.map((c) => c.orgId),
274
+ ...p.scopeInstalls.map((o) => o.orgId),
275
+ ...p.components.flatMap((c) => [...c.pinnedOrgs, ...(c.kept ?? []).map((k) => k.orgId)]),
276
+ ...(p.themes ?? []).flatMap((t) => t.orgDefaults.map((o) => o.orgId)),
277
+ ]);
278
+ if (ids.size === 0)
279
+ return {};
280
+ const rows = await this.db
281
+ .selectFrom("orgs")
282
+ .select(["id", "name"])
283
+ .where("id", "in", [...ids])
284
+ .where("deleted_at", "is", null)
285
+ .execute();
286
+ return Object.fromEntries(rows.map((r) => [r.id, r.name]));
287
+ }
288
+ /**
289
+ * Applies a new version of an org's own plugin for its owner (ruling P3-12, see
290
+ * {@link previewForOwner}): the actor must be an admin of the owner org (`catalog.upload`,
291
+ * re-checked under the org row lock in the transaction), then the platform update as
292
+ * {@link update} does, also removing the extension when the target drops it. In the update's
293
+ * transaction the orgs using the shared plugin are told (`shared_item_updated`, one notice per
294
+ * plugin) and a pending version is cleared (pre-flight F7: the new version replaces it).
295
+ */
296
+ async updateAsOwner(orgId, actor, itemId, version, diffHash, opts = {}) {
297
+ if (!UUID_RE.test(itemId))
298
+ throw itemNotFound();
299
+ await this.authorizeOwner(orgId, actor);
300
+ return this.locked(itemId, () => this.updateLocked(actor, itemId, { version, diffHash }, opts, { orgId }));
301
+ }
302
+ /** The actor is an admin of the owner org (a read of the membership under the org row lock). */
303
+ async authorizeOwner(orgId, actor) {
304
+ await this.orgLock.lockAndAuthorize(orgId, actor, "catalog.upload");
305
+ }
306
+ /** Runs `f` holding the item's update lock (another update -> `plugin.install_in_progress`). */
307
+ async locked(itemId, f) {
308
+ const handle = await this.locks.acquire(`plugin-update-${itemId}`, {
309
+ ttlMs: UPDATE_LOCK_TTL_MS,
310
+ });
311
+ if (!handle) {
312
+ throw new ApiError("plugin.install_in_progress", "This plugin is being updated; try again when that update finishes");
135
313
  }
136
- const { itemId } = diff;
137
- const upgradeId = randomUUID();
138
- // Start: the install `upgrading`, under the org lock (one upgrade or uninstall at a time)
139
- await this.d.db.transaction().execute(async (t) => {
140
- await lockOrgForActions(t, orgId, actor, diff.actions);
141
- const row = await t
142
- .selectFrom("plugin_installs")
143
- .select(["status", "version"])
144
- .where("id", "=", installId)
145
- .where("org_id", "=", orgId)
146
- .forUpdate()
147
- .executeTakeFirst();
148
- if (!row || row.status === "failed")
149
- throw installNotFound();
150
- if (row.status !== "installed")
151
- throw inProgress();
152
- if (row.version !== diff.from.version ||
153
- ledgerHash(await ledgerOf(t, installId)) !== diff.ledgerHash) {
154
- throw stale();
155
- }
156
- await assertItemInstallable(t, orgId, itemId);
157
- await t
158
- .updateTable("plugin_installs")
159
- .set({
160
- status: "upgrading",
161
- upgrade: sql `jsonb_build_object('id', ${upgradeId}::text, 'from', ${diff.from.version}::text, 'to', ${diff.to.version}::text, 'startedAt', now(), 'done', '[]'::jsonb)`,
162
- })
163
- .where("id", "=", installId)
164
- .execute();
314
+ try {
315
+ return await f();
316
+ }
317
+ finally {
318
+ await handle.release();
319
+ }
320
+ }
321
+ /**
322
+ * The super admin's confirmation of an org upload's pending new version (rulings P3-10, P3-21,
323
+ * pre-flight F8): the update to `version` as {@link update} does it (the super admin's, the
324
+ * extension installed or upgraded on the deployment), with the version allowed although it is
325
+ * pending. Its transaction re-reads the item under the row lock: removed meanwhile -> 409
326
+ * `catalog.item_removed`, the pending version replaced -> 409 `extension.approval_stale` (both
327
+ * undo the extension step); then the pending state is cleared and the owner told
328
+ * (`upload_confirmed`). The caller checked the digest of the version's package.
329
+ */
330
+ async updateToPending(actor, itemId, version, opts = {}) {
331
+ if (!UUID_RE.test(itemId))
332
+ throw itemNotFound();
333
+ return this.locked(itemId, () => this.updateToPendingLocked(actor, itemId, version, opts));
334
+ }
335
+ /**
336
+ * {@link updateToPending} for a caller already holding the item's update lock
337
+ * ({@link withItemLock}): the super admin's confirmation runs all its steps under it (ruling
338
+ * P3-35).
339
+ */
340
+ async updateToPendingLocked(actor, itemId, version, opts = {}) {
341
+ const d = await this.diff(itemId, version, { confirmPending: version });
342
+ return this.updateLocked(actor, itemId, { version, diffHash: d.diffHash }, opts, undefined, version);
343
+ }
344
+ /**
345
+ * Runs `f` holding the item's update lock (the one every platform update of the item takes;
346
+ * another holder -> 409 `plugin.install_in_progress`): the super admin's confirmation of an org
347
+ * upload runs every step under it (ruling P3-35).
348
+ */
349
+ withItemLock(itemId, f) {
350
+ if (!UUID_RE.test(itemId))
351
+ throw itemNotFound();
352
+ return this.locked(itemId, f);
353
+ }
354
+ /**
355
+ * {@link update} for a caller already holding the item's update lock ({@link withItemLock}):
356
+ * the platform's import and update runs its import and this update under one hold.
357
+ */
358
+ async updateHeld(actor, itemId, input, opts = {}) {
359
+ return this.updateLocked(actor, itemId, input, opts);
360
+ }
361
+ /**
362
+ * Runs an update confirmed with the preview's `diffHash` (see the class comment). A version an
363
+ * org upload waits with, or an item whose first version waits, -> 409 `catalog.item_pending`
364
+ * (confirmed in the admin console's pending confirmations instead, pre-flight F8). `actor`
365
+ * null: the kernel itself (the bootstrap step raising a pinned plugin without an extension): no
366
+ * super admin is re-checked and the audits name no account.
367
+ */
368
+ async update(actor, itemId, input, opts = {}) {
369
+ if (!UUID_RE.test(itemId))
370
+ throw itemNotFound();
371
+ return this.locked(itemId, () => this.updateLocked(actor, itemId, input, opts));
372
+ }
373
+ async updateLocked(actor, itemId, input, opts, owner, confirmPending) {
374
+ // Storage is read and written here, before any transaction (see the class comment)
375
+ const checked = await this.diff(itemId, input.version, {
376
+ ...(owner && { owner }),
377
+ ...(confirmPending !== undefined && { confirmPending }),
165
378
  });
166
- const done = [];
167
- /** The step whose journal write found the journal gone (cleaned up as interrupted meanwhile). */
168
- let unjournaled;
169
- // Appends a step to the journal (the journal gone: the upgrade was cleaned up as interrupted)
170
- const journal = async (s, t) => {
171
- done.push(s);
172
- unjournaled = s;
173
- const r = await t
174
- .updateTable("plugin_installs")
175
- .set({
176
- upgrade: sql `jsonb_set(upgrade, '{done}', (upgrade->'done') || ${JSON.stringify([s])}::jsonb)`,
177
- })
178
- .where("id", "=", installId)
179
- .where(sql `upgrade->>'id'`, "=", upgradeId)
180
- .executeTakeFirst();
181
- if (r.numUpdatedRows === 0n)
182
- throw cleanedUp();
183
- unjournaled = undefined;
184
- };
185
- // Records a component in the ledger and the journal, in the given transaction
186
- const record = async (c, t) => {
187
- const inserted = await t
188
- .insertInto("plugin_install_components")
189
- .values({
190
- install_id: installId,
191
- kind: c.kind,
192
- ref: c.ref,
193
- created: c.created,
194
- skill_version: c.skillVersion,
195
- template_id: c.templateId ?? null,
196
- })
197
- .onConflict((oc) => oc.columns(["install_id", "kind", "ref"]).doNothing())
198
- .returning("ref")
199
- .executeTakeFirst();
200
- if (c.created)
201
- await journal({ op: "created", kind: c.kind, ref: c.ref }, t);
202
- else if (inserted)
203
- await journal({ op: "recorded", kind: c.kind, ref: c.ref }, t);
204
- };
205
- let step = "dependencies";
206
- const disabled = [];
379
+ if (checked.diffHash !== input.diffHash)
380
+ throw stale();
381
+ const prepared = await this.platform.prepareSync(itemId, input.version);
382
+ const ext = checked.extension;
383
+ // The extension admin re-checks the actor: a super admin, or for an owner update the owner
384
+ // org's admin (and audits it with `ownerOrgId`)
385
+ const opsOwner = owner && { orgId: owner.orgId };
386
+ let step = "extension";
387
+ let extensionMoved = false;
388
+ let enabledHere = false;
389
+ let leftDisabled;
390
+ /** A removal: the extension was enabled before it (put back enabled on failure). */
391
+ let removedEnabled = false;
207
392
  try {
208
- for (const dep of diff.dependencies.filter((x) => x.change === "added")) {
209
- const resolved = dep.resolved;
210
- const rec = (c, t) => record(c, t);
211
- if ((await this.installer.recordDependency(orgId, resolved, rec)) !== undefined)
212
- continue;
213
- if (!dep.plan) {
214
- 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 }]);
393
+ if (ext?.sha256 === null) {
394
+ // The target drops the extension (P3-12'): disabled (drained), then uninstalled
395
+ const row = await this.db
396
+ .selectFrom("extension_installs")
397
+ .select("desired_state")
398
+ .where("name", "=", checked.name)
399
+ .executeTakeFirst();
400
+ removedEnabled = row?.desired_state === "enabled";
401
+ await this.ops.disable(checked.name, actor, opts.actorTokenId, opsOwner);
402
+ extensionMoved = true;
403
+ await this.ops.uninstall(checked.name, actor, opts.actorTokenId, opsOwner);
404
+ }
405
+ else if (ext) {
406
+ const installed = await this.ops.install(checked.name, ext.sha256, actor, opts.actorTokenId, { catalogItemId: itemId, ...(opsOwner && { owner: opsOwner }) });
407
+ extensionMoved = true;
408
+ // A new version newly providing a held single-provider point: left disabled by the install
409
+ leftDisabled = installed.leftDisabled;
410
+ if (ext.previous === null) {
411
+ // An occupied single-provider point leaves it installed disabled
412
+ const r = await this.ops.enableUnlessOccupied(checked.name, actor, opts.actorTokenId, opsOwner);
413
+ enabledHere = r.enabled;
414
+ if (!r.enabled)
415
+ leftDisabled = r.note;
215
416
  }
216
- let child;
417
+ }
418
+ step = "components";
419
+ const diff = await this.commit(actor, itemId, input, opts, {
420
+ contents: checked.contents,
421
+ extension: ext,
422
+ createOrgs: [...new Set(checked.creates.map((c) => c.orgId))],
423
+ }, prepared, owner, confirmPending);
424
+ return {
425
+ itemId,
426
+ version: diff.to.version,
427
+ components: diff.components,
428
+ extension: extensionView(diff.extension),
429
+ connectorOrgs: diff.connectorOrgs,
430
+ ...(leftDisabled !== undefined && { extensionLeftDisabled: leftDisabled }),
431
+ };
432
+ }
433
+ catch (e) {
434
+ let rolledBack = true;
435
+ if (extensionMoved && ext) {
436
+ // An owner update was authorized at its start: the put-back is not checked again
437
+ const back = opsOwner && { ...opsOwner, rollback: true };
217
438
  try {
218
- child = await this.installer.execute(orgId, actor, dep.plan, opts, {
219
- actions: requiredActions(dep.plan.manifest),
220
- approvedBy: itemId,
221
- parent: installId,
222
- });
223
- }
224
- catch (e) {
225
- if (e instanceof InstallFailure) {
226
- throw new InstallFailure(e.step, e.cause, [dep.name, ...e.dependency], e.rolledBack);
439
+ if (ext.sha256 === null) {
440
+ // Removed by this update: the previous package reinstalled (as it was)
441
+ await this.ops.install(checked.name, ext.previous, actor, opts.actorTokenId, {
442
+ catalogItemId: itemId,
443
+ ...(back && { owner: back }),
444
+ });
445
+ if (removedEnabled)
446
+ await this.ops.enable(checked.name, actor, opts.actorTokenId, back);
227
447
  }
228
- if (e instanceof ApiError &&
229
- e.code === "plugin.already_installed" &&
230
- (await this.installer.recordDependency(orgId, resolved, rec)) !== undefined) {
231
- continue;
448
+ else if (ext.previous !== null) {
449
+ await this.ops.install(checked.name, ext.previous, actor, opts.actorTokenId, {
450
+ ...(back && { owner: back }),
451
+ });
452
+ // The install left the enabled extension disabled (a held single-provider point): the
453
+ // previous version, which did not provide it, runs again
454
+ if (leftDisabled !== undefined) {
455
+ await this.ops.enable(checked.name, actor, opts.actorTokenId, back);
456
+ }
457
+ }
458
+ else {
459
+ // Installed by this update: an uninstall needs it disabled first
460
+ if (enabledHere)
461
+ await this.ops.disable(checked.name, actor, opts.actorTokenId, back);
462
+ await this.ops.uninstall(checked.name, actor, opts.actorTokenId, back);
232
463
  }
233
- throw new InstallFailure("dependencies", e, [dep.name], true);
234
464
  }
235
- await this.installer.recordDependency(orgId, resolved, rec, child);
236
- }
237
- step = "extension";
238
- if (diff.extension?.change === "added") {
239
- const name = diff.extension.name;
240
- await this.d.orgConfigs.put(orgId, name, {
241
- enabled: true,
242
- ...(input.extensionConfig !== undefined && { config: input.extensionConfig }),
243
- }, actor, opts.actorTokenId, {
244
- viaItem: itemId,
245
- ifDisabled: { skipped: false },
246
- inTransaction: (t, skipped) => record({ kind: "extension", ref: name, created: !skipped, skillVersion: null }, t),
247
- });
248
- }
249
- step = "skills";
250
- for (const s of diff.skills) {
251
- if (s.change !== "added" && s.change !== "changed")
252
- continue;
253
- const files = await readCatalogFiles(this.d.storage, diff.to.object_prefix, diff.to.files, s.dir);
254
- const r = await this.d.skills.createVersionFromFiles(orgId, actor, { ...skillOf(files), files }, {
255
- catalog: {
465
+ catch (u) {
466
+ rolledBack = false;
467
+ this.log.error("putting a plugin's extension back after a failed update failed", {
256
468
  itemId,
257
- version: diff.to.version,
258
- format: diff.to.source_format,
259
- suggestPinned: s.suggestPinned === true,
260
- },
261
- ...opts,
262
- });
263
- await this.d.db.transaction().execute(async (t) => {
264
- if (r.created) {
265
- await record({ kind: "skill", ref: r.skill.id, created: true, skillVersion: null }, t);
266
- return;
267
- }
268
- await journal({ op: "skill_version", ref: r.skill.id, version: r.version }, t);
269
- await record({ kind: "skill", ref: r.skill.id, created: false, skillVersion: r.version }, t);
270
- });
271
- }
272
- step = "agent_templates";
273
- for (const a of diff.agentTemplates) {
274
- if (a.change !== "added" && a.change !== "changed")
275
- continue;
276
- await this.d.db.transaction().execute(async (t) => {
277
- await lockOrg(t, orgId);
278
- const r = await putTemplateVersionIn(t, {
279
- orgId,
280
- plugin: diff.name,
281
- catalogItemId: itemId,
282
- catalogVersion: diff.to.version,
283
- sourceFormat: diff.to.source_format,
284
- }, a.template);
285
- if (r.created) {
286
- await record({ kind: "agent_template", ref: r.id, created: true, skillVersion: null }, t);
287
- return;
288
- }
289
- if (r.changed)
290
- await journal({ op: "template_version", ref: r.id, version: r.version }, t);
291
- await record({
292
- kind: "agent_template",
293
- ref: r.id,
294
- created: false,
295
- skillVersion: r.changed ? r.version : null,
296
- }, t);
297
- });
298
- }
299
- step = "connectors";
300
- for (const [templateId, ci] of diff.creates) {
301
- const r = await this.d.connectors.create(orgId, actor, ci, opts.actorTokenId);
302
- await this.d.db.transaction().execute((t) => record({
303
- kind: "connector",
304
- ref: r.connector.id,
305
- created: true,
306
- skillVersion: null,
307
- templateId,
308
- }, t));
309
- }
310
- const prepared = [];
311
- for (const tpl of diff.templates) {
312
- const update = diff.updates.get(tpl.id);
313
- if (!update || !tpl.connector)
314
- continue;
315
- try {
316
- prepared.push({
317
- connectorId: tpl.connector.id,
318
- p: await this.d.connectors.prepareTemplateUpdate(actor, tpl.connector.connector, update),
469
+ plugin: checked.name,
470
+ err: u,
319
471
  });
320
472
  }
321
- catch (e) {
322
- throw under(e, `connectors.${tpl.id}`);
323
- }
324
473
  }
325
- // Finish, in one transaction: changed connectors, removals, the version switch
326
- await this.d.db.transaction().execute(async (t) => {
327
- await lockOrgForActions(t, orgId, actor, diff.actions);
328
- const row = await t
329
- .selectFrom("plugin_installs")
330
- .select(["status", sql `upgrade->>'id'`.as("upgradeId")])
331
- .where("id", "=", installId)
332
- .forUpdate()
333
- .executeTakeFirst();
334
- if (row?.status !== "upgrading" || row.upgradeId !== upgradeId)
335
- throw cleanedUp();
336
- await assertItemInstallable(t, orgId, itemId);
337
- for (const c of prepared) {
338
- await this.d.connectors.applyTemplateIn(t, orgId, c.connectorId, actor, c.p, opts.actorTokenId);
339
- }
340
- step = "finish";
341
- for (const dep of diff.dependencies) {
342
- if (dep.change !== "changed" || !dep.child)
343
- continue;
344
- const live = await t
345
- .selectFrom("plugin_installs")
346
- .select("version")
347
- .where("id", "=", dep.child.installId)
348
- .forShare()
349
- .executeTakeFirst();
350
- if (!live || !satisfiesRange(live.version, dep.range)) {
351
- 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 }]);
352
- }
353
- }
354
- const report = await this.removeIn(t, orgId, actor, diff, disabled);
355
- // An unchanged skill gets no new version, so the target's pinned suggestion goes onto its
356
- // current version (when that version is this plugin's) here, with the version switch.
357
- for (const sk of diff.skills) {
358
- if (sk.change !== "unchanged" || !sk.ledger)
359
- continue;
360
- await t
361
- .updateTable("skill_versions as v")
362
- .set({ suggest_pinned: sk.suggestPinned === true })
363
- .from("skills as s")
364
- .whereRef("s.id", "=", "v.skill_id")
365
- .whereRef("s.current_version", "=", "v.version")
366
- .where("s.id", "=", sk.ledger.ref)
367
- .where("s.org_id", "=", orgId)
368
- .where("v.catalog_item_id", "=", itemId)
369
- .where("v.suggest_pinned", "<>", sk.suggestPinned === true)
370
- .execute();
371
- }
372
- await t
373
- .updateTable("plugin_installs")
374
- .set({ version: diff.to.version, status: "installed", upgrade: null, error: null })
375
- .where("id", "=", installId)
376
- .execute();
377
- await this.d.requests.resolveByInstall(t, orgId, itemId, actor, opts);
378
- await audit(t, {
379
- actorAccountId: actor,
380
- ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
381
- orgId,
382
- action: "plugin.org_upgraded",
383
- target: installId,
384
- detail: {
385
- itemId,
386
- name: diff.name,
387
- from: diff.from.version,
388
- to: diff.to.version,
389
- components: diff.components,
390
- removed: report.removed,
391
- kept: report.kept,
392
- },
393
- });
394
- });
395
- }
396
- catch (e) {
397
- throw await this.failed(orgId, actor, installId, upgradeId, diff, { done, unjournaled }, step, e, opts);
474
+ const code = e instanceof ApiError ? e.code : "internal";
475
+ await this.auditFailure(actor, checked, { step, code, rolledBack }, opts);
476
+ // A refusal found under the lock (stale, disabled meanwhile, a conflict, a downgrade the
477
+ // extension's migrations refuse): returned as it is
478
+ if (e instanceof ApiError && e.status < 500 && rolledBack)
479
+ throw e;
480
+ throw new ApiError("plugin.upgrade_failed", rolledBack
481
+ ? `Updating the plugin failed at step ${step} (${code}); the platform is back at version ${checked.from ?? "(none)"}`
482
+ : `Updating the plugin failed at step ${step} (${code}) and putting its extension back failed; check the extension in the admin console`, [
483
+ {
484
+ step,
485
+ code,
486
+ ...(e instanceof ApiError && { message: e.message }),
487
+ ...(e instanceof ApiError && e.details !== undefined && { causeDetails: e.details }),
488
+ rolledBack,
489
+ },
490
+ ]);
398
491
  }
399
- for (const p of disabled)
400
- await this.d.orgConfigs.afterDisable(orgId, p);
401
- const [view] = await this.installer.list(orgId, installId);
402
- if (!view)
403
- throw installNotFound();
404
- return view;
492
+ }
493
+ /** `plugin.platform_update_failed`, in a transaction of its own. */
494
+ async auditFailure(actor, diff, f, opts) {
495
+ await audit(this.db, {
496
+ actorAccountId: actor,
497
+ ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
498
+ action: "plugin.platform_update_failed",
499
+ target: diff.itemId,
500
+ detail: { name: diff.name, from: diff.from, to: diff.to.version, ...f },
501
+ });
405
502
  }
406
503
  /**
407
- * Undoes a failed upgrade (its journal, in one transaction): the install back `installed` at the
408
- * old version with `error = { step, code }`, audit `plugin.org_upgrade_failed`. When the journal
409
- * is no longer this upgrade's (another request cleaned it up as interrupted and undid what it
410
- * journaled), only the step whose journal write failed is undone and the install row is left as
411
- * the cleanup set it. Returns the error to throw: 502 `plugin.upgrade_failed` (a dependency
412
- * another install is still installing: its 409 as it is).
504
+ * The update's transaction (see the class comment): the super admin re-checked, the diff
505
+ * recomputed under the item name's lock, then every write. Returns the diff it applied.
413
506
  */
414
- async failed(orgId, actor, installId, upgradeId, diff, steps, step, e, opts) {
415
- const failure = e instanceof InstallFailure ? e : undefined;
416
- const cause = failure ? failure.cause : e;
417
- const code = cause instanceof ApiError ? cause.code : "internal";
418
- const at = failure ? failure.step : step;
419
- let rolledBack = failure?.rolledBack ?? true;
507
+ async commit(actor, itemId, input, opts, pre, prepared, owner, confirmPending) {
508
+ if (owner !== undefined && actor === null) {
509
+ throw new Error("an owner update needs the acting account");
510
+ }
511
+ // null: the kernel itself (the bootstrap step), no super admin to re-check
512
+ if (owner === undefined && actor !== null)
513
+ await this.adminLock.lockAndAuthorize(actor);
514
+ // The global lock order (ruling P3-50): the orgs (sorted; the acting owner org's admin
515
+ // re-checked at its place), then the item, then its components; an org deletion locks its org
516
+ // row, then the items it owns
517
+ const liveOrgs = await this.lockUpdateOrgs(itemId, pre.createOrgs, owner && actor !== null ? { orgId: owner.orgId, actor } : undefined);
518
+ const named = await this.db
519
+ .selectFrom("catalog_items")
520
+ .select("name")
521
+ .where("id", "=", itemId)
522
+ .executeTakeFirst();
523
+ if (!named)
524
+ throw itemNotFound();
525
+ await this.itemLock.lock(named.name);
526
+ let pendingOwner = null;
527
+ if (confirmPending !== undefined) {
528
+ // The super admin's confirmation (P3-21): still pending with the version they reviewed
529
+ const row = await this.db
530
+ .selectFrom("catalog_items")
531
+ .select(["deleted_at", "pending_version", "owner_org_id"])
532
+ .where("id", "=", itemId)
533
+ .forUpdate()
534
+ .executeTakeFirstOrThrow();
535
+ if (row.deleted_at !== null)
536
+ throw itemRemovedError(named.name);
537
+ if (row.pending_version !== confirmPending)
538
+ throw pendingStale(named.name);
539
+ pendingOwner = row.owner_org_id;
540
+ }
541
+ const diff = await this.diff(itemId, input.version, {
542
+ pre,
543
+ ...(owner && { owner }),
544
+ ...(confirmPending !== undefined && { confirmPending }),
545
+ });
546
+ if (diff.diffHash !== input.diffHash)
547
+ throw stale();
548
+ const t = this.db;
549
+ // The platform versions (files copied before the transaction; rows only here)
420
550
  try {
421
- const removed = await this.d.db.transaction().execute(async (t) => {
422
- await lockOrg(t, orgId);
423
- const row = await t
424
- .selectFrom("plugin_installs")
425
- .select(sql `upgrade->>'id'`.as("upgradeId"))
426
- .where("id", "=", installId)
427
- .forUpdate()
428
- .executeTakeFirst();
429
- const ours = row?.upgradeId === upgradeId;
430
- // Cleaned up meanwhile: only the step whose journal write found the journal gone is ours to
431
- // undo. When that step ran in the same transaction as its journal write (the extension
432
- // enable, the ledger rows), the transaction rolled back with the failed write, so undoing
433
- // it is a no-op (a never-enabled extension, a never-inserted row); undoing is still safe.
434
- const undo = ours ? steps.done : steps.unjournaled ? [steps.unjournaled] : [];
435
- const out = await this.installer.undoUpgradeIn(t, orgId, actor, installId, undo, "plugin_upgrade_rollback");
551
+ await this.platform.applySyncIn(prepared);
552
+ }
553
+ catch (e) {
554
+ if (e instanceof PlanStale)
555
+ throw stale();
556
+ throw e;
557
+ }
558
+ // Removals (spec §7.3): kept while agents use it; otherwise soft-deleted
559
+ const now = sql `now()`;
560
+ for (const c of diff.components) {
561
+ if (c.change !== "removed" || c.id === null || c.kept !== undefined)
562
+ continue;
563
+ const table = c.kind === "skill"
564
+ ? "platform_skills"
565
+ : c.kind === "agent_template"
566
+ ? "platform_agent_templates"
567
+ : c.kind === "theme"
568
+ ? "platform_themes"
569
+ : "platform_connector_templates";
570
+ await t
571
+ .updateTable(table)
572
+ .set({ deleted_at: now, updated_at: now })
573
+ .where("id", "=", c.id)
574
+ .execute();
575
+ }
576
+ // Pins of linked copies: moved to the plugin's version (spec §7.1)
577
+ for (const c of diff.components) {
578
+ if (c.change === "removed" || c.id === null || c.pinnedOrgs.length === 0)
579
+ continue;
580
+ if (c.kind === "skill") {
436
581
  await t
437
- .updateTable("plugin_installs")
438
- .set({ status: "installed", upgrade: null, error: JSON.stringify({ step: at, code }) })
439
- .where("id", "=", installId)
440
- .where(sql `upgrade->>'id'`, "=", upgradeId)
582
+ .updateTable("skills")
583
+ .set({ pinned_version: null, updated_at: now })
584
+ .where("platform_skill_id", "=", c.id)
585
+ .where("org_id", "in", c.pinnedOrgs)
586
+ .where("pinned_version", "is not", null)
587
+ .execute();
588
+ }
589
+ else if (c.kind === "agent_template") {
590
+ await t
591
+ .updateTable("agent_templates")
592
+ .set({ pinned_version: null, updated_at: now })
593
+ .where("platform_template_id", "=", c.id)
594
+ .where("org_id", "in", c.pinnedOrgs)
595
+ .where("pinned_version", "is not", null)
441
596
  .execute();
442
- await audit(t, {
443
- actorAccountId: actor,
444
- ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
445
- orgId,
446
- action: "plugin.org_upgrade_failed",
447
- target: installId,
448
- detail: {
449
- itemId: diff.itemId,
450
- name: diff.name,
451
- from: diff.from.version,
452
- to: diff.to.version,
453
- step: at,
454
- code,
455
- rolledBack: undo,
456
- ...(!ours && { cleanedUpMeanwhile: true }),
457
- },
458
- });
459
- return out;
460
- });
461
- for (const r of removed) {
462
- if (r.kind === "extension")
463
- await this.d.orgConfigs.afterDisable(orgId, r.ref);
464
597
  }
465
598
  }
466
- catch (u) {
467
- // Left `upgrading` with its journal: undone once it is older than catalog.staleInstallMinutes
468
- rolledBack = false;
469
- this.d.log?.warn("plugin upgrade rollback failed", {
470
- orgId,
471
- installId,
472
- error: u instanceof Error ? u.message : String(u),
599
+ // Connectors made from changed templates, in every org (ruling E2)
600
+ const orgs = [...new Set(diff.connectors.map((c) => c.orgId))].sort();
601
+ for (const orgId of orgs) {
602
+ if (!liveOrgs.has(orgId)) {
603
+ // Locked before the item (P3-50): an org not locked then is deleted (its connectors go
604
+ // with it), or its connector was made since, which changes what the update does
605
+ const live = await t
606
+ .selectFrom("orgs")
607
+ .select("id")
608
+ .where("id", "=", orgId)
609
+ .where("deleted_at", "is", null)
610
+ .executeTakeFirst();
611
+ if (live === undefined)
612
+ continue;
613
+ throw stale();
614
+ }
615
+ for (const c of diff.connectors.filter((x) => x.orgId === orgId)) {
616
+ const prepared = await this.prepare(actor, itemId, diff.to.version, c);
617
+ await this.connectors.applyTemplateIn(orgId, c.id, actor, prepared, opts.actorTokenId);
618
+ }
619
+ }
620
+ // Connectors of the templates the update turns on, in every org where the plugin is on (plugin
621
+ // pages spec §5.2.3): rows only, no outbound call; a ready one's tool list is owed through the
622
+ // outbox. Created by the kernel itself (no actor: the super admin need not be an org member)
623
+ for (const c of diff.creates) {
624
+ // Locked before the item (P3-50) from the diff before the transaction, which the diffHash
625
+ // check matched: the recomputed diff names only live, locked orgs (an org deleted since
626
+ // drops out of it and fails the hash check as stale), so this guards the invariant only
627
+ if (!liveOrgs.has(c.orgId))
628
+ throw stale();
629
+ await this.createTemplateConnectorIn(itemId, diff.to.version, c);
630
+ }
631
+ // A deferred connector writes nothing (ruling R27): the org's ensure creates it once its
632
+ // connector extension is on there and loaded (the job retries while it is not loaded)
633
+ for (const orgId of diff.deferredOrgs)
634
+ await oweTemplateConnectors(this.outbox, t, orgId);
635
+ // One version for the deployment: every live org install of the plugin moves with it (one
636
+ // still installing too; an install marked installed later records the platform version
637
+ // current at its commit, PluginInstaller.markInstalled)
638
+ await t
639
+ .updateTable("plugin_installs")
640
+ .set({ version: diff.to.version, error: null })
641
+ .where("item_id", "=", itemId)
642
+ .where("status", "in", [...LIVE_INSTALL_STATUSES])
643
+ .execute();
644
+ if (owner !== undefined || confirmPending !== undefined) {
645
+ // An org's version becomes its latest once applied or confirmed (ruling P3-34)
646
+ await t
647
+ .updateTable("catalog_items")
648
+ .set({ latest_version: diff.to.version })
649
+ .where("id", "=", itemId)
650
+ .execute();
651
+ await markVersionApplied(t, itemId, diff.to.version);
652
+ // An owner's new version replaces a version waiting for the super admin (pre-flight F7):
653
+ // their confirmation of it is then refused (409 extension.not_pending); the super admin's
654
+ // confirmation applied it
655
+ await t
656
+ .updateTable("catalog_items")
657
+ .set({ pending_version: null, pending_by: null, pending_at: null })
658
+ .where("id", "=", itemId)
659
+ .where("pending_version", "is not", null)
660
+ .execute();
661
+ }
662
+ if (confirmPending !== undefined && pendingOwner !== null) {
663
+ await addOrgNotice(t, pendingOwner, "upload_confirmed", {
664
+ itemId,
665
+ name: diff.name,
666
+ displayName: await itemDisplayName(t, itemId),
667
+ version: diff.to.version,
473
668
  });
474
669
  }
475
- if (cause instanceof ApiError && cause.code === "plugin.install_in_progress" && rolledBack) {
476
- return cause;
670
+ // The orgs using a shared org-owned plugin are told, one notice per plugin (a platform-owned
671
+ // plugin tells nobody); a plugin never synced before has no version to come from
672
+ if (diff.from !== null) {
673
+ await notifySharedUpdate(t, { kind: "plugin", id: itemId }, { name: diff.name, from: diff.from, to: diff.to.version });
477
674
  }
478
- const dependency = failure && failure.dependency.length > 0 ? failure.dependency : [];
479
- const dep = dependency.length > 0 ? ` in dependency ${dependency.join(" > ")}` : "";
480
- return new ApiError("plugin.upgrade_failed", rolledBack
481
- ? `Upgrading the plugin failed at step ${at}${dep} (${code}); this organization's components are back at version ${diff.from.version}`
482
- : `Upgrading the plugin failed at step ${at}${dep} (${code}) and rolling back failed; it is undone after catalog.staleInstallMinutes`, [
483
- {
484
- step: at,
485
- code,
486
- ...(dependency.length > 0 && { dependency: dependency.join(" > ") }),
487
- ...(cause instanceof ApiError && { message: cause.message }),
488
- ...(cause instanceof ApiError &&
489
- cause.details !== undefined && { causeDetails: cause.details }),
490
- rolledBack,
675
+ await audit(t, {
676
+ actorAccountId: actor,
677
+ ...(opts.actorTokenId !== undefined && { actorTokenId: opts.actorTokenId }),
678
+ action: "plugin.platform_updated",
679
+ target: itemId,
680
+ detail: {
681
+ name: diff.name,
682
+ from: diff.from,
683
+ to: diff.to.version,
684
+ ...(owner !== undefined && { ownerOrgId: owner.orgId }),
685
+ components: diff.components.map((c) => ({
686
+ kind: c.kind,
687
+ name: c.name,
688
+ change: c.change,
689
+ ...(c.kept !== undefined && { kept: true }),
690
+ ...(c.pinnedOrgs.length > 0 && c.change !== "removed" && { unpinned: c.pinnedOrgs }),
691
+ })),
692
+ ...(diff.extension && { extension: extensionView(diff.extension) }),
693
+ connectors: diff.connectors.map((c) => ({
694
+ orgId: c.orgId,
695
+ id: c.id,
696
+ credentialsReset: c.credentialsReset,
697
+ })),
698
+ ...(diff.deferredOrgs.length > 0 && {
699
+ deferredConnectors: diff.connectorOrgs.flatMap((o) => o.deferred.map((d) => ({ orgId: o.orgId, templateId: d.templateId, kind: d.kind }))),
700
+ }),
701
+ ...opts.auditDetail,
491
702
  },
492
- ]);
703
+ });
704
+ // The scope sync of the item and its dependencies is owed with the update (outbox spec §8.1)
705
+ for (const id of [itemId, ...diff.dependencies])
706
+ await this.sync.enqueueItem(id);
707
+ return diff;
493
708
  }
494
709
  /**
495
- * An upgrade interrupted for longer than `catalog.staleInstallMinutes` (a replica crashed
496
- * midway): its journal is undone, the install back `installed` at the old version (error step
497
- * `interrupted`), audit `plugin.org_upgrade_failed`. Nothing to do otherwise.
710
+ * The template update of one connector: the new endpoint preset with the org's values at the
711
+ * editable paths, the auth preset and default policies; credentials cleared (no new ones: they
712
+ * are the org's) when the credential shape changed.
498
713
  */
499
- async recoverInterrupted(orgId, actor, installId) {
500
- if (!UUID_RE.test(installId))
501
- throw installNotFound();
502
- const staleMinutes = this.d.staleInstallMinutes();
503
- const removed = await this.d.db.transaction().execute(async (t) => {
504
- const peek = await t
505
- .selectFrom("plugin_installs")
506
- .select("status")
507
- .where("id", "=", installId)
508
- .where("org_id", "=", orgId)
509
- .executeTakeFirst();
510
- if (peek?.status !== "upgrading")
511
- return [];
512
- await lockOrg(t, orgId);
513
- const row = await t
514
- .selectFrom("plugin_installs as a")
515
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
516
- .select([
517
- "a.status",
518
- "a.upgrade",
519
- "a.item_id",
520
- "i.name",
521
- sql `coalesce((a.upgrade->>'startedAt')::timestamptz < now() - make_interval(mins => ${staleMinutes}), false)`.as("stale"),
522
- ])
523
- .where("a.id", "=", installId)
524
- .where("a.org_id", "=", orgId)
525
- .forUpdate("a")
526
- .executeTakeFirst();
527
- if (row?.status !== "upgrading" || !row.stale)
528
- return [];
529
- const steps = journalEntries(row.upgrade);
530
- const out = await this.installer.undoUpgradeIn(t, orgId, actor, installId, steps, "plugin_upgrade_cleanup");
531
- await t
532
- .updateTable("plugin_installs")
533
- .set({
534
- status: "installed",
535
- upgrade: null,
536
- error: JSON.stringify({ step: "interrupted", code: "internal" }),
537
- })
538
- .where("id", "=", installId)
539
- .execute();
540
- const j = row.upgrade;
541
- await audit(t, {
542
- actorAccountId: actor,
543
- orgId,
544
- action: "plugin.org_upgrade_failed",
545
- target: installId,
546
- detail: {
547
- itemId: row.item_id,
548
- name: row.name,
549
- from: j?.from ?? null,
550
- to: j?.to ?? null,
551
- step: "interrupted",
552
- code: "internal",
553
- rolledBack: steps,
554
- },
555
- });
556
- return out;
557
- });
558
- for (const r of removed) {
559
- if (r.kind === "extension")
560
- await this.d.orgConfigs.afterDisable(orgId, r.ref);
714
+ async prepare(actor, itemId, version, c) {
715
+ const template = c.file.template;
716
+ const endpoint = structuredClone(template.endpoint);
717
+ for (const e of template.editableEndpoint ?? []) {
718
+ const v = getPath(c.endpoint, e);
719
+ if (v !== undefined)
720
+ setPath(endpoint, e, v);
561
721
  }
722
+ const input = {
723
+ endpoint,
724
+ auth: template.auth,
725
+ ...(template.git !== undefined && { git: template.git }),
726
+ template: {
727
+ itemId,
728
+ version,
729
+ templateId: c.templateId,
730
+ ...(template.defaultToolPolicies !== undefined && {
731
+ defaultToolPolicies: template.defaultToolPolicies,
732
+ }),
733
+ },
734
+ resetCredentials: false,
735
+ };
736
+ // Checked without credentials (nothing outbound); a changed shape then clears the old ones
737
+ const prepared = await this.connectors.prepareTemplateUpdate(actor, c.connector, input);
738
+ return c.credentialsReset
739
+ ? { ...prepared, input: { ...prepared.input, resetCredentials: true } }
740
+ : prepared;
562
741
  }
563
742
  /**
564
- * The removals of an upgrade, in the final transaction, by the uninstall rules
565
- * (`decideRemovalIn`): only components this install created are removed, and only when nothing
566
- * else uses them; one still used (by an agent, a connector or another extension) stays in the
567
- * ledger marked `dropped` ("no longer in the plugin", still this install's), every other removed
568
- * component leaves the ledger; a dropped component the target brings back is un-dropped. A dependency
569
- * install is uninstalled by the same rules (another install using it takes it over). Skills ->
570
- * connectors -> extension -> dependencies.
743
+ * Creates the connector of a template the update turns on in an org, in the update's
744
+ * transaction (the org row locked): as an install creates it (`PluginInstaller.planConnector`,
745
+ * `ConnectorsService.createDeferredIn`: no outbound call, `needs_config` when the template needs
746
+ * an org credential or OAuth client), by the kernel itself, and recorded on the org's live
747
+ * install of the plugin when there is one (a builtin plugin has none).
571
748
  */
572
- async removeIn(t, orgId, actor, diff, disabled) {
573
- const report = { removed: [], kept: [] };
574
- const reason = "plugin_upgrade";
575
- const keep = (kind, ref, why) => report.kept.push({ kind, ref, reason: why });
576
- const row = (kind, ref) => t
577
- .updateTable("plugin_install_components")
578
- .where("install_id", "=", diff.installId)
579
- .where("kind", "=", kind)
580
- .where("ref", "=", ref);
581
- const dropRow = (kind, ref) => t
582
- .deleteFrom("plugin_install_components")
583
- .where("install_id", "=", diff.installId)
584
- .where("kind", "=", kind)
585
- .where("ref", "=", ref)
586
- .execute();
587
- const removed = [
588
- ...diff.skills.flatMap((x) => (x.change === "removed" && x.ledger ? [x.ledger] : [])),
589
- ...diff.agentTemplates.flatMap((x) => (x.change === "removed" && x.ledger ? [x.ledger] : [])),
590
- ...diff.templates.flatMap((x) => (x.change === "removed" && x.ledger ? [x.ledger] : [])),
591
- ...(diff.extension?.change === "removed"
592
- ? diff.ledger.filter((l) => l.kind === "extension" && l.ref === diff.extension?.name)
593
- : []),
594
- ];
595
- const agentRefs = await this.installer.agentRefs(t, orgId);
596
- const self = new Set([diff.installId]);
597
- for (const l of removed) {
598
- if (!l.created) {
599
- await dropRow(l.kind, l.ref);
600
- keep(l.kind, l.ref, "pre_existing");
601
- continue;
602
- }
603
- const outcome = await this.installer.decideRemovalIn(t, orgId, actor, { kind: l.kind, ref: l.ref, created: true, skillVersion: null }, self, agentRefs, reason);
604
- if (outcome === "used_by_agents" ||
605
- outcome === "used_by_connectors" ||
606
- outcome === "used_by_plugins") {
607
- // Still used: stays this install's, marked dropped, so an uninstall (or a later upgrade
608
- // bringing it back) still finds it
609
- await row(l.kind, l.ref).set({ dropped: true }).execute();
610
- keep(l.kind, l.ref, outcome);
611
- continue;
612
- }
613
- await dropRow(l.kind, l.ref);
614
- if (outcome === "removed") {
615
- report.removed.push({ kind: l.kind, ref: l.ref });
616
- if (l.kind === "extension")
617
- disabled.push(l.ref);
618
- }
619
- else if (outcome !== "gone")
620
- keep(l.kind, l.ref, outcome);
621
- }
622
- // Components back in the plugin (dropped by an earlier upgrade, brought again by the target)
623
- const back = [
624
- ...diff.skills.flatMap((x) => x.change !== "removed" && x.ledger?.dropped
625
- ? [{ kind: "skill", ref: x.ledger.ref }]
626
- : []),
627
- ...diff.agentTemplates.flatMap((x) => x.change !== "removed" && x.ledger?.dropped
628
- ? [{ kind: "agent_template", ref: x.ledger.ref }]
629
- : []),
630
- ...diff.templates.flatMap((x) => x.change !== "removed" && x.ledger?.dropped
631
- ? [{ kind: "connector", ref: x.ledger.ref }]
632
- : []),
633
- ...(diff.extension && diff.extension.change !== "removed"
634
- ? diff.ledger
635
- .filter((l) => l.kind === "extension" && l.ref === diff.extension?.name && l.dropped)
636
- .map((l) => ({ kind: "extension", ref: l.ref }))
637
- : []),
638
- ];
639
- for (const b of back)
640
- await row(b.kind, b.ref).set({ dropped: false }).execute();
641
- for (const dep of diff.dependencies) {
642
- if (dep.change !== "removed" || !dep.child)
643
- continue;
644
- const ref = dep.child.installId;
645
- await dropRow("plugin", ref);
646
- if (!dep.child.ledger.created) {
647
- keep("plugin", ref, "pre_existing");
648
- continue;
649
- }
650
- const sub = { removed: [], kept: [] };
651
- const outcome = await this.installer.uninstallIn(t, orgId, actor, ref, {
652
- report: sub,
653
- removing: new Set(),
654
- from: diff.installId,
655
- authorize: false,
656
- reason,
657
- opts: {},
658
- });
659
- for (const r of sub.removed)
660
- if (r.kind === "extension")
661
- disabled.push(r.ref);
662
- if (outcome === "removed")
663
- report.removed.push({ kind: "plugin", ref });
664
- else if (outcome === "kept")
665
- keep("plugin", ref, "used_by_other_install");
666
- }
667
- return report;
749
+ async createTemplateConnectorIn(itemId, version, c) {
750
+ const ci = this.installer.planConnector(null, { itemId, version }, { id: c.templateId, file: c.file }, "", undefined);
751
+ const connectorId = await this.connectors.createDeferredIn(c.orgId, null, ci, {
752
+ auditDetail: { via: "platform_update" },
753
+ });
754
+ await this.installer.recordTemplateConnectorIn(c.orgId, itemId, connectorId, c.templateId, LIVE_INSTALL_STATUSES);
668
755
  }
669
756
  /**
670
- * Computes an upgrade (see the class comment). `input` null: the preview (no input checks);
671
- * otherwise the connector inputs are built and checked as at install.
757
+ * Computes an update (see the class comment). `target`: the target read from an org's staging
758
+ * instead of `catalog_item_versions` (pre-flight F3). `owner`: an owner update (P3-12): the item
759
+ * must be the org's, an extension-bearing target is refused, and a target dropping the
760
+ * extension removes it.
672
761
  */
673
- async diff(orgId, actor, installId, version, input) {
674
- const db = this.d.db;
675
- if (!UUID_RE.test(installId))
676
- throw installNotFound();
677
- const install = await db
678
- .selectFrom("plugin_installs as a")
679
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
680
- .select(["a.item_id", "a.version", "a.status", "i.name", "i.policy", "i.deleted_at"])
681
- .where("a.id", "=", installId)
682
- .where("a.org_id", "=", orgId)
762
+ async diff(itemId, version, o = {}) {
763
+ const db = this.db;
764
+ if (!UUID_RE.test(itemId))
765
+ throw itemNotFound();
766
+ const item = await db
767
+ .selectFrom("catalog_items")
768
+ .select([
769
+ "id",
770
+ "name",
771
+ "scope",
772
+ "disabled",
773
+ "builtin",
774
+ "deleted_at",
775
+ "platform_synced_version",
776
+ "owner_org_id",
777
+ "awaiting_confirmation",
778
+ "pending_version",
779
+ "latest_version",
780
+ ])
781
+ .where("id", "=", itemId)
683
782
  .executeTakeFirst();
684
- if (!install || install.status === "failed")
685
- throw installNotFound();
686
- if (install.status !== "installed")
687
- throw inProgress();
688
- const itemId = install.item_id;
689
- const name = install.name;
690
- if (install.deleted_at !== null) {
691
- throw new ApiError("catalog.item_not_found", "This plugin is no longer in the enterprise catalog");
783
+ if (!item || item.deleted_at !== null)
784
+ throw itemNotFound();
785
+ // A version waiting for the super admin applies only through their confirmation (P3-9, F8)
786
+ if (o.confirmPending !== version) {
787
+ if (item.awaiting_confirmation)
788
+ throw itemPendingError(item.name);
789
+ if (item.pending_version !== null && item.pending_version === version) {
790
+ throw itemPendingError(item.name, version);
791
+ }
792
+ // The super admin's generic update of an org's plugin reaches only its applied version
793
+ // (`latest_version`, ruling P3-34/P3-37): one the org uploaded that was never applied or
794
+ // confirmed (a rejected or failed one) is not theirs to apply
795
+ if (o.owner === undefined && item.owner_org_id !== null && version !== item.latest_version) {
796
+ throw notApplied(item.name, version);
797
+ }
692
798
  }
693
- if (install.policy === "disabled") {
694
- throw new ApiError("catalog.item_disabled", "This catalog item is disabled by the enterprise admin and cannot be upgraded");
799
+ if (o.owner !== undefined && item.owner_org_id !== o.owner.orgId)
800
+ throw itemNotFound();
801
+ if (item.disabled) {
802
+ throw new ApiError("catalog.item_disabled", "This plugin is disabled on the deployment; enable it before updating");
695
803
  }
696
- const versions = await db
804
+ const name = item.name;
805
+ const versions = (await db
697
806
  .selectFrom("catalog_item_versions")
698
807
  .select([
699
808
  "version",
@@ -701,519 +810,890 @@ export class PluginUpgrader {
701
810
  "object_prefix",
702
811
  "files",
703
812
  "extension_sha256",
704
- "imported_at",
705
- "source_format",
813
+ "applied_at",
814
+ "rejected_at",
706
815
  ])
707
816
  .where("item_id", "=", itemId)
708
- .execute();
709
- const fromRow = versions.find((v) => v.version === install.version);
710
- const toRow = versions.find((v) => v.version === version);
711
- if (!fromRow) {
712
- throw new ApiError("catalog.item_not_found", `The installed version ${install.version} is no longer in the enterprise catalog`);
713
- }
714
- if (!toRow)
817
+ .execute());
818
+ const to = o.target ?? versions.find((v) => v.version === version);
819
+ if (!to)
715
820
  throw new ApiError("catalog.item_not_found", `Version ${version} of this item not found`);
716
- const from = fromRow;
717
- const to = toRow;
718
- if (to.version === from.version) {
719
- // Confirming a preview whose upgrade already ran (a concurrent confirm won): stale
720
- if (input !== null)
821
+ // Whoever owns the item now (a transfer keeps the version rows), the generic update never
822
+ // reaches a version that was rejected or never applied (ruling P3-52)
823
+ const row = versions.find((v) => v.version === version);
824
+ if (o.owner === undefined && o.confirmPending !== version && row && !versionUsable(row)) {
825
+ throw notApplied(item.name, version);
826
+ }
827
+ if (o.owner !== undefined && to.manifest.extension) {
828
+ // An org's version with an extension waits for the super admin's confirmation (plan Task 6)
829
+ 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`);
830
+ }
831
+ const from = item.platform_synced_version;
832
+ const fromRow = versions.find((v) => v.version === from);
833
+ if (from === to.version) {
834
+ // Confirming a preview whose update already ran (a concurrent confirm won): stale
835
+ if (o.pre)
721
836
  throw stale();
722
- throw targetInvalid(`This organization already has version ${from.version} installed`, [
723
- { reason: "same_version", version: from.version },
837
+ throw targetInvalid(`The platform already runs version ${from} of plugin ${name}`, [
838
+ { reason: "same_version", version: from },
724
839
  ]);
725
840
  }
726
- // Target rules (Decision 10)
727
- if (to.manifest.extension) {
728
- const deployed = await deployedExtension(db, this.d.host, name);
729
- const allowed = deploymentTarget(versions, deployed);
730
- if (allowed?.version !== to.version) {
731
- throw targetInvalid(deployed === undefined
732
- ? `The deployment does not run the extension of plugin ${name}; ask the enterprise admin to install it first`
733
- : `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"}`, [
734
- {
735
- reason: "deployment_version",
736
- deploymentVersion: deployed?.version ?? null,
737
- allowedVersion: allowed?.version ?? null,
738
- },
739
- ]);
841
+ const target = await this.extensionTarget(name, fromRow, to, o.owner !== undefined);
842
+ let extension;
843
+ if (o.pre) {
844
+ // The confirm's transaction: the extension this update moved is expected in place (a
845
+ // removed one gone)
846
+ if (o.pre.extension) {
847
+ const row = await db
848
+ .selectFrom("extension_installs")
849
+ .select("sha256")
850
+ .where("name", "=", name)
851
+ .executeTakeFirst();
852
+ if ((row?.sha256 ?? null) !== o.pre.extension.sha256)
853
+ throw stale();
854
+ extension = o.pre.extension;
740
855
  }
741
- }
742
- // Installs in this org depending on this one must accept the target
743
- const parents = await db
744
- .selectFrom("plugin_install_components as c")
745
- .innerJoin("plugin_installs as a", "a.id", "c.install_id")
746
- .innerJoin("catalog_item_versions as v", (j) => j.onRef("v.item_id", "=", "a.item_id").onRef("v.version", "=", "a.version"))
747
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
748
- .select(["i.name", "v.manifest"])
749
- .where("c.kind", "=", "plugin")
750
- .where("c.ref", "=", installId)
751
- .where("a.org_id", "=", orgId)
752
- .where("a.status", "<>", "failed")
753
- .execute();
754
- for (const p of parents) {
755
- const range = p.manifest.dependencies?.find((x) => x.name === name)?.version;
756
- if (range !== undefined && !satisfiesRange(to.version, range)) {
757
- 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 }]);
856
+ else {
857
+ if (target !== null)
858
+ throw stale();
859
+ extension = null;
758
860
  }
759
861
  }
760
- const ledger = await ledgerOf(db, installId);
761
- const components = [];
762
- // Extension
763
- let extension = null;
764
- let extensionConfig = false;
765
- if (from.manifest.extension || to.manifest.extension) {
766
- const change = !from.manifest.extension
767
- ? "added"
768
- : !to.manifest.extension
769
- ? "removed"
770
- : from.extension_sha256 !== to.extension_sha256 ||
771
- from.manifest.extension.manifest.version !== to.manifest.extension.manifest.version
772
- ? "changed"
773
- : "unchanged";
774
- extension = { change, name };
775
- if (change === "added") {
776
- await this.installer.planExtension(orgId, to.manifest);
777
- extensionConfig = !(await isExtensionEnabled(db, orgId, name));
778
- }
779
- components.push({
780
- kind: "extension",
781
- ref: name,
782
- change,
783
- ...(change === "changed" && {
784
- detail: `${from.manifest.extension?.manifest.version} -> ${to.manifest.extension?.manifest.version}`,
785
- }),
786
- });
862
+ else {
863
+ extension = target && {
864
+ ...target,
865
+ needsApproval: target.sha256 !== null && (await this.needsApproval(name, target.sha256)),
866
+ orgs: [],
867
+ };
787
868
  }
788
- // Dependencies (by plugin name)
789
- const resolved = await resolveDependencies(db, to.manifest);
790
- const childIds = ledger.filter((l) => l.kind === "plugin").map((l) => l.ref);
791
- const children = childIds.length === 0
792
- ? []
793
- : await db
794
- .selectFrom("plugin_installs as a")
795
- .innerJoin("catalog_items as i", "i.id", "a.item_id")
796
- .select(["a.id", "a.version", "i.name"])
797
- .where("a.id", "in", childIds)
798
- .execute();
799
- const childOf = (n) => {
800
- const c = children.find((x) => x.name === n);
801
- const l = c && ledger.find((x) => x.kind === "plugin" && x.ref === c.id);
802
- return c && l ? { installId: c.id, version: c.version, ledger: l } : undefined;
803
- };
804
- const dependencies = [];
805
- const fromDeps = from.manifest.dependencies ?? [];
806
- for (const r of resolved) {
807
- const before = fromDeps.find((x) => x.name === r.name);
808
- const child = childOf(r.name);
809
- if (before && child) {
810
- const change = before.version === r.range ? "unchanged" : "changed";
811
- if (change === "changed" && !satisfiesRange(child.version, r.range)) {
812
- 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 }]);
813
- }
814
- dependencies.push({
815
- name: r.name,
816
- change,
817
- range: r.range,
818
- fromRange: before.version,
819
- resolved: r,
820
- child,
821
- });
869
+ const contents = o.pre?.contents ?? (await this.readContents(to));
870
+ const dependencies = await this.checkDependents(name, to);
871
+ // The platform's components of the plugin and the target's
872
+ const live = await this.liveComponents(itemId);
873
+ const components = [];
874
+ const direction = (fromVersion) => fromVersion === null || compareVersions(to.version, fromVersion) >= 0
875
+ ? "upgrade"
876
+ : "downgrade";
877
+ const added = (kind, n) => ({
878
+ kind,
879
+ id: null,
880
+ name: n,
881
+ change: "added",
882
+ from: null,
883
+ to: to.version,
884
+ updatedOnOwn: false,
885
+ ownScope: false,
886
+ pinnedOrgs: [],
887
+ });
888
+ // Skills (by name, by their files' digest)
889
+ const toSkills = contents.skillNames.map((n, i) => {
890
+ const entry = (to.manifest.skills ?? [])[i];
891
+ return {
892
+ name: n,
893
+ digest: dirDigest(to, packagePath(entry?.path)),
894
+ };
895
+ });
896
+ for (const s of toSkills) {
897
+ const l = live.skills.find((x) => x.name === s.name);
898
+ if (!l) {
899
+ components.push(added("skill", s.name));
822
900
  continue;
823
901
  }
824
- // New (or its install was not recorded): installed by the install flow
825
- const live = await this.installer.liveDependency(db, orgId, r);
826
- dependencies.push({
827
- name: r.name,
828
- change: "added",
829
- range: r.range,
830
- resolved: r,
831
- plan: live !== undefined
832
- ? null
833
- : await this.installer.plan(orgId, actor, r.itemId, r.version, input === null ? null : {}, `dependencies.${r.name}.`, itemId),
902
+ const same = skillFilesDigest(l.manifest.files) === s.digest;
903
+ components.push({
904
+ kind: "skill",
905
+ id: l.id,
906
+ name: s.name,
907
+ change: same ? "same" : direction(l.catalogVersion),
908
+ from: l.catalogVersion,
909
+ to: to.version,
910
+ updatedOnOwn: l.updatedOnOwn,
911
+ ownScope: l.ownScope,
912
+ pinnedOrgs: [],
834
913
  });
835
914
  }
836
- for (const before of fromDeps) {
837
- if (resolved.some((r) => r.name === before.name))
915
+ for (const l of live.skills) {
916
+ if (toSkills.some((s) => s.name === l.name))
838
917
  continue;
839
- const child = childOf(before.name);
840
- dependencies.push({
841
- name: before.name,
918
+ components.push({
919
+ kind: "skill",
920
+ id: l.id,
921
+ name: l.name,
842
922
  change: "removed",
843
- fromRange: before.version,
844
- ...(child && { child }),
923
+ from: l.catalogVersion,
924
+ to: null,
925
+ updatedOnOwn: l.updatedOnOwn,
926
+ ownScope: l.ownScope,
927
+ pinnedOrgs: [],
845
928
  });
846
929
  }
847
- for (const dep of dependencies) {
930
+ // Agent templates (by name, canonical definition)
931
+ const toAgents = contents.agents;
932
+ for (const a of toAgents) {
933
+ const l = live.agentTemplates.find((x) => x.name === a.template.name);
934
+ if (!l) {
935
+ components.push(added("agent_template", a.template.name));
936
+ continue;
937
+ }
938
+ const same = canonicalJson(l.definition) === canonicalJson(a.template);
848
939
  components.push({
849
- kind: "plugin",
850
- ref: dep.name,
851
- change: dep.change,
852
- ...(dep.change === "changed" && { detail: `${dep.fromRange} -> ${dep.range}` }),
853
- ...(dep.change === "added" && {
854
- detail: dep.plan === null ? "already installed" : `installs ${dep.resolved?.version}`,
855
- }),
940
+ kind: "agent_template",
941
+ id: l.id,
942
+ name: l.name,
943
+ change: same ? "same" : direction(l.catalogVersion),
944
+ from: l.catalogVersion,
945
+ to: to.version,
946
+ updatedOnOwn: l.updatedOnOwn,
947
+ ownScope: l.ownScope,
948
+ pinnedOrgs: [],
856
949
  });
857
950
  }
858
- // Skills (by name)
859
- const fromNames = await catalogSkillNames(this.d.storage, from, from.manifest);
860
- const toNames = await catalogSkillNames(this.d.storage, to, to.manifest);
861
- const dirOf = (m, i) => packagePath((m.skills ?? [])[i]?.path);
862
- const fromSkills = new Map(fromNames.map((n, i) => [n, dirOf(from.manifest, i)]));
863
- const toSkills = new Map(toNames.map((n, i) => [n, dirOf(to.manifest, i)]));
864
- const toPinned = new Set(toNames.filter((_, i) => (to.manifest.skills ?? [])[i]?.pinned === true));
865
- const skillRefs = ledger.filter((l) => l.kind === "skill").map((l) => l.ref);
866
- const liveSkills = skillRefs.length === 0
867
- ? []
868
- : await db
869
- .selectFrom("skills")
870
- .select(["id", "name"])
871
- .where("id", "in", skillRefs)
872
- .where("org_id", "=", orgId)
873
- .where("deleted_at", "is", null)
874
- .execute();
875
- const ledgerOfSkill = (n) => {
876
- const s = liveSkills.find((x) => x.name === n);
877
- return s && ledger.find((l) => l.kind === "skill" && l.ref === s.id);
878
- };
879
- const skills = [];
880
- for (const [n, dir] of toSkills) {
881
- const before = fromSkills.get(n);
882
- const l = ledgerOfSkill(n);
883
- const change = before === undefined
884
- ? "added"
885
- : dirDigest(from, before) === dirDigest(to, dir)
886
- ? "unchanged"
887
- : "changed";
888
- skills.push({
889
- name: n,
890
- change,
891
- dir,
892
- suggestPinned: toPinned.has(n),
893
- ...(l && { ledger: l }),
894
- });
895
- }
896
- for (const n of fromSkills.keys()) {
897
- if (toSkills.has(n))
951
+ for (const l of live.agentTemplates) {
952
+ if (toAgents.some((a) => a.template.name === l.name))
898
953
  continue;
899
- const l = ledgerOfSkill(n);
900
- skills.push({ name: n, change: "removed", ...(l && { ledger: l }) });
901
- }
902
- for (const s of skills)
903
- components.push({ kind: "skill", ref: s.name, change: s.change });
904
- // The same skill conflict check as an install (spec §9.2)
905
- const conflicts = await planSkillConflicts(db, orgId, {
906
- itemId,
907
- name,
908
- version: to.version,
909
- skillNames: toNames,
910
- dependencies: dependencies
911
- .filter((x) => x.change === "added")
912
- .map((x) => ({ plan: x.plan ?? null })),
913
- });
914
- if (conflicts.length > 0)
915
- throw skillConflictError(conflicts);
916
- // Agent templates (by name; phase C)
917
- const fromAgents = await readCatalogAgentTemplates(this.d.storage, from);
918
- const toAgents = await readCatalogAgentTemplates(this.d.storage, to);
919
- const templateRefs = ledger.filter((l) => l.kind === "agent_template").map((l) => l.ref);
920
- const liveTemplates = templateRefs.length === 0
921
- ? []
922
- : await db
923
- .selectFrom("agent_templates")
924
- .select(["id", "name"])
925
- .where("id", "in", templateRefs)
926
- .where("org_id", "=", orgId)
927
- .where("deleted_at", "is", null)
928
- .execute();
929
- const ledgerOfTemplate = (n) => {
930
- const r = liveTemplates.find((x) => x.name === n);
931
- return r && ledger.find((l) => l.kind === "agent_template" && l.ref === r.id);
932
- };
933
- const agentTemplates = [];
934
- for (const a of toAgents) {
935
- const n = a.template.name;
936
- const before = fromAgents.find((x) => x.template.name === n);
937
- const l = ledgerOfTemplate(n);
938
- const change = before === undefined
939
- ? "added"
940
- : canonicalJson(before.template) === canonicalJson(a.template)
941
- ? "unchanged"
942
- : "changed";
943
- agentTemplates.push({ name: n, change, template: a.template, ...(l && { ledger: l }) });
944
- }
945
- for (const a of fromAgents) {
946
- const n = a.template.name;
947
- if (toAgents.some((x) => x.template.name === n))
948
- continue;
949
- const l = ledgerOfTemplate(n);
950
- agentTemplates.push({ name: n, change: "removed", ...(l && { ledger: l }) });
951
- }
952
- for (const a of agentTemplates) {
953
- components.push({ kind: "agent_template", ref: a.name, change: a.change });
954
+ components.push({
955
+ kind: "agent_template",
956
+ id: l.id,
957
+ name: l.name,
958
+ change: "removed",
959
+ from: l.catalogVersion,
960
+ to: null,
961
+ updatedOnOwn: l.updatedOnOwn,
962
+ ownScope: l.ownScope,
963
+ pinnedOrgs: [],
964
+ });
954
965
  }
955
- // Connector templates (by id)
956
- const fromTemplates = await readCatalogTemplates(this.d.storage, from);
957
- const toTemplates = await readCatalogTemplates(this.d.storage, to);
958
- // The install's connectors by template; a dropped one (kept only for the agents using it) counts
959
- // only while its connector is live, so a template the target brings back maps onto it
960
- const connectorRows = ledger.filter((l) => l.kind === "connector" && l.template_id !== null);
961
- const liveConnectors = connectorRows.length === 0
962
- ? []
963
- : await db
964
- .selectFrom("connectors")
965
- .select(["id", "connector", "endpoint", "auth"])
966
- .where("id", "in", connectorRows.map((l) => l.ref))
967
- .where("org_id", "=", orgId)
968
- .where("deleted_at", "is", null)
969
- .execute();
970
- const connectorOf = (templateId) => {
971
- const rows = connectorRows.filter((x) => x.template_id === templateId);
972
- const l = rows.find((x) => !x.dropped) ??
973
- rows.find((x) => liveConnectors.some((c) => c.id === x.ref));
974
- const c = l && liveConnectors.find((x) => x.id === l.ref);
975
- return {
976
- ...(l && { ledger: l }),
977
- ...(c && {
978
- connector: {
979
- id: c.id,
980
- connector: c.connector,
981
- endpoint: c.endpoint,
982
- auth: c.auth,
983
- },
984
- }),
985
- };
986
- };
966
+ // Connector templates (by id, canonical file) and the connectors made from them
967
+ const toTemplates = contents.templates;
987
968
  const deps = this.installer.templateDeps();
988
- const templates = [];
969
+ const connectors = [];
970
+ const shippedOff = (f) => f.defaultEnabled === false;
971
+ /** Templates whose `defaultEnabled` the target flips: id -> shipped off, and the platform id. */
972
+ const flipped = new Map();
973
+ const flippedIds = new Map();
989
974
  for (const ct of toTemplates) {
990
- const problem = templatePluginProblem(deps, ct.file.template);
991
- const before = fromTemplates.find((x) => x.id === ct.id);
992
- const mapped = connectorOf(ct.id);
993
- if (!before && mapped.ledger?.dropped && mapped.connector) {
994
- // Back in the plugin (an earlier upgrade dropped it, its connector was kept): the kept
995
- // connector is updated to the template, not created again (its slug would be taken)
975
+ const l = live.templates.find((x) => x.name === ct.id);
976
+ if (!l) {
977
+ const problem = templatePluginProblem(deps, ct.file.template);
996
978
  if (problem !== undefined)
997
979
  throw new ApiError("catalog.not_deployed", problem);
998
- if (mapped.connector.connector !== ct.file.template.connector) {
999
- 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`, [
1000
- {
1001
- reason: "template_connector",
1002
- template: ct.id,
1003
- plugin: ct.file.template.plugin,
1004
- connector: ct.file.template.connector,
1005
- },
1006
- ]);
1007
- }
1008
- const credentialsChanged = credentialKey(mapped.connector.auth) !==
1009
- credentialKey(ct.file.template.auth);
1010
- templates.push({
1011
- id: ct.id,
1012
- change: "changed",
1013
- target: ct.file,
1014
- ...mapped,
1015
- credentialsChanged,
1016
- });
980
+ components.push(added("connector_template", ct.id));
1017
981
  continue;
1018
982
  }
1019
- if (!before) {
1020
- if (problem !== undefined)
1021
- throw new ApiError("catalog.not_deployed", problem);
1022
- templates.push({ id: ct.id, change: "added", target: ct.file, credentialsChanged: false });
983
+ const same = canonicalJson(l.file) === canonicalJson(ct.file);
984
+ components.push({
985
+ kind: "connector_template",
986
+ id: l.id,
987
+ name: ct.id,
988
+ change: same ? "same" : direction(l.version),
989
+ from: l.version,
990
+ to: to.version,
991
+ updatedOnOwn: false,
992
+ ownScope: l.ownScope,
993
+ pinnedOrgs: [],
994
+ });
995
+ if (same)
1023
996
  continue;
997
+ if (shippedOff(l.file) !== shippedOff(ct.file)) {
998
+ flipped.set(ct.id, shippedOff(ct.file));
999
+ flippedIds.set(ct.id, l.id);
1024
1000
  }
1025
- const change = canonicalJson(before.file) === canonicalJson(ct.file) ? "unchanged" : "changed";
1026
- if (change === "changed") {
1027
- if (before.file.template.plugin !== ct.file.template.plugin ||
1028
- before.file.template.connector !== ct.file.template.connector) {
1029
- 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`, [
1030
- {
1031
- reason: "template_connector",
1032
- template: ct.id,
1033
- plugin: ct.file.template.plugin,
1034
- connector: ct.file.template.connector,
1035
- },
1036
- ]);
1037
- }
1038
- if (problem !== undefined && mapped.connector) {
1001
+ const before = l.file.template;
1002
+ const after = ct.file.template;
1003
+ if (before.plugin !== after.plugin || before.connector !== after.connector) {
1004
+ 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`, [
1005
+ {
1006
+ reason: "template_connector",
1007
+ template: ct.id,
1008
+ plugin: after.plugin,
1009
+ connector: after.connector,
1010
+ },
1011
+ ]);
1012
+ }
1013
+ const made = await db
1014
+ .selectFrom("connectors")
1015
+ .select(["id", "org_id", "name", "connector", "endpoint", "auth"])
1016
+ .where("platform_template_id", "=", l.id)
1017
+ .where("deleted_at", "is", null)
1018
+ .orderBy("org_id")
1019
+ .orderBy("id")
1020
+ .execute();
1021
+ if (made.length > 0) {
1022
+ const problem = templatePluginProblem(deps, after);
1023
+ if (problem !== undefined)
1039
1024
  throw new ApiError("catalog.not_deployed", problem);
1040
- }
1041
1025
  }
1042
- const credentialsChanged = change === "changed" &&
1043
- mapped.connector !== undefined &&
1044
- credentialKey(mapped.connector.auth) !==
1045
- credentialKey(ct.file.template.auth);
1046
- templates.push({ id: ct.id, change, target: ct.file, ...mapped, credentialsChanged });
1026
+ for (const c of made) {
1027
+ connectors.push({
1028
+ orgId: c.org_id,
1029
+ id: c.id,
1030
+ name: c.name,
1031
+ connector: c.connector,
1032
+ endpoint: c.endpoint,
1033
+ templateId: ct.id,
1034
+ file: ct.file,
1035
+ credentialsReset: credentialKey(c.auth) !==
1036
+ credentialKey(after.auth),
1037
+ });
1038
+ }
1047
1039
  }
1048
- for (const ct of fromTemplates) {
1049
- if (toTemplates.some((x) => x.id === ct.id))
1040
+ for (const l of live.templates) {
1041
+ if (toTemplates.some((x) => x.id === l.name))
1050
1042
  continue;
1051
- templates.push({
1052
- id: ct.id,
1043
+ components.push({
1044
+ kind: "connector_template",
1045
+ id: l.id,
1046
+ name: l.name,
1053
1047
  change: "removed",
1054
- ...connectorOf(ct.id),
1055
- credentialsChanged: false,
1048
+ from: l.version,
1049
+ to: null,
1050
+ updatedOnOwn: false,
1051
+ ownScope: l.ownScope,
1052
+ pinnedOrgs: [],
1056
1053
  });
1057
1054
  }
1058
- for (const c of templates) {
1055
+ // Themes (by id, canonical definition and their assets' digest)
1056
+ const toThemes = contents.themes;
1057
+ for (const th of toThemes) {
1058
+ const l = live.themes.find((x) => x.name === th.id);
1059
+ if (!l) {
1060
+ components.push(added("theme", th.id));
1061
+ continue;
1062
+ }
1063
+ const same = canonicalJson(l.definition) === canonicalJson(th.theme) &&
1064
+ l.assetsDigest === th.assetsDigest;
1059
1065
  components.push({
1060
- kind: "connector",
1061
- ref: c.id,
1062
- change: c.change,
1063
- ...(c.credentialsChanged && { detail: "credentials change" }),
1064
- ...(c.change !== "added" &&
1065
- c.change !== "removed" &&
1066
- !c.connector && { detail: "no connector in this organization" }),
1066
+ kind: "theme",
1067
+ id: l.id,
1068
+ name: th.id,
1069
+ change: same ? "same" : direction(l.catalogVersion),
1070
+ from: l.catalogVersion,
1071
+ to: to.version,
1072
+ updatedOnOwn: false,
1073
+ ownScope: l.ownScope,
1074
+ pinnedOrgs: [],
1067
1075
  });
1068
1076
  }
1069
- const inputs = {
1070
- connectors: templates.filter((c) => c.change === "added").map((c) => c.id),
1071
- credentialsChanged: templates.filter((c) => c.credentialsChanged).map((c) => c.id),
1072
- extensionConfig,
1073
- };
1074
- // The inputs (as at install), when given
1075
- const creates = new Map();
1076
- const updates = new Map();
1077
- if (input !== null) {
1078
- for (const k of Object.keys(input.connectors ?? {})) {
1079
- if (!inputs.connectors.includes(k) && !inputs.credentialsChanged.includes(k)) {
1080
- throw fail(`connectors.${k}`, "This upgrade takes no input for this connector template (only added templates and changed credentials)");
1077
+ for (const l of live.themes) {
1078
+ if (toThemes.some((x) => x.id === l.name))
1079
+ continue;
1080
+ components.push({
1081
+ kind: "theme",
1082
+ id: l.id,
1083
+ name: l.name,
1084
+ change: "removed",
1085
+ from: l.catalogVersion,
1086
+ to: null,
1087
+ updatedOnOwn: false,
1088
+ ownScope: l.ownScope,
1089
+ pinnedOrgs: [],
1090
+ });
1091
+ }
1092
+ // The orgs where the plugin is on (a live install; builtin: every org)
1093
+ const onOrgs = await this.pluginOrgs(itemId, item.builtin);
1094
+ if (extension)
1095
+ extension = { ...extension, orgs: onOrgs };
1096
+ // Rule 10: an added skill must not take a name already used where the plugin is on
1097
+ const conflicts = [];
1098
+ for (const c of components) {
1099
+ if (c.kind !== "skill" || c.change !== "added")
1100
+ continue;
1101
+ for (const orgId of onOrgs) {
1102
+ const ids = [
1103
+ ...(await clashingOrgSkills(db, orgId, { id: "", itemId }, c.name)),
1104
+ ...(await clashingPlatformSkills(db, orgId, { id: "" }, c.name)).map((x) => x.id),
1105
+ ];
1106
+ if (ids.length > 0)
1107
+ conflicts.push({ skill: c.name, orgId, conflicts: ids.sort() });
1108
+ }
1109
+ }
1110
+ if (conflicts.length > 0) {
1111
+ 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);
1112
+ }
1113
+ // Themes spec §7: an update never removes the platform default theme; rule 10 (§6): an added
1114
+ // theme must not take an id already on where the plugin is on
1115
+ const removedThemes = components
1116
+ .filter((c) => c.kind === "theme" && c.change === "removed" && c.id !== null)
1117
+ .map((c) => c.id);
1118
+ await assertNotPlatformDefault(db, removedThemes, () => "gone");
1119
+ const themeConflicts = [];
1120
+ for (const c of components) {
1121
+ if (c.kind !== "theme" || c.change !== "added")
1122
+ continue;
1123
+ for (const orgId of onOrgs) {
1124
+ const clash = await themeIdClashes(db, orgId, null, c.name);
1125
+ if (clash.length > 0) {
1126
+ themeConflicts.push({
1127
+ theme: c.name,
1128
+ orgId,
1129
+ themes: clash.map((x) => x.id),
1130
+ plugins: clash.map((x) => x.plugin ?? "platform"),
1131
+ });
1081
1132
  }
1082
1133
  }
1083
- if (input.extensionConfig !== undefined && !inputs.extensionConfig) {
1084
- throw fail("extensionConfig", "This upgrade does not enable the plugin's extension");
1134
+ }
1135
+ if (themeConflicts.length > 0) {
1136
+ 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);
1137
+ }
1138
+ const themes = await this.themesLost(removedThemes);
1139
+ // Pinned copies (in orgs where the component is on) and removed components agents use
1140
+ for (const kind of ["skill", "agent_template"]) {
1141
+ const mine = components.filter((c) => c.kind === kind && c.id !== null);
1142
+ if (mine.length === 0)
1143
+ continue;
1144
+ const pins = kind === "skill"
1145
+ ? await db
1146
+ .selectFrom("skills")
1147
+ .select(["org_id", "platform_skill_id as platform_id"])
1148
+ .where("platform_skill_id", "in", mine.map((c) => c.id))
1149
+ .where("pinned_version", "is not", null)
1150
+ .where("deleted_at", "is", null)
1151
+ .execute()
1152
+ : await db
1153
+ .selectFrom("agent_templates")
1154
+ .select(["org_id", "platform_template_id as platform_id"])
1155
+ .where("platform_template_id", "in", mine.map((c) => c.id))
1156
+ .where("pinned_version", "is not", null)
1157
+ .where("deleted_at", "is", null)
1158
+ .execute();
1159
+ const facts = mine.map((c) => {
1160
+ const l = (kind === "skill" ? live.skills : live.agentTemplates).find((x) => x.id === c.id);
1161
+ return {
1162
+ id: c.id,
1163
+ itemId,
1164
+ scopeMode: l?.scopeMode ?? "follow",
1165
+ scope: l?.scope ?? "optional",
1166
+ disabled: l?.disabled ?? false,
1167
+ };
1168
+ });
1169
+ const st = await loadScopeState(db, kind, facts);
1170
+ for (const c of mine) {
1171
+ const f = facts.find((x) => x.id === c.id);
1172
+ if (!f)
1173
+ continue;
1174
+ const orgsPinned = [
1175
+ ...new Set(pins.filter((p) => p.platform_id === c.id).map((p) => p.org_id)),
1176
+ ];
1177
+ c.pinnedOrgs = orgsPinned
1178
+ .filter((orgId) => componentOn(f, pluginFactsOf(st, itemId, orgId), listedIn(st, f.id, orgId), switchOf(st, f.id, orgId)))
1179
+ .sort();
1180
+ if (c.change !== "removed")
1181
+ continue;
1182
+ const kept = [];
1183
+ for (const orgId of await this.liveOrgs()) {
1184
+ const agents = await agentsUsing(db, orgId, kind, [c.id]);
1185
+ if (agents.length > 0) {
1186
+ kept.push({ orgId, agents: agents.map((a) => ({ id: a.id, name: a.name })) });
1187
+ }
1188
+ }
1189
+ if (kept.length > 0)
1190
+ c.kept = kept;
1085
1191
  }
1086
- for (const c of templates) {
1087
- if (c.change === "added") {
1088
- creates.set(c.id, this.installer.planConnector(actor, { itemId, version: to.version, name }, { id: c.id, file: c.target }, input, "", undefined));
1192
+ }
1193
+ // The org connectors: changed templates' connectors, templates turned on (their connectors
1194
+ // created) or off
1195
+ const addedTemplates = components
1196
+ .filter((c) => c.kind === "connector_template" && c.change === "added")
1197
+ .map((c) => c.name)
1198
+ // an added template shipped off is on nowhere (no org can have switched it on yet)
1199
+ .filter((id) => {
1200
+ const f = toTemplates.find((x) => x.id === id)?.file;
1201
+ return item.builtin || f === undefined || !shippedOff(f);
1202
+ });
1203
+ const byOrg = new Map();
1204
+ const entry = (orgId) => {
1205
+ const e = byOrg.get(orgId) ?? { orgId, connectors: [], created: [], deferred: [] };
1206
+ byOrg.set(orgId, e);
1207
+ return e;
1208
+ };
1209
+ for (const c of connectors) {
1210
+ entry(c.orgId).connectors.push({
1211
+ id: c.id,
1212
+ name: c.name,
1213
+ templateId: c.templateId,
1214
+ credentialsReset: c.credentialsReset,
1215
+ });
1216
+ }
1217
+ const creates = [];
1218
+ /** The orgs with a deferred connector: the update owes their template connector ensure. */
1219
+ const deferred = new Set();
1220
+ if (addedTemplates.length > 0 || flipped.size > 0) {
1221
+ // a named plugin still on in an org it no longer lists gets nothing new there (the scope
1222
+ // sync removes it)
1223
+ const listedOrgs = item.scope === "named" && !item.builtin
1224
+ ? new Set((await db
1225
+ .selectFrom("catalog_item_scope_orgs")
1226
+ .select("org_id")
1227
+ .where("item_id", "=", itemId)
1228
+ .execute()).map((r) => r.org_id))
1229
+ : undefined;
1230
+ const ids = [...flipped.keys()].sort();
1231
+ for (const orgId of onOrgs) {
1232
+ if (listedOrgs !== undefined && !listedOrgs.has(orgId))
1089
1233
  continue;
1234
+ // a template the org already has a live connector from (one a switch-off kept) needs none
1235
+ const has = await this.installer.connectedTemplates(orgId, itemId);
1236
+ const turnedOn = [...(await connectorTemplatesOn(db, orgId, itemId, addedTemplates))];
1237
+ if (ids.length > 0) {
1238
+ const before = await connectorTemplatesOn(db, orgId, itemId, ids);
1239
+ const after = await connectorTemplatesOn(db, orgId, itemId, ids, flipped);
1240
+ for (const id of ids) {
1241
+ const platformId = flippedIds.get(id);
1242
+ if (after.has(id) && !before.has(id)) {
1243
+ turnedOn.push(id);
1244
+ }
1245
+ else if (before.has(id) && !after.has(id)) {
1246
+ const agents = await agentsUsing(db, orgId, "connector_template", [platformId]);
1247
+ const e = entry(orgId);
1248
+ e.turnedOff = [
1249
+ ...(e.turnedOff ?? []),
1250
+ {
1251
+ templateId: id,
1252
+ agents: agents.map((a) => ({ id: a.id, name: a.name })),
1253
+ connectorsKept: await connectorsMadeFrom(db, orgId, platformId),
1254
+ },
1255
+ ];
1256
+ }
1257
+ }
1090
1258
  }
1091
- if (c.change !== "changed" || !c.connector || !c.target)
1259
+ // A builtin plugin gets no connectors from an update until a design covers builtin
1260
+ // template connectors (ruling R28): it is on everywhere without an install
1261
+ if (item.builtin)
1092
1262
  continue;
1093
- updates.set(c.id, this.templateUpdate(itemId, to.version, c, input));
1263
+ for (const id of turnedOn.sort()) {
1264
+ if (has.has(id))
1265
+ continue;
1266
+ const file = toTemplates.find((x) => x.id === id)?.file;
1267
+ if (file === undefined)
1268
+ continue;
1269
+ const t = file.template;
1270
+ // Decided here, not only at the confirm (ruling R27), with the checks the confirm runs:
1271
+ // the template's connector extension loaded on this replica (planning; the bootstrap's
1272
+ // first pass runs before the extensions load) and its kind available in the org (the
1273
+ // create's own check, `ConnectorsService.kindAvailable`). Otherwise it waits; the update
1274
+ // owes the org's template connector ensure, which creates it once both hold
1275
+ if (!deps.findConnector(t.plugin, t.connector) ||
1276
+ !(await this.connectors.kindAvailable(orgId, t.connector))) {
1277
+ deferred.add(orgId);
1278
+ entry(orgId).deferred.push({
1279
+ templateId: id,
1280
+ displayName: file.displayName,
1281
+ kind: t.connector,
1282
+ });
1283
+ continue;
1284
+ }
1285
+ creates.push({ orgId, templateId: id, file });
1286
+ entry(orgId).created.push({
1287
+ templateId: id,
1288
+ displayName: file.displayName,
1289
+ setup: setupNeed(t.auth) === undefined
1290
+ ? "ready"
1291
+ : "needs_config",
1292
+ });
1293
+ }
1294
+ }
1295
+ // the connectors as the confirm plans them, checked now: a refusal shows in the preview as
1296
+ // a readable target refusal
1297
+ for (const id of new Set(creates.map((c) => c.templateId))) {
1298
+ const file = creates.find((c) => c.templateId === id)?.file;
1299
+ try {
1300
+ this.installer.planConnector(null, { itemId, version: to.version }, { id, file }, "", undefined);
1301
+ }
1302
+ catch (e) {
1303
+ if (!(e instanceof ApiError))
1304
+ throw e;
1305
+ throw targetInvalid(`Connector template ${id} of version ${to.version} cannot become a connector (${e.message}); fix the template and import a new version`, [
1306
+ {
1307
+ reason: "template_connector_invalid",
1308
+ template: id,
1309
+ code: e.code,
1310
+ ...(e.details !== undefined && { causeDetails: e.details }),
1311
+ },
1312
+ ]);
1313
+ }
1094
1314
  }
1095
1315
  }
1096
- const actions = new Set([
1097
- ...requiredActions(from.manifest),
1098
- ...requiredActions(to.manifest),
1099
- ]);
1100
- for (const dep of dependencies)
1101
- if (dep.plan)
1102
- for (const a of planActions(dep.plan))
1103
- actions.add(a);
1104
- const removedDeps = dependencies.filter((x) => x.change === "removed" && x.child);
1105
- if (removedDeps.length > 0) {
1106
- const manifests = await db
1107
- .selectFrom("plugin_installs as a")
1108
- .innerJoin("catalog_item_versions as v", (j) => j.onRef("v.item_id", "=", "a.item_id").onRef("v.version", "=", "a.version"))
1109
- .select("v.manifest")
1110
- .where("a.id", "in", removedDeps.map((x) => x.child?.installId))
1111
- .execute();
1112
- for (const m of manifests)
1113
- for (const a of requiredActions(m.manifest))
1114
- actions.add(a);
1115
- }
1116
- const lh = ledgerHash(ledger);
1316
+ const scopeInstalls = await this.scopeInstallsOf(item, onOrgs);
1317
+ const connectorOrgs = [...byOrg.values()]
1318
+ .map((e) => ({
1319
+ ...e,
1320
+ created: e.created.sort((a, b) => a.templateId.localeCompare(b.templateId)),
1321
+ deferred: e.deferred.sort((a, b) => a.templateId.localeCompare(b.templateId)),
1322
+ connectors: e.connectors.sort((a, b) => `${a.templateId}\0${a.id}`.localeCompare(`${b.templateId}\0${b.id}`)),
1323
+ }))
1324
+ .sort((a, b) => a.orgId.localeCompare(b.orgId));
1325
+ components.sort((a, b) => KIND_ORDER[a.kind] - KIND_ORDER[b.kind] || a.name.localeCompare(b.name));
1117
1326
  const diffHash = sha256(canonicalJson({
1118
- installId,
1119
- from: from.version,
1327
+ itemId,
1328
+ from,
1120
1329
  to: to.version,
1121
- fromFiles: filesDigest(from),
1122
- toFiles: filesDigest(to),
1123
- ledger: lh,
1330
+ manifest: to.manifest,
1331
+ files: filesDigest(to),
1332
+ // `needsApproval` is shown only: it does not change what the confirm does
1333
+ extension: extension && {
1334
+ from: extension.from,
1335
+ to: extension.to,
1336
+ orgs: extension.orgs,
1337
+ sha256: extension.sha256,
1338
+ },
1124
1339
  components,
1125
- inputs,
1340
+ connectors: connectors.map((c) => ({
1341
+ id: c.id,
1342
+ endpoint: c.endpoint,
1343
+ reset: c.credentialsReset,
1344
+ })),
1345
+ connectorOrgs,
1346
+ // by org and failing state: an org's name or failure message changes nothing it does
1347
+ scopeInstalls: scopeInstalls.map((o) => ({ orgId: o.orgId, failing: o.failing === true })),
1348
+ // only when present: a diff without themes keeps the hash it had before themes
1349
+ ...(themes !== undefined && { themes }),
1126
1350
  }));
1127
1351
  return {
1128
- installId,
1129
1352
  itemId,
1130
1353
  name,
1131
1354
  from,
1132
1355
  to,
1133
- ledger,
1356
+ components,
1134
1357
  extension,
1135
- skills,
1136
- agentTemplates,
1137
- templates,
1358
+ connectors,
1359
+ creates,
1360
+ deferredOrgs: [...deferred].sort(),
1361
+ connectorOrgs,
1362
+ scopeInstalls,
1363
+ ...(themes !== undefined && { themes }),
1364
+ contents,
1138
1365
  dependencies,
1139
- components,
1140
- inputs,
1141
1366
  diffHash,
1142
- ledgerHash: lh,
1143
- actions: [...actions],
1144
- creates,
1145
- updates,
1146
1367
  };
1147
1368
  }
1148
1369
  /**
1149
- * The update of a changed template's connector: the new endpoint preset with the org's values at
1150
- * the editable paths, the new auth preset and policies; credentials only when the auth method or
1151
- * the credentials it needs changed (then the input must give what the template needs).
1370
+ * The target's skill names, agent templates, connector templates and themes, from object storage
1371
+ * (a theme failing its checks -> 400 `theme.invalid`, themes spec §6).
1152
1372
  */
1153
- templateUpdate(itemId, version, c, input) {
1154
- const template = c.target.template;
1155
- const connector = c.connector;
1156
- const path = `connectors.${c.id}`;
1157
- const given = input.connectors?.[c.id];
1158
- if (given !== undefined) {
1159
- for (const k of ["name", "slug", "endpoint"]) {
1160
- if (given[k] !== undefined) {
1161
- throw fail(`${path}.${k}`, "An existing connector keeps its name, slug and endpoint fields");
1162
- }
1373
+ async readContents(to) {
1374
+ return {
1375
+ skillNames: await catalogSkillNames(this.storage, to, to.manifest),
1376
+ agents: await readCatalogAgentTemplates(this.storage, to),
1377
+ templates: await readCatalogTemplates(this.storage, to),
1378
+ themes: await readCatalogThemes(this.storage, to),
1379
+ };
1380
+ }
1381
+ /**
1382
+ * Whether the target's extension package asks for permissions the approved snapshot does not
1383
+ * cover (no snapshot, or a blocking addition): it then loads only once approved (§7.4).
1384
+ */
1385
+ async needsApproval(name, sha) {
1386
+ if (this.config.get().extensionPermissions.autoApprove)
1387
+ return false;
1388
+ const pkg = await readExtensionPackage(await this.blobs.get(sha), {
1389
+ maxBytes: this.config.get().packages.maxBytes,
1390
+ hostSdkVersion: SDK_VERSION,
1391
+ });
1392
+ const snap = await this.db
1393
+ .selectFrom("extension_permission_snapshots")
1394
+ .select("permissions")
1395
+ .where("plugin", "=", name)
1396
+ .executeTakeFirst();
1397
+ if (!snap)
1398
+ return true;
1399
+ const { added } = diffPermissions(snap.permissions, permissionSetOfPackage(pkg));
1400
+ return blockingKeys(added).length > 0;
1401
+ }
1402
+ /**
1403
+ * The deployment's extension step: none when the target carries the extension the deployment
1404
+ * runs; a version without the extension the deployment runs for the plugin is refused, except
1405
+ * for an owner update (`allowRemove`, ruling P3-12': removing code runs none), which removes an
1406
+ * installed one; a move of a config-declared extension is refused.
1407
+ */
1408
+ async extensionTarget(name, from, to, allowRemove = false) {
1409
+ const want = to.manifest.extension;
1410
+ const row = await this.db
1411
+ .selectFrom("extension_installs")
1412
+ .select(["sha256", "version"])
1413
+ .where("name", "=", name)
1414
+ .executeTakeFirst();
1415
+ // Only an extension declared in the startup config runs without an install record; one this
1416
+ // replica still has loaded after its uninstall (until its reconcile) does not count
1417
+ const declared = this.registry.declared().get(name) === "config";
1418
+ const loaded = declared ? this.registry.manifests().find((m) => m.name === name) : undefined;
1419
+ if (!want) {
1420
+ if (allowRemove && from?.manifest.extension && row && !declared) {
1421
+ return { from: row.version, to: null, sha256: null, previous: row.sha256 };
1163
1422
  }
1423
+ if (from?.manifest.extension && (row || declared)) {
1424
+ 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 }]);
1425
+ }
1426
+ return null;
1164
1427
  }
1165
- const endpoint = structuredClone(template.endpoint);
1166
- for (const e of template.editableEndpoint ?? []) {
1167
- const v = getPath(connector.endpoint, e);
1168
- if (v !== undefined)
1169
- setPath(endpoint, e, v);
1428
+ if (row) {
1429
+ if (row.sha256 === to.extension_sha256)
1430
+ return null;
1170
1431
  }
1171
- const auth = template.auth;
1172
- const oauth = auth.type === "oauth_code" || auth.type === "oauth_client";
1173
- if (c.credentialsChanged) {
1174
- const missing = missingTemplateInput(template, given, { personalCredential: false });
1175
- if (missing !== undefined) {
1176
- throw fail(`${path}.${missing}`, `The auth method of this connector template changed; it needs ${missing === "client" ? "an OAuth client" : "an org credential"}`);
1177
- }
1178
- if (oauth && given?.credential !== undefined) {
1179
- throw fail(`${path}.credential`, "This connector uses OAuth; provide client instead");
1180
- }
1181
- if (!oauth && given?.client !== undefined) {
1182
- throw fail(`${path}.client`, "This connector does not use OAuth; provide credential instead");
1183
- }
1432
+ else if (declared) {
1433
+ if (loaded?.version === want.manifest.version)
1434
+ return null;
1435
+ 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 }]);
1436
+ }
1437
+ if (to.extension_sha256 === null) {
1438
+ throw targetInvalid(`Version ${to.version} of plugin ${name} has no extension package`, [
1439
+ { reason: "extension_package", version: to.version },
1440
+ ]);
1184
1441
  }
1185
- const credential = oauth ? given?.client : given?.credential;
1186
1442
  return {
1187
- endpoint,
1188
- auth,
1189
- template: {
1190
- itemId,
1191
- version,
1192
- templateId: c.id,
1193
- ...(template.defaultToolPolicies !== undefined && {
1194
- defaultToolPolicies: template.defaultToolPolicies,
1195
- }),
1196
- },
1197
- resetCredentials: c.credentialsChanged,
1198
- ...(c.credentialsChanged && credential !== undefined && { credential }),
1443
+ from: row?.version ?? null,
1444
+ to: want.manifest.version,
1445
+ sha256: to.extension_sha256,
1446
+ previous: row?.sha256 ?? null,
1199
1447
  };
1200
1448
  }
1449
+ /**
1450
+ * Other platform plugins depending on this one must accept the target (their platform version's
1451
+ * dependency range); returns the catalog items of the target's own dependencies (their scope
1452
+ * sync is owed with the update: rule 9).
1453
+ */
1454
+ async checkDependents(name, to) {
1455
+ const rows = await this.db
1456
+ .selectFrom("catalog_items as i")
1457
+ .innerJoin("catalog_item_versions as v", (j) => j
1458
+ .onRef("v.item_id", "=", "i.id")
1459
+ .on(sql `v.version`, "=", sql `coalesce(i.platform_synced_version, i.latest_version)`))
1460
+ .select(["i.id", "i.name", "v.manifest"])
1461
+ .where("i.deleted_at", "is", null)
1462
+ .execute();
1463
+ for (const r of rows) {
1464
+ if (r.name === name)
1465
+ continue;
1466
+ const range = r.manifest.dependencies?.find((d) => d.name === name)?.version;
1467
+ if (range !== undefined && !satisfiesRange(to.version, range)) {
1468
+ 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 }]);
1469
+ }
1470
+ }
1471
+ const wanted = new Set((to.manifest.dependencies ?? []).map((d) => d.name));
1472
+ return rows.filter((r) => wanted.has(r.name)).map((r) => r.id);
1473
+ }
1474
+ /** The plugin's live platform components with their current versions. */
1475
+ async liveComponents(itemId) {
1476
+ const db = this.db;
1477
+ const skills = (await db
1478
+ .selectFrom("platform_skills as p")
1479
+ .innerJoin("platform_skill_versions as v", (j) => j.onRef("v.skill_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
1480
+ .select([
1481
+ "p.id",
1482
+ "p.name",
1483
+ "p.scope_mode",
1484
+ "p.scope",
1485
+ "p.disabled",
1486
+ "v.manifest",
1487
+ "v.catalog_version",
1488
+ "v.updated_on_own",
1489
+ ])
1490
+ .where("p.catalog_item_id", "=", itemId)
1491
+ .where("p.deleted_at", "is", null)
1492
+ .execute()).map((r) => ({
1493
+ id: r.id,
1494
+ name: r.name,
1495
+ scopeMode: r.scope_mode,
1496
+ scope: r.scope,
1497
+ disabled: r.disabled,
1498
+ manifest: r.manifest,
1499
+ catalogVersion: r.catalog_version,
1500
+ updatedOnOwn: r.updated_on_own,
1501
+ ownScope: r.scope_mode === "own",
1502
+ }));
1503
+ const agentTemplates = (await db
1504
+ .selectFrom("platform_agent_templates as p")
1505
+ .innerJoin("platform_agent_template_versions as v", (j) => j.onRef("v.template_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
1506
+ .select([
1507
+ "p.id",
1508
+ "p.name",
1509
+ "p.scope_mode",
1510
+ "p.scope",
1511
+ "p.disabled",
1512
+ "v.definition",
1513
+ "v.catalog_version",
1514
+ "v.updated_on_own",
1515
+ ])
1516
+ .where("p.catalog_item_id", "=", itemId)
1517
+ .where("p.deleted_at", "is", null)
1518
+ .execute()).map((r) => ({
1519
+ id: r.id,
1520
+ name: r.name,
1521
+ scopeMode: r.scope_mode,
1522
+ scope: r.scope,
1523
+ disabled: r.disabled,
1524
+ definition: r.definition,
1525
+ catalogVersion: r.catalog_version,
1526
+ updatedOnOwn: r.updated_on_own,
1527
+ ownScope: r.scope_mode === "own",
1528
+ }));
1529
+ const templates = (await db
1530
+ .selectFrom("platform_connector_templates")
1531
+ .select(["id", "template_id", "current_version", "file", "scope_mode"])
1532
+ .where("catalog_item_id", "=", itemId)
1533
+ .where("deleted_at", "is", null)
1534
+ .execute()).map((r) => ({
1535
+ id: r.id,
1536
+ name: r.template_id,
1537
+ version: r.current_version,
1538
+ file: r.file,
1539
+ ownScope: r.scope_mode === "own",
1540
+ }));
1541
+ const themes = (await db
1542
+ .selectFrom("platform_themes as p")
1543
+ .innerJoin("platform_theme_versions as v", (j) => j.onRef("v.theme_id", "=", "p.id").onRef("v.version", "=", "p.current_version"))
1544
+ .leftJoin("catalog_item_versions as cv", (j) => j
1545
+ .onRef("cv.item_id", "=", "p.catalog_item_id")
1546
+ .onRef("cv.version", "=", "v.catalog_version"))
1547
+ .select(["p.id", "p.name", "p.scope_mode", "v.definition", "v.catalog_version", "cv.files"])
1548
+ .where("p.catalog_item_id", "=", itemId)
1549
+ .where("p.deleted_at", "is", null)
1550
+ .execute()).map((r) => ({
1551
+ id: r.id,
1552
+ name: r.name,
1553
+ definition: r.definition,
1554
+ catalogVersion: r.catalog_version,
1555
+ // no recorded files (should not happen): never equal, the update writes a new version
1556
+ assetsDigest: r.files === null ? null : themeAssetsDigest(r.files, r.definition),
1557
+ ownScope: r.scope_mode === "own",
1558
+ }));
1559
+ return { skills, agentTemplates, templates, themes };
1560
+ }
1561
+ /** The `themes` block of the preview: the orgs each of the removed themes `ids` is on in. */
1562
+ async themesLost(ids) {
1563
+ if (ids.length === 0)
1564
+ return undefined;
1565
+ const comps = await loadComponents(this.db, "theme", { ids });
1566
+ const st = await loadScopeState(this.db, "theme", comps);
1567
+ const orgs = await this.liveOrgs();
1568
+ const lost = new Map();
1569
+ for (const c of comps) {
1570
+ const on = orgs.filter((orgId) => componentOn(c, pluginFactsOf(st, c.itemId, orgId), listedIn(st, c.id, orgId), switchOf(st, c.id, orgId)));
1571
+ lost.set(c.id, new Set(on));
1572
+ }
1573
+ return themesPreview(this.db, lost);
1574
+ }
1575
+ /**
1576
+ * {@link PlatformUpdatePreview.scopeInstalls}: the live orgs without a live install (`onOrgs`
1577
+ * are those with one) whose scope wants the plugin on, as the scope sync decides it
1578
+ * (`wantedOn`). None for a builtin plugin (on everywhere without an install) or one not usable.
1579
+ */
1580
+ async scopeInstallsOf(item, onOrgs) {
1581
+ if (item.builtin || !isUsable(item))
1582
+ return [];
1583
+ const [orgs, listed, switches, failures] = await Promise.all([
1584
+ this.db
1585
+ .selectFrom("orgs")
1586
+ .select(["id", "name"])
1587
+ .where("deleted_at", "is", null)
1588
+ .orderBy("id")
1589
+ .execute(),
1590
+ this.db
1591
+ .selectFrom("catalog_item_scope_orgs")
1592
+ .select("org_id")
1593
+ .where("item_id", "=", item.id)
1594
+ .execute(),
1595
+ this.db
1596
+ .selectFrom("catalog_item_org_switches")
1597
+ .select(["org_id", "enabled"])
1598
+ .where("item_id", "=", item.id)
1599
+ .execute(),
1600
+ this.db
1601
+ .selectFrom("plugin_scope_sync_failures")
1602
+ .select(["org_id", "message"])
1603
+ .where("item_id", "=", item.id)
1604
+ .execute(),
1605
+ ]);
1606
+ const failed = new Map(failures.map((r) => [r.org_id, r.message]));
1607
+ const on = new Set(onOrgs);
1608
+ const inList = new Set(listed.map((r) => r.org_id));
1609
+ const sw = new Map(switches.map((r) => [r.org_id, r.enabled]));
1610
+ return orgs
1611
+ .filter((o) => !on.has(o.id) && wantedOn(item, inList.has(o.id), sw.get(o.id) ?? null))
1612
+ .map((o) => {
1613
+ const lastFailure = failed.get(o.id);
1614
+ return {
1615
+ orgId: o.id,
1616
+ orgName: o.name,
1617
+ ...(lastFailure !== undefined && { failing: true, lastFailure }),
1618
+ };
1619
+ });
1620
+ }
1621
+ /** The orgs where the plugin is on: a live install (builtin: every live org). */
1622
+ async pluginOrgs(itemId, builtin) {
1623
+ if (builtin)
1624
+ return this.liveOrgs();
1625
+ const rows = await this.db
1626
+ .selectFrom("plugin_installs as a")
1627
+ .innerJoin("orgs as o", "o.id", "a.org_id")
1628
+ .select("a.org_id")
1629
+ .distinct()
1630
+ .where("a.item_id", "=", itemId)
1631
+ .where("a.status", "in", [...LIVE_INSTALL_STATUSES])
1632
+ .where("o.deleted_at", "is", null)
1633
+ .orderBy("a.org_id")
1634
+ .execute();
1635
+ return rows.map((r) => r.org_id);
1636
+ }
1637
+ async liveOrgs() {
1638
+ const rows = await this.db
1639
+ .selectFrom("orgs")
1640
+ .select("id")
1641
+ .where("deleted_at", "is", null)
1642
+ .orderBy("id")
1643
+ .execute();
1644
+ return rows.map((r) => r.id);
1645
+ }
1646
+ };
1647
+ __decorate([
1648
+ Transactional()
1649
+ ], PlatformPluginUpdater.prototype, "authorizeOwner", null);
1650
+ __decorate([
1651
+ Transactional({ propagation: "requires_new" })
1652
+ ], PlatformPluginUpdater.prototype, "auditFailure", null);
1653
+ __decorate([
1654
+ Transactional({ propagation: "requires_new" })
1655
+ ], PlatformPluginUpdater.prototype, "commit", null);
1656
+ PlatformPluginUpdater = __decorate([
1657
+ Injectable()
1658
+ // org-filter: the platform plugin update (one version per deployment) moves the item's installs,
1659
+ // connectors and pinned copies in every org by design, keyed by the platform item / template ids
1660
+ ,
1661
+ __param(0, Inject(KernelDb)),
1662
+ __param(1, Inject(TransactionHost)),
1663
+ __param(2, Inject(SuperAdminLock)),
1664
+ __param(3, Inject(CatalogItemLock)),
1665
+ __param(4, Inject(OrgLock)),
1666
+ __param(5, Inject(LockService)),
1667
+ __param(6, Inject(StorageService)),
1668
+ __param(7, Inject(ExtensionRegistry)),
1669
+ __param(8, Inject(ExtensionAdminOps)),
1670
+ __param(9, Inject(ExtensionBlobs)),
1671
+ __param(10, Inject(KernelConfigService)),
1672
+ __param(11, Inject(PlatformComponents)),
1673
+ __param(12, Inject(PluginInstaller)),
1674
+ __param(13, Inject(ConnectorsService)),
1675
+ __param(14, Inject(PluginScopeSync)),
1676
+ __param(15, Inject(KERNEL_LOGGER)),
1677
+ __param(16, Inject(PluginGuides)),
1678
+ __param(17, Inject(OutboxService))
1679
+ ], PlatformPluginUpdater);
1680
+ export { PlatformPluginUpdater };
1681
+ /** The preview of a diff (without `guideChanges`, which reads PG). */
1682
+ function previewOf(d) {
1683
+ return {
1684
+ itemId: d.itemId,
1685
+ name: d.name,
1686
+ from: d.from,
1687
+ to: d.to.version,
1688
+ components: d.components,
1689
+ extension: extensionView(d.extension),
1690
+ connectorOrgs: d.connectorOrgs,
1691
+ scopeInstalls: d.scopeInstalls,
1692
+ ...(d.themes !== undefined && { themes: d.themes }),
1693
+ diffHash: d.diffHash,
1694
+ };
1201
1695
  }
1202
- const cleanedUp = () => new ApiError("plugin.install_not_found", "The upgrade was cleaned up as interrupted while it was running");
1203
- /** The install's ledger rows. */
1204
- function ledgerOf(db, installId) {
1205
- return db
1206
- .selectFrom("plugin_install_components")
1207
- .select(["kind", "ref", "created", "skill_version", "template_id", "dropped"])
1208
- .where("install_id", "=", installId)
1209
- .orderBy("kind")
1210
- .orderBy("ref")
1211
- .execute();
1212
- }
1213
- /** A fingerprint of the ledger (order independent). */
1214
- function ledgerHash(rows) {
1215
- return sha256(rows
1216
- .map((r) => `${r.kind}\0${r.ref}\0${r.created}\0${r.skill_version}\0${r.template_id}\0${r.dropped}\n`)
1217
- .sort()
1218
- .join(""));
1696
+ /** The extension step as the preview and the result show it. */
1697
+ function extensionView(e) {
1698
+ return e && { from: e.from, to: e.to, orgs: e.orgs, needsApproval: e.needsApproval };
1219
1699
  }