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

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 (158) hide show
  1. package/dist/admin/audit-log.service.d.ts +96 -12
  2. package/dist/admin/audit-log.service.js +508 -44
  3. package/dist/admin/audit-targets.d.ts +17 -0
  4. package/dist/admin/audit-targets.js +84 -0
  5. package/dist/admin/audit.controller.d.ts +12 -9
  6. package/dist/admin/audit.controller.js +29 -8
  7. package/dist/admin/audit.schemas.d.ts +20 -4
  8. package/dist/admin/audit.schemas.js +42 -17
  9. package/dist/agents/templates.js +3 -10
  10. package/dist/app.d.ts +3 -1
  11. package/dist/app.js +1 -0
  12. package/dist/automations/automations.service.js +4 -5
  13. package/dist/catalog/catalog-content.d.ts +1 -1
  14. package/dist/catalog/catalog-content.js +17 -22
  15. package/dist/catalog/catalog-items.d.ts +5 -10
  16. package/dist/catalog/catalog-items.js +27 -51
  17. package/dist/catalog/catalog-scope.service.d.ts +4 -2
  18. package/dist/catalog/catalog-scope.service.js +105 -141
  19. package/dist/catalog/catalog.module.js +2 -0
  20. package/dist/catalog/catalog.service.d.ts +3 -3
  21. package/dist/catalog/catalog.service.js +33 -8
  22. package/dist/catalog/cli.js +17 -0
  23. package/dist/catalog/component-promotion.js +8 -4
  24. package/dist/catalog/component-scope.service.d.ts +3 -1
  25. package/dist/catalog/component-scope.service.js +101 -140
  26. package/dist/catalog/component-state.d.ts +10 -8
  27. package/dist/catalog/component-state.js +42 -30
  28. package/dist/catalog/dependency-edges.d.ts +25 -0
  29. package/dist/catalog/dependency-edges.js +125 -0
  30. package/dist/catalog/install-status.d.ts +2 -3
  31. package/dist/catalog/install-status.js +2 -3
  32. package/dist/catalog/org-catalog.service.d.ts +3 -1
  33. package/dist/catalog/org-catalog.service.js +33 -94
  34. package/dist/catalog/org-intent.d.ts +43 -0
  35. package/dist/catalog/org-intent.js +184 -0
  36. package/dist/catalog/owned-items.d.ts +1 -1
  37. package/dist/catalog/owned-items.js +9 -29
  38. package/dist/catalog/ownership.d.ts +2 -3
  39. package/dist/catalog/ownership.js +10 -28
  40. package/dist/catalog/platform-components.d.ts +3 -1
  41. package/dist/catalog/platform-components.js +9 -1
  42. package/dist/catalog/plugin-import.js +12 -16
  43. package/dist/catalog/plugin-install.d.ts +3 -4
  44. package/dist/catalog/plugin-install.js +25 -49
  45. package/dist/catalog/plugin-upgrade.d.ts +2 -2
  46. package/dist/catalog/plugin-upgrade.js +18 -34
  47. package/dist/catalog/request-rules.js +20 -8
  48. package/dist/catalog/scope-orgs.js +2 -7
  49. package/dist/catalog/scope-state.d.ts +6 -6
  50. package/dist/catalog/scope-state.js +24 -43
  51. package/dist/catalog/scope-sync.d.ts +0 -2
  52. package/dist/catalog/scope-sync.js +11 -39
  53. package/dist/catalog/scope-writer.d.ts +78 -0
  54. package/dist/catalog/scope-writer.js +181 -0
  55. package/dist/catalog/unshare.js +8 -41
  56. package/dist/channels/connections.service.js +6 -6
  57. package/dist/channels/supervisor.js +3 -7
  58. package/dist/client/client-access.service.js +2 -12
  59. package/dist/config/schema.d.ts +6 -0
  60. package/dist/config/schema.js +29 -1
  61. package/dist/ctx/create-ctx.d.ts +2 -2
  62. package/dist/ctx/create-ctx.js +2 -60
  63. package/dist/ctx/guard-db.d.ts +6 -0
  64. package/dist/ctx/guard-db.js +55 -0
  65. package/dist/db/extension-handoff-schema.d.ts +1 -1
  66. package/dist/db/extension-handoff-schema.js +48 -10
  67. package/dist/db/extension-schema-transfer.js +5 -2
  68. package/dist/db/kernel-schema.d.ts +11 -1
  69. package/dist/device-access/host-services.d.ts +2 -2
  70. package/dist/device-access/host-services.js +5 -6
  71. package/dist/erasure/org-catalog.js +2 -2
  72. package/dist/erasure/org-rules.js +5 -0
  73. package/dist/extensions/admin-ops.d.ts +9 -5
  74. package/dist/extensions/admin-ops.js +52 -8
  75. package/dist/extensions/admin-view.js +1 -4
  76. package/dist/extensions/bootstrap.js +4 -1
  77. package/dist/extensions/cli.js +1 -0
  78. package/dist/extensions/effective-config.js +1 -4
  79. package/dist/extensions/enabled.d.ts +23 -29
  80. package/dist/extensions/enabled.js +141 -62
  81. package/dist/extensions/host.d.ts +64 -45
  82. package/dist/extensions/host.js +443 -128
  83. package/dist/extensions/installs.d.ts +9 -0
  84. package/dist/extensions/installs.js +23 -0
  85. package/dist/extensions/isolated/admission.d.ts +10 -0
  86. package/dist/extensions/isolated/admission.js +206 -0
  87. package/dist/extensions/isolated/authorization.d.ts +37 -0
  88. package/dist/extensions/isolated/authorization.js +146 -0
  89. package/dist/extensions/isolated/broker.d.ts +15 -0
  90. package/dist/extensions/isolated/broker.js +452 -0
  91. package/dist/extensions/isolated/child-protocol.d.ts +84 -0
  92. package/dist/extensions/isolated/child-protocol.js +21 -0
  93. package/dist/extensions/isolated/child-registration.d.ts +22 -0
  94. package/dist/extensions/isolated/child-registration.js +152 -0
  95. package/dist/extensions/isolated/child-session.d.ts +6 -0
  96. package/dist/extensions/isolated/child-session.js +343 -0
  97. package/dist/extensions/isolated/child-streams.d.ts +4 -0
  98. package/dist/extensions/isolated/child-streams.js +142 -0
  99. package/dist/extensions/isolated/child.d.ts +1 -0
  100. package/dist/extensions/isolated/child.js +10 -0
  101. package/dist/extensions/isolated/configured-package.d.ts +15 -0
  102. package/dist/extensions/isolated/configured-package.js +73 -0
  103. package/dist/extensions/isolated/lanes.d.ts +100 -0
  104. package/dist/extensions/isolated/lanes.js +699 -0
  105. package/dist/extensions/isolated/postgres-gate.d.ts +14 -0
  106. package/dist/extensions/isolated/postgres-gate.js +255 -0
  107. package/dist/extensions/isolated/revision.d.ts +32 -0
  108. package/dist/extensions/isolated/revision.js +358 -0
  109. package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
  110. package/dist/extensions/isolated/rpc-frame.js +193 -0
  111. package/dist/extensions/isolated/rpc.d.ts +66 -0
  112. package/dist/extensions/isolated/rpc.js +314 -0
  113. package/dist/extensions/isolated/sandbox.d.ts +35 -0
  114. package/dist/extensions/isolated/sandbox.js +372 -0
  115. package/dist/extensions/isolated/tier.d.ts +6 -0
  116. package/dist/extensions/isolated/tier.js +45 -0
  117. package/dist/extensions/ledger.d.ts +1 -1
  118. package/dist/extensions/lifecycle-topics.d.ts +1 -0
  119. package/dist/extensions/lifecycle-topics.js +1 -0
  120. package/dist/extensions/lifecycle.d.ts +3 -1
  121. package/dist/extensions/lifecycle.js +32 -5
  122. package/dist/extensions/locks.d.ts +2 -0
  123. package/dist/extensions/locks.js +7 -0
  124. package/dist/extensions/org-config.d.ts +17 -27
  125. package/dist/extensions/org-config.js +114 -129
  126. package/dist/extensions/plugin-guides.d.ts +5 -10
  127. package/dist/extensions/plugin-guides.js +18 -37
  128. package/dist/extensions/plugin-icons.d.ts +3 -21
  129. package/dist/extensions/plugin-icons.js +9 -44
  130. package/dist/extensions/plugin-items.d.ts +10 -30
  131. package/dist/extensions/plugin-items.js +32 -73
  132. package/dist/extensions/source-intent.d.ts +14 -0
  133. package/dist/extensions/source-intent.js +77 -0
  134. package/dist/index.d.ts +2 -1
  135. package/dist/index.js +2 -1
  136. package/dist/infra/database/database.module.js +6 -1
  137. package/dist/infra/database/kernel-db.d.ts +3 -1
  138. package/dist/infra/database/kernel-db.js +4 -0
  139. package/dist/infra/paging/paged-read.d.ts +56 -0
  140. package/dist/infra/paging/paged-read.js +78 -0
  141. package/dist/kernel.d.ts +3 -2
  142. package/dist/kernel.js +21 -2
  143. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  144. package/dist/lifecycle/kernel-lifecycle.js +22 -12
  145. package/dist/lifecycle/tokens.d.ts +8 -0
  146. package/dist/lifecycle/tokens.js +2 -0
  147. package/dist/orgs/directory-sync.js +1 -4
  148. package/dist/platform/ops/admin.ops.js +14 -3
  149. package/dist/platform/ops/orgs.ops.js +13 -3
  150. package/dist/setup/setup-checks.service.js +3 -2
  151. package/dist/skills/usable.js +41 -30
  152. package/dist/themes/theme-state.js +3 -3
  153. package/dist/tools/registry.d.ts +1 -1
  154. package/dist/tools/registry.js +1 -1
  155. package/package.json +2 -2
  156. package/src/migrations/0228_extension_org_switches.sql +56 -0
  157. package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
  158. package/src/migrations/0230_audit_filter_idx.sql +18 -0
@@ -0,0 +1,84 @@
1
+ /** Exact action names, checked before {@link PREFIXES}. */
2
+ const EXACT = {
3
+ "org.created": "org",
4
+ "org.deleted": "org",
5
+ "org.updated": "org",
6
+ "org.settings_updated": "org",
7
+ "org.security_updated": "org",
8
+ "org.ownership_transferred": "account",
9
+ "deployment.setup_completed": "account",
10
+ "catalog.imported": "catalog_item",
11
+ "catalog.scope_changed": "catalog_item",
12
+ "catalog.shown_changed": "catalog_item",
13
+ "catalog.shareable_changed": "catalog_item",
14
+ "catalog.ownership_transferred": "catalog_item",
15
+ "catalog.removed": "catalog_item",
16
+ "plugin.platform_updated": "catalog_item",
17
+ "plugin.platform_update_failed": "catalog_item",
18
+ "plugin.scope_sync_failed": "catalog_item",
19
+ "plugin.org_installed": "plugin_install",
20
+ "plugin.org_uninstalled": "plugin_install",
21
+ "plugin.org_install_failed": "plugin_install",
22
+ "login_sources.updated": "extension",
23
+ "tool_grant.revoked": "agent",
24
+ "subagent.refused": "agent",
25
+ "automation.created": "automation",
26
+ "automation.deleted": "automation",
27
+ "automation.grants_changed": "automation",
28
+ "automation.paused": "automation",
29
+ "automation.resumed": "automation",
30
+ "automation.run_now": "automation",
31
+ "automation.updated": "automation",
32
+ "browser.view": "device",
33
+ "browser.view_closed": "device",
34
+ "permission.crossing_auto_granted": "device",
35
+ "skill.created": "skill",
36
+ "skill.deleted": "skill",
37
+ "skill.shared": "skill",
38
+ "skill.share_requested": "skill",
39
+ "skill.version_created": "skill",
40
+ "skill.version_reverted": "skill",
41
+ "eval.set_created": "eval_set",
42
+ "eval.set_updated": "eval_set",
43
+ "eval.set_deleted": "eval_set",
44
+ "eval.case_added": "eval_set",
45
+ "eval.case_removed": "eval_set",
46
+ };
47
+ /** Action prefixes whose every action targets one kind (the first match wins). */
48
+ const PREFIXES = [
49
+ ["account.", "account"],
50
+ ["identity.", "account"],
51
+ ["org.member.", "account"],
52
+ ["org.service_token.", "service_token"],
53
+ ["org.plugin_config.", "extension"],
54
+ ["org.directory.", "extension"],
55
+ ["extension.", "extension"],
56
+ ["connector.", "connector"],
57
+ ["agent.", "agent"],
58
+ ["agent_template.", "agent_template"],
59
+ ["device.", "device"],
60
+ ["channel.", "channel"],
61
+ ["marketplace.", "marketplace"],
62
+ ];
63
+ /** The kind of object `action`'s target names, or null when the log cannot name it. */
64
+ export function auditTargetKind(action) {
65
+ const exact = EXACT[action];
66
+ if (exact !== undefined)
67
+ return exact;
68
+ for (const [prefix, kind] of PREFIXES)
69
+ if (action.startsWith(prefix))
70
+ return kind;
71
+ return null;
72
+ }
73
+ /**
74
+ * The action conditions of one kind, for SQL: its exact names and its prefixes (the inverse of
75
+ * {@link auditTargetKind}, used to match `q` against names of that kind).
76
+ */
77
+ export function auditKindActions(kind) {
78
+ return {
79
+ exact: Object.entries(EXACT)
80
+ .filter(([, k]) => k === kind)
81
+ .map(([a]) => a),
82
+ prefixes: PREFIXES.filter(([, k]) => k === kind).map(([p]) => p),
83
+ };
84
+ }
@@ -1,26 +1,29 @@
1
1
  import type { z } from "zod";
2
2
  import { type OrgContext } from "../orgs/org.guard.js";
3
- import { AuditListQuery, OrgAuditListQuery } from "./audit.schemas.js";
4
- import { AuditLogService, type AuditPage } from "./audit-log.service.js";
3
+ import { AuditActorsQuery, AuditListQuery, OrgAuditActorsQuery, OrgAuditListQuery } from "./audit.schemas.js";
4
+ import { type AuditActors, AuditLogService, type AuditPage } from "./audit-log.service.js";
5
5
  /**
6
6
  * The platform-level audit log (`GET /api/v1/admin/audit`, admin overview spec §5.2, decision D2):
7
- * events with no org, or with `orgId` that org's, newest first, keyset paged; never an event's
8
- * `detail`. Super admins only; the read itself is not audited (D5).
7
+ * events with no org, or with `orgId` that org's, newest first, by page number on a snapshot with
8
+ * filters (table pagination spec §2.3, §3); never an event's `detail`. Super admins only; the read
9
+ * itself is not audited (D5).
9
10
  */
10
11
  export declare class AdminAuditController {
11
12
  private readonly audit;
12
13
  constructor(audit: AuditLogService);
13
- /** `next` is the `after` of the next page, null at the end. */
14
14
  list(q: z.infer<typeof AuditListQuery>): Promise<AuditPage>;
15
+ /** The accounts and tokens that acted in the log (the actor filter's options). */
16
+ actors(q: z.infer<typeof AuditActorsQuery>): Promise<AuditActors>;
15
17
  }
16
18
  /**
17
- * The org's audit log (`GET /api/v1/orgs/:orgId/audit`): the org's own events, newest first,
18
- * keyset paged, the same rows as the platform log (never `detail`). Org admins (`org.update`, a
19
- * person: service tokens are refused); a non-member gets 404. The read is not audited.
19
+ * The org's audit log (`GET /api/v1/orgs/:orgId/audit`): the org's own events, newest first, by
20
+ * page number with filters, the same rows as the platform log (never `detail`). Org admins
21
+ * (`org.update`, a person: service tokens are refused); a non-member gets 404. Not audited.
20
22
  */
21
23
  export declare class OrgAuditController {
22
24
  private readonly audit;
23
25
  constructor(audit: AuditLogService);
24
- /** `next` is the `after` of the next page, null at the end. */
25
26
  list(org: OrgContext, q: z.infer<typeof OrgAuditListQuery>): Promise<AuditPage>;
27
+ /** The accounts and service tokens that acted in the org's log (the actor filter's options). */
28
+ actors(org: OrgContext, _q: z.infer<typeof OrgAuditActorsQuery>): Promise<AuditActors>;
26
29
  }
@@ -12,32 +12,44 @@ import { SuperAdmin } from "../identity/principal.js";
12
12
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
13
13
  import { ZQuery } from "../infra/validation/zod-params.js";
14
14
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
15
- import { AuditListQuery, OrgAuditListQuery } from "./audit.schemas.js";
15
+ import { AuditActorsQuery, AuditListQuery, OrgAuditActorsQuery, OrgAuditListQuery, } from "./audit.schemas.js";
16
16
  import { AuditLogService } from "./audit-log.service.js";
17
17
  class AuditListQueryDto extends createZodDto(AuditListQuery, "AuditListQuery") {
18
18
  }
19
19
  class OrgAuditListQueryDto extends createZodDto(OrgAuditListQuery, "OrgAuditListQuery") {
20
20
  }
21
+ class AuditActorsQueryDto extends createZodDto(AuditActorsQuery, "AuditActorsQuery") {
22
+ }
23
+ class OrgAuditActorsQueryDto extends createZodDto(OrgAuditActorsQuery, "OrgAuditActorsQuery") {
24
+ }
21
25
  /**
22
26
  * The platform-level audit log (`GET /api/v1/admin/audit`, admin overview spec §5.2, decision D2):
23
- * events with no org, or with `orgId` that org's, newest first, keyset paged; never an event's
24
- * `detail`. Super admins only; the read itself is not audited (D5).
27
+ * events with no org, or with `orgId` that org's, newest first, by page number on a snapshot with
28
+ * filters (table pagination spec §2.3, §3); never an event's `detail`. Super admins only; the read
29
+ * itself is not audited (D5).
25
30
  */
26
31
  let AdminAuditController = class AdminAuditController {
27
32
  audit;
28
33
  constructor(audit) {
29
34
  this.audit = audit;
30
35
  }
31
- /** `next` is the `after` of the next page, null at the end. */
32
36
  list(q) {
33
37
  const { orgId, ...page } = q;
34
38
  return this.audit.list(orgId === undefined ? { platform: true } : { orgId }, page);
35
39
  }
40
+ /** The accounts and tokens that acted in the log (the actor filter's options). */
41
+ actors(q) {
42
+ return this.audit.actors(q.orgId === undefined ? { platform: true } : { orgId: q.orgId });
43
+ }
36
44
  };
37
45
  __decorate([
38
46
  Get(),
39
47
  __param(0, ZQuery(AuditListQueryDto))
40
48
  ], AdminAuditController.prototype, "list", null);
49
+ __decorate([
50
+ Get("actors"),
51
+ __param(0, ZQuery(AuditActorsQueryDto))
52
+ ], AdminAuditController.prototype, "actors", null);
41
53
  AdminAuditController = __decorate([
42
54
  Controller("api/v1/admin/audit"),
43
55
  SuperAdmin(),
@@ -45,19 +57,22 @@ AdminAuditController = __decorate([
45
57
  ], AdminAuditController);
46
58
  export { AdminAuditController };
47
59
  /**
48
- * The org's audit log (`GET /api/v1/orgs/:orgId/audit`): the org's own events, newest first,
49
- * keyset paged, the same rows as the platform log (never `detail`). Org admins (`org.update`, a
50
- * person: service tokens are refused); a non-member gets 404. The read is not audited.
60
+ * The org's audit log (`GET /api/v1/orgs/:orgId/audit`): the org's own events, newest first, by
61
+ * page number with filters, the same rows as the platform log (never `detail`). Org admins
62
+ * (`org.update`, a person: service tokens are refused); a non-member gets 404. Not audited.
51
63
  */
52
64
  let OrgAuditController = class OrgAuditController {
53
65
  audit;
54
66
  constructor(audit) {
55
67
  this.audit = audit;
56
68
  }
57
- /** `next` is the `after` of the next page, null at the end. */
58
69
  list(org, q) {
59
70
  return this.audit.list({ orgId: org.orgId }, q);
60
71
  }
72
+ /** The accounts and service tokens that acted in the org's log (the actor filter's options). */
73
+ actors(org, _q) {
74
+ return this.audit.actors({ orgId: org.orgId });
75
+ }
61
76
  };
62
77
  __decorate([
63
78
  Get(),
@@ -65,6 +80,12 @@ __decorate([
65
80
  __param(0, CurrentOrg()),
66
81
  __param(1, ZQuery(OrgAuditListQueryDto))
67
82
  ], OrgAuditController.prototype, "list", null);
83
+ __decorate([
84
+ Get("actors"),
85
+ OrgAction("org.update"),
86
+ __param(0, CurrentOrg()),
87
+ __param(1, ZQuery(OrgAuditActorsQueryDto))
88
+ ], OrgAuditController.prototype, "actors", null);
68
89
  OrgAuditController = __decorate([
69
90
  Controller("api/v1/orgs/:orgId/audit"),
70
91
  __param(0, Inject(AuditLogService))
@@ -2,15 +2,31 @@ import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
3
  /** `GET /api/v1/admin/audit`: the platform's events, or with `orgId` that org's. */
4
4
  export declare const AuditListQuery: 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
+ from: z.ZodOptional<z.ZodISODateTime>;
8
+ to: z.ZodOptional<z.ZodISODateTime>;
9
+ actor: z.ZodOptional<z.ZodString>;
7
10
  action: z.ZodOptional<z.ZodString>;
11
+ q: z.ZodOptional<z.ZodString>;
12
+ asOf: z.ZodOptional<z.ZodString>;
8
13
  orgId: z.ZodOptional<z.ZodString>;
9
14
  }, z.core.$strip>;
10
15
  /** `GET /api/v1/orgs/:orgId/audit`: the org's own events (org admins). */
11
16
  export declare const OrgAuditListQuery: z.ZodObject<{
12
- after: 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>>;
19
+ from: z.ZodOptional<z.ZodISODateTime>;
20
+ to: z.ZodOptional<z.ZodISODateTime>;
21
+ actor: z.ZodOptional<z.ZodString>;
14
22
  action: z.ZodOptional<z.ZodString>;
23
+ q: z.ZodOptional<z.ZodString>;
24
+ asOf: z.ZodOptional<z.ZodString>;
15
25
  }, z.core.$strip>;
26
+ /** `GET /api/v1/admin/audit/actors`: who acted in the platform's log, or with `orgId` an org's. */
27
+ export declare const AuditActorsQuery: z.ZodObject<{
28
+ orgId: z.ZodOptional<z.ZodString>;
29
+ }, z.core.$strip>;
30
+ /** `GET /api/v1/orgs/:orgId/audit/actors`: who acted in the org's log. */
31
+ export declare const OrgAuditActorsQuery: z.ZodObject<{}, z.core.$strip>;
16
32
  export declare const AUDIT_ROUTES: readonly RouteSchemas[];
@@ -1,37 +1,62 @@
1
1
  import { z } from "zod";
2
- /** The largest `bigserial` id; a larger `after` would make PG refuse the comparison. */
3
- const MAX_BIGINT = 9223372036854775807n;
2
+ import { bigserialAsOf, PageQueryFields } from "../infra/paging/paged-read.js";
3
+ /** `orgId` of the platform routes: read that org's log instead of the platform's. */
4
+ const OrgIdField = z
5
+ .string()
6
+ .min(1)
7
+ .max(100)
8
+ .optional()
9
+ .describe("Read this org's events instead of the platform's.");
4
10
  /**
5
- * A page of an audit log: keyset paging by event id, newest first (admin overview spec §5.2), and
6
- * an optional action prefix.
11
+ * The filters of an audit log (table pagination spec §3), combined with AND. `from` / `to` are a
12
+ * half-open time range (`from <= at < to`).
7
13
  */
8
- const AuditPageQuery = z.object({
9
- after: z
14
+ const AuditFilterFields = {
15
+ from: z.iso
16
+ .datetime({ offset: true })
17
+ .optional()
18
+ .describe("Only events at or after this time (ISO 8601)."),
19
+ to: z.iso
20
+ .datetime({ offset: true })
21
+ .optional()
22
+ .describe("Only events before this time (ISO 8601)."),
23
+ actor: z
10
24
  .string()
11
- .regex(/^\d{1,19}$/, "after must be an event id (digits)")
12
- // checks do not abort: only digits reach BigInt
13
- .refine((v) => !/^\d{1,19}$/.test(v) || BigInt(v) <= MAX_BIGINT, "after must be an event id")
25
+ .min(1)
26
+ .max(120)
27
+ .regex(/^[A-Za-z0-9_.:-]+$/, "actor must be an account id, system or token:<token id>")
14
28
  .optional()
15
- .describe("The id of the last event of the previous page (its next); absent: the newest."),
16
- limit: z.coerce.number().int().min(1).max(100).default(20),
29
+ .describe("Only events by this actor: an account id, system (the kernel itself: no account and no token), or token:<token id> (done with that access token)."),
17
30
  action: z
18
31
  .string()
19
32
  .regex(/^[a-z][a-z0-9_.]{0,63}$/, "action must be an action name or its prefix (a-z 0-9 _ .)")
20
33
  .optional()
21
34
  .describe("Only actions starting with this, e.g. connector. or org.member.added."),
22
- });
23
- /** `GET /api/v1/admin/audit`: the platform's events, or with `orgId` that org's. */
24
- export const AuditListQuery = AuditPageQuery.extend({
25
- orgId: z
35
+ q: z
26
36
  .string()
37
+ .trim()
27
38
  .min(1)
28
- .max(100)
39
+ .max(200)
29
40
  .optional()
30
- .describe("Read this org's events instead of the platform's."),
41
+ .describe("Only events whose target is exactly this id, or whose target's name contains it (case-insensitive): accounts, orgs, plugins, extensions, connectors, agents, agent templates, automations, devices, skills, channels, eval sets, service tokens, marketplaces."),
42
+ };
43
+ /** A page of an audit log: page numbers on a snapshot of event ids (spec §2.3), and the filters. */
44
+ const AuditPageQuery = z.object({
45
+ ...PageQueryFields,
46
+ asOf: bigserialAsOf("an event id"),
47
+ ...AuditFilterFields,
31
48
  });
49
+ /** `GET /api/v1/admin/audit`: the platform's events, or with `orgId` that org's. */
50
+ export const AuditListQuery = AuditPageQuery.extend({ orgId: OrgIdField });
32
51
  /** `GET /api/v1/orgs/:orgId/audit`: the org's own events (org admins). */
33
52
  export const OrgAuditListQuery = AuditPageQuery;
53
+ /** `GET /api/v1/admin/audit/actors`: who acted in the platform's log, or with `orgId` an org's. */
54
+ export const AuditActorsQuery = z.object({ orgId: OrgIdField });
55
+ /** `GET /api/v1/orgs/:orgId/audit/actors`: who acted in the org's log. */
56
+ export const OrgAuditActorsQuery = z.object({});
34
57
  export const AUDIT_ROUTES = [
35
58
  { route: "GET /api/v1/admin/audit", query: AuditListQuery },
36
59
  { route: "GET /api/v1/orgs/:orgId/audit", query: OrgAuditListQuery },
60
+ { route: "GET /api/v1/admin/audit/actors", query: AuditActorsQuery },
61
+ { route: "GET /api/v1/orgs/:orgId/audit/actors", query: OrgAuditActorsQuery },
37
62
  ];
@@ -11,7 +11,7 @@ import { randomUUID } from "node:crypto";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { componentOn } from "../catalog/component-state.js";
14
- import { LIVE_INSTALL_STATUSES } from "../catalog/install-status.js";
14
+ import { orgUsable } from "../catalog/org-intent.js";
15
15
  import { ownerOf, ownersOf } from "../catalog/ownership.js";
16
16
  import { KernelDb } from "../infra/database/kernel-db.js";
17
17
  import { canonicalJson } from "../tools/canonical-json.js";
@@ -88,14 +88,7 @@ async function platformRowsOn(db, orgId, ids) {
88
88
  "c.id as item_id",
89
89
  "c.disabled as item_disabled",
90
90
  "c.builtin as item_builtin",
91
- eb
92
- .exists(eb
93
- .selectFrom("plugin_installs as a")
94
- .select("a.id")
95
- .whereRef("a.item_id", "=", "p.catalog_item_id")
96
- .where("a.org_id", "=", orgId)
97
- .where("a.status", "in", [...LIVE_INSTALL_STATUSES]))
98
- .as("installed"),
91
+ orgUsable(db, orgId, eb.ref("p.catalog_item_id")).as("plugin_usable"),
99
92
  eb
100
93
  .exists(eb
101
94
  .selectFrom("component_scope_orgs as l")
@@ -126,7 +119,7 @@ async function platformRowsOn(db, orgId, ids) {
126
119
  // the plugin's own scope and list do not decide whether a component is on
127
120
  scope: "optional",
128
121
  listed: false,
129
- installed: Boolean(r.installed),
122
+ usable: r.plugin_usable,
130
123
  }, Boolean(r.listed), r.switch ?? null));
131
124
  }
132
125
  /**
package/dist/app.d.ts CHANGED
@@ -7,10 +7,12 @@ import type { KernelConfig } from "./config/schema.js";
7
7
  import type { ConfigSourceKind } from "./config/sources.js";
8
8
  import { type KernelHttp } from "./http/app.js";
9
9
  import { type ShutdownSignalOptions } from "./infra/lifecycle/shutdown-signals.js";
10
+ import type { KernelFixtureTrust } from "./lifecycle/tokens.js";
10
11
  import type { KernelLogger } from "./log.js";
11
12
  import type { KernelOverride } from "./overrides.js";
13
+ export { KERNEL_FIXTURE_TRUST } from "./lifecycle/tokens.js";
12
14
  /** What {@link createKernelApp} takes besides the config. */
13
- export interface KernelAppOptions {
15
+ export interface KernelAppOptions extends KernelFixtureTrust {
14
16
  /** Explicit startup CAS intent; never a reloadable configuration value. */
15
17
  permissionConfigActivation?: Readonly<{
16
18
  expectedActiveHash: string;
package/dist/app.js CHANGED
@@ -11,6 +11,7 @@ import { KernelModule } from "./kernel.module.js";
11
11
  import { KernelLifecycle } from "./lifecycle/kernel-lifecycle.js";
12
12
  import { createConfiguredLogger } from "./log-config.js";
13
13
  import { validatePermissionConfigActivation } from "./sandbox/permission-config-publication.js";
14
+ export { KERNEL_FIXTURE_TRUST } from "./lifecycle/tokens.js";
14
15
  /**
15
16
  * Builds the kernel application (one Nest application, root module {@link KernelModule}) and sets
16
17
  * up its HTTP side, without initializing it: nothing connects and nothing starts. A failure
@@ -15,7 +15,7 @@ import { ConversationAccess } from "../conversations/access.js";
15
15
  import { readMessageContext } from "../conversations/message-context.js";
16
16
  import { ApiError } from "../errors.js";
17
17
  import { ExtensionDisplayNames } from "../extensions/display-name.js";
18
- import { enabledExtensionsByOrg, isExtensionEnabled } from "../extensions/enabled.js";
18
+ import { enabledExtensionsQuery, isExtensionEnabled } from "../extensions/enabled.js";
19
19
  import { ExtensionPointDefaults } from "../extensions/point-defaults.js";
20
20
  import { ExtensionRegistry } from "../extensions/registry.js";
21
21
  import { loadPeople } from "../identity/account-avatar.js";
@@ -616,12 +616,10 @@ let AutomationsService = class AutomationsService {
616
616
  */
617
617
  async chatTargets(orgId, accountId) {
618
618
  await this.liveRole(orgId, accountId);
619
- const rows = await this.db.db
619
+ const db = this.db.db;
620
+ const rows = await db
620
621
  .selectFrom("channel_threads")
621
622
  .innerJoin("channel_connections", "channel_connections.id", "channel_threads.connection_id")
622
- .innerJoin(enabledExtensionsByOrg(this.db.db).as("en"), (j) => j
623
- .onRef("en.org_id", "=", "channel_connections.org_id")
624
- .onRef("en.plugin", "=", "channel_connections.plugin"))
625
623
  .select([
626
624
  "channel_connections.id as connection_id",
627
625
  "channel_connections.name",
@@ -631,6 +629,7 @@ let AutomationsService = class AutomationsService {
631
629
  "channel_threads.thread_key",
632
630
  ])
633
631
  .where("channel_connections.org_id", "=", orgId)
632
+ .where(({ exists, ref }) => exists(enabledExtensionsQuery(db, ref("channel_connections.org_id"), ref("channel_connections.plugin"))))
634
633
  .where("channel_connections.status", "=", "active")
635
634
  .where("channel_connections.deleted_at", "is", null)
636
635
  .where("channel_threads.account_id", "=", accountId)
@@ -179,7 +179,7 @@ export declare function catalogHasIcon(db: KernelSchemaDb, itemId: string): Prom
179
179
  * storage); no icon -> `catalog.icon_not_found`; stored content that is not a valid svg / png
180
180
  * (checked at import, this guards against tampered storage) -> `internal`.
181
181
  */
182
- export declare function readCatalogIcon(db: KernelSchemaDb, itemId: string, includeDisabled: boolean): Promise<CatalogIcon>;
182
+ export declare function readCatalogIcon(db: KernelSchemaDb, itemId: string, includeDisabled: boolean, orgId?: string): Promise<CatalogIcon>;
183
183
  export type { ConnectorInstallInput };
184
184
  /**
185
185
  * The input of `POST /orgs/:orgId/catalog/:itemId/install`: the platform version is installed
@@ -10,6 +10,7 @@ import { packagePath } from "../packages/tgz.js";
10
10
  import { checkSkillFiles, SkillArchiveError } from "../skills/package.js";
11
11
  import { mergeEditableEndpoint } from "../tools/editable-endpoint.js";
12
12
  import { readDisplayFiles } from "./catalog-files.js";
13
+ import { orgSees } from "./org-intent.js";
13
14
  import { iconProblem, pluginThemeError, themeApiError } from "./plugin-package.js";
14
15
  import { templateDescriptionText } from "./template-description.js";
15
16
  import { satisfiesRange } from "./versions.js";
@@ -62,28 +63,22 @@ export function dirDigest(row, dir) {
62
63
  * The item's latest version row; item missing, deleted or (when `includeDisabled` is false)
63
64
  * disabled -> `catalog.item_not_found`.
64
65
  */
65
- async function latestVersionRow(db, itemId, includeDisabled) {
66
+ async function latestVersionRow(db, itemId, includeDisabled, orgId) {
66
67
  if (!UUID_RE.test(itemId))
67
68
  throw itemNotFound();
68
- const item = await db
69
- .selectFrom("catalog_items")
70
- .select(["latest_version", "disabled"])
71
- .where("id", "=", itemId)
72
- .where("deleted_at", "is", null)
73
- .executeTakeFirst();
74
- // An item the caller cannot see is "not found" before any version / storage is read, so "no icon"
75
- // never reveals that it exists
76
- if (!item || (!includeDisabled && item.disabled))
69
+ const query = db
70
+ .selectFrom("catalog_items as item")
71
+ .innerJoin("catalog_item_versions as v", (join) => join.onRef("v.item_id", "=", "item.id").onRef("v.version", "=", "item.latest_version"))
72
+ .select(["v.manifest", "v.object_prefix", "v.files"])
73
+ .where("item.id", "=", itemId)
74
+ .where("item.deleted_at", "is", null)
75
+ .$if(!includeDisabled, (q) => q.where("item.disabled", "=", false));
76
+ const version = await (orgId === undefined
77
+ ? query
78
+ : query.where("item.id", "in", orgSees(db, orgId, includeDisabled).select("item.id"))).executeTakeFirst();
79
+ if (version === undefined)
77
80
  throw itemNotFound();
78
- const v = await db
79
- .selectFrom("catalog_item_versions")
80
- .select(["manifest", "object_prefix", "files"])
81
- .where("item_id", "=", itemId)
82
- .where("version", "=", item.latest_version)
83
- .executeTakeFirst();
84
- if (!v)
85
- throw itemNotFound();
86
- return { item, v };
81
+ return version;
87
82
  }
88
83
  /** The icon's path in the version's files (undefined without an icon). */
89
84
  const iconPath = (v) => {
@@ -93,7 +88,7 @@ const iconPath = (v) => {
93
88
  /** Whether the item's latest version has an icon; unreadable counts as none. */
94
89
  export async function catalogHasIcon(db, itemId) {
95
90
  try {
96
- const { v } = await latestVersionRow(db, itemId, true);
91
+ const v = await latestVersionRow(db, itemId, true);
97
92
  const path = iconPath(v);
98
93
  return path !== undefined && v.files.some((f) => f.path === path);
99
94
  }
@@ -108,8 +103,8 @@ export async function catalogHasIcon(db, itemId) {
108
103
  * storage); no icon -> `catalog.icon_not_found`; stored content that is not a valid svg / png
109
104
  * (checked at import, this guards against tampered storage) -> `internal`.
110
105
  */
111
- export async function readCatalogIcon(db, itemId, includeDisabled) {
112
- const { v } = await latestVersionRow(db, itemId, includeDisabled);
106
+ export async function readCatalogIcon(db, itemId, includeDisabled, orgId) {
107
+ const v = await latestVersionRow(db, itemId, includeDisabled, orgId);
113
108
  const path = iconPath(v);
114
109
  const f = path === undefined ? undefined : v.files.find((x) => x.path === path);
115
110
  if (path === undefined || !f)
@@ -160,11 +160,13 @@ export declare function precheckCatalogImport(db: KernelSchemaDb, name: string,
160
160
  * the release with the same content; `version` not taken meanwhile), creates the item when there is
161
161
  * none or adds the version (latest and display fields change only for a newer version, a version
162
162
  * equal but for build metadata being newer as the later import), and writes the version row (with
163
- * its content digest) and the `catalog.imported` audit. Returns the item id.
163
+ * its content digest) and the `catalog.imported` audit. The caller refreshes dependency edges if
164
+ * the selected version changed, after applying the new item's components.
164
165
  */
165
166
  export declare function writeCatalogVersion(db: KernelSchemaDb, w: CatalogVersionWrite): Promise<{
166
167
  id: string;
167
168
  created: boolean;
169
+ selectedVersionChanged: boolean;
168
170
  }>;
169
171
  /**
170
172
  * Records that `version` of the item was applied (ruling P3-52), in the caller's
@@ -207,15 +209,8 @@ export declare function marketplaceLatest(db: KernelSchemaDb, config: KernelConf
207
209
  name: string;
208
210
  marketplace_id?: string | null;
209
211
  }[], versions: ReadonlyMap<string, readonly RecordedVersion[]>): Promise<Map<string, MarketplaceStatus>>;
210
- /** Org install counts per item (see {@link CatalogItemView.installs}). */
211
- export declare function countInstalls(db: KernelSchemaDb, items: {
212
- id: string;
213
- name: string;
214
- latest_version: string;
215
- }[], versions: ReadonlyMap<string, {
216
- version: string;
217
- extension_sha256: string | null;
218
- }[]>): Promise<Map<string, number>>;
212
+ /** How many organizations have applied setup effects for each item. */
213
+ export declare function countInstalls(db: KernelSchemaDb, itemIds: string[]): Promise<Map<string, number>>;
219
214
  /**
220
215
  * Every id is a live org (`validation_failed` naming the unknown ones otherwise): the orgs of a
221
216
  * `named` scope.