@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
@@ -2,6 +2,7 @@ import type { z } from "zod";
2
2
  import { type AdminAgentDetail, type AdminAgentRow, AdminAgents } from "../agents/admin-agents.js";
3
3
  import { AgentsService } from "../agents/agents.service.js";
4
4
  import { type Principal } from "../identity/principal.js";
5
+ import type { Page } from "../infra/paging/paged-read.js";
5
6
  import { AdminAgentListQuery, AgentIdParams, OwnerBody } from "./admin-items.schemas.js";
6
7
  /**
7
8
  * Every org's agents for the super admin (admin agents and connectors spec §4.1): read any agent,
@@ -12,11 +13,8 @@ export declare class AdminAgentsController {
12
13
  private readonly admin;
13
14
  private readonly agents;
14
15
  constructor(admin: AdminAgents, agents: AgentsService);
15
- /** Live agents of live orgs by id; `next` is the `after` of the next page, null at the end. */
16
- list(q: z.infer<typeof AdminAgentListQuery>): Promise<{
17
- agents: AdminAgentRow[];
18
- next: string | null;
19
- }>;
16
+ /** Live agents of live orgs, newest first, by page number (table pagination spec §2.3). */
17
+ list(q: z.infer<typeof AdminAgentListQuery>): Promise<Page<AdminAgentRow>>;
20
18
  get({ agentId }: z.infer<typeof AgentIdParams>): Promise<{
21
19
  agent: AdminAgentDetail;
22
20
  }>;
@@ -33,7 +33,7 @@ let AdminAgentsController = class AdminAgentsController {
33
33
  this.admin = admin;
34
34
  this.agents = agents;
35
35
  }
36
- /** Live agents of live orgs by id; `next` is the `after` of the next page, null at the end. */
36
+ /** Live agents of live orgs, newest first, by page number (table pagination spec §2.3). */
37
37
  list(q) {
38
38
  return this.admin.list(q);
39
39
  }
@@ -1,5 +1,6 @@
1
1
  import type { z } from "zod";
2
2
  import { type Principal } from "../identity/principal.js";
3
+ import type { Page } from "../infra/paging/paged-read.js";
3
4
  import { type AdminConnectorDetail, type AdminConnectorRow, AdminConnectors } from "../tools/admin-connectors.js";
4
5
  import { ConnectorsService } from "../tools/connectors.service.js";
5
6
  import { AdminConnectorListQuery, ConnectorIdParams, ConnectorStatusBody } from "./admin-items.schemas.js";
@@ -12,11 +13,8 @@ export declare class AdminConnectorsController {
12
13
  private readonly admin;
13
14
  private readonly connectors;
14
15
  constructor(admin: AdminConnectors, connectors: ConnectorsService);
15
- /** Live connectors of live orgs by id; `next` is the `after` of the next page, null at the end. */
16
- list(q: z.infer<typeof AdminConnectorListQuery>): Promise<{
17
- connectors: AdminConnectorRow[];
18
- next: string | null;
19
- }>;
16
+ /** Live connectors of live orgs, newest first, by page number (table pagination spec §2.3). */
17
+ list(q: z.infer<typeof AdminConnectorListQuery>): Promise<Page<AdminConnectorRow>>;
20
18
  get({ connectorId }: z.infer<typeof ConnectorIdParams>): Promise<{
21
19
  connector: AdminConnectorDetail;
22
20
  }>;
@@ -33,7 +33,7 @@ let AdminConnectorsController = class AdminConnectorsController {
33
33
  this.admin = admin;
34
34
  this.connectors = connectors;
35
35
  }
36
- /** Live connectors of live orgs by id; `next` is the `after` of the next page, null at the end. */
36
+ /** Live connectors of live orgs, newest first, by page number (table pagination spec §2.3). */
37
37
  list(q) {
38
38
  return this.admin.list(q);
39
39
  }
@@ -1,16 +1,16 @@
1
1
  import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
- /** `GET /api/v1/admin/agents`: org filter, name search, id paging. */
3
+ /** `GET /api/v1/admin/agents`: org filter, name search, page numbers (no snapshot: spec §2.3). */
4
4
  export declare const AdminAgentListQuery: z.ZodObject<{
5
- after: z.ZodOptional<z.ZodString>;
6
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
5
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
6
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
7
7
  orgId: z.ZodOptional<z.ZodString>;
8
8
  q: z.ZodOptional<z.ZodString>;
9
9
  }, z.core.$strip>;
10
- /** `GET /api/v1/admin/connectors`: org and status filters, name search, id paging. */
10
+ /** `GET /api/v1/admin/connectors`: org and status filters, name search, page numbers. */
11
11
  export declare const AdminConnectorListQuery: z.ZodObject<{
12
- after: z.ZodOptional<z.ZodString>;
13
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
12
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
13
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
14
14
  orgId: z.ZodOptional<z.ZodString>;
15
15
  status: z.ZodOptional<z.ZodEnum<{
16
16
  active: "active";
@@ -1,27 +1,23 @@
1
1
  import { z } from "zod";
2
+ import { PageQueryFields } from "../infra/paging/paged-read.js";
2
3
  /**
3
4
  * Schemas of the super admin's routes for every org's agents and connectors (admin agents and
4
5
  * connectors spec §4.1). Ids are `text` columns, so a malformed id cannot fail the query: it is
5
6
  * bounded here (400 `validation_failed` past 100 characters) and otherwise reads as not found.
6
7
  */
7
8
  const Id = z.string().min(1).max(100);
8
- const Paging = {
9
- /** The last id of the previous page (the `next` of the previous response). */
10
- after: Id.optional(),
11
- limit: z.coerce.number().int().min(1).max(200).default(50),
12
- };
13
- /** `GET /api/v1/admin/agents`: org filter, name search, id paging. */
9
+ /** `GET /api/v1/admin/agents`: org filter, name search, page numbers (no snapshot: spec §2.3). */
14
10
  export const AdminAgentListQuery = z.object({
15
11
  orgId: Id.optional(),
16
12
  q: z.string().max(200).optional(),
17
- ...Paging,
13
+ ...PageQueryFields,
18
14
  });
19
- /** `GET /api/v1/admin/connectors`: org and status filters, name search, id paging. */
15
+ /** `GET /api/v1/admin/connectors`: org and status filters, name search, page numbers. */
20
16
  export const AdminConnectorListQuery = z.object({
21
17
  orgId: Id.optional(),
22
18
  status: z.enum(["active", "disabled"]).optional(),
23
19
  q: z.string().max(200).optional(),
24
- ...Paging,
20
+ ...PageQueryFields,
25
21
  });
26
22
  export const AgentIdParams = z.object({ agentId: Id });
27
23
  export const ConnectorIdParams = z.object({ connectorId: Id });
@@ -9,15 +9,16 @@ import { SessionService } from "../identity/sessions.js";
9
9
  import { type DeploymentSettingsView, SettingsService } from "../identity/settings.js";
10
10
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
11
11
  import { KernelDb } from "../infra/database/kernel-db.js";
12
+ import type { Page } from "../infra/paging/paged-read.js";
12
13
  import { type ModelDisabledPatch, type ModelProviderParams } from "../models/enablement.controller.js";
13
14
  import { type ModelDisableResult, ModelEnablement } from "../models/enablement.js";
14
15
  import { type ModelPrice, type ModelPricePut, PricesService } from "../models/prices.js";
15
16
  import { ModelPurposesService, type PurposeListing, type PurposePut } from "../models/purposes.js";
16
17
  import { type Member, MembersService } from "../orgs/members.service.js";
17
- import { type Org, OrgsService } from "../orgs/orgs.service.js";
18
+ import { type Org, type OrgDirectoryEntry, OrgsService } from "../orgs/orgs.service.js";
18
19
  import { type PlatformProviderState, ProviderRegistry, type ProviderStatus } from "../runtime/providers.js";
19
20
  import { AccountErasures } from "./account-erasures.js";
20
- import { AccountErasureBody, AccountListQuery, AccountParams, AdminOrgParams, CreateAccountBody, DeploymentSettingsBody, ErasureDispositionBody, ErasureWorkParams, PurposeParams, UpdateAccountBody } from "./admin.schemas.js";
21
+ import { AccountErasureBody, AccountListQuery, AccountParams, AdminOrgListQuery, AdminOrgParams, CreateAccountBody, DeploymentSettingsBody, ErasureDispositionBody, ErasureWorkParams, PurposeParams, UpdateAccountBody } from "./admin.schemas.js";
21
22
  import { ErasureDispositions } from "./erasure-dispositions.js";
22
23
  import { type LimitDefaults } from "./limit-defaults.js";
23
24
  /**
@@ -45,12 +46,10 @@ export declare class AdminController {
45
46
  /** One account with its avatar URL and source. */
46
47
  private view;
47
48
  /**
48
- * 全部账号,按 id 升序分页:`next` 为下一页的游标(作为 `after` 传回),没有更多时为 null。
49
- * 多取一条判断是否还有下一页。
49
+ * Every account, newest first, by page number (table pagination spec §2.3, no snapshot), with
50
+ * whether account erasure is on.
50
51
  */
51
- listAccounts(q: z.infer<typeof AccountListQuery>): Promise<{
52
- accounts: AccountView[];
53
- next: string | null;
52
+ listAccounts(q: z.infer<typeof AccountListQuery>): Promise<Page<AccountView> & {
54
53
  erasureEnabled: boolean;
55
54
  }>;
56
55
  requestAccountErasure(principal: Principal, { accountId }: z.infer<typeof AccountParams>, _body: z.infer<typeof AccountErasureBody>): Promise<{
@@ -89,15 +88,22 @@ export declare class AdminController {
89
88
  account: AccountView;
90
89
  }>;
91
90
  /**
92
- * 全部组织的元数据与成员数(不含成员明细), with the deployment's defaults of the limits an org
91
+ * One page of the live orgs with their member counts (never the members), newest first, by
92
+ * page number (table pagination spec §2.3), with the deployment's defaults of the limits an org
93
93
  * can be given its own value of (the org limits dialog shows them for the values left empty).
94
94
  */
95
- listOrgs(): Promise<{
96
- orgs: (Org & {
97
- memberCount: number;
98
- })[];
95
+ listOrgs(q: z.infer<typeof AdminOrgListQuery>): Promise<Page<Org & {
96
+ memberCount: number;
97
+ }> & {
99
98
  limitDefaults: LimitDefaults;
100
99
  }>;
100
+ /**
101
+ * Every live org at once in the compact directory shape (id, slug, name), oldest first: the org
102
+ * filters, pickers and names of the console; the orgs table pages `GET orgs`.
103
+ */
104
+ orgDirectory(): Promise<{
105
+ orgs: OrgDirectoryEntry[];
106
+ }>;
101
107
  /**
102
108
  * The members of any live org (the agent owner transfer picks the new owner from them); the super
103
109
  * admin need not be a member. A missing or deleted org → `org.not_found`.
@@ -30,7 +30,7 @@ import { MembersService } from "../orgs/members.service.js";
30
30
  import { OrgsService } from "../orgs/orgs.service.js";
31
31
  import { ProviderRegistry, } from "../runtime/providers.js";
32
32
  import { AccountErasures } from "./account-erasures.js";
33
- import { AccountErasureBody, AccountListQuery, AccountParams, AdminOrgParams, CreateAccountBody, DeploymentSettingsBody, ErasureDispositionBody, ErasureWorkParams, PurposeParams, UpdateAccountBody, } from "./admin.schemas.js";
33
+ import { AccountErasureBody, AccountListQuery, AccountParams, AdminOrgListQuery, AdminOrgParams, CreateAccountBody, DeploymentSettingsBody, ErasureDispositionBody, ErasureWorkParams, PurposeParams, UpdateAccountBody, } from "./admin.schemas.js";
34
34
  import { ErasureDispositions } from "./erasure-dispositions.js";
35
35
  import { limitDefaults } from "./limit-defaults.js";
36
36
  class AccountErasureBodyDto extends createZodDto(AccountErasureBody, "AccountErasureBody") {
@@ -47,6 +47,8 @@ class UpdateAccountBodyDto extends createZodDto(UpdateAccountBody, "UpdateAccoun
47
47
  }
48
48
  class AccountParamsDto extends createZodDto(AccountParams, "AccountParams") {
49
49
  }
50
+ class AdminOrgListQueryDto extends createZodDto(AdminOrgListQuery, "AdminOrgListQuery") {
51
+ }
50
52
  class AdminOrgParamsDto extends createZodDto(AdminOrgParams, "AdminOrgParams") {
51
53
  }
52
54
  class PurposeParamsDto extends createZodDto(PurposeParams, "PurposeParams") {
@@ -99,20 +101,15 @@ let AdminController = class AdminController {
99
101
  return withAvatarUrl(this.db.db, account);
100
102
  }
101
103
  /**
102
- * 全部账号,按 id 升序分页:`next` 为下一页的游标(作为 `after` 传回),没有更多时为 null。
103
- * 多取一条判断是否还有下一页。
104
+ * Every account, newest first, by page number (table pagination spec §2.3, no snapshot), with
105
+ * whether account erasure is on.
104
106
  */
105
107
  async listAccounts(q) {
106
- const rows = await this.accounts.list({
107
- limit: q.limit + 1,
108
- ...(q.after !== undefined && { after: q.after }),
109
- });
110
- const page = rows.slice(0, q.limit);
111
- const next = rows.length > q.limit ? (page.at(-1)?.id ?? null) : null;
108
+ const page = await this.accounts.list(q);
112
109
  const retention = this.config.get().retention;
113
110
  return {
114
- accounts: await withAvatarUrls(this.db.db, page),
115
- next,
111
+ ...page,
112
+ items: await withAvatarUrls(this.db.db, page.items),
116
113
  erasureEnabled: retention.erasureEnabled && retention.destructiveEnabled,
117
114
  };
118
115
  }
@@ -162,11 +159,24 @@ let AdminController = class AdminController {
162
159
  return { account: await this.view(account) };
163
160
  }
164
161
  /**
165
- * 全部组织的元数据与成员数(不含成员明细), with the deployment's defaults of the limits an org
162
+ * One page of the live orgs with their member counts (never the members), newest first, by
163
+ * page number (table pagination spec §2.3), with the deployment's defaults of the limits an org
166
164
  * can be given its own value of (the org limits dialog shows them for the values left empty).
167
165
  */
168
- async listOrgs() {
169
- return { orgs: await this.orgs.listAll(), limitDefaults: limitDefaults(this.config) };
166
+ async listOrgs(q) {
167
+ const page = await this.orgs.page({
168
+ page: q.page,
169
+ size: q.size,
170
+ ...(q.q !== undefined && { q: q.q }),
171
+ });
172
+ return { ...page, limitDefaults: limitDefaults(this.config) };
173
+ }
174
+ /**
175
+ * Every live org at once in the compact directory shape (id, slug, name), oldest first: the org
176
+ * filters, pickers and names of the console; the orgs table pages `GET orgs`.
177
+ */
178
+ async orgDirectory() {
179
+ return { orgs: await this.orgs.directory() };
170
180
  }
171
181
  /**
172
182
  * The members of any live org (the agent owner transfer picks the new owner from them); the super
@@ -293,8 +303,12 @@ __decorate([
293
303
  __param(2, ZBody(UpdateAccountBodyDto))
294
304
  ], AdminController.prototype, "updateAccount", null);
295
305
  __decorate([
296
- Get("orgs")
306
+ Get("orgs"),
307
+ __param(0, ZQuery(AdminOrgListQueryDto))
297
308
  ], AdminController.prototype, "listOrgs", null);
309
+ __decorate([
310
+ Get("orgs/directory")
311
+ ], AdminController.prototype, "orgDirectory", null);
298
312
  __decorate([
299
313
  Get("orgs/:orgId/members"),
300
314
  __param(0, ZParam(AdminOrgParamsDto))
@@ -1,9 +1,9 @@
1
1
  import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
- /** `GET /api/v1/admin/accounts`: keyset paging by account id. */
3
+ /** `GET /api/v1/admin/accounts`: page numbers without a snapshot (table pagination spec §2.3). */
4
4
  export declare const AccountListQuery: z.ZodObject<{
5
- after: z.ZodOptional<z.ZodString>;
6
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
5
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
6
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
7
7
  }, z.core.$strip>;
8
8
  export declare const CreateAccountBody: z.ZodObject<{
9
9
  login: z.ZodString;
@@ -179,6 +179,15 @@ export declare const DeploymentSettingsBody: z.ZodObject<{
179
179
  export declare const PurposeParams: z.ZodObject<{
180
180
  purpose: z.ZodString;
181
181
  }, z.core.$strip>;
182
+ /**
183
+ * `GET /api/v1/admin/orgs`: page numbers without a snapshot (spec §2.3) and a search (empty or
184
+ * blank: no search).
185
+ */
186
+ export declare const AdminOrgListQuery: z.ZodObject<{
187
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
188
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
189
+ q: z.ZodOptional<z.ZodString>;
190
+ }, z.core.$strip>;
182
191
  /** `:orgId` of an admin route: any org, the super admin need not be a member. */
183
192
  export declare const AdminOrgParams: z.ZodObject<{
184
193
  orgId: z.ZodString;
@@ -2,14 +2,12 @@ import { z } from "zod";
2
2
  import { externalDispositionBlockers } from "../erasure/external-evidence.js";
3
3
  import { MAX_PASSWORD_LENGTH } from "../identity/login.js";
4
4
  import { DEPLOYMENT_SETTINGS_PATCH } from "../identity/settings.js";
5
+ import { PageQueryFields } from "../infra/paging/paged-read.js";
5
6
  import { ModelDisabledPatch, ModelProviderParams } from "../models/enablement.controller.js";
6
7
  import { MODEL_PRICE_PUT } from "../models/prices.js";
7
8
  import { PURPOSE_PUT } from "../models/purposes.js";
8
- /** `GET /api/v1/admin/accounts`: keyset paging by account id. */
9
- export const AccountListQuery = z.object({
10
- after: z.string().min(1).optional(),
11
- limit: z.coerce.number().int().min(1).max(200).default(50),
12
- });
9
+ /** `GET /api/v1/admin/accounts`: page numbers without a snapshot (table pagination spec §2.3). */
10
+ export const AccountListQuery = z.object({ ...PageQueryFields });
13
11
  export const CreateAccountBody = z.object({
14
12
  login: z.string().min(1).max(64),
15
13
  password: z.string().min(1).max(MAX_PASSWORD_LENGTH),
@@ -34,6 +32,19 @@ export const UpdateAccountBody = z.object({
34
32
  /** At least one key; `runConcurrencyOverrides` merges by org, a null value drops that org's. */
35
33
  export const DeploymentSettingsBody = DEPLOYMENT_SETTINGS_PATCH.refine((b) => Object.keys(b).length > 0, { message: "at least one setting is required" });
36
34
  export const PurposeParams = z.object({ purpose: z.string().min(1).max(100) });
35
+ /**
36
+ * `GET /api/v1/admin/orgs`: page numbers without a snapshot (spec §2.3) and a search (empty or
37
+ * blank: no search).
38
+ */
39
+ export const AdminOrgListQuery = z.object({
40
+ q: z
41
+ .string()
42
+ .trim()
43
+ .max(200)
44
+ .optional()
45
+ .describe("Only orgs whose name or slug contains this (case-insensitive)."),
46
+ ...PageQueryFields,
47
+ });
37
48
  /** `:orgId` of an admin route: any org, the super admin need not be a member. */
38
49
  export const AdminOrgParams = z.object({ orgId: z.string().min(1).max(100) });
39
50
  export const ADMIN_ROUTES = [
@@ -56,7 +67,7 @@ export const ADMIN_ROUTES = [
56
67
  params: ErasureWorkParams,
57
68
  body: ErasureDispositionBody,
58
69
  },
59
- { route: "GET /api/v1/admin/orgs" },
70
+ { route: "GET /api/v1/admin/orgs", query: AdminOrgListQuery },
60
71
  // `:orgId` is the conversation's org for the operation, so never an operation field
61
72
  { route: "GET /api/v1/admin/orgs/:orgId/members" },
62
73
  { route: "GET /api/v1/admin/settings" },
@@ -1,4 +1,5 @@
1
1
  import { KernelDb } from "../infra/database/kernel-db.js";
2
+ import { type Page } from "../infra/paging/paged-read.js";
2
3
  import { AgentLookup, type AgentVisibility } from "./agent-lookup.js";
3
4
  import { type AgentDefinition } from "./definition.js";
4
5
  import type { AgentAvatarView } from "./profile.js";
@@ -69,9 +70,10 @@ export interface AdminAgentListQuery {
69
70
  orgId?: string | undefined;
70
71
  /** Case-insensitive substring of the name; LIKE wildcards match literally. */
71
72
  q?: string | undefined;
72
- /** The last id of the previous page. */
73
- after?: string | undefined;
74
- limit: number;
73
+ /** The page, 1-based. */
74
+ page: number;
75
+ /** Rows per page: 20, 50 or 100. */
76
+ size: number;
75
77
  }
76
78
  /**
77
79
  * Cross-org agent reads for the super admin (admin agents spec §3.2, §3.3): every org's live
@@ -82,11 +84,11 @@ export declare class AdminAgents {
82
84
  private readonly db;
83
85
  private readonly lookup;
84
86
  constructor(db: KernelDb, lookup: AgentLookup);
85
- /** Live agents of live orgs by id, `limit` per page; `next` is the last id when more follow. */
86
- list(q: AdminAgentListQuery): Promise<{
87
- agents: AdminAgentRow[];
88
- next: string | null;
89
- }>;
87
+ /**
88
+ * One page of every live org's live agents, filtered, newest first (`created_at`, then id), by
89
+ * page number without a snapshot (table pagination spec §2.3: agents are edited in place).
90
+ */
91
+ list(q: AdminAgentListQuery): Promise<Page<AdminAgentRow>>;
90
92
  /** One live agent of a live org; otherwise `agent.not_found`. */
91
93
  get(agentId: string): Promise<AdminAgentDetail>;
92
94
  /**
@@ -13,6 +13,7 @@ import { escapeLike } from "../conversations/conversations.service.js";
13
13
  import { ApiError } from "../errors.js";
14
14
  import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
15
15
  import { KernelDb } from "../infra/database/kernel-db.js";
16
+ import { assertReadablePage, cappedCount, PAGED_TOTAL_CAP, pageOf, pageOffset, } from "../infra/paging/paged-read.js";
16
17
  import { agentSkills, builtinSkillIds, builtinSkillPlugins, linkedCopyIds, skillIdsOf, usableSkillVersions, } from "../skills/usable.js";
17
18
  import { AgentLookup } from "./agent-lookup.js";
18
19
  import { avatarView } from "./avatar-view.js";
@@ -30,24 +31,27 @@ let AdminAgents = class AdminAgents {
30
31
  this.db = db;
31
32
  this.lookup = lookup;
32
33
  }
33
- /** Live agents of live orgs by id, `limit` per page; `next` is the last id when more follow. */
34
+ /**
35
+ * One page of every live org's live agents, filtered, newest first (`created_at`, then id), by
36
+ * page number without a snapshot (table pagination spec §2.3: agents are edited in place).
37
+ */
34
38
  async list(q) {
39
+ assertReadablePage(q.page, q.size);
35
40
  let query = this.rows();
36
41
  if (q.orgId !== undefined)
37
42
  query = query.where("agents.org_id", "=", q.orgId);
38
43
  if (q.q !== undefined && q.q !== "") {
39
44
  query = query.where(sql `agent_versions.definition->>'name' ILIKE ${`%${escapeLike(q.q)}%`} ESCAPE '\\'`);
40
45
  }
41
- if (q.after !== undefined)
42
- query = query.where("agents.id", ">", q.after);
46
+ const counted = await cappedCount(this.db.db, query, PAGED_TOTAL_CAP);
43
47
  const rows = await query
44
- .orderBy("agents.id")
45
- .limit(q.limit + 1)
48
+ .orderBy("agents.created_at", "desc")
49
+ .orderBy("agents.id", "desc")
50
+ .offset(pageOffset(q.page, q.size))
51
+ .limit(q.size)
46
52
  .execute();
47
- const kept = rows.slice(0, q.limit);
48
- const off = await this.skillsOff(kept);
49
- const page = kept.map((r) => toRow(r, off.get(r.id) ?? 0));
50
- return { agents: page, next: rows.length > q.limit ? (page.at(-1)?.id ?? null) : null };
53
+ const off = await this.skillsOff(rows);
54
+ return pageOf(rows.map((r) => toRow(r, off.get(r.id) ?? 0)), q, counted);
51
55
  }
52
56
  /** One live agent of a live org; otherwise `agent.not_found`. */
53
57
  async get(agentId) {
@@ -1,16 +1,19 @@
1
1
  import type { z } from "zod";
2
2
  import { type Principal } from "../identity/principal.js";
3
+ import type { Page } from "../infra/paging/paged-read.js";
3
4
  import { type OrgContext } from "../orgs/org.guard.js";
4
- import { type AutomationCalendarQuery, type AutomationChatTargetsQuery, type AutomationCreateBody, type AutomationEventSourcesQuery, type AutomationGrantableQuery, type AutomationGrantParams, type AutomationGrantsBody, type AutomationListQuery, type AutomationParams, type AutomationRunBody, type AutomationRunsQuery, type AutomationUpdateBody } from "./automations.schemas.js";
5
- import { type AutomationGrantView, type AutomationListItem, AutomationsService, type ChatTarget, type EventSourceView, type GrantableTool } from "./automations.service.js";
5
+ import { type AutomationCalendarQuery, type AutomationChatTargetsQuery, type AutomationCreateBody, type AutomationEventSourcesQuery, type AutomationGrantableQuery, type AutomationGrantParams, type AutomationGrantsBody, type AutomationListQuery, type AutomationNextRunsQuery, type AutomationParams, type AutomationRunBody, type AutomationRunsQuery, type AutomationUpdateBody } from "./automations.schemas.js";
6
+ import { type AutomationGrantView, type AutomationListItem, type AutomationNextRun, AutomationsService, type ChatTarget, type EventSourceView, type GrantableTool } from "./automations.service.js";
6
7
  import type { CalendarAnswer } from "./calendar.js";
7
8
  import type { Automation, AutomationGrant, TaskRun } from "./types.js";
8
9
  /**
9
10
  * Automations (`/api/v1/orgs/:orgId/automations`, spec 2026-11-11-scheduled-tasks §10); human
10
11
  * users only (a service token gets 403).
11
- * - `GET /` → `{ items }`: the caller's own tasks, each with its `lastRun`; `?all=true` every task
12
+ * - `GET /` → a page (`page`, `size`; table pagination spec §2.3) of the caller's own tasks, each with its `lastRun`; `?all=true` every task
12
13
  * of the org (org admins, `automations.manage`, enforced by the service: 403 `forbidden`
13
14
  * otherwise); `?conversationId=` only those posting into that conversation;
15
+ * - `GET /next-runs[?all=true]` → `{ items }`: every one of the caller's tasks (`all` as the
16
+ * list's) at once, each only `{ id, status, nextRunAt }` (the calendar's empty state);
14
17
  * - `GET /calendar?from&to&timeZone[&all][&taskId]` → the calendar (runs, planned occurrences,
15
18
  * collapsed task-days; calendar spec §5.1), `org.read` like the list, `all` as the list's;
16
19
  * - `GET /chat-targets` → `{ items }`: the chats the caller can point a `chat` task at;
@@ -32,8 +35,9 @@ import type { Automation, AutomationGrant, TaskRun } from "./types.js";
32
35
  export declare class AutomationsController {
33
36
  private readonly tasks;
34
37
  constructor(tasks: AutomationsService);
35
- list(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationListQuery>): Promise<{
36
- items: AutomationListItem[];
38
+ list(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationListQuery>): Promise<Page<AutomationListItem>>;
39
+ nextRuns(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationNextRunsQuery>): Promise<{
40
+ items: AutomationNextRun[];
37
41
  }>;
38
42
  calendar(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationCalendarQuery>): Promise<CalendarAnswer>;
39
43
  chatTargets(principal: Principal, org: OrgContext, _q: z.infer<typeof AutomationChatTargetsQuery>): Promise<{
@@ -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") {