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