@capybara-hq/kernel 0.1.0-rc.137 → 0.1.0-rc.139

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 (101) hide show
  1. package/bootstrap.json +31 -31
  2. package/dist/admin/extensions.controller.d.ts +5 -2
  3. package/dist/admin/extensions.controller.js +10 -1
  4. package/dist/admin/extensions.schemas.d.ts +4 -0
  5. package/dist/admin/extensions.schemas.js +9 -0
  6. package/dist/admin/health.service.d.ts +1 -1
  7. package/dist/admin/health.service.js +3 -3
  8. package/dist/catalog/catalog-content.d.ts +5 -7
  9. package/dist/catalog/catalog-items.js +1 -1
  10. package/dist/catalog/catalog-scope.service.js +5 -5
  11. package/dist/catalog/catalog.module.js +5 -4
  12. package/dist/catalog/catalog.service.d.ts +7 -1
  13. package/dist/catalog/catalog.service.js +19 -2
  14. package/dist/catalog/effect-work.d.ts +27 -0
  15. package/dist/catalog/effect-work.js +151 -0
  16. package/dist/catalog/jobs.d.ts +4 -1
  17. package/dist/catalog/jobs.js +14 -4
  18. package/dist/catalog/org-catalog.service.d.ts +2 -0
  19. package/dist/catalog/org-catalog.service.js +68 -12
  20. package/dist/catalog/org-intent.d.ts +4 -2
  21. package/dist/catalog/org-intent.js +25 -4
  22. package/dist/catalog/owned-items.d.ts +5 -1
  23. package/dist/catalog/owned-items.js +18 -3
  24. package/dist/catalog/plugin-import.d.ts +4 -2
  25. package/dist/catalog/plugin-import.js +10 -5
  26. package/dist/catalog/plugin-install.d.ts +17 -51
  27. package/dist/catalog/plugin-install.js +209 -235
  28. package/dist/catalog/plugin-upgrade.d.ts +8 -3
  29. package/dist/catalog/plugin-upgrade.js +63 -34
  30. package/dist/catalog/scope-sync-workers.d.ts +7 -11
  31. package/dist/catalog/scope-sync-workers.js +10 -26
  32. package/dist/catalog/scope-sync.d.ts +19 -114
  33. package/dist/catalog/scope-sync.js +220 -239
  34. package/dist/catalog/scope-writer.d.ts +10 -1
  35. package/dist/catalog/scope-writer.js +62 -4
  36. package/dist/catalog/template-connector-ensure.js +1 -1
  37. package/dist/catalog/unshare.js +1 -2
  38. package/dist/config/schema.d.ts +1 -1
  39. package/dist/config/schema.js +7 -4
  40. package/dist/db/kernel-schema.d.ts +18 -17
  41. package/dist/erasure/org-catalog.js +2 -2
  42. package/dist/erasure/org-rules.js +2 -2
  43. package/dist/extensions/admin-ops.d.ts +1 -1
  44. package/dist/extensions/admin-ops.js +1 -1
  45. package/dist/extensions/admin-view.d.ts +4 -1
  46. package/dist/extensions/admin-view.js +27 -11
  47. package/dist/extensions/bootstrap.d.ts +1 -1
  48. package/dist/extensions/bootstrap.js +2 -3
  49. package/dist/extensions/enabled.d.ts +159 -0
  50. package/dist/extensions/enabled.js +7 -0
  51. package/dist/extensions/host.d.ts +1 -0
  52. package/dist/extensions/host.js +5 -2
  53. package/dist/extensions/isolated/authorization.d.ts +8 -0
  54. package/dist/extensions/isolated/authorization.js +56 -11
  55. package/dist/extensions/isolated/broker.js +30 -11
  56. package/dist/extensions/isolated/engine-binds.d.ts +9 -0
  57. package/dist/extensions/isolated/engine-binds.js +82 -0
  58. package/dist/extensions/isolated/engine-policy.d.ts +85 -0
  59. package/dist/extensions/isolated/engine-policy.js +75 -0
  60. package/dist/extensions/isolated/engine-proxy-main.d.ts +1 -0
  61. package/dist/extensions/isolated/engine-proxy-main.js +20 -0
  62. package/dist/extensions/isolated/engine-proxy.d.ts +7 -0
  63. package/dist/extensions/isolated/engine-proxy.js +408 -0
  64. package/dist/extensions/isolated/engine-vaults.d.ts +12 -0
  65. package/dist/extensions/isolated/engine-vaults.js +93 -0
  66. package/dist/extensions/isolated/lanes.d.ts +11 -3
  67. package/dist/extensions/isolated/lanes.js +43 -16
  68. package/dist/extensions/isolated/postgres-gate.d.ts +1 -0
  69. package/dist/extensions/isolated/postgres-gate.js +6 -6
  70. package/dist/extensions/isolated/revision.d.ts +1 -1
  71. package/dist/extensions/isolated/revision.js +3 -2
  72. package/dist/extensions/isolated/sandbox.d.ts +10 -6
  73. package/dist/extensions/isolated/sandbox.js +101 -117
  74. package/dist/extensions/lifecycle-topics.d.ts +1 -0
  75. package/dist/extensions/lifecycle-topics.js +1 -0
  76. package/dist/extensions/lifecycle.js +23 -2
  77. package/dist/extensions/permission-view.d.ts +6 -1
  78. package/dist/inbox/platform-inbox.service.js +16 -27
  79. package/dist/infra/events/kernel-events.d.ts +4 -0
  80. package/dist/infra/outbox/registry.d.ts +3 -36
  81. package/dist/infra/outbox/registry.js +4 -49
  82. package/dist/infra/queue/queue-names.d.ts +1 -1
  83. package/dist/infra/queue/queue-names.js +1 -1
  84. package/dist/orgs/org-lock.d.ts +3 -1
  85. package/dist/orgs/org-lock.js +3 -1
  86. package/dist/orgs/orgs.service.d.ts +3 -1
  87. package/dist/orgs/orgs.service.js +15 -8
  88. package/dist/overrides.d.ts +0 -3
  89. package/dist/overrides.js +0 -2
  90. package/dist/platform/ops/extensions-admin.ops.js +20 -3
  91. package/dist/platform/ops/org-plugins.ops.js +5 -2
  92. package/dist/platform/ops/plugins.ops.js +11 -10
  93. package/dist/tools/registry.d.ts +1 -1
  94. package/dist/tools/registry.js +6 -2
  95. package/package.json +2 -2
  96. package/src/migrations/0231_plugin_effect_work.sql +171 -0
  97. package/src/migrations/0232_contract_plugin_effect_schema.sql +49 -0
  98. package/dist/catalog/install-status.d.ts +0 -5
  99. package/dist/catalog/install-status.js +0 -5
  100. package/dist/catalog/scope-jobs.d.ts +0 -59
  101. package/dist/catalog/scope-jobs.js +0 -78
@@ -401,44 +401,11 @@ export declare const OUTBOX_JOBS: {
401
401
  readonly removeOnFail: true;
402
402
  };
403
403
  };
404
- readonly "scope-item": {
405
- readonly queue: "cap-kernel-plugin-scope";
406
- readonly idempotent: "the fan-out owes the same chunk job ids again (`<item job id>-c<n>`), which the outbox and BullMQ dedupe, and each chunk converges from what it reads";
404
+ readonly "plugin-effect": {
405
+ readonly queue: "cap-kernel-plugin-effects";
406
+ readonly idempotent: "one organization lock and a pending generation check fence each effect; the recovery tick re-owes that generation";
407
407
  readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
408
408
  readonly opts: {
409
- readonly attempts: 7;
410
- readonly backoff: {
411
- readonly type: "exponential";
412
- readonly delay: 5000;
413
- };
414
- readonly removeOnComplete: true;
415
- readonly removeOnFail: true;
416
- };
417
- };
418
- readonly "scope-item-chunk": {
419
- readonly queue: "cap-kernel-plugin-scope";
420
- readonly idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing";
421
- readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
422
- readonly opts: {
423
- readonly attempts: 7;
424
- readonly backoff: {
425
- readonly type: "exponential";
426
- readonly delay: 5000;
427
- };
428
- readonly removeOnComplete: true;
429
- readonly removeOnFail: true;
430
- };
431
- };
432
- readonly "scope-org": {
433
- readonly queue: "cap-kernel-plugin-scope";
434
- readonly idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing";
435
- readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
436
- readonly opts: {
437
- readonly attempts: 7;
438
- readonly backoff: {
439
- readonly type: "exponential";
440
- readonly delay: 5000;
441
- };
442
409
  readonly removeOnComplete: true;
443
410
  readonly removeOnFail: true;
444
411
  };
@@ -1,21 +1,3 @@
1
- /**
2
- * The plugin scope queue's one retry policy (`scope-item`, `scope-item-chunk`, `scope-org`): 7
3
- * attempts, 5 s doubling, so the retries wait 5 + 10 + 20 + 40 + 80 + 160 = 315 s (about five
4
- * minutes) before the last attempt. That is the window a replica has to load an extension its
5
- * deploy enabled: the enable's `kernel.plugins.changed` message reconciles every replica at once,
6
- * and if a replica misses it, its periodic reconcile does within
7
- * `extensionHost.reconcileIntervalSeconds` (default 60 s). An interval longer than the window (it
8
- * is not capped: tests set an hour to keep the periodic reconcile out of the way) leaves such a
9
- * replica's chunk to its last attempt, which records `catalog.not_deployed` for the pair until the
10
- * next sync of the item.
11
- * Removed once done, so the next add of the same id is not swallowed.
12
- */
13
- const SCOPE_JOB_OPTS = {
14
- attempts: 7,
15
- backoff: { type: "exponential", delay: 5_000 },
16
- removeOnComplete: true,
17
- removeOnFail: true,
18
- };
19
1
  /**
20
2
  * The external conversation calls' retry policy: 10 attempts from 2 s, doubling (about 17 min in
21
3
  * all) before the call is dropped with a failed turn; removed once done, so the same id owed again
@@ -361,38 +343,11 @@ export const OUTBOX_JOBS = {
361
343
  removeOnFail: true,
362
344
  },
363
345
  },
364
- // `catalog/scope-jobs.ts` SCOPE_ITEM_JOB: owed by every transaction that changes what an item's
365
- // sync converges to (its scope, disabled flag, list, owner or platform version, an import's
366
- // commit deploying no extension) and by the deploy of its extension (enable, a new version of an
367
- // enabled one, an approval), under `scopeItemJobId` (one per owing transaction, spec §8.1)
368
- "scope-item": {
369
- queue: "cap-kernel-plugin-scope",
370
- idempotent: "the fan-out owes the same chunk job ids again (`<item job id>-c<n>`), which the outbox and BullMQ dedupe, and each chunk converges from what it reads",
371
- processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
372
- // the plugin scope queue's one retry policy (a PG or Redis blip); removed once done, so the
373
- // next add of the same id is not swallowed
374
- opts: SCOPE_JOB_OPTS,
375
- },
376
- // `catalog/scope-jobs.ts` SCOPE_CHUNK_JOB: owed by a scope-item job, one per chunk of orgs, under
377
- // `scopeChunkJobId`
378
- "scope-item-chunk": {
379
- queue: "cap-kernel-plugin-scope",
380
- idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing",
346
+ "plugin-effect": {
347
+ queue: "cap-kernel-plugin-effects",
348
+ idempotent: "one organization lock and a pending generation check fence each effect; the recovery tick re-owes that generation",
381
349
  processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
382
- // retried while the item's extension is enabled but not loaded on the replica (the job throws
383
- // after its other pairs, P3-38): 5 s doubling, about five minutes in all; the last attempt
384
- // installs anyway and records what fails. A pair's own failure is recorded and does not fail
385
- // the job; a retry of a deferred chunk attempts every pair again, a failed one included
386
- // (idempotent: it converges from what it reads)
387
- opts: SCOPE_JOB_OPTS,
388
- },
389
- // `catalog/scope-jobs.ts` SCOPE_ORG_JOB: owed by an org's creation, under `scopeOrgJobId`
390
- "scope-org": {
391
- queue: "cap-kernel-plugin-scope",
392
- idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing",
393
- processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
394
- // as a chunk job: retried while one of its items' extensions is not loaded on the replica
395
- opts: SCOPE_JOB_OPTS,
350
+ opts: { removeOnComplete: true, removeOnFail: true },
396
351
  },
397
352
  // `automations/job-ids.ts` AUTOMATION_FIRE_JOB: owed by the transaction that writes a pending task run
398
353
  // (the scan's tick, a person's "run now"), under `automationFireJobId` (spec §8.1)
@@ -4,5 +4,5 @@
4
4
  * (admin/health.service.ts) lists the same names from the feature constants;
5
5
  * test/infra/queue-names.test.ts keeps the two equal.
6
6
  */
7
- export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors", "cap-device-service-events", "cap-external-calls"];
7
+ export declare const KERNEL_QUEUES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-tool-watch", "cap-kernel-plugin-effects", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle", "cap-push-deliver", "cap-connector-tools", "cap-template-connectors", "cap-device-service-events", "cap-external-calls"];
8
8
  export type KernelQueueName = (typeof KERNEL_QUEUES)[number];
@@ -10,7 +10,7 @@ export const KERNEL_QUEUES = [
10
10
  "cap-kernel-channels",
11
11
  "cap-kernel-maintenance",
12
12
  "cap-kernel-tool-watch",
13
- "cap-kernel-plugin-scope",
13
+ "cap-kernel-plugin-effects",
14
14
  "cap-kernel-titles",
15
15
  "cap-kernel-suggestions",
16
16
  "cap-kernel-usage-report",
@@ -19,7 +19,9 @@ export interface LockedOrg {
19
19
  * log append (a conversation row, then the org foreign key check). Nothing takes the org row
20
20
  * `FOR UPDATE`: org deletion's `deleted_at` update is a no-key update too.
21
21
  *
22
- * The global lock order: the org admission lock ({@link lockForRemoval}; the run fence's shared
22
+ * The global lock order starts with `EFFECT_CANDIDATES_LOCK` when needed. It serializes org
23
+ * creation and deletion with plugin import commits and other writes that change effect
24
+ * candidates. Then take the org admission lock ({@link lockForRemoval}; the run fence's shared
23
25
  * admission, `RunExecution`) → this org row lock (also the run fence's exclusive admission) → a
24
26
  * membership row → a device row (`DevicesService.lockOwn`, the device project writes, the cloud
25
27
  * permission snapshot) → the super admin advisory lock (`SuperAdminLock`) → the permission
@@ -26,7 +26,9 @@ import { can } from "./roles.js";
26
26
  * log append (a conversation row, then the org foreign key check). Nothing takes the org row
27
27
  * `FOR UPDATE`: org deletion's `deleted_at` update is a no-key update too.
28
28
  *
29
- * The global lock order: the org admission lock ({@link lockForRemoval}; the run fence's shared
29
+ * The global lock order starts with `EFFECT_CANDIDATES_LOCK` when needed. It serializes org
30
+ * creation and deletion with plugin import commits and other writes that change effect
31
+ * candidates. Then take the org admission lock ({@link lockForRemoval}; the run fence's shared
30
32
  * admission, `RunExecution`) → this org row lock (also the run fence's exclusive admission) → a
31
33
  * membership row → a device row (`DevicesService.lockOwn`, the device project writes, the cloud
32
34
  * permission snapshot) → the super admin advisory lock (`SuperAdminLock`) → the permission
@@ -8,6 +8,7 @@ import { ApiTokenService } from "../identity/api-tokens.js";
8
8
  import { SettingsService } from "../identity/settings.js";
9
9
  import { KernelDb } from "../infra/database/kernel-db.js";
10
10
  import { TransactionHost } from "../infra/database/transaction-host.js";
11
+ import { XactLock } from "../infra/database/xact-lock.js";
11
12
  import { KernelEvents } from "../infra/events/kernel-events.js";
12
13
  import { OutboxService } from "../infra/outbox/outbox.service.js";
13
14
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
@@ -39,6 +40,7 @@ export declare class OrgsService {
39
40
  /** Cancels the deleted org's running eval runs (in the delete's transaction). */
40
41
  private readonly evalBudget;
41
42
  /** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
43
+ private readonly xactLock;
42
44
  private readonly scopeSync;
43
45
  /** What the deleted org owns is transferred or removed in the delete's transaction (P3-20). */
44
46
  private readonly ownedItems;
@@ -51,7 +53,7 @@ export declare class OrgsService {
51
53
  /** Cancels the deleted org's running eval runs (in the delete's transaction). */
52
54
  evalBudget: Pick<EvalBudget, "cancelRuns">,
53
55
  /** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
54
- scopeSync: Pick<PluginScopeSync, "enqueueOrg">,
56
+ xactLock: XactLock, scopeSync: Pick<PluginScopeSync, "enqueueOrg">,
55
57
  /** What the deleted org owns is transferred or removed in the delete's transaction (P3-20). */
56
58
  ownedItems: Pick<OwnedItems, "onOrgDeleted">,
57
59
  /** Records `org.deleted` for the subscribing plugins in the delete's transaction. */
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { randomBytes, randomUUID } from "node:crypto";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
+ import { EFFECT_CANDIDATES_LOCK } from "../catalog/effect-work.js";
13
14
  import { OwnedItems } from "../catalog/owned-items.js";
14
15
  import { cancelPendingRequests } from "../catalog/request-rules.js";
15
16
  import { PluginScopeSync } from "../catalog/scope-sync.js";
@@ -27,6 +28,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
27
28
  import { asPlatform, withOrgScope } from "../infra/database/org-scope.js";
28
29
  import { TransactionHost } from "../infra/database/transaction-host.js";
29
30
  import { Transactional } from "../infra/database/transactional.decorator.js";
31
+ import { XactLock } from "../infra/database/xact-lock.js";
30
32
  import { KernelEvents } from "../infra/events/kernel-events.js";
31
33
  import { OutboxService } from "../infra/outbox/outbox.service.js";
32
34
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
@@ -95,6 +97,7 @@ let OrgsService = class OrgsService {
95
97
  orgLock;
96
98
  events;
97
99
  evalBudget;
100
+ xactLock;
98
101
  scopeSync;
99
102
  ownedItems;
100
103
  lifecycle;
@@ -105,7 +108,7 @@ let OrgsService = class OrgsService {
105
108
  /** Cancels the deleted org's running eval runs (in the delete's transaction). */
106
109
  evalBudget,
107
110
  /** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
108
- scopeSync,
111
+ xactLock, scopeSync,
109
112
  /** What the deleted org owns is transferred or removed in the delete's transaction (P3-20). */
110
113
  ownedItems,
111
114
  /** Records `org.deleted` for the subscribing plugins in the delete's transaction. */
@@ -118,6 +121,7 @@ let OrgsService = class OrgsService {
118
121
  this.orgLock = orgLock;
119
122
  this.events = events;
120
123
  this.evalBudget = evalBudget;
124
+ this.xactLock = xactLock;
121
125
  this.scopeSync = scopeSync;
122
126
  this.ownedItems = ownedItems;
123
127
  this.lifecycle = lifecycle;
@@ -143,6 +147,7 @@ let OrgsService = class OrgsService {
143
147
  const name = checkName(input.name);
144
148
  const slug = input.slug ?? slugFromName(name);
145
149
  checkSlug(slug);
150
+ await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
146
151
  await lockAccountForAdmission(this.db, actor.id);
147
152
  const row = await this.db
148
153
  .insertInto("orgs")
@@ -257,7 +262,8 @@ let OrgsService = class OrgsService {
257
262
  await this.softDeleteIn(orgId, actor, actorTokenId);
258
263
  }
259
264
  async softDeleteIn(orgId, actor, actorTokenId) {
260
- // the org admission lock exclusively first (it waits for the run writes the fence admitted
265
+ await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
266
+ // the org admission lock exclusively before the org row (it waits for the run writes the fence admitted
261
267
  // shared, which see the org deleted after this commits), then the org row, which admits the
262
268
  // other fenced run writes (`RunExecution`)
263
269
  // an unauthorized call is refused before it holds off the org's run writes
@@ -362,11 +368,12 @@ OrgsService = __decorate([
362
368
  __param(5, Inject(OrgLock)),
363
369
  __param(6, Inject(KernelEvents)),
364
370
  __param(7, Inject(EvalBudget)),
365
- __param(8, Inject(PluginScopeSync)),
366
- __param(9, Inject(OwnedItems)),
367
- __param(10, Inject(LifecycleHooks)),
368
- __param(11, Inject(PermissionCeilingWrites)),
369
- __param(12, Inject(ErasureRequests)),
370
- __param(13, Inject(StorageService))
371
+ __param(8, Inject(XactLock)),
372
+ __param(9, Inject(PluginScopeSync)),
373
+ __param(10, Inject(OwnedItems)),
374
+ __param(11, Inject(LifecycleHooks)),
375
+ __param(12, Inject(PermissionCeilingWrites)),
376
+ __param(13, Inject(ErasureRequests)),
377
+ __param(14, Inject(StorageService))
371
378
  ], OrgsService);
372
379
  export { OrgsService };
@@ -2,7 +2,6 @@ import type { NestInterceptor } from "@nestjs/common";
2
2
  import { APP_INTERCEPTOR } from "@nestjs/core";
3
3
  import { ADMIN_USAGE_TIMINGS, type AdminUsageTimings } from "./admin/usage.service.js";
4
4
  import { BACKGROUND_STOP_ATTEMPT_MS } from "./background/stop.js";
5
- import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
6
5
  import { CHANNEL_WEBHOOK_TIMINGS, type ChannelWebhookTimings } from "./channels/webhook.js";
7
6
  import { PROMPT_SUGGESTION_TIMEOUT } from "./conversations/prompt-suggestions.js";
8
7
  import { EXTENSION_NET_SEAMS, type ExtensionNetSeams } from "./ctx/net.js";
@@ -67,7 +66,6 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
67
66
  * - `PROMPT_SUGGESTION_TIMEOUT`: the prompt suggestion call's time limit, read at every call (a test
68
67
  * shortens it for one call);
69
68
  * - `PLUGIN_PUBLIC_WRITE_LIMIT`: a lower limit for unsafe methods on `public` extension routes;
70
- * - `SCOPE_ORG_CHUNK_SIZE`: fewer orgs per plugin scope sync chunk job (several chunks in a test);
71
69
  * - `EXTENSION_NET_SEAMS`: `ctx.net`'s DNS and dispatcher (a hostname resolving to a private address
72
70
  * served by a loopback fake);
73
71
  * - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes);
@@ -98,7 +96,6 @@ interface KernelSeams {
98
96
  [USAGE_SUBSCRIBERS_CLOCK]: () => number;
99
97
  [OUTBOX_FAST_PATH_SETTLED]: (pass: Promise<void>) => void;
100
98
  [ENSURE_RUN_FAILS]: () => boolean;
101
- [SCOPE_ORG_CHUNK_SIZE]: number;
102
99
  [PROJECT_KNOWLEDGE_TIMEOUT]: () => ProjectKnowledgeTimeouts;
103
100
  [PROMPT_SUGGESTION_TIMEOUT]: () => number;
104
101
  [PUSH_SEND_TIMEOUT_MS]: () => number;
package/dist/overrides.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { APP_INTERCEPTOR } from "@nestjs/core";
2
2
  import { ADMIN_USAGE_TIMINGS } from "./admin/usage.service.js";
3
3
  import { BACKGROUND_STOP_ATTEMPT_MS } from "./background/stop.js";
4
- import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
5
4
  import { CHANNEL_WEBHOOK_TIMINGS } from "./channels/webhook.js";
6
5
  import { PROMPT_SUGGESTION_TIMEOUT } from "./conversations/prompt-suggestions.js";
7
6
  import { EXTENSION_NET_SEAMS } from "./ctx/net.js";
@@ -53,7 +52,6 @@ const SEAM_TOKENS = [
53
52
  OUTBOX_DISPATCH_FAILS,
54
53
  OUTBOX_FAST_PATH_SETTLED,
55
54
  ENSURE_RUN_FAILS,
56
- SCOPE_ORG_CHUNK_SIZE,
57
55
  PROJECT_KNOWLEDGE_TIMEOUT,
58
56
  PROMPT_SUGGESTION_TIMEOUT,
59
57
  PUSH_SEND_TIMEOUT_MS,
@@ -9,7 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
- import { AdminExtensionConfigBody, AdminExtensionNamePathParams, } from "../../admin/extensions.schemas.js";
12
+ import { AdminExtensionConfigBody, AdminExtensionNamePathParams, AdminExtensionOrgCountsQuery, EXTENSION_ORG_COUNT_PAGE_SIZE, } from "../../admin/extensions.schemas.js";
13
13
  import { CatalogService } from "../../catalog/catalog.service.js";
14
14
  import { ApiError } from "../../errors.js";
15
15
  import { ExtensionAdminOps } from "../../extensions/admin-ops.js";
@@ -224,7 +224,7 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
224
224
  this.registry.register([
225
225
  defineOperation({
226
226
  id: "extensions.platform-list",
227
- description: "List the extensions on the platform (super admin), one compact row each: the deployment status (enabled, disabled, pending_approval, pending_config, pending_migration, converging, failed, dependency, conflict), why one does not run (reason) and your next step (next), its version, how many orgs have it on and whether it is required. Extensions only other orgs' own plugins bring are counted (otherOrgExtensions), never listed. Details come from extensions.platform-get. Pages by 50: pass the returned next as params.cursor.",
227
+ description: "List the extensions on the platform (super admin), one compact row each: the deployment status (enabled, disabled, pending_approval, pending_config, pending_migration, converging, failed, dependency, conflict), why one does not run (reason) and your next step (next), its version, how many orgs have it on and whether it is required. Extensions only other orgs' own plugins bring are counted (otherOrgExtensions), never listed. Details come from extensions.platform-get. Pass the returned next as params.cursor.",
228
228
  input: z.object({ cursor: Cursor.optional() }).strict(),
229
229
  example: {},
230
230
  authz: { superAdmin: true },
@@ -234,13 +234,30 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
234
234
  run: async (input, ctx) => {
235
235
  const theirs = await otherOrgExtensions(this.kdb.db, ctx.orgId);
236
236
  const all = (await this.admin.list()).filter((v) => !theirs.has(v.name));
237
+ const page = pageOf(all, startOf(input.cursor), EXTENSION_ORG_COUNT_PAGE_SIZE);
238
+ const counts = new Map((await this.admin.orgCounts(page.items.map((v) => v.name))).map((v) => [v.name, v]));
237
239
  return {
238
- ...pageOf(all.map(row), startOf(input.cursor), 50),
240
+ ...page,
241
+ items: page.items.map((v) => row({ ...v, ...counts.get(v.name) })),
239
242
  otherOrgExtensions: theirs.size,
240
243
  drainSeconds: this.config.get().extensionHost.drainSeconds,
241
244
  };
242
245
  },
243
246
  }),
247
+ defineOperation({
248
+ id: "extensions.org-counts",
249
+ description: "Count the organizations where each of up to 20 platform extensions is enabled or needs configuration (super admin). Pass comma-separated extension names.",
250
+ input: AdminExtensionOrgCountsQuery,
251
+ example: { names: "model-openai,device-local" },
252
+ authz: { superAdmin: true },
253
+ mirrors: ["GET /api/v1/admin/extensions/counts/orgs"],
254
+ confirm: "read",
255
+ run: async (input, ctx) => {
256
+ const theirs = await otherOrgExtensions(this.kdb.db, ctx.orgId);
257
+ const names = input.names.split(",").filter((name) => !theirs.has(name));
258
+ return { counts: await this.admin.orgCounts(names) };
259
+ },
260
+ }),
244
261
  defineOperation({
245
262
  id: "extensions.pending-permissions",
246
263
  description: "List what waits for a super admin to confirm extension permissions (super admin): extensions whose permissions changed since they were approved (state pending_approval, with the permission keys added and removed and whether they are sensitive) and catalog plugins waiting for a confirmation. State and permission keys only, never config values. Other orgs' own plugins are only counted (otherOrgItems, otherOrgExtensions). Confirming is done by you in the admin console. Pages by 50: pass the returned next as params.cursor.",
@@ -44,7 +44,7 @@ const installRow = (i) => ({
44
44
  id: i.id,
45
45
  name: i.name,
46
46
  state: i.status,
47
- ...(i.error !== null && { reason: `${i.error.step}: ${i.error.code}` }),
47
+ ...(i.error !== null && { reason: `${i.error.operation}: ${i.error.code}` }),
48
48
  itemId: i.itemId,
49
49
  version: i.version,
50
50
  components: i.components.length,
@@ -460,7 +460,10 @@ let OrgPluginsOperations = class OrgPluginsOperations {
460
460
  },
461
461
  run: async (input, ctx) => {
462
462
  const r = await this.orgCatalog.install(ctx.orgId, ctx.actorAccountId, input.itemId, input.templatesOn !== undefined ? { templatesOn: input.templatesOn } : {}, undefined, viaAgent("plugins.install", ctx));
463
- return { installed: r.installed, install: installRow(r.install) };
463
+ return {
464
+ installed: r.installed,
465
+ install: r.install === null ? null : installRow(r.install),
466
+ };
464
467
  },
465
468
  }),
466
469
  ]);
@@ -63,6 +63,7 @@ const brief = (i, role) => ({
63
63
  description: i.description,
64
64
  scope: i.scope,
65
65
  state: i.state,
66
+ ...(i.setup !== undefined && { setup: i.setup }),
66
67
  ...unavailableFields(i.reason, enName(i), role),
67
68
  switchable: i.switchable,
68
69
  builtin: i.builtin,
@@ -78,6 +79,7 @@ const row = (i, role) => ({
78
79
  id: i.id,
79
80
  name: i.name,
80
81
  state: i.state,
82
+ ...(i.setup !== undefined && { setup: i.setup }),
81
83
  ...unavailableFields(i.reason, enName(i), role),
82
84
  displayName: i.displayName,
83
85
  switchable: i.switchable,
@@ -186,14 +188,16 @@ let PluginsOperations = class PluginsOperations {
186
188
  if (!d.item.switchable)
187
189
  throw new ToolError(LOCKED);
188
190
  const live = d.item.installed;
189
- if (live === null) {
191
+ const preview = live === null
192
+ ? await this.orgCatalog.previewContentOff(ctx.orgId, input.itemId)
193
+ : await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
194
+ if (preview === null) {
190
195
  return {
191
196
  preview: null,
192
197
  confirm: NOTHING_INSTALLED,
193
198
  next: "Nothing is installed in the org, so switching off removes nothing; pass this confirm value.",
194
199
  };
195
200
  }
196
- const preview = await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
197
201
  return { preview, confirm: uninstallPreviewHash(preview) };
198
202
  },
199
203
  }),
@@ -286,14 +290,11 @@ let PluginsOperations = class PluginsOperations {
286
290
  return { zh: `在本组织启用插件「${n.zh}」`, en: `Enable plugin "${n.en}" in the org` };
287
291
  }
288
292
  const live = item.installed;
289
- if (live === null) {
290
- return {
291
- zh: `在本组织停用插件「${n.zh}」(本组织未安装任何内容)`,
292
- en: `Disable plugin "${n.en}" in the org (nothing is installed here)`,
293
- };
294
- }
295
- // the preview the confirm value binds: what goes, and the agents that lose it
296
- const p = await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
293
+ const p = live === null
294
+ ? await this.orgCatalog.previewContentOff(ctx.orgId, i.itemId)
295
+ : await this.installer.previewUninstall(ctx.orgId, live.pluginInstallId);
296
+ if (p === null)
297
+ return { zh: `在本组织停用插件「${n.zh}」`, en: `Disable plugin "${n.en}" in the org` };
297
298
  return {
298
299
  zh: `在本组织停用插件「${n.zh}」:移除 ${p.components.length} 个组件,${p.agents.length} 个智能体在用`,
299
300
  en: `Disable plugin "${n.en}" in the org: removes ${p.components.length} components; ${p.agents.length} agents use it`,
@@ -454,7 +454,7 @@ export declare class ToolRegistry {
454
454
  kind: string;
455
455
  plugin: string;
456
456
  }[]>;
457
- /** True when `kind` is one of {@link connectorKindsFor}: loaded here and enabled in the org. */
457
+ /** Setup sees the same intent as the runtime, including writes in its transaction. */
458
458
  connectorKindAvailable(orgId: string, kind: string): Promise<boolean>;
459
459
  /**
460
460
  * Checks a definition's `disabledTools` on save (existence only): a builtin an agent can turn off
@@ -12,6 +12,7 @@ import { connectorToolKey, extensionToolKey } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
13
  import { builtinDisabled, connectorToolDisabled, extensionToolDisabled, } from "../agents/definition.js";
14
14
  import { EffectiveConfigs, NEEDS_CONFIG_REASON } from "../extensions/effective-config.js";
15
+ import { isExtensionEnabled } from "../extensions/enabled.js";
15
16
  import { ExtensionHost } from "../extensions/host.js";
16
17
  import { extensionVisibleTo } from "../extensions/org-config.js";
17
18
  import { ExtensionRegistry } from "../extensions/registry.js";
@@ -253,9 +254,12 @@ let ToolRegistry = class ToolRegistry {
253
254
  .map(([kind, plugin]) => ({ kind, plugin }))
254
255
  .sort((a, b) => a.kind.localeCompare(b.kind));
255
256
  }
256
- /** True when `kind` is one of {@link connectorKindsFor}: loaded here and enabled in the org. */
257
+ /** Setup sees the same intent as the runtime, including writes in its transaction. */
257
258
  async connectorKindAvailable(orgId, kind) {
258
- return (await this.connectorKindsFor(orgId)).some((k) => k.kind === kind);
259
+ const entry = this.extensions
260
+ .list("connector")
261
+ .find((entry) => entry.impl?.kind === kind);
262
+ return entry !== undefined && (await isExtensionEnabled(this.db.db, orgId, entry.plugin));
259
263
  }
260
264
  /**
261
265
  * Checks a definition's `disabledTools` on save (existence only): a builtin an agent can turn off
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.137",
3
+ "version": "0.1.0-rc.139",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -82,7 +82,7 @@
82
82
  "@types/yauzl": "3.4.0",
83
83
  "pg-cursor": "^2.22.1",
84
84
  "ws": "^8.22.0",
85
- "@capybara-hq/testing": "0.1.0-rc.57"
85
+ "@capybara-hq/testing": "0.1.0-rc.58"
86
86
  },
87
87
  "scripts": {
88
88
  "build": "tsc -b"