@heripo/pdf-parser 0.1.47 → 0.2.0

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.ts CHANGED
@@ -370,4 +370,5 @@ declare class VlmResponseValidator {
370
370
  private static detectRepetitivePattern;
371
371
  }
372
372
 
373
- 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 };
373
+ export { ImagePdfFallbackError, InvalidDocumentTypeError, PDFParser, PDF_CORRECTION_DEFAULTS, VlmResponseValidator };
374
+ export type { ConversionCompleteCallback, NormalizedPDFCorrectionOptions, PDFConvertOptions, PDFCorrectionConcurrencyOptions, PDFCorrectionMaxRetriesOptions, PDFCorrectionModelOptions, PDFCorrectionOptions, PDFCorrectionPageGateOptions, ReviewAssistanceTaskId, VlmPageQuality, VlmQualityIssue, VlmQualityIssueType, VlmValidationResult };
package/dist/index.js CHANGED
@@ -73,6 +73,8 @@ import {
73
73
  hasToolCall,
74
74
  tool
75
75
  } from "ai";
76
+ import { wrapLanguageModel } from "ai";
77
+ import { wrapLanguageModel as wrapLanguageModel2 } from "ai";
76
78
  var ConcurrentPool = class {
77
79
  /**
78
80
  * Process items concurrently using a worker pool pattern.
@@ -187,9 +189,23 @@ var LLMCaller = class {
187
189
  cacheWriteTokens: allWrites - (write1h ?? 0)
188
190
  },
189
191
  ...write1h !== void 0 && { cacheWrite1hTokens: write1h },
192
+ ...usage?.outputTokenDetails?.reasoningTokens != null && {
193
+ reasoningTokens: usage.outputTokenDetails.reasoningTokens
194
+ },
190
195
  metadata: config.metadata
191
196
  };
192
197
  }
198
+ /** Finish reason and structured-output attempts, when known. */
199
+ static callDetails(response) {
200
+ return {
201
+ ...response.finishReason !== void 0 && {
202
+ finishReason: response.finishReason
203
+ },
204
+ ...response.structuredAttempts !== void 0 && {
205
+ structuredAttempts: response.structuredAttempts
206
+ }
207
+ };
208
+ }
193
209
  /**
194
210
  * Maximum number of retries when structured output generation fails.
195
211
  * Total attempts = MAX_STRUCTURED_OUTPUT_RETRIES + 1.
@@ -230,7 +246,9 @@ var LLMCaller = class {
230
246
  return {
231
247
  output: toolCall.input,
232
248
  usage: lastResult.usage,
233
- steps: lastResult.steps
249
+ steps: lastResult.steps,
250
+ finishReason: lastResult.finishReason,
251
+ structuredAttempts: attempt + 1
234
252
  };
235
253
  }
236
254
  }
@@ -264,11 +282,18 @@ var LLMCaller = class {
264
282
  let lastError;
265
283
  for (let attempt = 0; attempt <= this.MAX_STRUCTURED_OUTPUT_RETRIES; attempt++) {
266
284
  try {
267
- return await generateText({
285
+ const result = await generateText({
268
286
  model,
269
287
  output: Output.object({ schema }),
270
288
  ...promptParams
271
289
  });
290
+ return {
291
+ output: result.output,
292
+ usage: result.usage,
293
+ steps: result.steps,
294
+ finishReason: result.finishReason,
295
+ structuredAttempts: attempt + 1
296
+ };
272
297
  } catch (error) {
273
298
  if (NoObjectGeneratedError.isInstance(error)) {
274
299
  lastError = error;
@@ -292,7 +317,8 @@ var LLMCaller = class {
292
317
  return {
293
318
  output: response.output,
294
319
  usage: this.buildUsage(config, primaryModelName, response, false),
295
- usedFallback: false
320
+ usedFallback: false,
321
+ ...this.callDetails(response)
296
322
  };
297
323
  } catch (primaryError) {
298
324
  if (config.abortSignal?.aborted) {
@@ -306,7 +332,8 @@ var LLMCaller = class {
306
332
  return {
307
333
  output: response.output,
308
334
  usage: this.buildUsage(config, fallbackModelName, response, true),
309
- usedFallback: true
335
+ usedFallback: true,
336
+ ...this.callDetails(response)
310
337
  };
311
338
  }
312
339
  }
@@ -329,8 +356,17 @@ var LLMCaller = class {
329
356
  return this.executeWithFallback(
330
357
  config,
331
358
  (model) => this.generateStructuredOutput(model, config.schema, {
332
- instructions: config.systemPrompt,
359
+ instructions: config.cacheSystemPrompt ? {
360
+ role: "system",
361
+ content: config.systemPrompt,
362
+ providerOptions: {
363
+ anthropic: { cacheControl: { type: "ephemeral" } }
364
+ }
365
+ } : config.systemPrompt,
333
366
  prompt: config.userPrompt,
367
+ ...config.providerOptions && {
368
+ providerOptions: config.providerOptions
369
+ },
334
370
  temperature: config.temperature,
335
371
  maxRetries: config.maxRetries,
336
372
  abortSignal: config.abortSignal
@@ -600,6 +636,7 @@ var LLMTokenUsageAggregator = class {
600
636
  this.usage = {};
601
637
  }
602
638
  };
639
+ var encoder = new TextEncoder();
603
640
 
604
641
  // src/environment/docling-server.ts
605
642
  import { spawn as spawn2 } from "child_process";