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

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 (134) 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 +30 -11
  12. package/dist/agents/admin-agents.js +51 -16
  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/marketplace-fetch.d.ts +2 -0
  25. package/dist/catalog/marketplace-fetch.js +7 -2
  26. package/dist/catalog/marketplaces.service.d.ts +1 -1
  27. package/dist/catalog/plugin-package.js +2 -1
  28. package/dist/client/client-access.service.js +29 -1
  29. package/dist/config/schema.d.ts +9 -0
  30. package/dist/config/schema.js +26 -0
  31. package/dist/ctx/create-ctx.d.ts +2 -19
  32. package/dist/ctx/create-ctx.js +3 -93
  33. package/dist/ctx/durable-relay.d.ts +2 -5
  34. package/dist/ctx/durable-relay.js +56 -29
  35. package/dist/db/extension-handoff-schema.js +5 -0
  36. package/dist/db/kernel-schema.d.ts +74 -0
  37. package/dist/erasure/account-batches.js +2 -0
  38. package/dist/erasure/account-residual.js +1 -0
  39. package/dist/erasure/org-catalog.js +8 -3
  40. package/dist/erasure/org-rules.js +1 -0
  41. package/dist/errors.d.ts +1 -1
  42. package/dist/errors.js +2 -2
  43. package/dist/evals/evals.schemas.d.ts +15 -5
  44. package/dist/evals/evals.schemas.js +17 -10
  45. package/dist/evals/runs.controller.d.ts +4 -12
  46. package/dist/evals/runs.controller.js +14 -11
  47. package/dist/evals/runs.service.d.ts +29 -25
  48. package/dist/evals/runs.service.js +73 -61
  49. package/dist/evals/trajectory.controller.d.ts +10 -6
  50. package/dist/evals/trajectory.controller.js +11 -4
  51. package/dist/evals/trajectory.service.d.ts +17 -9
  52. package/dist/evals/trajectory.service.js +52 -35
  53. package/dist/extensions/admin-ops.js +4 -3
  54. package/dist/extensions/blobs.d.ts +2 -0
  55. package/dist/extensions/blobs.js +11 -0
  56. package/dist/extensions/enabled.d.ts +5 -0
  57. package/dist/extensions/grant-epoch.d.ts +108 -0
  58. package/dist/extensions/grant-epoch.js +214 -0
  59. package/dist/extensions/host.d.ts +30 -10
  60. package/dist/extensions/host.js +162 -43
  61. package/dist/extensions/instance.d.ts +3 -3
  62. package/dist/extensions/instance.js +1 -1
  63. package/dist/extensions/isolated/authorization.d.ts +54 -2
  64. package/dist/extensions/isolated/authorization.js +148 -35
  65. package/dist/extensions/isolated/child-session.js +0 -1
  66. package/dist/extensions/isolated/revision.js +1 -1
  67. package/dist/extensions/isolated/tier.d.ts +14 -0
  68. package/dist/extensions/isolated/tier.js +27 -0
  69. package/dist/extensions/package-digest.job.d.ts +34 -0
  70. package/dist/extensions/package-digest.job.js +121 -0
  71. package/dist/extensions/package.js +10 -6
  72. package/dist/extensions/permission-set.d.ts +14 -78
  73. package/dist/extensions/permission-set.js +17 -143
  74. package/dist/extensions/permission-view.d.ts +13 -1
  75. package/dist/extensions/permission-view.js +20 -0
  76. package/dist/extensions/publisher-proof.job.d.ts +39 -0
  77. package/dist/extensions/publisher-proof.job.js +160 -0
  78. package/dist/extensions/registry.js +4 -1
  79. package/dist/extensions/resolve.d.ts +7 -8
  80. package/dist/extensions/resolve.js +7 -8
  81. package/dist/extensions/revision-approvals.d.ts +167 -0
  82. package/dist/extensions/revision-approvals.js +353 -0
  83. package/dist/extensions/revision-grants.d.ts +197 -0
  84. package/dist/extensions/revision-grants.js +584 -0
  85. package/dist/extensions/state.module.js +12 -1
  86. package/dist/identity/accounts.d.ts +10 -4
  87. package/dist/identity/accounts.js +18 -5
  88. package/dist/infra/database/extension-effect-key-lock.js +7 -0
  89. package/dist/infra/paging/paged-read.d.ts +34 -4
  90. package/dist/infra/paging/paged-read.js +38 -1
  91. package/dist/orgs/invitations.controller.d.ts +4 -7
  92. package/dist/orgs/invitations.controller.js +8 -5
  93. package/dist/orgs/invitations.service.d.ts +17 -3
  94. package/dist/orgs/invitations.service.js +35 -13
  95. package/dist/orgs/members.service.d.ts +35 -0
  96. package/dist/orgs/members.service.js +52 -3
  97. package/dist/orgs/orgs.controller.d.ts +11 -4
  98. package/dist/orgs/orgs.controller.js +25 -5
  99. package/dist/orgs/orgs.schemas.d.ts +14 -0
  100. package/dist/orgs/orgs.schemas.js +19 -2
  101. package/dist/orgs/orgs.service.d.ts +21 -1
  102. package/dist/orgs/orgs.service.js +40 -1
  103. package/dist/orgs/security-settings.service.d.ts +14 -6
  104. package/dist/orgs/security-settings.service.js +18 -13
  105. package/dist/orgs/settings.controller.d.ts +7 -4
  106. package/dist/packages/official-publisher.d.ts +5 -0
  107. package/dist/packages/official-publisher.js +24 -3
  108. package/dist/packages/provenance.d.ts +6 -0
  109. package/dist/packages/provenance.js +26 -9
  110. package/dist/platform/exclusions.js +15 -0
  111. package/dist/platform/ops/accounts.ops.js +7 -16
  112. package/dist/platform/ops/admin-items.ops.js +8 -8
  113. package/dist/platform/ops/automations.ops.js +6 -4
  114. package/dist/platform/ops/evals.ops.js +30 -15
  115. package/dist/platform/ops/org-settings.ops.js +2 -2
  116. package/dist/platform/ops/orgs.ops.js +44 -27
  117. package/dist/roles/worker.module.js +6 -0
  118. package/dist/runtime/step-log.d.ts +1 -1
  119. package/dist/runtime/step-log.js +5 -4
  120. package/dist/setup/kernel-checks.d.ts +3 -3
  121. package/dist/setup/kernel-checks.js +4 -4
  122. package/dist/setup/setup-check-registry.d.ts +16 -5
  123. package/dist/setup/setup-check-registry.js +11 -3
  124. package/dist/setup/setup-checks.service.d.ts +1 -2
  125. package/dist/setup/setup-checks.service.js +7 -6
  126. package/dist/tools/admin-connectors.d.ts +10 -8
  127. package/dist/tools/admin-connectors.js +12 -10
  128. package/dist/tools/builtins/automations.d.ts +1 -1
  129. package/dist/tools/builtins/automations.js +1 -1
  130. package/package.json +3 -3
  131. package/src/migrations/0234_extension_grant_epoch.sql +141 -0
  132. package/src/migrations/0235_extension_revision_grants.sql +166 -0
  133. package/src/migrations/0236_paged_table_idx.sql +33 -0
  134. package/src/migrations/0237_extension_handoff_health.sql +18 -0
@@ -11,14 +11,16 @@ import { Controller, Delete, Get, HttpCode, Inject, Patch, Post } from "@nestjs/
11
11
  import { CurrentPrincipal, requireUser } from "../identity/principal.js";
12
12
  import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
13
13
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
14
- import { AutomationCalendarQueryDto, AutomationChatTargetsQueryDto, AutomationCreateBodyDto, AutomationEventSourcesQueryDto, AutomationGrantableQueryDto, AutomationGrantParamsDto, AutomationGrantsBodyDto, AutomationListQueryDto, AutomationParamsDto, AutomationRunBodyDto, AutomationRunsQueryDto, AutomationUpdateBodyDto, calendarInputOf, createInputOf, grantsOf, updateInputOf, } from "./automations.schemas.js";
14
+ import { AutomationCalendarQueryDto, AutomationChatTargetsQueryDto, AutomationCreateBodyDto, AutomationEventSourcesQueryDto, AutomationGrantableQueryDto, AutomationGrantParamsDto, AutomationGrantsBodyDto, AutomationListQueryDto, AutomationNextRunsQueryDto, AutomationParamsDto, AutomationRunBodyDto, AutomationRunsQueryDto, AutomationUpdateBodyDto, calendarInputOf, createInputOf, grantsOf, updateInputOf, } from "./automations.schemas.js";
15
15
  import { AutomationsService, } from "./automations.service.js";
16
16
  /**
17
17
  * Automations (`/api/v1/orgs/:orgId/automations`, spec 2026-11-11-scheduled-tasks §10); human
18
18
  * users only (a service token gets 403).
19
- * - `GET /` → `{ items }`: the caller's own tasks, each with its `lastRun`; `?all=true` every task
19
+ * - `GET /` → a page (`page`, `size`; table pagination spec §2.3) of the caller's own tasks, each with its `lastRun`; `?all=true` every task
20
20
  * of the org (org admins, `automations.manage`, enforced by the service: 403 `forbidden`
21
21
  * otherwise); `?conversationId=` only those posting into that conversation;
22
+ * - `GET /next-runs[?all=true]` → `{ items }`: every one of the caller's tasks (`all` as the
23
+ * list's) at once, each only `{ id, status, nextRunAt }` (the calendar's empty state);
22
24
  * - `GET /calendar?from&to&timeZone[&all][&taskId]` → the calendar (runs, planned occurrences,
23
25
  * collapsed task-days; calendar spec §5.1), `org.read` like the list, `all` as the list's;
24
26
  * - `GET /chat-targets` → `{ items }`: the chats the caller can point a `chat` task at;
@@ -46,11 +48,19 @@ let AutomationsController = class AutomationsController {
46
48
  // `all` is the service's admin check
47
49
  async list(principal, org, q) {
48
50
  const p = requireUser(principal);
49
- const items = await this.tasks.list(org.orgId, { accountId: p.account.id }, {
51
+ return this.tasks.list(org.orgId, { accountId: p.account.id }, {
50
52
  all: q.all === "true",
53
+ page: q.page,
54
+ size: q.size,
51
55
  ...(q.conversationId !== undefined && { conversationId: q.conversationId }),
52
56
  });
53
- return { items };
57
+ }
58
+ // declared before `:id`; org.read and `all` like the list
59
+ async nextRuns(principal, org, q) {
60
+ const p = requireUser(principal);
61
+ return {
62
+ items: await this.tasks.nextRuns(org.orgId, { accountId: p.account.id }, { all: q.all === "true" }),
63
+ };
54
64
  }
55
65
  // declared before `:id`; org.read like the list (a creator demoted to guest still reads their own)
56
66
  async calendar(principal, org, q) {
@@ -146,6 +156,13 @@ __decorate([
146
156
  __param(1, CurrentOrg()),
147
157
  __param(2, ZQuery(AutomationListQueryDto))
148
158
  ], AutomationsController.prototype, "list", null);
159
+ __decorate([
160
+ Get("next-runs"),
161
+ OrgAction("org.read"),
162
+ __param(0, CurrentPrincipal()),
163
+ __param(1, CurrentOrg()),
164
+ __param(2, ZQuery(AutomationNextRunsQueryDto))
165
+ ], AutomationsController.prototype, "nextRuns", null);
149
166
  __decorate([
150
167
  Get("calendar"),
151
168
  OrgAction("org.read"),
@@ -193,6 +193,8 @@ export declare const AutomationUpdateBody: z.ZodObject<{
193
193
  }>>>;
194
194
  }, z.core.$strict>;
195
195
  export declare const AutomationListQuery: z.ZodObject<{
196
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
197
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
196
198
  all: z.ZodOptional<z.ZodEnum<{
197
199
  false: "false";
198
200
  true: "true";
@@ -214,6 +216,13 @@ export declare const AutomationCalendarQuery: z.ZodObject<{
214
216
  }>>;
215
217
  taskId: z.ZodOptional<z.ZodString>;
216
218
  }, z.core.$strict>;
219
+ /** `GET …/automations/next-runs`: `all` as the list's (org admins). */
220
+ export declare const AutomationNextRunsQuery: z.ZodObject<{
221
+ all: z.ZodOptional<z.ZodEnum<{
222
+ false: "false";
223
+ true: "true";
224
+ }>>;
225
+ }, z.core.$strict>;
217
226
  export declare const AutomationChatTargetsQuery: z.ZodObject<{}, z.core.$strict>;
218
227
  export declare const AutomationEventSourcesQuery: z.ZodObject<{}, z.core.$strict>;
219
228
  export declare const AutomationGrantableQuery: z.ZodObject<{
@@ -363,6 +372,8 @@ declare const AutomationUpdateBodyDto_base: import("../infra/validation/create-z
363
372
  export declare class AutomationUpdateBodyDto extends AutomationUpdateBodyDto_base {
364
373
  }
365
374
  declare const AutomationListQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
375
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
376
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
366
377
  all: z.ZodOptional<z.ZodEnum<{
367
378
  false: "false";
368
379
  true: "true";
@@ -383,6 +394,14 @@ declare const AutomationCalendarQueryDto_base: import("../infra/validation/creat
383
394
  }, z.core.$strict>>;
384
395
  export declare class AutomationCalendarQueryDto extends AutomationCalendarQueryDto_base {
385
396
  }
397
+ declare const AutomationNextRunsQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
398
+ all: z.ZodOptional<z.ZodEnum<{
399
+ false: "false";
400
+ true: "true";
401
+ }>>;
402
+ }, z.core.$strict>>;
403
+ export declare class AutomationNextRunsQueryDto extends AutomationNextRunsQueryDto_base {
404
+ }
386
405
  declare const AutomationChatTargetsQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{}, z.core.$strict>>;
387
406
  export declare class AutomationChatTargetsQueryDto extends AutomationChatTargetsQueryDto_base {
388
407
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { PageQueryFields } from "../infra/paging/paged-read.js";
2
3
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
3
4
  import { IanaTimeZone } from "../time-zone.js";
4
5
  /** Longest task name and prompt, in characters (the same bounds as the service). */
@@ -117,6 +118,8 @@ export const AutomationListQuery = z
117
118
  all: z.enum(["true", "false"]).optional(),
118
119
  /** Only the tasks that post into this conversation (the conversation's side panel). */
119
120
  conversationId: Id.optional(),
121
+ // page numbers without a snapshot (table pagination spec §2.3: tasks are edited in place)
122
+ ...PageQueryFields,
120
123
  })
121
124
  .strict();
122
125
  /** An instant with an offset (`2026-11-09T00:00:00+08:00`). */
@@ -135,6 +138,10 @@ export const AutomationCalendarQuery = z
135
138
  taskId: Id.optional(),
136
139
  })
137
140
  .strict();
141
+ /** `GET …/automations/next-runs`: `all` as the list's (org admins). */
142
+ export const AutomationNextRunsQuery = z
143
+ .object({ all: z.enum(["true", "false"]).optional() })
144
+ .strict();
138
145
  export const AutomationChatTargetsQuery = z.object({}).strict();
139
146
  export const AutomationEventSourcesQuery = z.object({}).strict();
140
147
  export const AutomationGrantableQuery = z.object({ agentId: Id }).strict();
@@ -155,6 +162,8 @@ export class AutomationListQueryDto extends createZodDto(AutomationListQuery, "A
155
162
  }
156
163
  export class AutomationCalendarQueryDto extends createZodDto(AutomationCalendarQuery, "AutomationCalendarQuery") {
157
164
  }
165
+ export class AutomationNextRunsQueryDto extends createZodDto(AutomationNextRunsQuery, "AutomationNextRunsQuery") {
166
+ }
158
167
  export class AutomationChatTargetsQueryDto extends createZodDto(AutomationChatTargetsQuery, "AutomationChatTargetsQuery") {
159
168
  }
160
169
  export class AutomationEventSourcesQueryDto extends createZodDto(AutomationEventSourcesQuery, "AutomationEventSourcesQuery") {
@@ -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
  }
@@ -3,6 +3,8 @@ import type { KernelConfig } from "../config/schema.js";
3
3
  import { type LookupFn, NetDeniedError, type NetPolicy } from "../net/public-address.js";
4
4
  import { type OfficialNpmRevision, type OfficialPublisherProof } from "../packages/official-publisher.js";
5
5
  export declare function requireMarketplacePublisher(config: Pick<KernelConfig, "packages" | "marketplaces" | "net">, revision: OfficialNpmRevision, signal?: AbortSignal): Promise<OfficialPublisherProof>;
6
+ /** Whether a {@link requireMarketplacePublisher} failure was a network or registry hiccup. */
7
+ export declare function publisherCheckTransient(error: unknown): boolean;
6
8
  /**
7
9
  * Fetching a marketplace manifest `marketplace.json` (C26, spec §5.2) and a marketplace's archive
8
10
  * sources. The URLs come from a super admin or the config, but responses are always hostile
@@ -4,7 +4,7 @@ import { ApiError } from "../errors.js";
4
4
  import { NetDeniedError } from "../net/public-address.js";
5
5
  import { describeFetchError, safeFetch } from "../net/safe-fetch.js";
6
6
  import { isLoopback, readCapped } from "../packages/npm.js";
7
- import { fetchOfficialPublisher, } from "../packages/official-publisher.js";
7
+ import { fetchOfficialPublisher, OfficialPublisherError, } from "../packages/official-publisher.js";
8
8
  export async function requireMarketplacePublisher(config, revision, signal) {
9
9
  try {
10
10
  return await fetchOfficialPublisher({
@@ -16,9 +16,14 @@ export async function requireMarketplacePublisher(config, revision, signal) {
16
16
  }
17
17
  catch (error) {
18
18
  const reason = error instanceof Error ? error.message : String(error);
19
- throw new ApiError("marketplace.publisher_unverified", `Cannot verify the official publisher for ${revision.name}@${revision.version}: ${reason}`);
19
+ throw new ApiError("marketplace.publisher_unverified", `Cannot verify the official publisher for ${revision.name}@${revision.version}: ${reason}`, undefined, { cause: error });
20
20
  }
21
21
  }
22
+ /** Whether a {@link requireMarketplacePublisher} failure was a network or registry hiccup. */
23
+ export function publisherCheckTransient(error) {
24
+ const cause = error instanceof Error ? error.cause : undefined;
25
+ return cause instanceof OfficialPublisherError && cause.transient;
26
+ }
22
27
  /**
23
28
  * The API error for a refused download, or undefined when the refusal is not one of the two
24
29
  * marketplace codes (an invalid URL or a DNS failure is an ordinary fetch failure).
@@ -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>;