@capybara-hq/kernel 0.1.0-rc.142 → 0.1.0-rc.144

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/dist/admin/admin-agents.controller.d.ts +3 -5
  2. package/dist/admin/admin-agents.controller.js +1 -1
  3. package/dist/admin/admin-connectors.controller.d.ts +3 -5
  4. package/dist/admin/admin-connectors.controller.js +1 -1
  5. package/dist/admin/admin-items.schemas.d.ts +6 -6
  6. package/dist/admin/admin-items.schemas.js +5 -9
  7. package/dist/admin/admin.controller.d.ts +18 -12
  8. package/dist/admin/admin.controller.js +29 -15
  9. package/dist/admin/admin.schemas.d.ts +12 -3
  10. package/dist/admin/admin.schemas.js +17 -6
  11. package/dist/agents/admin-agents.d.ts +10 -8
  12. package/dist/agents/admin-agents.js +13 -9
  13. package/dist/agents/agents.module.js +3 -0
  14. package/dist/agents/agents.service.js +1 -1
  15. package/dist/agents/org-templates.d.ts +3 -1
  16. package/dist/agents/org-templates.js +7 -3
  17. package/dist/agents/pending-connector-requests.d.ts +10 -4
  18. package/dist/agents/pending-connector-requests.js +29 -7
  19. package/dist/automations/automations.controller.d.ts +9 -5
  20. package/dist/automations/automations.controller.js +21 -4
  21. package/dist/automations/automations.schemas.d.ts +19 -0
  22. package/dist/automations/automations.schemas.js +9 -0
  23. package/dist/automations/automations.service.d.ts +25 -8
  24. package/dist/automations/automations.service.js +40 -34
  25. package/dist/automations/events/acceptance.d.ts +6 -1
  26. package/dist/automations/events/acceptance.js +30 -11
  27. package/dist/automations/store.d.ts +17 -0
  28. package/dist/automations/store.js +35 -0
  29. package/dist/catalog/admin-catalog.controller.d.ts +64 -2
  30. package/dist/catalog/admin-catalog.controller.js +17 -0
  31. package/dist/catalog/catalog-import.module.js +3 -0
  32. package/dist/catalog/catalog-scope.service.d.ts +3 -1
  33. package/dist/catalog/catalog-scope.service.js +11 -7
  34. package/dist/catalog/catalog.module.js +3 -0
  35. package/dist/catalog/catalog.service.d.ts +3 -1
  36. package/dist/catalog/catalog.service.js +8 -4
  37. package/dist/catalog/cli.js +2 -2
  38. package/dist/catalog/component-promotion.d.ts +3 -1
  39. package/dist/catalog/component-promotion.js +7 -3
  40. package/dist/catalog/component-scope.service.d.ts +3 -1
  41. package/dist/catalog/component-scope.service.js +7 -3
  42. package/dist/catalog/enable-requests.d.ts +10 -8
  43. package/dist/catalog/enable-requests.js +40 -21
  44. package/dist/catalog/marketplaces.service.d.ts +1 -1
  45. package/dist/catalog/owned-items.d.ts +3 -1
  46. package/dist/catalog/owned-items.js +13 -9
  47. package/dist/catalog/platform-components.d.ts +6 -1
  48. package/dist/catalog/platform-components.js +9 -3
  49. package/dist/catalog/plugin-connectors.d.ts +8 -4
  50. package/dist/catalog/plugin-connectors.js +12 -6
  51. package/dist/catalog/plugin-import.d.ts +3 -1
  52. package/dist/catalog/plugin-import.js +14 -5
  53. package/dist/catalog/plugin-install.d.ts +3 -1
  54. package/dist/catalog/plugin-install.js +8 -4
  55. package/dist/catalog/plugin-package.js +2 -1
  56. package/dist/catalog/plugin-upgrade.d.ts +3 -1
  57. package/dist/catalog/plugin-upgrade.js +8 -4
  58. package/dist/catalog/request-hints.d.ts +19 -0
  59. package/dist/catalog/request-hints.js +34 -0
  60. package/dist/catalog/request-rules.d.ts +9 -5
  61. package/dist/catalog/request-rules.js +16 -9
  62. package/dist/catalog/requests.service.d.ts +3 -1
  63. package/dist/catalog/requests.service.js +28 -9
  64. package/dist/catalog/scope-orgs.d.ts +2 -1
  65. package/dist/catalog/scope-orgs.js +2 -2
  66. package/dist/catalog/scope-sync.d.ts +3 -1
  67. package/dist/catalog/scope-sync.js +12 -2
  68. package/dist/catalog/scope-writer.d.ts +6 -3
  69. package/dist/catalog/scope-writer.js +28 -10
  70. package/dist/catalog/unshare.d.ts +3 -2
  71. package/dist/catalog/unshare.js +4 -4
  72. package/dist/client/client-access.service.js +29 -1
  73. package/dist/config/schema.d.ts +12 -0
  74. package/dist/config/schema.js +56 -0
  75. package/dist/ctx/create-ctx.d.ts +2 -19
  76. package/dist/ctx/create-ctx.js +3 -93
  77. package/dist/ctx/durable-relay.d.ts +2 -5
  78. package/dist/ctx/durable-relay.js +56 -29
  79. package/dist/db/extension-handoff-schema.js +5 -0
  80. package/dist/db/kernel-schema.d.ts +74 -0
  81. package/dist/db/migrator.js +36 -0
  82. package/dist/erasure/account-batches.js +2 -0
  83. package/dist/erasure/account-residual.js +1 -0
  84. package/dist/erasure/org-catalog.js +8 -3
  85. package/dist/erasure/org-rules.js +1 -0
  86. package/dist/evals/evals.schemas.d.ts +15 -5
  87. package/dist/evals/evals.schemas.js +17 -10
  88. package/dist/evals/runs.controller.d.ts +4 -12
  89. package/dist/evals/runs.controller.js +14 -11
  90. package/dist/evals/runs.service.d.ts +29 -25
  91. package/dist/evals/runs.service.js +73 -61
  92. package/dist/evals/trajectory.controller.d.ts +10 -6
  93. package/dist/evals/trajectory.controller.js +11 -4
  94. package/dist/evals/trajectory.service.d.ts +17 -9
  95. package/dist/evals/trajectory.service.js +52 -35
  96. package/dist/extensions/admin-ops.d.ts +6 -1
  97. package/dist/extensions/admin-ops.js +21 -7
  98. package/dist/extensions/blobs.d.ts +2 -0
  99. package/dist/extensions/blobs.js +11 -0
  100. package/dist/extensions/deployment-config.d.ts +6 -1
  101. package/dist/extensions/deployment-config.js +13 -2
  102. package/dist/extensions/enabled.d.ts +5 -0
  103. package/dist/extensions/extensions.module.js +3 -0
  104. package/dist/extensions/grant-epoch.d.ts +108 -0
  105. package/dist/extensions/grant-epoch.js +214 -0
  106. package/dist/extensions/host.d.ts +29 -9
  107. package/dist/extensions/host.js +148 -42
  108. package/dist/extensions/instance.d.ts +3 -3
  109. package/dist/extensions/instance.js +1 -1
  110. package/dist/extensions/isolated/authorization.d.ts +54 -2
  111. package/dist/extensions/isolated/authorization.js +148 -35
  112. package/dist/extensions/isolated/child-session.js +0 -1
  113. package/dist/extensions/isolated/revision.js +1 -1
  114. package/dist/extensions/org-config.d.ts +3 -1
  115. package/dist/extensions/org-config.js +13 -4
  116. package/dist/extensions/org-overrides.d.ts +6 -1
  117. package/dist/extensions/org-overrides.js +13 -2
  118. package/dist/extensions/package-digest.job.d.ts +34 -0
  119. package/dist/extensions/package-digest.job.js +121 -0
  120. package/dist/extensions/package.js +10 -6
  121. package/dist/extensions/permission-set.d.ts +14 -78
  122. package/dist/extensions/permission-set.js +17 -143
  123. package/dist/extensions/permission-view.d.ts +13 -1
  124. package/dist/extensions/permission-view.js +20 -0
  125. package/dist/extensions/registry.js +4 -1
  126. package/dist/extensions/resolve.d.ts +7 -8
  127. package/dist/extensions/resolve.js +7 -8
  128. package/dist/extensions/revision-approvals.d.ts +167 -0
  129. package/dist/extensions/revision-approvals.js +353 -0
  130. package/dist/extensions/revision-grants.d.ts +197 -0
  131. package/dist/extensions/revision-grants.js +584 -0
  132. package/dist/extensions/state.module.js +12 -1
  133. package/dist/identity/accounts.d.ts +10 -4
  134. package/dist/identity/accounts.js +18 -5
  135. package/dist/inbox/inbox-items.service.d.ts +6 -1
  136. package/dist/inbox/inbox-items.service.js +29 -10
  137. package/dist/inbox/inbox.module.js +3 -0
  138. package/dist/inbox/inbox.service.d.ts +3 -1
  139. package/dist/inbox/inbox.service.js +9 -2
  140. package/dist/inbox/org-notices.d.ts +4 -3
  141. package/dist/inbox/org-notices.js +9 -6
  142. package/dist/inbox/platform-inbox.service.d.ts +3 -1
  143. package/dist/inbox/platform-inbox.service.js +11 -3
  144. package/dist/inbox/platform-notices.d.ts +3 -2
  145. package/dist/inbox/platform-notices.js +10 -4
  146. package/dist/infra/config/kernel-config.service.js +4 -1
  147. package/dist/infra/database/extension-effect-key-lock.js +7 -0
  148. package/dist/infra/paging/paged-read.d.ts +34 -4
  149. package/dist/infra/paging/paged-read.js +38 -1
  150. package/dist/invalidation/audiences.d.ts +32 -0
  151. package/dist/invalidation/audiences.js +43 -0
  152. package/dist/invalidation/hints.d.ts +6 -0
  153. package/dist/invalidation/hints.js +7 -1
  154. package/dist/invalidation/invalidation-hints.d.ts +12 -1
  155. package/dist/invalidation/invalidation-hints.js +46 -5
  156. package/dist/invalidation/invalidation-hints.module.d.ts +2 -0
  157. package/dist/invalidation/invalidation-hints.module.js +4 -1
  158. package/dist/invalidation/me-stream.d.ts +1 -11
  159. package/dist/invalidation/me-stream.js +12 -41
  160. package/dist/invalidation/org-intent-bridge.d.ts +18 -0
  161. package/dist/invalidation/org-intent-bridge.js +46 -0
  162. package/dist/models/enablement.d.ts +3 -1
  163. package/dist/models/enablement.js +25 -5
  164. package/dist/orgs/invitations.controller.d.ts +4 -7
  165. package/dist/orgs/invitations.controller.js +8 -5
  166. package/dist/orgs/invitations.service.d.ts +17 -3
  167. package/dist/orgs/invitations.service.js +35 -13
  168. package/dist/orgs/members.service.d.ts +35 -0
  169. package/dist/orgs/members.service.js +52 -3
  170. package/dist/orgs/offboarding.d.ts +3 -1
  171. package/dist/orgs/offboarding.js +7 -3
  172. package/dist/orgs/orgs.controller.d.ts +11 -4
  173. package/dist/orgs/orgs.controller.js +25 -5
  174. package/dist/orgs/orgs.module.js +3 -0
  175. package/dist/orgs/orgs.schemas.d.ts +14 -0
  176. package/dist/orgs/orgs.schemas.js +19 -2
  177. package/dist/orgs/orgs.service.d.ts +24 -2
  178. package/dist/orgs/orgs.service.js +47 -4
  179. package/dist/orgs/security-settings.service.d.ts +14 -6
  180. package/dist/orgs/security-settings.service.js +18 -13
  181. package/dist/orgs/settings.controller.d.ts +7 -4
  182. package/dist/platform/exclusions.js +15 -0
  183. package/dist/platform/ops/accounts.ops.js +7 -16
  184. package/dist/platform/ops/admin-items.ops.js +7 -7
  185. package/dist/platform/ops/automations.ops.js +6 -4
  186. package/dist/platform/ops/evals.ops.js +30 -15
  187. package/dist/platform/ops/org-settings.ops.js +2 -2
  188. package/dist/platform/ops/orgs.ops.js +44 -27
  189. package/dist/push/delivery.d.ts +3 -1
  190. package/dist/push/delivery.js +7 -3
  191. package/dist/push/push-processor.js +8 -1
  192. package/dist/roles/worker.module.js +3 -0
  193. package/dist/runtime/step-log.d.ts +1 -1
  194. package/dist/runtime/step-log.js +5 -4
  195. package/dist/runtime/stream-limit.d.ts +13 -0
  196. package/dist/runtime/stream-limit.js +40 -0
  197. package/dist/runtime/stream.controller.d.ts +2 -0
  198. package/dist/runtime/stream.controller.js +2 -0
  199. package/dist/runtime/stream.d.ts +1 -0
  200. package/dist/runtime/stream.js +15 -6
  201. package/dist/sandbox/permission-authority.module.js +6 -1
  202. package/dist/sandbox/permission-transitions.d.ts +3 -1
  203. package/dist/sandbox/permission-transitions.js +17 -2
  204. package/dist/setup/kernel-checks.d.ts +3 -3
  205. package/dist/setup/kernel-checks.js +4 -4
  206. package/dist/setup/setup-check-registry.d.ts +16 -5
  207. package/dist/setup/setup-check-registry.js +11 -3
  208. package/dist/setup/setup-checks.service.d.ts +1 -2
  209. package/dist/setup/setup-checks.service.js +7 -6
  210. package/dist/skills/agent-skills.service.d.ts +6 -1
  211. package/dist/skills/agent-skills.service.js +12 -3
  212. package/dist/skills/changes.service.d.ts +6 -1
  213. package/dist/skills/changes.service.js +11 -3
  214. package/dist/skills/conversation-catalog.d.ts +3 -0
  215. package/dist/skills/conversation-catalog.js +2 -0
  216. package/dist/skills/skills.module.js +3 -0
  217. package/dist/skills/skills.service.d.ts +3 -1
  218. package/dist/skills/skills.service.js +8 -4
  219. package/dist/tools/admin-connectors.d.ts +10 -8
  220. package/dist/tools/admin-connectors.js +12 -10
  221. package/dist/tools/approvals.service.d.ts +12 -1
  222. package/dist/tools/approvals.service.js +36 -9
  223. package/dist/tools/builtins/automations.d.ts +1 -1
  224. package/dist/tools/builtins/automations.js +1 -1
  225. package/dist/tools/connectors.service.d.ts +3 -1
  226. package/dist/tools/connectors.service.js +29 -7
  227. package/dist/tools/tools.module.js +3 -0
  228. package/dist/ui/admin-ui.controller.d.ts +3 -1
  229. package/dist/ui/admin-ui.controller.js +3 -1
  230. package/dist/ui/ui-stream.d.ts +2 -0
  231. package/dist/ui/ui-stream.js +20 -6
  232. package/dist/ui/views.controller.d.ts +4 -2
  233. package/dist/ui/views.controller.js +4 -2
  234. package/package.json +3 -3
  235. package/src/migrations/0234_extension_grant_epoch.sql +141 -0
  236. package/src/migrations/0235_extension_revision_grants.sql +166 -0
  237. package/src/migrations/0236_paged_table_idx.sql +33 -0
  238. package/src/migrations/0237_extension_handoff_health.sql +18 -0
@@ -10,21 +10,25 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { randomUUID } from "node:crypto";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
+ import { publishRequestHints } from "../catalog/request-hints.js";
13
14
  import { audit } from "../identity/audit.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
15
16
  import { TransactionHost } from "../infra/database/transaction-host.js";
16
17
  import { Transactional } from "../infra/database/transactional.decorator.js";
18
+ import { InvalidationHints } from "../invalidation/invalidation-hints.js";
17
19
  /**
18
20
  * Moves the agents' setup requests that still concern their owner (pending, or decided and not
19
21
  * dismissed) to the new owner `owner` (an owner change: `AgentsService.reassignOwner`, member
20
- * offboarding). Runs through `db` (the caller's transaction).
22
+ * offboarding). Runs through `db` (the caller's transaction); the moved rows publish `requests`
23
+ * after the commit to the new owner and the org's admins, and to `previousOwner` when the caller
24
+ * holds it (an owner change; offboarding's previous owner leaves the org, so it passes none).
21
25
  */
22
- export async function retargetSetupRequests(db, agentIds, owner) {
26
+ export async function retargetSetupRequests(db, hints, agentIds, owner, previousOwner) {
23
27
  if (agentIds.length === 0)
24
28
  return;
25
29
  // org-filter: the agent ids were resolved in the caller's org (owner change, offboarding) and a
26
30
  // setup request lives in its agent's org
27
- await db
31
+ const moved = await db
28
32
  .updateTable("catalog_requests")
29
33
  .set({ requested_by: owner })
30
34
  .where("kind", "=", "connector_setup")
@@ -33,7 +37,11 @@ export async function retargetSetupRequests(db, agentIds, owner) {
33
37
  eb("status", "=", "pending"),
34
38
  eb.and([eb("status", "in", ["approved", "rejected"]), eb("dismissed_at", "is", null)]),
35
39
  ]))
40
+ .returning(["org_id", "requested_by", "kind"])
36
41
  .execute();
42
+ publishRequestHints(hints, moved, previousOwner !== undefined && moved.length > 0 && previousOwner !== owner
43
+ ? [previousOwner]
44
+ : []);
37
45
  }
38
46
  /**
39
47
  * The org inbox requests for an agent's pending connectors (ruling P4-7: one `connector_setup`
@@ -49,9 +57,11 @@ export async function retargetSetupRequests(db, agentIds, owner) {
49
57
  let PendingConnectorRequests = class PendingConnectorRequests {
50
58
  kdb;
51
59
  txHost;
52
- constructor(kdb, txHost) {
60
+ hints;
61
+ constructor(kdb, txHost, hints) {
53
62
  this.kdb = kdb;
54
63
  this.txHost = txHost;
64
+ this.hints = hints;
55
65
  }
56
66
  /**
57
67
  * The request for a new agent, requested by its owner (ruling P4-T6-4). `args.keys` are what the
@@ -118,6 +128,9 @@ let PendingConnectorRequests = class PendingConnectorRequests {
118
128
  .returning("id")
119
129
  .executeTakeFirst();
120
130
  if (inserted !== undefined) {
131
+ publishRequestHints(this.hints, [
132
+ { org_id: a.orgId, requested_by: a.requestedBy, kind: "connector_setup" },
133
+ ]);
121
134
  await audit(t, {
122
135
  actorAccountId: a.actor,
123
136
  ...(a.actorTokenId !== undefined && { actorTokenId: a.actorTokenId }),
@@ -145,8 +158,10 @@ let PendingConnectorRequests = class PendingConnectorRequests {
145
158
  * The agent's new owner receives its setup request's decision (fix round 1, item 4): the pending
146
159
  * request and the decided ones not dismissed move to `owner`. In the caller's transaction.
147
160
  */
148
- async retargetIn(agentIds, owner) {
149
- await retargetSetupRequests(this.kdb.db, agentIds, owner);
161
+ async retargetIn(agentIds, owner,
162
+ /** The owner the requests move from (it gets a `requests` hint). */
163
+ previousOwner) {
164
+ await retargetSetupRequests(this.kdb.db, this.hints, agentIds, owner, previousOwner);
150
165
  }
151
166
  /**
152
167
  * Settles the agent's pending request after a definition write, in the caller's transaction
@@ -178,6 +193,9 @@ let PendingConnectorRequests = class PendingConnectorRequests {
178
193
  .where("id", "=", row.id)
179
194
  .where("org_id", "=", a.orgId)
180
195
  .execute();
196
+ publishRequestHints(this.hints, [
197
+ { org_id: a.orgId, requested_by: row.requested_by, kind: "connector_setup" },
198
+ ]);
181
199
  }
182
200
  return;
183
201
  }
@@ -194,6 +212,9 @@ let PendingConnectorRequests = class PendingConnectorRequests {
194
212
  .where("id", "=", row.id)
195
213
  .where("org_id", "=", a.orgId)
196
214
  .execute();
215
+ publishRequestHints(this.hints, [
216
+ { org_id: a.orgId, requested_by: row.requested_by, kind: "connector_setup" },
217
+ ]);
197
218
  await audit(t, {
198
219
  actorAccountId: a.actor,
199
220
  ...(a.actorTokenId !== undefined && { actorTokenId: a.actorTokenId }),
@@ -216,6 +237,7 @@ __decorate([
216
237
  PendingConnectorRequests = __decorate([
217
238
  Injectable(),
218
239
  __param(0, Inject(KernelDb)),
219
- __param(1, Inject(TransactionHost))
240
+ __param(1, Inject(TransactionHost)),
241
+ __param(2, Inject(InvalidationHints))
220
242
  ], PendingConnectorRequests);
221
243
  export { PendingConnectorRequests };
@@ -1,16 +1,19 @@
1
1
  import type { z } from "zod";
2
2
  import { type Principal } from "../identity/principal.js";
3
+ import type { Page } from "../infra/paging/paged-read.js";
3
4
  import { type OrgContext } from "../orgs/org.guard.js";
4
- import { type AutomationCalendarQuery, type AutomationChatTargetsQuery, type AutomationCreateBody, type AutomationEventSourcesQuery, type AutomationGrantableQuery, type AutomationGrantParams, type AutomationGrantsBody, type AutomationListQuery, type AutomationParams, type AutomationRunBody, type AutomationRunsQuery, type AutomationUpdateBody } from "./automations.schemas.js";
5
- import { type AutomationGrantView, type AutomationListItem, AutomationsService, type ChatTarget, type EventSourceView, type GrantableTool } from "./automations.service.js";
5
+ import { type AutomationCalendarQuery, type AutomationChatTargetsQuery, type AutomationCreateBody, type AutomationEventSourcesQuery, type AutomationGrantableQuery, type AutomationGrantParams, type AutomationGrantsBody, type AutomationListQuery, type AutomationNextRunsQuery, type AutomationParams, type AutomationRunBody, type AutomationRunsQuery, type AutomationUpdateBody } from "./automations.schemas.js";
6
+ import { type AutomationGrantView, type AutomationListItem, type AutomationNextRun, AutomationsService, type ChatTarget, type EventSourceView, type GrantableTool } from "./automations.service.js";
6
7
  import type { CalendarAnswer } from "./calendar.js";
7
8
  import type { Automation, AutomationGrant, TaskRun } from "./types.js";
8
9
  /**
9
10
  * Automations (`/api/v1/orgs/:orgId/automations`, spec 2026-11-11-scheduled-tasks §10); human
10
11
  * users only (a service token gets 403).
11
- * - `GET /` → `{ items }`: the caller's own tasks, each with its `lastRun`; `?all=true` every task
12
+ * - `GET /` → a page (`page`, `size`; table pagination spec §2.3) of the caller's own tasks, each with its `lastRun`; `?all=true` every task
12
13
  * of the org (org admins, `automations.manage`, enforced by the service: 403 `forbidden`
13
14
  * otherwise); `?conversationId=` only those posting into that conversation;
15
+ * - `GET /next-runs[?all=true]` → `{ items }`: every one of the caller's tasks (`all` as the
16
+ * list's) at once, each only `{ id, status, nextRunAt }` (the calendar's empty state);
14
17
  * - `GET /calendar?from&to&timeZone[&all][&taskId]` → the calendar (runs, planned occurrences,
15
18
  * collapsed task-days; calendar spec §5.1), `org.read` like the list, `all` as the list's;
16
19
  * - `GET /chat-targets` → `{ items }`: the chats the caller can point a `chat` task at;
@@ -32,8 +35,9 @@ import type { Automation, AutomationGrant, TaskRun } from "./types.js";
32
35
  export declare class AutomationsController {
33
36
  private readonly tasks;
34
37
  constructor(tasks: AutomationsService);
35
- list(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationListQuery>): Promise<{
36
- items: AutomationListItem[];
38
+ list(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationListQuery>): Promise<Page<AutomationListItem>>;
39
+ nextRuns(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationNextRunsQuery>): Promise<{
40
+ items: AutomationNextRun[];
37
41
  }>;
38
42
  calendar(principal: Principal, org: OrgContext, q: z.infer<typeof AutomationCalendarQuery>): Promise<CalendarAnswer>;
39
43
  chatTargets(principal: Principal, org: OrgContext, _q: z.infer<typeof AutomationChatTargetsQuery>): Promise<{
@@ -11,14 +11,16 @@ import { Controller, Delete, Get, HttpCode, Inject, Patch, Post } from "@nestjs/
11
11
  import { CurrentPrincipal, requireUser } from "../identity/principal.js";
12
12
  import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
13
13
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
14
- import { AutomationCalendarQueryDto, AutomationChatTargetsQueryDto, AutomationCreateBodyDto, AutomationEventSourcesQueryDto, AutomationGrantableQueryDto, AutomationGrantParamsDto, AutomationGrantsBodyDto, AutomationListQueryDto, AutomationParamsDto, AutomationRunBodyDto, AutomationRunsQueryDto, AutomationUpdateBodyDto, calendarInputOf, createInputOf, grantsOf, updateInputOf, } from "./automations.schemas.js";
14
+ import { AutomationCalendarQueryDto, AutomationChatTargetsQueryDto, AutomationCreateBodyDto, AutomationEventSourcesQueryDto, AutomationGrantableQueryDto, AutomationGrantParamsDto, AutomationGrantsBodyDto, AutomationListQueryDto, AutomationNextRunsQueryDto, AutomationParamsDto, AutomationRunBodyDto, AutomationRunsQueryDto, AutomationUpdateBodyDto, calendarInputOf, createInputOf, grantsOf, updateInputOf, } from "./automations.schemas.js";
15
15
  import { AutomationsService, } from "./automations.service.js";
16
16
  /**
17
17
  * Automations (`/api/v1/orgs/:orgId/automations`, spec 2026-11-11-scheduled-tasks §10); human
18
18
  * users only (a service token gets 403).
19
- * - `GET /` → `{ items }`: the caller's own tasks, each with its `lastRun`; `?all=true` every task
19
+ * - `GET /` → a page (`page`, `size`; table pagination spec §2.3) of the caller's own tasks, each with its `lastRun`; `?all=true` every task
20
20
  * of the org (org admins, `automations.manage`, enforced by the service: 403 `forbidden`
21
21
  * otherwise); `?conversationId=` only those posting into that conversation;
22
+ * - `GET /next-runs[?all=true]` → `{ items }`: every one of the caller's tasks (`all` as the
23
+ * list's) at once, each only `{ id, status, nextRunAt }` (the calendar's empty state);
22
24
  * - `GET /calendar?from&to&timeZone[&all][&taskId]` → the calendar (runs, planned occurrences,
23
25
  * collapsed task-days; calendar spec §5.1), `org.read` like the list, `all` as the list's;
24
26
  * - `GET /chat-targets` → `{ items }`: the chats the caller can point a `chat` task at;
@@ -46,11 +48,19 @@ let AutomationsController = class AutomationsController {
46
48
  // `all` is the service's admin check
47
49
  async list(principal, org, q) {
48
50
  const p = requireUser(principal);
49
- const items = await this.tasks.list(org.orgId, { accountId: p.account.id }, {
51
+ return this.tasks.list(org.orgId, { accountId: p.account.id }, {
50
52
  all: q.all === "true",
53
+ page: q.page,
54
+ size: q.size,
51
55
  ...(q.conversationId !== undefined && { conversationId: q.conversationId }),
52
56
  });
53
- return { items };
57
+ }
58
+ // declared before `:id`; org.read and `all` like the list
59
+ async nextRuns(principal, org, q) {
60
+ const p = requireUser(principal);
61
+ return {
62
+ items: await this.tasks.nextRuns(org.orgId, { accountId: p.account.id }, { all: q.all === "true" }),
63
+ };
54
64
  }
55
65
  // declared before `:id`; org.read like the list (a creator demoted to guest still reads their own)
56
66
  async calendar(principal, org, q) {
@@ -146,6 +156,13 @@ __decorate([
146
156
  __param(1, CurrentOrg()),
147
157
  __param(2, ZQuery(AutomationListQueryDto))
148
158
  ], AutomationsController.prototype, "list", null);
159
+ __decorate([
160
+ Get("next-runs"),
161
+ OrgAction("org.read"),
162
+ __param(0, CurrentPrincipal()),
163
+ __param(1, CurrentOrg()),
164
+ __param(2, ZQuery(AutomationNextRunsQueryDto))
165
+ ], AutomationsController.prototype, "nextRuns", null);
149
166
  __decorate([
150
167
  Get("calendar"),
151
168
  OrgAction("org.read"),
@@ -193,6 +193,8 @@ export declare const AutomationUpdateBody: z.ZodObject<{
193
193
  }>>>;
194
194
  }, z.core.$strict>;
195
195
  export declare const AutomationListQuery: z.ZodObject<{
196
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
197
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
196
198
  all: z.ZodOptional<z.ZodEnum<{
197
199
  false: "false";
198
200
  true: "true";
@@ -214,6 +216,13 @@ export declare const AutomationCalendarQuery: z.ZodObject<{
214
216
  }>>;
215
217
  taskId: z.ZodOptional<z.ZodString>;
216
218
  }, z.core.$strict>;
219
+ /** `GET …/automations/next-runs`: `all` as the list's (org admins). */
220
+ export declare const AutomationNextRunsQuery: z.ZodObject<{
221
+ all: z.ZodOptional<z.ZodEnum<{
222
+ false: "false";
223
+ true: "true";
224
+ }>>;
225
+ }, z.core.$strict>;
217
226
  export declare const AutomationChatTargetsQuery: z.ZodObject<{}, z.core.$strict>;
218
227
  export declare const AutomationEventSourcesQuery: z.ZodObject<{}, z.core.$strict>;
219
228
  export declare const AutomationGrantableQuery: z.ZodObject<{
@@ -363,6 +372,8 @@ declare const AutomationUpdateBodyDto_base: import("../infra/validation/create-z
363
372
  export declare class AutomationUpdateBodyDto extends AutomationUpdateBodyDto_base {
364
373
  }
365
374
  declare const AutomationListQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
375
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
376
+ size: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
366
377
  all: z.ZodOptional<z.ZodEnum<{
367
378
  false: "false";
368
379
  true: "true";
@@ -383,6 +394,14 @@ declare const AutomationCalendarQueryDto_base: import("../infra/validation/creat
383
394
  }, z.core.$strict>>;
384
395
  export declare class AutomationCalendarQueryDto extends AutomationCalendarQueryDto_base {
385
396
  }
397
+ declare const AutomationNextRunsQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
398
+ all: z.ZodOptional<z.ZodEnum<{
399
+ false: "false";
400
+ true: "true";
401
+ }>>;
402
+ }, z.core.$strict>>;
403
+ export declare class AutomationNextRunsQueryDto extends AutomationNextRunsQueryDto_base {
404
+ }
386
405
  declare const AutomationChatTargetsQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{}, z.core.$strict>>;
387
406
  export declare class AutomationChatTargetsQueryDto extends AutomationChatTargetsQueryDto_base {
388
407
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { PageQueryFields } from "../infra/paging/paged-read.js";
2
3
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
3
4
  import { IanaTimeZone } from "../time-zone.js";
4
5
  /** Longest task name and prompt, in characters (the same bounds as the service). */
@@ -117,6 +118,8 @@ export const AutomationListQuery = z
117
118
  all: z.enum(["true", "false"]).optional(),
118
119
  /** Only the tasks that post into this conversation (the conversation's side panel). */
119
120
  conversationId: Id.optional(),
121
+ // page numbers without a snapshot (table pagination spec §2.3: tasks are edited in place)
122
+ ...PageQueryFields,
120
123
  })
121
124
  .strict();
122
125
  /** An instant with an offset (`2026-11-09T00:00:00+08:00`). */
@@ -135,6 +138,10 @@ export const AutomationCalendarQuery = z
135
138
  taskId: Id.optional(),
136
139
  })
137
140
  .strict();
141
+ /** `GET …/automations/next-runs`: `all` as the list's (org admins). */
142
+ export const AutomationNextRunsQuery = z
143
+ .object({ all: z.enum(["true", "false"]).optional() })
144
+ .strict();
138
145
  export const AutomationChatTargetsQuery = z.object({}).strict();
139
146
  export const AutomationEventSourcesQuery = z.object({}).strict();
140
147
  export const AutomationGrantableQuery = z.object({ agentId: Id }).strict();
@@ -155,6 +162,8 @@ export class AutomationListQueryDto extends createZodDto(AutomationListQuery, "A
155
162
  }
156
163
  export class AutomationCalendarQueryDto extends createZodDto(AutomationCalendarQuery, "AutomationCalendarQuery") {
157
164
  }
165
+ export class AutomationNextRunsQueryDto extends createZodDto(AutomationNextRunsQuery, "AutomationNextRunsQuery") {
166
+ }
158
167
  export class AutomationChatTargetsQueryDto extends createZodDto(AutomationChatTargetsQuery, "AutomationChatTargetsQuery") {
159
168
  }
160
169
  export class AutomationEventSourcesQueryDto extends createZodDto(AutomationEventSourcesQuery, "AutomationEventSourcesQuery") {
@@ -11,6 +11,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
11
11
  import { KernelDb } from "../infra/database/kernel-db.js";
12
12
  import { TransactionHost } from "../infra/database/transaction-host.js";
13
13
  import { OutboxService } from "../infra/outbox/outbox.service.js";
14
+ import { type Page } from "../infra/paging/paged-read.js";
14
15
  import type { KernelLogger } from "../log.js";
15
16
  import { OrgLock } from "../orgs/org-lock.js";
16
17
  import { ProviderRegistry } from "../runtime/providers.js";
@@ -37,6 +38,11 @@ export type TriggerInput = {
37
38
  types: string[];
38
39
  filter?: EventFilter;
39
40
  };
41
+ /**
42
+ * A task as the web calendar's empty state needs it (`GET …/automations/next-runs`): whether it is
43
+ * active and when it fires next (the next planned run, or "all paused").
44
+ */
45
+ export type AutomationNextRun = Pick<Automation, "id" | "status" | "nextRunAt">;
40
46
  /** One trigger source that serves an org, as the automation form offers it. */
41
47
  export interface EventSourceView {
42
48
  source: string;
@@ -245,11 +251,27 @@ export declare class AutomationsService {
245
251
  get(orgId: string, actor: AutomationActor, id: string): Promise<AutomationView>;
246
252
  /** Each task with its creator as a person, in one query. */
247
253
  private withAccounts;
248
- /** The actor's own tasks; `all` (org admins only, else `forbidden`): every task of the org. */
249
- list(orgId: string, actor: AutomationActor, opts?: {
254
+ /** Every one of the actor's own tasks, newest first (the AutomationList tool). */
255
+ listOwn(orgId: string, actor: AutomationActor): Promise<AutomationListItem[]>;
256
+ /**
257
+ * One page of the actor's own tasks, newest first; `all` (org admins only, else `forbidden`):
258
+ * every task of the org; `conversationId`: only those posting into it. By page number without a
259
+ * snapshot (table pagination spec §2.3: tasks are edited in place).
260
+ */
261
+ list(orgId: string, actor: AutomationActor, opts: {
250
262
  all?: boolean;
251
263
  conversationId?: string;
252
- }): Promise<AutomationListItem[]>;
264
+ page: number;
265
+ size: number;
266
+ }): Promise<Page<AutomationListItem>>;
267
+ /**
268
+ * Every one of the actor's own live tasks, or with `all` (org admins only, else `forbidden`)
269
+ * every live task of the org, newest first, in the compact {@link AutomationNextRun} shape (the
270
+ * calendar's empty state; the task tables read {@link list}).
271
+ */
272
+ nextRuns(orgId: string, actor: AutomationActor, opts: {
273
+ all?: boolean;
274
+ }): Promise<AutomationNextRun[]>;
253
275
  /**
254
276
  * The calendar between two instants (calendar spec §5): the runs and planned occurrences of the
255
277
  * actor's own tasks, or with `all` (org admins only, else `forbidden`) every task of the org; with
@@ -265,11 +287,6 @@ export declare class AutomationsService {
265
287
  all?: boolean;
266
288
  taskId?: string;
267
289
  }, now?: Date, limits?: CalendarLimits): Promise<CalendarAnswer>;
268
- /**
269
- * The tasks of `tasks` that post into the conversation: a `conversation` task naming it, or a
270
- * `chat` task whose chat the conversation is a thread of (spec §10 side panel).
271
- */
272
- private postingInto;
273
290
  /** Each task with its latest settled non-trial run, in one query. */
274
291
  private withLastRuns;
275
292
  /**
@@ -25,6 +25,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
25
25
  import { TransactionHost } from "../infra/database/transaction-host.js";
26
26
  import { Transactional } from "../infra/database/transactional.decorator.js";
27
27
  import { OutboxService } from "../infra/outbox/outbox.service.js";
28
+ import { assertReadablePage, cappedCount, PAGED_TOTAL_CAP, pageOf, pageOffset, } from "../infra/paging/paged-read.js";
28
29
  import { KERNEL_LOGGER } from "../infra/tokens.js";
29
30
  import { OrgLock } from "../orgs/org-lock.js";
30
31
  import { can, roleAtLeast } from "../orgs/roles.js";
@@ -405,23 +406,48 @@ let AutomationsService = class AutomationsService {
405
406
  const people = await loadPeople(this.db.db, tasks.map((t) => t.accountId));
406
407
  return tasks.map((t) => ({ ...t, account: people.get(t.accountId) ?? null }));
407
408
  }
408
- /** The actor's own tasks; `all` (org admins only, else `forbidden`): every task of the org. */
409
- async list(orgId, actor, opts = {}) {
409
+ /** Every one of the actor's own tasks, newest first (the AutomationList tool). */
410
+ async listOwn(orgId, actor) {
411
+ await this.liveRole(orgId, actor.accountId);
412
+ const tasks = await this.store.listForAccount(this.db.db, orgId, actor.accountId);
413
+ return this.withLastRuns(orgId, tasks);
414
+ }
415
+ /**
416
+ * One page of the actor's own tasks, newest first; `all` (org admins only, else `forbidden`):
417
+ * every task of the org; `conversationId`: only those posting into it. By page number without a
418
+ * snapshot (table pagination spec §2.3: tasks are edited in place).
419
+ */
420
+ async list(orgId, actor, opts) {
421
+ assertReadablePage(opts.page, opts.size);
410
422
  const role = await this.liveRole(orgId, actor.accountId);
411
- let tasks;
412
- if (opts.all === true) {
413
- if (!can(role, "automations.manage")) {
414
- throw new ApiError("forbidden", "Only org admins can list every automation");
415
- }
416
- tasks = await this.store.listForOrg(this.db.db, orgId);
417
- }
418
- else {
419
- tasks = await this.store.listForAccount(this.db.db, orgId, actor.accountId);
423
+ if (opts.all === true && !can(role, "automations.manage")) {
424
+ throw new ApiError("forbidden", "Only org admins can list every automation");
420
425
  }
421
- if (opts.conversationId !== undefined) {
422
- tasks = await this.postingInto(orgId, tasks, opts.conversationId);
426
+ const filter = {
427
+ ...(opts.all !== true && { accountId: actor.accountId }),
428
+ ...(opts.conversationId !== undefined && { conversationId: opts.conversationId }),
429
+ };
430
+ const counted = await cappedCount(this.db.db, this.store.matching(this.db.db, orgId, filter), PAGED_TOTAL_CAP);
431
+ const tasks = await this.store.listMatching(this.db.db, orgId, filter, {
432
+ offset: pageOffset(opts.page, opts.size),
433
+ limit: opts.size,
434
+ });
435
+ return pageOf(await this.withLastRuns(orgId, tasks), opts, counted);
436
+ }
437
+ /**
438
+ * Every one of the actor's own live tasks, or with `all` (org admins only, else `forbidden`)
439
+ * every live task of the org, newest first, in the compact {@link AutomationNextRun} shape (the
440
+ * calendar's empty state; the task tables read {@link list}).
441
+ */
442
+ async nextRuns(orgId, actor, opts) {
443
+ const role = await this.liveRole(orgId, actor.accountId);
444
+ if (opts.all === true && !can(role, "automations.manage")) {
445
+ throw new ApiError("forbidden", "Only org admins can list every automation");
423
446
  }
424
- return this.withLastRuns(orgId, tasks);
447
+ const tasks = opts.all === true
448
+ ? await this.store.listForOrg(this.db.db, orgId)
449
+ : await this.store.listForAccount(this.db.db, orgId, actor.accountId);
450
+ return tasks.map((t) => ({ id: t.id, status: t.status, nextRunAt: t.nextRunAt }));
425
451
  }
426
452
  /**
427
453
  * The calendar between two instants (calendar spec §5): the runs and planned occurrences of the
@@ -475,26 +501,6 @@ let AutomationsService = class AutomationsService {
475
501
  collapse: q.taskId === undefined,
476
502
  }, limits);
477
503
  }
478
- /**
479
- * The tasks of `tasks` that post into the conversation: a `conversation` task naming it, or a
480
- * `chat` task whose chat the conversation is a thread of (spec §10 side panel).
481
- */
482
- async postingInto(orgId, tasks, conversationId) {
483
- const chats = tasks.some((t) => t.mode === "chat")
484
- ? await this.db.db
485
- .selectFrom("channel_threads")
486
- .innerJoin("channel_connections", "channel_connections.id", "channel_threads.connection_id")
487
- .select(["channel_threads.connection_id", "channel_threads.chat_id"])
488
- .where("channel_threads.conversation_id", "=", conversationId)
489
- .where("channel_connections.org_id", "=", orgId)
490
- .execute()
491
- : [];
492
- return tasks.filter((t) => t.mode === "conversation"
493
- ? t.conversationId === conversationId
494
- : t.mode === "chat" &&
495
- t.chat !== null &&
496
- chats.some((c) => c.connection_id === t.chat?.connectionId && c.chat_id === t.chat.chatId));
497
- }
498
504
  /** Each task with its latest settled non-trial run, in one query. */
499
505
  async withLastRuns(orgId, plain) {
500
506
  if (plain.length === 0)
@@ -8,6 +8,7 @@ import { KernelConfigService } from "../../infra/config/kernel-config.service.js
8
8
  import { KernelDb } from "../../infra/database/kernel-db.js";
9
9
  import { TransactionHost } from "../../infra/database/transaction-host.js";
10
10
  import { OutboxService } from "../../infra/outbox/outbox.service.js";
11
+ import { type HintPublisher } from "../../invalidation/audiences.js";
11
12
  import type { KernelLogger } from "../../log.js";
12
13
  import { type EffectiveAutomationSettings } from "../effective-settings.js";
13
14
  import { type EventCause, type EventRow } from "./deliver.js";
@@ -99,6 +100,8 @@ export interface RouteContext {
99
100
  * Every read and write filters by the org; the person acts only on their own rules and offers.
100
101
  */
101
102
  export declare class AcceptanceService {
103
+ /** Offers publish `inbox` to their person after the commit. */
104
+ private readonly hints;
102
105
  private readonly kdb;
103
106
  readonly txHost: TransactionHost;
104
107
  private readonly config;
@@ -108,7 +111,9 @@ export declare class AcceptanceService {
108
111
  private readonly inbox;
109
112
  private readonly agents;
110
113
  private readonly displayNames;
111
- constructor(kdb: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get">, points: Pick<ExtensionPointDefaults, "providersFor">, outbox: Pick<OutboxService, "add">, log: Pick<KernelLogger, "info" | "warn">, inbox: Pick<InboxItemsService, "post" | "close">, agents: Pick<AgentLookup, "get">, displayNames: Pick<ExtensionDisplayNames, "many">);
114
+ constructor(
115
+ /** Offers publish `inbox` to their person after the commit. */
116
+ hints: HintPublisher, kdb: KernelDb, txHost: TransactionHost, config: Pick<KernelConfigService, "get">, points: Pick<ExtensionPointDefaults, "providersFor">, outbox: Pick<OutboxService, "add">, log: Pick<KernelLogger, "info" | "warn">, inbox: Pick<InboxItemsService, "post" | "close">, agents: Pick<AgentLookup, "get">, displayNames: Pick<ExtensionDisplayNames, "many">);
112
117
  /**
113
118
  * Routes the pending directed event `ev` (the dispatcher's guards for depth, the source and its
114
119
  * declarations already passed), see the class. The event ends `dispatched` (fired, offered, off
@@ -25,6 +25,9 @@ import { TransactionHost } from "../../infra/database/transaction-host.js";
25
25
  import { Transactional } from "../../infra/database/transactional.decorator.js";
26
26
  import { OutboxService } from "../../infra/outbox/outbox.service.js";
27
27
  import { KERNEL_LOGGER } from "../../infra/tokens.js";
28
+ import { publishAccountInbox } from "../../invalidation/audiences.js";
29
+ import { InvalidationHints } from "../../invalidation/invalidation-hints.js";
30
+ import { InvalidationHintsModule } from "../../invalidation/invalidation-hints.module.js";
28
31
  import { roleAtLeast } from "../../orgs/roles.js";
29
32
  import { pluginDisplayNames } from "../../tools/display-names.js";
30
33
  import { readAutomationSettings } from "../effective-settings.js";
@@ -88,6 +91,7 @@ const webLink = (url) => {
88
91
  * Every read and write filters by the org; the person acts only on their own rules and offers.
89
92
  */
90
93
  let AcceptanceService = class AcceptanceService {
94
+ hints;
91
95
  kdb;
92
96
  txHost;
93
97
  config;
@@ -97,7 +101,10 @@ let AcceptanceService = class AcceptanceService {
97
101
  inbox;
98
102
  agents;
99
103
  displayNames;
100
- constructor(kdb, txHost, config, points, outbox, log, inbox, agents, displayNames) {
104
+ constructor(
105
+ /** Offers publish `inbox` to their person after the commit. */
106
+ hints, kdb, txHost, config, points, outbox, log, inbox, agents, displayNames) {
107
+ this.hints = hints;
101
108
  this.kdb = kdb;
102
109
  this.txHost = txHost;
103
110
  this.config = config;
@@ -357,6 +364,8 @@ let AcceptanceService = class AcceptanceService {
357
364
  .executeTakeFirst();
358
365
  if (row === undefined)
359
366
  return;
367
+ // the offer lists in its person's inbox
368
+ publishAccountInbox(this.hints, [audience.accountId]);
360
369
  const [names, agentName] = await Promise.all([
361
370
  pluginDisplayNames(db, [ev.plugin]),
362
371
  this.agentName(orgId, audience.agentId),
@@ -616,6 +625,7 @@ let AcceptanceService = class AcceptanceService {
616
625
  .where("org_id", "=", orgId)
617
626
  .where("id", "=", offerId)
618
627
  .execute();
628
+ publishAccountInbox(this.hints, [accountId]);
619
629
  if (offer.inbox_item_id !== null)
620
630
  await this.inbox.close(orgId, offer.inbox_item_id);
621
631
  await audit(db, {
@@ -647,6 +657,7 @@ let AcceptanceService = class AcceptanceService {
647
657
  .where("org_id", "=", orgId)
648
658
  .where("id", "=", offerId)
649
659
  .execute();
660
+ publishAccountInbox(this.hints, [accountId]);
650
661
  if (offer.inbox_item_id !== null)
651
662
  await this.inbox.close(orgId, offer.inbox_item_id);
652
663
  await audit(db, {
@@ -729,6 +740,7 @@ let AcceptanceService = class AcceptanceService {
729
740
  .executeTakeFirst();
730
741
  if (row === undefined)
731
742
  return false;
743
+ publishAccountInbox(this.hints, [row.account_id]);
732
744
  if (row.inbox_item_id !== null)
733
745
  await this.inbox.close(orgId, row.inbox_item_id);
734
746
  const ev = await db
@@ -812,15 +824,16 @@ __decorate([
812
824
  ], AcceptanceService.prototype, "expireOffer", null);
813
825
  AcceptanceService = __decorate([
814
826
  Injectable(),
815
- __param(0, Inject(KernelDb)),
816
- __param(1, Inject(TransactionHost)),
817
- __param(2, Inject(KernelConfigService)),
818
- __param(3, Inject(ExtensionPointDefaults)),
819
- __param(4, Inject(OutboxService)),
820
- __param(5, Inject(KERNEL_LOGGER)),
821
- __param(6, Inject(InboxItemsService)),
822
- __param(7, Inject(AgentLookup)),
823
- __param(8, Inject(ExtensionDisplayNames))
827
+ __param(0, Inject(InvalidationHints)),
828
+ __param(1, Inject(KernelDb)),
829
+ __param(2, Inject(TransactionHost)),
830
+ __param(3, Inject(KernelConfigService)),
831
+ __param(4, Inject(ExtensionPointDefaults)),
832
+ __param(5, Inject(OutboxService)),
833
+ __param(6, Inject(KERNEL_LOGGER)),
834
+ __param(7, Inject(InboxItemsService)),
835
+ __param(8, Inject(AgentLookup)),
836
+ __param(9, Inject(ExtensionDisplayNames))
824
837
  ], AcceptanceService);
825
838
  export { AcceptanceService };
826
839
  /**
@@ -831,7 +844,13 @@ let AcceptanceModule = class AcceptanceModule {
831
844
  };
832
845
  AcceptanceModule = __decorate([
833
846
  Module({
834
- imports: [ExtensionsModule, AgentLookupModule, InboxItemsModule],
847
+ imports: [
848
+ // invalidation hints its writers publish after their commit
849
+ InvalidationHintsModule,
850
+ ExtensionsModule,
851
+ AgentLookupModule,
852
+ InboxItemsModule,
853
+ ],
835
854
  providers: [AcceptanceService],
836
855
  exports: [AcceptanceService],
837
856
  })
@@ -64,6 +64,23 @@ export declare class AutomationStore {
64
64
  listForAccount(t: KernelSchemaDb, orgId: string, accountId: string): Promise<Automation[]>;
65
65
  /** Every live task of the org, newest first. */
66
66
  listForOrg(t: KernelSchemaDb, orgId: string): Promise<Automation[]>;
67
+ /**
68
+ * The org's live tasks, newest first (then id), one creator's when `accountId` is given, those
69
+ * posting into `conversationId` when given (a `conversation` task into it, a `chat` task into a
70
+ * chat whose thread it is); `window` is one page of them.
71
+ */
72
+ listMatching(t: KernelSchemaDb, orgId: string, filter: {
73
+ accountId?: string;
74
+ conversationId?: string;
75
+ }, window: {
76
+ offset: number;
77
+ limit: number;
78
+ }): Promise<Automation[]>;
79
+ /** The filtered query of {@link listMatching}, for its count too. */
80
+ matching(t: KernelSchemaDb, orgId: string, filter: {
81
+ accountId?: string;
82
+ conversationId?: string;
83
+ }): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase, "automations", {}>;
67
84
  /** Live tasks that count against the caps (`active` and `paused`), of the org or one creator. */
68
85
  countActive(t: KernelSchemaDb, orgId: string, accountId?: string): Promise<number>;
69
86
  /**
@@ -216,6 +216,41 @@ let AutomationStore = class AutomationStore {
216
216
  .execute();
217
217
  return rows.map(toTask);
218
218
  }
219
+ /**
220
+ * The org's live tasks, newest first (then id), one creator's when `accountId` is given, those
221
+ * posting into `conversationId` when given (a `conversation` task into it, a `chat` task into a
222
+ * chat whose thread it is); `window` is one page of them.
223
+ */
224
+ async listMatching(t, orgId, filter, window) {
225
+ const rows = await this.matching(t, orgId, filter)
226
+ .selectAll()
227
+ .orderBy("created_at", "desc")
228
+ .orderBy("id")
229
+ .offset(window.offset)
230
+ .limit(window.limit)
231
+ .execute();
232
+ return rows.map(toTask);
233
+ }
234
+ /** The filtered query of {@link listMatching}, for its count too. */
235
+ matching(t, orgId, filter) {
236
+ let q = t.selectFrom("automations").where("org_id", "=", orgId).where("deleted_at", "is", null);
237
+ if (filter.accountId !== undefined)
238
+ q = q.where("account_id", "=", filter.accountId);
239
+ const conversationId = filter.conversationId;
240
+ if (conversationId !== undefined) {
241
+ q = q.where(sql `(
242
+ (automations.mode = 'conversation' AND automations.conversation_id = ${conversationId})
243
+ OR (automations.mode = 'chat' AND EXISTS (
244
+ SELECT 1 FROM capybara.channel_threads th
245
+ JOIN capybara.channel_connections cc ON cc.id = th.connection_id
246
+ WHERE th.conversation_id = ${conversationId} AND cc.org_id = ${orgId}
247
+ AND th.connection_id = automations.chat->>'connectionId'
248
+ AND th.chat_id = automations.chat->>'chatId'
249
+ ))
250
+ )`);
251
+ }
252
+ return q;
253
+ }
219
254
  /** Live tasks that count against the caps (`active` and `paused`), of the org or one creator. */
220
255
  async countActive(t, orgId, accountId) {
221
256
  let q = t