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

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 (359) hide show
  1. package/dist/admin/admin.schemas.d.ts +3 -0
  2. package/dist/agents/agents.schemas.d.ts +9 -9
  3. package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
  4. package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
  5. package/dist/automations/automations.module.d.ts +16 -0
  6. package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
  7. package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
  8. package/dist/automations/automations.schemas.js +253 -0
  9. package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
  10. package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
  11. package/dist/{schedules → automations}/calendar.d.ts +8 -8
  12. package/dist/{schedules → automations}/calendar.js +2 -2
  13. package/dist/automations/effective-settings.d.ts +28 -0
  14. package/dist/automations/effective-settings.js +25 -0
  15. package/dist/automations/errors.d.ts +19 -0
  16. package/dist/automations/errors.js +19 -0
  17. package/dist/automations/events/coalesce.d.ts +28 -0
  18. package/dist/automations/events/coalesce.js +131 -0
  19. package/dist/automations/events/deadline.d.ts +10 -0
  20. package/dist/automations/events/deadline.js +24 -0
  21. package/dist/automations/events/dispatcher.d.ts +74 -0
  22. package/dist/automations/events/dispatcher.js +353 -0
  23. package/dist/automations/events/events.module.d.ts +7 -0
  24. package/dist/automations/events/events.module.js +26 -0
  25. package/dist/automations/events/guards.d.ts +32 -0
  26. package/dist/automations/events/guards.js +87 -0
  27. package/dist/automations/events/sweep.job.d.ts +49 -0
  28. package/dist/automations/events/sweep.job.js +202 -0
  29. package/dist/automations/events/token.d.ts +5 -0
  30. package/dist/automations/events/token.js +5 -0
  31. package/dist/automations/events/trigger-events.service.d.ts +47 -0
  32. package/dist/automations/events/trigger-events.service.js +254 -0
  33. package/dist/{schedules → automations}/fire.d.ts +57 -17
  34. package/dist/{schedules → automations}/fire.js +311 -79
  35. package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
  36. package/dist/{schedules → automations}/grant-rules.js +5 -5
  37. package/dist/automations/job-ids.d.ts +113 -0
  38. package/dist/automations/job-ids.js +117 -0
  39. package/dist/{schedules → automations}/pause.d.ts +3 -3
  40. package/dist/{schedules → automations}/pause.js +3 -3
  41. package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
  42. package/dist/{schedules → automations}/run-tracker.js +68 -56
  43. package/dist/{schedules → automations}/scan.job.d.ts +12 -8
  44. package/dist/{schedules → automations}/scan.job.js +39 -23
  45. package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
  46. package/dist/{schedules → automations}/schedule-math.js +17 -7
  47. package/dist/{schedules → automations}/store.d.ts +57 -27
  48. package/dist/{schedules → automations}/store.js +102 -52
  49. package/dist/automations/store.module.d.ts +6 -0
  50. package/dist/{schedules → automations}/store.module.js +9 -9
  51. package/dist/automations/types.d.ts +178 -0
  52. package/dist/{schedules → automations}/unattended.d.ts +22 -11
  53. package/dist/{schedules → automations}/unattended.js +53 -30
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/channels/channels.module.js +7 -6
  56. package/dist/channels/file-delivery.d.ts +26 -11
  57. package/dist/channels/file-delivery.js +32 -11
  58. package/dist/channels/outbound.d.ts +8 -8
  59. package/dist/channels/outbound.js +32 -30
  60. package/dist/channels/threads.d.ts +1 -1
  61. package/dist/channels/threads.js +1 -1
  62. package/dist/config/schema.d.ts +8 -1
  63. package/dist/config/schema.js +56 -6
  64. package/dist/conversations/approval-profile.d.ts +2 -2
  65. package/dist/conversations/approval-profile.js +3 -3
  66. package/dist/conversations/artifacts.d.ts +20 -17
  67. package/dist/conversations/artifacts.js +30 -37
  68. package/dist/conversations/attachments.controller.d.ts +6 -19
  69. package/dist/conversations/attachments.controller.js +8 -59
  70. package/dist/conversations/attachments.service.d.ts +30 -74
  71. package/dist/conversations/attachments.service.js +51 -193
  72. package/dist/conversations/conversations.controller.d.ts +7 -1
  73. package/dist/conversations/conversations.controller.js +26 -10
  74. package/dist/conversations/conversations.module.js +4 -0
  75. package/dist/conversations/conversations.service.d.ts +112 -35
  76. package/dist/conversations/conversations.service.js +160 -43
  77. package/dist/conversations/event-log.d.ts +1 -0
  78. package/dist/conversations/events.d.ts +95 -27
  79. package/dist/conversations/events.js +108 -10
  80. package/dist/conversations/files.d.ts +66 -64
  81. package/dist/conversations/files.js +127 -147
  82. package/dist/conversations/message-context.d.ts +2 -2
  83. package/dist/conversations/message-context.js +1 -1
  84. package/dist/conversations/permission-profile-store.d.ts +2 -1
  85. package/dist/conversations/permission-profiles.controller.d.ts +3 -0
  86. package/dist/conversations/permission-profiles.service.js +1 -1
  87. package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
  88. package/dist/conversations/prompt-suggestion-request.js +4 -2
  89. package/dist/conversations/prompt-suggestions.d.ts +3 -3
  90. package/dist/conversations/prompt-suggestions.js +11 -10
  91. package/dist/conversations/queue.d.ts +7 -4
  92. package/dist/conversations/queue.js +6 -2
  93. package/dist/conversations/queue.service.d.ts +5 -5
  94. package/dist/conversations/queue.service.js +27 -16
  95. package/dist/ctx/create-ctx.d.ts +23 -2
  96. package/dist/ctx/create-ctx.js +78 -3
  97. package/dist/db/kernel-schema.d.ts +184 -27
  98. package/dist/devices/device-project-files.service.d.ts +88 -0
  99. package/dist/devices/device-project-files.service.js +249 -0
  100. package/dist/devices/device-projects.service.d.ts +40 -0
  101. package/dist/devices/device-projects.service.js +16 -13
  102. package/dist/devices/devices.controller.d.ts +9 -3
  103. package/dist/devices/devices.controller.js +27 -5
  104. package/dist/devices/devices.module.js +9 -1
  105. package/dist/devices/devices.schemas.js +6 -1
  106. package/dist/devices/dto.d.ts +15 -0
  107. package/dist/devices/dto.js +11 -0
  108. package/dist/devices/project-paths.d.ts +29 -0
  109. package/dist/devices/project-paths.js +66 -0
  110. package/dist/devices/project-rules.d.ts +5 -1
  111. package/dist/devices/project-rules.js +5 -1
  112. package/dist/errors.d.ts +53 -13
  113. package/dist/errors.js +53 -13
  114. package/dist/evals/canonical-json.d.ts +7 -0
  115. package/dist/evals/canonical-json.js +21 -0
  116. package/dist/evals/reconstruct.d.ts +10 -1
  117. package/dist/evals/reconstruct.js +20 -1
  118. package/dist/evals/recorded-tools.d.ts +0 -2
  119. package/dist/evals/recorded-tools.js +1 -16
  120. package/dist/evals/snapshot.d.ts +26 -3
  121. package/dist/evals/snapshot.js +110 -57
  122. package/dist/evals/worker.d.ts +4 -3
  123. package/dist/evals/worker.js +8 -4
  124. package/dist/extensions/host.d.ts +9 -2
  125. package/dist/extensions/host.js +12 -0
  126. package/dist/extensions/instance.d.ts +3 -1
  127. package/dist/extensions/instance.js +4 -0
  128. package/dist/extensions/ledger.d.ts +1 -1
  129. package/dist/extensions/permission-set.d.ts +17 -1
  130. package/dist/extensions/permission-set.js +13 -1
  131. package/dist/extensions/permission-view.d.ts +1 -1
  132. package/dist/extensions/permission-view.js +4 -1
  133. package/dist/files/blob-objects.d.ts +124 -0
  134. package/dist/files/blob-objects.js +341 -0
  135. package/dist/files/blob-sweep.job.d.ts +122 -0
  136. package/dist/files/blob-sweep.job.js +389 -0
  137. package/dist/files/blobs.service.d.ts +135 -0
  138. package/dist/files/blobs.service.js +300 -0
  139. package/dist/files/conversation-media.d.ts +41 -0
  140. package/dist/files/conversation-media.js +124 -0
  141. package/dist/files/deliveries.d.ts +64 -0
  142. package/dist/files/deliveries.js +156 -0
  143. package/dist/files/deliveries.module.d.ts +6 -0
  144. package/dist/files/deliveries.module.js +24 -0
  145. package/dist/files/draft-cleanup.job.d.ts +26 -0
  146. package/dist/files/draft-cleanup.job.js +93 -0
  147. package/dist/files/files.module.d.ts +1 -1
  148. package/dist/files/files.module.js +3 -2
  149. package/dist/files/hash-job.d.ts +127 -0
  150. package/dist/files/hash-job.js +447 -0
  151. package/dist/files/library-backfill.d.ts +63 -0
  152. package/dist/files/library-backfill.js +143 -0
  153. package/dist/files/library-files.service.d.ts +255 -0
  154. package/dist/files/library-files.service.js +883 -0
  155. package/dist/files/library-jobs.module.d.ts +8 -0
  156. package/dist/files/library-jobs.module.js +27 -0
  157. package/dist/files/library-query.d.ts +127 -0
  158. package/dist/files/library-query.js +322 -0
  159. package/dist/files/library-read.module.d.ts +9 -0
  160. package/dist/files/library-read.module.js +30 -0
  161. package/dist/files/library.controller.d.ts +77 -0
  162. package/dist/files/library.controller.js +235 -0
  163. package/dist/files/library.module.d.ts +9 -0
  164. package/dist/files/library.module.js +29 -0
  165. package/dist/files/library.schemas.d.ts +46 -0
  166. package/dist/files/library.schemas.js +49 -0
  167. package/dist/files/previewers.controller.d.ts +20 -0
  168. package/dist/files/previewers.controller.js +47 -0
  169. package/dist/files/previewers.d.ts +25 -11
  170. package/dist/files/previewers.js +43 -27
  171. package/dist/files/referenced-files.d.ts +150 -0
  172. package/dist/files/referenced-files.js +234 -0
  173. package/dist/git/gateway.js +2 -2
  174. package/dist/html/html-document.controller.d.ts +8 -1
  175. package/dist/html/html-document.controller.js +19 -1
  176. package/dist/html/html-document.service.d.ts +19 -4
  177. package/dist/html/html-document.service.js +43 -22
  178. package/dist/html/html-token.d.ts +10 -1
  179. package/dist/html/html-token.js +14 -0
  180. package/dist/html/html.module.js +8 -1
  181. package/dist/http/api.module.js +10 -5
  182. package/dist/http/request-signal.d.ts +8 -0
  183. package/dist/http/request-signal.js +14 -0
  184. package/dist/identity/settings.d.ts +26 -0
  185. package/dist/identity/settings.js +33 -2
  186. package/dist/inbox/inbox.module.js +2 -2
  187. package/dist/inbox/inbox.service.d.ts +8 -8
  188. package/dist/inbox/inbox.service.js +7 -7
  189. package/dist/infra/config/kernel-config.service.js +10 -5
  190. package/dist/infra/outbox/registry.d.ts +111 -2
  191. package/dist/infra/outbox/registry.js +104 -9
  192. package/dist/infra/throttler/named-throttlers.d.ts +2 -0
  193. package/dist/infra/throttler/named-throttlers.js +14 -0
  194. package/dist/kernel.module.js +3 -0
  195. package/dist/lifecycle/kernel-lifecycle.js +6 -0
  196. package/dist/models/purposes.js +1 -1
  197. package/dist/orgs/offboarding.js +1 -1
  198. package/dist/orgs/roles.d.ts +1 -1
  199. package/dist/orgs/roles.js +3 -3
  200. package/dist/orgs/settings.controller.d.ts +1 -1
  201. package/dist/orgs/settings.service.d.ts +75 -13
  202. package/dist/orgs/settings.service.js +104 -26
  203. package/dist/platform/exclusions.js +45 -8
  204. package/dist/platform/file-ref.d.ts +18 -3
  205. package/dist/platform/file-ref.js +22 -11
  206. package/dist/platform/operation.js +6 -2
  207. package/dist/platform/ops/admin.ops.js +5 -2
  208. package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
  209. package/dist/platform/ops/automations.ops.js +560 -0
  210. package/dist/platform/ops/devices.ops.d.ts +3 -1
  211. package/dist/platform/ops/devices.ops.js +77 -3
  212. package/dist/platform/ops/files.ops.d.ts +18 -0
  213. package/dist/platform/ops/files.ops.js +267 -0
  214. package/dist/platform/ops/inbox.ops.js +4 -4
  215. package/dist/platform/ops/org-settings.ops.js +6 -2
  216. package/dist/platform/ops/orgs.ops.js +2 -1
  217. package/dist/platform/ops/platform.ops.js +4 -4
  218. package/dist/platform/ops/shares.ops.js +2 -2
  219. package/dist/platform/platform-ops.module.d.ts +3 -2
  220. package/dist/platform/platform-ops.module.js +10 -5
  221. package/dist/platform/route-schemas.js +6 -3
  222. package/dist/push/jobs.d.ts +3 -3
  223. package/dist/push/jobs.js +2 -2
  224. package/dist/push/preferences.service.js +1 -1
  225. package/dist/push/push-owed.d.ts +3 -3
  226. package/dist/push/push-owed.js +6 -6
  227. package/dist/push/push.schemas.d.ts +4 -4
  228. package/dist/push/push.schemas.js +3 -3
  229. package/dist/push/recipients.d.ts +4 -4
  230. package/dist/push/recipients.js +23 -23
  231. package/dist/push/texts.d.ts +3 -3
  232. package/dist/push/texts.js +2 -2
  233. package/dist/push/triggers.d.ts +1 -1
  234. package/dist/roles/worker.module.js +18 -4
  235. package/dist/runtime/compaction-settings.service.d.ts +13 -1
  236. package/dist/runtime/compaction-settings.service.js +16 -1
  237. package/dist/runtime/compaction.service.d.ts +3 -1
  238. package/dist/runtime/compaction.service.js +3 -1
  239. package/dist/runtime/context/build.d.ts +24 -1
  240. package/dist/runtime/context/build.js +33 -11
  241. package/dist/runtime/context/cache-expiry.d.ts +31 -0
  242. package/dist/runtime/context/cache-expiry.js +60 -0
  243. package/dist/runtime/context/cache-ttl.d.ts +18 -0
  244. package/dist/runtime/context/cache-ttl.js +30 -0
  245. package/dist/runtime/context/compaction.d.ts +9 -2
  246. package/dist/runtime/context/compaction.js +64 -21
  247. package/dist/runtime/context/in-context-compaction.d.ts +156 -0
  248. package/dist/runtime/context/in-context-compaction.js +310 -0
  249. package/dist/runtime/context/run-context.d.ts +38 -0
  250. package/dist/runtime/context/run-context.js +54 -0
  251. package/dist/runtime/hook-calls.d.ts +2 -1
  252. package/dist/runtime/hook-calls.js +5 -2
  253. package/dist/runtime/maintenance.d.ts +16 -4
  254. package/dist/runtime/maintenance.js +79 -18
  255. package/dist/runtime/model-call.d.ts +34 -5
  256. package/dist/runtime/model-call.js +207 -22
  257. package/dist/runtime/providers.js +11 -1
  258. package/dist/runtime/run-finish.d.ts +4 -4
  259. package/dist/runtime/run-finish.js +3 -3
  260. package/dist/runtime/run-queue.js +12 -7
  261. package/dist/runtime/run-steps.d.ts +4 -2
  262. package/dist/runtime/run-steps.js +10 -5
  263. package/dist/runtime/run-worker.js +7 -1
  264. package/dist/runtime/runtime.module.js +6 -3
  265. package/dist/runtime/subagents/dispatch.js +11 -3
  266. package/dist/sandbox/browse-roots.d.ts +8 -0
  267. package/dist/sandbox/browse-roots.js +22 -0
  268. package/dist/sandbox/network-grants.d.ts +4 -4
  269. package/dist/sandbox/network-grants.js +7 -7
  270. package/dist/sandbox/operation-authority.d.ts +10 -3
  271. package/dist/sandbox/operation-authority.js +20 -10
  272. package/dist/sandbox/operation-intents.d.ts +3 -1
  273. package/dist/sandbox/operation-intents.js +11 -4
  274. package/dist/sandbox/permission-call-grants.js +2 -2
  275. package/dist/sandbox/permission-facts.js +1 -1
  276. package/dist/sandbox/review/classifier.d.ts +2 -2
  277. package/dist/sandbox/review/classifier.js +22 -11
  278. package/dist/sandbox/review/permission-candidate.d.ts +1 -1
  279. package/dist/sandbox/review/permission-candidate.js +1 -1
  280. package/dist/sandbox/sandbox.service.d.ts +15 -5
  281. package/dist/sandbox/sandbox.service.js +14 -8
  282. package/dist/shares/liveness.d.ts +26 -12
  283. package/dist/shares/liveness.js +79 -20
  284. package/dist/shares/revoke.d.ts +16 -11
  285. package/dist/shares/revoke.js +18 -14
  286. package/dist/shares/share-objects.d.ts +16 -21
  287. package/dist/shares/share-objects.js +25 -55
  288. package/dist/shares/share-open.service.d.ts +8 -4
  289. package/dist/shares/share-open.service.js +14 -11
  290. package/dist/shares/shares.controller.d.ts +16 -5
  291. package/dist/shares/shares.controller.js +39 -5
  292. package/dist/shares/shares.module.d.ts +4 -4
  293. package/dist/shares/shares.module.js +7 -6
  294. package/dist/shares/shares.schemas.d.ts +4 -0
  295. package/dist/shares/shares.schemas.js +2 -0
  296. package/dist/shares/shares.service.d.ts +93 -54
  297. package/dist/shares/shares.service.js +292 -131
  298. package/dist/shares/sweep.job.d.ts +18 -39
  299. package/dist/shares/sweep.job.js +47 -206
  300. package/dist/storage/purge.d.ts +1 -1
  301. package/dist/storage/purge.js +2 -2
  302. package/dist/tools/approvals.service.d.ts +6 -6
  303. package/dist/tools/approvals.service.js +19 -19
  304. package/dist/tools/builtin-names.d.ts +12 -12
  305. package/dist/tools/builtin-names.js +29 -29
  306. package/dist/tools/builtins/artifacts.d.ts +21 -13
  307. package/dist/tools/builtins/artifacts.js +81 -51
  308. package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
  309. package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
  310. package/dist/tools/builtins/builtin-tools.d.ts +15 -9
  311. package/dist/tools/builtins/builtin-tools.js +33 -22
  312. package/dist/tools/builtins/conversation-files.d.ts +23 -13
  313. package/dist/tools/builtins/conversation-files.js +62 -83
  314. package/dist/tools/builtins/image/generate.d.ts +7 -1
  315. package/dist/tools/builtins/image/generate.js +1 -1
  316. package/dist/tools/builtins/platform.js +1 -0
  317. package/dist/tools/builtins/sandbox/common.d.ts +6 -2
  318. package/dist/tools/builtins/sandbox/deliver.js +6 -7
  319. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
  320. package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
  321. package/dist/tools/call-scope.d.ts +1 -1
  322. package/dist/tools/git-asks.js +1 -1
  323. package/dist/tools/git-push-policy.d.ts +3 -3
  324. package/dist/tools/git-push-policy.js +6 -6
  325. package/dist/tools/network-asks.d.ts +3 -3
  326. package/dist/tools/network-asks.js +3 -3
  327. package/dist/tools/pipeline.d.ts +4 -4
  328. package/dist/tools/pipeline.js +2 -2
  329. package/dist/tools/policy.d.ts +3 -3
  330. package/dist/tools/policy.js +3 -3
  331. package/dist/tools/tools.module.js +15 -9
  332. package/dist/ui/call-extension.d.ts +6 -4
  333. package/dist/ui/call-extension.js +5 -4
  334. package/dist/ui/embed-token.js +6 -3
  335. package/dist/ui/registry.d.ts +21 -5
  336. package/dist/ui/registry.js +24 -6
  337. package/dist/ui/ui.schemas.d.ts +22 -0
  338. package/dist/ui/ui.schemas.js +22 -4
  339. package/dist/ui/views.controller.d.ts +13 -3
  340. package/dist/ui/views.controller.js +33 -2
  341. package/dist/ui/views.d.ts +29 -1
  342. package/dist/ui/views.js +131 -7
  343. package/package.json +3 -3
  344. package/src/migrations/0188_automations_rename.sql +309 -0
  345. package/src/migrations/0189_event_automations.sql +136 -0
  346. package/src/migrations/0190_file_library.sql +285 -0
  347. package/src/migrations/0191_file_library_copy.sql +4 -0
  348. package/dist/platform/ops/schedules.ops.js +0 -509
  349. package/dist/schedules/effective-settings.d.ts +0 -22
  350. package/dist/schedules/effective-settings.js +0 -18
  351. package/dist/schedules/errors.d.ts +0 -8
  352. package/dist/schedules/errors.js +0 -8
  353. package/dist/schedules/job-ids.d.ts +0 -81
  354. package/dist/schedules/job-ids.js +0 -95
  355. package/dist/schedules/schedules.module.d.ts +0 -16
  356. package/dist/schedules/schedules.schemas.js +0 -213
  357. package/dist/schedules/store.module.d.ts +0 -6
  358. package/dist/schedules/types.d.ts +0 -110
  359. /package/dist/{schedules → automations}/types.js +0 -0
@@ -15,8 +15,12 @@ import { avatarView } from "../agents/avatar-view.js";
15
15
  import { unbindConversation } from "../channels/threads.js";
16
16
  import { oweConversationDeletedNotice } from "../device-access/conversation-notices.js";
17
17
  import { ConversationDevices, } from "../devices/conversation-devices.js";
18
+ import { DeviceProjectFilesService } from "../devices/device-project-files.service.js";
18
19
  import { DeviceProjectsService } from "../devices/device-projects.service.js";
20
+ import { projectFilePath } from "../devices/project-paths.js";
21
+ import { clipped } from "../devices/project-rules.js";
19
22
  import { ApiError } from "../errors.js";
23
+ import { LibraryFilesService } from "../files/library-files.service.js";
20
24
  import { loadPeople } from "../identity/account-avatar.js";
21
25
  import { afterCommit } from "../infra/database/after-commit.js";
22
26
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -37,9 +41,9 @@ import { ConnectorContent } from "../tools/connector-content.js";
37
41
  import { QuestionsService } from "../tools/questions.service.js";
38
42
  import { ConversationAccess, parentReachable } from "./access.js";
39
43
  import { readAgentTree } from "./agent-tree.js";
40
- import { AttachmentsService } from "./attachments.service.js";
41
44
  import { EventLog } from "./event-log.js";
42
45
  import { peopleOfEvents } from "./event-people.js";
46
+ import { refFileId } from "./events.js";
43
47
  import { userMessageIdemKey } from "./idem-keys.js";
44
48
  import { readMessageContext, } from "./message-context.js";
45
49
  import { PermissionProfilesService } from "./permission-profiles.service.js";
@@ -97,6 +101,14 @@ function toConversationAgent(r) {
97
101
  }
98
102
  const notFound = () => new ApiError("conversation.not_found", "Conversation not found");
99
103
  export const NO_REPLY_SKIPS = { questions: [], network: [], seqs: new Map() };
104
+ export { MAX_PROJECT_FILES } from "../devices/device-project-files.service.js";
105
+ /**
106
+ * The model-visible text of one referenced project file (composer menus §5): English, logged in
107
+ * the `user_message`, so replay rebuilds it from the log as it is.
108
+ */
109
+ export const projectFileText = (path, root) => `Referenced project file: ${path} (in the project root ${root}; read it with Read when needed).`;
110
+ /** A message's project file that cannot be referenced (422, `details: [{ path }]` or `reason`). */
111
+ const projectFileUnavailable = (message, details) => new ApiError("conversation.project_file_unavailable", message, details);
100
112
  export { userMessageIdemKey } from "./idem-keys.js";
101
113
  const COLUMNS = [
102
114
  "id",
@@ -113,7 +125,8 @@ const COLUMNS = [
113
125
  "subagent_type",
114
126
  "archived_at",
115
127
  "device_id",
116
- "scheduled_task_id",
128
+ "automation_id",
129
+ "subject",
117
130
  "project_name",
118
131
  "project_path",
119
132
  ];
@@ -133,7 +146,15 @@ function toView(r) {
133
146
  subagentType: r.subagent_type,
134
147
  archivedAt: r.archived_at,
135
148
  deviceId: r.device_id,
136
- scheduledTaskId: r.scheduled_task_id,
149
+ automationId: r.automation_id,
150
+ subject: r.subject === null
151
+ ? null
152
+ : {
153
+ source: r.subject.source,
154
+ kind: r.subject.kind,
155
+ id: r.subject.id,
156
+ title: r.subject.title,
157
+ },
137
158
  project: r.project_name !== null && r.project_path !== null
138
159
  ? { name: r.project_name, path: r.project_path }
139
160
  : null,
@@ -148,6 +169,12 @@ export const CONVERSATION_TITLE_MAX_CHARS = 120;
148
169
  * paging spec §2); a longer run starts mid-run.
149
170
  */
150
171
  export const EVENTS_TURN_EXTEND = 2000;
172
+ /** `conversations.subject` as stored: the four fields, never the subject's link. */
173
+ function storedSubject(s) {
174
+ return s === undefined
175
+ ? null
176
+ : JSON.stringify({ source: s.source, kind: s.kind, id: s.id, title: s.title });
177
+ }
151
178
  /** The sums of the `usage` events matching `where` (over `conversation_events e`), one row. */
152
179
  const usageSums = (where) => sql `
153
180
  SELECT
@@ -177,11 +204,12 @@ let ConversationsService = class ConversationsService {
177
204
  runs;
178
205
  providers;
179
206
  content;
180
- attachments;
207
+ libraryFiles;
181
208
  invoker;
182
209
  deletion;
183
210
  devices;
184
211
  projects;
212
+ projectFiles;
185
213
  questions;
186
214
  approvals;
187
215
  events;
@@ -195,8 +223,8 @@ let ConversationsService = class ConversationsService {
195
223
  providers,
196
224
  /** Reads `@` resources with the sender's credentials. */
197
225
  content,
198
- /** Binds uploaded files to the conversation in the message's transaction. */
199
- attachments,
226
+ /** Attaches the sender's library files to the conversation in the message's transaction. */
227
+ libraryFiles,
200
228
  /** Renders a person's skill invocation (phase D). */
201
229
  invoker,
202
230
  /** Stops a deleted conversation's background tasks. */
@@ -205,6 +233,8 @@ let ConversationsService = class ConversationsService {
205
233
  devices,
206
234
  /** The project of that device a new conversation is bound to (project root design §4.3). */
207
235
  projects,
236
+ /** Checks a message's referenced project files on the device (composer menus §5). */
237
+ projectFiles,
208
238
  /** A starter's message skips the run's pending questions (reply-while-question spec §8.1). */
209
239
  questions,
210
240
  /** ... and its pending network asks (network ask-to-allow spec §6.7). */
@@ -219,11 +249,12 @@ let ConversationsService = class ConversationsService {
219
249
  this.runs = runs;
220
250
  this.providers = providers;
221
251
  this.content = content;
222
- this.attachments = attachments;
252
+ this.libraryFiles = libraryFiles;
223
253
  this.invoker = invoker;
224
254
  this.deletion = deletion;
225
255
  this.devices = devices;
226
256
  this.projects = projects;
257
+ this.projectFiles = projectFiles;
227
258
  this.questions = questions;
228
259
  this.approvals = approvals;
229
260
  this.events = events;
@@ -254,6 +285,7 @@ let ConversationsService = class ConversationsService {
254
285
  project_name: project?.name ?? null,
255
286
  project_path: project?.path ?? null,
256
287
  source: opts.source,
288
+ subject: storedSubject(opts.subject),
257
289
  })
258
290
  .returning(COLUMNS)
259
291
  .executeTakeFirstOrThrow();
@@ -267,8 +299,8 @@ let ConversationsService = class ConversationsService {
267
299
  * `agent.not_found` and nothing is written. Queues a run afterwards, like `postUserMessage`.
268
300
  * `events` are every event the create wrote, in seq order from seq 1 (a `model_switched` before
269
301
  * the message when the send switched), so a client can seed the new conversation's log whole.
270
- * `internal`: the conversation's source and, for kernel callers only, a scheduled task's marker,
271
- * which also sets `conversations.scheduled_task_id`, and its zone override. `pick.project` binds
302
+ * `internal`: the conversation's source and, for kernel callers only, an automation's marker,
303
+ * which also sets `conversations.automation_id`, and its zone override. `pick.project` binds
272
304
  * the conversation to one of its device's projects inside the write ({@link bindingFor}); a
273
305
  * retry answers with the conversation the first send created, its binding unchanged.
274
306
  */
@@ -284,7 +316,15 @@ let ConversationsService = class ConversationsService {
284
316
  return prior;
285
317
  const deviceId = await this.devices.forNew(orgId, accountId, pick);
286
318
  const next = await this.planSwitch(orgId, agent.definition, NO_SELECTION, input);
287
- const extra = await this.resolveExtra(orgId, accountId, input);
319
+ // the project its files are checked in, read before the write (the binding inside it decides)
320
+ const project = (input.projectFiles?.length ?? 0) > 0
321
+ ? await this.bindingFor(orgId, accountId, deviceId, pick.project)
322
+ : undefined;
323
+ const extra = await this.resolveExtra(orgId, accountId, input, {
324
+ deviceId,
325
+ project,
326
+ signal: internal.signal,
327
+ });
288
328
  const invoked = await this.prepareSkill(orgId, accountId, agentId, { conversationId: undefined, deviceId }, agent.definition, input);
289
329
  const id = randomUUID();
290
330
  let all;
@@ -324,6 +364,10 @@ let ConversationsService = class ConversationsService {
324
364
  if (internal.initialPermission)
325
365
  await this.permissions.lockInitial(orgId, id, conv.deviceId);
326
366
  const project = await this.bindingFor(orgId, accountId, conv.deviceId, conv.project);
367
+ // the project changed since its files were checked: the blocks would name another root
368
+ if (extra.projectRoot !== undefined && extra.projectRoot !== project?.path) {
369
+ throw new ApiError("conflict", "The project changed while the message was sent; retry");
370
+ }
327
371
  const row = await this.db
328
372
  .insertInto("conversations")
329
373
  .values({
@@ -336,8 +380,9 @@ let ConversationsService = class ConversationsService {
336
380
  project_path: project?.path ?? null,
337
381
  create_request_id: input.clientMessageId,
338
382
  create_request_hash: internal.createRequestHash ?? null,
339
- scheduled_task_id: internal.schedule?.taskId ?? null,
383
+ automation_id: internal.schedule?.taskId ?? internal.automationEvent?.automationId ?? null,
340
384
  source: internal.source,
385
+ subject: storedSubject(internal.subject),
341
386
  })
342
387
  .onConflict((oc) => oc
343
388
  .columns(["org_id", "account_id", "create_request_id"])
@@ -542,7 +587,7 @@ let ConversationsService = class ConversationsService {
542
587
  await unbindConversation(this.db.db, conversationId);
543
588
  // its shares stop with it and their snapshots are owed for deletion (file sharing spec §9);
544
589
  // a share being created waits on the row lock above (`FOR SHARE`) and then finds it deleted
545
- await revokeSharesIn(this.db.db, this.outbox, { conversationId }, "conversation_deleted");
590
+ await revokeSharesIn(this.db.db, { conversationId }, "conversation_deleted");
546
591
  // the device's services (the browser's tabs) forget the conversation: the notice is owed here
547
592
  // and delivered by the worker, an offline device's once it is back (close tabs on delete §4)
548
593
  if (subject.deviceId)
@@ -721,7 +766,7 @@ let ConversationsService = class ConversationsService {
721
766
  SELECT page.agent_id, page.latest_at, v.definition ->> 'name' AS agent_name,
722
767
  a.profile_avatar, a.profile_updated_at, cs.id, cs.org_id, cs.account_id, cs.title, cs.title_source, cs.selection, cs.last_seq,
723
768
  cs.created_at, cs.updated_at, cs.parent_conversation_id, cs.subagent_type,
724
- cs.archived_at, cs.device_id, cs.scheduled_task_id, cs.project_name, cs.project_path,
769
+ cs.archived_at, cs.device_id, cs.automation_id, cs.subject, cs.project_name, cs.project_path,
725
770
  cs.activity
726
771
  FROM page
727
772
  JOIN capybara.agents a ON a.id = page.agent_id
@@ -729,7 +774,7 @@ let ConversationsService = class ConversationsService {
729
774
  CROSS JOIN LATERAL (
730
775
  SELECT c.id, c.org_id, c.account_id, c.title, c.title_source, c.selection, c.last_seq,
731
776
  c.created_at, c.updated_at, c.parent_conversation_id, c.subagent_type,
732
- c.archived_at, c.device_id, c.scheduled_task_id, c.project_name, c.project_path,
777
+ c.archived_at, c.device_id, c.automation_id, c.subject, c.project_name, c.project_path,
733
778
  ${activitySql("c")} AS activity
734
779
  FROM capybara.conversations c
735
780
  WHERE c.org_id = ${orgId} AND c.account_id = ${accountId} AND c.kind = 'chat'
@@ -930,20 +975,32 @@ let ConversationsService = class ConversationsService {
930
975
  return this.eventLog.readTurnPageBefore(conversationId, beforeSeq, limit, EVENTS_TURN_EXTEND);
931
976
  }
932
977
  /**
933
- * 追加一条用户消息;带 `clientMessageId` 时重复提交返回同一事件。写入后调用 `ensureRun`:
934
- * 没有进行中的运行时投递一轮;运行中则由当前运行在步骤间隙吸收,或在它结束时再次 `ensureRun`。
935
- * A failed `ensureRun` is logged, not thrown: the message's transaction owes the ensure-run
978
+ * Appends a user message; a repeated send with the same `clientMessageId` returns the same
979
+ * event. After the write it calls `ensureRun`: with no run in progress it enqueues one; during
980
+ * a run the current run takes the message in between steps, or `ensureRun` runs again when it
981
+ * ends. A failed `ensureRun` is logged, not thrown: the message's transaction owes the ensure-run
936
982
  * backstop, which starts the run once the queue is reachable (transactional outbox spec §6).
937
983
  *
938
- * `attachments`(`@` 资源引用):内核以发送者的凭据读取资源(打码、限长),作为用户文本之后的额外文本块写入同一条
939
- * user_message,并在 `payload.attachments` 记录元数据(第 i 个附件对应 `content[i + 1]`)。读取失败整条不写。
940
- * 带 `clientMessageId` 的重复提交直接返回已写入的事件,不再读取。
984
+ * `attachments` (`@` resource references): the kernel reads each resource with the sender's
985
+ * credentials (redacted, length-capped) and writes it as an extra text block after the user's
986
+ * text in the same user_message, with its metadata in `payload.attachments` (attachment i is
987
+ * `content[i + 1]`). A failed read writes nothing. A repeated send with the same
988
+ * `clientMessageId` returns the written event without reading again.
941
989
  *
942
- * `files`(上传的附件 id):在写事件的同一事务里校验并绑定到本会话(见 {@link BindFiles}),作为 image /
943
- * document 引用块追加在最后(`@` 资源块之后);任一附件不可用则整条不写。日志里只有引用,没有字节。
944
- * `text` 为空时(只发附件,HTTP 层保证此时有 `files` 且没有 `@` 资源)不写文本块。
990
+ * `files` (uploaded attachment ids): checked and bound to this conversation in the transaction
991
+ * that writes the event (see {@link BindFiles}) and appended last as image / document reference
992
+ * blocks (after the `@` resource blocks); any unavailable file writes nothing. The log holds
993
+ * only references, never bytes. With empty `text` (files only: the HTTP layer ensures `files`
994
+ * and no `@` resources then) no text block is written.
995
+ *
996
+ * `projectFiles` (composer menus §5): checked in the conversation's stored project before the
997
+ * write ({@link resolveExtra}); one block each after the `@` resources' bodies, before the
998
+ * uploaded files' blocks, and `payload.projectFiles`. Any refusal writes nothing; a repeated
999
+ * send with the same `clientMessageId` returns the written event without checking again.
945
1000
  */
946
- async postUserMessage(orgId, conversationId, accountId, input) {
1001
+ async postUserMessage(orgId, conversationId, accountId, input,
1002
+ /** The request's signal: the project file check on the device stops when the client hangs up. */
1003
+ signal) {
947
1004
  const conv = await this.writable(orgId, conversationId, accountId);
948
1005
  // A retry returns the written event before resolving today's model or resources.
949
1006
  if (input.clientMessageId !== undefined) {
@@ -957,7 +1014,7 @@ let ConversationsService = class ConversationsService {
957
1014
  const agent = needsAgent
958
1015
  ? (await this.agents.get(orgId, conv.agentId, accountId)).definition
959
1016
  : undefined;
960
- const extra = await this.resolveExtra(orgId, accountId, input);
1017
+ const extra = await this.resolveExtra(orgId, accountId, input, { ...conv, signal });
961
1018
  const invoked = agent === undefined
962
1019
  ? undefined
963
1020
  : await this.prepareSkill(orgId, accountId, conv.agentId, { conversationId, deviceId: conv.deviceId }, agent, input);
@@ -1146,13 +1203,28 @@ let ConversationsService = class ConversationsService {
1146
1203
  im: input.im,
1147
1204
  timeZoneOverride: internal.timeZoneOverride,
1148
1205
  });
1149
- events.push(this.userMessage(accountId, input, extra, blocks, invoked, context, internal.schedule));
1206
+ events.push(this.userMessage(accountId, input, extra, blocks, invoked, context, internal));
1150
1207
  const { events: written, fresh } = await this.eventLog.appendInReport(conversationId, events);
1151
1208
  const message = written.at(-1);
1152
1209
  // the run this message starts is owed with it: the direct ensureRun after the commit may never
1153
1210
  // happen (the process died) or fail (transactional outbox spec §6)
1154
1211
  if (fresh.at(-1) === true)
1155
1212
  await this.runs.oweEnsureRun(conversationId, message.seq, orgId);
1213
+ // the files this message attached were first referred to by it (a queued message's files keep
1214
+ // a null `first_seq`: they were attached when queued, before the message had a seq)
1215
+ const fileIds = blocks.flatMap((b) => (b.type === "image" || b.type === "document" || b.type === "file") && b.source.kind === "ref"
1216
+ ? [refFileId(b.source)]
1217
+ : []);
1218
+ if (fileIds.length > 0) {
1219
+ await this.db.db
1220
+ .updateTable("conversation_files")
1221
+ .set({ first_seq: message.seq })
1222
+ .where("org_id", "=", orgId)
1223
+ .where("conversation_id", "=", conversationId)
1224
+ .where("file_id", "in", fileIds)
1225
+ .where("first_seq", "is", null)
1226
+ .execute();
1227
+ }
1156
1228
  const skips = fresh.at(-1) === true
1157
1229
  ? await this.skipWaitsIn(conversationId, accountId, message.seq)
1158
1230
  : { skipped: NO_REPLY_SKIPS, toSeq: null };
@@ -1202,28 +1274,69 @@ let ConversationsService = class ConversationsService {
1202
1274
  return this.prepareSkill(orgId, accountId, conv.agentId, { conversationId: conv.id, deviceId: conv.deviceId }, agent.definition, input);
1203
1275
  }
1204
1276
  /**
1205
- * Reads the `@` resources with the sender's credentials (nothing when there are none). Shared
1206
- * with the queue, which reads them when a message is queued (decision 15).
1277
+ * Reads the `@` resources with the sender's credentials and checks the referenced project files
1278
+ * (nothing when there are none). Shared with the queue, which reads the resources when a
1279
+ * message is queued (decision 15; a queued message carries no project files).
1280
+ *
1281
+ * Project files (composer menus §5) are checked in `target`'s project on its device as the
1282
+ * sender (the conversation's owner, through `DeviceProjectFilesService.statAll`, outside any
1283
+ * transaction): no bound project → `conversation.project_file_unavailable` with `reason:
1284
+ * "no_project"`; a path leaving the project → `device.path_outside_project`; one that is not a
1285
+ * file there → `conversation.project_file_unavailable` with its path; the device codes pass on.
1286
+ * Each becomes a {@link projectFileText} block after the resources' bodies.
1207
1287
  */
1208
- async resolveExtra(orgId, accountId, input) {
1288
+ async resolveExtra(orgId, accountId, input, target) {
1209
1289
  const refs = input.attachments ?? [];
1290
+ const files = await this.checkProjectFiles(orgId, accountId, input.projectFiles ?? [], target);
1291
+ const resolved = refs.length === 0
1292
+ ? { blocks: [], attachments: [] }
1293
+ : await this.content.resolveAttachments(orgId, accountId, refs);
1294
+ if (files === undefined)
1295
+ return resolved;
1296
+ return {
1297
+ blocks: [
1298
+ ...resolved.blocks,
1299
+ ...files.paths.map((path) => ({
1300
+ type: "text",
1301
+ text: projectFileText(path, files.root),
1302
+ })),
1303
+ ],
1304
+ attachments: resolved.attachments,
1305
+ projectFiles: files.paths.map((path) => ({ path })),
1306
+ projectRoot: files.root,
1307
+ };
1308
+ }
1309
+ /** {@link resolveExtra}'s project file check: the normalized paths and the root, or none. */
1310
+ async checkProjectFiles(orgId, accountId, refs, target) {
1210
1311
  if (refs.length === 0)
1211
- return { blocks: [], attachments: [] };
1212
- return this.content.resolveAttachments(orgId, accountId, refs);
1312
+ return undefined;
1313
+ const project = target?.project;
1314
+ if (!project || target?.deviceId == null) {
1315
+ throw projectFileUnavailable("This conversation has no device project, so it cannot reference project files; start it in a project", [{ reason: "no_project" }]);
1316
+ }
1317
+ // normalized first (a path leaving the project is refused before the device is asked), once each
1318
+ const paths = [...new Set(refs.map((r) => projectFilePath(r.path)))];
1319
+ const { missing } = await this.projectFiles.statAll({ orgId, accountId, deviceId: target.deviceId }, project.path, paths, target.signal);
1320
+ if (missing.length > 0) {
1321
+ throw projectFileUnavailable(`${clipped(missing[0])} is not a file in the project ${project.name}; pick it again`, missing.map((path) => ({ path: clipped(path) })));
1322
+ }
1323
+ return { paths, root: project.path };
1213
1324
  }
1214
1325
  /**
1215
- * Binds uploaded files inside the message's (or queue item's) transaction; none → no blocks.
1216
- * The bound files join the conversation's files, so open pages read the list again after the
1217
- * commit (`changed: files`, a hint).
1326
+ * Attaches the sender's library files inside the message's (or queue item's) transaction
1327
+ * (`LibraryFilesService.attachForMessage`: drafts become ready, the conversation refers to each);
1328
+ * none → no blocks. The files join the conversation's files, so open pages read the list again
1329
+ * after the commit (`changed: files`, a hint).
1218
1330
  */
1219
1331
  async bindIn(orgId, conversationId, accountId, files) {
1220
1332
  if (files.length === 0)
1221
1333
  return [];
1222
- const blocks = await this.attachments.bindForMessage(orgId, conversationId, accountId, files);
1334
+ const blocks = await this.libraryFiles.attachForMessage(orgId, conversationId, accountId, files);
1223
1335
  afterCommit(() => this.eventLog.publishChanged(conversationId, "files"));
1224
1336
  return blocks;
1225
1337
  }
1226
- userMessage(accountId, input, extra, fileBlocks, invoked, context, schedule) {
1338
+ userMessage(accountId, input, extra, fileBlocks, invoked, context, markers = {}) {
1339
+ const { schedule, automationEvent } = markers;
1227
1340
  // a skill invocation's rendered text replaces the typed arguments as content[0]
1228
1341
  const text = invoked?.text ?? input.text;
1229
1342
  return {
@@ -1239,12 +1352,15 @@ let ConversationsService = class ConversationsService {
1239
1352
  ...fileBlocks,
1240
1353
  ],
1241
1354
  ...(extra.attachments.length > 0 && { attachments: extra.attachments }),
1355
+ ...(extra.projectFiles !== undefined &&
1356
+ extra.projectFiles.length > 0 && { projectFiles: extra.projectFiles }),
1242
1357
  authorAccountId: accountId,
1243
1358
  ...context,
1244
1359
  ...(input.clientMessageId !== undefined && { clientMessageId: input.clientMessageId }),
1245
1360
  ...(input.retryOf !== undefined && { retryOf: input.retryOf }),
1246
1361
  ...(invoked !== undefined && { skill: invoked.skill }),
1247
1362
  ...(schedule !== undefined && { schedule }),
1363
+ ...(automationEvent !== undefined && { automationEvent }),
1248
1364
  },
1249
1365
  };
1250
1366
  }
@@ -1419,16 +1535,17 @@ ConversationsService = __decorate([
1419
1535
  __param(5, Inject(RunControlService)),
1420
1536
  __param(6, Inject(ProviderRegistry)),
1421
1537
  __param(7, Inject(ConnectorContent)),
1422
- __param(8, Inject(AttachmentsService)),
1538
+ __param(8, Inject(LibraryFilesService)),
1423
1539
  __param(9, Inject(SkillInvoker)),
1424
1540
  __param(10, Inject(RunDeletion)),
1425
1541
  __param(11, Inject(ConversationDevices)),
1426
1542
  __param(12, Inject(DeviceProjectsService)),
1427
- __param(13, Inject(QuestionsService)),
1428
- __param(14, Inject(ApprovalsService)),
1429
- __param(15, Inject(KernelEvents)),
1430
- __param(16, Inject(TransactionHost)),
1431
- __param(17, Inject(PermissionCeilingWrites)),
1432
- __param(18, Inject(OutboxService))
1543
+ __param(13, Inject(DeviceProjectFilesService)),
1544
+ __param(14, Inject(QuestionsService)),
1545
+ __param(15, Inject(ApprovalsService)),
1546
+ __param(16, Inject(KernelEvents)),
1547
+ __param(17, Inject(TransactionHost)),
1548
+ __param(18, Inject(PermissionCeilingWrites)),
1549
+ __param(19, Inject(OutboxService))
1433
1550
  ], ConversationsService);
1434
1551
  export { ConversationsService };
@@ -72,6 +72,7 @@ export type ConversationBusMessage = {
72
72
  kind: "ui";
73
73
  plugin: string;
74
74
  contribution: string;
75
+ queries?: true;
75
76
  } | {
76
77
  kind: "changed";
77
78
  what: ConversationChange;