@kreuzberg/node 4.2.14 → 4.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kreuzberg/node",
3
- "version": "4.2.14",
3
+ "version": "4.3.0",
4
4
  "description": "Kreuzberg document intelligence - Node.js native bindings",
5
5
  "author": {
6
6
  "name": "Na'aman Hirschfeld",
@@ -71,8 +71,10 @@
71
71
  "targets": [
72
72
  "aarch64-apple-darwin",
73
73
  "aarch64-unknown-linux-gnu",
74
+ "aarch64-unknown-linux-musl",
74
75
  "x86_64-pc-windows-msvc",
75
- "x86_64-unknown-linux-gnu"
76
+ "x86_64-unknown-linux-gnu",
77
+ "x86_64-unknown-linux-musl"
76
78
  ]
77
79
  },
78
80
  "engines": {
@@ -106,23 +108,23 @@
106
108
  "devDependencies": {
107
109
  "@napi-rs/cli": "^3.5.1",
108
110
  "@types/archiver": "^7.0.0",
109
- "@types/node": "^25.2.1",
111
+ "@types/node": "^25.2.3",
110
112
  "@types/which": "^3.0.4",
111
113
  "@vitest/coverage-v8": "^4.0.18",
112
114
  "archiver": "^7.0.1",
113
- "oxlint": "^1.43.0",
115
+ "oxlint": "^1.46.0",
114
116
  "tsup": "^8.5.1",
115
117
  "typescript": "^5.9.3",
116
118
  "vitest": "^4.0.18"
117
119
  },
118
120
  "dependencies": {
119
121
  "@emnapi/runtime": "1.8.1",
120
- "which": "^6.0.0"
122
+ "which": "^6.0.1"
121
123
  },
122
124
  "optionalDependencies": {
123
- "@kreuzberg/node-darwin-arm64": "4.2.14",
124
- "@kreuzberg/node-linux-arm64-gnu": "4.2.14",
125
- "@kreuzberg/node-linux-x64-gnu": "4.2.14",
126
- "@kreuzberg/node-win32-x64-msvc": "4.2.14"
125
+ "@kreuzberg/node-darwin-arm64": "4.3.0",
126
+ "@kreuzberg/node-linux-arm64-gnu": "4.3.0",
127
+ "@kreuzberg/node-linux-x64-gnu": "4.3.0",
128
+ "@kreuzberg/node-win32-x64-msvc": "4.3.0"
127
129
  }
128
130
  }
@@ -1,193 +0,0 @@
1
- import { OcrBackendProtocol } from '../types.mjs';
2
-
3
- /**
4
- * Guten OCR backend for document OCR processing.
5
- *
6
- * This module provides integration with @gutenye/ocr-node for optical character recognition.
7
- * Guten OCR uses PaddleOCR models via ONNX Runtime for high-performance text extraction.
8
- *
9
- * @module ocr/guten-ocr
10
- */
11
-
12
- /**
13
- * Guten OCR backend for OCR processing.
14
- *
15
- * This backend uses @gutenye/ocr-node for text extraction from images.
16
- * It uses PaddleOCR models via ONNX Runtime for efficient processing.
17
- *
18
- * ## Installation
19
- *
20
- * Install the optional dependency:
21
- * ```bash
22
- * npm install @gutenye/ocr-node
23
- * # or
24
- * pnpm add @gutenye/ocr-node
25
- * # or
26
- * bun add @gutenye/ocr-node
27
- * ```
28
- *
29
- * ## Usage
30
- *
31
- * ```typescript
32
- * import { GutenOcrBackend } from '@kreuzberg/node/ocr/guten-ocr';
33
- * import { registerOcrBackend, extractFile } from '@kreuzberg/node';
34
- *
35
- * // Create and register the backend
36
- * const backend = new GutenOcrBackend();
37
- * await backend.initialize();
38
- * registerOcrBackend(backend);
39
- *
40
- * // Extract with OCR enabled
41
- * const result = await extractFile('scanned.pdf', null, {
42
- * ocr: { backend: 'guten-ocr', language: 'en' },
43
- * });
44
- * console.log(result.content);
45
- * ```
46
- *
47
- * ## Supported Languages
48
- *
49
- * Guten OCR supports multiple languages via different model configurations.
50
- * The default models support English ("en") and Chinese ("ch_sim", "ch_tra").
51
- *
52
- * @example
53
- * ```typescript
54
- * // Basic usage with default settings
55
- * const backend = new GutenOcrBackend();
56
- * await backend.initialize();
57
- *
58
- * // Custom model configuration
59
- * const customBackend = new GutenOcrBackend({
60
- * models: {
61
- * detectionPath: './models/detection.onnx',
62
- * recognitionPath: './models/recognition.onnx',
63
- * dictionaryPath: './models/dict.txt'
64
- * }
65
- * });
66
- * await customBackend.initialize();
67
- * ```
68
- */
69
- declare class GutenOcrBackend implements OcrBackendProtocol {
70
- private ocr;
71
- private ocrModule;
72
- private options?;
73
- /**
74
- * Create a new Guten OCR backend.
75
- *
76
- * @param options - Optional configuration for Guten OCR
77
- * @param options.models - Custom model paths (default: uses bundled models)
78
- * @param options.isDebug - Enable debug mode (default: false)
79
- * @param options.debugOutputDir - Directory for debug output (default: undefined)
80
- * @param options.onnxOptions - Custom ONNX Runtime options (default: undefined)
81
- *
82
- * @example
83
- * ```typescript
84
- * // Default configuration
85
- * const backend = new GutenOcrBackend();
86
- *
87
- * // With debug enabled
88
- * const debugBackend = new GutenOcrBackend({
89
- * isDebug: true,
90
- * debugOutputDir: './ocr_debug'
91
- * });
92
- * ```
93
- */
94
- constructor(options?: {
95
- models?: {
96
- detectionPath: string;
97
- recognitionPath: string;
98
- dictionaryPath: string;
99
- };
100
- isDebug?: boolean;
101
- debugOutputDir?: string;
102
- onnxOptions?: unknown;
103
- });
104
- /**
105
- * Get the backend name.
106
- *
107
- * @returns Backend name ("guten-ocr")
108
- */
109
- name(): string;
110
- /**
111
- * Get list of supported language codes.
112
- *
113
- * Guten OCR supports multiple languages depending on the model configuration.
114
- * The default models support English and Chinese.
115
- *
116
- * @returns Array of ISO 639-1/2 language codes
117
- */
118
- supportedLanguages(): string[];
119
- /**
120
- * Initialize the OCR backend.
121
- *
122
- * This method loads the Guten OCR module and creates an OCR instance.
123
- * Call this before using processImage().
124
- *
125
- * @throws {Error} If @gutenye/ocr-node is not installed
126
- * @throws {Error} If OCR initialization fails
127
- *
128
- * @example
129
- * ```typescript
130
- * const backend = new GutenOcrBackend();
131
- * await backend.initialize();
132
- * ```
133
- */
134
- initialize(): Promise<void>;
135
- /**
136
- * Shutdown the backend and release resources.
137
- *
138
- * This method cleans up all resources associated with the backend,
139
- * including the GutenOCR instance and module references.
140
- *
141
- * @example
142
- * ```typescript
143
- * const backend = new GutenOcrBackend();
144
- * await backend.initialize();
145
- * // ... use backend ...
146
- * await backend.shutdown();
147
- * ```
148
- */
149
- shutdown(): Promise<void>;
150
- /**
151
- * Process image bytes and extract text using Guten OCR.
152
- *
153
- * This method:
154
- * 1. Decodes the image using sharp (if pixel data is needed) or passes bytes directly
155
- * 2. Runs OCR detection to find text regions
156
- * 3. Runs OCR recognition on each text region
157
- * 4. Returns extracted text with metadata
158
- *
159
- * @param imageBytes - Raw image data (PNG, JPEG, TIFF, etc.)
160
- * @param language - Language code (must be in supportedLanguages())
161
- * @returns Promise resolving to OCR result with content and metadata
162
- *
163
- * @throws {Error} If backend is not initialized
164
- * @throws {Error} If OCR processing fails
165
- *
166
- * @example
167
- * ```typescript
168
- * import { readFile } from 'fs/promises';
169
- *
170
- * const backend = new GutenOcrBackend();
171
- * await backend.initialize();
172
- *
173
- * const imageBytes = await readFile('scanned.png');
174
- * const result = await backend.processImage(imageBytes, 'en');
175
- * console.log(result.content);
176
- * console.log(result.metadata.confidence);
177
- * ```
178
- */
179
- processImage(imageBytes: Uint8Array | string, language: string): Promise<{
180
- content: string;
181
- mime_type: string;
182
- metadata: {
183
- width: number;
184
- height: number;
185
- confidence: number;
186
- text_regions: number;
187
- language: string;
188
- };
189
- tables: never[];
190
- }>;
191
- }
192
-
193
- export { GutenOcrBackend };
@@ -1,193 +0,0 @@
1
- import { OcrBackendProtocol } from '../types.js';
2
-
3
- /**
4
- * Guten OCR backend for document OCR processing.
5
- *
6
- * This module provides integration with @gutenye/ocr-node for optical character recognition.
7
- * Guten OCR uses PaddleOCR models via ONNX Runtime for high-performance text extraction.
8
- *
9
- * @module ocr/guten-ocr
10
- */
11
-
12
- /**
13
- * Guten OCR backend for OCR processing.
14
- *
15
- * This backend uses @gutenye/ocr-node for text extraction from images.
16
- * It uses PaddleOCR models via ONNX Runtime for efficient processing.
17
- *
18
- * ## Installation
19
- *
20
- * Install the optional dependency:
21
- * ```bash
22
- * npm install @gutenye/ocr-node
23
- * # or
24
- * pnpm add @gutenye/ocr-node
25
- * # or
26
- * bun add @gutenye/ocr-node
27
- * ```
28
- *
29
- * ## Usage
30
- *
31
- * ```typescript
32
- * import { GutenOcrBackend } from '@kreuzberg/node/ocr/guten-ocr';
33
- * import { registerOcrBackend, extractFile } from '@kreuzberg/node';
34
- *
35
- * // Create and register the backend
36
- * const backend = new GutenOcrBackend();
37
- * await backend.initialize();
38
- * registerOcrBackend(backend);
39
- *
40
- * // Extract with OCR enabled
41
- * const result = await extractFile('scanned.pdf', null, {
42
- * ocr: { backend: 'guten-ocr', language: 'en' },
43
- * });
44
- * console.log(result.content);
45
- * ```
46
- *
47
- * ## Supported Languages
48
- *
49
- * Guten OCR supports multiple languages via different model configurations.
50
- * The default models support English ("en") and Chinese ("ch_sim", "ch_tra").
51
- *
52
- * @example
53
- * ```typescript
54
- * // Basic usage with default settings
55
- * const backend = new GutenOcrBackend();
56
- * await backend.initialize();
57
- *
58
- * // Custom model configuration
59
- * const customBackend = new GutenOcrBackend({
60
- * models: {
61
- * detectionPath: './models/detection.onnx',
62
- * recognitionPath: './models/recognition.onnx',
63
- * dictionaryPath: './models/dict.txt'
64
- * }
65
- * });
66
- * await customBackend.initialize();
67
- * ```
68
- */
69
- declare class GutenOcrBackend implements OcrBackendProtocol {
70
- private ocr;
71
- private ocrModule;
72
- private options?;
73
- /**
74
- * Create a new Guten OCR backend.
75
- *
76
- * @param options - Optional configuration for Guten OCR
77
- * @param options.models - Custom model paths (default: uses bundled models)
78
- * @param options.isDebug - Enable debug mode (default: false)
79
- * @param options.debugOutputDir - Directory for debug output (default: undefined)
80
- * @param options.onnxOptions - Custom ONNX Runtime options (default: undefined)
81
- *
82
- * @example
83
- * ```typescript
84
- * // Default configuration
85
- * const backend = new GutenOcrBackend();
86
- *
87
- * // With debug enabled
88
- * const debugBackend = new GutenOcrBackend({
89
- * isDebug: true,
90
- * debugOutputDir: './ocr_debug'
91
- * });
92
- * ```
93
- */
94
- constructor(options?: {
95
- models?: {
96
- detectionPath: string;
97
- recognitionPath: string;
98
- dictionaryPath: string;
99
- };
100
- isDebug?: boolean;
101
- debugOutputDir?: string;
102
- onnxOptions?: unknown;
103
- });
104
- /**
105
- * Get the backend name.
106
- *
107
- * @returns Backend name ("guten-ocr")
108
- */
109
- name(): string;
110
- /**
111
- * Get list of supported language codes.
112
- *
113
- * Guten OCR supports multiple languages depending on the model configuration.
114
- * The default models support English and Chinese.
115
- *
116
- * @returns Array of ISO 639-1/2 language codes
117
- */
118
- supportedLanguages(): string[];
119
- /**
120
- * Initialize the OCR backend.
121
- *
122
- * This method loads the Guten OCR module and creates an OCR instance.
123
- * Call this before using processImage().
124
- *
125
- * @throws {Error} If @gutenye/ocr-node is not installed
126
- * @throws {Error} If OCR initialization fails
127
- *
128
- * @example
129
- * ```typescript
130
- * const backend = new GutenOcrBackend();
131
- * await backend.initialize();
132
- * ```
133
- */
134
- initialize(): Promise<void>;
135
- /**
136
- * Shutdown the backend and release resources.
137
- *
138
- * This method cleans up all resources associated with the backend,
139
- * including the GutenOCR instance and module references.
140
- *
141
- * @example
142
- * ```typescript
143
- * const backend = new GutenOcrBackend();
144
- * await backend.initialize();
145
- * // ... use backend ...
146
- * await backend.shutdown();
147
- * ```
148
- */
149
- shutdown(): Promise<void>;
150
- /**
151
- * Process image bytes and extract text using Guten OCR.
152
- *
153
- * This method:
154
- * 1. Decodes the image using sharp (if pixel data is needed) or passes bytes directly
155
- * 2. Runs OCR detection to find text regions
156
- * 3. Runs OCR recognition on each text region
157
- * 4. Returns extracted text with metadata
158
- *
159
- * @param imageBytes - Raw image data (PNG, JPEG, TIFF, etc.)
160
- * @param language - Language code (must be in supportedLanguages())
161
- * @returns Promise resolving to OCR result with content and metadata
162
- *
163
- * @throws {Error} If backend is not initialized
164
- * @throws {Error} If OCR processing fails
165
- *
166
- * @example
167
- * ```typescript
168
- * import { readFile } from 'fs/promises';
169
- *
170
- * const backend = new GutenOcrBackend();
171
- * await backend.initialize();
172
- *
173
- * const imageBytes = await readFile('scanned.png');
174
- * const result = await backend.processImage(imageBytes, 'en');
175
- * console.log(result.content);
176
- * console.log(result.metadata.confidence);
177
- * ```
178
- */
179
- processImage(imageBytes: Uint8Array | string, language: string): Promise<{
180
- content: string;
181
- mime_type: string;
182
- metadata: {
183
- width: number;
184
- height: number;
185
- confidence: number;
186
- text_regions: number;
187
- language: string;
188
- };
189
- tables: never[];
190
- }>;
191
- }
192
-
193
- export { GutenOcrBackend };
@@ -1,234 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // typescript/ocr/guten-ocr.ts
31
- var guten_ocr_exports = {};
32
- __export(guten_ocr_exports, {
33
- GutenOcrBackend: () => GutenOcrBackend
34
- });
35
- module.exports = __toCommonJS(guten_ocr_exports);
36
- var GutenOcrBackend = class {
37
- ocr = null;
38
- ocrModule = null;
39
- options;
40
- /**
41
- * Create a new Guten OCR backend.
42
- *
43
- * @param options - Optional configuration for Guten OCR
44
- * @param options.models - Custom model paths (default: uses bundled models)
45
- * @param options.isDebug - Enable debug mode (default: false)
46
- * @param options.debugOutputDir - Directory for debug output (default: undefined)
47
- * @param options.onnxOptions - Custom ONNX Runtime options (default: undefined)
48
- *
49
- * @example
50
- * ```typescript
51
- * // Default configuration
52
- * const backend = new GutenOcrBackend();
53
- *
54
- * // With debug enabled
55
- * const debugBackend = new GutenOcrBackend({
56
- * isDebug: true,
57
- * debugOutputDir: './ocr_debug'
58
- * });
59
- * ```
60
- */
61
- constructor(options) {
62
- if (options !== void 0) {
63
- this.options = options;
64
- }
65
- }
66
- /**
67
- * Get the backend name.
68
- *
69
- * @returns Backend name ("guten-ocr")
70
- */
71
- name() {
72
- return "guten-ocr";
73
- }
74
- /**
75
- * Get list of supported language codes.
76
- *
77
- * Guten OCR supports multiple languages depending on the model configuration.
78
- * The default models support English and Chinese.
79
- *
80
- * @returns Array of ISO 639-1/2 language codes
81
- */
82
- supportedLanguages() {
83
- return ["en", "eng", "ch_sim", "ch_tra", "chinese"];
84
- }
85
- /**
86
- * Initialize the OCR backend.
87
- *
88
- * This method loads the Guten OCR module and creates an OCR instance.
89
- * Call this before using processImage().
90
- *
91
- * @throws {Error} If @gutenye/ocr-node is not installed
92
- * @throws {Error} If OCR initialization fails
93
- *
94
- * @example
95
- * ```typescript
96
- * const backend = new GutenOcrBackend();
97
- * await backend.initialize();
98
- * ```
99
- */
100
- async initialize() {
101
- if (this.ocr !== null) {
102
- return;
103
- }
104
- try {
105
- this.ocrModule = await import("@gutenye/ocr-node").then((m) => m.default || m);
106
- } catch (e) {
107
- const error = e;
108
- throw new Error(
109
- `Guten OCR support requires the '@gutenye/ocr-node' package. Install with: npm install @gutenye/ocr-node. Error: ${error.message}`
110
- );
111
- }
112
- try {
113
- this.ocr = await this.ocrModule?.create(this.options) ?? null;
114
- } catch (e) {
115
- const error = e;
116
- throw new Error(`Failed to initialize Guten OCR: ${error.message}`);
117
- }
118
- }
119
- /**
120
- * Shutdown the backend and release resources.
121
- *
122
- * This method cleans up all resources associated with the backend,
123
- * including the GutenOCR instance and module references.
124
- *
125
- * @example
126
- * ```typescript
127
- * const backend = new GutenOcrBackend();
128
- * await backend.initialize();
129
- * // ... use backend ...
130
- * await backend.shutdown();
131
- * ```
132
- */
133
- async shutdown() {
134
- if (this.ocr !== null) {
135
- this.ocr = null;
136
- }
137
- if (this.ocrModule !== null) {
138
- this.ocrModule = null;
139
- }
140
- }
141
- /**
142
- * Process image bytes and extract text using Guten OCR.
143
- *
144
- * This method:
145
- * 1. Decodes the image using sharp (if pixel data is needed) or passes bytes directly
146
- * 2. Runs OCR detection to find text regions
147
- * 3. Runs OCR recognition on each text region
148
- * 4. Returns extracted text with metadata
149
- *
150
- * @param imageBytes - Raw image data (PNG, JPEG, TIFF, etc.)
151
- * @param language - Language code (must be in supportedLanguages())
152
- * @returns Promise resolving to OCR result with content and metadata
153
- *
154
- * @throws {Error} If backend is not initialized
155
- * @throws {Error} If OCR processing fails
156
- *
157
- * @example
158
- * ```typescript
159
- * import { readFile } from 'fs/promises';
160
- *
161
- * const backend = new GutenOcrBackend();
162
- * await backend.initialize();
163
- *
164
- * const imageBytes = await readFile('scanned.png');
165
- * const result = await backend.processImage(imageBytes, 'en');
166
- * console.log(result.content);
167
- * console.log(result.metadata.confidence);
168
- * ```
169
- */
170
- async processImage(imageBytes, language) {
171
- if (this.ocr === null) {
172
- await this.initialize();
173
- }
174
- if (this.ocr === null) {
175
- throw new Error("Guten OCR backend failed to initialize");
176
- }
177
- try {
178
- const buffer = typeof imageBytes === "string" ? Buffer.from(imageBytes, "base64") : Buffer.from(imageBytes);
179
- const debugEnv = process.env["KREUZBERG_DEBUG_GUTEN"];
180
- if (debugEnv === "1") {
181
- const header = Array.from(buffer.subarray(0, 8));
182
- console.log("[Guten OCR] Debug input header:", header);
183
- console.log(
184
- "[Guten OCR] Buffer?",
185
- Buffer.isBuffer(buffer),
186
- "constructor",
187
- imageBytes?.constructor?.name,
188
- "length",
189
- buffer.length,
190
- "type",
191
- typeof imageBytes
192
- );
193
- }
194
- let width = 0;
195
- let height = 0;
196
- try {
197
- const sharpModule = await import("sharp");
198
- const sharp = sharpModule.default || sharpModule;
199
- const image = sharp(buffer);
200
- const metadata = await image.metadata();
201
- const metadataRecord = metadata;
202
- width = metadataRecord["width"] ?? 0;
203
- height = metadataRecord["height"] ?? 0;
204
- } catch (metadataError) {
205
- const error = metadataError;
206
- console.warn(`[Guten OCR] Unable to read image metadata via sharp: ${error.message}`);
207
- }
208
- const result = await this.ocr.detect(buffer);
209
- const textLines = result.map((line) => line.text);
210
- const content = textLines.join("\n");
211
- const avgConfidence = result.length > 0 ? result.reduce((sum, line) => sum + line.mean, 0) / result.length : 0;
212
- return {
213
- content,
214
- mime_type: "text/plain",
215
- metadata: {
216
- width,
217
- height,
218
- confidence: avgConfidence,
219
- text_regions: result.length,
220
- language
221
- },
222
- tables: []
223
- };
224
- } catch (e) {
225
- const error = e;
226
- throw new Error(`Guten OCR processing failed: ${error.message}`);
227
- }
228
- }
229
- };
230
- // Annotate the CommonJS export names for ESM import in node:
231
- 0 && (module.exports = {
232
- GutenOcrBackend
233
- });
234
- //# sourceMappingURL=guten-ocr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../typescript/ocr/guten-ocr.ts"],"sourcesContent":["/**\n * Guten OCR backend for document OCR processing.\n *\n * This module provides integration with @gutenye/ocr-node for optical character recognition.\n * Guten OCR uses PaddleOCR models via ONNX Runtime for high-performance text extraction.\n *\n * @module ocr/guten-ocr\n */\n\nimport type { OcrBackendProtocol } from \"../types.js\";\n\n/**\n * Text line detected by Guten OCR.\n */\ninterface TextLine {\n\ttext: string;\n\tmean: number;\n\tbox: number[][];\n}\n\n/**\n * Guten OCR instance interface.\n */\ninterface GutenOcr {\n\tdetect(imagePath: string | Buffer, options?: { onnxOptions?: unknown }): Promise<TextLine[]>;\n}\n\n/**\n * Guten OCR module interface.\n */\ninterface GutenOcrModule {\n\tcreate(options?: {\n\t\tmodels?: {\n\t\t\tdetectionPath: string;\n\t\t\trecognitionPath: string;\n\t\t\tdictionaryPath: string;\n\t\t};\n\t\tisDebug?: boolean;\n\t\tdebugOutputDir?: string;\n\t\tonnxOptions?: unknown;\n\t}): Promise<GutenOcr>;\n}\n\n/**\n * Guten OCR backend for OCR processing.\n *\n * This backend uses @gutenye/ocr-node for text extraction from images.\n * It uses PaddleOCR models via ONNX Runtime for efficient processing.\n *\n * ## Installation\n *\n * Install the optional dependency:\n * ```bash\n * npm install @gutenye/ocr-node\n * # or\n * pnpm add @gutenye/ocr-node\n * # or\n * bun add @gutenye/ocr-node\n * ```\n *\n * ## Usage\n *\n * ```typescript\n * import { GutenOcrBackend } from '@kreuzberg/node/ocr/guten-ocr';\n * import { registerOcrBackend, extractFile } from '@kreuzberg/node';\n *\n * // Create and register the backend\n * const backend = new GutenOcrBackend();\n * await backend.initialize();\n * registerOcrBackend(backend);\n *\n * // Extract with OCR enabled\n * const result = await extractFile('scanned.pdf', null, {\n * ocr: { backend: 'guten-ocr', language: 'en' },\n * });\n * console.log(result.content);\n * ```\n *\n * ## Supported Languages\n *\n * Guten OCR supports multiple languages via different model configurations.\n * The default models support English (\"en\") and Chinese (\"ch_sim\", \"ch_tra\").\n *\n * @example\n * ```typescript\n * // Basic usage with default settings\n * const backend = new GutenOcrBackend();\n * await backend.initialize();\n *\n * // Custom model configuration\n * const customBackend = new GutenOcrBackend({\n * models: {\n * detectionPath: './models/detection.onnx',\n * recognitionPath: './models/recognition.onnx',\n * dictionaryPath: './models/dict.txt'\n * }\n * });\n * await customBackend.initialize();\n * ```\n */\nexport class GutenOcrBackend implements OcrBackendProtocol {\n\tprivate ocr: GutenOcr | null = null;\n\tprivate ocrModule: GutenOcrModule | null = null;\n\tprivate options?: {\n\t\tmodels?: {\n\t\t\tdetectionPath: string;\n\t\t\trecognitionPath: string;\n\t\t\tdictionaryPath: string;\n\t\t};\n\t\tisDebug?: boolean;\n\t\tdebugOutputDir?: string;\n\t\tonnxOptions?: unknown;\n\t};\n\n\t/**\n\t * Create a new Guten OCR backend.\n\t *\n\t * @param options - Optional configuration for Guten OCR\n\t * @param options.models - Custom model paths (default: uses bundled models)\n\t * @param options.isDebug - Enable debug mode (default: false)\n\t * @param options.debugOutputDir - Directory for debug output (default: undefined)\n\t * @param options.onnxOptions - Custom ONNX Runtime options (default: undefined)\n\t *\n\t * @example\n\t * ```typescript\n\t * // Default configuration\n\t * const backend = new GutenOcrBackend();\n\t *\n\t * // With debug enabled\n\t * const debugBackend = new GutenOcrBackend({\n\t * isDebug: true,\n\t * debugOutputDir: './ocr_debug'\n\t * });\n\t * ```\n\t */\n\tconstructor(options?: {\n\t\tmodels?: {\n\t\t\tdetectionPath: string;\n\t\t\trecognitionPath: string;\n\t\t\tdictionaryPath: string;\n\t\t};\n\t\tisDebug?: boolean;\n\t\tdebugOutputDir?: string;\n\t\tonnxOptions?: unknown;\n\t}) {\n\t\tif (options !== undefined) {\n\t\t\tthis.options = options;\n\t\t}\n\t}\n\n\t/**\n\t * Get the backend name.\n\t *\n\t * @returns Backend name (\"guten-ocr\")\n\t */\n\tname(): string {\n\t\treturn \"guten-ocr\";\n\t}\n\n\t/**\n\t * Get list of supported language codes.\n\t *\n\t * Guten OCR supports multiple languages depending on the model configuration.\n\t * The default models support English and Chinese.\n\t *\n\t * @returns Array of ISO 639-1/2 language codes\n\t */\n\tsupportedLanguages(): string[] {\n\t\treturn [\"en\", \"eng\", \"ch_sim\", \"ch_tra\", \"chinese\"];\n\t}\n\n\t/**\n\t * Initialize the OCR backend.\n\t *\n\t * This method loads the Guten OCR module and creates an OCR instance.\n\t * Call this before using processImage().\n\t *\n\t * @throws {Error} If @gutenye/ocr-node is not installed\n\t * @throws {Error} If OCR initialization fails\n\t *\n\t * @example\n\t * ```typescript\n\t * const backend = new GutenOcrBackend();\n\t * await backend.initialize();\n\t * ```\n\t */\n\tasync initialize(): Promise<void> {\n\t\tif (this.ocr !== null) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tthis.ocrModule = await import(\"@gutenye/ocr-node\").then((m) => (m.default || m) as GutenOcrModule);\n\t\t} catch (e) {\n\t\t\tconst error = e as Error;\n\t\t\tthrow new Error(\n\t\t\t\t`Guten OCR support requires the '@gutenye/ocr-node' package. ` +\n\t\t\t\t\t`Install with: npm install @gutenye/ocr-node. ` +\n\t\t\t\t\t`Error: ${error.message}`,\n\t\t\t);\n\t\t}\n\n\t\ttry {\n\t\t\tthis.ocr = (await this.ocrModule?.create(this.options)) ?? null;\n\t\t} catch (e) {\n\t\t\tconst error = e as Error;\n\t\t\tthrow new Error(`Failed to initialize Guten OCR: ${error.message}`);\n\t\t}\n\t}\n\n\t/**\n\t * Shutdown the backend and release resources.\n\t *\n\t * This method cleans up all resources associated with the backend,\n\t * including the GutenOCR instance and module references.\n\t *\n\t * @example\n\t * ```typescript\n\t * const backend = new GutenOcrBackend();\n\t * await backend.initialize();\n\t * // ... use backend ...\n\t * await backend.shutdown();\n\t * ```\n\t */\n\tasync shutdown(): Promise<void> {\n\t\tif (this.ocr !== null) {\n\t\t\tthis.ocr = null;\n\t\t}\n\n\t\tif (this.ocrModule !== null) {\n\t\t\tthis.ocrModule = null;\n\t\t}\n\t}\n\n\t/**\n\t * Process image bytes and extract text using Guten OCR.\n\t *\n\t * This method:\n\t * 1. Decodes the image using sharp (if pixel data is needed) or passes bytes directly\n\t * 2. Runs OCR detection to find text regions\n\t * 3. Runs OCR recognition on each text region\n\t * 4. Returns extracted text with metadata\n\t *\n\t * @param imageBytes - Raw image data (PNG, JPEG, TIFF, etc.)\n\t * @param language - Language code (must be in supportedLanguages())\n\t * @returns Promise resolving to OCR result with content and metadata\n\t *\n\t * @throws {Error} If backend is not initialized\n\t * @throws {Error} If OCR processing fails\n\t *\n\t * @example\n\t * ```typescript\n\t * import { readFile } from 'fs/promises';\n\t *\n\t * const backend = new GutenOcrBackend();\n\t * await backend.initialize();\n\t *\n\t * const imageBytes = await readFile('scanned.png');\n\t * const result = await backend.processImage(imageBytes, 'en');\n\t * console.log(result.content);\n\t * console.log(result.metadata.confidence);\n\t * ```\n\t */\n\tasync processImage(\n\t\timageBytes: Uint8Array | string,\n\t\tlanguage: string,\n\t): Promise<{\n\t\tcontent: string;\n\t\tmime_type: string;\n\t\tmetadata: {\n\t\t\twidth: number;\n\t\t\theight: number;\n\t\t\tconfidence: number;\n\t\t\ttext_regions: number;\n\t\t\tlanguage: string;\n\t\t};\n\t\ttables: never[];\n\t}> {\n\t\tif (this.ocr === null) {\n\t\t\tawait this.initialize();\n\t\t}\n\n\t\tif (this.ocr === null) {\n\t\t\tthrow new Error(\"Guten OCR backend failed to initialize\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst buffer = typeof imageBytes === \"string\" ? Buffer.from(imageBytes, \"base64\") : Buffer.from(imageBytes);\n\n\t\t\t// biome-ignore lint/complexity/useLiteralKeys: required for strict TypeScript noUncheckedIndexedAccess\n\t\t\tconst debugEnv = process.env[\"KREUZBERG_DEBUG_GUTEN\"];\n\t\t\tif (debugEnv === \"1\") {\n\t\t\t\tconst header = Array.from(buffer.subarray(0, 8));\n\t\t\t\tconsole.log(\"[Guten OCR] Debug input header:\", header);\n\t\t\t\tconsole.log(\n\t\t\t\t\t\"[Guten OCR] Buffer?\",\n\t\t\t\t\tBuffer.isBuffer(buffer),\n\t\t\t\t\t\"constructor\",\n\t\t\t\t\timageBytes?.constructor?.name,\n\t\t\t\t\t\"length\",\n\t\t\t\t\tbuffer.length,\n\t\t\t\t\t\"type\",\n\t\t\t\t\ttypeof imageBytes,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tlet width = 0;\n\t\t\tlet height = 0;\n\n\t\t\ttry {\n\t\t\t\tconst sharpModule = await import(\"sharp\");\n\t\t\t\tconst sharp = (sharpModule as unknown as { default?: unknown }).default || sharpModule;\n\t\t\t\tconst image = (sharp as (buffer: Buffer) => { metadata: () => Promise<Record<string, unknown>> })(buffer);\n\t\t\t\tconst metadata = await image.metadata();\n\t\t\t\tconst metadataRecord = metadata as Record<string, unknown>;\n\t\t\t\t// biome-ignore lint/complexity/useLiteralKeys: TypeScript TS4111 requires bracket notation for index signature properties\n\t\t\t\twidth = (metadataRecord[\"width\"] as number | undefined) ?? 0;\n\t\t\t\t// biome-ignore lint/complexity/useLiteralKeys: TypeScript TS4111 requires bracket notation for index signature properties\n\t\t\t\theight = (metadataRecord[\"height\"] as number | undefined) ?? 0;\n\t\t\t} catch (metadataError) {\n\t\t\t\tconst error = metadataError as Error;\n\t\t\t\tconsole.warn(`[Guten OCR] Unable to read image metadata via sharp: ${error.message}`);\n\t\t\t}\n\n\t\t\tconst result = await this.ocr.detect(buffer);\n\n\t\t\tconst textLines = result.map((line) => line.text);\n\t\t\tconst content = textLines.join(\"\\n\");\n\n\t\t\tconst avgConfidence = result.length > 0 ? result.reduce((sum, line) => sum + line.mean, 0) / result.length : 0;\n\n\t\t\treturn {\n\t\t\t\tcontent,\n\t\t\t\tmime_type: \"text/plain\",\n\t\t\t\tmetadata: {\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t\tconfidence: avgConfidence,\n\t\t\t\t\ttext_regions: result.length,\n\t\t\t\t\tlanguage,\n\t\t\t\t},\n\t\t\t\ttables: [],\n\t\t\t};\n\t\t} catch (e) {\n\t\t\tconst error = e as Error;\n\t\t\tthrow new Error(`Guten OCR processing failed: ${error.message}`);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoGO,IAAM,kBAAN,MAAoD;AAAA,EAClD,MAAuB;AAAA,EACvB,YAAmC;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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