@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.
- package/bootstrap.json +13 -13
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +4 -3
- package/dist/channels/file-delivery.d.ts +26 -11
- package/dist/channels/file-delivery.js +32 -11
- package/dist/channels/outbound.d.ts +3 -3
- package/dist/channels/outbound.js +15 -13
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.js +12 -0
- package/dist/conversations/artifacts.d.ts +20 -17
- package/dist/conversations/artifacts.js +30 -37
- package/dist/conversations/attachments.controller.d.ts +6 -19
- package/dist/conversations/attachments.controller.js +8 -59
- package/dist/conversations/attachments.service.d.ts +30 -74
- package/dist/conversations/attachments.service.js +51 -193
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/conversations.service.d.ts +10 -9
- package/dist/conversations/conversations.service.js +28 -11
- package/dist/conversations/event-log.d.ts +1 -0
- package/dist/conversations/events.d.ts +49 -27
- package/dist/conversations/events.js +54 -7
- package/dist/conversations/files.d.ts +66 -64
- package/dist/conversations/files.js +127 -147
- package/dist/conversations/prompt-suggestion-request.js +2 -1
- package/dist/conversations/prompt-suggestions.d.ts +3 -3
- package/dist/conversations/prompt-suggestions.js +11 -10
- package/dist/conversations/queue.service.js +7 -2
- package/dist/ctx/create-ctx.d.ts +3 -1
- package/dist/ctx/create-ctx.js +19 -1
- package/dist/db/kernel-schema.d.ts +80 -2
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/reconstruct.js +13 -1
- package/dist/evals/recorded-tools.d.ts +0 -2
- package/dist/evals/recorded-tools.js +1 -16
- package/dist/evals/snapshot.d.ts +26 -3
- package/dist/evals/snapshot.js +110 -57
- package/dist/evals/worker.d.ts +4 -3
- package/dist/evals/worker.js +8 -4
- package/dist/extensions/host.d.ts +3 -1
- package/dist/extensions/host.js +2 -0
- package/dist/extensions/instance.d.ts +3 -1
- package/dist/extensions/instance.js +4 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/files/blob-objects.d.ts +124 -0
- package/dist/files/blob-objects.js +341 -0
- package/dist/files/blob-sweep.job.d.ts +122 -0
- package/dist/files/blob-sweep.job.js +389 -0
- package/dist/files/blobs.service.d.ts +135 -0
- package/dist/files/blobs.service.js +300 -0
- package/dist/files/conversation-media.d.ts +41 -0
- package/dist/files/conversation-media.js +124 -0
- package/dist/files/deliveries.d.ts +64 -0
- package/dist/files/deliveries.js +156 -0
- package/dist/files/deliveries.module.d.ts +6 -0
- package/dist/files/deliveries.module.js +24 -0
- package/dist/files/draft-cleanup.job.d.ts +26 -0
- package/dist/files/draft-cleanup.job.js +93 -0
- package/dist/files/files.module.d.ts +1 -1
- package/dist/files/files.module.js +3 -2
- package/dist/files/hash-job.d.ts +127 -0
- package/dist/files/hash-job.js +447 -0
- package/dist/files/library-backfill.d.ts +63 -0
- package/dist/files/library-backfill.js +143 -0
- package/dist/files/library-files.service.d.ts +255 -0
- package/dist/files/library-files.service.js +883 -0
- package/dist/files/library-jobs.module.d.ts +8 -0
- package/dist/files/library-jobs.module.js +27 -0
- package/dist/files/library-query.d.ts +127 -0
- package/dist/files/library-query.js +322 -0
- package/dist/files/library-read.module.d.ts +9 -0
- package/dist/files/library-read.module.js +30 -0
- package/dist/files/library.controller.d.ts +77 -0
- package/dist/files/library.controller.js +235 -0
- package/dist/files/library.module.d.ts +9 -0
- package/dist/files/library.module.js +29 -0
- package/dist/files/library.schemas.d.ts +46 -0
- package/dist/files/library.schemas.js +49 -0
- package/dist/files/previewers.controller.d.ts +20 -0
- package/dist/files/previewers.controller.js +47 -0
- package/dist/files/previewers.d.ts +25 -11
- package/dist/files/previewers.js +43 -27
- package/dist/files/referenced-files.d.ts +150 -0
- package/dist/files/referenced-files.js +234 -0
- package/dist/html/html-document.controller.d.ts +8 -1
- package/dist/html/html-document.controller.js +19 -1
- package/dist/html/html-document.service.d.ts +19 -4
- package/dist/html/html-document.service.js +43 -22
- package/dist/html/html-token.d.ts +10 -1
- package/dist/html/html-token.js +14 -0
- package/dist/html/html.module.js +8 -1
- package/dist/http/api.module.js +5 -0
- package/dist/identity/settings.d.ts +26 -0
- package/dist/identity/settings.js +33 -2
- package/dist/infra/outbox/registry.d.ts +82 -0
- package/dist/infra/outbox/registry.js +74 -2
- package/dist/infra/throttler/named-throttlers.d.ts +2 -0
- package/dist/infra/throttler/named-throttlers.js +14 -0
- package/dist/lifecycle/kernel-lifecycle.js +6 -0
- package/dist/models/purposes.js +1 -1
- package/dist/orgs/offboarding.js +1 -1
- package/dist/orgs/settings.service.d.ts +48 -2
- package/dist/orgs/settings.service.js +63 -3
- package/dist/platform/exclusions.js +45 -8
- package/dist/platform/file-ref.d.ts +18 -3
- package/dist/platform/file-ref.js +22 -11
- package/dist/platform/operation.js +4 -0
- package/dist/platform/ops/admin.ops.js +5 -2
- package/dist/platform/ops/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/org-settings.ops.js +6 -2
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/shares.ops.js +2 -2
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +5 -0
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker.module.js +15 -1
- package/dist/runtime/compaction-settings.service.d.ts +13 -1
- package/dist/runtime/compaction-settings.service.js +16 -1
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +18 -1
- package/dist/runtime/context/build.js +19 -8
- package/dist/runtime/context/cache-expiry.d.ts +31 -0
- package/dist/runtime/context/cache-expiry.js +60 -0
- package/dist/runtime/context/cache-ttl.d.ts +18 -0
- package/dist/runtime/context/cache-ttl.js +30 -0
- package/dist/runtime/context/compaction.d.ts +9 -2
- package/dist/runtime/context/compaction.js +50 -17
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/hook-calls.d.ts +2 -1
- package/dist/runtime/hook-calls.js +5 -2
- package/dist/runtime/maintenance.d.ts +10 -2
- package/dist/runtime/maintenance.js +48 -8
- package/dist/runtime/model-call.d.ts +34 -5
- package/dist/runtime/model-call.js +207 -22
- package/dist/runtime/providers.js +11 -1
- package/dist/runtime/run-steps.d.ts +4 -2
- package/dist/runtime/run-steps.js +10 -5
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/shares/liveness.d.ts +26 -12
- package/dist/shares/liveness.js +79 -20
- package/dist/shares/revoke.d.ts +16 -11
- package/dist/shares/revoke.js +18 -14
- package/dist/shares/share-objects.d.ts +16 -21
- package/dist/shares/share-objects.js +25 -55
- package/dist/shares/share-open.service.d.ts +8 -4
- package/dist/shares/share-open.service.js +14 -11
- package/dist/shares/shares.controller.d.ts +16 -5
- package/dist/shares/shares.controller.js +39 -5
- package/dist/shares/shares.module.d.ts +4 -4
- package/dist/shares/shares.module.js +7 -6
- package/dist/shares/shares.schemas.d.ts +4 -0
- package/dist/shares/shares.schemas.js +2 -0
- package/dist/shares/shares.service.d.ts +93 -54
- package/dist/shares/shares.service.js +292 -131
- package/dist/shares/sweep.job.d.ts +18 -39
- package/dist/shares/sweep.job.js +47 -206
- package/dist/tools/builtins/artifacts.d.ts +21 -13
- package/dist/tools/builtins/artifacts.js +81 -51
- package/dist/tools/builtins/builtin-tools.d.ts +7 -1
- package/dist/tools/builtins/builtin-tools.js +17 -6
- package/dist/tools/builtins/conversation-files.d.ts +23 -13
- package/dist/tools/builtins/conversation-files.js +62 -83
- package/dist/tools/builtins/image/generate.d.ts +7 -1
- package/dist/tools/builtins/image/generate.js +1 -1
- package/dist/tools/builtins/platform.js +1 -0
- package/dist/tools/builtins/sandbox/common.d.ts +6 -2
- package/dist/tools/builtins/sandbox/deliver.js +6 -7
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
- package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
- package/dist/tools/tools.module.js +6 -0
- package/dist/ui/call-extension.d.ts +6 -4
- package/dist/ui/call-extension.js +5 -4
- package/dist/ui/embed-token.js +6 -3
- package/dist/ui/registry.d.ts +21 -5
- package/dist/ui/registry.js +24 -6
- package/dist/ui/ui.schemas.d.ts +22 -0
- package/dist/ui/ui.schemas.js +22 -4
- package/dist/ui/views.controller.d.ts +13 -3
- package/dist/ui/views.controller.js +33 -2
- package/dist/ui/views.d.ts +29 -1
- package/dist/ui/views.js +131 -7
- package/package.json +3 -3
- package/src/migrations/0190_file_library.sql +285 -0
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
319
|
-
*
|
|
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
|
|
322
|
-
|
|
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
|
-
|
|
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
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* cache); `status` comes from the
|
|
10
|
-
*
|
|
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
|
-
/**
|
|
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
|
|
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`:
|
|
40
|
-
*
|
|
41
|
-
*
|
|
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
|
|
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
|
|
76
|
-
private readonly
|
|
77
|
-
constructor(db: KernelDb,
|
|
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
|
|
81
|
-
|
|
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
|
-
/**
|
|
84
|
-
private
|
|
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
|
|
87
|
-
*
|
|
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
|
|
95
|
-
* version's id finds its file); a cursor that names no file gives an
|
|
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
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
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
|
|
128
|
-
* checking the viewer can read the conversation; storage is not read,
|
|
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`
|
|
137
|
-
* viewer can read the conversation (a share's "update to latest",
|
|
138
|
-
* `after` (a version id), only versions delivered after it. Versions
|
|
139
|
-
* skipped; at most {@link FILE_VERSIONS_MAX} are looked at.
|
|
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
|
|
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
|
|
157
|
-
* conversation). Not text, or NUL bytes in
|
|
158
|
-
*
|
|
159
|
-
*
|
|
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
|
}
|