@heripo/pdf-parser 0.1.28 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,37 +1,58 @@
1
1
  import { LoggerMethods } from '@heripo/logger';
2
- import { OcrStrategy, TokenUsageReport, ReviewAssistanceProgressEvent } from '@heripo/model';
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
- interface ReviewAssistanceOptions {
9
- /** Enable page-level review assistance. Defaults to false. */
10
- enabled?: boolean;
11
- /** Minimum final confidence for direct mutation. Defaults to 0.85. */
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 NormalizedReviewAssistanceOptions {
23
- enabled: boolean;
24
- concurrency: number;
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
- type ReviewAssistanceOptionInput = boolean | ReviewAssistanceOptions | undefined;
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
- /** Vision model for OCR strategy sampling (enables new strategy-based flow) */
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 each batch of VLM pages completes, with cumulative token usage */
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;
@@ -80,13 +87,6 @@ type PDFConvertOptions = Omit<ConversionOptions, 'to_formats' | 'image_export_mo
80
87
  /** LLM model for document type validation (opt-in: skipped when not set) */
81
88
  documentValidationModel?: LanguageModel;
82
89
  };
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
90
 
91
91
  type Options = {
92
92
  logger: LoggerMethods;
@@ -334,4 +334,4 @@ declare class VlmResponseValidator {
334
334
  private static detectRepetitivePattern;
335
335
  }
336
336
 
337
- export { type ConversionCompleteCallback, type ConvertWithStrategyResult, ImagePdfFallbackError, InvalidDocumentTypeError, type NormalizedReviewAssistanceOptions, type PDFConvertOptions, PDFParser, REVIEW_ASSISTANCE_DEFAULTS, type ReviewAssistanceOptions, type VlmPageQuality, type VlmQualityIssue, type VlmQualityIssueType, VlmResponseValidator, type VlmValidationResult, isReviewAssistanceEnabled, normalizeReviewAssistanceOptions };
337
+ 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 { OcrStrategy, TokenUsageReport, ReviewAssistanceProgressEvent } from '@heripo/model';
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
- interface ReviewAssistanceOptions {
9
- /** Enable page-level review assistance. Defaults to false. */
10
- enabled?: boolean;
11
- /** Minimum final confidence for direct mutation. Defaults to 0.85. */
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 NormalizedReviewAssistanceOptions {
23
- enabled: boolean;
24
- concurrency: number;
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
- type ReviewAssistanceOptionInput = boolean | ReviewAssistanceOptions | undefined;
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
- /** Vision model for OCR strategy sampling (enables new strategy-based flow) */
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 each batch of VLM pages completes, with cumulative token usage */
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;
@@ -80,13 +87,6 @@ type PDFConvertOptions = Omit<ConversionOptions, 'to_formats' | 'image_export_mo
80
87
  /** LLM model for document type validation (opt-in: skipped when not set) */
81
88
  documentValidationModel?: LanguageModel;
82
89
  };
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
90
 
91
91
  type Options = {
92
92
  logger: LoggerMethods;
@@ -334,4 +334,4 @@ declare class VlmResponseValidator {
334
334
  private static detectRepetitivePattern;
335
335
  }
336
336
 
337
- export { type ConversionCompleteCallback, type ConvertWithStrategyResult, ImagePdfFallbackError, InvalidDocumentTypeError, type NormalizedReviewAssistanceOptions, type PDFConvertOptions, PDFParser, REVIEW_ASSISTANCE_DEFAULTS, type ReviewAssistanceOptions, type VlmPageQuality, type VlmQualityIssue, type VlmQualityIssueType, VlmResponseValidator, type VlmValidationResult, isReviewAssistanceEnabled, normalizeReviewAssistanceOptions };
337
+ 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 };