@heripo/document-processor 0.1.14 → 0.1.16

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.cjs CHANGED
@@ -3095,6 +3095,9 @@ var PageRangeParser = class extends VisionLLMComponent {
3095
3095
  };
3096
3096
  }
3097
3097
  const sampledPages = /* @__PURE__ */ new Set();
3098
+ let consecutiveAllNullAttempts = 0;
3099
+ const MAX_ALL_NULL_ATTEMPTS = 3;
3100
+ const allSamples = [];
3098
3101
  for (let attempt = 0; attempt <= this.MAX_PATTERN_RETRIES; attempt++) {
3099
3102
  const samplePageNos = this.selectRandomSamples(
3100
3103
  pageNos,
@@ -3115,6 +3118,20 @@ var PageRangeParser = class extends VisionLLMComponent {
3115
3118
  );
3116
3119
  usageList.push(result.usage);
3117
3120
  const samples = result.samples;
3121
+ allSamples.push(...samples);
3122
+ const allNull = samples.every((s) => s.startPageNo === null);
3123
+ if (allNull) {
3124
+ consecutiveAllNullAttempts++;
3125
+ if (consecutiveAllNullAttempts >= MAX_ALL_NULL_ATTEMPTS) {
3126
+ this.log(
3127
+ "warn",
3128
+ `All samples returned null for ${MAX_ALL_NULL_ATTEMPTS} consecutive attempts, pages likely have no page numbers`
3129
+ );
3130
+ break;
3131
+ }
3132
+ } else {
3133
+ consecutiveAllNullAttempts = 0;
3134
+ }
3118
3135
  const pattern = this.detectPattern(samples);
3119
3136
  if (pattern.pattern !== "unknown" /* UNKNOWN */) {
3120
3137
  this.log(
@@ -3131,9 +3148,29 @@ var PageRangeParser = class extends VisionLLMComponent {
3131
3148
  `Pattern detection failed, attempt ${attempt + 1}/${this.MAX_PATTERN_RETRIES + 1}`
3132
3149
  );
3133
3150
  }
3134
- throw new PageRangeParseError(
3135
- `Failed to detect page pattern after ${this.MAX_PATTERN_RETRIES + 1} attempts for size group with ${pageNos.length} pages`
3151
+ const allValidSamples = allSamples.filter((s) => s.startPageNo !== null);
3152
+ if (allValidSamples.length >= 2) {
3153
+ const finalPattern = this.detectPattern(allSamples);
3154
+ if (finalPattern.pattern !== "unknown" /* UNKNOWN */) {
3155
+ this.log(
3156
+ "info",
3157
+ `Pattern detected from accumulated samples: ${finalPattern.pattern}`
3158
+ );
3159
+ return {
3160
+ pageRangeMap: this.applyPattern(pageNos, finalPattern),
3161
+ usage: usageList
3162
+ };
3163
+ }
3164
+ }
3165
+ this.log(
3166
+ "warn",
3167
+ `Could not detect page pattern after ${consecutiveAllNullAttempts >= MAX_ALL_NULL_ATTEMPTS ? consecutiveAllNullAttempts : this.MAX_PATTERN_RETRIES + 1} attempts for group with ${pageNos.length} pages, marking as failed`
3136
3168
  );
3169
+ const fallbackMap = {};
3170
+ for (const pageNo of pageNos) {
3171
+ fallbackMap[pageNo] = { startPageNo: 0, endPageNo: 0 };
3172
+ }
3173
+ return { pageRangeMap: fallbackMap, usage: usageList };
3137
3174
  }
3138
3175
  /**
3139
3176
  * Select random samples from page numbers