@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
@@ -1,4 +1,5 @@
1
1
  import type { Logger } from "@capybara-hq/plugin-sdk";
2
+ import { AutomationStore } from "../../automations/store.js";
2
3
  import { BackgroundTaskFinisher } from "../../background/finish.js";
3
4
  import { BackgroundTaskStopper } from "../../background/stop.js";
4
5
  import { BackgroundTaskStore } from "../../background/store.js";
@@ -6,6 +7,8 @@ import { AttachmentsService } from "../../conversations/attachments.service.js";
6
7
  import { EventLog } from "../../conversations/event-log.js";
7
8
  import { ConversationDevices } from "../../devices/conversation-devices.js";
8
9
  import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
10
+ import { FileDeliveries } from "../../files/deliveries.js";
11
+ import { ReferencedFiles } from "../../files/referenced-files.js";
9
12
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
10
13
  import { KernelDb } from "../../infra/database/kernel-db.js";
11
14
  import { ModelImages } from "../../models/images.js";
@@ -20,11 +23,10 @@ import { ProviderRegistry } from "../../runtime/providers.js";
20
23
  import { StepLog } from "../../runtime/step-log.js";
21
24
  import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
22
25
  import { SandboxService } from "../../sandbox/sandbox.service.js";
23
- import { ScheduledTaskStore } from "../../schedules/store.js";
24
26
  import { StorageService } from "../../storage/storage.service.js";
25
27
  import { ToolOutputs } from "../outputs.js";
26
28
  import type { BuiltinCallContext, BuiltinTool } from "../registry.js";
27
- import { ScheduleToolsPort, ScheduleUpdates } from "./schedules.js";
29
+ import { AutomationToolsPort, AutomationUpdates } from "./automations.js";
28
30
  import { WebPages } from "./web/index.js";
29
31
  /**
30
32
  * The kernel's builtin tools, built once from the injected services (their specs: names,
@@ -43,17 +45,21 @@ export declare class BuiltinTools {
43
45
  sealedInputs: SealedInputs,
44
46
  /** A Platform write's file reference: a conversation file (spec §5). */
45
47
  fileRefs: FileRefs,
46
- /** The schedule tools read tasks and grants; their writes go through the task service. */
47
- scheduleStore: ScheduledTaskStore,
48
- /** `ScheduleUpdate`'s write: its field change and grant changes in one transaction. */
49
- scheduleUpdates: ScheduleUpdates,
50
- /** The task service, bound by `SchedulesModule` at start (a registration port: no cycle). */
51
- schedulePort: ScheduleToolsPort,
48
+ /** The automation tools read tasks and grants; their writes go through the task service. */
49
+ automationStore: AutomationStore,
50
+ /** `AutomationUpdate`'s write: its field change and grant changes in one transaction. */
51
+ automationUpdates: AutomationUpdates,
52
+ /** The task service, bound by `AutomationsModule` at start (a registration port: no cycle). */
53
+ automationPort: AutomationToolsPort,
52
54
  /** `GenerateImage`: the image calls, and the image model's availability per listing. */
53
55
  images: ModelImages, providers: ProviderRegistry,
54
56
  /** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
55
57
  /** The managed sandbox route's device context writer (permission context replay spec B3). */
56
- managedDeviceContext: ManagedDeviceContextRecorder, now?: () => number);
58
+ managedDeviceContext: ManagedDeviceContextRecorder,
59
+ /** The library files a conversation refers to (`Read` / `Deliver` by id, `FetchAttachment`). */
60
+ referencedFiles: ReferencedFiles,
61
+ /** `Deliver` and `GenerateImage` store files as library files on shared blobs. */
62
+ deliveries: FileDeliveries, now?: () => number);
57
63
  /** The builtin tools, in a fixed order. */
58
64
  list(): readonly BuiltinTool[];
59
65
  }
@@ -8,6 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { Inject, Injectable, Optional } from "@nestjs/common";
11
+ import { AutomationStore } from "../../automations/store.js";
11
12
  import { BackgroundTaskFinisher } from "../../background/finish.js";
12
13
  import { BackgroundTaskStopper } from "../../background/stop.js";
13
14
  import { BackgroundTaskStore } from "../../background/store.js";
@@ -19,6 +20,8 @@ import { ConversationDevices } from "../../devices/conversation-devices.js";
19
20
  import { ApiError } from "../../errors.js";
20
21
  import { ExtensionHost } from "../../extensions/host.js";
21
22
  import { ExtensionPointDefaults } from "../../extensions/point-defaults.js";
23
+ import { FileDeliveries } from "../../files/deliveries.js";
24
+ import { ReferencedFiles } from "../../files/referenced-files.js";
22
25
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
23
26
  import { KernelDb } from "../../infra/database/kernel-db.js";
24
27
  import { KERNEL_LOGGER } from "../../infra/tokens.js";
@@ -35,18 +38,17 @@ import { conversationTimeZone, RUN_CONTEXT_CLOCK } from "../../runtime/run-conte
35
38
  import { StepLog } from "../../runtime/step-log.js";
36
39
  import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
37
40
  import { SandboxService } from "../../sandbox/sandbox.service.js";
38
- import { ScheduledTaskStore } from "../../schedules/store.js";
39
41
  import { StorageService } from "../../storage/storage.service.js";
40
42
  import { ToolOutputs } from "../outputs.js";
41
43
  import { agentTool } from "./agent.js";
42
44
  import { askUserTool } from "./ask-user.js";
45
+ import { AutomationToolsPort, AutomationUpdates, automationTools } from "./automations.js";
43
46
  import { currentTimeTool } from "./current-time.js";
44
47
  import { handbackTool } from "./handback.js";
45
48
  import { generateImageTool } from "./image/index.js";
46
49
  import { platformTool } from "./platform.js";
47
50
  import { readToolOutputTool } from "./read-tool-output.js";
48
51
  import { sandboxTools } from "./sandbox/index.js";
49
- import { ScheduleToolsPort, ScheduleUpdates, scheduleTools } from "./schedules.js";
50
52
  import { sendMessageTool } from "./send-message.js";
51
53
  import { skillLoadTool } from "./skill-load.js";
52
54
  import { toolSearchTool } from "./tool-search.js";
@@ -66,17 +68,21 @@ let BuiltinTools = class BuiltinTools {
66
68
  sealedInputs,
67
69
  /** A Platform write's file reference: a conversation file (spec §5). */
68
70
  fileRefs,
69
- /** The schedule tools read tasks and grants; their writes go through the task service. */
70
- scheduleStore,
71
- /** `ScheduleUpdate`'s write: its field change and grant changes in one transaction. */
72
- scheduleUpdates,
73
- /** The task service, bound by `SchedulesModule` at start (a registration port: no cycle). */
74
- schedulePort,
71
+ /** The automation tools read tasks and grants; their writes go through the task service. */
72
+ automationStore,
73
+ /** `AutomationUpdate`'s write: its field change and grant changes in one transaction. */
74
+ automationUpdates,
75
+ /** The task service, bound by `AutomationsModule` at start (a registration port: no cycle). */
76
+ automationPort,
75
77
  /** `GenerateImage`: the image calls, and the image model's availability per listing. */
76
78
  images, providers,
77
79
  /** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
78
80
  /** The managed sandbox route's device context writer (permission context replay spec B3). */
79
- managedDeviceContext, now) {
81
+ managedDeviceContext,
82
+ /** The library files a conversation refers to (`Read` / `Deliver` by id, `FetchAttachment`). */
83
+ referencedFiles,
84
+ /** `Deliver` and `GenerateImage` store files as library files on shared blobs. */
85
+ deliveries, now) {
80
86
  // `Read` beyond the device (vision-read design §1): files by id, the vision read with its
81
87
  // hooks (as the WebFetch extraction), the stored copies and the chat model's capabilities
82
88
  const vision = { purposes, eventLog, stepLog, config, log, hooks: host?.hooks };
@@ -86,7 +92,7 @@ let BuiltinTools = class BuiltinTools {
86
92
  return db.db;
87
93
  },
88
94
  attachments,
89
- storage,
95
+ files: referencedFiles,
90
96
  },
91
97
  reads: attachments,
92
98
  vision,
@@ -101,8 +107,9 @@ let BuiltinTools = class BuiltinTools {
101
107
  inTree: async (root, id) => id !== root && (await conversationAncestors(db.db, id)).includes(root),
102
108
  childrenOf: (orgId, conversationId) => readChildAgents(db.db, orgId, conversationId),
103
109
  },
104
- attachments,
110
+ attachments: referencedFiles,
105
111
  storage,
112
+ deliveries,
106
113
  eventLog,
107
114
  config,
108
115
  log,
@@ -126,7 +133,7 @@ let BuiltinTools = class BuiltinTools {
126
133
  config,
127
134
  sandbox,
128
135
  devices,
129
- attachments,
136
+ attachments: referencedFiles,
130
137
  eventLog,
131
138
  log,
132
139
  managedDeviceContext,
@@ -150,12 +157,14 @@ let BuiltinTools = class BuiltinTools {
150
157
  providers,
151
158
  storage,
152
159
  eventLog,
160
+ deliveries,
153
161
  stepLog,
154
162
  config,
155
163
  log,
156
164
  hooks: host?.hooks,
157
165
  db,
158
166
  attachments,
167
+ files: referencedFiles,
159
168
  sandbox: sandboxDeps,
160
169
  }),
161
170
  // the platform's own operations and docs, as the run's person (Platform tool spec)
@@ -211,13 +220,13 @@ let BuiltinTools = class BuiltinTools {
211
220
  now: now ?? Date.now,
212
221
  timeZoneOf: ({ orgId, conversationId }) => conversationTimeZone(db.db, orgId, conversationId),
213
222
  }),
214
- // the person's scheduled tasks (scheduled tasks spec §11)
215
- ...scheduleTools({
223
+ // the person's automations (scheduled tasks spec §11)
224
+ ...automationTools({
216
225
  db: () => db.db,
217
226
  config,
218
- store: scheduleStore,
219
- service: () => schedulePort.get(),
220
- updates: scheduleUpdates,
227
+ store: automationStore,
228
+ service: () => automationPort.get(),
229
+ updates: automationUpdates,
221
230
  timeZoneOf: (orgId, conversationId) => conversationTimeZone(db.db, orgId, conversationId),
222
231
  now: now ?? Date.now,
223
232
  }),
@@ -252,14 +261,16 @@ BuiltinTools = __decorate([
252
261
  __param(19, Inject(AgentDocs)),
253
262
  __param(20, Inject(SealedInputs)),
254
263
  __param(21, Inject(FileRefs)),
255
- __param(22, Inject(ScheduledTaskStore)),
256
- __param(23, Inject(ScheduleUpdates)),
257
- __param(24, Inject(ScheduleToolsPort)),
264
+ __param(22, Inject(AutomationStore)),
265
+ __param(23, Inject(AutomationUpdates)),
266
+ __param(24, Inject(AutomationToolsPort)),
258
267
  __param(25, Inject(ModelImages)),
259
268
  __param(26, Inject(ProviderRegistry)),
260
269
  __param(27, Inject(ManagedDeviceContextRecorder)),
261
- __param(28, Optional()),
262
- __param(28, Inject(RUN_CONTEXT_CLOCK))
270
+ __param(28, Inject(ReferencedFiles)),
271
+ __param(29, Inject(FileDeliveries)),
272
+ __param(30, Optional()),
273
+ __param(30, Inject(RUN_CONTEXT_CLOCK))
263
274
  ], BuiltinTools);
264
275
  export { BuiltinTools };
265
276
  /**
@@ -1,8 +1,12 @@
1
1
  import type { AttachmentsService } from "../../conversations/attachments.service.js";
2
+ import type { ReferencedFiles } from "../../files/referenced-files.js";
2
3
  import type { KernelDb } from "../../infra/database/kernel-db.js";
3
- import type { StorageService } from "../../storage/storage.service.js";
4
- /** An id of the conversation's files: an attachment or an artifact (generated or delivered). */
4
+ /**
5
+ * A file of the conversation by id: a library file the conversation set refers to (an upload, a
6
+ * delivery or a generated image) or a `read` copy (an image a tool showed the agent).
7
+ */
5
8
  export interface ConversationFile {
9
+ /** `attachment`: an upload or a `read` copy; `artifact`: a delivered or generated file. */
6
10
  kind: "attachment" | "artifact";
7
11
  id: string;
8
12
  /**
@@ -10,13 +14,14 @@ export interface ConversationFile {
10
14
  * `Read` of a copy that is already the calling conversation's needs no new copy.
11
15
  */
12
16
  readCopyOf?: string;
17
+ /** The owner of a library file; absent for a `read` copy. */
18
+ accountId?: string;
13
19
  name: string;
14
20
  contentType: string;
15
21
  size: number;
16
22
  /**
17
- * Reads the bytes, at most `maxBytes` of them when given (the head of a larger file: an
18
- * attachment's stream is cancelled there, an artifact is read with a range). Call it, or
19
- * {@link discard}, exactly once: an attachment holds its stream.
23
+ * Reads the bytes, at most `maxBytes` of them when given (the head of a larger file: the stream
24
+ * is cancelled there). Call it, or {@link discard}, exactly once: the lookup holds the stream.
20
25
  */
21
26
  open(opts?: {
22
27
  maxBytes?: number;
@@ -26,23 +31,28 @@ export interface ConversationFile {
26
31
  }
27
32
  export interface ConversationFileDeps {
28
33
  db: Pick<KernelDb, "selectFrom">;
34
+ /** The `read` copies. */
29
35
  attachments: Pick<AttachmentsService, "openForConversation">;
30
- storage: Pick<StorageService, "kernel">;
36
+ /** The library files the conversations refer to, and their bytes. */
37
+ files: Pick<ReferencedFiles, "referenced" | "referencedBelow" | "open" | "head">;
31
38
  }
32
39
  /**
33
- * A file of the conversation by id, always inside `orgId`: an attachment (a `chat` attachment or
34
- * a `read` copy: this lookup is the model's, vision-read design §1.1) or an `artifact_created`
35
- * event of the conversation, of its root, or of a sub-agent conversation below the conversation
36
- * (so a parent reaches an image its sub-agent's tool returned; tool result images design §5).
37
- * Anything else (a sibling's or another tree's, another org's, a missing object, an id that is
38
- * not a UUID) is `null`. Storage errors are thrown as they are. `signal` aborts the storage reads.
40
+ * A file of the conversation by id, always inside `orgId` (file library spec §2, §5): a library
41
+ * file referred to (`conversation_files`) by the conversation, by its root, or by a sub-agent
42
+ * conversation below the conversation (so a parent reaches an image its sub-agent's tool returned;
43
+ * tool result images design §5), else a `read` copy bound to one of them (this lookup is the
44
+ * model's, vision-read design §1.1). Anything else (a library file the person never attached, a
45
+ * sibling's or another tree's, another org's, a deleted file, bytes gone or replaced, an id that is
46
+ * not a UUID) is `null`. A library file's size and type come from its rows and its bytes are
47
+ * checked by a HEAD; they are opened only when {@link ConversationFile.open} is called. Storage
48
+ * errors are thrown as they are. `signal` aborts the storage reads.
39
49
  */
40
50
  export declare function findConversationFile(deps: ConversationFileDeps, q: {
41
51
  orgId: string;
42
52
  conversationId: string;
43
53
  rootConversationId: string;
44
54
  id: string;
45
- /** The most bytes {@link ConversationFile.open} may be asked for (an attachment's range). */
55
+ /** The most bytes {@link ConversationFile.open} may be asked for (a range read). */
46
56
  maxBytes?: number;
47
57
  signal?: AbortSignal;
48
58
  }): Promise<ConversationFile | null>;
@@ -1,5 +1,4 @@
1
- import { sql } from "kysely";
2
- /** Lower-case or upper-case UUIDs: attachment and artifact ids. */
1
+ /** Lower-case or upper-case UUIDs: file and `read` copy ids. */
3
2
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
4
3
  /**
5
4
  * The bytes of `body`, at most `maxBytes` (the stream is cancelled once that many are read: a
@@ -55,108 +54,88 @@ async function isBelow(db, orgId, candidate, ancestor) {
55
54
  }
56
55
  return false;
57
56
  }
58
- /**
59
- * The conversation an attachment (`chat` or `read`, ready) or artifact with this id belongs to,
60
- * in `orgId`; null when there is none.
61
- */
62
- async function ownerOf(db, orgId, id) {
57
+ /** The conversation a ready `read` copy of this id is bound to, in `orgId`; null when none. */
58
+ async function readCopyOwner(db, orgId, id) {
63
59
  const att = await db
64
60
  .selectFrom("attachments")
65
- .select(["conversation_id", "purpose"])
61
+ .select("conversation_id")
66
62
  .where("id", "=", id)
67
63
  .where("org_id", "=", orgId)
68
64
  .where("status", "=", "ready")
69
- .where("purpose", "in", ["chat", "read"])
65
+ .where("purpose", "=", "read")
70
66
  .executeTakeFirst();
71
- if (att?.conversation_id)
72
- return { conversationId: att.conversation_id, purpose: att.purpose };
73
- const ev = await db
74
- .selectFrom("conversation_events as e")
75
- .innerJoin("conversations as c", "c.id", "e.conversation_id")
76
- .select("e.conversation_id")
77
- .where("c.org_id", "=", orgId)
78
- .where("e.type", "=", "artifact_created")
79
- .where(sql `e.payload->>'artifactId'`, "=", id)
80
- .limit(1)
81
- .executeTakeFirst();
82
- return ev ? { conversationId: ev.conversation_id, purpose: "artifact" } : null;
67
+ return att?.conversation_id ?? null;
83
68
  }
84
69
  /**
85
- * A file of the conversation by id, always inside `orgId`: an attachment (a `chat` attachment or
86
- * a `read` copy: this lookup is the model's, vision-read design §1.1) or an `artifact_created`
87
- * event of the conversation, of its root, or of a sub-agent conversation below the conversation
88
- * (so a parent reaches an image its sub-agent's tool returned; tool result images design §5).
89
- * Anything else (a sibling's or another tree's, another org's, a missing object, an id that is
90
- * not a UUID) is `null`. Storage errors are thrown as they are. `signal` aborts the storage reads.
70
+ * A file of the conversation by id, always inside `orgId` (file library spec §2, §5): a library
71
+ * file referred to (`conversation_files`) by the conversation, by its root, or by a sub-agent
72
+ * conversation below the conversation (so a parent reaches an image its sub-agent's tool returned;
73
+ * tool result images design §5), else a `read` copy bound to one of them (this lookup is the
74
+ * model's, vision-read design §1.1). Anything else (a library file the person never attached, a
75
+ * sibling's or another tree's, another org's, a deleted file, bytes gone or replaced, an id that is
76
+ * not a UUID) is `null`. A library file's size and type come from its rows and its bytes are
77
+ * checked by a HEAD; they are opened only when {@link ConversationFile.open} is called. Storage
78
+ * errors are thrown as they are. `signal` aborts the storage reads.
91
79
  */
92
80
  export async function findConversationFile(deps, q) {
93
81
  if (!UUID.test(q.id))
94
82
  return null;
95
83
  const id = q.id.toLowerCase();
96
84
  const conversations = [...new Set([q.conversationId, q.rootConversationId])];
97
- // a file of a sub-agent below the calling conversation joins the lookup
98
- const found = await ownerOf(deps.db, q.orgId, id);
99
- const owner = found?.conversationId;
100
- if (owner !== undefined &&
101
- !conversations.includes(owner) &&
102
- (await isBelow(deps.db, q.orgId, owner, q.conversationId))) {
103
- conversations.push(owner);
104
- }
105
- for (const conversationId of conversations) {
106
- const opened = await deps.attachments.openForConversation(q.orgId, conversationId, id, {
107
- purposes: ["chat", "read"],
108
- ...(q.maxBytes !== undefined && { maxBytes: q.maxBytes }),
109
- ...(q.signal !== undefined && { signal: q.signal }),
110
- });
111
- if (opened === null)
112
- continue;
85
+ const files = deps.files;
86
+ // the conversation and its root first; only on a miss the sub-agents below the conversation
87
+ let refs = (await files.referenced(q.orgId, conversations, [id])).sort(attachedFirst);
88
+ if (refs.length === 0)
89
+ refs = await files.referencedBelow(q.orgId, q.conversationId, id);
90
+ const file = refs[0];
91
+ if (file !== undefined) {
92
+ if ((await files.head(q.orgId, file)) === null)
93
+ return null;
113
94
  return {
114
- kind: "attachment",
95
+ // an upload, or a delivered file sent into this conversation set, is an attachment here
96
+ kind: file.role === "attached" || file.sourcePath === null ? "attachment" : "artifact",
115
97
  id,
116
- ...(found?.purpose === "read" && owner === conversationId && { readCopyOf: conversationId }),
117
- name: opened.name,
118
- contentType: opened.contentType,
119
- size: opened.size,
120
- // the one storage read of the lookup: its stream is read by open() or cancelled by discard()
121
- open: (opts) => bytesOf(opened.body, opts?.maxBytes),
122
- discard: () => opened.body.cancel().catch(() => { }),
98
+ accountId: file.accountId,
99
+ name: file.name,
100
+ contentType: file.contentType,
101
+ size: file.blob.size,
102
+ async open(opts) {
103
+ const max = opts?.maxBytes ?? q.maxBytes;
104
+ // only a larger object is ranged (a range on an empty object is unsatisfiable)
105
+ const got = await files.open(q.orgId, file, {
106
+ ...(q.signal !== undefined && { signal: q.signal }),
107
+ ...(max !== undefined && file.blob.size > max && { range: { start: 0, end: max - 1 } }),
108
+ });
109
+ if (got === null)
110
+ throw new Error(`file ${id} is no longer available`);
111
+ return bytesOf(got.body, max);
112
+ },
113
+ discard: async () => { },
123
114
  };
124
115
  }
125
- const row = await deps.db
126
- .selectFrom("conversation_events as e")
127
- .innerJoin("conversations as c", "c.id", "e.conversation_id")
128
- .select("e.payload")
129
- .where("c.org_id", "=", q.orgId)
130
- .where("e.conversation_id", "in", conversations)
131
- .where("e.type", "=", "artifact_created")
132
- .where(sql `e.payload->>'artifactId'`, "=", id)
133
- .limit(1)
134
- .executeTakeFirst();
135
- if (!row)
116
+ const owner = await readCopyOwner(deps.db, q.orgId, id);
117
+ if (owner === null)
118
+ return null;
119
+ if (!conversations.includes(owner) &&
120
+ !(await isBelow(deps.db, q.orgId, owner, q.conversationId))) {
136
121
  return null;
137
- const a = row.payload;
138
- const store = deps.storage.kernel(q.orgId);
139
- const head = await store.head(a.objectKey);
140
- if (head === null)
122
+ }
123
+ const opened = await deps.attachments.openForConversation(q.orgId, owner, id, {
124
+ ...(q.maxBytes !== undefined && { maxBytes: q.maxBytes }),
125
+ ...(q.signal !== undefined && { signal: q.signal }),
126
+ });
127
+ if (opened === null)
141
128
  return null;
142
129
  return {
143
- kind: "artifact",
130
+ kind: "attachment",
144
131
  id,
145
- name: a.name,
146
- contentType: a.contentType,
147
- size: head.size,
148
- async open(opts) {
149
- const max = opts?.maxBytes;
150
- // only a larger object is ranged (a range on an empty object is unsatisfiable)
151
- const ranged = max !== undefined && head.size > max;
152
- const got = await store.get(a.objectKey, {
153
- ...(q.signal !== undefined && { signal: q.signal }),
154
- ...(ranged && { range: { start: 0, end: max - 1 } }),
155
- });
156
- if (got === null)
157
- throw new Error(`artifact ${id} is no longer available`);
158
- return bytesOf(got.body, max);
159
- },
160
- discard: async () => { },
132
+ readCopyOf: owner,
133
+ name: opened.name,
134
+ contentType: opened.contentType,
135
+ size: opened.size,
136
+ open: (opts) => bytesOf(opened.body, opts?.maxBytes),
137
+ discard: () => opened.body.cancel().catch(() => { }),
161
138
  };
162
139
  }
140
+ /** References of one file across a conversation set: an `attached` one first. */
141
+ const attachedFirst = (a, b) => (a.role === "attached" ? 0 : 1) - (b.role === "attached" ? 0 : 1);
@@ -2,6 +2,7 @@ import { type ImageMediaType, type Logger, type ToolSpec } from "@capybara-hq/pl
2
2
  import type { AttachmentsService } from "../../../conversations/attachments.service.js";
3
3
  import type { EventLog } from "../../../conversations/event-log.js";
4
4
  import type { DeviceUnusableReason } from "../../../devices/conversation-devices.js";
5
+ import type { FileDeliveries } from "../../../files/deliveries.js";
5
6
  import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
6
7
  import type { KernelDb } from "../../../infra/database/kernel-db.js";
7
8
  import { type ImageInputCaps } from "../../../models/image-usable.js";
@@ -12,6 +13,7 @@ import { type ProviderRegistry } from "../../../runtime/providers.js";
12
13
  import type { StepLog } from "../../../runtime/step-log.js";
13
14
  import type { StorageService } from "../../../storage/storage.service.js";
14
15
  import type { BuiltinTool } from "../../registry.js";
16
+ import { type ConversationFileDeps } from "../conversation-files.js";
15
17
  import { type SandboxToolDeps } from "../sandbox/common.js";
16
18
  /** The listed spec for an org whose image model accepts `caps` (pure; `n` and references drop or cap). */
17
19
  export declare function generateImageSpec(caps: ImageInputCaps, standardPixels: number): ToolSpec;
@@ -33,7 +35,9 @@ export interface GenerateImageDeps {
33
35
  purposes: Pick<ModelPurposesService, "resolve">;
34
36
  providers: Pick<ProviderRegistry, "resolve">;
35
37
  storage: Pick<StorageService, "kernel" | "available">;
36
- eventLog: Pick<EventLog, "append" | "notify" | "readDeliveryScope"> & Partial<Pick<EventLog, "publishChanged">>;
38
+ eventLog: Pick<EventLog, "notify" | "readDeliveryScope"> & Partial<Pick<EventLog, "publishChanged">>;
39
+ /** The images' blobs and their delivery transaction ({@link storeArtifacts}). */
40
+ deliveries: Pick<FileDeliveries, "ensureBlob" | "appendDelivered">;
37
41
  stepLog: Pick<StepLog, "appendCounted" | "appendReported" | "appendAudited">;
38
42
  config: Pick<KernelConfigService, "get">;
39
43
  log: Pick<Logger, "warn">;
@@ -42,6 +46,8 @@ export interface GenerateImageDeps {
42
46
  /** The artifact lookup of `reference_images`. */
43
47
  db: Pick<KernelDb, "selectFrom">;
44
48
  attachments: Pick<AttachmentsService, "openForConversation">;
49
+ /** The library files of `reference_images` (attached or delivered in the conversation set). */
50
+ files: ConversationFileDeps["files"];
45
51
  /** The device copy of `file_path` (the sandbox tools' own dependencies). */
46
52
  sandbox: SandboxToolDeps;
47
53
  }
@@ -302,7 +302,7 @@ async function resolveReferences(deps, ctx, ids) {
302
302
  const out = [];
303
303
  for (const [k, id] of ids.entries()) {
304
304
  try {
305
- const found = await findConversationFile({ db: deps.db, attachments: deps.attachments, storage: deps.storage }, { orgId: ctx.orgId, conversationId: ctx.conversationId, rootConversationId: root, id });
305
+ const found = await findConversationFile({ db: deps.db, attachments: deps.attachments, files: deps.files }, { orgId: ctx.orgId, conversationId: ctx.conversationId, rootConversationId: root, id });
306
306
  if (found === null)
307
307
  throw new ToolError(unknownReferenceText(k));
308
308
  const mediaType = found.contentType.split(";")[0]?.trim().toLowerCase() ?? "";
@@ -650,6 +650,7 @@ async function fileOf(op, params, deps, ctx, rootConversationId, signal) {
650
650
  orgId: ctx.orgId,
651
651
  conversationId: ctx.conversationId,
652
652
  rootConversationId,
653
+ actorAccountId: ctx.actorAccountId,
653
654
  signal: signal ?? ctx.signal,
654
655
  });
655
656
  }
@@ -4,9 +4,10 @@ import type { BackgroundTaskStopper } from "../../../background/stop.js";
4
4
  import type { BackgroundTaskStore } from "../../../background/store.js";
5
5
  import type { KernelConfig } from "../../../config/schema.js";
6
6
  import type { ChildAgent } from "../../../conversations/agent-tree.js";
7
- import type { AttachmentsService } from "../../../conversations/attachments.service.js";
8
7
  import type { EventLog } from "../../../conversations/event-log.js";
9
8
  import { type ConversationDevices, type DeviceUnusableReason } from "../../../devices/conversation-devices.js";
9
+ import type { FileDeliveries } from "../../../files/deliveries.js";
10
+ import type { ReferencedFiles } from "../../../files/referenced-files.js";
10
11
  import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
11
12
  import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
12
13
  import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
@@ -50,8 +51,11 @@ export interface SandboxToolDeps {
50
51
  finisher: Pick<BackgroundTaskFinisher, "finish">;
51
52
  stopper: Pick<BackgroundTaskStopper, "stop">;
52
53
  };
53
- attachments: Pick<AttachmentsService, "listForConversation" | "openForConversation">;
54
+ /** The files sent into a conversation that `FetchAttachment` copies (file library). */
55
+ attachments: Pick<ReferencedFiles, "listForConversation" | "openForConversation">;
54
56
  storage: Pick<StorageService, "kernel" | "deployment" | "available">;
57
+ /** `Deliver`'s blobs and delivery transaction (file library spec §4); absent in test stubs. */
58
+ deliveries?: Pick<FileDeliveries, "ensureBlob" | "appendDelivered">;
55
59
  /**
56
60
  * `readDeliveryScope`: `Deliver`'s delivery scope (truthful delivery spec §2). `publishChanged`:
57
61
  * `Deliver` announces `changed: files` (UI refresh B).
@@ -11,9 +11,8 @@ const SPEC = {
11
11
  description: "Deliver a file to the user as a downloadable artifact. Use it when the user should receive a " +
12
12
  "file you produced (a report, chart, spreadsheet, archive and so on); files that stay on the " +
13
13
  "device are not visible to the user, and images in tool results are shown to you, not " +
14
- "delivered to the user. Pass file_path for a file on the device, or file_id for an attachment " +
15
- "or artifact of this conversation, such as the file_id an image in a tool result names (needs " +
16
- "no device). Each call delivers only that one file, so a directory must first be packed into " +
14
+ "delivered to the user. Pass file_path for a file on the device, or file_id for a file id of " +
15
+ "this conversation, such as the file_id an image in a tool result names (needs no device). Each call delivers only that one file, so a directory must first be packed into " +
17
16
  "one archive. The file size is limited (100 MB by default). Do not use it for intermediate " +
18
17
  "files the user does not need. An HTML file is shown on its own: files it references by " +
19
18
  "relative path are not delivered with it, so inline or embed them.",
@@ -28,7 +27,7 @@ const SPEC = {
28
27
  file_id: {
29
28
  type: "string",
30
29
  minLength: 1,
31
- description: "Instead of file_path: an attachment or artifact id of this conversation, e.g. the file_id of an image in a tool result.",
30
+ description: "Instead of file_path: a file id of this conversation (a file the user sent, a delivered file, or the file_id of an image in a tool result).",
32
31
  },
33
32
  name: {
34
33
  type: "string",
@@ -168,9 +167,9 @@ export function sandboxDeliverTool(deps) {
168
167
  };
169
168
  }
170
169
  /**
171
- * A `file_id` delivery: the file of the conversation or its root (an attachment, a `read` copy
172
- * such as a tool result's image, or an artifact) read from the object store, no device; the
173
- * artifact's source path is `file_id/<id>`.
170
+ * A `file_id` delivery: a file of the conversation or its root ({@link findConversationFile}: a
171
+ * library file they refer to, or a `read` copy such as a tool result's image) read from the object
172
+ * store, no device; the artifact's source path is `file_id/<id>`.
174
173
  */
175
174
  async function deliverById(deps, ctx, id, given, max) {
176
175
  if (deps.read === undefined)
@@ -1,10 +1,11 @@
1
1
  import type { BuiltinTool } from "../../registry.js";
2
2
  import { type SandboxToolDeps } from "./common.js";
3
3
  /**
4
- * The builtin `FetchAttachment`: copy one attachment of this conversation into the device
5
- * ({@link attachmentsDir}); it runs nothing. Names come from the conversation's whole attachment
6
- * list ({@link assignAttachmentNames}), so a given attachment always lands on the same path;
7
- * copying it twice writes the same bytes and returns the same path. A failure is an ordinary tool
8
- * error and the run continues.
4
+ * The builtin `FetchAttachment`: copy one file sent into this conversation (its root's: the files
5
+ * its messages attached, file library spec §5) into the device ({@link attachmentsDir}); it runs
6
+ * nothing. A library file the person never attached to the conversation is not in the list.
7
+ * Names come from the conversation's whole attachment list ({@link assignAttachmentNames}), so a
8
+ * given attachment always lands on the same path; copying it twice writes the same bytes and
9
+ * returns the same path. A failure is an ordinary tool error and the run continues.
9
10
  */
10
11
  export declare function sandboxFetchAttachmentTool(deps: SandboxToolDeps): BuiltinTool;