@heripo/document-processor 0.1.16 → 0.1.18
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/README.ko.md +28 -16
- package/README.md +28 -16
- package/dist/index.cjs +649 -688
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +156 -69
- package/dist/index.d.ts +156 -69
- package/dist/index.js +644 -687
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -60,8 +60,8 @@ interface DocumentProcessorOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
maxRetries?: number;
|
|
62
62
|
/**
|
|
63
|
-
* Enable fallback retry mechanism - automatically retries with fallback model on failure (default:
|
|
64
|
-
* Set to
|
|
63
|
+
* Enable fallback retry mechanism - automatically retries with fallback model on failure (default: false)
|
|
64
|
+
* Set to true to enable automatic fallback retry with fallback model on component-specific model errors
|
|
65
65
|
*/
|
|
66
66
|
enableFallbackRetry?: boolean;
|
|
67
67
|
/**
|
|
@@ -155,7 +155,9 @@ declare class DocumentProcessor {
|
|
|
155
155
|
private visionTocExtractor?;
|
|
156
156
|
private captionParser?;
|
|
157
157
|
private chapterConverter?;
|
|
158
|
-
private
|
|
158
|
+
private resourceConverter?;
|
|
159
|
+
private tocExtractionPipeline?;
|
|
160
|
+
private captionProcessingPipeline?;
|
|
159
161
|
private readonly usageAggregator;
|
|
160
162
|
constructor(options: DocumentProcessorOptions);
|
|
161
163
|
/**
|
|
@@ -214,77 +216,12 @@ declare class DocumentProcessor {
|
|
|
214
216
|
* Token usage is automatically tracked by PageRangeParser into the shared aggregator.
|
|
215
217
|
*/
|
|
216
218
|
private parsePageRanges;
|
|
217
|
-
/**
|
|
218
|
-
* Convert images, tables, and footnotes
|
|
219
|
-
*
|
|
220
|
-
* Runs conversions:
|
|
221
|
-
* - Images conversion (with caption extraction)
|
|
222
|
-
* - Tables conversion (with caption extraction, excluding TOC tables)
|
|
223
|
-
* - Footnotes conversion (synchronous, from text items with label='footnote')
|
|
224
|
-
*/
|
|
225
|
-
private convertResources;
|
|
226
|
-
/**
|
|
227
|
-
* Convert footnotes
|
|
228
|
-
*
|
|
229
|
-
* Extracts footnotes from DoclingDocument text items with label='footnote'
|
|
230
|
-
*/
|
|
231
|
-
private convertFootnotes;
|
|
232
219
|
/**
|
|
233
220
|
* Assemble the final ProcessedDocument
|
|
234
221
|
*
|
|
235
222
|
* Creates the ProcessedDocument structure with all converted components
|
|
236
223
|
*/
|
|
237
224
|
private assembleProcessedDocument;
|
|
238
|
-
/**
|
|
239
|
-
* Extract table of contents (TOC)
|
|
240
|
-
*
|
|
241
|
-
* Uses rule-based extraction with LLM validation and vision fallback:
|
|
242
|
-
* 1. TocFinder - find TOC area in document (rule-based)
|
|
243
|
-
* 2. MarkdownConverter - convert TOC items to Markdown
|
|
244
|
-
* 3. TocContentValidator - validate if content is actually a TOC (LLM)
|
|
245
|
-
* 4. If invalid: VisionTocExtractor - extract from page images (vision LLM fallback)
|
|
246
|
-
* 5. TocExtractor - LLM-based structured extraction
|
|
247
|
-
*/
|
|
248
|
-
private extractTableOfContents;
|
|
249
|
-
/**
|
|
250
|
-
* Extract the maximum page number from TOC markdown
|
|
251
|
-
*
|
|
252
|
-
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
253
|
-
* and table cell patterns (e.g., "| title | 175 |") to detect compiled
|
|
254
|
-
* volume scenarios where TOC page numbers exceed the sub-document's page count.
|
|
255
|
-
*/
|
|
256
|
-
private extractMaxPageNumber;
|
|
257
|
-
/**
|
|
258
|
-
* Process resource captions (for images and tables)
|
|
259
|
-
*
|
|
260
|
-
* Common caption processing pipeline:
|
|
261
|
-
* 1. Parse captions in batch
|
|
262
|
-
* 2. Validate parsed captions
|
|
263
|
-
* 3. Reparse failed captions with fallback model
|
|
264
|
-
*
|
|
265
|
-
* @param captionTexts - Array of caption texts to process
|
|
266
|
-
* @param resourceType - Type of resource for logging (e.g., 'image', 'table')
|
|
267
|
-
* @returns Parsed captions with index mapping
|
|
268
|
-
*/
|
|
269
|
-
private processResourceCaptions;
|
|
270
|
-
/**
|
|
271
|
-
* Extract caption text from resource
|
|
272
|
-
*
|
|
273
|
-
* Handles both string references and $ref resolution
|
|
274
|
-
*/
|
|
275
|
-
private extractCaptionText;
|
|
276
|
-
/**
|
|
277
|
-
* Convert images
|
|
278
|
-
*
|
|
279
|
-
* Converts pictures from DoclingDocument to ProcessedImage
|
|
280
|
-
*/
|
|
281
|
-
private convertImages;
|
|
282
|
-
/**
|
|
283
|
-
* Convert tables
|
|
284
|
-
*
|
|
285
|
-
* Converts tables from DoclingDocument to ProcessedTable
|
|
286
|
-
*/
|
|
287
|
-
private convertTables;
|
|
288
225
|
/**
|
|
289
226
|
* Convert chapters and link resources
|
|
290
227
|
*
|
|
@@ -924,6 +861,18 @@ declare class IdGenerator {
|
|
|
924
861
|
private padNumber;
|
|
925
862
|
}
|
|
926
863
|
|
|
864
|
+
/**
|
|
865
|
+
* Extract the maximum page number from TOC markdown
|
|
866
|
+
*
|
|
867
|
+
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
868
|
+
* and table cell patterns (e.g., "| title | 175 |") to detect compiled
|
|
869
|
+
* volume scenarios where TOC page numbers exceed the sub-document's page count.
|
|
870
|
+
*
|
|
871
|
+
* @param markdown - TOC markdown content
|
|
872
|
+
* @returns Maximum page number found, or 0 if none found
|
|
873
|
+
*/
|
|
874
|
+
declare function extractMaxPageNumber(markdown: string): number;
|
|
875
|
+
|
|
927
876
|
/**
|
|
928
877
|
* TOC keyword patterns for different languages
|
|
929
878
|
* Korean: 목차, 차례, 목 차
|
|
@@ -1508,4 +1457,142 @@ declare class ChapterConverter {
|
|
|
1508
1457
|
private buildChapterMap;
|
|
1509
1458
|
}
|
|
1510
1459
|
|
|
1511
|
-
|
|
1460
|
+
/**
|
|
1461
|
+
* Dependencies required by CaptionProcessingPipeline
|
|
1462
|
+
*/
|
|
1463
|
+
interface CaptionProcessingPipelineDeps {
|
|
1464
|
+
logger: LoggerMethods;
|
|
1465
|
+
captionParser: CaptionParser;
|
|
1466
|
+
captionValidator: CaptionValidator;
|
|
1467
|
+
refResolver?: RefResolver;
|
|
1468
|
+
fallbackModel: LanguageModel;
|
|
1469
|
+
enableFallbackRetry: boolean;
|
|
1470
|
+
maxRetries: number;
|
|
1471
|
+
captionParserBatchSize: number;
|
|
1472
|
+
captionValidatorBatchSize: number;
|
|
1473
|
+
usageAggregator: LLMTokenUsageAggregator;
|
|
1474
|
+
abortSignal?: AbortSignal;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* CaptionProcessingPipeline
|
|
1478
|
+
*
|
|
1479
|
+
* Processes resource captions through a multi-step pipeline:
|
|
1480
|
+
* 1. Parse captions in batch (CaptionParser)
|
|
1481
|
+
* 2. Handle length mismatch recovery
|
|
1482
|
+
* 3. Validate parsed captions (CaptionValidator)
|
|
1483
|
+
* 4. Reparse failed captions with fallback model
|
|
1484
|
+
*/
|
|
1485
|
+
declare class CaptionProcessingPipeline {
|
|
1486
|
+
private readonly logger;
|
|
1487
|
+
private readonly captionParser;
|
|
1488
|
+
private readonly captionValidator;
|
|
1489
|
+
private readonly refResolver?;
|
|
1490
|
+
private readonly fallbackModel;
|
|
1491
|
+
private readonly enableFallbackRetry;
|
|
1492
|
+
private readonly maxRetries;
|
|
1493
|
+
private readonly captionParserBatchSize;
|
|
1494
|
+
private readonly captionValidatorBatchSize;
|
|
1495
|
+
private readonly usageAggregator;
|
|
1496
|
+
private readonly abortSignal?;
|
|
1497
|
+
constructor(deps: CaptionProcessingPipelineDeps);
|
|
1498
|
+
/**
|
|
1499
|
+
* Process resource captions (for images and tables)
|
|
1500
|
+
*
|
|
1501
|
+
* Common caption processing pipeline:
|
|
1502
|
+
* 1. Parse captions in batch
|
|
1503
|
+
* 2. Validate parsed captions
|
|
1504
|
+
* 3. Reparse failed captions with fallback model
|
|
1505
|
+
*
|
|
1506
|
+
* @param captionTexts - Array of caption texts to process
|
|
1507
|
+
* @param resourceType - Type of resource for logging (e.g., 'image', 'table')
|
|
1508
|
+
* @returns Parsed captions with index mapping
|
|
1509
|
+
*/
|
|
1510
|
+
processResourceCaptions(captionTexts: Array<string | undefined>, resourceType: string): Promise<Map<number, Caption>>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Extract caption text from resource
|
|
1513
|
+
*
|
|
1514
|
+
* Handles both string references and $ref resolution
|
|
1515
|
+
*/
|
|
1516
|
+
extractCaptionText(captions: Array<string | {
|
|
1517
|
+
$ref: string;
|
|
1518
|
+
}> | undefined): string | undefined;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* Dependencies required by TocExtractionPipeline
|
|
1523
|
+
*/
|
|
1524
|
+
interface TocExtractionPipelineDeps {
|
|
1525
|
+
logger: LoggerMethods;
|
|
1526
|
+
tocFinder: TocFinder;
|
|
1527
|
+
tocExtractor: TocExtractor;
|
|
1528
|
+
tocContentValidator: TocContentValidator;
|
|
1529
|
+
visionTocExtractor: VisionTocExtractor;
|
|
1530
|
+
refResolver: RefResolver;
|
|
1531
|
+
usageAggregator: LLMTokenUsageAggregator;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* TocExtractionPipeline
|
|
1535
|
+
*
|
|
1536
|
+
* Orchestrates the multi-stage TOC extraction process:
|
|
1537
|
+
* 1. Rule-based extraction (TocFinder + MarkdownConverter)
|
|
1538
|
+
* 2. Content validation (TocContentValidator)
|
|
1539
|
+
* 3. Vision fallback (VisionTocExtractor)
|
|
1540
|
+
* 4. Structured extraction with validation retry (TocExtractor)
|
|
1541
|
+
* 5. Vision fallback retry when text-based extraction yields 0 entries
|
|
1542
|
+
*/
|
|
1543
|
+
declare class TocExtractionPipeline {
|
|
1544
|
+
private readonly logger;
|
|
1545
|
+
private readonly tocFinder;
|
|
1546
|
+
private readonly tocExtractor;
|
|
1547
|
+
private readonly tocContentValidator;
|
|
1548
|
+
private readonly visionTocExtractor;
|
|
1549
|
+
private readonly refResolver;
|
|
1550
|
+
private readonly usageAggregator;
|
|
1551
|
+
constructor(deps: TocExtractionPipelineDeps);
|
|
1552
|
+
/**
|
|
1553
|
+
* Execute the TOC extraction pipeline
|
|
1554
|
+
*
|
|
1555
|
+
* @param doclingDoc - Document containing texts, pages, etc.
|
|
1556
|
+
* @param _filteredTexts - Pre-filtered texts (reserved for future use)
|
|
1557
|
+
* @returns Extracted TOC entries
|
|
1558
|
+
* @throws {TocNotFoundError} When TOC cannot be found or extracted
|
|
1559
|
+
*/
|
|
1560
|
+
extract(doclingDoc: DoclingDocument, _filteredTexts: string[]): Promise<TocEntry[]>;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
/**
|
|
1564
|
+
* ResourceConverter
|
|
1565
|
+
*
|
|
1566
|
+
* Converts DoclingDocument resources (images, tables, footnotes) to processed format.
|
|
1567
|
+
* Uses CaptionProcessingPipeline for caption extraction and validation.
|
|
1568
|
+
*/
|
|
1569
|
+
declare class ResourceConverter {
|
|
1570
|
+
private readonly logger;
|
|
1571
|
+
private readonly idGenerator;
|
|
1572
|
+
private readonly captionProcessingPipeline;
|
|
1573
|
+
constructor(logger: LoggerMethods, idGenerator: IdGenerator, captionProcessingPipeline: CaptionProcessingPipeline);
|
|
1574
|
+
/**
|
|
1575
|
+
* Convert all resources (images, tables, footnotes)
|
|
1576
|
+
*
|
|
1577
|
+
* Runs image and table conversions in parallel, then footnotes synchronously.
|
|
1578
|
+
*/
|
|
1579
|
+
convertAll(doclingDoc: DoclingDocument, outputPath: string): Promise<{
|
|
1580
|
+
images: ProcessedImage[];
|
|
1581
|
+
tables: ProcessedTable[];
|
|
1582
|
+
footnotes: ProcessedFootnote[];
|
|
1583
|
+
}>;
|
|
1584
|
+
/**
|
|
1585
|
+
* Convert images from DoclingDocument to ProcessedImage[]
|
|
1586
|
+
*/
|
|
1587
|
+
convertImages(doclingDoc: DoclingDocument, outputPath: string): Promise<ProcessedImage[]>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Convert tables from DoclingDocument to ProcessedTable[]
|
|
1590
|
+
*/
|
|
1591
|
+
convertTables(doclingDoc: DoclingDocument): Promise<ProcessedTable[]>;
|
|
1592
|
+
/**
|
|
1593
|
+
* Convert footnotes from DoclingDocument text items
|
|
1594
|
+
*/
|
|
1595
|
+
convertFootnotes(doclingDoc: DoclingDocument): ProcessedFootnote[];
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
export { BaseLLMComponent, type BaseLLMComponentOptions, BaseValidator, type BaseValidatorOptions, CONTINUATION_MARKERS, CaptionParseError, CaptionParser, type CaptionParserOptions, CaptionProcessingPipeline, type CaptionProcessingPipelineDeps, CaptionValidationError, CaptionValidator, type CaptionValidatorOptions, ChapterConverter, DocumentProcessor, type DocumentProcessorOptions, type ImageContent, PAGE_NUMBER_PATTERN, PagePattern, PageRangeParseError, PageRangeParser, type PageSizeGroup, ResourceConverter, TOC_KEYWORDS, TextLLMComponent, type TocAreaResult, type TocContentValidationResult, TocContentValidationSchema, TocContentValidator, type TocContentValidatorOptions, type TocEntry, TocEntrySchema, TocExtractError, TocExtractionPipeline, type TocExtractionPipelineDeps, TocExtractor, type TocExtractorOptions, TocFinder, type TocFinderOptions, TocNotFoundError, TocParseError, type TocResponse, TocResponseSchema, VisionLLMComponent, type VisionLLMComponentOptions, type VisionTocExtractionResult, VisionTocExtractionSchema, VisionTocExtractor, type VisionTocExtractorOptions, extractMaxPageNumber };
|
package/dist/index.d.ts
CHANGED
|
@@ -60,8 +60,8 @@ interface DocumentProcessorOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
maxRetries?: number;
|
|
62
62
|
/**
|
|
63
|
-
* Enable fallback retry mechanism - automatically retries with fallback model on failure (default:
|
|
64
|
-
* Set to
|
|
63
|
+
* Enable fallback retry mechanism - automatically retries with fallback model on failure (default: false)
|
|
64
|
+
* Set to true to enable automatic fallback retry with fallback model on component-specific model errors
|
|
65
65
|
*/
|
|
66
66
|
enableFallbackRetry?: boolean;
|
|
67
67
|
/**
|
|
@@ -155,7 +155,9 @@ declare class DocumentProcessor {
|
|
|
155
155
|
private visionTocExtractor?;
|
|
156
156
|
private captionParser?;
|
|
157
157
|
private chapterConverter?;
|
|
158
|
-
private
|
|
158
|
+
private resourceConverter?;
|
|
159
|
+
private tocExtractionPipeline?;
|
|
160
|
+
private captionProcessingPipeline?;
|
|
159
161
|
private readonly usageAggregator;
|
|
160
162
|
constructor(options: DocumentProcessorOptions);
|
|
161
163
|
/**
|
|
@@ -214,77 +216,12 @@ declare class DocumentProcessor {
|
|
|
214
216
|
* Token usage is automatically tracked by PageRangeParser into the shared aggregator.
|
|
215
217
|
*/
|
|
216
218
|
private parsePageRanges;
|
|
217
|
-
/**
|
|
218
|
-
* Convert images, tables, and footnotes
|
|
219
|
-
*
|
|
220
|
-
* Runs conversions:
|
|
221
|
-
* - Images conversion (with caption extraction)
|
|
222
|
-
* - Tables conversion (with caption extraction, excluding TOC tables)
|
|
223
|
-
* - Footnotes conversion (synchronous, from text items with label='footnote')
|
|
224
|
-
*/
|
|
225
|
-
private convertResources;
|
|
226
|
-
/**
|
|
227
|
-
* Convert footnotes
|
|
228
|
-
*
|
|
229
|
-
* Extracts footnotes from DoclingDocument text items with label='footnote'
|
|
230
|
-
*/
|
|
231
|
-
private convertFootnotes;
|
|
232
219
|
/**
|
|
233
220
|
* Assemble the final ProcessedDocument
|
|
234
221
|
*
|
|
235
222
|
* Creates the ProcessedDocument structure with all converted components
|
|
236
223
|
*/
|
|
237
224
|
private assembleProcessedDocument;
|
|
238
|
-
/**
|
|
239
|
-
* Extract table of contents (TOC)
|
|
240
|
-
*
|
|
241
|
-
* Uses rule-based extraction with LLM validation and vision fallback:
|
|
242
|
-
* 1. TocFinder - find TOC area in document (rule-based)
|
|
243
|
-
* 2. MarkdownConverter - convert TOC items to Markdown
|
|
244
|
-
* 3. TocContentValidator - validate if content is actually a TOC (LLM)
|
|
245
|
-
* 4. If invalid: VisionTocExtractor - extract from page images (vision LLM fallback)
|
|
246
|
-
* 5. TocExtractor - LLM-based structured extraction
|
|
247
|
-
*/
|
|
248
|
-
private extractTableOfContents;
|
|
249
|
-
/**
|
|
250
|
-
* Extract the maximum page number from TOC markdown
|
|
251
|
-
*
|
|
252
|
-
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
253
|
-
* and table cell patterns (e.g., "| title | 175 |") to detect compiled
|
|
254
|
-
* volume scenarios where TOC page numbers exceed the sub-document's page count.
|
|
255
|
-
*/
|
|
256
|
-
private extractMaxPageNumber;
|
|
257
|
-
/**
|
|
258
|
-
* Process resource captions (for images and tables)
|
|
259
|
-
*
|
|
260
|
-
* Common caption processing pipeline:
|
|
261
|
-
* 1. Parse captions in batch
|
|
262
|
-
* 2. Validate parsed captions
|
|
263
|
-
* 3. Reparse failed captions with fallback model
|
|
264
|
-
*
|
|
265
|
-
* @param captionTexts - Array of caption texts to process
|
|
266
|
-
* @param resourceType - Type of resource for logging (e.g., 'image', 'table')
|
|
267
|
-
* @returns Parsed captions with index mapping
|
|
268
|
-
*/
|
|
269
|
-
private processResourceCaptions;
|
|
270
|
-
/**
|
|
271
|
-
* Extract caption text from resource
|
|
272
|
-
*
|
|
273
|
-
* Handles both string references and $ref resolution
|
|
274
|
-
*/
|
|
275
|
-
private extractCaptionText;
|
|
276
|
-
/**
|
|
277
|
-
* Convert images
|
|
278
|
-
*
|
|
279
|
-
* Converts pictures from DoclingDocument to ProcessedImage
|
|
280
|
-
*/
|
|
281
|
-
private convertImages;
|
|
282
|
-
/**
|
|
283
|
-
* Convert tables
|
|
284
|
-
*
|
|
285
|
-
* Converts tables from DoclingDocument to ProcessedTable
|
|
286
|
-
*/
|
|
287
|
-
private convertTables;
|
|
288
225
|
/**
|
|
289
226
|
* Convert chapters and link resources
|
|
290
227
|
*
|
|
@@ -924,6 +861,18 @@ declare class IdGenerator {
|
|
|
924
861
|
private padNumber;
|
|
925
862
|
}
|
|
926
863
|
|
|
864
|
+
/**
|
|
865
|
+
* Extract the maximum page number from TOC markdown
|
|
866
|
+
*
|
|
867
|
+
* Parses page numbers from dot-leader patterns (e.g., "..... 175")
|
|
868
|
+
* and table cell patterns (e.g., "| title | 175 |") to detect compiled
|
|
869
|
+
* volume scenarios where TOC page numbers exceed the sub-document's page count.
|
|
870
|
+
*
|
|
871
|
+
* @param markdown - TOC markdown content
|
|
872
|
+
* @returns Maximum page number found, or 0 if none found
|
|
873
|
+
*/
|
|
874
|
+
declare function extractMaxPageNumber(markdown: string): number;
|
|
875
|
+
|
|
927
876
|
/**
|
|
928
877
|
* TOC keyword patterns for different languages
|
|
929
878
|
* Korean: 목차, 차례, 목 차
|
|
@@ -1508,4 +1457,142 @@ declare class ChapterConverter {
|
|
|
1508
1457
|
private buildChapterMap;
|
|
1509
1458
|
}
|
|
1510
1459
|
|
|
1511
|
-
|
|
1460
|
+
/**
|
|
1461
|
+
* Dependencies required by CaptionProcessingPipeline
|
|
1462
|
+
*/
|
|
1463
|
+
interface CaptionProcessingPipelineDeps {
|
|
1464
|
+
logger: LoggerMethods;
|
|
1465
|
+
captionParser: CaptionParser;
|
|
1466
|
+
captionValidator: CaptionValidator;
|
|
1467
|
+
refResolver?: RefResolver;
|
|
1468
|
+
fallbackModel: LanguageModel;
|
|
1469
|
+
enableFallbackRetry: boolean;
|
|
1470
|
+
maxRetries: number;
|
|
1471
|
+
captionParserBatchSize: number;
|
|
1472
|
+
captionValidatorBatchSize: number;
|
|
1473
|
+
usageAggregator: LLMTokenUsageAggregator;
|
|
1474
|
+
abortSignal?: AbortSignal;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* CaptionProcessingPipeline
|
|
1478
|
+
*
|
|
1479
|
+
* Processes resource captions through a multi-step pipeline:
|
|
1480
|
+
* 1. Parse captions in batch (CaptionParser)
|
|
1481
|
+
* 2. Handle length mismatch recovery
|
|
1482
|
+
* 3. Validate parsed captions (CaptionValidator)
|
|
1483
|
+
* 4. Reparse failed captions with fallback model
|
|
1484
|
+
*/
|
|
1485
|
+
declare class CaptionProcessingPipeline {
|
|
1486
|
+
private readonly logger;
|
|
1487
|
+
private readonly captionParser;
|
|
1488
|
+
private readonly captionValidator;
|
|
1489
|
+
private readonly refResolver?;
|
|
1490
|
+
private readonly fallbackModel;
|
|
1491
|
+
private readonly enableFallbackRetry;
|
|
1492
|
+
private readonly maxRetries;
|
|
1493
|
+
private readonly captionParserBatchSize;
|
|
1494
|
+
private readonly captionValidatorBatchSize;
|
|
1495
|
+
private readonly usageAggregator;
|
|
1496
|
+
private readonly abortSignal?;
|
|
1497
|
+
constructor(deps: CaptionProcessingPipelineDeps);
|
|
1498
|
+
/**
|
|
1499
|
+
* Process resource captions (for images and tables)
|
|
1500
|
+
*
|
|
1501
|
+
* Common caption processing pipeline:
|
|
1502
|
+
* 1. Parse captions in batch
|
|
1503
|
+
* 2. Validate parsed captions
|
|
1504
|
+
* 3. Reparse failed captions with fallback model
|
|
1505
|
+
*
|
|
1506
|
+
* @param captionTexts - Array of caption texts to process
|
|
1507
|
+
* @param resourceType - Type of resource for logging (e.g., 'image', 'table')
|
|
1508
|
+
* @returns Parsed captions with index mapping
|
|
1509
|
+
*/
|
|
1510
|
+
processResourceCaptions(captionTexts: Array<string | undefined>, resourceType: string): Promise<Map<number, Caption>>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Extract caption text from resource
|
|
1513
|
+
*
|
|
1514
|
+
* Handles both string references and $ref resolution
|
|
1515
|
+
*/
|
|
1516
|
+
extractCaptionText(captions: Array<string | {
|
|
1517
|
+
$ref: string;
|
|
1518
|
+
}> | undefined): string | undefined;
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* Dependencies required by TocExtractionPipeline
|
|
1523
|
+
*/
|
|
1524
|
+
interface TocExtractionPipelineDeps {
|
|
1525
|
+
logger: LoggerMethods;
|
|
1526
|
+
tocFinder: TocFinder;
|
|
1527
|
+
tocExtractor: TocExtractor;
|
|
1528
|
+
tocContentValidator: TocContentValidator;
|
|
1529
|
+
visionTocExtractor: VisionTocExtractor;
|
|
1530
|
+
refResolver: RefResolver;
|
|
1531
|
+
usageAggregator: LLMTokenUsageAggregator;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* TocExtractionPipeline
|
|
1535
|
+
*
|
|
1536
|
+
* Orchestrates the multi-stage TOC extraction process:
|
|
1537
|
+
* 1. Rule-based extraction (TocFinder + MarkdownConverter)
|
|
1538
|
+
* 2. Content validation (TocContentValidator)
|
|
1539
|
+
* 3. Vision fallback (VisionTocExtractor)
|
|
1540
|
+
* 4. Structured extraction with validation retry (TocExtractor)
|
|
1541
|
+
* 5. Vision fallback retry when text-based extraction yields 0 entries
|
|
1542
|
+
*/
|
|
1543
|
+
declare class TocExtractionPipeline {
|
|
1544
|
+
private readonly logger;
|
|
1545
|
+
private readonly tocFinder;
|
|
1546
|
+
private readonly tocExtractor;
|
|
1547
|
+
private readonly tocContentValidator;
|
|
1548
|
+
private readonly visionTocExtractor;
|
|
1549
|
+
private readonly refResolver;
|
|
1550
|
+
private readonly usageAggregator;
|
|
1551
|
+
constructor(deps: TocExtractionPipelineDeps);
|
|
1552
|
+
/**
|
|
1553
|
+
* Execute the TOC extraction pipeline
|
|
1554
|
+
*
|
|
1555
|
+
* @param doclingDoc - Document containing texts, pages, etc.
|
|
1556
|
+
* @param _filteredTexts - Pre-filtered texts (reserved for future use)
|
|
1557
|
+
* @returns Extracted TOC entries
|
|
1558
|
+
* @throws {TocNotFoundError} When TOC cannot be found or extracted
|
|
1559
|
+
*/
|
|
1560
|
+
extract(doclingDoc: DoclingDocument, _filteredTexts: string[]): Promise<TocEntry[]>;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
/**
|
|
1564
|
+
* ResourceConverter
|
|
1565
|
+
*
|
|
1566
|
+
* Converts DoclingDocument resources (images, tables, footnotes) to processed format.
|
|
1567
|
+
* Uses CaptionProcessingPipeline for caption extraction and validation.
|
|
1568
|
+
*/
|
|
1569
|
+
declare class ResourceConverter {
|
|
1570
|
+
private readonly logger;
|
|
1571
|
+
private readonly idGenerator;
|
|
1572
|
+
private readonly captionProcessingPipeline;
|
|
1573
|
+
constructor(logger: LoggerMethods, idGenerator: IdGenerator, captionProcessingPipeline: CaptionProcessingPipeline);
|
|
1574
|
+
/**
|
|
1575
|
+
* Convert all resources (images, tables, footnotes)
|
|
1576
|
+
*
|
|
1577
|
+
* Runs image and table conversions in parallel, then footnotes synchronously.
|
|
1578
|
+
*/
|
|
1579
|
+
convertAll(doclingDoc: DoclingDocument, outputPath: string): Promise<{
|
|
1580
|
+
images: ProcessedImage[];
|
|
1581
|
+
tables: ProcessedTable[];
|
|
1582
|
+
footnotes: ProcessedFootnote[];
|
|
1583
|
+
}>;
|
|
1584
|
+
/**
|
|
1585
|
+
* Convert images from DoclingDocument to ProcessedImage[]
|
|
1586
|
+
*/
|
|
1587
|
+
convertImages(doclingDoc: DoclingDocument, outputPath: string): Promise<ProcessedImage[]>;
|
|
1588
|
+
/**
|
|
1589
|
+
* Convert tables from DoclingDocument to ProcessedTable[]
|
|
1590
|
+
*/
|
|
1591
|
+
convertTables(doclingDoc: DoclingDocument): Promise<ProcessedTable[]>;
|
|
1592
|
+
/**
|
|
1593
|
+
* Convert footnotes from DoclingDocument text items
|
|
1594
|
+
*/
|
|
1595
|
+
convertFootnotes(doclingDoc: DoclingDocument): ProcessedFootnote[];
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
export { BaseLLMComponent, type BaseLLMComponentOptions, BaseValidator, type BaseValidatorOptions, CONTINUATION_MARKERS, CaptionParseError, CaptionParser, type CaptionParserOptions, CaptionProcessingPipeline, type CaptionProcessingPipelineDeps, CaptionValidationError, CaptionValidator, type CaptionValidatorOptions, ChapterConverter, DocumentProcessor, type DocumentProcessorOptions, type ImageContent, PAGE_NUMBER_PATTERN, PagePattern, PageRangeParseError, PageRangeParser, type PageSizeGroup, ResourceConverter, TOC_KEYWORDS, TextLLMComponent, type TocAreaResult, type TocContentValidationResult, TocContentValidationSchema, TocContentValidator, type TocContentValidatorOptions, type TocEntry, TocEntrySchema, TocExtractError, TocExtractionPipeline, type TocExtractionPipelineDeps, TocExtractor, type TocExtractorOptions, TocFinder, type TocFinderOptions, TocNotFoundError, TocParseError, type TocResponse, TocResponseSchema, VisionLLMComponent, type VisionLLMComponentOptions, type VisionTocExtractionResult, VisionTocExtractionSchema, VisionTocExtractor, type VisionTocExtractorOptions, extractMaxPageNumber };
|