@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
@@ -147,7 +147,7 @@ export function buildSuggestionRequest(input) {
147
147
  }
148
148
  /**
149
149
  * Whether a finished run may get a suggestion by its outcome, conversation and trigger (spec §2):
150
- * `completed` or `max_steps`, a `chat` conversation from `web`, not a scheduled or compact run.
150
+ * `completed` or `max_steps`, a `chat` conversation from `web`, not an automation's or compact run.
151
151
  * The final reply, freshness and the switches are checked elsewhere.
152
152
  */
153
153
  export function suggestionEligible(i) {
@@ -155,6 +155,7 @@ export function suggestionEligible(i) {
155
155
  i.kind === "chat" &&
156
156
  i.source === "web" &&
157
157
  i.trigger !== "schedule" &&
158
+ i.trigger !== "automation_event" &&
158
159
  i.trigger !== "compact");
159
160
  }
160
161
  // C0 and C1 controls (newlines are split on first; a tab becomes a space)
@@ -1,7 +1,7 @@
1
1
  import { type ModelRef } from "../agents/definition.js";
2
+ import type { ScheduleMarker } from "../automations/types.js";
2
3
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
4
  import { ApiError } from "../errors.js";
4
- import type { ScheduleMarker } from "../schedules/types.js";
5
5
  import { type InvocationRecord, type RenderedInvocation } from "../skills/invoke.js";
6
6
  import type { AttachmentRef } from "./conversations.service.js";
7
7
  import { type AppendEvent, type EventLog } from "./event-log.js";
@@ -30,7 +30,7 @@ export interface QueuedSkill {
30
30
  record: InvocationRecord;
31
31
  }
32
32
  /**
33
- * A scheduled task's queued message (scheduled tasks spec §6), stored in
33
+ * An automation's queued message (scheduled tasks spec §6), stored in
34
34
  * `conversation_queue.schedule`: the marker the `user_message` carries and the task's zone, which
35
35
  * becomes the message's `timeZone` (the top-priority override of `readMessageContext`).
36
36
  */
@@ -104,9 +104,11 @@ export interface QueueRow {
104
104
  effort: string | null;
105
105
  skill: unknown;
106
106
  schedule: unknown;
107
+ /** An event automation's marker (collaboration spec §4.6); null for any other message. */
108
+ automation_event: unknown;
107
109
  created_at: Date;
108
110
  }
109
- export declare const COLUMNS: readonly ["id", "conversation_id", "account_id", "position", "text", "content", "attachments", "files", "client_message_id", "model", "effort", "skill", "schedule", "created_at"];
111
+ export declare const COLUMNS: readonly ["id", "conversation_id", "account_id", "position", "text", "content", "attachments", "files", "client_message_id", "model", "effort", "skill", "schedule", "automation_event", "created_at"];
110
112
  /**
111
113
  * Queued text as the event log will store it: NUL becomes U+FFFD (PG rejects NUL in text and
112
114
  * jsonb), the mapping `payloadJson` applies to a direct send (final review m1).
@@ -127,7 +129,8 @@ export declare function storedSkill(invokedAs: string, invoked: RenderedInvocati
127
129
  };
128
130
  /**
129
131
  * The `user_message` a queued item becomes, as `postUserMessage` would have written it; a scheduled
130
- * task's item carries its marker (without the stored zone, which is in `context`).
132
+ * task's item carries its marker (without the stored zone, which is in `context`), an event
133
+ * automation's item its event marker.
131
134
  */
132
135
  export declare function queuedUserMessage(r: QueueRow, context?: MessageContext): AppendEvent;
133
136
  /**
@@ -29,6 +29,7 @@ export const COLUMNS = [
29
29
  "effort",
30
30
  "skill",
31
31
  "schedule",
32
+ "automation_event",
32
33
  "created_at",
33
34
  ];
34
35
  /**
@@ -80,12 +81,14 @@ export function storedSkill(invokedAs, invoked) {
80
81
  }
81
82
  /**
82
83
  * The `user_message` a queued item becomes, as `postUserMessage` would have written it; a scheduled
83
- * task's item carries its marker (without the stored zone, which is in `context`).
84
+ * task's item carries its marker (without the stored zone, which is in `context`), an event
85
+ * automation's item its event marker.
84
86
  */
85
87
  export function queuedUserMessage(r, context = {}) {
86
88
  const attachments = r.attachments;
87
89
  const skill = r.skill;
88
90
  const marker = queuedMarker(r);
91
+ const event = r.automation_event;
89
92
  return {
90
93
  type: "user_message",
91
94
  idemKey: userMessageIdemKey(r.client_message_id),
@@ -101,6 +104,7 @@ export function queuedUserMessage(r, context = {}) {
101
104
  clientMessageId: r.client_message_id,
102
105
  ...(skill !== null && { skill: skill.record }),
103
106
  ...(marker !== undefined && { schedule: marker }),
107
+ ...(event !== null && event !== undefined && { automationEvent: event }),
104
108
  },
105
109
  };
106
110
  }
@@ -136,7 +140,7 @@ export async function appendQueuedIn(t, eventLog, conversationId, r) {
136
140
  payload: { ...next, byAccountId: r.account_id, reason: "user" },
137
141
  });
138
142
  }
139
- // run context spec §3.4: no browser values were stored with a leftover row; a scheduled task's
143
+ // run context spec §3.4: no browser values were stored with a leftover row; an automation's
140
144
  // item stored its task's zone, which wins (scheduled tasks spec §6)
141
145
  // org-filter: reads the org of the conversation the caller holds the row lock of
142
146
  const org = await t
@@ -30,7 +30,7 @@ export declare class ConversationQueue {
30
30
  * credentials. The same `clientMessageId` again returns the queued item (`created: false`), or,
31
31
  * when it was already sent, the sent `user_message` with `item: null`. Then `ensureRun`: on an
32
32
  * idle conversation the item goes out at once. `internal` (kernel callers only, never HTTP): a
33
- * scheduled task's marker and zone, stored with the item and written with its `user_message`
33
+ * automation's marker and zone, stored with the item and written with its `user_message`
34
34
  * (scheduled tasks spec §6).
35
35
  */
36
36
  add(orgId: string, conversationId: string, accountId: string, input: QueueInput, internal?: InternalMessageOptions): Promise<{
@@ -41,9 +41,9 @@ export declare class ConversationQueue {
41
41
  private addIn;
42
42
  /**
43
43
  * Changes a queued item's text (its resources and files stay as queued). A skill invocation's
44
- * text is its arguments: the skill is rendered again with them now. A scheduled task's item
45
- * becomes the person's message: its schedule marker (and the task's zone) is dropped, so the run
46
- * it triggers is attended (scheduled tasks spec §7).
44
+ * text is its arguments: the skill is rendered again with them now. An automation's item
45
+ * becomes the person's message: its schedule or event marker (and the task's zone) is dropped,
46
+ * so the run it triggers is attended (scheduled tasks spec §7).
47
47
  */
48
48
  edit(orgId: string, conversationId: string, accountId: string, itemId: string, text: string): Promise<QueueItem>;
49
49
  private editIn;
@@ -53,7 +53,7 @@ export declare class ConversationQueue {
53
53
  * Sends a queued item now: it leaves the queue and is posted as a user message in the same
54
54
  * transaction (an interjection when a run is active; the items before it keep their place).
55
55
  * Racing the dispatcher, exactly one of them takes the item; the loser sees it gone (404). A
56
- * scheduled task's item is sent as the person's message, without its schedule marker
56
+ * automation's item is sent as the person's message, without its schedule marker
57
57
  * (scheduled tasks spec §7).
58
58
  */
59
59
  sendNow(orgId: string, conversationId: string, accountId: string, itemId: string): Promise<ConversationEvent>;
@@ -10,11 +10,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { randomUUID } from "node:crypto";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
+ import { releaseQueuedTaskRunIn } from "../automations/run-tracker.js";
13
14
  import { KernelDb } from "../infra/database/kernel-db.js";
14
15
  import { TransactionHost } from "../infra/database/transaction-host.js";
15
16
  import { Transactional } from "../infra/database/transactional.decorator.js";
16
17
  import { RunControl as RunControlService } from "../runtime/run-control.js";
17
- import { releaseQueuedTaskRunIn } from "../schedules/run-tracker.js";
18
18
  import { notInvocable } from "../skills/invoke.js";
19
19
  import { ConversationsService, NO_REPLY_SKIPS, } from "./conversations.service.js";
20
20
  import { EventLog, payloadJson } from "./event-log.js";
@@ -70,7 +70,7 @@ let ConversationQueue = class ConversationQueue {
70
70
  * credentials. The same `clientMessageId` again returns the queued item (`created: false`), or,
71
71
  * when it was already sent, the sent `user_message` with `item: null`. Then `ensureRun`: on an
72
72
  * idle conversation the item goes out at once. `internal` (kernel callers only, never HTTP): a
73
- * scheduled task's marker and zone, stored with the item and written with its `user_message`
73
+ * automation's marker and zone, stored with the item and written with its `user_message`
74
74
  * (scheduled tasks spec §6).
75
75
  */
76
76
  async add(orgId, conversationId, accountId, input, internal = {}) {
@@ -174,6 +174,7 @@ let ConversationQueue = class ConversationQueue {
174
174
  timeZone: internal.timeZoneOverride,
175
175
  }),
176
176
  }),
177
+ automation_event: internal.automationEvent === undefined ? null : JSON.stringify(internal.automationEvent),
177
178
  })
178
179
  .returning(COLUMNS)
179
180
  .executeTakeFirstOrThrow();
@@ -184,9 +185,9 @@ let ConversationQueue = class ConversationQueue {
184
185
  }
185
186
  /**
186
187
  * Changes a queued item's text (its resources and files stay as queued). A skill invocation's
187
- * text is its arguments: the skill is rendered again with them now. A scheduled task's item
188
- * becomes the person's message: its schedule marker (and the task's zone) is dropped, so the run
189
- * it triggers is attended (scheduled tasks spec §7).
188
+ * text is its arguments: the skill is rendered again with them now. An automation's item
189
+ * becomes the person's message: its schedule or event marker (and the task's zone) is dropped,
190
+ * so the run it triggers is attended (scheduled tasks spec §7).
190
191
  */
191
192
  async edit(orgId, conversationId, accountId, itemId, text) {
192
193
  const conv = await this.conversations.writable(orgId, conversationId, accountId);
@@ -214,15 +215,15 @@ let ConversationQueue = class ConversationQueue {
214
215
  const t = this.db.db;
215
216
  const cur = await t
216
217
  .selectFrom("conversation_queue")
217
- .select(["attachments", "files", "content", "skill", "schedule"])
218
+ .select(["attachments", "files", "content", "skill", "schedule", "automation_event"])
218
219
  .where("id", "=", itemId)
219
220
  .where("conversation_id", "=", conversationId)
220
221
  .forUpdate()
221
222
  .executeTakeFirst();
222
223
  if (!cur)
223
224
  throw itemNotFound();
224
- // a person's words now: the task's run for this item will not happen (scheduled tasks §6)
225
- await releaseQueuedTaskRunIn(t, cur.schedule);
225
+ // a person's words now: the task's run for this item will not happen (automations §6)
226
+ await releaseQueuedTaskRunIn(t, cur);
226
227
  const skill = cur.skill;
227
228
  checkText(text, cur.files.length, cur.attachments.length, skill !== null);
228
229
  // an invocation's first block is its rendered text: replace it and the record
@@ -233,6 +234,7 @@ let ConversationQueue = class ConversationQueue {
233
234
  text: noNul(text),
234
235
  // edited by a person: no longer the task's message
235
236
  schedule: null,
237
+ automation_event: null,
236
238
  updated_at: sql `now()`,
237
239
  ...(stored !== undefined && {
238
240
  skill: stored.skill,
@@ -258,12 +260,12 @@ let ConversationQueue = class ConversationQueue {
258
260
  .deleteFrom("conversation_queue")
259
261
  .where("id", "=", itemId)
260
262
  .where("conversation_id", "=", conversationId)
261
- .returning(["id", "schedule"])
263
+ .returning(["id", "schedule", "automation_event"])
262
264
  .executeTakeFirst();
263
265
  if (!gone)
264
266
  throw itemNotFound();
265
- // a task's queued message deleted by a person: its run is skipped (scheduled tasks §6)
266
- await releaseQueuedTaskRunIn(t, gone.schedule);
267
+ // a task's queued message deleted by a person: its run is skipped (automations §6)
268
+ await releaseQueuedTaskRunIn(t, gone);
267
269
  await unpauseIfEmpty(t, conversationId);
268
270
  // the wakes an unpause releases for the tree are owed with it (transactional outbox spec §6)
269
271
  await this.runs.oweHeldTreeIn(conversationId);
@@ -272,7 +274,7 @@ let ConversationQueue = class ConversationQueue {
272
274
  * Sends a queued item now: it leaves the queue and is posted as a user message in the same
273
275
  * transaction (an interjection when a run is active; the items before it keep their place).
274
276
  * Racing the dispatcher, exactly one of them takes the item; the loser sees it gone (404). A
275
- * scheduled task's item is sent as the person's message, without its schedule marker
277
+ * automation's item is sent as the person's message, without its schedule marker
276
278
  * (scheduled tasks spec §7).
277
279
  */
278
280
  async sendNow(orgId, conversationId, accountId, itemId) {
@@ -319,8 +321,12 @@ let ConversationQueue = class ConversationQueue {
319
321
  throw itemNotFound();
320
322
  const sent = await alreadySent(t, conversationId, row.client_message_id);
321
323
  // sent by a person: their message, not the task's, whose run is skipped
322
- await releaseQueuedTaskRunIn(t, row.schedule);
323
- const out = await appendQueuedIn(t, this.eventLog, conversationId, { ...row, schedule: null });
324
+ await releaseQueuedTaskRunIn(t, row);
325
+ const out = await appendQueuedIn(t, this.eventLog, conversationId, {
326
+ ...row,
327
+ schedule: null,
328
+ automation_event: null,
329
+ });
324
330
  await unpauseIfEmpty(t, conversationId);
325
331
  // sent during the run, the item is the author's message like a direct send: it skips the
326
332
  // pending questions they may answer (reply-while-question spec §4.2)
@@ -1,6 +1,7 @@
1
- import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher } from "@capybara-hq/plugin-sdk";
1
+ import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher, type TriggerEvent } from "@capybara-hq/plugin-sdk";
2
2
  import type { Redis } from "ioredis";
3
3
  import { Kysely } from "kysely";
4
+ import type { TriggerEventsService } from "../automations/events/trigger-events.service.js";
4
5
  import type { DeviceAccessService } from "../device-access/device-access.service.js";
5
6
  import type { DialInAccess } from "../dial-in/access.js";
6
7
  import { type RegisteredHook } from "../extensions/hooks.js";
@@ -76,6 +77,12 @@ export interface KernelDeps {
76
77
  * a test, the CLI): `ctx.deviceAccess` calls are refused.
77
78
  */
78
79
  deviceAccess?: () => DeviceAccessBackend | undefined;
80
+ /**
81
+ * What `ctx.triggers` calls through (`TriggerEventsService`), found at the time of use like
82
+ * `deviceAccess`. Absent, or resolving to undefined (a ctx built alone in a test, the CLI):
83
+ * `ctx.triggers.emit` rejects.
84
+ */
85
+ triggers?: () => TriggersBackend | undefined;
79
86
  runWorkers: boolean;
80
87
  /** 内核 logger(`debug` 可选:插件 Logger 没有它,测试可不给)。 */
81
88
  log: Logger & {
@@ -84,6 +91,16 @@ export interface KernelDeps {
84
91
  }
85
92
  /** What `ctx.deviceAccess` calls through (`DeviceAccessService`). */
86
93
  export type DeviceAccessBackend = Pick<DeviceAccessService, "ensureService" | "request" | "reportBlockedHosts" | "streamTicket" | "addNetworkHosts" | "answerHandoff">;
94
+ /** What `ctx.triggers` calls through (`TriggerEventsService`). */
95
+ export type TriggersBackend = Pick<TriggerEventsService, "emit">;
96
+ /**
97
+ * A plain-data copy of an emitted event, taken once at the ctx boundary (check-then-use): every
98
+ * own enumerable field is read once (a getter cannot change a value after it was validated),
99
+ * prototypes and accessors are dropped. `cause.call` keeps its original reference, since the
100
+ * pipeline's call scope is a symbol-keyed field and the context holds an `AbortSignal`, neither of
101
+ * which a clone keeps; only its scope is read. Data that cannot be cloned is `invalid_event`.
102
+ */
103
+ export declare function snapshotTriggerEvent(event: TriggerEvent): TriggerEvent;
87
104
  /**
88
105
  * What `ctx.ui.verifyEmbedToken` returns for a valid token: the signed claims, with an org
89
106
  * token's `role` replaced by the caller's role at verification time.
@@ -209,6 +226,8 @@ export declare class LiveConfig {
209
226
  * (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
210
227
  * an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
211
228
  * this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
229
+ * `triggers` only with `permissions.triggers`, each emit only of a declared event type, stored
230
+ * in the event's org scope (through `deps.triggers`);
212
231
  * `http.route`
213
232
  * only the method + path declared in `permissions.http` (the record carries the declared access and
214
233
  * its mount, see {@link Route}); `tools.register` only names declared in
@@ -1,4 +1,4 @@
1
- import { DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
1
+ import { DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, EXTENSION_POINTS, ExtensionPermissionError, ExtensionPointUnavailableError, FILE_PREVIEW_EXTENSION_POINT, OBJECT_STORE_EXTENSION_POINT, parseExtensionPoint, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, TriggerError, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
2
2
  import { Command, ConnectionBuilder, ControlledTransactionBuilder, Kysely, TransactionBuilder, } from "kysely";
3
3
  import { conversationTopic } from "../conversations/event-log.js";
4
4
  import { kernelDb } from "../db/kernel-schema.js";
@@ -7,6 +7,7 @@ import { enabledExtensionsQuery, isExtensionEnabled } from "../extensions/enable
7
7
  import { checkHookRegistration } from "../extensions/hooks.js";
8
8
  import { RegistrationLedger } from "../extensions/ledger.js";
9
9
  import { audit } from "../identity/audit.js";
10
+ import { withOrgScope } from "../infra/database/org-scope.js";
10
11
  import { can } from "../orgs/roles.js";
11
12
  import { PrefixedStorage } from "../storage/storage.service.js";
12
13
  import { canUseSlot, orgUiTopic, PLATFORM_UI_TOPIC, PluginUiRegistration, } from "../ui/registry.js";
@@ -17,6 +18,39 @@ import { createLock } from "./lock.js";
17
18
  import { createExtensionNet } from "./net.js";
18
19
  import { createQueue } from "./queue.js";
19
20
  import { createSecrets } from "./secrets.js";
21
+ /**
22
+ * A plain-data copy of an emitted event, taken once at the ctx boundary (check-then-use): every
23
+ * own enumerable field is read once (a getter cannot change a value after it was validated),
24
+ * prototypes and accessors are dropped. `cause.call` keeps its original reference, since the
25
+ * pipeline's call scope is a symbol-keyed field and the context holds an `AbortSignal`, neither of
26
+ * which a clone keeps; only its scope is read. Data that cannot be cloned is `invalid_event`.
27
+ */
28
+ export function snapshotTriggerEvent(event) {
29
+ if (typeof event !== "object" || event === null || Array.isArray(event))
30
+ throw new TriggerError("invalid_event", "the event must be an object");
31
+ try {
32
+ const { cause, ...rest } = event;
33
+ const snap = structuredClone(rest);
34
+ if (cause === undefined)
35
+ return snap;
36
+ if (typeof cause !== "object" || cause === null) {
37
+ snap.cause = cause;
38
+ return snap;
39
+ }
40
+ const plain = { ...cause };
41
+ if ("call" in plain) {
42
+ const { call, ...others } = plain;
43
+ snap.cause = { ...structuredClone(others), call };
44
+ }
45
+ else {
46
+ snap.cause = structuredClone(plain);
47
+ }
48
+ return snap;
49
+ }
50
+ catch (err) {
51
+ throw new TriggerError("invalid_event", "the event must be plain data", { cause: err });
52
+ }
53
+ }
20
54
  /**
21
55
  * Queries the names of the extensions enabled in the organization (org config rows plus the
22
56
  * required bootstrap plugins, see `extensions/enabled.ts`), not cached.
@@ -193,6 +227,8 @@ export class LiveConfig {
193
227
  * (through `deps.dialIn`; another device throws `ExtensionPermissionError`); `devices` only for
194
228
  * an extension that provides `device-provider@1`, `reportChanged` only for a live device bound to
195
229
  * this extension (through `deps.devices`; another device throws `ExtensionPermissionError`);
230
+ * `triggers` only with `permissions.triggers`, each emit only of a declared event type, stored
231
+ * in the event's org scope (through `deps.triggers`);
196
232
  * `http.route`
197
233
  * only the method + path declared in `permissions.http` (the record carries the declared access and
198
234
  * its mount, see {@link Route}); `tools.register` only names declared in
@@ -396,6 +432,26 @@ identity = { sha256: null }) {
396
432
  };
397
433
  })()
398
434
  : undefined;
435
+ // ctx.triggers: only with permissions.triggers; the event types come from the approved manifest
436
+ // (a frozen copy: the extension changing its manifest object later changes nothing), and the
437
+ // event is stored in its own org's scope (TriggerEventsService checks the rest)
438
+ const triggersApi = perms.triggers
439
+ ? (() => {
440
+ const declared = Object.freeze([...(perms.triggers?.emit ?? [])]);
441
+ return {
442
+ emit: async (event) => {
443
+ const b = deps.triggers?.();
444
+ if (!b)
445
+ throw new Error("Trigger events are not available in this process.");
446
+ // one snapshot, read once: what is checked is what is stored
447
+ const snap = snapshotTriggerEvent(event);
448
+ if (typeof snap.orgId !== "string" || snap.orgId === "")
449
+ throw new TriggerError("invalid_event", "invalid event: missing_org_id");
450
+ return withOrgScope(snap.orgId, () => b.emit(name, declared, snap));
451
+ },
452
+ };
453
+ })()
454
+ : undefined;
399
455
  // "METHOD path" -> the access the manifest declares for it (the approved manifest)
400
456
  const declaredRoutes = new Map((perms.http ?? []).map((r) => [`${r.method} ${r.path}`, r.access]));
401
457
  const declaredTools = new Set(perms.tools ?? []);
@@ -851,7 +907,7 @@ identity = { sha256: null }) {
851
907
  return closing;
852
908
  },
853
909
  };
854
- // secrets / storage / models / dialIn / devices / deviceAccess: a plain property when declared; otherwise a
910
+ // secrets / storage / models / dialIn / devices / deviceAccess / triggers: a plain property when declared; otherwise a
855
911
  // non-enumerable getter that throws, so spreading or printing ctx triggers no denial and no audit
856
912
  const gated = (key, api, item = `permissions.${key}`) => {
857
913
  if (api) {
@@ -870,6 +926,7 @@ identity = { sha256: null }) {
870
926
  gated("dialIn", dialInApi);
871
927
  gated("devices", devicesApi, `provides ${DEVICE_PROVIDER_EXTENSION_POINT}`);
872
928
  gated("deviceAccess", deviceAccessApi);
929
+ gated("triggers", triggersApi);
873
930
  return ctx;
874
931
  }
875
932
  /**
@@ -1,6 +1,7 @@
1
- import type { ConversationSource, FileSystemHandle, GitHostEntry, ParsedTheme, PermissionProfile, SandboxBrowseScope, SandboxExecutionRef, SandboxOperationScope, SandboxPermissionSupport, SandboxRoots, SkillInvocation } from "@capybara-hq/plugin-sdk";
1
+ import type { ConversationSource, FileSystemHandle, GitHostEntry, ParsedTheme, PermissionProfile, SandboxBrowseScope, SandboxExecutionRef, SandboxOperationScope, SandboxPermissionSupport, SandboxRoots, SkillInvocation, TriggerFactValue, TriggerSubject } from "@capybara-hq/plugin-sdk";
2
2
  import type { ColumnType, Generated, Kysely } from "kysely";
3
3
  import type { ModelRef } from "../agents/definition.js";
4
+ import type { AutomationChat, AutomationEventMarker, AutomationMode, AutomationOrigin, AutomationPauseReason, AutomationPrincipal, AutomationStatus, AutomationTrigger, AutomationUnattendedAsk, ScheduleMarker, TaskRunSkipReason, TaskRunStatus } from "../automations/types.js";
4
5
  import type { AccountAvatar } from "../identity/account-avatar.js";
5
6
  import type { DeviceNetwork } from "../sandbox/modes.js";
6
7
  import type { StartingExecutionGrants } from "../sandbox/operation-authority-types.js";
@@ -8,7 +9,6 @@ import type { AuthorityEpochVector } from "../sandbox/permission-authority-epoch
8
9
  import type { PermissionEscalation, PermissionExpansion, PermissionGrantSource, PermissionScopeKind } from "../sandbox/permission-call-types.js";
9
10
  import type { PermissionConfigProjection } from "../sandbox/permission-config-publication.js";
10
11
  import type { PermissionRuntimeIdentity } from "../sandbox/permission-runtime-reports.js";
11
- import type { ScheduleChat, ScheduleMarker, ScheduleMode, SchedulePauseReason, ScheduleStatus, ScheduleTrigger, TaskRunSkipReason, TaskRunStatus } from "../schedules/types.js";
12
12
  /** 带默认值的时间戳列:插入可省略,读出为 Date。 */
13
13
  type Ts = ColumnType<Date, Date | string | undefined, Date | string>;
14
14
  type TsNullable = ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
@@ -184,7 +184,7 @@ export interface PushRegistrationsTable {
184
184
  /** A person's switch for one push category (migration 0172); an absent row is on. */
185
185
  export interface PushPreferencesTable {
186
186
  account_id: string;
187
- category: "waiting" | "replies" | "tasks" | "schedules";
187
+ category: "waiting" | "replies" | "tasks" | "automations";
188
188
  enabled: boolean;
189
189
  updated_at: Ts;
190
190
  }
@@ -426,8 +426,10 @@ export interface ConversationsTable {
426
426
  subagent_depth: ColumnType<number, number | undefined, number>;
427
427
  /** 0088, renamed in 0105: the device the conversation runs in; null = not chosen yet. */
428
428
  device_id: ColumnType<string | null, string | null | undefined, string | null>;
429
- /** 0113: the scheduled task that created it (`new` mode); null otherwise. */
430
- scheduled_task_id: ColumnType<string | null, string | null | undefined, string | null>;
429
+ /** 0113, renamed in 0188: the automation that created it (`new` mode); null otherwise. */
430
+ automation_id: ColumnType<string | null, string | null | undefined, string | null>;
431
+ /** 0189: the event subject the conversation serves (collaboration spec §4.5); null = none. */
432
+ subject: ColumnType<ConversationSubject | null, string | null | undefined, string | null>;
431
433
  /**
432
434
  * 0124: where the conversation comes from, set at creation and never changed. Required on insert
433
435
  * (the column's `web` default is not relied on: a forgotten source must not read as web).
@@ -484,16 +486,26 @@ export interface ConversationQueueTable {
484
486
  /** 0062: the `user_message.skill` record of a queued skill invocation, or null. */
485
487
  skill: ColumnType<unknown, string | null | undefined, string | null>;
486
488
  /**
487
- * 0113: the schedule marker of a scheduled task's message, plus the task's zone (`timeZone`, the
489
+ * 0113: the schedule marker of an automation's message, plus the task's zone (`timeZone`, the
488
490
  * message's zone override; not copied into the logged marker); null for a person's message.
489
491
  */
490
492
  schedule: ColumnType<(ScheduleMarker & {
491
493
  timeZone?: string;
492
494
  }) | null, string | null | undefined, string | null>;
495
+ /** 0189: the event marker of an event automation's message; null otherwise. */
496
+ automation_event: ColumnType<AutomationEventMarker | null, string | null | undefined, string | null>;
493
497
  created_at: Ts;
494
498
  updated_at: Ts;
495
499
  }
496
500
  export type TitleSource = "generated" | "manual";
501
+ /** `conversations.subject` (0189): what an event automation's conversation is about. */
502
+ export interface ConversationSubject {
503
+ /** The extension that emitted the subject's events. */
504
+ source: string;
505
+ kind: string;
506
+ id: string;
507
+ title: string;
508
+ }
497
509
  /** chat; eval (a hidden full-run replay conversation); subagent (0053: a sub-agent's conversation). */
498
510
  export type ConversationKind = "chat" | "eval" | "subagent";
499
511
  /** 0006_conversations.sql:会话事件日志,只追加。 */
@@ -547,10 +559,12 @@ export interface RunsTable {
547
559
  */
548
560
  budget_run_id: ColumnType<string | null, string | null | undefined, string | null>;
549
561
  /**
550
- * 0113: the scheduled task run this run serves (set on the run the task's message triggers and
562
+ * 0113, renamed in 0188: the automation run this run serves (set on the run the task's message triggers and
551
563
  * inherited by its unattended descendants); null = a person's run.
552
564
  */
553
- scheduled_task_run_id: ColumnType<string | null, string | null | undefined, string | null>;
565
+ automation_run_id: ColumnType<string | null, string | null | undefined, string | null>;
566
+ /** 0189: the trigger event an event automation's run serves; null otherwise. */
567
+ trigger_event_id: ColumnType<string | null, string | null | undefined, string | null>;
554
568
  /**
555
569
  * 0132: a manual compaction run (context compaction spec §4.7): it calls the shared compaction
556
570
  * execution with `force: true` instead of the agent loop, and writes no model step.
@@ -1520,23 +1534,23 @@ export interface ModelUsageTable {
1520
1534
  }
1521
1535
  type NullableText = ColumnType<string | null, string | null | undefined, string | null>;
1522
1536
  type NullableTs = ColumnType<Date | null, Date | string | null | undefined, Date | string | null>;
1523
- /** 0113: a scheduled task (scheduled tasks spec §4). */
1524
- export interface ScheduledTasksTable {
1537
+ /** 0113 (renamed in 0188 from the scheduled tasks table): an automation (scheduled tasks spec §4). */
1538
+ export interface AutomationsTable {
1525
1539
  id: string;
1526
1540
  org_id: string;
1527
1541
  account_id: string;
1528
1542
  agent_id: string;
1529
1543
  name: string;
1530
1544
  prompt: string;
1531
- trigger: ColumnType<ScheduleTrigger, string, string>;
1532
- mode: ScheduleMode;
1545
+ trigger: ColumnType<AutomationTrigger, string, string>;
1546
+ mode: AutomationMode;
1533
1547
  conversation_id: NullableText;
1534
- chat: ColumnType<ScheduleChat | null, string | null | undefined, string | null>;
1548
+ chat: ColumnType<AutomationChat | null, string | null | undefined, string | null>;
1535
1549
  model: ColumnType<ModelRef | null, string | null | undefined, string | null>;
1536
1550
  effort: NullableText;
1537
1551
  device_id: NullableText;
1538
- status: ColumnType<ScheduleStatus, ScheduleStatus | undefined, ScheduleStatus>;
1539
- pause_reason: ColumnType<SchedulePauseReason | null, SchedulePauseReason | null | undefined, SchedulePauseReason | null>;
1552
+ status: ColumnType<AutomationStatus, AutomationStatus | undefined, AutomationStatus>;
1553
+ pause_reason: ColumnType<AutomationPauseReason | null, AutomationPauseReason | null | undefined, AutomationPauseReason | null>;
1540
1554
  paused_by: NullableText;
1541
1555
  next_run_at: NullableTs;
1542
1556
  jitter_seconds: ColumnType<number, number | undefined, number>;
@@ -1545,6 +1559,12 @@ export interface ScheduledTasksTable {
1545
1559
  created_at: Ts;
1546
1560
  updated_at: Ts;
1547
1561
  deleted_at: NullableTs;
1562
+ /** 0189: who made it (collaboration spec §4.1). */
1563
+ origin: ColumnType<AutomationOrigin, AutomationOrigin | undefined, AutomationOrigin>;
1564
+ /** 0189: whom it acts as; null = the member `account_id` (reserved for agent principals). */
1565
+ principal: ColumnType<AutomationPrincipal | null, string | null | undefined, string | null>;
1566
+ /** 0189: what a question in an unattended run does; null = the default. */
1567
+ unattended_ask: ColumnType<AutomationUnattendedAsk | null, AutomationUnattendedAsk | null | undefined, AutomationUnattendedAsk | null>;
1548
1568
  }
1549
1569
  /** Why a file share was revoked (0161). */
1550
1570
  export type FileShareRevokeReason = "creator" | "admin" | "conversation_deleted" | "member_offboarded" | "creator_lost_access";
@@ -1584,12 +1604,19 @@ export interface FileSharesTable {
1584
1604
  created_at: Ts;
1585
1605
  updated_at: Ts;
1586
1606
  }
1587
- /** 0113: one tick (or trial run) of a scheduled task; unique per (task, tick) when not trial. */
1588
- export interface ScheduledTaskRunsTable {
1607
+ /**
1608
+ * 0113 (renamed in 0188 from the scheduled task runs table): one tick, event fire (0189) or trial
1609
+ * run of an automation; unique per (automation, trigger key) when not trial.
1610
+ */
1611
+ export interface AutomationRunsTable {
1589
1612
  id: string;
1590
- task_id: string;
1613
+ /** 0188: renamed from `task_id`. */
1614
+ automation_id: string;
1591
1615
  org_id: string;
1592
- scheduled_for: Date | string;
1616
+ /** 0189: nullable; null for an event run. */
1617
+ scheduled_for: ColumnType<Date | null, Date | string | null, Date | string | null>;
1618
+ /** 0189: the tick as `Date.toISOString()` for a time run, the event id for an event run. */
1619
+ trigger_key: string;
1593
1620
  fired_at: NullableTs;
1594
1621
  trial: ColumnType<boolean, boolean | undefined, boolean>;
1595
1622
  /** A person's "run now" (trial or not): runs even while the task is paused. */
@@ -1600,10 +1627,59 @@ export interface ScheduledTaskRunsTable {
1600
1627
  skip_reason: ColumnType<TaskRunSkipReason | null, TaskRunSkipReason | null | undefined, TaskRunSkipReason | null>;
1601
1628
  error: NullableText;
1602
1629
  missing_grants: ColumnType<string[], string | undefined, string>;
1630
+ /** 0189: when the run was recorded (an event run's moment before its claim). */
1631
+ created_at: Ts;
1603
1632
  }
1604
- /** 0113: a scheduled task's remembered grants (same shape as `conversation_tool_grants`). */
1605
- export interface ScheduledTaskGrantsTable {
1606
- task_id: string;
1633
+ /**
1634
+ * 0189: an event an extension emitted (`ctx.triggers.emit`, collaboration spec §4.2); unique per
1635
+ * (org, plugin, dedupe key).
1636
+ */
1637
+ export interface TriggerEventsTable {
1638
+ id: string;
1639
+ org_id: string;
1640
+ plugin: string;
1641
+ type: string;
1642
+ subject: ColumnType<TriggerSubject, string, string>;
1643
+ facts: ColumnType<Record<string, TriggerFactValue>, string | undefined, string>;
1644
+ summary: string;
1645
+ dedupe_key: string;
1646
+ audience: ColumnType<{
1647
+ accountId: string;
1648
+ agentId: string;
1649
+ } | null, string | null | undefined, string | null>;
1650
+ cause_account_id: NullableText;
1651
+ cause_run_id: NullableText;
1652
+ depth: ColumnType<number, number | undefined, number>;
1653
+ state: ColumnType<TriggerEventState, TriggerEventState | undefined, TriggerEventState>;
1654
+ created_at: Ts;
1655
+ }
1656
+ export type TriggerEventState = "pending" | "dispatched" | "undelivered" | "depth_stopped";
1657
+ /**
1658
+ * 0189: an event that reached an automation, and the run that served it (null while it waits:
1659
+ * events of one subject coalesce, collaboration spec §4.7).
1660
+ */
1661
+ export interface AutomationEventDeliveriesTable {
1662
+ org_id: string;
1663
+ automation_id: string;
1664
+ event_id: string;
1665
+ /** `<subject kind>:<subject id>`. */
1666
+ subject_key: string;
1667
+ automation_run_id: NullableText;
1668
+ created_at: Ts;
1669
+ }
1670
+ /** 0189: the one conversation per subject of a `subject`-mode automation (collaboration §4.5). */
1671
+ export interface AutomationConversationsTable {
1672
+ org_id: string;
1673
+ automation_id: string;
1674
+ subject_kind: string;
1675
+ subject_id: string;
1676
+ conversation_id: string;
1677
+ created_at: Ts;
1678
+ }
1679
+ /** 0113 (renamed in 0188 from the scheduled task grants table): an automation's remembered grants (same shape as `conversation_tool_grants`). */
1680
+ export interface AutomationGrantsTable {
1681
+ /** 0188: renamed from `task_id`. */
1682
+ automation_id: string;
1607
1683
  tool_key: string;
1608
1684
  spec_hash: string;
1609
1685
  connector_id: string | null;
@@ -1770,9 +1846,12 @@ export interface KernelDatabase {
1770
1846
  device_projects: DeviceProjectsTable;
1771
1847
  device_conversation_notices: DeviceConversationNoticesTable;
1772
1848
  background_tasks: BackgroundTasksTable;
1773
- scheduled_tasks: ScheduledTasksTable;
1774
- scheduled_task_runs: ScheduledTaskRunsTable;
1775
- scheduled_task_grants: ScheduledTaskGrantsTable;
1849
+ automations: AutomationsTable;
1850
+ automation_runs: AutomationRunsTable;
1851
+ automation_grants: AutomationGrantsTable;
1852
+ trigger_events: TriggerEventsTable;
1853
+ automation_event_deliveries: AutomationEventDeliveriesTable;
1854
+ automation_conversations: AutomationConversationsTable;
1776
1855
  file_shares: FileSharesTable;
1777
1856
  platform_icons: PlatformIconsTable;
1778
1857
  skills: SkillsTable;