@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.37
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 +5 -5
- package/dist/admin/admin.module.d.ts +3 -3
- package/dist/admin/admin.module.js +6 -6
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -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 +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +53 -47
- package/dist/config/schema.js +190 -40
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +2 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- 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.js +0 -17
- 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/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +3 -7
- package/dist/overrides.js +2 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +1 -0
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.js +4 -3
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- 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/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +16 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- 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/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- 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/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 -114
|
@@ -33,6 +33,7 @@ import { ConnectorsService } from "../tools/connectors.service.js";
|
|
|
33
33
|
import { findConnectorIn, lockOrgForActions, readCatalogAgentTemplates, readCatalogFiles, readCatalogTemplates, requiredActions, templateConnectorInput, templatePluginProblem, } from "./catalog-content.js";
|
|
34
34
|
import { versionUsable } from "./catalog-items.js";
|
|
35
35
|
import { agentDefinitionRefs, componentOn, connectorTemplateState, connectorTemplatesOn, listedIn, loadComponents, loadScopeState, pluginFactsOf, referenceIds, switchOf, themeIdClashes, } from "./component-state.js";
|
|
36
|
+
import { LIVE_INSTALL_STATUSES } from "./install-status.js";
|
|
36
37
|
import { assertItemInstallable, disabledPluginItems, pluginItemDisabled, resolveRequestsByInstall, } from "./request-rules.js";
|
|
37
38
|
import { visibleTo } from "./scope.js";
|
|
38
39
|
import { ScopeNoLongerWanted, ScopeStillWanted, wantedByScope } from "./scope-state.js";
|
|
@@ -288,8 +289,7 @@ export function under(e, at) {
|
|
|
288
289
|
* `plugin.install_failed` is thrown. Uninstall removes only components with created=true that
|
|
289
290
|
* nothing else uses, and reports what it kept and why. No in-process state; the org row lock
|
|
290
291
|
* serializes writes within one org. There is no per-org upgrade: a platform plugin is updated
|
|
291
|
-
* once for the deployment (`PlatformPluginUpdater`, plugin-upgrade.ts, ruling F2)
|
|
292
|
-
* `upgrading` by an earlier per-org upgrade is undone from its journal by the next uninstall. The
|
|
292
|
+
* once for the deployment (`PlatformPluginUpdater`, plugin-upgrade.ts, ruling F2). The
|
|
293
293
|
* methods without `private` are internal to the catalog, not an API.
|
|
294
294
|
*/
|
|
295
295
|
let PluginInstaller = class PluginInstaller {
|
|
@@ -1069,13 +1069,6 @@ let PluginInstaller = class PluginInstaller {
|
|
|
1069
1069
|
}
|
|
1070
1070
|
if (c.kind === "plugin")
|
|
1071
1071
|
return false;
|
|
1072
|
-
// A row the org promoted is the org's own shared item (ruling P3-47): an install never
|
|
1073
|
-
// removes or reverts it (P3-46 keeps plugin content from being promoted; this guards rows
|
|
1074
|
-
// recorded before that or by a legacy install)
|
|
1075
|
-
if ((c.kind === "agent_template" || c.kind === "skill") &&
|
|
1076
|
-
(await promotedOrgRow(t, orgId, c.kind, c.ref))) {
|
|
1077
|
-
return false;
|
|
1078
|
-
}
|
|
1079
1072
|
if (c.kind === "agent_template") {
|
|
1080
1073
|
if (c.created)
|
|
1081
1074
|
return softDeleteTemplateIn(t, orgId, c.ref);
|
|
@@ -1229,7 +1222,7 @@ let PluginInstaller = class PluginInstaller {
|
|
|
1229
1222
|
.innerJoin("plugin_installs as a", "a.id", "c.install_id")
|
|
1230
1223
|
.select("a.id")
|
|
1231
1224
|
.where("a.org_id", "=", orgId)
|
|
1232
|
-
.where("a.status", "in", [
|
|
1225
|
+
.where("a.status", "in", [...LIVE_INSTALL_STATUSES])
|
|
1233
1226
|
.where("c.kind", "=", kind)
|
|
1234
1227
|
.where("c.ref", "=", ref);
|
|
1235
1228
|
if (removing.size > 0)
|
|
@@ -1289,8 +1282,6 @@ let PluginInstaller = class PluginInstaller {
|
|
|
1289
1282
|
"a.status",
|
|
1290
1283
|
"i.name",
|
|
1291
1284
|
sql `a.installed_at < now() - make_interval(mins => ${staleMinutes})`.as("stale"),
|
|
1292
|
-
sql `coalesce((a.upgrade->>'startedAt')::timestamptz < now() - make_interval(mins => ${staleMinutes}), false)`.as("upgradeStale"),
|
|
1293
|
-
"a.upgrade",
|
|
1294
1285
|
])
|
|
1295
1286
|
.where("a.id", "=", installId)
|
|
1296
1287
|
.where("a.org_id", "=", orgId)
|
|
@@ -1311,26 +1302,16 @@ let PluginInstaller = class PluginInstaller {
|
|
|
1311
1302
|
await this.handOver(user, "plugin", installId);
|
|
1312
1303
|
return "kept";
|
|
1313
1304
|
}
|
|
1314
|
-
if (row.status === "uninstalling" ||
|
|
1315
|
-
(row.status === "installing" && !row.stale) ||
|
|
1316
|
-
(row.status === "upgrading" && !row.upgradeStale)) {
|
|
1305
|
+
if (row.status === "uninstalling" || (row.status === "installing" && !row.stale)) {
|
|
1317
1306
|
throw new ApiError("plugin.install_in_progress", `This plugin install is still in progress; it can be cleaned up after ${staleMinutes} minutes`);
|
|
1318
1307
|
}
|
|
1319
|
-
if (row.status === "upgrading") {
|
|
1320
|
-
// An upgrade interrupted midway (a replica crashed): undone first, back at the old version
|
|
1321
|
-
const undone = await this.undoUpgradeIn(orgId, actor, installId, journalEntries(row.upgrade), "plugin_upgrade_cleanup");
|
|
1322
|
-
for (const x of undone)
|
|
1323
|
-
addRemoved(x);
|
|
1324
|
-
}
|
|
1325
1308
|
removing.add(installId);
|
|
1326
1309
|
// failed (already rolled back) and a stale installing (a replica crashed midway) are cleaned up
|
|
1327
1310
|
// as a rollback
|
|
1328
|
-
const rollbackMode = row.status !== "installed"
|
|
1329
|
-
// A dependency install removed by a failed install's
|
|
1330
|
-
//
|
|
1331
|
-
const connectorRollback = rollbackMode ||
|
|
1332
|
-
ctx.reason === "plugin_install_rollback" ||
|
|
1333
|
-
ctx.reason === "plugin_upgrade_cleanup";
|
|
1311
|
+
const rollbackMode = row.status !== "installed";
|
|
1312
|
+
// A dependency install removed by a failed install's rollback removes what it created, like
|
|
1313
|
+
// the rolled-back install itself: it is a rollback, not a switch-off
|
|
1314
|
+
const connectorRollback = rollbackMode || ctx.reason === "plugin_install_rollback";
|
|
1334
1315
|
const comps = await t
|
|
1335
1316
|
.selectFrom("plugin_install_components")
|
|
1336
1317
|
.select(["kind", "ref", "created", "skill_version"])
|
|
@@ -1536,65 +1517,6 @@ let PluginInstaller = class PluginInstaller {
|
|
|
1536
1517
|
deploymentPending: false,
|
|
1537
1518
|
}));
|
|
1538
1519
|
}
|
|
1539
|
-
/**
|
|
1540
|
-
* Undoes the steps of an upgrade in the caller's transaction (the caller holds the org row lock),
|
|
1541
|
-
* in reverse order: components it created are removed (a dependency install by the uninstall
|
|
1542
|
-
* rules, an extension another enabled extension depends on is kept), the ledger rows it added
|
|
1543
|
-
* are deleted, and versions it added to skills are reverted (`revertVersionIn` reverts exactly
|
|
1544
|
-
* one version, and an upgrade adds at most one per skill). Returns the components removed (an
|
|
1545
|
-
* extension among them needs `afterDisable` once committed). Used when an upgrade fails and when
|
|
1546
|
-
* an interrupted one is cleaned up.
|
|
1547
|
-
*/
|
|
1548
|
-
async undoUpgradeIn(orgId, actor, installId, steps, reason) {
|
|
1549
|
-
const removed = [];
|
|
1550
|
-
const dropRow = (kind, ref) => this.db
|
|
1551
|
-
.deleteFrom("plugin_install_components")
|
|
1552
|
-
.where("install_id", "=", installId)
|
|
1553
|
-
.where("kind", "=", kind)
|
|
1554
|
-
.where("ref", "=", ref)
|
|
1555
|
-
.execute();
|
|
1556
|
-
for (const s of [...steps].reverse()) {
|
|
1557
|
-
if (s.op === "skill_version") {
|
|
1558
|
-
await this.skills.revertVersionIn(orgId, s.ref, s.version, actor, reason);
|
|
1559
|
-
continue;
|
|
1560
|
-
}
|
|
1561
|
-
if (s.op === "template_version") {
|
|
1562
|
-
await revertTemplateVersionIn(this.db, orgId, s.ref, s.version);
|
|
1563
|
-
continue;
|
|
1564
|
-
}
|
|
1565
|
-
if (s.op === "recorded") {
|
|
1566
|
-
await dropRow(s.kind, s.ref);
|
|
1567
|
-
continue;
|
|
1568
|
-
}
|
|
1569
|
-
if (s.kind === "plugin") {
|
|
1570
|
-
const sub = { removed: [], kept: [] };
|
|
1571
|
-
await dropRow(s.kind, s.ref);
|
|
1572
|
-
const outcome = await this.uninstallIn(orgId, actor, s.ref, {
|
|
1573
|
-
report: sub,
|
|
1574
|
-
removing: new Set([installId]),
|
|
1575
|
-
from: installId,
|
|
1576
|
-
authorize: false,
|
|
1577
|
-
reason,
|
|
1578
|
-
opts: {},
|
|
1579
|
-
});
|
|
1580
|
-
removed.push(...sub.removed.filter((r) => r.kind === "extension"));
|
|
1581
|
-
if (outcome === "removed")
|
|
1582
|
-
removed.push({ kind: "plugin", ref: s.ref });
|
|
1583
|
-
continue;
|
|
1584
|
-
}
|
|
1585
|
-
if (s.kind === "extension" &&
|
|
1586
|
-
(await this.orgConfigs.enabledDependents(orgId, s.ref)).length > 0) {
|
|
1587
|
-
// Another enabled extension needs it: kept, and stays this install's component
|
|
1588
|
-
continue;
|
|
1589
|
-
}
|
|
1590
|
-
const c = { kind: s.kind, ref: s.ref, created: true, skillVersion: null };
|
|
1591
|
-
if (await this.removeComponent(orgId, actor, c, reason)) {
|
|
1592
|
-
removed.push({ kind: s.kind, ref: s.ref });
|
|
1593
|
-
}
|
|
1594
|
-
await dropRow(s.kind, s.ref);
|
|
1595
|
-
}
|
|
1596
|
-
return removed;
|
|
1597
|
-
}
|
|
1598
1520
|
/**
|
|
1599
1521
|
* Installs the dependencies an installed plugin's version declares and the org lacks (rule 9),
|
|
1600
1522
|
* as the kernel (actor null): a platform update can add one. Each is recorded on the install
|
|
@@ -2094,9 +2016,6 @@ __decorate([
|
|
|
2094
2016
|
__decorate([
|
|
2095
2017
|
Transactional({ propagation: "mandatory" })
|
|
2096
2018
|
], PluginInstaller.prototype, "decideRemovalIn", null);
|
|
2097
|
-
__decorate([
|
|
2098
|
-
Transactional({ propagation: "mandatory" })
|
|
2099
|
-
], PluginInstaller.prototype, "undoUpgradeIn", null);
|
|
2100
2019
|
__decorate([
|
|
2101
2020
|
Transactional({ propagation: "requires_new" })
|
|
2102
2021
|
], PluginInstaller.prototype, "recordConnector", null);
|
|
@@ -2169,34 +2088,6 @@ export async function planSkillConflicts(db, orgId, plan) {
|
|
|
2169
2088
|
await visit(plan);
|
|
2170
2089
|
return out;
|
|
2171
2090
|
}
|
|
2172
|
-
const COMPONENT_KINDS = new Set([
|
|
2173
|
-
"extension",
|
|
2174
|
-
"connector",
|
|
2175
|
-
"skill",
|
|
2176
|
-
"plugin",
|
|
2177
|
-
"agent_template",
|
|
2178
|
-
]);
|
|
2179
|
-
/** The journaled steps of `plugin_installs.upgrade` (malformed entries are skipped). */
|
|
2180
|
-
export function journalEntries(upgrade) {
|
|
2181
|
-
const done = upgrade?.done;
|
|
2182
|
-
if (!Array.isArray(done))
|
|
2183
|
-
return [];
|
|
2184
|
-
const out = [];
|
|
2185
|
-
for (const e of done) {
|
|
2186
|
-
if (typeof e !== "object" || e === null || typeof e.ref !== "string")
|
|
2187
|
-
continue;
|
|
2188
|
-
if ((e.op === "skill_version" || e.op === "template_version") &&
|
|
2189
|
-
typeof e.version === "number") {
|
|
2190
|
-
out.push({ op: e.op, ref: e.ref, version: e.version });
|
|
2191
|
-
}
|
|
2192
|
-
else if ((e.op === "created" || e.op === "recorded") &&
|
|
2193
|
-
typeof e.kind === "string" &&
|
|
2194
|
-
COMPONENT_KINDS.has(e.kind)) {
|
|
2195
|
-
out.push({ op: e.op, kind: e.kind, ref: e.ref });
|
|
2196
|
-
}
|
|
2197
|
-
}
|
|
2198
|
-
return out;
|
|
2199
|
-
}
|
|
2200
2091
|
/** The org actions a plan needs: the union over the plugins it installs (spec §10). */
|
|
2201
2092
|
export function planActions(plan) {
|
|
2202
2093
|
const out = new Set(requiredActions(plan.manifest));
|
|
@@ -2226,36 +2117,3 @@ function orderByRequires(set) {
|
|
|
2226
2117
|
}
|
|
2227
2118
|
return placed;
|
|
2228
2119
|
}
|
|
2229
|
-
/**
|
|
2230
|
-
* Whether org row `id` (a skill or an agent template of the org) is linked without a pin to a live
|
|
2231
|
-
* platform row the org promoted when sharing it (ruling P3-3): owned by the org and from no plugin
|
|
2232
|
-
* (`catalog_item_id` null). A component of the org's own uploaded plugin is a plugin's, so its
|
|
2233
|
-
* install copies are removed and reverted as any plugin's.
|
|
2234
|
-
*/
|
|
2235
|
-
async function promotedOrgRow(db, orgId, kind, id) {
|
|
2236
|
-
const row = kind === "skill"
|
|
2237
|
-
? await db
|
|
2238
|
-
.selectFrom("skills as s")
|
|
2239
|
-
.innerJoin("platform_skills as p", "p.id", "s.platform_skill_id")
|
|
2240
|
-
.select("s.id")
|
|
2241
|
-
.where("s.id", "=", id)
|
|
2242
|
-
.where("s.org_id", "=", orgId)
|
|
2243
|
-
.where("s.pinned_version", "is", null)
|
|
2244
|
-
.where("p.owner_org_id", "=", orgId)
|
|
2245
|
-
// promoted, not an org plugin's component (which has its plugin, P3-2)
|
|
2246
|
-
.where("p.catalog_item_id", "is", null)
|
|
2247
|
-
.where("p.deleted_at", "is", null)
|
|
2248
|
-
.executeTakeFirst()
|
|
2249
|
-
: await db
|
|
2250
|
-
.selectFrom("agent_templates as a")
|
|
2251
|
-
.innerJoin("platform_agent_templates as p", "p.id", "a.platform_template_id")
|
|
2252
|
-
.select("a.id")
|
|
2253
|
-
.where("a.id", "=", id)
|
|
2254
|
-
.where("a.org_id", "=", orgId)
|
|
2255
|
-
.where("a.pinned_version", "is", null)
|
|
2256
|
-
.where("p.owner_org_id", "=", orgId)
|
|
2257
|
-
.where("p.catalog_item_id", "is", null)
|
|
2258
|
-
.where("p.deleted_at", "is", null)
|
|
2259
|
-
.executeTakeFirst();
|
|
2260
|
-
return row !== undefined;
|
|
2261
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AgentTemplate, type ConnectorTemplateFile, type ParsedTheme, type PluginManifest } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { ApiError } from "../errors.js";
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
3
|
+
import { type PackageTgzLimits, packagePath } from "../packages/tgz.js";
|
|
4
|
+
export { packagePath };
|
|
5
5
|
/**
|
|
6
6
|
* Reads a plugin tgz (spec §4.1): `package/.capybara-plugin/plugin.json` plus the skills, connector
|
|
7
7
|
* templates and extension it describes. The tgz is untrusted input and is unpacked by the extension
|
|
@@ -9,10 +9,6 @@ export { LEGACY_FORMAT_MESSAGE, packagePath };
|
|
|
9
9
|
* count, regular files only, safe paths under `package/`). No code from the package runs here; the extension's module graph is
|
|
10
10
|
* checked by `readExtensionPackage`. The checks after unpacking live in {@link readPluginFiles},
|
|
11
11
|
* shared with the git reader (`git-source.ts`), which reads the tree from a commit instead.
|
|
12
|
-
*
|
|
13
|
-
* A tgz in the pre-0.1.0 format (a `capybara` section in package.json, or `app.yaml`, and no
|
|
14
|
-
* plugin.json) is rejected first, with {@link LEGACY_FORMAT_MESSAGE}: there is no reader for the
|
|
15
|
-
* old formats.
|
|
16
12
|
*/
|
|
17
13
|
/**
|
|
18
14
|
* Codes of {@link PluginPackageError}: `theme.invalid` / `theme.unreadable` when the package's only
|
|
@@ -20,7 +16,7 @@ export { LEGACY_FORMAT_MESSAGE, packagePath };
|
|
|
20
16
|
* `client.undeclared` for an `extension.client` section whose manifest lacks
|
|
21
17
|
* `permissions.client: true` (client extensions spec §5.4: client code is always reviewed).
|
|
22
18
|
*/
|
|
23
|
-
export type PluginPackageErrorCode = "catalog.invalid_manifest" | "
|
|
19
|
+
export type PluginPackageErrorCode = "catalog.invalid_manifest" | "theme.invalid" | "theme.unreadable" | "client.undeclared";
|
|
24
20
|
/** The problems of one theme of a refused plugin (English; `unreadable:` lines for readability). */
|
|
25
21
|
export interface PluginThemeProblem {
|
|
26
22
|
/** The theme id (the file's base name). */
|
|
@@ -137,9 +133,8 @@ export declare const PLUGIN_ICON_MAX_BYTES: number;
|
|
|
137
133
|
export declare function iconProblem(path: string, data: Uint8Array): string | undefined;
|
|
138
134
|
/**
|
|
139
135
|
* Reads and validates a plugin tgz (see the file header). Invalid -> {@link PluginPackageError}:
|
|
140
|
-
* `catalog.
|
|
141
|
-
*
|
|
142
|
-
* problems stop at the first stage that fails).
|
|
136
|
+
* `catalog.invalid_manifest` listing every problem it can find, each naming the path it is about
|
|
137
|
+
* (unpacking and manifest parse problems stop at the first stage that fails).
|
|
143
138
|
*/
|
|
144
139
|
export declare function readPluginPackage(bytes: Uint8Array, opts: ReadPluginPackageOptions): Promise<PluginPackage>;
|
|
145
140
|
/** Options of {@link readPluginFiles}. */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { AGENT_TEMPLATE_LIMITS, CATALOG_ITEM_NAME_RE, CONNECTOR_TEMPLATE_LIMITS, hostSdkProblem, PLUGIN_MANIFEST_FILE, PLUGIN_MANIFEST_LIMITS, parseAgentTemplate, parseConnectorTemplateFile, parsePluginManifest, parseSkillMd, parseThemeFile, SKILL_ENTRY_FILE, setupGuideDocPath, setupGuideDocProblem, THEME_LIMITS, themeIdOf, validatePluginPackageJsonFor, validateSetupGuide, validateThemeAssets, } from "@capybara-hq/plugin-sdk";
|
|
3
3
|
import { ApiError } from "../errors.js";
|
|
4
|
-
import { HOST_ZOD_VERSION,
|
|
5
|
-
export {
|
|
4
|
+
import { HOST_ZOD_VERSION, PackageTgzError, packagePath, parsePackageJsonFile, unpackPackageTgz, } from "../packages/tgz.js";
|
|
5
|
+
export { packagePath };
|
|
6
6
|
/** The plugin package is invalid; `issues` lists the problems (English, shown to the admin). */
|
|
7
7
|
export class PluginPackageError extends Error {
|
|
8
8
|
code;
|
|
@@ -10,13 +10,11 @@ export class PluginPackageError extends Error {
|
|
|
10
10
|
/** The failing themes of a `theme.*` code. */
|
|
11
11
|
themes;
|
|
12
12
|
constructor(code, issues, themes) {
|
|
13
|
-
super(code === "
|
|
14
|
-
? (issues[0] ??
|
|
15
|
-
: code === "
|
|
16
|
-
?
|
|
17
|
-
:
|
|
18
|
-
? `Theme ${themes?.[0]?.theme ?? "?"} ${code === "theme.invalid" ? "is invalid" : "is not readable"}: ${issues[0] ?? "unknown problem"}`
|
|
19
|
-
: `Invalid plugin package: ${issues[0] ?? "unknown problem"}`);
|
|
13
|
+
super(code === "client.undeclared"
|
|
14
|
+
? (issues[0] ?? code)
|
|
15
|
+
: code === "theme.invalid" || code === "theme.unreadable"
|
|
16
|
+
? `Theme ${themes?.[0]?.theme ?? "?"} ${code === "theme.invalid" ? "is invalid" : "is not readable"}: ${issues[0] ?? "unknown problem"}`
|
|
17
|
+
: `Invalid plugin package: ${issues[0] ?? "unknown problem"}`);
|
|
20
18
|
this.name = "PluginPackageError";
|
|
21
19
|
this.code = code;
|
|
22
20
|
this.issues = issues;
|
|
@@ -105,7 +103,6 @@ export function iconProblem(path, data) {
|
|
|
105
103
|
return `${path} is not a UTF-8 SVG document`;
|
|
106
104
|
return /<svg[\s>/]/i.test(text) ? undefined : `${path} is not an SVG document`;
|
|
107
105
|
}
|
|
108
|
-
/** package.json parsed, or undefined when it is not valid (only used to name a legacy package). */
|
|
109
106
|
/**
|
|
110
107
|
* Client code the extension manifest does not declare (an `extension.client` section without
|
|
111
108
|
* `permissions.client: true`), read from the raw plugin.json before it is parsed, so the refusal
|
|
@@ -127,16 +124,6 @@ function clientUndeclared(text) {
|
|
|
127
124
|
return undefined;
|
|
128
125
|
return `${PLUGIN_MANIFEST_FILE}: extension.client ships client code, but the extension manifest does not declare permissions.client: true; client code must be declared so it is reviewed (capybara-plugin pack writes both)`;
|
|
129
126
|
}
|
|
130
|
-
const parsedOrUndefined = (data) => {
|
|
131
|
-
try {
|
|
132
|
-
return parsePackageJsonFile({ data });
|
|
133
|
-
}
|
|
134
|
-
catch (e) {
|
|
135
|
-
if (e instanceof PackageTgzError)
|
|
136
|
-
return undefined;
|
|
137
|
-
throw e;
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
127
|
const invalid = (issues) => {
|
|
141
128
|
throw new PluginPackageError("catalog.invalid_manifest", issues);
|
|
142
129
|
};
|
|
@@ -173,9 +160,8 @@ function hostSdkIssues(manifest, hostSdkVersion) {
|
|
|
173
160
|
}
|
|
174
161
|
/**
|
|
175
162
|
* Reads and validates a plugin tgz (see the file header). Invalid -> {@link PluginPackageError}:
|
|
176
|
-
* `catalog.
|
|
177
|
-
*
|
|
178
|
-
* problems stop at the first stage that fails).
|
|
163
|
+
* `catalog.invalid_manifest` listing every problem it can find, each naming the path it is about
|
|
164
|
+
* (unpacking and manifest parse problems stop at the first stage that fails).
|
|
179
165
|
*/
|
|
180
166
|
export async function readPluginPackage(bytes, opts) {
|
|
181
167
|
const unpacked = await step(() => unpackPackageTgz(bytes, opts));
|
|
@@ -225,20 +211,13 @@ function fallbackManifest(files, opts) {
|
|
|
225
211
|
export function readPluginFiles(files, opts) {
|
|
226
212
|
const pj = files.get("package.json");
|
|
227
213
|
const manifestBytes = files.get(PLUGIN_MANIFEST_FILE);
|
|
228
|
-
if (manifestBytes === undefined) {
|
|
229
|
-
// The old formats are recognised only to say so; nothing in them is read. app.yaml is checked
|
|
230
|
-
// before package.json is parsed, so an old bundle with a broken package.json is still legacy.
|
|
231
|
-
const pkg = pj && parsedOrUndefined(pj);
|
|
232
|
-
if (files.has("app.yaml") || (isObj(pkg) && pkg.capybara !== undefined)) {
|
|
233
|
-
const who = isObj(pkg) && typeof pkg.name === "string" ? `Package ${pkg.name}` : "The package";
|
|
234
|
-
throw new PluginPackageError("catalog.legacy_format", [`${who} ${LEGACY_FORMAT_MESSAGE}`]);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
214
|
const fallback = manifestBytes === undefined ? fallbackManifest(files, opts) : undefined;
|
|
238
215
|
if (manifestBytes === undefined && fallback === undefined) {
|
|
239
216
|
if (pj)
|
|
240
217
|
stepSync(() => parsePackageJsonFile({ data: pj }));
|
|
241
|
-
return invalid([
|
|
218
|
+
return invalid([
|
|
219
|
+
`${PLUGIN_MANIFEST_FILE} not found in the package: a plugin package carries its manifest at that path (build it with \`capybara-plugin pack\`)`,
|
|
220
|
+
]);
|
|
242
221
|
}
|
|
243
222
|
const packageJson = pj === undefined && !opts.requirePackageJson
|
|
244
223
|
? undefined
|
|
@@ -40,6 +40,7 @@ import { ConnectorsService } from "../tools/connectors.service.js";
|
|
|
40
40
|
import { dirDigest, getPath, readCatalogAgentTemplates, readCatalogTemplates, readCatalogThemes, setPath, skillFilesDigest, templatePluginProblem, themeAssetsDigest, } from "./catalog-content.js";
|
|
41
41
|
import { markVersionApplied, versionUsable } from "./catalog-items.js";
|
|
42
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";
|
|
43
44
|
import { CatalogItemLock } from "./locks.js";
|
|
44
45
|
import { itemPendingError, itemRemovedError } from "./ownership.js";
|
|
45
46
|
import { PlanStale, PlatformComponents } from "./platform-components.js";
|
|
@@ -603,13 +604,13 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
603
604
|
}
|
|
604
605
|
}
|
|
605
606
|
// One version for the deployment: every live org install of the plugin moves with it (one
|
|
606
|
-
// still installing too
|
|
607
|
-
//
|
|
607
|
+
// still installing too; an install marked installed later records the platform version
|
|
608
|
+
// current at its commit, PluginInstaller.markInstalled)
|
|
608
609
|
await t
|
|
609
610
|
.updateTable("plugin_installs")
|
|
610
611
|
.set({ version: diff.to.version, error: null })
|
|
611
612
|
.where("item_id", "=", itemId)
|
|
612
|
-
.where("status", "in", [
|
|
613
|
+
.where("status", "in", [...LIVE_INSTALL_STATUSES])
|
|
613
614
|
.execute();
|
|
614
615
|
if (owner !== undefined || confirmPending !== undefined) {
|
|
615
616
|
// An org's version becomes its latest once applied or confirmed (ruling P3-34)
|
|
@@ -1462,7 +1463,7 @@ let PlatformPluginUpdater = class PlatformPluginUpdater {
|
|
|
1462
1463
|
.select("a.org_id")
|
|
1463
1464
|
.distinct()
|
|
1464
1465
|
.where("a.item_id", "=", itemId)
|
|
1465
|
-
.where("a.status", "in", [
|
|
1466
|
+
.where("a.status", "in", [...LIVE_INSTALL_STATUSES])
|
|
1466
1467
|
.where("o.deleted_at", "is", null)
|
|
1467
1468
|
.orderBy("a.org_id")
|
|
1468
1469
|
.execute();
|
|
@@ -2,58 +2,58 @@ import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
|
2
2
|
import type { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
3
3
|
/**
|
|
4
4
|
* The plugin scope sync's jobs as the outbox owes them (transactional outbox spec §8.1): a leaf
|
|
5
|
-
* module (type imports only), so the import confirm (`PluginImport`, below the scope service)
|
|
6
|
-
*
|
|
5
|
+
* module (type imports only), so the import confirm (`PluginImport`, below the scope service), the
|
|
6
|
+
* extension host's deploy (`ExtensionAdminOps`, `ExtensionAdmin`) and the CLI owe them without the
|
|
7
|
+
* sync. `scope-sync.ts` (the consumer side) re-exports these names.
|
|
7
8
|
*/
|
|
8
9
|
/** The scope sync queue (no `:` in the name). */
|
|
9
10
|
export declare const PLUGIN_SCOPE_QUEUE = "cap-kernel-plugin-scope";
|
|
10
|
-
/** The job
|
|
11
|
+
/** The job fanning one item out to every org: one {@link SCOPE_CHUNK_JOB} per org chunk. */
|
|
11
12
|
export declare const SCOPE_ITEM_JOB = "scope-item";
|
|
13
|
+
/** The job converging one item in one chunk of orgs (at most {@link SCOPE_ORG_CHUNK} of them). */
|
|
14
|
+
export declare const SCOPE_CHUNK_JOB = "scope-item-chunk";
|
|
12
15
|
/** The job converging every item in one org. */
|
|
13
16
|
export declare const SCOPE_ORG_JOB = "scope-org";
|
|
17
|
+
/** How many orgs one chunk job converges. */
|
|
18
|
+
export declare const SCOPE_ORG_CHUNK = 100;
|
|
14
19
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* retries it with its backoff) while the extension is not enabled on the deployment yet.
|
|
20
|
+
* Optional provider (a test seam): the chunk size instead of {@link SCOPE_ORG_CHUNK}, so a test
|
|
21
|
+
* with a few orgs fans out to several chunks.
|
|
18
22
|
*/
|
|
19
|
-
export declare const
|
|
20
|
-
/** How long after the confirmation's commit the backstop runs (the deploy has finished by then). */
|
|
21
|
-
export declare const SCOPE_BACKSTOP_DELAY_MS: number;
|
|
23
|
+
export declare const SCOPE_ORG_CHUNK_SIZE: unique symbol;
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
+
* One item job per owing transaction (`xact`: its PostgreSQL transaction id, so two owes in one
|
|
26
|
+
* transaction are one job, and a later transaction's job is never swallowed by an earlier one
|
|
27
|
+
* still running; no `:`: item ids are UUIDs).
|
|
25
28
|
*/
|
|
26
|
-
export declare const
|
|
27
|
-
/**
|
|
28
|
-
export declare const
|
|
29
|
-
/** The backstop of the item job of a scope version (distinct from the immediate one). */
|
|
30
|
-
export declare const scopeBackstopJobId: (itemId: string, version: number) => string;
|
|
29
|
+
export declare const scopeItemJobId: (itemId: string, xact: string) => string;
|
|
30
|
+
/** Chunk `n` of an item job (deterministic: a redelivered item job adds the same chunks). */
|
|
31
|
+
export declare const scopeChunkJobId: (itemJobId: string, n: number) => string;
|
|
31
32
|
/** One org job at a time per org. */
|
|
32
33
|
export declare const scopeOrgJobId: (orgId: string) => string;
|
|
33
|
-
/**
|
|
34
|
-
* The delayed retry `n` of an item job whose extension this replica had not loaded yet (ruling
|
|
35
|
-
* P3-38); deterministic, so replicas deferring the same item add it once.
|
|
36
|
-
*/
|
|
37
|
-
export declare const scopeRetryJobId: (itemId: string, version: number, n: number) => string;
|
|
38
|
-
/**
|
|
39
|
-
* The job's data. `retry`: the item job's delayed retry number (P3-38). `backstop`: a
|
|
40
|
-
* {@link SCOPE_BACKSTOP_JOB}.
|
|
41
|
-
*/
|
|
34
|
+
/** The job's data. */
|
|
42
35
|
export type ScopeJob = {
|
|
43
36
|
kind: "item";
|
|
44
37
|
itemId: string;
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
} | {
|
|
39
|
+
kind: "chunk";
|
|
40
|
+
itemId: string;
|
|
41
|
+
orgIds: string[];
|
|
47
42
|
} | {
|
|
48
43
|
kind: "org";
|
|
49
44
|
orgId: string;
|
|
50
45
|
};
|
|
51
46
|
/**
|
|
52
|
-
* Owes the item's scope sync in the transaction in context,
|
|
53
|
-
*
|
|
54
|
-
|
|
47
|
+
* Owes the item's scope sync in the transaction in context, one job per transaction (see
|
|
48
|
+
* {@link scopeItemJobId}). A missing item owes nothing.
|
|
49
|
+
*/
|
|
50
|
+
export declare function oweScopeItem(outbox: Pick<OutboxService, "add">, db: KernelSchemaDb, itemId: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Owes the scope sync of the live catalog item of an extension (its plugin, by name; at most one
|
|
53
|
+
* live item has a name) in the transaction that deploys it: the extension became enabled, a new
|
|
54
|
+
* version of an enabled one was installed, or its permissions were approved while enabled (or
|
|
55
|
+
* config-declared). The sync then installs it where its scope wants it on; a replica that has not
|
|
56
|
+
* loaded the extension yet fails the chunk job, and BullMQ retries it. A builtin item (on
|
|
57
|
+
* everywhere through its required extension) owes nothing.
|
|
55
58
|
*/
|
|
56
|
-
export declare function
|
|
57
|
-
backstop?: boolean;
|
|
58
|
-
backstopDelayMs?: number;
|
|
59
|
-
}): Promise<void>;
|
|
59
|
+
export declare function oweDeployedExtensionSync(outbox: Pick<OutboxService, "add">, db: KernelSchemaDb, extensionName: string): Promise<void>;
|
|
@@ -1,65 +1,78 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
1
2
|
/**
|
|
2
3
|
* The plugin scope sync's jobs as the outbox owes them (transactional outbox spec §8.1): a leaf
|
|
3
|
-
* module (type imports only), so the import confirm (`PluginImport`, below the scope service)
|
|
4
|
-
*
|
|
4
|
+
* module (type imports only), so the import confirm (`PluginImport`, below the scope service), the
|
|
5
|
+
* extension host's deploy (`ExtensionAdminOps`, `ExtensionAdmin`) and the CLI owe them without the
|
|
6
|
+
* sync. `scope-sync.ts` (the consumer side) re-exports these names.
|
|
5
7
|
*/
|
|
6
8
|
/** The scope sync queue (no `:` in the name). */
|
|
7
9
|
export const PLUGIN_SCOPE_QUEUE = "cap-kernel-plugin-scope";
|
|
8
|
-
/** The job
|
|
10
|
+
/** The job fanning one item out to every org: one {@link SCOPE_CHUNK_JOB} per org chunk. */
|
|
9
11
|
export const SCOPE_ITEM_JOB = "scope-item";
|
|
12
|
+
/** The job converging one item in one chunk of orgs (at most {@link SCOPE_ORG_CHUNK} of them). */
|
|
13
|
+
export const SCOPE_CHUNK_JOB = "scope-item-chunk";
|
|
10
14
|
/** The job converging every item in one org. */
|
|
11
15
|
export const SCOPE_ORG_JOB = "scope-org";
|
|
16
|
+
/** How many orgs one chunk job converges. */
|
|
17
|
+
export const SCOPE_ORG_CHUNK = 100;
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* retries it with its backoff) while the extension is not enabled on the deployment yet.
|
|
19
|
+
* Optional provider (a test seam): the chunk size instead of {@link SCOPE_ORG_CHUNK}, so a test
|
|
20
|
+
* with a few orgs fans out to several chunks.
|
|
16
21
|
*/
|
|
17
|
-
export const
|
|
18
|
-
/** How long after the confirmation's commit the backstop runs (the deploy has finished by then). */
|
|
19
|
-
export const SCOPE_BACKSTOP_DELAY_MS = 5 * 60_000;
|
|
22
|
+
export const SCOPE_ORG_CHUNK_SIZE = Symbol("SCOPE_ORG_CHUNK_SIZE");
|
|
20
23
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
24
|
+
* One item job per owing transaction (`xact`: its PostgreSQL transaction id, so two owes in one
|
|
25
|
+
* transaction are one job, and a later transaction's job is never swallowed by an earlier one
|
|
26
|
+
* still running; no `:`: item ids are UUIDs).
|
|
23
27
|
*/
|
|
24
|
-
export const
|
|
25
|
-
/**
|
|
26
|
-
export const
|
|
27
|
-
/** The backstop of the item job of a scope version (distinct from the immediate one). */
|
|
28
|
-
export const scopeBackstopJobId = (itemId, version) => `${scopeItemJobId(itemId, version)}-backstop`;
|
|
28
|
+
export const scopeItemJobId = (itemId, xact) => `scope-item-${itemId}-x${xact}`;
|
|
29
|
+
/** Chunk `n` of an item job (deterministic: a redelivered item job adds the same chunks). */
|
|
30
|
+
export const scopeChunkJobId = (itemJobId, n) => `${itemJobId}-c${n}`;
|
|
29
31
|
/** One org job at a time per org. */
|
|
30
32
|
export const scopeOrgJobId = (orgId) => `scope-org-${orgId}`;
|
|
33
|
+
/** The id of the transaction in context (assigned now if it has none yet). */
|
|
34
|
+
async function currentXact(db) {
|
|
35
|
+
const r = await sql `SELECT pg_current_xact_id()::text AS xact`.execute(db);
|
|
36
|
+
const xact = r.rows[0]?.xact;
|
|
37
|
+
if (xact === undefined)
|
|
38
|
+
throw new Error("no transaction id");
|
|
39
|
+
return xact;
|
|
40
|
+
}
|
|
31
41
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
export const scopeRetryJobId = (itemId, version, n) => `scope-item-${itemId}-${version}-r${n}`;
|
|
36
|
-
/**
|
|
37
|
-
* Owes the item's scope sync in the transaction in context, once per scope version (read in that
|
|
38
|
-
* transaction, so after its own bump); `backstop` owes the delayed backstop instead, due
|
|
39
|
-
* `backstopDelayMs` later (default {@link SCOPE_BACKSTOP_DELAY_MS}). A missing item owes nothing.
|
|
42
|
+
* Owes the item's scope sync in the transaction in context, one job per transaction (see
|
|
43
|
+
* {@link scopeItemJobId}). A missing item owes nothing.
|
|
40
44
|
*/
|
|
41
|
-
export async function oweScopeItem(outbox, db, itemId
|
|
45
|
+
export async function oweScopeItem(outbox, db, itemId) {
|
|
42
46
|
const row = await db
|
|
43
47
|
.selectFrom("catalog_items")
|
|
44
|
-
.select("
|
|
48
|
+
.select("id")
|
|
45
49
|
.where("id", "=", itemId)
|
|
46
50
|
.executeTakeFirst();
|
|
47
51
|
if (!row)
|
|
48
52
|
return;
|
|
49
|
-
if (opts.backstop === true) {
|
|
50
|
-
await outbox.add({
|
|
51
|
-
queue: PLUGIN_SCOPE_QUEUE,
|
|
52
|
-
name: SCOPE_BACKSTOP_JOB,
|
|
53
|
-
jobId: scopeBackstopJobId(itemId, row.scope_version),
|
|
54
|
-
data: { kind: "item", itemId, backstop: true },
|
|
55
|
-
runAt: new Date(Date.now() + (opts.backstopDelayMs ?? SCOPE_BACKSTOP_DELAY_MS)),
|
|
56
|
-
});
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
53
|
await outbox.add({
|
|
60
54
|
queue: PLUGIN_SCOPE_QUEUE,
|
|
61
55
|
name: SCOPE_ITEM_JOB,
|
|
62
|
-
jobId: scopeItemJobId(itemId,
|
|
56
|
+
jobId: scopeItemJobId(itemId, await currentXact(db)),
|
|
63
57
|
data: { kind: "item", itemId },
|
|
64
58
|
});
|
|
65
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Owes the scope sync of the live catalog item of an extension (its plugin, by name; at most one
|
|
62
|
+
* live item has a name) in the transaction that deploys it: the extension became enabled, a new
|
|
63
|
+
* version of an enabled one was installed, or its permissions were approved while enabled (or
|
|
64
|
+
* config-declared). The sync then installs it where its scope wants it on; a replica that has not
|
|
65
|
+
* loaded the extension yet fails the chunk job, and BullMQ retries it. A builtin item (on
|
|
66
|
+
* everywhere through its required extension) owes nothing.
|
|
67
|
+
*/
|
|
68
|
+
export async function oweDeployedExtensionSync(outbox, db, extensionName) {
|
|
69
|
+
const item = await db
|
|
70
|
+
.selectFrom("catalog_items")
|
|
71
|
+
.select("id")
|
|
72
|
+
.where("name", "=", extensionName)
|
|
73
|
+
.where("deleted_at", "is", null)
|
|
74
|
+
.where("builtin", "=", false)
|
|
75
|
+
.executeTakeFirst();
|
|
76
|
+
if (item)
|
|
77
|
+
await oweScopeItem(outbox, db, item.id);
|
|
78
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
2
|
/**
|
|
3
3
|
* Adds one org to a `named` item's list in the caller's transaction (the caller holds the item row
|
|
4
|
-
* `FOR UPDATE`):
|
|
4
|
+
* `FOR UPDATE`): audits `catalog.scope_changed` the way a scope change
|
|
5
5
|
* does (`from` / `to` with the sorted lists; `requestId` when a request asked for it). Nothing is
|
|
6
6
|
* written when the item is not `named` (or builtin) or the org is listed already. Returns whether
|
|
7
7
|
* the list changed; the caller enqueues the item's scope sync after the commit. Adding an org other
|
|
@@ -4,7 +4,7 @@ import { notifyItemShared } from "../inbox/org-notices.js";
|
|
|
4
4
|
import { assertShareable, shareGate } from "./ownership.js";
|
|
5
5
|
/**
|
|
6
6
|
* Adds one org to a `named` item's list in the caller's transaction (the caller holds the item row
|
|
7
|
-
* `FOR UPDATE`):
|
|
7
|
+
* `FOR UPDATE`): audits `catalog.scope_changed` the way a scope change
|
|
8
8
|
* does (`from` / `to` with the sorted lists; `requestId` when a request asked for it). Nothing is
|
|
9
9
|
* written when the item is not `named` (or builtin) or the org is listed already. Returns whether
|
|
10
10
|
* the list changed; the caller enqueues the item's scope sync after the commit. Adding an org other
|
|
@@ -36,7 +36,6 @@ export async function addScopeOrg(db, actor, item, orgId, opts = {}) {
|
|
|
36
36
|
await db
|
|
37
37
|
.updateTable("catalog_items")
|
|
38
38
|
.set({
|
|
39
|
-
scope_version: sql `scope_version + 1`,
|
|
40
39
|
updated_at: sql `now()`,
|
|
41
40
|
})
|
|
42
41
|
.where("id", "=", item.id)
|