@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
@@ -4,6 +4,7 @@ import { PluginGuides } from "../extensions/plugin-guides.js";
4
4
  import { SuperAdminLock } from "../identity/super-admin.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
6
  import { TransactionHost } from "../infra/database/transaction-host.js";
7
+ import type { HintPublisher } from "../invalidation/audiences.js";
7
8
  import { OrgLock } from "../orgs/org-lock.js";
8
9
  import type { OrgRole } from "../orgs/roles.js";
9
10
  import { type ThemeSwatch } from "../themes/theme-state.js";
@@ -259,6 +260,7 @@ export declare class ComponentScopeService {
259
260
  private readonly guides;
260
261
  /** A connector template switched on where its plugin is installed gets its connector. */
261
262
  private readonly installer;
263
+ private readonly hints;
262
264
  constructor(kdb: KernelDb, adminLock: SuperAdminLock, scopeWriter: ScopeWriter,
263
265
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
264
266
  orgLock: OrgLock,
@@ -267,7 +269,7 @@ export declare class ComponentScopeService {
267
269
  /** The connector templates' setup guides (the org list's `guide`). */
268
270
  guides: Pick<PluginGuides, "templateGuides">,
269
271
  /** A connector template switched on where its plugin is installed gets its connector. */
270
- installer: PluginInstaller);
272
+ installer: PluginInstaller, hints: HintPublisher);
271
273
  private get db();
272
274
  /**
273
275
  * What the admin routes act on (ruling P3-23): the platform component `id`, an org row the org
@@ -19,6 +19,7 @@ import { notifyItemShared } from "../inbox/org-notices.js";
19
19
  import { KernelDb } from "../infra/database/kernel-db.js";
20
20
  import { TransactionHost } from "../infra/database/transaction-host.js";
21
21
  import { Transactional } from "../infra/database/transactional.decorator.js";
22
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
22
23
  import { OrgLock } from "../orgs/org-lock.js";
23
24
  import { themeDefinitions, themeSwatches } from "../themes/theme-state.js";
24
25
  import { assertNotPlatformDefault, platformDefaultThemeId, themesPreview, } from "../themes/theme-usage.js";
@@ -131,6 +132,7 @@ let ComponentScopeService = class ComponentScopeService {
131
132
  txHost;
132
133
  guides;
133
134
  installer;
135
+ hints;
134
136
  constructor(kdb, adminLock, scopeWriter,
135
137
  /** The org row lock (orgs/org-lock.ts): joins the caller's transaction. */
136
138
  orgLock,
@@ -139,7 +141,7 @@ let ComponentScopeService = class ComponentScopeService {
139
141
  /** The connector templates' setup guides (the org list's `guide`). */
140
142
  guides,
141
143
  /** A connector template switched on where its plugin is installed gets its connector. */
142
- installer) {
144
+ installer, hints) {
143
145
  this.kdb = kdb;
144
146
  this.adminLock = adminLock;
145
147
  this.scopeWriter = scopeWriter;
@@ -148,6 +150,7 @@ let ComponentScopeService = class ComponentScopeService {
148
150
  this.txHost = txHost;
149
151
  this.guides = guides;
150
152
  this.installer = installer;
153
+ this.hints = hints;
151
154
  }
152
155
  get db() {
153
156
  return this.kdb.db;
@@ -701,7 +704,7 @@ let ComponentScopeService = class ComponentScopeService {
701
704
  if (t.scopeMode === "own" && kind !== "connector_template" && kind !== "theme") {
702
705
  const shared = newlySharedWith(before, t);
703
706
  if (shared === "all_orgs" || shared.length > 0) {
704
- await notifyItemShared(this.db, c.ownerOrgId, { kind, id }, c.name, shared);
707
+ await notifyItemShared(this.db, this.hints, c.ownerOrgId, { kind, id }, c.name, shared);
705
708
  }
706
709
  }
707
710
  await audit(this.db, {
@@ -1085,7 +1088,8 @@ ComponentScopeService = __decorate([
1085
1088
  __param(4, Inject(ComponentPromotion)),
1086
1089
  __param(5, Inject(TransactionHost)),
1087
1090
  __param(6, Inject(PluginGuides)),
1088
- __param(7, Inject(PluginInstaller))
1091
+ __param(7, Inject(PluginInstaller)),
1092
+ __param(8, Inject(InvalidationHints))
1089
1093
  ], ComponentScopeService);
1090
1094
  export { ComponentScopeService };
1091
1095
  /** Whether `c` is the platform default theme `uiTheme` (locked on in every org, themes spec §7). */
@@ -1,5 +1,6 @@
1
1
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
2
  import { ApiError } from "../errors.js";
3
+ import type { HintPublisher } from "../invalidation/audiences.js";
3
4
  import { type OrgRole } from "../orgs/roles.js";
4
5
  import { type ComponentKind } from "./component-state.js";
5
6
  import { type EnableTarget } from "./enable-targets.js";
@@ -118,9 +119,10 @@ interface Settler {
118
119
  * the requester's subject is usable (a `cancelReason: "target_changed"` cancellation otherwise),
119
120
  * and each follower's own outcome is recorded in `detail.followers` for their notice. Audits
120
121
  * each row under its own id. Returns the outcome of every row it settled (rows kept pending under
121
- * `reconcile` are absent).
122
+ * `reconcile` are absent). Every row it writes publishes `requests` after the commit
123
+ * ({@link publishRequestHints}: its requester, its followers, the org's admins).
122
124
  */
123
- export declare function settleRequestRows(db: KernelSchemaDb, orgId: string, rows: readonly {
125
+ export declare function settleRequestRows(db: KernelSchemaDb, hints: HintPublisher, orgId: string, rows: readonly {
124
126
  id: string;
125
127
  detail: unknown;
126
128
  item_id?: string | null;
@@ -140,7 +142,7 @@ export declare function settleRequestRows(db: KernelSchemaDb, orgId: string, row
140
142
  * switched back on) and `ConnectorsService` (a connector set active, by an org admin, the platform
141
143
  * or a plugin switch-on).
142
144
  */
143
- export declare function settleEnableRequests(db: KernelSchemaDb, orgId: string, target: EnableTarget, actor: string | null, opts?: RequestActorOpts & {
145
+ export declare function settleEnableRequests(db: KernelSchemaDb, hints: HintPublisher, orgId: string, target: EnableTarget, actor: string | null, opts?: RequestActorOpts & {
144
146
  settle?: boolean;
145
147
  }): Promise<string[]>;
146
148
  /**
@@ -149,25 +151,25 @@ export declare function settleEnableRequests(db: KernelSchemaDb, orgId: string,
149
151
  * are stale (the plugin is their owning switch now) and are cancelled with
150
152
  * `cancelReason: "target_changed"`. Called by `ScopeWriter.setOrgSwitch` (plugin off).
151
153
  */
152
- export declare function cancelEnableRequestsOfBundle(db: KernelSchemaDb, orgId: string, itemId: string, actor: string | null): Promise<void>;
154
+ export declare function cancelEnableRequestsOfBundle(db: KernelSchemaDb, hints: HintPublisher, orgId: string, itemId: string, actor: string | null): Promise<void>;
153
155
  /**
154
156
  * A model provider extension was switched off in the org, in the writer's transaction: pending
155
157
  * requests for its models are stale (the extension is their owning switch now). Called by
156
158
  * `OrgExtensionConfigs` (extension off).
157
159
  */
158
- export declare function cancelEnableRequestsOfProvider(db: KernelSchemaDb, orgId: string, provider: string, actor: string | null): Promise<void>;
160
+ export declare function cancelEnableRequestsOfProvider(db: KernelSchemaDb, hints: HintPublisher, orgId: string, provider: string, actor: string | null): Promise<void>;
159
161
  /**
160
162
  * A connector was disabled by its plugin's switch-off (`target_changed`: the plugin is its owning
161
163
  * switch now) or removed (`connector_removed`, no notice), in the writer's transaction: pending
162
164
  * requests for it are cancelled. Called by `ConnectorsService.disableWithPluginIn` and `removeIn`.
163
165
  */
164
- export declare function cancelEnableRequestsOfConnector(db: KernelSchemaDb, orgId: string, connectorId: string, actor: string | null, reason: "target_changed" | "connector_removed"): Promise<void>;
166
+ export declare function cancelEnableRequestsOfConnector(db: KernelSchemaDb, hints: HintPublisher, orgId: string, connectorId: string, actor: string | null, reason: "target_changed" | "connector_removed"): Promise<void>;
165
167
  /**
166
168
  * The platform disabled models of a provider, in its transaction: every org's pending requests
167
169
  * for them (as target or subject) are cancelled; the model is hidden from the orgs, so no "ask
168
170
  * again" notice. Called by `ModelEnablement.setPlatform`.
169
171
  */
170
- export declare function cancelEnableRequestsOfPlatformModels(db: KernelSchemaDb, provider: string, models: readonly string[], actor: string | null): Promise<void>;
172
+ export declare function cancelEnableRequestsOfPlatformModels(db: KernelSchemaDb, hints: HintPublisher, provider: string, models: readonly string[], actor: string | null): Promise<void>;
171
173
  /**
172
174
  * The platform changed a plugin's or a component's scope, share or disabled flag, in its
173
175
  * transaction: the pending enable requests of every org that target it, or that need the plugin
@@ -177,7 +179,7 @@ export declare function cancelEnableRequestsOfPlatformModels(db: KernelSchemaDb,
177
179
  * cancels it with `cancelReason: "target_changed"`. Called by `writeScope` (every scope write),
178
180
  * `ScopeWriter.setDisabled` and the unshare paths.
179
181
  */
180
- export declare function reconcileEnableRequestsOf(db: KernelSchemaDb, subject: {
182
+ export declare function reconcileEnableRequestsOf(db: KernelSchemaDb, hints: HintPublisher, subject: {
181
183
  kind: "plugin" | ComponentKind;
182
184
  id: string;
183
185
  }, actor: string | null): Promise<void>;
@@ -9,6 +9,7 @@ import { componentLocked, componentOffered, componentOn, componentPluginOn, list
9
9
  import { currentEnableDecision } from "./enable-decision.js";
10
10
  import { decodeModelId, readEnableDetail, sameTarget, targetKey, } from "./enable-targets.js";
11
11
  import { orgPluginDirectIntent, orgSees, orgUsable } from "./org-intent.js";
12
+ import { publishRequestHints } from "./request-hints.js";
12
13
  import { requestable } from "./scope.js";
13
14
  /** Builds a {@link ModelListing} from `ProviderRegistry.catalog(orgId)`. */
14
15
  export function modelListingOf(catalog) {
@@ -454,9 +455,10 @@ const usableNow = (r) => r !== undefined && !r.ok && r.on === true;
454
455
  * the requester's subject is usable (a `cancelReason: "target_changed"` cancellation otherwise),
455
456
  * and each follower's own outcome is recorded in `detail.followers` for their notice. Audits
456
457
  * each row under its own id. Returns the outcome of every row it settled (rows kept pending under
457
- * `reconcile` are absent).
458
+ * `reconcile` are absent). Every row it writes publishes `requests` after the commit
459
+ * ({@link publishRequestHints}: its requester, its followers, the org's admins).
458
460
  */
459
- export async function settleRequestRows(db, orgId, rows, mode, settlerOf) {
461
+ export async function settleRequestRows(db, hints, orgId, rows, mode, settlerOf) {
460
462
  const out = new Map();
461
463
  const parsed = rows.flatMap((r) => {
462
464
  const d = readEnableDetail(r.detail);
@@ -467,6 +469,8 @@ export async function settleRequestRows(db, orgId, rows, mode, settlerOf) {
467
469
  ...(p.d.followers ?? []).map((f) => f.subject),
468
470
  ]);
469
471
  const resolved = await resolveSubjects(db, orgId, subjects, true);
472
+ const written = [];
473
+ const dropped = [];
470
474
  const outcomeOf = (subject, target) => (mode.kind === "on" && sameTarget(subject, mode.target) && sameTarget(target, mode.target)) ||
471
475
  usableNow(resolved.get(targetKey(subject)))
472
476
  ? "approved"
@@ -484,12 +488,17 @@ export async function settleRequestRows(db, orgId, rows, mode, settlerOf) {
484
488
  });
485
489
  if (kept.length !== followers.length) {
486
490
  const raw = (row.detail ?? {});
487
- await db
491
+ const w = await db
488
492
  .updateTable("catalog_requests")
489
493
  .set({ detail: JSON.stringify({ ...raw, followers: kept }) })
490
494
  .where("id", "=", row.id)
491
495
  .where("org_id", "=", orgId)
492
- .execute();
496
+ .returning(["org_id", "requested_by", "kind", "detail"])
497
+ .executeTakeFirst();
498
+ if (w !== undefined)
499
+ written.push(w);
500
+ // a follower who stopped following no longer sees the request
501
+ dropped.push(...followers.filter((f) => !kept.includes(f)).map((f) => f.accountId));
493
502
  }
494
503
  continue;
495
504
  }
@@ -507,7 +516,7 @@ export async function settleRequestRows(db, orgId, rows, mode, settlerOf) {
507
516
  }),
508
517
  };
509
518
  const s = settlerOf(row.id);
510
- await db
519
+ const w = await db
511
520
  .updateTable("catalog_requests")
512
521
  .set({
513
522
  status: outcome === "approved" ? "approved" : "cancelled",
@@ -517,7 +526,10 @@ export async function settleRequestRows(db, orgId, rows, mode, settlerOf) {
517
526
  })
518
527
  .where("id", "=", row.id)
519
528
  .where("org_id", "=", orgId)
520
- .execute();
529
+ .returning(["org_id", "requested_by", "kind", "detail"])
530
+ .executeTakeFirst();
531
+ if (w !== undefined)
532
+ written.push(w);
521
533
  await audit(db, {
522
534
  actorAccountId: s.actor,
523
535
  ...(s.actorTokenId !== undefined && { actorTokenId: s.actorTokenId }),
@@ -534,6 +546,7 @@ export async function settleRequestRows(db, orgId, rows, mode, settlerOf) {
534
546
  });
535
547
  out.set(row.id, outcome);
536
548
  }
549
+ publishRequestHints(hints, written, dropped);
537
550
  return out;
538
551
  }
539
552
  /** An audit detail without a `requestId` (it names the request the writer was called for). */
@@ -556,7 +569,7 @@ function ownDetail(detail) {
556
569
  * switched back on) and `ConnectorsService` (a connector set active, by an org admin, the platform
557
570
  * or a plugin switch-on).
558
571
  */
559
- export async function settleEnableRequests(db, orgId, target, actor, opts = {}) {
572
+ export async function settleEnableRequests(db, hints, orgId, target, actor, opts = {}) {
560
573
  if (opts.settle === false)
561
574
  return [];
562
575
  const decision = currentEnableDecision();
@@ -591,7 +604,7 @@ export async function settleEnableRequests(db, orgId, target, actor, opts = {})
591
604
  if (deciding !== undefined && rows.some((r) => r.id === deciding.requestId)) {
592
605
  deciding.settled = true;
593
606
  }
594
- const settled = await settleRequestRows(db, orgId, rows, { kind: "on", target }, (id) => id === deciding?.requestId
607
+ const settled = await settleRequestRows(db, hints, orgId, rows, { kind: "on", target }, (id) => id === deciding?.requestId
595
608
  ? {
596
609
  actor: deciding.actor,
597
610
  actorTokenId: deciding.actorTokenId,
@@ -604,8 +617,11 @@ export async function settleEnableRequests(db, orgId, target, actor, opts = {})
604
617
  });
605
618
  return [...settled.keys()];
606
619
  }
607
- /** Cancels the pending enable requests `where` selects in the org (rows the caller chose). */
608
- async function cancelEnableWhere(db, orgId, where, actor, reason) {
620
+ /**
621
+ * Cancels the pending enable requests `where` selects in the org (rows the caller chose); the
622
+ * cancelled rows publish `requests` after the commit ({@link publishRequestHints}).
623
+ */
624
+ async function cancelEnableWhere(db, hints, orgId, where, actor, reason) {
609
625
  // rows locked in id order first, as settlement and reconciliation lock them (no deadlock)
610
626
  const locked = await db
611
627
  .selectFrom("catalog_requests")
@@ -632,8 +648,9 @@ async function cancelEnableWhere(db, orgId, where, actor, reason) {
632
648
  })
633
649
  .where("org_id", "=", orgId)
634
650
  .where("id", "in", locked.map((r) => r.id))
635
- .returning(["id", "detail"])
651
+ .returning(["id", "org_id", "requested_by", "kind", "detail"])
636
652
  .execute();
653
+ publishRequestHints(hints, rows);
637
654
  for (const r of rows) {
638
655
  await audit(db, {
639
656
  actorAccountId: actor,
@@ -650,16 +667,16 @@ async function cancelEnableWhere(db, orgId, where, actor, reason) {
650
667
  * are stale (the plugin is their owning switch now) and are cancelled with
651
668
  * `cancelReason: "target_changed"`. Called by `ScopeWriter.setOrgSwitch` (plugin off).
652
669
  */
653
- export function cancelEnableRequestsOfBundle(db, orgId, itemId, actor) {
654
- return cancelEnableWhere(db, orgId, sql `detail ->> 'bundle' = ${itemId}`, actor, "target_changed");
670
+ export function cancelEnableRequestsOfBundle(db, hints, orgId, itemId, actor) {
671
+ return cancelEnableWhere(db, hints, orgId, sql `detail ->> 'bundle' = ${itemId}`, actor, "target_changed");
655
672
  }
656
673
  /**
657
674
  * A model provider extension was switched off in the org, in the writer's transaction: pending
658
675
  * requests for its models are stale (the extension is their owning switch now). Called by
659
676
  * `OrgExtensionConfigs` (extension off).
660
677
  */
661
- export function cancelEnableRequestsOfProvider(db, orgId, provider, actor) {
662
- return cancelEnableWhere(db, orgId,
678
+ export function cancelEnableRequestsOfProvider(db, hints, orgId, provider, actor) {
679
+ return cancelEnableWhere(db, hints, orgId,
663
680
  // a prefix match of the canonical tuple: never parses another row's id (nothing can throw)
664
681
  sql `detail -> 'target' ->> 'kind' = 'model' AND starts_with(detail -> 'target' ->> 'id', '[' || to_jsonb(${provider}::text)::text || ',')`, actor, "target_changed");
665
682
  }
@@ -668,15 +685,15 @@ export function cancelEnableRequestsOfProvider(db, orgId, provider, actor) {
668
685
  * switch now) or removed (`connector_removed`, no notice), in the writer's transaction: pending
669
686
  * requests for it are cancelled. Called by `ConnectorsService.disableWithPluginIn` and `removeIn`.
670
687
  */
671
- export function cancelEnableRequestsOfConnector(db, orgId, connectorId, actor, reason) {
672
- return cancelEnableWhere(db, orgId, sql `detail -> 'target' ->> 'kind' = 'connector' AND detail -> 'target' ->> 'id' = ${connectorId}`, actor, reason);
688
+ export function cancelEnableRequestsOfConnector(db, hints, orgId, connectorId, actor, reason) {
689
+ return cancelEnableWhere(db, hints, orgId, sql `detail -> 'target' ->> 'kind' = 'connector' AND detail -> 'target' ->> 'id' = ${connectorId}`, actor, reason);
673
690
  }
674
691
  /**
675
692
  * The platform disabled models of a provider, in its transaction: every org's pending requests
676
693
  * for them (as target or subject) are cancelled; the model is hidden from the orgs, so no "ask
677
694
  * again" notice. Called by `ModelEnablement.setPlatform`.
678
695
  */
679
- export async function cancelEnableRequestsOfPlatformModels(db, provider, models, actor) {
696
+ export async function cancelEnableRequestsOfPlatformModels(db, hints, provider, models, actor) {
680
697
  if (models.length === 0)
681
698
  return;
682
699
  const ids = models.map((m) => JSON.stringify([provider, m]));
@@ -702,10 +719,12 @@ export async function cancelEnableRequestsOfPlatformModels(db, provider, models,
702
719
  .updateTable("catalog_requests")
703
720
  .set({ status: "cancelled", decided_by: actor, decided_at: sql `now()` })
704
721
  .where("id", "in", locked.map((r) => r.id))
705
- .returning(["id", "org_id", "detail"])
722
+ .returning(["id", "org_id", "requested_by", "kind", "detail"])
706
723
  .execute();
707
724
  return found;
708
725
  });
726
+ // the cancelled rows' requesters, followers and orgs' admins (the orgs the rows name)
727
+ publishRequestHints(hints, rows);
709
728
  for (const r of rows) {
710
729
  await withOrgScope(r.org_id, () => audit(db, {
711
730
  actorAccountId: actor,
@@ -729,7 +748,7 @@ export async function cancelEnableRequestsOfPlatformModels(db, provider, models,
729
748
  * cancels it with `cancelReason: "target_changed"`. Called by `writeScope` (every scope write),
730
749
  * `ScopeWriter.setDisabled` and the unshare paths.
731
750
  */
732
- export async function reconcileEnableRequestsOf(db, subject, actor) {
751
+ export async function reconcileEnableRequestsOf(db, hints, subject, actor) {
733
752
  if (subject.kind === "theme")
734
753
  return;
735
754
  const kind = subject.kind;
@@ -757,7 +776,7 @@ export async function reconcileEnableRequestsOf(db, subject, actor) {
757
776
  byOrg.set(r.org_id, [...(byOrg.get(r.org_id) ?? []), r]);
758
777
  for (const [orgId, list] of byOrg) {
759
778
  // each org's requests are checked and written in that org's scope
760
- await withOrgScope(orgId, () => settleRequestRows(db, orgId, list, { kind: "reconcile" }, () => ({ actor })));
779
+ await withOrgScope(orgId, () => settleRequestRows(db, hints, orgId, list, { kind: "reconcile" }, () => ({ actor })));
761
780
  }
762
781
  }
763
782
  /** Whether the request's subject is its target (a legacy row without a subject counts as one). */
@@ -2,6 +2,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { TransactionHost } from "../infra/database/transaction-host.js";
3
3
  import { XactLock } from "../infra/database/xact-lock.js";
4
4
  import { KernelEvents } from "../infra/events/kernel-events.js";
5
+ import type { HintPublisher } from "../invalidation/audiences.js";
5
6
  import type { KernelLogger } from "../log.js";
6
7
  import { OrgLock } from "../orgs/org-lock.js";
7
8
  import { SkillsService } from "../skills/skills.service.js";
@@ -50,11 +51,12 @@ export declare class OwnedItems {
50
51
  readonly txHost: TransactionHost;
51
52
  private readonly xactLock;
52
53
  private readonly events;
54
+ private readonly hints;
53
55
  constructor(kdb: KernelDb, orgLock: OrgLock, catalog: CatalogService, scope: CatalogScopeService,
54
56
  /** The owner org's own uninstall of a removed plugin (ruling P3-41). */
55
57
  installer: PluginInstaller,
56
58
  /** The owner's org skill row, soft-deleted after its promoted platform row leaves it. */
57
- skills: SkillsService, log: KernelLogger, txHost: TransactionHost, xactLock: XactLock, events: KernelEvents);
59
+ skills: SkillsService, log: KernelLogger, txHost: TransactionHost, xactLock: XactLock, events: KernelEvents, hints: HintPublisher);
58
60
  private get db();
59
61
  /**
60
62
  * The owner org's 可共享 flag of its item, written on the item and (a plugin) every component
@@ -28,6 +28,7 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
28
28
  import { XactLock } from "../infra/database/xact-lock.js";
29
29
  import { KernelEvents } from "../infra/events/kernel-events.js";
30
30
  import { KERNEL_LOGGER } from "../infra/tokens.js";
31
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
31
32
  import { OrgLock } from "../orgs/org-lock.js";
32
33
  import { SkillsService } from "../skills/skills.service.js";
33
34
  import { assertNotPlatformDefault } from "../themes/theme-usage.js";
@@ -86,11 +87,12 @@ let OwnedItems = class OwnedItems {
86
87
  txHost;
87
88
  xactLock;
88
89
  events;
90
+ hints;
89
91
  constructor(kdb, orgLock, catalog, scope,
90
92
  /** The owner org's own uninstall of a removed plugin (ruling P3-41). */
91
93
  installer,
92
94
  /** The owner's org skill row, soft-deleted after its promoted platform row leaves it. */
93
- skills, log, txHost, xactLock, events) {
95
+ skills, log, txHost, xactLock, events, hints) {
94
96
  this.kdb = kdb;
95
97
  this.orgLock = orgLock;
96
98
  this.catalog = catalog;
@@ -101,6 +103,7 @@ let OwnedItems = class OwnedItems {
101
103
  this.txHost = txHost;
102
104
  this.xactLock = xactLock;
103
105
  this.events = events;
106
+ this.hints = hints;
104
107
  }
105
108
  get db() {
106
109
  return this.kdb.db;
@@ -164,8 +167,8 @@ let OwnedItems = class OwnedItems {
164
167
  .where("id", "=", c.id)
165
168
  .execute();
166
169
  if (!shareable) {
167
- await narrowComponentOnUnshare(this.db, actor, c);
168
- await reconcileEnableRequestsOf(this.db, { kind, id: c.id }, actor);
170
+ await narrowComponentOnUnshare(this.db, this.hints, actor, c);
171
+ await reconcileEnableRequestsOf(this.db, this.hints, { kind, id: c.id }, actor);
169
172
  }
170
173
  }
171
174
  }
@@ -443,7 +446,7 @@ let OwnedItems = class OwnedItems {
443
446
  if (item.scope === "all") {
444
447
  // org-filter: deployment-wide rewrite of the transferred item's named list.
445
448
  await asPlatform("replace the transferred plugin's named scope", async () => {
446
- await writeScope(t, {
449
+ await writeScope(t, this.hints, {
447
450
  kind: "plugin",
448
451
  id: item.id,
449
452
  scope: "named",
@@ -458,7 +461,7 @@ let OwnedItems = class OwnedItems {
458
461
  .where("org_id", "=", owner)
459
462
  .execute();
460
463
  // the former owner's named entry went: its pending enable requests are checked again
461
- await reconcileEnableRequestsOf(t, { kind: "plugin", id: item.id }, actor);
464
+ await reconcileEnableRequestsOf(t, this.hints, { kind: "plugin", id: item.id }, actor);
462
465
  }
463
466
  await t
464
467
  .deleteFrom("catalog_item_org_switches")
@@ -506,7 +509,7 @@ let OwnedItems = class OwnedItems {
506
509
  .select(["id", "name"])
507
510
  .where("id", "=", owner)
508
511
  .executeTakeFirst();
509
- await addPlatformNotice(t, "ownership_transferred", {
512
+ await addPlatformNotice(t, this.hints, "ownership_transferred", {
510
513
  ref,
511
514
  name: item.name,
512
515
  fromOrg: from ?? { id: owner, name: owner },
@@ -643,7 +646,7 @@ let OwnedItems = class OwnedItems {
643
646
  .select(["id", "name"])
644
647
  .where("id", "=", owner)
645
648
  .executeTakeFirst();
646
- await addPlatformNotice(t, "ownership_transferred", {
649
+ await addPlatformNotice(t, this.hints, "ownership_transferred", {
647
650
  ref,
648
651
  name: c.name,
649
652
  fromOrg: from ?? { id: owner, name: owner },
@@ -684,7 +687,7 @@ let OwnedItems = class OwnedItems {
684
687
  /** Replaces a transferred component's named list in the transfer's transaction. */
685
688
  async replaceComponentScope(kind, id, orgs) {
686
689
  // org-filter: deployment-wide rewrite of the transferred component's named list.
687
- await asPlatform("replace the transferred component's named scope", () => writeScope(this.db, { kind, id, scopeMode: "own", scope: "named", orgs }));
690
+ await asPlatform("replace the transferred component's named scope", () => writeScope(this.db, this.hints, { kind, id, scopeMode: "own", scope: "named", orgs }));
688
691
  }
689
692
  /**
690
693
  * The owner org's live install of a removed plugin, uninstalled in the caller's transaction
@@ -781,6 +784,7 @@ OwnedItems = __decorate([
781
784
  __param(6, Inject(KERNEL_LOGGER)),
782
785
  __param(7, Inject(TransactionHost)),
783
786
  __param(8, Inject(XactLock)),
784
- __param(9, Inject(KernelEvents))
787
+ __param(9, Inject(KernelEvents)),
788
+ __param(10, Inject(InvalidationHints))
785
789
  ], OwnedItems);
786
790
  export { OwnedItems };
@@ -2,6 +2,7 @@ import { type AgentTemplate, type ConnectorTemplateFile, type ParsedTheme, type
2
2
  import type { SkillManifest, SourceFormat } from "../db/kernel-schema.js";
3
3
  import { KernelDb } from "../infra/database/kernel-db.js";
4
4
  import { TransactionHost } from "../infra/database/transaction-host.js";
5
+ import type { HintPublisher } from "../invalidation/audiences.js";
5
6
  import type { KernelLogger } from "../log.js";
6
7
  import { type SkillPackageFile } from "../skills/package.js";
7
8
  import { type PrefixedStorage, StorageService } from "../storage/storage.service.js";
@@ -176,9 +177,13 @@ export declare class PlatformComponents {
176
177
  private readonly itemLock;
177
178
  private readonly log;
178
179
  readonly txHost: TransactionHost;
180
+ /** The connectors a re-import relinks publish `capabilities` to their orgs. */
181
+ private readonly hints;
179
182
  /** Where the files are read and written (the kernel's object storage; the CLI's own). */
180
183
  private files;
181
- constructor(kdb: KernelDb, storage: StorageService, itemLock: CatalogItemLock, log: KernelLogger, txHost: TransactionHost);
184
+ constructor(kdb: KernelDb, storage: StorageService, itemLock: CatalogItemLock, log: KernelLogger, txHost: TransactionHost,
185
+ /** The connectors a re-import relinks publish `capabilities` to their orgs. */
186
+ hints: HintPublisher);
182
187
  private get db();
183
188
  initializeDependencyEdges(): Promise<void>;
184
189
  /** CLI only (see `PluginImport.useCliStorage`): files go to the object store the CLI set up. */
@@ -22,6 +22,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
22
22
  import { TransactionHost } from "../infra/database/transaction-host.js";
23
23
  import { Transactional } from "../infra/database/transactional.decorator.js";
24
24
  import { KERNEL_LOGGER } from "../infra/tokens.js";
25
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
25
26
  import { packagePath } from "../packages/tgz.js";
26
27
  import { readSkillPackage, skillManifest } from "../skills/package.js";
27
28
  import { StorageService } from "../storage/storage.service.js";
@@ -67,13 +68,17 @@ let PlatformComponents = class PlatformComponents {
67
68
  itemLock;
68
69
  log;
69
70
  txHost;
71
+ hints;
70
72
  /** Where the files are read and written (the kernel's object storage; the CLI's own). */
71
73
  files;
72
- constructor(kdb, storage, itemLock, log, txHost) {
74
+ constructor(kdb, storage, itemLock, log, txHost,
75
+ /** The connectors a re-import relinks publish `capabilities` to their orgs. */
76
+ hints) {
73
77
  this.kdb = kdb;
74
78
  this.itemLock = itemLock;
75
79
  this.log = log;
76
80
  this.txHost = txHost;
81
+ this.hints = hints;
77
82
  this.files = storage;
78
83
  }
79
84
  get db() {
@@ -753,7 +758,7 @@ let PlatformComponents = class PlatformComponents {
753
758
  // made move to this one, and its installs take them back (spec §5 rule 8). Their orgs are
754
759
  // not locked: nothing else writes a deleted plugin's connectors but their org's admins,
755
760
  // whose row locks this waits for without holding anything they need
756
- await relinkDeletedItemConnectors(t, {
761
+ await relinkDeletedItemConnectors(t, this.hints, {
757
762
  itemId: plan.itemId,
758
763
  name: plan.plugin,
759
764
  ownerOrgId,
@@ -857,7 +862,8 @@ PlatformComponents = __decorate([
857
862
  __param(1, Inject(StorageService)),
858
863
  __param(2, Inject(CatalogItemLock)),
859
864
  __param(3, Inject(KERNEL_LOGGER)),
860
- __param(4, Inject(TransactionHost))
865
+ __param(4, Inject(TransactionHost)),
866
+ __param(5, Inject(InvalidationHints))
861
867
  ], PlatformComponents);
862
868
  export { PlatformComponents };
863
869
  /** An org's own item it promoted (ruling P3-3): owned by an org, from no plugin. */
@@ -1,4 +1,5 @@
1
1
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
+ import { type HintPublisher } from "../invalidation/audiences.js";
2
3
  /**
3
4
  * The update that switches a connector off with plugin `itemId`: status `disabled`, and the marker
4
5
  * set only on a connector that was active, so switching the plugin back on re-enables exactly what
@@ -14,18 +15,21 @@ export declare function pluginSwitchOff(itemId: string): {
14
15
  * Switches off, in the caller's transaction, every live connector in any org made from one of the
15
16
  * item's connector templates ({@link pluginSwitchOff}): the super admin's delete of the item
16
17
  * (`CatalogService.removeIn`). The caller holds the orgs' row locks where it can (the global lock
17
- * order puts them before the item). Returns how many connectors it touched.
18
+ * order puts them before the item). Each org whose connectors it touched gets `capabilities` after
19
+ * the commit (the orgs the update returns). Returns how many connectors it touched.
18
20
  */
19
- export declare function switchOffItemConnectors(db: KernelSchemaDb, itemId: string): Promise<number>;
21
+ export declare function switchOffItemConnectors(db: KernelSchemaDb, hints: HintPublisher, itemId: string): Promise<number>;
20
22
  /**
21
23
  * When a plugin is imported again after its delete (a new catalog item of the same name and
22
24
  * owner), the live connectors that the deleted items' connector template `templateId` made move to
23
25
  * the new item's template `newTemplateId`: their template, item and version links point at the new
24
26
  * item, and a marker of a deleted item's switch-off becomes the new item's, so the new item's
25
27
  * install takes them back and re-enables them exactly as switching the plugin back on does (one an
26
- * org admin disabled by hand stays off). In the caller's transaction, under the item lock.
28
+ * org admin disabled by hand stays off). In the caller's transaction, under the item lock. Each
29
+ * org whose connectors moved gets `capabilities` after the commit (its connector list names the
30
+ * new plugin).
27
31
  */
28
- export declare function relinkDeletedItemConnectors(db: KernelSchemaDb, to: {
32
+ export declare function relinkDeletedItemConnectors(db: KernelSchemaDb, hints: HintPublisher, to: {
29
33
  itemId: string;
30
34
  name: string;
31
35
  ownerOrgId: string | null;
@@ -1,4 +1,5 @@
1
1
  import { sql } from "kysely";
2
+ import { publishCapabilities } from "../invalidation/audiences.js";
2
3
  // The connectors a plugin's connector templates made, switched off and on with the plugin (spec §5
3
4
  // rule 8): an org's uninstall or switch-off (`ConnectorsService.disableWithPluginIn`), the super
4
5
  // admin's delete of the plugin ({@link switchOffItemConnectors}) and an import of the same plugin
@@ -21,9 +22,10 @@ export function pluginSwitchOff(itemId) {
21
22
  * Switches off, in the caller's transaction, every live connector in any org made from one of the
22
23
  * item's connector templates ({@link pluginSwitchOff}): the super admin's delete of the item
23
24
  * (`CatalogService.removeIn`). The caller holds the orgs' row locks where it can (the global lock
24
- * order puts them before the item). Returns how many connectors it touched.
25
+ * order puts them before the item). Each org whose connectors it touched gets `capabilities` after
26
+ * the commit (the orgs the update returns). Returns how many connectors it touched.
25
27
  */
26
- export async function switchOffItemConnectors(db, itemId) {
28
+ export async function switchOffItemConnectors(db, hints, itemId) {
27
29
  // org-filter: the delete of a catalog item switches off its template connectors in every org
28
30
  // by design (spec §5 rule 8), keyed by the item's own template ids
29
31
  const rows = await db
@@ -34,8 +36,9 @@ export async function switchOffItemConnectors(db, itemId) {
34
36
  .selectFrom("platform_connector_templates")
35
37
  .select("id")
36
38
  .where("catalog_item_id", "=", itemId))
37
- .returning("id")
39
+ .returning(["id", "org_id"])
38
40
  .execute();
41
+ publishCapabilities(hints, rows.map((r) => r.org_id));
39
42
  return rows.length;
40
43
  }
41
44
  /**
@@ -44,9 +47,11 @@ export async function switchOffItemConnectors(db, itemId) {
44
47
  * the new item's template `newTemplateId`: their template, item and version links point at the new
45
48
  * item, and a marker of a deleted item's switch-off becomes the new item's, so the new item's
46
49
  * install takes them back and re-enables them exactly as switching the plugin back on does (one an
47
- * org admin disabled by hand stays off). In the caller's transaction, under the item lock.
50
+ * org admin disabled by hand stays off). In the caller's transaction, under the item lock. Each
51
+ * org whose connectors moved gets `capabilities` after the commit (its connector list names the
52
+ * new plugin).
48
53
  */
49
- export async function relinkDeletedItemConnectors(db, to) {
54
+ export async function relinkDeletedItemConnectors(db, hints, to) {
50
55
  // The deleted items of this plugin (its name, the same owner) and their template `templateId`
51
56
  const old = await db
52
57
  .selectFrom("platform_connector_templates as t")
@@ -75,7 +80,8 @@ export async function relinkDeletedItemConnectors(db, to) {
75
80
  })
76
81
  .where("deleted_at", "is", null)
77
82
  .where("platform_template_id", "in", old.map((r) => r.id))
78
- .returning("id")
83
+ .returning(["id", "org_id"])
79
84
  .execute();
85
+ publishCapabilities(hints, rows.map((r) => r.org_id));
80
86
  return rows.length;
81
87
  }
@@ -17,6 +17,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
17
17
  import { TransactionHost } from "../infra/database/transaction-host.js";
18
18
  import { XactLock } from "../infra/database/xact-lock.js";
19
19
  import { OutboxService } from "../infra/outbox/outbox.service.js";
20
+ import type { HintPublisher } from "../invalidation/audiences.js";
20
21
  import type { KernelLogger } from "../log.js";
21
22
  import { OrgLock } from "../orgs/org-lock.js";
22
23
  import type { ProvenanceResult } from "../packages/provenance.js";
@@ -427,6 +428,7 @@ export declare class PluginImport {
427
428
  private readonly platform;
428
429
  /** The item's scope sync, owed by the confirm's commit when it deploys no extension. */
429
430
  private readonly outbox;
431
+ private readonly hints;
430
432
  /** Where plugin files go (the kernel's object storage; the CLI's own, see {@link useCliStorage}). */
431
433
  private files;
432
434
  /**
@@ -447,7 +449,7 @@ export declare class PluginImport {
447
449
  /** The platform rows of a new item's components, written in the confirm's transaction. */
448
450
  platform: PlatformComponents,
449
451
  /** The item's scope sync, owed by the confirm's commit when it deploys no extension. */
450
- outbox: Pick<OutboxService, "add" | "addMany">);
452
+ outbox: Pick<OutboxService, "add" | "addMany">, hints: HintPublisher);
451
453
  /** The kernel-schema handle of the current context (the transaction, else the pool). */
452
454
  private get db();
453
455
  /**