@absolutejs/documents 0.0.0-stage → 0.1.0
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/CHANGELOG.md +14 -0
- package/LICENSE +88 -0
- package/README.md +41 -2
- package/changelog.json +20 -0
- package/dist/archive/containers.d.ts +5 -0
- package/dist/binary.d.ts +13 -0
- package/dist/define.d.ts +6 -0
- package/dist/email/body.d.ts +20 -0
- package/dist/email/headers.d.ts +20 -0
- package/dist/email/mailboxContainer.d.ts +19 -0
- package/dist/email/mailboxMetadata.d.ts +25 -0
- package/dist/email/maildir.d.ts +29 -0
- package/dist/email/mbox.d.ts +5 -0
- package/dist/email/message.d.ts +21 -0
- package/dist/email/mime.d.ts +24 -0
- package/dist/email/threads.d.ts +2 -0
- package/dist/epub.d.ts +2 -0
- package/dist/extractors/archive.d.ts +5 -0
- package/dist/extractors/email.d.ts +2 -0
- package/dist/extractors/epub.d.ts +2 -0
- package/dist/extractors/image.d.ts +2 -0
- package/dist/extractors/legacy.d.ts +2 -0
- package/dist/extractors/mailbox.d.ts +2 -0
- package/dist/extractors/media.d.ts +2 -0
- package/dist/extractors/office.d.ts +2 -0
- package/dist/extractors/pdf.d.ts +2 -0
- package/dist/extractors/pdfOCR.d.ts +2 -0
- package/dist/extractors/supports.d.ts +11 -0
- package/dist/extractors/text.d.ts +2 -0
- package/dist/formats.d.ts +37 -0
- package/dist/helpers.d.ts +11 -0
- package/dist/helpers.js +39 -0
- package/dist/html.d.ts +4 -0
- package/dist/identity.d.ts +3 -0
- package/dist/index-6cd9rbkj.js +3677 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1126 -0
- package/dist/legacy.d.ts +3 -0
- package/dist/media.d.ts +22 -0
- package/dist/ocr.d.ts +22 -0
- package/dist/office/presentation.d.ts +10 -0
- package/dist/office/spreadsheet.d.ts +26 -0
- package/dist/office/word.d.ts +20 -0
- package/dist/pdf/bounded.d.ts +33 -0
- package/dist/pdf/checkpoint.d.ts +28 -0
- package/dist/pdf/native.d.ts +39 -0
- package/dist/pdf/paged.d.ts +17 -0
- package/dist/read.d.ts +25 -0
- package/dist/registry.d.ts +5 -0
- package/dist/structured.d.ts +2 -0
- package/dist/text.d.ts +1 -0
- package/dist/types.d.ts +123 -0
- package/package.json +55 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,1126 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_BINARY_NAME,
|
|
4
|
+
inferFormatFromUrl2,
|
|
5
|
+
inferFormatFromContentType2,
|
|
6
|
+
decodeUploadContent2,
|
|
7
|
+
slugify2,
|
|
8
|
+
documentIdentity2,
|
|
9
|
+
normalizeWhitespace2,
|
|
10
|
+
pdfExtractorSupports,
|
|
11
|
+
mediaExtractorSupports,
|
|
12
|
+
imageExtractorSupports,
|
|
13
|
+
createBuiltinArchiveExpander2,
|
|
14
|
+
createArchiveFileExtractor2,
|
|
15
|
+
createEmailExtractor2,
|
|
16
|
+
createEPUBExtractor2,
|
|
17
|
+
createLegacyDocumentExtractor2,
|
|
18
|
+
createMailboxContainerExtractor2,
|
|
19
|
+
createOfficeDocumentExtractor2,
|
|
20
|
+
OCR_SUMMARY_CONFIDENCE_THRESHOLD,
|
|
21
|
+
OCR_SUMMARY_MIN_STRONG_TEXT_RATIO,
|
|
22
|
+
extractNativePDFText,
|
|
23
|
+
createPDFFileExtractor2,
|
|
24
|
+
createTextFileExtractor2,
|
|
25
|
+
extractDocuments2,
|
|
26
|
+
getFirstExtractedDocument2,
|
|
27
|
+
authoredEmailText2,
|
|
28
|
+
reconcileLoadedEmailThreads2
|
|
29
|
+
} from "./index-6cd9rbkj.js";
|
|
30
|
+
|
|
31
|
+
// src/define.ts
|
|
32
|
+
var createArchiveExpander = (expander) => expander;
|
|
33
|
+
var createFileExtractor = (extractor) => extractor;
|
|
34
|
+
var createExtractorRegistry = (registry) => registry;
|
|
35
|
+
var createMediaTranscriber = (transcriber) => transcriber;
|
|
36
|
+
var createOCRProvider = (provider) => provider;
|
|
37
|
+
// src/ocr.ts
|
|
38
|
+
var ocrMetadata = (result) => {
|
|
39
|
+
const regions = result.regions?.filter((region) => normalizeWhitespace2(region.text ?? "").length > 0);
|
|
40
|
+
const pageNumbers = [
|
|
41
|
+
...new Set((regions ?? []).map((region) => typeof region.page === "number" && region.page > 0 ? region.page : undefined).filter((value) => value !== undefined))
|
|
42
|
+
].sort((left, right) => left - right);
|
|
43
|
+
const confidenceValues = [
|
|
44
|
+
typeof result.confidence === "number" ? result.confidence : undefined,
|
|
45
|
+
...(regions ?? []).map((region) => typeof region.confidence === "number" ? region.confidence : undefined)
|
|
46
|
+
].filter((value) => value !== undefined);
|
|
47
|
+
const averageConfidence = confidenceValues.length > 0 ? confidenceValues.reduce((sum, value) => sum + value, 0) / confidenceValues.length : undefined;
|
|
48
|
+
const minConfidence = confidenceValues.length > 0 ? Math.min(...confidenceValues) : undefined;
|
|
49
|
+
const maxConfidence = confidenceValues.length > 0 ? Math.max(...confidenceValues) : undefined;
|
|
50
|
+
const pageStart = pageNumbers[0];
|
|
51
|
+
const pageEnd = pageNumbers.at(-1);
|
|
52
|
+
return {
|
|
53
|
+
...result.metadata ?? {},
|
|
54
|
+
ocrConfidence: result.confidence,
|
|
55
|
+
ocrPageCount: pageNumbers.length,
|
|
56
|
+
...typeof pageStart === "number" ? { ocrPageStart: pageStart } : {},
|
|
57
|
+
...typeof pageEnd === "number" ? { ocrPageEnd: pageEnd } : {},
|
|
58
|
+
ocrPageNumbers: pageNumbers,
|
|
59
|
+
ocrRegionCount: regions?.length,
|
|
60
|
+
ocrRegions: regions,
|
|
61
|
+
ocrAverageConfidence: averageConfidence,
|
|
62
|
+
...typeof minConfidence === "number" ? { ocrMinConfidence: minConfidence } : {},
|
|
63
|
+
...typeof maxConfidence === "number" ? { ocrMaxConfidence: maxConfidence } : {}
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
var toOCRReadingOrder = (regions) => [...regions].sort((left, right) => {
|
|
67
|
+
const leftY = typeof left.y === "number" && Number.isFinite(left.y) ? left.y : 0;
|
|
68
|
+
const rightY = typeof right.y === "number" && Number.isFinite(right.y) ? right.y : 0;
|
|
69
|
+
const leftHeight = typeof left.height === "number" && Number.isFinite(left.height) ? left.height : 0;
|
|
70
|
+
const rightHeight = typeof right.height === "number" && Number.isFinite(right.height) ? right.height : 0;
|
|
71
|
+
const lineThreshold = Math.max(leftHeight, rightHeight, 12) * 0.6;
|
|
72
|
+
if (Math.abs(leftY - rightY) > lineThreshold) {
|
|
73
|
+
return leftY - rightY;
|
|
74
|
+
}
|
|
75
|
+
const leftX = typeof left.x === "number" && Number.isFinite(left.x) ? left.x : 0;
|
|
76
|
+
const rightX = typeof right.x === "number" && Number.isFinite(right.x) ? right.x : 0;
|
|
77
|
+
if (leftX !== rightX) {
|
|
78
|
+
return leftX - rightX;
|
|
79
|
+
}
|
|
80
|
+
return normalizeWhitespace2(left.text ?? "").localeCompare(normalizeWhitespace2(right.text ?? ""));
|
|
81
|
+
});
|
|
82
|
+
var buildOCRReadingLinesText = (regions) => {
|
|
83
|
+
const ordered = toOCRReadingOrder(regions);
|
|
84
|
+
const lines = [];
|
|
85
|
+
for (const region of ordered) {
|
|
86
|
+
const text = normalizeWhitespace2(region.text ?? "");
|
|
87
|
+
if (!text) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const y = typeof region.y === "number" && Number.isFinite(region.y) ? region.y : 0;
|
|
91
|
+
const height = typeof region.height === "number" && Number.isFinite(region.height) ? region.height : 12;
|
|
92
|
+
const line = lines.at(-1);
|
|
93
|
+
const threshold = Math.max(line?.height ?? 0, height, 12) * 0.6;
|
|
94
|
+
if (line && Math.abs(y - line.y) <= threshold) {
|
|
95
|
+
line.segments.push(region);
|
|
96
|
+
line.y = Math.min(line.y, y);
|
|
97
|
+
line.height = Math.max(line.height, height);
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
lines.push({ height, segments: [region], y });
|
|
101
|
+
}
|
|
102
|
+
return normalizeWhitespace2(lines.map((line) => toOCRReadingOrder(line.segments).map((segment) => normalizeWhitespace2(segment.text ?? "")).filter(Boolean).join(" ")).filter(Boolean).join(`
|
|
103
|
+
`));
|
|
104
|
+
};
|
|
105
|
+
var splitOCRColumns = (regions) => {
|
|
106
|
+
if (regions.length < 4) {
|
|
107
|
+
return [regions];
|
|
108
|
+
}
|
|
109
|
+
const xAnchors = regions.map((region) => typeof region.x === "number" && Number.isFinite(region.x) ? region.x : undefined).filter((value) => typeof value === "number").sort((left, right) => left - right);
|
|
110
|
+
if (xAnchors.length < 4) {
|
|
111
|
+
return [regions];
|
|
112
|
+
}
|
|
113
|
+
let largestGap = 0;
|
|
114
|
+
let splitX;
|
|
115
|
+
for (let index = 1;index < xAnchors.length; index += 1) {
|
|
116
|
+
const gap = xAnchors[index] - xAnchors[index - 1];
|
|
117
|
+
if (gap > largestGap) {
|
|
118
|
+
largestGap = gap;
|
|
119
|
+
splitX = xAnchors[index - 1] + gap / 2;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!(largestGap >= 80) || typeof splitX !== "number") {
|
|
123
|
+
return [regions];
|
|
124
|
+
}
|
|
125
|
+
const leftColumn = regions.filter((region) => {
|
|
126
|
+
const x = typeof region.x === "number" && Number.isFinite(region.x) ? region.x : 0;
|
|
127
|
+
return x < splitX;
|
|
128
|
+
});
|
|
129
|
+
const rightColumn = regions.filter((region) => {
|
|
130
|
+
const x = typeof region.x === "number" && Number.isFinite(region.x) ? region.x : 0;
|
|
131
|
+
return x >= splitX;
|
|
132
|
+
});
|
|
133
|
+
if (leftColumn.length < 2 || rightColumn.length < 2) {
|
|
134
|
+
return [regions];
|
|
135
|
+
}
|
|
136
|
+
const yRange = (column) => {
|
|
137
|
+
const ys = column.map((region) => typeof region.y === "number" && Number.isFinite(region.y) ? region.y : undefined).filter((value) => typeof value === "number");
|
|
138
|
+
return ys.length > 0 ? { max: Math.max(...ys), min: Math.min(...ys) } : undefined;
|
|
139
|
+
};
|
|
140
|
+
const leftRange = yRange(leftColumn);
|
|
141
|
+
const rightRange = yRange(rightColumn);
|
|
142
|
+
const overlapsVertically = leftRange && rightRange && Math.min(leftRange.max, rightRange.max) >= Math.max(leftRange.min, rightRange.min);
|
|
143
|
+
if (!overlapsVertically) {
|
|
144
|
+
return [regions];
|
|
145
|
+
}
|
|
146
|
+
return [leftColumn, rightColumn];
|
|
147
|
+
};
|
|
148
|
+
var buildOCRReadingText = (regions) => normalizeWhitespace2(splitOCRColumns(regions).map((column) => buildOCRReadingLinesText(column)).filter(Boolean).join(`
|
|
149
|
+
|
|
150
|
+
`));
|
|
151
|
+
var buildOCRSummaryText = (result) => {
|
|
152
|
+
const regions = result.regions?.filter((region) => normalizeWhitespace2(region.text ?? "").length > 0) ?? [];
|
|
153
|
+
if (regions.length === 0) {
|
|
154
|
+
return {
|
|
155
|
+
lowConfidenceRegionCount: 0,
|
|
156
|
+
strongRegionCount: 0,
|
|
157
|
+
summaryConfidenceThreshold: OCR_SUMMARY_CONFIDENCE_THRESHOLD,
|
|
158
|
+
text: result.text,
|
|
159
|
+
usedStrongRegionsOnly: false
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const strongRegions = regions.filter((region) => typeof region.confidence !== "number" || region.confidence >= OCR_SUMMARY_CONFIDENCE_THRESHOLD);
|
|
163
|
+
const lowConfidenceRegionCount = regions.length - strongRegions.length;
|
|
164
|
+
const strongTextLength = strongRegions.reduce((sum, region) => sum + normalizeWhitespace2(region.text ?? "").length, 0);
|
|
165
|
+
const totalTextLength = regions.reduce((sum, region) => sum + normalizeWhitespace2(region.text ?? "").length, 0);
|
|
166
|
+
const strongCoverageRatio = totalTextLength > 0 ? strongTextLength / totalTextLength : 0;
|
|
167
|
+
const useStrongRegionsOnly = strongRegions.length > 0 && lowConfidenceRegionCount > 0 && strongCoverageRatio >= OCR_SUMMARY_MIN_STRONG_TEXT_RATIO;
|
|
168
|
+
const strongReconstructed = buildOCRReadingText(strongRegions);
|
|
169
|
+
const allReconstructed = buildOCRReadingText(regions);
|
|
170
|
+
return {
|
|
171
|
+
lowConfidenceRegionCount,
|
|
172
|
+
strongRegionCount: strongRegions.length,
|
|
173
|
+
summaryConfidenceThreshold: OCR_SUMMARY_CONFIDENCE_THRESHOLD,
|
|
174
|
+
text: (useStrongRegionsOnly ? strongReconstructed : allReconstructed) || result.text,
|
|
175
|
+
usedStrongRegionsOnly: useStrongRegionsOnly
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
var ocrPageDocuments = (result, input, baseMetadata) => {
|
|
179
|
+
const grouped = new Map;
|
|
180
|
+
for (const region of result.regions ?? []) {
|
|
181
|
+
const text = normalizeWhitespace2(region.text ?? "");
|
|
182
|
+
if (!text || typeof region.page !== "number" || region.page < 1) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const bucket = grouped.get(region.page) ?? [];
|
|
186
|
+
bucket.push({ ...region, text });
|
|
187
|
+
grouped.set(region.page, bucket);
|
|
188
|
+
}
|
|
189
|
+
return [...grouped.entries()].sort((left, right) => left[0] - right[0]).map(([pageNumber, regions]) => {
|
|
190
|
+
const orderedRegions = toOCRReadingOrder(regions);
|
|
191
|
+
const confidenceValues = regions.map((region) => typeof region.confidence === "number" ? region.confidence : undefined).filter((value) => value !== undefined);
|
|
192
|
+
const averageConfidence = confidenceValues.length > 0 ? confidenceValues.reduce((sum, value) => sum + value, 0) / confidenceValues.length : undefined;
|
|
193
|
+
const minConfidence = confidenceValues.length > 0 ? Math.min(...confidenceValues) : undefined;
|
|
194
|
+
const maxConfidence = confidenceValues.length > 0 ? Math.max(...confidenceValues) : undefined;
|
|
195
|
+
return {
|
|
196
|
+
contentType: input.contentType,
|
|
197
|
+
format: "text",
|
|
198
|
+
metadata: {
|
|
199
|
+
...input.metadata ?? {},
|
|
200
|
+
...baseMetadata,
|
|
201
|
+
ocrPageAverageConfidence: averageConfidence,
|
|
202
|
+
ocrPageConfidence: averageConfidence,
|
|
203
|
+
...typeof minConfidence === "number" ? { ocrPageMinConfidence: minConfidence } : {},
|
|
204
|
+
...typeof maxConfidence === "number" ? { ocrPageMaxConfidence: maxConfidence } : {},
|
|
205
|
+
ocrRegionCount: regions.length,
|
|
206
|
+
ocrRegionNumbers: regions.map((_region, index) => index + 1),
|
|
207
|
+
ocrRegions: regions,
|
|
208
|
+
pageNumber,
|
|
209
|
+
pageIndex: pageNumber - 1,
|
|
210
|
+
sourceNativeKind: "pdf_page"
|
|
211
|
+
},
|
|
212
|
+
source: input.source ?? input.path ?? input.name ?? `${slugify2(input.title ?? DEFAULT_BINARY_NAME)}.pdf`,
|
|
213
|
+
text: normalizeWhitespace2(`PDF page ${pageNumber} from ${input.title ?? input.name ?? input.path ?? DEFAULT_BINARY_NAME}.
|
|
214
|
+
${buildOCRReadingText(orderedRegions)}`),
|
|
215
|
+
title: input.title ? `${input.title} \xB7 Page ${pageNumber}` : `Page ${pageNumber}`
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
var ocrRegionDocuments = (result, input, baseMetadata) => {
|
|
220
|
+
const documents = [];
|
|
221
|
+
for (const [index, region] of (result.regions ?? []).entries()) {
|
|
222
|
+
const text = normalizeWhitespace2(region.text ?? "");
|
|
223
|
+
if (!text || typeof region.page !== "number" || region.page < 1) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const pageNumber = region.page;
|
|
227
|
+
const regionNumber = index + 1;
|
|
228
|
+
documents.push({
|
|
229
|
+
contentType: input.contentType,
|
|
230
|
+
format: "text",
|
|
231
|
+
metadata: {
|
|
232
|
+
...input.metadata ?? {},
|
|
233
|
+
...baseMetadata,
|
|
234
|
+
ocrPageCount: 1,
|
|
235
|
+
ocrPageNumbers: [pageNumber],
|
|
236
|
+
ocrRegionConfidence: region.confidence,
|
|
237
|
+
ocrRegionHeight: region.height,
|
|
238
|
+
ocrRegionWidth: region.width,
|
|
239
|
+
ocrRegionX: region.x,
|
|
240
|
+
ocrRegionY: region.y,
|
|
241
|
+
pageNumber,
|
|
242
|
+
pageIndex: pageNumber - 1,
|
|
243
|
+
regionIndex: index,
|
|
244
|
+
regionNumber,
|
|
245
|
+
sourceNativeKind: "pdf_region"
|
|
246
|
+
},
|
|
247
|
+
source: input.source ?? input.path ?? input.name ?? `${slugify2(input.title ?? DEFAULT_BINARY_NAME)}.pdf`,
|
|
248
|
+
text: normalizeWhitespace2(`PDF page ${pageNumber} region ${regionNumber} from ${input.title ?? input.name ?? input.path ?? DEFAULT_BINARY_NAME}.
|
|
249
|
+
${text}`),
|
|
250
|
+
title: input.title ? `${input.title} \xB7 Page ${pageNumber} Region ${regionNumber}` : `Page ${pageNumber} Region ${regionNumber}`
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
return documents;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/extractors/image.ts
|
|
257
|
+
var createImageOCRExtractor = (provider) => ({
|
|
258
|
+
name: `absolute_image_ocr:${provider.name}`,
|
|
259
|
+
supports: imageExtractorSupports,
|
|
260
|
+
extract: async (input) => {
|
|
261
|
+
const result = await provider.extractText(input);
|
|
262
|
+
const summary = buildOCRSummaryText(result);
|
|
263
|
+
return {
|
|
264
|
+
contentType: input.contentType,
|
|
265
|
+
format: "text",
|
|
266
|
+
metadata: {
|
|
267
|
+
...input.metadata ?? {},
|
|
268
|
+
...ocrMetadata(result),
|
|
269
|
+
ocrLowConfidenceRegionCount: summary.lowConfidenceRegionCount,
|
|
270
|
+
ocrStrongRegionCount: summary.strongRegionCount,
|
|
271
|
+
ocrSummaryConfidenceThreshold: summary.summaryConfidenceThreshold,
|
|
272
|
+
ocrSummaryUsedStrongRegionsOnly: summary.usedStrongRegionsOnly,
|
|
273
|
+
fileKind: "image",
|
|
274
|
+
sourceNativeKind: "image_ocr"
|
|
275
|
+
},
|
|
276
|
+
source: input.source ?? input.path ?? input.name ?? `${slugify2(input.title ?? DEFAULT_BINARY_NAME)}.image.txt`,
|
|
277
|
+
text: summary.text,
|
|
278
|
+
title: result.title ?? input.title
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
// src/media.ts
|
|
283
|
+
var MAX_MEDIA_GROUP_CONTINUITY_GAP_MS = 3000;
|
|
284
|
+
var MAX_MEDIA_BRIDGED_UNKNOWN_SEGMENTS = 2;
|
|
285
|
+
var formatMediaTimestampForIngest = (value) => {
|
|
286
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const totalSeconds = Math.floor(value / 1000);
|
|
290
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
291
|
+
const seconds = totalSeconds % 60;
|
|
292
|
+
const milliseconds = Math.floor(value % 1000);
|
|
293
|
+
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}.${String(milliseconds).padStart(3, "0")}`;
|
|
294
|
+
};
|
|
295
|
+
var normalizeMediaSpeaker = (value) => typeof value === "string" && value.trim().length > 0 ? normalizeWhitespace2(value) : undefined;
|
|
296
|
+
var canonicalMediaSpeakerKey = (value) => {
|
|
297
|
+
const normalized = normalizeMediaSpeaker(value);
|
|
298
|
+
return typeof normalized === "string" ? normalized.toLowerCase().replace(/[^a-z0-9]+/gi, "") : undefined;
|
|
299
|
+
};
|
|
300
|
+
var normalizeMediaTimestamp = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
|
|
301
|
+
var normalizeMediaSegmentWindow = (startMs, endMs) => {
|
|
302
|
+
if (typeof startMs !== "number" && typeof endMs !== "number") {
|
|
303
|
+
return { endMs, startMs };
|
|
304
|
+
}
|
|
305
|
+
if (typeof startMs === "number" && typeof endMs === "number" && endMs < startMs) {
|
|
306
|
+
return {
|
|
307
|
+
startMs: undefined,
|
|
308
|
+
endMs: undefined
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
startMs,
|
|
313
|
+
endMs
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
var canonicalMediaChannel = (value) => {
|
|
317
|
+
if (typeof value !== "string") {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
switch (value.trim().toLowerCase().replace(/[\s_-]+/g, "")) {
|
|
321
|
+
case "l":
|
|
322
|
+
case "left":
|
|
323
|
+
case "ch1":
|
|
324
|
+
case "channel1":
|
|
325
|
+
case "one":
|
|
326
|
+
return "left";
|
|
327
|
+
case "r":
|
|
328
|
+
case "right":
|
|
329
|
+
case "ch2":
|
|
330
|
+
case "channel2":
|
|
331
|
+
case "two":
|
|
332
|
+
return "right";
|
|
333
|
+
case "m":
|
|
334
|
+
case "mono":
|
|
335
|
+
case "center":
|
|
336
|
+
case "centre":
|
|
337
|
+
case "middle":
|
|
338
|
+
return "mono";
|
|
339
|
+
default:
|
|
340
|
+
return value.trim().toLowerCase();
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
var normalizeMediaChannel = (value) => canonicalMediaChannel(value);
|
|
344
|
+
var buildMediaTimestampBoundary = (segments) => {
|
|
345
|
+
let startMs;
|
|
346
|
+
let endMs;
|
|
347
|
+
for (const segment of segments) {
|
|
348
|
+
if (typeof segment.startMs === "number" && Number.isFinite(segment.startMs)) {
|
|
349
|
+
startMs = typeof startMs === "number" ? Math.min(startMs, segment.startMs) : segment.startMs;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
for (const segment of segments) {
|
|
353
|
+
if (typeof segment.endMs === "number" && Number.isFinite(segment.endMs)) {
|
|
354
|
+
endMs = typeof endMs === "number" ? Math.max(endMs, segment.endMs) : segment.endMs;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return { endMs, startMs };
|
|
358
|
+
};
|
|
359
|
+
var buildMediaSegmentGapFromPrevious = (startMs, previousGroupEndMs) => {
|
|
360
|
+
if (typeof startMs !== "number" || typeof previousGroupEndMs !== "number" || !Number.isFinite(startMs) || !Number.isFinite(previousGroupEndMs)) {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (startMs < previousGroupEndMs) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
return startMs - previousGroupEndMs;
|
|
367
|
+
};
|
|
368
|
+
var buildMediaSegmentGapToNext = (endMs, nextGroupStartMs) => {
|
|
369
|
+
if (typeof endMs !== "number" || typeof nextGroupStartMs !== "number" || !Number.isFinite(endMs) || !Number.isFinite(nextGroupStartMs)) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (nextGroupStartMs < endMs) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
return nextGroupStartMs - endMs;
|
|
376
|
+
};
|
|
377
|
+
var normalizeMediaSegment = (segment) => {
|
|
378
|
+
const normalizedTimestampWindow = normalizeMediaSegmentWindow(normalizeMediaTimestamp(segment.startMs), normalizeMediaTimestamp(segment.endMs));
|
|
379
|
+
return {
|
|
380
|
+
...segment,
|
|
381
|
+
speaker: normalizeMediaSpeaker(segment.speaker),
|
|
382
|
+
channel: canonicalMediaChannel(segment.channel),
|
|
383
|
+
...normalizedTimestampWindow
|
|
384
|
+
};
|
|
385
|
+
};
|
|
386
|
+
var hasMediaSegmentTiming = (segment) => Boolean(segment && (typeof segment.startMs === "number" && Number.isFinite(segment.startMs) || typeof segment.endMs === "number" && Number.isFinite(segment.endMs)));
|
|
387
|
+
var sortMediaTranscriptSegments = (segments) => {
|
|
388
|
+
const sortTimedRun = (run) => run.sort((left, right) => {
|
|
389
|
+
const leftStart = left.segment.startMs;
|
|
390
|
+
const rightStart = right.segment.startMs;
|
|
391
|
+
const leftHasStart = typeof leftStart === "number" && Number.isFinite(leftStart);
|
|
392
|
+
const rightHasStart = typeof rightStart === "number" && Number.isFinite(rightStart);
|
|
393
|
+
if (leftHasStart && rightHasStart && leftStart !== rightStart) {
|
|
394
|
+
return leftStart - rightStart;
|
|
395
|
+
}
|
|
396
|
+
if (leftHasStart !== rightHasStart) {
|
|
397
|
+
return leftHasStart ? -1 : 1;
|
|
398
|
+
}
|
|
399
|
+
const leftEnd = left.segment.endMs;
|
|
400
|
+
const rightEnd = right.segment.endMs;
|
|
401
|
+
const leftHasEnd = typeof leftEnd === "number" && Number.isFinite(leftEnd);
|
|
402
|
+
const rightHasEnd = typeof rightEnd === "number" && Number.isFinite(rightEnd);
|
|
403
|
+
if (leftHasEnd && rightHasEnd && leftEnd !== rightEnd) {
|
|
404
|
+
return leftEnd - rightEnd;
|
|
405
|
+
}
|
|
406
|
+
if (leftHasEnd !== rightHasEnd) {
|
|
407
|
+
return leftHasEnd ? -1 : 1;
|
|
408
|
+
}
|
|
409
|
+
return left.index - right.index;
|
|
410
|
+
});
|
|
411
|
+
const ordered = [];
|
|
412
|
+
let timedRun = [];
|
|
413
|
+
for (const [index, segment] of segments.entries()) {
|
|
414
|
+
if (hasMediaSegmentTiming(segment)) {
|
|
415
|
+
timedRun.push({ index, segment });
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (timedRun.length > 0) {
|
|
419
|
+
ordered.push(...sortTimedRun(timedRun).map((entry) => entry.segment));
|
|
420
|
+
timedRun = [];
|
|
421
|
+
}
|
|
422
|
+
ordered.push(segment);
|
|
423
|
+
}
|
|
424
|
+
if (timedRun.length > 0) {
|
|
425
|
+
ordered.push(...sortTimedRun(timedRun).map((entry) => entry.segment));
|
|
426
|
+
}
|
|
427
|
+
return ordered;
|
|
428
|
+
};
|
|
429
|
+
var findNextInformativeMediaSegment = (segments, resolveValue) => {
|
|
430
|
+
let unknownSegments = 0;
|
|
431
|
+
for (const segment of segments) {
|
|
432
|
+
if (!segment || typeof segment !== "object") {
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (normalizeWhitespace2(segment.text ?? "").length === 0) {
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
const value = resolveValue(segment);
|
|
439
|
+
if (typeof value === "string" && value.length > 0) {
|
|
440
|
+
return value;
|
|
441
|
+
}
|
|
442
|
+
unknownSegments += 1;
|
|
443
|
+
if (unknownSegments > MAX_MEDIA_BRIDGED_UNKNOWN_SEGMENTS) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return;
|
|
448
|
+
};
|
|
449
|
+
var groupTranscriptSegments = (segments) => {
|
|
450
|
+
const groups = [];
|
|
451
|
+
for (const [index, segment] of segments.entries()) {
|
|
452
|
+
if (!segment || typeof segment !== "object") {
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
const text = normalizeWhitespace2(segment.text ?? "");
|
|
456
|
+
if (!text) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
let speaker = normalizeMediaSpeaker(segment.speaker);
|
|
460
|
+
let speakerKey = canonicalMediaSpeakerKey(segment.speaker);
|
|
461
|
+
let channel = normalizeMediaChannel(segment.channel);
|
|
462
|
+
const lastGroup = groups.at(-1);
|
|
463
|
+
const remainingSegments = segments.slice(index + 1);
|
|
464
|
+
const nextSpeakerKey = findNextInformativeMediaSegment(remainingSegments, (candidate) => canonicalMediaSpeakerKey(candidate.speaker));
|
|
465
|
+
const nextChannel = findNextInformativeMediaSegment(remainingSegments, (candidate) => normalizeMediaChannel(candidate.channel));
|
|
466
|
+
if (!speakerKey && !channel && lastGroup?.speakerKey && lastGroup.channel && nextSpeakerKey === lastGroup.speakerKey && nextChannel === lastGroup.channel) {
|
|
467
|
+
speakerKey = lastGroup.speakerKey;
|
|
468
|
+
speaker = lastGroup.speaker;
|
|
469
|
+
channel = lastGroup.channel;
|
|
470
|
+
}
|
|
471
|
+
if (!speakerKey && lastGroup?.speakerKey && lastGroup.channel === channel && nextSpeakerKey === lastGroup.speakerKey && nextChannel === channel) {
|
|
472
|
+
speakerKey = lastGroup.speakerKey;
|
|
473
|
+
speaker = lastGroup.speaker;
|
|
474
|
+
}
|
|
475
|
+
if (!channel && lastGroup?.channel && lastGroup.speakerKey === speakerKey && nextChannel === lastGroup.channel && nextSpeakerKey === speakerKey) {
|
|
476
|
+
channel = lastGroup.channel;
|
|
477
|
+
}
|
|
478
|
+
const shouldSplitForTimingModeChange = hasMediaSegmentTiming(segment) !== hasMediaSegmentTiming(lastGroup);
|
|
479
|
+
const shouldSplitForGap = typeof segment.startMs === "number" && typeof lastGroup?.endMs === "number" && Number.isFinite(segment.startMs) && Number.isFinite(lastGroup.endMs) && segment.startMs - lastGroup.endMs > MAX_MEDIA_GROUP_CONTINUITY_GAP_MS;
|
|
480
|
+
if (!lastGroup || lastGroup.speakerKey !== speakerKey || lastGroup.channel !== channel || shouldSplitForTimingModeChange || shouldSplitForGap) {
|
|
481
|
+
groups.push({
|
|
482
|
+
channel,
|
|
483
|
+
endMs: segment.endMs,
|
|
484
|
+
segments: [segment],
|
|
485
|
+
speaker,
|
|
486
|
+
speakerKey,
|
|
487
|
+
startMs: segment.startMs
|
|
488
|
+
});
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
lastGroup.endMs = typeof segment.endMs === "number" && Number.isFinite(segment.endMs) ? segment.endMs : lastGroup.endMs;
|
|
492
|
+
lastGroup.segments.push(segment);
|
|
493
|
+
if (typeof segment.startMs === "number" && Number.isFinite(segment.startMs)) {
|
|
494
|
+
if (typeof lastGroup.startMs !== "number" || !Number.isFinite(lastGroup.startMs) || segment.startMs < lastGroup.startMs) {
|
|
495
|
+
lastGroup.startMs = segment.startMs;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
return groups;
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
// src/extractors/media.ts
|
|
503
|
+
var createMediaFileExtractor = (transcriber) => ({
|
|
504
|
+
name: `absolute_media:${transcriber.name}`,
|
|
505
|
+
supports: mediaExtractorSupports,
|
|
506
|
+
extract: async (input) => {
|
|
507
|
+
const result = await transcriber.transcribe(input);
|
|
508
|
+
const rawSegments = sortMediaTranscriptSegments((result.segments ?? []).filter((segment) => {
|
|
509
|
+
if (!segment || typeof segment !== "object") {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
return normalizeWhitespace2(segment.text ?? "").length > 0;
|
|
513
|
+
}).map(normalizeMediaSegment));
|
|
514
|
+
const segmentGroups = groupTranscriptSegments(rawSegments);
|
|
515
|
+
const source = input.source ?? input.path ?? input.name ?? `${slugify2(input.title ?? DEFAULT_BINARY_NAME)}.media.txt`;
|
|
516
|
+
const baseDocumentId = documentIdentity2(source || input.title || input.name || input.path || DEFAULT_BINARY_NAME);
|
|
517
|
+
const segmentCount = rawSegments.length;
|
|
518
|
+
const mediaDurationMs = rawSegments.reduce((max, segment) => {
|
|
519
|
+
const endMs = typeof segment.endMs === "number" ? segment.endMs : undefined;
|
|
520
|
+
if (typeof endMs !== "number") {
|
|
521
|
+
return max;
|
|
522
|
+
}
|
|
523
|
+
return typeof max === "number" ? Math.max(max, endMs) : endMs;
|
|
524
|
+
}, undefined);
|
|
525
|
+
const mediaSpeakers = [
|
|
526
|
+
...new Set(rawSegments.map((segment) => normalizeMediaSpeaker(segment.speaker)).filter((value) => typeof value === "string"))
|
|
527
|
+
];
|
|
528
|
+
const segmentDocuments = [];
|
|
529
|
+
let previousGroupEndMs;
|
|
530
|
+
for (const [index, segmentGroup] of segmentGroups.entries()) {
|
|
531
|
+
const { endMs, startMs } = buildMediaTimestampBoundary(segmentGroup.segments);
|
|
532
|
+
const groupText = normalizeWhitespace2(segmentGroup.segments.map((segment) => normalizeWhitespace2(segment.text ?? "")).filter((value) => value.length > 0).join(" "));
|
|
533
|
+
if (!groupText) {
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
const mediaSegmentStartMs = startMs;
|
|
537
|
+
const mediaSegmentEndMs = endMs;
|
|
538
|
+
const startLabel = formatMediaTimestampForIngest(startMs);
|
|
539
|
+
const endLabel = formatMediaTimestampForIngest(endMs);
|
|
540
|
+
const mediaKind = typeof result.metadata?.mediaKind === "string" ? result.metadata.mediaKind : "media";
|
|
541
|
+
const mediaSegmentGapFromPreviousMs = buildMediaSegmentGapFromPrevious(startMs, previousGroupEndMs);
|
|
542
|
+
const nextSegmentGroup = segmentGroups[index + 1];
|
|
543
|
+
const nextSegmentGroupStartMs = nextSegmentGroup ? buildMediaTimestampBoundary(nextSegmentGroup.segments).startMs : undefined;
|
|
544
|
+
const mediaSegmentGapToNextMs = buildMediaSegmentGapToNext(endMs, nextSegmentGroupStartMs);
|
|
545
|
+
previousGroupEndMs = endMs;
|
|
546
|
+
const mediaSegmentGroupDurationMs = typeof endMs === "number" && typeof startMs === "number" && Number.isFinite(endMs) && Number.isFinite(startMs) && endMs >= startMs ? endMs - startMs : undefined;
|
|
547
|
+
segmentDocuments.push({
|
|
548
|
+
contentType: input.contentType,
|
|
549
|
+
format: "text",
|
|
550
|
+
id: `${baseDocumentId}-segment-${String(index + 1).padStart(2, "0")}`,
|
|
551
|
+
metadata: {
|
|
552
|
+
...input.metadata ?? {},
|
|
553
|
+
...result.metadata ?? {},
|
|
554
|
+
fileKind: "media",
|
|
555
|
+
sourceNativeKind: "media_segment",
|
|
556
|
+
mediaDurationMs,
|
|
557
|
+
mediaSegmentIndex: index,
|
|
558
|
+
mediaSegmentStartMs,
|
|
559
|
+
mediaSegmentEndMs,
|
|
560
|
+
mediaSegmentCount: segmentCount,
|
|
561
|
+
mediaSegmentGroupIndex: index,
|
|
562
|
+
mediaSegmentGroupSize: segmentGroup.segments.length,
|
|
563
|
+
mediaSegmentGroupSpeaker: segmentGroup.speaker,
|
|
564
|
+
mediaChannel: segmentGroup.channel,
|
|
565
|
+
mediaSegmentGroupDurationMs,
|
|
566
|
+
mediaSegmentGapFromPreviousMs,
|
|
567
|
+
mediaSegmentGapToNextMs,
|
|
568
|
+
mediaSegmentGroupStartMs: startMs,
|
|
569
|
+
mediaSegmentGroupEndMs: endMs,
|
|
570
|
+
mediaSegments: segmentGroup.segments,
|
|
571
|
+
startMs: mediaSegmentStartMs,
|
|
572
|
+
endMs: mediaSegmentEndMs,
|
|
573
|
+
...mediaSpeakers.length > 0 ? {
|
|
574
|
+
mediaSpeakerCount: mediaSpeakers.length,
|
|
575
|
+
mediaSpeakers
|
|
576
|
+
} : {},
|
|
577
|
+
speaker: segmentGroup.speaker
|
|
578
|
+
},
|
|
579
|
+
source,
|
|
580
|
+
text: normalizeWhitespace2(`${mediaKind} transcript segment${startLabel ? ` at timestamp ${startLabel}${endLabel ? ` to ${endLabel}` : ""}` : ""} from ${input.title ?? input.name ?? input.path ?? DEFAULT_BINARY_NAME}. ` + `${mediaKind} timestamp evidence${startLabel ? ` ${startLabel}${endLabel ? ` to ${endLabel}` : ""}` : ""}.` + `
|
|
581
|
+
${groupText}`),
|
|
582
|
+
title: input.title ? `${input.title} \xB7 ${mediaKind[0]?.toUpperCase() + mediaKind.slice(1)} segment ${index + 1}` : `${mediaKind[0]?.toUpperCase() + mediaKind.slice(1)} segment ${index + 1}`
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
const summaryDocument = {
|
|
586
|
+
contentType: input.contentType,
|
|
587
|
+
format: "text",
|
|
588
|
+
id: baseDocumentId,
|
|
589
|
+
metadata: {
|
|
590
|
+
...input.metadata ?? {},
|
|
591
|
+
...result.metadata ?? {},
|
|
592
|
+
fileKind: "media",
|
|
593
|
+
mediaDurationMs,
|
|
594
|
+
mediaSegmentCount: segmentCount,
|
|
595
|
+
mediaSegments: rawSegments,
|
|
596
|
+
...mediaSpeakers.length > 0 ? {
|
|
597
|
+
mediaSpeakerCount: mediaSpeakers.length,
|
|
598
|
+
mediaSpeakers
|
|
599
|
+
} : {}
|
|
600
|
+
},
|
|
601
|
+
source,
|
|
602
|
+
text: result.text,
|
|
603
|
+
title: result.title ?? input.title
|
|
604
|
+
};
|
|
605
|
+
return [summaryDocument, ...segmentDocuments];
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
// src/extractors/pdfOCR.ts
|
|
609
|
+
var createPDFOCRExtractor = (options) => ({
|
|
610
|
+
name: `absolute_pdf_ocr:${options.provider.name}`,
|
|
611
|
+
supports: pdfExtractorSupports,
|
|
612
|
+
extract: async (input) => {
|
|
613
|
+
const extracted = await extractNativePDFText(input.data);
|
|
614
|
+
const nativeText = extracted.text;
|
|
615
|
+
const minLength = options.minExtractedTextLength ?? 80;
|
|
616
|
+
const shouldUseNativeText = !options.alwaysOCR && nativeText.length >= minLength;
|
|
617
|
+
const shouldUseHybridText = !options.alwaysOCR && nativeText.length > 0 && nativeText.length < minLength;
|
|
618
|
+
if (shouldUseNativeText) {
|
|
619
|
+
return {
|
|
620
|
+
contentType: input.contentType ?? "application/pdf",
|
|
621
|
+
format: "text",
|
|
622
|
+
metadata: {
|
|
623
|
+
...input.metadata ?? {},
|
|
624
|
+
fileKind: "pdf",
|
|
625
|
+
pageCount: extracted.pageCount,
|
|
626
|
+
pdfEvidenceMode: "native",
|
|
627
|
+
pdfEvidenceOrigin: "native",
|
|
628
|
+
pdfTextBlockCount: extracted.textBlockCount,
|
|
629
|
+
pdfTextBlocks: extracted.textBlocks,
|
|
630
|
+
pdfTextMode: "native"
|
|
631
|
+
},
|
|
632
|
+
source: input.source ?? input.path ?? input.name ?? `${slugify2(input.title ?? DEFAULT_BINARY_NAME)}.pdf`,
|
|
633
|
+
text: nativeText,
|
|
634
|
+
title: input.title
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
const ocr = await options.provider.extractText({
|
|
638
|
+
...input,
|
|
639
|
+
contentType: input.contentType ?? "application/pdf"
|
|
640
|
+
});
|
|
641
|
+
const summary = buildOCRSummaryText(ocr);
|
|
642
|
+
const baseMetadata = {
|
|
643
|
+
...ocrMetadata(ocr),
|
|
644
|
+
ocrLowConfidenceRegionCount: summary.lowConfidenceRegionCount,
|
|
645
|
+
ocrStrongRegionCount: summary.strongRegionCount,
|
|
646
|
+
ocrSummaryConfidenceThreshold: summary.summaryConfidenceThreshold,
|
|
647
|
+
ocrSummaryUsedStrongRegionsOnly: summary.usedStrongRegionsOnly,
|
|
648
|
+
fileKind: "pdf",
|
|
649
|
+
pageCount: extracted.pageCount,
|
|
650
|
+
pdfEvidenceMode: "ocr",
|
|
651
|
+
pdfEvidenceOrigin: "ocr",
|
|
652
|
+
pdfTextMode: "ocr"
|
|
653
|
+
};
|
|
654
|
+
if (shouldUseHybridText) {
|
|
655
|
+
const hybridMetadata = {
|
|
656
|
+
...input.metadata ?? {},
|
|
657
|
+
...baseMetadata,
|
|
658
|
+
pageCount: extracted.pageCount,
|
|
659
|
+
pdfEvidenceMode: "hybrid",
|
|
660
|
+
pdfEvidenceOrigin: "native",
|
|
661
|
+
pdfEvidenceSupplement: "ocr",
|
|
662
|
+
pdfHybridOCRSupplement: true,
|
|
663
|
+
pdfNativeTextBlockCount: extracted.textBlockCount,
|
|
664
|
+
pdfNativeTextLength: nativeText.length,
|
|
665
|
+
pdfOCRFallbackReason: "native_below_min_length",
|
|
666
|
+
pdfOCRTextLength: summary.text.length,
|
|
667
|
+
pdfTextBlockCount: extracted.textBlockCount,
|
|
668
|
+
pdfTextBlocks: extracted.textBlocks,
|
|
669
|
+
pdfTextMode: "hybrid"
|
|
670
|
+
};
|
|
671
|
+
const hybridDocument = {
|
|
672
|
+
contentType: input.contentType ?? "application/pdf",
|
|
673
|
+
format: "text",
|
|
674
|
+
metadata: hybridMetadata,
|
|
675
|
+
source: input.source ?? input.path ?? input.name ?? `${slugify2(input.title ?? DEFAULT_BINARY_NAME)}.pdf`,
|
|
676
|
+
text: nativeText,
|
|
677
|
+
title: input.title
|
|
678
|
+
};
|
|
679
|
+
const pageDocuments = ocrPageDocuments(ocr, input, baseMetadata);
|
|
680
|
+
const regionDocuments = ocrRegionDocuments(ocr, input, baseMetadata);
|
|
681
|
+
return [hybridDocument, ...pageDocuments, ...regionDocuments];
|
|
682
|
+
}
|
|
683
|
+
const summaryDocument = {
|
|
684
|
+
contentType: input.contentType ?? "application/pdf",
|
|
685
|
+
format: "text",
|
|
686
|
+
metadata: {
|
|
687
|
+
...input.metadata ?? {},
|
|
688
|
+
...baseMetadata
|
|
689
|
+
},
|
|
690
|
+
source: input.source ?? input.path ?? input.name ?? `${slugify2(input.title ?? DEFAULT_BINARY_NAME)}.pdf`,
|
|
691
|
+
text: summary.text,
|
|
692
|
+
title: ocr.title ?? input.title
|
|
693
|
+
};
|
|
694
|
+
const pageDocuments = ocrPageDocuments(ocr, input, baseMetadata);
|
|
695
|
+
const regionDocuments = ocrRegionDocuments(ocr, input, baseMetadata);
|
|
696
|
+
return [summaryDocument, ...pageDocuments, ...regionDocuments];
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
// src/pdf/bounded.ts
|
|
700
|
+
import { mkdtemp, readFile, rm, stat } from "fs/promises";
|
|
701
|
+
import { tmpdir } from "os";
|
|
702
|
+
import { join, resolve } from "path";
|
|
703
|
+
|
|
704
|
+
class PDFSafetyError extends Error {
|
|
705
|
+
code;
|
|
706
|
+
diagnostics;
|
|
707
|
+
constructor(code, message) {
|
|
708
|
+
super(message);
|
|
709
|
+
this.code = code;
|
|
710
|
+
this.name = "PDFSafetyError";
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
var MIB = 1024 * 1024;
|
|
714
|
+
var inspectBoundedPDF = async (path, options = {}) => {
|
|
715
|
+
for (const [name, value] of Object.entries(options)) {
|
|
716
|
+
if ([
|
|
717
|
+
"maxFileBytes",
|
|
718
|
+
"maxPages",
|
|
719
|
+
"maxOutputBytes",
|
|
720
|
+
"memoryBytes",
|
|
721
|
+
"timeoutMs"
|
|
722
|
+
].includes(name) && (!Number.isSafeInteger(value) || Number(value) <= 0))
|
|
723
|
+
throw new RangeError(`PDF ${name} must be a positive safe integer`);
|
|
724
|
+
}
|
|
725
|
+
options.signal?.throwIfAborted();
|
|
726
|
+
const source = resolve(path);
|
|
727
|
+
const size = (await stat(source)).size;
|
|
728
|
+
if (size > (options.maxFileBytes ?? 100 * MIB))
|
|
729
|
+
throw new PDFSafetyError("size", "This PDF exceeds the supported file size. Export a smaller PDF or split it into relevant documents.");
|
|
730
|
+
const header = await Bun.file(source).slice(0, 1024).text();
|
|
731
|
+
if (!header.includes("%PDF-"))
|
|
732
|
+
throw new PDFSafetyError("invalid", "This file is not a readable PDF. Export it as PDF again.");
|
|
733
|
+
const run = async (tool, args, maxBytes = options.maxOutputBytes ?? 4 * MIB) => {
|
|
734
|
+
options.signal?.throwIfAborted();
|
|
735
|
+
const started = Date.now();
|
|
736
|
+
let exitCode;
|
|
737
|
+
const executable = options.executableDirectory ? join(options.executableDirectory, tool) : tool;
|
|
738
|
+
const child = Bun.spawn([
|
|
739
|
+
"/usr/bin/prlimit",
|
|
740
|
+
`--as=${options.memoryBytes ?? 512 * MIB}`,
|
|
741
|
+
"--cpu=30",
|
|
742
|
+
"--fsize=16777216",
|
|
743
|
+
"--nofile=64",
|
|
744
|
+
"--",
|
|
745
|
+
executable,
|
|
746
|
+
...args
|
|
747
|
+
], {
|
|
748
|
+
env: { PATH: process.env.PATH, LANG: "C", LC_ALL: "C" },
|
|
749
|
+
stdin: "ignore",
|
|
750
|
+
stdout: "pipe",
|
|
751
|
+
stderr: "pipe"
|
|
752
|
+
});
|
|
753
|
+
const controller = new AbortController;
|
|
754
|
+
const signal = AbortSignal.any([
|
|
755
|
+
...options.signal ? [options.signal] : [],
|
|
756
|
+
controller.signal
|
|
757
|
+
]);
|
|
758
|
+
const kill = () => child.kill("SIGKILL");
|
|
759
|
+
signal.addEventListener("abort", kill, { once: true });
|
|
760
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 30000);
|
|
761
|
+
const collect = async (stream, limit) => {
|
|
762
|
+
const reader = stream.getReader();
|
|
763
|
+
const chunks = [];
|
|
764
|
+
let total = 0;
|
|
765
|
+
try {
|
|
766
|
+
for (;; ) {
|
|
767
|
+
const part = await reader.read();
|
|
768
|
+
if (part.done)
|
|
769
|
+
break;
|
|
770
|
+
total += part.value.byteLength;
|
|
771
|
+
if (total > limit) {
|
|
772
|
+
kill();
|
|
773
|
+
throw new PDFSafetyError("output", "This PDF expands beyond safe processing limits. Export a simpler PDF or split it into relevant documents.");
|
|
774
|
+
}
|
|
775
|
+
chunks.push(part.value);
|
|
776
|
+
}
|
|
777
|
+
return Buffer.concat(chunks);
|
|
778
|
+
} finally {
|
|
779
|
+
reader.releaseLock();
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
try {
|
|
783
|
+
if (signal.aborted)
|
|
784
|
+
kill();
|
|
785
|
+
const [stdout, stderr, exit] = await Promise.all([
|
|
786
|
+
collect(child.stdout, maxBytes),
|
|
787
|
+
collect(child.stderr, 64 * 1024),
|
|
788
|
+
child.exited
|
|
789
|
+
]);
|
|
790
|
+
exitCode = exit;
|
|
791
|
+
options.signal?.throwIfAborted();
|
|
792
|
+
if (controller.signal.aborted)
|
|
793
|
+
throw new PDFSafetyError("resources", "This PDF exceeded its processing time limit. Export a simpler PDF or split it into relevant documents.");
|
|
794
|
+
if (exit !== 0) {
|
|
795
|
+
if (/password|encrypted/i.test(stderr.toString()))
|
|
796
|
+
throw new PDFSafetyError("password", "This PDF is password-protected. Upload an unlocked copy.");
|
|
797
|
+
throw new PDFSafetyError("resources", "This PDF could not be processed safely. Export it as a new PDF or split it into relevant documents.");
|
|
798
|
+
}
|
|
799
|
+
return stdout;
|
|
800
|
+
} catch (error) {
|
|
801
|
+
if (error instanceof PDFSafetyError)
|
|
802
|
+
error.diagnostics = {
|
|
803
|
+
tool,
|
|
804
|
+
exitCode,
|
|
805
|
+
elapsedMs: Date.now() - started,
|
|
806
|
+
timedOut: controller.signal.aborted,
|
|
807
|
+
memoryBytes: options.memoryBytes ?? 512 * MIB,
|
|
808
|
+
maxOutputBytes: maxBytes
|
|
809
|
+
};
|
|
810
|
+
throw error;
|
|
811
|
+
} finally {
|
|
812
|
+
clearTimeout(timer);
|
|
813
|
+
signal.removeEventListener("abort", kill);
|
|
814
|
+
kill();
|
|
815
|
+
await child.exited;
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
const info = (await run("pdfinfo", [source], 64 * 1024)).toString();
|
|
819
|
+
const pages = Number(info.match(/^Pages:\s+(\d+)$/m)?.[1]);
|
|
820
|
+
if (!Number.isSafeInteger(pages) || pages < 1)
|
|
821
|
+
throw new PDFSafetyError("invalid", "No readable pages were found in this PDF.");
|
|
822
|
+
if (pages > (options.maxPages ?? 1e4))
|
|
823
|
+
throw new PDFSafetyError("pages", "This PDF contains too many pages for one intake document. Split it into relevant documents.");
|
|
824
|
+
const imageList = (await run("pdfimages", ["-list", source])).toString();
|
|
825
|
+
const imagePages = new Set(imageList.split(`
|
|
826
|
+
`).flatMap((line) => {
|
|
827
|
+
const match = line.match(/^\s*(\d+)\s+\d+\s+(?:image|mask|smask)\s/);
|
|
828
|
+
return match ? [Number(match[1])] : [];
|
|
829
|
+
}));
|
|
830
|
+
const readPage = async (page) => {
|
|
831
|
+
if (!Number.isInteger(page) || page < 1 || page > pages)
|
|
832
|
+
throw new RangeError("PDF page is outside this document");
|
|
833
|
+
const text = (await run("pdftotext", [
|
|
834
|
+
"-f",
|
|
835
|
+
String(page),
|
|
836
|
+
"-l",
|
|
837
|
+
String(page),
|
|
838
|
+
"-layout",
|
|
839
|
+
"-enc",
|
|
840
|
+
"UTF-8",
|
|
841
|
+
source,
|
|
842
|
+
"-"
|
|
843
|
+
])).toString().replaceAll("\f", "").trim();
|
|
844
|
+
let needsOCR = imagePages.has(page) || !text;
|
|
845
|
+
if (!text) {
|
|
846
|
+
const directory = await mkdtemp(join(tmpdir(), "rag-pdf-blank-"));
|
|
847
|
+
try {
|
|
848
|
+
const output = join(directory, "page");
|
|
849
|
+
await run("pdftoppm", [
|
|
850
|
+
"-f",
|
|
851
|
+
String(page),
|
|
852
|
+
"-l",
|
|
853
|
+
String(page),
|
|
854
|
+
"-singlefile",
|
|
855
|
+
"-scale-to",
|
|
856
|
+
"1600",
|
|
857
|
+
"-gray",
|
|
858
|
+
source,
|
|
859
|
+
output
|
|
860
|
+
]);
|
|
861
|
+
const file = `${output}.pgm`;
|
|
862
|
+
if ((await stat(file)).size > 4 * MIB)
|
|
863
|
+
throw new PDFSafetyError("output", "The rendered page exceeds safe processing limits.");
|
|
864
|
+
const raster = await readFile(file);
|
|
865
|
+
const header = raster.subarray(0, 100).toString("ascii").match(/^P5\n(\d+) (\d+)\n255\n/);
|
|
866
|
+
if (!header || raster.length !== header[0].length + Number(header[1]) * Number(header[2]))
|
|
867
|
+
throw new PDFSafetyError("invalid", "This PDF page could not be inspected safely.");
|
|
868
|
+
needsOCR = !raster.subarray(header[0].length).every((pixel) => pixel === 255);
|
|
869
|
+
} finally {
|
|
870
|
+
await rm(directory, { recursive: true, force: true });
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return { page, text, needsOCR };
|
|
874
|
+
};
|
|
875
|
+
const renderPage = async (page) => {
|
|
876
|
+
if (!Number.isInteger(page) || page < 1 || page > pages)
|
|
877
|
+
throw new RangeError("PDF page is outside this document");
|
|
878
|
+
const directory = await mkdtemp(join(tmpdir(), "rag-pdf-page-"));
|
|
879
|
+
try {
|
|
880
|
+
const output = join(directory, "page");
|
|
881
|
+
await run("pdftoppm", [
|
|
882
|
+
"-f",
|
|
883
|
+
String(page),
|
|
884
|
+
"-l",
|
|
885
|
+
String(page),
|
|
886
|
+
"-singlefile",
|
|
887
|
+
"-scale-to",
|
|
888
|
+
"1600",
|
|
889
|
+
"-png",
|
|
890
|
+
source,
|
|
891
|
+
output
|
|
892
|
+
]);
|
|
893
|
+
const file = `${output}.png`;
|
|
894
|
+
if ((await stat(file)).size > 16 * MIB)
|
|
895
|
+
throw new PDFSafetyError("output", "The rendered page exceeds safe processing limits.");
|
|
896
|
+
return new Uint8Array(await readFile(file));
|
|
897
|
+
} finally {
|
|
898
|
+
await rm(directory, { recursive: true, force: true });
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
return { pages, imagePages: [...imagePages], readPage, renderPage };
|
|
902
|
+
};
|
|
903
|
+
// src/pdf/checkpoint.ts
|
|
904
|
+
import { z } from "zod";
|
|
905
|
+
var pageSchema = z.object({
|
|
906
|
+
page: z.number().int().positive(),
|
|
907
|
+
text: z.string(),
|
|
908
|
+
mode: z.enum(["native", "ocr", "blank"]),
|
|
909
|
+
hybrid: z.boolean()
|
|
910
|
+
});
|
|
911
|
+
var pdfCheckpointSchema = z.object({
|
|
912
|
+
version: z.literal(1),
|
|
913
|
+
fingerprint: z.string(),
|
|
914
|
+
pageCount: z.number().int().positive(),
|
|
915
|
+
pages: z.array(pageSchema)
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
class PDFIncompleteError extends Error {
|
|
919
|
+
checkpoint;
|
|
920
|
+
failedPage;
|
|
921
|
+
nativeText;
|
|
922
|
+
constructor(checkpoint, failedPage, nativeText, cause) {
|
|
923
|
+
super(`Could not completely read PDF page ${failedPage}: ${cause instanceof Error ? cause.message : "extraction failed"}. ${checkpoint.pages.length} of ${checkpoint.pageCount} pages completed.`, { cause });
|
|
924
|
+
this.checkpoint = checkpoint;
|
|
925
|
+
this.failedPage = failedPage;
|
|
926
|
+
this.nativeText = nativeText;
|
|
927
|
+
this.name = "PDFIncompleteError";
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
// src/pdf/paged.ts
|
|
931
|
+
var createPagedPDFExtractor = (options) => ({
|
|
932
|
+
name: `absolute_pdf_paged:${options.provider.name}`,
|
|
933
|
+
supports: (input) => input.contentType === "application/pdf" || /\.pdf(?:[?#].*)?$/iu.test(input.name ?? input.path ?? input.source ?? ""),
|
|
934
|
+
extract: async (input) => {
|
|
935
|
+
options.signal?.throwIfAborted();
|
|
936
|
+
await import("pdfjs-dist/legacy/build/pdf.worker.mjs");
|
|
937
|
+
const { getDocument, OPS } = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
|
938
|
+
const task = getDocument({
|
|
939
|
+
data: Uint8Array.from(input.data),
|
|
940
|
+
disableFontFace: true,
|
|
941
|
+
useSystemFonts: true,
|
|
942
|
+
stopAtErrors: true
|
|
943
|
+
});
|
|
944
|
+
try {
|
|
945
|
+
const pdf = await task.promise;
|
|
946
|
+
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", Uint8Array.from(input.data)));
|
|
947
|
+
const fingerprint = `pdf-v1:${options.provider.name}:${Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
948
|
+
const checkpoint = {
|
|
949
|
+
version: 1,
|
|
950
|
+
fingerprint,
|
|
951
|
+
pageCount: pdf.numPages,
|
|
952
|
+
pages: []
|
|
953
|
+
};
|
|
954
|
+
const stored = await options.checkpoints?.load(fingerprint);
|
|
955
|
+
if (stored !== undefined && stored !== null) {
|
|
956
|
+
const parsed = pdfCheckpointSchema.parse(stored);
|
|
957
|
+
if (parsed.fingerprint !== fingerprint || parsed.pageCount !== pdf.numPages || parsed.pages.some((page, index) => page.page !== index + 1) || parsed.pages.length > pdf.numPages)
|
|
958
|
+
throw new Error("PDF checkpoint does not match this document or page sequence.");
|
|
959
|
+
checkpoint.pages.push(...parsed.pages);
|
|
960
|
+
}
|
|
961
|
+
const documents = [];
|
|
962
|
+
const append = (saved) => {
|
|
963
|
+
if (!saved.text)
|
|
964
|
+
return;
|
|
965
|
+
documents.push({
|
|
966
|
+
contentType: "application/pdf",
|
|
967
|
+
format: "text",
|
|
968
|
+
source: input.source ?? input.path ?? input.name ?? "document.pdf",
|
|
969
|
+
title: input.title,
|
|
970
|
+
text: saved.text,
|
|
971
|
+
metadata: {
|
|
972
|
+
...input.metadata,
|
|
973
|
+
fileKind: "pdf",
|
|
974
|
+
pageNumber: saved.page,
|
|
975
|
+
pageCount: pdf.numPages,
|
|
976
|
+
sourceNativeKind: "pdf_page",
|
|
977
|
+
pdfEvidenceMode: saved.hybrid ? "hybrid" : saved.mode,
|
|
978
|
+
pdfEvidenceOrigin: saved.mode,
|
|
979
|
+
...saved.mode === "ocr" ? { ocrEngine: options.provider.name } : {}
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
};
|
|
983
|
+
let original;
|
|
984
|
+
const imageOperators = new Set([
|
|
985
|
+
OPS.paintImageXObject,
|
|
986
|
+
OPS.paintInlineImageXObject,
|
|
987
|
+
OPS.paintImageMaskXObject,
|
|
988
|
+
OPS.paintImageXObjectRepeat,
|
|
989
|
+
OPS.paintImageMaskXObjectRepeat,
|
|
990
|
+
OPS.paintInlineImageXObjectGroup,
|
|
991
|
+
OPS.paintImageMaskXObjectGroup
|
|
992
|
+
]);
|
|
993
|
+
for (let pageNumber = 1;pageNumber <= pdf.numPages; pageNumber++) {
|
|
994
|
+
let page;
|
|
995
|
+
let nativeText = "";
|
|
996
|
+
try {
|
|
997
|
+
options.signal?.throwIfAborted();
|
|
998
|
+
const cached = checkpoint.pages[pageNumber - 1];
|
|
999
|
+
if (cached) {
|
|
1000
|
+
append(cached);
|
|
1001
|
+
options.onProgress?.({
|
|
1002
|
+
page: pageNumber,
|
|
1003
|
+
pageCount: pdf.numPages,
|
|
1004
|
+
mode: cached.mode
|
|
1005
|
+
});
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
1008
|
+
page = await pdf.getPage(pageNumber);
|
|
1009
|
+
const content = await page.getTextContent();
|
|
1010
|
+
nativeText = content.items.map((item) => ("str" in item) ? `${item.str}${item.hasEOL ? `
|
|
1011
|
+
` : " "}` : "").join("").trim();
|
|
1012
|
+
const operations = await page.getOperatorList();
|
|
1013
|
+
const needsOCR = !nativeText && operations.fnArray.length > 0 || operations.fnArray.some((operation) => imageOperators.has(operation));
|
|
1014
|
+
let text = nativeText;
|
|
1015
|
+
let mode = nativeText ? "native" : "blank";
|
|
1016
|
+
if (needsOCR) {
|
|
1017
|
+
const { PDFDocument } = await import("pdf-lib");
|
|
1018
|
+
original ??= await PDFDocument.load(input.data);
|
|
1019
|
+
const single = await PDFDocument.create();
|
|
1020
|
+
const [copied] = await single.copyPages(original, [pageNumber - 1]);
|
|
1021
|
+
single.addPage(copied);
|
|
1022
|
+
const result = await options.provider.extractText({
|
|
1023
|
+
...input,
|
|
1024
|
+
contentType: "application/pdf",
|
|
1025
|
+
data: await single.save(),
|
|
1026
|
+
metadata: {
|
|
1027
|
+
...input.metadata,
|
|
1028
|
+
pageNumber,
|
|
1029
|
+
pageCount: pdf.numPages
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
const extracted = result.text.trim();
|
|
1033
|
+
if (!extracted)
|
|
1034
|
+
throw new Error(`OCR returned no readable text for PDF page ${pageNumber}.`);
|
|
1035
|
+
text = nativeText && !extracted.includes(nativeText) ? `${nativeText}
|
|
1036
|
+
|
|
1037
|
+
${extracted}` : extracted;
|
|
1038
|
+
mode = "ocr";
|
|
1039
|
+
}
|
|
1040
|
+
const saved = {
|
|
1041
|
+
page: pageNumber,
|
|
1042
|
+
text,
|
|
1043
|
+
mode,
|
|
1044
|
+
hybrid: mode === "ocr" && Boolean(nativeText)
|
|
1045
|
+
};
|
|
1046
|
+
checkpoint.pages.push(saved);
|
|
1047
|
+
append(saved);
|
|
1048
|
+
await options.checkpoints?.save(structuredClone(checkpoint));
|
|
1049
|
+
options.onProgress?.({
|
|
1050
|
+
page: pageNumber,
|
|
1051
|
+
pageCount: pdf.numPages,
|
|
1052
|
+
mode
|
|
1053
|
+
});
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
throw new PDFIncompleteError(structuredClone(checkpoint), pageNumber, nativeText, error);
|
|
1056
|
+
} finally {
|
|
1057
|
+
page?.cleanup();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
if (!documents.length)
|
|
1061
|
+
throw new Error("No readable text found in this PDF.");
|
|
1062
|
+
return documents;
|
|
1063
|
+
} finally {
|
|
1064
|
+
await task.destroy();
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
// src/read.ts
|
|
1069
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
1070
|
+
import { basename } from "path";
|
|
1071
|
+
var readDocuments = (input, options = {}) => extractDocuments2(input, options.extractors, options.registry ?? input.extractorRegistry);
|
|
1072
|
+
var readDocument = async (input, options = {}) => getFirstExtractedDocument2(await readDocuments(input, options), "for this file");
|
|
1073
|
+
var readDocumentFile = async (path, input = {}, options = {}) => readDocument({ ...input, data: await readFile2(path), path }, options);
|
|
1074
|
+
var readDocumentUploads = async (uploads, options = {}) => {
|
|
1075
|
+
const documents = (await Promise.all(uploads.map((upload) => readDocuments({
|
|
1076
|
+
contentType: upload.contentType,
|
|
1077
|
+
data: decodeUploadContent2(upload),
|
|
1078
|
+
format: upload.format,
|
|
1079
|
+
metadata: upload.metadata,
|
|
1080
|
+
name: upload.name,
|
|
1081
|
+
source: upload.source ?? upload.name,
|
|
1082
|
+
title: upload.title
|
|
1083
|
+
}, options)))).flat();
|
|
1084
|
+
return reconcileLoadedEmailThreads2(documents);
|
|
1085
|
+
};
|
|
1086
|
+
var readWebDocument = async (input) => {
|
|
1087
|
+
const document = await readDocument({
|
|
1088
|
+
contentType: input.contentType || undefined,
|
|
1089
|
+
data: input.body,
|
|
1090
|
+
format: inferFormatFromContentType2(input.contentType || null) ?? inferFormatFromUrl2(input.url),
|
|
1091
|
+
name: basename(new URL(input.url).pathname) || undefined,
|
|
1092
|
+
source: input.url
|
|
1093
|
+
});
|
|
1094
|
+
return { text: document.text, title: document.title ?? null };
|
|
1095
|
+
};
|
|
1096
|
+
export {
|
|
1097
|
+
PDFIncompleteError,
|
|
1098
|
+
PDFSafetyError,
|
|
1099
|
+
authoredEmailText2 as authoredEmailText,
|
|
1100
|
+
createArchiveExpander,
|
|
1101
|
+
createArchiveFileExtractor2 as createArchiveFileExtractor,
|
|
1102
|
+
createBuiltinArchiveExpander2 as createBuiltinArchiveExpander,
|
|
1103
|
+
createEPUBExtractor2 as createEPUBExtractor,
|
|
1104
|
+
createEmailExtractor2 as createEmailExtractor,
|
|
1105
|
+
createExtractorRegistry,
|
|
1106
|
+
createFileExtractor,
|
|
1107
|
+
createImageOCRExtractor,
|
|
1108
|
+
createLegacyDocumentExtractor2 as createLegacyDocumentExtractor,
|
|
1109
|
+
createMailboxContainerExtractor2 as createMailboxContainerExtractor,
|
|
1110
|
+
createMediaFileExtractor,
|
|
1111
|
+
createMediaTranscriber,
|
|
1112
|
+
createOCRProvider,
|
|
1113
|
+
createOfficeDocumentExtractor2 as createOfficeDocumentExtractor,
|
|
1114
|
+
createPDFFileExtractor2 as createPDFFileExtractor,
|
|
1115
|
+
createPDFOCRExtractor,
|
|
1116
|
+
createPagedPDFExtractor,
|
|
1117
|
+
createTextFileExtractor2 as createTextFileExtractor,
|
|
1118
|
+
extractDocuments2 as extractDocuments,
|
|
1119
|
+
inspectBoundedPDF,
|
|
1120
|
+
pdfCheckpointSchema,
|
|
1121
|
+
readDocument,
|
|
1122
|
+
readDocumentFile,
|
|
1123
|
+
readDocumentUploads,
|
|
1124
|
+
readDocuments,
|
|
1125
|
+
readWebDocument
|
|
1126
|
+
};
|