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

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 (604) hide show
  1. package/bootstrap.json +61 -5
  2. package/dist/admin/admin.controller.d.ts +47 -16
  3. package/dist/admin/admin.controller.js +44 -19
  4. package/dist/admin/extensions.controller.d.ts +24 -3
  5. package/dist/admin/extensions.controller.js +48 -8
  6. package/dist/admin/setup-lock.d.ts +1 -1
  7. package/dist/admin/setup-lock.js +1 -1
  8. package/dist/admin/setup.controller.d.ts +1 -1
  9. package/dist/admin/setup.controller.js +1 -1
  10. package/dist/admin/setup.service.d.ts +4 -4
  11. package/dist/admin/setup.service.js +8 -8
  12. package/dist/agents/agent-lookup.d.ts +19 -0
  13. package/dist/agents/agent-lookup.js +21 -0
  14. package/dist/agents/agent-profile.service.d.ts +29 -0
  15. package/dist/agents/agent-profile.service.js +117 -0
  16. package/dist/agents/agents.controller.d.ts +168 -3
  17. package/dist/agents/agents.controller.js +201 -12
  18. package/dist/agents/agents.module.d.ts +4 -1
  19. package/dist/agents/agents.module.js +36 -6
  20. package/dist/agents/agents.service.d.ts +64 -27
  21. package/dist/agents/agents.service.js +199 -74
  22. package/dist/agents/definition.d.ts +53 -0
  23. package/dist/agents/definition.js +55 -0
  24. package/dist/agents/from-template.d.ts +106 -0
  25. package/dist/agents/from-template.js +649 -0
  26. package/dist/agents/from-template.service.d.ts +60 -0
  27. package/dist/agents/from-template.service.js +161 -0
  28. package/dist/agents/instruction-files.d.ts +60 -0
  29. package/dist/agents/instruction-files.js +111 -0
  30. package/dist/agents/models.controller.d.ts +9 -3
  31. package/dist/agents/models.controller.js +19 -4
  32. package/dist/agents/org-templates.d.ts +176 -0
  33. package/dist/agents/org-templates.js +827 -0
  34. package/dist/agents/pending-connector-requests.d.ts +77 -0
  35. package/dist/agents/pending-connector-requests.js +215 -0
  36. package/dist/agents/pending-connectors.controller.d.ts +39 -0
  37. package/dist/agents/pending-connectors.controller.js +91 -0
  38. package/dist/agents/pending-connectors.service.d.ts +62 -0
  39. package/dist/agents/pending-connectors.service.js +282 -0
  40. package/dist/agents/profile.d.ts +96 -0
  41. package/dist/agents/profile.js +51 -0
  42. package/dist/agents/readiness.controller.d.ts +26 -0
  43. package/dist/agents/readiness.controller.js +56 -0
  44. package/dist/agents/templates.controller.d.ts +86 -5
  45. package/dist/agents/templates.controller.js +171 -7
  46. package/dist/agents/templates.d.ts +127 -23
  47. package/dist/agents/templates.js +476 -53
  48. package/dist/background/background.controller.d.ts +38 -0
  49. package/dist/background/background.controller.js +87 -0
  50. package/dist/background/background.module.d.ts +10 -0
  51. package/dist/background/background.module.js +39 -0
  52. package/dist/background/finish.d.ts +44 -0
  53. package/dist/background/finish.js +94 -0
  54. package/dist/background/launch-lock.d.ts +15 -0
  55. package/dist/background/launch-lock.js +40 -0
  56. package/dist/background/launch.d.ts +36 -0
  57. package/dist/background/launch.js +70 -0
  58. package/dist/background/poll.job.d.ts +56 -0
  59. package/dist/background/poll.job.js +190 -0
  60. package/dist/background/render.d.ts +23 -0
  61. package/dist/background/render.js +48 -0
  62. package/dist/background/session.d.ts +48 -0
  63. package/dist/background/session.js +79 -0
  64. package/dist/background/status.d.ts +35 -0
  65. package/dist/background/status.js +57 -0
  66. package/dist/background/stop.d.ts +68 -0
  67. package/dist/background/stop.js +243 -0
  68. package/dist/background/store.d.ts +162 -0
  69. package/dist/background/store.js +357 -0
  70. package/dist/background/store.module.d.ts +6 -0
  71. package/dist/background/store.module.js +22 -0
  72. package/dist/background/tasks.service.d.ts +77 -0
  73. package/dist/background/tasks.service.js +211 -0
  74. package/dist/background/wake-rules.d.ts +66 -0
  75. package/dist/background/wake-rules.js +113 -0
  76. package/dist/background/wake.d.ts +30 -0
  77. package/dist/background/wake.js +63 -0
  78. package/dist/catalog/admin-catalog.controller.d.ts +129 -30
  79. package/dist/catalog/admin-catalog.controller.js +213 -42
  80. package/dist/catalog/catalog-content.d.ts +58 -32
  81. package/dist/catalog/catalog-content.js +34 -8
  82. package/dist/catalog/catalog-import.module.d.ts +7 -0
  83. package/dist/catalog/catalog-import.module.js +60 -0
  84. package/dist/catalog/catalog-items.d.ts +111 -7
  85. package/dist/catalog/catalog-items.js +279 -13
  86. package/dist/catalog/catalog-scope.service.d.ts +260 -0
  87. package/dist/catalog/catalog-scope.service.js +1116 -0
  88. package/dist/catalog/catalog.module.d.ts +7 -9
  89. package/dist/catalog/catalog.module.js +41 -31
  90. package/dist/catalog/catalog.service.d.ts +101 -29
  91. package/dist/catalog/catalog.service.js +104 -106
  92. package/dist/catalog/claude/agents.js +2 -0
  93. package/dist/catalog/cli.d.ts +11 -1
  94. package/dist/catalog/cli.js +26 -1
  95. package/dist/catalog/component-promotion.d.ts +96 -0
  96. package/dist/catalog/component-promotion.js +395 -0
  97. package/dist/catalog/component-scope.controller.d.ts +152 -0
  98. package/dist/catalog/component-scope.controller.js +287 -0
  99. package/dist/catalog/component-scope.service.d.ts +303 -0
  100. package/dist/catalog/component-scope.service.js +936 -0
  101. package/dist/catalog/component-state.d.ts +174 -0
  102. package/dist/catalog/component-state.js +437 -0
  103. package/dist/catalog/job-ids.d.ts +30 -0
  104. package/dist/catalog/job-ids.js +25 -0
  105. package/dist/catalog/marketplace-fetch.d.ts +1 -1
  106. package/dist/catalog/marketplaces.controller.d.ts +22 -5
  107. package/dist/catalog/marketplaces.controller.js +56 -7
  108. package/dist/catalog/marketplaces.service.d.ts +54 -14
  109. package/dist/catalog/marketplaces.service.js +71 -22
  110. package/dist/catalog/org-catalog.controller.d.ts +125 -34
  111. package/dist/catalog/org-catalog.controller.js +181 -65
  112. package/dist/catalog/org-catalog.service.d.ts +65 -33
  113. package/dist/catalog/org-catalog.service.js +324 -157
  114. package/dist/catalog/org-extension-switch.d.ts +41 -0
  115. package/dist/catalog/org-extension-switch.js +115 -0
  116. package/dist/catalog/org-extension.controller.d.ts +119 -0
  117. package/dist/catalog/org-extension.controller.js +266 -0
  118. package/dist/catalog/org-plugin-uploads.controller.d.ts +98 -0
  119. package/dist/catalog/org-plugin-uploads.controller.js +213 -0
  120. package/dist/catalog/org-plugin-uploads.d.ts +63 -0
  121. package/dist/catalog/org-plugin-uploads.js +116 -0
  122. package/dist/catalog/owned-items.d.ts +184 -0
  123. package/dist/catalog/owned-items.js +789 -0
  124. package/dist/catalog/owned-plugin-cleanup.d.ts +56 -0
  125. package/dist/catalog/owned-plugin-cleanup.js +194 -0
  126. package/dist/catalog/ownership.d.ts +172 -0
  127. package/dist/catalog/ownership.js +326 -0
  128. package/dist/catalog/platform-components.d.ts +221 -0
  129. package/dist/catalog/platform-components.js +761 -0
  130. package/dist/catalog/platform-migration.d.ts +115 -0
  131. package/dist/catalog/platform-migration.js +582 -0
  132. package/dist/catalog/plugin-import.d.ts +178 -34
  133. package/dist/catalog/plugin-import.js +623 -83
  134. package/dist/catalog/plugin-install.d.ts +185 -41
  135. package/dist/catalog/plugin-install.js +758 -126
  136. package/dist/catalog/plugin-upgrade.d.ts +260 -225
  137. package/dist/catalog/plugin-upgrade.js +1148 -1137
  138. package/dist/catalog/request-rules.d.ts +65 -0
  139. package/dist/catalog/request-rules.js +217 -0
  140. package/dist/catalog/requests.service.d.ts +193 -118
  141. package/dist/catalog/requests.service.js +526 -343
  142. package/dist/catalog/reserved-names.d.ts +8 -0
  143. package/dist/catalog/reserved-names.js +42 -0
  144. package/dist/catalog/scope-orgs.d.ts +21 -0
  145. package/dist/catalog/scope-orgs.js +67 -0
  146. package/dist/catalog/scope-state.d.ts +35 -0
  147. package/dist/catalog/scope-state.js +87 -0
  148. package/dist/catalog/scope-sync-workers.d.ts +7 -0
  149. package/dist/catalog/scope-sync-workers.js +29 -0
  150. package/dist/catalog/scope-sync.d.ts +176 -0
  151. package/dist/catalog/scope-sync.js +576 -0
  152. package/dist/catalog/scope.d.ts +42 -0
  153. package/dist/catalog/scope.js +42 -0
  154. package/dist/catalog/unshare.d.ts +22 -0
  155. package/dist/catalog/unshare.js +118 -0
  156. package/dist/channels/actions.js +1 -0
  157. package/dist/channels/cards.js +21 -3
  158. package/dist/channels/channels.module.js +2 -0
  159. package/dist/channels/connections.service.d.ts +16 -1
  160. package/dist/channels/connections.service.js +38 -4
  161. package/dist/channels/inbound.d.ts +9 -1
  162. package/dist/channels/inbound.js +67 -5
  163. package/dist/channels/phrases.d.ts +35 -0
  164. package/dist/channels/phrases.js +29 -0
  165. package/dist/channels/threads.d.ts +5 -0
  166. package/dist/channels/threads.js +8 -0
  167. package/dist/config/docs.js +3 -1
  168. package/dist/config/schema.d.ts +24 -2
  169. package/dist/config/schema.js +145 -19
  170. package/dist/conversations/access.d.ts +6 -4
  171. package/dist/conversations/access.js +29 -5
  172. package/dist/conversations/agent-tree.d.ts +46 -0
  173. package/dist/conversations/agent-tree.js +92 -0
  174. package/dist/conversations/attachments.service.d.ts +30 -0
  175. package/dist/conversations/attachments.service.js +130 -5
  176. package/dist/conversations/conversations.controller.d.ts +79 -23
  177. package/dist/conversations/conversations.controller.js +141 -50
  178. package/dist/conversations/conversations.module.d.ts +1 -1
  179. package/dist/conversations/conversations.module.js +10 -7
  180. package/dist/conversations/conversations.service.d.ts +108 -9
  181. package/dist/conversations/conversations.service.js +237 -30
  182. package/dist/conversations/environment-status.d.ts +24 -0
  183. package/dist/conversations/environment-status.js +71 -0
  184. package/dist/conversations/event-log.d.ts +21 -6
  185. package/dist/conversations/event-log.js +70 -1
  186. package/dist/conversations/events.d.ts +140 -0
  187. package/dist/conversations/events.js +142 -13
  188. package/dist/conversations/queue.d.ts +3 -1
  189. package/dist/conversations/queue.js +13 -2
  190. package/dist/conversations/queue.service.d.ts +1 -1
  191. package/dist/conversations/queue.service.js +8 -1
  192. package/dist/conversations/titles.d.ts +12 -3
  193. package/dist/conversations/titles.js +36 -8
  194. package/dist/conversations/tree.d.ts +17 -0
  195. package/dist/conversations/tree.js +42 -0
  196. package/dist/ctx/create-ctx.d.ts +5 -0
  197. package/dist/ctx/create-ctx.js +15 -5
  198. package/dist/db/kernel-schema.d.ts +420 -20
  199. package/dist/db/pool.d.ts +5 -0
  200. package/dist/db/pool.js +3 -0
  201. package/dist/environments/access.d.ts +41 -0
  202. package/dist/environments/access.js +77 -0
  203. package/dist/environments/conversation-environments.d.ts +61 -0
  204. package/dist/environments/conversation-environments.js +170 -0
  205. package/dist/environments/dto.d.ts +25 -0
  206. package/dist/environments/dto.js +12 -0
  207. package/dist/environments/environments.controller.d.ts +33 -0
  208. package/dist/environments/environments.controller.js +110 -0
  209. package/dist/environments/environments.module.d.ts +8 -0
  210. package/dist/environments/environments.module.js +27 -0
  211. package/dist/environments/environments.service.d.ts +153 -0
  212. package/dist/environments/environments.service.js +541 -0
  213. package/dist/environments/legacy-cleanup.job.d.ts +34 -0
  214. package/dist/environments/legacy-cleanup.job.js +141 -0
  215. package/dist/errors.d.ts +90 -2
  216. package/dist/errors.js +90 -2
  217. package/dist/evals/reconstruct.d.ts +18 -9
  218. package/dist/evals/reconstruct.js +26 -7
  219. package/dist/evals/run-replay.d.ts +7 -2
  220. package/dist/evals/run-replay.js +42 -7
  221. package/dist/evals/step-replay.d.ts +2 -5
  222. package/dist/evals/step-replay.js +13 -7
  223. package/dist/evals/trajectory.js +1 -1
  224. package/dist/evals/trajectory.service.d.ts +8 -3
  225. package/dist/evals/trajectory.service.js +26 -14
  226. package/dist/evals/worker.d.ts +5 -5
  227. package/dist/evals/worker.js +9 -3
  228. package/dist/extensions/admin-ops.d.ts +36 -10
  229. package/dist/extensions/admin-ops.js +67 -42
  230. package/dist/extensions/admin-view.d.ts +39 -10
  231. package/dist/extensions/admin-view.js +111 -20
  232. package/dist/extensions/blobs.js +1 -0
  233. package/dist/extensions/bootstrap.d.ts +17 -4
  234. package/dist/extensions/bootstrap.js +70 -9
  235. package/dist/extensions/cli.d.ts +12 -0
  236. package/dist/extensions/cli.js +11 -2
  237. package/dist/extensions/config-issues.d.ts +13 -1
  238. package/dist/extensions/config-issues.js +22 -5
  239. package/dist/extensions/config-json-schema.d.ts +43 -7
  240. package/dist/extensions/config-json-schema.js +124 -58
  241. package/dist/extensions/deployment-config-store.d.ts +6 -0
  242. package/dist/extensions/deployment-config.d.ts +78 -8
  243. package/dist/extensions/deployment-config.js +172 -34
  244. package/dist/extensions/display-name.d.ts +22 -0
  245. package/dist/extensions/display-name.js +77 -0
  246. package/dist/extensions/effective-config.d.ts +127 -0
  247. package/dist/extensions/effective-config.js +368 -0
  248. package/dist/extensions/extensions.module.js +14 -2
  249. package/dist/extensions/hooks.d.ts +37 -4
  250. package/dist/extensions/hooks.js +82 -16
  251. package/dist/extensions/host.d.ts +45 -2
  252. package/dist/extensions/host.js +112 -16
  253. package/dist/extensions/installs.d.ts +20 -8
  254. package/dist/extensions/installs.js +37 -15
  255. package/dist/extensions/org-config.d.ts +81 -6
  256. package/dist/extensions/org-config.js +195 -44
  257. package/dist/extensions/org-levels.d.ts +37 -0
  258. package/dist/extensions/org-levels.js +71 -0
  259. package/dist/extensions/org-overrides.d.ts +151 -0
  260. package/dist/extensions/org-overrides.js +524 -0
  261. package/dist/extensions/package.d.ts +14 -1
  262. package/dist/extensions/package.js +51 -2
  263. package/dist/extensions/permission-view.d.ts +19 -4
  264. package/dist/extensions/permission-view.js +4 -4
  265. package/dist/extensions/plugin-items.d.ts +21 -0
  266. package/dist/extensions/plugin-items.js +42 -0
  267. package/dist/extensions/point-defaults.controller.d.ts +34 -0
  268. package/dist/extensions/point-defaults.controller.js +71 -0
  269. package/dist/extensions/point-defaults.d.ts +71 -0
  270. package/dist/extensions/point-defaults.js +234 -0
  271. package/dist/extensions/registry.d.ts +1 -1
  272. package/dist/extensions/registry.js +2 -0
  273. package/dist/extensions/resolve.d.ts +5 -1
  274. package/dist/extensions/resolve.js +15 -2
  275. package/dist/files/previewers.d.ts +8 -1
  276. package/dist/files/previewers.js +35 -6
  277. package/dist/http/api.module.js +31 -3
  278. package/dist/http/app.d.ts +11 -2
  279. package/dist/http/app.js +31 -5
  280. package/dist/http/nest-logger.d.ts +6 -5
  281. package/dist/http/nest-logger.js +24 -10
  282. package/dist/identity/accounts.d.ts +29 -29
  283. package/dist/identity/accounts.js +47 -47
  284. package/dist/identity/audit.d.ts +2 -1
  285. package/dist/identity/auth.controller.js +9 -5
  286. package/dist/identity/auth.guard.d.ts +13 -5
  287. package/dist/identity/auth.guard.js +26 -9
  288. package/dist/identity/cookies.d.ts +20 -5
  289. package/dist/identity/cookies.js +44 -6
  290. package/dist/identity/identity.module.d.ts +1 -1
  291. package/dist/identity/identity.module.js +4 -4
  292. package/dist/identity/me.controller.d.ts +5 -1
  293. package/dist/identity/me.controller.js +12 -3
  294. package/dist/identity/principal.d.ts +3 -3
  295. package/dist/identity/principal.js +3 -3
  296. package/dist/identity/sessions.d.ts +12 -0
  297. package/dist/identity/sessions.js +45 -0
  298. package/dist/identity/settings.d.ts +22 -11
  299. package/dist/identity/settings.js +53 -18
  300. package/dist/identity/{enterprise-admin.d.ts → super-admin.d.ts} +5 -5
  301. package/dist/identity/{enterprise-admin.js → super-admin.js} +24 -24
  302. package/dist/inbox/inbox.module.d.ts +4 -1
  303. package/dist/inbox/inbox.module.js +7 -3
  304. package/dist/inbox/inbox.service.d.ts +62 -3
  305. package/dist/inbox/inbox.service.js +74 -4
  306. package/dist/inbox/org-notices.d.ts +63 -0
  307. package/dist/inbox/org-notices.js +91 -0
  308. package/dist/inbox/platform-inbox.controller.d.ts +23 -0
  309. package/dist/inbox/platform-inbox.controller.js +58 -0
  310. package/dist/inbox/platform-inbox.service.d.ts +151 -0
  311. package/dist/inbox/platform-inbox.service.js +263 -0
  312. package/dist/inbox/platform-notices.d.ts +19 -0
  313. package/dist/inbox/platform-notices.js +9 -0
  314. package/dist/index.d.ts +2 -2
  315. package/dist/index.js +1 -1
  316. package/dist/infra/cli/kernel-cli.module.js +9 -1
  317. package/dist/infra/config/kernel-config.service.js +27 -1
  318. package/dist/infra/database/database.module.js +1 -0
  319. package/dist/infra/database/xact-lock.d.ts +1 -1
  320. package/dist/infra/database/xact-lock.js +1 -1
  321. package/dist/infra/events/kernel-events.d.ts +19 -2
  322. package/dist/infra/lifecycle/process-guards.js +4 -0
  323. package/dist/infra/logging/logging.module.d.ts +4 -2
  324. package/dist/infra/logging/logging.module.js +24 -6
  325. package/dist/infra/queue/add-job-once.d.ts +14 -0
  326. package/dist/infra/queue/add-job-once.js +16 -0
  327. package/dist/infra/queue/redis-connection.d.ts +6 -0
  328. package/dist/infra/queue/redis-connection.js +7 -0
  329. package/dist/infra/redis/redis.module.js +6 -2
  330. package/dist/infra/tokens.d.ts +6 -1
  331. package/dist/infra/tokens.js +6 -1
  332. package/dist/kernel.module.js +6 -0
  333. package/dist/lifecycle/kernel-lifecycle.d.ts +1 -1
  334. package/dist/lifecycle/kernel-lifecycle.js +4 -4
  335. package/dist/log.d.ts +13 -1
  336. package/dist/log.js +93 -17
  337. package/dist/models/prices.d.ts +5 -5
  338. package/dist/models/prices.js +4 -4
  339. package/dist/models/purposes.controller.d.ts +6 -4
  340. package/dist/models/purposes.controller.js +13 -7
  341. package/dist/models/purposes.d.ts +43 -9
  342. package/dist/models/purposes.js +48 -18
  343. package/dist/orgs/directory-sync.d.ts +14 -5
  344. package/dist/orgs/directory-sync.js +41 -17
  345. package/dist/orgs/offboarding.d.ts +12 -8
  346. package/dist/orgs/offboarding.js +54 -33
  347. package/dist/orgs/org-lock.d.ts +5 -0
  348. package/dist/orgs/org-lock.js +13 -0
  349. package/dist/orgs/org.guard.d.ts +10 -0
  350. package/dist/orgs/org.guard.js +43 -32
  351. package/dist/orgs/orgs.module.js +3 -0
  352. package/dist/orgs/orgs.service.d.ts +20 -7
  353. package/dist/orgs/orgs.service.js +32 -12
  354. package/dist/orgs/roles.d.ts +1 -1
  355. package/dist/orgs/roles.js +5 -1
  356. package/dist/orgs/settings.controller.d.ts +1 -1
  357. package/dist/orgs/settings.service.d.ts +20 -3
  358. package/dist/orgs/settings.service.js +19 -4
  359. package/dist/overrides.d.ts +3 -0
  360. package/dist/overrides.js +2 -0
  361. package/dist/platform/actor.d.ts +48 -0
  362. package/dist/platform/actor.js +100 -0
  363. package/dist/platform/agent-docs.d.ts +18 -0
  364. package/dist/platform/agent-docs.js +59 -0
  365. package/dist/platform/availability.d.ts +14 -0
  366. package/dist/platform/availability.js +43 -0
  367. package/dist/platform/errors.d.ts +11 -0
  368. package/dist/platform/errors.js +26 -0
  369. package/dist/platform/exclusions.d.ts +12 -0
  370. package/dist/platform/exclusions.js +1387 -0
  371. package/dist/platform/method.d.ts +6 -0
  372. package/dist/platform/method.js +15 -0
  373. package/dist/platform/operation.d.ts +92 -0
  374. package/dist/platform/operation.js +35 -0
  375. package/dist/platform/ops/agent-templates.ops.d.ts +14 -0
  376. package/dist/platform/ops/agent-templates.ops.js +92 -0
  377. package/dist/platform/ops/agents.ops.d.ts +19 -0
  378. package/dist/platform/ops/agents.ops.js +294 -0
  379. package/dist/platform/ops/connectors.ops.d.ts +15 -0
  380. package/dist/platform/ops/connectors.ops.js +126 -0
  381. package/dist/platform/ops/errors.d.ts +11 -0
  382. package/dist/platform/ops/errors.js +22 -0
  383. package/dist/platform/ops/extensions.ops.d.ts +19 -0
  384. package/dist/platform/ops/extensions.ops.js +116 -0
  385. package/dist/platform/ops/marketplaces.ops.d.ts +16 -0
  386. package/dist/platform/ops/marketplaces.ops.js +157 -0
  387. package/dist/platform/ops/paging.d.ts +14 -0
  388. package/dist/platform/ops/paging.js +20 -0
  389. package/dist/platform/ops/platform.ops.d.ts +23 -0
  390. package/dist/platform/ops/platform.ops.js +158 -0
  391. package/dist/platform/ops/plugins.ops.d.ts +33 -0
  392. package/dist/platform/ops/plugins.ops.js +377 -0
  393. package/dist/platform/ops/requests.ops.d.ts +14 -0
  394. package/dist/platform/ops/requests.ops.js +153 -0
  395. package/dist/platform/ops/role.d.ts +4 -0
  396. package/dist/platform/ops/role.js +10 -0
  397. package/dist/platform/ops/skills.ops.d.ts +13 -0
  398. package/dist/platform/ops/skills.ops.js +98 -0
  399. package/dist/platform/ops/summary.d.ts +10 -0
  400. package/dist/platform/ops/summary.js +18 -0
  401. package/dist/platform/platform-ops.module.d.ts +7 -0
  402. package/dist/platform/platform-ops.module.js +55 -0
  403. package/dist/platform/platform.module.d.ts +8 -0
  404. package/dist/platform/platform.module.js +25 -0
  405. package/dist/platform/redact-orgs.d.ts +7 -0
  406. package/dist/platform/redact-orgs.js +52 -0
  407. package/dist/platform/registry.d.ts +30 -0
  408. package/dist/platform/registry.js +111 -0
  409. package/dist/roles/worker-role.d.ts +6 -4
  410. package/dist/roles/worker-role.js +14 -7
  411. package/dist/roles/worker.module.d.ts +1 -1
  412. package/dist/roles/worker.module.js +15 -1
  413. package/dist/runtime/context/build.d.ts +11 -7
  414. package/dist/runtime/context/build.js +46 -19
  415. package/dist/runtime/context/claude-tools.d.ts +3 -1
  416. package/dist/runtime/context/claude-tools.js +8 -6
  417. package/dist/runtime/context/compaction.js +13 -0
  418. package/dist/runtime/context/reminders.d.ts +2 -0
  419. package/dist/runtime/context/reminders.js +2 -0
  420. package/dist/runtime/context/skills.js +9 -2
  421. package/dist/runtime/context/tool-changes.d.ts +27 -0
  422. package/dist/runtime/context/tool-changes.js +60 -0
  423. package/dist/runtime/hook-calls.js +2 -0
  424. package/dist/runtime/langgraph-loop.d.ts +3 -1
  425. package/dist/runtime/langgraph-loop.js +36 -17
  426. package/dist/runtime/loop.d.ts +34 -5
  427. package/dist/runtime/maintenance.d.ts +9 -4
  428. package/dist/runtime/maintenance.js +35 -8
  429. package/dist/runtime/model-call.d.ts +46 -8
  430. package/dist/runtime/model-call.js +72 -21
  431. package/dist/runtime/providers.d.ts +6 -0
  432. package/dist/runtime/providers.js +8 -0
  433. package/dist/runtime/run-control.d.ts +11 -1
  434. package/dist/runtime/run-control.js +12 -0
  435. package/dist/runtime/run-drafts.d.ts +85 -0
  436. package/dist/runtime/run-drafts.js +230 -0
  437. package/dist/runtime/run-jobs.d.ts +3 -5
  438. package/dist/runtime/run-jobs.js +3 -7
  439. package/dist/runtime/run-queue.d.ts +59 -2
  440. package/dist/runtime/run-queue.js +311 -38
  441. package/dist/runtime/run-worker.d.ts +11 -5
  442. package/dist/runtime/run-worker.js +69 -33
  443. package/dist/runtime/runtime.module.js +11 -3
  444. package/dist/runtime/step-log.d.ts +15 -4
  445. package/dist/runtime/step-log.js +24 -7
  446. package/dist/runtime/stream.controller.d.ts +23 -1
  447. package/dist/runtime/stream.controller.js +60 -3
  448. package/dist/runtime/stream.d.ts +4 -1
  449. package/dist/runtime/stream.js +27 -3
  450. package/dist/runtime/subagents/child.d.ts +55 -7
  451. package/dist/runtime/subagents/child.js +105 -7
  452. package/dist/runtime/subagents/definition.d.ts +12 -3
  453. package/dist/runtime/subagents/definition.js +44 -28
  454. package/dist/runtime/subagents/deliveries.d.ts +71 -0
  455. package/dist/runtime/subagents/deliveries.js +228 -0
  456. package/dist/runtime/subagents/dispatch.d.ts +115 -26
  457. package/dist/runtime/subagents/dispatch.js +212 -141
  458. package/dist/runtime/subagents/limits.d.ts +24 -5
  459. package/dist/runtime/subagents/limits.js +40 -6
  460. package/dist/runtime/subagents/messages.d.ts +95 -0
  461. package/dist/runtime/subagents/messages.js +328 -0
  462. package/dist/runtime/subagents/preamble.d.ts +4 -4
  463. package/dist/runtime/subagents/preamble.js +9 -7
  464. package/dist/runtime/subagents/progress.d.ts +8 -6
  465. package/dist/runtime/subagents/progress.js +11 -6
  466. package/dist/runtime/subagents/render.d.ts +30 -0
  467. package/dist/runtime/subagents/render.js +53 -0
  468. package/dist/runtime/subagents/roster.d.ts +24 -7
  469. package/dist/runtime/subagents/roster.js +47 -11
  470. package/dist/runtime/subagents/skill-fork.d.ts +3 -2
  471. package/dist/runtime/subagents/skill-fork.js +8 -4
  472. package/dist/runtime/subagents/status.d.ts +14 -0
  473. package/dist/runtime/subagents/status.js +23 -0
  474. package/dist/runtime/subagents/subagents.service.d.ts +7 -4
  475. package/dist/runtime/subagents/subagents.service.js +11 -6
  476. package/dist/runtime/usage-report.d.ts +2 -1
  477. package/dist/runtime/usage-report.js +19 -13
  478. package/dist/runtime/waits.d.ts +145 -36
  479. package/dist/runtime/waits.js +423 -109
  480. package/dist/sandbox/jobs.d.ts +40 -13
  481. package/dist/sandbox/jobs.js +57 -20
  482. package/dist/sandbox/leases.d.ts +37 -54
  483. package/dist/sandbox/leases.js +71 -115
  484. package/dist/sandbox/providers.d.ts +2 -2
  485. package/dist/sandbox/providers.js +1 -1
  486. package/dist/sandbox/sandbox.module.d.ts +3 -2
  487. package/dist/sandbox/sandbox.module.js +10 -4
  488. package/dist/sandbox/sandbox.service.d.ts +282 -129
  489. package/dist/sandbox/sandbox.service.js +736 -381
  490. package/dist/skills/catalog.d.ts +3 -2
  491. package/dist/skills/catalog.js +21 -43
  492. package/dist/skills/changes.controller.d.ts +7 -0
  493. package/dist/skills/changes.controller.js +19 -1
  494. package/dist/skills/invoke.js +8 -3
  495. package/dist/skills/package.d.ts +20 -1
  496. package/dist/skills/package.js +28 -1
  497. package/dist/skills/skills.controller.d.ts +39 -4
  498. package/dist/skills/skills.controller.js +88 -10
  499. package/dist/skills/skills.module.js +10 -1
  500. package/dist/skills/skills.service.d.ts +106 -26
  501. package/dist/skills/skills.service.js +421 -75
  502. package/dist/skills/usable.d.ts +81 -0
  503. package/dist/skills/usable.js +379 -0
  504. package/dist/tools/approvals.service.d.ts +20 -2
  505. package/dist/tools/approvals.service.js +25 -4
  506. package/dist/tools/builtin-names.d.ts +41 -7
  507. package/dist/tools/builtin-names.js +59 -7
  508. package/dist/tools/builtins/agent.d.ts +23 -21
  509. package/dist/tools/builtins/agent.js +62 -55
  510. package/dist/tools/builtins/builtin-tools.d.ts +19 -1
  511. package/dist/tools/builtins/builtin-tools.js +59 -2
  512. package/dist/tools/builtins/handback.d.ts +28 -0
  513. package/dist/tools/builtins/handback.js +53 -0
  514. package/dist/tools/builtins/platform.d.ts +34 -0
  515. package/dist/tools/builtins/platform.js +362 -0
  516. package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
  517. package/dist/tools/builtins/sandbox/bash.js +241 -4
  518. package/dist/tools/builtins/sandbox/common.d.ts +69 -27
  519. package/dist/tools/builtins/sandbox/common.js +87 -48
  520. package/dist/tools/builtins/sandbox/deliver.js +1 -1
  521. package/dist/tools/builtins/sandbox/edit.js +2 -2
  522. package/dist/tools/builtins/sandbox/glob.js +2 -2
  523. package/dist/tools/builtins/sandbox/grep.js +2 -4
  524. package/dist/tools/builtins/sandbox/index.d.ts +3 -1
  525. package/dist/tools/builtins/sandbox/index.js +7 -1
  526. package/dist/tools/builtins/sandbox/read.js +1 -1
  527. package/dist/tools/builtins/sandbox/task-output.d.ts +74 -0
  528. package/dist/tools/builtins/sandbox/task-output.js +329 -0
  529. package/dist/tools/builtins/sandbox/task-stop.d.ts +10 -0
  530. package/dist/tools/builtins/sandbox/task-stop.js +113 -0
  531. package/dist/tools/builtins/sandbox/write.js +2 -2
  532. package/dist/tools/builtins/send-message.d.ts +56 -0
  533. package/dist/tools/builtins/send-message.js +100 -0
  534. package/dist/tools/builtins/skill-load.d.ts +22 -14
  535. package/dist/tools/builtins/skill-load.js +86 -57
  536. package/dist/tools/builtins/skill-write.js +1 -1
  537. package/dist/tools/builtins/web/errors.d.ts +8 -0
  538. package/dist/tools/builtins/web/errors.js +53 -0
  539. package/dist/tools/builtins/web/extract.d.ts +62 -0
  540. package/dist/tools/builtins/web/extract.js +271 -0
  541. package/dist/tools/builtins/web/fetch.d.ts +55 -0
  542. package/dist/tools/builtins/web/fetch.js +175 -0
  543. package/dist/tools/builtins/web/index.d.ts +13 -0
  544. package/dist/tools/builtins/web/index.js +12 -0
  545. package/dist/tools/builtins/web/page-cache.d.ts +25 -0
  546. package/dist/tools/builtins/web/page-cache.js +77 -0
  547. package/dist/tools/builtins/web/search.d.ts +25 -0
  548. package/dist/tools/builtins/web/search.js +210 -0
  549. package/dist/tools/builtins/web/url.d.ts +17 -0
  550. package/dist/tools/builtins/web/url.js +43 -0
  551. package/dist/tools/connectors.controller.d.ts +10 -0
  552. package/dist/tools/connectors.controller.js +12 -0
  553. package/dist/tools/connectors.service.d.ts +46 -5
  554. package/dist/tools/connectors.service.js +94 -15
  555. package/dist/tools/extension-tools.controller.d.ts +14 -0
  556. package/dist/tools/extension-tools.controller.js +37 -0
  557. package/dist/tools/info.d.ts +42 -1
  558. package/dist/tools/info.js +64 -1
  559. package/dist/tools/oauth/flow-paths.d.ts +1 -1
  560. package/dist/tools/oauth/flow-paths.js +1 -1
  561. package/dist/tools/org-tool-switches.d.ts +74 -0
  562. package/dist/tools/org-tool-switches.js +184 -0
  563. package/dist/tools/pipeline.d.ts +46 -40
  564. package/dist/tools/pipeline.js +202 -364
  565. package/dist/tools/policy.d.ts +1 -1
  566. package/dist/tools/policy.js +36 -16
  567. package/dist/tools/registry.d.ts +120 -8
  568. package/dist/tools/registry.js +112 -19
  569. package/dist/tools/tools.module.js +24 -2
  570. package/dist/tools/validate.js +1 -1
  571. package/dist/ui/views.d.ts +2 -1
  572. package/dist/ui/views.js +17 -3
  573. package/package.json +3 -3
  574. package/src/migrations/0064_account_last_org.sql +7 -0
  575. package/src/migrations/0065_conversation_archive.sql +8 -0
  576. package/src/migrations/0066_extension_display_name.sql +4 -0
  577. package/src/migrations/0067_agent_profiles.sql +20 -0
  578. package/src/migrations/0068_agent_avatar_uploads.sql +7 -0
  579. package/src/migrations/0069_attachments_agent_idx.sql +3 -0
  580. package/src/migrations/0070_background_tasks.sql +37 -0
  581. package/src/migrations/0071_background_tasks_reserve.sql +6 -0
  582. package/src/migrations/0072_background_tasks_stopping.sql +5 -0
  583. package/src/migrations/0073_org_extension_point_defaults.sql +11 -0
  584. package/src/migrations/0074_subagent_tree.sql +50 -0
  585. package/src/migrations/0075_plugin_scope.sql +61 -0
  586. package/src/migrations/0076_skills_created_by_nullable.sql +6 -0
  587. package/src/migrations/0077_scope_requests.sql +52 -0
  588. package/src/migrations/0078_scope_grant_switches.sql +18 -0
  589. package/src/migrations/0079_scope_live_install_switches.sql +19 -0
  590. package/src/migrations/0080_rename_enterprise_admin.sql +18 -0
  591. package/src/migrations/0081_platform_components.sql +129 -0
  592. package/src/migrations/0082_platform_migration.sql +33 -0
  593. package/src/migrations/0083_plugin_scope_sync_failures.sql +15 -0
  594. package/src/migrations/0084_org_owned_items.sql +85 -0
  595. package/src/migrations/0085_agent_templates_phase4.sql +45 -0
  596. package/src/migrations/0086_org_layering.sql +30 -0
  597. package/src/migrations/0087_approval_summary.sql +6 -0
  598. package/src/migrations/0088_environments.sql +80 -0
  599. package/dist/catalog/upgrade-targets.d.ts +0 -56
  600. package/dist/catalog/upgrade-targets.js +0 -90
  601. package/dist/conversations/sandbox-status.d.ts +0 -24
  602. package/dist/conversations/sandbox-status.js +0 -52
  603. package/dist/extensions/org-config.controller.d.ts +0 -24
  604. package/dist/extensions/org-config.controller.js +0 -62
@@ -18,45 +18,43 @@ import { OrgLock } from "../orgs/org-lock.js";
18
18
  import { can, roleAtLeast } from "../orgs/roles.js";
19
19
  import { packagePath } from "../packages/tgz.js";
20
20
  import { StorageService } from "../storage/storage.service.js";
21
- import { catalogHasIcon, findConnectorIn, lockOrgForActions, orgTemplateView, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
22
- import { itemView } from "./catalog-items.js";
23
- import { PluginInstaller } from "./plugin-install.js";
24
- import { PluginUpgrader } from "./plugin-upgrade.js";
25
- import { CatalogRequestsService } from "./requests.service.js";
26
- import { upgradeInfo } from "./upgrade-targets.js";
21
+ import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
22
+ import { itemView, ownerOnlyFacts, versionUsable } from "./catalog-items.js";
23
+ import { connectorTemplatesOn, templateIdOfPath } from "./component-state.js";
24
+ import { itemPendingError, ownerOf, ownersOf } from "./ownership.js";
25
+ import { PluginInstaller, uninstallPreviewHash, upsertOrgSwitch, } from "./plugin-install.js";
26
+ import { requestable, switchable, visibleTo, wantedOn } from "./scope.js";
27
27
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
28
28
  const itemNotFound = () => new ApiError("catalog.item_not_found", "Catalog item not found");
29
- const itemDisabled = () => new ApiError("catalog.item_disabled", "This catalog item is disabled by the enterprise admin and cannot be newly installed");
29
+ const notOffered = () => new ApiError("catalog.approval_required", "This plugin is not offered to this organization; an org admin can request access");
30
+ const pluginDisabled = () => new ApiError("plugin.disabled", "This plugin is disabled by the super admin and cannot be switched on");
30
31
  /**
31
- * Organizations browse and install from the enterprise catalog (C22): members browse (without
32
- * disabled items) and request, org admins install. Every item is a plugin, installed with its
33
- * dependencies by {@link PluginInstaller}; installing requires the union of the component actions
34
- * of the plugins it brings in ({@link requiredActions}), re-checked inside the org row lock; item
35
- * disabled -> `catalog.item_disabled`; a dependency unresolved / disabled / in a cycle ->
36
- * `catalog.dependency_*`; an extension or a template's connector not on the deployment ->
37
- * `catalog.not_deployed`; needs_approval without a grant -> a stage deployment request (HTTP 202;
38
- * dependencies are not approved separately, spec §10). No in-process state.
32
+ * Organizations see the platform catalog with the plugin scope rules applied (plugin and component
33
+ * management spec §5): a plugin is `all` (on in every org unless an org admin switched it off,
34
+ * layering spec §4), `optional` (an org admin switches it on), or `named` (offered to the listed
35
+ * orgs). Members get the list read-only; org admins switch a plugin on (an install by
36
+ * {@link PluginInstaller}, with its dependencies; the union of the component actions of the plugins
37
+ * it brings in is re-checked inside the org row lock) or off (an uninstall, after a preview they
38
+ * confirm with its hash). Disabled item -> `plugin.disabled`; a
39
+ * dependency unresolved / disabled / in a cycle -> `catalog.dependency_*`; an extension or a
40
+ * template's connector not on the deployment -> `catalog.not_deployed`. No in-process state.
39
41
  */
40
42
  let OrgCatalogService = class OrgCatalogService {
41
43
  kdb;
42
44
  orgLock;
43
45
  storage;
44
46
  registry;
45
- requests;
46
47
  pluginInstaller;
47
- pluginUpgrader;
48
48
  log;
49
49
  txHost;
50
50
  constructor(kdb,
51
51
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
52
- orgLock, storage, registry, requests, pluginInstaller, pluginUpgrader, log, txHost) {
52
+ orgLock, storage, registry, pluginInstaller, log, txHost) {
53
53
  this.kdb = kdb;
54
54
  this.orgLock = orgLock;
55
55
  this.storage = storage;
56
56
  this.registry = registry;
57
- this.requests = requests;
58
57
  this.pluginInstaller = pluginInstaller;
59
- this.pluginUpgrader = pluginUpgrader;
60
58
  this.log = log;
61
59
  this.txHost = txHost;
62
60
  }
@@ -64,7 +62,11 @@ let OrgCatalogService = class OrgCatalogService {
64
62
  get db() {
65
63
  return this.kdb.db;
66
64
  }
67
- /** The org's view of the items; members (not admins) don't see disabled items. */
65
+ /**
66
+ * The org's view of the items: a `named` item without the org on its list is `not_offered` when
67
+ * shown to other orgs and absent otherwise; disabled ones are shown to admins as `unavailable`
68
+ * and absent for members. Each item carries the org's pending request for it.
69
+ */
68
70
  async list(orgId, accountId, itemId) {
69
71
  const m = await this.db
70
72
  .selectFrom("memberships")
@@ -82,67 +84,141 @@ let OrgCatalogService = class OrgCatalogService {
82
84
  if (itemId !== undefined)
83
85
  q = q.where("id", "=", itemId);
84
86
  if (!isAdmin)
85
- q = q.where("policy", "<>", "disabled");
86
- const items = await q.execute();
87
+ q = q.where("disabled", "=", false);
88
+ const all = await q.execute();
89
+ const [listed, switches] = await Promise.all([
90
+ this.db
91
+ .selectFrom("catalog_item_scope_orgs")
92
+ .select("item_id")
93
+ .where("org_id", "=", orgId)
94
+ .execute(),
95
+ this.db
96
+ .selectFrom("catalog_item_org_switches")
97
+ .select(["item_id", "enabled"])
98
+ .where("org_id", "=", orgId)
99
+ .execute(),
100
+ ]);
101
+ const inList = new Set(listed.map((r) => r.item_id));
102
+ // Hidden `named` items (not listed, not shown to other orgs) are absent; shown ones are
103
+ // `not_offered`
104
+ // An org upload waiting for the super admin is its owner's only (ruling P3-9)
105
+ const items = all.filter((i) => (!i.awaiting_confirmation || i.owner_org_id === orgId) &&
106
+ (visibleTo({ scope: i.builtin ? "all" : i.scope }, inList.has(i.id)) ||
107
+ requestable(i, inList.has(i.id))));
87
108
  if (items.length === 0)
88
109
  return [];
110
+ const sw = new Map(switches.map((r) => [r.item_id, r.enabled]));
89
111
  const ids = items.map((i) => i.id);
90
- const [versions, grants, requests, pluginInstalls] = await Promise.all([
112
+ const [versions, pluginInstalls, configs, requests] = await Promise.all([
91
113
  this.db
92
114
  .selectFrom("catalog_item_versions")
93
- .select(["item_id", "version", "source", "manifest", "object_prefix", "files"])
115
+ .select([
116
+ "item_id",
117
+ "version",
118
+ "source",
119
+ "source_format",
120
+ "manifest",
121
+ "object_prefix",
122
+ "files",
123
+ "applied_at",
124
+ "rejected_at",
125
+ ])
94
126
  .where("item_id", "in", ids)
95
127
  .execute(),
96
- this.db
97
- .selectFrom("catalog_org_grants")
98
- .select("item_id")
99
- .where("org_id", "=", orgId)
100
- .execute(),
101
- this.requests.latestByItem(orgId),
102
128
  this.db
103
129
  .selectFrom("plugin_installs")
104
130
  .select(["id", "item_id", "version"])
105
131
  .where("org_id", "=", orgId)
106
132
  .where("status", "in", ["installing", "installed", "upgrading"])
107
133
  .execute(),
134
+ this.db
135
+ .selectFrom("extension_org_configs")
136
+ .select("plugin")
137
+ .where("org_id", "=", orgId)
138
+ .where("config", "is not", null)
139
+ .execute(),
140
+ this.db
141
+ .selectFrom("catalog_requests")
142
+ .select(["id", "item_id", "kind", "created_at"])
143
+ .where("org_id", "=", orgId)
144
+ .where("item_id", "in", ids)
145
+ .where("kind", "in", ["access", "enable"])
146
+ .where("status", "=", "pending")
147
+ .orderBy("created_at")
148
+ .execute(),
108
149
  ]);
109
- const upgrades = await upgradeInfo(this.db, this.registry, pluginInstalls.flatMap((a) => {
110
- const item = items.find((i) => i.id === a.item_id);
111
- return item ? [{ itemId: a.item_id, name: item.name, version: a.version }] : [];
112
- }));
113
- const granted = new Set(grants.map((g) => g.item_id));
150
+ const pending = new Map(requests.map((r) => [
151
+ r.item_id,
152
+ { id: r.id, kind: r.kind, createdAt: r.created_at.toISOString() },
153
+ ]));
114
154
  const undeployed = await this.undeployed(items.flatMap((i) => {
115
155
  const v = versions.find((x) => x.item_id === i.id && x.version === i.latest_version);
116
156
  return v ? [v] : [];
117
157
  }));
158
+ const configured = new Set(configs.map((c) => c.plugin));
159
+ const owners = await ownersOf(this.db, items.flatMap((i) => (i.owner_org_id === null ? [] : [i.owner_org_id])));
160
+ const loaded = new Map(this.registry.manifests().map((x) => [x.name, x]));
118
161
  const out = [];
119
162
  for (const i of items) {
120
- const vs = versions.filter((v) => v.item_id === i.id);
121
- const { installs: _installs, marketplaceId: _source, latestMarketplaceVersion: _latest, newerInMarketplace: _newer, ...view } = itemView(i, vs);
163
+ // Another org sees only an org-owned plugin's applied version, never one its owner
164
+ // uploaded that is pending or was rejected (ruling P3-34), nor such a version of a plugin
165
+ // transferred to the platform since (ruling P3-52)
166
+ const vs = versions.filter((v) => v.item_id === i.id &&
167
+ (i.owner_org_id === orgId ||
168
+ (versionUsable(v) && (i.owner_org_id === null || v.version === i.latest_version))));
169
+ const { installs: _installs, marketplaceId: _source, latestMarketplaceVersion: _latest, newerInMarketplace: _newer, scopeOrgs: _scopeOrgs, enabledOrgs: _enabledOrgs, offCount: _offCount, pending: _pending, shownToOthers: _shown, awaitingConfirmation, pendingVersion, ...view } = itemView(i, vs, 0, undefined, ownerOnlyFacts(ownerOf(i.owner_org_id, owners)));
122
170
  const latest = vs.find((v) => v.version === i.latest_version);
123
- let installable;
124
- if (i.policy === "disabled")
125
- installable = "disabled";
126
- else if (latest && undeployed.has(i.id)) {
127
- installable = "not_deployed";
171
+ const a = pluginInstalls.find((x) => x.item_id === i.id);
172
+ const scope = i.builtin ? "all" : i.scope;
173
+ const wanted = wantedOn(i, inList.has(i.id), sw.get(i.id) ?? null);
174
+ let state;
175
+ if (i.awaiting_confirmation)
176
+ state = "awaiting_confirmation";
177
+ else if (i.disabled)
178
+ state = "unavailable";
179
+ else if (requestable(i, inList.has(i.id)))
180
+ state = "not_offered";
181
+ else if (a) {
182
+ // An on connector template without a connector here (ruling P2-10)
183
+ const missing = await this.pluginInstaller.missingConnectors(orgId, i.id);
184
+ state = (missing?.templates.length ?? 0) > 0 ? "needs_config" : "on";
128
185
  }
129
- else if (i.policy === "needs_approval") {
130
- installable = granted.has(i.id) ? "granted" : "needs_approval";
186
+ else if (i.builtin)
187
+ state = "on";
188
+ else if (!wanted)
189
+ state = "off";
190
+ else {
191
+ const m = latest?.manifest;
192
+ const ext = m?.extension ? loaded.get(m.name) : undefined;
193
+ // only the connector templates on in the org need input (ruling P2-6)
194
+ const templateIds = (m?.connectorTemplates ?? []).map((t) => templateIdOfPath(t.path));
195
+ const needsInputs = (await connectorTemplatesOn(this.db, orgId, i.id, templateIds)).size > 0 ||
196
+ (m?.extension !== undefined &&
197
+ ext?.config?.org !== undefined &&
198
+ !ext.config.org.safeParse({}).success &&
199
+ !configured.has(m.name));
200
+ // Wanted but not installed and needing nothing: the sync has not installed it (yet, or its
201
+ // install failed); `off`, so an org admin can switch it on (the worker start retries it)
202
+ state = needsInputs ? "needs_config" : "off";
131
203
  }
132
- else
133
- installable = "yes";
134
- const a = pluginInstalls.find((x) => x.item_id === i.id);
135
204
  out.push({
136
205
  ...view,
137
- installable,
206
+ // A pending upload is the owner's business only (other orgs never learn of it)
207
+ ...(i.owner_org_id === orgId && { awaitingConfirmation, pendingVersion }),
208
+ scope,
209
+ builtin: i.builtin,
210
+ state,
211
+ switchable: state !== "not_offered" && state !== "awaiting_confirmation" && switchable(i),
212
+ notDeployed: latest !== undefined && undeployed.has(i.id),
138
213
  installed: a
139
214
  ? {
140
215
  pluginInstallId: a.id,
141
216
  version: a.version,
142
- upgradeAvailable: upgrades.get(`${a.item_id}@${a.version}`)?.upgradeAvailable ?? null,
217
+ // no per-org upgrade: the platform update moves every org (ruling F2)
218
+ upgradeAvailable: null,
143
219
  }
144
220
  : null,
145
- request: requests.get(i.id) ?? null,
221
+ request: pending.get(i.id) ?? null,
146
222
  });
147
223
  }
148
224
  return out;
@@ -168,21 +244,59 @@ let OrgCatalogService = class OrgCatalogService {
168
244
  if (!v)
169
245
  throw itemNotFound();
170
246
  const m = v.manifest;
247
+ const templates = await readCatalogTemplates(this.storage, v);
248
+ // Providers the install would switch on first (a refusal is the install's to report)
249
+ const implied = await this.pluginInstaller
250
+ .impliedProviders(orgId, m, templates, m.dependencies ?? [])
251
+ .catch((e) => {
252
+ if (e instanceof ApiError)
253
+ return [];
254
+ throw e;
255
+ });
171
256
  return {
172
257
  item,
173
258
  hasIcon: m.icon !== undefined,
174
259
  extension: m.extension ? m.name : null,
175
- templates: (await readCatalogTemplates(this.storage, v)).map((t) => orgTemplateView(t.id, t.file)),
176
- dependencies: (m.dependencies ?? []).map((d) => ({ name: d.name, range: d.version })),
260
+ templates: templates.map((t) => orgTemplateView(t.id, t.file)),
261
+ dependencies: [
262
+ ...(m.dependencies ?? []).map((d) => ({ name: d.name, range: d.version })),
263
+ ...implied.map((d) => ({ name: d.name, range: d.range, implied: true })),
264
+ ],
177
265
  skills: (m.skills ?? []).map((s) => packagePath(s.path)),
178
266
  agents: (m.agents ?? []).map((a) => packagePath(a.path)),
267
+ missingTemplates: item.installed !== null && item.state === "needs_config"
268
+ ? ((await this.pluginInstaller.missingConnectors(orgId, itemId))?.templates ?? []).map((t) => orgTemplateView(t.id, t.file))
269
+ : [],
179
270
  };
180
271
  }
181
272
  /**
182
- * The item's icon; members don't see disabled items (-> `catalog.item_not_found`, decided before
183
- * reading storage).
273
+ * The item's icon; members don't see disabled items, nobody outside its list sees a hidden
274
+ * `named` item (-> `catalog.item_not_found`, decided before reading storage). Without `orgId`
275
+ * (the super admin) every item.
184
276
  */
185
- icon(itemId, isAdmin) {
277
+ async icon(itemId, isAdmin, orgId) {
278
+ if (orgId === undefined)
279
+ return readCatalogIcon(this.db, this.storage, itemId, isAdmin);
280
+ if (!UUID_RE.test(itemId))
281
+ throw itemNotFound();
282
+ // A hidden `named` item stays absent here too
283
+ const item = await this.db
284
+ .selectFrom("catalog_items")
285
+ .select(["scope", "builtin", "shown_to_others", "owner_org_id", "shareable"])
286
+ .where("id", "=", itemId)
287
+ .where("deleted_at", "is", null)
288
+ .executeTakeFirst();
289
+ // Not requestable from outside its list (hidden, or held back by the share gate): only listed orgs
290
+ if (item && !item.builtin && item.scope === "named" && !requestable(item, false)) {
291
+ const listed = await this.db
292
+ .selectFrom("catalog_item_scope_orgs")
293
+ .select("item_id")
294
+ .where("item_id", "=", itemId)
295
+ .where("org_id", "=", orgId)
296
+ .executeTakeFirst();
297
+ if (listed === undefined)
298
+ throw itemNotFound();
299
+ }
186
300
  return readCatalogIcon(this.db, this.storage, itemId, isAdmin);
187
301
  }
188
302
  /** For the admin item detail: whether the latest version has an icon. */
@@ -226,22 +340,18 @@ let OrgCatalogService = class OrgCatalogService {
226
340
  }));
227
341
  return out;
228
342
  }
229
- /** Installs a plugin in the org (see the class comment). */
230
- async install(orgId, actor, itemId, body, actorTokenId) {
343
+ /**
344
+ * Installs a plugin in the org (the old install route, an alias of switching it on): the role
345
+ * first, then item errors (a member cannot probe a disabled item through error codes), then the
346
+ * installer. Records the org's switch as on.
347
+ */
348
+ async install(orgId, actor, itemId, body, actorTokenId, auditDetail) {
231
349
  if (!UUID_RE.test(itemId))
232
350
  throw itemNotFound();
233
- // The role first (forbidden when it can install nothing), then item errors: a member cannot
234
- // probe the existence or versions of a disabled item through error codes
235
351
  await this.assertCanInstall(orgId, actor);
236
- const item = await this.db
237
- .selectFrom("catalog_items")
238
- .selectAll()
239
- .where("id", "=", itemId)
240
- .where("deleted_at", "is", null)
241
- .executeTakeFirst();
242
- if (!item)
243
- throw itemNotFound();
244
- const version = body.version ?? item.latest_version;
352
+ const item = await this.visibleItem(orgId, itemId);
353
+ // The platform's version (one per deployment, ruling P2-17)
354
+ const version = item.platform_synced_version ?? item.latest_version;
245
355
  const v = await this.db
246
356
  .selectFrom("catalog_item_versions")
247
357
  .select("version")
@@ -250,107 +360,169 @@ let OrgCatalogService = class OrgCatalogService {
250
360
  .executeTakeFirst();
251
361
  if (!v)
252
362
  throw new ApiError("catalog.item_not_found", `Version ${version} of this item not found`);
253
- const opts = actorTokenId !== undefined ? { actorTokenId } : {};
254
- if (item.policy === "disabled")
255
- throw itemDisabled();
256
- // Dependencies resolved, extensions deployed, template connectors available: before a request
257
- // is created. The actions are the union over the plugins the install brings in
258
- const { actions } = await this.pluginInstaller.preflight(orgId, actor, itemId, version);
259
- // 1. Role and policy under the lock; needs_approval without a grant -> a request (202). Approval
260
- // follows this plugin's policy only, not its dependencies' (spec §10)
261
- const pending = await this.requestIfNeeded(orgId, actor, item, version, actions, opts);
262
- if (pending !== undefined) {
263
- return { status: 202, request: await this.requests.view(pending) };
264
- }
265
- // 2. Install (each step re-checks the item policy in its own transaction)
266
- const { version: _version, ...input } = body;
267
- const view = await this.pluginInstaller.install(orgId, actor, itemId, version, input, opts);
363
+ const opts = {
364
+ switchOn: true,
365
+ ...(actorTokenId !== undefined && { actorTokenId }),
366
+ ...(auditDetail !== undefined && { auditDetail }),
367
+ };
368
+ if (item.disabled)
369
+ throw pluginDisabled();
370
+ // Dependencies resolved, extensions deployed, template connectors available
371
+ await this.pluginInstaller.preflight(orgId, actor, itemId, version);
372
+ const view = await this.pluginInstaller.install(orgId, actor, itemId, version, body, opts);
268
373
  return {
269
374
  status: 201,
270
375
  installed: { itemId, version, pluginInstallId: view.id },
271
376
  install: view,
272
377
  };
273
378
  }
274
- /**
275
- * Role and policy under the org row lock; needs_approval without a grant -> a stage deployment
276
- * request (its id). Approval follows this plugin's policy only, not its dependencies' (spec §10).
277
- */
278
- async requestIfNeeded(orgId, actor, item, version, actions, opts) {
279
- const itemId = item.id;
280
- const t = this.db;
281
- await lockOrgForActions(this.orgLock, orgId, actor, actions);
282
- const locked = await t
379
+ /** The item when the org may see it (scope), else `catalog.item_not_found`. */
380
+ async visibleItem(orgId, itemId) {
381
+ const item = await this.db
283
382
  .selectFrom("catalog_items")
284
- .select(["policy", "deleted_at"])
383
+ .selectAll()
285
384
  .where("id", "=", itemId)
286
- .forShare()
385
+ .where("deleted_at", "is", null)
287
386
  .executeTakeFirst();
288
- if (!locked || locked.deleted_at !== null)
387
+ if (!item)
388
+ throw itemNotFound();
389
+ // An org upload waiting for the super admin: absent for other orgs, not switchable by its
390
+ // owner (ruling P3-9)
391
+ if (item.awaiting_confirmation) {
392
+ if (item.owner_org_id !== orgId)
393
+ throw itemNotFound();
394
+ throw itemPendingError(item.name);
395
+ }
396
+ const listed = await this.db
397
+ .selectFrom("catalog_item_scope_orgs")
398
+ .select("item_id")
399
+ .where("item_id", "=", itemId)
400
+ .where("org_id", "=", orgId)
401
+ .executeTakeFirst();
402
+ if (!visibleTo({ scope: item.builtin ? "all" : item.scope }, listed !== undefined)) {
403
+ // Shown to other orgs: the org sees it and may request access, but cannot switch it on
404
+ if (requestable(item, false))
405
+ throw notOffered();
289
406
  throw itemNotFound();
290
- if (locked.policy === "disabled")
291
- throw itemDisabled();
292
- if (locked.policy === "needs_approval") {
293
- const grant = await t
294
- .selectFrom("catalog_org_grants")
295
- .select("item_id")
296
- .where("item_id", "=", itemId)
297
- .where("org_id", "=", orgId)
298
- .executeTakeFirst();
299
- if (!grant) {
300
- return this.requests.requestDeployment(orgId, actor, item, version, opts);
301
- }
302
407
  }
303
- return undefined;
408
+ return item;
304
409
  }
305
- /** The upgrade preview of an org install (spec §10, see `PluginUpgrader`). */
306
- async upgradePreview(orgId, actor, installId, version) {
307
- await this.assertCanInstall(orgId, actor);
308
- return this.pluginUpgrader.preview(orgId, actor, installId, version);
410
+ /** The org's live plugin install of the item, if any. */
411
+ liveInstall(orgId, itemId) {
412
+ return this.db
413
+ .selectFrom("plugin_installs")
414
+ .select("id")
415
+ .where("org_id", "=", orgId)
416
+ .where("item_id", "=", itemId)
417
+ .where("status", "in", ["installing", "installed", "upgrading"])
418
+ .executeTakeFirst();
309
419
  }
310
420
  /**
311
- * Upgrades an org install in place (spec §10, Decision 11): the preview's `diffHash` is checked
312
- * first (`plugin.upgrade_stale`); the item disabled -> `catalog.item_disabled`; needs_approval
313
- * without a grant -> a stage deployment request for the target version (202; after approval the
314
- * org admin runs the upgrade again); otherwise the upgrade runs (200, the install view).
421
+ * The org admin's switch of a plugin (`PUT catalog/:itemId/switch`). On: installs it (or just
422
+ * records the switch when it is installed already). Off: refused for builtin items
423
+ * (`plugin.scope_locked`; an `all` one may go off, layering spec §4); without `confirm` returns
424
+ * the uninstall preview and its hash, with the hash of the current preview uninstalls (a changed
425
+ * preview -> `plugin.switch_stale`). The switch row is written after the install / uninstall.
315
426
  */
316
- async upgrade(orgId, actor, installId, body, actorTokenId) {
427
+ async setSwitch(orgId, actor, itemId, body, actorTokenId, auditDetail) {
428
+ if (!UUID_RE.test(itemId))
429
+ throw itemNotFound();
317
430
  await this.assertCanInstall(orgId, actor);
318
- const opts = actorTokenId !== undefined ? { actorTokenId } : {};
319
- const { itemId, actions, diff } = await this.pluginUpgrader.check(orgId, actor, installId, body);
320
- const pending = await this.upgradeRequestIfNeeded(orgId, actor, itemId, body, actions, opts);
321
- if (pending !== undefined) {
322
- return { status: 202, request: await this.requests.view(pending) };
323
- }
324
- return {
325
- status: 200,
326
- install: await this.pluginUpgrader.upgrade(orgId, actor, installId, body, opts, diff),
431
+ const item = await this.visibleItem(orgId, itemId);
432
+ const opts = {
433
+ ...(actorTokenId !== undefined && { actorTokenId }),
434
+ ...(auditDetail !== undefined && { auditDetail }),
327
435
  };
436
+ if (body.enabled) {
437
+ if (item.disabled)
438
+ throw pluginDisabled();
439
+ if ((await this.liveInstall(orgId, itemId)) !== undefined) {
440
+ await this.recordSwitch(orgId, actor, itemId, true);
441
+ }
442
+ else {
443
+ await this.install(orgId, actor, itemId, body.inputs ?? {}, actorTokenId, auditDetail);
444
+ }
445
+ return { kind: "done", item: await this.itemOf(orgId, actor, itemId) };
446
+ }
447
+ if (!switchable(item)) {
448
+ throw new ApiError("plugin.scope_locked", "This plugin is built in: it is on for every organization and cannot be switched off here");
449
+ }
450
+ const live = await this.liveInstall(orgId, itemId);
451
+ if (live === undefined) {
452
+ await this.recordSwitch(orgId, actor, itemId, false);
453
+ return { kind: "done", item: await this.itemOf(orgId, actor, itemId) };
454
+ }
455
+ const preview = await this.pluginInstaller.previewUninstall(orgId, live.id);
456
+ const confirm = uninstallPreviewHash(preview);
457
+ if (body.confirm === undefined)
458
+ return { kind: "preview", preview, confirm };
459
+ // The hash is re-checked and the switch row written inside the uninstall's transaction
460
+ await this.pluginInstaller.uninstall(orgId, actor, live.id, opts, { expectHash: body.confirm });
461
+ return { kind: "done", item: await this.itemOf(orgId, actor, itemId) };
328
462
  }
329
- /** Like {@link requestIfNeeded}, for an upgrade's target version. */
330
- async upgradeRequestIfNeeded(orgId, actor, itemId, body, actions, opts) {
331
- const t = this.db;
332
- await lockOrgForActions(this.orgLock, orgId, actor, actions);
333
- const locked = await t
463
+ /**
464
+ * `DELETE plugin-installs/:installId` of a catalog plugin follows the switch-off semantics: builtin
465
+ * items are refused (`plugin.scope_locked`) unless the install is not live (failed, or
466
+ * `installing`: the installer cleans up a stale one and refuses a fresh one). Removing a live
467
+ * install writes the switch row false in the uninstall's transaction (an `all` item then stays
468
+ * off in the org); removing a failed or stale one writes none.
469
+ */
470
+ async uninstall(orgId, actor, installId, actorTokenId) {
471
+ if (!UUID_RE.test(installId))
472
+ throw new ApiError("plugin.install_not_found", "Plugin install not found");
473
+ const row = await this.db
474
+ .selectFrom("plugin_installs as a")
475
+ .innerJoin("catalog_items as i", "i.id", "a.item_id")
476
+ .select(["i.scope", "i.builtin", "a.status"])
477
+ .where("a.id", "=", installId)
478
+ .where("a.org_id", "=", orgId)
479
+ .executeTakeFirst();
480
+ // A failed or stuck install is cleaned up whatever the scope (it is not on anyway)
481
+ const live = row?.status === "installed" || row?.status === "upgrading";
482
+ if (row !== undefined && live && !switchable(row)) {
483
+ throw new ApiError("plugin.scope_locked", "This plugin is built in: it is on for every organization and cannot be uninstalled here");
484
+ }
485
+ return this.pluginInstaller.uninstall(orgId, actor, installId, actorTokenId !== undefined ? { actorTokenId } : {},
486
+ // only a live install was on: removing a failed or stale one writes no switch row, so an
487
+ // item its scope wants stays wanted and the sync installs it again
488
+ row !== undefined && live ? {} : undefined);
489
+ }
490
+ async itemOf(orgId, accountId, itemId) {
491
+ const [item] = await this.list(orgId, accountId, itemId);
492
+ if (!item)
493
+ throw itemNotFound();
494
+ return item;
495
+ }
496
+ /**
497
+ * Writes the org's switch row of the item under the org row lock. The item row is locked FOR
498
+ * SHARE first (exclusive with a scope change, an unshare, ruling P3-25, and an owner's delete or
499
+ * transfer); switching on re-checks that the org may still see it; the install path re-checks the same in `assertItemInstallable`.
500
+ */
501
+ async recordSwitch(orgId, actor, itemId, enabled) {
502
+ await this.orgLock.lock(orgId);
503
+ // Both directions lock the item row FOR SHARE: an owner's delete or transfer (FOR UPDATE)
504
+ // decides on who uses it, so a switch-off racing it must not change that answer meanwhile
505
+ const item = await this.db
334
506
  .selectFrom("catalog_items")
335
- .select(["id", "name", "policy", "deleted_at"])
507
+ .select(["scope", "builtin"])
336
508
  .where("id", "=", itemId)
509
+ .where("deleted_at", "is", null)
337
510
  .forShare()
338
511
  .executeTakeFirst();
339
- if (!locked || locked.deleted_at !== null)
340
- throw itemNotFound();
341
- if (locked.policy === "disabled")
342
- throw itemDisabled();
343
- if (locked.policy !== "needs_approval")
344
- return undefined;
345
- const grant = await t
346
- .selectFrom("catalog_org_grants")
347
- .select("item_id")
348
- .where("item_id", "=", itemId)
349
- .where("org_id", "=", orgId)
350
- .executeTakeFirst();
351
- if (grant)
352
- return undefined;
353
- return this.requests.requestDeployment(orgId, actor, locked, body.version, opts);
512
+ if (enabled) {
513
+ if (!item)
514
+ throw itemNotFound();
515
+ const listed = await this.db
516
+ .selectFrom("catalog_item_scope_orgs")
517
+ .select("item_id")
518
+ .where("item_id", "=", itemId)
519
+ .where("org_id", "=", orgId)
520
+ .executeTakeFirst();
521
+ if (!visibleTo({ scope: item.builtin ? "all" : item.scope }, listed !== undefined)) {
522
+ throw itemNotFound();
523
+ }
524
+ }
525
+ await upsertOrgSwitch(this.db, orgId, itemId, enabled, actor);
354
526
  }
355
527
  /** The actor can install something in the org (forbidden otherwise), checked before item errors. */
356
528
  async assertCanInstall(orgId, actor) {
@@ -362,10 +534,7 @@ let OrgCatalogService = class OrgCatalogService {
362
534
  };
363
535
  __decorate([
364
536
  Transactional()
365
- ], OrgCatalogService.prototype, "requestIfNeeded", null);
366
- __decorate([
367
- Transactional()
368
- ], OrgCatalogService.prototype, "upgradeRequestIfNeeded", null);
537
+ ], OrgCatalogService.prototype, "recordSwitch", null);
369
538
  __decorate([
370
539
  Transactional()
371
540
  ], OrgCatalogService.prototype, "assertCanInstall", null);
@@ -375,10 +544,8 @@ OrgCatalogService = __decorate([
375
544
  __param(1, Inject(OrgLock)),
376
545
  __param(2, Inject(StorageService)),
377
546
  __param(3, Inject(ExtensionRegistry)),
378
- __param(4, Inject(CatalogRequestsService)),
379
- __param(5, Inject(PluginInstaller)),
380
- __param(6, Inject(PluginUpgrader)),
381
- __param(7, Inject(KERNEL_LOGGER)),
382
- __param(8, Inject(TransactionHost))
547
+ __param(4, Inject(PluginInstaller)),
548
+ __param(5, Inject(KERNEL_LOGGER)),
549
+ __param(6, Inject(TransactionHost))
383
550
  ], OrgCatalogService);
384
551
  export { OrgCatalogService };