@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.
- package/dist/admin/admin-agents.controller.d.ts +3 -5
- package/dist/admin/admin-agents.controller.js +1 -1
- package/dist/admin/admin-connectors.controller.d.ts +3 -5
- package/dist/admin/admin-connectors.controller.js +1 -1
- package/dist/admin/admin-items.schemas.d.ts +6 -6
- package/dist/admin/admin-items.schemas.js +5 -9
- package/dist/admin/admin.controller.d.ts +18 -12
- package/dist/admin/admin.controller.js +29 -15
- package/dist/admin/admin.schemas.d.ts +12 -3
- package/dist/admin/admin.schemas.js +17 -6
- package/dist/agents/admin-agents.d.ts +10 -8
- package/dist/agents/admin-agents.js +13 -9
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.js +1 -1
- package/dist/agents/org-templates.d.ts +3 -1
- package/dist/agents/org-templates.js +7 -3
- package/dist/agents/pending-connector-requests.d.ts +10 -4
- package/dist/agents/pending-connector-requests.js +29 -7
- package/dist/automations/automations.controller.d.ts +9 -5
- package/dist/automations/automations.controller.js +21 -4
- package/dist/automations/automations.schemas.d.ts +19 -0
- package/dist/automations/automations.schemas.js +9 -0
- package/dist/automations/automations.service.d.ts +25 -8
- package/dist/automations/automations.service.js +40 -34
- package/dist/automations/events/acceptance.d.ts +6 -1
- package/dist/automations/events/acceptance.js +30 -11
- package/dist/automations/store.d.ts +17 -0
- package/dist/automations/store.js +35 -0
- package/dist/catalog/admin-catalog.controller.d.ts +64 -2
- package/dist/catalog/admin-catalog.controller.js +17 -0
- package/dist/catalog/catalog-import.module.js +3 -0
- package/dist/catalog/catalog-scope.service.d.ts +3 -1
- package/dist/catalog/catalog-scope.service.js +11 -7
- package/dist/catalog/catalog.module.js +3 -0
- package/dist/catalog/catalog.service.d.ts +3 -1
- package/dist/catalog/catalog.service.js +8 -4
- package/dist/catalog/cli.js +2 -2
- package/dist/catalog/component-promotion.d.ts +3 -1
- package/dist/catalog/component-promotion.js +7 -3
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +7 -3
- package/dist/catalog/enable-requests.d.ts +10 -8
- package/dist/catalog/enable-requests.js +40 -21
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/owned-items.d.ts +3 -1
- package/dist/catalog/owned-items.js +13 -9
- package/dist/catalog/platform-components.d.ts +6 -1
- package/dist/catalog/platform-components.js +9 -3
- package/dist/catalog/plugin-connectors.d.ts +8 -4
- package/dist/catalog/plugin-connectors.js +12 -6
- package/dist/catalog/plugin-import.d.ts +3 -1
- package/dist/catalog/plugin-import.js +14 -5
- package/dist/catalog/plugin-install.d.ts +3 -1
- package/dist/catalog/plugin-install.js +8 -4
- package/dist/catalog/plugin-package.js +2 -1
- package/dist/catalog/plugin-upgrade.d.ts +3 -1
- package/dist/catalog/plugin-upgrade.js +8 -4
- package/dist/catalog/request-hints.d.ts +19 -0
- package/dist/catalog/request-hints.js +34 -0
- package/dist/catalog/request-rules.d.ts +9 -5
- package/dist/catalog/request-rules.js +16 -9
- package/dist/catalog/requests.service.d.ts +3 -1
- package/dist/catalog/requests.service.js +28 -9
- package/dist/catalog/scope-orgs.d.ts +2 -1
- package/dist/catalog/scope-orgs.js +2 -2
- package/dist/catalog/scope-sync.d.ts +3 -1
- package/dist/catalog/scope-sync.js +12 -2
- package/dist/catalog/scope-writer.d.ts +6 -3
- package/dist/catalog/scope-writer.js +28 -10
- package/dist/catalog/unshare.d.ts +3 -2
- package/dist/catalog/unshare.js +4 -4
- package/dist/client/client-access.service.js +29 -1
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +56 -0
- package/dist/ctx/create-ctx.d.ts +2 -19
- package/dist/ctx/create-ctx.js +3 -93
- package/dist/ctx/durable-relay.d.ts +2 -5
- package/dist/ctx/durable-relay.js +56 -29
- package/dist/db/extension-handoff-schema.js +5 -0
- package/dist/db/kernel-schema.d.ts +74 -0
- package/dist/db/migrator.js +36 -0
- package/dist/erasure/account-batches.js +2 -0
- package/dist/erasure/account-residual.js +1 -0
- package/dist/erasure/org-catalog.js +8 -3
- package/dist/erasure/org-rules.js +1 -0
- package/dist/evals/evals.schemas.d.ts +15 -5
- package/dist/evals/evals.schemas.js +17 -10
- package/dist/evals/runs.controller.d.ts +4 -12
- package/dist/evals/runs.controller.js +14 -11
- package/dist/evals/runs.service.d.ts +29 -25
- package/dist/evals/runs.service.js +73 -61
- package/dist/evals/trajectory.controller.d.ts +10 -6
- package/dist/evals/trajectory.controller.js +11 -4
- package/dist/evals/trajectory.service.d.ts +17 -9
- package/dist/evals/trajectory.service.js +52 -35
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +21 -7
- package/dist/extensions/blobs.d.ts +2 -0
- package/dist/extensions/blobs.js +11 -0
- package/dist/extensions/deployment-config.d.ts +6 -1
- package/dist/extensions/deployment-config.js +13 -2
- package/dist/extensions/enabled.d.ts +5 -0
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/grant-epoch.d.ts +108 -0
- package/dist/extensions/grant-epoch.js +214 -0
- package/dist/extensions/host.d.ts +29 -9
- package/dist/extensions/host.js +148 -42
- package/dist/extensions/instance.d.ts +3 -3
- package/dist/extensions/instance.js +1 -1
- package/dist/extensions/isolated/authorization.d.ts +54 -2
- package/dist/extensions/isolated/authorization.js +148 -35
- package/dist/extensions/isolated/child-session.js +0 -1
- package/dist/extensions/isolated/revision.js +1 -1
- package/dist/extensions/org-config.d.ts +3 -1
- package/dist/extensions/org-config.js +13 -4
- package/dist/extensions/org-overrides.d.ts +6 -1
- package/dist/extensions/org-overrides.js +13 -2
- package/dist/extensions/package-digest.job.d.ts +34 -0
- package/dist/extensions/package-digest.job.js +121 -0
- package/dist/extensions/package.js +10 -6
- package/dist/extensions/permission-set.d.ts +14 -78
- package/dist/extensions/permission-set.js +17 -143
- package/dist/extensions/permission-view.d.ts +13 -1
- package/dist/extensions/permission-view.js +20 -0
- package/dist/extensions/registry.js +4 -1
- package/dist/extensions/resolve.d.ts +7 -8
- package/dist/extensions/resolve.js +7 -8
- package/dist/extensions/revision-approvals.d.ts +167 -0
- package/dist/extensions/revision-approvals.js +353 -0
- package/dist/extensions/revision-grants.d.ts +197 -0
- package/dist/extensions/revision-grants.js +584 -0
- package/dist/extensions/state.module.js +12 -1
- package/dist/identity/accounts.d.ts +10 -4
- package/dist/identity/accounts.js +18 -5
- package/dist/inbox/inbox-items.service.d.ts +6 -1
- package/dist/inbox/inbox-items.service.js +29 -10
- package/dist/inbox/inbox.module.js +3 -0
- package/dist/inbox/inbox.service.d.ts +3 -1
- package/dist/inbox/inbox.service.js +9 -2
- package/dist/inbox/org-notices.d.ts +4 -3
- package/dist/inbox/org-notices.js +9 -6
- package/dist/inbox/platform-inbox.service.d.ts +3 -1
- package/dist/inbox/platform-inbox.service.js +11 -3
- package/dist/inbox/platform-notices.d.ts +3 -2
- package/dist/inbox/platform-notices.js +10 -4
- package/dist/infra/config/kernel-config.service.js +4 -1
- package/dist/infra/database/extension-effect-key-lock.js +7 -0
- package/dist/infra/paging/paged-read.d.ts +34 -4
- package/dist/infra/paging/paged-read.js +38 -1
- package/dist/invalidation/audiences.d.ts +32 -0
- package/dist/invalidation/audiences.js +43 -0
- package/dist/invalidation/hints.d.ts +6 -0
- package/dist/invalidation/hints.js +7 -1
- package/dist/invalidation/invalidation-hints.d.ts +12 -1
- package/dist/invalidation/invalidation-hints.js +46 -5
- package/dist/invalidation/invalidation-hints.module.d.ts +2 -0
- package/dist/invalidation/invalidation-hints.module.js +4 -1
- package/dist/invalidation/me-stream.d.ts +1 -11
- package/dist/invalidation/me-stream.js +12 -41
- package/dist/invalidation/org-intent-bridge.d.ts +18 -0
- package/dist/invalidation/org-intent-bridge.js +46 -0
- package/dist/models/enablement.d.ts +3 -1
- package/dist/models/enablement.js +25 -5
- package/dist/orgs/invitations.controller.d.ts +4 -7
- package/dist/orgs/invitations.controller.js +8 -5
- package/dist/orgs/invitations.service.d.ts +17 -3
- package/dist/orgs/invitations.service.js +35 -13
- package/dist/orgs/members.service.d.ts +35 -0
- package/dist/orgs/members.service.js +52 -3
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +7 -3
- package/dist/orgs/orgs.controller.d.ts +11 -4
- package/dist/orgs/orgs.controller.js +25 -5
- package/dist/orgs/orgs.module.js +3 -0
- package/dist/orgs/orgs.schemas.d.ts +14 -0
- package/dist/orgs/orgs.schemas.js +19 -2
- package/dist/orgs/orgs.service.d.ts +24 -2
- package/dist/orgs/orgs.service.js +47 -4
- package/dist/orgs/security-settings.service.d.ts +14 -6
- package/dist/orgs/security-settings.service.js +18 -13
- package/dist/orgs/settings.controller.d.ts +7 -4
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/accounts.ops.js +7 -16
- package/dist/platform/ops/admin-items.ops.js +7 -7
- package/dist/platform/ops/automations.ops.js +6 -4
- package/dist/platform/ops/evals.ops.js +30 -15
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +44 -27
- package/dist/push/delivery.d.ts +3 -1
- package/dist/push/delivery.js +7 -3
- package/dist/push/push-processor.js +8 -1
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/step-log.d.ts +1 -1
- package/dist/runtime/step-log.js +5 -4
- package/dist/runtime/stream-limit.d.ts +13 -0
- package/dist/runtime/stream-limit.js +40 -0
- package/dist/runtime/stream.controller.d.ts +2 -0
- package/dist/runtime/stream.controller.js +2 -0
- package/dist/runtime/stream.d.ts +1 -0
- package/dist/runtime/stream.js +15 -6
- package/dist/sandbox/permission-authority.module.js +6 -1
- package/dist/sandbox/permission-transitions.d.ts +3 -1
- package/dist/sandbox/permission-transitions.js +17 -2
- package/dist/setup/kernel-checks.d.ts +3 -3
- package/dist/setup/kernel-checks.js +4 -4
- package/dist/setup/setup-check-registry.d.ts +16 -5
- package/dist/setup/setup-check-registry.js +11 -3
- package/dist/setup/setup-checks.service.d.ts +1 -2
- package/dist/setup/setup-checks.service.js +7 -6
- package/dist/skills/agent-skills.service.d.ts +6 -1
- package/dist/skills/agent-skills.service.js +12 -3
- package/dist/skills/changes.service.d.ts +6 -1
- package/dist/skills/changes.service.js +11 -3
- package/dist/skills/conversation-catalog.d.ts +3 -0
- package/dist/skills/conversation-catalog.js +2 -0
- package/dist/skills/skills.module.js +3 -0
- package/dist/skills/skills.service.d.ts +3 -1
- package/dist/skills/skills.service.js +8 -4
- package/dist/tools/admin-connectors.d.ts +10 -8
- package/dist/tools/admin-connectors.js +12 -10
- package/dist/tools/approvals.service.d.ts +12 -1
- package/dist/tools/approvals.service.js +36 -9
- package/dist/tools/builtins/automations.d.ts +1 -1
- package/dist/tools/builtins/automations.js +1 -1
- package/dist/tools/connectors.service.d.ts +3 -1
- package/dist/tools/connectors.service.js +29 -7
- package/dist/tools/tools.module.js +3 -0
- package/dist/ui/admin-ui.controller.d.ts +3 -1
- package/dist/ui/admin-ui.controller.js +3 -1
- package/dist/ui/ui-stream.d.ts +2 -0
- package/dist/ui/ui-stream.js +20 -6
- package/dist/ui/views.controller.d.ts +4 -2
- package/dist/ui/views.controller.js +4 -2
- package/package.json +3 -3
- package/src/migrations/0234_extension_grant_epoch.sql +141 -0
- package/src/migrations/0235_extension_revision_grants.sql +166 -0
- package/src/migrations/0236_paged_table_idx.sql +33 -0
- 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
|
-
|
|
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
|
-
|
|
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 /` → `
|
|
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
|
-
|
|
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 /` → `
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
249
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
409
|
-
async
|
|
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
|
-
|
|
412
|
-
|
|
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
|
-
|
|
422
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
816
|
-
__param(1, Inject(
|
|
817
|
-
__param(2, Inject(
|
|
818
|
-
__param(3, Inject(
|
|
819
|
-
__param(4, Inject(
|
|
820
|
-
__param(5, Inject(
|
|
821
|
-
__param(6, Inject(
|
|
822
|
-
__param(7, Inject(
|
|
823
|
-
__param(8, Inject(
|
|
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: [
|
|
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
|