@capybara-hq/kernel 0.1.0-rc.142 → 0.1.0-rc.143

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/agents/agents.module.js +3 -0
  2. package/dist/agents/agents.service.js +1 -1
  3. package/dist/agents/org-templates.d.ts +3 -1
  4. package/dist/agents/org-templates.js +7 -3
  5. package/dist/agents/pending-connector-requests.d.ts +10 -4
  6. package/dist/agents/pending-connector-requests.js +29 -7
  7. package/dist/automations/events/acceptance.d.ts +6 -1
  8. package/dist/automations/events/acceptance.js +30 -11
  9. package/dist/catalog/catalog-import.module.js +3 -0
  10. package/dist/catalog/catalog-scope.service.d.ts +3 -1
  11. package/dist/catalog/catalog-scope.service.js +11 -7
  12. package/dist/catalog/catalog.module.js +3 -0
  13. package/dist/catalog/catalog.service.d.ts +3 -1
  14. package/dist/catalog/catalog.service.js +8 -4
  15. package/dist/catalog/component-promotion.d.ts +3 -1
  16. package/dist/catalog/component-promotion.js +7 -3
  17. package/dist/catalog/component-scope.service.d.ts +3 -1
  18. package/dist/catalog/component-scope.service.js +7 -3
  19. package/dist/catalog/enable-requests.d.ts +10 -8
  20. package/dist/catalog/enable-requests.js +40 -21
  21. package/dist/catalog/owned-items.d.ts +3 -1
  22. package/dist/catalog/owned-items.js +13 -9
  23. package/dist/catalog/platform-components.d.ts +6 -1
  24. package/dist/catalog/platform-components.js +9 -3
  25. package/dist/catalog/plugin-connectors.d.ts +8 -4
  26. package/dist/catalog/plugin-connectors.js +12 -6
  27. package/dist/catalog/plugin-import.d.ts +3 -1
  28. package/dist/catalog/plugin-import.js +14 -5
  29. package/dist/catalog/plugin-install.d.ts +3 -1
  30. package/dist/catalog/plugin-install.js +8 -4
  31. package/dist/catalog/plugin-upgrade.d.ts +3 -1
  32. package/dist/catalog/plugin-upgrade.js +8 -4
  33. package/dist/catalog/request-hints.d.ts +19 -0
  34. package/dist/catalog/request-hints.js +34 -0
  35. package/dist/catalog/request-rules.d.ts +9 -5
  36. package/dist/catalog/request-rules.js +16 -9
  37. package/dist/catalog/requests.service.d.ts +3 -1
  38. package/dist/catalog/requests.service.js +28 -9
  39. package/dist/catalog/scope-orgs.d.ts +2 -1
  40. package/dist/catalog/scope-orgs.js +2 -2
  41. package/dist/catalog/scope-sync.d.ts +3 -1
  42. package/dist/catalog/scope-sync.js +12 -2
  43. package/dist/catalog/scope-writer.d.ts +6 -3
  44. package/dist/catalog/scope-writer.js +28 -10
  45. package/dist/catalog/unshare.d.ts +3 -2
  46. package/dist/catalog/unshare.js +4 -4
  47. package/dist/config/schema.d.ts +3 -0
  48. package/dist/config/schema.js +30 -0
  49. package/dist/db/migrator.js +36 -0
  50. package/dist/extensions/admin-ops.d.ts +6 -1
  51. package/dist/extensions/admin-ops.js +17 -4
  52. package/dist/extensions/deployment-config.d.ts +6 -1
  53. package/dist/extensions/deployment-config.js +13 -2
  54. package/dist/extensions/extensions.module.js +3 -0
  55. package/dist/extensions/org-config.d.ts +3 -1
  56. package/dist/extensions/org-config.js +13 -4
  57. package/dist/extensions/org-overrides.d.ts +6 -1
  58. package/dist/extensions/org-overrides.js +13 -2
  59. package/dist/inbox/inbox-items.service.d.ts +6 -1
  60. package/dist/inbox/inbox-items.service.js +29 -10
  61. package/dist/inbox/inbox.module.js +3 -0
  62. package/dist/inbox/inbox.service.d.ts +3 -1
  63. package/dist/inbox/inbox.service.js +9 -2
  64. package/dist/inbox/org-notices.d.ts +4 -3
  65. package/dist/inbox/org-notices.js +9 -6
  66. package/dist/inbox/platform-inbox.service.d.ts +3 -1
  67. package/dist/inbox/platform-inbox.service.js +11 -3
  68. package/dist/inbox/platform-notices.d.ts +3 -2
  69. package/dist/inbox/platform-notices.js +10 -4
  70. package/dist/infra/config/kernel-config.service.js +4 -1
  71. package/dist/invalidation/audiences.d.ts +32 -0
  72. package/dist/invalidation/audiences.js +43 -0
  73. package/dist/invalidation/hints.d.ts +6 -0
  74. package/dist/invalidation/hints.js +7 -1
  75. package/dist/invalidation/invalidation-hints.d.ts +12 -1
  76. package/dist/invalidation/invalidation-hints.js +46 -5
  77. package/dist/invalidation/invalidation-hints.module.d.ts +2 -0
  78. package/dist/invalidation/invalidation-hints.module.js +4 -1
  79. package/dist/invalidation/me-stream.d.ts +1 -11
  80. package/dist/invalidation/me-stream.js +12 -41
  81. package/dist/invalidation/org-intent-bridge.d.ts +18 -0
  82. package/dist/invalidation/org-intent-bridge.js +46 -0
  83. package/dist/models/enablement.d.ts +3 -1
  84. package/dist/models/enablement.js +25 -5
  85. package/dist/orgs/offboarding.d.ts +3 -1
  86. package/dist/orgs/offboarding.js +7 -3
  87. package/dist/orgs/orgs.module.js +3 -0
  88. package/dist/orgs/orgs.service.d.ts +3 -1
  89. package/dist/orgs/orgs.service.js +7 -3
  90. package/dist/push/delivery.d.ts +3 -1
  91. package/dist/push/delivery.js +7 -3
  92. package/dist/push/push-processor.js +8 -1
  93. package/dist/runtime/stream-limit.d.ts +13 -0
  94. package/dist/runtime/stream-limit.js +40 -0
  95. package/dist/runtime/stream.controller.d.ts +2 -0
  96. package/dist/runtime/stream.controller.js +2 -0
  97. package/dist/runtime/stream.d.ts +1 -0
  98. package/dist/runtime/stream.js +15 -6
  99. package/dist/sandbox/permission-authority.module.js +6 -1
  100. package/dist/sandbox/permission-transitions.d.ts +3 -1
  101. package/dist/sandbox/permission-transitions.js +17 -2
  102. package/dist/skills/agent-skills.service.d.ts +6 -1
  103. package/dist/skills/agent-skills.service.js +12 -3
  104. package/dist/skills/changes.service.d.ts +6 -1
  105. package/dist/skills/changes.service.js +11 -3
  106. package/dist/skills/conversation-catalog.d.ts +3 -0
  107. package/dist/skills/conversation-catalog.js +2 -0
  108. package/dist/skills/skills.module.js +3 -0
  109. package/dist/skills/skills.service.d.ts +3 -1
  110. package/dist/skills/skills.service.js +8 -4
  111. package/dist/tools/approvals.service.d.ts +12 -1
  112. package/dist/tools/approvals.service.js +36 -9
  113. package/dist/tools/connectors.service.d.ts +3 -1
  114. package/dist/tools/connectors.service.js +29 -7
  115. package/dist/tools/tools.module.js +3 -0
  116. package/dist/ui/admin-ui.controller.d.ts +3 -1
  117. package/dist/ui/admin-ui.controller.js +3 -1
  118. package/dist/ui/ui-stream.d.ts +2 -0
  119. package/dist/ui/ui-stream.js +20 -6
  120. package/dist/ui/views.controller.d.ts +4 -2
  121. package/dist/ui/views.controller.js +4 -2
  122. package/package.json +1 -1
@@ -12,7 +12,7 @@ import { addNamedPluginOrg } from "./scope-writer.js";
12
12
  * than its owner to an org-owned item that is not shareable -> 409 `catalog.not_shareable` (the
13
13
  * share gate, ruling P3-16, read on the caller's locked row).
14
14
  */
15
- export async function addScopeOrg(db, actor, item, orgId, opts = {}) {
15
+ export async function addScopeOrg(db, hints, actor, item, orgId, opts = {}) {
16
16
  if (item.builtin || item.scope !== "named")
17
17
  return false;
18
18
  if (!shareGate(item) && orgId !== item.owner_org_id) {
@@ -55,7 +55,7 @@ export async function addScopeOrg(db, actor, item, orgId, opts = {}) {
55
55
  ...(opts.requestId !== undefined && { requestId: opts.requestId }),
56
56
  },
57
57
  });
58
- await notifyItemShared(db, item.owner_org_id, { kind: "plugin", id: item.id }, item.name, [
58
+ await notifyItemShared(db, hints, item.owner_org_id, { kind: "plugin", id: item.id }, item.name, [
59
59
  orgId,
60
60
  ]);
61
61
  return true;
@@ -5,6 +5,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
5
5
  import { TransactionHost } from "../infra/database/transaction-host.js";
6
6
  import { LockService } from "../infra/lock/lock.service.js";
7
7
  import { OutboxService } from "../infra/outbox/outbox.service.js";
8
+ import { type HintPublisher } from "../invalidation/audiences.js";
8
9
  import type { KernelLogger } from "../log.js";
9
10
  import { OrgLock } from "../orgs/org-lock.js";
10
11
  import { type EffectJob } from "./effect-work.js";
@@ -25,7 +26,8 @@ export declare class PluginScopeSync {
25
26
  private readonly locks;
26
27
  private readonly log;
27
28
  readonly txHost: TransactionHost;
28
- constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add" | "addMany">, installer: PluginInstaller, registry: ExtensionRegistry, config: KernelConfigService, effective: Pick<EffectiveConfigs, "get">, orgLock: OrgLock, locks: LockService, log: KernelLogger, txHost: TransactionHost);
29
+ private readonly hints;
30
+ constructor(kdb: KernelDb, outbox: Pick<OutboxService, "add" | "addMany">, installer: PluginInstaller, registry: ExtensionRegistry, config: KernelConfigService, effective: Pick<EffectiveConfigs, "get">, orgLock: OrgLock, locks: LockService, log: KernelLogger, txHost: TransactionHost, hints: HintPublisher);
29
31
  private get db();
30
32
  enqueueItem(itemId: string, previousOrgs?: readonly string[]): Promise<void>;
31
33
  enqueueOrg(orgId: string): Promise<void>;
@@ -23,6 +23,8 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
23
23
  import { LockService } from "../infra/lock/lock.service.js";
24
24
  import { OutboxService } from "../infra/outbox/outbox.service.js";
25
25
  import { KERNEL_LOGGER } from "../infra/tokens.js";
26
+ import { publishCapabilities } from "../invalidation/audiences.js";
27
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
26
28
  import { OrgLock } from "../orgs/org-lock.js";
27
29
  import { effectGeneration, oweEffectWork, recoverEffectWork, } from "./effect-work.js";
28
30
  import { isUsable } from "./ownership.js";
@@ -50,7 +52,8 @@ let PluginScopeSync = class PluginScopeSync {
50
52
  locks;
51
53
  log;
52
54
  txHost;
53
- constructor(kdb, outbox, installer, registry, config, effective, orgLock, locks, log, txHost) {
55
+ hints;
56
+ constructor(kdb, outbox, installer, registry, config, effective, orgLock, locks, log, txHost, hints) {
54
57
  this.kdb = kdb;
55
58
  this.outbox = outbox;
56
59
  this.installer = installer;
@@ -61,6 +64,7 @@ let PluginScopeSync = class PluginScopeSync {
61
64
  this.locks = locks;
62
65
  this.log = log;
63
66
  this.txHost = txHost;
67
+ this.hints = hints;
64
68
  }
65
69
  get db() {
66
70
  return this.kdb.db;
@@ -165,6 +169,9 @@ let PluginScopeSync = class PluginScopeSync {
165
169
  if (!(await this.settleGeneration(itemId, orgId, generation))) {
166
170
  throw new SupersededEffect();
167
171
  }
172
+ // the pair's generation settled: the org's capabilities changed (one hint per owed pair, the
173
+ // org set the writer computed)
174
+ publishCapabilities(this.hints, [orgId]);
168
175
  await this.db
169
176
  .updateTable("plugin_installs")
170
177
  .set({ status: "on", error: null })
@@ -389,6 +396,8 @@ let PluginScopeSync = class PluginScopeSync {
389
396
  return;
390
397
  if (!(await this.settleGeneration(itemId, orgId, generation)))
391
398
  return;
399
+ // the pair settled as failed: the org's catalog shows the failure (and the intent it settles)
400
+ publishCapabilities(this.hints, [orgId]);
392
401
  const { op, code } = failure;
393
402
  const error = {
394
403
  generation: generation ?? "0",
@@ -458,6 +467,7 @@ PluginScopeSync = __decorate([
458
467
  __param(6, Inject(OrgLock)),
459
468
  __param(7, Inject(LockService)),
460
469
  __param(8, Inject(KERNEL_LOGGER)),
461
- __param(9, Inject(TransactionHost))
470
+ __param(9, Inject(TransactionHost)),
471
+ __param(10, Inject(InvalidationHints))
462
472
  ], PluginScopeSync);
463
473
  export { PluginScopeSync };
@@ -7,6 +7,7 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
7
7
  import { XactLock } from "../infra/database/xact-lock.js";
8
8
  import { KernelEvents } from "../infra/events/kernel-events.js";
9
9
  import { OutboxService } from "../infra/outbox/outbox.service.js";
10
+ import { type HintPublisher } from "../invalidation/audiences.js";
10
11
  import type { ComponentKind } from "./component-state.js";
11
12
  import type { RequestActorOpts } from "./request-rules.js";
12
13
  import type { PluginScope } from "./scope.js";
@@ -44,9 +45,10 @@ type ScopeListChange = {
44
45
  /**
45
46
  * Apply a typed scope change in the caller's transaction and under its target lock. Every scope
46
47
  * write re-checks the pending enable requests of the subject in every org
47
- * ({@link reconcileEnableRequestsOf}), so no caller can narrow a scope and leave a stale request.
48
+ * ({@link reconcileEnableRequestsOf}), so no caller can narrow a scope and leave a stale request;
49
+ * `hints` publishes the requests it settles.
48
50
  */
49
- export declare function writeScope(db: KernelSchemaDb, change: ScopeListChange): Promise<void>;
51
+ export declare function writeScope(db: KernelSchemaDb, hints: HintPublisher, change: ScopeListChange): Promise<void>;
50
52
  /** Extend a named plugin scope under its item lock. */
51
53
  export declare function addNamedPluginOrg(db: KernelSchemaDb, itemId: string, orgId: string): Promise<boolean>;
52
54
  type ScopeConfirmation = {
@@ -77,7 +79,8 @@ export declare class ScopeWriter {
77
79
  private readonly adminLock;
78
80
  readonly txHost: TransactionHost;
79
81
  private readonly events;
80
- constructor(kdb: KernelDb, installLock: PluginInstallLock, xactLock: XactLock, outbox: OutboxService, adminLock: SuperAdminLock, txHost: TransactionHost, events: KernelEvents);
82
+ private readonly hints;
83
+ constructor(kdb: KernelDb, installLock: PluginInstallLock, xactLock: XactLock, outbox: OutboxService, adminLock: SuperAdminLock, txHost: TransactionHost, events: KernelEvents, hints: HintPublisher);
81
84
  platformChange<Result, Conflict>(actor: string, confirmation: ScopeConfirmation, prepare: () => Promise<PreparedScopeWrite<Result, Conflict> | undefined>): Promise<Result | undefined>;
82
85
  /** Persist the scope and its named list together after platform confirmation. */
83
86
  replaceScope(change: ScopeListChange): Promise<void>;
@@ -20,6 +20,8 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
20
20
  import { XactLock } from "../infra/database/xact-lock.js";
21
21
  import { KernelEvents } from "../infra/events/kernel-events.js";
22
22
  import { OutboxService } from "../infra/outbox/outbox.service.js";
23
+ import { publishCapabilities, publishPlatformCapabilities, } from "../invalidation/audiences.js";
24
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
23
25
  import { EFFECT_CANDIDATES_LOCK, oweEffectWork } from "./effect-work.js";
24
26
  import { cancelEnableRequestsOfBundle, reconcileEnableRequestsOf, settleEnableRequests, } from "./enable-requests.js";
25
27
  export const COMPONENT_SCOPE_TABLE = {
@@ -49,11 +51,12 @@ export async function writeComponentSwitch(db, subject, orgId, enabled, actor) {
49
51
  /**
50
52
  * Apply a typed scope change in the caller's transaction and under its target lock. Every scope
51
53
  * write re-checks the pending enable requests of the subject in every org
52
- * ({@link reconcileEnableRequestsOf}), so no caller can narrow a scope and leave a stale request.
54
+ * ({@link reconcileEnableRequestsOf}), so no caller can narrow a scope and leave a stale request;
55
+ * `hints` publishes the requests it settles.
53
56
  */
54
- export async function writeScope(db, change) {
57
+ export async function writeScope(db, hints, change) {
55
58
  await writeScopeRows(db, change);
56
- await reconcileEnableRequestsOf(db, { kind: change.kind, id: change.id }, null);
59
+ await reconcileEnableRequestsOf(db, hints, { kind: change.kind, id: change.id }, null);
57
60
  }
58
61
  async function writeScopeRows(db, change) {
59
62
  const { kind, id, scope, orgs } = change;
@@ -114,7 +117,8 @@ let ScopeWriter = class ScopeWriter {
114
117
  adminLock;
115
118
  txHost;
116
119
  events;
117
- constructor(kdb, installLock, xactLock, outbox, adminLock, txHost, events) {
120
+ hints;
121
+ constructor(kdb, installLock, xactLock, outbox, adminLock, txHost, events, hints) {
118
122
  this.kdb = kdb;
119
123
  this.installLock = installLock;
120
124
  this.xactLock = xactLock;
@@ -122,6 +126,7 @@ let ScopeWriter = class ScopeWriter {
122
126
  this.adminLock = adminLock;
123
127
  this.txHost = txHost;
124
128
  this.events = events;
129
+ this.hints = hints;
125
130
  }
126
131
  async platformChange(actor, confirmation, prepare) {
127
132
  await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
@@ -145,13 +150,17 @@ let ScopeWriter = class ScopeWriter {
145
150
  .execute()).map((row) => row.org_id)
146
151
  : [];
147
152
  // (writeScope re-checks the pending enable requests of the subject)
148
- await writeScope(db, change);
153
+ await writeScope(db, this.hints, change);
149
154
  if (change.kind === "connector_template") {
150
155
  await this.oweConnectorTemplate(change.id, { previousOrgs });
151
156
  }
152
157
  if (change.kind === "plugin" || change.kind === "connector_template") {
153
158
  this.refreshIsolatedOrgIntent();
154
159
  }
160
+ // a skill or agent template owes no effect pairs (no affected-org set): `platform-caps`
161
+ if (change.kind === "skill" || change.kind === "agent_template") {
162
+ publishPlatformCapabilities(this.hints);
163
+ }
155
164
  }
156
165
  /** Persist deployment enablement after platform confirmation. */
157
166
  async setDisabled(subject, disabled) {
@@ -163,10 +172,13 @@ let ScopeWriter = class ScopeWriter {
163
172
  .execute();
164
173
  if (subject.kind === "connector_template")
165
174
  await this.oweConnectorTemplate(subject.id, {});
166
- await reconcileEnableRequestsOf(this.kdb.db, subject, null);
175
+ await reconcileEnableRequestsOf(this.kdb.db, this.hints, subject, null);
167
176
  if ((subject.kind === "plugin" && disabled) || subject.kind === "connector_template") {
168
177
  this.refreshIsolatedOrgIntent();
169
178
  }
179
+ if (subject.kind === "skill" || subject.kind === "agent_template") {
180
+ publishPlatformCapabilities(this.hints);
181
+ }
170
182
  }
171
183
  /**
172
184
  * Store local intent under the caller's transaction and org lock. The org's pending enable
@@ -209,10 +221,10 @@ let ScopeWriter = class ScopeWriter {
209
221
  }
210
222
  await oweEffectWork(this.outbox, db, { itemIds: [subject.id], orgId, previousOrgs: [orgId] });
211
223
  if (enabled) {
212
- await settleEnableRequests(db, orgId, { kind: "plugin", id: subject.id }, actor, opts);
224
+ await settleEnableRequests(db, this.hints, orgId, { kind: "plugin", id: subject.id }, actor, opts);
213
225
  }
214
226
  else
215
- await cancelEnableRequestsOfBundle(db, orgId, subject.id, actor);
227
+ await cancelEnableRequestsOfBundle(db, this.hints, orgId, subject.id, actor);
216
228
  }
217
229
  else {
218
230
  await writeComponentSwitch(db, { kind: subject.kind, id: subject.id }, orgId, enabled, actor);
@@ -220,12 +232,17 @@ let ScopeWriter = class ScopeWriter {
220
232
  await this.oweConnectorTemplate(subject.id, { orgId, previousOrgs: [orgId] });
221
233
  }
222
234
  if (enabled && subject.kind !== "theme") {
223
- await settleEnableRequests(db, orgId, { kind: subject.kind, id: subject.id }, actor, opts);
235
+ await settleEnableRequests(db, this.hints, orgId, { kind: subject.kind, id: subject.id }, actor, opts);
224
236
  }
225
237
  }
226
238
  if ((subject.kind === "plugin" && !enabled) || subject.kind === "connector_template") {
239
+ // (its `catalog.org-intent-changed` publishes the org's `capabilities` hint too)
227
240
  this.refreshIsolatedOrgIntent(orgId);
228
241
  }
242
+ else {
243
+ // the org's committed intent changed: its members' pickers refetch
244
+ publishCapabilities(this.hints, [orgId]);
245
+ }
229
246
  }
230
247
  async oweConnectorTemplate(id, scope) {
231
248
  const db = this.kdb.db;
@@ -263,6 +280,7 @@ ScopeWriter = __decorate([
263
280
  __param(3, Inject(OutboxService)),
264
281
  __param(4, Inject(SuperAdminLock)),
265
282
  __param(5, Inject(TransactionHost)),
266
- __param(6, Inject(KernelEvents))
283
+ __param(6, Inject(KernelEvents)),
284
+ __param(7, Inject(InvalidationHints))
267
285
  ], ScopeWriter);
268
286
  export { ScopeWriter };
@@ -1,4 +1,5 @@
1
1
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
+ import type { HintPublisher } from "../invalidation/audiences.js";
2
3
  import { type ComponentRow } from "./component-state.js";
3
4
  import type { PluginScope } from "./scope.js";
4
5
  /**
@@ -7,7 +8,7 @@ import type { PluginScope } from "./scope.js";
7
8
  * `catalog.scope_changed`; returns whether the scope changed (the caller enqueues the item's
8
9
  * scope sync after the commit).
9
10
  */
10
- export declare function narrowItemOnUnshare(db: KernelSchemaDb, actor: string | null, item: {
11
+ export declare function narrowItemOnUnshare(db: KernelSchemaDb, hints: HintPublisher, actor: string | null, item: {
11
12
  id: string;
12
13
  name: string;
13
14
  scope: PluginScope;
@@ -18,4 +19,4 @@ export declare function narrowItemOnUnshare(db: KernelSchemaDb, actor: string |
18
19
  * to `named` = owner + the live orgs where it is on now ({@link componentOn}). A component that
19
20
  * follows its plugin is narrowed with the plugin. Audits `component.scope_changed`.
20
21
  */
21
- export declare function narrowComponentOnUnshare(db: KernelSchemaDb, actor: string | null, c: ComponentRow): Promise<boolean>;
22
+ export declare function narrowComponentOnUnshare(db: KernelSchemaDb, hints: HintPublisher, actor: string | null, c: ComponentRow): Promise<boolean>;
@@ -12,7 +12,7 @@ async function liveOrgIds(db) {
12
12
  * `catalog.scope_changed`; returns whether the scope changed (the caller enqueues the item's
13
13
  * scope sync after the commit).
14
14
  */
15
- export async function narrowItemOnUnshare(db, actor, item) {
15
+ export async function narrowItemOnUnshare(db, hints, actor, item) {
16
16
  const ownerOrgId = item.owner_org_id;
17
17
  if (ownerOrgId === null || item.scope === "named")
18
18
  return false;
@@ -37,7 +37,7 @@ export async function narrowItemOnUnshare(db, actor, item) {
37
37
  ...[...installs, ...switches].map((r) => r.org_id).filter((o) => live.has(o)),
38
38
  ]),
39
39
  ].sort();
40
- await writeScope(db, { kind: "plugin", id: item.id, scope: "named", orgs: kept });
40
+ await writeScope(db, hints, { kind: "plugin", id: item.id, scope: "named", orgs: kept });
41
41
  return kept;
42
42
  });
43
43
  await audit(db, {
@@ -58,7 +58,7 @@ export async function narrowItemOnUnshare(db, actor, item) {
58
58
  * to `named` = owner + the live orgs where it is on now ({@link componentOn}). A component that
59
59
  * follows its plugin is narrowed with the plugin. Audits `component.scope_changed`.
60
60
  */
61
- export async function narrowComponentOnUnshare(db, actor, c) {
61
+ export async function narrowComponentOnUnshare(db, hints, actor, c) {
62
62
  const ownerOrgId = c.ownerOrgId;
63
63
  if (ownerOrgId === null || c.scopeMode !== "own" || c.scope === "named")
64
64
  return false;
@@ -67,7 +67,7 @@ export async function narrowComponentOnUnshare(db, actor, c) {
67
67
  const st = await loadScopeState(db, c.kind, [c]);
68
68
  const on = (await liveOrgIds(db)).filter((o) => componentOn(c, pluginFactsOf(st, c.itemId, o), listedIn(st, c.id, o), switchOf(st, c.id, o)));
69
69
  const kept = [...new Set([ownerOrgId, ...on])].sort();
70
- await writeScope(db, {
70
+ await writeScope(db, hints, {
71
71
  kind: c.kind,
72
72
  id: c.id,
73
73
  scopeMode: "own",
@@ -176,6 +176,9 @@ export declare const KernelConfigSchema: z.ZodObject<{
176
176
  sseHeartbeatMs: z.ZodDefault<z.ZodNumber>;
177
177
  sseRecheckMs: z.ZodDefault<z.ZodNumber>;
178
178
  meStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
179
+ orgUiStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
180
+ platformUiStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
181
+ conversationStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
179
182
  }, z.core.$strict>>;
180
183
  tools: z.ZodDefault<z.ZodObject<{
181
184
  timeoutMs: z.ZodDefault<z.ZodNumber>;
@@ -993,6 +993,33 @@ export const KernelConfigSchema = z.strictObject({
993
993
  hot: true,
994
994
  description: "Maximum concurrent account invalidation streams (GET /api/v1/orgs/:orgId/me/stream) per account on one replica; a new stream over the limit closes that account's oldest stream on the replica",
995
995
  })),
996
+ orgUiStreamMaxPerAccount: z
997
+ .number()
998
+ .int()
999
+ .positive()
1000
+ .default(8)
1001
+ .meta(meta({
1002
+ hot: true,
1003
+ description: "Maximum concurrent org UI streams per account on one replica; a new stream over the limit closes that account's oldest stream of the same family on the replica",
1004
+ })),
1005
+ platformUiStreamMaxPerAccount: z
1006
+ .number()
1007
+ .int()
1008
+ .positive()
1009
+ .default(8)
1010
+ .meta(meta({
1011
+ hot: true,
1012
+ description: "Maximum concurrent platform UI streams per account on one replica; a new stream over the limit closes that account's oldest stream of the same family on the replica",
1013
+ })),
1014
+ conversationStreamMaxPerAccount: z
1015
+ .number()
1016
+ .int()
1017
+ .positive()
1018
+ .default(16)
1019
+ .meta(meta({
1020
+ hot: true,
1021
+ description: "Maximum concurrent conversation streams per account on one replica; a new stream over the limit closes that account's oldest stream of the same family on the replica",
1022
+ })),
996
1023
  })
997
1024
  .default({
998
1025
  maxSteps: 0,
@@ -1008,6 +1035,9 @@ export const KernelConfigSchema = z.strictObject({
1008
1035
  sseHeartbeatMs: 15000,
1009
1036
  sseRecheckMs: 60000,
1010
1037
  meStreamMaxPerAccount: 8,
1038
+ orgUiStreamMaxPerAccount: 8,
1039
+ platformUiStreamMaxPerAccount: 8,
1040
+ conversationStreamMaxPerAccount: 16,
1011
1041
  }),
1012
1042
  tools: z
1013
1043
  .strictObject({
@@ -48,6 +48,37 @@ export async function canMigrateKernel(db) {
48
48
  return privileges.can_create && (privileges.owns_schema ?? true);
49
49
  }
50
50
  const migrateHint = "Run capybara migrate with CAPYBARA_DB__MIGRATION_URL set to the schema owner URL for split roles.";
51
+ const eventOrgContract = "0219_event_org_constraint_check.sql";
52
+ /** The rc.159 worker is the last release that can backfill events before 0219. */
53
+ async function checkEventOrgBackfill(client) {
54
+ await client.query("begin read only");
55
+ try {
56
+ await client.query("set local row_security = off");
57
+ const { rows: [table], } = await client.query(`
58
+ select exists (
59
+ select from pg_catalog.pg_attribute
60
+ where attrelid = relation and attname = 'org_id' and attnum > 0 and not attisdropped
61
+ ) as has_org_id
62
+ from (select pg_catalog.to_regclass('capybara.conversation_events') as relation) events
63
+ where relation is not null
64
+ `);
65
+ if (!table)
66
+ return;
67
+ // Before 0215, every existing event would receive a null org_id from the expansion.
68
+ const filter = table.has_org_id ? "where org_id is null" : "";
69
+ const { rows: [state], } = await client.query(`select exists (select from capybara.conversation_events ${filter}) as incomplete`);
70
+ if (state?.incomplete) {
71
+ throw new Error("Migration 0219 requires the conversation event organization backfill. " +
72
+ "Upgrade to Capybara 0.1.0-rc.159 and run its worker after older writers have drained. " +
73
+ "Wait for EventOrgBackfillJob to finish, then verify " +
74
+ "SELECT count(*) FROM capybara.conversation_events WHERE org_id IS NULL returns 0 " +
75
+ "before rerunning capybara migrate.");
76
+ }
77
+ }
78
+ finally {
79
+ await client.query("rollback");
80
+ }
81
+ }
51
82
  /** Verify the files expected by this binary without taking a migration lock or writing the journal.
52
83
  * Extra entries are valid when a newer release has already migrated a shared database.
53
84
  */
@@ -178,6 +209,11 @@ export async function migrate(connectionString, owner, opts = {}) {
178
209
  throw new Error(`Migration ${schema}/${f.name} is out of order: a higher-numbered migration (${String(highest).padStart(4, "0")}) is already applied`);
179
210
  }
180
211
  }
212
+ if (schema === "capybara" &&
213
+ !done.has(eventOrgContract) &&
214
+ files.some((f) => f.name === eventOrgContract)) {
215
+ await checkEventOrgBackfill(client);
216
+ }
181
217
  const applied = [];
182
218
  for (const f of files) {
183
219
  if (done.has(f.name))
@@ -5,6 +5,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
7
7
  import { OutboxService } from "../infra/outbox/outbox.service.js";
8
+ import { type HintPublisher } from "../invalidation/audiences.js";
8
9
  import type { KernelLogger } from "../log.js";
9
10
  import { OrgLock } from "../orgs/org-lock.js";
10
11
  import { ExtensionAdmin, type PublishBus } from "./admin-view.js";
@@ -85,6 +86,8 @@ export declare class ExtensionAdminOps {
85
86
  private readonly singleProvider;
86
87
  /** The plugin scope sync a deploy owes (`oweDeployedExtensionSync`). */
87
88
  private readonly outbox;
89
+ /** A platform enable, disable or new version publishes `platform-caps` after the commit. */
90
+ private readonly hints;
88
91
  constructor(kdb: KernelDb, txHost: TransactionHost,
89
92
  /** The super admin lock (identity/super-admin.ts): joins the transaction. */
90
93
  adminLock: SuperAdminLock,
@@ -111,7 +114,9 @@ export declare class ExtensionAdminOps {
111
114
  /** One enabled provider per single-provider extension point (checked in the enable). */
112
115
  singleProvider: SingleProviderGuard,
113
116
  /** The plugin scope sync a deploy owes (`oweDeployedExtensionSync`). */
114
- outbox: Pick<OutboxService, "add" | "addMany">);
117
+ outbox: Pick<OutboxService, "add" | "addMany">,
118
+ /** A platform enable, disable or new version publishes `platform-caps` after the commit. */
119
+ hints: HintPublisher);
115
120
  private get db();
116
121
  /**
117
122
  * New install or version change (upgrade / downgrade): the install record points at package
@@ -30,6 +30,8 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
30
30
  import { Transactional } from "../infra/database/transactional.decorator.js";
31
31
  import { OutboxService } from "../infra/outbox/outbox.service.js";
32
32
  import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
33
+ import { publishPlatformCapabilities } from "../invalidation/audiences.js";
34
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
33
35
  import { OrgLock } from "../orgs/org-lock.js";
34
36
  import { ExtensionAdmin } from "./admin-view.js";
35
37
  import { ExtensionBlobs } from "./blobs.js";
@@ -57,6 +59,7 @@ let ExtensionAdminOps = class ExtensionAdminOps {
57
59
  log;
58
60
  singleProvider;
59
61
  outbox;
62
+ hints;
60
63
  constructor(kdb, txHost,
61
64
  /** The super admin lock (identity/super-admin.ts): joins the transaction. */
62
65
  adminLock,
@@ -83,7 +86,9 @@ let ExtensionAdminOps = class ExtensionAdminOps {
83
86
  /** One enabled provider per single-provider extension point (checked in the enable). */
84
87
  singleProvider,
85
88
  /** The plugin scope sync a deploy owes (`oweDeployedExtensionSync`). */
86
- outbox) {
89
+ outbox,
90
+ /** A platform enable, disable or new version publishes `platform-caps` after the commit. */
91
+ hints) {
87
92
  this.kdb = kdb;
88
93
  this.txHost = txHost;
89
94
  this.adminLock = adminLock;
@@ -99,6 +104,7 @@ let ExtensionAdminOps = class ExtensionAdminOps {
99
104
  this.log = log;
100
105
  this.singleProvider = singleProvider;
101
106
  this.outbox = outbox;
107
+ this.hints = hints;
102
108
  }
103
109
  get db() {
104
110
  return this.kdb.db;
@@ -298,6 +304,7 @@ let ExtensionAdminOps = class ExtensionAdminOps {
298
304
  .set({ desired_state: "disabled", enabled_at: null })
299
305
  .where("name", "=", name)
300
306
  .execute();
307
+ publishPlatformCapabilities(this.hints);
301
308
  await this.audit(actor, actorTokenId, "extension.disabled", name, row.version, row.sha256, {
302
309
  singleProvider: block,
303
310
  ...ownerDetail(opts.owner),
@@ -340,9 +347,12 @@ let ExtensionAdminOps = class ExtensionAdminOps {
340
347
  await oweHostServicesStop(db, this.outbox, { extension: name });
341
348
  return { changed: true, state: "disabled", leftDisabled };
342
349
  }
343
- // A new version of an enabled extension is a deploy: it owes its plugin's scope sync
344
- if (row?.desired_state === "enabled")
350
+ // A new version of an enabled extension is a deploy: it owes its plugin's scope sync, and
351
+ // what it offers every org may change (`platform-caps`)
352
+ if (row?.desired_state === "enabled") {
353
+ publishPlatformCapabilities(this.hints);
345
354
  await oweDeployedExtensionSync(this.outbox, db, name);
355
+ }
346
356
  return { changed: true, state: row?.desired_state ?? "disabled" };
347
357
  }
348
358
  /**
@@ -452,6 +462,8 @@ let ExtensionAdminOps = class ExtensionAdminOps {
452
462
  })
453
463
  .where("name", "=", name)
454
464
  .execute();
465
+ // switched on or off for the whole platform: every org's members refetch
466
+ publishPlatformCapabilities(this.hints);
455
467
  if (state === "disabled") {
456
468
  await revokeSiteGrantsOfExtensionEverywhere(db, name);
457
469
  // its host services stop on every machine that runs one (local agents spec, call 5)
@@ -576,7 +588,8 @@ ExtensionAdminOps = __decorate([
576
588
  __param(11, Inject(ExtensionLifecycle)),
577
589
  __param(12, Inject(KERNEL_LOGGER)),
578
590
  __param(13, Inject(SingleProviderGuard)),
579
- __param(14, Inject(OutboxService))
591
+ __param(14, Inject(OutboxService)),
592
+ __param(15, Inject(InvalidationHints))
580
593
  ], ExtensionAdminOps);
581
594
  export { ExtensionAdminOps };
582
595
  /**
@@ -8,6 +8,7 @@ import { SuperAdminLock } from "../identity/super-admin.js";
8
8
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
9
9
  import { KernelDb } from "../infra/database/kernel-db.js";
10
10
  import { TransactionHost } from "../infra/database/transaction-host.js";
11
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
11
12
  import type { KernelLogger } from "../log.js";
12
13
  import type { PublishBus } from "./admin-view.js";
13
14
  import { type ConfigIssue } from "./config-issues.js";
@@ -116,6 +117,8 @@ export declare class ExtensionDeploymentConfigService {
116
117
  private readonly bus;
117
118
  private readonly log;
118
119
  private readonly displayNames;
120
+ /** A saved or cleared config publishes `platform-caps` after it applied here. */
121
+ private readonly hints;
119
122
  /** Where each startup-config field comes from (see `extensionConfigSources`); those fields are read-only. */
120
123
  private readonly sources;
121
124
  constructor(kdb: KernelDb, txHost: TransactionHost,
@@ -128,7 +131,9 @@ export declare class ExtensionDeploymentConfigService {
128
131
  /** Applies a saved config on this replica at once (other replicas through the bus). */
129
132
  lifecycle: ExtensionLifecycle,
130
133
  /** Publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} after a save (a failure only warns). */
131
- bus: PublishBus, log: KernelLogger, options: Pick<KernelAppOptions, "env" | "extensionConfigSources">, displayNames: ExtensionDisplayNames);
134
+ bus: PublishBus, log: KernelLogger, options: Pick<KernelAppOptions, "env" | "extensionConfigSources">, displayNames: ExtensionDisplayNames,
135
+ /** A saved or cleared config publishes `platform-caps` after it applied here. */
136
+ hints: Pick<InvalidationHints, "publish">);
132
137
  private get db();
133
138
  /** The startup config's `extensionConfig` (file / Nacos merged with env). */
134
139
  private fileConfig;
@@ -21,6 +21,8 @@ import { KernelDb } from "../infra/database/kernel-db.js";
21
21
  import { TransactionHost } from "../infra/database/transaction-host.js";
22
22
  import { Transactional } from "../infra/database/transactional.decorator.js";
23
23
  import { KERNEL_BUS, KERNEL_LOGGER, KEYRING } from "../infra/tokens.js";
24
+ import { PLATFORM_CAPS_TOPIC } from "../invalidation/hints.js";
25
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
24
26
  import { KERNEL_APP_OPTIONS } from "../lifecycle/tokens.js";
25
27
  import { toIssues } from "./config-issues.js";
26
28
  import { checkConfigUi, configMessages, hintedSecretPaths, safeConfigFormSchema, } from "./config-json-schema.js";
@@ -63,6 +65,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
63
65
  bus;
64
66
  log;
65
67
  displayNames;
68
+ hints;
66
69
  /** Where each startup-config field comes from (see `extensionConfigSources`); those fields are read-only. */
67
70
  sources;
68
71
  constructor(kdb, txHost,
@@ -75,7 +78,9 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
75
78
  /** Applies a saved config on this replica at once (other replicas through the bus). */
76
79
  lifecycle,
77
80
  /** Publishes {@link PLUGIN_DEPLOYMENT_CONFIG_TOPIC} after a save (a failure only warns). */
78
- bus, log, options, displayNames) {
81
+ bus, log, options, displayNames,
82
+ /** A saved or cleared config publishes `platform-caps` after it applied here. */
83
+ hints) {
79
84
  this.kdb = kdb;
80
85
  this.txHost = txHost;
81
86
  this.adminLock = adminLock;
@@ -88,6 +93,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
88
93
  this.bus = bus;
89
94
  this.log = log;
90
95
  this.displayNames = displayNames;
96
+ this.hints = hints;
91
97
  const env = options.env ?? process.env;
92
98
  this.sources =
93
99
  options.extensionConfigSources ??
@@ -194,6 +200,9 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
194
200
  err,
195
201
  });
196
202
  }
203
+ // the config may move whether orgs can call the extension (needs config): every org's
204
+ // members refetch (already after the commit)
205
+ await this.hints.publish([PLATFORM_CAPS_TOPIC], { kind: "capabilities" });
197
206
  };
198
207
  // Inside a caller's transaction (a Platform write applying the person's sealed values) the
199
208
  // save is not committed yet: replicas re-read only after the commit
@@ -283,6 +292,7 @@ let ExtensionDeploymentConfigService = class ExtensionDeploymentConfigService {
283
292
  err,
284
293
  });
285
294
  }
295
+ await this.hints.publish([PLATFORM_CAPS_TOPIC], { kind: "capabilities" });
286
296
  });
287
297
  }
288
298
  /**
@@ -517,7 +527,8 @@ ExtensionDeploymentConfigService = __decorate([
517
527
  __param(9, Inject(KERNEL_BUS)),
518
528
  __param(10, Inject(KERNEL_LOGGER)),
519
529
  __param(11, Inject(KERNEL_APP_OPTIONS)),
520
- __param(12, Inject(ExtensionDisplayNames))
530
+ __param(12, Inject(ExtensionDisplayNames)),
531
+ __param(13, Inject(InvalidationHints))
521
532
  ], ExtensionDeploymentConfigService);
522
533
  export { ExtensionDeploymentConfigService };
523
534
  /** The org level of each top-level key: from the zod schema, else the package's form schema. */
@@ -12,6 +12,7 @@ import { ConfiguredExtensionDbIdentity } from "../db/extension-db.js";
12
12
  import { DialInRelayModule } from "../dial-in/relay.module.js";
13
13
  import { SuperAdminLockModule } from "../identity/super-admin.js";
14
14
  import { InboxItemsModule } from "../inbox/inbox-items.service.js";
15
+ import { InvalidationHintsModule } from "../invalidation/invalidation-hints.module.js";
15
16
  import { ModelsModule } from "../models/models.module.js";
16
17
  import { OrgNetworkAllowancesModule } from "../orgs/network-allowances.service.js";
17
18
  import { OrgLockModule } from "../orgs/org-lock.js";
@@ -50,6 +51,8 @@ let ExtensionsModule = class ExtensionsModule {
50
51
  ExtensionsModule = __decorate([
51
52
  Module({
52
53
  imports: [
54
+ // invalidation hints its writers publish after their commit
55
+ InvalidationHintsModule,
53
56
  ExtensionRegistryModule,
54
57
  // one provider's candidacy for a point, shared with the conversation access check
55
58
  ExtensionPointServingModule,
@@ -5,6 +5,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
5
5
  import { TransactionHost } from "../infra/database/transaction-host.js";
6
6
  import { KernelEvents } from "../infra/events/kernel-events.js";
7
7
  import { OutboxService } from "../infra/outbox/outbox.service.js";
8
+ import { type HintPublisher } from "../invalidation/audiences.js";
8
9
  import { OrgLock } from "../orgs/org-lock.js";
9
10
  import { EffectiveConfigs } from "./effective-config.js";
10
11
  import { ExtensionHost } from "./host.js";
@@ -137,6 +138,7 @@ export declare class OrgExtensionConfigs {
137
138
  private readonly availability;
138
139
  /** Owes the org's template connector ensure when an extension is switched on (ruling R27). */
139
140
  private readonly outbox;
141
+ private readonly hints;
140
142
  constructor(installLock: PluginInstallLock, kdb: KernelDb, txHost: TransactionHost, host: ExtensionHost,
141
143
  /** The org row lock (orgs/org-lock.ts): joins the transaction. */
142
144
  orgLock: OrgLock,
@@ -149,7 +151,7 @@ export declare class OrgExtensionConfigs {
149
151
  /** Why an installed extension is not loaded (`status` / `reason` of the unavailable ones). */
150
152
  availability: ExtensionAvailability,
151
153
  /** Owes the org's template connector ensure when an extension is switched on (ruling R27). */
152
- outbox: Pick<OutboxService, "add">);
154
+ outbox: Pick<OutboxService, "add">, hints: HintPublisher);
153
155
  /** The kernel-schema handle of the current transaction. */
154
156
  private get db();
155
157
  /** After a write committed: a disabled extension's channel connections drop at once. */