@bli-cockpit/telemetry-core 0.1.87 → 0.1.89
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/dist/evidence-rules-fingerprint.js +5 -0
- package/dist/evidence-upload.d.ts +15 -0
- package/dist/evidence-upload.js +9 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/pdf-markers.d.ts +21 -0
- package/dist/pdf-markers.js +39 -0
- package/dist/transcript-images.d.ts +5 -0
- package/dist/transcript-images.js +2 -2
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ import { formatImageMarker, imageMarkerPattern, IMAGE_MIN_BASE64_CHARS } from ".
|
|
|
17
17
|
import { SECRET_LIKE_CONTENT_PATTERNS } from "./secret-guards-content-rules.js";
|
|
18
18
|
import { SECRET_REDACTION_RULES } from "./secret-guards-masking.js";
|
|
19
19
|
import { SECRET_FILE_SEGMENT_PATTERN } from "./secret-guards-path-rules.js";
|
|
20
|
+
import { PDF_RULES_VERSION, formatPdfMarker, formatPdfReference } from "./pdf-markers.js";
|
|
20
21
|
import { findEmbeddedImages } from "./transcript-images.js";
|
|
21
22
|
let cached;
|
|
22
23
|
/** The probe: a tiny PNG header padded past the detector's minimum, in both shapes the detector knows. */
|
|
@@ -39,6 +40,10 @@ export function evidenceRulesFingerprint() {
|
|
|
39
40
|
image_min_base64_chars: IMAGE_MIN_BASE64_CHARS,
|
|
40
41
|
image_marker_pattern: describe(imageMarkerPattern()),
|
|
41
42
|
image_marker_sample: formatImageMarker({ sha256: "0123456789abcdef".repeat(4), mediaType: "image/png", byteSize: 412 * 1024 }),
|
|
43
|
+
// BLI-23347: PDFs become text. The rules version and both marker shapes decide those bytes.
|
|
44
|
+
pdf_rules_version: PDF_RULES_VERSION,
|
|
45
|
+
pdf_marker_sample: formatPdfMarker({ sha256: "0123456789abcdef".repeat(4), pages: 3, byteSize: 412 * 1024, method: "text-layer", notes: ["sample"] }, "body"),
|
|
46
|
+
pdf_reference_sample: formatPdfReference({ sha256: "0123456789abcdef".repeat(4), byteSize: 412 * 1024 }),
|
|
42
47
|
image_detector_probe: findEmbeddedImages(probe).map((image) => [image.replaceStart, image.replaceEnd, image.mediaType, image.byteSize]),
|
|
43
48
|
};
|
|
44
49
|
cached = createHash("sha256").update(JSON.stringify(parts)).digest("hex");
|
|
@@ -252,6 +252,11 @@ export declare const RawEvidenceUploadEncodingSchema: z.ZodEnum<{
|
|
|
252
252
|
br: "br";
|
|
253
253
|
}>;
|
|
254
254
|
export type RawEvidenceUploadEncoding = z.infer<typeof RawEvidenceUploadEncodingSchema>;
|
|
255
|
+
/**
|
|
256
|
+
* Sent on `begin` by a collector that can encode more than gzip, listing what it can write
|
|
257
|
+
* (`zstd,br,gzip`). A server that knows the header answers with `accepted_encodings`.
|
|
258
|
+
*/
|
|
259
|
+
export declare const EVIDENCE_CODECS_HEADER = "x-tower-evidence-codecs";
|
|
255
260
|
export declare const RawEvidenceUploadBeginResponseObjectSchema: z.ZodObject<{
|
|
256
261
|
object_key: z.ZodString;
|
|
257
262
|
raw_evidence_pointer_id: z.ZodString;
|
|
@@ -269,6 +274,11 @@ export declare const RawEvidenceUploadBeginResponseObjectSchema: z.ZodObject<{
|
|
|
269
274
|
signed_url: z.ZodString;
|
|
270
275
|
}, z.core.$strict>>>;
|
|
271
276
|
reason: z.ZodOptional<z.ZodString>;
|
|
277
|
+
accepted_encodings: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
278
|
+
gzip: "gzip";
|
|
279
|
+
zstd: "zstd";
|
|
280
|
+
br: "br";
|
|
281
|
+
}>>>;
|
|
272
282
|
}, z.core.$strict>;
|
|
273
283
|
export type RawEvidenceUploadBeginResponseObject = z.infer<typeof RawEvidenceUploadBeginResponseObjectSchema>;
|
|
274
284
|
export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
|
|
@@ -290,6 +300,11 @@ export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
|
|
|
290
300
|
signed_url: z.ZodString;
|
|
291
301
|
}, z.core.$strict>>>;
|
|
292
302
|
reason: z.ZodOptional<z.ZodString>;
|
|
303
|
+
accepted_encodings: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
304
|
+
gzip: "gzip";
|
|
305
|
+
zstd: "zstd";
|
|
306
|
+
br: "br";
|
|
307
|
+
}>>>;
|
|
293
308
|
}, z.core.$strict>>;
|
|
294
309
|
}, z.core.$strict>;
|
|
295
310
|
export type RawEvidenceUploadBeginResponse = z.infer<typeof RawEvidenceUploadBeginResponseSchema>;
|
package/dist/evidence-upload.js
CHANGED
|
@@ -104,6 +104,11 @@ export const RawEvidenceUploadDispositionSchema = z.enum([
|
|
|
104
104
|
]);
|
|
105
105
|
/** How a chunk's bytes are compressed on the wire (BLI-23334). `gzip` is what every collector speaks today; the door decodes all three. */
|
|
106
106
|
export const RawEvidenceUploadEncodingSchema = z.enum(["gzip", "zstd", "br"]);
|
|
107
|
+
/**
|
|
108
|
+
* Sent on `begin` by a collector that can encode more than gzip, listing what it can write
|
|
109
|
+
* (`zstd,br,gzip`). A server that knows the header answers with `accepted_encodings`.
|
|
110
|
+
*/
|
|
111
|
+
export const EVIDENCE_CODECS_HEADER = "x-tower-evidence-codecs";
|
|
107
112
|
export const RawEvidenceUploadBeginResponseObjectSchema = z
|
|
108
113
|
.object({
|
|
109
114
|
object_key: NonEmptyStringSchema,
|
|
@@ -119,6 +124,10 @@ export const RawEvidenceUploadBeginResponseObjectSchema = z
|
|
|
119
124
|
signed_url: z.string().url(),
|
|
120
125
|
}).strict()).optional(),
|
|
121
126
|
reason: SafeLabelSchema.optional(),
|
|
127
|
+
// BLI-23334: the codecs this server decodes. Sent only to a collector that asked with
|
|
128
|
+
// `EVIDENCE_CODECS_HEADER`; this schema is strict, so an old collector must never be shown the
|
|
129
|
+
// key. Absent means gzip only.
|
|
130
|
+
accepted_encodings: z.array(RawEvidenceUploadEncodingSchema).optional(),
|
|
122
131
|
})
|
|
123
132
|
.strict();
|
|
124
133
|
export const RawEvidenceUploadBeginResponseSchema = z
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./evidence-upload.js";
|
|
|
14
14
|
export * from "./image-description-store.js";
|
|
15
15
|
export * from "./image-descriptions.js";
|
|
16
16
|
export * from "./image-marker-resolver.js";
|
|
17
|
+
export * from "./pdf-markers.js";
|
|
17
18
|
export * from "./transcript-images.js";
|
|
18
19
|
export * from "./ingest-dto.js";
|
|
19
20
|
export * from "./local-config.js";
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./evidence-upload.js";
|
|
|
14
14
|
export * from "./image-description-store.js";
|
|
15
15
|
export * from "./image-descriptions.js";
|
|
16
16
|
export * from "./image-marker-resolver.js";
|
|
17
|
+
export * from "./pdf-markers.js";
|
|
17
18
|
export * from "./transcript-images.js";
|
|
18
19
|
export * from "./ingest-dto.js";
|
|
19
20
|
export * from "./local-config.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Bump when the extraction rules (layout heuristics, limits, page-image encoding) change what a PDF becomes. */
|
|
2
|
+
export declare const PDF_RULES_VERSION = "pdf-text.v1";
|
|
3
|
+
/** What every PDF marker starts with: a cheap `includes` check before anyone runs a regex. */
|
|
4
|
+
export declare const PDF_MARKER_START = "[pdf sha256:";
|
|
5
|
+
export declare const PDF_MARKER_END = "[/pdf]";
|
|
6
|
+
export type PdfConversionMethod = "text-layer" | "page-images";
|
|
7
|
+
export interface PdfMarkerFacts {
|
|
8
|
+
sha256: string;
|
|
9
|
+
pages: number;
|
|
10
|
+
byteSize: number;
|
|
11
|
+
method: PdfConversionMethod;
|
|
12
|
+
/** Short plain statements about the conversion ("pages 1-200 of 412 shown"), shown after the method. */
|
|
13
|
+
notes?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/** The marker block for the first copy of a PDF: header, body, closing line. */
|
|
16
|
+
export declare function formatPdfMarker(facts: PdfMarkerFacts, body: string): string;
|
|
17
|
+
/** The one-line stand-in for a repeat copy of a PDF already converted earlier in the same transcript. */
|
|
18
|
+
export declare function formatPdfReference(facts: {
|
|
19
|
+
sha256: string;
|
|
20
|
+
byteSize: number;
|
|
21
|
+
}): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDFs inside collected transcripts: what replaces their base64 (BLI-23347).
|
|
3
|
+
*
|
|
4
|
+
* Claude Code stores a PDF it read as base64, twice on one line (the tool result block and the
|
|
5
|
+
* structured `toolUseResult.file.base64`). In `describe_and_drop` mode the collector replaces each copy:
|
|
6
|
+
*
|
|
7
|
+
* - the FIRST copy of a PDF becomes a marker block: a header line with the sha256 prefix, page count,
|
|
8
|
+
* size and how it was converted, then the converted body (the PDF's text with tables as Markdown, or
|
|
9
|
+
* for a scan the markers of the page images the describe door described), then `[/pdf]`;
|
|
10
|
+
* - every further copy of the same PDF in the same transcript becomes a one-line reference to it.
|
|
11
|
+
*
|
|
12
|
+
* Shared by the collector (builds the marker) and anything that reads a marker back. Pure: no I/O.
|
|
13
|
+
* Changing the format, or `PDF_RULES_VERSION`, changes `evidenceRulesFingerprint()`, which rebuilds every
|
|
14
|
+
* collector's prepare memo once. That is intended: the bytes the collector makes from a PDF changed.
|
|
15
|
+
*/
|
|
16
|
+
import { imageSizeLabel } from "./image-descriptions.js";
|
|
17
|
+
/** Bump when the extraction rules (layout heuristics, limits, page-image encoding) change what a PDF becomes. */
|
|
18
|
+
export const PDF_RULES_VERSION = "pdf-text.v1";
|
|
19
|
+
/** What every PDF marker starts with: a cheap `includes` check before anyone runs a regex. */
|
|
20
|
+
export const PDF_MARKER_START = "[pdf sha256:";
|
|
21
|
+
export const PDF_MARKER_END = "[/pdf]";
|
|
22
|
+
/** Hex characters of the sha256 a PDF marker carries (same as an image marker). */
|
|
23
|
+
const PDF_MARKER_HASH_CHARS = 16;
|
|
24
|
+
function header(facts) {
|
|
25
|
+
const hash = facts.sha256.slice(0, PDF_MARKER_HASH_CHARS);
|
|
26
|
+
const pages = `${facts.pages} ${facts.pages === 1 ? "page" : "pages"}`;
|
|
27
|
+
const method = facts.method === "text-layer" ? "text" : "scanned, page images described";
|
|
28
|
+
const notes = (facts.notes ?? []).map((note) => `; ${note}`).join("");
|
|
29
|
+
return `${PDF_MARKER_START}${hash}… ${pages} ${imageSizeLabel(facts.byteSize)} ${method}${notes}]`;
|
|
30
|
+
}
|
|
31
|
+
/** The marker block for the first copy of a PDF: header, body, closing line. */
|
|
32
|
+
export function formatPdfMarker(facts, body) {
|
|
33
|
+
return `${header(facts)}\n${body}\n${PDF_MARKER_END}`;
|
|
34
|
+
}
|
|
35
|
+
/** The one-line stand-in for a repeat copy of a PDF already converted earlier in the same transcript. */
|
|
36
|
+
export function formatPdfReference(facts) {
|
|
37
|
+
const hash = facts.sha256.slice(0, PDF_MARKER_HASH_CHARS);
|
|
38
|
+
return `${PDF_MARKER_START}${hash}… ${imageSizeLabel(facts.byteSize)} same PDF as the earlier copy in this transcript]`;
|
|
39
|
+
}
|
|
@@ -10,6 +10,11 @@ export interface EmbeddedImage {
|
|
|
10
10
|
mediaType: ImageMediaType;
|
|
11
11
|
/** Decoded size in bytes. */
|
|
12
12
|
byteSize: number;
|
|
13
|
+
/**
|
|
14
|
+
* BLI-23347: set on a stand-in for something that is not an image (a PDF's base64). When present the
|
|
15
|
+
* range is swapped for exactly this text, whatever `replace` says, and no image marker is built.
|
|
16
|
+
*/
|
|
17
|
+
replacement?: string;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* Cheap check on raw bytes before anyone decodes a whole transcript to text: does it hold a data
|
|
@@ -83,9 +83,9 @@ export function replaceImagesWithMarkers(text, images, replace) {
|
|
|
83
83
|
let replacedCount = 0;
|
|
84
84
|
let charsSaved = 0;
|
|
85
85
|
for (const image of images) {
|
|
86
|
-
if (!replace(image))
|
|
86
|
+
if (image.replacement === undefined && !replace(image))
|
|
87
87
|
continue;
|
|
88
|
-
const marker = formatImageMarker({
|
|
88
|
+
const marker = image.replacement ?? formatImageMarker({
|
|
89
89
|
sha256: image.sha256,
|
|
90
90
|
mediaType: image.mediaType,
|
|
91
91
|
byteSize: image.byteSize,
|