@capybara-hq/kernel 0.1.0-rc.104 → 0.1.0-rc.106

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 (250) hide show
  1. package/dist/agents/agents.schemas.d.ts +9 -9
  2. package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
  3. package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
  4. package/dist/automations/automations.module.d.ts +16 -0
  5. package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
  6. package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
  7. package/dist/automations/automations.schemas.js +253 -0
  8. package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
  9. package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
  10. package/dist/{schedules → automations}/calendar.d.ts +8 -8
  11. package/dist/{schedules → automations}/calendar.js +2 -2
  12. package/dist/automations/effective-settings.d.ts +28 -0
  13. package/dist/automations/effective-settings.js +25 -0
  14. package/dist/automations/errors.d.ts +19 -0
  15. package/dist/automations/errors.js +19 -0
  16. package/dist/automations/events/coalesce.d.ts +28 -0
  17. package/dist/automations/events/coalesce.js +131 -0
  18. package/dist/automations/events/deadline.d.ts +10 -0
  19. package/dist/automations/events/deadline.js +24 -0
  20. package/dist/automations/events/dispatcher.d.ts +74 -0
  21. package/dist/automations/events/dispatcher.js +353 -0
  22. package/dist/automations/events/events.module.d.ts +7 -0
  23. package/dist/automations/events/events.module.js +26 -0
  24. package/dist/automations/events/guards.d.ts +32 -0
  25. package/dist/automations/events/guards.js +87 -0
  26. package/dist/automations/events/sweep.job.d.ts +49 -0
  27. package/dist/automations/events/sweep.job.js +202 -0
  28. package/dist/automations/events/token.d.ts +5 -0
  29. package/dist/automations/events/token.js +5 -0
  30. package/dist/automations/events/trigger-events.service.d.ts +47 -0
  31. package/dist/automations/events/trigger-events.service.js +254 -0
  32. package/dist/{schedules → automations}/fire.d.ts +57 -17
  33. package/dist/{schedules → automations}/fire.js +311 -79
  34. package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
  35. package/dist/{schedules → automations}/grant-rules.js +5 -5
  36. package/dist/automations/job-ids.d.ts +113 -0
  37. package/dist/automations/job-ids.js +117 -0
  38. package/dist/{schedules → automations}/pause.d.ts +3 -3
  39. package/dist/{schedules → automations}/pause.js +3 -3
  40. package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
  41. package/dist/{schedules → automations}/run-tracker.js +68 -56
  42. package/dist/{schedules → automations}/scan.job.d.ts +12 -8
  43. package/dist/{schedules → automations}/scan.job.js +39 -23
  44. package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
  45. package/dist/{schedules → automations}/schedule-math.js +17 -7
  46. package/dist/{schedules → automations}/store.d.ts +57 -27
  47. package/dist/{schedules → automations}/store.js +102 -52
  48. package/dist/automations/store.module.d.ts +6 -0
  49. package/dist/{schedules → automations}/store.module.js +9 -9
  50. package/dist/automations/types.d.ts +178 -0
  51. package/dist/{schedules → automations}/unattended.d.ts +22 -11
  52. package/dist/{schedules → automations}/unattended.js +53 -30
  53. package/dist/catalog/marketplaces.service.d.ts +1 -1
  54. package/dist/channels/channels.module.js +3 -3
  55. package/dist/channels/outbound.d.ts +5 -5
  56. package/dist/channels/outbound.js +17 -17
  57. package/dist/channels/threads.d.ts +1 -1
  58. package/dist/channels/threads.js +1 -1
  59. package/dist/config/schema.d.ts +5 -1
  60. package/dist/config/schema.js +44 -6
  61. package/dist/conversations/approval-profile.d.ts +2 -2
  62. package/dist/conversations/approval-profile.js +3 -3
  63. package/dist/conversations/conversations.controller.d.ts +7 -1
  64. package/dist/conversations/conversations.controller.js +26 -10
  65. package/dist/conversations/conversations.service.d.ts +103 -25
  66. package/dist/conversations/conversations.service.js +138 -33
  67. package/dist/conversations/events.d.ts +48 -1
  68. package/dist/conversations/events.js +61 -9
  69. package/dist/conversations/message-context.d.ts +2 -2
  70. package/dist/conversations/message-context.js +1 -1
  71. package/dist/conversations/permission-profile-store.d.ts +2 -1
  72. package/dist/conversations/permission-profiles.controller.d.ts +3 -0
  73. package/dist/conversations/permission-profiles.service.js +1 -1
  74. package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
  75. package/dist/conversations/prompt-suggestion-request.js +2 -1
  76. package/dist/conversations/queue.d.ts +7 -4
  77. package/dist/conversations/queue.js +6 -2
  78. package/dist/conversations/queue.service.d.ts +5 -5
  79. package/dist/conversations/queue.service.js +20 -14
  80. package/dist/ctx/create-ctx.d.ts +20 -1
  81. package/dist/ctx/create-ctx.js +59 -2
  82. package/dist/db/kernel-schema.d.ts +104 -25
  83. package/dist/devices/device-project-files.service.d.ts +88 -0
  84. package/dist/devices/device-project-files.service.js +249 -0
  85. package/dist/devices/device-projects.service.d.ts +40 -0
  86. package/dist/devices/device-projects.service.js +16 -13
  87. package/dist/devices/devices.controller.d.ts +9 -3
  88. package/dist/devices/devices.controller.js +27 -5
  89. package/dist/devices/devices.module.js +9 -1
  90. package/dist/devices/devices.schemas.js +6 -1
  91. package/dist/devices/dto.d.ts +15 -0
  92. package/dist/devices/dto.js +11 -0
  93. package/dist/devices/project-paths.d.ts +29 -0
  94. package/dist/devices/project-paths.js +66 -0
  95. package/dist/devices/project-rules.d.ts +5 -1
  96. package/dist/devices/project-rules.js +5 -1
  97. package/dist/errors.d.ts +47 -13
  98. package/dist/errors.js +47 -13
  99. package/dist/evals/reconstruct.d.ts +10 -1
  100. package/dist/evals/reconstruct.js +7 -0
  101. package/dist/extensions/host.d.ts +6 -1
  102. package/dist/extensions/host.js +10 -0
  103. package/dist/extensions/permission-set.d.ts +17 -1
  104. package/dist/extensions/permission-set.js +13 -1
  105. package/dist/extensions/permission-view.d.ts +1 -1
  106. package/dist/extensions/permission-view.js +4 -1
  107. package/dist/git/gateway.js +2 -2
  108. package/dist/handoff/app-schemes.d.ts +28 -0
  109. package/dist/handoff/app-schemes.js +41 -0
  110. package/dist/handoff/handoff-paths.d.ts +26 -0
  111. package/dist/handoff/handoff-paths.js +25 -0
  112. package/dist/handoff/handoff-tickets.d.ts +28 -0
  113. package/dist/handoff/handoff-tickets.js +111 -0
  114. package/dist/handoff/handoff.controller.d.ts +24 -0
  115. package/dist/handoff/handoff.controller.js +74 -0
  116. package/dist/handoff/handoff.module.d.ts +7 -0
  117. package/dist/handoff/handoff.module.js +26 -0
  118. package/dist/handoff/handoff.schemas.d.ts +13 -0
  119. package/dist/handoff/handoff.schemas.js +3 -0
  120. package/dist/handoff/handoff.service.d.ts +49 -0
  121. package/dist/handoff/handoff.service.js +96 -0
  122. package/dist/http/api.module.js +13 -5
  123. package/dist/http/meta.controller.d.ts +1 -0
  124. package/dist/http/meta.controller.js +7 -0
  125. package/dist/http/request-signal.d.ts +8 -0
  126. package/dist/http/request-signal.js +14 -0
  127. package/dist/identity/sso.controller.d.ts +30 -6
  128. package/dist/identity/sso.controller.js +51 -17
  129. package/dist/identity/sso.d.ts +10 -2
  130. package/dist/identity/sso.js +15 -3
  131. package/dist/inbox/inbox.module.js +2 -2
  132. package/dist/inbox/inbox.service.d.ts +8 -8
  133. package/dist/inbox/inbox.service.js +7 -7
  134. package/dist/infra/config/kernel-config.service.js +10 -5
  135. package/dist/infra/outbox/registry.d.ts +29 -2
  136. package/dist/infra/outbox/registry.js +30 -7
  137. package/dist/kernel.module.js +3 -0
  138. package/dist/orgs/roles.d.ts +1 -1
  139. package/dist/orgs/roles.js +3 -3
  140. package/dist/orgs/settings.controller.d.ts +1 -1
  141. package/dist/orgs/settings.service.d.ts +27 -11
  142. package/dist/orgs/settings.service.js +42 -24
  143. package/dist/overrides.d.ts +4 -4
  144. package/dist/overrides.js +1 -1
  145. package/dist/platform/exclusions.js +5 -0
  146. package/dist/platform/operation.js +2 -2
  147. package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
  148. package/dist/platform/ops/automations.ops.js +560 -0
  149. package/dist/platform/ops/connectors.ops.js +4 -2
  150. package/dist/platform/ops/devices.ops.d.ts +3 -1
  151. package/dist/platform/ops/devices.ops.js +77 -3
  152. package/dist/platform/ops/inbox.ops.js +4 -4
  153. package/dist/platform/ops/orgs.ops.js +1 -1
  154. package/dist/platform/ops/platform.ops.js +4 -4
  155. package/dist/platform/platform-ops.module.d.ts +2 -2
  156. package/dist/platform/platform-ops.module.js +5 -5
  157. package/dist/platform/route-schemas.js +3 -3
  158. package/dist/push/jobs.d.ts +3 -3
  159. package/dist/push/jobs.js +2 -2
  160. package/dist/push/preferences.service.js +1 -1
  161. package/dist/push/push-owed.d.ts +3 -3
  162. package/dist/push/push-owed.js +6 -6
  163. package/dist/push/push.schemas.d.ts +4 -4
  164. package/dist/push/push.schemas.js +3 -3
  165. package/dist/push/recipients.d.ts +4 -4
  166. package/dist/push/recipients.js +23 -23
  167. package/dist/push/texts.d.ts +3 -3
  168. package/dist/push/texts.js +2 -2
  169. package/dist/push/triggers.d.ts +1 -1
  170. package/dist/roles/worker.module.js +3 -3
  171. package/dist/runtime/compaction.service.d.ts +3 -1
  172. package/dist/runtime/compaction.service.js +3 -1
  173. package/dist/runtime/context/build.d.ts +6 -0
  174. package/dist/runtime/context/build.js +14 -3
  175. package/dist/runtime/context/compaction.d.ts +27 -1
  176. package/dist/runtime/context/compaction.js +102 -37
  177. package/dist/runtime/context/run-context.d.ts +38 -0
  178. package/dist/runtime/context/run-context.js +54 -0
  179. package/dist/runtime/maintenance.d.ts +8 -4
  180. package/dist/runtime/maintenance.js +37 -16
  181. package/dist/runtime/model-call.d.ts +6 -4
  182. package/dist/runtime/model-call.js +17 -7
  183. package/dist/runtime/project/knowledge.service.d.ts +16 -7
  184. package/dist/runtime/project/knowledge.service.js +31 -13
  185. package/dist/runtime/run-finish.d.ts +4 -4
  186. package/dist/runtime/run-finish.js +3 -3
  187. package/dist/runtime/run-queue.js +12 -7
  188. package/dist/runtime/run-worker.js +7 -1
  189. package/dist/runtime/runtime.module.js +3 -3
  190. package/dist/runtime/subagents/dispatch.js +11 -3
  191. package/dist/sandbox/browse-roots.d.ts +8 -0
  192. package/dist/sandbox/browse-roots.js +22 -0
  193. package/dist/sandbox/network-grants.d.ts +4 -4
  194. package/dist/sandbox/network-grants.js +7 -7
  195. package/dist/sandbox/operation-authority.d.ts +10 -3
  196. package/dist/sandbox/operation-authority.js +20 -10
  197. package/dist/sandbox/operation-intents.d.ts +3 -1
  198. package/dist/sandbox/operation-intents.js +11 -4
  199. package/dist/sandbox/permission-call-grants.js +2 -2
  200. package/dist/sandbox/permission-facts.js +1 -1
  201. package/dist/sandbox/review/classifier.d.ts +2 -2
  202. package/dist/sandbox/review/classifier.js +22 -11
  203. package/dist/sandbox/review/permission-candidate.d.ts +1 -1
  204. package/dist/sandbox/review/permission-candidate.js +1 -1
  205. package/dist/sandbox/sandbox.service.d.ts +15 -5
  206. package/dist/sandbox/sandbox.service.js +14 -8
  207. package/dist/storage/purge.d.ts +1 -1
  208. package/dist/storage/purge.js +2 -2
  209. package/dist/tools/approvals.service.d.ts +6 -6
  210. package/dist/tools/approvals.service.js +19 -19
  211. package/dist/tools/builtin-names.d.ts +12 -12
  212. package/dist/tools/builtin-names.js +29 -29
  213. package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
  214. package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
  215. package/dist/tools/builtins/builtin-tools.d.ts +8 -8
  216. package/dist/tools/builtins/builtin-tools.js +16 -16
  217. package/dist/tools/call-scope.d.ts +1 -1
  218. package/dist/tools/connectors.service.d.ts +4 -13
  219. package/dist/tools/connectors.service.js +12 -21
  220. package/dist/tools/git-asks.js +1 -1
  221. package/dist/tools/git-push-policy.d.ts +3 -3
  222. package/dist/tools/git-push-policy.js +6 -6
  223. package/dist/tools/network-asks.d.ts +3 -3
  224. package/dist/tools/network-asks.js +3 -3
  225. package/dist/tools/oauth/flow.d.ts +16 -2
  226. package/dist/tools/oauth/flow.js +23 -4
  227. package/dist/tools/oauth/oauth.controller.d.ts +19 -7
  228. package/dist/tools/oauth/oauth.controller.js +42 -12
  229. package/dist/tools/oauth/oauth.schemas.d.ts +14 -1
  230. package/dist/tools/oauth/oauth.schemas.js +4 -1
  231. package/dist/tools/pipeline.d.ts +4 -4
  232. package/dist/tools/pipeline.js +2 -2
  233. package/dist/tools/policy.d.ts +3 -3
  234. package/dist/tools/policy.js +3 -3
  235. package/dist/tools/tools.module.js +9 -9
  236. package/package.json +3 -3
  237. package/src/migrations/0188_automations_rename.sql +309 -0
  238. package/src/migrations/0189_event_automations.sql +136 -0
  239. package/dist/platform/ops/schedules.ops.js +0 -509
  240. package/dist/schedules/effective-settings.d.ts +0 -22
  241. package/dist/schedules/effective-settings.js +0 -18
  242. package/dist/schedules/errors.d.ts +0 -8
  243. package/dist/schedules/errors.js +0 -8
  244. package/dist/schedules/job-ids.d.ts +0 -81
  245. package/dist/schedules/job-ids.js +0 -95
  246. package/dist/schedules/schedules.module.d.ts +0 -16
  247. package/dist/schedules/schedules.schemas.js +0 -213
  248. package/dist/schedules/store.module.d.ts +0 -6
  249. package/dist/schedules/types.d.ts +0 -110
  250. /package/dist/{schedules → automations}/types.js +0 -0
@@ -0,0 +1,14 @@
1
+ /**
2
+ * An `AbortSignal` tied to one HTTP request: aborted when the connection closes before the
3
+ * response is written (the client hung up), never by a close after a finished response. The same
4
+ * rule as the plugin routes' `req.signal` and the channel webhooks. For a route whose handler asks
5
+ * a device (or another remote) on the request's behalf, so the call stops when nobody waits.
6
+ */
7
+ export function requestSignal(reply) {
8
+ const ac = new AbortController();
9
+ reply.raw.once("close", () => {
10
+ if (!reply.raw.writableFinished)
11
+ ac.abort();
12
+ });
13
+ return ac.signal;
14
+ }
@@ -1,5 +1,6 @@
1
1
  import type { FastifyReply, FastifyRequest } from "fastify";
2
2
  import { z } from "zod";
3
+ import { HandoffTickets } from "../handoff/handoff-tickets.js";
3
4
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
4
5
  import { CredentialThrottler } from "../infra/throttler/credential-throttler.js";
5
6
  import { type Account, AccountsService } from "./accounts.js";
@@ -15,10 +16,32 @@ declare const LinkBodySchema: z.ZodObject<{
15
16
  login: z.ZodString;
16
17
  password: z.ZodString;
17
18
  }, z.core.$strip>;
19
+ /**
20
+ * `POST /auth/sso/:plugin/start`: a link intent and the page to come back to. `handoff` (a native
21
+ * shell): finish the link in the system browser through a handoff ticket instead.
22
+ */
18
23
  declare const StartLinkBodySchema: z.ZodObject<{
19
24
  intent: z.ZodLiteral<"link">;
20
25
  returnTo: z.ZodOptional<z.ZodString>;
26
+ handoff: z.ZodOptional<z.ZodObject<{
27
+ returnScheme: z.ZodOptional<z.ZodString>;
28
+ }, z.core.$strict>>;
21
29
  }, z.core.$strip>;
30
+ /**
31
+ * The link start's answer: where the browser goes next (the source's authorize URL, or the page
32
+ * with `?error=<code>`), or with `handoff` the web page that starts the link in the system browser.
33
+ */
34
+ export type SsoStartLinkResponse = {
35
+ location: string;
36
+ } | {
37
+ handoffUrl: string;
38
+ };
39
+ /**
40
+ * Writes the SSO browser binding cookie `cap_sso` (HttpOnly, SameSite=Lax: the source's redirect
41
+ * back is a cross-site top-level GET, which Lax sends; Path only `/api/v1/auth/sso`). `secure` is
42
+ * {@link SsoFlow.cookieSecure}.
43
+ */
44
+ export declare function setSsoBindingCookie(reply: FastifyReply, binding: string, secure: boolean, maxAge?: number): void;
22
45
  /** What the link page shows (`GET /api/v1/auth/sso/link`). */
23
46
  export interface SsoLinkView {
24
47
  plugin: string;
@@ -44,7 +67,8 @@ export declare class SsoController {
44
67
  private readonly linkTickets;
45
68
  private readonly external;
46
69
  private readonly throttler;
47
- constructor(flow: SsoFlow, sessions: SessionService, accounts: AccountsService, config: KernelConfigService, linkTickets: SsoLinkTickets, external: ExternalIdentities, throttler: CredentialThrottler);
70
+ private readonly tickets;
71
+ constructor(flow: SsoFlow, sessions: SessionService, accounts: AccountsService, config: KernelConfigService, linkTickets: SsoLinkTickets, external: ExternalIdentities, throttler: CredentialThrottler, tickets: HandoffTickets);
48
72
  sources(): Promise<{
49
73
  sources: {
50
74
  plugin: string;
@@ -68,12 +92,12 @@ export declare class SsoController {
68
92
  * method it needs the CSRF header (global guard), so no other site can start it. The state
69
93
  * records the session's account; the callback must carry the same session. Writes the binding
70
94
  * cookie as the GET start does and returns where the browser goes next: the source's authorize
71
- * URL, or, on failure, the page with `?error=<code>`.
95
+ * URL, or, on failure, the page with `?error=<code>`. With `handoff` (a native shell, shell
96
+ * external authorization spec §1): no cookie and no state; a source on offer gets a handoff
97
+ * ticket and its web page, where the link starts when the person redeems it in the system
98
+ * browser; a source not on offer answers the same `?error=sso.unavailable` location.
72
99
  */
73
- startLink(plugin: string, body: z.infer<typeof StartLinkBodySchema>, principal: Principal, req: FastifyRequest, reply: FastifyReply): Promise<{
74
- location: string;
75
- }>;
76
- private setBindingCookie;
100
+ startLink(plugin: string, body: z.infer<typeof StartLinkBodySchema>, principal: Principal, req: FastifyRequest, reply: FastifyReply): Promise<SsoStartLinkResponse>;
77
101
  /**
78
102
  * The identity source's redirect back: state and binding cookie checked → the plugin verifies
79
103
  * the external identity → spec §4's decision ({@link SsoFlow.callback}). A sign-in creates a
@@ -10,6 +10,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Controller, Delete, Get, HttpCode, Inject, Param, Post, Query, Req, Res, } from "@nestjs/common";
11
11
  import { z } from "zod";
12
12
  import { ApiError } from "../errors.js";
13
+ import { assertReturnSchemeAllowed, HandoffRequestSchema } from "../handoff/app-schemes.js";
14
+ import { HandoffTickets } from "../handoff/handoff-tickets.js";
13
15
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
14
16
  import { CredentialThrottler } from "../infra/throttler/credential-throttler.js";
15
17
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
@@ -22,7 +24,7 @@ import { ExternalIdentities } from "./external.js";
22
24
  import { LinkedAccountsService, } from "./linked-accounts.js";
23
25
  import { CurrentPrincipal, Public, requireUser, SessionOnly } from "./principal.js";
24
26
  import { SessionService } from "./sessions.js";
25
- import { SSO_BINDING_COOKIE, SSO_COOKIE_PATH, SSO_STATE_TTL_SECONDS, SsoFlow, ssoBrowserBinding, withError, } from "./sso.js";
27
+ import { SSO_BINDING_COOKIE, SSO_COOKIE_PATH, SSO_STATE_TTL_SECONDS, SsoFlow, safeReturnTo, ssoBrowserBinding, withError, } from "./sso.js";
26
28
  import { linkExpired, SSO_LINK_PAGE_PATH, SSO_LINK_TTL_SECONDS, SsoLinkTickets, } from "./sso-link.js";
27
29
  const LinkBodySchema = z.object({
28
30
  ticket: z.string().max(100),
@@ -31,12 +33,31 @@ const LinkBodySchema = z.object({
31
33
  });
32
34
  class LinkBody extends createZodDto(LinkBodySchema, "SsoLinkBody") {
33
35
  }
36
+ /**
37
+ * `POST /auth/sso/:plugin/start`: a link intent and the page to come back to. `handoff` (a native
38
+ * shell): finish the link in the system browser through a handoff ticket instead.
39
+ */
34
40
  const StartLinkBodySchema = z.object({
35
41
  intent: z.literal("link"),
36
42
  returnTo: z.string().max(2000).optional(),
43
+ handoff: HandoffRequestSchema.optional(),
37
44
  });
38
45
  class StartLinkBody extends createZodDto(StartLinkBodySchema, "SsoStartLinkBody") {
39
46
  }
47
+ /**
48
+ * Writes the SSO browser binding cookie `cap_sso` (HttpOnly, SameSite=Lax: the source's redirect
49
+ * back is a cross-site top-level GET, which Lax sends; Path only `/api/v1/auth/sso`). `secure` is
50
+ * {@link SsoFlow.cookieSecure}.
51
+ */
52
+ export function setSsoBindingCookie(reply, binding, secure, maxAge = SSO_STATE_TTL_SECONDS) {
53
+ reply.setCookie(SSO_BINDING_COOKIE, binding, {
54
+ path: SSO_COOKIE_PATH,
55
+ httpOnly: true,
56
+ sameSite: "lax",
57
+ secure,
58
+ maxAge,
59
+ });
60
+ }
40
61
  const MAX_QUERY_KEYS = 50;
41
62
  const MAX_QUERY_VALUE = 4096;
42
63
  /** 查询参数只取单值字符串(重复参数 / 数组 / 超长值丢弃)。 */
@@ -60,7 +81,8 @@ let SsoController = class SsoController {
60
81
  linkTickets;
61
82
  external;
62
83
  throttler;
63
- constructor(flow, sessions, accounts, config, linkTickets, external, throttler) {
84
+ tickets;
85
+ constructor(flow, sessions, accounts, config, linkTickets, external, throttler, tickets) {
64
86
  this.flow = flow;
65
87
  this.sessions = sessions;
66
88
  this.accounts = accounts;
@@ -68,6 +90,7 @@ let SsoController = class SsoController {
68
90
  this.linkTickets = linkTickets;
69
91
  this.external = external;
70
92
  this.throttler = throttler;
93
+ this.tickets = tickets;
71
94
  }
72
95
  async sources() {
73
96
  return { sources: await this.flow.sources() };
@@ -89,7 +112,7 @@ let SsoController = class SsoController {
89
112
  }
90
113
  const binding = ssoBrowserBinding(req.cookies[SSO_BINDING_COOKIE]);
91
114
  const location = await this.flow.start(plugin, typeof returnTo === "string" ? returnTo : undefined, binding);
92
- this.setBindingCookie(reply, binding, SSO_STATE_TTL_SECONDS);
115
+ setSsoBindingCookie(reply, binding, this.flow.cookieSecure());
93
116
  await reply.header("cache-control", "no-store").redirect(location, 302);
94
117
  }
95
118
  /**
@@ -97,25 +120,35 @@ let SsoController = class SsoController {
97
120
  * method it needs the CSRF header (global guard), so no other site can start it. The state
98
121
  * records the session's account; the callback must carry the same session. Writes the binding
99
122
  * cookie as the GET start does and returns where the browser goes next: the source's authorize
100
- * URL, or, on failure, the page with `?error=<code>`.
123
+ * URL, or, on failure, the page with `?error=<code>`. With `handoff` (a native shell, shell
124
+ * external authorization spec §1): no cookie and no state; a source on offer gets a handoff
125
+ * ticket and its web page, where the link starts when the person redeems it in the system
126
+ * browser; a source not on offer answers the same `?error=sso.unavailable` location.
101
127
  */
102
128
  async startLink(plugin, body, principal, req, reply) {
103
129
  const p = requireUser(principal);
130
+ reply.header("cache-control", "no-store");
131
+ if (body.handoff !== undefined) {
132
+ const returnScheme = body.handoff.returnScheme;
133
+ assertReturnSchemeAllowed(this.config.get(), returnScheme);
134
+ const returnTo = safeReturnTo(body.returnTo);
135
+ if (!(await this.flow.linkAvailable(plugin))) {
136
+ return { location: this.flow.webUrl(withError(returnTo, "sso.unavailable")) };
137
+ }
138
+ const ticket = await this.tickets.create({
139
+ kind: "identity-link",
140
+ accountId: p.account.id,
141
+ plugin,
142
+ returnTo,
143
+ ...(returnScheme !== undefined && { returnScheme }),
144
+ });
145
+ return { handoffUrl: this.tickets.url(ticket) };
146
+ }
104
147
  const binding = ssoBrowserBinding(req.cookies[SSO_BINDING_COOKIE]);
105
148
  const location = await this.flow.start(plugin, body.returnTo, binding, p.account.id, body.intent);
106
- this.setBindingCookie(reply, binding, SSO_STATE_TTL_SECONDS);
107
- reply.header("cache-control", "no-store");
149
+ setSsoBindingCookie(reply, binding, this.flow.cookieSecure());
108
150
  return { location };
109
151
  }
110
- setBindingCookie(reply, binding, maxAge) {
111
- reply.setCookie(SSO_BINDING_COOKIE, binding, {
112
- path: SSO_COOKIE_PATH,
113
- httpOnly: true,
114
- sameSite: "lax",
115
- secure: this.flow.cookieSecure(),
116
- maxAge,
117
- });
118
- }
119
152
  /**
120
153
  * The identity source's redirect back: state and binding cookie checked → the plugin verifies
121
154
  * the external identity → spec §4's decision ({@link SsoFlow.callback}). A sign-in creates a
@@ -137,7 +170,7 @@ let SsoController = class SsoController {
137
170
  }
138
171
  else if (r.kind === "link_page") {
139
172
  // the binding value is the one the state was checked against
140
- this.setBindingCookie(reply, binding, SSO_LINK_TTL_SECONDS);
173
+ setSsoBindingCookie(reply, binding, this.flow.cookieSecure(), SSO_LINK_TTL_SECONDS);
141
174
  const target = this.flow.webUrl(`${SSO_LINK_PAGE_PATH}?ticket=${encodeURIComponent(r.ticket)}`);
142
175
  await reply.header("cache-control", "no-store").redirect(target, 302);
143
176
  return;
@@ -302,7 +335,8 @@ SsoController = __decorate([
302
335
  __param(3, Inject(KernelConfigService)),
303
336
  __param(4, Inject(SsoLinkTickets)),
304
337
  __param(5, Inject(ExternalIdentities)),
305
- __param(6, Inject(CredentialThrottler))
338
+ __param(6, Inject(CredentialThrottler)),
339
+ __param(7, Inject(HandoffTickets))
306
340
  ], SsoController);
307
341
  export { SsoController };
308
342
  const identityTaken = () => new ApiError("identity.taken", "This external identity is already linked to another account");
@@ -1,6 +1,7 @@
1
1
  import { type IdentitySource, type Logger } from "@capybara-hq/plugin-sdk";
2
2
  import type { Redis } from "ioredis";
3
3
  import { ExtensionRegistry } from "../extensions/registry.js";
4
+ import { type HandoffRecord } from "../handoff/handoff-paths.js";
4
5
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
5
6
  import { ExternalIdentities } from "./external.js";
6
7
  import { LoginSourcesService } from "./login-sources.js";
@@ -94,6 +95,11 @@ export declare class SsoFlow {
94
95
  private entry;
95
96
  /** The identity source of `plugin` when its login source is on offer (see {@link sources}). */
96
97
  provider(plugin: string): Promise<IdentitySource | undefined>;
98
+ /**
99
+ * Whether a link intent of `plugin` can start now: its login source is on offer and
100
+ * `http.publicUrl` is set (otherwise {@link start} answers `sso.unavailable`).
101
+ */
102
+ linkAvailable(plugin: string): Promise<boolean>;
97
103
  private redirectUri;
98
104
  /** 绑定 Cookie 是否加 Secure:`auth.cookieSecure`,或 `http.publicUrl` 是 https(浏览器经 https 访问)。 */
99
105
  cookieSecure(): boolean;
@@ -107,9 +113,11 @@ export declare class SsoFlow {
107
113
  * the sign-in page; a link intent's back to its page with `?error=<code>`. A link intent needs
108
114
  * the web session's account and must come from a CSRF-protected request (the controller's
109
115
  * `POST …/start`; a cross-site top-level GET carries the Lax session cookie, so a GET start never
110
- * links). `binding` is this browser's binding value (the controller writes the cookie).
116
+ * links). `binding` is this browser's binding value (the controller writes the cookie). With
117
+ * `handoff` (a browser handoff redeemed in this browser), the return page is the handoff done
118
+ * page the kernel builds from the ticket's record, and `returnTo` is ignored.
111
119
  */
112
- start(plugin: string, returnTo: string | undefined, binding: string, sessionAccountId?: string, intent?: SsoIntent): Promise<string>;
120
+ start(plugin: string, returnTo: string | undefined, binding: string, sessionAccountId?: string, intent?: SsoIntent, handoff?: HandoffRecord): Promise<string>;
113
121
  /**
114
122
  * Handles the identity source's redirect back. The state is read and deleted in one step (it can
115
123
  * never be used again, whatever the outcome); a state that belongs to another plugin →
@@ -12,6 +12,7 @@ import { isIdentitySourceRefused } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
13
  import { ApiError } from "../errors.js";
14
14
  import { ExtensionRegistry } from "../extensions/registry.js";
15
+ import { handoffDonePath } from "../handoff/handoff-paths.js";
15
16
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
16
17
  import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
17
18
  import { isSafeReturnPath } from "../tools/oauth/flow-paths.js";
@@ -105,6 +106,15 @@ let SsoFlow = class SsoFlow {
105
106
  async provider(plugin) {
106
107
  return (await this.entry(plugin))?.source;
107
108
  }
109
+ /**
110
+ * Whether a link intent of `plugin` can start now: its login source is on offer and
111
+ * `http.publicUrl` is set (otherwise {@link start} answers `sso.unavailable`).
112
+ */
113
+ async linkAvailable(plugin) {
114
+ if (!this.config.get().http.publicUrl)
115
+ return false;
116
+ return (await this.provider(plugin)) !== undefined;
117
+ }
108
118
  redirectUri(plugin) {
109
119
  const base = (this.config.get().http.publicUrl ?? "").replace(/\/+$/, "");
110
120
  return `${base}${ssoCallbackPath(plugin)}`;
@@ -129,10 +139,12 @@ let SsoFlow = class SsoFlow {
129
139
  * the sign-in page; a link intent's back to its page with `?error=<code>`. A link intent needs
130
140
  * the web session's account and must come from a CSRF-protected request (the controller's
131
141
  * `POST …/start`; a cross-site top-level GET carries the Lax session cookie, so a GET start never
132
- * links). `binding` is this browser's binding value (the controller writes the cookie).
142
+ * links). `binding` is this browser's binding value (the controller writes the cookie). With
143
+ * `handoff` (a browser handoff redeemed in this browser), the return page is the handoff done
144
+ * page the kernel builds from the ticket's record, and `returnTo` is ignored.
133
145
  */
134
- async start(plugin, returnTo, binding, sessionAccountId, intent = "signin") {
135
- const back = safeReturnTo(returnTo);
146
+ async start(plugin, returnTo, binding, sessionAccountId, intent = "signin", handoff) {
147
+ const back = handoff !== undefined ? handoffDonePath(handoff) : safeReturnTo(returnTo);
136
148
  const fail = (code) => intent === "link" ? this.webUrl(withError(back, code)) : this.loginError(code);
137
149
  if (intent === "link" && sessionAccountId === undefined) {
138
150
  return this.loginError("sso.session_mismatch");
@@ -5,8 +5,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Module } from "@nestjs/common";
8
+ import { AutomationsModule } from "../automations/automations.module.js";
8
9
  import { CatalogModule } from "../catalog/catalog.module.js";
9
- import { SchedulesModule } from "../schedules/schedules.module.js";
10
10
  import { SkillsModule } from "../skills/skills.module.js";
11
11
  import { ToolsModule } from "../tools/tools.module.js";
12
12
  import { InboxService } from "./inbox.service.js";
@@ -19,7 +19,7 @@ let InboxModule = class InboxModule {
19
19
  };
20
20
  InboxModule = __decorate([
21
21
  Module({
22
- imports: [ToolsModule, SkillsModule, CatalogModule, SchedulesModule],
22
+ imports: [ToolsModule, SkillsModule, CatalogModule, AutomationsModule],
23
23
  providers: [InboxService, PlatformInboxService],
24
24
  exports: [InboxService, PlatformInboxService],
25
25
  })
@@ -1,6 +1,6 @@
1
+ import { type AutomationAttention, AutomationsService } from "../automations/automations.service.js";
1
2
  import { CatalogRequestsService, type CatalogRequestView } from "../catalog/requests.service.js";
2
3
  import { KernelDb } from "../infra/database/kernel-db.js";
3
- import { type ScheduleAttention, ScheduledTasksService } from "../schedules/scheduled-tasks.service.js";
4
4
  import { SkillChangesService, type SkillChangeView } from "../skills/changes.service.js";
5
5
  import { ApprovalsService, type ApprovalView } from "../tools/approvals.service.js";
6
6
  import type { OrgNoticeDetails } from "./org-notices.js";
@@ -34,7 +34,7 @@ export declare const INBOX_MAX_ITEMS = 100;
34
34
  * (M6 T26, C22; plugin scope spec §5.1);
35
35
  * - `catalog_request_decided`: the current user's own requests in this org that were approved or
36
36
  * rejected (with the reason), until dismissed (`POST catalog-requests/:id/dismiss`);
37
- * - `schedule_attention`: the current user's own scheduled task that needs them (spec §8): paused
37
+ * - `automation_attention`: the current user's own automation that needs them (spec §8): paused
38
38
  * for any reason but their own pause, its latest run failed, or its latest run was refused tools
39
39
  * or connections; derived live, gone once the task is resumed or runs clean;
40
40
  * - the org notices (`item_shared`, `shared_item_updated`, `upload_confirmed`,
@@ -63,19 +63,19 @@ export type InboxItem = {
63
63
  createdAt: string;
64
64
  request: CatalogRequestView;
65
65
  } | {
66
- type: "schedule_attention";
66
+ type: "automation_attention";
67
67
  /** `<taskId>:paused`, `<taskId>:failed` or `<taskId>:grants`. */
68
68
  id: string;
69
69
  createdAt: string;
70
- attention: ScheduleAttentionView;
70
+ attention: AutomationAttentionView;
71
71
  } | {
72
72
  type: OrgNoticeView["kind"];
73
73
  id: string;
74
74
  createdAt: string;
75
75
  notice: OrgNoticeView;
76
76
  };
77
- /** A scheduled task that needs its creator ({@link ScheduleAttention}, dates as ISO strings). */
78
- export type ScheduleAttentionView = Omit<ScheduleAttention, "at">;
77
+ /** An automation that needs its creator ({@link AutomationAttention}, dates as ISO strings). */
78
+ export type AutomationAttentionView = Omit<AutomationAttention, "at">;
79
79
  /** `GET /inbox` 的结果:新的在前,最多 {@link INBOX_MAX_ITEMS} 项;`truncated` 为 true 表示还有更多。 */
80
80
  export interface InboxView {
81
81
  items: InboxItem[];
@@ -87,8 +87,8 @@ export declare class InboxService {
87
87
  private readonly skillChanges;
88
88
  private readonly kdb;
89
89
  private readonly catalogRequests;
90
- private readonly schedules;
91
- constructor(approvals: Pick<ApprovalsService, "list">, skillChanges: Pick<SkillChangesService, "listPending">, kdb: KernelDb, catalogRequests: Pick<CatalogRequestsService, "listForOrgAdmin" | "listDecidedForRequester">, schedules: Pick<ScheduledTasksService, "attentionFor">);
90
+ private readonly automations;
91
+ constructor(approvals: Pick<ApprovalsService, "list">, skillChanges: Pick<SkillChangesService, "listPending">, kdb: KernelDb, catalogRequests: Pick<CatalogRequestsService, "listForOrgAdmin" | "listDecidedForRequester">, automations: Pick<AutomationsService, "attentionFor">);
92
92
  list(orgId: string, accountId: string): Promise<InboxView>;
93
93
  /** The org's open notices when the account is an org admin (else none), newest first. */
94
94
  private notices;
@@ -9,11 +9,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
+ import { AutomationsService, } from "../automations/automations.service.js";
12
13
  import { CATALOG_REQUESTS_LIST_MAX, CatalogRequestsService, } from "../catalog/requests.service.js";
13
14
  import { ApiError } from "../errors.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
15
16
  import { roleAtLeast } from "../orgs/roles.js";
16
- import { ScheduledTasksService, } from "../schedules/scheduled-tasks.service.js";
17
17
  import { SKILL_CHANGES_LIST_MAX, SkillChangesService, } from "../skills/changes.service.js";
18
18
  import { APPROVALS_LIST_MAX, ApprovalsService, } from "../tools/approvals.service.js";
19
19
  /** The most open org notices one inbox read returns. */
@@ -26,13 +26,13 @@ let InboxService = class InboxService {
26
26
  skillChanges;
27
27
  kdb;
28
28
  catalogRequests;
29
- schedules;
30
- constructor(approvals, skillChanges, kdb, catalogRequests, schedules) {
29
+ automations;
30
+ constructor(approvals, skillChanges, kdb, catalogRequests, automations) {
31
31
  this.approvals = approvals;
32
32
  this.skillChanges = skillChanges;
33
33
  this.kdb = kdb;
34
34
  this.catalogRequests = catalogRequests;
35
- this.schedules = schedules;
35
+ this.automations = automations;
36
36
  }
37
37
  async list(orgId, accountId) {
38
38
  const [approvals, changes, requests, decided, notices, attention] = await Promise.all([
@@ -41,7 +41,7 @@ let InboxService = class InboxService {
41
41
  this.catalogRequests.listForOrgAdmin(orgId, accountId),
42
42
  this.catalogRequests.listDecidedForRequester(orgId, accountId),
43
43
  this.notices(orgId, accountId),
44
- this.schedules.attentionFor(orgId, accountId),
44
+ this.automations.attentionFor(orgId, accountId),
45
45
  ]);
46
46
  const all = [
47
47
  ...approvals.map((a) => ({
@@ -69,7 +69,7 @@ let InboxService = class InboxService {
69
69
  request: r,
70
70
  })),
71
71
  ...attention.map(({ at, ...view }) => ({
72
- type: "schedule_attention",
72
+ type: "automation_attention",
73
73
  id: `${view.taskId}:${view.reason === "missing_grants" ? "grants" : view.reason === "failed" ? "failed" : "paused"}`,
74
74
  createdAt: at.toISOString(),
75
75
  attention: view,
@@ -150,7 +150,7 @@ InboxService = __decorate([
150
150
  __param(1, Inject(SkillChangesService)),
151
151
  __param(2, Inject(KernelDb)),
152
152
  __param(3, Inject(CatalogRequestsService)),
153
- __param(4, Inject(ScheduledTasksService))
153
+ __param(4, Inject(AutomationsService))
154
154
  ], InboxService);
155
155
  export { InboxService };
156
156
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -75,11 +75,16 @@ const HOT_APPLIERS = {
75
75
  "web.fetch.timeoutMs": () => { },
76
76
  // The push fanout reads the preview setting at every fanout.
77
77
  "push.previews": () => { },
78
- // Scheduled-task settings are clamped to these bounds on every read.
79
- "schedules.minIntervalFloorMinutes": () => { },
80
- "schedules.maxTasksPerMemberCap": () => { },
81
- "schedules.maxTasksPerOrgCap": () => { },
82
- "schedules.maxRunsPerHourCap": () => { },
78
+ // Automation settings are clamped to these bounds on every read.
79
+ "automations.minIntervalFloorMinutes": () => { },
80
+ "automations.maxTasksPerMemberCap": () => { },
81
+ "automations.maxTasksPerOrgCap": () => { },
82
+ "automations.maxRunsPerHourCap": () => { },
83
+ "automations.maxEventDepthCap": () => { },
84
+ "automations.coalesceSecondsCap": () => { },
85
+ "automations.maxEventRunsPerSubjectPerHourCap": () => { },
86
+ // The trigger event sweep reads the retention at every tick.
87
+ "automations.eventRetentionDays": () => { },
83
88
  // Run start reads the skills catalog budget when it records a snapshot.
84
89
  "skills.catalogBudgetChars": () => { },
85
90
  // The attribution defaults are read live at every run start, admin settings view and org settings.
@@ -19,6 +19,33 @@ export interface OutboxJobSpec {
19
19
  * name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
20
20
  */
21
21
  export declare const OUTBOX_JOBS: {
22
+ readonly "trigger-dispatch": {
23
+ readonly queue: "cap-kernel-maintenance";
24
+ readonly idempotent: "Dispatches one stored event by id; the dispatcher reads the event's state and delivers each automation at most once (deliveries keyed by automation and event)";
25
+ readonly processedIn: "packages/kernel/src/runtime/maintenance.ts";
26
+ readonly opts: {
27
+ readonly attempts: 10;
28
+ readonly backoff: {
29
+ readonly type: "exponential";
30
+ readonly delay: 5000;
31
+ };
32
+ readonly removeOnComplete: true;
33
+ };
34
+ };
35
+ readonly "automation-coalesce": {
36
+ readonly queue: "cap-kernel-maintenance";
37
+ readonly idempotent: "Flushes the pair's deliveries still waiting for a run under the automation row lock; a repeat finds none and records nothing";
38
+ readonly processedIn: "packages/kernel/src/runtime/maintenance.ts";
39
+ readonly opts: {
40
+ readonly attempts: 10;
41
+ readonly backoff: {
42
+ readonly type: "exponential";
43
+ readonly delay: 5000;
44
+ };
45
+ readonly removeOnComplete: true;
46
+ readonly removeOnFail: true;
47
+ };
48
+ };
22
49
  readonly "share-object-delete": {
23
50
  readonly queue: "cap-kernel-maintenance";
24
51
  readonly idempotent: "Deletes one object key; deleting a missing object is a no-op";
@@ -326,7 +353,7 @@ export declare const OUTBOX_JOBS: {
326
353
  readonly removeOnFail: true;
327
354
  };
328
355
  };
329
- readonly "sched-fire": {
356
+ readonly "automation-fire": {
330
357
  readonly queue: "cap-kernel-maintenance";
331
358
  readonly idempotent: "a fire acts only on a pending task run, under its row lock; a retried start reuses what the first one made";
332
359
  readonly processedIn: "packages/kernel/src/runtime/maintenance.ts";
@@ -340,7 +367,7 @@ export declare const OUTBOX_JOBS: {
340
367
  readonly removeOnFail: true;
341
368
  };
342
369
  };
343
- readonly "sched-settle": {
370
+ readonly "automation-settle": {
344
371
  readonly queue: "cap-kernel-maintenance";
345
372
  readonly idempotent: "a check acts only on a task run still pending (claimed for the claimed check, unclaimed for the unfired one), under the task and run row locks, so a run claimed, started, ended or skipped since is left as it is";
346
373
  readonly processedIn: "packages/kernel/src/runtime/maintenance.ts";
@@ -21,6 +21,29 @@ const SCOPE_JOB_OPTS = {
21
21
  * name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
22
22
  */
23
23
  export const OUTBOX_JOBS = {
24
+ // `automations/job-ids.ts` TRIGGER_DISPATCH_JOB: owed by the transaction that stores a trigger
25
+ // event (`TriggerEventsService.emit`, collaboration spec §4.2), under `trigger-dispatch-<eventId>`
26
+ "trigger-dispatch": {
27
+ queue: "cap-kernel-maintenance",
28
+ idempotent: "Dispatches one stored event by id; the dispatcher reads the event's state and delivers each automation at most once (deliveries keyed by automation and event)",
29
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
30
+ opts: { attempts: 10, backoff: { type: "exponential", delay: 5000 }, removeOnComplete: true },
31
+ },
32
+ // `automations/job-ids.ts` AUTOMATION_COALESCE_JOB: owed by the dispatch that opens a window of
33
+ // events for one (automation, subject) pair (`TriggerDispatcher`, collaboration spec §4.7), under
34
+ // `<coalesceJobId(automation, subject)>-<first event id>`, due when the window closes
35
+ "automation-coalesce": {
36
+ queue: "cap-kernel-maintenance",
37
+ idempotent: "Flushes the pair's deliveries still waiting for a run under the automation row lock; a repeat finds none and records nothing",
38
+ processedIn: "packages/kernel/src/runtime/maintenance.ts",
39
+ // removed once done, so a later window's add is never swallowed by a kept job
40
+ opts: {
41
+ attempts: 10,
42
+ backoff: { type: "exponential", delay: 5000 },
43
+ removeOnComplete: true,
44
+ removeOnFail: true,
45
+ },
46
+ },
24
47
  // `shares/share-objects.ts` SHARE_OBJECT_DELETE_JOB: owed by a share's refresh (the previous
25
48
  // generation) and revoke (the current one), under `shareObjectDeleteJobId` (file sharing spec §2)
26
49
  "share-object-delete": {
@@ -287,9 +310,9 @@ export const OUTBOX_JOBS = {
287
310
  removeOnFail: true,
288
311
  },
289
312
  },
290
- // `schedules/job-ids.ts` SCHED_FIRE_JOB: owed by the transaction that writes a pending task run
291
- // (the scan's tick, a person's "run now"), under `schedFireJobId` (spec §8.1)
292
- "sched-fire": {
313
+ // `automations/job-ids.ts` AUTOMATION_FIRE_JOB: owed by the transaction that writes a pending task run
314
+ // (the scan's tick, a person's "run now"), under `automationFireJobId` (spec §8.1)
315
+ "automation-fire": {
293
316
  queue: "cap-kernel-maintenance",
294
317
  idempotent: "a fire acts only on a pending task run, under its row lock; a retried start reuses what the first one made",
295
318
  processedIn: "packages/kernel/src/runtime/maintenance.ts",
@@ -301,11 +324,11 @@ export const OUTBOX_JOBS = {
301
324
  removeOnFail: true,
302
325
  },
303
326
  },
304
- // `schedules/job-ids.ts` SCHED_SETTLE_JOB: the claimed check, owed by the fire job's claim (the
305
- // transaction that writes `fired_at`) with `runAt` 10 min on, under `schedSettleJobId` (a run
327
+ // `automations/job-ids.ts` AUTOMATION_SETTLE_JOB: the claimed check, owed by the fire job's claim (the
328
+ // transaction that writes `fired_at`) with `runAt` 10 min on, under `automationSettleJobId` (a run
306
329
  // still in flight owes the next check an hour on); the unfired check, owed with the task run
307
- // (scan tick, "run now") under `schedSettleUnfiredJobId` (ruling R26)
308
- "sched-settle": {
330
+ // (scan tick, "run now") under `automationSettleUnfiredJobId` (ruling R26)
331
+ "automation-settle": {
309
332
  queue: "cap-kernel-maintenance",
310
333
  idempotent: "a check acts only on a task run still pending (claimed for the claimed check, unclaimed for the unfired one), under the task and run row locks, so a run claimed, started, ended or skipped since is left as it is",
311
334
  processedIn: "packages/kernel/src/runtime/maintenance.ts",
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var KernelAppOptionsModule_1, KernelModule_1;
8
8
  import { Global, Module } from "@nestjs/common";
9
9
  import { APP_INTERCEPTOR } from "@nestjs/core";
10
+ import { TriggerEventsModule } from "./automations/events/events.module.js";
10
11
  import { CatalogModule } from "./catalog/catalog.module.js";
11
12
  import { ChannelsModule } from "./channels/channels.module.js";
12
13
  import { ClientModule } from "./client/client.module.js";
@@ -131,6 +132,8 @@ let KernelModule = KernelModule_1 = class KernelModule {
131
132
  ClientModule,
132
133
  // ctx.deviceAccess: extensions' device services (the host finds it at the time of use)
133
134
  ExtensionDeviceAccessModule,
135
+ // ctx.triggers: the events extensions emit (the host finds it at the time of use)
136
+ TriggerEventsModule,
134
137
  // the Platform tool's operation registry and actor facts
135
138
  PlatformModule,
136
139
  // its operations (skills, agents, ...), registered at start on every role
@@ -4,7 +4,7 @@ export type OrgRole = (typeof ORG_ROLES)[number];
4
4
  /** `role` 是否不低于 `min`。 */
5
5
  export declare function roleAtLeast(role: OrgRole, min: OrgRole): boolean;
6
6
  /** 组织级动作;路由用 `@OrgAction(action)` 声明所需动作。 */
7
- export type OrgAction = "org.read" | "org.update" | "org.delete" | "org.transfer" | "org.members.read" | "org.members.manage" | "org.invitations.manage" | "org.tokens.manage" | "org.extensions.read" | "org.extensions.manage" | "agents.create" | "agents.use" | "agents.manage" | "conversations.compact" | "connectors.manage" | "connectors.use" | "approvals.decide" | "channels.manage" | "skills.read" | "skills.manage" | "ui.use" | "trajectories.read" | "evals.manage" | "org.models.manage" | "catalog.read" | "catalog.request" | "catalog.decide" | "catalog.upload" | "schedules.use" | "schedules.manage";
7
+ export type OrgAction = "org.read" | "org.update" | "org.delete" | "org.transfer" | "org.members.read" | "org.members.manage" | "org.invitations.manage" | "org.tokens.manage" | "org.extensions.read" | "org.extensions.manage" | "agents.create" | "agents.use" | "agents.manage" | "conversations.compact" | "connectors.manage" | "connectors.use" | "approvals.decide" | "channels.manage" | "skills.read" | "skills.manage" | "ui.use" | "trajectories.read" | "evals.manage" | "org.models.manage" | "catalog.read" | "catalog.request" | "catalog.decide" | "catalog.upload" | "automations.use" | "automations.manage";
8
8
  /** 每个动作所需的最低角色。 */
9
9
  export declare const ACTION_MIN_ROLE: Record<OrgAction, OrgRole>;
10
10
  /** 只允许 user principal 执行的动作:服务令牌即使角色足够也拒绝(除 SERVICE_ALLOWED 外全部)。 */
@@ -49,10 +49,10 @@ export const ACTION_MIN_ROLE = {
49
49
  "catalog.decide": "admin",
50
50
  // An org admin uploads a plugin package the org owns (spec §14.1 item 1, ruling P3-7)
51
51
  "catalog.upload": "admin",
52
- // Scheduled tasks (spec 2026-11-11 §10): create, edit, pause, resume, run and delete one's own
53
- "schedules.use": "member",
52
+ // Automations (spec 2026-11-11 §10): create, edit, pause, resume, run and delete one's own
53
+ "automations.use": "member",
54
54
  // list every task of the org, pause, resume and delete any (never edit another person's)
55
- "schedules.manage": "admin",
55
+ "automations.manage": "admin",
56
56
  };
57
57
  /** 服务令牌也可执行的动作:只读的 org.read、org.members.read,以及使用 agent 的 agents.use。 */
58
58
  const SERVICE_ALLOWED = new Set([
@@ -7,7 +7,7 @@ import { type OrgEffectiveNetwork, type OrgSandboxLimits, type OrgSettingsDeploy
7
7
  * 以及只读的 `sandboxLimits`(组织实际生效的沙箱 cpu / 内存与来源,超级管理员在部署设置里覆盖,C19)。
8
8
  */
9
9
  type SettingsResponse = {
10
- /** `scheduledTasks.forbiddenToolsUnreadable: true` when the stored list cannot be read. */
10
+ /** `automations.forbiddenToolsUnreadable: true` when the stored list cannot be read. */
11
11
  settings: OrgSettingsView;
12
12
  deployment: OrgSettingsDeployment;
13
13
  /** The org's effective sandbox-mode network (org egress ceiling spec §D4). */