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

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/admin/admin-agents.controller.d.ts +3 -5
  2. package/dist/admin/admin-agents.controller.js +1 -1
  3. package/dist/admin/admin-connectors.controller.d.ts +3 -5
  4. package/dist/admin/admin-connectors.controller.js +1 -1
  5. package/dist/admin/admin-items.schemas.d.ts +6 -6
  6. package/dist/admin/admin-items.schemas.js +5 -9
  7. package/dist/admin/admin.controller.d.ts +18 -12
  8. package/dist/admin/admin.controller.js +29 -15
  9. package/dist/admin/admin.schemas.d.ts +12 -3
  10. package/dist/admin/admin.schemas.js +17 -6
  11. package/dist/agents/admin-agents.d.ts +10 -8
  12. package/dist/agents/admin-agents.js +13 -9
  13. package/dist/automations/automations.controller.d.ts +9 -5
  14. package/dist/automations/automations.controller.js +21 -4
  15. package/dist/automations/automations.schemas.d.ts +19 -0
  16. package/dist/automations/automations.schemas.js +9 -0
  17. package/dist/automations/automations.service.d.ts +25 -8
  18. package/dist/automations/automations.service.js +40 -34
  19. package/dist/automations/store.d.ts +17 -0
  20. package/dist/automations/store.js +35 -0
  21. package/dist/catalog/admin-catalog.controller.d.ts +64 -2
  22. package/dist/catalog/admin-catalog.controller.js +17 -0
  23. package/dist/catalog/cli.js +2 -2
  24. package/dist/catalog/marketplaces.service.d.ts +1 -1
  25. package/dist/catalog/plugin-package.js +2 -1
  26. package/dist/client/client-access.service.js +29 -1
  27. package/dist/config/schema.d.ts +9 -0
  28. package/dist/config/schema.js +26 -0
  29. package/dist/ctx/create-ctx.d.ts +2 -19
  30. package/dist/ctx/create-ctx.js +3 -93
  31. package/dist/ctx/durable-relay.d.ts +2 -5
  32. package/dist/ctx/durable-relay.js +56 -29
  33. package/dist/db/extension-handoff-schema.js +5 -0
  34. package/dist/db/kernel-schema.d.ts +74 -0
  35. package/dist/erasure/account-batches.js +2 -0
  36. package/dist/erasure/account-residual.js +1 -0
  37. package/dist/erasure/org-catalog.js +8 -3
  38. package/dist/erasure/org-rules.js +1 -0
  39. package/dist/evals/evals.schemas.d.ts +15 -5
  40. package/dist/evals/evals.schemas.js +17 -10
  41. package/dist/evals/runs.controller.d.ts +4 -12
  42. package/dist/evals/runs.controller.js +14 -11
  43. package/dist/evals/runs.service.d.ts +29 -25
  44. package/dist/evals/runs.service.js +73 -61
  45. package/dist/evals/trajectory.controller.d.ts +10 -6
  46. package/dist/evals/trajectory.controller.js +11 -4
  47. package/dist/evals/trajectory.service.d.ts +17 -9
  48. package/dist/evals/trajectory.service.js +52 -35
  49. package/dist/extensions/admin-ops.js +4 -3
  50. package/dist/extensions/blobs.d.ts +2 -0
  51. package/dist/extensions/blobs.js +11 -0
  52. package/dist/extensions/enabled.d.ts +5 -0
  53. package/dist/extensions/grant-epoch.d.ts +108 -0
  54. package/dist/extensions/grant-epoch.js +214 -0
  55. package/dist/extensions/host.d.ts +29 -9
  56. package/dist/extensions/host.js +148 -42
  57. package/dist/extensions/instance.d.ts +3 -3
  58. package/dist/extensions/instance.js +1 -1
  59. package/dist/extensions/isolated/authorization.d.ts +54 -2
  60. package/dist/extensions/isolated/authorization.js +148 -35
  61. package/dist/extensions/isolated/child-session.js +0 -1
  62. package/dist/extensions/isolated/revision.js +1 -1
  63. package/dist/extensions/package-digest.job.d.ts +34 -0
  64. package/dist/extensions/package-digest.job.js +121 -0
  65. package/dist/extensions/package.js +10 -6
  66. package/dist/extensions/permission-set.d.ts +14 -78
  67. package/dist/extensions/permission-set.js +17 -143
  68. package/dist/extensions/permission-view.d.ts +13 -1
  69. package/dist/extensions/permission-view.js +20 -0
  70. package/dist/extensions/registry.js +4 -1
  71. package/dist/extensions/resolve.d.ts +7 -8
  72. package/dist/extensions/resolve.js +7 -8
  73. package/dist/extensions/revision-approvals.d.ts +167 -0
  74. package/dist/extensions/revision-approvals.js +353 -0
  75. package/dist/extensions/revision-grants.d.ts +197 -0
  76. package/dist/extensions/revision-grants.js +584 -0
  77. package/dist/extensions/state.module.js +12 -1
  78. package/dist/identity/accounts.d.ts +10 -4
  79. package/dist/identity/accounts.js +18 -5
  80. package/dist/infra/database/extension-effect-key-lock.js +7 -0
  81. package/dist/infra/paging/paged-read.d.ts +34 -4
  82. package/dist/infra/paging/paged-read.js +38 -1
  83. package/dist/orgs/invitations.controller.d.ts +4 -7
  84. package/dist/orgs/invitations.controller.js +8 -5
  85. package/dist/orgs/invitations.service.d.ts +17 -3
  86. package/dist/orgs/invitations.service.js +35 -13
  87. package/dist/orgs/members.service.d.ts +35 -0
  88. package/dist/orgs/members.service.js +52 -3
  89. package/dist/orgs/orgs.controller.d.ts +11 -4
  90. package/dist/orgs/orgs.controller.js +25 -5
  91. package/dist/orgs/orgs.schemas.d.ts +14 -0
  92. package/dist/orgs/orgs.schemas.js +19 -2
  93. package/dist/orgs/orgs.service.d.ts +21 -1
  94. package/dist/orgs/orgs.service.js +40 -1
  95. package/dist/orgs/security-settings.service.d.ts +14 -6
  96. package/dist/orgs/security-settings.service.js +18 -13
  97. package/dist/orgs/settings.controller.d.ts +7 -4
  98. package/dist/platform/exclusions.js +15 -0
  99. package/dist/platform/ops/accounts.ops.js +7 -16
  100. package/dist/platform/ops/admin-items.ops.js +7 -7
  101. package/dist/platform/ops/automations.ops.js +6 -4
  102. package/dist/platform/ops/evals.ops.js +30 -15
  103. package/dist/platform/ops/org-settings.ops.js +2 -2
  104. package/dist/platform/ops/orgs.ops.js +44 -27
  105. package/dist/roles/worker.module.js +3 -0
  106. package/dist/runtime/step-log.d.ts +1 -1
  107. package/dist/runtime/step-log.js +5 -4
  108. package/dist/setup/kernel-checks.d.ts +3 -3
  109. package/dist/setup/kernel-checks.js +4 -4
  110. package/dist/setup/setup-check-registry.d.ts +16 -5
  111. package/dist/setup/setup-check-registry.js +11 -3
  112. package/dist/setup/setup-checks.service.d.ts +1 -2
  113. package/dist/setup/setup-checks.service.js +7 -6
  114. package/dist/tools/admin-connectors.d.ts +10 -8
  115. package/dist/tools/admin-connectors.js +12 -10
  116. package/dist/tools/builtins/automations.d.ts +1 -1
  117. package/dist/tools/builtins/automations.js +1 -1
  118. package/package.json +3 -3
  119. package/src/migrations/0234_extension_grant_epoch.sql +141 -0
  120. package/src/migrations/0235_extension_revision_grants.sql +166 -0
  121. package/src/migrations/0236_paged_table_idx.sql +33 -0
  122. package/src/migrations/0237_extension_handoff_health.sql +18 -0
@@ -11,6 +11,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
11
11
  import { KernelDb } from "../infra/database/kernel-db.js";
12
12
  import { TransactionHost } from "../infra/database/transaction-host.js";
13
13
  import { OutboxService } from "../infra/outbox/outbox.service.js";
14
+ import { type Page } from "../infra/paging/paged-read.js";
14
15
  import type { KernelLogger } from "../log.js";
15
16
  import { OrgLock } from "../orgs/org-lock.js";
16
17
  import { ProviderRegistry } from "../runtime/providers.js";
@@ -37,6 +38,11 @@ export type TriggerInput = {
37
38
  types: string[];
38
39
  filter?: EventFilter;
39
40
  };
41
+ /**
42
+ * A task as the web calendar's empty state needs it (`GET …/automations/next-runs`): whether it is
43
+ * active and when it fires next (the next planned run, or "all paused").
44
+ */
45
+ export type AutomationNextRun = Pick<Automation, "id" | "status" | "nextRunAt">;
40
46
  /** One trigger source that serves an org, as the automation form offers it. */
41
47
  export interface EventSourceView {
42
48
  source: string;
@@ -245,11 +251,27 @@ export declare class AutomationsService {
245
251
  get(orgId: string, actor: AutomationActor, id: string): Promise<AutomationView>;
246
252
  /** Each task with its creator as a person, in one query. */
247
253
  private withAccounts;
248
- /** The actor's own tasks; `all` (org admins only, else `forbidden`): every task of the org. */
249
- list(orgId: string, actor: AutomationActor, opts?: {
254
+ /** Every one of the actor's own tasks, newest first (the AutomationList tool). */
255
+ listOwn(orgId: string, actor: AutomationActor): Promise<AutomationListItem[]>;
256
+ /**
257
+ * One page of the actor's own tasks, newest first; `all` (org admins only, else `forbidden`):
258
+ * every task of the org; `conversationId`: only those posting into it. By page number without a
259
+ * snapshot (table pagination spec §2.3: tasks are edited in place).
260
+ */
261
+ list(orgId: string, actor: AutomationActor, opts: {
250
262
  all?: boolean;
251
263
  conversationId?: string;
252
- }): Promise<AutomationListItem[]>;
264
+ page: number;
265
+ size: number;
266
+ }): Promise<Page<AutomationListItem>>;
267
+ /**
268
+ * Every one of the actor's own live tasks, or with `all` (org admins only, else `forbidden`)
269
+ * every live task of the org, newest first, in the compact {@link AutomationNextRun} shape (the
270
+ * calendar's empty state; the task tables read {@link list}).
271
+ */
272
+ nextRuns(orgId: string, actor: AutomationActor, opts: {
273
+ all?: boolean;
274
+ }): Promise<AutomationNextRun[]>;
253
275
  /**
254
276
  * The calendar between two instants (calendar spec §5): the runs and planned occurrences of the
255
277
  * actor's own tasks, or with `all` (org admins only, else `forbidden`) every task of the org; with
@@ -265,11 +287,6 @@ export declare class AutomationsService {
265
287
  all?: boolean;
266
288
  taskId?: string;
267
289
  }, now?: Date, limits?: CalendarLimits): Promise<CalendarAnswer>;
268
- /**
269
- * The tasks of `tasks` that post into the conversation: a `conversation` task naming it, or a
270
- * `chat` task whose chat the conversation is a thread of (spec §10 side panel).
271
- */
272
- private postingInto;
273
290
  /** Each task with its latest settled non-trial run, in one query. */
274
291
  private withLastRuns;
275
292
  /**
@@ -25,6 +25,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
25
25
  import { TransactionHost } from "../infra/database/transaction-host.js";
26
26
  import { Transactional } from "../infra/database/transactional.decorator.js";
27
27
  import { OutboxService } from "../infra/outbox/outbox.service.js";
28
+ import { assertReadablePage, cappedCount, PAGED_TOTAL_CAP, pageOf, pageOffset, } from "../infra/paging/paged-read.js";
28
29
  import { KERNEL_LOGGER } from "../infra/tokens.js";
29
30
  import { OrgLock } from "../orgs/org-lock.js";
30
31
  import { can, roleAtLeast } from "../orgs/roles.js";
@@ -405,23 +406,48 @@ let AutomationsService = class AutomationsService {
405
406
  const people = await loadPeople(this.db.db, tasks.map((t) => t.accountId));
406
407
  return tasks.map((t) => ({ ...t, account: people.get(t.accountId) ?? null }));
407
408
  }
408
- /** The actor's own tasks; `all` (org admins only, else `forbidden`): every task of the org. */
409
- async list(orgId, actor, opts = {}) {
409
+ /** Every one of the actor's own tasks, newest first (the AutomationList tool). */
410
+ async listOwn(orgId, actor) {
411
+ await this.liveRole(orgId, actor.accountId);
412
+ const tasks = await this.store.listForAccount(this.db.db, orgId, actor.accountId);
413
+ return this.withLastRuns(orgId, tasks);
414
+ }
415
+ /**
416
+ * One page of the actor's own tasks, newest first; `all` (org admins only, else `forbidden`):
417
+ * every task of the org; `conversationId`: only those posting into it. By page number without a
418
+ * snapshot (table pagination spec §2.3: tasks are edited in place).
419
+ */
420
+ async list(orgId, actor, opts) {
421
+ assertReadablePage(opts.page, opts.size);
410
422
  const role = await this.liveRole(orgId, actor.accountId);
411
- let tasks;
412
- if (opts.all === true) {
413
- if (!can(role, "automations.manage")) {
414
- throw new ApiError("forbidden", "Only org admins can list every automation");
415
- }
416
- tasks = await this.store.listForOrg(this.db.db, orgId);
417
- }
418
- else {
419
- tasks = await this.store.listForAccount(this.db.db, orgId, actor.accountId);
423
+ if (opts.all === true && !can(role, "automations.manage")) {
424
+ throw new ApiError("forbidden", "Only org admins can list every automation");
420
425
  }
421
- if (opts.conversationId !== undefined) {
422
- tasks = await this.postingInto(orgId, tasks, opts.conversationId);
426
+ const filter = {
427
+ ...(opts.all !== true && { accountId: actor.accountId }),
428
+ ...(opts.conversationId !== undefined && { conversationId: opts.conversationId }),
429
+ };
430
+ const counted = await cappedCount(this.db.db, this.store.matching(this.db.db, orgId, filter), PAGED_TOTAL_CAP);
431
+ const tasks = await this.store.listMatching(this.db.db, orgId, filter, {
432
+ offset: pageOffset(opts.page, opts.size),
433
+ limit: opts.size,
434
+ });
435
+ return pageOf(await this.withLastRuns(orgId, tasks), opts, counted);
436
+ }
437
+ /**
438
+ * Every one of the actor's own live tasks, or with `all` (org admins only, else `forbidden`)
439
+ * every live task of the org, newest first, in the compact {@link AutomationNextRun} shape (the
440
+ * calendar's empty state; the task tables read {@link list}).
441
+ */
442
+ async nextRuns(orgId, actor, opts) {
443
+ const role = await this.liveRole(orgId, actor.accountId);
444
+ if (opts.all === true && !can(role, "automations.manage")) {
445
+ throw new ApiError("forbidden", "Only org admins can list every automation");
423
446
  }
424
- return this.withLastRuns(orgId, tasks);
447
+ const tasks = opts.all === true
448
+ ? await this.store.listForOrg(this.db.db, orgId)
449
+ : await this.store.listForAccount(this.db.db, orgId, actor.accountId);
450
+ return tasks.map((t) => ({ id: t.id, status: t.status, nextRunAt: t.nextRunAt }));
425
451
  }
426
452
  /**
427
453
  * The calendar between two instants (calendar spec §5): the runs and planned occurrences of the
@@ -475,26 +501,6 @@ let AutomationsService = class AutomationsService {
475
501
  collapse: q.taskId === undefined,
476
502
  }, limits);
477
503
  }
478
- /**
479
- * The tasks of `tasks` that post into the conversation: a `conversation` task naming it, or a
480
- * `chat` task whose chat the conversation is a thread of (spec §10 side panel).
481
- */
482
- async postingInto(orgId, tasks, conversationId) {
483
- const chats = tasks.some((t) => t.mode === "chat")
484
- ? await this.db.db
485
- .selectFrom("channel_threads")
486
- .innerJoin("channel_connections", "channel_connections.id", "channel_threads.connection_id")
487
- .select(["channel_threads.connection_id", "channel_threads.chat_id"])
488
- .where("channel_threads.conversation_id", "=", conversationId)
489
- .where("channel_connections.org_id", "=", orgId)
490
- .execute()
491
- : [];
492
- return tasks.filter((t) => t.mode === "conversation"
493
- ? t.conversationId === conversationId
494
- : t.mode === "chat" &&
495
- t.chat !== null &&
496
- chats.some((c) => c.connection_id === t.chat?.connectionId && c.chat_id === t.chat.chatId));
497
- }
498
504
  /** Each task with its latest settled non-trial run, in one query. */
499
505
  async withLastRuns(orgId, plain) {
500
506
  if (plain.length === 0)
@@ -64,6 +64,23 @@ export declare class AutomationStore {
64
64
  listForAccount(t: KernelSchemaDb, orgId: string, accountId: string): Promise<Automation[]>;
65
65
  /** Every live task of the org, newest first. */
66
66
  listForOrg(t: KernelSchemaDb, orgId: string): Promise<Automation[]>;
67
+ /**
68
+ * The org's live tasks, newest first (then id), one creator's when `accountId` is given, those
69
+ * posting into `conversationId` when given (a `conversation` task into it, a `chat` task into a
70
+ * chat whose thread it is); `window` is one page of them.
71
+ */
72
+ listMatching(t: KernelSchemaDb, orgId: string, filter: {
73
+ accountId?: string;
74
+ conversationId?: string;
75
+ }, window: {
76
+ offset: number;
77
+ limit: number;
78
+ }): Promise<Automation[]>;
79
+ /** The filtered query of {@link listMatching}, for its count too. */
80
+ matching(t: KernelSchemaDb, orgId: string, filter: {
81
+ accountId?: string;
82
+ conversationId?: string;
83
+ }): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase, "automations", {}>;
67
84
  /** Live tasks that count against the caps (`active` and `paused`), of the org or one creator. */
68
85
  countActive(t: KernelSchemaDb, orgId: string, accountId?: string): Promise<number>;
69
86
  /**
@@ -216,6 +216,41 @@ let AutomationStore = class AutomationStore {
216
216
  .execute();
217
217
  return rows.map(toTask);
218
218
  }
219
+ /**
220
+ * The org's live tasks, newest first (then id), one creator's when `accountId` is given, those
221
+ * posting into `conversationId` when given (a `conversation` task into it, a `chat` task into a
222
+ * chat whose thread it is); `window` is one page of them.
223
+ */
224
+ async listMatching(t, orgId, filter, window) {
225
+ const rows = await this.matching(t, orgId, filter)
226
+ .selectAll()
227
+ .orderBy("created_at", "desc")
228
+ .orderBy("id")
229
+ .offset(window.offset)
230
+ .limit(window.limit)
231
+ .execute();
232
+ return rows.map(toTask);
233
+ }
234
+ /** The filtered query of {@link listMatching}, for its count too. */
235
+ matching(t, orgId, filter) {
236
+ let q = t.selectFrom("automations").where("org_id", "=", orgId).where("deleted_at", "is", null);
237
+ if (filter.accountId !== undefined)
238
+ q = q.where("account_id", "=", filter.accountId);
239
+ const conversationId = filter.conversationId;
240
+ if (conversationId !== undefined) {
241
+ q = q.where(sql `(
242
+ (automations.mode = 'conversation' AND automations.conversation_id = ${conversationId})
243
+ OR (automations.mode = 'chat' AND EXISTS (
244
+ SELECT 1 FROM capybara.channel_threads th
245
+ JOIN capybara.channel_connections cc ON cc.id = th.connection_id
246
+ WHERE th.conversation_id = ${conversationId} AND cc.org_id = ${orgId}
247
+ AND th.connection_id = automations.chat->>'connectionId'
248
+ AND th.chat_id = automations.chat->>'chatId'
249
+ ))
250
+ )`);
251
+ }
252
+ return q;
253
+ }
219
254
  /** Live tasks that count against the caps (`active` and `paused`), of the org or one creator. */
220
255
  async countActive(t, orgId, accountId) {
221
256
  let q = t
@@ -1,4 +1,4 @@
1
- import type { SuggestedAppearance } from "@capybara-hq/plugin-sdk";
1
+ import { type PluginManifest, type SuggestedAppearance } from "@capybara-hq/plugin-sdk";
2
2
  import type { FastifyReply } from "fastify";
3
3
  import { z } from "zod";
4
4
  import { type ClientBuildSummary, ClientBuilds } from "../client/client-builds.service.js";
@@ -32,6 +32,67 @@ declare const ConfirmPermissionsBody: z.ZodObject<{
32
32
  * disable (previewed, then confirmed with `scopeHash`), delete. Writes re-check the super admin inside the service's lock and are
33
33
  * audited.
34
34
  */
35
+ /** Keep the catalog UI on normalized declaration values while artifacts retain authoring rows. */
36
+ declare function catalogManifestForDisplay(manifest: PluginManifest): {
37
+ $schema?: string;
38
+ schemaVersion: 1;
39
+ name: string;
40
+ version: string;
41
+ publisher: string;
42
+ description: import("@capybara-hq/plugin-sdk").PluginDescription;
43
+ displayName?: import("@capybara-hq/plugin-sdk").LocalizedName;
44
+ icon?: string;
45
+ license?: string;
46
+ homepage?: string;
47
+ dependencies?: import("@capybara-hq/plugin-sdk").PluginDependency[];
48
+ skills?: import("@capybara-hq/plugin-sdk").PluginSkillRef[];
49
+ connectorTemplates?: import("@capybara-hq/plugin-sdk").PluginConnectorTemplateRef[];
50
+ agents?: import("@capybara-hq/plugin-sdk").PluginAgentRef[];
51
+ themes?: import("@capybara-hq/plugin-sdk").PluginThemeRef[];
52
+ setupGuides?: import("@capybara-hq/plugin-sdk").PluginSetupGuide[];
53
+ suggestedAppearance?: SuggestedAppearance;
54
+ } | {
55
+ $schema?: string;
56
+ schemaVersion: 1;
57
+ name: string;
58
+ version: string;
59
+ publisher: string;
60
+ description: import("@capybara-hq/plugin-sdk").PluginDescription;
61
+ displayName?: import("@capybara-hq/plugin-sdk").LocalizedName;
62
+ icon?: string;
63
+ license?: string;
64
+ homepage?: string;
65
+ dependencies?: import("@capybara-hq/plugin-sdk").PluginDependency[];
66
+ skills?: import("@capybara-hq/plugin-sdk").PluginSkillRef[];
67
+ connectorTemplates?: import("@capybara-hq/plugin-sdk").PluginConnectorTemplateRef[];
68
+ agents?: import("@capybara-hq/plugin-sdk").PluginAgentRef[];
69
+ themes?: import("@capybara-hq/plugin-sdk").PluginThemeRef[];
70
+ setupGuides?: import("@capybara-hq/plugin-sdk").PluginSetupGuide[];
71
+ suggestedAppearance?: SuggestedAppearance;
72
+ extension: {
73
+ entry: string;
74
+ migrations?: string;
75
+ ui?: string;
76
+ configSchemas?: {
77
+ deployment?: import("@capybara-hq/plugin-sdk").JsonSchema;
78
+ };
79
+ client?: import("@capybara-hq/plugin-sdk").PluginClientSection;
80
+ manifest: {
81
+ name: string;
82
+ version: string;
83
+ sdk: string;
84
+ tables?: import("@capybara-hq/plugin-sdk").PermissionDeclaration<string>[];
85
+ ui?: import("@capybara-hq/plugin-sdk").ExtensionManifest["ui"];
86
+ config: {
87
+ deployment: import("@capybara-hq/plugin-sdk").StaticConfigField[];
88
+ };
89
+ provides: string[];
90
+ requires: string[];
91
+ optional: string[];
92
+ permissions: import("@capybara-hq/plugin-sdk").ExtensionPermissions;
93
+ };
94
+ };
95
+ };
35
96
  export declare class AdminCatalogController {
36
97
  private readonly catalog;
37
98
  private readonly pluginImport;
@@ -141,7 +202,8 @@ export declare class AdminCatalogController {
141
202
  * §5.4). Unknown -> 404 `catalog.item_not_found`.
142
203
  */
143
204
  get(id: string): Promise<Omit<CatalogItemDetail, "versions"> & {
144
- versions: (CatalogItemDetail["versions"][number] & {
205
+ versions: (Omit<CatalogItemDetail["versions"][number], "manifest"> & {
206
+ manifest: ReturnType<typeof catalogManifestForDisplay>;
145
207
  client: ClientBuildSummary | null;
146
208
  })[];
147
209
  hasIcon: boolean;
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
+ import { staticPermissionDeclarations, } from "@capybara-hq/plugin-sdk";
10
11
  import { Controller, Delete, Get, HttpCode, Inject, Param, Post, Put, Req, Res, } from "@nestjs/common";
11
12
  import { z } from "zod";
12
13
  import { ClientBuilds } from "../client/client-builds.service.js";
@@ -73,6 +74,21 @@ class AppearanceApplyBodyDto extends createZodDto(AppearanceApplyBody, "Appearan
73
74
  * disable (previewed, then confirmed with `scopeHash`), delete. Writes re-check the super admin inside the service's lock and are
74
75
  * audited.
75
76
  */
77
+ /** Keep the catalog UI on normalized declaration values while artifacts retain authoring rows. */
78
+ function catalogManifestForDisplay(manifest) {
79
+ const section = manifest.extension;
80
+ const { extension: _extension, ...rest } = manifest;
81
+ if (!section)
82
+ return rest;
83
+ const { provides, requires, optional, permissions } = staticPermissionDeclarations(section.manifest);
84
+ return {
85
+ ...rest,
86
+ extension: {
87
+ ...section,
88
+ manifest: { ...section.manifest, provides, requires, optional, permissions },
89
+ },
90
+ };
91
+ }
76
92
  let AdminCatalogController = class AdminCatalogController {
77
93
  catalog;
78
94
  pluginImport;
@@ -225,6 +241,7 @@ let AdminCatalogController = class AdminCatalogController {
225
241
  ...detail,
226
242
  versions: detail.versions.map((v) => ({
227
243
  ...v,
244
+ manifest: catalogManifestForDisplay(v.manifest),
228
245
  client: v.extensionSha256 === null ? null : (builds.get(v.extensionSha256) ?? null),
229
246
  })),
230
247
  hasIcon,
@@ -1,7 +1,7 @@
1
1
  import { mkdtemp, rm } from "node:fs/promises";
2
2
  import { tmpdir } from "node:os";
3
3
  import { join } from "node:path";
4
- import { OBJECT_STORE_EXTENSION_POINT, } from "@capybara-hq/plugin-sdk";
4
+ import { extensionPointRefs, OBJECT_STORE_EXTENSION_POINT, } from "@capybara-hq/plugin-sdk";
5
5
  import { ClientBuilds } from "../client/client-builds.service.js";
6
6
  import { ApiError } from "../errors.js";
7
7
  import { planApprovals, snapshotCovers } from "../extensions/approvals.js";
@@ -34,7 +34,7 @@ export async function loadCliObjectStore(cli, log, syncDir) {
34
34
  const providers = cli.inspected.filter((p) => p.manifest.provides.includes(OBJECT_STORE_EXTENSION_POINT));
35
35
  const declared = new Set(cli.inspected.map((p) => p.manifest.name));
36
36
  const installed = (await cli.installs.desired()).filter((d) => !declared.has(d.name) &&
37
- (d.section.manifest?.provides ?? []).includes(OBJECT_STORE_EXTENSION_POINT));
37
+ extensionPointRefs(d.section.manifest?.provides ?? []).includes(OBJECT_STORE_EXTENSION_POINT));
38
38
  if (providers.length === 0 && installed.length === 0) {
39
39
  return { store: undefined, reason: "no object-store extension is declared or installed" };
40
40
  }
@@ -209,7 +209,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
209
209
  /** The host versions (an entry's `minKernel` is judged against them). */
210
210
  export declare const HOST_VERSIONS: {
211
211
  readonly kernel: string;
212
- readonly sdk: "0.1.0-rc.101";
212
+ readonly sdk: "0.1.0-rc.102";
213
213
  };
214
214
  /** Whether this deployment satisfies the entry's `minKernel`. */
215
215
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -120,7 +120,8 @@ function clientUndeclared(text) {
120
120
  if (!isObj(ext) || ext.client === undefined)
121
121
  return undefined;
122
122
  const perms = isObj(ext.manifest) ? ext.manifest.permissions : undefined;
123
- if (isObj(perms) && perms.client === true)
123
+ if (isObj(perms) &&
124
+ (perms.client === true || (isObj(perms.client) && Object.hasOwn(perms.client, "purpose"))))
124
125
  return undefined;
125
126
  return `${PLUGIN_MANIFEST_FILE}: extension.client ships client code, but the extension manifest does not declare permissions.client: true; client code must be declared so it is reviewed (capybara-plugin pack writes both)`;
126
127
  }
@@ -135,6 +135,34 @@ let ClientAccess = class ClientAccess {
135
135
  */
136
136
  served(db) {
137
137
  const staleSeconds = STALE_RECONCILE_PERIODS * this.config.get().extensionHost.reconcileIntervalSeconds;
138
+ const declaredComponents = sql `p.section -> 'manifest' -> 'permissions' -> 'ui' -> 'components'`;
139
+ const approvedComponents = sql `coalesce(s.permissions -> 'permissions' -> 'ui' -> 'components', '[]'::jsonb)`;
140
+ // The package retains authored declarations. The snapshot approves the component IDs.
141
+ const componentApproval = sql `
142
+ not exists (
143
+ select 1 from jsonb_array_elements(
144
+ case
145
+ when ${declaredComponents} is null then '[]'::jsonb
146
+ when jsonb_typeof(${declaredComponents}) = 'array' then ${declaredComponents}
147
+ else '[null]'::jsonb
148
+ end
149
+ ) as declared(entry)
150
+ where not coalesce(
151
+ ${approvedComponents} @> case
152
+ when jsonb_typeof(declared.entry) = 'string'
153
+ then jsonb_build_array(declared.entry)
154
+ when jsonb_typeof(declared.entry -> 'value') = 'string'
155
+ and not (declared.entry ? 'covers')
156
+ then jsonb_build_array(declared.entry -> 'value')
157
+ when jsonb_typeof(declared.entry -> 'covers') = 'array'
158
+ and not (declared.entry ? 'value')
159
+ and declared.entry -> 'covers' <> '[]'::jsonb
160
+ then declared.entry -> 'covers'
161
+ end,
162
+ false
163
+ )
164
+ )
165
+ `;
138
166
  return db
139
167
  .selectFrom("extension_installs as i")
140
168
  .innerJoin("extension_client_builds as b", "b.plugin", "i.name")
@@ -142,7 +170,7 @@ let ClientAccess = class ClientAccess {
142
170
  .innerJoin("extension_permission_snapshots as s", "s.plugin", "i.name")
143
171
  .where("i.desired_state", "=", "enabled")
144
172
  .where(sql `s.permissions -> 'permissions' -> 'client' = 'true'::jsonb`)
145
- .where(sql `coalesce(s.permissions -> 'permissions' -> 'ui' -> 'components', '[]'::jsonb) @> coalesce(p.section -> 'manifest' -> 'permissions' -> 'ui' -> 'components', '[]'::jsonb)`)
173
+ .where(componentApproval)
146
174
  .where((eb) => eb.exists(eb
147
175
  .selectFrom("extension_replica_status as r")
148
176
  .select(sql `1`.as("one"))
@@ -10,6 +10,11 @@ export interface FieldMeta {
10
10
  * 构造给 Zod 4 `.meta()` 使用的字段元信息。
11
11
  * 用法:`z.string().meta(meta({ secret: true, description: "..." }))`。
12
12
  */
13
+ /** Defaults of `extensionHost.capacity`, also used where a hand-built config leaves it out. */
14
+ export declare const EXTENSION_CAPACITY_DEFAULTS: {
15
+ readonly grantEpochMaxAgeMs: 3000;
16
+ readonly grantCacheEntries: 10000;
17
+ };
13
18
  export declare function meta(opts: FieldMeta): FieldMeta;
14
19
  /** `sandbox.limits.maxCommandSeconds` 的默认值。 */
15
20
  export declare const DEFAULT_MAX_COMMAND_SECONDS = 7200;
@@ -102,6 +107,10 @@ export declare const KernelConfigSchema: z.ZodObject<{
102
107
  socketDir: z.ZodString;
103
108
  postgresSocket: z.ZodString;
104
109
  }, z.core.$strict>>;
110
+ capacity: z.ZodPrefault<z.ZodObject<{
111
+ grantEpochMaxAgeMs: z.ZodDefault<z.ZodNumber>;
112
+ grantCacheEntries: z.ZodDefault<z.ZodNumber>;
113
+ }, z.core.$strict>>;
105
114
  drainSeconds: z.ZodDefault<z.ZodNumber>;
106
115
  disposeTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
107
116
  reloadSetupTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
@@ -9,6 +9,11 @@ import { privateHostEntryProblem } from "../net/public-address.js";
9
9
  * 构造给 Zod 4 `.meta()` 使用的字段元信息。
10
10
  * 用法:`z.string().meta(meta({ secret: true, description: "..." }))`。
11
11
  */
12
+ /** Defaults of `extensionHost.capacity`, also used where a hand-built config leaves it out. */
13
+ export const EXTENSION_CAPACITY_DEFAULTS = {
14
+ grantEpochMaxAgeMs: 3000,
15
+ grantCacheEntries: 10_000,
16
+ };
12
17
  export function meta(opts) {
13
18
  return { ...opts };
14
19
  }
@@ -506,6 +511,27 @@ export const KernelConfigSchema = z.strictObject({
506
511
  })),
507
512
  })
508
513
  .optional(),
514
+ capacity: z
515
+ .strictObject({
516
+ grantEpochMaxAgeMs: z
517
+ .number()
518
+ .int()
519
+ .min(1500)
520
+ .max(3500)
521
+ .default(EXTENSION_CAPACITY_DEFAULTS.grantEpochMaxAgeMs)
522
+ .meta(meta({
523
+ description: "Milliseconds a replica trusts its cached isolated extension grants after its last successful read of the grant epoch (read every second); when the epoch is older, new isolated calls wait for a fresh read and are refused if it fails. Kept below the 4 s fence deadline, which leaves 1 s of slack under the 5 s revocation bound",
524
+ })),
525
+ grantCacheEntries: z
526
+ .number()
527
+ .int()
528
+ .positive()
529
+ .default(EXTENSION_CAPACITY_DEFAULTS.grantCacheEntries)
530
+ .meta(meta({
531
+ description: "Maximum isolated extension grants (one per running extension instance and org) each replica caches; the least recently used idle grant is evicted first, and a call is refused when every cached grant is in use",
532
+ })),
533
+ })
534
+ .prefault({}),
509
535
  drainSeconds: z
510
536
  .number()
511
537
  .int()
@@ -1,4 +1,4 @@
1
- import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher, type TriggerEvent } from "@capybara-hq/plugin-sdk";
1
+ import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type ObjectStore, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher, type TriggerEvent } from "@capybara-hq/plugin-sdk";
2
2
  import type { Redis } from "ioredis";
3
3
  import type { Kysely } from "kysely";
4
4
  import type { TriggerEventsService } from "../automations/events/trigger-events.service.js";
@@ -170,21 +170,6 @@ export type RegisteredSetupCheck = Readonly<{
170
170
  place: SetupGuidePlace;
171
171
  run: (args: SetupCheckArgs) => Promise<unknown>;
172
172
  }>;
173
- /** 插件经 `ctx.extensionPoints` 取用其他插件能力时,内核注入的访问接口。 */
174
- export interface ExtensionPointAccess {
175
- /** 已加载(setup 完成)的提供方,按加载顺序;按完整引用(含主版本)精确匹配。 */
176
- providers(ref: ExtensionPointRef): {
177
- plugin: string;
178
- impl: unknown;
179
- }[];
180
- /** Names of the extensions enabled in the organization (the org intent projection, `enabled.ts`); queried every time, not cached. */
181
- enabledPlugins(orgId: string): Promise<Set<string>>;
182
- /**
183
- * Whether the extension's effective config is valid in the organization (layering spec A §6):
184
- * a provider that is not is excluded from point resolution for that org.
185
- */
186
- configOk(orgId: string, plugin: string): Promise<boolean>;
187
- }
188
173
  /**
189
174
  * Queries the names of the extensions enabled in the organization (org config rows plus the
190
175
  * required bootstrap plugins, see `extensions/enabled.ts`), not cached.
@@ -280,15 +265,13 @@ export declare class LiveConfig {
280
265
  * replicas; `ui.verifyEmbedToken` checks an embed token the kernel signed: `claims.plugin` must be
281
266
  * this extension, the extension still enabled in that org and the caller still an active member of
282
267
  * the org (org not deleted); returns the current role;
283
- * - `extensionPoints` only gives extension points declared in `requires` / `optional` that are not
284
- * brokered (through `extensionPointAccess`).
285
268
  * - `hooks.on` only during setup, only mount points declared in `permissions.hooks` and available
286
269
  * (`HOOKS_AVAILABLE`), `policy` only on `POLICY_HOOKS` declared in `permissions.policyHooks`; kept on the ctx (`registeredHooks`, read by
287
270
  * the host's `HookRegistry` from active instances only) and recorded in the ledger.
288
271
  * An undeclared access throws `ExtensionPermissionError` and audits `extension.permission_denied`
289
272
  * (once per extension and item).
290
273
  */
291
- export declare function createExtensionContext(deps: KernelDeps, manifest: ExtensionManifest, deploymentConfig: unknown, extensionPointAccess?: ExtensionPointAccess,
274
+ export declare function createExtensionContext(deps: KernelDeps, manifest: ExtensionManifest, deploymentConfig: unknown, objectStore?: () => ObjectStore | undefined,
292
275
  /** The package this instance was loaded from (null: not from an install record). */
293
276
  identity?: {
294
277
  sha256: string | null;