@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,10 +1,11 @@
1
1
  import type { FastifyReply } from "fastify";
2
2
  import { ConversationFiles } from "../conversations/files.js";
3
3
  import { ApiError } from "../errors.js";
4
+ import { BlobsService } from "../files/blobs.service.js";
5
+ import { LibraryQuery } from "../files/library-query.js";
4
6
  import { KernelDb } from "../infra/database/kernel-db.js";
5
7
  import type { KernelLogger } from "../log.js";
6
8
  import { ShareLiveness } from "../shares/liveness.js";
7
- import { StorageService } from "../storage/storage.service.js";
8
9
  import { type HtmlClaims, HtmlTokens } from "./html-token.js";
9
10
  /** What `POST …/html-token` returns: `path` loads the document once within `expiresIn` seconds. */
10
11
  export interface HtmlTokenResponse {
@@ -18,7 +19,8 @@ export declare const htmlNotFound: () => ApiError;
18
19
  * mints a short-lived document token for one version of an HTML file ({@link mint}); the public
19
20
  * route serves it ({@link serve}) under the sandbox CSP after re-checking, live, what the token
20
21
  * names: the owner can still read the file (`ConversationFiles.file`: membership, active account,
21
- * conversation and agent not deleted; an upload's object still the one finalize checked), or the
22
+ * conversation and agent not deleted; the file not deleted and its blob still the recorded bytes;
23
+ * a library file: `LibraryQuery.live`, still the account's and not deleted), or the
22
24
  * share is still live at that generation (`ShareLiveness.byId`). The bytes are streamed by the
23
25
  * kernel as stored; never a presigned URL on the app origin. HTML larger than
24
26
  * `FILE_PREVIEW_MAX_BYTES` is never rendered.
@@ -26,11 +28,18 @@ export declare const htmlNotFound: () => ApiError;
26
28
  export declare class HtmlDocumentService {
27
29
  private readonly db;
28
30
  private readonly files;
31
+ /** The account's own library files (the Files page). */
32
+ private readonly library;
29
33
  private readonly liveness;
30
- private readonly storage;
34
+ /** A conversation file's or a share's bytes, through its blob. */
35
+ private readonly blobs;
31
36
  private readonly tokens;
32
37
  private readonly log?;
33
- constructor(db: KernelDb, files: Pick<ConversationFiles, "file">, liveness: Pick<ShareLiveness, "byId">, storage: Pick<StorageService, "kernel">, tokens: HtmlTokens, log?: KernelLogger | undefined);
38
+ constructor(db: KernelDb, files: Pick<ConversationFiles, "file">,
39
+ /** The account's own library files (the Files page). */
40
+ library: Pick<LibraryQuery, "live">, liveness: Pick<ShareLiveness, "byId">,
41
+ /** A conversation file's or a share's bytes, through its blob. */
42
+ blobs: Pick<BlobsService, "open">, tokens: HtmlTokens, log?: KernelLogger | undefined);
34
43
  /**
35
44
  * A document token for one version of the caller's conversation file (a delivered version or an
36
45
  * upload). Not the owner → `conversation.not_found`; unknown file →
@@ -39,6 +48,12 @@ export declare class HtmlDocumentService {
39
48
  * `conversation.artifact_not_previewable`.
40
49
  */
41
50
  mint(orgId: string, conversationId: string, accountId: string, fileId: string): Promise<HtmlTokenResponse>;
51
+ /**
52
+ * A document token for one of the caller's library files (the Files page; file library spec
53
+ * §6): another account's, unknown or deleted → `file.not_found`; bytes gone → `file.deleted`;
54
+ * not HTML, or larger than `FILE_PREVIEW_MAX_BYTES` → `conversation.artifact_not_previewable`.
55
+ */
56
+ mintLibrary(orgId: string, accountId: string, fileId: string): Promise<HtmlTokenResponse>;
42
57
  /**
43
58
  * Serves the document verified claims name with the spec §4 headers, the CSP built from the CDN
44
59
  * allowlist read now. Any live check failing → 404 `not_found`.
@@ -10,14 +10,14 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Readable } from "node:stream";
11
11
  import { FILE_PREVIEW_MAX_BYTES } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable, Optional } from "@nestjs/common";
13
- import { attachmentContentMatches } from "../conversations/attachments.service.js";
14
13
  import { ConversationFiles } from "../conversations/files.js";
15
14
  import { ApiError } from "../errors.js";
15
+ import { BlobsService } from "../files/blobs.service.js";
16
+ import { LibraryQuery } from "../files/library-query.js";
16
17
  import { KernelDb } from "../infra/database/kernel-db.js";
17
18
  import { KERNEL_LOGGER } from "../infra/tokens.js";
18
19
  import { ShareLiveness } from "../shares/liveness.js";
19
20
  import { readHtmlCdnAllowlist } from "../shares/settings.js";
20
- import { StorageService } from "../storage/storage.service.js";
21
21
  import { htmlDocumentCsp } from "./csp.js";
22
22
  import { HTML_TOKEN_TTL_SECONDS, HtmlTokens } from "./html-token.js";
23
23
  import { htmlContentType, isHtmlType } from "./html-type.js";
@@ -29,7 +29,8 @@ const notPreviewable = (message) => new ApiError("conversation.artifact_not_prev
29
29
  * mints a short-lived document token for one version of an HTML file ({@link mint}); the public
30
30
  * route serves it ({@link serve}) under the sandbox CSP after re-checking, live, what the token
31
31
  * names: the owner can still read the file (`ConversationFiles.file`: membership, active account,
32
- * conversation and agent not deleted; an upload's object still the one finalize checked), or the
32
+ * conversation and agent not deleted; the file not deleted and its blob still the recorded bytes;
33
+ * a library file: `LibraryQuery.live`, still the account's and not deleted), or the
33
34
  * share is still live at that generation (`ShareLiveness.byId`). The bytes are streamed by the
34
35
  * kernel as stored; never a presigned URL on the app origin. HTML larger than
35
36
  * `FILE_PREVIEW_MAX_BYTES` is never rendered.
@@ -37,15 +38,21 @@ const notPreviewable = (message) => new ApiError("conversation.artifact_not_prev
37
38
  let HtmlDocumentService = class HtmlDocumentService {
38
39
  db;
39
40
  files;
41
+ library;
40
42
  liveness;
41
- storage;
43
+ blobs;
42
44
  tokens;
43
45
  log;
44
- constructor(db, files, liveness, storage, tokens, log) {
46
+ constructor(db, files,
47
+ /** The account's own library files (the Files page). */
48
+ library, liveness,
49
+ /** A conversation file's or a share's bytes, through its blob. */
50
+ blobs, tokens, log) {
45
51
  this.db = db;
46
52
  this.files = files;
53
+ this.library = library;
47
54
  this.liveness = liveness;
48
- this.storage = storage;
55
+ this.blobs = blobs;
49
56
  this.tokens = tokens;
50
57
  this.log = log;
51
58
  }
@@ -73,6 +80,22 @@ let HtmlDocumentService = class HtmlDocumentService {
73
80
  });
74
81
  return { path: `/api/v1/html/${token}`, expiresIn: HTML_TOKEN_TTL_SECONDS };
75
82
  }
83
+ /**
84
+ * A document token for one of the caller's library files (the Files page; file library spec
85
+ * §6): another account's, unknown or deleted → `file.not_found`; bytes gone → `file.deleted`;
86
+ * not HTML, or larger than `FILE_PREVIEW_MAX_BYTES` → `conversation.artifact_not_previewable`.
87
+ */
88
+ async mintLibrary(orgId, accountId, fileId) {
89
+ const f = await this.library.live(orgId, accountId, fileId);
90
+ if (!isHtmlType(f.name, f.contentType)) {
91
+ throw notPreviewable("Only HTML files render as documents; download this file instead");
92
+ }
93
+ if (f.size > FILE_PREVIEW_MAX_BYTES) {
94
+ throw notPreviewable("This HTML file is too large to render; download it instead");
95
+ }
96
+ const { token } = this.tokens.issue({ kind: "library", orgId, fileId: f.id, accountId });
97
+ return { path: `/api/v1/html/${token}`, expiresIn: HTML_TOKEN_TTL_SECONDS };
98
+ }
76
99
  /**
77
100
  * Serves the document verified claims name with the spec §4 headers, the CSP built from the CDN
78
101
  * allowlist read now. Any live check failing → 404 `not_found`.
@@ -83,11 +106,10 @@ let HtmlDocumentService = class HtmlDocumentService {
83
106
  throw htmlNotFound();
84
107
  // read before the object is opened, so no stream is held across this query
85
108
  const allowlist = await readHtmlCdnAllowlist(this.db.db, this.log);
86
- const got = await this.storage.kernel(source.orgId).get(source.objectKey);
109
+ const got = await this.blobs.open(source.orgId, source.blob);
87
110
  if (!got)
88
111
  throw htmlNotFound();
89
- if (got.head.size > FILE_PREVIEW_MAX_BYTES ||
90
- (source.recorded && !attachmentContentMatches(source.recorded, got.head))) {
112
+ if (got.head.size > FILE_PREVIEW_MAX_BYTES) {
91
113
  await got.body.cancel().catch(() => { });
92
114
  throw htmlNotFound();
93
115
  }
@@ -108,11 +130,14 @@ let HtmlDocumentService = class HtmlDocumentService {
108
130
  if (s === null || !isHtmlType(s.name, s.contentType) || s.size > FILE_PREVIEW_MAX_BYTES) {
109
131
  return null;
110
132
  }
111
- return { orgId: s.orgId, objectKey: s.objectKey, contentType: s.contentType };
133
+ return { orgId: s.orgId, contentType: s.contentType, blob: s.blob };
112
134
  }
113
135
  let f;
114
136
  try {
115
- f = await this.files.file(claims.orgId, claims.conversationId, claims.accountId, claims.fileId);
137
+ f =
138
+ claims.kind === "library"
139
+ ? await this.library.live(claims.orgId, claims.accountId, claims.fileId)
140
+ : await this.files.file(claims.orgId, claims.conversationId, claims.accountId, claims.fileId);
116
141
  }
117
142
  catch (e) {
118
143
  // the owner lost access, the file is unknown or the upload changed: all the same 404
@@ -122,22 +147,18 @@ let HtmlDocumentService = class HtmlDocumentService {
122
147
  }
123
148
  if (!isHtmlType(f.name, f.contentType) || f.size > FILE_PREVIEW_MAX_BYTES)
124
149
  return null;
125
- return {
126
- orgId: claims.orgId,
127
- objectKey: f.objectKey,
128
- contentType: f.contentType,
129
- recorded: f.recorded,
130
- };
150
+ return { orgId: claims.orgId, contentType: f.contentType, blob: f.blob };
131
151
  }
132
152
  };
133
153
  HtmlDocumentService = __decorate([
134
154
  Injectable(),
135
155
  __param(0, Inject(KernelDb)),
136
156
  __param(1, Inject(ConversationFiles)),
137
- __param(2, Inject(ShareLiveness)),
138
- __param(3, Inject(StorageService)),
139
- __param(4, Inject(HtmlTokens)),
140
- __param(5, Optional()),
141
- __param(5, Inject(KERNEL_LOGGER))
157
+ __param(2, Inject(LibraryQuery)),
158
+ __param(3, Inject(ShareLiveness)),
159
+ __param(4, Inject(BlobsService)),
160
+ __param(5, Inject(HtmlTokens)),
161
+ __param(6, Optional()),
162
+ __param(6, Inject(KERNEL_LOGGER))
142
163
  ], HtmlDocumentService);
143
164
  export { HtmlDocumentService };
@@ -7,7 +7,8 @@ export declare const HTML_TOKEN_TTL_SECONDS = 300;
7
7
  export declare const HTML_TOKEN_SKEW_SECONDS = 30;
8
8
  /**
9
9
  * What a document token names (file sharing spec §4): one version of a conversation file for its
10
- * owner (the right panel), or one generation of a share (the share page). Re-checked live on use.
10
+ * owner (the right panel), one of the account's library files (`library`, the Files page; file
11
+ * library spec §6), or one generation of a share (the share page). Re-checked live on use.
11
12
  */
12
13
  export type HtmlClaims = {
13
14
  kind: "file";
@@ -16,6 +17,12 @@ export type HtmlClaims = {
16
17
  fileId: string;
17
18
  accountId: string;
18
19
  exp: number;
20
+ } | {
21
+ kind: "library";
22
+ orgId: string;
23
+ fileId: string;
24
+ accountId: string;
25
+ exp: number;
19
26
  } | {
20
27
  kind: "share";
21
28
  shareId: string;
@@ -25,6 +32,8 @@ export type HtmlClaims = {
25
32
  /** Claims before issuing (the token's expiry is set by {@link HtmlTokens.issue}). */
26
33
  export type HtmlClaimsInput = Omit<Extract<HtmlClaims, {
27
34
  kind: "file";
35
+ }>, "exp"> | Omit<Extract<HtmlClaims, {
36
+ kind: "library";
28
37
  }>, "exp"> | Omit<Extract<HtmlClaims, {
29
38
  kind: "share";
30
39
  }>, "exp">;
@@ -20,6 +20,7 @@ const TOKEN_MAX = 2048;
20
20
  const MAC_LEN = 32;
21
21
  const B64URL = /^[A-Za-z0-9_-]+$/;
22
22
  const FILE_KEYS = ["kind", "orgId", "conversationId", "fileId", "accountId", "exp"];
23
+ const LIBRARY_KEYS = ["kind", "orgId", "fileId", "accountId", "exp"];
23
24
  const SHARE_KEYS = ["kind", "shareId", "generation", "exp"];
24
25
  const isId = (v) => typeof v === "string" && v !== "" && v.length <= 100;
25
26
  /** Strict base64url: the alphabet only, no padding, the canonical encoding of its bytes. */
@@ -55,6 +56,19 @@ function parseClaims(v) {
55
56
  exp: c.exp,
56
57
  };
57
58
  }
59
+ if (c.kind === "library") {
60
+ if (!sameKeys(c, LIBRARY_KEYS))
61
+ return null;
62
+ if (!isId(c.orgId) || !isId(c.fileId) || !isId(c.accountId))
63
+ return null;
64
+ return {
65
+ kind: "library",
66
+ orgId: c.orgId,
67
+ fileId: c.fileId,
68
+ accountId: c.accountId,
69
+ exp: c.exp,
70
+ };
71
+ }
58
72
  if (c.kind === "share") {
59
73
  if (!sameKeys(c, SHARE_KEYS) || !isId(c.shareId))
60
74
  return null;
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { Module } from "@nestjs/common";
8
8
  import { ConversationsModule } from "../conversations/conversations.module.js";
9
+ import { LibraryReadModule } from "../files/library-read.module.js";
9
10
  import { ShareLivenessModule } from "../shares/liveness.js";
10
11
  import { StorageModule } from "../storage/storage.module.js";
11
12
  import { HtmlDocumentService } from "./html-document.service.js";
@@ -18,7 +19,13 @@ let HtmlModule = class HtmlModule {
18
19
  };
19
20
  HtmlModule = __decorate([
20
21
  Module({
21
- imports: [ConversationsModule, ShareLivenessModule, StorageModule, HtmlTokensModule],
22
+ imports: [
23
+ ConversationsModule,
24
+ LibraryReadModule,
25
+ ShareLivenessModule,
26
+ StorageModule,
27
+ HtmlTokensModule,
28
+ ],
22
29
  providers: [HtmlDocumentService],
23
30
  exports: [HtmlDocumentService, HtmlTokensModule],
24
31
  })
@@ -23,6 +23,8 @@ import { ModelsController } from "../agents/models.controller.js";
23
23
  import { PendingConnectorsController } from "../agents/pending-connectors.controller.js";
24
24
  import { ReadinessController } from "../agents/readiness.controller.js";
25
25
  import { AgentSaveAsTemplateController, AgentTemplatesController, } from "../agents/templates.controller.js";
26
+ import { AutomationsController } from "../automations/automations.controller.js";
27
+ import { AutomationsModule } from "../automations/automations.module.js";
26
28
  import { BackgroundController } from "../background/background.controller.js";
27
29
  import { BackgroundModule } from "../background/background.module.js";
28
30
  import { AdminCatalogController } from "../catalog/admin-catalog.controller.js";
@@ -54,6 +56,8 @@ import { TrajectoryController } from "../evals/trajectory.controller.js";
54
56
  import { ExtensionsModule } from "../extensions/extensions.module.js";
55
57
  import { ExtensionPointDefaultsController } from "../extensions/point-defaults.controller.js";
56
58
  import { FilesModule } from "../files/files.module.js";
59
+ import { LibraryFilesController } from "../files/library.controller.js";
60
+ import { LibraryReadModule } from "../files/library-read.module.js";
57
61
  import { FilePreviewersController } from "../files/previewers.controller.js";
58
62
  import { GitModule } from "../git/git.module.js";
59
63
  import { HandoffController } from "../handoff/handoff.controller.js";
@@ -86,8 +90,6 @@ import { PushController } from "../push/push.controller.js";
86
90
  import { PushModule } from "../push/push.module.js";
87
91
  import { RuntimeModule } from "../runtime/runtime.module.js";
88
92
  import { ConversationStreamController } from "../runtime/stream.controller.js";
89
- import { SchedulesController } from "../schedules/schedules.controller.js";
90
- import { SchedulesModule } from "../schedules/schedules.module.js";
91
93
  import { SetupModule } from "../setup/setup.module.js";
92
94
  import { SetupChecksController } from "../setup/setup-checks.controller.js";
93
95
  import { SetupGuidesController } from "../setup/setup-guides.controller.js";
@@ -161,8 +163,9 @@ const CONTROLLERS = [
161
163
  PermissionProfilesController,
162
164
  BackgroundController,
163
165
  DevicesController,
164
- SchedulesController,
166
+ AutomationsController,
165
167
  AttachmentsController,
168
+ LibraryFilesController,
166
169
  SkillsController,
167
170
  SkillChangesController,
168
171
  AgentSkillsController,
@@ -253,13 +256,15 @@ ApiModule = __decorate([
253
256
  ChannelsModule,
254
257
  EvalsModule,
255
258
  FilesModule,
259
+ // the person's files: uploads, drafts, blobs
260
+ LibraryReadModule,
256
261
  UiModule,
257
262
  InboxModule,
258
263
  ThemesModule,
259
264
  ClientModule,
260
265
  SetupModule,
261
- // scheduled tasks (the controller comes with the HTTP routes)
262
- SchedulesModule,
266
+ // automations (the controller comes with the HTTP routes)
267
+ AutomationsModule,
263
268
  // the git gateway (run tickets; the gateway route comes with it)
264
269
  GitModule,
265
270
  // file sharing (shares of conversation files)
@@ -0,0 +1,8 @@
1
+ import type { FastifyReply } from "fastify";
2
+ /**
3
+ * An `AbortSignal` tied to one HTTP request: aborted when the connection closes before the
4
+ * response is written (the client hung up), never by a close after a finished response. The same
5
+ * rule as the plugin routes' `req.signal` and the channel webhooks. For a route whose handler asks
6
+ * a device (or another remote) on the request's behalf, so the call stops when nobody waits.
7
+ */
8
+ export declare function requestSignal(reply: FastifyReply): AbortSignal;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * An `AbortSignal` tied to one HTTP request: aborted when the connection closes before the
3
+ * response is written (the client hung up), never by a close after a finished response. The same
4
+ * rule as the plugin routes' `req.signal` and the channel webhooks. For a route whose handler asks
5
+ * a device (or another remote) on the request's behalf, so the call stops when nobody waits.
6
+ */
7
+ export function requestSignal(reply) {
8
+ const ac = new AbortController();
9
+ reply.raw.once("close", () => {
10
+ if (!reply.raw.writableFinished)
11
+ ac.abort();
12
+ });
13
+ return ac.signal;
14
+ }
@@ -119,6 +119,24 @@ export type CompactionSettingsPatch = z.infer<typeof COMPACTION_SETTINGS_PARTIAL
119
119
  * the rest follow the platform's settings, which are themselves the built-in defaults when unset.
120
120
  */
121
121
  export declare function effectiveCompactionSettings(platform: CompactionSettings, org: CompactionSettingsPatch | undefined): CompactionSettings;
122
+ /**
123
+ * Prompt cache settings (idle compaction spec): `longTtl` asks the model call for the longer
124
+ * cache tier, which costs more per write and keeps a conversation's prefix warm longer.
125
+ */
126
+ export declare const PROMPT_CACHE_SETTINGS: z.ZodObject<{
127
+ longTtl: z.ZodDefault<z.ZodBoolean>;
128
+ }, z.core.$strip>;
129
+ export type PromptCacheSettings = z.infer<typeof PROMPT_CACHE_SETTINGS>;
130
+ /** The partial form the platform and org patches carry: only the given fields. */
131
+ export declare const PROMPT_CACHE_SETTINGS_PARTIAL: z.ZodObject<{
132
+ longTtl: z.ZodOptional<z.ZodBoolean>;
133
+ }, z.core.$strip>;
134
+ /** The strict request-body form: a misspelled field is a 400, not a silent no-op. */
135
+ export declare const PROMPT_CACHE_SETTINGS_PATCH: z.ZodObject<{
136
+ longTtl: z.ZodOptional<z.ZodBoolean>;
137
+ }, z.core.$strict>;
138
+ /** The prompt cache settings in effect for an organization: its override over the platform. */
139
+ export declare function effectivePromptCacheSettings(platform: PromptCacheSettings, org: z.infer<typeof PROMPT_CACHE_SETTINGS_PARTIAL> | undefined): PromptCacheSettings;
122
140
  export declare const DEPLOYMENT_SETTINGS: z.ZodObject<{
123
141
  orgCreation: z.ZodDefault<z.ZodEnum<{
124
142
  anyone: "anyone";
@@ -160,6 +178,9 @@ export declare const DEPLOYMENT_SETTINGS: z.ZodObject<{
160
178
  reserveTokens: z.ZodDefault<z.ZodNumber>;
161
179
  maxOutputTokens: z.ZodDefault<z.ZodNumber>;
162
180
  }, z.core.$strip>>;
181
+ promptCache: z.ZodPrefault<z.ZodObject<{
182
+ longTtl: z.ZodDefault<z.ZodBoolean>;
183
+ }, z.core.$strip>>;
163
184
  htmlRenderCdnAllowlist: z.ZodDefault<z.ZodArray<z.ZodType<string, unknown, z.core.$ZodTypeInternals<string, unknown>>>>;
164
185
  }, z.core.$strip>;
165
186
  export type DeploymentSettings = z.infer<typeof DEPLOYMENT_SETTINGS>;
@@ -264,6 +285,9 @@ export declare const DEPLOYMENT_SETTINGS_PATCH: z.ZodObject<{
264
285
  reserveTokens: z.ZodOptional<z.ZodNumber>;
265
286
  maxOutputTokens: z.ZodOptional<z.ZodNumber>;
266
287
  }, z.core.$strict>>;
288
+ promptCache: z.ZodOptional<z.ZodObject<{
289
+ longTtl: z.ZodOptional<z.ZodBoolean>;
290
+ }, z.core.$strict>>;
267
291
  externalSharing: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
268
292
  allow: "allow";
269
293
  deny: "deny";
@@ -293,6 +317,8 @@ export declare function readSubagentLimitOverride(db: KernelSchemaDb, orgId: str
293
317
  * defaults, as {@link SettingsService.get} reads them.
294
318
  */
295
319
  export declare function readPlatformCompactionSettings(db: KernelSchemaDb): Promise<CompactionSettings>;
320
+ /** The platform's prompt cache settings, read live from PG (what an org that follows gets). */
321
+ export declare function readPlatformPromptCacheSettings(db: KernelSchemaDb): Promise<PromptCacheSettings>;
296
322
  /**
297
323
  * When orgs may not create their own connectors / skills (deployment setting `customConnectors` /
298
324
  * `customSkills` is `deny`, C22) throws `catalog.custom_disabled`: install from the platform
@@ -173,6 +173,19 @@ export function effectiveCompactionSettings(platform, org) {
173
173
  maxOutputTokens: org?.maxOutputTokens ?? platform.maxOutputTokens,
174
174
  };
175
175
  }
176
+ /**
177
+ * Prompt cache settings (idle compaction spec): `longTtl` asks the model call for the longer
178
+ * cache tier, which costs more per write and keeps a conversation's prefix warm longer.
179
+ */
180
+ export const PROMPT_CACHE_SETTINGS = z.object({ longTtl: z.boolean().default(false) });
181
+ /** The partial form the platform and org patches carry: only the given fields. */
182
+ export const PROMPT_CACHE_SETTINGS_PARTIAL = z.object({ longTtl: z.boolean() }).partial();
183
+ /** The strict request-body form: a misspelled field is a 400, not a silent no-op. */
184
+ export const PROMPT_CACHE_SETTINGS_PATCH = PROMPT_CACHE_SETTINGS_PARTIAL.strict();
185
+ /** The prompt cache settings in effect for an organization: its override over the platform. */
186
+ export function effectivePromptCacheSettings(platform, org) {
187
+ return { longTtl: org?.longTtl ?? platform.longTtl };
188
+ }
176
189
  export const DEPLOYMENT_SETTINGS = z.object({
177
190
  orgCreation: z.enum(["anyone", "super_admin"]).default("anyone"),
178
191
  /** 按组织覆盖运行并发上限(orgId → 上限);未列出的组织用 `runtime.orgConcurrency`。 */
@@ -213,6 +226,8 @@ export const DEPLOYMENT_SETTINGS = z.object({
213
226
  * values; an organization may override any field in its own settings.
214
227
  */
215
228
  compaction: COMPACTION_SETTINGS.prefault({}),
229
+ /** Prompt cache tier (idle compaction spec): the platform default; an org may override it. */
230
+ promptCache: PROMPT_CACHE_SETTINGS.prefault({}),
216
231
  /**
217
232
  * The CDN origins a rendered HTML file may load scripts, styles, fonts and images from (file
218
233
  * sharing spec §4): `https://` origins only; applies to the next document load. No org level.
@@ -324,6 +339,8 @@ export const DEPLOYMENT_SETTINGS_PATCH = z
324
339
  * one, fields left out keep their value.
325
340
  */
326
341
  compaction: COMPACTION_SETTINGS_PATCH.optional(),
342
+ /** Prompt cache settings: each given field replaces the stored one. */
343
+ promptCache: PROMPT_CACHE_SETTINGS_PATCH.optional(),
327
344
  /**
328
345
  * The platform's external sharing switch (file sharing spec §8): allow or deny; null clears it
329
346
  * (back to the default, deny). A value set in the startup config is read-only (409
@@ -398,6 +415,16 @@ export async function readPlatformCompactionSettings(db) {
398
415
  const parsed = COMPACTION_SETTINGS.safeParse(row?.value ?? {});
399
416
  return parsed.success ? parsed.data : DEFAULTS.compaction;
400
417
  }
418
+ /** The platform's prompt cache settings, read live from PG (what an org that follows gets). */
419
+ export async function readPlatformPromptCacheSettings(db) {
420
+ const row = await db
421
+ .selectFrom("deployment_settings")
422
+ .select("value")
423
+ .where("key", "=", "promptCache")
424
+ .executeTakeFirst();
425
+ const parsed = PROMPT_CACHE_SETTINGS.safeParse(row?.value ?? {});
426
+ return parsed.success ? parsed.data : DEFAULTS.promptCache;
427
+ }
401
428
  /**
402
429
  * When orgs may not create their own connectors / skills (deployment setting `customConnectors` /
403
430
  * `customSkills` is `deny`, C22) throws `catalog.custom_disabled`: install from the platform
@@ -819,13 +846,14 @@ let SettingsService = class SettingsService {
819
846
  }
820
847
  next.uiTheme = { id: patch.uiTheme.id };
821
848
  }
822
- const { runConcurrencyOverrides: runPatch, sandboxLimitOverrides: sandboxPatch, subagentLimitOverrides: subagentPatch, uiArrangement: arrangementPatch, clientExtensions: clientPatch, compaction: compactionPatch, } = patch;
849
+ const { runConcurrencyOverrides: runPatch, sandboxLimitOverrides: sandboxPatch, subagentLimitOverrides: subagentPatch, uiArrangement: arrangementPatch, clientExtensions: clientPatch, compaction: compactionPatch, promptCache: promptCachePatch, } = patch;
823
850
  if (runPatch !== undefined ||
824
851
  sandboxPatch !== undefined ||
825
852
  subagentPatch !== undefined ||
826
853
  arrangementPatch !== undefined ||
827
854
  clientPatch !== undefined ||
828
- compactionPatch !== undefined) {
855
+ compactionPatch !== undefined ||
856
+ promptCachePatch !== undefined) {
829
857
  const current = await this.get();
830
858
  if (clientPatch !== undefined) {
831
859
  next.clientExtensions = {
@@ -844,6 +872,9 @@ let SettingsService = class SettingsService {
844
872
  maxOutputTokens: compactionPatch.maxOutputTokens ?? current.compaction.maxOutputTokens,
845
873
  };
846
874
  }
875
+ if (promptCachePatch !== undefined) {
876
+ next.promptCache = { longTtl: promptCachePatch.longTtl ?? current.promptCache.longTtl };
877
+ }
847
878
  if (arrangementPatch !== undefined) {
848
879
  next.uiArrangement = mergeArrangement(current.uiArrangement, arrangementPatch);
849
880
  }
@@ -5,8 +5,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { Module } from "@nestjs/common";
8
+ import { AutomationsModule } from "../automations/automations.module.js";
8
9
  import { CatalogModule } from "../catalog/catalog.module.js";
9
- import { SchedulesModule } from "../schedules/schedules.module.js";
10
10
  import { SkillsModule } from "../skills/skills.module.js";
11
11
  import { ToolsModule } from "../tools/tools.module.js";
12
12
  import { InboxService } from "./inbox.service.js";
@@ -19,7 +19,7 @@ let InboxModule = class InboxModule {
19
19
  };
20
20
  InboxModule = __decorate([
21
21
  Module({
22
- imports: [ToolsModule, SkillsModule, CatalogModule, SchedulesModule],
22
+ imports: [ToolsModule, SkillsModule, CatalogModule, AutomationsModule],
23
23
  providers: [InboxService, PlatformInboxService],
24
24
  exports: [InboxService, PlatformInboxService],
25
25
  })
@@ -1,6 +1,6 @@
1
+ import { type AutomationAttention, AutomationsService } from "../automations/automations.service.js";
1
2
  import { CatalogRequestsService, type CatalogRequestView } from "../catalog/requests.service.js";
2
3
  import { KernelDb } from "../infra/database/kernel-db.js";
3
- import { type ScheduleAttention, ScheduledTasksService } from "../schedules/scheduled-tasks.service.js";
4
4
  import { SkillChangesService, type SkillChangeView } from "../skills/changes.service.js";
5
5
  import { ApprovalsService, type ApprovalView } from "../tools/approvals.service.js";
6
6
  import type { OrgNoticeDetails } from "./org-notices.js";
@@ -34,7 +34,7 @@ export declare const INBOX_MAX_ITEMS = 100;
34
34
  * (M6 T26, C22; plugin scope spec §5.1);
35
35
  * - `catalog_request_decided`: the current user's own requests in this org that were approved or
36
36
  * rejected (with the reason), until dismissed (`POST catalog-requests/:id/dismiss`);
37
- * - `schedule_attention`: the current user's own scheduled task that needs them (spec §8): paused
37
+ * - `automation_attention`: the current user's own automation that needs them (spec §8): paused
38
38
  * for any reason but their own pause, its latest run failed, or its latest run was refused tools
39
39
  * or connections; derived live, gone once the task is resumed or runs clean;
40
40
  * - the org notices (`item_shared`, `shared_item_updated`, `upload_confirmed`,
@@ -63,19 +63,19 @@ export type InboxItem = {
63
63
  createdAt: string;
64
64
  request: CatalogRequestView;
65
65
  } | {
66
- type: "schedule_attention";
66
+ type: "automation_attention";
67
67
  /** `<taskId>:paused`, `<taskId>:failed` or `<taskId>:grants`. */
68
68
  id: string;
69
69
  createdAt: string;
70
- attention: ScheduleAttentionView;
70
+ attention: AutomationAttentionView;
71
71
  } | {
72
72
  type: OrgNoticeView["kind"];
73
73
  id: string;
74
74
  createdAt: string;
75
75
  notice: OrgNoticeView;
76
76
  };
77
- /** A scheduled task that needs its creator ({@link ScheduleAttention}, dates as ISO strings). */
78
- export type ScheduleAttentionView = Omit<ScheduleAttention, "at">;
77
+ /** An automation that needs its creator ({@link AutomationAttention}, dates as ISO strings). */
78
+ export type AutomationAttentionView = Omit<AutomationAttention, "at">;
79
79
  /** `GET /inbox` 的结果:新的在前,最多 {@link INBOX_MAX_ITEMS} 项;`truncated` 为 true 表示还有更多。 */
80
80
  export interface InboxView {
81
81
  items: InboxItem[];
@@ -87,8 +87,8 @@ export declare class InboxService {
87
87
  private readonly skillChanges;
88
88
  private readonly kdb;
89
89
  private readonly catalogRequests;
90
- private readonly schedules;
91
- constructor(approvals: Pick<ApprovalsService, "list">, skillChanges: Pick<SkillChangesService, "listPending">, kdb: KernelDb, catalogRequests: Pick<CatalogRequestsService, "listForOrgAdmin" | "listDecidedForRequester">, schedules: Pick<ScheduledTasksService, "attentionFor">);
90
+ private readonly automations;
91
+ constructor(approvals: Pick<ApprovalsService, "list">, skillChanges: Pick<SkillChangesService, "listPending">, kdb: KernelDb, catalogRequests: Pick<CatalogRequestsService, "listForOrgAdmin" | "listDecidedForRequester">, automations: Pick<AutomationsService, "attentionFor">);
92
92
  list(orgId: string, accountId: string): Promise<InboxView>;
93
93
  /** The org's open notices when the account is an org admin (else none), newest first. */
94
94
  private notices;
@@ -9,11 +9,11 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
+ import { AutomationsService, } from "../automations/automations.service.js";
12
13
  import { CATALOG_REQUESTS_LIST_MAX, CatalogRequestsService, } from "../catalog/requests.service.js";
13
14
  import { ApiError } from "../errors.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
15
16
  import { roleAtLeast } from "../orgs/roles.js";
16
- import { ScheduledTasksService, } from "../schedules/scheduled-tasks.service.js";
17
17
  import { SKILL_CHANGES_LIST_MAX, SkillChangesService, } from "../skills/changes.service.js";
18
18
  import { APPROVALS_LIST_MAX, ApprovalsService, } from "../tools/approvals.service.js";
19
19
  /** The most open org notices one inbox read returns. */
@@ -26,13 +26,13 @@ let InboxService = class InboxService {
26
26
  skillChanges;
27
27
  kdb;
28
28
  catalogRequests;
29
- schedules;
30
- constructor(approvals, skillChanges, kdb, catalogRequests, schedules) {
29
+ automations;
30
+ constructor(approvals, skillChanges, kdb, catalogRequests, automations) {
31
31
  this.approvals = approvals;
32
32
  this.skillChanges = skillChanges;
33
33
  this.kdb = kdb;
34
34
  this.catalogRequests = catalogRequests;
35
- this.schedules = schedules;
35
+ this.automations = automations;
36
36
  }
37
37
  async list(orgId, accountId) {
38
38
  const [approvals, changes, requests, decided, notices, attention] = await Promise.all([
@@ -41,7 +41,7 @@ let InboxService = class InboxService {
41
41
  this.catalogRequests.listForOrgAdmin(orgId, accountId),
42
42
  this.catalogRequests.listDecidedForRequester(orgId, accountId),
43
43
  this.notices(orgId, accountId),
44
- this.schedules.attentionFor(orgId, accountId),
44
+ this.automations.attentionFor(orgId, accountId),
45
45
  ]);
46
46
  const all = [
47
47
  ...approvals.map((a) => ({
@@ -69,7 +69,7 @@ let InboxService = class InboxService {
69
69
  request: r,
70
70
  })),
71
71
  ...attention.map(({ at, ...view }) => ({
72
- type: "schedule_attention",
72
+ type: "automation_attention",
73
73
  id: `${view.taskId}:${view.reason === "missing_grants" ? "grants" : view.reason === "failed" ? "failed" : "paused"}`,
74
74
  createdAt: at.toISOString(),
75
75
  attention: view,
@@ -150,7 +150,7 @@ InboxService = __decorate([
150
150
  __param(1, Inject(SkillChangesService)),
151
151
  __param(2, Inject(KernelDb)),
152
152
  __param(3, Inject(CatalogRequestsService)),
153
- __param(4, Inject(ScheduledTasksService))
153
+ __param(4, Inject(AutomationsService))
154
154
  ], InboxService);
155
155
  export { InboxService };
156
156
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -75,11 +75,16 @@ const HOT_APPLIERS = {
75
75
  "web.fetch.timeoutMs": () => { },
76
76
  // The push fanout reads the preview setting at every fanout.
77
77
  "push.previews": () => { },
78
- // Scheduled-task settings are clamped to these bounds on every read.
79
- "schedules.minIntervalFloorMinutes": () => { },
80
- "schedules.maxTasksPerMemberCap": () => { },
81
- "schedules.maxTasksPerOrgCap": () => { },
82
- "schedules.maxRunsPerHourCap": () => { },
78
+ // Automation settings are clamped to these bounds on every read.
79
+ "automations.minIntervalFloorMinutes": () => { },
80
+ "automations.maxTasksPerMemberCap": () => { },
81
+ "automations.maxTasksPerOrgCap": () => { },
82
+ "automations.maxRunsPerHourCap": () => { },
83
+ "automations.maxEventDepthCap": () => { },
84
+ "automations.coalesceSecondsCap": () => { },
85
+ "automations.maxEventRunsPerSubjectPerHourCap": () => { },
86
+ // The trigger event sweep reads the retention at every tick.
87
+ "automations.eventRetentionDays": () => { },
83
88
  // Run start reads the skills catalog budget when it records a snapshot.
84
89
  "skills.catalogBudgetChars": () => { },
85
90
  // The attribution defaults are read live at every run start, admin settings view and org settings.