@heripo/pdf-parser 0.1.29 → 0.1.31
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 +158 -85
- package/README.md +158 -86
- package/dist/index.cjs +8085 -5789
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -45
- package/dist/index.d.ts +47 -45
- package/dist/index.js +8131 -5833
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.d.cts
CHANGED
|
@@ -1,37 +1,58 @@
|
|
|
1
1
|
import { LoggerMethods } from '@heripo/logger';
|
|
2
|
-
import {
|
|
2
|
+
import { TokenUsageReport, ReviewAssistanceProgressEvent } from '@heripo/model';
|
|
3
3
|
export { ReviewAssistanceProgressEvent, ReviewAssistanceProgressStatus, ReviewAssistanceProgressSubstage } from '@heripo/model';
|
|
4
4
|
import { LanguageModel } from 'ai';
|
|
5
5
|
import { ConversionOptions } from 'docling-sdk';
|
|
6
6
|
import { LLMTokenUsageAggregator } from '@heripo/shared';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
type ReviewAssistanceTaskId = 'text_ocr_hanja' | 'text_integrity' | 'text_role_footnote' | 'tables' | 'pictures_captions' | 'layout_bbox_order';
|
|
9
|
+
|
|
10
|
+
interface PDFCorrectionModelOptions {
|
|
11
|
+
textCorrection: LanguageModel;
|
|
12
|
+
pageGate: LanguageModel;
|
|
13
|
+
reviewAssistance: LanguageModel;
|
|
14
|
+
reviewAssistanceTasks?: Partial<Record<ReviewAssistanceTaskId, LanguageModel>>;
|
|
15
|
+
tableCorrection?: LanguageModel;
|
|
16
|
+
}
|
|
17
|
+
interface PDFCorrectionConcurrencyOptions {
|
|
18
|
+
pages?: number;
|
|
19
|
+
reviewTasks?: number;
|
|
20
|
+
tables?: number;
|
|
21
|
+
}
|
|
22
|
+
interface PDFCorrectionMaxRetriesOptions {
|
|
23
|
+
textCorrection?: number;
|
|
24
|
+
pageGate?: number;
|
|
25
|
+
reviewAssistance?: number;
|
|
26
|
+
tableCorrection?: number;
|
|
27
|
+
}
|
|
28
|
+
interface PDFCorrectionPageGateOptions {
|
|
29
|
+
structuralNoiseThreshold?: number;
|
|
30
|
+
}
|
|
31
|
+
interface PDFCorrectionOptions {
|
|
32
|
+
models: PDFCorrectionModelOptions;
|
|
33
|
+
concurrency?: PDFCorrectionConcurrencyOptions;
|
|
34
|
+
maxRetries?: PDFCorrectionMaxRetriesOptions;
|
|
35
|
+
localModelConcurrency?: number;
|
|
36
|
+
workItemTimeoutMs?: number;
|
|
37
|
+
outputLanguage?: string;
|
|
38
|
+
pageGate?: PDFCorrectionPageGateOptions;
|
|
12
39
|
autoApplyThreshold?: number;
|
|
13
|
-
/** Minimum final confidence for sidecar proposals. Defaults to 0.5. */
|
|
14
40
|
proposalThreshold?: number;
|
|
15
|
-
/** Maximum retries per page-level VLM call. Defaults to 3. */
|
|
16
|
-
maxRetries?: number;
|
|
17
|
-
/** VLM generation temperature. Defaults to 0. */
|
|
18
41
|
temperature?: number;
|
|
19
|
-
/** Language for human-readable review reasons. Defaults to English. */
|
|
20
|
-
outputLanguage?: string;
|
|
21
42
|
}
|
|
22
|
-
interface
|
|
23
|
-
|
|
24
|
-
concurrency:
|
|
43
|
+
interface NormalizedPDFCorrectionOptions {
|
|
44
|
+
models: PDFCorrectionModelOptions;
|
|
45
|
+
concurrency: Required<PDFCorrectionConcurrencyOptions>;
|
|
46
|
+
maxRetries: Required<PDFCorrectionMaxRetriesOptions>;
|
|
47
|
+
localModelConcurrency: number;
|
|
48
|
+
workItemTimeoutMs: number;
|
|
49
|
+
outputLanguage: string;
|
|
50
|
+
pageGate: Required<PDFCorrectionPageGateOptions>;
|
|
25
51
|
autoApplyThreshold: number;
|
|
26
52
|
proposalThreshold: number;
|
|
27
|
-
maxRetries: number;
|
|
28
53
|
temperature: number;
|
|
29
|
-
outputLanguage: string;
|
|
30
54
|
}
|
|
31
|
-
|
|
32
|
-
declare const REVIEW_ASSISTANCE_DEFAULTS: NormalizedReviewAssistanceOptions;
|
|
33
|
-
declare function normalizeReviewAssistanceOptions(value: ReviewAssistanceOptionInput): NormalizedReviewAssistanceOptions;
|
|
34
|
-
declare function isReviewAssistanceEnabled(value: ReviewAssistanceOptionInput): boolean;
|
|
55
|
+
declare const PDF_CORRECTION_DEFAULTS: Omit<NormalizedPDFCorrectionOptions, 'models'>;
|
|
35
56
|
|
|
36
57
|
/**
|
|
37
58
|
* Callback function invoked after PDF conversion completes
|
|
@@ -42,30 +63,16 @@ type ConversionCompleteCallback = (outputPath: string) => Promise<void> | void;
|
|
|
42
63
|
* Extended options for PDF conversion.
|
|
43
64
|
*/
|
|
44
65
|
type PDFConvertOptions = Omit<ConversionOptions, 'to_formats' | 'image_export_mode' | 'ocr_engine' | 'accelerator_options' | 'ocr_options' | 'generate_picture_images' | 'generate_page_images' | 'images_scale' | 'force_ocr' | 'pipeline' | 'vlm_pipeline_model_local' | 'vlm_pipeline_model_api'> & {
|
|
66
|
+
correction: PDFCorrectionOptions;
|
|
45
67
|
num_threads?: number;
|
|
46
68
|
/**
|
|
47
69
|
* Force pre-conversion to image-based PDF before processing.
|
|
48
70
|
* Requires ImageMagick and Ghostscript.
|
|
49
71
|
*/
|
|
50
72
|
forceImagePdf?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
strategySamplerModel?: LanguageModel;
|
|
53
|
-
/** Vision model for VLM page processing (required when strategy selects VLM) */
|
|
54
|
-
vlmProcessorModel?: LanguageModel;
|
|
55
|
-
/** Concurrency for VLM page processing (default: 1) */
|
|
56
|
-
vlmConcurrency?: number;
|
|
57
|
-
/**
|
|
58
|
-
* Optional page-level review assistance.
|
|
59
|
-
* Boolean true enables defaults; object form still requires enabled: true.
|
|
60
|
-
*/
|
|
61
|
-
reviewAssistance?: boolean | ReviewAssistanceOptions;
|
|
62
|
-
/** Skip sampling and default to ocrmac */
|
|
63
|
-
skipSampling?: boolean;
|
|
64
|
-
/** Force a specific OCR method, bypassing sampling */
|
|
65
|
-
forcedMethod?: 'ocrmac' | 'vlm';
|
|
66
|
-
/** Token usage aggregator for tracking across sampling and VLM processing */
|
|
73
|
+
/** Token usage aggregator for tracking post-Docling correction calls */
|
|
67
74
|
aggregator?: LLMTokenUsageAggregator;
|
|
68
|
-
/** Callback fired after
|
|
75
|
+
/** Callback fired after correction work completes, with cumulative token usage */
|
|
69
76
|
onTokenUsage?: (report: TokenUsageReport) => void;
|
|
70
77
|
/** Callback fired when Review Assistance advances through parser substages */
|
|
71
78
|
onReviewAssistanceProgress?: (event: ReviewAssistanceProgressEvent) => void;
|
|
@@ -77,16 +84,11 @@ type PDFConvertOptions = Omit<ConversionOptions, 'to_formats' | 'image_export_mo
|
|
|
77
84
|
chunkSize?: number;
|
|
78
85
|
/** Max retry attempts per failed chunk (default: CHUNKED_CONVERSION.DEFAULT_MAX_RETRIES) */
|
|
79
86
|
chunkMaxRetries?: number;
|
|
87
|
+
/** Vision model for document language detection when the PDF text layer is insufficient */
|
|
88
|
+
languageDetectionModel?: LanguageModel;
|
|
80
89
|
/** LLM model for document type validation (opt-in: skipped when not set) */
|
|
81
90
|
documentValidationModel?: LanguageModel;
|
|
82
91
|
};
|
|
83
|
-
/** Result of strategy-based conversion */
|
|
84
|
-
interface ConvertWithStrategyResult {
|
|
85
|
-
/** The OCR strategy that was determined */
|
|
86
|
-
strategy: OcrStrategy;
|
|
87
|
-
/** Token usage report from sampling and/or VLM processing (null when no LLM usage occurs) */
|
|
88
|
-
tokenUsageReport: TokenUsageReport | null;
|
|
89
|
-
}
|
|
90
92
|
|
|
91
93
|
type Options = {
|
|
92
94
|
logger: LoggerMethods;
|
|
@@ -334,4 +336,4 @@ declare class VlmResponseValidator {
|
|
|
334
336
|
private static detectRepetitivePattern;
|
|
335
337
|
}
|
|
336
338
|
|
|
337
|
-
export { type ConversionCompleteCallback, type
|
|
339
|
+
export { type ConversionCompleteCallback, ImagePdfFallbackError, InvalidDocumentTypeError, type NormalizedPDFCorrectionOptions, type PDFConvertOptions, type PDFCorrectionConcurrencyOptions, type PDFCorrectionMaxRetriesOptions, type PDFCorrectionModelOptions, type PDFCorrectionOptions, type PDFCorrectionPageGateOptions, PDFParser, PDF_CORRECTION_DEFAULTS, type ReviewAssistanceTaskId, type VlmPageQuality, type VlmQualityIssue, type VlmQualityIssueType, VlmResponseValidator, type VlmValidationResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,58 @@
|
|
|
1
1
|
import { LoggerMethods } from '@heripo/logger';
|
|
2
|
-
import {
|
|
2
|
+
import { TokenUsageReport, ReviewAssistanceProgressEvent } from '@heripo/model';
|
|
3
3
|
export { ReviewAssistanceProgressEvent, ReviewAssistanceProgressStatus, ReviewAssistanceProgressSubstage } from '@heripo/model';
|
|
4
4
|
import { LanguageModel } from 'ai';
|
|
5
5
|
import { ConversionOptions } from 'docling-sdk';
|
|
6
6
|
import { LLMTokenUsageAggregator } from '@heripo/shared';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
type ReviewAssistanceTaskId = 'text_ocr_hanja' | 'text_integrity' | 'text_role_footnote' | 'tables' | 'pictures_captions' | 'layout_bbox_order';
|
|
9
|
+
|
|
10
|
+
interface PDFCorrectionModelOptions {
|
|
11
|
+
textCorrection: LanguageModel;
|
|
12
|
+
pageGate: LanguageModel;
|
|
13
|
+
reviewAssistance: LanguageModel;
|
|
14
|
+
reviewAssistanceTasks?: Partial<Record<ReviewAssistanceTaskId, LanguageModel>>;
|
|
15
|
+
tableCorrection?: LanguageModel;
|
|
16
|
+
}
|
|
17
|
+
interface PDFCorrectionConcurrencyOptions {
|
|
18
|
+
pages?: number;
|
|
19
|
+
reviewTasks?: number;
|
|
20
|
+
tables?: number;
|
|
21
|
+
}
|
|
22
|
+
interface PDFCorrectionMaxRetriesOptions {
|
|
23
|
+
textCorrection?: number;
|
|
24
|
+
pageGate?: number;
|
|
25
|
+
reviewAssistance?: number;
|
|
26
|
+
tableCorrection?: number;
|
|
27
|
+
}
|
|
28
|
+
interface PDFCorrectionPageGateOptions {
|
|
29
|
+
structuralNoiseThreshold?: number;
|
|
30
|
+
}
|
|
31
|
+
interface PDFCorrectionOptions {
|
|
32
|
+
models: PDFCorrectionModelOptions;
|
|
33
|
+
concurrency?: PDFCorrectionConcurrencyOptions;
|
|
34
|
+
maxRetries?: PDFCorrectionMaxRetriesOptions;
|
|
35
|
+
localModelConcurrency?: number;
|
|
36
|
+
workItemTimeoutMs?: number;
|
|
37
|
+
outputLanguage?: string;
|
|
38
|
+
pageGate?: PDFCorrectionPageGateOptions;
|
|
12
39
|
autoApplyThreshold?: number;
|
|
13
|
-
/** Minimum final confidence for sidecar proposals. Defaults to 0.5. */
|
|
14
40
|
proposalThreshold?: number;
|
|
15
|
-
/** Maximum retries per page-level VLM call. Defaults to 3. */
|
|
16
|
-
maxRetries?: number;
|
|
17
|
-
/** VLM generation temperature. Defaults to 0. */
|
|
18
41
|
temperature?: number;
|
|
19
|
-
/** Language for human-readable review reasons. Defaults to English. */
|
|
20
|
-
outputLanguage?: string;
|
|
21
42
|
}
|
|
22
|
-
interface
|
|
23
|
-
|
|
24
|
-
concurrency:
|
|
43
|
+
interface NormalizedPDFCorrectionOptions {
|
|
44
|
+
models: PDFCorrectionModelOptions;
|
|
45
|
+
concurrency: Required<PDFCorrectionConcurrencyOptions>;
|
|
46
|
+
maxRetries: Required<PDFCorrectionMaxRetriesOptions>;
|
|
47
|
+
localModelConcurrency: number;
|
|
48
|
+
workItemTimeoutMs: number;
|
|
49
|
+
outputLanguage: string;
|
|
50
|
+
pageGate: Required<PDFCorrectionPageGateOptions>;
|
|
25
51
|
autoApplyThreshold: number;
|
|
26
52
|
proposalThreshold: number;
|
|
27
|
-
maxRetries: number;
|
|
28
53
|
temperature: number;
|
|
29
|
-
outputLanguage: string;
|
|
30
54
|
}
|
|
31
|
-
|
|
32
|
-
declare const REVIEW_ASSISTANCE_DEFAULTS: NormalizedReviewAssistanceOptions;
|
|
33
|
-
declare function normalizeReviewAssistanceOptions(value: ReviewAssistanceOptionInput): NormalizedReviewAssistanceOptions;
|
|
34
|
-
declare function isReviewAssistanceEnabled(value: ReviewAssistanceOptionInput): boolean;
|
|
55
|
+
declare const PDF_CORRECTION_DEFAULTS: Omit<NormalizedPDFCorrectionOptions, 'models'>;
|
|
35
56
|
|
|
36
57
|
/**
|
|
37
58
|
* Callback function invoked after PDF conversion completes
|
|
@@ -42,30 +63,16 @@ type ConversionCompleteCallback = (outputPath: string) => Promise<void> | void;
|
|
|
42
63
|
* Extended options for PDF conversion.
|
|
43
64
|
*/
|
|
44
65
|
type PDFConvertOptions = Omit<ConversionOptions, 'to_formats' | 'image_export_mode' | 'ocr_engine' | 'accelerator_options' | 'ocr_options' | 'generate_picture_images' | 'generate_page_images' | 'images_scale' | 'force_ocr' | 'pipeline' | 'vlm_pipeline_model_local' | 'vlm_pipeline_model_api'> & {
|
|
66
|
+
correction: PDFCorrectionOptions;
|
|
45
67
|
num_threads?: number;
|
|
46
68
|
/**
|
|
47
69
|
* Force pre-conversion to image-based PDF before processing.
|
|
48
70
|
* Requires ImageMagick and Ghostscript.
|
|
49
71
|
*/
|
|
50
72
|
forceImagePdf?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
strategySamplerModel?: LanguageModel;
|
|
53
|
-
/** Vision model for VLM page processing (required when strategy selects VLM) */
|
|
54
|
-
vlmProcessorModel?: LanguageModel;
|
|
55
|
-
/** Concurrency for VLM page processing (default: 1) */
|
|
56
|
-
vlmConcurrency?: number;
|
|
57
|
-
/**
|
|
58
|
-
* Optional page-level review assistance.
|
|
59
|
-
* Boolean true enables defaults; object form still requires enabled: true.
|
|
60
|
-
*/
|
|
61
|
-
reviewAssistance?: boolean | ReviewAssistanceOptions;
|
|
62
|
-
/** Skip sampling and default to ocrmac */
|
|
63
|
-
skipSampling?: boolean;
|
|
64
|
-
/** Force a specific OCR method, bypassing sampling */
|
|
65
|
-
forcedMethod?: 'ocrmac' | 'vlm';
|
|
66
|
-
/** Token usage aggregator for tracking across sampling and VLM processing */
|
|
73
|
+
/** Token usage aggregator for tracking post-Docling correction calls */
|
|
67
74
|
aggregator?: LLMTokenUsageAggregator;
|
|
68
|
-
/** Callback fired after
|
|
75
|
+
/** Callback fired after correction work completes, with cumulative token usage */
|
|
69
76
|
onTokenUsage?: (report: TokenUsageReport) => void;
|
|
70
77
|
/** Callback fired when Review Assistance advances through parser substages */
|
|
71
78
|
onReviewAssistanceProgress?: (event: ReviewAssistanceProgressEvent) => void;
|
|
@@ -77,16 +84,11 @@ type PDFConvertOptions = Omit<ConversionOptions, 'to_formats' | 'image_export_mo
|
|
|
77
84
|
chunkSize?: number;
|
|
78
85
|
/** Max retry attempts per failed chunk (default: CHUNKED_CONVERSION.DEFAULT_MAX_RETRIES) */
|
|
79
86
|
chunkMaxRetries?: number;
|
|
87
|
+
/** Vision model for document language detection when the PDF text layer is insufficient */
|
|
88
|
+
languageDetectionModel?: LanguageModel;
|
|
80
89
|
/** LLM model for document type validation (opt-in: skipped when not set) */
|
|
81
90
|
documentValidationModel?: LanguageModel;
|
|
82
91
|
};
|
|
83
|
-
/** Result of strategy-based conversion */
|
|
84
|
-
interface ConvertWithStrategyResult {
|
|
85
|
-
/** The OCR strategy that was determined */
|
|
86
|
-
strategy: OcrStrategy;
|
|
87
|
-
/** Token usage report from sampling and/or VLM processing (null when no LLM usage occurs) */
|
|
88
|
-
tokenUsageReport: TokenUsageReport | null;
|
|
89
|
-
}
|
|
90
92
|
|
|
91
93
|
type Options = {
|
|
92
94
|
logger: LoggerMethods;
|
|
@@ -334,4 +336,4 @@ declare class VlmResponseValidator {
|
|
|
334
336
|
private static detectRepetitivePattern;
|
|
335
337
|
}
|
|
336
338
|
|
|
337
|
-
export { type ConversionCompleteCallback, type
|
|
339
|
+
export { type ConversionCompleteCallback, ImagePdfFallbackError, InvalidDocumentTypeError, type NormalizedPDFCorrectionOptions, type PDFConvertOptions, type PDFCorrectionConcurrencyOptions, type PDFCorrectionMaxRetriesOptions, type PDFCorrectionModelOptions, type PDFCorrectionOptions, type PDFCorrectionPageGateOptions, PDFParser, PDF_CORRECTION_DEFAULTS, type ReviewAssistanceTaskId, type VlmPageQuality, type VlmQualityIssue, type VlmQualityIssueType, VlmResponseValidator, type VlmValidationResult };
|