@capybara-hq/kernel 0.1.0-rc.107 → 0.1.0-rc.109

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 (100) hide show
  1. package/bootstrap.json +13 -13
  2. package/dist/automations/acceptance.controller.d.ts +29 -0
  3. package/dist/automations/acceptance.controller.js +87 -0
  4. package/dist/automations/automations.module.js +4 -1
  5. package/dist/automations/automations.schemas.d.ts +46 -0
  6. package/dist/automations/automations.schemas.js +31 -0
  7. package/dist/automations/automations.service.js +10 -1
  8. package/dist/automations/errors.d.ts +5 -0
  9. package/dist/automations/errors.js +5 -0
  10. package/dist/automations/events/acceptance.d.ts +205 -0
  11. package/dist/automations/events/acceptance.js +822 -0
  12. package/dist/automations/events/deliver.d.ts +39 -0
  13. package/dist/automations/events/deliver.js +112 -0
  14. package/dist/automations/events/dispatcher.d.ts +26 -10
  15. package/dist/automations/events/dispatcher.js +98 -99
  16. package/dist/automations/events/sweep.job.d.ts +104 -18
  17. package/dist/automations/events/sweep.job.js +311 -45
  18. package/dist/automations/events/trigger-events.service.d.ts +31 -2
  19. package/dist/automations/events/trigger-events.service.js +113 -30
  20. package/dist/automations/store.d.ts +7 -3
  21. package/dist/automations/store.js +6 -0
  22. package/dist/automations/types.d.ts +5 -0
  23. package/dist/catalog/marketplaces.service.d.ts +1 -1
  24. package/dist/config/schema.d.ts +3 -0
  25. package/dist/config/schema.js +14 -0
  26. package/dist/ctx/create-ctx.d.ts +24 -4
  27. package/dist/ctx/create-ctx.js +119 -6
  28. package/dist/db/kernel-schema.d.ts +89 -1
  29. package/dist/errors.d.ts +18 -0
  30. package/dist/errors.js +18 -0
  31. package/dist/extensions/hooks.d.ts +8 -5
  32. package/dist/extensions/hooks.js +2 -1
  33. package/dist/extensions/host.d.ts +12 -2
  34. package/dist/extensions/host.js +21 -1
  35. package/dist/extensions/lifecycle-hooks.d.ts +21 -7
  36. package/dist/extensions/lifecycle-hooks.js +51 -3
  37. package/dist/extensions/permission-set.d.ts +33 -1
  38. package/dist/extensions/permission-set.js +28 -1
  39. package/dist/extensions/permission-view.d.ts +1 -1
  40. package/dist/extensions/permission-view.js +24 -1
  41. package/dist/extensions/run-lifecycle-owe.d.ts +67 -0
  42. package/dist/extensions/run-lifecycle-owe.js +84 -0
  43. package/dist/http/api.module.js +4 -0
  44. package/dist/inbox/inbox-item-actions.d.ts +37 -0
  45. package/dist/inbox/inbox-item-actions.js +69 -0
  46. package/dist/inbox/inbox-items.controller.d.ts +27 -0
  47. package/dist/inbox/inbox-items.controller.js +80 -0
  48. package/dist/inbox/inbox-items.service.d.ts +110 -0
  49. package/dist/inbox/inbox-items.service.js +324 -0
  50. package/dist/inbox/inbox.module.d.ts +2 -1
  51. package/dist/inbox/inbox.module.js +15 -4
  52. package/dist/inbox/inbox.schemas.d.ts +20 -1
  53. package/dist/inbox/inbox.schemas.js +16 -1
  54. package/dist/inbox/inbox.service.d.ts +29 -7
  55. package/dist/inbox/inbox.service.js +29 -8
  56. package/dist/inbox/token.d.ts +5 -0
  57. package/dist/inbox/token.js +5 -0
  58. package/dist/infra/config/kernel-config.service.js +2 -0
  59. package/dist/infra/outbox/registry.d.ts +17 -0
  60. package/dist/infra/outbox/registry.js +15 -0
  61. package/dist/kernel.module.js +6 -0
  62. package/dist/orgs/settings.service.d.ts +20 -0
  63. package/dist/orgs/settings.service.js +4 -0
  64. package/dist/platform/exclusions.js +15 -0
  65. package/dist/platform/operation.d.ts +8 -0
  66. package/dist/platform/ops/automations.ops.d.ts +3 -1
  67. package/dist/platform/ops/automations.ops.js +45 -3
  68. package/dist/platform/ops/inbox.ops.d.ts +3 -1
  69. package/dist/platform/ops/inbox.ops.js +69 -4
  70. package/dist/platform/ops/platform.ops.js +4 -3
  71. package/dist/plugin-reads/plugin-reads.service.d.ts +29 -0
  72. package/dist/plugin-reads/plugin-reads.service.js +210 -0
  73. package/dist/plugin-reads/token.d.ts +5 -0
  74. package/dist/plugin-reads/token.js +5 -0
  75. package/dist/push/jobs.d.ts +5 -0
  76. package/dist/push/jobs.js +2 -0
  77. package/dist/push/preferences.service.d.ts +2 -2
  78. package/dist/push/preferences.service.js +9 -3
  79. package/dist/push/push-owed.d.ts +2 -0
  80. package/dist/push/push-owed.js +10 -1
  81. package/dist/push/push.schemas.d.ts +5 -2
  82. package/dist/push/push.schemas.js +4 -3
  83. package/dist/push/recipients.d.ts +2 -0
  84. package/dist/push/recipients.js +44 -3
  85. package/dist/push/texts.d.ts +14 -5
  86. package/dist/push/texts.js +2 -1
  87. package/dist/push/triggers.d.ts +1 -1
  88. package/dist/runtime/run-finish.js +19 -1
  89. package/dist/runtime/run-jobs.d.ts +12 -2
  90. package/dist/runtime/run-jobs.js +41 -4
  91. package/dist/runtime/run-queue.js +10 -0
  92. package/dist/runtime/waits.js +24 -1
  93. package/dist/tools/builtins/platform.js +2 -0
  94. package/dist/tools/pipeline.d.ts +5 -0
  95. package/dist/tools/pipeline.js +13 -1
  96. package/dist/tools/registry.d.ts +6 -0
  97. package/package.json +3 -3
  98. package/src/migrations/0192_inbox_items.sql +50 -0
  99. package/src/migrations/0193_trigger_cause_handles.sql +49 -0
  100. package/src/migrations/0194_automation_acceptance.sql +83 -0
package/bootstrap.json CHANGED
@@ -3,15 +3,15 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "87ca221485218c947d592a6642e441620f1f27cc"
6
+ "commit": "5ace2e570721d3ab278f7fd2bffc3d40ec88503a"
7
7
  },
8
8
  "plugins": [
9
9
  {
10
10
  "name": "openai-compatible",
11
11
  "source": "npm",
12
12
  "npm": "@capybara-hq/plugin-openai-compatible",
13
- "version": "0.1.0-rc.14",
14
- "integrity": "sha512-BbB4lSBy4kEZA2kLOBDz00oOOjmQ4IaPPthmho00M15ZGcvDRMTuilw+244lbYPALZ3Kxzo1zNPWFI8STqUyDw==",
13
+ "version": "0.1.0-rc.15",
14
+ "integrity": "sha512-GwDNf+46SwFdDOodWGJokorOWQCvO+0QJx5NhsXChWCnpezmLFiXxgmIuG2V1KNQnRSCvH1SJBUE5EsOTFRvKA==",
15
15
  "required": false
16
16
  },
17
17
  {
@@ -26,40 +26,40 @@
26
26
  "name": "anthropic",
27
27
  "source": "npm",
28
28
  "npm": "@capybara-hq/plugin-anthropic",
29
- "version": "0.1.0-rc.11",
30
- "integrity": "sha512-du0wCj2z3asIZk1mpDOBAtlZSmqB1WQTr8doHb8uPSKGCqfkcCgSVrJWP8dbqW//BHO8un0uWLs74TBvk+f9ug==",
29
+ "version": "0.1.0-rc.12",
30
+ "integrity": "sha512-ABCkExMaGJUxcbDClv2mip931CmQGvbPcy9KV73vYEWUFGf/chU9I1irEKItIbx0I/yJRG1144GkpO3hfcmGrQ==",
31
31
  "required": false
32
32
  },
33
33
  {
34
34
  "name": "openai",
35
35
  "source": "npm",
36
36
  "npm": "@capybara-hq/plugin-openai",
37
- "version": "0.1.0-rc.14",
38
- "integrity": "sha512-Ybde3qfkz0PruixbxzgxrlVYTahz2eplRj4ioeTP20yFQcoPTLbm5hoBuj64nZTKlvTtmYQ+gvK6ofYUWY2NTw==",
37
+ "version": "0.1.0-rc.15",
38
+ "integrity": "sha512-D6iGu0lJMoXxHAPubBxPdF7NK8qxZhzF4DP27fI3p2oA3OvEaysQlU3EhMiGYgB31zjl9dqJMjIgVBaXHL711Q==",
39
39
  "required": false
40
40
  },
41
41
  {
42
42
  "name": "deepseek",
43
43
  "source": "npm",
44
44
  "npm": "@capybara-hq/plugin-deepseek",
45
- "version": "0.1.0-rc.12",
46
- "integrity": "sha512-bDl3SWO/SO23PaY7Jc9km79kctaGYKqjWOTaXcb+olJNHCNwP4lEXuAY7jylBMaDxL3WttWdHDS6c/QjHFbUeA==",
45
+ "version": "0.1.0-rc.13",
46
+ "integrity": "sha512-i6cPL8gTGCvPRdC5UzlKnJdYjrGfPUQHrpdJDp8q8cekMu6GReJQHBFb5dt3U+zlUfOX75IwoIlTPfeJwr/ACg==",
47
47
  "required": false
48
48
  },
49
49
  {
50
50
  "name": "bailian",
51
51
  "source": "npm",
52
52
  "npm": "@capybara-hq/plugin-bailian",
53
- "version": "0.1.0-rc.13",
54
- "integrity": "sha512-TglGdOPeJTUVSxm+KQOdWDrxRnjhFVEatvfQFVkSwOElxocNyEFBm7K3GSQmmuY2ISgxJQceA7Yvjlb0JNpKiA==",
53
+ "version": "0.1.0-rc.14",
54
+ "integrity": "sha512-m1e6FaD0ouHq/2vJkyQPyj3pz4PH7QpYNRlftOJYBaKve8EqKGz/uH44UGBtI+tROmDhdnZ5xn3FFlyyQIYCkA==",
55
55
  "required": false
56
56
  },
57
57
  {
58
58
  "name": "ark",
59
59
  "source": "npm",
60
60
  "npm": "@capybara-hq/plugin-ark",
61
- "version": "0.1.0-rc.14",
62
- "integrity": "sha512-sMyvv8eTeOHnR5WzxRxdYCXMnIn3uiS1kQokSFvojWy8Jk70t/kqMshUgisL+Tl8g3C0SFGwJYqvonWK+NI2jQ==",
61
+ "version": "0.1.0-rc.15",
62
+ "integrity": "sha512-IgsN+PARqkaO6wt5ndM+28UESleVEp0btmH/rUvNAsWp47IghYObGOikYkjHWVlWTApuFefKLkro+fKsS5HHPQ==",
63
63
  "required": false
64
64
  },
65
65
  {
@@ -0,0 +1,29 @@
1
+ import type { z } from "zod";
2
+ import { type Principal } from "../identity/principal.js";
3
+ import { type OrgContext } from "../orgs/org.guard.js";
4
+ import { type AutomationAcceptanceBody, type AutomationAcceptanceQuery, type AutomationOfferParams } from "./automations.schemas.js";
5
+ import { type AcceptanceRulesView, AcceptanceService } from "./events/acceptance.js";
6
+ /**
7
+ * Directed events and acceptance (`/api/v1/orgs/:orgId/automations`, collaboration spec §4.4);
8
+ * human users only (a service token gets 403), each acting on their own rules and offers only:
9
+ * - `GET /acceptance` → `{ items, directedDefault }`: the caller's rule per trigger source that
10
+ * assigns work (has directed event types), null where they follow the org's default;
11
+ * - `PUT /acceptance { rules }` → the same: sets (or, with `mode: null`, removes) the caller's
12
+ * rules;
13
+ * - `POST /offers/:id/accept` → `{ automationId }`: the caller accepts their own work offer, the
14
+ * acceptance automation runs the work;
15
+ * - `POST /offers/:id/decline` → 204: the caller declines it, the person who caused it is told.
16
+ *
17
+ * Another person's offer is 404 `automation.offer_not_found` (org admins included). The org's
18
+ * default is an org setting (`automations.directedDefault`, the org settings route).
19
+ */
20
+ export declare class AcceptanceController {
21
+ private readonly acceptance;
22
+ constructor(acceptance: AcceptanceService);
23
+ rules(principal: Principal, org: OrgContext, _q: z.infer<typeof AutomationAcceptanceQuery>): Promise<AcceptanceRulesView>;
24
+ setRules(principal: Principal, org: OrgContext, body: z.infer<typeof AutomationAcceptanceBody>): Promise<AcceptanceRulesView>;
25
+ accept(principal: Principal, org: OrgContext, params: z.infer<typeof AutomationOfferParams>): Promise<{
26
+ automationId: string;
27
+ }>;
28
+ decline(principal: Principal, org: OrgContext, params: z.infer<typeof AutomationOfferParams>): Promise<void>;
29
+ }
@@ -0,0 +1,87 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Controller, Get, HttpCode, Inject, Post, Put } from "@nestjs/common";
11
+ import { CurrentPrincipal, requireUser } from "../identity/principal.js";
12
+ import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
13
+ import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
14
+ import { AutomationAcceptanceBodyDto, AutomationAcceptanceQueryDto, AutomationOfferParamsDto, } from "./automations.schemas.js";
15
+ import { AcceptanceService } from "./events/acceptance.js";
16
+ /**
17
+ * Directed events and acceptance (`/api/v1/orgs/:orgId/automations`, collaboration spec §4.4);
18
+ * human users only (a service token gets 403), each acting on their own rules and offers only:
19
+ * - `GET /acceptance` → `{ items, directedDefault }`: the caller's rule per trigger source that
20
+ * assigns work (has directed event types), null where they follow the org's default;
21
+ * - `PUT /acceptance { rules }` → the same: sets (or, with `mode: null`, removes) the caller's
22
+ * rules;
23
+ * - `POST /offers/:id/accept` → `{ automationId }`: the caller accepts their own work offer, the
24
+ * acceptance automation runs the work;
25
+ * - `POST /offers/:id/decline` → 204: the caller declines it, the person who caused it is told.
26
+ *
27
+ * Another person's offer is 404 `automation.offer_not_found` (org admins included). The org's
28
+ * default is an org setting (`automations.directedDefault`, the org settings route).
29
+ */
30
+ let AcceptanceController = class AcceptanceController {
31
+ acceptance;
32
+ constructor(acceptance) {
33
+ this.acceptance = acceptance;
34
+ }
35
+ async rules(principal, org, _q) {
36
+ const p = requireUser(principal);
37
+ return this.acceptance.rules(org.orgId, p.account.id);
38
+ }
39
+ async setRules(principal, org, body) {
40
+ const p = requireUser(principal);
41
+ return this.acceptance.setRules(org.orgId, p.account.id, body.rules);
42
+ }
43
+ async accept(principal, org, params) {
44
+ const p = requireUser(principal);
45
+ return this.acceptance.accept(org.orgId, p.account.id, params.id);
46
+ }
47
+ // org.read: a person demoted to guest may still decline what was offered to them
48
+ async decline(principal, org, params) {
49
+ const p = requireUser(principal);
50
+ await this.acceptance.decline(org.orgId, p.account.id, params.id);
51
+ }
52
+ };
53
+ __decorate([
54
+ Get("acceptance"),
55
+ OrgAction("automations.use"),
56
+ __param(0, CurrentPrincipal()),
57
+ __param(1, CurrentOrg()),
58
+ __param(2, ZQuery(AutomationAcceptanceQueryDto))
59
+ ], AcceptanceController.prototype, "rules", null);
60
+ __decorate([
61
+ Put("acceptance"),
62
+ OrgAction("automations.use"),
63
+ __param(0, CurrentPrincipal()),
64
+ __param(1, CurrentOrg()),
65
+ __param(2, ZBody(AutomationAcceptanceBodyDto))
66
+ ], AcceptanceController.prototype, "setRules", null);
67
+ __decorate([
68
+ Post("offers/:id/accept"),
69
+ OrgAction("automations.use"),
70
+ HttpCode(200),
71
+ __param(0, CurrentPrincipal()),
72
+ __param(1, CurrentOrg()),
73
+ __param(2, ZParam(AutomationOfferParamsDto))
74
+ ], AcceptanceController.prototype, "accept", null);
75
+ __decorate([
76
+ Post("offers/:id/decline"),
77
+ OrgAction("org.read"),
78
+ HttpCode(204),
79
+ __param(0, CurrentPrincipal()),
80
+ __param(1, CurrentOrg()),
81
+ __param(2, ZParam(AutomationOfferParamsDto))
82
+ ], AcceptanceController.prototype, "decline", null);
83
+ AcceptanceController = __decorate([
84
+ Controller("api/v1/orgs/:orgId/automations"),
85
+ __param(0, Inject(AcceptanceService))
86
+ ], AcceptanceController);
87
+ export { AcceptanceController };
@@ -20,6 +20,7 @@ import { SandboxModule } from "../sandbox/sandbox.module.js";
20
20
  import { AutomationToolsPort } from "../tools/builtins/automations.js";
21
21
  import { ToolsModule } from "../tools/tools.module.js";
22
22
  import { AutomationsService } from "./automations.service.js";
23
+ import { AcceptanceModule } from "./events/acceptance.js";
23
24
  import { AutomationStoreModule } from "./store.module.js";
24
25
  /**
25
26
  * Automations for people (spec 2026-11-11): the service the HTTP API, the Platform operations
@@ -56,9 +57,11 @@ AutomationsModule = __decorate([
56
57
  SandboxModule,
57
58
  NetworkGrantsModule,
58
59
  DialInModule,
60
+ // directed events: the person's acceptance rules and work offers (collaboration spec §4.4)
61
+ AcceptanceModule,
59
62
  ],
60
63
  providers: [AutomationsService],
61
- exports: [AutomationsService, AutomationStoreModule],
64
+ exports: [AutomationsService, AutomationStoreModule, AcceptanceModule],
62
65
  }),
63
66
  __param(0, Inject(AutomationToolsPort)),
64
67
  __param(1, Inject(AutomationsService))
@@ -423,6 +423,52 @@ declare const AutomationGrantParamsDto_base: import("../infra/validation/create-
423
423
  }, z.core.$strip>>;
424
424
  export declare class AutomationGrantParamsDto extends AutomationGrantParamsDto_base {
425
425
  }
426
+ /** A person's acceptance rule mode for one source's directed events (collaboration spec §4.4). */
427
+ export declare const AcceptanceModeInput: z.ZodEnum<{
428
+ auto: "auto";
429
+ confirm: "confirm";
430
+ off: "off";
431
+ }>;
432
+ /** `GET automations/acceptance`: no query. */
433
+ export declare const AutomationAcceptanceQuery: z.ZodObject<{}, z.core.$strict>;
434
+ /**
435
+ * `PUT automations/acceptance`: the caller's rules to change, each `{ source, mode }`; `mode: null`
436
+ * removes the caller's rule for the source (the org's default applies again).
437
+ */
438
+ export declare const AutomationAcceptanceBody: z.ZodObject<{
439
+ rules: z.ZodArray<z.ZodObject<{
440
+ source: z.ZodString;
441
+ mode: z.ZodNullable<z.ZodEnum<{
442
+ auto: "auto";
443
+ confirm: "confirm";
444
+ off: "off";
445
+ }>>;
446
+ }, z.core.$strict>>;
447
+ }, z.core.$strict>;
448
+ /** `POST automations/offers/:id/accept|decline`. */
449
+ export declare const AutomationOfferParams: z.ZodObject<{
450
+ id: z.ZodString;
451
+ }, z.core.$strip>;
452
+ declare const AutomationAcceptanceQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{}, z.core.$strict>>;
453
+ export declare class AutomationAcceptanceQueryDto extends AutomationAcceptanceQueryDto_base {
454
+ }
455
+ declare const AutomationAcceptanceBodyDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
456
+ rules: z.ZodArray<z.ZodObject<{
457
+ source: z.ZodString;
458
+ mode: z.ZodNullable<z.ZodEnum<{
459
+ auto: "auto";
460
+ confirm: "confirm";
461
+ off: "off";
462
+ }>>;
463
+ }, z.core.$strict>>;
464
+ }, z.core.$strict>>;
465
+ export declare class AutomationAcceptanceBodyDto extends AutomationAcceptanceBodyDto_base {
466
+ }
467
+ declare const AutomationOfferParamsDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
468
+ id: z.ZodString;
469
+ }, z.core.$strip>>;
470
+ export declare class AutomationOfferParamsDto extends AutomationOfferParamsDto_base {
471
+ }
426
472
  /** The automation routes the Platform operations mirror (`check:platform-ops` keys). */
427
473
  export declare const AUTOMATION_ROUTES: readonly RouteSchemas[];
428
474
  /** The object without its undefined properties (the service's inputs take absent, not undefined). */
@@ -171,6 +171,35 @@ export class AutomationGrantsBodyDto extends createZodDto(AutomationGrantsBody,
171
171
  }
172
172
  export class AutomationGrantParamsDto extends createZodDto(AutomationGrantParams, "AutomationGrantParams") {
173
173
  }
174
+ /** A person's acceptance rule mode for one source's directed events (collaboration spec §4.4). */
175
+ export const AcceptanceModeInput = z.enum(["auto", "confirm", "off"]);
176
+ /** `GET automations/acceptance`: no query. */
177
+ export const AutomationAcceptanceQuery = z.object({}).strict();
178
+ /**
179
+ * `PUT automations/acceptance`: the caller's rules to change, each `{ source, mode }`; `mode: null`
180
+ * removes the caller's rule for the source (the org's default applies again).
181
+ */
182
+ export const AutomationAcceptanceBody = z
183
+ .object({
184
+ rules: z
185
+ .array(z
186
+ .object({
187
+ source: z.string().trim().min(1).max(214),
188
+ mode: AcceptanceModeInput.nullable(),
189
+ })
190
+ .strict())
191
+ .min(1)
192
+ .max(100),
193
+ })
194
+ .strict();
195
+ /** `POST automations/offers/:id/accept|decline`. */
196
+ export const AutomationOfferParams = z.object({ id: Id });
197
+ export class AutomationAcceptanceQueryDto extends createZodDto(AutomationAcceptanceQuery, "AutomationAcceptanceQuery") {
198
+ }
199
+ export class AutomationAcceptanceBodyDto extends createZodDto(AutomationAcceptanceBody, "AutomationAcceptanceBody") {
200
+ }
201
+ export class AutomationOfferParamsDto extends createZodDto(AutomationOfferParams, "AutomationOfferParams") {
202
+ }
174
203
  /** The automation routes the Platform operations mirror (`check:platform-ops` keys). */
175
204
  export const AUTOMATION_ROUTES = [
176
205
  { route: "GET /api/v1/orgs/:orgId/automations", query: AutomationListQuery },
@@ -181,6 +210,8 @@ export const AUTOMATION_ROUTES = [
181
210
  route: "GET /api/v1/orgs/:orgId/automations/event-sources",
182
211
  query: AutomationEventSourcesQuery,
183
212
  },
213
+ { route: "GET /api/v1/orgs/:orgId/automations/acceptance", query: AutomationAcceptanceQuery },
214
+ { route: "PUT /api/v1/orgs/:orgId/automations/acceptance", body: AutomationAcceptanceBody },
184
215
  { route: "POST /api/v1/orgs/:orgId/automations", body: AutomationCreateBody },
185
216
  { route: "GET /api/v1/orgs/:orgId/automations/:id", params: AutomationParams },
186
217
  {
@@ -37,7 +37,7 @@ import { isTimeZone } from "../time-zone.js";
37
37
  import { ToolRegistry } from "../tools/registry.js";
38
38
  import { assembleCalendar, CALENDAR_LIMITS, CALENDAR_RANGE_DAYS, CALENDAR_TASK_RANGE_DAYS, calendarRunReadLimit, } from "./calendar.js";
39
39
  import { readAutomationSettings } from "./effective-settings.js";
40
- import { automationDisabled, automationForbidden, automationNotFound, eventSourceUnavailable, eventTypeUnknown, filterInvalid, grantNotAllowed, runNowUnsupported, targetInvalid, } from "./errors.js";
40
+ import { acceptanceFixed, automationDisabled, automationForbidden, automationNotFound, eventSourceUnavailable, eventTypeUnknown, filterInvalid, grantNotAllowed, runNowUnsupported, targetInvalid, } from "./errors.js";
41
41
  import { TriggerSourceTimeout, withDeadline } from "./events/deadline.js";
42
42
  import { validateFilter } from "./events/guards.js";
43
43
  import { GIT_GRANT_SPEC_HASH, GIT_PUSH_GRANT, gitGrantRefusal, grantRefusal, grantRefusalOf, isGitGrantKey, isNetworkGrantKey, isPolicyGrantKey, isTierGrantKey, NETWORK_GRANT_PREFIX, NETWORK_GRANT_SPEC_HASH, networkGrantHost, networkGrantRefusal, normalizeGitGrantKey, tierGrantRefusal, } from "./grant-rules.js";
@@ -202,6 +202,15 @@ let AutomationsService = class AutomationsService {
202
202
  const { role } = await this.orgLock.lockAndAuthorize(orgId, accountId, "automations.use");
203
203
  const t = this.db.db;
204
204
  const task = await this.lockOwn(orgId, accountId, role, id);
205
+ if (task.origin === "acceptance" &&
206
+ (patch.trigger !== undefined ||
207
+ patch.timeZone !== undefined ||
208
+ patch.agentId !== undefined ||
209
+ patch.mode !== undefined ||
210
+ patch.conversationId !== undefined ||
211
+ patch.chat !== undefined)) {
212
+ throw acceptanceFixed();
213
+ }
205
214
  const settings = await readAutomationSettings(t, this.config, orgId);
206
215
  const now = new Date();
207
216
  const changes = {};
@@ -17,3 +17,8 @@ export declare const eventTypeUnknown: (message: string) => ApiError;
17
17
  export declare const runNowUnsupported: () => ApiError;
18
18
  /** A filter clause on a missing, unfilterable or mistyped fact. */
19
19
  export declare const filterInvalid: (message: string) => ApiError;
20
+ /**
21
+ * An edit of an acceptance automation's trigger, agent or target: the kernel keeps them as the
22
+ * person's acceptance rule made them (collaboration spec §4.4).
23
+ */
24
+ export declare const acceptanceFixed: () => ApiError;
@@ -17,3 +17,8 @@ export const eventTypeUnknown = (message) => new ApiError("automation.event_type
17
17
  export const runNowUnsupported = () => new ApiError("automation.run_now_unsupported", "An event automation runs only when its events arrive, so it cannot be run now or as a trial; make an event of its source happen to test it, or switch it to a schedule");
18
18
  /** A filter clause on a missing, unfilterable or mistyped fact. */
19
19
  export const filterInvalid = (message) => new ApiError("automation.filter_invalid", message);
20
+ /**
21
+ * An edit of an acceptance automation's trigger, agent or target: the kernel keeps them as the
22
+ * person's acceptance rule made them (collaboration spec §4.4).
23
+ */
24
+ export const acceptanceFixed = () => new ApiError("automation.acceptance_fixed", "This automation accepts work assigned to you and your agent, so its trigger, agent and target are fixed; change its name, prompt, approved tools or unattended setting, pause it, or change your acceptance rule for the source");
@@ -0,0 +1,205 @@
1
+ import { type LocalizedName, type TriggerEventDeclaration, type TriggerSubject } from "@capybara-hq/plugin-sdk";
2
+ import { AgentLookup } from "../../agents/agent-lookup.js";
3
+ import type { AcceptanceMode } from "../../db/kernel-schema.js";
4
+ import { ExtensionDisplayNames } from "../../extensions/display-name.js";
5
+ import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
6
+ import { InboxItemsService } from "../../inbox/inbox-items.service.js";
7
+ import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
8
+ import { KernelDb } from "../../infra/database/kernel-db.js";
9
+ import { TransactionHost } from "../../infra/database/transaction-host.js";
10
+ import { OutboxService } from "../../infra/outbox/outbox.service.js";
11
+ import type { KernelLogger } from "../../log.js";
12
+ import { type EffectiveAutomationSettings } from "../effective-settings.js";
13
+ import { type EventCause, type EventRow } from "./deliver.js";
14
+ export type { AcceptanceMode } from "../../db/kernel-schema.js";
15
+ /** How long a work offer stays open (collaboration spec §4.4). */
16
+ export declare const OFFER_TTL_SECONDS: number;
17
+ /** The prompt of an acceptance automation (model-visible; the event block carries the work). */
18
+ export declare const ACCEPTANCE_PROMPT = "This work was assigned to you. Read the assigned item, do what it asks within what you are allowed to do, and report what you did.";
19
+ /** A person's acceptance rule for one trigger source with directed event types. */
20
+ export interface AcceptanceRuleView {
21
+ source: string;
22
+ /** The source's display name. */
23
+ name: LocalizedName;
24
+ /** The person's rule; null = they follow the org's `directedDefault`. */
25
+ mode: AcceptanceMode | null;
26
+ }
27
+ /** What `GET automations/acceptance` answers. */
28
+ export interface AcceptanceRulesView {
29
+ items: AcceptanceRuleView[];
30
+ /** The org's default for a source without a rule (`automations.directedDefault`). */
31
+ directedDefault: AcceptanceMode;
32
+ }
33
+ /** An open work offer, as its person's inbox shows it. */
34
+ export interface AutomationOfferView {
35
+ id: string;
36
+ source: string;
37
+ sourceName: LocalizedName;
38
+ agent: {
39
+ id: string;
40
+ name: string;
41
+ };
42
+ eventType: string;
43
+ subject: TriggerSubject;
44
+ /** The extension's summary of what happened (written by people, shown as text). */
45
+ summary: string;
46
+ /** The offer's own inbox item (it carries the push, whose link names it); null if not posted. */
47
+ inboxItemId: string | null;
48
+ createdAt: string;
49
+ expiresAt: string;
50
+ }
51
+ /**
52
+ * What routing a directed event did: `paused` when the rule is `auto` but the person's acceptance
53
+ * automation is paused or ended (nothing runs); `skipped` when its own audience agent caused it
54
+ * (self-trigger) or another dispatch of it settled it first.
55
+ */
56
+ export type RouteOutcome = "fired" | "offered" | "off" | "paused" | "undelivered" | "skipped";
57
+ /** The most open offers one inbox read returns. */
58
+ export declare const OFFERS_LIST_MAX = 100;
59
+ /** What the dispatcher already knows when it hands a directed event over. */
60
+ export interface RouteContext {
61
+ decl: TriggerEventDeclaration;
62
+ /** Every event type the source declares now. */
63
+ declared: readonly TriggerEventDeclaration[];
64
+ cause: EventCause;
65
+ settings: EffectiveAutomationSettings;
66
+ /**
67
+ * The source's `visible()` within its deadline; undefined when it did not answer on the
68
+ * dispatch's last attempt (the dispatcher then left the event `undelivered`).
69
+ */
70
+ visible(accountIds: string[]): Promise<string[] | undefined>;
71
+ }
72
+ /**
73
+ * Directed events and acceptance (collaboration spec §4.4). A directed event names the person and
74
+ * the agent the work is for (`audience`); work runs as that person, with that agent, only within
75
+ * what the person allowed:
76
+ *
77
+ * - **Rules.** The person's rule for the source (`automation_acceptance`), else the org's
78
+ * `automations.directedDefault` (default `auto`): `auto` runs the work through the person's
79
+ * acceptance automation for (source, agent), made by the kernel on first need (owner = the
80
+ * person, `subject` mode, no grants, `unattended_ask = wait`, every directed type of the source);
81
+ * `confirm` posts a work offer to the person's inbox; `off` runs nothing. The rule is read on
82
+ * every event, so switching to `confirm` or `off` takes effect even while the acceptance
83
+ * automation exists, and a paused one runs nothing.
84
+ * - **Guards** (before the rule): the type must be directed; the person must be an active member
85
+ * (member role or above) who may use the agent (`AgentLookup.get`) and whom the source's
86
+ * `visible()` admits, in an org with automations on; otherwise the event is `undelivered`. An
87
+ * event caused by a run of that person on that agent (self-trigger) runs nothing.
88
+ * - **Offers.** Accept (the person's own act, never an agent's) makes or reuses the acceptance
89
+ * automation and delivers the event to it, after checking the guards again; decline tells the
90
+ * person who caused the event (`cause_account_id`, else the cause run's trigger account) through
91
+ * a kernel inbox item. An offer is open for {@link OFFER_TTL_SECONDS}; past it, it is `expired`
92
+ * when next read.
93
+ *
94
+ * Every read and write filters by the org; the person acts only on their own rules and offers.
95
+ */
96
+ export declare class AcceptanceService {
97
+ private readonly kdb;
98
+ readonly txHost: TransactionHost;
99
+ private readonly config;
100
+ private readonly points;
101
+ private readonly outbox;
102
+ private readonly log;
103
+ private readonly inbox;
104
+ private readonly agents;
105
+ private readonly displayNames;
106
+ 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">);
107
+ /**
108
+ * Routes the pending directed event `ev` (the dispatcher's guards for depth, the source and its
109
+ * declarations already passed), see the class. The event ends `dispatched` (fired, offered, off
110
+ * or self-triggered) or `undelivered`.
111
+ */
112
+ route(ev: EventRow, ctx: RouteContext): Promise<RouteOutcome>;
113
+ /** {@link route}'s writes, in one transaction under the event row's lock. */
114
+ private routeIn;
115
+ /**
116
+ * Tells the event's source plugin that directed work was not run (`run.lifecycle`
117
+ * `offer_declined`), owed in the caller's transaction; nothing when the plugin does not
118
+ * subscribe in the org.
119
+ */
120
+ private oweDeclined;
121
+ /**
122
+ * Why the audience cannot receive work, or null: an active member (member role or above) of the
123
+ * org who may use the agent.
124
+ */
125
+ private audienceProblem;
126
+ /** The person's rule for `source`, else the org's default. */
127
+ private modeFor;
128
+ /**
129
+ * The live acceptance automation of (org, person, source, agent), made when missing (see the
130
+ * class); an existing one gains directed types its source declares since. The caller runs it in
131
+ * a transaction; the partial unique index makes two concurrent first events make one.
132
+ */
133
+ private ensureAutomation;
134
+ /** Posts the work offer for `ev` and its inbox item (one offer per event). */
135
+ private offer;
136
+ private agentName;
137
+ private settle;
138
+ /**
139
+ * The caller's rules (`GET automations/acceptance`): each trigger source that serves the org
140
+ * (not switched off) and declares a directed type, with the caller's rule or null, and the org's
141
+ * default. A source whose `events()` fails or times out is left out.
142
+ */
143
+ rules(orgId: string, accountId: string): Promise<AcceptanceRulesView>;
144
+ /**
145
+ * Sets the caller's rules (`PUT automations/acceptance`): each `{ source, mode }` stores the
146
+ * rule, `mode: null` removes it (the org default applies again). A rule for a source that is not
147
+ * a serving source with directed types is `automation.event_source_unavailable`; removing one is
148
+ * always allowed. Returns {@link rules}.
149
+ */
150
+ setRules(orgId: string, accountId: string, rules: readonly {
151
+ source: string;
152
+ mode: AcceptanceMode | null;
153
+ }[]): Promise<AcceptanceRulesView>;
154
+ private writeRules;
155
+ /** The trigger sources that serve the org, are not switched off and declare a directed type. */
156
+ private directedSources;
157
+ /**
158
+ * The caller's open, unexpired offers, newest first (the inbox's `automation_offer` entries).
159
+ */
160
+ openOffers(orgId: string, accountId: string): Promise<AutomationOfferView[]>;
161
+ /**
162
+ * The person accepts their own open offer (`POST automations/offers/:id/accept`): the guards of
163
+ * {@link route} are checked again (`automation.offer_unavailable` when one fails: the source no
164
+ * longer serves the org or shows the subject, the agent cannot be used, automations are off, or
165
+ * the acceptance automation is paused), then the acceptance automation is made or reused and the
166
+ * event delivered to it, and the offer is `accepted`. Another person's offer or an unknown id is
167
+ * `automation.offer_not_found`; one decided or expired is `automation.offer_closed`.
168
+ */
169
+ accept(orgId: string, accountId: string, offerId: string): Promise<{
170
+ automationId: string;
171
+ }>;
172
+ private acceptIn;
173
+ /**
174
+ * The person declines their own open offer (`POST automations/offers/:id/decline`): the offer is
175
+ * `declined`, its inbox item resolved, and the person who caused the event (the event's
176
+ * `cause_account_id`, else the trigger account of the run that caused it; nobody when neither,
177
+ * or when it is the decliner) gets a kernel inbox item `automation_offer_declined`. Errors as
178
+ * {@link accept}'s.
179
+ */
180
+ decline(orgId: string, accountId: string, offerId: string): Promise<void>;
181
+ private declineIn;
182
+ /** Who caused `ev`: its cause account, else its cause run's trigger account, else null. */
183
+ private causerOf;
184
+ /**
185
+ * Marks the open offer `offerId` `expired` when it was made at or before `cutoff` (default: its
186
+ * seven days ago, on the database's clock), resolves its inbox item and tells the event's source
187
+ * plugin (`run.lifecycle` `offer_declined`, reason `expired`), all in one transaction; the trigger
188
+ * event sweep calls it for every stale open offer, and {@link openOffer} for one it finds stale.
189
+ * False when the offer was not open or not yet stale (nothing written).
190
+ */
191
+ expireOffer(orgId: string, offerId: string, cutoff?: Date): Promise<boolean>;
192
+ /**
193
+ * The caller's offer `offerId` and its event, open and unexpired (see {@link accept}'s errors);
194
+ * an offer past its life is marked `expired` ({@link expireOffer}).
195
+ */
196
+ private openOffer;
197
+ /** The caller's offer, locked, still open and unexpired; else `automation.offer_closed`. */
198
+ private lockOpen;
199
+ }
200
+ /**
201
+ * {@link AcceptanceService}: the trigger dispatcher (worker) routes directed events through it; the
202
+ * acceptance routes, the inbox and the Platform operations (API) read and decide through it.
203
+ */
204
+ export declare class AcceptanceModule {
205
+ }