@flowdular/sdk 0.2.3 → 0.3.0

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 (912) hide show
  1. package/.ai/agents/sandbox/business-manager.md +5 -1
  2. package/.ai/blueprints/author-spec/README.md +1 -1
  3. package/.ai/blueprints/author-spec/spec-requirements.yaml +44 -0
  4. package/.ai/blueprints/author-spec/steps.yaml +5 -5
  5. package/.ai/blueprints/author-spec/templates/module.yaml +99 -3
  6. package/.ai/blueprints/edit-module/gates.yaml +4 -0
  7. package/.ai/blueprints/edit-module/required-files.yaml +9 -0
  8. package/.ai/blueprints/new-module/gates.yaml +4 -0
  9. package/.ai/blueprints/new-module/spec-requirements.yaml +2 -2
  10. package/.ai/blueprints/release/gates.yaml +4 -0
  11. package/.ai/platform-capabilities.md +128 -0
  12. package/.ai/policies/capabilities.yaml +100 -0
  13. package/.ai/policies/path-ownership.yaml +5 -2
  14. package/.ai/policies/task-budgets.yaml +5 -3
  15. package/.ai/references/catalog/module.json +4 -4
  16. package/.ai/references/catalog/package.json +2 -2
  17. package/.ai/references/catalog/spec/module.yaml +5 -3
  18. package/.ai/references/catalog/src/platform.ts +2 -0
  19. package/.ai/references/catalog/src/services/catalog-service.ts +89 -1
  20. package/.ai/references/catalog/src/services/data-classes.ts +47 -0
  21. package/.ai/references/catalog/src/services/database-repository.ts +98 -1
  22. package/.ai/references/catalog/src/services/repository.ts +22 -1
  23. package/.ai/references/catalog/tests/data-classes.test.ts +157 -0
  24. package/.ai/references/catalog.provenance.json +12 -10
  25. package/.ai/skills/README.md +10 -0
  26. package/.ai/skills/agent-tool-design/SKILL.md +1 -2
  27. package/.ai/skills/auth-security-review/SKILL.md +1 -1
  28. package/.ai/skills/business-agent-design/SKILL.md +0 -1
  29. package/.ai/skills/deploy-operate/SKILL.md +114 -0
  30. package/.ai/skills/module-new/SKILL.md +29 -3
  31. package/.ai/skills/module-update/SKILL.md +9 -3
  32. package/.ai/skills/perf-audit/SKILL.md +0 -1
  33. package/.ai/skills/release-eject-pr/SKILL.md +0 -1
  34. package/.ai/skills/spec-interview/SKILL.md +120 -0
  35. package/.ai/skills/test-hardening/SKILL.md +1 -0
  36. package/.ai/skills/ux-design/SKILL.md +34 -3
  37. package/.ai/skills/variables/SKILL.md +0 -2
  38. package/.ai/skills/workflow-development/SKILL.md +0 -1
  39. package/AGENTS.md +4 -0
  40. package/docs/agent-contract.md +2 -2
  41. package/docs/design-system.md +185 -31
  42. package/modules/access/migrations/0001_access_core.down.sql +1 -0
  43. package/modules/access/migrations/0001_access_core.up.sql +28 -0
  44. package/modules/access/migrations/README.md +3 -0
  45. package/modules/access/module.json +33 -0
  46. package/modules/access/package.json +43 -0
  47. package/modules/access/spec/module.yaml +225 -0
  48. package/modules/access/src/acl/permissions.ts +6 -0
  49. package/modules/access/src/api/endpoints.ts +244 -0
  50. package/modules/access/src/client/ActivityView.tsrx +245 -0
  51. package/modules/access/src/client/AttestationsView.tsrx +176 -0
  52. package/modules/access/src/client/ReviewView.tsrx +586 -0
  53. package/modules/access/src/client/api.ts +132 -0
  54. package/modules/access/src/client/contribution.tsrx +41 -0
  55. package/modules/access/src/client/index.ts +41 -0
  56. package/modules/access/src/client/navigation.ts +57 -0
  57. package/modules/access/src/client/presentation.ts +69 -0
  58. package/modules/access/src/client/state.ts +72 -0
  59. package/modules/access/src/domain/types.ts +189 -0
  60. package/modules/access/src/index.ts +38 -0
  61. package/modules/access/src/platform.ts +60 -0
  62. package/modules/access/src/server/index.ts +42 -0
  63. package/modules/access/src/server/runtime.ts +105 -0
  64. package/modules/access/src/services/access-service.ts +298 -0
  65. package/modules/access/src/services/audit-window.ts +78 -0
  66. package/modules/access/src/services/auth-directory.ts +72 -0
  67. package/modules/access/src/services/changes.ts +91 -0
  68. package/modules/access/src/services/data-classes.ts +28 -0
  69. package/modules/access/src/services/database-repository.ts +185 -0
  70. package/modules/access/src/services/directory.ts +102 -0
  71. package/modules/access/src/services/index.ts +33 -0
  72. package/modules/access/src/services/list-exports.ts +150 -0
  73. package/modules/access/src/services/migration.ts +54 -0
  74. package/modules/access/src/services/repository.ts +30 -0
  75. package/modules/access/src/services/review.ts +178 -0
  76. package/modules/access/translations/en.json +155 -0
  77. package/modules/access/translations/pl.json +155 -0
  78. package/modules/agents/migrations/0022_credential_rotation_inventory.down.sql +2 -0
  79. package/modules/agents/migrations/0022_credential_rotation_inventory.up.sql +7 -0
  80. package/modules/agents/migrations/0023_agents_retention_indexes.down.sql +2 -0
  81. package/modules/agents/migrations/0023_agents_retention_indexes.up.sql +9 -0
  82. package/modules/agents/migrations/0024_agent_meter_refusals.down.sql +3 -0
  83. package/modules/agents/migrations/0024_agent_meter_refusals.up.sql +22 -0
  84. package/modules/agents/migrations/0025_agent_list_indexes.down.sql +3 -0
  85. package/modules/agents/migrations/0025_agent_list_indexes.up.sql +11 -0
  86. package/modules/agents/module.json +30 -4
  87. package/modules/agents/package.json +3 -2
  88. package/modules/agents/spec/module.yaml +63 -5
  89. package/modules/agents/src/api/endpoints.ts +291 -33
  90. package/modules/agents/src/cli/commands.json +11 -0
  91. package/modules/agents/src/cli/index.ts +45 -0
  92. package/modules/agents/src/client/AgentDashboardWidget.tsrx +19 -11
  93. package/modules/agents/src/client/AgentDefinitionList.tsrx +53 -10
  94. package/modules/agents/src/client/AgentPlaygroundView.tsrx +4 -4
  95. package/modules/agents/src/client/AgentProceduresView.tsrx +2 -2
  96. package/modules/agents/src/client/AgentRunsView.tsrx +143 -40
  97. package/modules/agents/src/client/AgentsView.tsrx +109 -33
  98. package/modules/agents/src/client/api.ts +99 -21
  99. package/modules/agents/src/client/state.ts +97 -0
  100. package/modules/agents/src/domain/types.ts +44 -4
  101. package/modules/agents/src/platform.ts +42 -0
  102. package/modules/agents/src/server/action-execution.ts +201 -106
  103. package/modules/agents/src/server/runtime.ts +32 -0
  104. package/modules/agents/src/services/agent-service.ts +158 -30
  105. package/modules/agents/src/services/credential-rotation.ts +185 -0
  106. package/modules/agents/src/services/credential-vault.ts +71 -46
  107. package/modules/agents/src/services/data-classes.ts +176 -0
  108. package/modules/agents/src/services/database-repository.ts +393 -101
  109. package/modules/agents/src/services/metering.ts +111 -0
  110. package/modules/agents/src/services/migration.ts +109 -0
  111. package/modules/agents/src/services/module-agent-preflight.ts +17 -9
  112. package/modules/agents/src/services/notifications.ts +98 -0
  113. package/modules/agents/src/services/provider-repository.ts +9 -18
  114. package/modules/agents/src/services/provider-service.ts +1 -9
  115. package/modules/agents/src/services/reports.ts +107 -0
  116. package/modules/agents/src/services/repository.ts +86 -6
  117. package/modules/agents/src/services/usage-service.ts +2 -0
  118. package/modules/agents/src/services/worker.ts +114 -4
  119. package/modules/agents/src/settings.ts +14 -3
  120. package/modules/agents/translations/en.json +14 -4
  121. package/modules/agents/translations/pl.json +14 -4
  122. package/modules/approvals/migrations/0001_approvals_core.down.sql +3 -0
  123. package/modules/approvals/migrations/0001_approvals_core.up.sql +78 -0
  124. package/modules/approvals/migrations/0002_approvals_expiry_routing_role.down.sql +2 -0
  125. package/modules/approvals/migrations/0002_approvals_expiry_routing_role.up.sql +19 -0
  126. package/modules/approvals/migrations/0003_approvals_retention_indexes.down.sql +6 -0
  127. package/modules/approvals/migrations/0003_approvals_retention_indexes.up.sql +14 -0
  128. package/modules/approvals/migrations/0004_approvals_inbox_keyset_indexes.down.sql +5 -0
  129. package/modules/approvals/migrations/0004_approvals_inbox_keyset_indexes.up.sql +12 -0
  130. package/modules/approvals/migrations/README.md +3 -0
  131. package/modules/approvals/module.json +34 -0
  132. package/modules/approvals/package.json +43 -0
  133. package/modules/approvals/spec/module.yaml +318 -0
  134. package/modules/approvals/src/acl/permissions.ts +7 -0
  135. package/modules/approvals/src/api/endpoints.ts +457 -0
  136. package/modules/approvals/src/client/ApprovalRequestDrawer.tsrx +138 -0
  137. package/modules/approvals/src/client/ApprovalsView.tsrx +562 -0
  138. package/modules/approvals/src/client/PendingCountWidget.tsrx +52 -0
  139. package/modules/approvals/src/client/api.ts +203 -0
  140. package/modules/approvals/src/client/approvals.css +51 -0
  141. package/modules/approvals/src/client/contribution.tsrx +44 -0
  142. package/modules/approvals/src/client/index.ts +26 -0
  143. package/modules/approvals/src/client/navigation.ts +39 -0
  144. package/modules/approvals/src/client/pending-count.ts +26 -0
  145. package/modules/approvals/src/client/presentation.ts +52 -0
  146. package/modules/approvals/src/client/state.ts +141 -0
  147. package/modules/approvals/src/domain/capability.ts +95 -0
  148. package/modules/approvals/src/domain/types.ts +154 -0
  149. package/modules/approvals/src/index.ts +52 -0
  150. package/modules/approvals/src/platform.ts +128 -0
  151. package/modules/approvals/src/server/index.ts +42 -0
  152. package/modules/approvals/src/server/runtime.ts +181 -0
  153. package/modules/approvals/src/services/approvals-service.ts +557 -0
  154. package/modules/approvals/src/services/callbacks.ts +75 -0
  155. package/modules/approvals/src/services/data-classes.ts +167 -0
  156. package/modules/approvals/src/services/database-repository.ts +724 -0
  157. package/modules/approvals/src/services/eligibility.ts +121 -0
  158. package/modules/approvals/src/services/expiry-runner.ts +81 -0
  159. package/modules/approvals/src/services/index.ts +31 -0
  160. package/modules/approvals/src/services/migration.ts +222 -0
  161. package/modules/approvals/src/services/notifications.ts +95 -0
  162. package/modules/approvals/src/services/repository.ts +161 -0
  163. package/modules/approvals/src/services/service-error.ts +70 -0
  164. package/modules/approvals/src/settings.ts +102 -0
  165. package/modules/approvals/translations/en.json +104 -0
  166. package/modules/approvals/translations/pl.json +104 -0
  167. package/modules/audit/migrations/0001_audit_core.down.sql +8 -0
  168. package/modules/audit/migrations/0001_audit_core.up.sql +107 -0
  169. package/modules/audit/migrations/0002_audit_sweep_routing_role.down.sql +2 -0
  170. package/modules/audit/migrations/0002_audit_sweep_routing_role.up.sql +21 -0
  171. package/modules/audit/migrations/0003_audit_export_request.down.sql +12 -0
  172. package/modules/audit/migrations/0003_audit_export_request.up.sql +40 -0
  173. package/modules/audit/migrations/0004_audit_hold_seal_erasure.down.sql +17 -0
  174. package/modules/audit/migrations/0004_audit_hold_seal_erasure.up.sql +192 -0
  175. package/modules/audit/migrations/0005_audit_event_format.down.sql +17 -0
  176. package/modules/audit/migrations/0005_audit_event_format.up.sql +60 -0
  177. package/modules/audit/migrations/0006_audit_own_class_walks.down.sql +3 -0
  178. package/modules/audit/migrations/0006_audit_own_class_walks.up.sql +14 -0
  179. package/modules/audit/migrations/README.md +3 -0
  180. package/modules/audit/module.json +32 -0
  181. package/modules/audit/package.json +49 -0
  182. package/modules/audit/spec/module.yaml +809 -0
  183. package/modules/audit/src/acl/permissions.ts +7 -0
  184. package/modules/audit/src/api/endpoints.ts +315 -0
  185. package/modules/audit/src/cli/commands.json +95 -0
  186. package/modules/audit/src/cli/index.ts +658 -0
  187. package/modules/audit/src/client/DataClassesView.tsrx +420 -0
  188. package/modules/audit/src/client/ExportsView.tsrx +256 -0
  189. package/modules/audit/src/client/HoldsView.tsrx +604 -0
  190. package/modules/audit/src/client/SweepsView.tsrx +251 -0
  191. package/modules/audit/src/client/api.ts +185 -0
  192. package/modules/audit/src/client/contribution.tsrx +52 -0
  193. package/modules/audit/src/client/index.ts +23 -0
  194. package/modules/audit/src/client/navigation.ts +74 -0
  195. package/modules/audit/src/client/presentation.ts +105 -0
  196. package/modules/audit/src/client/state.ts +86 -0
  197. package/modules/audit/src/domain/data-classes.ts +16 -0
  198. package/modules/audit/src/domain/types.ts +339 -0
  199. package/modules/audit/src/index.ts +76 -0
  200. package/modules/audit/src/platform.ts +44 -0
  201. package/modules/audit/src/server/index.ts +177 -0
  202. package/modules/audit/src/server/runtime.ts +303 -0
  203. package/modules/audit/src/services/anchor-key.ts +143 -0
  204. package/modules/audit/src/services/anchor-rotation.ts +147 -0
  205. package/modules/audit/src/services/audit-runners.ts +278 -0
  206. package/modules/audit/src/services/backup-guard.ts +95 -0
  207. package/modules/audit/src/services/database-repository.ts +1946 -0
  208. package/modules/audit/src/services/declared-classes.ts +64 -0
  209. package/modules/audit/src/services/erasure-port.ts +126 -0
  210. package/modules/audit/src/services/erasure-service.ts +770 -0
  211. package/modules/audit/src/services/export-directory.ts +106 -0
  212. package/modules/audit/src/services/export-service.ts +714 -0
  213. package/modules/audit/src/services/hold-service.ts +295 -0
  214. package/modules/audit/src/services/index.ts +17 -0
  215. package/modules/audit/src/services/migration.ts +658 -0
  216. package/modules/audit/src/services/own-classes.ts +318 -0
  217. package/modules/audit/src/services/platform-version.ts +23 -0
  218. package/modules/audit/src/services/repository.ts +495 -0
  219. package/modules/audit/src/services/retention-service.ts +191 -0
  220. package/modules/audit/src/services/seal-service.ts +769 -0
  221. package/modules/audit/src/services/service-error.ts +61 -0
  222. package/modules/audit/src/services/subject-keys.ts +90 -0
  223. package/modules/audit/src/services/sweep-service.ts +298 -0
  224. package/modules/audit/src/services/zip.ts +217 -0
  225. package/modules/audit/src/settings.ts +69 -0
  226. package/modules/audit/translations/en.json +210 -0
  227. package/modules/audit/translations/pl.json +210 -0
  228. package/modules/auth/README.md +77 -29
  229. package/modules/auth/migrations/0016_external_identities.up.sql +16 -0
  230. package/modules/auth/migrations/0017_mfa_key_id.up.sql +8 -0
  231. package/modules/auth/migrations/0018_retire_bundled_module_scopes.up.sql +29 -0
  232. package/modules/auth/migrations/0019_notifications_member_scopes.up.sql +44 -0
  233. package/modules/auth/migrations/0020_identity_providers.up.sql +61 -0
  234. package/modules/auth/migrations/0021_membership_status.up.sql +19 -0
  235. package/modules/auth/migrations/0022_auth_provider_scopes.up.sql +45 -0
  236. package/modules/auth/migrations/0023_enterprise_module_scopes.down.sql +19 -0
  237. package/modules/auth/migrations/0023_enterprise_module_scopes.up.sql +71 -0
  238. package/modules/auth/migrations/0024_approvals_member_scopes.down.sql +22 -0
  239. package/modules/auth/migrations/0024_approvals_member_scopes.up.sql +48 -0
  240. package/modules/auth/migrations/0025_audit_holds_owner_scope.down.sql +21 -0
  241. package/modules/auth/migrations/0025_audit_holds_owner_scope.up.sql +47 -0
  242. package/modules/auth/migrations/0026_auth_export_keyset_indexes.down.sql +6 -0
  243. package/modules/auth/migrations/0026_auth_export_keyset_indexes.up.sql +15 -0
  244. package/modules/auth/migrations/0027_workflow_automation_profile_scopes.down.sql +34 -0
  245. package/modules/auth/migrations/0027_workflow_automation_profile_scopes.up.sql +72 -0
  246. package/modules/auth/migrations/0028_auth_member_search_prefix_indexes.down.sql +6 -0
  247. package/modules/auth/migrations/0028_auth_member_search_prefix_indexes.up.sql +21 -0
  248. package/modules/auth/migrations/0029_reports_exports_access_scopes.down.sql +22 -0
  249. package/modules/auth/migrations/0029_reports_exports_access_scopes.up.sql +56 -0
  250. package/modules/auth/migrations/0030_auth_membership_keyset_index.down.sql +4 -0
  251. package/modules/auth/migrations/0030_auth_membership_keyset_index.up.sql +10 -0
  252. package/modules/auth/migrations/0031_membership_scope_backfills_under_rls.down.sql +4 -0
  253. package/modules/auth/migrations/0031_membership_scope_backfills_under_rls.up.sql +31 -0
  254. package/modules/auth/migrations/0032_audit_actor_service.down.sql +9 -0
  255. package/modules/auth/migrations/0032_audit_actor_service.up.sql +10 -0
  256. package/modules/auth/migrations/0033_auth_account_keyset_indexes.down.sql +5 -0
  257. package/modules/auth/migrations/0033_auth_account_keyset_indexes.up.sql +23 -0
  258. package/modules/auth/module.json +3 -3
  259. package/modules/auth/package.json +3 -2
  260. package/modules/auth/spec/module.yaml +372 -3
  261. package/modules/auth/src/acl/scopes.ts +50 -6
  262. package/modules/auth/src/cli/commands.json +11 -0
  263. package/modules/auth/src/cli/greenfield.ts +2 -2
  264. package/modules/auth/src/cli/index.ts +14 -0
  265. package/modules/auth/src/cli/secrets.ts +114 -0
  266. package/modules/auth/src/client/AuthenticationCore.tsrx +61 -8
  267. package/modules/auth/src/client/api.ts +72 -6
  268. package/modules/auth/src/client/contribution.tsrx +23 -0
  269. package/modules/auth/src/client/index.ts +6 -0
  270. package/modules/auth/src/client/providers/IdentityProviderForm.tsrx +191 -0
  271. package/modules/auth/src/client/providers/IdentityProvidersView.tsrx +358 -0
  272. package/modules/auth/src/client/providers/api.ts +128 -0
  273. package/modules/auth/src/client/providers/provider-columns.tsrx +60 -0
  274. package/modules/auth/src/client/providers/state.ts +35 -0
  275. package/modules/auth/src/client/security/SecurityView.tsrx +9 -1
  276. package/modules/auth/src/client/state.ts +15 -1
  277. package/modules/auth/src/domain/types.ts +55 -0
  278. package/modules/auth/src/index.ts +11 -1
  279. package/modules/auth/src/middleware/authentication.ts +4 -0
  280. package/modules/auth/src/server/endpoints.ts +467 -171
  281. package/modules/auth/src/server/http.ts +3 -2
  282. package/modules/auth/src/server/index.ts +22 -1
  283. package/modules/auth/src/server/membership-endpoints.ts +62 -0
  284. package/modules/auth/src/server/mfa-enforcement.ts +156 -0
  285. package/modules/auth/src/server/oidc.ts +389 -0
  286. package/modules/auth/src/server/provider-endpoints.ts +246 -0
  287. package/modules/auth/src/server/provider-host.ts +77 -0
  288. package/modules/auth/src/server/runtime.ts +231 -55
  289. package/modules/auth/src/services/auth-service-error.ts +7 -2
  290. package/modules/auth/src/services/auth-service.ts +948 -51
  291. package/modules/auth/src/services/data-classes.ts +236 -0
  292. package/modules/auth/src/services/database-repository.ts +853 -71
  293. package/modules/auth/src/services/identity-provider-service.ts +571 -0
  294. package/modules/auth/src/services/mail-delivery.ts +16 -16
  295. package/modules/auth/src/services/mail-message.ts +54 -0
  296. package/modules/auth/src/services/mail-port.ts +24 -0
  297. package/modules/auth/src/services/mail-smtp.ts +85 -0
  298. package/modules/auth/src/services/mfa-rotation.ts +144 -0
  299. package/modules/auth/src/services/migration.ts +810 -0
  300. package/modules/auth/src/services/password.ts +14 -0
  301. package/modules/auth/src/services/provider-secret-rotation.ts +169 -0
  302. package/modules/auth/src/services/provider-secrets.ts +136 -0
  303. package/modules/auth/src/services/repository.ts +321 -5
  304. package/modules/auth/src/services/session-sweep-runner.ts +73 -0
  305. package/modules/auth/src/services/settings-store.ts +10 -83
  306. package/modules/auth/src/services/totp.ts +88 -62
  307. package/modules/auth/src/services/validation.ts +194 -7
  308. package/modules/auth/src/settings.ts +18 -0
  309. package/modules/auth/translations/en.json +84 -1
  310. package/modules/auth/translations/pl.json +84 -1
  311. package/modules/automations/migrations/0005_secret_rotation_inventory.down.sql +1 -0
  312. package/modules/automations/migrations/0005_secret_rotation_inventory.up.sql +6 -0
  313. package/modules/automations/migrations/0006_automations_list_sort_indexes.down.sql +4 -0
  314. package/modules/automations/migrations/0006_automations_list_sort_indexes.up.sql +11 -0
  315. package/modules/automations/module.json +24 -6
  316. package/modules/automations/package.json +5 -2
  317. package/modules/automations/spec/module.yaml +81 -7
  318. package/modules/automations/src/api/endpoints.ts +202 -28
  319. package/modules/automations/src/cli/commands.json +17 -0
  320. package/modules/automations/src/cli/index.ts +114 -0
  321. package/modules/automations/src/client/AutomationScheduleForm.tsrx +77 -19
  322. package/modules/automations/src/client/AutomationSchedulesView.tsrx +144 -40
  323. package/modules/automations/src/client/AutomationTriggersView.tsrx +131 -32
  324. package/modules/automations/src/client/api.ts +62 -19
  325. package/modules/automations/src/client/presentation.ts +20 -2
  326. package/modules/automations/src/client/state.ts +84 -0
  327. package/modules/automations/src/domain/cadence.ts +99 -3
  328. package/modules/automations/src/domain/cron.ts +366 -0
  329. package/modules/automations/src/domain/time-zone.ts +61 -0
  330. package/modules/automations/src/platform.ts +38 -4
  331. package/modules/automations/src/server/index.ts +11 -0
  332. package/modules/automations/src/server/runtime.ts +46 -22
  333. package/modules/{automations-workflows-integration/src/server/adapter.ts → automations/src/server/workflow-target.ts} +13 -14
  334. package/modules/{automations-workflows-integration/src/server/tools.ts → automations/src/server/workflow-tools.ts} +0 -0
  335. package/modules/automations/src/services/data-classes.ts +62 -0
  336. package/modules/automations/src/services/database-repository.ts +152 -38
  337. package/modules/automations/src/services/migration.ts +119 -9
  338. package/modules/automations/src/services/repository.ts +52 -1
  339. package/modules/automations/src/services/schedule-runner.ts +84 -0
  340. package/modules/automations/src/services/schedule-service.ts +152 -26
  341. package/modules/automations/src/services/secret-rotation.ts +176 -0
  342. package/modules/automations/src/services/secret-vault.ts +68 -41
  343. package/modules/automations/src/services/trigger-service.ts +13 -10
  344. package/modules/automations/translations/en.json +15 -2
  345. package/modules/automations/translations/pl.json +15 -2
  346. package/modules/connectors/migrations/0001_connectors_core.down.sql +3 -0
  347. package/modules/connectors/migrations/0001_connectors_core.up.sql +72 -0
  348. package/modules/connectors/migrations/0002_connectors_call_keys.down.sql +3 -0
  349. package/modules/connectors/migrations/0002_connectors_call_keys.up.sql +18 -0
  350. package/modules/connectors/migrations/README.md +3 -0
  351. package/modules/connectors/module.json +28 -0
  352. package/modules/{automations-workflows-integration → connectors}/package.json +27 -26
  353. package/modules/connectors/spec/module.yaml +447 -0
  354. package/modules/connectors/src/acl/permissions.ts +6 -0
  355. package/modules/connectors/src/agent/tools.ts +180 -0
  356. package/modules/connectors/src/api/endpoints.ts +572 -0
  357. package/modules/connectors/src/client/ConnectorCallsView.tsrx +358 -0
  358. package/modules/connectors/src/client/ConnectorForm.tsrx +424 -0
  359. package/modules/connectors/src/client/ConnectorsView.tsrx +711 -0
  360. package/modules/connectors/src/client/api.ts +281 -0
  361. package/modules/connectors/src/client/consent.ts +48 -0
  362. package/modules/connectors/src/client/contribution.tsrx +37 -0
  363. package/modules/connectors/src/client/index.ts +22 -0
  364. package/modules/connectors/src/client/navigation.ts +42 -0
  365. package/modules/connectors/src/client/presentation.ts +38 -0
  366. package/modules/connectors/src/client/state.ts +175 -0
  367. package/modules/connectors/src/domain/calls.ts +70 -0
  368. package/modules/connectors/src/domain/definitions.ts +190 -0
  369. package/modules/connectors/src/domain/http-json.ts +68 -0
  370. package/modules/connectors/src/domain/types.ts +185 -0
  371. package/modules/connectors/src/index.ts +64 -0
  372. package/modules/connectors/src/platform.ts +56 -0
  373. package/modules/connectors/src/server/index.ts +66 -0
  374. package/modules/connectors/src/server/runtime.ts +163 -0
  375. package/modules/connectors/src/services/call-service.ts +903 -0
  376. package/modules/connectors/src/services/connectors-service.ts +653 -0
  377. package/modules/connectors/src/services/credential-vault.ts +188 -0
  378. package/modules/connectors/src/services/data-classes.ts +158 -0
  379. package/modules/connectors/src/services/database-repository.ts +897 -0
  380. package/modules/connectors/src/services/egress.ts +261 -0
  381. package/modules/connectors/src/services/index.ts +19 -0
  382. package/modules/connectors/src/services/migration.ts +166 -0
  383. package/modules/connectors/src/services/repository.ts +175 -0
  384. package/modules/connectors/src/services/service-error.ts +46 -0
  385. package/modules/connectors/src/settings.ts +69 -0
  386. package/modules/connectors/translations/en.json +191 -0
  387. package/modules/connectors/translations/pl.json +191 -0
  388. package/modules/directory/migrations/0001_directory_core.down.sql +5 -0
  389. package/modules/directory/migrations/0001_directory_core.up.sql +111 -0
  390. package/modules/directory/migrations/README.md +3 -0
  391. package/modules/directory/module.json +27 -0
  392. package/modules/directory/package.json +46 -0
  393. package/modules/directory/spec/module.yaml +351 -0
  394. package/modules/directory/src/acl/permissions.ts +7 -0
  395. package/modules/directory/src/api/endpoints.ts +478 -0
  396. package/modules/directory/src/api/scim-endpoints.ts +516 -0
  397. package/modules/directory/src/client/GroupMappingsView.tsrx +430 -0
  398. package/modules/directory/src/client/ProvisioningLogView.tsrx +248 -0
  399. package/modules/directory/src/client/ScimTokensView.tsrx +587 -0
  400. package/modules/directory/src/client/api.ts +222 -0
  401. package/modules/directory/src/client/contribution.tsrx +46 -0
  402. package/modules/directory/src/client/index.ts +22 -0
  403. package/modules/directory/src/client/navigation.ts +57 -0
  404. package/modules/directory/src/client/presentation.ts +143 -0
  405. package/modules/directory/src/client/state.ts +173 -0
  406. package/modules/directory/src/domain/scim.ts +346 -0
  407. package/modules/directory/src/domain/types.ts +166 -0
  408. package/modules/directory/src/index.ts +44 -0
  409. package/modules/directory/src/platform.ts +43 -0
  410. package/modules/directory/src/server/index.ts +17 -0
  411. package/modules/directory/src/server/runtime.ts +124 -0
  412. package/modules/directory/src/services/auth-port.ts +127 -0
  413. package/modules/directory/src/services/data-classes.ts +41 -0
  414. package/modules/directory/src/services/database-repository.ts +1067 -0
  415. package/modules/directory/src/services/directory-service.ts +311 -0
  416. package/modules/directory/src/services/index.ts +43 -0
  417. package/modules/directory/src/services/migration.ts +146 -0
  418. package/modules/directory/src/services/provisioning-service.ts +1420 -0
  419. package/modules/directory/src/services/rate-limiter.ts +103 -0
  420. package/modules/directory/src/services/repository.ts +208 -0
  421. package/modules/directory/src/services/service-error.ts +42 -0
  422. package/modules/directory/src/services/token-service.ts +215 -0
  423. package/modules/directory/src/settings.ts +86 -0
  424. package/modules/directory/translations/en.json +185 -0
  425. package/modules/directory/translations/pl.json +185 -0
  426. package/modules/documents/migrations/0001_documents_core.down.sql +1 -0
  427. package/modules/documents/migrations/0001_documents_core.up.sql +35 -0
  428. package/modules/documents/migrations/0002_documents_files_page.down.sql +1 -0
  429. package/modules/documents/migrations/0002_documents_files_page.up.sql +6 -0
  430. package/modules/documents/migrations/README.md +3 -0
  431. package/modules/documents/module.json +28 -0
  432. package/modules/documents/package.json +49 -0
  433. package/modules/documents/spec/module.yaml +247 -0
  434. package/modules/documents/src/acl/permissions.ts +6 -0
  435. package/modules/documents/src/api/endpoints.ts +401 -0
  436. package/modules/documents/src/client/DocumentUploader.tsrx +148 -0
  437. package/modules/documents/src/client/DocumentsView.tsrx +540 -0
  438. package/modules/documents/src/client/api.ts +209 -0
  439. package/modules/documents/src/client/contribution.tsrx +29 -0
  440. package/modules/documents/src/client/download.ts +70 -0
  441. package/modules/documents/src/client/index.ts +22 -0
  442. package/modules/documents/src/client/navigation.ts +25 -0
  443. package/modules/documents/src/client/presentation.ts +110 -0
  444. package/modules/documents/src/client/state.ts +117 -0
  445. package/modules/documents/src/domain/attachments.ts +84 -0
  446. package/modules/documents/src/domain/types.ts +80 -0
  447. package/modules/documents/src/index.ts +46 -0
  448. package/modules/documents/src/platform.ts +61 -0
  449. package/modules/documents/src/server/index.ts +30 -0
  450. package/modules/documents/src/server/runtime.ts +107 -0
  451. package/modules/documents/src/services/attachments.ts +39 -0
  452. package/modules/documents/src/services/data-classes.ts +25 -0
  453. package/modules/documents/src/services/database-repository.ts +259 -0
  454. package/modules/documents/src/services/documents-service.ts +586 -0
  455. package/modules/documents/src/services/index.ts +18 -0
  456. package/modules/documents/src/services/migration.ts +82 -0
  457. package/modules/documents/src/services/repository.ts +48 -0
  458. package/modules/documents/src/settings.ts +107 -0
  459. package/modules/documents/translations/en.json +111 -0
  460. package/modules/documents/translations/pl.json +111 -0
  461. package/modules/exports/migrations/0001_exports_core.down.sql +2 -0
  462. package/modules/exports/migrations/0001_exports_core.up.sql +28 -0
  463. package/modules/exports/migrations/0002_exports_job_routing_role.down.sql +4 -0
  464. package/modules/exports/migrations/0002_exports_job_routing_role.up.sql +21 -0
  465. package/modules/exports/migrations/README.md +3 -0
  466. package/modules/exports/module.json +28 -0
  467. package/modules/exports/package.json +44 -0
  468. package/modules/exports/spec/module.yaml +229 -0
  469. package/modules/exports/src/acl/permissions.ts +6 -0
  470. package/modules/exports/src/api/endpoints.ts +211 -0
  471. package/modules/exports/src/client/ExportsView.tsrx +327 -0
  472. package/modules/exports/src/client/api.ts +133 -0
  473. package/modules/exports/src/client/contribution.tsrx +31 -0
  474. package/modules/exports/src/client/index.ts +20 -0
  475. package/modules/exports/src/client/navigation.ts +25 -0
  476. package/modules/exports/src/client/presentation.ts +53 -0
  477. package/modules/exports/src/client/state.ts +56 -0
  478. package/modules/exports/src/domain/lists.ts +29 -0
  479. package/modules/exports/src/domain/types.ts +120 -0
  480. package/modules/exports/src/index.ts +41 -0
  481. package/modules/exports/src/platform.ts +80 -0
  482. package/modules/exports/src/server/index.ts +51 -0
  483. package/modules/exports/src/server/runtime.ts +160 -0
  484. package/modules/exports/src/services/data-classes.ts +56 -0
  485. package/modules/exports/src/services/database-repository.ts +405 -0
  486. package/modules/exports/src/services/export-runner.ts +123 -0
  487. package/modules/exports/src/services/export-service.ts +356 -0
  488. package/modules/exports/src/services/index.ts +6 -0
  489. package/modules/exports/src/services/list-registry.ts +105 -0
  490. package/modules/exports/src/services/migration.ts +89 -0
  491. package/modules/exports/src/services/repository.ts +97 -0
  492. package/modules/exports/src/settings.ts +70 -0
  493. package/modules/exports/translations/en.json +69 -0
  494. package/modules/exports/translations/pl.json +69 -0
  495. package/modules/import/migrations/0001_import_core.down.sql +6 -0
  496. package/modules/import/migrations/0001_import_core.up.sql +61 -0
  497. package/modules/import/migrations/0002_import_job_routing_role.down.sql +4 -0
  498. package/modules/import/migrations/0002_import_job_routing_role.up.sql +20 -0
  499. package/modules/import/migrations/0003_import_jobs_export_index.down.sql +1 -0
  500. package/modules/import/migrations/0003_import_jobs_export_index.up.sql +7 -0
  501. package/modules/import/migrations/0004_import_jobs_traceparent.down.sql +1 -0
  502. package/modules/import/migrations/0004_import_jobs_traceparent.up.sql +7 -0
  503. package/modules/import/migrations/README.md +3 -0
  504. package/modules/import/module.json +37 -0
  505. package/modules/import/package.json +50 -0
  506. package/modules/import/spec/module.yaml +335 -0
  507. package/modules/import/src/acl/permissions.ts +6 -0
  508. package/modules/import/src/api/endpoints.ts +400 -0
  509. package/modules/import/src/client/ImportJobDrawer.tsrx +229 -0
  510. package/modules/import/src/client/ImportsView.tsrx +455 -0
  511. package/modules/import/src/client/NewImportForm.tsrx +274 -0
  512. package/modules/import/src/client/api.ts +243 -0
  513. package/modules/import/src/client/contribution.tsrx +29 -0
  514. package/modules/import/src/client/index.ts +23 -0
  515. package/modules/import/src/client/navigation.ts +25 -0
  516. package/modules/import/src/client/presentation.ts +59 -0
  517. package/modules/import/src/client/state.ts +43 -0
  518. package/modules/import/src/domain/csv.ts +258 -0
  519. package/modules/import/src/domain/ports.ts +157 -0
  520. package/modules/import/src/domain/types.ts +179 -0
  521. package/modules/import/src/index.ts +58 -0
  522. package/modules/import/src/platform.ts +60 -0
  523. package/modules/import/src/server/index.ts +49 -0
  524. package/modules/import/src/server/runtime.ts +158 -0
  525. package/modules/import/src/services/csv-source.ts +121 -0
  526. package/modules/import/src/services/data-classes.ts +63 -0
  527. package/modules/import/src/services/database-repository.ts +780 -0
  528. package/modules/import/src/services/import-runner.ts +127 -0
  529. package/modules/import/src/services/import-service.ts +872 -0
  530. package/modules/import/src/services/index.ts +6 -0
  531. package/modules/import/src/services/migration.ts +156 -0
  532. package/modules/import/src/services/port-registry.ts +158 -0
  533. package/modules/import/src/services/repository.ts +147 -0
  534. package/modules/import/src/settings.ts +70 -0
  535. package/modules/import/translations/en.json +175 -0
  536. package/modules/import/translations/pl.json +175 -0
  537. package/modules/metering/migrations/0001_metering_core.down.sql +6 -0
  538. package/modules/metering/migrations/0001_metering_core.up.sql +119 -0
  539. package/modules/metering/migrations/0002_metering_bucket_export.down.sql +3 -0
  540. package/modules/metering/migrations/0002_metering_bucket_export.up.sql +5 -0
  541. package/modules/metering/migrations/README.md +3 -0
  542. package/modules/metering/module.json +46 -0
  543. package/modules/metering/package.json +50 -0
  544. package/modules/metering/spec/module.yaml +269 -0
  545. package/modules/metering/src/acl/permissions.ts +5 -0
  546. package/modules/metering/src/api/endpoints.ts +104 -0
  547. package/modules/metering/src/cli/commands.json +28 -0
  548. package/modules/metering/src/cli/index.ts +246 -0
  549. package/modules/metering/src/client/LimitsView.tsrx +170 -0
  550. package/modules/metering/src/client/UsageSummaryWidget.tsrx +63 -0
  551. package/modules/metering/src/client/UsageView.tsrx +205 -0
  552. package/modules/metering/src/client/api.ts +91 -0
  553. package/modules/metering/src/client/contribution.tsrx +42 -0
  554. package/modules/metering/src/client/index.ts +26 -0
  555. package/modules/metering/src/client/navigation.ts +54 -0
  556. package/modules/metering/src/client/presentation.ts +63 -0
  557. package/modules/metering/src/client/state.ts +31 -0
  558. package/modules/metering/src/domain/meters.ts +100 -0
  559. package/modules/metering/src/domain/types.ts +71 -0
  560. package/modules/metering/src/index.ts +51 -0
  561. package/modules/metering/src/platform.ts +84 -0
  562. package/modules/metering/src/server/index.ts +40 -0
  563. package/modules/metering/src/server/runtime.ts +165 -0
  564. package/modules/metering/src/services/data-classes.ts +34 -0
  565. package/modules/metering/src/services/database-repository.ts +574 -0
  566. package/modules/metering/src/services/index.ts +9 -0
  567. package/modules/metering/src/services/meter-registry.ts +145 -0
  568. package/modules/metering/src/services/metering-service.ts +441 -0
  569. package/modules/metering/src/services/migration.ts +183 -0
  570. package/modules/metering/src/services/notifications.ts +75 -0
  571. package/modules/metering/src/services/reports.ts +105 -0
  572. package/modules/metering/src/services/repository.ts +132 -0
  573. package/modules/metering/src/services/service-error.ts +46 -0
  574. package/modules/metering/src/settings.ts +47 -0
  575. package/modules/metering/translations/en.json +68 -0
  576. package/modules/metering/translations/pl.json +68 -0
  577. package/modules/notifications/migrations/0001_notifications_core.down.sql +1 -0
  578. package/modules/notifications/migrations/0001_notifications_core.up.sql +26 -0
  579. package/modules/notifications/migrations/0002_notifications_preferences.down.sql +1 -0
  580. package/modules/notifications/migrations/0002_notifications_preferences.up.sql +17 -0
  581. package/modules/notifications/migrations/0003_notifications_webhook_subscriptions.down.sql +1 -0
  582. package/modules/notifications/migrations/0003_notifications_webhook_subscriptions.up.sql +30 -0
  583. package/modules/notifications/migrations/0004_notifications_deliveries.down.sql +1 -0
  584. package/modules/notifications/migrations/0004_notifications_deliveries.up.sql +35 -0
  585. package/modules/notifications/migrations/0005_notifications_delivery_routing_role.down.sql +2 -0
  586. package/modules/notifications/migrations/0005_notifications_delivery_routing_role.up.sql +17 -0
  587. package/modules/notifications/migrations/0006_notifications_delivery_title.down.sql +1 -0
  588. package/modules/notifications/migrations/0006_notifications_delivery_title.up.sql +11 -0
  589. package/modules/notifications/migrations/0007_notifications_secret_rotation_inventory.down.sql +2 -0
  590. package/modules/notifications/migrations/0007_notifications_secret_rotation_inventory.up.sql +19 -0
  591. package/modules/notifications/migrations/0008_notifications_delivery_claim.down.sql +8 -0
  592. package/modules/notifications/migrations/0008_notifications_delivery_claim.up.sql +19 -0
  593. package/modules/notifications/migrations/0009_notifications_kind_approvals.down.sql +16 -0
  594. package/modules/notifications/migrations/0009_notifications_kind_approvals.up.sql +18 -0
  595. package/modules/notifications/migrations/0010_notifications_kind_meter_threshold.down.sql +16 -0
  596. package/modules/notifications/migrations/0010_notifications_kind_meter_threshold.up.sql +18 -0
  597. package/modules/notifications/migrations/0011_notifications_retention_keyset.down.sql +5 -0
  598. package/modules/notifications/migrations/0011_notifications_retention_keyset.up.sql +15 -0
  599. package/modules/notifications/migrations/0012_notifications_email_channel.down.sql +12 -0
  600. package/modules/notifications/migrations/0012_notifications_email_channel.up.sql +38 -0
  601. package/modules/notifications/migrations/0013_notifications_list_pages.down.sql +5 -0
  602. package/modules/notifications/migrations/0013_notifications_list_pages.up.sql +13 -0
  603. package/modules/notifications/migrations/README.md +3 -0
  604. package/modules/notifications/module.json +32 -0
  605. package/modules/notifications/package.json +49 -0
  606. package/modules/notifications/spec/module.yaml +718 -0
  607. package/modules/notifications/src/acl/permissions.ts +11 -0
  608. package/modules/notifications/src/api/endpoints.ts +814 -0
  609. package/modules/notifications/src/cli/commands.json +17 -0
  610. package/modules/notifications/src/cli/index.ts +126 -0
  611. package/modules/notifications/src/client/DeliveriesView.tsrx +483 -0
  612. package/modules/notifications/src/client/FactList.tsrx +24 -0
  613. package/modules/notifications/src/client/NotificationPreferencesView.tsrx +240 -0
  614. package/modules/notifications/src/client/NotificationsInboxView.tsrx +592 -0
  615. package/modules/notifications/src/client/UnreadCountWidget.tsrx +62 -0
  616. package/modules/notifications/src/client/WebhookForm.tsrx +297 -0
  617. package/modules/notifications/src/client/WebhooksView.tsrx +637 -0
  618. package/modules/notifications/src/client/api.ts +382 -0
  619. package/modules/notifications/src/client/contribution.tsrx +83 -0
  620. package/modules/notifications/src/client/inbox.ts +41 -0
  621. package/modules/notifications/src/client/index.ts +29 -0
  622. package/modules/notifications/src/client/navigation.ts +92 -0
  623. package/modules/notifications/src/client/notifications.css +70 -0
  624. package/modules/notifications/src/client/presentation.ts +81 -0
  625. package/modules/notifications/src/client/state.ts +246 -0
  626. package/modules/notifications/src/client/unread-count.ts +26 -0
  627. package/modules/notifications/src/domain/locale.ts +47 -0
  628. package/modules/notifications/src/domain/publish.ts +46 -0
  629. package/modules/notifications/src/domain/types.ts +186 -0
  630. package/modules/notifications/src/index.ts +62 -0
  631. package/modules/notifications/src/platform.ts +85 -0
  632. package/modules/notifications/src/server/index.ts +82 -0
  633. package/modules/notifications/src/server/runtime.ts +251 -0
  634. package/modules/notifications/src/services/data-classes.ts +139 -0
  635. package/modules/notifications/src/services/database-repository.ts +1334 -0
  636. package/modules/notifications/src/services/delivery-payload.ts +93 -0
  637. package/modules/notifications/src/services/delivery-runner.ts +170 -0
  638. package/modules/notifications/src/services/delivery-service.ts +811 -0
  639. package/modules/notifications/src/services/egress.ts +239 -0
  640. package/modules/notifications/src/services/email-channel.ts +93 -0
  641. package/modules/notifications/src/services/index.ts +23 -0
  642. package/modules/notifications/src/services/migration.ts +572 -0
  643. package/modules/notifications/src/services/notifications-service.ts +297 -0
  644. package/modules/notifications/src/services/paging.ts +60 -0
  645. package/modules/notifications/src/services/publish-service.ts +133 -0
  646. package/modules/notifications/src/services/repository.ts +342 -0
  647. package/modules/notifications/src/services/secret-rotation.ts +177 -0
  648. package/modules/notifications/src/services/secret-vault.ts +168 -0
  649. package/modules/notifications/src/services/service-error.ts +67 -0
  650. package/modules/notifications/src/services/signature.ts +81 -0
  651. package/modules/notifications/src/services/webhook-service.ts +307 -0
  652. package/modules/notifications/src/settings.ts +130 -0
  653. package/modules/notifications/translations/en.json +255 -0
  654. package/modules/notifications/translations/pl.json +255 -0
  655. package/modules/profile/module.json +3 -3
  656. package/modules/profile/package.json +2 -2
  657. package/modules/profile/spec/module.yaml +3 -3
  658. package/modules/profile/src/services/database-repository.ts +3 -13
  659. package/modules/reports/module.json +28 -0
  660. package/modules/reports/package.json +42 -0
  661. package/modules/reports/spec/module.yaml +231 -0
  662. package/modules/reports/src/acl/permissions.ts +5 -0
  663. package/modules/reports/src/api/endpoints.ts +72 -0
  664. package/modules/reports/src/client/ReportsSummaryWidget.tsrx +52 -0
  665. package/modules/reports/src/client/ReportsView.tsrx +246 -0
  666. package/modules/reports/src/client/api.ts +65 -0
  667. package/modules/reports/src/client/contribution.tsrx +36 -0
  668. package/modules/reports/src/client/index.ts +18 -0
  669. package/modules/reports/src/client/navigation.ts +39 -0
  670. package/modules/reports/src/client/presentation.ts +123 -0
  671. package/modules/reports/src/client/state.ts +28 -0
  672. package/modules/reports/src/domain/providers.ts +115 -0
  673. package/modules/reports/src/domain/types.ts +44 -0
  674. package/modules/reports/src/index.ts +47 -0
  675. package/modules/reports/src/platform.ts +37 -0
  676. package/modules/reports/src/server/index.ts +21 -0
  677. package/modules/reports/src/server/runtime.ts +40 -0
  678. package/modules/reports/src/services/index.ts +17 -0
  679. package/modules/reports/src/services/provider-registry.ts +144 -0
  680. package/modules/reports/src/services/range.ts +65 -0
  681. package/modules/reports/src/services/reports-service.ts +316 -0
  682. package/modules/reports/src/services/service-error.ts +26 -0
  683. package/modules/reports/src/settings.ts +49 -0
  684. package/modules/reports/translations/en.json +35 -0
  685. package/modules/reports/translations/pl.json +35 -0
  686. package/modules/sandbox/module.json +4 -4
  687. package/modules/sandbox/package.json +2 -2
  688. package/modules/sandbox/spec/module.yaml +3 -3
  689. package/modules/sandbox/src/services/database-repository.ts +14 -23
  690. package/modules/sandbox/src/services/directory.ts +16 -0
  691. package/modules/sandbox/src/services/sandbox-service.ts +13 -11
  692. package/modules/search/migrations/0001_search_core.down.sql +1 -0
  693. package/modules/search/migrations/0001_search_core.up.sql +22 -0
  694. package/modules/search/migrations/0002_search_recent_export.down.sql +3 -0
  695. package/modules/search/migrations/0002_search_recent_export.up.sql +5 -0
  696. package/modules/search/migrations/README.md +3 -0
  697. package/modules/search/module.json +28 -0
  698. package/modules/search/package.json +43 -0
  699. package/modules/search/spec/module.yaml +177 -0
  700. package/modules/search/src/acl/permissions.ts +5 -0
  701. package/modules/search/src/api/endpoints.ts +221 -0
  702. package/modules/search/src/client/SearchView.tsrx +346 -0
  703. package/modules/search/src/client/api.ts +157 -0
  704. package/modules/search/src/client/contribution.tsrx +31 -0
  705. package/modules/search/src/client/index.ts +17 -0
  706. package/modules/search/src/client/navigation.ts +97 -0
  707. package/modules/search/src/client/search.css +56 -0
  708. package/modules/search/src/client/state.ts +113 -0
  709. package/modules/search/src/domain/data-classes.ts +73 -0
  710. package/modules/search/src/domain/providers.ts +88 -0
  711. package/modules/search/src/domain/types.ts +56 -0
  712. package/modules/search/src/index.ts +46 -0
  713. package/modules/search/src/platform.ts +42 -0
  714. package/modules/search/src/server/index.ts +25 -0
  715. package/modules/search/src/server/runtime.ts +123 -0
  716. package/modules/search/src/services/database-repository.ts +163 -0
  717. package/modules/search/src/services/index.ts +21 -0
  718. package/modules/search/src/services/migration.ts +65 -0
  719. package/modules/search/src/services/provider-registry.ts +137 -0
  720. package/modules/search/src/services/repository.ts +43 -0
  721. package/modules/search/src/services/search-service.ts +442 -0
  722. package/modules/search/src/services/service-error.ts +35 -0
  723. package/modules/search/src/settings.ts +68 -0
  724. package/modules/search/translations/en.json +45 -0
  725. package/modules/search/translations/pl.json +45 -0
  726. package/modules/system/module.json +2 -2
  727. package/modules/system/package.json +2 -2
  728. package/modules/system/spec/module.yaml +30 -3
  729. package/modules/system/src/client/FlagsPanel.tsrx +127 -0
  730. package/modules/system/src/client/ModuleSettingRow.tsrx +17 -7
  731. package/modules/system/src/client/ModuleSettingsSection.tsrx +10 -71
  732. package/modules/system/src/client/ModulesView.tsrx +91 -65
  733. package/modules/system/src/client/flags.ts +35 -0
  734. package/modules/system/src/client/index.ts +8 -0
  735. package/modules/system/src/client/navigation.ts +8 -0
  736. package/modules/system/src/client/settings-state.ts +159 -0
  737. package/modules/system/src/client/state.ts +2 -0
  738. package/modules/system/src/domain/time-zone.ts +105 -0
  739. package/modules/system/src/index.ts +12 -0
  740. package/modules/system/src/platform.ts +5 -1
  741. package/modules/system/src/server/endpoints.ts +72 -21
  742. package/modules/system/src/settings.ts +28 -0
  743. package/modules/system/translations/en.json +17 -0
  744. package/modules/system/translations/pl.json +17 -0
  745. package/modules/users/module.json +30 -4
  746. package/modules/users/package.json +5 -2
  747. package/modules/users/spec/module.yaml +290 -7
  748. package/modules/users/src/api/endpoints.ts +228 -15
  749. package/modules/users/src/client/InviteMemberForm.tsrx +2 -2
  750. package/modules/users/src/client/MemberDrawer.tsrx +142 -26
  751. package/modules/users/src/client/UserAccountForm.tsrx +2 -2
  752. package/modules/users/src/client/UsersView.tsrx +432 -71
  753. package/modules/users/src/client/api.ts +106 -12
  754. package/modules/users/src/client/contribution.tsrx +5 -0
  755. package/modules/users/src/client/member-columns.tsrx +22 -9
  756. package/modules/users/src/client/state.ts +172 -7
  757. package/modules/users/src/domain/lists.ts +9 -0
  758. package/modules/users/src/index.ts +11 -0
  759. package/modules/users/src/platform.ts +50 -1
  760. package/modules/users/src/services/member-export.ts +51 -0
  761. package/modules/users/src/services/member-import.ts +249 -0
  762. package/modules/users/src/services/member-search.ts +145 -0
  763. package/modules/users/src/services/users-service.ts +117 -4
  764. package/modules/users/translations/en.json +57 -8
  765. package/modules/users/translations/pl.json +57 -8
  766. package/modules/workflows/migrations/0004_payload_rotation_inventory.up.sql +17 -0
  767. package/modules/workflows/migrations/0005_workflows_human_approval.up.sql +28 -0
  768. package/modules/workflows/migrations/0006_workflows_retention_indexes.up.sql +11 -0
  769. package/modules/workflows/migrations/0007_workflows_erasure_subject_indexes.up.sql +17 -0
  770. package/modules/workflows/migrations/0008_workflows_subject_account.up.sql +24 -0
  771. package/modules/workflows/migrations/0009_workflows_definition_list_indexes.up.sql +9 -0
  772. package/modules/workflows/module.json +34 -6
  773. package/modules/workflows/package.json +3 -2
  774. package/modules/workflows/spec/module.yaml +26 -9
  775. package/modules/workflows/src/api/endpoints.ts +131 -25
  776. package/modules/workflows/src/cli/commands.json +17 -0
  777. package/modules/workflows/src/cli/index.ts +114 -0
  778. package/modules/workflows/src/client/WorkflowExecutionHistory.tsrx +36 -27
  779. package/modules/workflows/src/client/WorkflowInspector.tsrx +116 -0
  780. package/modules/workflows/src/client/WorkflowNodePalette.tsrx +1 -0
  781. package/modules/workflows/src/client/WorkflowsView.tsrx +236 -99
  782. package/modules/workflows/src/client/api.ts +54 -34
  783. package/modules/workflows/src/client/canvas-model.ts +12 -0
  784. package/modules/workflows/src/client/state.ts +95 -0
  785. package/modules/workflows/src/domain/events.ts +25 -11
  786. package/modules/workflows/src/domain/graph.ts +135 -1
  787. package/modules/workflows/src/domain/types.ts +91 -4
  788. package/modules/workflows/src/platform.ts +12 -0
  789. package/modules/workflows/src/server/runtime.ts +78 -5
  790. package/modules/workflows/src/services/approvals.ts +62 -0
  791. package/modules/workflows/src/services/cursors.ts +37 -0
  792. package/modules/workflows/src/services/data-classes.ts +232 -0
  793. package/modules/workflows/src/services/database-repository.ts +660 -171
  794. package/modules/workflows/src/services/migration.ts +240 -0
  795. package/modules/workflows/src/services/notifications.ts +98 -0
  796. package/modules/workflows/src/services/payload-codec.ts +51 -28
  797. package/modules/workflows/src/services/payload-rotation.ts +171 -0
  798. package/modules/workflows/src/services/repository.ts +123 -8
  799. package/modules/workflows/src/services/simulation.ts +7 -0
  800. package/modules/workflows/src/services/worker.ts +446 -25
  801. package/modules/workflows/src/services/workflows-service.ts +264 -103
  802. package/modules/workflows/translations/en.json +12 -4
  803. package/modules/workflows/translations/pl.json +12 -4
  804. package/modules.json +48 -4
  805. package/package.json +66 -7
  806. package/packages/client/package.json +2 -1
  807. package/packages/client/src/ApplicationShell.tsrx +43 -0
  808. package/packages/client/src/contributions.ts +55 -0
  809. package/packages/client/src/i18n/locales/en.json +5 -0
  810. package/packages/client/src/i18n/locales/pl.json +5 -0
  811. package/packages/client/src/index.ts +13 -1
  812. package/packages/client/src/routing.ts +22 -0
  813. package/packages/client/src/shell/CommandPalette.tsrx +223 -11
  814. package/packages/client/src/shell/command-search.ts +126 -0
  815. package/packages/client/src/shell/command.ts +30 -0
  816. package/packages/client/src/shell/navigation.ts +12 -0
  817. package/packages/client/src/shell/palette-keys.ts +27 -0
  818. package/packages/client/src/shell/shell.css +7 -0
  819. package/packages/contracts/schemas/module-spec.schema.json +287 -1
  820. package/packages/contracts/schemas/module.schema.json +25 -0
  821. package/packages/contracts/src/index.ts +144 -1
  822. package/packages/database/src/backup.ts +179 -0
  823. package/packages/database/src/decoders.ts +25 -0
  824. package/packages/database/src/index.ts +17 -0
  825. package/packages/database/src/record-history.ts +5 -14
  826. package/packages/dev-console/package.json +2 -1
  827. package/packages/dev-console/src/brand.d.mts +8 -0
  828. package/packages/dev-console/src/brand.mjs +33 -0
  829. package/packages/dev-console/src/index.mjs +2 -1
  830. package/packages/harness/src/index.ts +2 -0
  831. package/packages/harness/src/runtime.ts +218 -1
  832. package/packages/harness/src/tool-adapters.ts +19 -1
  833. package/packages/kernel/src/acl.ts +179 -0
  834. package/packages/kernel/src/capability-registry.ts +69 -2
  835. package/packages/kernel/src/data-class-registry.ts +354 -0
  836. package/packages/kernel/src/index.ts +65 -4
  837. package/packages/kernel/src/keyring.ts +208 -0
  838. package/packages/kernel/src/module-compatibility.ts +35 -4
  839. package/packages/kernel/src/module-registry.ts +49 -2
  840. package/packages/kernel/src/module-settings.ts +189 -27
  841. package/packages/server/package.json +2 -1
  842. package/packages/server/src/composition.ts +38 -0
  843. package/packages/server/src/endpoint.ts +104 -47
  844. package/packages/server/src/export/csv.ts +34 -0
  845. package/packages/server/src/export/definition.ts +346 -0
  846. package/packages/server/src/export/index.ts +61 -0
  847. package/packages/server/src/export/run.ts +116 -0
  848. package/packages/server/src/index.ts +155 -0
  849. package/packages/server/src/jobs/index.ts +93 -0
  850. package/packages/server/src/jobs/runner.ts +486 -0
  851. package/packages/server/src/log.ts +291 -0
  852. package/packages/server/src/mail/config.ts +184 -0
  853. package/packages/server/src/mail/contracts.ts +251 -0
  854. package/packages/server/src/mail/index.ts +31 -0
  855. package/packages/server/src/mail/port.ts +101 -0
  856. package/packages/server/src/mail/smtp.ts +191 -0
  857. package/packages/server/src/mail/template.ts +105 -0
  858. package/packages/server/src/metrics.ts +447 -0
  859. package/packages/server/src/pagination.ts +246 -0
  860. package/packages/server/src/trace/context.ts +103 -0
  861. package/packages/server/src/trace/egress.ts +66 -0
  862. package/packages/server/src/trace/error-sink.ts +296 -0
  863. package/packages/server/src/trace/exporter.ts +295 -0
  864. package/packages/server/src/trace/index.ts +60 -0
  865. package/packages/server/src/trace/job-sink.ts +172 -0
  866. package/packages/server/src/trace/tracer.ts +338 -0
  867. package/packages/server/src/web.ts +5 -1
  868. package/packages/storage/package.json +40 -0
  869. package/packages/storage/src/config.ts +189 -0
  870. package/packages/storage/src/content-type.ts +124 -0
  871. package/packages/storage/src/contracts.ts +112 -0
  872. package/packages/storage/src/envelope.ts +189 -0
  873. package/packages/storage/src/index.ts +43 -0
  874. package/packages/storage/src/local.ts +75 -0
  875. package/packages/storage/src/port.ts +251 -0
  876. package/packages/storage/src/read-token.ts +130 -0
  877. package/packages/storage/src/s3.ts +144 -0
  878. package/packages/storage/src/scanner.ts +22 -0
  879. package/packages/storage/src/sigv4.ts +104 -0
  880. package/packages/storage/src/store.ts +13 -0
  881. package/packages/ui/package.json +1 -0
  882. package/packages/ui/src/components/Button.tsrx +3 -0
  883. package/packages/ui/src/components/ConfirmDialog.tsrx +13 -2
  884. package/packages/ui/src/components/DateField.tsrx +92 -0
  885. package/packages/ui/src/components/DatePicker.tsrx +525 -0
  886. package/packages/ui/src/components/DateRangeField.tsrx +93 -0
  887. package/packages/ui/src/components/Drawer.tsrx +10 -1
  888. package/packages/ui/src/components/FileUpload.tsrx +158 -0
  889. package/packages/ui/src/components/Pagination.tsrx +130 -0
  890. package/packages/ui/src/components/Select.tsrx +78 -0
  891. package/packages/ui/src/components/Table.tsrx +498 -81
  892. package/packages/ui/src/components/Tabs.tsrx +53 -0
  893. package/packages/ui/src/components/ToastHost.tsrx +48 -0
  894. package/packages/ui/src/components/calendar.ts +243 -0
  895. package/packages/ui/src/components/date-field.ts +62 -0
  896. package/packages/ui/src/components/file-upload.ts +49 -0
  897. package/packages/ui/src/components/focus-trap.ts +62 -0
  898. package/packages/ui/src/components/pagination.ts +68 -0
  899. package/packages/ui/src/components/table-sorting.ts +49 -0
  900. package/packages/ui/src/components/tabs.ts +61 -0
  901. package/packages/ui/src/components/toast-store.ts +116 -0
  902. package/packages/ui/src/icons/Icon.tsrx +5 -0
  903. package/packages/ui/src/index.ts +45 -0
  904. package/packages/ui/src/styles/components.css +598 -0
  905. package/modules/automations-workflows-integration/module.json +0 -27
  906. package/modules/automations-workflows-integration/spec/module.yaml +0 -93
  907. package/modules/automations-workflows-integration/src/index.ts +0 -14
  908. package/modules/automations-workflows-integration/src/platform.ts +0 -24
  909. package/modules/automations-workflows-integration/src/server/index.ts +0 -11
  910. package/modules/automations-workflows-integration/translations/en.json +0 -21
  911. package/modules/automations-workflows-integration/translations/pl.json +0 -21
  912. package/modules/workflows/src/services/cursor-codec.ts +0 -62
@@ -1,5 +1,6 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import {
3
+ integer,
3
4
  runDatabaseMigrations,
4
5
  type DatabaseHandle,
5
6
  type DatabaseTransaction,
@@ -14,10 +15,13 @@ import type {
14
15
  JsonValue,
15
16
  } from '@flowdular/sdk/harness';
16
17
  import { usageCostMicros } from '@flowdular/sdk/harness/catalog';
18
+ import { keysetWhere } from '@flowdular/sdk/server';
17
19
  import type {
18
20
  AgentAuditEvent,
19
- AgentAuditPage,
21
+ AgentAuditListQuery,
20
22
  AgentDefinition,
23
+ AgentListPage,
24
+ AgentListQuery,
21
25
  AgentDefinitionRevision,
22
26
  AgentActionInvocation,
23
27
  AgentRevisionProcedure,
@@ -28,6 +32,7 @@ import type {
28
32
  AgentRun,
29
33
  AgentRunDetail,
30
34
  AgentRunExecution,
35
+ AgentRunListQuery,
31
36
  AgentUsageAgent,
32
37
  AgentUsageBucket,
33
38
  AgentUsageDay,
@@ -41,7 +46,10 @@ import {
41
46
  DuplicateActionIdempotencyKeyError,
42
47
  DuplicateRunIdempotencyKeyError,
43
48
  ModuleAgentBindingConflictError,
49
+ type AgentReadOptions,
44
50
  type AgentRepository,
51
+ type AgentRunExportCursor,
52
+ type ExportedAgentRun,
45
53
  type PendingAgentAuditEvent,
46
54
  type RecoverableRun,
47
55
  } from './repository.ts';
@@ -192,6 +200,11 @@ interface RunEventRow {
192
200
  occurred_at: number | string;
193
201
  }
194
202
 
203
+ /** The run id a page of events carries, so one query can serve many runs. */
204
+ interface RunEventPageRow extends RunEventRow {
205
+ run_id: string;
206
+ }
207
+
195
208
  interface AuditRow {
196
209
  id: string;
197
210
  tenant_id: string;
@@ -243,7 +256,7 @@ interface UsageRow {
243
256
  input_tokens: number | string;
244
257
  output_tokens: number | string;
245
258
  cost_micro_usd: number | string | null;
246
- unpriced_runs: number | string;
259
+ unpriced_runs: number | string | null;
247
260
  }
248
261
 
249
262
  function stringArray(value: string): readonly string[] {
@@ -296,15 +309,15 @@ function fromAgentRow(row: AgentRow): AgentDefinition {
296
309
  allowedTools: stringArray(row.allowed_tools_json),
297
310
  procedureIds: [],
298
311
  maxSteps: row.max_steps,
299
- timeoutMs: integer(row.timeout_ms),
312
+ timeoutMs: integer(row.timeout_ms, 'timeout_ms'),
300
313
  temperature: row.temperature_milli / 1_000,
301
- maxOutputTokens: integer(row.max_output_tokens),
314
+ maxOutputTokens: integer(row.max_output_tokens, 'max_output_tokens'),
302
315
  status: row.status,
303
316
  revision: row.revision,
304
317
  createdBy: row.created_by,
305
- createdAt: integer(row.created_at),
318
+ createdAt: integer(row.created_at, 'created_at'),
306
319
  updatedBy: row.updated_by,
307
- updatedAt: integer(row.updated_at),
320
+ updatedAt: integer(row.updated_at, 'updated_at'),
308
321
  };
309
322
  }
310
323
 
@@ -343,10 +356,10 @@ function fromRunRow(row: RunRow): AgentRun {
343
356
  failureCode: row.failure_code,
344
357
  failureMessage: row.failure_message,
345
358
  attempt: row.attempt,
346
- queuedAt: integer(row.queued_at),
347
- startedAt: integerOrNull(row.started_at),
348
- completedAt: integerOrNull(row.completed_at),
349
- leaseExpiresAt: integerOrNull(row.lease_expires_at),
359
+ queuedAt: integer(row.queued_at, 'queued_at'),
360
+ startedAt: integerOrNull(row.started_at, 'started_at'),
361
+ completedAt: integerOrNull(row.completed_at, 'completed_at'),
362
+ leaseExpiresAt: integerOrNull(row.lease_expires_at, 'lease_expires_at'),
350
363
  };
351
364
  }
352
365
 
@@ -364,9 +377,9 @@ function fromRevisionRow(row: AgentRevisionRow): AgentDefinitionRevision {
364
377
  allowedTools: stringArray(row.allowed_tools_json),
365
378
  procedures: JSON.parse(row.skills_json) as AgentRevisionProcedure[],
366
379
  maxSteps: row.max_steps,
367
- timeoutMs: integer(row.timeout_ms),
380
+ timeoutMs: integer(row.timeout_ms, 'timeout_ms'),
368
381
  temperature: row.temperature_milli / 1_000,
369
- maxOutputTokens: integer(row.max_output_tokens),
382
+ maxOutputTokens: integer(row.max_output_tokens, 'max_output_tokens'),
370
383
  status: row.status,
371
384
  ownership:
372
385
  row.module_id === null
@@ -378,7 +391,7 @@ function fromRevisionRow(row: AgentRevisionRow): AgentDefinitionRevision {
378
391
  },
379
392
  moduleDefinitionRevision: row.module_definition_revision,
380
393
  retainedBy: row.retained_by,
381
- retainedAt: integer(row.retained_at),
394
+ retainedAt: integer(row.retained_at, 'retained_at'),
382
395
  };
383
396
  }
384
397
 
@@ -394,7 +407,7 @@ function fromModuleBindingRow(row: ModuleAgentBindingRow): ModuleAgentBinding {
394
407
  executableRevision: row.executable_revision,
395
408
  revision: row.revision,
396
409
  updatedBy: row.updated_by,
397
- updatedAt: integer(row.updated_at),
410
+ updatedAt: integer(row.updated_at, 'updated_at'),
398
411
  };
399
412
  }
400
413
 
@@ -421,10 +434,10 @@ function fromActionRow(row: ActionRow): AgentActionInvocation {
421
434
  output: jsonValue(row.output_json),
422
435
  code: row.failure_code,
423
436
  attempt: row.attempt,
424
- queuedAt: integer(row.queued_at),
425
- startedAt: integerOrNull(row.started_at),
426
- completedAt: integerOrNull(row.completed_at),
427
- leaseExpiresAt: integerOrNull(row.lease_expires_at),
437
+ queuedAt: integer(row.queued_at, 'queued_at'),
438
+ startedAt: integerOrNull(row.started_at, 'started_at'),
439
+ completedAt: integerOrNull(row.completed_at, 'completed_at'),
440
+ leaseExpiresAt: integerOrNull(row.lease_expires_at, 'lease_expires_at'),
428
441
  };
429
442
  }
430
443
 
@@ -440,9 +453,9 @@ function fromSkillRow(row: SkillRow): AgentProcedure {
440
453
  status: row.status,
441
454
  revision: row.revision,
442
455
  createdBy: row.created_by,
443
- createdAt: integer(row.created_at),
456
+ createdAt: integer(row.created_at, 'created_at'),
444
457
  updatedBy: row.updated_by,
445
- updatedAt: integer(row.updated_at),
458
+ updatedAt: integer(row.updated_at, 'updated_at'),
446
459
  };
447
460
  }
448
461
 
@@ -456,32 +469,29 @@ function executionFromRow(row: RunRow): AgentRunExecution {
456
469
  model: row.model,
457
470
  allowedTools: stringArray(row.allowed_tools_json),
458
471
  maxSteps: row.max_steps,
459
- timeoutMs: integer(row.timeout_ms),
472
+ timeoutMs: integer(row.timeout_ms, 'timeout_ms'),
460
473
  temperature: row.temperature_milli / 1_000,
461
- maxOutputTokens: integer(row.max_output_tokens),
474
+ maxOutputTokens: integer(row.max_output_tokens, 'max_output_tokens'),
462
475
  };
463
476
  return { run: fromRunRow(row), definition };
464
477
  }
465
478
 
466
- /* SUM() over BIGINT is NUMERIC in PostgreSQL, and the driver hands NUMERIC
467
- back as a string. Aggregates leave this repository as numbers. */
468
- function integer(value: number | string | null): number {
469
- return typeof value === 'number' ? value : Number(value ?? 0);
470
- }
471
-
472
479
  /* A nullable BIGINT must stay null: coercing it to 0 would turn "never started"
473
480
  into "started at the epoch". */
474
- function integerOrNull(value: number | string | null): number | null {
475
- return value === null ? null : integer(value);
481
+ function integerOrNull(
482
+ value: number | string | null,
483
+ field: string,
484
+ ): number | null {
485
+ return value === null ? null : integer(value, field);
476
486
  }
477
487
 
478
488
  function fromUsageRow(row: UsageRow): AgentUsageBucket {
479
489
  return {
480
- runs: integer(row.runs),
481
- inputTokens: integer(row.input_tokens),
482
- outputTokens: integer(row.output_tokens),
483
- costMicroUsd: integer(row.cost_micro_usd),
484
- unpricedRuns: integer(row.unpriced_runs),
490
+ runs: integer(row.runs, 'runs'),
491
+ inputTokens: integer(row.input_tokens, 'input_tokens'),
492
+ outputTokens: integer(row.output_tokens, 'output_tokens'),
493
+ costMicroUsd: integer(row.cost_micro_usd ?? 0, 'cost_micro_usd'),
494
+ unpricedRuns: integer(row.unpriced_runs ?? 0, 'unpriced_runs'),
485
495
  };
486
496
  }
487
497
 
@@ -491,17 +501,27 @@ const USAGE_COLUMNS = `COUNT(*) AS runs,
491
501
  COALESCE(SUM(cost_micro_usd), 0) AS cost_micro_usd,
492
502
  SUM(CASE WHEN cost_micro_usd IS NULL THEN 1 ELSE 0 END) AS unpriced_runs`;
493
503
 
504
+ function fromRunEventRow(row: RunEventRow): AgentExecutionEvent {
505
+ return {
506
+ sequence: integer(row.sequence, 'sequence'),
507
+ type: row.event_type,
508
+ timestamp: integer(row.occurred_at, 'occurred_at'),
509
+ message: row.message,
510
+ metadata: metadata(row.metadata_json),
511
+ };
512
+ }
513
+
494
514
  function fromAuditRow(row: AuditRow): AgentAuditEvent {
495
515
  return {
496
516
  id: row.id,
497
517
  tenantId: row.tenant_id,
498
- sequence: integer(row.sequence),
518
+ sequence: integer(row.sequence, 'sequence'),
499
519
  actorId: row.actor_id,
500
520
  action: row.action,
501
521
  subjectType: row.subject_type,
502
522
  subjectId: row.subject_id,
503
523
  metadata: metadata(row.metadata_json),
504
- occurredAt: integer(row.occurred_at),
524
+ occurredAt: integer(row.occurred_at, 'occurred_at'),
505
525
  previousHash: row.previous_hash,
506
526
  eventHash: row.event_hash,
507
527
  };
@@ -558,15 +578,75 @@ const RUN_FROM = `agent_runs LEFT JOIN agent_run_execution_limits
558
578
  LEFT JOIN agent_run_contracts ON agent_run_contracts.run_id = agent_runs.id
559
579
  JOIN agent_run_actors ON agent_run_actors.run_id = agent_runs.id
560
580
  AND agent_run_actors.tenant_id = agent_runs.tenant_id`;
561
- const AGENT_SELECT = `SELECT agent_definitions.*,
581
+ const AGENT_COLUMNS = `agent_definitions.*,
562
582
  COALESCE(agent_definition_execution_limits.timeout_ms,
563
583
  agent_definitions.timeout_ms) AS timeout_ms,
564
584
  COALESCE(agent_definition_output_limits.max_output_tokens,
565
- ${DEFAULT_MAX_OUTPUT_TOKENS}) AS max_output_tokens
566
- FROM agent_definitions LEFT JOIN agent_definition_execution_limits
585
+ ${DEFAULT_MAX_OUTPUT_TOKENS}) AS max_output_tokens`;
586
+ const AGENT_FROM = `agent_definitions LEFT JOIN agent_definition_execution_limits
567
587
  ON agent_definition_execution_limits.agent_id = agent_definitions.id
568
588
  LEFT JOIN agent_definition_output_limits
569
589
  ON agent_definition_output_limits.agent_id = agent_definitions.id`;
590
+ const AGENT_SELECT = `SELECT ${AGENT_COLUMNS} FROM ${AGENT_FROM}`;
591
+
592
+ /* The term is matched as a substring, so the three characters LIKE reads as
593
+ syntax are escaped with PostgreSQL's default backslash. */
594
+ function likePattern(term: string): string {
595
+ return '%' + term.replace(/[\\%_]/g, (character) => '\\' + character) + '%';
596
+ }
597
+
598
+ /* The page order and the keyset predicate are one decision, so the planner
599
+ walks agent_definitions_tenant_name_key_idx or _tenant_updated_idx from the
600
+ cursor; tests/list-plan.test.ts reads the plan. A subquery names the collation key, since a keyset column must be a
601
+ plain identifier; PostgreSQL pulls it up and reads the expression index. */
602
+ const AGENT_PAGE_FROM = `(SELECT ${AGENT_COLUMNS},
603
+ lower(agent_definitions.name) AS name_key
604
+ FROM ${AGENT_FROM}
605
+ WHERE agent_definitions.tenant_id = $1
606
+ AND ($2::text IS NULL OR agent_definitions.name ILIKE $2
607
+ OR agent_definitions.agent_key ILIKE $2
608
+ OR agent_definitions.description ILIKE $2)) AS agents`;
609
+
610
+ export function agentPageStatement(query: AgentListQuery): string {
611
+ const column = query.sort === 'name' ? 'name_key' : 'updated_at';
612
+ const order = query.direction === 'asc' ? 'ASC' : 'DESC';
613
+ const keyset =
614
+ query.after === null
615
+ ? ''
616
+ : ' WHERE ' +
617
+ keysetWhere([column, 'id'], ['', ''], {
618
+ direction: query.direction,
619
+ parameterOffset: 2,
620
+ }).text;
621
+ return `SELECT * FROM ${AGENT_PAGE_FROM}${keyset}
622
+ ORDER BY ${column} ${order}, id ${order} LIMIT $${query.after === null ? 3 : 5}`;
623
+ }
624
+
625
+ const RUN_LIST_FILTERS = `agent_runs.tenant_id = $1
626
+ AND ($2::text IS NULL OR status = $2)
627
+ AND ($3::text IS NULL OR agent_id = $3)
628
+ AND ($4::text IS NULL OR trigger = $4)
629
+ AND ($5::text IS NULL OR agent_name ILIKE $5 OR agent_runs.id = $6)`;
630
+
631
+ export function runPageStatement(query: AgentRunListQuery): string {
632
+ const order = query.direction === 'asc' ? 'ASC' : 'DESC';
633
+ const keyset =
634
+ query.after === null
635
+ ? ''
636
+ : ' AND ' +
637
+ keysetWhere(['queued_at', 'id'], ['', ''], {
638
+ direction: query.direction,
639
+ parameterOffset: 6,
640
+ }).text;
641
+ return `SELECT ${RUN_COLUMNS} FROM ${RUN_FROM} WHERE ${RUN_LIST_FILTERS}${keyset}
642
+ ORDER BY queued_at ${order}, agent_runs.id ${order} LIMIT $${query.after === null ? 7 : 9}`;
643
+ }
644
+
645
+ /* Newest first over the order agent_audit_v4_tenant_time_idx carries. */
646
+ const AUDIT_PAGE_KEYSET = keysetWhere(['occurred_at', 'sequence'], ['', ''], {
647
+ direction: 'desc',
648
+ parameterOffset: 1,
649
+ }).text;
570
650
  const AGENT_REVISION_SELECT = `SELECT agent_definition_revisions.*,
571
651
  agent_revision_ownership.module_id,
572
652
  agent_revision_ownership.module_definition_revision
@@ -618,7 +698,6 @@ export interface AgentsPersistenceStatements {
618
698
  readonly updateProcedure: string;
619
699
  readonly procedureUsage: string;
620
700
  readonly deleteProcedure: string;
621
- readonly listRuns: string;
622
701
  readonly getRun: string;
623
702
  readonly listRunEvents: string;
624
703
  readonly findRunByIdempotencyKey: string;
@@ -648,12 +727,21 @@ export interface AgentsPersistenceStatements {
648
727
  readonly listRecoverableActions: string;
649
728
  readonly claimAction: string;
650
729
  readonly renewActionLease: string;
730
+ readonly releaseAction: string;
651
731
  readonly completeAction: string;
652
732
  readonly failAction: string;
653
733
  readonly cancelAction: string;
734
+ readonly exportRunsPage1: string;
735
+ readonly exportRunsPage2: string;
736
+ readonly exportRunEvents: string;
737
+ readonly deleteSettledRunsBefore: string;
738
+ readonly deleteRunsRequestedBy: string;
654
739
  readonly appendAuditEvent1: string;
655
740
  readonly appendAuditEvent2: string;
741
+ readonly pruneMeterRefusals: string;
742
+ readonly claimMeterRefusal: string;
656
743
  readonly listAuditEvents: string;
744
+ readonly exportAuditEventsPage: string;
657
745
  readonly pageAuditEvents1: string;
658
746
  readonly pageAuditEvents2: string;
659
747
  readonly verifyAuditChainDetailed: string;
@@ -822,8 +910,6 @@ export const AGENTS_SQL: AgentsPersistenceStatements = Object.freeze({
822
910
  WHERE agent_skill_assignments.tenant_id = $1
823
911
  AND agent_skill_assignments.skill_id = $2`,
824
912
  deleteProcedure: `DELETE FROM agent_skills WHERE tenant_id = $1 AND id = $2`,
825
- listRuns: `SELECT ${RUN_COLUMNS} FROM ${RUN_FROM} WHERE agent_runs.tenant_id = $1
826
- ORDER BY queued_at DESC, agent_runs.id DESC LIMIT $2`,
827
913
  getRun: `SELECT ${RUN_COLUMNS} FROM ${RUN_FROM} WHERE agent_runs.tenant_id = $1 AND agent_runs.id = $2`,
828
914
  listRunEvents: `SELECT sequence, event_type, message, metadata_json, occurred_at
829
915
  FROM agent_run_events WHERE tenant_id = $1 AND run_id = $2
@@ -930,6 +1016,13 @@ export const AGENTS_SQL: AgentsPersistenceStatements = Object.freeze({
930
1016
  renewActionLease: `UPDATE agent_action_invocations SET lease_expires_at = $1
931
1017
  WHERE tenant_id = $2 AND id = $3 AND status = 'running'
932
1018
  AND lease_owner = $4`,
1019
+ /* The claim handed back by the worker that took it, so the queue offers the
1020
+ invocation again at once instead of waiting out a lease nothing renews.
1021
+ `started_at` keeps the first claim instant, as a reclaim does. */
1022
+ releaseAction: `UPDATE agent_action_invocations SET status = 'queued',
1023
+ lease_owner = NULL, lease_expires_at = NULL
1024
+ WHERE tenant_id = $1 AND id = $2 AND status = 'running'
1025
+ AND lease_owner = $3`,
933
1026
  completeAction: `UPDATE agent_action_invocations SET status = 'succeeded',
934
1027
  output_json = $1, completed_at = $2, lease_owner = NULL,
935
1028
  lease_expires_at = NULL WHERE tenant_id = $3 AND id = $4
@@ -948,11 +1041,46 @@ export const AGENTS_SQL: AgentsPersistenceStatements = Object.freeze({
948
1041
  (id, tenant_id, sequence, actor_id, action, subject_type,
949
1042
  subject_id, metadata_json, occurred_at, previous_hash, event_hash)
950
1043
  VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`,
1044
+ /* The order agent_runs_tenant_queued_idx already carries, so the walk is an
1045
+ index range scan and a run queued during it lands ahead of the cursor
1046
+ rather than being visited twice. */
1047
+ exportRunsPage1: `SELECT ${RUN_COLUMNS} FROM ${RUN_FROM}
1048
+ WHERE agent_runs.tenant_id = $1
1049
+ ORDER BY queued_at DESC, agent_runs.id LIMIT $2`,
1050
+ exportRunsPage2: `SELECT ${RUN_COLUMNS} FROM ${RUN_FROM}
1051
+ WHERE agent_runs.tenant_id = $1
1052
+ AND (queued_at < $2 OR (queued_at = $3 AND agent_runs.id > $4))
1053
+ ORDER BY queued_at DESC, agent_runs.id LIMIT $5`,
1054
+ exportRunEvents: `SELECT run_id, sequence, event_type, message, metadata_json,
1055
+ occurred_at FROM agent_run_events
1056
+ WHERE tenant_id = $1 AND run_id = ANY($2::text[])
1057
+ ORDER BY run_id, sequence`,
1058
+ /* The inner select applies the batch limit; the child tables of a run go
1059
+ with it through their own cascade. */
1060
+ deleteSettledRunsBefore: `DELETE FROM agent_runs WHERE id IN (
1061
+ SELECT id FROM agent_runs
1062
+ WHERE tenant_id = $1 AND completed_at < $2
1063
+ AND status IN ('succeeded', 'failed', 'cancelled')
1064
+ ORDER BY completed_at LIMIT $3)`,
1065
+ deleteRunsRequestedBy: `DELETE FROM agent_runs WHERE id IN (
1066
+ SELECT id FROM agent_runs
1067
+ WHERE tenant_id = $1 AND requested_by = $2
1068
+ ORDER BY id LIMIT $3)`,
1069
+ pruneMeterRefusals: `DELETE FROM agent_meter_refusals
1070
+ WHERE tenant_id = $1 AND meter = $2 AND period <> $3`,
1071
+ claimMeterRefusal: `INSERT INTO agent_meter_refusals
1072
+ (tenant_id, meter, period, first_refused_at)
1073
+ VALUES ($1, $2, $3, $4)
1074
+ ON CONFLICT (tenant_id, meter, period) DO NOTHING
1075
+ RETURNING tenant_id`,
951
1076
  listAuditEvents: `SELECT * FROM agent_audit_events_v4 WHERE tenant_id = $1
952
1077
  ORDER BY sequence DESC LIMIT $2`,
1078
+ exportAuditEventsPage: `SELECT * FROM agent_audit_events_v4
1079
+ WHERE tenant_id = $1 AND sequence > $2
1080
+ ORDER BY sequence LIMIT $3`,
953
1081
  pageAuditEvents1: `SELECT * FROM agent_audit_events_v4 WHERE tenant_id = $1
954
- AND (occurred_at < $2 OR (occurred_at = $3 AND sequence < $4))
955
- ORDER BY occurred_at DESC, sequence DESC LIMIT $5`,
1082
+ AND ${AUDIT_PAGE_KEYSET}
1083
+ ORDER BY occurred_at DESC, sequence DESC LIMIT $4`,
956
1084
  pageAuditEvents2: `SELECT * FROM agent_audit_events_v4 WHERE tenant_id = $1
957
1085
  ORDER BY occurred_at DESC, sequence DESC LIMIT $2`,
958
1086
  verifyAuditChainDetailed: `SELECT * FROM agent_audit_events_v4 WHERE tenant_id = $1
@@ -999,9 +1127,16 @@ export class DatabaseAgentRepository implements AgentRepository {
999
1127
  tenantId: string,
1000
1128
  access: 'read' | 'write',
1001
1129
  body: (transaction: DatabaseTransaction) => Promise<T>,
1130
+ options?: AgentReadOptions,
1002
1131
  ): Promise<T> {
1003
1132
  await this.readyPromise;
1004
- return this.handles.runtime.transaction(body, { access, tenantId });
1133
+ return this.handles.runtime.transaction(body, {
1134
+ access,
1135
+ tenantId,
1136
+ /* The caller's budget reaches the statement, so a read nobody waits
1137
+ for stops holding a connection open. */
1138
+ ...(options?.signal === undefined ? {} : { signal: options.signal }),
1139
+ });
1005
1140
  }
1006
1141
 
1007
1142
  /* The recovery polls have to find work before they know whose it is. They
@@ -1533,22 +1668,57 @@ export class DatabaseAgentRepository implements AgentRepository {
1533
1668
  const rows = (await this.#query(transaction, AGENTS_SQL.listAgents, [
1534
1669
  tenantId,
1535
1670
  ])) as unknown as AgentRow[];
1536
- const agents: AgentDefinition[] = [];
1537
- for (const row of rows) {
1538
- const agent = fromAgentRow(row);
1539
- agents.push({
1540
- ...agent,
1541
- procedureIds: await this.#procedureIds(
1542
- transaction,
1543
- agent.tenantId,
1544
- agent.id,
1545
- ),
1546
- });
1547
- }
1548
- return agents;
1671
+ return await this.#withProcedureIds(transaction, rows);
1549
1672
  });
1550
1673
  }
1551
1674
 
1675
+ async listAgentsPage(
1676
+ tenantId: string,
1677
+ query: AgentListQuery,
1678
+ ): Promise<AgentListPage> {
1679
+ return this.#tx(tenantId, 'read', async (transaction) => {
1680
+ const rows = (await this.#query(transaction, agentPageStatement(query), [
1681
+ tenantId,
1682
+ query.search === null ? null : likePattern(query.search),
1683
+ ...(query.after === null
1684
+ ? []
1685
+ : [query.after.sortValue, query.after.id]),
1686
+ query.limit,
1687
+ ])) as unknown as (AgentRow & { name_key: string })[];
1688
+ const agents = await this.#withProcedureIds(transaction, rows);
1689
+ const last = agents.at(-1);
1690
+ return {
1691
+ agents,
1692
+ last: last
1693
+ ? {
1694
+ nameKey: rows[rows.length - 1]!.name_key,
1695
+ updatedAt: last.updatedAt,
1696
+ id: last.id,
1697
+ }
1698
+ : null,
1699
+ };
1700
+ });
1701
+ }
1702
+
1703
+ async #withProcedureIds(
1704
+ transaction: DatabaseTransaction,
1705
+ rows: readonly AgentRow[],
1706
+ ): Promise<readonly AgentDefinition[]> {
1707
+ const agents: AgentDefinition[] = [];
1708
+ for (const row of rows) {
1709
+ const agent = fromAgentRow(row);
1710
+ agents.push({
1711
+ ...agent,
1712
+ procedureIds: await this.#procedureIds(
1713
+ transaction,
1714
+ agent.tenantId,
1715
+ agent.id,
1716
+ ),
1717
+ });
1718
+ }
1719
+ return agents;
1720
+ }
1721
+
1552
1722
  providerUsage(
1553
1723
  tenantId: string,
1554
1724
  providerId: string,
@@ -1569,8 +1739,8 @@ export class DatabaseAgentRepository implements AgentRepository {
1569
1739
  ])
1570
1740
  )[0] as unknown as { count: number | string };
1571
1741
  return {
1572
- definitions: integer(definitions.count),
1573
- pendingRuns: integer(pendingRuns.count),
1742
+ definitions: integer(definitions.count, 'count'),
1743
+ pendingRuns: integer(pendingRuns.count, 'count'),
1574
1744
  };
1575
1745
  });
1576
1746
  }
@@ -1881,12 +2051,18 @@ export class DatabaseAgentRepository implements AgentRepository {
1881
2051
 
1882
2052
  async listRuns(
1883
2053
  tenantId: string,
1884
- limit: number,
2054
+ query: AgentRunListQuery,
1885
2055
  ): Promise<readonly AgentRun[]> {
1886
2056
  return this.#tx(tenantId, 'read', async (transaction) => {
1887
- const rows = (await this.#query(transaction, AGENTS_SQL.listRuns, [
2057
+ const rows = (await this.#query(transaction, runPageStatement(query), [
1888
2058
  tenantId,
1889
- limit,
2059
+ query.status,
2060
+ query.agentId,
2061
+ query.trigger,
2062
+ query.search === null ? null : likePattern(query.search),
2063
+ query.search,
2064
+ ...(query.after === null ? [] : [query.after.queuedAt, query.after.id]),
2065
+ query.limit,
1890
2066
  ])) as unknown as RunRow[];
1891
2067
  const runs: AgentRun[] = [];
1892
2068
  for (const row of rows) {
@@ -1939,15 +2115,7 @@ export class DatabaseAgentRepository implements AgentRepository {
1939
2115
  runId,
1940
2116
  afterSequence,
1941
2117
  ])) as unknown as RunEventRow[]
1942
- ).map(
1943
- (event): AgentExecutionEvent => ({
1944
- sequence: integer(event.sequence),
1945
- type: event.event_type,
1946
- timestamp: integer(event.occurred_at),
1947
- message: event.message,
1948
- metadata: metadata(event.metadata_json),
1949
- }),
1950
- );
2118
+ ).map(fromRunEventRow);
1951
2119
  }
1952
2120
  }
1953
2121
 
@@ -2482,6 +2650,22 @@ export class DatabaseAgentRepository implements AgentRepository {
2482
2650
  });
2483
2651
  }
2484
2652
 
2653
+ async releaseAction(
2654
+ tenantId: string,
2655
+ invocationId: string,
2656
+ workerId: string,
2657
+ ): Promise<boolean> {
2658
+ return this.#tx(tenantId, 'write', async (transaction) => {
2659
+ return (
2660
+ (await this.#exec(transaction, AGENTS_SQL.releaseAction, [
2661
+ tenantId,
2662
+ invocationId,
2663
+ workerId,
2664
+ ])) === 1
2665
+ );
2666
+ });
2667
+ }
2668
+
2485
2669
  async completeAction(
2486
2670
  tenantId: string,
2487
2671
  invocationId: string,
@@ -2587,7 +2771,7 @@ export class DatabaseAgentRepository implements AgentRepository {
2587
2771
  /* count and every BIGINT arrive as a string from the server driver, so the
2588
2772
  next sequence must be added as a number. Without this the chain reads
2589
2773
  1, then "11", then "111". */
2590
- const sequence = integer(previous?.sequence ?? 0) + 1;
2774
+ const sequence = integer(previous?.sequence ?? 0, 'sequence') + 1;
2591
2775
  const previousHash = previous?.event_hash ?? null;
2592
2776
  const metadataJson = stableMetadata(event.metadata);
2593
2777
  const eventHash = auditHash({
@@ -2632,6 +2816,29 @@ export class DatabaseAgentRepository implements AgentRepository {
2632
2816
  );
2633
2817
  }
2634
2818
 
2819
+ async claimMeterRefusal(
2820
+ tenantId: string,
2821
+ meter: string,
2822
+ period: string,
2823
+ at: number,
2824
+ ): Promise<boolean> {
2825
+ return this.#tx(tenantId, 'write', async (transaction) => {
2826
+ /* The earlier month goes in the same transaction as the claim, so the
2827
+ workspace holds one row per meter however long it keeps refusing. */
2828
+ await this.#exec(transaction, AGENTS_SQL.pruneMeterRefusals, [
2829
+ tenantId,
2830
+ meter,
2831
+ period,
2832
+ ]);
2833
+ const claimed = await this.#query<{ tenant_id: string }>(
2834
+ transaction,
2835
+ AGENTS_SQL.claimMeterRefusal,
2836
+ [tenantId, meter, period, at],
2837
+ );
2838
+ return claimed.length > 0;
2839
+ });
2840
+ }
2841
+
2635
2842
  async listAuditEvents(
2636
2843
  tenantId: string,
2637
2844
  limit: number,
@@ -2648,31 +2855,21 @@ export class DatabaseAgentRepository implements AgentRepository {
2648
2855
 
2649
2856
  async pageAuditEvents(
2650
2857
  tenantId: string,
2651
- cursor: { readonly occurredAt: number; readonly sequence: number } | null,
2652
- limit: number,
2653
- ): Promise<AgentAuditPage> {
2858
+ query: AgentAuditListQuery,
2859
+ ): Promise<readonly AgentAuditEvent[]> {
2654
2860
  return this.#tx(tenantId, 'read', async (transaction) => {
2655
- const rows = (cursor
2861
+ const rows = (query.after
2656
2862
  ? await this.#query(transaction, AGENTS_SQL.pageAuditEvents1, [
2657
2863
  tenantId,
2658
- cursor.occurredAt,
2659
- cursor.occurredAt,
2660
- cursor.sequence,
2661
- limit + 1,
2864
+ query.after.occurredAt,
2865
+ query.after.sequence,
2866
+ query.limit,
2662
2867
  ])
2663
2868
  : await this.#query(transaction, AGENTS_SQL.pageAuditEvents2, [
2664
2869
  tenantId,
2665
- limit + 1,
2870
+ query.limit,
2666
2871
  ])) as unknown as AuditRow[];
2667
- const page = rows.slice(0, limit).map(fromAuditRow);
2668
- const last = page[page.length - 1];
2669
- return {
2670
- events: page,
2671
- nextCursor:
2672
- rows.length > limit && last
2673
- ? `${last.occurredAt}:${last.sequence}`
2674
- : null,
2675
- };
2872
+ return rows.map(fromAuditRow);
2676
2873
  });
2677
2874
  }
2678
2875
 
@@ -2718,16 +2915,22 @@ export class DatabaseAgentRepository implements AgentRepository {
2718
2915
  tenantId: string,
2719
2916
  fromDay: string,
2720
2917
  toDay: string,
2918
+ options?: AgentReadOptions,
2721
2919
  ): Promise<readonly AgentUsageDay[]> {
2722
- return this.#tx(tenantId, 'read', async (transaction) => {
2723
- return (
2724
- (await this.#query(transaction, AGENTS_SQL.usageByDay, [
2725
- tenantId,
2726
- fromDay,
2727
- toDay,
2728
- ])) as unknown as UsageRow[]
2729
- ).map((row) => ({ day: row.day, ...fromUsageRow(row) }));
2730
- });
2920
+ return this.#tx(
2921
+ tenantId,
2922
+ 'read',
2923
+ async (transaction) => {
2924
+ return (
2925
+ (await this.#query(transaction, AGENTS_SQL.usageByDay, [
2926
+ tenantId,
2927
+ fromDay,
2928
+ toDay,
2929
+ ])) as unknown as UsageRow[]
2930
+ ).map((row) => ({ day: row.day, ...fromUsageRow(row) }));
2931
+ },
2932
+ options,
2933
+ );
2731
2934
  }
2732
2935
 
2733
2936
  async usageByAgent(
@@ -2782,5 +2985,94 @@ export class DatabaseAgentRepository implements AgentRepository {
2782
2985
  });
2783
2986
  }
2784
2987
 
2988
+ /* The operations behind the declared data classes. Each runs on this
2989
+ module's own lease, inside its own tenant-scoped transaction. */
2990
+
2991
+ async exportRunsPage(
2992
+ tenantId: string,
2993
+ after: AgentRunExportCursor | null,
2994
+ limit: number,
2995
+ ): Promise<readonly ExportedAgentRun[]> {
2996
+ return this.#tx(tenantId, 'read', async (transaction) => {
2997
+ const runs = (after === null
2998
+ ? await this.#query(transaction, AGENTS_SQL.exportRunsPage1, [
2999
+ tenantId,
3000
+ limit,
3001
+ ])
3002
+ : await this.#query(transaction, AGENTS_SQL.exportRunsPage2, [
3003
+ tenantId,
3004
+ after.queuedAt,
3005
+ after.queuedAt,
3006
+ after.id,
3007
+ limit,
3008
+ ])) as unknown as RunRow[];
3009
+ if (runs.length === 0) return [];
3010
+ /* One query for the steps of the whole page: a run is a row, not a
3011
+ round trip. */
3012
+ const events = (await this.#query(
3013
+ transaction,
3014
+ AGENTS_SQL.exportRunEvents,
3015
+ [tenantId, runs.map((run) => run.id)],
3016
+ )) as unknown as RunEventPageRow[];
3017
+ const steps = new Map<string, AgentExecutionEvent[]>();
3018
+ for (const event of events) {
3019
+ const existing = steps.get(event.run_id);
3020
+ if (existing) existing.push(fromRunEventRow(event));
3021
+ else steps.set(event.run_id, [fromRunEventRow(event)]);
3022
+ }
3023
+ return runs.map((run) => ({
3024
+ run: fromRunRow(run),
3025
+ events: steps.get(run.id) ?? [],
3026
+ }));
3027
+ });
3028
+ }
3029
+
3030
+ async deleteSettledRunsBefore(
3031
+ tenantId: string,
3032
+ before: number,
3033
+ limit: number,
3034
+ ): Promise<number> {
3035
+ return this.#tx(tenantId, 'write', (transaction) =>
3036
+ this.#exec(transaction, AGENTS_SQL.deleteSettledRunsBefore, [
3037
+ tenantId,
3038
+ before,
3039
+ limit,
3040
+ ]),
3041
+ );
3042
+ }
3043
+
3044
+ /* A run this removes while a worker holds it takes its lease with it: the
3045
+ next renewal finds no row, the worker stops the execution as it does for
3046
+ any lost lease, and its settle write reaches nothing. */
3047
+ async deleteRunsRequestedBy(
3048
+ tenantId: string,
3049
+ accountId: string,
3050
+ limit: number,
3051
+ ): Promise<number> {
3052
+ return this.#tx(tenantId, 'write', (transaction) =>
3053
+ this.#exec(transaction, AGENTS_SQL.deleteRunsRequestedBy, [
3054
+ tenantId,
3055
+ accountId,
3056
+ limit,
3057
+ ]),
3058
+ );
3059
+ }
3060
+
3061
+ async exportAuditEventsPage(
3062
+ tenantId: string,
3063
+ afterSequence: number,
3064
+ limit: number,
3065
+ ): Promise<readonly AgentAuditEvent[]> {
3066
+ return this.#tx(tenantId, 'read', async (transaction) =>
3067
+ (
3068
+ (await this.#query(transaction, AGENTS_SQL.exportAuditEventsPage, [
3069
+ tenantId,
3070
+ afterSequence,
3071
+ limit,
3072
+ ])) as unknown as AuditRow[]
3073
+ ).map(fromAuditRow),
3074
+ );
3075
+ }
3076
+
2785
3077
  async close(): Promise<void> {}
2786
3078
  }