@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
@@ -25,6 +25,8 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
25
25
  import { Transactional } from "../infra/database/transactional.decorator.js";
26
26
  import { KernelEvents } from "../infra/events/kernel-events.js";
27
27
  import { OutboxService } from "../infra/outbox/outbox.service.js";
28
+ import { publishCapabilities } from "../invalidation/audiences.js";
29
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
28
30
  import { OrgLock } from "../orgs/org-lock.js";
29
31
  import { EffectiveConfigs } from "./effective-config.js";
30
32
  import { alwaysOnExtensions, enabledExtensionsQuery, extensionSwitch, isExtensionEnabled, requiredExtensions, } from "./enabled.js";
@@ -78,6 +80,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
78
80
  effective;
79
81
  availability;
80
82
  outbox;
83
+ hints;
81
84
  constructor(installLock, kdb, txHost, host,
82
85
  /** The org row lock (orgs/org-lock.ts): joins the transaction. */
83
86
  orgLock,
@@ -90,7 +93,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
90
93
  /** Why an installed extension is not loaded (`status` / `reason` of the unavailable ones). */
91
94
  availability,
92
95
  /** Owes the org's template connector ensure when an extension is switched on (ruling R27). */
93
- outbox) {
96
+ outbox, hints) {
94
97
  this.installLock = installLock;
95
98
  this.kdb = kdb;
96
99
  this.txHost = txHost;
@@ -101,6 +104,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
101
104
  this.effective = effective;
102
105
  this.availability = availability;
103
106
  this.outbox = outbox;
107
+ this.hints = hints;
104
108
  }
105
109
  /** The kernel-schema handle of the current transaction. */
106
110
  get db() {
@@ -312,7 +316,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
312
316
  await revokeSiteGrantsOfExtension(t, { orgId, extensionName: plugin });
313
317
  // a model provider switched off: requests for its models need the extension first now
314
318
  if (before)
315
- await cancelEnableRequestsOfProvider(t, orgId, plugin, actorAccountId);
319
+ await cancelEnableRequestsOfProvider(t, this.hints, orgId, plugin, actorAccountId);
316
320
  // its host services on the org's machines stop (local agents spec, call 5)
317
321
  await oweHostServicesStop(t, this.outbox, { orgId, extension: plugin });
318
322
  }
@@ -322,7 +326,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
322
326
  if (enabled && !before) {
323
327
  await oweTemplateConnectors(this.outbox, t, orgId);
324
328
  // the org's pending enable requests for this extension are settled with the write
325
- await settleEnableRequests(t, orgId, { kind: "extension", id: plugin }, actorAccountId, {
329
+ await settleEnableRequests(t, this.hints, orgId, { kind: "extension", id: plugin }, actorAccountId, {
326
330
  ...(actorTokenId !== undefined && { actorTokenId }),
327
331
  });
328
332
  }
@@ -338,6 +342,9 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
338
342
  ...opts.auditDetail,
339
343
  },
340
344
  });
345
+ // the org's extension switch moved: its members' pickers refetch
346
+ if (enabled !== before)
347
+ publishCapabilities(this.hints, [orgId]);
341
348
  const view = this.view(manifest, enabled, required, item, bundleUsable, seen);
342
349
  // Only once the root transaction committed (an outer caller's too): a rolled-back write
343
350
  // disconnects nothing
@@ -434,6 +441,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
434
441
  target: plugin,
435
442
  detail: { enabled: false, reason },
436
443
  });
444
+ publishCapabilities(this.hints, [orgId]);
437
445
  return true;
438
446
  }
439
447
  /** {@link disableIn} 的事务提交之后:通知停用(断开该插件的渠道连接等)。 */
@@ -551,7 +559,8 @@ OrgExtensionConfigs = __decorate([
551
559
  __param(6, Inject(KernelEvents)),
552
560
  __param(7, Inject(EffectiveConfigs)),
553
561
  __param(8, Inject(ExtensionAvailability)),
554
- __param(9, Inject(OutboxService))
562
+ __param(9, Inject(OutboxService)),
563
+ __param(10, Inject(InvalidationHints))
555
564
  ], OrgExtensionConfigs);
556
565
  export { OrgExtensionConfigs };
557
566
  /**
@@ -1,6 +1,7 @@
1
1
  import { type Keyring } from "../ctx/secrets.js";
2
2
  import { KernelDb } from "../infra/database/kernel-db.js";
3
3
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
+ import { type HintPublisher } from "../invalidation/audiences.js";
4
5
  import type { KernelLogger } from "../log.js";
5
6
  import { OrgLock } from "../orgs/org-lock.js";
6
7
  import { type ConfigIssue } from "./config-issues.js";
@@ -80,9 +81,13 @@ export declare class OrgOverrides {
80
81
  private readonly orgLock;
81
82
  private readonly effective;
82
83
  private readonly log;
84
+ /** A changed copy publishes `capabilities` to the org (after the cache eviction). */
85
+ private readonly hints;
83
86
  constructor(kdb: KernelDb, txHost: TransactionHost, keyring: Keyring, host: ExtensionHost,
84
87
  /** The org row lock: re-checks `org.extensions.manage` under the lock. */
85
- orgLock: OrgLock, effective: EffectiveConfigs, log: KernelLogger);
88
+ orgLock: OrgLock, effective: EffectiveConfigs, log: KernelLogger,
89
+ /** A changed copy publishes `capabilities` to the org (after the cache eviction). */
90
+ hints: HintPublisher);
86
91
  private get db();
87
92
  private running;
88
93
  /**
@@ -18,6 +18,8 @@ import { KernelDb } from "../infra/database/kernel-db.js";
18
18
  import { TransactionHost } from "../infra/database/transaction-host.js";
19
19
  import { Transactional } from "../infra/database/transactional.decorator.js";
20
20
  import { KERNEL_LOGGER, KEYRING } from "../infra/tokens.js";
21
+ import { publishCapabilities } from "../invalidation/audiences.js";
22
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
21
23
  import { OrgLock } from "../orgs/org-lock.js";
22
24
  import { toIssues } from "./config-issues.js";
23
25
  import { configMessages, safeConfigFormSchema } from "./config-json-schema.js";
@@ -46,9 +48,12 @@ let OrgOverrides = class OrgOverrides {
46
48
  orgLock;
47
49
  effective;
48
50
  log;
51
+ hints;
49
52
  constructor(kdb, txHost, keyring, host,
50
53
  /** The org row lock: re-checks `org.extensions.manage` under the lock. */
51
- orgLock, effective, log) {
54
+ orgLock, effective, log,
55
+ /** A changed copy publishes `capabilities` to the org (after the cache eviction). */
56
+ hints) {
52
57
  this.kdb = kdb;
53
58
  this.txHost = txHost;
54
59
  this.keyring = keyring;
@@ -56,6 +61,7 @@ let OrgOverrides = class OrgOverrides {
56
61
  this.orgLock = orgLock;
57
62
  this.effective = effective;
58
63
  this.log = log;
64
+ this.hints = hints;
59
65
  }
60
66
  get db() {
61
67
  return this.kdb.db;
@@ -190,6 +196,8 @@ let OrgOverrides = class OrgOverrides {
190
196
  this.log.addOrgSecrets(secretValues);
191
197
  await this.effective.invalidate(orgId, plugin);
192
198
  });
199
+ // the org's effective config moved (it may need config, or no longer): its members refetch
200
+ publishCapabilities(this.hints, [orgId]);
193
201
  return this.render(orgId, run);
194
202
  }
195
203
  /**
@@ -249,6 +257,7 @@ let OrgOverrides = class OrgOverrides {
249
257
  detail: { changedPaths: changed.sort(), ...actor.auditDetail },
250
258
  });
251
259
  afterCommit(() => this.effective.invalidate(orgId, plugin));
260
+ publishCapabilities(this.hints, [orgId]);
252
261
  return this.render(orgId, run);
253
262
  }
254
263
  /**
@@ -281,6 +290,7 @@ let OrgOverrides = class OrgOverrides {
281
290
  ...(actor.auditDetail !== undefined && { detail: actor.auditDetail }),
282
291
  });
283
292
  afterCommit(() => this.effective.invalidate(orgId, plugin));
293
+ publishCapabilities(this.hints, [orgId]);
284
294
  return this.render(orgId, run);
285
295
  }
286
296
  /**
@@ -474,7 +484,8 @@ OrgOverrides = __decorate([
474
484
  __param(3, Inject(ExtensionHost)),
475
485
  __param(4, Inject(OrgLock)),
476
486
  __param(5, Inject(EffectiveConfigs)),
477
- __param(6, Inject(KERNEL_LOGGER))
487
+ __param(6, Inject(KERNEL_LOGGER)),
488
+ __param(7, Inject(InvalidationHints))
478
489
  ], OrgOverrides);
479
490
  export { OrgOverrides };
480
491
  /**
@@ -2,6 +2,7 @@ import { type InboxPost, type LocalizedName, type LocalizedText } from "@capybar
2
2
  import type { StoredInboxAction } 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 { PushOwed } from "../push/push-owed.js";
6
7
  /** Who posts an item: the kernel, or an extension (by plugin name). */
7
8
  export type InboxSource = {
@@ -60,7 +61,11 @@ export declare class InboxItemsService {
60
61
  private readonly kdb;
61
62
  readonly txHost: TransactionHost;
62
63
  private readonly push;
63
- constructor(kdb: KernelDb, txHost: TransactionHost, push: Pick<PushOwed, "oweInboxItem">);
64
+ /** Every write publishes `inbox` to the item's person after the commit. */
65
+ private readonly hints;
66
+ constructor(kdb: KernelDb, txHost: TransactionHost, push: Pick<PushOwed, "oweInboxItem">,
67
+ /** Every write publishes `inbox` to the item's person after the commit. */
68
+ hints: HintPublisher);
64
69
  /**
65
70
  * Posts `p` for `source` and owes its push fanout in the same transaction. The SDK's
66
71
  * `validateInboxPost` checks the fields (a plugin item links only to `/p/<plugin>/…`; a kernel
@@ -16,6 +16,9 @@ import { isExtensionEnabled } from "../extensions/enabled.js";
16
16
  import { KernelDb } from "../infra/database/kernel-db.js";
17
17
  import { TransactionHost } from "../infra/database/transaction-host.js";
18
18
  import { Transactional } from "../infra/database/transactional.decorator.js";
19
+ import { publishAccountInbox } from "../invalidation/audiences.js";
20
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
21
+ import { InvalidationHintsModule } from "../invalidation/invalidation-hints.module.js";
19
22
  import { PushOwed, PushOwedModule } from "../push/push-owed.js";
20
23
  import { pluginDisplayNames } from "../tools/display-names.js";
21
24
  import { INBOX_ITEMS_BACKEND } from "./token.js";
@@ -48,10 +51,14 @@ let InboxItemsService = class InboxItemsService {
48
51
  kdb;
49
52
  txHost;
50
53
  push;
51
- constructor(kdb, txHost, push) {
54
+ hints;
55
+ constructor(kdb, txHost, push,
56
+ /** Every write publishes `inbox` to the item's person after the commit. */
57
+ hints) {
52
58
  this.kdb = kdb;
53
59
  this.txHost = txHost;
54
60
  this.push = push;
61
+ this.hints = hints;
55
62
  }
56
63
  /**
57
64
  * Posts `p` for `source` and owes its push fanout in the same transaction. The SDK's
@@ -118,6 +125,7 @@ let InboxItemsService = class InboxItemsService {
118
125
  // the conflicting item may close between the insert and the read: then the insert runs again
119
126
  for (let attempt = 0; attempt < 2; attempt++) {
120
127
  if ((await insert()) !== undefined) {
128
+ publishAccountInbox(this.hints, [p.accountId]);
121
129
  if (!opts.resolved)
122
130
  await this.push.oweInboxItem(id, p.orgId);
123
131
  return { itemId: id };
@@ -178,7 +186,7 @@ let InboxItemsService = class InboxItemsService {
178
186
  }
179
187
  /** Resolves open posts of this exact plugin, recipient and post key. */
180
188
  async resolveForPostKey(plugin, orgId, accountId, postKey) {
181
- await this.kdb.db
189
+ const r = await this.kdb.db
182
190
  .updateTable("inbox_items")
183
191
  .set({ state: "resolved", resolved_at: sql `now()` })
184
192
  .where("org_id", "=", orgId)
@@ -187,7 +195,9 @@ let InboxItemsService = class InboxItemsService {
187
195
  .where("plugin", "=", plugin)
188
196
  .where("dedupe_key", "=", postKey)
189
197
  .where("state", "=", "open")
190
- .execute();
198
+ .executeTakeFirst();
199
+ if (r.numUpdatedRows > 0n)
200
+ publishAccountInbox(this.hints, [accountId]);
191
201
  }
192
202
  /** The open items of (org, account, source, plugin) with `dedupe`, closed as `expired`. */
193
203
  sameKey(orgId, accountId, source, dedupe) {
@@ -228,7 +238,7 @@ let InboxItemsService = class InboxItemsService {
228
238
  * scope.
229
239
  */
230
240
  async resolveKernelItem(orgId, accountId, dedupeKey) {
231
- await this.kdb.db
241
+ const r = await this.kdb.db
232
242
  .updateTable("inbox_items")
233
243
  .set({ state: "resolved", resolved_at: sql `now()` })
234
244
  .where("org_id", "=", orgId)
@@ -237,14 +247,16 @@ let InboxItemsService = class InboxItemsService {
237
247
  .where("plugin", "is", null)
238
248
  .where("dedupe_key", "=", dedupeKey)
239
249
  .where("state", "=", "open")
240
- .execute();
250
+ .executeTakeFirst();
251
+ if (r.numUpdatedRows > 0n)
252
+ publishAccountInbox(this.hints, [accountId]);
241
253
  }
242
254
  /**
243
255
  * Resolves every open kernel item of `accountId` in `orgId` whose dedupe key starts with
244
256
  * `prefix` (the things they asked about are gone). The caller runs it in the org's scope.
245
257
  */
246
258
  async resolveKernelItems(orgId, accountId, prefix) {
247
- await this.kdb.db
259
+ const r = await this.kdb.db
248
260
  .updateTable("inbox_items")
249
261
  .set({ state: "resolved", resolved_at: sql `now()` })
250
262
  .where("org_id", "=", orgId)
@@ -253,7 +265,9 @@ let InboxItemsService = class InboxItemsService {
253
265
  .where("plugin", "is", null)
254
266
  .where(sql `starts_with(dedupe_key, ${prefix})`)
255
267
  .where("state", "=", "open")
256
- .execute();
268
+ .executeTakeFirst();
269
+ if (r.numUpdatedRows > 0n)
270
+ publishAccountInbox(this.hints, [accountId]);
257
271
  }
258
272
  /** Marks an open item resolved; whether it was open. */
259
273
  async close(orgId, itemId) {
@@ -263,8 +277,12 @@ let InboxItemsService = class InboxItemsService {
263
277
  .where("org_id", "=", orgId)
264
278
  .where("id", "=", itemId)
265
279
  .where("state", "=", "open")
280
+ .returning("account_id")
266
281
  .executeTakeFirst();
267
- return r.numUpdatedRows > 0n;
282
+ if (r === undefined)
283
+ return false;
284
+ publishAccountInbox(this.hints, [r.account_id]);
285
+ return true;
268
286
  }
269
287
  /** The open, unexpired item `itemId` of `accountId` in `orgId`, or `inbox.item_not_found`. */
270
288
  async openOf(orgId, accountId, itemId) {
@@ -375,7 +393,8 @@ InboxItemsService = __decorate([
375
393
  Injectable(),
376
394
  __param(0, Inject(KernelDb)),
377
395
  __param(1, Inject(TransactionHost)),
378
- __param(2, Inject(PushOwed))
396
+ __param(2, Inject(PushOwed)),
397
+ __param(3, Inject(InvalidationHints))
379
398
  ], InboxItemsService);
380
399
  export { InboxItemsService };
381
400
  /**
@@ -387,7 +406,7 @@ let InboxItemsModule = class InboxItemsModule {
387
406
  };
388
407
  InboxItemsModule = __decorate([
389
408
  Module({
390
- imports: [PushOwedModule],
409
+ imports: [PushOwedModule, InvalidationHintsModule],
391
410
  providers: [InboxItemsService, { provide: INBOX_ITEMS_BACKEND, useExisting: InboxItemsService }],
392
411
  exports: [InboxItemsService, INBOX_ITEMS_BACKEND],
393
412
  })
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { Module } from "@nestjs/common";
8
8
  import { AutomationsModule } from "../automations/automations.module.js";
9
9
  import { CatalogModule } from "../catalog/catalog.module.js";
10
+ import { InvalidationHintsModule } from "../invalidation/invalidation-hints.module.js";
10
11
  import { SkillsModule } from "../skills/skills.module.js";
11
12
  import { ToolsModule } from "../tools/tools.module.js";
12
13
  import { UiModule } from "../ui/ui.module.js";
@@ -24,6 +25,8 @@ let InboxModule = class InboxModule {
24
25
  InboxModule = __decorate([
25
26
  Module({
26
27
  imports: [
28
+ // the notice dismissals publish invalidation hints after their commit
29
+ InvalidationHintsModule,
27
30
  ToolsModule,
28
31
  SkillsModule,
29
32
  CatalogModule,
@@ -2,6 +2,7 @@ import { type AutomationAttention, AutomationsService } from "../automations/aut
2
2
  import { AcceptanceService, type AutomationOfferView } from "../automations/events/acceptance.js";
3
3
  import { CatalogRequestsService, type CatalogRequestView } from "../catalog/requests.service.js";
4
4
  import { KernelDb } from "../infra/database/kernel-db.js";
5
+ import { type HintPublisher } from "../invalidation/audiences.js";
5
6
  import { SkillChangesService, type SkillChangeView } from "../skills/changes.service.js";
6
7
  import { ApprovalsService, type ApprovalView } from "../tools/approvals.service.js";
7
8
  import { InboxItemsService, type PersonalInboxItemView } from "./inbox-items.service.js";
@@ -109,7 +110,8 @@ export declare class InboxService {
109
110
  private readonly automations;
110
111
  private readonly items;
111
112
  private readonly acceptance;
112
- constructor(approvals: Pick<ApprovalsService, "list">, skillChanges: Pick<SkillChangesService, "listPending">, kdb: KernelDb, catalogRequests: Pick<CatalogRequestsService, "listForOrgAdmin" | "listDecidedForRequester">, automations: Pick<AutomationsService, "attentionFor">, items: Pick<InboxItemsService, "listOpen">, acceptance: Pick<AcceptanceService, "openOffers">);
113
+ private readonly hints;
114
+ constructor(approvals: Pick<ApprovalsService, "list">, skillChanges: Pick<SkillChangesService, "listPending">, kdb: KernelDb, catalogRequests: Pick<CatalogRequestsService, "listForOrgAdmin" | "listDecidedForRequester">, automations: Pick<AutomationsService, "attentionFor">, items: Pick<InboxItemsService, "listOpen">, acceptance: Pick<AcceptanceService, "openOffers">, hints: HintPublisher);
113
115
  list(orgId: string, accountId: string): Promise<InboxView>;
114
116
  /** The org's open notices when the account is an org admin (else none), newest first. */
115
117
  private notices;
@@ -14,6 +14,8 @@ import { AcceptanceService, OFFERS_LIST_MAX, } from "../automations/events/accep
14
14
  import { CATALOG_REQUESTS_LIST_MAX, CatalogRequestsService, } from "../catalog/requests.service.js";
15
15
  import { ApiError } from "../errors.js";
16
16
  import { KernelDb } from "../infra/database/kernel-db.js";
17
+ import { publishOrgAdminsInbox } from "../invalidation/audiences.js";
18
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
17
19
  import { roleAtLeast } from "../orgs/roles.js";
18
20
  import { SKILL_CHANGES_LIST_MAX, SkillChangesService, } from "../skills/changes.service.js";
19
21
  import { APPROVALS_LIST_MAX, ApprovalsService, } from "../tools/approvals.service.js";
@@ -31,7 +33,8 @@ let InboxService = class InboxService {
31
33
  automations;
32
34
  items;
33
35
  acceptance;
34
- constructor(approvals, skillChanges, kdb, catalogRequests, automations, items, acceptance) {
36
+ hints;
37
+ constructor(approvals, skillChanges, kdb, catalogRequests, automations, items, acceptance, hints) {
35
38
  this.approvals = approvals;
36
39
  this.skillChanges = skillChanges;
37
40
  this.kdb = kdb;
@@ -39,6 +42,7 @@ let InboxService = class InboxService {
39
42
  this.automations = automations;
40
43
  this.items = items;
41
44
  this.acceptance = acceptance;
45
+ this.hints = hints;
42
46
  }
43
47
  async list(orgId, accountId) {
44
48
  const [approvals, changes, requests, decided, notices, attention, allItems, offers] = await Promise.all([
@@ -152,6 +156,8 @@ let InboxService = class InboxService {
152
156
  .executeTakeFirst();
153
157
  if (r.numUpdatedRows === 0n)
154
158
  throw notFound;
159
+ // dismissed for every admin of the org: their inboxes refetch
160
+ publishOrgAdminsInbox(this.hints, [orgId]);
155
161
  }
156
162
  async isAdmin(orgId, accountId) {
157
163
  const m = await this.kdb.db
@@ -171,7 +177,8 @@ InboxService = __decorate([
171
177
  __param(3, Inject(CatalogRequestsService)),
172
178
  __param(4, Inject(AutomationsService)),
173
179
  __param(5, Inject(InboxItemsService)),
174
- __param(6, Inject(AcceptanceService))
180
+ __param(6, Inject(AcceptanceService)),
181
+ __param(7, Inject(InvalidationHints))
175
182
  ], InboxService);
176
183
  export { InboxService };
177
184
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -1,5 +1,6 @@
1
1
  import { type OwnedRef, type Owner } from "../catalog/ownership.js";
2
2
  import type { KernelSchemaDb, OrgNoticeKind } from "../db/kernel-schema.js";
3
+ import { type HintPublisher } from "../invalidation/audiences.js";
3
4
  export type { OrgNoticeKind };
4
5
  /** The `detail` of each notice kind. */
5
6
  export interface OrgNoticeDetails {
@@ -31,18 +32,18 @@ type LocalizedName = {
31
32
  /** A catalog item's display name for an upload notice (null without one, or for an unknown id). */
32
33
  export declare function itemDisplayName(db: KernelSchemaDb, itemId: string): Promise<LocalizedName>;
33
34
  /** Writes an org notice in the caller's transaction. */
34
- export declare function addOrgNotice<K extends keyof OrgNoticeDetails>(db: KernelSchemaDb, orgId: string, kind: K, detail: OrgNoticeDetails[K]): Promise<void>;
35
+ export declare function addOrgNotice<K extends keyof OrgNoticeDetails>(db: KernelSchemaDb, hints: HintPublisher, orgId: string, kind: K, detail: OrgNoticeDetails[K]): Promise<void>;
35
36
  /**
36
37
  * Tells the owner org that its item was shared (`item_shared`): with each org of `orgs` (the owner
37
38
  * itself is skipped), or with `all_orgs`. A platform-owned item writes nothing.
38
39
  */
39
- export declare function notifyItemShared(db: KernelSchemaDb, ownerOrgId: string | null, ref: OwnedRef, name: string, orgs: readonly string[] | "all_orgs"): Promise<void>;
40
+ export declare function notifyItemShared(db: KernelSchemaDb, hints: HintPublisher, ownerOrgId: string | null, ref: OwnedRef, name: string, orgs: readonly string[] | "all_orgs"): Promise<void>;
40
41
  /**
41
42
  * Tells every live org the org-owned item is on in, except its owner (P3-18, {@link orgsUsing}),
42
43
  * that it changed version (`shared_item_updated`); returns how many orgs were told. A platform-owned
43
44
  * or missing item tells nobody.
44
45
  */
45
- export declare function notifySharedUpdate(db: KernelSchemaDb, ref: OwnedRef, change: {
46
+ export declare function notifySharedUpdate(db: KernelSchemaDb, hints: HintPublisher, ref: OwnedRef, change: {
46
47
  name: string;
47
48
  from: string;
48
49
  to: string;
@@ -4,6 +4,7 @@
4
4
  import { randomUUID } from "node:crypto";
5
5
  import { orgsUsing, ownerOf, ownersOf } from "../catalog/ownership.js";
6
6
  import { withOrgScope } from "../infra/database/org-scope.js";
7
+ import { publishOrgAdminsInbox } from "../invalidation/audiences.js";
7
8
  /** An owned ref's display name: a plugin's (skills and agent templates have none). */
8
9
  const refDisplayName = (db, ref) => ref.kind === "plugin" ? itemDisplayName(db, ref.id) : Promise.resolve(null);
9
10
  /** A catalog item's display name for an upload notice (null without one, or for an unknown id). */
@@ -16,11 +17,13 @@ export async function itemDisplayName(db, itemId) {
16
17
  return row?.display_name ?? null;
17
18
  }
18
19
  /** Writes an org notice in the caller's transaction. */
19
- export async function addOrgNotice(db, orgId, kind, detail) {
20
+ export async function addOrgNotice(db, hints, orgId, kind, detail) {
20
21
  await db
21
22
  .insertInto("org_notices")
22
23
  .values({ id: randomUUID(), org_id: orgId, kind, detail: JSON.stringify(detail) })
23
24
  .execute();
25
+ // the org's admins see it in their inbox (account invalidation stream spec §4)
26
+ publishOrgAdminsInbox(hints, [orgId]);
24
27
  }
25
28
  const OWNER_TABLE = {
26
29
  plugin: "catalog_items",
@@ -31,12 +34,12 @@ const OWNER_TABLE = {
31
34
  * Tells the owner org that its item was shared (`item_shared`): with each org of `orgs` (the owner
32
35
  * itself is skipped), or with `all_orgs`. A platform-owned item writes nothing.
33
36
  */
34
- export async function notifyItemShared(db, ownerOrgId, ref, name, orgs) {
37
+ export async function notifyItemShared(db, hints, ownerOrgId, ref, name, orgs) {
35
38
  if (ownerOrgId === null)
36
39
  return;
37
40
  const displayName = await refDisplayName(db, ref);
38
41
  if (orgs === "all_orgs") {
39
- await addOrgNotice(db, ownerOrgId, "item_shared", {
42
+ await addOrgNotice(db, hints, ownerOrgId, "item_shared", {
40
43
  ref,
41
44
  name,
42
45
  displayName,
@@ -54,7 +57,7 @@ export async function notifyItemShared(db, ownerOrgId, ref, name, orgs) {
54
57
  .execute();
55
58
  const names = new Map(rows.map((r) => [r.id, r.name]));
56
59
  for (const id of targets) {
57
- await addOrgNotice(db, ownerOrgId, "item_shared", {
60
+ await addOrgNotice(db, hints, ownerOrgId, "item_shared", {
58
61
  ref,
59
62
  name,
60
63
  displayName,
@@ -67,7 +70,7 @@ export async function notifyItemShared(db, ownerOrgId, ref, name, orgs) {
67
70
  * that it changed version (`shared_item_updated`); returns how many orgs were told. A platform-owned
68
71
  * or missing item tells nobody.
69
72
  */
70
- export async function notifySharedUpdate(db, ref, change) {
73
+ export async function notifySharedUpdate(db, hints, ref, change) {
71
74
  const row = await db
72
75
  .selectFrom(OWNER_TABLE[ref.kind])
73
76
  .select("owner_org_id")
@@ -79,7 +82,7 @@ export async function notifySharedUpdate(db, ref, change) {
79
82
  const using = await orgsUsing(db, ref, { except: row.owner_org_id });
80
83
  const displayName = await refDisplayName(db, ref);
81
84
  for (const o of using) {
82
- await withOrgScope(o.id, () => addOrgNotice(db, o.id, "shared_item_updated", {
85
+ await withOrgScope(o.id, () => addOrgNotice(db, hints, o.id, "shared_item_updated", {
83
86
  ref,
84
87
  name: change.name,
85
88
  displayName,
@@ -3,6 +3,7 @@ import { type CatalogItemView, CatalogService } from "../catalog/catalog.service
3
3
  import { CatalogRequestsService, type CatalogRequestView } from "../catalog/requests.service.js";
4
4
  import type { ScopeSyncOp } from "../db/kernel-schema.js";
5
5
  import { KernelDb } from "../infra/database/kernel-db.js";
6
+ import type { HintPublisher } from "../invalidation/audiences.js";
6
7
  import type { PlatformNoticeDetails, PlatformNoticeKind } from "./platform-notices.js";
7
8
  /** The most items one platform inbox read returns. */
8
9
  export declare const PLATFORM_INBOX_MAX_ITEMS = 100;
@@ -131,7 +132,8 @@ export declare class PlatformInboxService {
131
132
  private readonly requests;
132
133
  private readonly catalog;
133
134
  private readonly kdb;
134
- constructor(requests: Pick<CatalogRequestsService, "listDeployment" | "countPendingDeployment">, catalog: Pick<CatalogService, "list">, kdb: KernelDb);
135
+ private readonly hints;
136
+ constructor(requests: Pick<CatalogRequestsService, "listDeployment" | "countPendingDeployment">, catalog: Pick<CatalogService, "list">, kdb: KernelDb, hints: HintPublisher);
135
137
  list(): Promise<PlatformInboxView>;
136
138
  /**
137
139
  * How many items wait (the sidebar's count): the same sources, counted where they can be (the
@@ -13,6 +13,8 @@ import { CatalogService } from "../catalog/catalog.service.js";
13
13
  import { CatalogRequestsService } from "../catalog/requests.service.js";
14
14
  import { ApiError } from "../errors.js";
15
15
  import { KernelDb } from "../infra/database/kernel-db.js";
16
+ import { PLATFORM_ADMINS_TOPIC } from "../invalidation/hints.js";
17
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
16
18
  /** The most items one platform inbox read returns. */
17
19
  export const PLATFORM_INBOX_MAX_ITEMS = 100;
18
20
  /** The most open scope sync failures one read takes. */
@@ -36,10 +38,12 @@ let PlatformInboxService = class PlatformInboxService {
36
38
  requests;
37
39
  catalog;
38
40
  kdb;
39
- constructor(requests, catalog, kdb) {
41
+ hints;
42
+ constructor(requests, catalog, kdb, hints) {
40
43
  this.requests = requests;
41
44
  this.catalog = catalog;
42
45
  this.kdb = kdb;
46
+ this.hints = hints;
43
47
  }
44
48
  async list() {
45
49
  const [requests, requestCount, pending, failures, failureCount, disabled, disabledCount, notices, noticeCount,] = await Promise.all([
@@ -172,8 +176,11 @@ let PlatformInboxService = class PlatformInboxService {
172
176
  .where("id", "=", id)
173
177
  .where("dismissed_at", "is", null)
174
178
  .executeTakeFirst();
175
- if (r.numUpdatedRows > 0n)
179
+ if (r.numUpdatedRows > 0n) {
180
+ // dismissed for every super admin: their platform inboxes refetch
181
+ this.hints.publishAfterCommit([PLATFORM_ADMINS_TOPIC], { kind: "platform-inbox" });
176
182
  return;
183
+ }
177
184
  const exists = await this.kdb.db
178
185
  .selectFrom("platform_notices")
179
186
  .select("id")
@@ -257,7 +264,8 @@ PlatformInboxService = __decorate([
257
264
  Injectable(),
258
265
  __param(0, Inject(CatalogRequestsService)),
259
266
  __param(1, Inject(CatalogService)),
260
- __param(2, Inject(KernelDb))
267
+ __param(2, Inject(KernelDb)),
268
+ __param(3, Inject(InvalidationHints))
261
269
  ], PlatformInboxService);
262
270
  export { PlatformInboxService };
263
271
  /**
@@ -1,5 +1,6 @@
1
1
  import type { OwnedRef } from "../catalog/ownership.js";
2
2
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
+ import type { HintPublisher } from "../invalidation/audiences.js";
3
4
  export type PlatformNoticeKind = "ownership_transferred" | "push_auth_failed";
4
5
  /** The `detail` of each platform notice kind. */
5
6
  export interface PlatformNoticeDetails {
@@ -23,11 +24,11 @@ export interface PlatformNoticeDetails {
23
24
  plugin: string;
24
25
  };
25
26
  }
26
- export declare function addPlatformNotice<K extends PlatformNoticeKind>(db: KernelSchemaDb, kind: K, detail: PlatformNoticeDetails[K]): Promise<void>;
27
+ export declare function addPlatformNotice<K extends PlatformNoticeKind>(db: KernelSchemaDb, hints: HintPublisher, kind: K, detail: PlatformNoticeDetails[K]): Promise<void>;
27
28
  /**
28
29
  * Tells the super admins that `plugin`'s push credentials were refused, unless a notice of that
29
30
  * kind naming the plugin is still open. The partial unique index
30
31
  * `platform_notices_push_auth_open_idx` (migration 0173) keeps it at one open notice per plugin
31
32
  * even when deliveries on several replicas fail at once.
32
33
  */
33
- export declare function addPushAuthNotice(db: KernelSchemaDb, plugin: string): Promise<void>;
34
+ export declare function addPushAuthNotice(db: KernelSchemaDb, hints: HintPublisher, plugin: string): Promise<void>;
@@ -2,11 +2,13 @@
2
2
  // are told, until any one of them dismisses it. Written in the caller's transaction.
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { sql } from "kysely";
5
- export async function addPlatformNotice(db, kind, detail) {
5
+ import { PLATFORM_ADMINS_TOPIC } from "../invalidation/hints.js";
6
+ export async function addPlatformNotice(db, hints, kind, detail) {
6
7
  await db
7
8
  .insertInto("platform_notices")
8
9
  .values({ id: randomUUID(), kind, detail: JSON.stringify(detail) })
9
10
  .execute();
11
+ hints.publishAfterCommit([PLATFORM_ADMINS_TOPIC], { kind: "platform-inbox" });
10
12
  }
11
13
  /**
12
14
  * Tells the super admins that `plugin`'s push credentials were refused, unless a notice of that
@@ -14,9 +16,9 @@ export async function addPlatformNotice(db, kind, detail) {
14
16
  * `platform_notices_push_auth_open_idx` (migration 0173) keeps it at one open notice per plugin
15
17
  * even when deliveries on several replicas fail at once.
16
18
  */
17
- export async function addPushAuthNotice(db, plugin) {
19
+ export async function addPushAuthNotice(db, hints, plugin) {
18
20
  const detail = { plugin };
19
- await db
21
+ const inserted = await db
20
22
  .insertInto("platform_notices")
21
23
  .values({ id: randomUUID(), kind: "push_auth_failed", detail: JSON.stringify(detail) })
22
24
  .onConflict((oc) => oc
@@ -25,5 +27,9 @@ export async function addPushAuthNotice(db, plugin) {
25
27
  .where("kind", "=", sql.lit("push_auth_failed"))
26
28
  .where("dismissed_at", "is", null)
27
29
  .doNothing())
28
- .execute();
30
+ .returning("id")
31
+ .executeTakeFirst();
32
+ if (inserted !== undefined) {
33
+ hints.publishAfterCommit([PLATFORM_ADMINS_TOPIC], { kind: "platform-inbox" });
34
+ }
29
35
  }
@@ -25,8 +25,11 @@ const HOT_APPLIERS = {
25
25
  "log.level": (k, v) => k.log.setLevel(String(v)),
26
26
  // The runtime reads the concurrency cap through the config service on every quota request.
27
27
  "runtime.orgConcurrency": () => { },
28
- // MeStreams reads the per-account stream cap at every stream open.
28
+ // SSE stream families read their per-account cap when admitting a new connection.
29
29
  "runtime.meStreamMaxPerAccount": () => { },
30
+ "runtime.orgUiStreamMaxPerAccount": () => { },
31
+ "runtime.platformUiStreamMaxPerAccount": () => { },
32
+ "runtime.conversationStreamMaxPerAccount": () => { },
30
33
  // Eval org concurrency is read the same way at every quota request.
31
34
  "evals.orgConcurrency": () => { },
32
35
  // The git gateway reads tools.git.enabled through the config service on every request.