@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
@@ -65,6 +65,15 @@ export declare const DeviceProjectParams: z.ZodObject<{
65
65
  id: z.ZodString;
66
66
  name: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
67
67
  }, z.core.$strip>;
68
+ /**
69
+ * `GET /devices/:id/projects/:name/files` (composer menus §5): `path` is the directory to list,
70
+ * relative to the project root (absent or empty: the root; the service normalizes it and refuses
71
+ * one that leaves the project, `device.path_outside_project`); `q` filters the names in it.
72
+ */
73
+ export declare const DeviceProjectFilesQuery: z.ZodObject<{
74
+ path: z.ZodOptional<z.ZodString>;
75
+ q: z.ZodOptional<z.ZodString>;
76
+ }, z.core.$strip>;
68
77
  declare const DeviceCreateBodyDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
69
78
  name: z.ZodString;
70
79
  provider: z.ZodOptional<z.ZodString>;
@@ -101,4 +110,10 @@ declare const DeviceProjectParamsDto_base: import("../infra/validation/create-zo
101
110
  }, z.core.$strip>>;
102
111
  export declare class DeviceProjectParamsDto extends DeviceProjectParamsDto_base {
103
112
  }
113
+ declare const DeviceProjectFilesQueryDto_base: import("../infra/validation/create-zod-dto.js").ZodDtoClass<z.ZodObject<{
114
+ path: z.ZodOptional<z.ZodString>;
115
+ q: z.ZodOptional<z.ZodString>;
116
+ }, z.core.$strip>>;
117
+ export declare class DeviceProjectFilesQueryDto extends DeviceProjectFilesQueryDto_base {
118
+ }
104
119
  export {};
@@ -89,6 +89,15 @@ export const DeviceProjectAddBody = z
89
89
  .strict();
90
90
  /** `DELETE /devices/:id/projects/:name`. */
91
91
  export const DeviceProjectParams = DeviceParams.extend({ name: DeviceProjectName });
92
+ /**
93
+ * `GET /devices/:id/projects/:name/files` (composer menus §5): `path` is the directory to list,
94
+ * relative to the project root (absent or empty: the root; the service normalizes it and refuses
95
+ * one that leaves the project, `device.path_outside_project`); `q` filters the names in it.
96
+ */
97
+ export const DeviceProjectFilesQuery = z.object({
98
+ path: z.string().max(4096).optional(),
99
+ q: z.string().max(200).optional(),
100
+ });
92
101
  export class DeviceCreateBodyDto extends createZodDto(DeviceCreateBody, "DeviceCreateBody") {
93
102
  }
94
103
  export class DevicePatchBodyDto extends createZodDto(DevicePatchBody, "DevicePatchBody") {
@@ -99,3 +108,5 @@ export class DeviceProjectAddBodyDto extends createZodDto(DeviceProjectAddBody,
99
108
  }
100
109
  export class DeviceProjectParamsDto extends createZodDto(DeviceProjectParams, "DeviceProjectParams") {
101
110
  }
111
+ export class DeviceProjectFilesQueryDto extends createZodDto(DeviceProjectFilesQuery, "DeviceProjectFilesQuery") {
112
+ }
@@ -0,0 +1,29 @@
1
+ import { ApiError } from "../errors.js";
2
+ /** The longest path relative to a project the kernel takes (the add route's bound). */
3
+ export declare const MAX_PROJECT_RELATIVE_PATH = 4096;
4
+ /**
5
+ * A path relative to a device project (composer menus §5) that is refused: absolute, escaping the
6
+ * project root with `..`, holding a backslash or a control character, or too long. 422
7
+ * `device.path_outside_project` with the path (clipped) in `details`.
8
+ */
9
+ export declare const pathOutsideProject: (rel: string) => ApiError;
10
+ /**
11
+ * `rel` normalized as a posix path relative to a project's root: `""` for the root itself, no
12
+ * `.` segments, no doubled or trailing `/`, `..` resolved. Refused ({@link pathOutsideProject})
13
+ * when it is absolute, climbs above the root, holds a backslash or a control character (NUL
14
+ * included), or is longer than {@link MAX_PROJECT_RELATIVE_PATH}. Pure string work: the device
15
+ * is never asked, so a symlink below the root is the provider's and its browse scope's to judge.
16
+ */
17
+ export declare function projectRelativePath(rel: string): string;
18
+ /**
19
+ * The absolute device path of `rel` (normalized through {@link projectRelativePath}, so refused
20
+ * the same way) inside the project rooted at `projectPath`, which must itself be absolute and
21
+ * normalized (no `.` / `..` segments, no doubled or trailing `/`): an internal error otherwise.
22
+ */
23
+ export declare function joinProjectPath(projectPath: string, rel: string): string;
24
+ /**
25
+ * {@link projectRelativePath} for a path that must name a file below the root: one that
26
+ * normalizes to the root itself (`"."`, `"./"`, `"a/.."`) is refused with
27
+ * `device.path_outside_project` as well, its path in `details` as given (none when empty).
28
+ */
29
+ export declare function projectFilePath(rel: string): string;
@@ -0,0 +1,66 @@
1
+ import { posix } from "node:path";
2
+ import { ApiError } from "../errors.js";
3
+ import { clipped } from "./project-rules.js";
4
+ /** The longest path relative to a project the kernel takes (the add route's bound). */
5
+ export const MAX_PROJECT_RELATIVE_PATH = 4096;
6
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what it refuses
7
+ const CONTROL = /[\u0000-\u001f\u007f]/;
8
+ /**
9
+ * A path relative to a device project (composer menus §5) that is refused: absolute, escaping the
10
+ * project root with `..`, holding a backslash or a control character, or too long. 422
11
+ * `device.path_outside_project` with the path (clipped) in `details`.
12
+ */
13
+ export const pathOutsideProject = (rel) => new ApiError("device.path_outside_project", "Give a path relative to the project root that stays inside it: no absolute path, no .. above the root, no backslashes or control characters", [{ path: clipped(rel) }]);
14
+ /**
15
+ * `rel` normalized as a posix path relative to a project's root: `""` for the root itself, no
16
+ * `.` segments, no doubled or trailing `/`, `..` resolved. Refused ({@link pathOutsideProject})
17
+ * when it is absolute, climbs above the root, holds a backslash or a control character (NUL
18
+ * included), or is longer than {@link MAX_PROJECT_RELATIVE_PATH}. Pure string work: the device
19
+ * is never asked, so a symlink below the root is the provider's and its browse scope's to judge.
20
+ */
21
+ export function projectRelativePath(rel) {
22
+ if (rel.length > MAX_PROJECT_RELATIVE_PATH ||
23
+ rel.startsWith("/") ||
24
+ rel.includes("\\") ||
25
+ CONTROL.test(rel)) {
26
+ throw pathOutsideProject(rel);
27
+ }
28
+ if (rel === "")
29
+ return "";
30
+ const n = posix.normalize(rel);
31
+ if (n === ".." || n.startsWith("../") || posix.isAbsolute(n))
32
+ throw pathOutsideProject(rel);
33
+ const trimmed = n.endsWith("/") ? n.slice(0, -1) : n;
34
+ return trimmed === "." ? "" : trimmed;
35
+ }
36
+ /**
37
+ * The absolute device path of `rel` (normalized through {@link projectRelativePath}, so refused
38
+ * the same way) inside the project rooted at `projectPath`, which must itself be absolute and
39
+ * normalized (no `.` / `..` segments, no doubled or trailing `/`): an internal error otherwise.
40
+ */
41
+ export function joinProjectPath(projectPath, rel) {
42
+ // the project path is the kernel's own (a stored project): one that is not absolute and
43
+ // normalized is a kernel bug, never the person's path
44
+ if (!posix.isAbsolute(projectPath) ||
45
+ posix.normalize(projectPath) !== projectPath ||
46
+ (projectPath !== "/" && projectPath.endsWith("/"))) {
47
+ throw new Error(`joinProjectPath: the project path ${JSON.stringify(clipped(projectPath))} is not absolute and normalized`);
48
+ }
49
+ const r = projectRelativePath(rel);
50
+ const root = projectPath;
51
+ if (r === "")
52
+ return root;
53
+ return root === "/" ? `/${r}` : `${root}/${r}`;
54
+ }
55
+ /**
56
+ * {@link projectRelativePath} for a path that must name a file below the root: one that
57
+ * normalizes to the root itself (`"."`, `"./"`, `"a/.."`) is refused with
58
+ * `device.path_outside_project` as well, its path in `details` as given (none when empty).
59
+ */
60
+ export function projectFilePath(rel) {
61
+ const r = projectRelativePath(rel);
62
+ if (r === "") {
63
+ throw new ApiError("device.path_outside_project", "The project root is not a file; give the path of a file inside the project", rel === "" ? undefined : [{ path: clipped(rel) }]);
64
+ }
65
+ return r;
66
+ }
@@ -24,7 +24,11 @@ export declare const projectNotFound: (name: string) => ApiError;
24
24
  * the resolved path is not one a device can hold.
25
25
  */
26
26
  export declare const outsideMode: (path: string) => ApiError;
27
- export declare const tooBroad: (path: string) => ApiError;
27
+ /**
28
+ * A project directory above the owner's home: named by the project (`name`, when there is one),
29
+ * never by its absolute path, which stays out of the message.
30
+ */
31
+ export declare const tooBroad: (name?: string) => ApiError;
28
32
  /** A device-supplied or person-supplied string inside a message, bounded. */
29
33
  export declare function clipped(s: string, max?: number): string;
30
34
  export {};
@@ -9,7 +9,11 @@ export const projectNotFound = (name) => new ApiError("device.project_not_found"
9
9
  * the resolved path is not one a device can hold.
10
10
  */
11
11
  export const outsideMode = (path) => new ApiError("device.project_outside_mode", `${clipped(path)} is outside what the device lets a project reach; pick a directory inside its base`);
12
- export const tooBroad = (path) => new ApiError("device.project_path_too_broad", `${clipped(path)} holds the owner's home directory (or other people's): pick the project's own directory, the home or below it`);
12
+ /**
13
+ * A project directory above the owner's home: named by the project (`name`, when there is one),
14
+ * never by its absolute path, which stays out of the message.
15
+ */
16
+ export const tooBroad = (name) => new ApiError("device.project_path_too_broad", `${name === undefined ? "This directory" : `The project "${clipped(name)}"`} holds the owner's home directory (or other people's): pick the project's own directory, the home or below it`);
13
17
  /** A device-supplied or person-supplied string inside a message, bounded. */
14
18
  export function clipped(s, max = 200) {
15
19
  return s.length <= max ? s : `${s.slice(0, max)}…`;
package/dist/errors.d.ts CHANGED
@@ -38,6 +38,19 @@ export declare const ERROR_CODES: {
38
38
  readonly "app_auth.code_invalid": 400;
39
39
  /** Native-app sign-in needs `http.publicUrl` (the issuer the app checks). */
40
40
  readonly "app_auth.unavailable": 503;
41
+ /**
42
+ * A browser handoff start names a return scheme whose `<scheme>://auth/callback` is not in
43
+ * `auth.appRedirectUris` (exact match), or `http.publicUrl` is not set.
44
+ */
45
+ readonly "handoff.scheme_not_allowed": 400;
46
+ /** The browser handoff ticket is unknown, expired or already used; start again in the app. */
47
+ readonly "handoff.invalid": 410;
48
+ /**
49
+ * The browser is signed in as another account than the one that started the handoff (the
50
+ * ticket is spent); details `[{ login, displayName, email }]` of the ticket's account (`login`
51
+ * its local login, null without one; `email` null when unset).
52
+ */
53
+ readonly "handoff.account_mismatch": 403;
41
54
  readonly "token.not_found": 404;
42
55
  readonly "org.not_found": 404;
43
56
  readonly "org.creation_disabled": 403;
@@ -368,6 +381,12 @@ export declare const ERROR_CODES: {
368
381
  readonly "conversation.queue_item_not_found": 404;
369
382
  /** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
370
383
  readonly "conversation.read_only": 409;
384
+ /**
385
+ * A referenced project file is not there to reference (composer menus §5): the conversation has
386
+ * no device project, the path leaves it, or the device reports no file there;
387
+ * `details: [{ path?, reason? }]`.
388
+ */
389
+ readonly "conversation.project_file_unavailable": 422;
371
390
  readonly "run.not_active": 409;
372
391
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
373
392
  readonly "run.not_found": 404;
@@ -536,6 +555,13 @@ export declare const ERROR_CODES: {
536
555
  readonly "device.project_path_unreadable": 422;
537
556
  /** The device provider refused the project's directory (its reason is the message and details). */
538
557
  readonly "device.project_refused": 422;
558
+ /**
559
+ * A path relative to a device project that leaves it (composer menus §5): absolute, `..` above
560
+ * the root, a backslash or a control character; `details: [{ path }]`.
561
+ */
562
+ readonly "device.path_outside_project": 422;
563
+ /** The device's provider cannot list its directories for its owner (no `list` / owner browse). */
564
+ readonly "device.list_unsupported": 409;
539
565
  /** Device sign-in (RFC 8628 style): the person has not approved the code yet; keep polling. */
540
566
  readonly "device_sign_in.authorization_pending": 400;
541
567
  /** Device sign-in: the program polls faster than the interval; add 5 seconds and keep polling. */
@@ -552,28 +578,36 @@ export declare const ERROR_CODES: {
552
578
  readonly "device.credential_invalid": 401;
553
579
  /** A device stream hop from another gateway replica without a valid MAC (or replayed). */
554
580
  readonly "device.stream_hop_refused": 401;
555
- /** The scheduled task is missing, deleted, in another org or not the caller's to see. */
556
- readonly "schedule.not_found": 404;
581
+ /** The automation is missing, deleted, in another org or not the caller's to see. */
582
+ readonly "automation.not_found": 404;
557
583
  /** Not a 5-field cron expression (no seconds field). */
558
- readonly "schedule.invalid_cron": 400;
584
+ readonly "automation.invalid_cron": 400;
559
585
  /** Not an IANA time zone. */
560
- readonly "schedule.invalid_time_zone": 400;
586
+ readonly "automation.invalid_time_zone": 400;
561
587
  /** A `once` time that is not a local date-time `YYYY-MM-DDTHH:mm[:ss]`. */
562
- readonly "schedule.invalid_once_time": 400;
588
+ readonly "automation.invalid_once_time": 400;
563
589
  /** A `once` time that is not in the future. */
564
- readonly "schedule.once_in_past": 400;
590
+ readonly "automation.once_in_past": 400;
565
591
  /** Two fire times closer than the org's `minIntervalMinutes`. */
566
- readonly "schedule.interval_too_short": 400;
592
+ readonly "automation.interval_too_short": 400;
567
593
  /** The creator or the org has as many active and paused tasks as the org allows. */
568
- readonly "schedule.limit_reached": 409;
569
- /** The org turned scheduled tasks off. */
570
- readonly "schedule.disabled": 409;
594
+ readonly "automation.limit_reached": 409;
595
+ /** The org turned automations off. */
596
+ readonly "automation.disabled": 409;
571
597
  /** Where the task runs is inconsistent or not the creator's to use (conversation, chat, device). */
572
- readonly "schedule.target_invalid": 400;
598
+ readonly "automation.target_invalid": 400;
573
599
  /** A tool the creator cannot pre-approve for the task (spec §7). */
574
- readonly "schedule.grant_not_allowed": 400;
600
+ readonly "automation.grant_not_allowed": 400;
601
+ /** An event trigger names a source that is not an enabled trigger source of the org. */
602
+ readonly "automation.event_source_unavailable": 400;
603
+ /** An event trigger names an event type its source does not declare (or a directed one). */
604
+ readonly "automation.event_type_unknown": 400;
605
+ /** An event trigger's filter names a missing or unfilterable fact, or mistypes a value. */
606
+ readonly "automation.filter_invalid": 400;
575
607
  /** An org admin may pause, resume and delete another person's task, never edit it. */
576
- readonly "schedule.forbidden": 403;
608
+ readonly "automation.forbidden": 403;
609
+ /** "Run now" and trial runs: an event automation runs only on its events (no run now, no trial). */
610
+ readonly "automation.run_now_unsupported": 409;
577
611
  readonly "skill.not_found": 404;
578
612
  /** The skill's file routes: no such version of the skill, or no such path in that version. */
579
613
  readonly "skill.file_not_found": 404;
package/dist/errors.js CHANGED
@@ -38,6 +38,19 @@ export const ERROR_CODES = {
38
38
  "app_auth.code_invalid": 400,
39
39
  /** Native-app sign-in needs `http.publicUrl` (the issuer the app checks). */
40
40
  "app_auth.unavailable": 503,
41
+ /**
42
+ * A browser handoff start names a return scheme whose `<scheme>://auth/callback` is not in
43
+ * `auth.appRedirectUris` (exact match), or `http.publicUrl` is not set.
44
+ */
45
+ "handoff.scheme_not_allowed": 400,
46
+ /** The browser handoff ticket is unknown, expired or already used; start again in the app. */
47
+ "handoff.invalid": 410,
48
+ /**
49
+ * The browser is signed in as another account than the one that started the handoff (the
50
+ * ticket is spent); details `[{ login, displayName, email }]` of the ticket's account (`login`
51
+ * its local login, null without one; `email` null when unset).
52
+ */
53
+ "handoff.account_mismatch": 403,
41
54
  "token.not_found": 404,
42
55
  "org.not_found": 404,
43
56
  "org.creation_disabled": 403,
@@ -368,6 +381,12 @@ export const ERROR_CODES = {
368
381
  "conversation.queue_item_not_found": 404,
369
382
  /** A sub-agent's conversation takes no messages from people (sub-agents spec §6.1). */
370
383
  "conversation.read_only": 409,
384
+ /**
385
+ * A referenced project file is not there to reference (composer menus §5): the conversation has
386
+ * no device project, the path leaves it, or the device reports no file there;
387
+ * `details: [{ path?, reason? }]`.
388
+ */
389
+ "conversation.project_file_unavailable": 422,
371
390
  "run.not_active": 409,
372
391
  /** A run that is not one of the conversation's (the live draft route, spec 2026-11-07 §3.2). */
373
392
  "run.not_found": 404,
@@ -536,6 +555,13 @@ export const ERROR_CODES = {
536
555
  "device.project_path_unreadable": 422,
537
556
  /** The device provider refused the project's directory (its reason is the message and details). */
538
557
  "device.project_refused": 422,
558
+ /**
559
+ * A path relative to a device project that leaves it (composer menus §5): absolute, `..` above
560
+ * the root, a backslash or a control character; `details: [{ path }]`.
561
+ */
562
+ "device.path_outside_project": 422,
563
+ /** The device's provider cannot list its directories for its owner (no `list` / owner browse). */
564
+ "device.list_unsupported": 409,
539
565
  /** Device sign-in (RFC 8628 style): the person has not approved the code yet; keep polling. */
540
566
  "device_sign_in.authorization_pending": 400,
541
567
  /** Device sign-in: the program polls faster than the interval; add 5 seconds and keep polling. */
@@ -552,28 +578,36 @@ export const ERROR_CODES = {
552
578
  "device.credential_invalid": 401,
553
579
  /** A device stream hop from another gateway replica without a valid MAC (or replayed). */
554
580
  "device.stream_hop_refused": 401,
555
- /** The scheduled task is missing, deleted, in another org or not the caller's to see. */
556
- "schedule.not_found": 404,
581
+ /** The automation is missing, deleted, in another org or not the caller's to see. */
582
+ "automation.not_found": 404,
557
583
  /** Not a 5-field cron expression (no seconds field). */
558
- "schedule.invalid_cron": 400,
584
+ "automation.invalid_cron": 400,
559
585
  /** Not an IANA time zone. */
560
- "schedule.invalid_time_zone": 400,
586
+ "automation.invalid_time_zone": 400,
561
587
  /** A `once` time that is not a local date-time `YYYY-MM-DDTHH:mm[:ss]`. */
562
- "schedule.invalid_once_time": 400,
588
+ "automation.invalid_once_time": 400,
563
589
  /** A `once` time that is not in the future. */
564
- "schedule.once_in_past": 400,
590
+ "automation.once_in_past": 400,
565
591
  /** Two fire times closer than the org's `minIntervalMinutes`. */
566
- "schedule.interval_too_short": 400,
592
+ "automation.interval_too_short": 400,
567
593
  /** The creator or the org has as many active and paused tasks as the org allows. */
568
- "schedule.limit_reached": 409,
569
- /** The org turned scheduled tasks off. */
570
- "schedule.disabled": 409,
594
+ "automation.limit_reached": 409,
595
+ /** The org turned automations off. */
596
+ "automation.disabled": 409,
571
597
  /** Where the task runs is inconsistent or not the creator's to use (conversation, chat, device). */
572
- "schedule.target_invalid": 400,
598
+ "automation.target_invalid": 400,
573
599
  /** A tool the creator cannot pre-approve for the task (spec §7). */
574
- "schedule.grant_not_allowed": 400,
600
+ "automation.grant_not_allowed": 400,
601
+ /** An event trigger names a source that is not an enabled trigger source of the org. */
602
+ "automation.event_source_unavailable": 400,
603
+ /** An event trigger names an event type its source does not declare (or a directed one). */
604
+ "automation.event_type_unknown": 400,
605
+ /** An event trigger's filter names a missing or unfilterable fact, or mistypes a value. */
606
+ "automation.filter_invalid": 400,
575
607
  /** An org admin may pause, resume and delete another person's task, never edit it. */
576
- "schedule.forbidden": 403,
608
+ "automation.forbidden": 403,
609
+ /** "Run now" and trial runs: an event automation runs only on its events (no run now, no trial). */
610
+ "automation.run_now_unsupported": 409,
577
611
  "skill.not_found": 404,
578
612
  /** The skill's file routes: no such version of the skill, or no such path in that version. */
579
613
  "skill.file_not_found": 404,
@@ -27,7 +27,9 @@ import { type CaseSnapshot } from "./snapshot.js";
27
27
  * - `context_fit` (context compaction spec §4.9, never for a baseline): the candidate model's window
28
28
  * makes the hard fit guard plan a different trim than the recorded `model_call.request.fit` (the
29
29
  * recorded plan is replayed for a baseline; a candidate applies its recomputed plan);
30
- * - `run_outcome_note`: the rebuilt run outcome notes differ from the recorded `runOutcomeSeqs`.
30
+ * - `run_outcome_note`: the rebuilt run outcome notes differ from the recorded `runOutcomeSeqs`;
31
+ * - `automation_event_block`: the rebuilt event automation blocks differ from the recorded
32
+ * `automationEventSeqs`.
31
33
  */
32
34
  /** 还原结果与原请求不一致的原因。 */
33
35
  export type DriftReason = "system_hash" | "tools_changed" | "tool_spec_missing" | "definition_missing"
@@ -59,6 +61,13 @@ export type DriftReason = "system_hash" | "tools_changed" | "tool_spec_missing"
59
61
  * the log alone, so a candidate cannot change them.
60
62
  */
61
63
  | "run_outcome_note"
64
+ /**
65
+ * Collaboration spec §4.6: the rebuild renders the event automation block
66
+ * (`automationEventBlock`) for another set of messages than the request recorded in
67
+ * `model_call.request.automationEventSeqs`: a request sent before the block was rendered.
68
+ * Judged for every reconstruction: the block comes from the log alone.
69
+ */
70
+ | "automation_event_block"
62
71
  /** 整轮回放(T5):有工具调用没有匹配到记录(模型收到 REPLAY_NO_RECORDING)。 */
63
72
  | "tool_unmatched";
64
73
  export interface ReconstructOptions {
@@ -47,6 +47,7 @@ const DRIFT_ORDER = [
47
47
  "media_changed",
48
48
  "context_fit",
49
49
  "run_outcome_note",
50
+ "automation_event_block",
50
51
  "tool_unmatched",
51
52
  ];
52
53
  function findCall(events, seq) {
@@ -283,6 +284,12 @@ export function reconstructFromInputs(s, gathered, opts) {
283
284
  if (notes.length !== recordedNotes.length || notes.some((x, i) => x !== recordedNotes[i])) {
284
285
  drift.add("run_outcome_note");
285
286
  }
287
+ // event automation blocks: from the log alone, so only a request sent before they existed differs
288
+ const blocks = meta.automationEventSeqs ?? [];
289
+ const recordedBlocks = rec.automationEventSeqs ?? [];
290
+ if (blocks.length !== recordedBlocks.length || blocks.some((x, i) => x !== recordedBlocks[i])) {
291
+ drift.add("automation_event_block");
292
+ }
286
293
  // 媒体:按附件 id 与记录比较
287
294
  const recordedMedia = new Map((rec.media ?? []).map((m) => [m.attachmentId, m]));
288
295
  for (const m of meta.media ?? []) {
@@ -2,8 +2,9 @@ import { type DroppedUiContribution, type ExtensionManifest, type ExtensionPoint
2
2
  import type { Redis } from "ioredis";
3
3
  import type { core } from "zod";
4
4
  import type { KernelAppOptions } from "../app.js";
5
+ import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
5
6
  import type { BusSubscriber } from "../ctx/bus.js";
6
- import { type DeviceAccessBackend, type Route } from "../ctx/create-ctx.js";
7
+ import { type DeviceAccessBackend, type Route, type TriggersBackend } from "../ctx/create-ctx.js";
7
8
  import { type ExtensionNetSeams } from "../ctx/net.js";
8
9
  import type { Keyring } from "../ctx/secrets.js";
9
10
  import { DEVICE_ACCESS_BACKEND } from "../device-access/token.js";
@@ -288,11 +289,15 @@ export declare class ExtensionHost {
288
289
  * of use: its module imports the sandbox, devices and tools modules, which import this one (a
289
290
  * module cycle otherwise).
290
291
  * Absent (a hand-built host) or not found (the CLI): `ctx.deviceAccess` calls are refused.
292
+ * `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) likewise.
291
293
  */
292
294
  modules?: {
293
295
  get(token: typeof DEVICE_ACCESS_BACKEND, opts: {
294
296
  strict: false;
295
297
  }): DeviceAccessBackend;
298
+ get(token: typeof TRIGGER_EVENTS_BACKEND, opts: {
299
+ strict: false;
300
+ }): TriggersBackend;
296
301
  },
297
302
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
298
303
  netSeams?: ExtensionNetSeams);
@@ -14,6 +14,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
14
14
  import { EXTENSION_POINT_CARDINALITY, parseExtensionPoint, SDK_VERSION, } from "@capybara-hq/plugin-sdk";
15
15
  import { Inject, Injectable, Optional } from "@nestjs/common";
16
16
  import { ModuleRef } from "@nestjs/core";
17
+ import { TRIGGER_EVENTS_BACKEND } from "../automations/events/token.js";
17
18
  import { changedPaths, configFields, secretValues, unreachableSecrets } from "../config/fields.js";
18
19
  import { pluginSchemaName, queryEnabledPlugins, } from "../ctx/create-ctx.js";
19
20
  import { EXTENSION_NET_SEAMS } from "../ctx/net.js";
@@ -434,6 +435,7 @@ let ExtensionHost = class ExtensionHost {
434
435
  * of use: its module imports the sandbox, devices and tools modules, which import this one (a
435
436
  * module cycle otherwise).
436
437
  * Absent (a hand-built host) or not found (the CLI): `ctx.deviceAccess` calls are refused.
438
+ * `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) likewise.
437
439
  */
438
440
  modules,
439
441
  /** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
@@ -480,6 +482,14 @@ let ExtensionHost = class ExtensionHost {
480
482
  return undefined;
481
483
  }
482
484
  },
485
+ triggers: () => {
486
+ try {
487
+ return modules?.get(TRIGGER_EVENTS_BACKEND, { strict: false });
488
+ }
489
+ catch {
490
+ return undefined;
491
+ }
492
+ },
483
493
  locks,
484
494
  runWorkers: c.roles.includes("worker"),
485
495
  log,
@@ -78,6 +78,14 @@ export interface PermissionSet {
78
78
  deviceAccess?: {
79
79
  services: string[];
80
80
  };
81
+ /**
82
+ * The event types the extension may emit (`permissions.triggers.emit`, collaboration spec
83
+ * §4.2): one blocking key per type, so an upgrade adding a type waits for approval. Absent
84
+ * when not declared.
85
+ */
86
+ triggers?: {
87
+ emit: string[];
88
+ };
81
89
  };
82
90
  /**
83
91
  * 安装记录包迁移警告的摘要(`warningsDigest`,Ruling P4);没有警告或不是安装记录时省略。
@@ -125,7 +133,8 @@ export declare function buildPermissionSet(input: {
125
133
  * `config.deployment.secret:apiKey`, `table:todos`, `permissions.tools:write`,
126
134
  * `permissions.http.<access>:<METHOD> <path>` (`permissions.http.public:POST /events`),
127
135
  * `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud`,
128
- * `permissions.dialin:capybara-device/6`, `permissions.deviceaccess:browser`.
136
+ * `permissions.dialin:capybara-device/6`, `permissions.deviceaccess:browser`,
137
+ * `permissions.triggers:item.created`.
129
138
  * Tolerates old snapshots missing fields (read as empty), so format changes never throw.
130
139
  */
131
140
  export declare function permissionKeys(set: PermissionSet): string[];
@@ -150,6 +159,13 @@ export declare const DIAL_IN_KEY_PREFIX = "permissions.dialin:";
150
159
  * catalog permission keys require (`PERMISSION_KEY_RE`).
151
160
  */
152
161
  export declare const DEVICE_ACCESS_KEY_PREFIX = "permissions.deviceaccess:";
162
+ /**
163
+ * Key prefix of an event type the extension emits (`permissions.triggers.emit`): blocking, not
164
+ * sensitive (an event only reaches automations an org built on it, collaboration spec §4.2).
165
+ * Lower-case letters and dots before the colon, as catalog permission keys require
166
+ * (`PERMISSION_KEY_RE`).
167
+ */
168
+ export declare const TRIGGERS_KEY_PREFIX = "permissions.triggers:";
153
169
  /** Key prefix of a client component (`ui.component:<id>`): sensitive and blocking. */
154
170
  export declare const UI_COMPONENT_KEY_PREFIX = "ui.component:";
155
171
  /** 渲染 schema 视图的权限键前缀:记入快照但不卡加载(见 {@link blockingKeys})。 */
@@ -121,6 +121,8 @@ export function buildPermissionSet(input) {
121
121
  ...(p.deviceAccess
122
122
  ? { deviceAccess: { services: sortedUnique(p.deviceAccess.services) } }
123
123
  : {}),
124
+ // only when declared, likewise
125
+ ...(p.triggers ? { triggers: { emit: sortedUnique(p.triggers.emit) } } : {}),
124
126
  },
125
127
  ...(input.warningsDigest ? { warningsDigest: input.warningsDigest } : {}),
126
128
  };
@@ -130,7 +132,8 @@ export function buildPermissionSet(input) {
130
132
  * `config.deployment.secret:apiKey`, `table:todos`, `permissions.tools:write`,
131
133
  * `permissions.http.<access>:<METHOD> <path>` (`permissions.http.public:POST /events`),
132
134
  * `ui.view:tasks`, `ui.embed:board`, `permissions.client`, `ui.component:hud`,
133
- * `permissions.dialin:capybara-device/6`, `permissions.deviceaccess:browser`.
135
+ * `permissions.dialin:capybara-device/6`, `permissions.deviceaccess:browser`,
136
+ * `permissions.triggers:item.created`.
134
137
  * Tolerates old snapshots missing fields (read as empty), so format changes never throw.
135
138
  */
136
139
  export function permissionKeys(set) {
@@ -181,6 +184,8 @@ export function permissionKeys(set) {
181
184
  keys.push(`${DIAL_IN_KEY_PREFIX}${p.dialIn.protocol}`);
182
185
  for (const svc of p.deviceAccess?.services ?? [])
183
186
  keys.push(`${DEVICE_ACCESS_KEY_PREFIX}${svc}`);
187
+ for (const t of p.triggers?.emit ?? [])
188
+ keys.push(`${TRIGGERS_KEY_PREFIX}${t}`);
184
189
  if (s.warningsDigest)
185
190
  keys.push(`${WARNINGS_KEY_PREFIX}${s.warningsDigest}`);
186
191
  return sortedUnique(keys);
@@ -206,6 +211,13 @@ export const DIAL_IN_KEY_PREFIX = "permissions.dialin:";
206
211
  * catalog permission keys require (`PERMISSION_KEY_RE`).
207
212
  */
208
213
  export const DEVICE_ACCESS_KEY_PREFIX = "permissions.deviceaccess:";
214
+ /**
215
+ * Key prefix of an event type the extension emits (`permissions.triggers.emit`): blocking, not
216
+ * sensitive (an event only reaches automations an org built on it, collaboration spec §4.2).
217
+ * Lower-case letters and dots before the colon, as catalog permission keys require
218
+ * (`PERMISSION_KEY_RE`).
219
+ */
220
+ export const TRIGGERS_KEY_PREFIX = "permissions.triggers:";
209
221
  /** Key prefix of a client component (`ui.component:<id>`): sensitive and blocking. */
210
222
  export const UI_COMPONENT_KEY_PREFIX = "ui.component:";
211
223
  /** 渲染 schema 视图的权限键前缀:记入快照但不卡加载(见 {@link blockingKeys})。 */
@@ -13,7 +13,7 @@ import type { ExtensionSource } from "./sources.js";
13
13
  export declare function reviewHash(set: PermissionSet, warnings?: readonly PackageWarning[]): string;
14
14
  /** 权限清单展示用的一组:按类别分组,`sensitive` 标出需要管理员特别留意的类别。 */
15
15
  export interface PermissionGroup {
16
- category: "provides" | "requires" | "optional" | "config" | "tables" | "secrets" | "storage" | "http" | "publicRoutes" | "embedRoutes" | "tools" | "hooks" | "models" | "network" | "ui" | "components" | "client" | "dialIn" | "deviceAccess";
16
+ category: "provides" | "requires" | "optional" | "config" | "tables" | "secrets" | "storage" | "http" | "publicRoutes" | "embedRoutes" | "tools" | "hooks" | "models" | "network" | "ui" | "components" | "client" | "dialIn" | "deviceAccess" | "triggers";
17
17
  /**
18
18
  * Sensitive category: secrets, public routes, tools, hooks, client components, client code,
19
19
  * device services; also
@@ -1,7 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { pluginSchemaName } from "../ctx/create-ctx.js";
3
3
  import { isDestructiveSql, splitSqlStatements } from "../db/sql-statements.js";
4
- import { CLIENT_KEY, DEVICE_ACCESS_KEY_PREFIX, DIAL_IN_KEY_PREFIX, permissionKeys, UI_COMPONENT_KEY_PREFIX, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
4
+ import { CLIENT_KEY, DEVICE_ACCESS_KEY_PREFIX, DIAL_IN_KEY_PREFIX, permissionKeys, TRIGGERS_KEY_PREFIX, UI_COMPONENT_KEY_PREFIX, WARNINGS_KEY_PREFIX, } from "./permission-set.js";
5
5
  /**
6
6
  * Review digest: the first 16 hex digits of `sha256(permissionKeys(set).join("\n"))`; with migration
7
7
  * warnings their digest (kind, file, line and statement) is folded in, without warnings it equals the
@@ -109,6 +109,7 @@ function keyItem(key) {
109
109
  ["ui.view:", "ui", "view:"],
110
110
  [DIAL_IN_KEY_PREFIX, "dialIn", ""],
111
111
  [DEVICE_ACCESS_KEY_PREFIX, "deviceAccess", ""],
112
+ [TRIGGERS_KEY_PREFIX, "triggers", ""],
112
113
  ];
113
114
  for (const [prefix, category, itemPrefix] of table) {
114
115
  const rest = after(prefix);
@@ -188,6 +189,8 @@ export function permissionGroups(set) {
188
189
  { category: "dialIn", items: p.dialIn ? [p.dialIn.protocol] : [] },
189
190
  // long-lived services the extension runs in conversations' devices
190
191
  { category: "deviceAccess", items: p.deviceAccess?.services ?? [] },
192
+ // the event types it emits for the orgs' event automations (not sensitive)
193
+ { category: "triggers", items: p.triggers?.emit ?? [] },
191
194
  ];
192
195
  return groups
193
196
  .filter((g) => g.items.length > 0)
@@ -10,6 +10,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Readable, Transform } from "node:stream";
11
11
  import { pipeline } from "node:stream/promises";
12
12
  import { Inject, Injectable, Optional } from "@nestjs/common";
13
+ import { normalizeGitRepo } from "../automations/grant-rules.js";
14
+ import { appendMissingGrant } from "../automations/unattended.js";
13
15
  import { productName } from "../config/product-name.js";
14
16
  import { audit } from "../identity/audit.js";
15
17
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
@@ -17,8 +19,6 @@ import { KernelDb } from "../infra/database/kernel-db.js";
17
19
  import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
18
20
  import { NetDeniedError } from "../net/public-address.js";
19
21
  import { safeFetch } from "../net/safe-fetch.js";
20
- import { normalizeGitRepo } from "../schedules/grant-rules.js";
21
- import { appendMissingGrant } from "../schedules/unattended.js";
22
22
  import { CredentialMissing, Credentials } from "../tools/credentials.js";
23
23
  import { gitAskedNote, gitNotConnectedNote, gitPolicyDeniedNote, gitUnattendedNote, recordGitAsk, } from "../tools/git-asks.js";
24
24
  import { decideGitPush } from "../tools/git-push-policy.js";
@@ -0,0 +1,28 @@
1
+ import { z } from "zod";
2
+ /** A plain URL scheme (RFC 3986 letters, lowercase only so the match stays exact). */
3
+ export declare const APP_SCHEME_RE: RegExp;
4
+ /** The config a scheme decision reads (`KernelConfig` fits). */
5
+ export type AppSchemesConfig = {
6
+ http: {
7
+ publicUrl?: string | undefined;
8
+ };
9
+ auth: {
10
+ appRedirectUris: readonly string[];
11
+ };
12
+ };
13
+ /**
14
+ * The schemes `s` for which an entry of `auth.appRedirectUris` is exactly `${s}://auth/callback`,
15
+ * in list order; `[]` without `http.publicUrl` (no app sign-in, so no shell to return to).
16
+ */
17
+ export declare function appSchemes(config: AppSchemesConfig): string[];
18
+ /** A handoff start's return scheme: none passes; otherwise it must be one of {@link appSchemes}. */
19
+ export declare function assertReturnSchemeAllowed(config: AppSchemesConfig, scheme: string | undefined): void;
20
+ /**
21
+ * The `handoff` field of the connector connect and the login-method link start: present when a
22
+ * native shell asks to finish the flow in the system browser. `returnScheme` is the shell's own
23
+ * URL scheme (for the done page's way back into the app).
24
+ */
25
+ export declare const HandoffRequestSchema: z.ZodObject<{
26
+ returnScheme: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strict>;
28
+ export type HandoffRequest = z.infer<typeof HandoffRequestSchema>;