@capybara-hq/kernel 0.1.0-rc.106 → 0.1.0-rc.108

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 (190) hide show
  1. package/bootstrap.json +13 -13
  2. package/dist/admin/admin.schemas.d.ts +3 -0
  3. package/dist/catalog/marketplaces.service.d.ts +1 -1
  4. package/dist/channels/channels.module.js +4 -3
  5. package/dist/channels/file-delivery.d.ts +26 -11
  6. package/dist/channels/file-delivery.js +32 -11
  7. package/dist/channels/outbound.d.ts +3 -3
  8. package/dist/channels/outbound.js +15 -13
  9. package/dist/config/schema.d.ts +3 -0
  10. package/dist/config/schema.js +12 -0
  11. package/dist/conversations/artifacts.d.ts +20 -17
  12. package/dist/conversations/artifacts.js +30 -37
  13. package/dist/conversations/attachments.controller.d.ts +6 -19
  14. package/dist/conversations/attachments.controller.js +8 -59
  15. package/dist/conversations/attachments.service.d.ts +30 -74
  16. package/dist/conversations/attachments.service.js +51 -193
  17. package/dist/conversations/conversations.module.js +4 -0
  18. package/dist/conversations/conversations.service.d.ts +10 -9
  19. package/dist/conversations/conversations.service.js +28 -11
  20. package/dist/conversations/event-log.d.ts +1 -0
  21. package/dist/conversations/events.d.ts +49 -27
  22. package/dist/conversations/events.js +54 -7
  23. package/dist/conversations/files.d.ts +66 -64
  24. package/dist/conversations/files.js +127 -147
  25. package/dist/conversations/prompt-suggestion-request.js +2 -1
  26. package/dist/conversations/prompt-suggestions.d.ts +3 -3
  27. package/dist/conversations/prompt-suggestions.js +11 -10
  28. package/dist/conversations/queue.service.js +7 -2
  29. package/dist/ctx/create-ctx.d.ts +3 -1
  30. package/dist/ctx/create-ctx.js +19 -1
  31. package/dist/db/kernel-schema.d.ts +80 -2
  32. package/dist/errors.d.ts +19 -0
  33. package/dist/errors.js +19 -0
  34. package/dist/evals/canonical-json.d.ts +7 -0
  35. package/dist/evals/canonical-json.js +21 -0
  36. package/dist/evals/reconstruct.js +13 -1
  37. package/dist/evals/recorded-tools.d.ts +0 -2
  38. package/dist/evals/recorded-tools.js +1 -16
  39. package/dist/evals/snapshot.d.ts +26 -3
  40. package/dist/evals/snapshot.js +110 -57
  41. package/dist/evals/worker.d.ts +4 -3
  42. package/dist/evals/worker.js +8 -4
  43. package/dist/extensions/host.d.ts +3 -1
  44. package/dist/extensions/host.js +2 -0
  45. package/dist/extensions/instance.d.ts +3 -1
  46. package/dist/extensions/instance.js +4 -0
  47. package/dist/extensions/ledger.d.ts +1 -1
  48. package/dist/files/blob-objects.d.ts +124 -0
  49. package/dist/files/blob-objects.js +341 -0
  50. package/dist/files/blob-sweep.job.d.ts +122 -0
  51. package/dist/files/blob-sweep.job.js +389 -0
  52. package/dist/files/blobs.service.d.ts +135 -0
  53. package/dist/files/blobs.service.js +300 -0
  54. package/dist/files/conversation-media.d.ts +41 -0
  55. package/dist/files/conversation-media.js +124 -0
  56. package/dist/files/deliveries.d.ts +64 -0
  57. package/dist/files/deliveries.js +156 -0
  58. package/dist/files/deliveries.module.d.ts +6 -0
  59. package/dist/files/deliveries.module.js +24 -0
  60. package/dist/files/draft-cleanup.job.d.ts +26 -0
  61. package/dist/files/draft-cleanup.job.js +93 -0
  62. package/dist/files/files.module.d.ts +1 -1
  63. package/dist/files/files.module.js +3 -2
  64. package/dist/files/hash-job.d.ts +127 -0
  65. package/dist/files/hash-job.js +447 -0
  66. package/dist/files/library-backfill.d.ts +63 -0
  67. package/dist/files/library-backfill.js +143 -0
  68. package/dist/files/library-files.service.d.ts +255 -0
  69. package/dist/files/library-files.service.js +883 -0
  70. package/dist/files/library-jobs.module.d.ts +8 -0
  71. package/dist/files/library-jobs.module.js +27 -0
  72. package/dist/files/library-query.d.ts +127 -0
  73. package/dist/files/library-query.js +322 -0
  74. package/dist/files/library-read.module.d.ts +9 -0
  75. package/dist/files/library-read.module.js +30 -0
  76. package/dist/files/library.controller.d.ts +77 -0
  77. package/dist/files/library.controller.js +235 -0
  78. package/dist/files/library.module.d.ts +9 -0
  79. package/dist/files/library.module.js +29 -0
  80. package/dist/files/library.schemas.d.ts +46 -0
  81. package/dist/files/library.schemas.js +49 -0
  82. package/dist/files/previewers.controller.d.ts +20 -0
  83. package/dist/files/previewers.controller.js +47 -0
  84. package/dist/files/previewers.d.ts +25 -11
  85. package/dist/files/previewers.js +43 -27
  86. package/dist/files/referenced-files.d.ts +150 -0
  87. package/dist/files/referenced-files.js +234 -0
  88. package/dist/html/html-document.controller.d.ts +8 -1
  89. package/dist/html/html-document.controller.js +19 -1
  90. package/dist/html/html-document.service.d.ts +19 -4
  91. package/dist/html/html-document.service.js +43 -22
  92. package/dist/html/html-token.d.ts +10 -1
  93. package/dist/html/html-token.js +14 -0
  94. package/dist/html/html.module.js +8 -1
  95. package/dist/http/api.module.js +5 -0
  96. package/dist/identity/settings.d.ts +26 -0
  97. package/dist/identity/settings.js +33 -2
  98. package/dist/infra/outbox/registry.d.ts +82 -0
  99. package/dist/infra/outbox/registry.js +74 -2
  100. package/dist/infra/throttler/named-throttlers.d.ts +2 -0
  101. package/dist/infra/throttler/named-throttlers.js +14 -0
  102. package/dist/lifecycle/kernel-lifecycle.js +6 -0
  103. package/dist/models/purposes.js +1 -1
  104. package/dist/orgs/offboarding.js +1 -1
  105. package/dist/orgs/settings.service.d.ts +48 -2
  106. package/dist/orgs/settings.service.js +63 -3
  107. package/dist/platform/exclusions.js +45 -8
  108. package/dist/platform/file-ref.d.ts +18 -3
  109. package/dist/platform/file-ref.js +22 -11
  110. package/dist/platform/operation.js +4 -0
  111. package/dist/platform/ops/admin.ops.js +5 -2
  112. package/dist/platform/ops/files.ops.d.ts +18 -0
  113. package/dist/platform/ops/files.ops.js +267 -0
  114. package/dist/platform/ops/org-settings.ops.js +6 -2
  115. package/dist/platform/ops/orgs.ops.js +1 -0
  116. package/dist/platform/ops/shares.ops.js +2 -2
  117. package/dist/platform/platform-ops.module.d.ts +2 -1
  118. package/dist/platform/platform-ops.module.js +5 -0
  119. package/dist/platform/route-schemas.js +3 -0
  120. package/dist/roles/worker.module.js +15 -1
  121. package/dist/runtime/compaction-settings.service.d.ts +13 -1
  122. package/dist/runtime/compaction-settings.service.js +16 -1
  123. package/dist/runtime/compaction.service.d.ts +3 -1
  124. package/dist/runtime/compaction.service.js +3 -1
  125. package/dist/runtime/context/build.d.ts +18 -1
  126. package/dist/runtime/context/build.js +19 -8
  127. package/dist/runtime/context/cache-expiry.d.ts +31 -0
  128. package/dist/runtime/context/cache-expiry.js +60 -0
  129. package/dist/runtime/context/cache-ttl.d.ts +18 -0
  130. package/dist/runtime/context/cache-ttl.js +30 -0
  131. package/dist/runtime/context/compaction.d.ts +9 -2
  132. package/dist/runtime/context/compaction.js +50 -17
  133. package/dist/runtime/context/in-context-compaction.d.ts +156 -0
  134. package/dist/runtime/context/in-context-compaction.js +310 -0
  135. package/dist/runtime/hook-calls.d.ts +2 -1
  136. package/dist/runtime/hook-calls.js +5 -2
  137. package/dist/runtime/maintenance.d.ts +10 -2
  138. package/dist/runtime/maintenance.js +48 -8
  139. package/dist/runtime/model-call.d.ts +34 -5
  140. package/dist/runtime/model-call.js +207 -22
  141. package/dist/runtime/providers.js +11 -1
  142. package/dist/runtime/run-steps.d.ts +4 -2
  143. package/dist/runtime/run-steps.js +10 -5
  144. package/dist/runtime/runtime.module.js +3 -0
  145. package/dist/shares/liveness.d.ts +26 -12
  146. package/dist/shares/liveness.js +79 -20
  147. package/dist/shares/revoke.d.ts +16 -11
  148. package/dist/shares/revoke.js +18 -14
  149. package/dist/shares/share-objects.d.ts +16 -21
  150. package/dist/shares/share-objects.js +25 -55
  151. package/dist/shares/share-open.service.d.ts +8 -4
  152. package/dist/shares/share-open.service.js +14 -11
  153. package/dist/shares/shares.controller.d.ts +16 -5
  154. package/dist/shares/shares.controller.js +39 -5
  155. package/dist/shares/shares.module.d.ts +4 -4
  156. package/dist/shares/shares.module.js +7 -6
  157. package/dist/shares/shares.schemas.d.ts +4 -0
  158. package/dist/shares/shares.schemas.js +2 -0
  159. package/dist/shares/shares.service.d.ts +93 -54
  160. package/dist/shares/shares.service.js +292 -131
  161. package/dist/shares/sweep.job.d.ts +18 -39
  162. package/dist/shares/sweep.job.js +47 -206
  163. package/dist/tools/builtins/artifacts.d.ts +21 -13
  164. package/dist/tools/builtins/artifacts.js +81 -51
  165. package/dist/tools/builtins/builtin-tools.d.ts +7 -1
  166. package/dist/tools/builtins/builtin-tools.js +17 -6
  167. package/dist/tools/builtins/conversation-files.d.ts +23 -13
  168. package/dist/tools/builtins/conversation-files.js +62 -83
  169. package/dist/tools/builtins/image/generate.d.ts +7 -1
  170. package/dist/tools/builtins/image/generate.js +1 -1
  171. package/dist/tools/builtins/platform.js +1 -0
  172. package/dist/tools/builtins/sandbox/common.d.ts +6 -2
  173. package/dist/tools/builtins/sandbox/deliver.js +6 -7
  174. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
  175. package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
  176. package/dist/tools/tools.module.js +6 -0
  177. package/dist/ui/call-extension.d.ts +6 -4
  178. package/dist/ui/call-extension.js +5 -4
  179. package/dist/ui/embed-token.js +6 -3
  180. package/dist/ui/registry.d.ts +21 -5
  181. package/dist/ui/registry.js +24 -6
  182. package/dist/ui/ui.schemas.d.ts +22 -0
  183. package/dist/ui/ui.schemas.js +22 -4
  184. package/dist/ui/views.controller.d.ts +13 -3
  185. package/dist/ui/views.controller.js +33 -2
  186. package/dist/ui/views.d.ts +29 -1
  187. package/dist/ui/views.js +131 -7
  188. package/package.json +3 -3
  189. package/src/migrations/0190_file_library.sql +285 -0
  190. package/src/migrations/0191_file_library_copy.sql +4 -0
@@ -257,6 +257,14 @@ export declare const PermissionContextMetaV1Schema: z.ZodObject<{
257
257
  sandbox: z.ZodOptional<z.ZodString>;
258
258
  }, z.core.$strict>;
259
259
  export type PermissionContextMetaV1 = z.infer<typeof PermissionContextMetaV1Schema>;
260
+ /**
261
+ * The file id a logged media ref names. Events are validated on write but read back as stored, so
262
+ * a block logged before the rename still carries the same id as `attachmentId`; every reader of a
263
+ * stored ref takes the id through here.
264
+ */
265
+ export declare function refFileId(source: Extract<MediaSource, {
266
+ kind: "ref";
267
+ }>): string;
260
268
  /** The most hosts one network ask (and one `network_blocked` event) lists. */
261
269
  export declare const NETWORK_ASK_MAX_HOSTS = 20;
262
270
  /** The longest host name a network ask or `network_blocked` event carries. */
@@ -446,10 +454,10 @@ export declare const ContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
446
454
  "image/png": "image/png";
447
455
  "image/webp": "image/webp";
448
456
  }>;
449
- source: z.ZodObject<{
457
+ source: z.ZodPreprocess<z.ZodObject<{
450
458
  kind: z.ZodLiteral<"ref">;
451
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
452
- }, z.core.$strip>;
459
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
460
+ }, z.core.$strip>, unknown>;
453
461
  name: z.ZodOptional<z.ZodString>;
454
462
  size: z.ZodOptional<z.ZodNumber>;
455
463
  }, z.core.$strip>, z.ZodObject<{
@@ -460,19 +468,19 @@ export declare const ContentBlockSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
460
468
  "text/markdown": "text/markdown";
461
469
  "text/plain": "text/plain";
462
470
  }>;
463
- source: z.ZodObject<{
471
+ source: z.ZodPreprocess<z.ZodObject<{
464
472
  kind: z.ZodLiteral<"ref">;
465
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
466
- }, z.core.$strip>;
473
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
474
+ }, z.core.$strip>, unknown>;
467
475
  name: z.ZodOptional<z.ZodString>;
468
476
  size: z.ZodOptional<z.ZodNumber>;
469
477
  }, z.core.$strip>, z.ZodObject<{
470
478
  type: z.ZodLiteral<"file">;
471
479
  mediaType: z.ZodString;
472
- source: z.ZodObject<{
480
+ source: z.ZodPreprocess<z.ZodObject<{
473
481
  kind: z.ZodLiteral<"ref">;
474
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
475
- }, z.core.$strip>;
482
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
483
+ }, z.core.$strip>, unknown>;
476
484
  name: z.ZodOptional<z.ZodString>;
477
485
  size: z.ZodOptional<z.ZodNumber>;
478
486
  }, z.core.$strip>], "type">;
@@ -922,10 +930,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
922
930
  "image/png": "image/png";
923
931
  "image/webp": "image/webp";
924
932
  }>;
925
- source: z.ZodObject<{
933
+ source: z.ZodPreprocess<z.ZodObject<{
926
934
  kind: z.ZodLiteral<"ref">;
927
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
928
- }, z.core.$strip>;
935
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
936
+ }, z.core.$strip>, unknown>;
929
937
  name: z.ZodOptional<z.ZodString>;
930
938
  size: z.ZodOptional<z.ZodNumber>;
931
939
  }, z.core.$strip>, z.ZodObject<{
@@ -936,19 +944,19 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
936
944
  "text/markdown": "text/markdown";
937
945
  "text/plain": "text/plain";
938
946
  }>;
939
- source: z.ZodObject<{
947
+ source: z.ZodPreprocess<z.ZodObject<{
940
948
  kind: z.ZodLiteral<"ref">;
941
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
942
- }, z.core.$strip>;
949
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
950
+ }, z.core.$strip>, unknown>;
943
951
  name: z.ZodOptional<z.ZodString>;
944
952
  size: z.ZodOptional<z.ZodNumber>;
945
953
  }, z.core.$strip>, z.ZodObject<{
946
954
  type: z.ZodLiteral<"file">;
947
955
  mediaType: z.ZodString;
948
- source: z.ZodObject<{
956
+ source: z.ZodPreprocess<z.ZodObject<{
949
957
  kind: z.ZodLiteral<"ref">;
950
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
951
- }, z.core.$strip>;
958
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
959
+ }, z.core.$strip>, unknown>;
952
960
  name: z.ZodOptional<z.ZodString>;
953
961
  size: z.ZodOptional<z.ZodNumber>;
954
962
  }, z.core.$strip>], "type">>;
@@ -1133,6 +1141,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1133
1141
  auto: "auto";
1134
1142
  none: "none";
1135
1143
  }>>;
1144
+ cacheTtl: z.ZodOptional<z.ZodNumber>;
1136
1145
  media: z.ZodOptional<z.ZodArray<z.ZodObject<{
1137
1146
  attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
1138
1147
  outcome: z.ZodEnum<{
@@ -1205,10 +1214,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1205
1214
  "image/png": "image/png";
1206
1215
  "image/webp": "image/webp";
1207
1216
  }>;
1208
- source: z.ZodObject<{
1217
+ source: z.ZodPreprocess<z.ZodObject<{
1209
1218
  kind: z.ZodLiteral<"ref">;
1210
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
1211
- }, z.core.$strip>;
1219
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
1220
+ }, z.core.$strip>, unknown>;
1212
1221
  name: z.ZodOptional<z.ZodString>;
1213
1222
  size: z.ZodOptional<z.ZodNumber>;
1214
1223
  }, z.core.$strip>, z.ZodObject<{
@@ -1219,19 +1228,19 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1219
1228
  "text/markdown": "text/markdown";
1220
1229
  "text/plain": "text/plain";
1221
1230
  }>;
1222
- source: z.ZodObject<{
1231
+ source: z.ZodPreprocess<z.ZodObject<{
1223
1232
  kind: z.ZodLiteral<"ref">;
1224
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
1225
- }, z.core.$strip>;
1233
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
1234
+ }, z.core.$strip>, unknown>;
1226
1235
  name: z.ZodOptional<z.ZodString>;
1227
1236
  size: z.ZodOptional<z.ZodNumber>;
1228
1237
  }, z.core.$strip>, z.ZodObject<{
1229
1238
  type: z.ZodLiteral<"file">;
1230
1239
  mediaType: z.ZodString;
1231
- source: z.ZodObject<{
1240
+ source: z.ZodPreprocess<z.ZodObject<{
1232
1241
  kind: z.ZodLiteral<"ref">;
1233
- attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
1234
- }, z.core.$strip>;
1242
+ fileId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
1243
+ }, z.core.$strip>, unknown>;
1235
1244
  name: z.ZodOptional<z.ZodString>;
1236
1245
  size: z.ZodOptional<z.ZodNumber>;
1237
1246
  }, z.core.$strip>], "type">>;
@@ -1252,6 +1261,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1252
1261
  cacheReadTokens: z.ZodNumber;
1253
1262
  cacheWriteTokens: z.ZodNumber;
1254
1263
  outputImages: z.ZodExactOptional<z.ZodNumber>;
1264
+ cacheWriteByTtl: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
1265
+ ttl: z.ZodNumber;
1266
+ tokens: z.ZodNumber;
1267
+ }, z.core.$strip>>>;
1255
1268
  step: z.ZodNumber;
1256
1269
  provider: z.ZodString;
1257
1270
  model: z.ZodString;
@@ -1734,6 +1747,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
1734
1747
  type: z.ZodLiteral<"artifact_created">;
1735
1748
  payload: z.ZodObject<{
1736
1749
  artifactId: z.ZodUUID;
1750
+ fileId: z.ZodOptional<z.ZodUUID>;
1737
1751
  name: z.ZodString;
1738
1752
  contentType: z.ZodString;
1739
1753
  size: z.ZodNumber;
@@ -2018,6 +2032,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
2018
2032
  cacheReadTokens: z.ZodNumber;
2019
2033
  cacheWriteTokens: z.ZodNumber;
2020
2034
  outputImages: z.ZodExactOptional<z.ZodNumber>;
2035
+ cacheWriteByTtl: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
2036
+ ttl: z.ZodNumber;
2037
+ tokens: z.ZodNumber;
2038
+ }, z.core.$strip>>>;
2021
2039
  }, z.core.$strip>;
2022
2040
  }, z.core.$strip>;
2023
2041
  }, z.core.$strip>, z.ZodObject<{
@@ -2089,6 +2107,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
2089
2107
  text: z.ZodString;
2090
2108
  savedTokens: z.ZodNumber;
2091
2109
  openingSeqs: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
2110
+ method: z.ZodOptional<z.ZodEnum<{
2111
+ in_context: "in_context";
2112
+ transcript: "transcript";
2113
+ }>>;
2092
2114
  step: z.ZodNumber;
2093
2115
  }, z.core.$strip>;
2094
2116
  }, z.core.$strip>, z.ZodObject<{
@@ -1,5 +1,5 @@
1
1
  import { posix } from "node:path";
2
- import { CARD_BADGE_MAX, CARD_TEXT_MAX, CONTEXT_LIMITS, DOCUMENT_MEDIA_TYPES, hasControlChars, IMAGE_MEDIA_TYPES, isAttachmentId, isSkillName, MEDIA_NAME_MAX_CHARS, validateAllowHost, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
2
+ import { CARD_BADGE_MAX, CARD_TEXT_MAX, CONTEXT_LIMITS, DOCUMENT_MEDIA_TYPES, hasControlChars, IMAGE_MEDIA_TYPES, isAttachmentId, isFileId, isSkillName, MEDIA_NAME_MAX_CHARS, validateAllowHost, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
3
3
  import { z } from "zod";
4
4
  import { AgentDefinitionSchema, DisabledSkillRef, DisabledToolRef, ModelRef, } from "../agents/definition.js";
5
5
  import { ORG_ROLES } from "../orgs/roles.js";
@@ -314,15 +314,37 @@ const ProviderOpaqueSchema = z.object({
314
314
  model: z.string(),
315
315
  data: z.unknown(),
316
316
  });
317
+ const AttachmentIdSchema = z.string().refine(isAttachmentId, "attachmentId must be a UUID");
317
318
  /**
318
- * 日志里的媒体来源:只有附件引用。字节(`base64`)绝不进事件日志——日志是事实源、字节不是;
319
- * 构建模型请求时内核按 `attachmentId` 取字节换成 `base64`(见 {@link LogContentBlock})。
319
+ * A media source in the log is only a file reference. Bytes (`base64`) never enter the event log:
320
+ * the log is the source of truth, bytes are not; request building fetches the bytes by `fileId`
321
+ * and swaps in `base64` (see {@link LogContentBlock}).
322
+ *
323
+ * Blocks logged before the file library name the same id `attachmentId`: parsing accepts that key
324
+ * as an alias of `fileId` (the stored JSON is never rewritten, so readers of stored payloads go
325
+ * through {@link refFileId}).
320
326
  */
321
- const AttachmentIdSchema = z.string().refine(isAttachmentId, "attachmentId must be a UUID");
322
- const RefMediaSourceSchema = z.object({
327
+ const RefMediaSourceSchema = z.preprocess((v) => {
328
+ if (v === null || typeof v !== "object" || Array.isArray(v))
329
+ return v;
330
+ const o = v;
331
+ if (o.fileId !== undefined || !Object.hasOwn(o, "attachmentId"))
332
+ return v;
333
+ const { attachmentId, ...rest } = o;
334
+ return { ...rest, fileId: attachmentId };
335
+ }, z.object({
323
336
  kind: z.literal("ref"),
324
- attachmentId: AttachmentIdSchema,
325
- });
337
+ fileId: z.string().refine(isFileId, "fileId must be a UUID"),
338
+ }));
339
+ /**
340
+ * The file id a logged media ref names. Events are validated on write but read back as stored, so
341
+ * a block logged before the rename still carries the same id as `attachmentId`; every reader of a
342
+ * stored ref takes the id through here.
343
+ */
344
+ export function refFileId(source) {
345
+ const s = source;
346
+ return (s.fileId ?? s.attachmentId);
347
+ }
326
348
  /**
327
349
  * Who may decide an approval, as the approval row says (display only): the assigned account
328
350
  * (`requestedFor`), else the escalation role (`approverRole`). Pages word the waiting state with it
@@ -650,6 +672,11 @@ const ModelUsageShape = {
650
672
  cacheWriteTokens: count,
651
673
  /** Images produced (an image generation call). */
652
674
  outputImages: count.exactOptional(),
675
+ /**
676
+ * Cache writes per lifetime tier (`ttl` seconds), as the provider reported them; sums to
677
+ * `cacheWriteTokens`. Absent when the provider reported no breakdown.
678
+ */
679
+ cacheWriteByTtl: z.array(z.object({ ttl: count, tokens: count })).exactOptional(),
653
680
  };
654
681
  /**
655
682
  * How a sub-agent's run ended (`subagent_finished`, a `subagent_delivery` finish). `timed_out`:
@@ -1077,6 +1104,13 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1077
1104
  * themselves are in `capybara.tool_specs` by specHash.
1078
1105
  */
1079
1106
  toolChoice: z.enum(["auto", "none"]).optional(),
1107
+ /**
1108
+ * The prompt cache lifetime the request asked for (`ModelRequest.cacheTtl`, seconds: one
1109
+ * of the model's `ttlOptions`, chosen from `promptCache.longTtl`); absent when it named
1110
+ * none (the model's default). A transport option, not model-visible: no DriftReason
1111
+ * (idle compaction spec §9.2).
1112
+ */
1113
+ cacheTtl: count.optional(),
1080
1114
  /**
1081
1115
  * What became of each attachment in the request (Ruling M8, in first-seen order, one
1082
1116
  * entry per attachment): bytes sent (`bytes`, with the etag at finalize), inline text, a
@@ -1536,6 +1570,11 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1536
1570
  */
1537
1571
  ev("artifact_created", z.object({
1538
1572
  artifactId: z.uuid(),
1573
+ /**
1574
+ * The library file the delivery created (file library spec §4): the artifact id itself.
1575
+ * Optional because earlier events lack it (their file, migrated, kept the artifact id).
1576
+ */
1577
+ fileId: z.uuid().optional(),
1539
1578
  name: ArtifactNameSchema,
1540
1579
  contentType: z.string().min(1).max(200),
1541
1580
  size: z.number().int().nonnegative(),
@@ -1826,6 +1865,14 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
1826
1865
  * (nothing re-rendered).
1827
1866
  */
1828
1867
  openingSeqs: z.array(seqNo).optional(),
1868
+ /**
1869
+ * How the summary was written (idle compaction spec §9.4): `in_context` from the
1870
+ * conversation's last request rebuilt with the summary instruction appended (its cached
1871
+ * prefix), `transcript` from the plan's transcript. Not model-visible itself: only the
1872
+ * framing sentence after the summary reads it (context compaction spec §4.2.2), derived from
1873
+ * the log, so no `DriftReason`. Absent on summaries written before it (read as `transcript`).
1874
+ */
1875
+ method: z.enum(["transcript", "in_context"]).optional(),
1829
1876
  /**
1830
1877
  * The step the compaction ran in (0 for a manual compact run), so a later compaction in the
1831
1878
  * same step takes the next idempotency key.
@@ -1,13 +1,14 @@
1
+ import type { BlobRef } from "../files/blobs.service.js";
2
+ import { ReferencedFiles } from "../files/referenced-files.js";
1
3
  import { KernelDb } from "../infra/database/kernel-db.js";
2
- import { StorageService } from "../storage/storage.service.js";
3
4
  import { ConversationAccess } from "./access.js";
4
- import { AttachmentsService } from "./attachments.service.js";
5
5
  /**
6
- * A conversation's files (UI refresh B, spec §5.8 / §5.9): the files the agent delivered
7
- * (`artifact_created`), grouped by `sourcePath` into versions, and the files users sent in it
8
- * (ready `chat` attachments bound to the conversation), newest first. Read on every request (no
9
- * cache); `status` comes from the object store. Both kinds are read under the conversation's
10
- * access: whoever may read the conversation may read the attachments sent in it, nobody else.
6
+ * A conversation's files (UI refresh B, spec §5.8 / §5.9; file library spec §2): the library files
7
+ * the conversation refers to (`conversation_files`). Files an agent delivered or generated are
8
+ * grouped by `source_path` into versions; files a person uploaded are listed one by one; newest
9
+ * first. Read on every request (no cache); `status` comes from the file and its blob (a deleted
10
+ * file, or a blob gone or replaced, is `removed`). Everything is read under the conversation's
11
+ * access: whoever may read the conversation may read the files it refers to, nobody else.
11
12
  */
12
13
  /** Versions listed per file (newest first). */
13
14
  export declare const FILE_VERSIONS_MAX = 20;
@@ -16,7 +17,7 @@ export declare const FILES_PAGE_MAX = 100;
16
17
  /** Largest `limit` (bytes) of the text content route. */
17
18
  export declare const FILE_CONTENT_MAX_BYTES: number;
18
19
  export interface FileOutput {
19
- /** artifactId of the latest version. */
20
+ /** The file id of the latest version (an artifact id for a delivery). */
20
21
  id: string;
21
22
  name: string;
22
23
  contentType: string;
@@ -32,18 +33,18 @@ export interface FileOutput {
32
33
  }[];
33
34
  callId: string;
34
35
  createdAt: Date;
35
- /** `removed`: the latest version's object is gone from storage (decision 8). */
36
+ /** `removed`: the latest version's file was deleted or its bytes are gone (decision 8). */
36
37
  status: "available" | "removed";
37
38
  previewable: "image" | "text" | null;
38
39
  /**
39
- * `delivered`: the agent delivered it (`artifact_created`); `uploaded`: a user sent it with a
40
- * message (an attachment: `id` is the attachment id, one version, `sourcePath` is its name and
41
- * `callId` is empty).
40
+ * `delivered`: an agent delivered or generated it (`artifact_created`); `uploaded`: a person
41
+ * uploaded it and sent it with a message (one version, `sourcePath` is its name and `callId` is
42
+ * empty).
42
43
  */
43
44
  origin: "delivered" | "uploaded";
44
45
  /**
45
46
  * The viewer has a share of this file that is not revoked or expired (file sharing spec §5): of
46
- * its source path for a delivered file (any version), of the attachment for an uploaded one.
47
+ * its source path for a delivered file (any version), of the file for an uploaded one.
47
48
  */
48
49
  shared: boolean;
49
50
  }
@@ -59,6 +60,24 @@ export interface FileContent {
59
60
  originalType: string;
60
61
  truncated: boolean;
61
62
  }
63
+ /** One readable file version of the conversation, for the kernel only (the key never leaves it). */
64
+ export interface ResolvedConversationFile {
65
+ id: string;
66
+ name: string;
67
+ contentType: string;
68
+ size: number;
69
+ /** The blob's key (relative to the org's kernel prefix). */
70
+ objectKey: string;
71
+ /** The version group of a delivered file; null for an upload. */
72
+ sourcePath: string | null;
73
+ /** What a later read of the object must still match (`blobContentMatches`). */
74
+ recorded: {
75
+ size: number;
76
+ etag: string | null;
77
+ };
78
+ /** The blob, for `BlobsService.open` / `head`. */
79
+ blob: BlobRef;
80
+ }
62
81
  /** The built-in preview kind of a content type (the files list's `previewable`; share metadata too). */
63
82
  export declare const previewKind: (contentType: string) => FileOutput["previewable"];
64
83
  /** Drops an incomplete UTF-8 sequence at the end of a cut buffer. */
@@ -69,31 +88,31 @@ export declare function readPrefix(body: ReadableStream<Uint8Array>, max: number
69
88
  export declare const HEAD_CONCURRENCY = 8;
70
89
  export declare class ConversationFiles {
71
90
  private readonly db;
72
- private readonly storage;
73
91
  /** Same visibility as the event stream. */
74
92
  private readonly access;
75
- /** The attachments sent in the conversation, and the rule their stored content must meet. */
76
- private readonly attachments;
77
- constructor(db: KernelDb, storage: Pick<StorageService, "kernel">,
93
+ /** The files the conversation refers to, and their bytes (size and etag checked). */
94
+ private readonly files;
95
+ constructor(db: KernelDb,
78
96
  /** Same visibility as the event stream. */
79
97
  access: Pick<ConversationAccess, "isAccessible">,
80
- /** The attachments sent in the conversation, and the rule their stored content must meet. */
81
- attachments: Pick<AttachmentsService, "boundRows" | "storedMatches">);
98
+ /** The files the conversation refers to, and their bytes (size and etag checked). */
99
+ files: Pick<ReferencedFiles, "references" | "open" | "head">);
82
100
  private checkAccess;
83
- /** Every delivery of the conversation in log order. */
84
- private deliveries;
101
+ /** Whether a reference can be read now: live, and its stored head still the recorded bytes. */
102
+ private available;
85
103
  /**
86
- * One file of the conversation by id: a delivered version first, then an attachment sent in it;
87
- * neither → `conversation.artifact_not_found`. An attachment carries `upload`, the row its stored
88
- * object must still match. Call after {@link checkAccess}.
104
+ * One file the conversation refers to by id (any status: a deleted file still resolves, so its
105
+ * shares are found); none → `conversation.artifact_not_found`. Call after {@link checkAccess}.
89
106
  */
90
107
  private resolve;
108
+ /** The tool call of each delivery logged in the conversation, by artifact (= file) id. */
109
+ private callIds;
91
110
  /**
92
111
  * Files newest first: a delivered file by its **first** delivery, so a new version keeps the
93
112
  * file's place and a cursor stays stable while files are re-delivered (review M2); an uploaded
94
- * file by its upload time; equal times by id. `after` is a file id from the previous page (any
95
- * version's id finds its file); a cursor that names no file gives an empty page. Storage HEADs run
96
- * at most {@link HEAD_CONCURRENCY} at a time.
113
+ * file by when the conversation started referring to it; equal times by id. `after` is a file id
114
+ * from the previous page (any version's id finds its file); a cursor that names no file gives an
115
+ * empty page. Storage HEADs run at most {@link HEAD_CONCURRENCY} at a time.
97
116
  */
98
117
  list(orgId: string, conversationId: string, viewer: string, opts: {
99
118
  after?: string;
@@ -103,29 +122,17 @@ export declare class ConversationFiles {
103
122
  next: string | null;
104
123
  }>;
105
124
  /**
106
- * One file version of the conversation (any version's id, or an attachment sent in it) with its
107
- * object key, after checking the viewer can read the conversation. For the kernel only
108
- * (previewers, embed grants): the key never leaves the kernel. An attachment whose stored object
109
- * is gone or no longer the one finalize checked → `conversation.artifact_removed`; `recorded` is
110
- * then what a later read of the object must still match ({@link attachmentContentMatches}).
111
- * `sourcePath` is the version group of a delivered file, null for an attachment.
125
+ * One file version of the conversation (any version's id, or an upload sent in it) with its
126
+ * blob, after checking the viewer can read the conversation. For the kernel only (previewers,
127
+ * embed grants, documents): the key never leaves the kernel. A deleted file, or a blob gone or no
128
+ * longer the recorded bytes → `conversation.artifact_removed`; `recorded` is what a later read of
129
+ * the object must still match. `sourcePath` is the version group of a delivered file, null for
130
+ * an upload.
112
131
  */
113
- file(orgId: string, conversationId: string, viewer: string, fileId: string): Promise<{
114
- id: string;
115
- name: string;
116
- contentType: string;
117
- size: number;
118
- objectKey: string;
119
- /** The version group of a delivered file; null for an attachment. */
120
- sourcePath: string | null;
121
- recorded?: {
122
- size: number;
123
- etag: string | null;
124
- };
125
- }>;
132
+ file(orgId: string, conversationId: string, viewer: string, fileId: string): Promise<ResolvedConversationFile>;
126
133
  /**
127
- * Which file a file id names (any version's id, or an attachment sent in the conversation), after
128
- * checking the viewer can read the conversation; storage is not read, so a removed file still
134
+ * Which file a file id names (any version's id, or an upload sent in the conversation), after
135
+ * checking the viewer can read the conversation; storage is not read, and a deleted file still
129
136
  * resolves (its shares are listed and revoked by it).
130
137
  */
131
138
  identify(orgId: string, conversationId: string, viewer: string, fileId: string): Promise<{
@@ -133,30 +140,25 @@ export declare class ConversationFiles {
133
140
  sourcePath: string | null;
134
141
  }>;
135
142
  /**
136
- * The newest delivered version of `sourcePath` whose object is still stored, after checking the
137
- * viewer can read the conversation (a share's "update to latest", file sharing spec §2); with
138
- * `after` (a version id), only versions delivered after it. Versions whose object is gone are
139
- * skipped; at most {@link FILE_VERSIONS_MAX} are looked at. Null when none is available.
143
+ * The newest delivered version of `sourcePath` the conversation refers to that is still
144
+ * readable, after checking the viewer can read the conversation (a share's "update to latest",
145
+ * file sharing spec §2); with `after` (a version id), only versions delivered after it. Versions
146
+ * deleted or whose bytes are gone are skipped; at most {@link FILE_VERSIONS_MAX} are looked at.
147
+ * Null when none is available.
140
148
  */
141
149
  latestAvailable(orgId: string, conversationId: string, viewer: string, sourcePath: string, opts?: {
142
150
  after?: string;
143
- }): Promise<{
144
- id: string;
145
- name: string;
146
- contentType: string;
147
- size: number;
148
- objectKey: string;
149
- } | null>;
151
+ }): Promise<ResolvedConversationFile | null>;
150
152
  /**
151
- * The source paths and attachments the viewer has a share of in the conversation that is not
153
+ * The source paths and uploads the viewer has a share of in the conversation that is not
152
154
  * revoked or expired ({@link FileOutput.shared}).
153
155
  */
154
156
  private viewerShares;
155
157
  /**
156
- * The first `limit` bytes of a text file version (any version's id, or an attachment sent in the
157
- * conversation). Not text, or NUL bytes in
158
- * what was read → `conversation.artifact_not_previewable`; the object is gone →
159
- * `conversation.artifact_removed`. A cut never splits a UTF-8 character.
158
+ * The first `limit` bytes of a text file version (any version's id, or an upload sent in the
159
+ * conversation). Not text, or NUL bytes in what was read → `conversation.artifact_not_previewable`;
160
+ * the file deleted or its bytes gone → `conversation.artifact_removed`. A cut never splits a
161
+ * UTF-8 character.
160
162
  */
161
163
  content(orgId: string, conversationId: string, viewer: string, fileId: string, limit: number): Promise<FileContent>;
162
164
  }