@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
@@ -0,0 +1,255 @@
1
+ import { type PresignedUpload } from "@capybara-hq/plugin-sdk";
2
+ import { EventLog } from "../conversations/event-log.js";
3
+ import type { LogContentBlock } from "../conversations/events.js";
4
+ import type { FileStatus } from "../db/kernel-schema.js";
5
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
6
+ import { KernelDb } from "../infra/database/kernel-db.js";
7
+ import { TransactionHost } from "../infra/database/transaction-host.js";
8
+ import { OutboxService } from "../infra/outbox/outbox.service.js";
9
+ import { StorageService } from "../storage/storage.service.js";
10
+ import { BlobsService } from "./blobs.service.js";
11
+ export type { FileOrigin, FileStatus } from "../db/kernel-schema.js";
12
+ /** Unfinished uploads (`uploading` + `draft`) one account may have in an org. */
13
+ export declare const MAX_PENDING_FILES = 50;
14
+ /**
15
+ * {@link LibraryFilesService.addFromBytes} found the blob of these bytes claimed by a deletion
16
+ * {@link ADD_BLOB_ATTEMPTS} times in a row (nothing written): a transient race, worth a retry.
17
+ */
18
+ export declare class FileBlobClaimedError extends Error {
19
+ constructor();
20
+ }
21
+ /** Where an upload is made: the composer (a draft until sent) or the Files page (ready at once). */
22
+ export type UploadPurpose = "composer" | "library";
23
+ /** A file as the upload routes answer it. */
24
+ export interface FileView {
25
+ id: string;
26
+ name: string;
27
+ contentType: string;
28
+ size: number;
29
+ status: Exclude<FileStatus, "deleted">;
30
+ }
31
+ /**
32
+ * `POST /files`: `upload` is the presigned form to send the bytes with (then finalize), or null
33
+ * when the caller already holds these bytes in one of their own files (the file is created at
34
+ * once; nothing to upload or finalize). `expiresAt`: the form's expiry, null without a form.
35
+ */
36
+ export interface CreatedFile {
37
+ file: FileView;
38
+ upload: PresignedUpload | null;
39
+ expiresAt: string | null;
40
+ }
41
+ /** The upload limits (`GET /files/limits`): the web's pre-checks. */
42
+ export interface FileLimits {
43
+ /** The accepted content types. */
44
+ types: string[];
45
+ /** The accepted extensions next to `types` (lower case, no dot). */
46
+ extensions: string[];
47
+ /** The size limit of a file that is not an image (bytes). */
48
+ maxBytes: number;
49
+ /** The size limit of an image (bytes; also bound by `MEDIA_LIMITS.imageBytes`). */
50
+ imageMaxBytes: number;
51
+ /** Files per message. */
52
+ maxPerMessage: number;
53
+ /** The media budget of one model request (raw bytes). */
54
+ requestMediaBytes: number;
55
+ /** Whether the deployment has an object store; uploads are unavailable without one. */
56
+ available: boolean;
57
+ }
58
+ /**
59
+ * The content block a message carries for a file (a `ref` to its id, never bytes): images, PDFs
60
+ * and text become blocks the model reads itself; every other accepted type a `file` block the
61
+ * model only gets a reference to.
62
+ */
63
+ export declare function fileContentBlock(f: {
64
+ id: string;
65
+ name: string;
66
+ contentType: string;
67
+ size: number;
68
+ }): LogContentBlock;
69
+ /**
70
+ * The files of the file library (file library spec §2–§4 with the builder amendment of §3):
71
+ * account-owned rows over blobs.
72
+ *
73
+ * Uploading: `create` admits the upload and, unless the caller already holds the same bytes in a
74
+ * file of their own, inserts an `uploading` row (with the declared sha256 and the purpose) before
75
+ * presigning `uploads/<fileId>`. `finalize` checks the staging object (size, type, signature, PDF
76
+ * pages), reads it whole, compares its sha256 with the declared one, copies the verified bytes to a
77
+ * kernel-owned blob (`blobs/<blobId>`, intent first) and settles that blob in one transaction
78
+ * ({@link BlobsService.settle}); the staging object's deletion is always owed. No form can write a
79
+ * blob's key, and every branch does the same work, so nothing the caller can observe depends on
80
+ * whether another account stored the same bytes. `discard` drops a composer upload before it is
81
+ * sent; expired uploads and drafts go with {@link expireBatch}.
82
+ *
83
+ * Sending: {@link attachForMessage} turns the sender's drafts into `ready` files and records the
84
+ * conversation's reference, in the message's transaction. No process state.
85
+ */
86
+ export declare class LibraryFilesService {
87
+ private readonly db;
88
+ readonly txHost: TransactionHost;
89
+ private readonly storage;
90
+ private readonly config;
91
+ private readonly blobs;
92
+ private readonly outbox;
93
+ /** The `files` change of the conversations that referred to a deleted file. */
94
+ private readonly eventLog;
95
+ constructor(db: KernelDb, txHost: TransactionHost, storage: Pick<StorageService, "available" | "assertAvailable" | "kernel">, config: Pick<KernelConfigService, "get">, blobs: Pick<BlobsService, "writeVerified" | "settle" | "lockReady" | "ensureFromBytes">, outbox: Pick<OutboxService, "add">,
96
+ /** The `files` change of the conversations that referred to a deleted file. */
97
+ eventLog: Pick<EventLog, "publishChanged">);
98
+ /** This replica's bound on finalizes reading and copying at once ({@link LocalSlots}). */
99
+ private readonly finalizeSlots;
100
+ /** The upload limits under the current config (needs no object store). */
101
+ limits(): FileLimits;
102
+ /** One file's size limit: the configured `maxBytes`, an image also `MEDIA_LIMITS.imageBytes`. */
103
+ limitFor(contentType: string): number;
104
+ /**
105
+ * Starts an upload. Admission: a type outside `attachments.allowedTypes` →
106
+ * `file.type_not_allowed`; over the size limit → `file.too_large`; {@link MAX_PENDING_FILES}
107
+ * unfinished files (`uploading` + `draft`) of the account in the org → `file.too_many_pending`
108
+ * (a soft cap); no object store → `storage.unavailable`.
109
+ *
110
+ * When one of the caller's own `ready` or unexpired `draft` files of the same type and size has
111
+ * this sha256 and a `ready` blob, the new file is created on that blob at once (`upload: null`):
112
+ * the caller already holds those bytes, so nothing is learned. In every other case (another
113
+ * account's bytes included) an `uploading` row is inserted with the declared sha256 and purpose
114
+ * (expiring after `attachments.unboundTtlHours`) before a form for `uploads/<fileId>` is
115
+ * presigned, the store enforcing the declared size and type.
116
+ */
117
+ create(orgId: string, accountId: string, input: {
118
+ name: string;
119
+ contentType: string;
120
+ size: number;
121
+ sha256: string;
122
+ purpose: UploadPurpose;
123
+ }): Promise<CreatedFile>;
124
+ /** The admission checks of {@link create}; returns the normalized content type. */
125
+ private admit;
126
+ /** The type and size checks of an upload; returns the normalized content type. */
127
+ private admitType;
128
+ /**
129
+ * The owner of a library file of the org that is not deleted, or null (no such file: a `read`
130
+ * copy, another org's id). A file has one owner (file library spec §2).
131
+ */
132
+ ownerOf(orgId: string, fileId: string): Promise<string | null>;
133
+ /**
134
+ * Adds bytes the kernel already holds (a conversation file the `Platform` tool resolved, never
135
+ * another account's library file: the caller refuses those) to the account's library as an
136
+ * upload, `ready` at once.
137
+ *
138
+ * - `referencedId` already one of the account's `ready` files: returned as it is
139
+ * (`existing: true`), or, with a `rename` other than its name, a new entry on its blob.
140
+ * - Otherwise: no object store → `storage.unavailable`, the upload's type and size checks, the
141
+ * signature check of finalize (`file.type_not_allowed`); the account's own `ready` file of the
142
+ * same name, type and sha256 is returned as it is (`existing: true`; a repeated call adds
143
+ * nothing). Else the bytes go through {@link BlobsService.ensureFromBytes} (the org's ready
144
+ * blob of this hash, else a new one written intent first and settled) and the file row is
145
+ * inserted on it behind {@link BlobsService.lockReady}; a blob a deletion claimed meanwhile is
146
+ * ensured again, and {@link FileBlobClaimedError} is thrown after
147
+ * {@link ADD_BLOB_ATTEMPTS} tries. No presigned form is involved.
148
+ */
149
+ addFromBytes(orgId: string, accountId: string, input: {
150
+ /** The id the bytes were referenced by. */
151
+ referencedId?: string;
152
+ /** The referenced file's name. */
153
+ name: string;
154
+ /** The name the new entry takes instead of {@link name}. */
155
+ rename?: string;
156
+ contentType: string;
157
+ bytes: Uint8Array;
158
+ sha256: string;
159
+ signal?: AbortSignal;
160
+ }): Promise<FileView & {
161
+ existing: boolean;
162
+ }>;
163
+ /**
164
+ * The transaction of {@link addFromBytes}: the blob locked ready, then a `ready` upload file of
165
+ * the account on it. Null when a deletion claimed the blob (nothing written).
166
+ */
167
+ private insertReady;
168
+ /**
169
+ * The instant path of {@link create}: a new file on the blob of one of the caller's own files
170
+ * with this sha256, or undefined. The blob passes {@link BlobsService.lockReady}, so a deletion
171
+ * claiming it concurrently either waits for this file or makes the caller upload.
172
+ */
173
+ private createOnOwnBlob;
174
+ /**
175
+ * Finishes an upload (the uploader only; a file already `draft` or `ready` is answered as it
176
+ * is; an expired upload is `file.not_found`):
177
+ *
178
+ * - the staging object missing, or smaller than declared → `file.not_ready` (upload again);
179
+ * - larger than declared, a stored type or a signature that does not match →
180
+ * `file.type_not_allowed` / `file.too_large`, and the upload is rejected;
181
+ * - the whole object is read; a sha256 other than the declared one → `file.hash_mismatch`, and
182
+ * the upload is rejected.
183
+ *
184
+ * A rejected upload expires at once and owes its staging object's deletion (no direct delete:
185
+ * the outbox handler re-reads the row). Otherwise the verified bytes are copied to a new
186
+ * kernel-owned blob (intent first) and one transaction, holding the file row, settles that blob
187
+ * and makes the file `draft` (composer, expiring after `attachments.unboundTtlHours`) or `ready`
188
+ * (library), owing the staging object's deletion. The same work runs whether or not the org held
189
+ * these bytes already.
190
+ */
191
+ finalize(orgId: string, accountId: string, fileId: string): Promise<FileView>;
192
+ /**
193
+ * The bounded part of {@link finalize}: reads the staging object, checks its signature and hash,
194
+ * copies the verified bytes to a new blob and commits.
195
+ */
196
+ private verifyAndCopy;
197
+ /**
198
+ * Streams the whole staging object once (bounded by the declared size and a timeout): its bytes,
199
+ * sha256, leading bytes' signature check and, for a PDF, its page count. Null when the object
200
+ * vanished or is not the declared size.
201
+ */
202
+ private readUpload;
203
+ /**
204
+ * A rejected upload: under the file row's lock, an upload still in progress expires now and its
205
+ * staging object's deletion is owed (the cleanup job then drops the row).
206
+ */
207
+ private reject;
208
+ /**
209
+ * The transaction of {@link finalize}: the file row locked and still an unexpired upload, the new
210
+ * blob settled ({@link BlobsService.settle}), the file pointed at the result and set `draft` /
211
+ * `ready` with the verified hash, the staging object's deletion owed. When the file is no longer
212
+ * an upload in progress (a concurrent finalize, a discard, the cleanup) the new blob is released
213
+ * instead (`deleting`, its deletion owed); the answer is then the file as it is, or null when it
214
+ * expired or is gone.
215
+ */
216
+ private commitFinalize;
217
+ /**
218
+ * A composer upload removed before it was sent (the uploader only; an `uploading` or `draft`
219
+ * file no conversation refers to, else `file.not_found`): `deleted`, with the deferred release of
220
+ * what it held owed (`file-release`, run by `BlobObjects.releaseFile`): the request does the same
221
+ * work whatever else points at its blob.
222
+ */
223
+ discard(orgId: string, accountId: string, fileId: string): Promise<void>;
224
+ /**
225
+ * Expires one batch of the org's `uploading` / `draft` files past `expires_at` (`FOR UPDATE SKIP
226
+ * LOCKED`, so concurrent runs never share a row): each becomes `deleted` with the deferred release
227
+ * of what it held owed (`file-release`). Returns how many it took.
228
+ */
229
+ expireBatch(orgId: string): Promise<number>;
230
+ /**
231
+ * Attaches the sender's files to a message, in the message's transaction (rows `FOR UPDATE`, in
232
+ * id order). The caller has already checked that the sender may write to the conversation (this
233
+ * checks only the files' ownership). Returns the content blocks the `user_message` carries
234
+ * (`ref`, in `ids` order):
235
+ *
236
+ * - more than `attachments.maxPerMessage`, or an id twice → `validation_failed` (path `files`);
237
+ * - not found, another account's, deleted, or an expired draft → `file.not_found`;
238
+ * - still uploading → `file.not_ready`;
239
+ * both with details `[{ path: "files", message, fileId }]`, for the web to mark the entry.
240
+ *
241
+ * Drafts become `ready` (no expiry; `source_conversation_id` set when it has none), and each
242
+ * file gets the conversation's `attached` reference (`first_seq` when given; an existing one is
243
+ * kept). A file may be attached in any number of the owner's conversations.
244
+ */
245
+ attachForMessage(orgId: string, conversationId: string, accountId: string, ids: readonly string[], firstSeq?: number): Promise<LogContentBlock[]>;
246
+ /**
247
+ * Deletes one of the account's ready files from the library (file library spec §6; the owner
248
+ * only, else `file.not_found`): `deleted` with `deleted_at`, its shares revoked
249
+ * (`file_deleted`) in the same transaction. Its bytes stay until the blob sweep frees them after
250
+ * `files.deletedRetentionDays`; conversations that referred to it show it as no longer available
251
+ * and later model requests render the placeholder. Each referring conversation gets a `files`
252
+ * change after the commit (a lost publish only delays the panel's refresh).
253
+ */
254
+ delete(orgId: string, accountId: string, fileId: string): Promise<void>;
255
+ }