@heripo/pdf-parser 0.1.34 → 0.1.36

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
@@ -54,6 +54,12 @@ interface PDFCorrectionOptions {
54
54
  * Enabled by the engine demo; defaults to false everywhere else.
55
55
  */
56
56
  forceAutoApply?: boolean;
57
+ /**
58
+ * When false, the review-assistance stage (the per-page eligibility gate plus
59
+ * the structural review-assistance runner) is skipped entirely and only the
60
+ * text-correction stage runs. Defaults to true.
61
+ */
62
+ reviewAssistanceEnabled?: boolean;
57
63
  temperature?: number;
58
64
  }
59
65
  interface NormalizedPDFCorrectionOptions {
@@ -67,6 +73,7 @@ interface NormalizedPDFCorrectionOptions {
67
73
  autoApplyThreshold: number;
68
74
  proposalThreshold: number;
69
75
  forceAutoApply: boolean;
76
+ reviewAssistanceEnabled: boolean;
70
77
  temperature: number;
71
78
  }
72
79
  declare const PDF_CORRECTION_DEFAULTS: Omit<NormalizedPDFCorrectionOptions, 'models'>;
package/dist/index.d.ts CHANGED
@@ -54,6 +54,12 @@ interface PDFCorrectionOptions {
54
54
  * Enabled by the engine demo; defaults to false everywhere else.
55
55
  */
56
56
  forceAutoApply?: boolean;
57
+ /**
58
+ * When false, the review-assistance stage (the per-page eligibility gate plus
59
+ * the structural review-assistance runner) is skipped entirely and only the
60
+ * text-correction stage runs. Defaults to true.
61
+ */
62
+ reviewAssistanceEnabled?: boolean;
57
63
  temperature?: number;
58
64
  }
59
65
  interface NormalizedPDFCorrectionOptions {
@@ -67,6 +73,7 @@ interface NormalizedPDFCorrectionOptions {
67
73
  autoApplyThreshold: number;
68
74
  proposalThreshold: number;
69
75
  forceAutoApply: boolean;
76
+ reviewAssistanceEnabled: boolean;
70
77
  temperature: number;
71
78
  }
72
79
  declare const PDF_CORRECTION_DEFAULTS: Omit<NormalizedPDFCorrectionOptions, 'models'>;
package/dist/index.js CHANGED
@@ -590,6 +590,9 @@ var DoclingServer = class _DoclingServer {
590
590
  this.venvPath = venvPath;
591
591
  this.port = port;
592
592
  }
593
+ logger;
594
+ venvPath;
595
+ port;
593
596
  async isPortInUse() {
594
597
  try {
595
598
  const result = await spawnAsync("lsof", ["-ti", `:${this.port}`]);
@@ -736,6 +739,8 @@ var PythonEnvironment = class {
736
739
  this.logger = logger;
737
740
  this.venvPath = venvPath;
738
741
  }
742
+ logger;
743
+ venvPath;
739
744
  async setup() {
740
745
  await this.checkPythonVersion();
741
746
  await this.setupPythonEnvironment();
@@ -989,6 +994,7 @@ var PdfTextExtractor = class _PdfTextExtractor {
989
994
  constructor(logger) {
990
995
  this.logger = logger;
991
996
  }
997
+ logger;
992
998
  /**
993
999
  * Safely extract page texts: returns the map on success, `undefined` on
994
1000
  * failure. Failures are logged as a single warning and do not throw, so
@@ -1141,6 +1147,8 @@ var PdfLanguageDetector = class {
1141
1147
  this.pageRenderer = pageRenderer;
1142
1148
  this.textExtractor = textExtractor ?? new PdfTextExtractor(logger);
1143
1149
  }
1150
+ logger;
1151
+ pageRenderer;
1144
1152
  textExtractor;
1145
1153
  async detect(pdfPath, outputDir, options) {
1146
1154
  this.logger.info(
@@ -1357,6 +1365,8 @@ var ImagePdfFallbackError = class extends Error {
1357
1365
  this.originalError = originalError;
1358
1366
  this.fallbackError = fallbackError;
1359
1367
  }
1368
+ originalError;
1369
+ fallbackError;
1360
1370
  name = "ImagePdfFallbackError";
1361
1371
  };
1362
1372
 
@@ -1368,6 +1378,7 @@ var PageRenderer = class {
1368
1378
  constructor(logger) {
1369
1379
  this.logger = logger;
1370
1380
  }
1381
+ logger;
1371
1382
  lastLoggedPercent = 0;
1372
1383
  /**
1373
1384
  * Render all pages of a PDF to individual PNG files.
@@ -1493,6 +1504,7 @@ var InvalidDocumentTypeError = class extends Error {
1493
1504
  );
1494
1505
  this.reason = reason;
1495
1506
  }
1507
+ reason;
1496
1508
  name = "InvalidDocumentTypeError";
1497
1509
  code = "INVALID_DOCUMENT_TYPE";
1498
1510
  };
@@ -2423,6 +2435,10 @@ var ChunkedPDFConverter = class {
2423
2435
  this.config = config;
2424
2436
  this.timeout = timeout;
2425
2437
  }
2438
+ logger;
2439
+ client;
2440
+ config;
2441
+ timeout;
2426
2442
  /**
2427
2443
  * Convert a local PDF in chunks.
2428
2444
  *
@@ -2769,6 +2785,9 @@ var DoclingConversionExecutor = class {
2769
2785
  this.client = client;
2770
2786
  this.timeout = timeout;
2771
2787
  }
2788
+ logger;
2789
+ client;
2790
+ timeout;
2772
2791
  /**
2773
2792
  * Execute a full Docling conversion pipeline.
2774
2793
  *
@@ -2931,6 +2950,7 @@ var ImagePdfConverter = class {
2931
2950
  constructor(logger) {
2932
2951
  this.logger = logger;
2933
2952
  }
2953
+ logger;
2934
2954
  /**
2935
2955
  * Convert a PDF file to an image-based PDF.
2936
2956
  * Downloads the PDF from URL, converts it using ImageMagick, and returns the path.
@@ -3415,6 +3435,7 @@ var PostDoclingPageProcessor = class {
3415
3435
  constructor(logger) {
3416
3436
  this.logger = logger;
3417
3437
  }
3438
+ logger;
3418
3439
  /**
3419
3440
  * Read DoclingDocument from output directory, correct text via VLM,
3420
3441
  * and save the corrected document back.
@@ -5221,6 +5242,8 @@ var ImageRegionSnapper = class {
5221
5242
  this.logger = logger;
5222
5243
  this.options = options;
5223
5244
  }
5245
+ logger;
5246
+ options;
5224
5247
  async snap(pageImagePath, pageSize, bbox) {
5225
5248
  const warnings = [];
5226
5249
  const dims = await this.getImageDimensions(pageImagePath);
@@ -5433,6 +5456,8 @@ var PictureSplitCandidateDetector = class {
5433
5456
  this.options = options;
5434
5457
  this.snapper = snapper ?? new ImageRegionSnapper(logger);
5435
5458
  }
5459
+ logger;
5460
+ options;
5436
5461
  snapper;
5437
5462
  async detect(input) {
5438
5463
  if (!this.isLargeEnoughForInspection(input.pictureBbox)) {
@@ -5734,6 +5759,9 @@ var ReviewAssistanceCheckpointStore = class _ReviewAssistanceCheckpointStore {
5734
5759
  this.checkpoint = checkpoint;
5735
5760
  this.now = now;
5736
5761
  }
5762
+ path;
5763
+ checkpoint;
5764
+ now;
5737
5765
  static open(outputDir, runId, now) {
5738
5766
  const path = join12(outputDir, CHECKPOINT_FILE);
5739
5767
  const checkpoint = this.read(path, runId, now?.() ?? /* @__PURE__ */ new Date());
@@ -6107,6 +6135,7 @@ var ImageCropWriter = class {
6107
6135
  this.logger = logger;
6108
6136
  this.snapper = snapper ?? new ImageRegionSnapper(logger);
6109
6137
  }
6138
+ logger;
6110
6139
  snapper;
6111
6140
  async writeCrop(input) {
6112
6141
  const imagesDir = join13(input.outputDir, "images");
@@ -6229,6 +6258,7 @@ var ReviewAssistancePatcher = class {
6229
6258
  this.snapper = new ImageRegionSnapper(logger);
6230
6259
  this.cropWriter = new ImageCropWriter(logger, this.snapper);
6231
6260
  }
6261
+ logger;
6232
6262
  snapper;
6233
6263
  cropWriter;
6234
6264
  captionResolver = new OrphanCaptionResolver();
@@ -8640,6 +8670,7 @@ var ReviewAssistanceRunner = class {
8640
8670
  constructor(logger) {
8641
8671
  this.logger = logger;
8642
8672
  }
8673
+ logger;
8643
8674
  async analyzeAndSave(outputDir, reportId, modelResolver, options) {
8644
8675
  this.emitProgress(options, {
8645
8676
  substage: "review-assistance:prepare",
@@ -10437,6 +10468,7 @@ var PDF_CORRECTION_DEFAULTS = {
10437
10468
  autoApplyThreshold: 0.85,
10438
10469
  proposalThreshold: 0.5,
10439
10470
  forceAutoApply: false,
10471
+ reviewAssistanceEnabled: true,
10440
10472
  temperature: 0
10441
10473
  };
10442
10474
  function normalizeNumber(value, fallback) {
@@ -10536,6 +10568,7 @@ function normalizePDFCorrectionOptions(value) {
10536
10568
  autoApplyThreshold,
10537
10569
  proposalThreshold,
10538
10570
  forceAutoApply: value.forceAutoApply ?? PDF_CORRECTION_DEFAULTS.forceAutoApply,
10571
+ reviewAssistanceEnabled: value.reviewAssistanceEnabled ?? PDF_CORRECTION_DEFAULTS.reviewAssistanceEnabled,
10539
10572
  temperature: normalizeTemperature(
10540
10573
  value.temperature,
10541
10574
  PDF_CORRECTION_DEFAULTS.temperature
@@ -10548,6 +10581,7 @@ var PostDoclingCorrectionPipeline = class {
10548
10581
  constructor(logger) {
10549
10582
  this.logger = logger;
10550
10583
  }
10584
+ logger;
10551
10585
  wrapCallback(pdfPath, reportId, options, originalCallback, abortSignal) {
10552
10586
  const correction = normalizePDFCorrectionOptions(options.correction);
10553
10587
  return async (outputDir) => {
@@ -10569,44 +10603,49 @@ var PostDoclingCorrectionPipeline = class {
10569
10603
  onTokenUsage: options.onTokenUsage,
10570
10604
  documentLanguages: options.ocr_lang,
10571
10605
  pageTexts,
10572
- reviewAssistanceGate: {
10606
+ // When review assistance is disabled, omit the gate entirely so the
10607
+ // per-page eligibility checks (pageGate LLM calls + sidecar report)
10608
+ // never run — only text correction executes.
10609
+ reviewAssistanceGate: correction.reviewAssistanceEnabled ? {
10573
10610
  model: correction.models.pageGate,
10574
10611
  fallback: correction.models.pageGateFallback,
10575
10612
  maxRetries: correction.maxRetries.pageGate,
10576
10613
  temperature: correction.temperature,
10577
10614
  outputLanguage: correction.outputLanguage
10578
- }
10579
- }
10580
- );
10581
- const runner = new ReviewAssistanceRunner(this.logger);
10582
- await runner.analyzeAndSave(
10583
- outputDir,
10584
- reportId,
10585
- this.buildReviewAssistanceModelResolver(correction),
10586
- {
10587
- pdfPath,
10588
- pageTexts,
10589
- pageGateModel: correction.models.pageGate,
10590
- pageGateFallback: correction.models.pageGateFallback,
10591
- pageGateMaxRetries: correction.maxRetries.pageGate,
10592
- pageGateTemperature: correction.temperature,
10593
- pageConcurrency: correction.concurrency.pages,
10594
- taskConcurrency: correction.concurrency.reviewTasks,
10595
- modelConcurrency: correction.modelConcurrency,
10596
- workItemTimeoutMs: correction.workItemTimeoutMs,
10597
- autoApplyThreshold: correction.autoApplyThreshold,
10598
- proposalThreshold: correction.proposalThreshold,
10599
- forceAutoApply: correction.forceAutoApply,
10600
- maxRetries: correction.maxRetries.reviewAssistance,
10601
- tableMaxRetries: correction.maxRetries.tableCorrection,
10602
- temperature: correction.temperature,
10603
- outputLanguage: correction.outputLanguage,
10604
- aggregator: options.aggregator,
10605
- abortSignal,
10606
- onTokenUsage: options.onTokenUsage,
10607
- onProgress: options.onReviewAssistanceProgress
10615
+ } : void 0
10608
10616
  }
10609
10617
  );
10618
+ if (correction.reviewAssistanceEnabled) {
10619
+ const runner = new ReviewAssistanceRunner(this.logger);
10620
+ await runner.analyzeAndSave(
10621
+ outputDir,
10622
+ reportId,
10623
+ this.buildReviewAssistanceModelResolver(correction),
10624
+ {
10625
+ pdfPath,
10626
+ pageTexts,
10627
+ pageGateModel: correction.models.pageGate,
10628
+ pageGateFallback: correction.models.pageGateFallback,
10629
+ pageGateMaxRetries: correction.maxRetries.pageGate,
10630
+ pageGateTemperature: correction.temperature,
10631
+ pageConcurrency: correction.concurrency.pages,
10632
+ taskConcurrency: correction.concurrency.reviewTasks,
10633
+ modelConcurrency: correction.modelConcurrency,
10634
+ workItemTimeoutMs: correction.workItemTimeoutMs,
10635
+ autoApplyThreshold: correction.autoApplyThreshold,
10636
+ proposalThreshold: correction.proposalThreshold,
10637
+ forceAutoApply: correction.forceAutoApply,
10638
+ maxRetries: correction.maxRetries.reviewAssistance,
10639
+ tableMaxRetries: correction.maxRetries.tableCorrection,
10640
+ temperature: correction.temperature,
10641
+ outputLanguage: correction.outputLanguage,
10642
+ aggregator: options.aggregator,
10643
+ abortSignal,
10644
+ onTokenUsage: options.onTokenUsage,
10645
+ onProgress: options.onReviewAssistanceProgress
10646
+ }
10647
+ );
10648
+ }
10610
10649
  await originalCallback(outputDir);
10611
10650
  };
10612
10651
  }
@@ -10649,6 +10688,10 @@ var PDFConverter = class {
10649
10688
  this.enableImagePdfFallback = enableImagePdfFallback;
10650
10689
  this.timeout = timeout;
10651
10690
  }
10691
+ logger;
10692
+ client;
10693
+ enableImagePdfFallback;
10694
+ timeout;
10652
10695
  documentTypeValidated = false;
10653
10696
  /**
10654
10697
  * Validate that the PDF is an archaeological investigation report.