@heripo/document-processor 0.1.16 → 0.1.18

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 CHANGED
@@ -72,16 +72,18 @@ const processor = new DocumentProcessor({
72
72
  });
73
73
 
74
74
  // 문서 처리
75
- const processedDoc = await processor.process(
75
+ const { document, usage } = await processor.process(
76
76
  doclingDocument, // PDF 파서 출력
77
77
  'report-001', // 리포트 ID
78
78
  outputPath, // 이미지/페이지가 있는 디렉토리
79
79
  );
80
80
 
81
81
  // 결과 사용
82
- console.log('목차:', processedDoc.chapters);
83
- console.log('이미지:', processedDoc.images);
84
- console.log('표:', processedDoc.tables);
82
+ console.log('목차:', document.chapters);
83
+ console.log('이미지:', document.images);
84
+ console.log('표:', document.tables);
85
+ console.log('각주:', document.footnotes);
86
+ console.log('토큰 사용량:', usage.total);
85
87
  ```
86
88
 
87
89
  ### 고급 사용법 - 컴포넌트별 모델 지정
@@ -109,10 +111,10 @@ const processor = new DocumentProcessor({
109
111
 
110
112
  // 재시도 설정
111
113
  maxRetries: 3,
112
- enableFallbackRetry: true, // fallback 모델로 자동 재시도
114
+ enableFallbackRetry: true, // fallback 모델로 자동 재시도 (기본값: false)
113
115
  });
114
116
 
115
- const processedDoc = await processor.process(
117
+ const { document, usage } = await processor.process(
116
118
  doclingDocument,
117
119
  'report-001',
118
120
  outputPath,
@@ -176,6 +178,7 @@ DocumentProcessor는 다음 5단계 파이프라인으로 문서를 처리합니
176
178
  - Chapter 계층 생성
177
179
  - 페이지 범위별로 텍스트 블록을 챕터에 연결
178
180
  - 이미지/테이블 ID를 적절한 챕터에 연결
181
+ - 각주 ID를 적절한 챕터에 연결
179
182
  - Fallback: TOC가 비어있을 때 단일 "Document" 챕터 생성
180
183
 
181
184
  ## API 문서
@@ -197,19 +200,23 @@ interface DocumentProcessorOptions {
197
200
  captionParserModel?: LanguageModel; // 캡션 파서용
198
201
 
199
202
  // 배치 처리 설정
200
- textCleanerBatchSize?: number; // 텍스트 정리 (기본값: 10)
201
- captionParserBatchSize?: number; // 캡션 파싱 (기본값: 5)
202
- captionValidatorBatchSize?: number; // 캡션 검증 (기본값: 5)
203
+ textCleanerBatchSize: number; // 텍스트 정리 배치 크기 (필수)
204
+ captionParserBatchSize: number; // 캡션 파싱 배치 크기 (필수)
205
+ captionValidatorBatchSize: number; // 캡션 검증 배치 크기 (필수)
203
206
 
204
207
  // 재시도 설정
205
208
  maxRetries?: number; // LLM API 재시도 횟수 (기본값: 3)
206
- enableFallbackRetry?: boolean; // Fallback 재시도 활성화 (기본값: true)
209
+ enableFallbackRetry?: boolean; // Fallback 재시도 활성화 (기본값: false)
210
+
211
+ // 고급 옵션
212
+ abortSignal?: AbortSignal; // 취소 지원
213
+ onTokenUsage?: (report: TokenUsageReport) => void; // 실시간 토큰 사용량 모니터링
207
214
  }
208
215
  ```
209
216
 
210
217
  #### 메서드
211
218
 
212
- ##### `process(doclingDoc, reportId, outputPath): Promise<ProcessedDocument>`
219
+ ##### `process(doclingDoc, reportId, outputPath): Promise<DocumentProcessResult>`
213
220
 
214
221
  DoclingDocument를 ProcessedDocument로 변환합니다.
215
222
 
@@ -221,22 +228,27 @@ DoclingDocument를 ProcessedDocument로 변환합니다.
221
228
 
222
229
  **반환값:**
223
230
 
224
- - `Promise<ProcessedDocument>`: 처리된 문서
231
+ - `Promise<DocumentProcessResult>`: 결과 객체:
232
+ - `document` (ProcessedDocument): 처리된 문서 (`chapters`, `images`, `tables`, `footnotes` 포함)
233
+ - `usage` (TokenUsageReport): 토큰 사용량 리포트
225
234
 
226
235
  ### Fallback 재시도 메커니즘
227
236
 
228
- `enableFallbackRetry: true`로 설정하면, LLM 컴포넌트가 실패할 때 자동으로 fallbackModel로 재시도합니다:
237
+ `enableFallbackRetry: true`로 설정하면 (기본값은 `false`), LLM 컴포넌트가 실패할 때 자동으로 fallbackModel로 재시도합니다:
229
238
 
230
239
  ```typescript
231
240
  const processor = new DocumentProcessor({
232
241
  logger,
233
242
  fallbackModel: anthropic('claude-opus-4-5'), // 재시도용
234
243
  pageRangeParserModel: openai('gpt-5.2'), // 첫 시도
235
- enableFallbackRetry: true, // 실패 시 fallback 사용
244
+ enableFallbackRetry: true, // 실패 시 fallback 사용 (기본값: false)
245
+ textCleanerBatchSize: 10,
246
+ captionParserBatchSize: 5,
247
+ captionValidatorBatchSize: 5,
236
248
  });
237
249
 
238
250
  // pageRangeParserModel이 실패하면 자동으로 fallbackModel로 재시도
239
- const result = await processor.process(doc, 'id', 'path');
251
+ const { document, usage } = await processor.process(doc, 'id', 'path');
240
252
  ```
241
253
 
242
254
  ### 배치 크기 파라미터
@@ -257,7 +269,7 @@ TOC 추출 실패 시 발생하는 에러들:
257
269
 
258
270
  ```typescript
259
271
  try {
260
- const result = await processor.process(doc, 'id', 'path');
272
+ const { document, usage } = await processor.process(doc, 'id', 'path');
261
273
  } catch (error) {
262
274
  if (error instanceof TocNotFoundError) {
263
275
  console.log('TOC를 찾을 수 없습니다. 단일 챕터로 처리됩니다.');
package/README.md CHANGED
@@ -72,16 +72,18 @@ const processor = new DocumentProcessor({
72
72
  });
73
73
 
74
74
  // Process document
75
- const processedDoc = await processor.process(
75
+ const { document, usage } = await processor.process(
76
76
  doclingDocument, // PDF parser output
77
77
  'report-001', // Report ID
78
78
  outputPath, // Directory containing images/pages
79
79
  );
80
80
 
81
81
  // Use results
82
- console.log('TOC:', processedDoc.chapters);
83
- console.log('Images:', processedDoc.images);
84
- console.log('Tables:', processedDoc.tables);
82
+ console.log('TOC:', document.chapters);
83
+ console.log('Images:', document.images);
84
+ console.log('Tables:', document.tables);
85
+ console.log('Footnotes:', document.footnotes);
86
+ console.log('Token Usage:', usage.total);
85
87
  ```
86
88
 
87
89
  ### Advanced Usage - Per-Component Model Specification
@@ -109,10 +111,10 @@ const processor = new DocumentProcessor({
109
111
 
110
112
  // Retry settings
111
113
  maxRetries: 3,
112
- enableFallbackRetry: true, // Automatic retry with fallback model
114
+ enableFallbackRetry: true, // Automatic retry with fallback model (default: false)
113
115
  });
114
116
 
115
- const processedDoc = await processor.process(
117
+ const { document, usage } = await processor.process(
116
118
  doclingDocument,
117
119
  'report-001',
118
120
  outputPath,
@@ -176,6 +178,7 @@ DocumentProcessor processes documents through a 5-stage pipeline:
176
178
  - Create Chapter hierarchy
177
179
  - Link text blocks to chapters by page range
178
180
  - Connect image/table IDs to appropriate chapters
181
+ - Link footnote IDs to appropriate chapters
179
182
  - Fallback: Create single "Document" chapter when TOC is empty
180
183
 
181
184
  ## API Documentation
@@ -197,19 +200,23 @@ interface DocumentProcessorOptions {
197
200
  captionParserModel?: LanguageModel; // For caption parser
198
201
 
199
202
  // Batch processing settings
200
- textCleanerBatchSize?: number; // Text cleaning (default: 10)
201
- captionParserBatchSize?: number; // Caption parsing (default: 5)
202
- captionValidatorBatchSize?: number; // Caption validation (default: 5)
203
+ textCleanerBatchSize: number; // Text cleaning batch size (required)
204
+ captionParserBatchSize: number; // Caption parsing batch size (required)
205
+ captionValidatorBatchSize: number; // Caption validation batch size (required)
203
206
 
204
207
  // Retry settings
205
208
  maxRetries?: number; // LLM API retry count (default: 3)
206
- enableFallbackRetry?: boolean; // Enable fallback retry (default: true)
209
+ enableFallbackRetry?: boolean; // Enable fallback retry (default: false)
210
+
211
+ // Advanced options
212
+ abortSignal?: AbortSignal; // Cancellation support
213
+ onTokenUsage?: (report: TokenUsageReport) => void; // Real-time token usage monitoring
207
214
  }
208
215
  ```
209
216
 
210
217
  #### Methods
211
218
 
212
- ##### `process(doclingDoc, reportId, outputPath): Promise<ProcessedDocument>`
219
+ ##### `process(doclingDoc, reportId, outputPath): Promise<DocumentProcessResult>`
213
220
 
214
221
  Transforms DoclingDocument into ProcessedDocument.
215
222
 
@@ -221,22 +228,27 @@ Transforms DoclingDocument into ProcessedDocument.
221
228
 
222
229
  **Returns:**
223
230
 
224
- - `Promise<ProcessedDocument>`: Processed document
231
+ - `Promise<DocumentProcessResult>`: Result containing:
232
+ - `document` (ProcessedDocument): Processed document (includes `chapters`, `images`, `tables`, `footnotes`)
233
+ - `usage` (TokenUsageReport): Token usage report
225
234
 
226
235
  ### Fallback Retry Mechanism
227
236
 
228
- When `enableFallbackRetry: true` is set, LLM components automatically retry with fallbackModel on failure:
237
+ When `enableFallbackRetry: true` is set (default is `false`), LLM components automatically retry with fallbackModel on failure:
229
238
 
230
239
  ```typescript
231
240
  const processor = new DocumentProcessor({
232
241
  logger,
233
242
  fallbackModel: anthropic('claude-opus-4-5'), // For retry
234
243
  pageRangeParserModel: openai('gpt-5.2'), // First attempt
235
- enableFallbackRetry: true, // Use fallback on failure
244
+ enableFallbackRetry: true, // Use fallback on failure (default: false)
245
+ textCleanerBatchSize: 10,
246
+ captionParserBatchSize: 5,
247
+ captionValidatorBatchSize: 5,
236
248
  });
237
249
 
238
250
  // If pageRangeParserModel fails, automatically retries with fallbackModel
239
- const result = await processor.process(doc, 'id', 'path');
251
+ const { document, usage } = await processor.process(doc, 'id', 'path');
240
252
  ```
241
253
 
242
254
  ### Batch Size Parameters
@@ -257,7 +269,7 @@ Errors thrown when TOC extraction fails:
257
269
 
258
270
  ```typescript
259
271
  try {
260
- const result = await processor.process(doc, 'id', 'path');
272
+ const { document, usage } = await processor.process(doc, 'id', 'path');
261
273
  } catch (error) {
262
274
  if (error instanceof TocNotFoundError) {
263
275
  console.log('TOC not found. Processing as single chapter.');