@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.37

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 (309) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -3
  3. package/dist/admin/admin.module.js +6 -6
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  11. package/dist/admin/outbox-dead.controller.js +9 -6
  12. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  13. package/dist/admin/outbox-dead.schemas.js +25 -1
  14. package/dist/admin/outbox-dead.service.d.ts +16 -7
  15. package/dist/admin/outbox-dead.service.js +34 -10
  16. package/dist/admin/overview.service.d.ts +3 -3
  17. package/dist/admin/overview.service.js +0 -1
  18. package/dist/agents/agent-lookup.js +2 -10
  19. package/dist/agents/agents.service.js +9 -20
  20. package/dist/agents/definition.d.ts +3 -51
  21. package/dist/agents/definition.js +4 -254
  22. package/dist/agents/org-templates.js +2 -6
  23. package/dist/agents/readiness.controller.d.ts +4 -12
  24. package/dist/agents/readiness.controller.js +4 -12
  25. package/dist/agents/readiness.service.d.ts +23 -11
  26. package/dist/agents/readiness.service.js +31 -14
  27. package/dist/agents/templates.d.ts +0 -6
  28. package/dist/agents/templates.js +8 -34
  29. package/dist/background/store.d.ts +2 -0
  30. package/dist/background/store.js +3 -1
  31. package/dist/background/wake-rules.js +2 -1
  32. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  33. package/dist/catalog/admin-catalog.controller.js +1 -2
  34. package/dist/catalog/appearance.service.js +1 -3
  35. package/dist/catalog/catalog-content.d.ts +1 -1
  36. package/dist/catalog/catalog-content.js +1 -4
  37. package/dist/catalog/catalog-items.js +3 -3
  38. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  39. package/dist/catalog/catalog-scope.service.js +22 -73
  40. package/dist/catalog/cli.d.ts +0 -11
  41. package/dist/catalog/cli.js +0 -20
  42. package/dist/catalog/component-scope.service.js +0 -2
  43. package/dist/catalog/component-state.js +2 -2
  44. package/dist/catalog/install-status.d.ts +6 -0
  45. package/dist/catalog/install-status.js +6 -0
  46. package/dist/catalog/job-ids.d.ts +0 -4
  47. package/dist/catalog/job-ids.js +0 -4
  48. package/dist/catalog/marketplaces.service.d.ts +1 -1
  49. package/dist/catalog/org-catalog.service.d.ts +2 -0
  50. package/dist/catalog/org-catalog.service.js +8 -3
  51. package/dist/catalog/org-extension-switch.d.ts +7 -2
  52. package/dist/catalog/org-extension-switch.js +56 -9
  53. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  54. package/dist/catalog/org-plugin-uploads.js +9 -27
  55. package/dist/catalog/owned-items.js +1 -3
  56. package/dist/catalog/platform-import-update.js +1 -1
  57. package/dist/catalog/plugin-import.d.ts +15 -13
  58. package/dist/catalog/plugin-import.js +21 -30
  59. package/dist/catalog/plugin-install.d.ts +3 -43
  60. package/dist/catalog/plugin-install.js +8 -150
  61. package/dist/catalog/plugin-package.d.ts +5 -10
  62. package/dist/catalog/plugin-package.js +12 -33
  63. package/dist/catalog/plugin-upgrade.js +5 -4
  64. package/dist/catalog/scope-jobs.d.ts +34 -34
  65. package/dist/catalog/scope-jobs.js +50 -37
  66. package/dist/catalog/scope-orgs.d.ts +1 -1
  67. package/dist/catalog/scope-orgs.js +1 -2
  68. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  69. package/dist/catalog/scope-sync-workers.js +18 -6
  70. package/dist/catalog/scope-sync.d.ts +56 -59
  71. package/dist/catalog/scope-sync.js +96 -166
  72. package/dist/catalog/unshare.d.ts +3 -4
  73. package/dist/catalog/unshare.js +5 -8
  74. package/dist/channels/job-ids.d.ts +2 -6
  75. package/dist/channels/job-ids.js +2 -6
  76. package/dist/channels/outbound.d.ts +1 -1
  77. package/dist/channels/outbound.js +1 -1
  78. package/dist/channels/supervisor.d.ts +2 -3
  79. package/dist/channels/supervisor.js +2 -3
  80. package/dist/client/client-access.service.js +1 -1
  81. package/dist/config/env.js +19 -1
  82. package/dist/config/load.d.ts +0 -6
  83. package/dist/config/load.js +8 -27
  84. package/dist/config/schema.d.ts +53 -47
  85. package/dist/config/schema.js +190 -40
  86. package/dist/conversations/attachments.service.d.ts +10 -3
  87. package/dist/conversations/attachments.service.js +49 -16
  88. package/dist/conversations/conversations.controller.d.ts +0 -39
  89. package/dist/conversations/conversations.controller.js +0 -39
  90. package/dist/conversations/events.d.ts +71 -46
  91. package/dist/conversations/events.js +124 -112
  92. package/dist/conversations/media-types.d.ts +25 -0
  93. package/dist/conversations/media-types.js +38 -0
  94. package/dist/conversations/queue.d.ts +3 -1
  95. package/dist/conversations/queue.service.js +9 -2
  96. package/dist/conversations/titles.js +6 -0
  97. package/dist/ctx/create-ctx.js +1 -2
  98. package/dist/ctx/secrets.d.ts +24 -7
  99. package/dist/ctx/secrets.js +97 -30
  100. package/dist/db/kernel-schema.d.ts +17 -6
  101. package/dist/errors.d.ts +5 -2
  102. package/dist/errors.js +5 -2
  103. package/dist/evals/reconstruct.d.ts +4 -17
  104. package/dist/evals/reconstruct.js +13 -53
  105. package/dist/evals/recorded-tools.d.ts +0 -27
  106. package/dist/evals/recorded-tools.js +2 -92
  107. package/dist/evals/run-replay.d.ts +1 -6
  108. package/dist/evals/run-replay.js +10 -17
  109. package/dist/evals/sets.service.d.ts +17 -5
  110. package/dist/evals/sets.service.js +33 -12
  111. package/dist/evals/snapshot.d.ts +1 -2
  112. package/dist/evals/snapshot.js +4 -17
  113. package/dist/extensions/admin-ops.d.ts +6 -1
  114. package/dist/extensions/admin-ops.js +17 -4
  115. package/dist/extensions/admin-view.d.ts +7 -4
  116. package/dist/extensions/admin-view.js +27 -21
  117. package/dist/extensions/bootstrap.js +0 -1
  118. package/dist/extensions/cli.js +0 -1
  119. package/dist/extensions/host.d.ts +2 -3
  120. package/dist/extensions/host.js +1 -5
  121. package/dist/extensions/installs.d.ts +1 -3
  122. package/dist/extensions/instance.d.ts +0 -2
  123. package/dist/extensions/instance.js +0 -3
  124. package/dist/extensions/org-config.d.ts +4 -4
  125. package/dist/extensions/org-config.js +13 -22
  126. package/dist/extensions/package.d.ts +6 -6
  127. package/dist/extensions/package.js +3 -7
  128. package/dist/extensions/permission-view.d.ts +2 -4
  129. package/dist/extensions/plugin-items.d.ts +21 -1
  130. package/dist/extensions/plugin-items.js +28 -0
  131. package/dist/extensions/sync.js +5 -10
  132. package/dist/extensions/unavailable.js +0 -1
  133. package/dist/http/api.module.js +2 -1
  134. package/dist/identity/audit.d.ts +0 -12
  135. package/dist/identity/audit.js +0 -27
  136. package/dist/identity/auth.controller.js +5 -9
  137. package/dist/identity/cookies.d.ts +4 -9
  138. package/dist/identity/cookies.js +8 -32
  139. package/dist/identity/initial-passwords.d.ts +1 -1
  140. package/dist/identity/initial-passwords.js +1 -2
  141. package/dist/identity/sessions.d.ts +0 -6
  142. package/dist/identity/sessions.js +0 -18
  143. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  144. package/dist/inbox/platform-inbox.service.js +56 -6
  145. package/dist/index.d.ts +4 -2
  146. package/dist/index.js +4 -2
  147. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  148. package/dist/infra/cli/master-key-rewrap.js +24 -0
  149. package/dist/infra/config/kernel-config.service.js +0 -17
  150. package/dist/infra/health/health.controller.js +8 -0
  151. package/dist/infra/health/process-fault.d.ts +16 -0
  152. package/dist/infra/health/process-fault.js +49 -0
  153. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  154. package/dist/infra/lifecycle/process-guards.js +12 -3
  155. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  156. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  157. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  158. package/dist/infra/outbox/outbox.service.js +22 -26
  159. package/dist/infra/outbox/registry.d.ts +15 -7
  160. package/dist/infra/outbox/registry.js +39 -23
  161. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  162. package/dist/models/enablement.d.ts +5 -6
  163. package/dist/models/enablement.js +7 -14
  164. package/dist/orgs/orgs.module.d.ts +2 -2
  165. package/dist/orgs/orgs.module.js +2 -2
  166. package/dist/orgs/settings.controller.d.ts +3 -2
  167. package/dist/orgs/settings.service.d.ts +59 -14
  168. package/dist/orgs/settings.service.js +102 -20
  169. package/dist/overrides.d.ts +3 -7
  170. package/dist/overrides.js +2 -4
  171. package/dist/packages/tgz.d.ts +0 -2
  172. package/dist/packages/tgz.js +0 -2
  173. package/dist/platform/exclusions.js +0 -5
  174. package/dist/platform/operation.js +1 -1
  175. package/dist/platform/ops/admin.ops.d.ts +2 -2
  176. package/dist/platform/ops/admin.ops.js +9 -6
  177. package/dist/platform/ops/agents.ops.js +1 -1
  178. package/dist/platform/ops/connectors.ops.js +46 -1
  179. package/dist/platform/ops/evals.ops.js +1 -64
  180. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  181. package/dist/platform/ops/inbox.ops.js +16 -3
  182. package/dist/platform/ops/org-plugins.ops.js +1 -1
  183. package/dist/platform/ops/orgs.ops.d.ts +5 -3
  184. package/dist/platform/ops/orgs.ops.js +19 -4
  185. package/dist/platform/ops/outbox.ops.js +5 -5
  186. package/dist/roles/worker-role.d.ts +2 -3
  187. package/dist/roles/worker-role.js +3 -13
  188. package/dist/runtime/context/build.d.ts +56 -18
  189. package/dist/runtime/context/build.js +143 -50
  190. package/dist/runtime/context/compaction.d.ts +1 -3
  191. package/dist/runtime/context/compaction.js +42 -8
  192. package/dist/runtime/context/run-context.js +1 -2
  193. package/dist/runtime/context/skills.d.ts +27 -56
  194. package/dist/runtime/context/skills.js +42 -114
  195. package/dist/runtime/context/tool-changes.d.ts +3 -3
  196. package/dist/runtime/context/tool-changes.js +6 -16
  197. package/dist/runtime/hook-calls.d.ts +6 -6
  198. package/dist/runtime/hook-calls.js +7 -7
  199. package/dist/runtime/langgraph-loop.js +1 -0
  200. package/dist/runtime/maintenance.d.ts +3 -11
  201. package/dist/runtime/maintenance.js +5 -20
  202. package/dist/runtime/model-call.d.ts +5 -0
  203. package/dist/runtime/model-call.js +48 -36
  204. package/dist/runtime/providers.d.ts +33 -35
  205. package/dist/runtime/providers.js +64 -109
  206. package/dist/runtime/run-context.service.js +7 -22
  207. package/dist/runtime/run-deletion.d.ts +6 -0
  208. package/dist/runtime/run-deletion.js +39 -16
  209. package/dist/runtime/run-execution.js +4 -3
  210. package/dist/runtime/run-finish.js +2 -1
  211. package/dist/runtime/run-liveness.d.ts +11 -0
  212. package/dist/runtime/run-liveness.js +19 -0
  213. package/dist/runtime/run-orphan-check.job.js +2 -1
  214. package/dist/runtime/run-queue.js +8 -16
  215. package/dist/runtime/run-worker.d.ts +2 -2
  216. package/dist/runtime/run-worker.js +8 -6
  217. package/dist/runtime/subagents/definition.d.ts +16 -20
  218. package/dist/runtime/subagents/definition.js +27 -27
  219. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  220. package/dist/runtime/subagents/dispatch.js +17 -3
  221. package/dist/runtime/subagents/org-agents.js +1 -2
  222. package/dist/runtime/subagents/preamble.d.ts +3 -2
  223. package/dist/runtime/subagents/preamble.js +3 -2
  224. package/dist/runtime/subagents/render.d.ts +1 -2
  225. package/dist/runtime/subagents/render.js +1 -2
  226. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  227. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  228. package/dist/runtime/subagents/template-skills.js +76 -0
  229. package/dist/schedules/effective-settings.d.ts +9 -3
  230. package/dist/schedules/effective-settings.js +5 -4
  231. package/dist/schedules/fire.js +11 -0
  232. package/dist/schedules/scheduled-tasks.service.js +5 -0
  233. package/dist/schedules/unattended.d.ts +2 -0
  234. package/dist/schedules/unattended.js +6 -1
  235. package/dist/skills/agent-skills.service.js +1 -2
  236. package/dist/skills/catalog.d.ts +1 -3
  237. package/dist/skills/catalog.js +1 -3
  238. package/dist/skills/conversation-catalog.d.ts +1 -2
  239. package/dist/skills/conversation-catalog.js +1 -2
  240. package/dist/skills/usable.js +2 -3
  241. package/dist/storage/storage.service.js +9 -1
  242. package/dist/tools/approvals.service.js +2 -4
  243. package/dist/tools/builtin-names.d.ts +2 -9
  244. package/dist/tools/builtin-names.js +4 -13
  245. package/dist/tools/builtins/sandbox/bash.js +3 -3
  246. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  247. package/dist/tools/builtins/sandbox/common.js +8 -115
  248. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  249. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  250. package/dist/tools/builtins/sandbox/glob.js +1 -3
  251. package/dist/tools/builtins/sandbox/grep.js +3 -5
  252. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  253. package/dist/tools/builtins/sandbox/index.js +10 -5
  254. package/dist/tools/builtins/sandbox/read.js +3 -2
  255. package/dist/tools/builtins/tool-search.d.ts +4 -7
  256. package/dist/tools/builtins/tool-search.js +6 -10
  257. package/dist/tools/connector-account-policies.d.ts +30 -3
  258. package/dist/tools/connector-account-policies.js +54 -7
  259. package/dist/tools/connectors.controller.d.ts +24 -11
  260. package/dist/tools/connectors.controller.js +35 -6
  261. package/dist/tools/connectors.schemas.d.ts +14 -1
  262. package/dist/tools/connectors.schemas.js +14 -2
  263. package/dist/tools/connectors.service.d.ts +22 -0
  264. package/dist/tools/connectors.service.js +56 -0
  265. package/dist/tools/drift.d.ts +1 -1
  266. package/dist/tools/drift.js +1 -1
  267. package/dist/tools/git-push-policy.d.ts +4 -1
  268. package/dist/tools/git-push-policy.js +3 -1
  269. package/dist/tools/info.d.ts +1 -7
  270. package/dist/tools/info.js +5 -18
  271. package/dist/tools/job-ids.d.ts +0 -4
  272. package/dist/tools/job-ids.js +1 -6
  273. package/dist/tools/pipeline.d.ts +4 -10
  274. package/dist/tools/pipeline.js +16 -62
  275. package/dist/tools/policy.d.ts +6 -2
  276. package/dist/tools/policy.js +14 -12
  277. package/dist/tools/registry.js +1 -5
  278. package/dist/ui/views.d.ts +5 -5
  279. package/dist/ui/views.js +10 -16
  280. package/package.json +3 -3
  281. package/src/migrations/0137_audit_org_idx.sql +5 -0
  282. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  283. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  284. package/src/migrations/0140_retire_history_forms.sql +148 -0
  285. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  286. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  287. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  288. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  289. package/dist/admin/platform-audit.service.d.ts +0 -41
  290. package/dist/conversations/job-ids.d.ts +0 -6
  291. package/dist/conversations/job-ids.js +0 -6
  292. package/dist/extensions/job-ids.d.ts +0 -6
  293. package/dist/extensions/job-ids.js +0 -6
  294. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  295. package/dist/infra/queue/retired-schedulers.js +0 -9
  296. package/dist/orgs/job-ids.d.ts +0 -8
  297. package/dist/orgs/job-ids.js +0 -8
  298. package/dist/runtime/context/legacy-text.d.ts +0 -22
  299. package/dist/runtime/context/legacy-text.js +0 -37
  300. package/dist/runtime/job-ids.d.ts +0 -10
  301. package/dist/runtime/job-ids.js +0 -10
  302. package/dist/runtime/retired-schedulers.d.ts +0 -7
  303. package/dist/runtime/retired-schedulers.js +0 -31
  304. package/dist/storage/job-ids.d.ts +0 -6
  305. package/dist/storage/job-ids.js +0 -6
  306. package/dist/tools/legacy-data.d.ts +0 -34
  307. package/dist/tools/legacy-data.js +0 -76
  308. package/dist/tools/legacy-keys.d.ts +0 -51
  309. package/dist/tools/legacy-keys.js +0 -114
package/bootstrap.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "85aaf6598bee6f27ed9da9836084e2295eb29e03"
6
+ "commit": "05d00a946d26e9e519a258583c2f2468f7b7fcb5"
7
7
  },
8
8
  "plugins": [
9
9
  {
@@ -18,8 +18,8 @@
18
18
  "name": "object-store-s3",
19
19
  "source": "npm",
20
20
  "npm": "@capybara-hq/plugin-object-store-s3",
21
- "version": "0.1.0-rc.9",
22
- "integrity": "sha512-yqW5gM5+4sdY/nJWDyu7ltDLdUm6b4q9+R/yrCLJhMRCI7HQbxeqDWky29EiDjjsJD5BaiQ6N3a5Ua75ANll7g==",
21
+ "version": "0.1.0-rc.10",
22
+ "integrity": "sha512-uzpvEixkXcngBr33iXSgsupTGG8wLkLTo9JeA134rCeknrUX1IhkfkJKw6L2mwpnefyuBwt9l/vb+eiSZrZXCw==",
23
23
  "required": true
24
24
  },
25
25
  {
@@ -98,8 +98,8 @@
98
98
  "name": "todo",
99
99
  "source": "npm",
100
100
  "npm": "@capybara-hq/plugin-todo",
101
- "version": "0.1.0-rc.10",
102
- "integrity": "sha512-9sRVd7MaUsUF5Uk0EDsRqIae492TDEGjOcH5IM+SxTY2NcQCiXVs4ck/N6kRuV65x5LzVcrGLBfyx/Zi+2229w==",
101
+ "version": "0.1.0-rc.11",
102
+ "integrity": "sha512-9vS5wRiX4Rk255T51WWfFDNB3SjVsJx2DNikaZr3yUVnzowHRH+SQ90OHdh7GK4RuFzVZxNaafPaGMgJZ++mLw==",
103
103
  "required": false
104
104
  },
105
105
  {
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Deployment administration: the setup wizard, the platform-level audit log and the admin overview
3
- * with its health read, seven-day usage aggregate and dead outbox rows (its controllers are the api
4
- * role's, `ApiModule`).
2
+ * Deployment administration: the setup wizard, the audit log reader (the platform's and each
3
+ * org's) and the admin overview with its health read, seven-day usage aggregate and dead outbox
4
+ * rows (its controllers are the api role's, `ApiModule`).
5
5
  */
6
6
  export declare class AdminModule {
7
7
  }
@@ -18,17 +18,17 @@ import { OrgsModule } from "../orgs/orgs.module.js";
18
18
  import { ProvidersModule } from "../runtime/providers.js";
19
19
  import { RunJobsModule } from "../runtime/run-jobs.js";
20
20
  import { UsageReportModule } from "../runtime/usage-report.js";
21
+ import { AuditLogService } from "./audit-log.service.js";
21
22
  import { AdminHealthService } from "./health.service.js";
22
23
  import { OutboxDeadService } from "./outbox-dead.service.js";
23
24
  import { AdminOverviewService } from "./overview.service.js";
24
- import { PlatformAuditService } from "./platform-audit.service.js";
25
25
  import { SetupService } from "./setup.service.js";
26
26
  import { SetupLockModule } from "./setup-lock.js";
27
27
  import { AdminUsageService } from "./usage.service.js";
28
28
  /**
29
- * Deployment administration: the setup wizard, the platform-level audit log and the admin overview
30
- * with its health read, seven-day usage aggregate and dead outbox rows (its controllers are the api
31
- * role's, `ApiModule`).
29
+ * Deployment administration: the setup wizard, the audit log reader (the platform's and each
30
+ * org's) and the admin overview with its health read, seven-day usage aggregate and dead outbox
31
+ * rows (its controllers are the api role's, `ApiModule`).
32
32
  */
33
33
  let AdminModule = class AdminModule {
34
34
  };
@@ -55,7 +55,7 @@ AdminModule = __decorate([
55
55
  ],
56
56
  providers: [
57
57
  SetupService,
58
- PlatformAuditService,
58
+ AuditLogService,
59
59
  AdminOverviewService,
60
60
  AdminHealthService,
61
61
  AdminUsageService,
@@ -63,7 +63,7 @@ AdminModule = __decorate([
63
63
  ],
64
64
  exports: [
65
65
  SetupService,
66
- PlatformAuditService,
66
+ AuditLogService,
67
67
  AdminOverviewService,
68
68
  AdminHealthService,
69
69
  AdminUsageService,
@@ -0,0 +1,51 @@
1
+ import { KernelDb } from "../infra/database/kernel-db.js";
2
+ /**
3
+ * One audit event (admin overview spec §5.2, §9): who, what, on what and when, and two flags.
4
+ * Never the event's `detail` (it may carry config field names, ids or values); a deleted actor
5
+ * account reads as its id with a null name and email; `actor` is null for the kernel itself.
6
+ */
7
+ export interface AuditEvent {
8
+ /** The event id (a bigserial, as a decimal string); also the keyset cursor. */
9
+ id: string;
10
+ at: string;
11
+ actor: {
12
+ id: string;
13
+ name: string | null;
14
+ email: string | null;
15
+ } | null;
16
+ /** Done with a personal access token. */
17
+ viaToken: boolean;
18
+ /** Done through the Platform tool by the actor's own agent (`detail.via === "agent"`). */
19
+ viaAgent: boolean;
20
+ /** The action. */
21
+ action: string;
22
+ target: string | null;
23
+ }
24
+ /** A page of {@link AuditEvent}s; `next` is the `after` of the next page, null at the end. */
25
+ export interface AuditPage {
26
+ events: AuditEvent[];
27
+ next: string | null;
28
+ }
29
+ /** Whose events: the platform's (`org_id IS NULL`, decision D3) or one org's. */
30
+ export type AuditScope = {
31
+ platform: true;
32
+ } | {
33
+ orgId: string;
34
+ };
35
+ export interface AuditListQuery {
36
+ after?: string | undefined;
37
+ limit: number;
38
+ /** Only actions starting with this prefix. */
39
+ action?: string | undefined;
40
+ }
41
+ /**
42
+ * Reads the audit log of one scope: the platform's (the admin console's Audit log) or one org's (the
43
+ * org settings' Audit log, and the super admin's view of an org), newest first by id, keyset paged
44
+ * (`audit_events_platform_idx` / `audit_events_org_id_idx`). Read-only and not audited (D5).
45
+ */
46
+ export declare class AuditLogService {
47
+ private readonly kdb;
48
+ constructor(kdb: KernelDb);
49
+ /** `limit` events with an id below `after` (from the newest without it); one extra row tells `next`. */
50
+ list(scope: AuditScope, q: AuditListQuery): Promise<AuditPage>;
51
+ }
@@ -9,19 +9,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
- import { LEGACY_AUDIT_ACTIONS } from "../identity/audit.js";
13
12
  import { KernelDb } from "../infra/database/kernel-db.js";
13
+ /** `prefix` as a LIKE pattern matching the strings that start with it. */
14
+ const likePrefix = (prefix) => `${prefix.replace(/[\\%_]/g, "\\$&")}%`;
14
15
  /**
15
- * Reads the platform-level audit log: events with no org (`org_id IS NULL`, decision D3), newest
16
- * first by id, keyset paged (`audit_events_platform_idx`). Read-only and not audited (D5).
16
+ * Reads the audit log of one scope: the platform's (the admin console's Audit log) or one org's (the
17
+ * org settings' Audit log, and the super admin's view of an org), newest first by id, keyset paged
18
+ * (`audit_events_platform_idx` / `audit_events_org_id_idx`). Read-only and not audited (D5).
17
19
  */
18
- let PlatformAuditService = class PlatformAuditService {
20
+ let AuditLogService = class AuditLogService {
19
21
  kdb;
20
22
  constructor(kdb) {
21
23
  this.kdb = kdb;
22
24
  }
23
25
  /** `limit` events with an id below `after` (from the newest without it); one extra row tells `next`. */
24
- async list(q) {
26
+ async list(scope, q) {
25
27
  let query = this.kdb.db
26
28
  .selectFrom("audit_events as a")
27
29
  .leftJoin("accounts as ac", "ac.id", "a.actor_account_id")
@@ -34,12 +36,18 @@ let PlatformAuditService = class PlatformAuditService {
34
36
  "a.target",
35
37
  "ac.display_name",
36
38
  "ac.email",
37
- // only the one flag the overview shows, never the whole detail (spec §9)
39
+ // only the one flag the log shows, never the whole detail (spec §9)
38
40
  sql `a.detail->>'via'`.as("via"),
39
- ])
40
- .where("a.org_id", "is", null);
41
+ ]);
42
+ query =
43
+ "orgId" in scope
44
+ ? query.where("a.org_id", "=", scope.orgId)
45
+ : query.where("a.org_id", "is", null);
41
46
  if (q.after !== undefined)
42
47
  query = query.where("a.id", "<", q.after);
48
+ if (q.action !== undefined) {
49
+ query = query.where("a.action", "like", likePrefix(q.action));
50
+ }
43
51
  const rows = await query
44
52
  .orderBy("a.id", "desc")
45
53
  .limit(q.limit + 1)
@@ -56,15 +64,15 @@ let PlatformAuditService = class PlatformAuditService {
56
64
  },
57
65
  viaToken: r.actor_token_id !== null,
58
66
  viaAgent: r.via === "agent",
59
- action: LEGACY_AUDIT_ACTIONS[r.action] ?? r.action,
67
+ action: r.action,
60
68
  target: r.target,
61
69
  }));
62
70
  const next = rows.length > q.limit ? (events.at(-1)?.id ?? null) : null;
63
71
  return { events, next };
64
72
  }
65
73
  };
66
- PlatformAuditService = __decorate([
74
+ AuditLogService = __decorate([
67
75
  Injectable(),
68
76
  __param(0, Inject(KernelDb))
69
- ], PlatformAuditService);
70
- export { PlatformAuditService };
77
+ ], AuditLogService);
78
+ export { AuditLogService };
@@ -1,14 +1,26 @@
1
1
  import type { z } from "zod";
2
- import { AuditListQuery } from "./audit.schemas.js";
3
- import { type PlatformAuditPage, PlatformAuditService } from "./platform-audit.service.js";
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";
4
5
  /**
5
6
  * The platform-level audit log (`GET /api/v1/admin/audit`, admin overview spec §5.2, decision D2):
6
- * events with no org, newest first, keyset paged; never an event's `detail`. Super admins only;
7
- * the read itself is not audited (D5).
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).
8
9
  */
9
10
  export declare class AdminAuditController {
10
11
  private readonly audit;
11
- constructor(audit: PlatformAuditService);
12
+ constructor(audit: AuditLogService);
12
13
  /** `next` is the `after` of the next page, null at the end. */
13
- list(q: z.infer<typeof AuditListQuery>): Promise<PlatformAuditPage>;
14
+ list(q: z.infer<typeof AuditListQuery>): Promise<AuditPage>;
15
+ }
16
+ /**
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.
20
+ */
21
+ export declare class OrgAuditController {
22
+ private readonly audit;
23
+ constructor(audit: AuditLogService);
24
+ /** `next` is the `after` of the next page, null at the end. */
25
+ list(org: OrgContext, q: z.infer<typeof OrgAuditListQuery>): Promise<AuditPage>;
14
26
  }
@@ -11,14 +11,17 @@ import { Controller, Get, Inject } from "@nestjs/common";
11
11
  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
- import { AuditListQuery } from "./audit.schemas.js";
15
- import { PlatformAuditService } from "./platform-audit.service.js";
14
+ import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
15
+ import { AuditListQuery, OrgAuditListQuery } from "./audit.schemas.js";
16
+ import { AuditLogService } from "./audit-log.service.js";
16
17
  class AuditListQueryDto extends createZodDto(AuditListQuery, "AuditListQuery") {
17
18
  }
19
+ class OrgAuditListQueryDto extends createZodDto(OrgAuditListQuery, "OrgAuditListQuery") {
20
+ }
18
21
  /**
19
22
  * The platform-level audit log (`GET /api/v1/admin/audit`, admin overview spec §5.2, decision D2):
20
- * events with no org, newest first, keyset paged; never an event's `detail`. Super admins only;
21
- * the read itself is not audited (D5).
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).
22
25
  */
23
26
  let AdminAuditController = class AdminAuditController {
24
27
  audit;
@@ -27,7 +30,8 @@ let AdminAuditController = class AdminAuditController {
27
30
  }
28
31
  /** `next` is the `after` of the next page, null at the end. */
29
32
  list(q) {
30
- return this.audit.list(q);
33
+ const { orgId, ...page } = q;
34
+ return this.audit.list(orgId === undefined ? { platform: true } : { orgId }, page);
31
35
  }
32
36
  };
33
37
  __decorate([
@@ -37,6 +41,32 @@ __decorate([
37
41
  AdminAuditController = __decorate([
38
42
  Controller("api/v1/admin/audit"),
39
43
  SuperAdmin(),
40
- __param(0, Inject(PlatformAuditService))
44
+ __param(0, Inject(AuditLogService))
41
45
  ], AdminAuditController);
42
46
  export { AdminAuditController };
47
+ /**
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.
51
+ */
52
+ let OrgAuditController = class OrgAuditController {
53
+ audit;
54
+ constructor(audit) {
55
+ this.audit = audit;
56
+ }
57
+ /** `next` is the `after` of the next page, null at the end. */
58
+ list(org, q) {
59
+ return this.audit.list({ orgId: org.orgId }, q);
60
+ }
61
+ };
62
+ __decorate([
63
+ Get(),
64
+ OrgAction("org.update"),
65
+ __param(0, CurrentOrg()),
66
+ __param(1, ZQuery(OrgAuditListQueryDto))
67
+ ], OrgAuditController.prototype, "list", null);
68
+ OrgAuditController = __decorate([
69
+ Controller("api/v1/orgs/:orgId/audit"),
70
+ __param(0, Inject(AuditLogService))
71
+ ], OrgAuditController);
72
+ export { OrgAuditController };
@@ -1,8 +1,16 @@
1
1
  import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
- /** `GET /api/v1/admin/audit`: keyset paging by event id, newest first (admin overview spec §5.2). */
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
5
  after: z.ZodOptional<z.ZodString>;
6
6
  limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
7
+ action: z.ZodOptional<z.ZodString>;
8
+ orgId: z.ZodOptional<z.ZodString>;
9
+ }, z.core.$strip>;
10
+ /** `GET /api/v1/orgs/:orgId/audit`: the org's own events (org admins). */
11
+ export declare const OrgAuditListQuery: z.ZodObject<{
12
+ after: z.ZodOptional<z.ZodString>;
13
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
14
+ action: z.ZodOptional<z.ZodString>;
7
15
  }, z.core.$strip>;
8
16
  export declare const AUDIT_ROUTES: readonly RouteSchemas[];
@@ -1,8 +1,11 @@
1
1
  import { z } from "zod";
2
2
  /** The largest `bigserial` id; a larger `after` would make PG refuse the comparison. */
3
3
  const MAX_BIGINT = 9223372036854775807n;
4
- /** `GET /api/v1/admin/audit`: keyset paging by event id, newest first (admin overview spec §5.2). */
5
- export const AuditListQuery = z.object({
4
+ /**
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.
7
+ */
8
+ const AuditPageQuery = z.object({
6
9
  after: z
7
10
  .string()
8
11
  .regex(/^\d{1,19}$/, "after must be an event id (digits)")
@@ -11,7 +14,24 @@ export const AuditListQuery = z.object({
11
14
  .optional()
12
15
  .describe("The id of the last event of the previous page (its next); absent: the newest."),
13
16
  limit: z.coerce.number().int().min(1).max(100).default(20),
17
+ action: z
18
+ .string()
19
+ .regex(/^[a-z][a-z0-9_.]{0,63}$/, "action must be an action name or its prefix (a-z 0-9 _ .)")
20
+ .optional()
21
+ .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
26
+ .string()
27
+ .min(1)
28
+ .max(100)
29
+ .optional()
30
+ .describe("Read this org's events instead of the platform's."),
14
31
  });
32
+ /** `GET /api/v1/orgs/:orgId/audit`: the org's own events (org admins). */
33
+ export const OrgAuditListQuery = AuditPageQuery;
15
34
  export const AUDIT_ROUTES = [
16
35
  { route: "GET /api/v1/admin/audit", query: AuditListQuery },
36
+ { route: "GET /api/v1/orgs/:orgId/audit", query: OrgAuditListQuery },
17
37
  ];
@@ -1,7 +1,7 @@
1
1
  import type { z } from "zod";
2
2
  import { type Principal } from "../identity/principal.js";
3
- import { OutboxDeadParams } from "./outbox-dead.schemas.js";
4
- import { type OutboxDeadRow, OutboxDeadService, type OutboxRetryOutcome } from "./outbox-dead.service.js";
3
+ import { OutboxDeadListQuery, OutboxDeadParams } from "./outbox-dead.schemas.js";
4
+ import { type OutboxDeadPage, OutboxDeadService, type OutboxRetryOutcome } from "./outbox-dead.service.js";
5
5
  /**
6
6
  * Dead outbox rows (`/api/v1/admin/outbox/dead*`, transactional outbox spec §3.4): background work
7
7
  * the kernel could not queue after its last attempt. Super admins only; service tokens 403. Retry
@@ -10,10 +10,8 @@ import { type OutboxDeadRow, OutboxDeadService, type OutboxRetryOutcome } from "
10
10
  export declare class OutboxDeadController {
11
11
  private readonly dead;
12
12
  constructor(dead: OutboxDeadService);
13
- /** The dead rows, oldest first (at most 200). */
14
- list(): Promise<{
15
- items: OutboxDeadRow[];
16
- }>;
13
+ /** A page of dead rows, oldest first; `next` is the `after` of the next page, null at the end. */
14
+ list(q: z.infer<typeof OutboxDeadListQuery>): Promise<OutboxDeadPage>;
17
15
  /** Makes the row due again, or discards it when the same job is owed already (`already_owed`). */
18
16
  retry(principal: Principal, { id }: z.infer<typeof OutboxDeadParams>): Promise<{
19
17
  outcome: OutboxRetryOutcome;
@@ -11,9 +11,11 @@ import { Controller, Delete, Get, HttpCode, Inject, Post } from "@nestjs/common"
11
11
  import { CurrentPrincipal, SuperAdmin } from "../identity/principal.js";
12
12
  import { writeActorOf } from "../identity/write-actor.js";
13
13
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
14
- import { ZParam } from "../infra/validation/zod-params.js";
15
- import { OutboxDeadParams } from "./outbox-dead.schemas.js";
14
+ import { ZParam, ZQuery } from "../infra/validation/zod-params.js";
15
+ import { OutboxDeadListQuery, OutboxDeadParams } from "./outbox-dead.schemas.js";
16
16
  import { OutboxDeadService, } from "./outbox-dead.service.js";
17
+ class OutboxDeadListQueryDto extends createZodDto(OutboxDeadListQuery, "OutboxDeadListQuery") {
18
+ }
17
19
  class OutboxDeadParamsDto extends createZodDto(OutboxDeadParams, "OutboxDeadParams") {
18
20
  }
19
21
  /**
@@ -26,9 +28,9 @@ let OutboxDeadController = class OutboxDeadController {
26
28
  constructor(dead) {
27
29
  this.dead = dead;
28
30
  }
29
- /** The dead rows, oldest first (at most 200). */
30
- list() {
31
- return this.dead.list();
31
+ /** A page of dead rows, oldest first; `next` is the `after` of the next page, null at the end. */
32
+ list(q) {
33
+ return this.dead.list(q);
32
34
  }
33
35
  /** Makes the row due again, or discards it when the same job is owed already (`already_owed`). */
34
36
  retry(principal, { id }) {
@@ -40,7 +42,8 @@ let OutboxDeadController = class OutboxDeadController {
40
42
  }
41
43
  };
42
44
  __decorate([
43
- Get()
45
+ Get(),
46
+ __param(0, ZQuery(OutboxDeadListQueryDto))
44
47
  ], OutboxDeadController.prototype, "list", null);
45
48
  __decorate([
46
49
  Post(":id/retry"),
@@ -4,5 +4,21 @@ import type { RouteSchemas } from "../platform/route-schemas.js";
4
4
  export declare const OutboxDeadParams: z.ZodObject<{
5
5
  id: z.ZodString;
6
6
  }, z.core.$strip>;
7
+ /** The most dead rows one page of `GET /api/v1/admin/outbox/dead` returns. */
8
+ export declare const OUTBOX_DEAD_LIST_MAX = 200;
9
+ /** A page cursor: the last row's `dead_at` (as PG prints it, microseconds) and id. */
10
+ export interface OutboxDeadCursor {
11
+ deadAt: string;
12
+ id: string;
13
+ }
14
+ /** The opaque `next` / `after` token of a page ending at `c`. */
15
+ export declare const encodeOutboxDeadCursor: (c: OutboxDeadCursor) => string;
16
+ /** The cursor in `token`, or null when it is not one {@link encodeOutboxDeadCursor} made. */
17
+ export declare function decodeOutboxDeadCursor(token: string): OutboxDeadCursor | null;
18
+ /** `GET /api/v1/admin/outbox/dead`: keyset paging by `(dead_at, id)`, oldest first. */
19
+ export declare const OutboxDeadListQuery: z.ZodObject<{
20
+ after: z.ZodOptional<z.ZodString>;
21
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
22
+ }, z.core.$strip>;
7
23
  /** The super admin's dead outbox rows (transactional outbox spec §3.4). */
8
24
  export declare const OUTBOX_DEAD_ROUTES: readonly RouteSchemas[];
@@ -10,9 +10,33 @@ export const OutboxDeadParams = z.object({
10
10
  .refine((v) => !/^\d{1,19}$/.test(v) || BigInt(v) <= MAX_BIGINT, "id must be an outbox row id")
11
11
  .describe("The dead row's id, as admin.outbox-list-dead lists it."),
12
12
  });
13
+ /** The most dead rows one page of `GET /api/v1/admin/outbox/dead` returns. */
14
+ export const OUTBOX_DEAD_LIST_MAX = 200;
15
+ const CURSOR_TS = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,6})?[+-]\d{2}(:\d{2})?$/;
16
+ /** The opaque `next` / `after` token of a page ending at `c`. */
17
+ export const encodeOutboxDeadCursor = (c) => Buffer.from(`${c.deadAt}|${c.id}`, "utf8").toString("base64url");
18
+ /** The cursor in `token`, or null when it is not one {@link encodeOutboxDeadCursor} made. */
19
+ export function decodeOutboxDeadCursor(token) {
20
+ const [deadAt, id, ...rest] = Buffer.from(token, "base64url").toString("utf8").split("|");
21
+ if (deadAt === undefined || id === undefined || rest.length > 0)
22
+ return null;
23
+ if (!CURSOR_TS.test(deadAt) || !/^\d{1,19}$/.test(id) || BigInt(id) > MAX_BIGINT)
24
+ return null;
25
+ return { deadAt, id };
26
+ }
27
+ /** `GET /api/v1/admin/outbox/dead`: keyset paging by `(dead_at, id)`, oldest first. */
28
+ export const OutboxDeadListQuery = z.object({
29
+ after: z
30
+ .string()
31
+ .max(200)
32
+ .refine((v) => decodeOutboxDeadCursor(v) !== null, "after must be a cursor from a previous page")
33
+ .optional()
34
+ .describe("The `next` of the previous page; absent: the oldest dead rows."),
35
+ limit: z.coerce.number().int().min(1).max(OUTBOX_DEAD_LIST_MAX).default(OUTBOX_DEAD_LIST_MAX),
36
+ });
13
37
  /** The super admin's dead outbox rows (transactional outbox spec §3.4). */
14
38
  export const OUTBOX_DEAD_ROUTES = [
15
- { route: "GET /api/v1/admin/outbox/dead" },
39
+ { route: "GET /api/v1/admin/outbox/dead", query: OutboxDeadListQuery },
16
40
  { route: "POST /api/v1/admin/outbox/dead/:id/retry", params: OutboxDeadParams },
17
41
  { route: "DELETE /api/v1/admin/outbox/dead/:id", params: OutboxDeadParams },
18
42
  ];
@@ -1,9 +1,8 @@
1
+ import { SuperAdminLock } from "../identity/super-admin.js";
1
2
  import type { WriteActor } from "../identity/write-actor.js";
2
3
  import { KernelDb } from "../infra/database/kernel-db.js";
3
4
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
5
  import { type OutboxFastPath } from "../infra/outbox/outbox.service.js";
5
- /** The most dead rows `GET /api/v1/admin/outbox/dead` returns, oldest first. */
6
- export declare const OUTBOX_DEAD_LIST_MAX = 200;
7
6
  /** A dead outbox row as the super admin sees it (transactional outbox spec §3.4). */
8
7
  export interface OutboxDeadRow {
9
8
  id: string;
@@ -17,6 +16,11 @@ export interface OutboxDeadRow {
17
16
  deadAt: string;
18
17
  createdAt: string;
19
18
  }
19
+ /** A page of dead rows; `next` is the `after` of the next page, null at the end. */
20
+ export interface OutboxDeadPage {
21
+ items: OutboxDeadRow[];
22
+ next: string | null;
23
+ }
20
24
  /** Dead rows in all: how many and since when (the overview's `outbox_dead` attention item). */
21
25
  export interface OutboxDeadSummary {
22
26
  count: number;
@@ -38,11 +42,16 @@ export declare class OutboxDeadService {
38
42
  readonly txHost: TransactionHost;
39
43
  private readonly db;
40
44
  private readonly fastPath;
41
- constructor(txHost: TransactionHost, db: KernelDb, fastPath: OutboxFastPath);
42
- /** The dead rows, oldest first, at most {@link OUTBOX_DEAD_LIST_MAX}. */
43
- list(): Promise<{
44
- items: OutboxDeadRow[];
45
- }>;
45
+ private readonly adminLock;
46
+ constructor(txHost: TransactionHost, db: KernelDb, fastPath: OutboxFastPath, adminLock: SuperAdminLock);
47
+ /**
48
+ * `limit` dead rows (at most {@link OUTBOX_DEAD_LIST_MAX}) after the cursor `after`, oldest
49
+ * first by `(dead_at, id)`; one extra row tells `next`. A malformed cursor is a validation error.
50
+ */
51
+ list(q?: {
52
+ after?: string | undefined;
53
+ limit?: number;
54
+ }): Promise<OutboxDeadPage>;
46
55
  /** How many rows are dead, and the oldest one's `dead_at`. */
47
56
  summary(): Promise<OutboxDeadSummary>;
48
57
  /**
@@ -11,13 +11,13 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { ApiError } from "../errors.js";
13
13
  import { audit } from "../identity/audit.js";
14
+ import { SuperAdminLock } from "../identity/super-admin.js";
14
15
  import { afterCommit } from "../infra/database/after-commit.js";
15
16
  import { KernelDb } from "../infra/database/kernel-db.js";
16
17
  import { TransactionHost } from "../infra/database/transaction-host.js";
17
18
  import { Transactional } from "../infra/database/transactional.decorator.js";
18
19
  import { OUTBOX_FAST_PATH } from "../infra/outbox/outbox.service.js";
19
- /** The most dead rows `GET /api/v1/admin/outbox/dead` returns, oldest first. */
20
- export const OUTBOX_DEAD_LIST_MAX = 200;
20
+ import { decodeOutboxDeadCursor, encodeOutboxDeadCursor, OUTBOX_DEAD_LIST_MAX, } from "./outbox-dead.schemas.js";
21
21
  /** The unique index of pending rows (0119): one pending row per (queue, job_id). */
22
22
  const PENDING_UNIQUE = "outbox_job_uniq";
23
23
  const isPendingConflict = (e) => typeof e === "object" &&
@@ -36,14 +36,24 @@ let OutboxDeadService = class OutboxDeadService {
36
36
  txHost;
37
37
  db;
38
38
  fastPath;
39
- constructor(txHost, db, fastPath) {
39
+ adminLock;
40
+ constructor(txHost, db, fastPath, adminLock) {
40
41
  this.txHost = txHost;
41
42
  this.db = db;
42
43
  this.fastPath = fastPath;
44
+ this.adminLock = adminLock;
43
45
  }
44
- /** The dead rows, oldest first, at most {@link OUTBOX_DEAD_LIST_MAX}. */
45
- async list() {
46
- const rows = await this.db.db
46
+ /**
47
+ * `limit` dead rows (at most {@link OUTBOX_DEAD_LIST_MAX}) after the cursor `after`, oldest
48
+ * first by `(dead_at, id)`; one extra row tells `next`. A malformed cursor is a validation error.
49
+ */
50
+ async list(q = {}) {
51
+ const limit = Math.min(q.limit ?? OUTBOX_DEAD_LIST_MAX, OUTBOX_DEAD_LIST_MAX);
52
+ const cursor = q.after === undefined ? null : decodeOutboxDeadCursor(q.after);
53
+ if (q.after !== undefined && cursor === null) {
54
+ throw new ApiError("validation_failed", "after must be a cursor from a previous page");
55
+ }
56
+ let query = this.db.db
47
57
  .selectFrom("outbox")
48
58
  .select([
49
59
  "id",
@@ -55,14 +65,25 @@ let OutboxDeadService = class OutboxDeadService {
55
65
  "last_error",
56
66
  "dead_at",
57
67
  "created_at",
68
+ // PG's own text keeps the microseconds a JS Date would cut
69
+ sql `dead_at::text`.as("dead_at_text"),
58
70
  ])
59
- .where("dead_at", "is not", null)
71
+ .where("dead_at", "is not", null);
72
+ if (cursor !== null) {
73
+ query = query.where(sql `(dead_at, id) > (${cursor.deadAt}::timestamptz, ${cursor.id}::bigint)`);
74
+ }
75
+ const rows = await query
60
76
  .orderBy("dead_at")
61
77
  .orderBy("id")
62
- .limit(OUTBOX_DEAD_LIST_MAX)
78
+ .limit(limit + 1)
63
79
  .execute();
80
+ const page = rows.slice(0, limit);
81
+ const last = page.at(-1);
64
82
  return {
65
- items: rows.map((r) => ({
83
+ next: rows.length > limit && last !== undefined
84
+ ? encodeOutboxDeadCursor({ deadAt: last.dead_at_text, id: String(last.id) })
85
+ : null,
86
+ items: page.map((r) => ({
66
87
  id: String(r.id),
67
88
  queue: r.queue,
68
89
  jobName: r.job_name,
@@ -111,6 +132,7 @@ let OutboxDeadService = class OutboxDeadService {
111
132
  }
112
133
  }
113
134
  async retryOnce(id, actor, detail) {
135
+ await this.adminLock.lockAndAuthorize(actor.accountId);
114
136
  await this.lockRunRetryIn(id);
115
137
  const row = await this.lockDead(id);
116
138
  const owed = await this.db.db
@@ -169,6 +191,7 @@ let OutboxDeadService = class OutboxDeadService {
169
191
  }
170
192
  /** Deletes a dead row: its job is never delivered. `outbox.not_found` (404) when none. */
171
193
  async discard(id, actor, detail = {}) {
194
+ await this.adminLock.lockAndAuthorize(actor.accountId);
172
195
  const row = await this.lockDead(id);
173
196
  await this.db.db.deleteFrom("outbox").where("id", "=", id).execute();
174
197
  await this.audit("outbox.discarded", id, row, actor, detail);
@@ -219,6 +242,7 @@ OutboxDeadService = __decorate([
219
242
  Injectable(),
220
243
  __param(0, Inject(TransactionHost)),
221
244
  __param(1, Inject(KernelDb)),
222
- __param(2, Inject(OUTBOX_FAST_PATH))
245
+ __param(2, Inject(OUTBOX_FAST_PATH)),
246
+ __param(3, Inject(SuperAdminLock))
223
247
  ], OutboxDeadService);
224
248
  export { OutboxDeadService };
@@ -29,10 +29,10 @@ export interface AdminOverviewStats {
29
29
  /**
30
30
  * Why an extension needs a look (spec §5.2), from its status and `configValid`: `config` (missing
31
31
  * or invalid deployment config), `load_failed`, `approval` (permissions wait for confirmation),
32
- * `dependency`, `conflict`, `converging` (replicas disagree, or a migration waits) and
33
- * `legacy_format`. Never the raw replica detail.
32
+ * `dependency`, `conflict` and `converging` (replicas disagree, or a migration waits). Never the
33
+ * raw replica detail.
34
34
  */
35
- export type AttentionExtensionReason = "config" | "load_failed" | "approval" | "dependency" | "conflict" | "converging" | "legacy_format";
35
+ export type AttentionExtensionReason = "config" | "load_failed" | "approval" | "dependency" | "conflict" | "converging";
36
36
  /** What is wrong with a model provider: its model list failed, or it lists no usable chat model. */
37
37
  export type AttentionProviderProblem = "list_failed" | "no_chat_model";
38
38
  /** An attention list a source failed to read (it is then empty, the others intact). */
@@ -33,7 +33,6 @@ export function extensionReason(e) {
33
33
  return "approval";
34
34
  case "dependency":
35
35
  case "conflict":
36
- case "legacy_format":
37
36
  return e.status;
38
37
  case "converging":
39
38
  case "pending_migration":