@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,6 +11,7 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
11
11
  import { XactLock } from "../infra/database/xact-lock.js";
12
12
  import { KernelEvents } from "../infra/events/kernel-events.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 { HintPublisher } from "../invalidation/audiences.js";
15
16
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
16
17
  import { StorageService } from "../storage/storage.service.js";
@@ -22,6 +23,8 @@ export type Org = {
22
23
  name: string;
23
24
  createdAt: Date;
24
25
  };
26
+ /** One org as the super admin's org pickers and names need it (`GET /admin/orgs/directory`). */
27
+ export type OrgDirectoryEntry = Pick<Org, "id" | "slug" | "name">;
25
28
  /** 组织 slug:小写字母数字与 `-`,首尾不能是 `-`,1–40 个字符。 */
26
29
  export declare const SLUG_RE: RegExp;
27
30
  /** 由名字生成 slug:转小写、非字母数字换 `-`、去首尾 `-`;为空则 `org-<6 位随机>`。 */
@@ -76,10 +79,27 @@ export declare class OrgsService {
76
79
  listForAccount(accountId: string): Promise<(Org & {
77
80
  role: OrgRole;
78
81
  })[]>;
79
- /** 全部(未软删除的)组织及成员数(超级管理员用)。 */
82
+ /** Every live org with its member count, oldest first (internal callers that need them all). */
80
83
  listAll(): Promise<(Org & {
81
84
  memberCount: number;
82
85
  })[]>;
86
+ /**
87
+ * Every live org in the compact directory shape, oldest first (the super admin's org filters,
88
+ * pickers and names; the orgs table reads {@link page}).
89
+ */
90
+ directory(): Promise<OrgDirectoryEntry[]>;
91
+ /**
92
+ * One page of the live orgs with their member counts (the super admin's orgs list), newest first
93
+ * (`created_at`, then id), by page number without a snapshot (table pagination spec §2.3: orgs
94
+ * are edited in place); `q` keeps those whose name or slug contains it (case-insensitive).
95
+ */
96
+ page(q: {
97
+ page: number;
98
+ size: number;
99
+ q?: string;
100
+ }): Promise<Page<Org & {
101
+ memberCount: number;
102
+ }>>;
83
103
  /** 未软删除的组织;不存在或已软删除为 undefined。 */
84
104
  get(orgId: string): Promise<Org | undefined>;
85
105
  /** Renames / re-slugs (needs admin, decided live under the org lock). */
@@ -31,6 +31,7 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
31
31
  import { XactLock } from "../infra/database/xact-lock.js";
32
32
  import { KernelEvents } from "../infra/events/kernel-events.js";
33
33
  import { OutboxService } from "../infra/outbox/outbox.service.js";
34
+ import { assertReadablePage, cappedCount, PAGED_TOTAL_CAP, pageOf, pageOffset, } from "../infra/paging/paged-read.js";
34
35
  import { InvalidationHints } from "../invalidation/invalidation-hints.js";
35
36
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
36
37
  import { STOP_DELETED_ORG_JOB } from "../runtime/run-deletion.js";
@@ -188,7 +189,7 @@ let OrgsService = class OrgsService {
188
189
  .execute());
189
190
  return rows.map((r) => ({ ...toOrg(r), role: r.role }));
190
191
  }
191
- /** 全部(未软删除的)组织及成员数(超级管理员用)。 */
192
+ /** Every live org with its member count, oldest first (internal callers that need them all). */
192
193
  async listAll() {
193
194
  const rows = await this.db
194
195
  .selectFrom("orgs")
@@ -202,6 +203,44 @@ let OrgsService = class OrgsService {
202
203
  .execute();
203
204
  return rows.map((r) => ({ ...toOrg(r), memberCount: Number(r.member_count) }));
204
205
  }
206
+ /**
207
+ * Every live org in the compact directory shape, oldest first (the super admin's org filters,
208
+ * pickers and names; the orgs table reads {@link page}).
209
+ */
210
+ async directory() {
211
+ // listAll's order without its member counts (and so without reading memberships)
212
+ return this.db
213
+ .selectFrom("orgs")
214
+ .select(["id", "slug", "name"])
215
+ .where("deleted_at", "is", null)
216
+ .orderBy("created_at")
217
+ .orderBy("id")
218
+ .execute();
219
+ }
220
+ /**
221
+ * One page of the live orgs with their member counts (the super admin's orgs list), newest first
222
+ * (`created_at`, then id), by page number without a snapshot (table pagination spec §2.3: orgs
223
+ * are edited in place); `q` keeps those whose name or slug contains it (case-insensitive).
224
+ */
225
+ async page(q) {
226
+ assertReadablePage(q.page, q.size);
227
+ let matching = this.db.selectFrom("orgs").where("orgs.deleted_at", "is", null);
228
+ // an empty search (the route trims it) is no search
229
+ if (q.q !== undefined && q.q !== "") {
230
+ const like = `%${q.q.replace(/[\\%_]/g, (ch) => `\\${ch}`)}%`;
231
+ matching = matching.where(sql `(orgs.name ILIKE ${like} ESCAPE '\\' OR orgs.slug ILIKE ${like} ESCAPE '\\')`);
232
+ }
233
+ const counted = await cappedCount(this.db.db, matching, PAGED_TOTAL_CAP);
234
+ const rows = await matching
235
+ .select(["orgs.id", "orgs.slug", "orgs.name", "orgs.created_at"])
236
+ .select(sql `(SELECT count(*) FROM capybara.memberships m WHERE m.org_id = orgs.id)`.as("member_count"))
237
+ .orderBy("orgs.created_at", "desc")
238
+ .orderBy("orgs.id", "desc")
239
+ .offset(pageOffset(q.page, q.size))
240
+ .limit(q.size)
241
+ .execute();
242
+ return pageOf(rows.map((r) => ({ ...toOrg(r), memberCount: Number(r.member_count) })), q, counted);
243
+ }
205
244
  /** 未软删除的组织;不存在或已软删除为 undefined。 */
206
245
  async get(orgId) {
207
246
  const row = await this.db
@@ -8,9 +8,14 @@ import { ToolRegistry } from "../tools/registry.js";
8
8
  import { OrgLock } from "./org-lock.js";
9
9
  import { OrgSettingsService } from "./settings.service.js";
10
10
  type ToolSource = "builtin" | "connector" | "extension" | "operation" | "unavailable";
11
+ /**
12
+ * The ceilings and one page of the tool policies, by tool key, by page number without a snapshot
13
+ * (table pagination spec §2.3: the tool list follows the loaded extensions and the policies are
14
+ * edited in place).
15
+ */
11
16
  export declare const OrgSecurityQuerySchema: z.ZodObject<{
12
- cursor: z.ZodOptional<z.ZodString>;
13
- limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
17
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
18
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
14
19
  }, z.core.$strict>;
15
20
  export declare const OrgSecurityPatchSchema: z.ZodObject<{
16
21
  expectedRevision: z.ZodString;
@@ -58,15 +63,18 @@ export declare class OrgSecuritySettingsService {
58
63
  private snapshot;
59
64
  private toolSources;
60
65
  view(orgId: string, query: OrgSecurityQuery): Promise<{
61
- gitPushDenials: string[];
62
- revision: string;
63
- tools: {
66
+ items: {
64
67
  toolKey: string;
65
68
  source: ToolSource;
66
69
  policy: import("../tools/org-tool-policies.js").OrgToolPolicy;
67
70
  unattendedPolicy: import("../tools/org-tool-policies.js").OrgToolPolicy;
68
71
  }[];
69
- nextCursor: string | null;
72
+ page: number;
73
+ size: number;
74
+ total: number;
75
+ totalCapped: boolean;
76
+ gitPushDenials: string[];
77
+ revision: string;
70
78
  allowedProfiles: {
71
79
  configured: ("approve-for-me" | "full-access" | "request-approval")[] | null;
72
80
  platform: import("@capybara-hq/plugin-sdk").PermissionProfile[];
@@ -16,6 +16,7 @@ import { audit } from "../identity/audit.js";
16
16
  import { KernelDb } from "../infra/database/kernel-db.js";
17
17
  import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
18
18
  import { Transactional } from "../infra/database/transactional.decorator.js";
19
+ import { assertReadablePage, PAGED_TOTAL_CAP, PageQueryFields, pageOf, pageOffset, } from "../infra/paging/paged-read.js";
19
20
  import { PlatformOperations } from "../platform/registry.js";
20
21
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
21
22
  import { readOrgGitPushDenials, readOrgToolPolicies, writeOrgGitPushDenial, writeOrgToolPolicy, } from "../tools/org-tool-policies.js";
@@ -33,12 +34,12 @@ const GitTarget = z
33
34
  .max(200)
34
35
  .transform((value) => (value.trim() === "*" ? "*" : normalizeGitRepo(value)))
35
36
  .pipe(z.string());
36
- export const OrgSecurityQuerySchema = z
37
- .object({
38
- cursor: ToolKey.optional(),
39
- limit: z.coerce.number().int().min(1).max(100).default(50),
40
- })
41
- .strict();
37
+ /**
38
+ * The ceilings and one page of the tool policies, by tool key, by page number without a snapshot
39
+ * (table pagination spec §2.3: the tool list follows the loaded extensions and the policies are
40
+ * edited in place).
41
+ */
42
+ export const OrgSecurityQuerySchema = z.object({ ...PageQueryFields }).strict();
42
43
  export const OrgSecurityPatchSchema = OrgSecurityCeilingsPatchSchema.extend({
43
44
  expectedRevision: Revision,
44
45
  confirmation: Revision.optional(),
@@ -118,19 +119,23 @@ let OrgSecuritySettingsService = class OrgSecuritySettingsService {
118
119
  for (const { toolKey } of policies)
119
120
  if (!sources.has(toolKey))
120
121
  sources.set(toolKey, "unavailable");
121
- const keys = [...sources.keys()]
122
- .filter((key) => query.cursor === undefined || key > query.cursor)
123
- .sort();
124
- const page = keys.slice(0, query.limit);
122
+ assertReadablePage(query.page, query.size);
123
+ // the list is built in memory (the registry's tools and the Platform operations), so it is
124
+ // counted here, with the same cap as a counted query
125
+ const keys = [...sources.keys()].sort();
126
+ const start = pageOffset(query.page, query.size);
127
+ const page = keys.slice(start, start + query.size);
125
128
  return {
126
129
  ...snapshot,
127
- tools: page.map((toolKey) => ({
130
+ ...pageOf(page.map((toolKey) => ({
128
131
  toolKey,
129
132
  source: sources.get(toolKey) ?? "unavailable",
130
133
  policy: rows.get(toolKey)?.policy ?? "allow",
131
134
  unattendedPolicy: rows.get(toolKey)?.unattendedPolicy ?? "allow",
132
- })),
133
- nextCursor: keys.length > page.length ? (page.at(-1) ?? null) : null,
135
+ })), query, {
136
+ count: Math.min(keys.length, PAGED_TOTAL_CAP),
137
+ capped: keys.length > PAGED_TOTAL_CAP,
138
+ }),
134
139
  };
135
140
  }
136
141
  async update(orgId, patch, actor, options) {
@@ -14,15 +14,18 @@ export declare class OrgSecuritySettingsController {
14
14
  private readonly security;
15
15
  constructor(security: OrgSecuritySettingsService);
16
16
  get(org: OrgContext, query: OrgSecurityQuery): Promise<{
17
- gitPushDenials: string[];
18
- revision: string;
19
- tools: {
17
+ items: {
20
18
  toolKey: string;
21
19
  source: "builtin" | "connector" | "extension" | "operation" | "unavailable";
22
20
  policy: import("../tools/org-tool-policies.js").OrgToolPolicy;
23
21
  unattendedPolicy: import("../tools/org-tool-policies.js").OrgToolPolicy;
24
22
  }[];
25
- nextCursor: string | null;
23
+ page: number;
24
+ size: number;
25
+ total: number;
26
+ totalCapped: boolean;
27
+ gitPushDenials: string[];
28
+ revision: string;
26
29
  allowedProfiles: {
27
30
  configured: ("approve-for-me" | "full-access" | "request-approval")[] | null;
28
31
  platform: import("@capybara-hq/plugin-sdk").PermissionProfile[];
@@ -16,4 +16,9 @@ export interface OfficialPublisherProof extends Provenance {
16
16
  export declare function verifyOfficialPublisher(body: unknown, revision: OfficialNpmRevision): OfficialPublisherProof;
17
17
  /** Uses the same bounded registry client as the review's display-only provenance. */
18
18
  export declare function fetchOfficialPublisher(cfg: NpmFetchConfig, revision: OfficialNpmRevision, signal?: AbortSignal): Promise<OfficialPublisherProof>;
19
+ /** A failed publisher check; `transient` failures (network, timeout, 5xx) may pass on a retry soon. */
20
+ export declare class OfficialPublisherError extends Error {
21
+ readonly transient: boolean;
22
+ constructor(cause: unknown, transient: boolean);
23
+ }
19
24
  export {};
@@ -5,7 +5,7 @@ import { toSignedEntity, toTrustMaterial, Verifier } from "@sigstore/verify";
5
5
  import { z } from "zod";
6
6
  import { canonicalJson } from "../tools/canonical-json.js";
7
7
  import npmPublishKeys from "./npm-publish-keys.json" with { type: "json" };
8
- import { fetchNpmAttestations, PROVENANCE_TIMEOUT_MS, SLSA_PROVENANCE_V1, sha512Hex, } from "./provenance.js";
8
+ import { fetchNpmAttestations, isTransientAttestationsFailure, PROVENANCE_TIMEOUT_MS, SLSA_PROVENANCE_V1, sha512Hex, } from "./provenance.js";
9
9
  import trustedRoot from "./sigstore-trusted-root.json" with { type: "json" };
10
10
  const NPM_PUBLISH = "https://github.com/npm/attestation/tree/main/specs/publish/v0.1";
11
11
  const REGISTRY = "https://registry.npmjs.org";
@@ -147,6 +147,27 @@ export function verifyOfficialPublisher(body, revision) {
147
147
  /** Uses the same bounded registry client as the review's display-only provenance. */
148
148
  export async function fetchOfficialPublisher(cfg, revision, signal) {
149
149
  const timeout = AbortSignal.timeout(PROVENANCE_TIMEOUT_MS);
150
- const attestations = await fetchNpmAttestations(cfg, revision.name, revision.version, signal ? AbortSignal.any([signal, timeout]) : timeout);
151
- return verifyOfficialPublisher(attestations, revision);
150
+ let attestations;
151
+ try {
152
+ attestations = await fetchNpmAttestations(cfg, revision.name, revision.version, signal ? AbortSignal.any([signal, timeout]) : timeout);
153
+ }
154
+ catch (e) {
155
+ throw new OfficialPublisherError(e, isTransientAttestationsFailure(e));
156
+ }
157
+ try {
158
+ return verifyOfficialPublisher(attestations, revision);
159
+ }
160
+ catch (e) {
161
+ // Verification is deterministic for the fetched evidence: another signer, digest or name.
162
+ throw new OfficialPublisherError(e, false);
163
+ }
164
+ }
165
+ /** A failed publisher check; `transient` failures (network, timeout, 5xx) may pass on a retry soon. */
166
+ export class OfficialPublisherError extends Error {
167
+ transient;
168
+ constructor(cause, transient) {
169
+ super(cause instanceof Error ? cause.message : String(cause), { cause });
170
+ this.transient = transient;
171
+ this.name = "OfficialPublisherError";
172
+ }
152
173
  }
@@ -35,6 +35,12 @@ export type ProvenanceResult = Provenance | ProvenanceNotChecked;
35
35
  export declare const SLSA_PROVENANCE_V1 = "https://slsa.dev/provenance/v1";
36
36
  /** Provenance must not hold up an import: a slow registry gives "not checked". */
37
37
  export declare const PROVENANCE_TIMEOUT_MS = 15000;
38
+ /**
39
+ * Whether a {@link fetchNpmAttestations} failure may pass on a retry soon (timeouts, network
40
+ * errors, other HTTP statuses than 404) rather than being the registry's answer (no provenance, an
41
+ * invalid name, a malformed or oversized body).
42
+ */
43
+ export declare function isTransientAttestationsFailure(e: unknown): boolean;
38
44
  /** The hex sha512 of a `sha512-<base64>` integrity (undefined for anything else). */
39
45
  export declare function sha512Hex(integrity: string): string | undefined;
40
46
  /**
@@ -11,6 +11,25 @@ const NPM_NAME_RE = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
11
11
  const SEMVER_RE = /^[0-9A-Za-z.+-]{1,256}$/;
12
12
  const COMMIT_RE = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
13
13
  class NpmAttestationsError extends Error {
14
+ transient;
15
+ constructor(message,
16
+ /** A network or registry hiccup worth retrying soon; false for the registry's definite answers. */
17
+ transient, options) {
18
+ super(message, options);
19
+ this.transient = transient;
20
+ }
21
+ }
22
+ class AttestationsTooLarge extends Error {
23
+ }
24
+ /**
25
+ * Whether a {@link fetchNpmAttestations} failure may pass on a retry soon (timeouts, network
26
+ * errors, other HTTP statuses than 404) rather than being the registry's answer (no provenance, an
27
+ * invalid name, a malformed or oversized body).
28
+ */
29
+ export function isTransientAttestationsFailure(e) {
30
+ if (e instanceof NpmAttestationsError)
31
+ return e.transient;
32
+ return !(e instanceof SyntaxError || e instanceof AttestationsTooLarge);
14
33
  }
15
34
  const notChecked = (reason) => ({ checked: false, reason });
16
35
  const errMsg = (e) => (e instanceof Error ? e.message : String(e));
@@ -44,7 +63,7 @@ export async function fetchProvenance(cfg, name, version, signal, opts = {}) {
44
63
  /** Fetches bounded attestation evidence without accepting it as publisher proof. */
45
64
  export async function fetchNpmAttestations(cfg, name, version, signal) {
46
65
  if (!NPM_NAME_RE.test(name) || name.length > 214 || !SEMVER_RE.test(version)) {
47
- throw new NpmAttestationsError("not a valid npm package name and version");
66
+ throw new NpmAttestationsError("not a valid npm package name and version", false);
48
67
  }
49
68
  try {
50
69
  const registry = new URL(cfg.registry.endsWith("/") ? cfg.registry : `${cfg.registry}/`);
@@ -58,20 +77,18 @@ export async function fetchNpmAttestations(cfg, name, version, signal) {
58
77
  }, cfg.net, cfg.lookup !== undefined ? { lookup: cfg.lookup } : {});
59
78
  if (!res.ok) {
60
79
  await res.body?.cancel().catch(() => { });
61
- throw new NpmAttestationsError(res.status === 404
62
- ? "the registry has no provenance for this version"
63
- : `the registry answered HTTP ${res.status} for the attestations`);
80
+ throw res.status === 404
81
+ ? new NpmAttestationsError("the registry has no provenance for this version", false)
82
+ : new NpmAttestationsError(`the registry answered HTTP ${res.status} for the attestations`, true);
64
83
  }
65
- const raw = await readCapped(res, MAX_ATTESTATION_BYTES, () => new Error("the attestations are too large"));
84
+ const raw = await readCapped(res, MAX_ATTESTATION_BYTES, () => new AttestationsTooLarge("the attestations are too large"));
66
85
  return JSON.parse(raw.toString("utf8"));
67
86
  }
68
87
  catch (e) {
69
88
  if (signal.aborted)
70
- throw new NpmAttestationsError("the registry did not answer in time", { cause: e });
89
+ throw new NpmAttestationsError("the registry did not answer in time", true, { cause: e });
71
90
  if (e instanceof NetDeniedError) {
72
- throw new NpmAttestationsError(`the network rules refused the attestations: ${e.message}`, {
73
- cause: e,
74
- });
91
+ throw new NpmAttestationsError(`the network rules refused the attestations: ${e.message}`, true, { cause: e });
75
92
  }
76
93
  throw e;
77
94
  }
@@ -618,6 +618,21 @@ export const PLATFORM_EXCLUSIONS = [
618
618
  category: "human-only",
619
619
  reason: "Creates an org and makes the caller its owner",
620
620
  },
621
+ {
622
+ route: "GET /api/v1/orgs/:orgId/members/directory",
623
+ category: "internal",
624
+ reason: "The web's whole member list for owner pickers and member names; orgs.members gives an agent the same members page by page",
625
+ },
626
+ {
627
+ route: "GET /api/v1/admin/orgs/directory",
628
+ category: "internal",
629
+ reason: "The super admin console's whole org list for org filters, pickers and names; orgs.list gives an agent the same orgs page by page",
630
+ },
631
+ {
632
+ route: "GET /api/v1/orgs/:orgId/automations/next-runs",
633
+ category: "internal",
634
+ reason: "The web calendar's whole task list reduced to status and next run for its empty state; automations.list gives an agent the same tasks page by page",
635
+ },
621
636
  {
622
637
  route: "GET /api/v1/orgs",
623
638
  category: "internal",
@@ -20,7 +20,6 @@ import { defineOperation } from "../operation.js";
20
20
  import { PlatformOperations } from "../registry.js";
21
21
  import { precheckBy, viaAgent } from "./errors.js";
22
22
  import { named } from "./summary.js";
23
- const PAGE = 50;
24
23
  const AccountId = AccountParams.shape.accountId.describe("The account id (accounts.list).");
25
24
  /** What the tool result says instead of the password (model-visible English). */
26
25
  export const INITIAL_PASSWORD_NOTE = "The kernel generated a one-time initial password. It is shown once, on the web, to the person this call was made for, under the tool call in this conversation, and never to you. The account must change it at first sign-in.";
@@ -124,25 +123,18 @@ let AccountsOperations = class AccountsOperations {
124
123
  this.registry.register([
125
124
  defineOperation({
126
125
  id: "accounts.list",
127
- description: "List the platform's accounts (super admin), one compact row each: id, display name, state (active or disabled), login, email and whether it is a super admin. Ordered by id; pages by 50: pass the returned next as params.after. Details come from accounts.get.",
128
- input: z
129
- .object({ after: AccountListQuery.shape.after.unwrap().max(100).optional() })
130
- .strict(),
131
- example: {},
126
+ description: "List the platform's accounts (super admin), one compact row each: id, display name, state (active or disabled), login, email and whether it is a super admin. Newest first; paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total (capped at 10000, totalCapped true above). Pages beyond the first 10000 accounts are refused. Details come from accounts.get.",
127
+ input: AccountListQuery.strict(),
128
+ example: { page: 1, size: 50 },
132
129
  authz: { superAdmin: true },
133
130
  mirrors: ["GET /api/v1/admin/accounts"],
134
- // the page size is fixed at 50 (compact rows)
135
- omits: ["limit"],
136
131
  confirm: "read",
137
132
  run: async (input) => {
138
- const rows = await this.accounts.list({
139
- limit: PAGE + 1,
140
- ...(input.after !== undefined && { after: input.after }),
141
- });
142
- const page = rows.slice(0, PAGE);
143
- const logins = await this.accounts.localLogins(page.map((a) => a.id));
133
+ const page = await this.accounts.list(input);
134
+ const logins = await this.accounts.localLogins(page.items.map((a) => a.id));
144
135
  return {
145
- items: page.map((a) => ({
136
+ ...page,
137
+ items: page.items.map((a) => ({
146
138
  id: a.id,
147
139
  name: a.displayName,
148
140
  state: a.status,
@@ -150,7 +142,6 @@ let AccountsOperations = class AccountsOperations {
150
142
  email: a.email,
151
143
  superAdmin: a.isSuperAdmin,
152
144
  })),
153
- next: rows.length > PAGE ? (page.at(-1)?.id ?? null) : null,
154
145
  };
155
146
  },
156
147
  }),
@@ -86,9 +86,9 @@ let AdminItemsOperations = class AdminItemsOperations {
86
86
  this.registry.register([
87
87
  defineOperation({
88
88
  id: "admin.agents-list",
89
- description: "List this org's agents as the admin console shows them (super admin): private ones too, with owner, visibility, whether the agent needs a new owner and the template it was created from. q searches the name; pages by limit (default 50), pass the returned next as after. Other orgs' agents are only in the admin console.",
90
- input: AdminAgentListQuery.pick({ q: true, after: true, limit: true }).strict(),
91
- example: { limit: 50 },
89
+ description: "List this org's agents as the admin console shows them (super admin): private ones too, with owner, visibility, whether the agent needs a new owner and the template it was created from. q searches the name. Newest first; paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total (capped at 10000, totalCapped true above). Other orgs' agents are only in the admin console.",
90
+ input: AdminAgentListQuery.pick({ q: true, page: true, size: true }).strict(),
91
+ example: { page: 1, size: 50 },
92
92
  authz: { superAdmin: true },
93
93
  mirrors: ["GET /api/v1/admin/agents"],
94
94
  confirm: "read",
@@ -96,7 +96,7 @@ let AdminItemsOperations = class AdminItemsOperations {
96
96
  }),
97
97
  defineOperation({
98
98
  id: "admin.agent-get",
99
- description: "Read one agent of this org as the admin console shows it (super admin): its definition with the instructions in full, members, profile with quick action labels, versions count, the skills and connectors it has by name, and how many of the org's skills it turns off (skillsOff). Never its conversations or credentials.",
99
+ description: "Read one agent of this org as the admin console shows it (super admin): its definition with the instructions in full, members, profile with quick action labels, versions count, the skills it has by name and the connectors with their status, setup state and icon, and how many of the org's skills it turns off (skillsOff). Never its conversations or credentials.",
100
100
  input: AgentIdInput,
101
101
  example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
102
102
  authz: { superAdmin: true },
@@ -153,14 +153,14 @@ let AdminItemsOperations = class AdminItemsOperations {
153
153
  }),
154
154
  defineOperation({
155
155
  id: "admin.connectors-list",
156
- description: "List this org's connectors as the admin console shows them (super admin): name, protocol, status, tool count, who created it and from which template. Never an endpoint, credential or whether anyone has one. status and q (name search) filter; pages by limit (default 50), pass the returned next as after. Other orgs' connectors are only in the admin console.",
156
+ description: "List this org's connectors as the admin console shows them (super admin): name, protocol, status, tool count, who created it and from which template. Never an endpoint, credential or whether anyone has one. status and q (name search) filter. Newest first; paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total (capped at 10000, totalCapped true above). Other orgs' connectors are only in the admin console.",
157
157
  input: AdminConnectorListQuery.pick({
158
158
  status: true,
159
159
  q: true,
160
- after: true,
161
- limit: true,
160
+ page: true,
161
+ size: true,
162
162
  }).strict(),
163
- example: { limit: 50 },
163
+ example: { page: 1, size: 50 },
164
164
  authz: { superAdmin: true },
165
165
  mirrors: ["GET /api/v1/admin/connectors"],
166
166
  confirm: "read",
@@ -92,9 +92,9 @@ let AutomationsOperations = class AutomationsOperations {
92
92
  this.registry.register([
93
93
  defineOperation({
94
94
  id: "automations.list",
95
- description: "List your automations: one compact row each (name, agent, status and why it is paused, schedule with its time zone, where runs post, next run, last settled run). all=true lists every task of the org and needs the org admin role; conversationId keeps the tasks that post into that conversation.",
95
+ description: "List your automations: one compact row each (name, agent, status and why it is paused, schedule with its time zone, where runs post, next run, last settled run). all=true lists every task of the org and needs the org admin role; conversationId keeps the tasks that post into that conversation. Newest first; paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total (capped at 10000, totalCapped true above).",
96
96
  input: ListQuery,
97
- example: {},
97
+ example: { page: 1, size: 20 },
98
98
  // a creator demoted to guest still lists their own tasks (to pause or delete them)
99
99
  authz: { orgAction: "org.read" },
100
100
  mirrors: ["GET /api/v1/orgs/:orgId/automations"],
@@ -106,11 +106,13 @@ let AutomationsOperations = class AutomationsOperations {
106
106
  },
107
107
  ],
108
108
  run: async (input, ctx) => {
109
- const items = await this.tasks.list(ctx.orgId, this.actor(ctx), {
109
+ const page = await this.tasks.list(ctx.orgId, this.actor(ctx), {
110
110
  all: input.all === "true",
111
+ page: input.page,
112
+ size: input.size,
111
113
  ...(input.conversationId !== undefined && { conversationId: input.conversationId }),
112
114
  });
113
- return { items: items.map(row) };
115
+ return { ...page, items: page.items.map(row) };
114
116
  },
115
117
  }),
116
118
  defineOperation({
@@ -11,7 +11,7 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
12
  import { ModelRef } from "../../agents/definition.js";
13
13
  import { ApiError } from "../../errors.js";
14
- import { EvalAddCaseBody, EvalCandidateSchema, EvalCaseParams, EvalLabelBody, EvalResultParams, EvalRunEstimateBody, EvalRunParams, EvalRunResultsQuery, EvalSampleBody, EvalSetCreateBody, EvalSetParams, EvalSetPatchBody, } from "../../evals/evals.schemas.js";
14
+ import { EvalAddCaseBody, EvalCandidateSchema, EvalCaseParams, EvalLabelBody, EvalResultParams, EvalRunEstimateBody, EvalRunParams, EvalRunResultsQuery, EvalSampleBody, EvalSetCreateBody, EvalSetParams, EvalSetPatchBody, EvalSetRunsQuery, } from "../../evals/evals.schemas.js";
15
15
  import { EvalRunsService } from "../../evals/runs.service.js";
16
16
  import { EvalSetsService } from "../../evals/sets.service.js";
17
17
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
@@ -546,17 +546,23 @@ let EvalsOperations = class EvalsOperations {
546
546
  }),
547
547
  defineOperation({
548
548
  id: "evals.list-runs",
549
- description: "List the runs of one eval set, newest first (org admins): id, mode, state and progress. Read one with evals.get-run. Pages by 50: pass the returned next as params.cursor.",
550
- input: z.object({ setId: SetId, cursor: Cursor.optional() }).strict(),
551
- example: { setId: "3b1f0c52-8d2a-4a57-9a43-6f1d2c9e7a10" },
549
+ description: "List the runs of one eval set, newest first (org admins): id, mode, state and progress. Read one with evals.get-run. Paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, total (capped at 10000, totalCapped true above), asOf and newer. Pass the returned asOf with the next pages so they stay the same while new runs start; newer counts runs started after asOf.",
550
+ input: EvalSetRunsQuery.extend({ setId: SetId }).strict(),
551
+ example: { setId: "3b1f0c52-8d2a-4a57-9a43-6f1d2c9e7a10", page: 1, size: 20 },
552
552
  authz: { orgAction: "evals.manage" },
553
553
  mirrors: ["GET /api/v1/orgs/:orgId/eval-sets/:setId/runs"],
554
- extras: ["cursor"],
555
554
  confirm: "read",
556
555
  errors: [
557
556
  { code: "eval.set_not_found", next: "Check the eval set id with evals.list-sets." },
558
557
  ],
559
- run: async (input, ctx) => pageOf((await this.runs.listForSet(ctx.orgId, input.setId)).map(runRow), startOf(input.cursor), PAGE),
558
+ run: async (input, ctx) => {
559
+ const page = await this.runs.listForSet(ctx.orgId, input.setId, {
560
+ page: input.page,
561
+ size: input.size,
562
+ ...(input.asOf !== undefined && { asOf: input.asOf }),
563
+ });
564
+ return { ...page, items: page.items.map(runRow) };
565
+ },
560
566
  }),
561
567
  defineOperation({
562
568
  id: "evals.get-run",
@@ -571,21 +577,31 @@ let EvalsOperations = class EvalsOperations {
571
577
  }),
572
578
  defineOperation({
573
579
  id: "evals.list-results",
574
- description: "List the results of one eval run without their content (org admins): state, judge verdict, your label, drift and error code per case step. Pages by 50: pass the returned next as params.after. Read one result's scalar fields with evals.get-result.",
575
- input: EvalRunResultsQuery.pick({ after: true, limit: true })
576
- .extend({ runId: RunId, limit: z.number().int().min(1).max(50).default(50) })
580
+ description: "List the results of one eval run without their content (org admins): state, judge verdict, your label, drift and error code per case step. Paged by page number: page (1-based) and size (20 or 50); the answer has items, page, size and total (capped at 10000, totalCapped true above). Read one result's scalar fields with evals.get-result.",
581
+ // model-visible: at most 50 rows a call (the route's tables also offer 100)
582
+ input: EvalRunResultsQuery.pick({ page: true, size: true })
583
+ .extend({
584
+ runId: RunId,
585
+ size: z.coerce
586
+ .number()
587
+ .int()
588
+ .refine((v) => v === 20 || v === 50, "size must be 20 or 50")
589
+ .default(20)
590
+ .describe("Rows per page: 20 or 50 (default 20)."),
591
+ })
577
592
  .strict(),
578
- example: { runId: "2c3d4e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f", limit: 50 },
593
+ example: { runId: "2c3d4e5f-6a7b-4c8d-9e0f-1a2b3c4d5e6f", page: 1, size: 50 },
579
594
  authz: { orgAction: "evals.manage" },
580
595
  mirrors: ["GET /api/v1/orgs/:orgId/eval-runs/:runId/results"],
581
- // the light view only; polling by `updatedSince` is the web's
582
- omits: ["view", "updatedSince"],
596
+ // the light view only
597
+ omits: ["view"],
583
598
  confirm: "read",
584
599
  errors: [{ code: "eval.run_not_found", next: "Check the run id with evals.list-runs." }],
585
600
  run: async (input, ctx) => {
586
- const out = await this.runs.resultsLight(ctx.orgId, ctx.actorAccountId, input.runId, { limit: input.limit, ...(input.after !== undefined && { after: input.after }) }, undefined, viaAgent("evals.list-results", ctx));
601
+ const out = await this.runs.resultsLight(ctx.orgId, ctx.actorAccountId, input.runId, { page: input.page, size: input.size }, undefined, viaAgent("evals.list-results", ctx));
587
602
  return {
588
- items: out.results.map((r) => ({
603
+ ...out,
604
+ items: out.items.map((r) => ({
589
605
  id: r.id,
590
606
  name: r.step === null ? "whole run" : `step ${r.step}`,
591
607
  state: r.status,
@@ -594,7 +610,6 @@ let EvalsOperations = class EvalsOperations {
594
610
  verdict: r.label ?? r.verdict,
595
611
  toolCallsMatch: r.toolCallsMatch,
596
612
  })),
597
- next: out.next,
598
613
  };
599
614
  },
600
615
  }),
@@ -48,9 +48,9 @@ let OrgSettingsOperations = class OrgSettingsOperations {
48
48
  this.registry.register([
49
49
  defineOperation({
50
50
  id: "org-security.get",
51
- description: "Read organization security ceilings and a page of canonical tool policies. Pass nextCursor as cursor to continue.",
51
+ description: "Read organization security ceilings and a page of canonical tool policies (items), by tool key. Paged by page number: page (1-based) and size (20, 50 or 100); the answer has items, page, size and total.",
52
52
  input: OrgSecurityQuerySchema,
53
- example: { limit: 50 },
53
+ example: { page: 1, size: 50 },
54
54
  authz: { orgAction: "org.update" },
55
55
  mirrors: ["GET /api/v1/orgs/:orgId/settings/security"],
56
56
  confirm: "read",