@bli-cockpit/telemetry-core 0.1.43 → 0.1.44
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.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** In-object manifest. Legacy objects without this exact prefix remain raw. */
|
|
2
|
+
export declare const EVIDENCE_ENCODING_MANIFEST: Buffer<ArrayBuffer>;
|
|
3
|
+
export declare const MAX_DECODED_EVIDENCE_BYTES: number;
|
|
4
|
+
export declare function encodeEvidenceBytes(bytes: Uint8Array): Buffer;
|
|
5
|
+
export declare function decodeEvidenceBytes(bytes: Uint8Array): Buffer;
|
|
6
|
+
export declare function encodeEvidenceBody(body: Buffer | ReadableStream<Uint8Array>): Buffer | ReadableStream<Uint8Array>;
|
|
7
|
+
/** Lazy opening keeps read failures inside the caller's normal stream cleanup. */
|
|
8
|
+
export declare function decodeEvidenceStream(body: ReadableStream<Uint8Array>): ReadableStream<Uint8Array>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { gzipSync, gunzipSync } from "node:zlib";
|
|
2
|
+
/** In-object manifest. Legacy objects without this exact prefix remain raw. */
|
|
3
|
+
export const EVIDENCE_ENCODING_MANIFEST = Buffer.from('TOWER-EVIDENCE\n{"version":1,"encoding":"gzip"}\n');
|
|
4
|
+
export const MAX_DECODED_EVIDENCE_BYTES = 512 * 1024 * 1024;
|
|
5
|
+
export function encodeEvidenceBytes(bytes) {
|
|
6
|
+
return Buffer.concat([EVIDENCE_ENCODING_MANIFEST, gzipSync(bytes)]);
|
|
7
|
+
}
|
|
8
|
+
export function decodeEvidenceBytes(bytes) {
|
|
9
|
+
const buffer = Buffer.from(bytes);
|
|
10
|
+
return buffer.subarray(0, EVIDENCE_ENCODING_MANIFEST.length).equals(EVIDENCE_ENCODING_MANIFEST)
|
|
11
|
+
? gunzipSync(buffer.subarray(EVIDENCE_ENCODING_MANIFEST.length), { maxOutputLength: MAX_DECODED_EVIDENCE_BYTES })
|
|
12
|
+
: buffer;
|
|
13
|
+
}
|
|
14
|
+
export function encodeEvidenceBody(body) {
|
|
15
|
+
if (Buffer.isBuffer(body))
|
|
16
|
+
return encodeEvidenceBytes(body);
|
|
17
|
+
const reader = body.pipeThrough(new CompressionStream("gzip")).getReader();
|
|
18
|
+
let prefixSent = false;
|
|
19
|
+
return new ReadableStream({
|
|
20
|
+
async pull(controller) {
|
|
21
|
+
if (!prefixSent) {
|
|
22
|
+
prefixSent = true;
|
|
23
|
+
controller.enqueue(EVIDENCE_ENCODING_MANIFEST);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const next = await reader.read();
|
|
27
|
+
if (next.done)
|
|
28
|
+
controller.close();
|
|
29
|
+
else
|
|
30
|
+
controller.enqueue(next.value);
|
|
31
|
+
},
|
|
32
|
+
cancel(reason) { return reader.cancel(reason); },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Look ahead only as far as the manifest, then decode with bounded residency. */
|
|
36
|
+
async function openDecodedStream(reader) {
|
|
37
|
+
let head = Buffer.alloc(0);
|
|
38
|
+
while (head.length < EVIDENCE_ENCODING_MANIFEST.length) {
|
|
39
|
+
const next = await reader.read();
|
|
40
|
+
if (next.done)
|
|
41
|
+
break;
|
|
42
|
+
head = Buffer.concat([head, next.value]);
|
|
43
|
+
const prefixLength = Math.min(head.length, EVIDENCE_ENCODING_MANIFEST.length);
|
|
44
|
+
if (!head.subarray(0, prefixLength).equals(EVIDENCE_ENCODING_MANIFEST.subarray(0, prefixLength)))
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
const encoded = head.subarray(0, EVIDENCE_ENCODING_MANIFEST.length).equals(EVIDENCE_ENCODING_MANIFEST);
|
|
48
|
+
let first = encoded ? head.subarray(EVIDENCE_ENCODING_MANIFEST.length) : head;
|
|
49
|
+
const remainder = new ReadableStream({
|
|
50
|
+
async pull(controller) {
|
|
51
|
+
if (first !== null) {
|
|
52
|
+
const bytes = first;
|
|
53
|
+
first = null;
|
|
54
|
+
controller.enqueue(bytes);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const next = await reader.read();
|
|
58
|
+
if (next.done)
|
|
59
|
+
controller.close();
|
|
60
|
+
else
|
|
61
|
+
controller.enqueue(next.value);
|
|
62
|
+
},
|
|
63
|
+
cancel(reason) { return reader.cancel(reason); },
|
|
64
|
+
});
|
|
65
|
+
if (!encoded)
|
|
66
|
+
return remainder;
|
|
67
|
+
let decodedBytes = 0;
|
|
68
|
+
return remainder.pipeThrough(new DecompressionStream("gzip")).pipeThrough(new TransformStream({
|
|
69
|
+
transform(chunk, controller) {
|
|
70
|
+
decodedBytes += chunk.byteLength;
|
|
71
|
+
if (decodedBytes > MAX_DECODED_EVIDENCE_BYTES)
|
|
72
|
+
throw new Error("evidence_decoded_size_exceeded");
|
|
73
|
+
controller.enqueue(chunk);
|
|
74
|
+
},
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
/** Lazy opening keeps read failures inside the caller's normal stream cleanup. */
|
|
78
|
+
export function decodeEvidenceStream(body) {
|
|
79
|
+
const sourceReader = body.getReader();
|
|
80
|
+
let reader;
|
|
81
|
+
return new ReadableStream({
|
|
82
|
+
async pull(controller) {
|
|
83
|
+
reader ??= (await openDecodedStream(sourceReader)).getReader();
|
|
84
|
+
const next = await reader.read();
|
|
85
|
+
if (next.done)
|
|
86
|
+
controller.close();
|
|
87
|
+
else
|
|
88
|
+
controller.enqueue(next.value);
|
|
89
|
+
},
|
|
90
|
+
async cancel(reason) {
|
|
91
|
+
if (reader)
|
|
92
|
+
await reader.cancel(reason);
|
|
93
|
+
else
|
|
94
|
+
await sourceReader.cancel(reason);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -269,7 +269,11 @@ export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
|
|
|
269
269
|
}, z.core.$strict>;
|
|
270
270
|
export type RawEvidenceUploadBeginResponse = z.infer<typeof RawEvidenceUploadBeginResponseSchema>;
|
|
271
271
|
export declare const RawEvidenceUploadChunkRequestSchema: z.ZodObject<{
|
|
272
|
-
schema_version: z.
|
|
272
|
+
schema_version: z.ZodEnum<{
|
|
273
|
+
"ambient-raw-evidence-upload-chunk.v1": "ambient-raw-evidence-upload-chunk.v1";
|
|
274
|
+
"ambient-raw-evidence-upload-chunk.v2": "ambient-raw-evidence-upload-chunk.v2";
|
|
275
|
+
}>;
|
|
276
|
+
encoding: z.ZodOptional<z.ZodLiteral<"gzip">>;
|
|
273
277
|
generated_at: z.ZodString;
|
|
274
278
|
provenance: z.ZodObject<{
|
|
275
279
|
capture_source: z.ZodEnum<{
|
package/dist/evidence-upload.js
CHANGED
|
@@ -122,7 +122,8 @@ export const RawEvidenceUploadBeginResponseSchema = z
|
|
|
122
122
|
.strict();
|
|
123
123
|
export const RawEvidenceUploadChunkRequestSchema = z
|
|
124
124
|
.object({
|
|
125
|
-
schema_version: z.
|
|
125
|
+
schema_version: z.enum(["ambient-raw-evidence-upload-chunk.v1", "ambient-raw-evidence-upload-chunk.v2"]),
|
|
126
|
+
encoding: z.literal("gzip").optional(),
|
|
126
127
|
generated_at: IsoDateTimeSchema,
|
|
127
128
|
provenance: CaptureProvenanceSchema,
|
|
128
129
|
upload_id: NonEmptyStringSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bli-cockpit/telemetry-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.44",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"./memory-experience": {
|
|
19
19
|
"types": "./dist/memory-experience.d.ts",
|
|
20
20
|
"import": "./dist/memory-experience.js"
|
|
21
|
+
},
|
|
22
|
+
"./evidence-storage-encoding": {
|
|
23
|
+
"types": "./dist/evidence-storage-encoding.d.ts",
|
|
24
|
+
"import": "./dist/evidence-storage-encoding.js"
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"publishConfig": {
|